Added engine
This commit is contained in:
commit
61ddd9fc26
78 changed files with 26595 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
x64/
|
||||
Debug/
|
||||
Release/
|
||||
*.vcxproj*
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
Mit License
|
||||
|
||||
Copyright (c) 2018 Gnarly Narwhal
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
34
src/geno/GenoChars.h
Normal file
34
src/geno/GenoChars.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_CHARS
|
||||
#define GNARLY_GENOME_CHARS
|
||||
|
||||
using char8 = char;
|
||||
using char16 = short;
|
||||
using char32 = int;
|
||||
|
||||
#endif // GNARLY_GENOME_CHARS
|
39
src/geno/GenoInts.h
Normal file
39
src/geno/GenoInts.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_INTS
|
||||
#define GNARLY_GENOME_INTS
|
||||
|
||||
using int8 = signed char;
|
||||
using uint8 = unsigned char;
|
||||
using int16 = signed short;
|
||||
using uint16 = unsigned short;
|
||||
using int32 = signed int;
|
||||
using uint32 = unsigned int;
|
||||
using int64 = signed long long;
|
||||
using uint64 = unsigned long long;
|
||||
|
||||
#endif // GNARLY_GENOME_INTS
|
32
src/geno/GenoMacros.h
Normal file
32
src/geno/GenoMacros.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_MACROS
|
||||
#define GNARLY_GENOME_MACROS
|
||||
|
||||
#define GENO_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
|
||||
#endif // GNARLY_GENOME_MACROS
|
33
src/geno/audio/GenoAL.h
Normal file
33
src/geno/audio/GenoAL.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_AL
|
||||
#define GNARLY_GENOME_AL
|
||||
|
||||
#include <AL\al.h>
|
||||
#include <AL\alc.h>
|
||||
|
||||
#endif // GNARLY_GENOME_AL
|
74
src/geno/audio/GenoAudioBuffer.cpp
Normal file
74
src/geno/audio/GenoAudioBuffer.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "AL\al.h"
|
||||
|
||||
#include "GenoAudioBuffer.h"
|
||||
|
||||
void GenoAudioBuffer::clean() {
|
||||
if (buffer)
|
||||
alDeleteBuffers(1, &buffer);
|
||||
}
|
||||
|
||||
GenoAudioBuffer::GenoAudioBuffer(uint32 format, uint32 size, uint8 data[], uint32 frequency) {
|
||||
clean();
|
||||
alGenBuffers(1, &buffer);
|
||||
alBufferData(buffer, format, data, size, frequency);
|
||||
}
|
||||
|
||||
GenoAudioBuffer::GenoAudioBuffer(GenoWavFile * wavFile) {
|
||||
bufferData(wavFile->getFormat(), wavFile->getSize(), wavFile->getData(), wavFile->getSampleRate());
|
||||
}
|
||||
|
||||
GenoAudioBuffer::GenoAudioBuffer(const char * path) {
|
||||
GenoWavFile * file = new GenoWavFile(path);
|
||||
loadWav(file);
|
||||
delete file;
|
||||
}
|
||||
|
||||
void GenoAudioBuffer::bufferData(uint32 format, uint32 size, uint8 data[], uint32 frequency) {
|
||||
clean();
|
||||
alGenBuffers(1, &buffer);
|
||||
alBufferData(buffer, format, data, size, frequency);
|
||||
}
|
||||
|
||||
void GenoAudioBuffer::loadWav(GenoWavFile * wavFile) {
|
||||
bufferData(wavFile->getFormat(), wavFile->getSize(), wavFile->getData(), wavFile->getSampleRate());
|
||||
}
|
||||
|
||||
void GenoAudioBuffer::loadWav(const char * path) {
|
||||
GenoWavFile * file = new GenoWavFile(path);
|
||||
loadWav(file);
|
||||
delete file;
|
||||
}
|
||||
|
||||
uint32 GenoAudioBuffer::getBuffer() {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
GenoAudioBuffer::~GenoAudioBuffer() {
|
||||
clean();
|
||||
}
|
50
src/geno/audio/GenoAudioBuffer.h
Normal file
50
src/geno/audio/GenoAudioBuffer.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_AUDIO_BUFFER
|
||||
#define GNARLY_GENOME_AUDIO_BUFFER
|
||||
|
||||
#include "../GenoInts.h"
|
||||
#include "../data/GenoWavFile.h"
|
||||
|
||||
class GenoAudioBuffer {
|
||||
private:
|
||||
uint32 buffer;
|
||||
|
||||
void clean();
|
||||
public:
|
||||
GenoAudioBuffer(uint32 format, uint32 size, uint8 data[], uint32 frequency);
|
||||
GenoAudioBuffer(GenoWavFile * wavFile);
|
||||
GenoAudioBuffer(const char * path);
|
||||
void bufferData(uint32 format, uint32 size, uint8 data[], uint32 frequency);
|
||||
void loadWav(GenoWavFile * wavFile);
|
||||
void loadWav(const char * path);
|
||||
uint32 getBuffer();
|
||||
~GenoAudioBuffer();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_AUDIO_BUFFER_FORWARD
|
||||
#endif // GNARLY_GENOME_AUDIO_BUFFER
|
108
src/geno/audio/GenoAudioDevice.cpp
Normal file
108
src/geno/audio/GenoAudioDevice.cpp
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
#include "GenoAudioDevice.h"
|
||||
|
||||
GenoAudioOutputDevice::GenoAudioOutputDevice(ALCdevice * device, const char * name) {
|
||||
this->device = device;
|
||||
context = alcCreateContext(device, 0);
|
||||
int32 nameLength = strlen(name);
|
||||
this->name = new char[nameLength + 1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
|
||||
void GenoAudioOutputDevice::setActive() {
|
||||
alcMakeContextCurrent(context);
|
||||
}
|
||||
|
||||
const char * GenoAudioOutputDevice::getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
GenoAudioOutputDevice::~GenoAudioOutputDevice() {
|
||||
alcDestroyContext(context);
|
||||
alcCloseDevice(device);
|
||||
}
|
||||
|
||||
int32 GenoAudioDevices::numOutputDevices = 0;
|
||||
GenoAudioOutputDevice ** GenoAudioDevices::outputDevices = 0;
|
||||
|
||||
void GenoAudioDevices::init() {
|
||||
bool enumOk = alcIsExtensionPresent(0, "ALC_ENUMERATION_EXT");
|
||||
if (enumOk) {
|
||||
numOutputDevices = 0;
|
||||
const char * devices = alcGetString(0, ALC_DEVICE_SPECIFIER);
|
||||
const char * loop = devices;
|
||||
while (*loop) {
|
||||
++numOutputDevices;
|
||||
loop += strlen(loop) + 1;
|
||||
}
|
||||
outputDevices = new GenoAudioOutputDevice*[numOutputDevices];
|
||||
loop = devices;
|
||||
for (int32 i = 0; i < numOutputDevices; ++i) {
|
||||
outputDevices[i] = new GenoAudioOutputDevice(alcOpenDevice(loop), loop);
|
||||
loop += strlen(loop) + 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ALCdevice * device = alcOpenDevice(0);
|
||||
if(device) {
|
||||
numOutputDevices = 1;
|
||||
outputDevices = new GenoAudioOutputDevice*[1] { new GenoAudioOutputDevice(device, alcGetString(device, ALC_DEVICE_SPECIFIER)) };
|
||||
}
|
||||
else {
|
||||
numOutputDevices = 0;
|
||||
outputDevices = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32 GenoAudioDevices::getNumOutputDevices() {
|
||||
return numOutputDevices;
|
||||
}
|
||||
|
||||
GenoAudioOutputDevice * GenoAudioDevices::getDefaultOutputDevice() {
|
||||
return outputDevices[0];
|
||||
}
|
||||
|
||||
GenoAudioOutputDevice * GenoAudioDevices::getOutputDevice(uint32 outputDevice) {
|
||||
if(outputDevice >= 0 && outputDevice < numOutputDevices)
|
||||
return outputDevices[outputDevice];
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GenoAudioDevices::cleanup() {
|
||||
for (int32 i = 0; i < numOutputDevices; ++i)
|
||||
delete outputDevices[i];
|
||||
delete [] outputDevices;
|
||||
}
|
||||
|
||||
GenoAudioDevices::GenoAudioDevices() {}
|
||||
GenoAudioDevices::~GenoAudioDevices() {}
|
68
src/geno/audio/GenoAudioDevice.h
Normal file
68
src/geno/audio/GenoAudioDevice.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_AUDIO_DEVICE
|
||||
#define GNARLY_GENOME_AUDIO_DEVICE
|
||||
|
||||
#include "../GenoInts.h"
|
||||
#include "GenoAL.h"
|
||||
#include "../engine/GenoEngine.h"
|
||||
|
||||
class GenoAudioOutputDevice {
|
||||
private:
|
||||
GenoAudioOutputDevice(ALCdevice * device, const char * name);
|
||||
ALCdevice * device;
|
||||
ALCcontext * context;
|
||||
char * name;
|
||||
|
||||
public:
|
||||
void setActive();
|
||||
const char * getName();
|
||||
~GenoAudioOutputDevice();
|
||||
|
||||
friend class GenoAudioDevices;
|
||||
};
|
||||
|
||||
class GenoAudioDevices final {
|
||||
private:
|
||||
static int32 numOutputDevices;
|
||||
static GenoAudioOutputDevice ** outputDevices;
|
||||
|
||||
GenoAudioDevices();
|
||||
~GenoAudioDevices();
|
||||
|
||||
static void init();
|
||||
static void cleanup();
|
||||
public:
|
||||
static uint32 getNumOutputDevices();
|
||||
static GenoAudioOutputDevice * getDefaultOutputDevice();
|
||||
static GenoAudioOutputDevice * getOutputDevice(uint32 outputDevice);
|
||||
|
||||
friend class GenoEngine;
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_AUDIO_DEVICE_FORWARD
|
||||
#endif // GNARLY_GENOME_AUDIO_DEVICE
|
70
src/geno/audio/GenoAudioSource.cpp
Normal file
70
src/geno/audio/GenoAudioSource.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <AL\al.h>
|
||||
|
||||
#include "GenoAudioSource.h"
|
||||
|
||||
GenoAudioSource::GenoAudioSource() {
|
||||
alGenSources(1, &source);
|
||||
alSourcef(source, AL_GAIN, 1);
|
||||
alSource3f(source, AL_POSITION, 0, 0, 0);
|
||||
alSource3f(source, AL_DIRECTION, 0, 0, 0);
|
||||
}
|
||||
|
||||
GenoAudioSource::GenoAudioSource(GenoAudioBuffer * buffer) {
|
||||
alGenSources(1, &source);
|
||||
alSourcef(source, AL_GAIN, 1);
|
||||
alSource3f(source, AL_POSITION, 0, 0, 0);
|
||||
alSource3f(source, AL_DIRECTION, 0, 0, 0);
|
||||
alSourcei(source, AL_BUFFER, buffer->getBuffer());
|
||||
}
|
||||
|
||||
void GenoAudioSource::setBuffer(GenoAudioBuffer * buffer) {
|
||||
alSourcei(source, AL_BUFFER, buffer->getBuffer());
|
||||
}
|
||||
|
||||
void GenoAudioSource::play() {
|
||||
alSourcePlay(source);
|
||||
}
|
||||
|
||||
void GenoAudioSource::stop() {
|
||||
alSourceStop(source);
|
||||
}
|
||||
|
||||
void GenoAudioSource::pause() {
|
||||
alSourcePause(source);
|
||||
}
|
||||
|
||||
void GenoAudioSource::loop(bool loop) {
|
||||
alSourcei(source, AL_LOOPING, loop);
|
||||
}
|
||||
|
||||
GenoAudioSource::~GenoAudioSource() {
|
||||
alDeleteSources(1, &source);
|
||||
}
|
49
src/geno/audio/GenoAudioSource.h
Normal file
49
src/geno/audio/GenoAudioSource.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_AUDIO_SOURCE
|
||||
#define GNARLY_GENOME_AUDIO_SOURCE
|
||||
|
||||
#include "../GenoInts.h"
|
||||
#include "GenoAudioBuffer.h"
|
||||
|
||||
class GenoAudioSource {
|
||||
private:
|
||||
uint32 source;
|
||||
|
||||
public:
|
||||
GenoAudioSource();
|
||||
GenoAudioSource(GenoAudioBuffer * buffer);
|
||||
void play();
|
||||
void pause();
|
||||
void stop();
|
||||
void setBuffer(GenoAudioBuffer * buffer);
|
||||
void loop(bool loop);
|
||||
~GenoAudioSource();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_AUDIO_SOURCE_FOWARD
|
||||
#endif // GNARLY_GENOME_AUDIO_SOURCE
|
73
src/geno/audio/GenoListener.cpp
Normal file
73
src/geno/audio/GenoListener.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "GenoAL.h"
|
||||
|
||||
#include "GenoListener.h"
|
||||
|
||||
GenoListener::GenoListener() :
|
||||
position(GenoVector3f()),
|
||||
velocity(GenoVector3f()),
|
||||
at(0, 0, -1),
|
||||
up(0, 1, 0),
|
||||
gain(1) {}
|
||||
|
||||
GenoListener::GenoListener(GenoVector3f position, GenoVector3f velocity, GenoVector3f at, GenoVector3f up, float gain) :
|
||||
position(position),
|
||||
velocity(velocity),
|
||||
at(at),
|
||||
up(up),
|
||||
gain(gain) {}
|
||||
|
||||
void GenoListener::setActive() {
|
||||
alListener3f(AL_POSITION, position.x(), position.y(), position.z());
|
||||
|
||||
alListener3f(AL_VELOCITY, velocity.x(), velocity.y(), velocity.z());
|
||||
|
||||
float orientation[] = { at.x(), at.y(), at.z(), up.x(), up.y(), up.z() };
|
||||
alListenerfv(AL_ORIENTATION, orientation);
|
||||
|
||||
alListenerf(AL_GAIN, gain);
|
||||
}
|
||||
|
||||
void GenoListener::setPosition(GenoVector3f position) {
|
||||
this->position = position;
|
||||
}
|
||||
|
||||
void GenoListener::setVelocity(GenoVector3f velocity) {
|
||||
this->velocity = velocity;
|
||||
}
|
||||
|
||||
void GenoListener::setOrientation(GenoVector3f at, GenoVector3f up) {
|
||||
this->at = at;
|
||||
this->up = up;
|
||||
}
|
||||
|
||||
void GenoListener::setGain(float gain) {
|
||||
this->gain = gain;
|
||||
}
|
||||
|
||||
GenoListener::~GenoListener() {}
|
49
src/geno/audio/GenoListener.h
Normal file
49
src/geno/audio/GenoListener.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_LISTENER
|
||||
#define GNARLY_GENOME_LISTENER
|
||||
|
||||
#include "../math/linear/GenoVector3.h"
|
||||
|
||||
class GenoListener {
|
||||
private:
|
||||
GenoVector3f position, velocity, at, up;
|
||||
float gain;
|
||||
|
||||
public:
|
||||
GenoListener();
|
||||
GenoListener(GenoVector3f position, GenoVector3f velocity, GenoVector3f at, GenoVector3f up, float gain);
|
||||
void setActive();
|
||||
void setPosition(GenoVector3f position);
|
||||
void setVelocity(GenoVector3f velocity);
|
||||
void setOrientation(GenoVector3f at, GenoVector3f up);
|
||||
void setGain(float gain);
|
||||
~GenoListener();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_LISTENER_FORWARD
|
||||
#endif // GNARLY_GENOME_LISTENER
|
208
src/geno/data/GenoImage.cpp
Normal file
208
src/geno/data/GenoImage.cpp
Normal file
|
@ -0,0 +1,208 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
|
||||
#include <PNG\png.h>
|
||||
|
||||
#include "GenoImage.h"
|
||||
|
||||
struct GenoBitmapFileHeader {
|
||||
uint16 signature;
|
||||
uint32 fileSize;
|
||||
uint16 res1;
|
||||
uint16 res2;
|
||||
uint32 offset;
|
||||
};
|
||||
|
||||
struct GenoBitmapInfoHeader {
|
||||
uint32 headerSize;
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
uint16 colorPlanes;
|
||||
uint16 bitsPerPixel;
|
||||
uint32 compression;
|
||||
uint32 imageSize;
|
||||
uint32 horzRes;
|
||||
uint32 vertRes;
|
||||
uint32 colorPerPalette;
|
||||
uint32 important;
|
||||
};
|
||||
|
||||
GenoImage::GenoImage() {}
|
||||
|
||||
GenoImage * GenoImage::create(const GenoImageCreateInfo & info) {
|
||||
uint32 width = 0;
|
||||
uint32 height = 0;
|
||||
uint8 * image = 0;
|
||||
switch (info.type) {
|
||||
case GENO_IMAGE_TYPE_CREATE: {
|
||||
width = info.width;
|
||||
height = info.height;
|
||||
uint64 size = width * height * 4;
|
||||
image = new uint8[size];
|
||||
for (int32 i = 0; i < size; i += 4) {
|
||||
image[i ] = info.r;
|
||||
image[i + 1] = info.g;
|
||||
image[i + 2] = info.b;
|
||||
image[i + 3] = info.a;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GENO_IMAGE_TYPE_BMP: {
|
||||
std::ifstream file(info.path, std::ios::binary);
|
||||
if (file) {
|
||||
GenoBitmapFileHeader fileHeader;
|
||||
file.read(reinterpret_cast<char *> (&fileHeader), sizeof(fileHeader));
|
||||
|
||||
if (fileHeader.signature == 0x4D42) {
|
||||
GenoBitmapInfoHeader infoHeader;
|
||||
file.read(reinterpret_cast<char *> (&infoHeader), sizeof(infoHeader));
|
||||
|
||||
|
||||
width = infoHeader.width;
|
||||
height = infoHeader.height;
|
||||
|
||||
image = new uint8[width * height * 4];
|
||||
|
||||
if (infoHeader.bitsPerPixel == 24 && infoHeader.compression == 0) {
|
||||
|
||||
uint8 padding = (4 - (width * 3) % 4) % 4;
|
||||
|
||||
file.seekg(fileHeader.offset);
|
||||
int32 lWidth = width * 4;
|
||||
int32 lHeight = height * 4;
|
||||
for (int32 i = lHeight - 4; i >= 0; i -= 4) {
|
||||
for (int32 j = 0; j < lWidth; j += 4) {
|
||||
int pixel = j * height + i;
|
||||
image[pixel + 3] = file.get();
|
||||
image[pixel + 2] = file.get();
|
||||
image[pixel + 1] = file.get();
|
||||
image[pixel ] = 0xFF;
|
||||
}
|
||||
file.seekg(padding, std::ios::cur);
|
||||
}
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
file.close();
|
||||
break;
|
||||
}
|
||||
case GENO_IMAGE_TYPE_PNG: {
|
||||
FILE * fp = fopen(info.path, "rb");
|
||||
|
||||
png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
|
||||
png_infop info = png_create_info_struct(png);
|
||||
|
||||
png_init_io(png, fp);
|
||||
|
||||
png_read_info(png, info);
|
||||
|
||||
width = png_get_image_width(png, info);
|
||||
height = png_get_image_height(png, info);
|
||||
png_byte colorType = png_get_color_type(png, info);
|
||||
png_byte bitDepth = png_get_bit_depth(png, info);
|
||||
|
||||
if (bitDepth == 16)
|
||||
png_set_strip_16(png);
|
||||
|
||||
if (colorType == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_palette_to_rgb(png);
|
||||
|
||||
if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8)
|
||||
png_set_expand_gray_1_2_4_to_8(png);
|
||||
|
||||
if (png_get_valid(png, info, PNG_INFO_tRNS))
|
||||
png_set_tRNS_to_alpha(png);
|
||||
|
||||
if (colorType == PNG_COLOR_TYPE_RGB || colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
|
||||
|
||||
if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb(png);
|
||||
|
||||
png_read_update_info(png, info);
|
||||
|
||||
png_bytep * rowPointers = (png_bytep *)malloc(sizeof(png_bytep) * height);
|
||||
for (int y = 0; y < height; y++)
|
||||
rowPointers[y] = (png_byte *) malloc(png_get_rowbytes(png, info));
|
||||
|
||||
png_read_image(png, rowPointers);
|
||||
|
||||
image = new uint8[width * height * 4];
|
||||
for (int j = 0; j < height; ++j) {
|
||||
png_bytep row = rowPointers[j];
|
||||
for (int i = 0; i < width; ++i) {
|
||||
uint32 pixel = i * 4 + j * width * 4;
|
||||
png_bytep px = row + (i * 4);
|
||||
image[pixel ] = px[0];
|
||||
image[pixel + 1] = px[1];
|
||||
image[pixel + 2] = px[2];
|
||||
image[pixel + 3] = px[3];
|
||||
}
|
||||
}
|
||||
|
||||
png_destroy_read_struct(&png, &info, NULL);
|
||||
fclose(fp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GenoImage * ret = new GenoImage();
|
||||
ret->width = width;
|
||||
ret->height = height;
|
||||
ret->image = image;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32 GenoImage::getWidth() const {
|
||||
return width;
|
||||
}
|
||||
|
||||
uint32 GenoImage::getHeight() const {
|
||||
return height;
|
||||
}
|
||||
|
||||
uint8 * GenoImage::getBytes() {
|
||||
return image;
|
||||
}
|
||||
|
||||
const uint8 * GenoImage::getBytes() const {
|
||||
return image;
|
||||
}
|
||||
|
||||
GenoImage::~GenoImage() {
|
||||
delete [] image;
|
||||
}
|
66
src/geno/data/GenoImage.h
Normal file
66
src/geno/data/GenoImage.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_IMAGE
|
||||
#define GNARLY_GENOME_IMAGE
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
#define GENO_IMAGE_TYPE_CREATE 0x00
|
||||
#define GENO_IMAGE_TYPE_PNG 0x01
|
||||
#define GENO_IMAGE_TYPE_BMP 0x02
|
||||
|
||||
struct GenoImageCreateInfo {
|
||||
uint32 type;
|
||||
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
uint8 r;
|
||||
uint8 g;
|
||||
uint8 b;
|
||||
uint8 a;
|
||||
|
||||
const char * path;
|
||||
};
|
||||
|
||||
class GenoImage {
|
||||
private:
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
uint8 * image;
|
||||
|
||||
GenoImage();
|
||||
public:
|
||||
static GenoImage * create(const GenoImageCreateInfo & info);
|
||||
uint32 getWidth() const;
|
||||
uint32 getHeight() const;
|
||||
uint8 * getBytes();
|
||||
const uint8 * getBytes() const;
|
||||
~GenoImage();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_IMAGE_FORWARD
|
||||
#endif // GNARLY_GENOME_IMAGE
|
87
src/geno/data/GenoWavFile.cpp
Normal file
87
src/geno/data/GenoWavFile.cpp
Normal file
|
@ -0,0 +1,87 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "../audio/GenoAL.h"
|
||||
|
||||
#include "GenoWavFile.h"
|
||||
|
||||
#pragma pack(2)
|
||||
|
||||
struct GenoWavFileHeader {
|
||||
uint32 signature;
|
||||
uint32 size;
|
||||
uint32 format;
|
||||
};
|
||||
|
||||
struct GenoWavFormatChunk {
|
||||
uint32 id;
|
||||
uint32 size;
|
||||
uint16 format;
|
||||
uint16 numChannels;
|
||||
uint32 sampleRate;
|
||||
uint32 byteRate;
|
||||
uint16 blockAlign;
|
||||
uint16 bitsPerSample;
|
||||
};
|
||||
|
||||
struct GenoWavSubChunk {
|
||||
uint32 id;
|
||||
uint32 size;
|
||||
};
|
||||
|
||||
GenoWavFile::GenoWavFile(const char * path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (file) {
|
||||
GenoWavFileHeader fileHeader;
|
||||
file.read(reinterpret_cast<char *>(&fileHeader), sizeof(fileHeader));
|
||||
|
||||
if (fileHeader.signature == 0x46464952 && !file.eof()) {
|
||||
GenoWavFormatChunk formatChunk;
|
||||
file.read(reinterpret_cast<char *>(&formatChunk), sizeof(formatChunk));
|
||||
|
||||
if (formatChunk.id == 0x20746d66 && !file.eof()) {
|
||||
GenoWavSubChunk subChunk = GenoWavSubChunk();
|
||||
subChunk.size = 0;
|
||||
do {
|
||||
file.ignore(subChunk.size);
|
||||
file.read(reinterpret_cast<char *>(&subChunk), sizeof(subChunk));
|
||||
} while (subChunk.id != 0x61746164 && !file.eof());
|
||||
if (!file.eof()) {
|
||||
data = new uint8[subChunk.size];
|
||||
file.read(reinterpret_cast<char *>(data), subChunk.size);
|
||||
if (!file.eof()) {
|
||||
size = subChunk.size;
|
||||
if (formatChunk.numChannels == 1)
|
||||
format = formatChunk.bitsPerSample == 8 ? AL_FORMAT_MONO8 : AL_FORMAT_MONO16;
|
||||
else
|
||||
format = formatChunk.bitsPerSample == 8 ? AL_FORMAT_STEREO8 : AL_FORMAT_STEREO16;
|
||||
sampleRate = formatChunk.sampleRate;
|
||||
}
|
||||
else
|
||||
delete [] data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
uint32 GenoWavFile::getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
uint32 GenoWavFile::getSampleRate() {
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
uint32 GenoWavFile::getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
uint8 * GenoWavFile::getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
GenoWavFile::~GenoWavFile() {
|
||||
delete [] data;
|
||||
}
|
21
src/geno/data/GenoWavFile.h
Normal file
21
src/geno/data/GenoWavFile.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef GNARLY_GENOME_WAVFILE
|
||||
#define GNARLY_GENOME_WAVFILE
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
class GenoWavFile {
|
||||
private:
|
||||
uint32 format, sampleRate, size;
|
||||
uint8 * data;
|
||||
|
||||
public:
|
||||
GenoWavFile(const char * path);
|
||||
uint32 getFormat();
|
||||
uint32 getSampleRate();
|
||||
uint32 getSize();
|
||||
uint8 * getData();
|
||||
~GenoWavFile();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_WAVFILE_FORWARD
|
||||
#endif // GNARLY_GENOME_WAVFILE
|
71
src/geno/engine/GenoCamera2D.cpp
Normal file
71
src/geno/engine/GenoCamera2D.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "GenoCamera2D.h"
|
||||
|
||||
GenoCamera2D::GenoCamera2D(float left, float right, float bottom, float top, float near, float far) :
|
||||
width(right - left),
|
||||
height(bottom - top),
|
||||
projection(GenoMatrix4f::makeOrthographic(left, right, bottom, top, near, far)),
|
||||
view(GenoMatrix4f::makeIdentity()),
|
||||
projectionView(projection),
|
||||
position(),
|
||||
rotation(0) {}
|
||||
|
||||
void GenoCamera2D::update() {
|
||||
view.setTranslateXY(-position).rotateZ(-rotation);
|
||||
projectionView = projection * view;
|
||||
}
|
||||
|
||||
void GenoCamera2D::setProjection(float left, float right, float bottom, float top, float near, float far) {
|
||||
projection.setOrthographic(left, right, bottom, top, near, far);
|
||||
}
|
||||
|
||||
GenoMatrix4f GenoCamera2D::getProjection() {
|
||||
return projection;
|
||||
}
|
||||
|
||||
GenoMatrix4f GenoCamera2D::getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
GenoMatrix4f GenoCamera2D::getVPMatrix() {
|
||||
return projectionView;
|
||||
}
|
||||
|
||||
float GenoCamera2D::getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
float GenoCamera2D::getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
GenoVector2f GenoCamera2D::getDimensions() {
|
||||
return { width, height };
|
||||
}
|
||||
|
||||
GenoCamera2D::~GenoCamera2D() {}
|
58
src/geno/engine/GenoCamera2D.h
Normal file
58
src/geno/engine/GenoCamera2D.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_CAMERA2D
|
||||
#define GNARLY_GENOME_CAMERA2D
|
||||
|
||||
#include "../math/linear/GenoVector2.h"
|
||||
#include "../math/linear/GenoMatrix4.h"
|
||||
|
||||
class GenoCamera2D {
|
||||
private:
|
||||
float width;
|
||||
float height;
|
||||
|
||||
GenoMatrix4f projection;
|
||||
GenoMatrix4f view;
|
||||
GenoMatrix4f projectionView;
|
||||
public:
|
||||
GenoVector2f position;
|
||||
float rotation;
|
||||
|
||||
GenoCamera2D(float left, float right, float bottom, float top, float near, float far);
|
||||
void update();
|
||||
void setProjection(float left, float right, float bottom, float top, float near, float far);
|
||||
GenoMatrix4f getProjection();
|
||||
GenoMatrix4f getView();
|
||||
GenoMatrix4f getVPMatrix();
|
||||
float getWidth();
|
||||
float getHeight();
|
||||
GenoVector2f getDimensions();
|
||||
~GenoCamera2D();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_CAMERA2D_FORWARD
|
||||
#endif // GNARLY_GENOME_CAMERA2D
|
127
src/geno/engine/GenoEngine.cpp
Normal file
127
src/geno/engine/GenoEngine.cpp
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "../gl/GenoGL.h"
|
||||
#include "GenoInput.h"
|
||||
#include "GenoMonitor.h"
|
||||
#include "../audio/GenoAudioDevice.h"
|
||||
|
||||
#include "GenoEngine.h"
|
||||
|
||||
namespace {
|
||||
void errorCallback(int32 code, const char * message);
|
||||
}
|
||||
|
||||
GenoLoopCallback GenoEngine::callback = 0;
|
||||
GenoLoop * GenoEngine::loop = 0;
|
||||
GenoEngine::GenoEventPollFunc GenoEngine::getEvents = 0;
|
||||
|
||||
void GenoEngine::defaultLoop() {
|
||||
GenoInput::update();
|
||||
GenoEngine::pollEvents();
|
||||
callback();
|
||||
}
|
||||
|
||||
bool GenoEngine::init() {
|
||||
glfwSetErrorCallback(errorCallback);
|
||||
|
||||
if (!glfwInit()) {
|
||||
std::cerr << "GL Framework failed to initialize!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
getEvents = glfwPollEvents;
|
||||
|
||||
GenoMonitors::init();
|
||||
GenoAudioDevices::init();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GenoEngine::initGlew() {
|
||||
if (glewInit() != GLEW_NO_ERROR) {
|
||||
std::cerr << "GL Extension Wrangler failed to initialize!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GenoEngine::setLoop(GenoLoopCreateInfo info, bool overrideDefault) {
|
||||
delete loop;
|
||||
|
||||
if (!overrideDefault) {
|
||||
callback = info.callback;
|
||||
info.callback = defaultLoop;
|
||||
}
|
||||
|
||||
loop = new GenoLoop(info);
|
||||
}
|
||||
|
||||
void GenoEngine::startLoop() {
|
||||
loop->start();
|
||||
}
|
||||
|
||||
void GenoEngine::stopLoop() {
|
||||
loop->stop();
|
||||
}
|
||||
|
||||
void GenoEngine::destroy() {
|
||||
stopLoop();
|
||||
delete loop;
|
||||
|
||||
GenoAudioDevices::cleanup();
|
||||
GenoMonitors::cleanup();
|
||||
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
void GenoEngine::setSwapInterval(uint8 swapInterval) {
|
||||
glfwSwapInterval(swapInterval);
|
||||
}
|
||||
|
||||
void GenoEngine::pollEvents() {
|
||||
getEvents();
|
||||
}
|
||||
|
||||
void GenoEngine::setPollFunc(bool pollFunc) {
|
||||
getEvents = pollFunc ? glfwPollEvents : glfwWaitEvents;
|
||||
}
|
||||
|
||||
GenoLoop * GenoEngine::getLoop() {
|
||||
return loop;
|
||||
}
|
||||
|
||||
GenoEngine::GenoEngine() {}
|
||||
GenoEngine::~GenoEngine() {}
|
||||
|
||||
namespace {
|
||||
void errorCallback(int32 code, const char * message) {
|
||||
std::cerr << "GLFW error " << code << ": " << message << std::endl;
|
||||
}
|
||||
}
|
122
src/geno/engine/GenoEngine.h
Normal file
122
src/geno/engine/GenoEngine.h
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_LOOP_FORWARD
|
||||
#define GNARLY_GENOME_LOOP_FORWARD
|
||||
|
||||
class GenoLoop;
|
||||
|
||||
#endif // GNARLY_GENOME_LOOP_FORWARD
|
||||
|
||||
#ifndef GNARLY_GENOME_ENGINE
|
||||
#define GNARLY_GENOME_ENGINE
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
#include "GenoLoop.h"
|
||||
|
||||
#define GENO_ENGINE_EVENTS_WAIT false
|
||||
#define GENO_ENGINE_EVENTS_POLL true
|
||||
|
||||
/**
|
||||
* The engine
|
||||
**/
|
||||
class GenoEngine final {
|
||||
private:
|
||||
typedef void (*GenoEventPollFunc)();
|
||||
|
||||
static GenoLoopCallback callback;
|
||||
static GenoLoop * loop;
|
||||
static GenoEventPollFunc getEvents;
|
||||
|
||||
static void defaultLoop();
|
||||
|
||||
GenoEngine();
|
||||
~GenoEngine();
|
||||
public:
|
||||
|
||||
////// PROGRAM FLOW CONTROL METHODS //////
|
||||
|
||||
/**
|
||||
* Initializes the engine
|
||||
**/
|
||||
static bool init();
|
||||
|
||||
/**
|
||||
* Initializes glew
|
||||
**/
|
||||
static bool initGlew();
|
||||
|
||||
/**
|
||||
* Sets the parameters for the loop. Can either override the default loop or run in conjunction with it
|
||||
*
|
||||
* @param info - The loop info struct
|
||||
* @param overrideDefault - Whether or not to override the default loop
|
||||
**/
|
||||
static void setLoop(GenoLoopCreateInfo info, bool overrideDefault = false);
|
||||
|
||||
/**
|
||||
* Starts the loop
|
||||
**/
|
||||
static void startLoop();
|
||||
|
||||
/**
|
||||
* Stops the loop
|
||||
**/
|
||||
static void stopLoop();
|
||||
|
||||
/**
|
||||
* Destroys the engine
|
||||
**/
|
||||
static void destroy();
|
||||
|
||||
////// UTILITY METHODS //////
|
||||
|
||||
/**
|
||||
* Enables or disabled vsync. Sets the ratio between monitor refresh rate and buffer swap rate.
|
||||
**/
|
||||
static void setSwapInterval(uint8 interval);
|
||||
|
||||
/**
|
||||
* Polls events (e.g. keyboard, mouse, window changes)
|
||||
*
|
||||
* Calls the currently set getEvent func, either glfwPollEvents() or glfwWaitEvents()
|
||||
**/
|
||||
static void pollEvents();
|
||||
|
||||
/**
|
||||
* Sets the event polling function
|
||||
**/
|
||||
static void setPollFunc(bool pollFunc);
|
||||
|
||||
/**
|
||||
* Returns the game loop
|
||||
**/
|
||||
static GenoLoop * getLoop();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_ENGINE_FORWARD
|
||||
#endif // GNARLY_GENOME_ENGINE
|
142
src/geno/engine/GenoInput.cpp
Normal file
142
src/geno/engine/GenoInput.cpp
Normal file
|
@ -0,0 +1,142 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "GenoEngine.h"
|
||||
#include "../gl/GenoFramebuffer.h"
|
||||
|
||||
#include "GenoInput.h"
|
||||
|
||||
double GenoInput::repeatDelay = GENO_INPUT_DEFAULT_DELAY;
|
||||
double GenoInput::repeatSpeed = GENO_INPUT_DEFAULT_SPEED;
|
||||
|
||||
uint8 GenoInput::keyStates[GLFW_KEY_LAST];
|
||||
double GenoInput::keyTimes[GLFW_KEY_LAST];
|
||||
double GenoInput::keyTargets[GLFW_KEY_LAST];
|
||||
|
||||
uint8 GenoInput::mouseButtonStates[GLFW_MOUSE_BUTTON_LAST];
|
||||
double GenoInput::mouseButtonTimes[GLFW_MOUSE_BUTTON_LAST];
|
||||
double GenoInput::mouseButtonTargets[GLFW_MOUSE_BUTTON_LAST];
|
||||
|
||||
GenoVector2d GenoInput::mouseCoords = {};
|
||||
|
||||
void GenoInput::update() {
|
||||
double delta = GenoEngine::getLoop()->getDelta();
|
||||
for (uint32 i = 0; i < GLFW_KEY_LAST; ++i) {
|
||||
if (keyStates[i] > GENO_INPUT_UNPRESSED)
|
||||
keyTimes[i] += delta;
|
||||
if (keyStates[i] == GENO_INPUT_RELEASED || keyStates[i] == GENO_INPUT_PRESSED)
|
||||
++keyStates[i];
|
||||
if (keyStates[i] == GENO_INPUT_REPEATED)
|
||||
keyStates[i] = GENO_INPUT_HELD;
|
||||
if (keyStates[i] == GENO_INPUT_HELD && keyTimes[i] >= keyTargets[i]) {
|
||||
keyStates[i] = GENO_INPUT_REPEATED;
|
||||
keyTargets[i] += repeatSpeed;
|
||||
}
|
||||
}
|
||||
for (uint32 i = 0; i < GLFW_MOUSE_BUTTON_LAST; ++i) {
|
||||
if (mouseButtonStates[i] > GENO_INPUT_UNPRESSED)
|
||||
mouseButtonTimes[i] += delta;
|
||||
if (mouseButtonStates[i] == GENO_INPUT_RELEASED || mouseButtonStates[i] == GENO_INPUT_PRESSED)
|
||||
++mouseButtonStates[i];
|
||||
if (mouseButtonStates[i] == GENO_INPUT_REPEATED)
|
||||
mouseButtonStates[i] = GENO_INPUT_HELD;
|
||||
if (mouseButtonStates[i] == GENO_INPUT_HELD && mouseButtonTimes[i] >= mouseButtonTargets[i]) {
|
||||
mouseButtonStates[i] = GENO_INPUT_REPEATED;
|
||||
mouseButtonTargets[i] += repeatSpeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GenoInput::setRepeatSpeed(double speed) {
|
||||
GenoInput::repeatSpeed = speed;
|
||||
}
|
||||
|
||||
void GenoInput::setRepeatDelay(double delay) {
|
||||
GenoInput::repeatDelay = delay;
|
||||
}
|
||||
|
||||
void GenoInput::setRepeat(double delay, double speed) {
|
||||
GenoInput::repeatDelay = delay;
|
||||
GenoInput::repeatSpeed = speed;
|
||||
}
|
||||
|
||||
uint8 GenoInput::getKeyState(uint16 key) {
|
||||
return keyStates[key];
|
||||
}
|
||||
|
||||
double GenoInput::getKeyDuration(uint16 key) {
|
||||
return keyTimes[key];
|
||||
}
|
||||
|
||||
uint8 GenoInput::getMouseButtonState(uint8 key) {
|
||||
return mouseButtonStates[key];
|
||||
}
|
||||
|
||||
double GenoInput::getMouseButtonDuration(uint8 key) {
|
||||
return mouseButtonTimes[key];
|
||||
}
|
||||
|
||||
GenoVector2d GenoInput::getRawMouseCoords() {
|
||||
return mouseCoords;
|
||||
}
|
||||
|
||||
GenoVector2f GenoInput::getMouseCoords(GenoCamera2D * camera) {
|
||||
return (GenoVector2f) mouseCoords / GenoVector2f(GenoFramebuffer::getCurrentWidth(), GenoFramebuffer::getCurrentHeight()) * camera->getDimensions() + camera->position;
|
||||
}
|
||||
|
||||
GenoInput::GenoInput() {}
|
||||
GenoInput::~GenoInput() {}
|
||||
|
||||
////// CALLBACKS //////
|
||||
|
||||
void GenoInput::keyCallback(GLFWwindow * window, int32 key, int32 scancode, int32 action, int32 mods) {
|
||||
if (key != GLFW_KEY_UNKNOWN) {
|
||||
if (action == GLFW_PRESS)
|
||||
keyStates[key] = GENO_INPUT_PRESSED;
|
||||
else if (action == GLFW_RELEASE) {
|
||||
keyStates[key] = GENO_INPUT_RELEASED;
|
||||
keyTimes[key] = 0;
|
||||
keyTargets[key] = repeatDelay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GenoInput::mouseButtonCallback(GLFWwindow * window, int32 button, int32 action, int32 mods) {
|
||||
if (button != GLFW_KEY_UNKNOWN) {
|
||||
if (action == GLFW_PRESS)
|
||||
mouseButtonStates[button] = GENO_INPUT_PRESSED;
|
||||
else if (action == GLFW_RELEASE) {
|
||||
mouseButtonStates[button] = GENO_INPUT_RELEASED;
|
||||
mouseButtonTimes[button] = 0;
|
||||
mouseButtonTargets[button] = repeatDelay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GenoInput::cursorPositionCallback(GLFWwindow * window, double x, double y) {
|
||||
mouseCoords.v[0] = x;
|
||||
mouseCoords.v[1] = y;
|
||||
}
|
88
src/geno/engine/GenoInput.h
Normal file
88
src/geno/engine/GenoInput.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_INPUT
|
||||
#define GNARLY_GENOME_INPUT
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
#include "../gl/GenoGL.h"
|
||||
#include "../math/linear/GenoVector2.h"
|
||||
#include "../engine/GenoCamera2D.h"
|
||||
|
||||
#define GENO_INPUT_RELEASED 0x00
|
||||
#define GENO_INPUT_UNPRESSED 0x01
|
||||
#define GENO_INPUT_PRESSED 0x02
|
||||
#define GENO_INPUT_HELD 0x03
|
||||
#define GENO_INPUT_REPEATED 0x04
|
||||
|
||||
#define GENO_INPUT_DEFAULT_DELAY 0.3
|
||||
#define GENO_INPUT_DEFAULT_SPEED 0.05
|
||||
|
||||
class GenoInput final {
|
||||
private:
|
||||
GenoInput();
|
||||
~GenoInput();
|
||||
|
||||
static double repeatDelay;
|
||||
static double repeatSpeed;
|
||||
|
||||
static uint8 keyStates[GLFW_KEY_LAST];
|
||||
static double keyTimes[GLFW_KEY_LAST];
|
||||
static double keyTargets[GLFW_KEY_LAST];
|
||||
|
||||
static uint8 mouseButtonStates[GLFW_MOUSE_BUTTON_LAST];
|
||||
static double mouseButtonTimes[GLFW_MOUSE_BUTTON_LAST];
|
||||
static double mouseButtonTargets[GLFW_MOUSE_BUTTON_LAST];
|
||||
|
||||
static GenoVector2d mouseCoords;
|
||||
|
||||
////// CALLBACKS //////
|
||||
|
||||
static void cursorPositionCallback(GLFWwindow * window, double x, double y);
|
||||
static void keyCallback(GLFWwindow * window, int32 key, int32 scancode, int32 action, int32 mods);
|
||||
static void mouseButtonCallback(GLFWwindow * window, int32 button, int32 action, int32 mods);
|
||||
public:
|
||||
static void update();
|
||||
|
||||
static void setRepeatDelay(double delay);
|
||||
static void setRepeatSpeed(double speed);
|
||||
static void setRepeat(double delay, double speed);
|
||||
|
||||
static uint8 getKeyState(uint16 key);
|
||||
static double getKeyDuration(uint16 key);
|
||||
|
||||
static uint8 getMouseButtonState(uint8 mouseButton);
|
||||
static double getMouseButtonDuration(uint8 mouseButton);
|
||||
|
||||
static GenoVector2d getRawMouseCoords();
|
||||
static GenoVector2f getMouseCoords(GenoCamera2D * camera);
|
||||
|
||||
friend class GenoWindow;
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_INPUT_FORWARD
|
||||
#endif // GNARLY_GENOME_INPUT
|
133
src/geno/engine/GenoLoop.cpp
Normal file
133
src/geno/engine/GenoLoop.cpp
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "../thread/GenoTime.h"
|
||||
|
||||
#include "GenoLoop.h"
|
||||
|
||||
GenoLoop::GenoLoop(const GenoLoopCreateInfo & info) :
|
||||
sanicLoop(false),
|
||||
callbackCount(1 + info.numSubLoops),
|
||||
looping(false),
|
||||
deltas(new double[callbackCount]),
|
||||
deltaScales(new double[callbackCount]),
|
||||
fps(new uint32[callbackCount]),
|
||||
millisPerFrames(new double[callbackCount]),
|
||||
callbacks(new GenoLoopCallback[callbackCount]) {
|
||||
|
||||
fps[0] = 0;
|
||||
deltas[0] = 0;
|
||||
deltaScales[0] = info.deltaScale;
|
||||
if (info.targetFps != 0)
|
||||
millisPerFrames[0] = 1000 / info.targetFps;
|
||||
else {
|
||||
sanicLoop = true;
|
||||
millisPerFrames[0] = 0;
|
||||
}
|
||||
callbacks[0] = info.callback;
|
||||
|
||||
for (uint32 i = 1; i < callbackCount; ++i) {
|
||||
fps[i] = 0;
|
||||
deltas[i] = 0;
|
||||
deltaScales[i] = info.subLoops[i - 1].deltaScale;
|
||||
if (info.subLoops[i - 1].targetFps != 0)
|
||||
millisPerFrames[i] = 1000 / info.subLoops[i - 1].targetFps;
|
||||
else
|
||||
millisPerFrames[i] = 0;
|
||||
callbacks[i] = info.subLoops[i - 1].callback;
|
||||
}
|
||||
}
|
||||
|
||||
void GenoLoop::start() {
|
||||
uint32 * frames = new uint32[callbackCount];
|
||||
double * pastTimes = new double[callbackCount + 1];
|
||||
double * truePastTimes = new double[callbackCount + 1];
|
||||
double curTime = 0;
|
||||
|
||||
for (uint32 i = 0; i < callbackCount; ++i) {
|
||||
frames[i] = 0;
|
||||
pastTimes[i] = GenoTime::getTime(milliseconds);
|
||||
}
|
||||
pastTimes[callbackCount] = GenoTime::getTime(milliseconds);
|
||||
|
||||
looping = true;
|
||||
while (looping) {
|
||||
curTime = GenoTime::getTime(milliseconds);
|
||||
if (curTime - pastTimes[0] > 1000) {
|
||||
for (uint32 i = 0; i < callbackCount; ++i) {
|
||||
fps[i] = frames[i];
|
||||
frames[i] = 0;
|
||||
}
|
||||
pastTimes[0] += 1000;
|
||||
}
|
||||
for (uint32 i = 0; i < callbackCount; ++i) {
|
||||
if (curTime - pastTimes[i + 1] >= millisPerFrames[i]) {
|
||||
callbacks[i]();
|
||||
deltas[i] = (curTime - truePastTimes[i + 1]) * deltaScales[i];
|
||||
pastTimes[i + 1] += millisPerFrames[i];
|
||||
truePastTimes[i + 1] = curTime;
|
||||
++frames[i];
|
||||
}
|
||||
}
|
||||
if (!sanicLoop)
|
||||
GenoTime::sleepUntil(pastTimes[1] + millisPerFrames[0]);
|
||||
}
|
||||
|
||||
delete [] truePastTimes;
|
||||
delete [] pastTimes;
|
||||
delete [] frames;
|
||||
}
|
||||
|
||||
void GenoLoop::stop() {
|
||||
looping = false;
|
||||
}
|
||||
|
||||
double GenoLoop::getDelta(uint32 loopIndex) {
|
||||
return deltas[loopIndex];
|
||||
}
|
||||
|
||||
uint32 GenoLoop::getFPS(uint32 loopIndex) {
|
||||
return fps[loopIndex];
|
||||
}
|
||||
|
||||
void GenoLoop::setFPS(double fps, uint32 loopIndex) {
|
||||
millisPerFrames[loopIndex] = 1000 / fps;
|
||||
}
|
||||
|
||||
void GenoLoop::setDeltaScale(double deltaScale, uint32 loopIndex) {
|
||||
deltaScales[loopIndex] = deltaScale;
|
||||
}
|
||||
|
||||
void GenoLoop::setCallback(GenoLoopCallback callback, uint32 loopIndex) {
|
||||
callbacks[loopIndex] = callback;
|
||||
}
|
||||
|
||||
GenoLoop::~GenoLoop() {
|
||||
delete [] deltas;
|
||||
delete [] deltaScales;
|
||||
delete [] millisPerFrames;
|
||||
delete [] callbacks;
|
||||
}
|
82
src/geno/engine/GenoLoop.h
Normal file
82
src/geno/engine/GenoLoop.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_LOOP
|
||||
#define GNARLY_GENOME_LOOP
|
||||
|
||||
// bröther may I have some lööps
|
||||
//
|
||||
// ^..---..^
|
||||
// / @ v @ \
|
||||
// / ^ \
|
||||
// . .
|
||||
// || | | ||
|
||||
// '|_| |_|'
|
||||
// \ /
|
||||
// \_|_____|_/
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
typedef void (*GenoLoopCallback)();
|
||||
|
||||
struct GenoSubLoopCreateInfo {
|
||||
double targetFps;
|
||||
double deltaScale;
|
||||
GenoLoopCallback callback;
|
||||
};
|
||||
|
||||
struct GenoLoopCreateInfo {
|
||||
double targetFps;
|
||||
double deltaScale;
|
||||
GenoLoopCallback callback;
|
||||
uint32 numSubLoops;
|
||||
GenoSubLoopCreateInfo * subLoops;
|
||||
};
|
||||
|
||||
class GenoLoop {
|
||||
private:
|
||||
bool sanicLoop;
|
||||
uint32 callbackCount;
|
||||
bool looping;
|
||||
uint32 * fps;
|
||||
double * deltas;
|
||||
double * deltaScales;
|
||||
double * millisPerFrames;
|
||||
GenoLoopCallback * callbacks;
|
||||
public:
|
||||
GenoLoop(const GenoLoopCreateInfo & info);
|
||||
void start();
|
||||
void stop();
|
||||
double getDelta(uint32 loopIndex = 0);
|
||||
uint32 getFPS(uint32 loopIndex = 0);
|
||||
void setFPS(double fps, uint32 loopIndex = 0);
|
||||
void setDeltaScale(double scale, uint32 loopIndex = 0);
|
||||
void setCallback(GenoLoopCallback callback, uint32 loopIndex = 0);
|
||||
~GenoLoop();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_LOOP_FORWARD
|
||||
#endif // GNARLY_GENOME_LOOP
|
227
src/geno/engine/GenoMonitor.cpp
Normal file
227
src/geno/engine/GenoMonitor.cpp
Normal file
|
@ -0,0 +1,227 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "GenoMonitor.h"
|
||||
|
||||
GenoVideoMode::GenoVideoMode(const GLFWvidmode & videoMode) :
|
||||
width(videoMode.width),
|
||||
height(videoMode.height),
|
||||
redBits(videoMode.redBits),
|
||||
greenBits(videoMode.greenBits),
|
||||
blueBits(videoMode.blueBits),
|
||||
refreshRate(videoMode.refreshRate) {}
|
||||
|
||||
int32 GenoVideoMode::getWidth() const {
|
||||
return width;
|
||||
}
|
||||
|
||||
int32 GenoVideoMode::getHeight() const {
|
||||
return height;
|
||||
}
|
||||
|
||||
GenoVector2i GenoVideoMode::getDimensions() const {
|
||||
return { width, height };
|
||||
}
|
||||
|
||||
int32 GenoVideoMode::getRedBits() const {
|
||||
return redBits;
|
||||
}
|
||||
|
||||
int32 GenoVideoMode::getGreenBits() const {
|
||||
return greenBits;
|
||||
}
|
||||
|
||||
int32 GenoVideoMode::getBlueBits() const {
|
||||
return blueBits;
|
||||
}
|
||||
|
||||
GenoVector3i GenoVideoMode::getBitDepth() const {
|
||||
return { redBits, greenBits, blueBits };
|
||||
}
|
||||
|
||||
int32 GenoVideoMode::getRefreshRate() const {
|
||||
return refreshRate;
|
||||
}
|
||||
|
||||
GenoVideoMode::~GenoVideoMode() {}
|
||||
|
||||
GenoMonitor::GenoMonitor(GLFWmonitor * monitor) :
|
||||
monitor(monitor) {
|
||||
int32 count;
|
||||
const GLFWvidmode * vidmodes = glfwGetVideoModes(monitor, &count);
|
||||
numVideoModes = count;
|
||||
videoModes = new GenoVideoMode*[numVideoModes];
|
||||
for (uint32 i = 0; i < count; ++i)
|
||||
videoModes[i] = new GenoVideoMode(vidmodes[i]);
|
||||
|
||||
GenoVideoMode * videoMode = videoModes[numVideoModes - 1];
|
||||
width = videoMode->getWidth();
|
||||
height = videoMode->getHeight();
|
||||
glfwGetMonitorPos(monitor, &x, &y);
|
||||
int32 physicalWidth;
|
||||
int32 physicalHeight;
|
||||
glfwGetMonitorPhysicalSize(monitor, &physicalWidth, &physicalHeight);
|
||||
sizeX = physicalWidth;
|
||||
sizeY = physicalHeight;
|
||||
name = glfwGetMonitorName(monitor);
|
||||
}
|
||||
|
||||
int32 GenoMonitor::getX() const {
|
||||
return x;
|
||||
}
|
||||
|
||||
int32 GenoMonitor::getY() const {
|
||||
return y;
|
||||
}
|
||||
|
||||
GenoVector2i GenoMonitor::getPosition() const {
|
||||
return { x, y };
|
||||
}
|
||||
|
||||
int32 GenoMonitor::getWidth() const {
|
||||
return width;
|
||||
}
|
||||
|
||||
int32 GenoMonitor::getHeight() const {
|
||||
return height;
|
||||
}
|
||||
|
||||
GenoVector2i GenoMonitor::getDimensions() const {
|
||||
return { width, height };
|
||||
}
|
||||
|
||||
double GenoMonitor::getPhysicalWidth(double scale) const {
|
||||
return sizeX / scale;
|
||||
}
|
||||
|
||||
double GenoMonitor::getPhysicalHeight(double scale) const {
|
||||
return sizeY / scale;
|
||||
}
|
||||
|
||||
GenoVector2d GenoMonitor::getPhysicalDimensions(double scale) const {
|
||||
return { sizeX / scale, sizeY / scale };
|
||||
}
|
||||
|
||||
double GenoMonitor::getPhysicalDiagonal(double scale) const {
|
||||
return sqrt(sizeX * sizeX + sizeY * sizeY) / scale;
|
||||
}
|
||||
const char * GenoMonitor::getName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
uint32 GenoMonitor::getNumVideoModes() const {
|
||||
return numVideoModes;
|
||||
}
|
||||
|
||||
GenoVideoMode * GenoMonitor::getDefaultVideoMode() const {
|
||||
return videoModes[numVideoModes - 1];
|
||||
}
|
||||
|
||||
GenoVideoMode * GenoMonitor::getVideoMode(uint32 num) const {
|
||||
return videoModes[num];
|
||||
}
|
||||
|
||||
GenoMonitor::~GenoMonitor() {
|
||||
for (uint32 i = 0; i < numVideoModes; ++i)
|
||||
delete videoModes[i];
|
||||
delete [] videoModes;
|
||||
}
|
||||
|
||||
uint32 GenoMonitors::numMonitors = 0;
|
||||
GenoMonitor ** GenoMonitors::monitors = 0;
|
||||
|
||||
uint32 GenoMonitors::getNumMonitors() {
|
||||
return numMonitors;
|
||||
}
|
||||
|
||||
void GenoMonitors::init() {
|
||||
int32 count;
|
||||
GLFWmonitor ** glfwMonitors = glfwGetMonitors(&count);
|
||||
numMonitors = count;
|
||||
|
||||
monitors = new GenoMonitor*[numMonitors];
|
||||
|
||||
for (uint32 i = 0; i < numMonitors; ++i)
|
||||
monitors[i] = new GenoMonitor(glfwMonitors[i]);
|
||||
|
||||
glfwSetMonitorCallback(monitorCallback);
|
||||
}
|
||||
|
||||
GenoMonitor * GenoMonitors::getPrimaryMonitor() {
|
||||
return monitors[0];
|
||||
}
|
||||
|
||||
GenoMonitor * GenoMonitors::getMonitor(uint32 num) {
|
||||
return monitors[num];
|
||||
}
|
||||
|
||||
void GenoMonitors::cleanup() {
|
||||
for (uint32 i = 0; i < numMonitors; ++i)
|
||||
delete monitors[i];
|
||||
delete [] monitors;
|
||||
}
|
||||
|
||||
void GenoMonitors::monitorCallback(GLFWmonitor * monitor, int32 event) {
|
||||
if (event == GLFW_DISCONNECTED) {
|
||||
bool found = false;
|
||||
for (uint32 i = 0; i < numMonitors - 1; ++i) {
|
||||
if (found)
|
||||
monitors[i] = monitors[i + 1];
|
||||
else if (monitors[i]->monitor == monitor) {
|
||||
delete monitors[i];
|
||||
monitors[i] = monitors[i + 1];
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
delete monitors[numMonitors - 1];
|
||||
}
|
||||
else {
|
||||
GenoMonitor * gMonitor = new GenoMonitor(monitor);
|
||||
|
||||
GenoMonitor ** target = new GenoMonitor*[++numMonitors];
|
||||
|
||||
int32 count;
|
||||
GLFWmonitor ** monitors = glfwGetMonitors(&count);
|
||||
|
||||
for (uint32 i = 0; i < count; ++i) {
|
||||
bool found = false;
|
||||
for (uint32 j = 0; j < numMonitors - 1; ++j) {
|
||||
if (GenoMonitors::monitors[j]->monitor == monitors[i]) {
|
||||
found = true;
|
||||
target[i] = GenoMonitors::monitors[j];
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
target[i] = gMonitor;
|
||||
}
|
||||
|
||||
delete [] GenoMonitors::monitors;
|
||||
GenoMonitors::monitors = target;
|
||||
}
|
||||
}
|
||||
|
||||
GenoMonitors::GenoMonitors() {}
|
||||
GenoMonitors::~GenoMonitors() {}
|
131
src/geno/engine/GenoMonitor.h
Normal file
131
src/geno/engine/GenoMonitor.h
Normal file
|
@ -0,0 +1,131 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_MONITOR
|
||||
#define GNARLY_GENOME_MONITOR
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
#include "../math/linear/GenoVector2.h"
|
||||
#include "../math/linear/GenoVector3.h"
|
||||
#include "../gl/GenoGL.h"
|
||||
|
||||
#define GENO_MONITOR_SCALE_MILLIMETERS 1.0
|
||||
#define GENO_MONITOR_SCALE_CENTIMETERS 10.0
|
||||
#define GENO_MONITOR_SCALE_INCHES 25.4
|
||||
#define GENO_MONITOR_SCALE_FEET 304.8
|
||||
|
||||
class GenoVideoMode final {
|
||||
private:
|
||||
int32 width;
|
||||
int32 height;
|
||||
int32 redBits;
|
||||
int32 greenBits;
|
||||
int32 blueBits;
|
||||
int32 refreshRate;
|
||||
|
||||
GenoVideoMode(const GLFWvidmode & videoMode);
|
||||
~GenoVideoMode();
|
||||
public:
|
||||
int32 getWidth() const;
|
||||
int32 getHeight() const;
|
||||
GenoVector2i getDimensions() const;
|
||||
|
||||
int32 getRedBits() const;
|
||||
int32 getGreenBits() const;
|
||||
int32 getBlueBits() const;
|
||||
GenoVector3i getBitDepth() const;
|
||||
|
||||
int32 getRefreshRate() const;
|
||||
|
||||
friend class GenoMonitor;
|
||||
};
|
||||
|
||||
class GenoMonitor final {
|
||||
private:
|
||||
GLFWmonitor * monitor;
|
||||
|
||||
uint32 numVideoModes;
|
||||
GenoVideoMode ** videoModes;
|
||||
|
||||
int32 x;
|
||||
int32 y;
|
||||
int32 width;
|
||||
int32 height;
|
||||
double sizeX;
|
||||
double sizeY;
|
||||
const char * name;
|
||||
|
||||
GenoMonitor(GLFWmonitor * monitor);
|
||||
~GenoMonitor();
|
||||
public:
|
||||
int32 getX() const;
|
||||
int32 getY() const;
|
||||
GenoVector2i getPosition() const;
|
||||
|
||||
int32 getWidth() const;
|
||||
int32 getHeight() const;
|
||||
GenoVector2i getDimensions() const;
|
||||
|
||||
double getPhysicalWidth(double scale = GENO_MONITOR_SCALE_INCHES) const;
|
||||
double getPhysicalHeight(double scale = GENO_MONITOR_SCALE_INCHES) const;
|
||||
GenoVector2d getPhysicalDimensions(double scale = GENO_MONITOR_SCALE_INCHES) const;
|
||||
double getPhysicalDiagonal(double scale = GENO_MONITOR_SCALE_INCHES) const;
|
||||
|
||||
const char * getName() const;
|
||||
|
||||
uint32 getNumVideoModes() const;
|
||||
GenoVideoMode * getDefaultVideoMode() const;
|
||||
GenoVideoMode * getVideoMode(uint32 num) const;
|
||||
|
||||
friend class GenoMonitors;
|
||||
friend class GenoWindow;
|
||||
};
|
||||
|
||||
class GenoMonitors final {
|
||||
private:
|
||||
static uint32 numMonitors;
|
||||
static GenoMonitor ** monitors;
|
||||
|
||||
GenoMonitors();
|
||||
~GenoMonitors();
|
||||
|
||||
static void init();
|
||||
static void cleanup();
|
||||
|
||||
////// Callbacks //////
|
||||
|
||||
static void monitorCallback(GLFWmonitor * monitor, int32 event);
|
||||
public:
|
||||
static uint32 getNumMonitors();
|
||||
static GenoMonitor * getPrimaryMonitor();
|
||||
static GenoMonitor * getMonitor(uint32 num);
|
||||
|
||||
friend class GenoEngine;
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_MONITOR_FORWARD
|
||||
#endif // GNARLY_GENOME_MONITOR
|
300
src/geno/engine/GenoWindow.cpp
Normal file
300
src/geno/engine/GenoWindow.cpp
Normal file
|
@ -0,0 +1,300 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "GenoInput.h"
|
||||
|
||||
#include "GenoWindow.h"
|
||||
|
||||
GenoWindow::GenoWindow() {}
|
||||
|
||||
GenoWindow * GenoWindow::create(const GenoWindowCreateInfo & info) {
|
||||
GenoWindow * ret = new GenoWindow();
|
||||
|
||||
bool visible = true;
|
||||
for (uint32 i = 0; i < info.numHints; ++i) {
|
||||
uint32 index = i * 2;
|
||||
if (info.hints[index] == GLFW_VISIBLE)
|
||||
visible = info.hints[index + 1];
|
||||
else
|
||||
glfwWindowHint(info.hints[index], info.hints[index + 1]);
|
||||
}
|
||||
glfwWindowHint(GLFW_VISIBLE, false);
|
||||
|
||||
GenoMonitor * monitor = info.monitor;
|
||||
GenoVideoMode * vidMode = info.videoMode;
|
||||
|
||||
if (monitor == 0)
|
||||
monitor = GenoMonitors::getPrimaryMonitor();
|
||||
|
||||
int32 width = info.width;
|
||||
int32 height = info.height;
|
||||
if (width == 0)
|
||||
width = monitor->getWidth() * 0.5;
|
||||
if (height == 0)
|
||||
height = monitor->getHeight() * 0.5;
|
||||
if (info.fullscreen) {
|
||||
if (vidMode == 0)
|
||||
vidMode = monitor->getDefaultVideoMode();
|
||||
|
||||
glfwWindowHint(GLFW_RED_BITS, vidMode->getRedBits());
|
||||
glfwWindowHint(GLFW_GREEN_BITS, vidMode->getGreenBits());
|
||||
glfwWindowHint(GLFW_BLUE_BITS, vidMode->getBlueBits());
|
||||
glfwWindowHint(GLFW_REFRESH_RATE, vidMode->getRefreshRate());
|
||||
}
|
||||
|
||||
GLFWwindow * window;
|
||||
window = glfwCreateWindow(width, height, info.title, 0, 0);
|
||||
|
||||
if (window == 0) {
|
||||
delete ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 x = 0;
|
||||
int32 y = 0;
|
||||
if (info.defaultPosition) {
|
||||
glfwGetWindowPos(window, &x, &y);
|
||||
double rx = (double) x / (double) GenoMonitors::getPrimaryMonitor()->getWidth();
|
||||
double ry = (double) y / (double) GenoMonitors::getPrimaryMonitor()->getHeight();
|
||||
x = rx * monitor->getWidth();
|
||||
y = ry * monitor->getHeight();
|
||||
glfwSetWindowPos(window, x, y);
|
||||
}
|
||||
else
|
||||
glfwSetWindowPos(window, info.x + monitor->getX(), info.y + monitor->getY());
|
||||
|
||||
ret->cachedX = (double) x / (double) monitor->getWidth();
|
||||
ret->cachedY = (double) y / (double) monitor->getHeight();
|
||||
ret->cachedWidth = width;
|
||||
ret->cachedHeight = height;
|
||||
|
||||
glfwGetWindowSize(window, &width, &height);
|
||||
|
||||
glfwSetWindowPosCallback(window, positionCallback);
|
||||
glfwSetWindowSizeCallback(window, sizeCallback);
|
||||
glfwSetFramebufferSizeCallback(window, framebufferSizeCallback);
|
||||
glfwSetWindowFocusCallback(window, windowFocusCallback);
|
||||
|
||||
glfwSetCursorPosCallback(window, GenoInput::cursorPositionCallback);
|
||||
glfwSetKeyCallback(window, GenoInput::keyCallback);
|
||||
glfwSetMouseButtonCallback(window, GenoInput::mouseButtonCallback);
|
||||
|
||||
ret->curMonitor = monitor;
|
||||
|
||||
ret->x = x;
|
||||
ret->y = y;
|
||||
ret->width = width;
|
||||
ret->height = height;
|
||||
ret->window = window;
|
||||
|
||||
uint32 clearBits = GL_COLOR_BUFFER_BIT;
|
||||
|
||||
if (info.depth) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
clearBits |= GL_DEPTH_BUFFER_BIT;
|
||||
}
|
||||
|
||||
int32 frameWidth;
|
||||
int32 frameHeight;
|
||||
glfwGetFramebufferSize(window, &frameWidth, &frameHeight);
|
||||
|
||||
GenoFramebuffer * framebuffer = new GenoFramebuffer();
|
||||
framebuffer->id = 0;
|
||||
framebuffer->width = frameWidth;
|
||||
framebuffer->width = frameHeight;
|
||||
framebuffer->clearRed = info.clearRed;
|
||||
framebuffer->clearGreen = info.clearGreen;
|
||||
framebuffer->clearBlue = info.clearBlue;
|
||||
framebuffer->clearBits = clearBits;
|
||||
|
||||
ret->framebuffer = framebuffer;
|
||||
|
||||
if (GenoFramebuffer::activeFramebuffer == 0)
|
||||
GenoFramebuffer::activeFramebuffer = framebuffer;
|
||||
|
||||
glfwSetWindowUserPointer(window, ret);
|
||||
|
||||
if (vidMode != 0)
|
||||
ret->setFullscreen(monitor, vidMode);
|
||||
|
||||
glfwShowWindow(window);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void GenoWindow::activate() const {
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwFocusWindow(window);
|
||||
}
|
||||
|
||||
void GenoWindow::bindFramebuffer() const {
|
||||
framebuffer->bind();
|
||||
}
|
||||
|
||||
void GenoWindow::swap() const {
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
int32 GenoWindow::getX() const {
|
||||
return x;
|
||||
}
|
||||
|
||||
int32 GenoWindow::getY() const {
|
||||
return y;
|
||||
}
|
||||
|
||||
GenoVector2i GenoWindow::getPosition() const {
|
||||
return { x, y };
|
||||
}
|
||||
|
||||
int32 GenoWindow::getWidth() const {
|
||||
return width;
|
||||
}
|
||||
|
||||
int32 GenoWindow::getHeight() const {
|
||||
return height;
|
||||
}
|
||||
|
||||
GenoVector2i GenoWindow::getDimensions() const {
|
||||
return { width, height };
|
||||
}
|
||||
|
||||
bool GenoWindow::shouldClose() const {
|
||||
return glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
void GenoWindow::setShouldClose(bool shouldClose) {
|
||||
glfwSetWindowShouldClose(window, shouldClose);
|
||||
}
|
||||
|
||||
void GenoWindow::disableFullscreen(GenoMonitor * monitor) {
|
||||
glfwSetWindowMonitor(window, 0, monitor->getX() + cachedX * monitor->getWidth(), monitor->getY() + cachedY * monitor->getHeight(), cachedWidth, cachedHeight, 0);
|
||||
fullscreen = false;
|
||||
}
|
||||
|
||||
void GenoWindow::disableFullscreen(GenoMonitor * monitor, int32 x, int32 y, int32 width, int32 height) {
|
||||
glfwSetWindowMonitor(window, 0, x + monitor->getX(), y + monitor->getY(), width, height, 0);
|
||||
fullscreen = false;
|
||||
}
|
||||
|
||||
void GenoWindow::setFullscreen(GenoMonitor * monitor, GenoVideoMode * videoMode) {
|
||||
if (!fullscreen) {
|
||||
cachedX = (double) x / (double) curMonitor->getWidth();
|
||||
cachedY = (double) y / (double) curMonitor->getHeight();
|
||||
cachedWidth = width;
|
||||
cachedHeight = height;
|
||||
}
|
||||
glfwSetWindowMonitor(window, monitor->monitor, monitor->getX() + 1, monitor->getY() + 1, videoMode->getWidth(), videoMode->getHeight(), videoMode->getRefreshRate());
|
||||
fullscreen = true;
|
||||
}
|
||||
|
||||
void GenoWindow::setX(int32 x) {
|
||||
glfwSetWindowPos(window, x, y);
|
||||
}
|
||||
|
||||
void GenoWindow::setY(int32 y) {
|
||||
glfwSetWindowPos(window, x, y);
|
||||
}
|
||||
|
||||
void GenoWindow::setPosition(int32 x, int32 y) {
|
||||
glfwSetWindowPos(window, x, y);
|
||||
}
|
||||
|
||||
void GenoWindow::setPosition(const GenoVector2i & position) {
|
||||
glfwSetWindowPos(window, position.v[0], position.v[1]);
|
||||
}
|
||||
|
||||
void GenoWindow::setWidth(uint32 width) {
|
||||
glfwSetWindowSize(window, width, height);
|
||||
}
|
||||
|
||||
void GenoWindow::setHeight(int32 height) {
|
||||
glfwSetWindowSize(window, width, height);
|
||||
}
|
||||
|
||||
void GenoWindow::setDimensions(int32 width, int32 height) {
|
||||
glfwSetWindowSize(window, width, height);
|
||||
}
|
||||
|
||||
void GenoWindow::setDimensions(const GenoVector2i & position) {
|
||||
glfwSetWindowSize(window, position.v[0], position.v[1]);
|
||||
}
|
||||
|
||||
void GenoWindow::maximize() {
|
||||
glfwMaximizeWindow(window);
|
||||
}
|
||||
|
||||
void GenoWindow::minimize() {
|
||||
glfwIconifyWindow(window);
|
||||
}
|
||||
|
||||
GenoWindow::~GenoWindow() {
|
||||
glfwDestroyWindow(window);
|
||||
}
|
||||
|
||||
void GenoWindow::positionCallback(GLFWwindow * window, int32 x, int32 y) {
|
||||
GenoWindow * win = reinterpret_cast<GenoWindow *>(glfwGetWindowUserPointer(window));
|
||||
win->x = x;
|
||||
win->y = y;
|
||||
|
||||
int32 cx = win->x + win->width / 2;
|
||||
int32 cy = win->y + win->height / 2;
|
||||
for (uint32 i = 0; i < GenoMonitors::getNumMonitors(); ++i) {
|
||||
GenoMonitor * cur = GenoMonitors::getMonitor(i);
|
||||
if (cx >= cur->getX() && cy >= cur->getY() && cx < cur->getX() + cur->getWidth() && cy < cur->getY() + cur->getHeight())
|
||||
win->curMonitor = cur;
|
||||
}
|
||||
}
|
||||
|
||||
void GenoWindow::sizeCallback(GLFWwindow * window, int32 width, int32 height) {
|
||||
GenoWindow * win = reinterpret_cast<GenoWindow *>(glfwGetWindowUserPointer(window));
|
||||
win->width = width;
|
||||
win->height = height;
|
||||
|
||||
int32 cx = win->x + win->width / 2;
|
||||
int32 cy = win->y + win->height / 2;
|
||||
for (uint32 i = 0; i < GenoMonitors::getNumMonitors(); ++i) {
|
||||
GenoMonitor * cur = GenoMonitors::getMonitor(i);
|
||||
if (cx >= cur->getX() && cy >= cur->getY() && cx < cur->getX() + cur->getWidth() && cy < cur->getY() + cur->getHeight())
|
||||
win->curMonitor = cur;
|
||||
}
|
||||
}
|
||||
|
||||
void GenoWindow::framebufferSizeCallback(GLFWwindow * window, int32 width, int32 height) {
|
||||
GenoWindow * win = reinterpret_cast<GenoWindow *>(glfwGetWindowUserPointer(window));
|
||||
GenoFramebuffer * framebuffer = win->framebuffer;
|
||||
framebuffer->width = width;
|
||||
framebuffer->height = height;
|
||||
if (GenoFramebuffer::activeFramebuffer == framebuffer)
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
void GenoWindow::windowFocusCallback(GLFWwindow * window, int32 action) {
|
||||
if (action == GLFW_TRUE) {
|
||||
GenoWindow * win = reinterpret_cast<GenoWindow *>(glfwGetWindowUserPointer(window));
|
||||
GenoFramebuffer::activeWindow = win;
|
||||
}
|
||||
}
|
127
src/geno/engine/GenoWindow.h
Normal file
127
src/geno/engine/GenoWindow.h
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_MONITOR_FORWARD
|
||||
#define GNARLY_GENOME_MONITOR_FORWARD
|
||||
|
||||
struct GenoVideoMode;
|
||||
class GenoMonitor;
|
||||
class GenoMonitors;
|
||||
|
||||
#endif // GNARLY_GENOME_MONITOR_FORWARD
|
||||
|
||||
#ifndef GNARLY_GENOME_FRAMEBUFFER_FORWARD
|
||||
#define GNARLY_GENOME_FRAMEBUFFER_FORWARD
|
||||
|
||||
class GenoFramebuffer;
|
||||
|
||||
#endif // GNARLY_GENOME_FRAMEBUFFER_FORWARD
|
||||
|
||||
#ifndef GNARLY_GENOME_WINDOW
|
||||
#define GNARLY_GENOME_WINDOW
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
#include "GenoMonitor.h"
|
||||
#include "../gl/GenoGL.h"
|
||||
#include "../gl/GenoFramebuffer.h"
|
||||
|
||||
struct GenoWindowCreateInfo {
|
||||
bool defaultPosition;
|
||||
int32 x;
|
||||
int32 y;
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
bool fullscreen;
|
||||
GenoMonitor * monitor;
|
||||
GenoVideoMode * videoMode;
|
||||
const char * title;
|
||||
uint32 numHints;
|
||||
int32 * hints;
|
||||
float clearRed;
|
||||
float clearGreen;
|
||||
float clearBlue;
|
||||
bool depth;
|
||||
};
|
||||
|
||||
class GenoWindow {
|
||||
private:
|
||||
bool fullscreen;
|
||||
|
||||
double cachedX;
|
||||
double cachedY;
|
||||
int32 cachedWidth;
|
||||
int32 cachedHeight;
|
||||
|
||||
GenoMonitor * curMonitor;
|
||||
|
||||
int32 x;
|
||||
int32 y;
|
||||
int32 width;
|
||||
int32 height;
|
||||
GLFWwindow * window;
|
||||
|
||||
GenoFramebuffer * framebuffer;
|
||||
|
||||
GenoWindow();
|
||||
|
||||
////// Callbacks //////
|
||||
|
||||
static void positionCallback(GLFWwindow * window, int32 x, int32 y);
|
||||
static void sizeCallback(GLFWwindow * window, int32 width, int32 height);
|
||||
static void framebufferSizeCallback(GLFWwindow * window, int32 width, int32 height);
|
||||
static void windowFocusCallback(GLFWwindow * window, int32 action);
|
||||
public:
|
||||
static GenoWindow * create(const GenoWindowCreateInfo & info);
|
||||
void activate() const;
|
||||
void bindFramebuffer() const;
|
||||
void swap() const;
|
||||
int32 getX() const;
|
||||
int32 getY() const;
|
||||
GenoVector2i getPosition() const;
|
||||
int32 getWidth() const;
|
||||
int32 getHeight() const;
|
||||
GenoVector2i getDimensions() const;
|
||||
bool shouldClose() const;
|
||||
void setShouldClose(bool shouldClose);
|
||||
void disableFullscreen(GenoMonitor * monitor);
|
||||
void disableFullscreen(GenoMonitor * monitor, int32 x, int32 y, int32 width, int32 height);
|
||||
void setFullscreen(GenoMonitor * monitor, GenoVideoMode * videoMode);
|
||||
void setX(int32 x);
|
||||
void setY(int32 y);
|
||||
void setPosition(int32 x, int32 y);
|
||||
void setPosition(const GenoVector2i & position);
|
||||
void setWidth(uint32 width);
|
||||
void setHeight(int32 height);
|
||||
void setDimensions(int32 width, int32 height);
|
||||
void setDimensions(const GenoVector2i & position);
|
||||
void maximize();
|
||||
void minimize();
|
||||
~GenoWindow();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_WINDOW_FORWARD
|
||||
#endif // GNARLY_GENOME_WINDOW
|
35
src/geno/exceptions/GenoException.cpp
Normal file
35
src/geno/exceptions/GenoException.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "GenoException.h"
|
||||
|
||||
GenoException::GenoException(const char8 * message) :
|
||||
message(message) {}
|
||||
|
||||
|
||||
const char8 * GenoException::getMessage() {
|
||||
return message;
|
||||
}
|
42
src/geno/exceptions/GenoException.h
Normal file
42
src/geno/exceptions/GenoException.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_EXCEPTION
|
||||
#define GNARLY_GENOME_EXCEPTION
|
||||
|
||||
#include "../GenoChars.h"
|
||||
|
||||
class GenoException {
|
||||
protected:
|
||||
const char8 * message;
|
||||
|
||||
public:
|
||||
GenoException(const char8 * message);
|
||||
const char8 * getMessage();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_EXCEPTION_FORWARD
|
||||
#endif // GNARLY_GENOME_EXCEPTION
|
30
src/geno/exceptions/GenoMaxCapacityException.cpp
Normal file
30
src/geno/exceptions/GenoMaxCapacityException.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "GenoMaxCapacityException.h"
|
||||
|
||||
GenoMaxCapacityException::GenoMaxCapacityException() :
|
||||
GenoException("GenoMaxCapacityException: Max capacity reached in GenoArrayList!") {}
|
38
src/geno/exceptions/GenoMaxCapacityException.h
Normal file
38
src/geno/exceptions/GenoMaxCapacityException.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_MAX_CAPACITY_EXCEPTION
|
||||
#define GNARLY_GENOME_MAX_CAPACITY_EXCEPTION
|
||||
|
||||
#include "GenoException.h"
|
||||
|
||||
class GenoMaxCapacityException : public GenoException {
|
||||
public:
|
||||
GenoMaxCapacityException();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_MAX_CAPACITY_EXCEPTION_FORWARD
|
||||
#endif // GNARLY_GENOME_MAX_CAPACITY_EXCEPTION
|
151
src/geno/gl/GenoFramebuffer.cpp
Normal file
151
src/geno/gl/GenoFramebuffer.cpp
Normal file
|
@ -0,0 +1,151 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "GenoGL.h"
|
||||
#include "GenoFramebuffer.h"
|
||||
|
||||
const GenoWindow * GenoFramebuffer::activeWindow = 0;
|
||||
const GenoFramebuffer * GenoFramebuffer::activeFramebuffer = 0;
|
||||
|
||||
void GenoFramebuffer::clear() {
|
||||
glClear(activeFramebuffer->clearBits);
|
||||
}
|
||||
|
||||
void GenoFramebuffer::bindDefault() {
|
||||
activeWindow->bindFramebuffer();
|
||||
}
|
||||
|
||||
uint32 GenoFramebuffer::getCurrentWidth() {
|
||||
return activeFramebuffer->width;
|
||||
}
|
||||
|
||||
uint32 GenoFramebuffer::getCurrentHeight() {
|
||||
return activeFramebuffer->height;
|
||||
}
|
||||
|
||||
GenoFramebuffer::GenoFramebuffer() {}
|
||||
|
||||
GenoFramebuffer::GenoFramebuffer(const GenoFramebufferCreateInfo & info) :
|
||||
width(info.width),
|
||||
height(info.height),
|
||||
numColorAttachments(info.numColorAttachments),
|
||||
depthType(info.depthAttachmentType) {
|
||||
|
||||
glGenFramebuffers(1, &id);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
||||
|
||||
if (numColorAttachments != 0) {
|
||||
clearBits |= GL_COLOR_BUFFER_BIT;
|
||||
clearRed = info.clearRed;
|
||||
clearGreen = info.clearGreen;
|
||||
clearBlue = info.clearBlue;
|
||||
uint32 * colorAttachmentIds = new uint32[numColorAttachments];
|
||||
uint32 * drawBuffers = new uint32[numColorAttachments];
|
||||
colorAttachments = new GenoTexture2D*[numColorAttachments];
|
||||
glGenTextures(numColorAttachments, colorAttachmentIds);
|
||||
for (uint32 i = 0; i < numColorAttachments; ++i) {
|
||||
glBindTexture(GL_TEXTURE_2D, colorAttachmentIds[i]);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
for (uint32 j = 0; j < info.numTextureParams; ++j) {
|
||||
uint32 index = j * 2;
|
||||
glTexParameteri(GL_TEXTURE_2D, info.textureParams[index], info.textureParams[index + 1]);
|
||||
}
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, colorAttachmentIds[i], 0);
|
||||
colorAttachments[i] = new GenoTexture2D(colorAttachmentIds[i], width, height);
|
||||
drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
|
||||
}
|
||||
glDrawBuffers(numColorAttachments, drawBuffers);
|
||||
|
||||
delete [] colorAttachmentIds;
|
||||
delete [] drawBuffers;
|
||||
}
|
||||
if (depthType == GENO_FRAMEBUFFER_DEPTH_BUFFER) {
|
||||
clearBits |= GL_DEPTH_BUFFER_BIT;
|
||||
clearDepth = info.clearDepth;
|
||||
glGenRenderbuffers(1, &depthBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
|
||||
}
|
||||
else if (depthType == GENO_FRAMEBUFFER_DEPTH_TEXTURE) {
|
||||
clearBits |= GL_DEPTH_BUFFER_BIT;
|
||||
clearDepth = info.clearDepth;
|
||||
uint32 textureId;
|
||||
glGenTextures(1, &textureId);
|
||||
glBindTexture(GL_TEXTURE_2D, textureId);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
|
||||
for (uint32 i = 0; i < info.numTextureParams; ++i) {
|
||||
uint32 index = i * 2;
|
||||
glTexParameteri(GL_TEXTURE_2D, info.textureParams[index], info.textureParams[index + 1]);
|
||||
}
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, textureId, 0);
|
||||
depthTexture = new GenoTexture2D(textureId, width, height);
|
||||
}
|
||||
|
||||
activeFramebuffer->bind();
|
||||
}
|
||||
|
||||
uint32 GenoFramebuffer::getWidth() const {
|
||||
return width;
|
||||
}
|
||||
|
||||
uint32 GenoFramebuffer::getHeight() const {
|
||||
return height;
|
||||
}
|
||||
|
||||
const GenoTexture2D * GenoFramebuffer::getColorTexture(uint32 index) const {
|
||||
return colorAttachments[index];
|
||||
}
|
||||
|
||||
const GenoTexture2D * GenoFramebuffer::getDepthTexture() const {
|
||||
return depthTexture;
|
||||
}
|
||||
|
||||
void GenoFramebuffer::bind() const {
|
||||
for (uint32 i = GL_TEXTURE0; i < GL_TEXTURE31; ++i) {
|
||||
glActiveTexture(i);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
activeFramebuffer = this;
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
||||
glClearColor(clearRed, clearGreen, clearBlue, 1);
|
||||
glClearDepth(clearDepth);
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
GenoFramebuffer::~GenoFramebuffer() {
|
||||
for (uint32 i = 0; i < numColorAttachments; ++i)
|
||||
delete colorAttachments[i];
|
||||
delete [] colorAttachments;
|
||||
if (depthType == GENO_FRAMEBUFFER_DEPTH_TEXTURE)
|
||||
delete depthTexture;
|
||||
else if (depthType == GENO_FRAMEBUFFER_DEPTH_BUFFER)
|
||||
glDeleteRenderbuffers(1, &depthBuffer);
|
||||
glDeleteFramebuffers(1, &id);
|
||||
}
|
||||
|
100
src/geno/gl/GenoFramebuffer.h
Normal file
100
src/geno/gl/GenoFramebuffer.h
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_WINDOW_FORWARD
|
||||
#define GNARLY_GENOME_WINDOW_FORWARD
|
||||
|
||||
class GenoWindow;
|
||||
|
||||
#endif // GNARLY_GENOME_WINDOW_FORWARD
|
||||
|
||||
#ifndef GNARLY_GENOME_FRAMEBUFFER
|
||||
#define GNARLY_GENOME_FRAMEBUFFER
|
||||
|
||||
#include "../GenoInts.h"
|
||||
#include "../engine/GenoWindow.h"
|
||||
#include "GenoTexture2D.h"
|
||||
|
||||
#define GENO_FRAMEBUFFER_DEPTH_NONE 0x00
|
||||
#define GENO_FRAMEBUFFER_DEPTH_TEXTURE 0x01
|
||||
#define GENO_FRAMEBUFFER_DEPTH_BUFFER 0x02
|
||||
|
||||
struct GenoFramebufferCreateInfo {
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
uint32 numColorAttachments;
|
||||
uint32 depthAttachmentType;
|
||||
uint32 numTextureParams;
|
||||
uint32 * textureParams;
|
||||
|
||||
float clearRed;
|
||||
float clearGreen;
|
||||
float clearBlue;
|
||||
float clearDepth;
|
||||
};
|
||||
|
||||
class GenoFramebuffer {
|
||||
private:
|
||||
static const GenoWindow * activeWindow;
|
||||
static const GenoFramebuffer * activeFramebuffer;
|
||||
|
||||
uint32 id;
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
|
||||
uint32 clearBits;
|
||||
float clearRed;
|
||||
float clearGreen;
|
||||
float clearBlue;
|
||||
float clearDepth;
|
||||
|
||||
uint32 numColorAttachments;
|
||||
GenoTexture2D ** colorAttachments;
|
||||
uint32 depthType;
|
||||
uint32 depthBuffer;
|
||||
GenoTexture2D * depthTexture;
|
||||
|
||||
GenoFramebuffer();
|
||||
public:
|
||||
static void clear();
|
||||
static void bindDefault();
|
||||
|
||||
static uint32 getCurrentWidth();
|
||||
static uint32 getCurrentHeight();
|
||||
|
||||
GenoFramebuffer(const GenoFramebufferCreateInfo & info);
|
||||
uint32 getWidth() const;
|
||||
uint32 getHeight() const;
|
||||
void bind() const;
|
||||
const GenoTexture2D * getColorTexture(uint32 index = 0) const;
|
||||
const GenoTexture2D * getDepthTexture() const;
|
||||
~GenoFramebuffer();
|
||||
|
||||
friend class GenoWindow;
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_FRAMEBUFFER_FORWARD
|
||||
#endif // GNARLY_GENOME_FRAMEBUFFER
|
36
src/geno/gl/GenoGL.h
Normal file
36
src/geno/gl/GenoGL.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_GL
|
||||
#define GNARLY_GENOME_GL
|
||||
|
||||
/**
|
||||
* Includes both glew and glfw to ensure that they are included in the correct order
|
||||
**/
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#endif // GNARLY_GENOME_GL
|
178
src/geno/gl/GenoShader.cpp
Normal file
178
src/geno/gl/GenoShader.cpp
Normal file
|
@ -0,0 +1,178 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
|
||||
#include "GenoGL.h"
|
||||
|
||||
#include "GenoShader.h"
|
||||
|
||||
int32 GenoShader::active = 0;
|
||||
|
||||
GenoShader::GenoShader(const char * vert, const char * frag, bool file) {
|
||||
uint32 vertId = loadShader(vert, GL_VERTEX_SHADER, file);
|
||||
uint32 fragId = loadShader(frag, GL_FRAGMENT_SHADER, file);
|
||||
program = glCreateProgram();
|
||||
glAttachShader(program, vertId);
|
||||
glAttachShader(program, fragId);
|
||||
glLinkProgram(program);
|
||||
|
||||
int result, length;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &result);
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
|
||||
|
||||
if (length > 1) {
|
||||
char * message = new char[length + 1];
|
||||
glGetProgramInfoLog(program, length, 0, message);
|
||||
std::cerr << message << std::endl;
|
||||
delete[] message;
|
||||
}
|
||||
|
||||
glDetachShader(program, vertId);
|
||||
glDetachShader(program, fragId);
|
||||
|
||||
glDeleteShader(vertId);
|
||||
glDeleteShader(fragId);
|
||||
}
|
||||
|
||||
GenoShader::GenoShader(const char * vert, const char * geom, const char * frag, bool file) {
|
||||
uint32 vertId = loadShader(vert, GL_VERTEX_SHADER, file);
|
||||
uint32 geomId = loadShader(geom, GL_GEOMETRY_SHADER, file);
|
||||
uint32 fragId = loadShader(frag, GL_FRAGMENT_SHADER, file);
|
||||
program = glCreateProgram();
|
||||
glAttachShader(program, vertId);
|
||||
glAttachShader(program, geomId);
|
||||
glAttachShader(program, fragId);
|
||||
glLinkProgram(program);
|
||||
|
||||
|
||||
int result, length;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &result);
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
|
||||
|
||||
if (length > 1) {
|
||||
char * message = new char[length + 1];
|
||||
glGetProgramInfoLog(program, length, 0, message);
|
||||
std::cerr << message << std::endl;
|
||||
delete[] message;
|
||||
}
|
||||
|
||||
glDetachShader(program, vertId);
|
||||
glDetachShader(program, geomId);
|
||||
glDetachShader(program, fragId);
|
||||
|
||||
glDeleteShader(vertId);
|
||||
glDeleteShader(geomId);
|
||||
glDeleteShader(fragId);
|
||||
}
|
||||
|
||||
uint32 GenoShader::loadShader(const char * path, int32 type, bool file) {
|
||||
int length;
|
||||
char * input;
|
||||
if (file) {
|
||||
std::ifstream fin(path, std::ifstream::binary);
|
||||
if (fin) {
|
||||
std::string contents((std::istreambuf_iterator<char>(fin)), std::istreambuf_iterator<char>());
|
||||
|
||||
input = new char[contents.length() + 1];
|
||||
memcpy(input, contents.c_str(), contents.length());
|
||||
input[contents.length()] = 0;
|
||||
|
||||
fin.close();
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
else {
|
||||
std::cerr << "Genome Error (GenoShader): Cannot find shader '" << path << "'!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
length = strlen(path);
|
||||
input = new char[length];
|
||||
strcpy(input, path);
|
||||
}
|
||||
|
||||
uint32 id = glCreateShader(type);
|
||||
glShaderSource(id, 1, &input, 0);
|
||||
glCompileShader(id);
|
||||
|
||||
int result;
|
||||
glGetShaderiv(id, GL_COMPILE_STATUS, &result);
|
||||
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length);
|
||||
|
||||
if (length > 1) {
|
||||
if(file)
|
||||
std::cerr << "Genome Error (GenoShader): Shader '" << path << "' compilation failed!" << std::endl;
|
||||
else
|
||||
std::cerr << "Genome Error (GenoShader): Shader compilation failed!" << std::endl;
|
||||
char * message = new char[length + 1];
|
||||
glGetShaderInfoLog(id, length, 0, message);
|
||||
std::cerr << "\t" << message << std::endl;
|
||||
delete [] message;
|
||||
}
|
||||
|
||||
return id;
|
||||
delete [] input;
|
||||
}
|
||||
|
||||
void GenoShader::enable() {
|
||||
if (active != program) {
|
||||
glUseProgram(program);
|
||||
active = program;
|
||||
}
|
||||
}
|
||||
|
||||
void GenoShader::disable() {
|
||||
if (active != 0) {
|
||||
glUseProgram(0);
|
||||
active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
GenoShader::~GenoShader() {
|
||||
glDeleteProgram(program);
|
||||
}
|
||||
|
||||
GenoMvpShader::GenoMvpShader(const char * vert, const char * frag, bool file) :
|
||||
GenoShader(vert, frag, file) {
|
||||
mvpLoc = glGetUniformLocation(program, "mvp");
|
||||
}
|
||||
|
||||
GenoMvpShader::GenoMvpShader(const char * vert, const char * frag, const char * geom, bool file) :
|
||||
GenoShader(vert, frag, geom, file) {
|
||||
mvpLoc = glGetUniformLocation(program, "mvp");
|
||||
}
|
||||
|
||||
void GenoMvpShader::setMvp(const GenoMatrix4f & mvp) {
|
||||
glUniformMatrix4fv(mvpLoc, 1, GL_FALSE, mvp.m);
|
||||
}
|
||||
|
||||
void GenoMvpShader::setMvp(const float * mvp) {
|
||||
glUniformMatrix4fv(mvpLoc, 1, GL_FALSE, mvp);
|
||||
}
|
65
src/geno/gl/GenoShader.h
Normal file
65
src/geno/gl/GenoShader.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_SHADER
|
||||
#define GNARLY_GENOME_SHADER
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
#include "../math/linear/GenoMatrix4.h"
|
||||
|
||||
#define GENO_SHADER_STRING_IS_SOURCE 0x00
|
||||
#define GENO_SHADER_STRING_IS_PATH 0x01
|
||||
|
||||
class GenoShader {
|
||||
private:
|
||||
static int32 active;
|
||||
|
||||
uint32 loadShader(const char * path, int32 type, bool file);
|
||||
protected:
|
||||
GenoShader(const char * vert, const char * frag, bool file);
|
||||
GenoShader(const char * vert, const char * geom, const char * frag, bool file);
|
||||
int32 program;
|
||||
public:
|
||||
void enable();
|
||||
void disable();
|
||||
~GenoShader();
|
||||
};
|
||||
|
||||
class GenoMvpShader : public GenoShader {
|
||||
private:
|
||||
uint32 mvpLoc;
|
||||
protected:
|
||||
GenoMvpShader(const char * vert, const char * frag, bool file);
|
||||
GenoMvpShader(const char * vert, const char * frag, const char * geom, bool file);
|
||||
public:
|
||||
void setMvp(const GenoMatrix4f & mvp);
|
||||
void setMvp(const float * mvp);
|
||||
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_SHADER_FORWARD
|
||||
#endif // GNARLY_GENOME_SHADER
|
172
src/geno/gl/GenoSpritesheet.cpp
Normal file
172
src/geno/gl/GenoSpritesheet.cpp
Normal file
|
@ -0,0 +1,172 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "GenoGL.h"
|
||||
#include "../data/GenoImage.h"
|
||||
#include "GenoSpritesheet.h"
|
||||
|
||||
GenoSpritesheet::GenoSpritesheet() {}
|
||||
|
||||
GenoSpritesheet * GenoSpritesheet::create(const GenoSpritesheetCreateInfo & info) {
|
||||
GenoImage * image = 0;
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
uint32 fullWidth;
|
||||
uint32 fullHeight;
|
||||
uint8 * data;
|
||||
if (info.type == GENO_SPRITESHEET_TYPE_CREATE) {
|
||||
width = info.width / info.numSpritesX;
|
||||
height = info.height / info.numSpritesY;
|
||||
fullWidth = info.width;
|
||||
fullHeight = info.height;
|
||||
data = info.data;
|
||||
}
|
||||
else {
|
||||
GenoImageCreateInfo imageInfo = {};
|
||||
imageInfo.type = info.type;
|
||||
imageInfo.path = info.texture;
|
||||
|
||||
image = GenoImage::create(imageInfo);
|
||||
|
||||
if (image == 0)
|
||||
return 0;
|
||||
|
||||
width = image->getWidth() / info.numSpritesX;
|
||||
height = image->getHeight() / info.numSpritesY;
|
||||
fullWidth = image->getWidth();
|
||||
fullHeight = image->getHeight();
|
||||
data = image->getBytes();
|
||||
}
|
||||
|
||||
float fractionalWidth = (float) width / (float) fullWidth;
|
||||
float fractionalHeight = (float) height / (float) fullHeight;
|
||||
|
||||
float paddingX = 0;
|
||||
float paddingY = 0;
|
||||
bool cleanData = false;
|
||||
if (info.addPadding) {
|
||||
cleanData = true;
|
||||
uint32 fullPadWidth = fullWidth + info.numSpritesX * 2;
|
||||
uint32 fullPadHeight = fullHeight + info.numSpritesY * 2;
|
||||
uint32 padWidth = width + 2;
|
||||
uint32 padHeight = height + 2;
|
||||
uint8 * newData = new uint8[fullPadWidth * fullPadHeight * 4];
|
||||
uint32 numSprites = info.numSpritesX * info.numSpritesY;
|
||||
uint32 numPixels = padWidth * padHeight;
|
||||
for (uint32 i = 0; i < numSprites; ++i) {
|
||||
uint32 spriteX = i % info.numSpritesX;
|
||||
uint32 spriteY = i / info.numSpritesX;
|
||||
uint32 padOffsetX = padWidth * spriteX;
|
||||
uint32 padOffsetY = padHeight * spriteY;
|
||||
uint32 offsetX = width * spriteX;
|
||||
uint32 offsetY = height * spriteY;
|
||||
for (uint32 j = 0; j < numPixels; ++j) {
|
||||
uint32 pixelX = j % padWidth;
|
||||
uint32 pixelY = j / padWidth;
|
||||
uint32 targetX = pixelX == padWidth - 1 ? pixelX - 2 : (pixelX > 0 ? pixelX - 1 : 0);
|
||||
uint32 targetY = pixelY == padHeight - 1 ? pixelY - 2 : (pixelY > 0 ? pixelY - 1 : 0);
|
||||
uint32 writeIndex = ((pixelY + padOffsetY) * fullPadWidth + pixelX + padOffsetX) * 4;
|
||||
uint32 readIndex = ((targetY + offsetY ) * fullWidth + targetX + offsetX ) * 4;
|
||||
newData[writeIndex ] = data[readIndex ];
|
||||
newData[writeIndex + 1] = data[readIndex + 1];
|
||||
newData[writeIndex + 2] = data[readIndex + 2];
|
||||
newData[writeIndex + 3] = data[readIndex + 3];
|
||||
}
|
||||
}
|
||||
fullWidth = padWidth * info.numSpritesX;
|
||||
fullHeight = padHeight * info.numSpritesY;
|
||||
data = newData;
|
||||
|
||||
paddingX = 1.0 / (float) fullPadWidth;
|
||||
paddingY = 1.0 / (float) fullPadHeight;
|
||||
}
|
||||
|
||||
|
||||
uint32 id;
|
||||
glGenTextures(1, &id);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fullWidth, fullHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
|
||||
for (uint32 i = 0; i < info.numParams; ++i) {
|
||||
uint32 index = i * 2;
|
||||
glTexParameteri(GL_TEXTURE_2D, info.params[index], info.params[index + 1]);
|
||||
}
|
||||
|
||||
GenoSpritesheet * ret = new GenoSpritesheet();
|
||||
ret->id = id;
|
||||
ret->width = width;
|
||||
ret->height = height;
|
||||
ret->numSpritesX = info.numSpritesX;
|
||||
ret->numSpritesY = info.numSpritesY;
|
||||
ret->paddingX = paddingX;
|
||||
ret->paddingY = paddingY;
|
||||
ret->fractionalWidth = fractionalWidth;
|
||||
ret->fractionalHeight = fractionalHeight;
|
||||
ret->scaleX = fractionalWidth - paddingX * 2;
|
||||
ret->scaleY = fractionalHeight - paddingY * 2;
|
||||
|
||||
if (cleanData)
|
||||
delete [] data;
|
||||
delete image;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32 GenoSpritesheet::getWidth() const {
|
||||
return width;
|
||||
}
|
||||
|
||||
uint32 GenoSpritesheet::getHeight() const {
|
||||
return height;
|
||||
}
|
||||
|
||||
GenoMatrix4f GenoSpritesheet::getTransform(uint32 sprite) const {
|
||||
return GenoMatrix4f::makeTranslateXY((sprite % numSpritesX) * fractionalWidth + paddingX,
|
||||
(sprite / numSpritesX) * fractionalHeight + paddingY).scaleXY(scaleX, scaleY);
|
||||
}
|
||||
|
||||
GenoMatrix4f GenoSpritesheet::getTransform(uint32 x, uint32 y) const {
|
||||
return GenoMatrix4f::makeTranslateXY(x * fractionalWidth + paddingX,
|
||||
y * fractionalHeight + paddingY).scaleXY(scaleX, scaleY);
|
||||
}
|
||||
|
||||
GenoMatrix4f GenoSpritesheet::getTransform(const GenoVector2i & coords) const {
|
||||
return GenoMatrix4f::makeTranslateXY(coords.v[0] * fractionalWidth + paddingX,
|
||||
coords.v[1] * fractionalHeight + paddingY).scaleXY(scaleX, scaleY);
|
||||
}
|
||||
|
||||
void GenoSpritesheet::bind(uint8 textureNum) const {
|
||||
glActiveTexture(GL_TEXTURE0 + textureNum);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
}
|
||||
|
||||
void GenoSpritesheet::unbind() const {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
GenoSpritesheet::~GenoSpritesheet() {}
|
92
src/geno/gl/GenoSpritesheet.h
Normal file
92
src/geno/gl/GenoSpritesheet.h
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_TEXTURE_FORWARD
|
||||
#define GNARLY_GENOME_TEXTURE_FORWARD
|
||||
|
||||
class GenoTexture;
|
||||
|
||||
#endif // GNARLY_GENOME_TEXTURE_FORWARD
|
||||
|
||||
#ifndef GNARLY_GENOME_SPRITESHEET
|
||||
#define GNARLY_GENOME_SPRITESHEET
|
||||
|
||||
#define GENO_SPRITESHEET_TYPE_CREATE 0x00
|
||||
#define GENO_SPRITESHEET_TYPE_PNG 0x01
|
||||
#define GENO_SPRITESHEET_TYPE_BMP 0x02
|
||||
|
||||
#include "../GenoInts.h"
|
||||
#include "../math/linear/GenoMatrix4.h"
|
||||
#include "../math/linear/GenoVector2.h"
|
||||
#include "GenoTexture.h"
|
||||
|
||||
struct GenoSpritesheetCreateInfo {
|
||||
uint32 type;
|
||||
bool addPadding;
|
||||
uint32 numSpritesX;
|
||||
uint32 numSpritesY;
|
||||
uint32 numParams;
|
||||
uint32 * params;
|
||||
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
uint8 * data;
|
||||
|
||||
const char * texture;
|
||||
};
|
||||
|
||||
class GenoSpritesheet : public GenoTexture {
|
||||
private:
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
uint32 numSpritesX;
|
||||
uint32 numSpritesY;
|
||||
|
||||
float paddingX;
|
||||
float paddingY;
|
||||
float fractionalWidth;
|
||||
float fractionalHeight;
|
||||
float scaleX;
|
||||
float scaleY;
|
||||
|
||||
GenoSpritesheet();
|
||||
public:
|
||||
static GenoSpritesheet * create(const GenoSpritesheetCreateInfo & info);
|
||||
uint32 getWidth() const;
|
||||
uint32 getHeight() const;
|
||||
|
||||
GenoMatrix4f getTransform(uint32 sprite) const;
|
||||
GenoMatrix4f getTransform(uint32 x, uint32 y) const;
|
||||
GenoMatrix4f getTransform(const GenoVector2i & coords) const;
|
||||
|
||||
virtual void bind(uint8 textureNum = 0) const;
|
||||
virtual void unbind() const;
|
||||
|
||||
~GenoSpritesheet();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_SPRITESHEET_FORWARD
|
||||
#endif // GNARLY_GENOME_SPRITESHEET
|
38
src/geno/gl/GenoTexture.cpp
Normal file
38
src/geno/gl/GenoTexture.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "GenoGL.h"
|
||||
|
||||
#include "GenoTexture.h"
|
||||
|
||||
GenoTexture::GenoTexture() {}
|
||||
|
||||
GenoTexture::GenoTexture(uint32 id) :
|
||||
id(id) {}
|
||||
|
||||
GenoTexture::~GenoTexture() {
|
||||
glDeleteTextures(1, &id);
|
||||
}
|
45
src/geno/gl/GenoTexture.h
Normal file
45
src/geno/gl/GenoTexture.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_TEXTURE
|
||||
#define GNARLY_GENOME_TEXTURE
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
class GenoTexture {
|
||||
protected:
|
||||
uint32 id;
|
||||
|
||||
GenoTexture();
|
||||
GenoTexture(uint32 id);
|
||||
public:
|
||||
virtual void bind(uint8 textureNum = 0) const = 0;
|
||||
virtual void unbind() const = 0;
|
||||
virtual ~GenoTexture();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_TEXTURE_FORWARD
|
||||
#endif // GNARLY_GENOME_TEXTURE
|
94
src/geno/gl/GenoTexture2D.cpp
Normal file
94
src/geno/gl/GenoTexture2D.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "GenoGL.h"
|
||||
#include "../data/GenoImage.h"
|
||||
|
||||
#include "GenoTexture2D.h"
|
||||
|
||||
GenoTexture2D::GenoTexture2D(uint32 id, uint32 width, uint32 height) :
|
||||
GenoTexture(id),
|
||||
width(width),
|
||||
height(height) {}
|
||||
|
||||
GenoTexture2D * GenoTexture2D::create(const GenoTexture2DCreateInfo & info) {
|
||||
GenoImage * image = 0;
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
uint8 * data;
|
||||
if (info.type == GENO_TEXTURE2D_TYPE_CREATE) {
|
||||
width = info.width;
|
||||
height = info.height;
|
||||
data = info.data;
|
||||
}
|
||||
else {
|
||||
GenoImageCreateInfo imageInfo = {};
|
||||
imageInfo.type = info.type;
|
||||
imageInfo.path = info.texture;
|
||||
|
||||
image = GenoImage::create(imageInfo);
|
||||
|
||||
if (image == 0)
|
||||
return 0;
|
||||
width = image->getWidth();
|
||||
height = image->getHeight();
|
||||
data = image->getBytes();
|
||||
}
|
||||
|
||||
uint32 id;
|
||||
glGenTextures(1, &id);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
for (uint32 i = 0; i < info.numParams; ++i) {
|
||||
uint32 index = i * 2;
|
||||
glTexParameteri(GL_TEXTURE_2D, info.params[index], info.params[index + 1]);
|
||||
}
|
||||
|
||||
GenoTexture2D * ret = new GenoTexture2D(id, width, height);
|
||||
|
||||
delete image;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32 GenoTexture2D::getWidth() const {
|
||||
return width;
|
||||
}
|
||||
|
||||
uint32 GenoTexture2D::getHeight() const {
|
||||
return height;
|
||||
}
|
||||
|
||||
void GenoTexture2D::bind(uint8 textureNum) const {
|
||||
glActiveTexture(GL_TEXTURE0 + textureNum);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
}
|
||||
|
||||
void GenoTexture2D::unbind() const {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
GenoTexture2D::~GenoTexture2D() {}
|
75
src/geno/gl/GenoTexture2D.h
Normal file
75
src/geno/gl/GenoTexture2D.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_TEXTURE_FORWARD
|
||||
#define GNARLY_GENOME_TEXTURE_FORWARD
|
||||
|
||||
class GenoTexture;
|
||||
|
||||
#endif // GNARLY_GENOME_TEXTURE_FORWARD
|
||||
|
||||
#ifndef GNARLY_GENOME_TEXTURE2D
|
||||
#define GNARLY_GENOME_TEXTURE2D
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
#include "GenoTexture.h"
|
||||
|
||||
#define GENO_TEXTURE2D_TYPE_CREATE 0x00
|
||||
#define GENO_TEXTURE2D_TYPE_PNG 0x01
|
||||
#define GENO_TEXTURE2D_TYPE_BMP 0x02
|
||||
|
||||
struct GenoTexture2DCreateInfo {
|
||||
uint32 type;
|
||||
uint32 numParams;
|
||||
uint32 * params;
|
||||
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
uint8 * data;
|
||||
|
||||
const char * texture;
|
||||
};
|
||||
|
||||
class GenoTexture2D : public GenoTexture {
|
||||
private:
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
|
||||
GenoTexture2D(uint32 id, uint32 width, uint32 height);
|
||||
public:
|
||||
static GenoTexture2D * create(const GenoTexture2DCreateInfo & info);
|
||||
uint32 getWidth() const;
|
||||
uint32 getHeight() const;
|
||||
virtual void bind(uint8 textureNum = 0) const;
|
||||
virtual void unbind() const;
|
||||
~GenoTexture2D();
|
||||
|
||||
friend class GenoFramebuffer;
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_TEXTURE2D_FORWARD
|
||||
#endif // GNARLY_GENOME_TEXTURE2D
|
72
src/geno/gl/GenoVao.cpp
Normal file
72
src/geno/gl/GenoVao.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "GenoGL.h"
|
||||
|
||||
#include "GenoVao.h"
|
||||
|
||||
template <typename T>
|
||||
struct GenoVertexAttribType {};
|
||||
|
||||
template<> struct GenoVertexAttribType< int8 > { const static uint32 TYPE = GL_UNSIGNED_BYTE; };
|
||||
template<> struct GenoVertexAttribType<uint8 > { const static uint32 TYPE = GL_BYTE; };
|
||||
template<> struct GenoVertexAttribType< int16> { const static uint32 TYPE = GL_UNSIGNED_SHORT; };
|
||||
template<> struct GenoVertexAttribType<uint16> { const static uint32 TYPE = GL_SHORT; };
|
||||
template<> struct GenoVertexAttribType< int32> { const static uint32 TYPE = GL_UNSIGNED_INT; };
|
||||
template<> struct GenoVertexAttribType<uint32> { const static uint32 TYPE = GL_INT; };
|
||||
template<> struct GenoVertexAttribType<float > { const static uint32 TYPE = GL_FLOAT; };
|
||||
template<> struct GenoVertexAttribType<double> { const static uint32 TYPE = GL_DOUBLE; };
|
||||
|
||||
GenoVao::GenoVao(uint32 num, float verts[], uint32 count, uint32 indices[]) {
|
||||
this->count = count;
|
||||
glGenVertexArrays(1, &vao);
|
||||
addAttrib(num, 3, verts);
|
||||
glGenBuffers(1, &ibo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(int32), indices, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void GenoVao::addAttrib(uint32 num, uint32 stride, T data[]) {
|
||||
glBindVertexArray(vao);
|
||||
glGenBuffers(1, vbos + attribs);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbos[attribs]);
|
||||
glBufferData(GL_ARRAY_BUFFER, stride * num * sizeof(T), data, GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(attribs, stride, GenoVertexAttribType<T>::TYPE, GL_FALSE, 0, (void*) 0);
|
||||
glEnableVertexAttribArray(attribs);
|
||||
++attribs;
|
||||
}
|
||||
|
||||
void GenoVao::render() {
|
||||
glBindVertexArray(vao);
|
||||
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
||||
GenoVao::~GenoVao() {
|
||||
glDeleteBuffers(attribs, vbos);
|
||||
glDeleteBuffers(1, &ibo);
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
}
|
44
src/geno/gl/GenoVao.h
Normal file
44
src/geno/gl/GenoVao.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_VAO
|
||||
#define GNARLY_GENOME_VAO
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
class GenoVao {
|
||||
private:
|
||||
uint32 vao, vbos[15], ibo, count;
|
||||
uint8 attribs = 0;
|
||||
public:
|
||||
GenoVao(uint32 num, float verts[], uint32 count, uint32 indices[]);
|
||||
template <typename T> void addAttrib(uint32 num, uint32 stride, T data[]);
|
||||
void render();
|
||||
~GenoVao();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_VAO_FORWARD
|
||||
#endif // GNARLY_GENOME_VAO
|
34
src/geno/math/GenoConstants.h
Normal file
34
src/geno/math/GenoConstants.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_CONSTANTS
|
||||
#define GNARLY_GENOME_CONSTANTS
|
||||
|
||||
template <typename T> constexpr T GENO_PI = T(3.141592653589793238462643383279l);
|
||||
template <typename T> constexpr T GENO_TAU = T(6.283185307179586476925286766559l);
|
||||
template <typename T> constexpr T GENO_E = T(2.718281828459045235360287471353l);
|
||||
|
||||
#endif // GNARLY_GENOME_CONSTANTS
|
195
src/geno/math/linear/GenoMatrix.h
Normal file
195
src/geno/math/linear/GenoMatrix.h
Normal file
|
@ -0,0 +1,195 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "../../GenoInts.h"
|
||||
|
||||
#ifndef GNARLY_GENOME_VECTOR_FORWARD
|
||||
#define GNARLY_GENOME_VECTOR_FORWARD
|
||||
|
||||
template <uint32 N, typename T>
|
||||
class GenoVector;
|
||||
|
||||
#endif // GNARLY_GENOME_VECTOR_FORWARD
|
||||
|
||||
#ifndef GNARLY_GENOME_MATRIX
|
||||
#define GNARLY_GENOME_MATRIX
|
||||
|
||||
#include <ostream>
|
||||
#include <initializer_list>
|
||||
|
||||
#include "GenoVector.h"
|
||||
|
||||
template <uint32 N, uint32 M, typename T>
|
||||
class GenoMatrix {
|
||||
|
||||
static_assert(N > 0 && M > 0, "Matrix dimensions must be greater than 0!");
|
||||
|
||||
private:
|
||||
bool owner = true;
|
||||
|
||||
void clean() {
|
||||
if (owner)
|
||||
delete [] m;
|
||||
}
|
||||
public:
|
||||
T * m;
|
||||
|
||||
GenoMatrix() :
|
||||
m(new T[N * M]()) {}
|
||||
|
||||
GenoMatrix(T * m, bool owner = true) noexcept :
|
||||
owner(owner),
|
||||
m(m) {}
|
||||
|
||||
GenoMatrix(std::initializer_list<T> list) :
|
||||
m(new T[N * M]) {
|
||||
auto min = list.size() < N * M ? list.size() : N * M;
|
||||
auto init = list.begin();
|
||||
for (uint32 i = 0; i < min; ++i)
|
||||
m[(i % M) * N + (i / M)] = init[i];
|
||||
}
|
||||
|
||||
template <typename T2>
|
||||
GenoMatrix(const GenoMatrix<N, M, T2> & matrix) :
|
||||
m(new T[N * M]) {
|
||||
for (uint32 i = 0; i < N * M; ++i)
|
||||
m[i] = (T) matrix.m[i];
|
||||
}
|
||||
|
||||
GenoMatrix(const GenoMatrix<N, M, T> & matrix) :
|
||||
m(new T[N * M]) {
|
||||
for (uint32 i = 0; i < N * M; ++i)
|
||||
m[i] = matrix.m[i];
|
||||
}
|
||||
|
||||
GenoMatrix(GenoMatrix<N, M, T> && matrix) noexcept :
|
||||
owner(matrix.owner),
|
||||
m(matrix.m) {
|
||||
matrix.owner = false;
|
||||
}
|
||||
|
||||
GenoMatrix<N, M, T> & operator=(const GenoMatrix<N, M, T> & matrix) {
|
||||
for (uint32 i = 0; i < N * M; ++i)
|
||||
m[i] = matrix.m[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoMatrix<N, M, T> & operator=(GenoMatrix<N, M, T> && matrix) noexcept {
|
||||
clean();
|
||||
owner = matrix.owner;
|
||||
m = matrix.m;
|
||||
matrix.owner = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoMatrix<N, M, T> & operator+=(const GenoMatrix<N, M, T> & matrix) {
|
||||
for (uint32 i = 0; i < N * M; ++i)
|
||||
m[i] += matrix.m[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoMatrix<N, M, T> & operator-=(const GenoMatrix<N, M, T> & matrix) {
|
||||
for (uint32 i = 0; i < N * M; ++i)
|
||||
m[i] -= matrix.m[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<M, T> operator[](uint32 index) const noexcept {
|
||||
return GenoVector<M, T>(index * M, false);
|
||||
}
|
||||
|
||||
~GenoMatrix() {
|
||||
clean();
|
||||
}
|
||||
};
|
||||
|
||||
template <uint32 N, uint32 M, typename T>
|
||||
GenoMatrix<N, M, T> operator+(const GenoMatrix<N, M, T> & left, const GenoMatrix<N, M, T> & right) {
|
||||
auto sum = new T[N * M];
|
||||
for (uint32 i = 0; i < N * M; ++i)
|
||||
sum[i] = left.m[i] + right.m[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
template <uint32 N, uint32 M, typename T>
|
||||
GenoMatrix<N, M, T> operator-(const GenoMatrix<N, M, T> & left, const GenoMatrix<N, M, T> & right) {
|
||||
auto difference = new T[N * M];
|
||||
for (uint32 i = 0; i < N * M; ++i)
|
||||
difference[i] = left.m[i] - right.m[i];
|
||||
return difference;
|
||||
}
|
||||
|
||||
template <uint32 N, uint32 N2, uint32 M, typename T>
|
||||
GenoMatrix<N2, M, T> operator*(const GenoMatrix<N, M, T> & left, const GenoMatrix<N2, N, T> & right) {
|
||||
auto product = new T[N2 * M];
|
||||
for (uint32 i = 0; i < M; ++i) {
|
||||
for (uint32 j = 0; j < N2; ++j) {
|
||||
product[j * M + i] = 0;
|
||||
for (uint32 k = 0; k < N; ++k)
|
||||
product[j * M + i] += left.m[k * M + i] * right.m[j * N + k];
|
||||
}
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
template <uint32 N, uint32 M, typename T>
|
||||
GenoVector<M, T> operator*(const GenoMatrix<N, M, T> & left, const GenoVector<N, T> & right) {
|
||||
auto product = new T[M];
|
||||
for (uint32 i = 0; i < M; ++i) {
|
||||
product[i] = 0;
|
||||
for (uint32 j = 0; j < N; ++j)
|
||||
product[i] += left.m[j * M + i] * right.v[j];
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
template <uint32 N, uint32 M, typename T>
|
||||
std::ostream & operator<<(std::ostream & stream, const GenoMatrix<N, M, T> & matrix) {
|
||||
for (uint32 i = 0; i < M; ++i) {
|
||||
stream << '[';
|
||||
for (uint32 j = 0; j < N; ++j) {
|
||||
stream << matrix.m[j * M + i];
|
||||
if (j < N - 1)
|
||||
stream << ", ";
|
||||
}
|
||||
stream << "]\n";
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
template <uint32 N, uint32 M> using GenoMatrixNMb = GenoMatrix<N, M, int8 >;
|
||||
template <uint32 N, uint32 M> using GenoMatrixNMub = GenoMatrix<N, M, uint8 >;
|
||||
template <uint32 N, uint32 M> using GenoMatrixNMs = GenoMatrix<N, M, int16>;
|
||||
template <uint32 N, uint32 M> using GenoMatrixNMus = GenoMatrix<N, M, uint16>;
|
||||
template <uint32 N, uint32 M> using GenoMatrixNMi = GenoMatrix<N, M, int32>;
|
||||
template <uint32 N, uint32 M> using GenoMatrixNMui = GenoMatrix<N, M, uint32>;
|
||||
template <uint32 N, uint32 M> using GenoMatrixNMl = GenoMatrix<N, M, int8 >;
|
||||
template <uint32 N, uint32 M> using GenoMatrixNMul = GenoMatrix<N, M, uint64>;
|
||||
template <uint32 N, uint32 M> using GenoMatrixNMf = GenoMatrix<N, M, float >;
|
||||
template <uint32 N, uint32 M> using GenoMatrixNMd = GenoMatrix<N, M, double>;
|
||||
|
||||
#define GNARLY_GENOME_MATRIX_FORWARD
|
||||
#endif // GNARLY_GENOME_MATRIX
|
8579
src/geno/math/linear/GenoMatrix4.h
Normal file
8579
src/geno/math/linear/GenoMatrix4.h
Normal file
File diff suppressed because it is too large
Load diff
200
src/geno/math/linear/GenoMatrixN.h
Normal file
200
src/geno/math/linear/GenoMatrixN.h
Normal file
|
@ -0,0 +1,200 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* INPLIED, INCLUDING BUT NOT LINITED TO THE WARRANTIES OF NERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGENENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIN, DANAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FRON,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "../../GenoInts.h"
|
||||
|
||||
#ifndef GNARLY_GENOME_VECTOR_FORWARD
|
||||
#define GNARLY_GENOME_VECTOR_FORWARD
|
||||
|
||||
template <uint32 N, typename T>
|
||||
class GenoVector<N, T>;
|
||||
|
||||
#endif // GNARLY_GENOME_VECTOR_FORWARD
|
||||
|
||||
#ifndef GNARLY_GENOME_MATRIX_FORWARD
|
||||
#define GNARLY_GENOME_MATRIX_FORWARD
|
||||
|
||||
template <uint32 N, uint32 M, typename T>
|
||||
class GenoMatrix;
|
||||
|
||||
#endif // GNARLY_GENOME_MATRIX_FORWARD
|
||||
|
||||
#ifndef GNARLY_GENOME_MATRIXN
|
||||
#define GNARLY_GENOME_MATRIXN
|
||||
|
||||
#include <ostream>
|
||||
|
||||
#include "GenoVector.h"
|
||||
#include "GenoMatrix.h"
|
||||
|
||||
template <uint32 N, typename T>
|
||||
class GenoMatrix<N, N, T> {
|
||||
|
||||
static_assert(N > 0 && N > 0, "Matrix dimensions must be greater than 0!");
|
||||
|
||||
private:
|
||||
bool owner = true;
|
||||
|
||||
void clean() {
|
||||
if (owner)
|
||||
delete [] m;
|
||||
}
|
||||
public:
|
||||
T * m;
|
||||
|
||||
static GenoMatrix<N, N, T> makeIdentity() {
|
||||
auto identity = new T[N * N];
|
||||
for (uint32 i = 0; i < N * N; ++i) {
|
||||
if (i % N == i / N)
|
||||
identity[i] = 1;
|
||||
else
|
||||
identity[i] = 0;
|
||||
}
|
||||
return identity;
|
||||
}
|
||||
|
||||
GenoMatrix() :
|
||||
m(new T[N * N]()) {}
|
||||
|
||||
GenoMatrix(T * m, bool owner = true) noexcept :
|
||||
owner(owner),
|
||||
m(m) {}
|
||||
|
||||
GenoMatrix(std::initializer_list<T> list) :
|
||||
m(new T[N * N]) {
|
||||
auto min = list.size() < N * N ? list.size() : N * N;
|
||||
auto init = list.begin();
|
||||
for (uint32 i = 0; i < min; ++i)
|
||||
m[(i % N) * N + (i / N)] = init[i];
|
||||
}
|
||||
|
||||
template <typename T2>
|
||||
GenoMatrix(const GenoMatrix<N, N, T2> & matrix) :
|
||||
m(new T[N * N]) {
|
||||
for (uint32 i = 0; i < N * N; ++i)
|
||||
m[i] = (T) matrix.m[i];
|
||||
}
|
||||
|
||||
GenoMatrix(const GenoMatrix<N, N, T> & matrix) :
|
||||
m(new T[N * N]) {
|
||||
for (uint32 i = 0; i < N * N; ++i)
|
||||
m[i] = matrix.m[i];
|
||||
}
|
||||
|
||||
GenoMatrix(GenoMatrix<N, N, T> && matrix) noexcept :
|
||||
owner(matrix.owner),
|
||||
m(matrix.m) {
|
||||
matrix.owner = false;
|
||||
}
|
||||
|
||||
GenoMatrix<N, N, T> & operator=(const GenoMatrix<N, N, T> & matrix) {
|
||||
for (uint32 i = 0; i < N * N; ++i)
|
||||
m[i] = matrix.m[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoMatrix<N, N, T> & operator=(GenoMatrix<N, N, T> && matrix) noexcept {
|
||||
clean();
|
||||
owner = matrix.owner;
|
||||
m = matrix.m;
|
||||
matrix.owner = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoMatrix<N, N, T> & operator+=(const GenoMatrix<N, N, T> & matrix) {
|
||||
for (uint32 i = 0; i < N * N; ++i)
|
||||
m[i] += matrix.m[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoMatrix<N, N, T> & operator-=(const GenoMatrix<N, N, T> & matrix) {
|
||||
for (uint32 i = 0; i < N * N; ++i)
|
||||
m[i] -= matrix.m[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoMatrix<N, N, T> & operator*=(const GenoMatrix<N, N, T> & matrix) {
|
||||
return *this = *this * matrix;
|
||||
}
|
||||
|
||||
GenoVector<N, T> operator[](uint32 index) const noexcept {
|
||||
return GenoVector<N, T>(index * N, false);
|
||||
}
|
||||
|
||||
GenoMatrix<N, N, T> & setIdentity() {
|
||||
for (uint32 i = 0; i < N * N; ++i) {
|
||||
if (i % N == i / N)
|
||||
m[i] = 1;
|
||||
else
|
||||
m[i] = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~GenoMatrix() {
|
||||
clean();
|
||||
}
|
||||
};
|
||||
|
||||
template <uint32 N, typename T>
|
||||
T det(const GenoMatrix<N, N, T> & matrix) {
|
||||
auto ret = T{ 0 };
|
||||
auto sign = T{ 1 };
|
||||
GenoMatrix<N - 1, N - 1, T> storage;
|
||||
for (uint32 i = 0; i < N; ++i) {
|
||||
auto offset = uint32( -1 );
|
||||
for (uint32 j = 0; j < N * N; ++j)
|
||||
if (j % N != 0 && j / N != i)
|
||||
storage.m[++offset] = matrix.m[j];
|
||||
ret += sign * matrix.m[i * N] * det(storage);
|
||||
sign *= -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T det(const GenoMatrix<2, 2, T> & matrix) {
|
||||
return matrix.m[0] * matrix.m[3] - matrix.m[2] * matrix.m[1];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T det(const GenoMatrix<1, 1, T> & matrix) {
|
||||
return matrix.m[0];
|
||||
}
|
||||
|
||||
template <uint32 N> using GenoMatrixNb = GenoMatrix<N, N, int8 >;
|
||||
template <uint32 N> using GenoMatrixNub = GenoMatrix<N, N, uint8 >;
|
||||
template <uint32 N> using GenoMatrixNs = GenoMatrix<N, N, int16>;
|
||||
template <uint32 N> using GenoMatrixNus = GenoMatrix<N, N, uint16>;
|
||||
template <uint32 N> using GenoMatrixNi = GenoMatrix<N, N, int32>;
|
||||
template <uint32 N> using GenoMatrixNui = GenoMatrix<N, N, uint32>;
|
||||
template <uint32 N> using GenoMatrixNl = GenoMatrix<N, N, int8 >;
|
||||
template <uint32 N> using GenoMatrixNul = GenoMatrix<N, N, uint64>;
|
||||
template <uint32 N> using GenoMatrixNf = GenoMatrix<N, N, float >;
|
||||
template <uint32 N> using GenoMatrixNd = GenoMatrix<N, N, double>;
|
||||
|
||||
#define GNARLY_GENOME_MATRIXN_FORWARD
|
||||
#endif // GNARLY_GENOME_MATRIXN
|
476
src/geno/math/linear/GenoVector.h
Normal file
476
src/geno/math/linear/GenoVector.h
Normal file
|
@ -0,0 +1,476 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_VECTOR
|
||||
#define GNARLY_GENOME_VECTOR
|
||||
|
||||
#include <ostream>
|
||||
#include <cmath>
|
||||
#include <initializer_list>
|
||||
|
||||
#include "../../GenoInts.h"
|
||||
|
||||
template <uint32 N, typename T>
|
||||
class GenoVector {
|
||||
|
||||
static_assert(N > 0, "Vector dimensions must be greater than 0!");
|
||||
|
||||
private:
|
||||
bool owner = true;
|
||||
|
||||
void clean() {
|
||||
if (owner)
|
||||
delete [] v;
|
||||
}
|
||||
|
||||
public:
|
||||
static GenoVector<N, T> * newArray(uint32 length) {
|
||||
T * v = new T[N * length];
|
||||
GenoVector<N, T> * ret = new GenoVector<N, T>[length];
|
||||
ret[0] = GenoVector<N, T>(v);
|
||||
for (uint32 i = 1; i < length; ++i)
|
||||
ret[i] = GenoVector<N, T>(v + i * N, false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
T * v;
|
||||
|
||||
GenoVector() :
|
||||
v(new T[N]()) {}
|
||||
|
||||
GenoVector(T * v, bool owner = true) noexcept :
|
||||
owner(owner),
|
||||
v(v) {}
|
||||
|
||||
explicit GenoVector(T value) :
|
||||
v(new T[N]) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] = value;
|
||||
}
|
||||
|
||||
GenoVector(std::initializer_list<T> list) :
|
||||
v(new T[N]) {
|
||||
auto min = list.size() < N ? list.size() : N;
|
||||
auto init = list.begin();
|
||||
for (uint32 i = 0; i < min; ++i)
|
||||
v[i] = init[i];
|
||||
}
|
||||
|
||||
template <typename T2>
|
||||
GenoVector(const GenoVector<N, T2> & vector) :
|
||||
v(new T[N]) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] = (T) vector.v[i];
|
||||
}
|
||||
|
||||
GenoVector(const GenoVector<N, T> & vector) :
|
||||
v(new T[N]) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] = vector.v[i];
|
||||
}
|
||||
|
||||
GenoVector(GenoVector<N, T> && vector) noexcept :
|
||||
owner(vector.owner),
|
||||
v(vector.v) {
|
||||
vector.owner = false;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & operator=(const GenoVector<N, T> & vector) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] = vector.v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & operator=(GenoVector<N, T> && vector) noexcept {
|
||||
if (owner) {
|
||||
clean();
|
||||
owner = vector.owner;
|
||||
v = vector.v;
|
||||
vector.owner = false;
|
||||
}
|
||||
else for (uint32 i = 0; i < N; ++i)
|
||||
v[i] = vector.v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & operator+=(const GenoVector<N, T> & vector) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] += vector.v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & operator-=(const GenoVector<N, T> & vector) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] -= vector.v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & operator*=(T scalar) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] *= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & operator*=(const GenoVector<N, T> & vector) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] *= vector.v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & operator/=(T scalar) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] /= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & operator/=(const GenoVector<N, T> & vector) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] /= vector.v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
T & operator[](uint32 index) noexcept {
|
||||
return v[index];
|
||||
}
|
||||
|
||||
const T & operator[](uint32 index) const noexcept {
|
||||
return v[index];
|
||||
}
|
||||
|
||||
T getLength() const {
|
||||
auto lengthSquared = 0;
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
lengthSquared += v[i] * v[i];
|
||||
return sqrt(lengthSquared);
|
||||
}
|
||||
|
||||
T getLengthSquared() const {
|
||||
auto lengthSquared = 0;
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
lengthSquared += v[i] * v[i];
|
||||
return lengthSquared;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & setLength(T length) {
|
||||
auto scalar = length / getLength();
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] *= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & normalize() {
|
||||
auto scalar = 1 / getLength();
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] *= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & negate() {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] = -v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & project(const GenoVector<N, T> & projection) {
|
||||
auto scalar = dot(*this, projection) / projection.getLengthSquared();
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] = scalar * projection.v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & set(const GenoVector<N, T> & set) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] = set.v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & translate(const GenoVector<N, T> & translate) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] += translate.v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & scale(T scale) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] *= scale;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoVector<N, T> & scale(const GenoVector<N, T> & scale) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
v[i] *= scale.v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~GenoVector() noexcept {
|
||||
clean();
|
||||
}
|
||||
};
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> operator-(const GenoVector<N, T> & vector) {
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = -vector.v[i];
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> operator+(const GenoVector<N, T> & left, const GenoVector<N, T> & right) {
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = left.v[i] + right.v[i];
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> operator-(const GenoVector<N, T> & left, const GenoVector<N, T> & right) {
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = left.v[i] - right.v[i];
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> operator*(const GenoVector<N, T> & left, T right) {
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = left.v[i] * right;
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> operator*(T left, const GenoVector<N, T> & right) {
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = left * right.v[i];
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> operator*(const GenoVector<N, T> & left, const GenoVector<N, T> & right) {
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = left.v[i] * right.v[i];
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> operator/(const GenoVector<N, T> & left, T right) {
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = left.v[i] / right;
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> operator/(const GenoVector<N, T> & left, const GenoVector<N, T> & right) {
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = left.v[i] / right.v[i];
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N + 1, T> operator|(const GenoVector<N, T> & left, T right) {
|
||||
auto newV = new T[N + 1];
|
||||
for (uint32 i = 0; i < N + 1; ++i)
|
||||
newV[i] = left.v[i];
|
||||
newV[N] = right;
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N + 1, T> operator|(T left, const GenoVector<N, T> & right) {
|
||||
auto newV = new T[N + 1];
|
||||
newV[0] = left;
|
||||
for (uint32 i = 0; i < N + 1; ++i)
|
||||
newV[i + 1] = right.v[i];
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, uint32 N2, typename T>
|
||||
GenoVector<N + N2, T> operator|(const GenoVector<N, T> & left, const GenoVector<N2, T> & right) {
|
||||
auto newV = new T[N + N2];
|
||||
auto vRight = newV + N;
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = left.v[i];
|
||||
for (uint32 i = 0; i < N2; ++i)
|
||||
vRight[i] = right.v[i];
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> setLength(const GenoVector<N, T> & vector, T length) {
|
||||
auto scalar = length / vector.getLength();
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = vector.v[i] * scalar;
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> & setLength(const GenoVector<N, T> & vector, T length, const GenoVector<N, T> & target) {
|
||||
auto scalar = length / vector.getLength();
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
target.v[i] = vector.v[i] * scalar;
|
||||
return target;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> normalize(const GenoVector<N, T> & vector) {
|
||||
auto scalar = 1 / vector.getLength();
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = vector.v[i] * scalar;
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> & normalize(const GenoVector<N, T> & vector, const GenoVector<N, T> & target) {
|
||||
auto scalar = 1 / vector.getLength();
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
target.v[i] = vector.v[i] * scalar;
|
||||
return target;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> negate(const GenoVector<N, T> & vector) {
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = -vector.v[i];
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> & negate(const GenoVector<N, T> & vector, GenoVector<N, T> & target) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
target.v[i] = -vector.v[i];
|
||||
return target;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
T dot(const GenoVector<N, T> & left, const GenoVector<N, T> & right) {
|
||||
auto product = T();
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
product += left.v[i] * right.v[i];
|
||||
return product;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> project(const GenoVector<N, T> & vector, const GenoVector<N, T> & projection) {
|
||||
auto scalar = dot(vector, projection) / projection.getLengthSquared();
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = scalar * projection.v[i];
|
||||
return newV;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> & project(const GenoVector<N, T> & vector, const GenoVector<N, T> & projection, GenoVector<N, T> & target) {
|
||||
auto scalar = dot(vector, projection) / projection.getLengthSquared();
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
target.v[i] = scalar * projection.v[i];
|
||||
return target;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
T angleBetween(const GenoVector<N, T> & vector1, const GenoVector<N, T> & vector2) {
|
||||
return acos(dot(vector1, vector2) / (vector1.getLength() * vector2.getLength()));
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> & translate(const GenoVector<N, T> & vector, const GenoVector<N, T> & translate) {
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = vector.v[i] + translate.v[i];
|
||||
return newV;
|
||||
}
|
||||
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> & translate(const GenoVector<N, T> & vector, const GenoVector<N, T> & translate, GenoVector<N, T> & target) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
target.v[i] = vector.v[i] + translate.v[i];
|
||||
return target;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> & scale(const GenoVector<N, T> & vector, T scale) {
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = vector.v[i] * scale;
|
||||
return newV;
|
||||
}
|
||||
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> & scale(const GenoVector<N, T> & vector, T scale, GenoVector<N, T> & target) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
target.v[i] = vector.v[i] * scale;
|
||||
return target;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> & scale(const GenoVector<N, T> & vector, const GenoVector<N, T> & scale) {
|
||||
auto newV = new T[N];
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
newV[i] = vector.v[i] * scale.v[i];
|
||||
return newV;
|
||||
}
|
||||
|
||||
|
||||
template <uint32 N, typename T>
|
||||
GenoVector<N, T> & scale(const GenoVector<N, T> & vector, const GenoVector<N, T> & scale, GenoVector<N, T> & target) {
|
||||
for (uint32 i = 0; i < N; ++i)
|
||||
target.v[i] = vector.v[i] * scale.v[i];
|
||||
return target;
|
||||
}
|
||||
|
||||
template <uint32 N, typename T>
|
||||
std::ostream & operator<<(std::ostream & stream, const GenoVector<N, T> & vector) {
|
||||
stream << '<';
|
||||
for (uint32 i = 0; i < N; ++i) {
|
||||
stream << vector.v[i];
|
||||
if (i < N - 1)
|
||||
stream << ", ";
|
||||
}
|
||||
return stream << '>';
|
||||
}
|
||||
|
||||
template <uint32 N> using GenoVectorNb = GenoVector<N, int8 >;
|
||||
template <uint32 N> using GenoVectorNub = GenoVector<N, uint8 >;
|
||||
template <uint32 N> using GenoVectorNs = GenoVector<N, int16>;
|
||||
template <uint32 N> using GenoVectorNus = GenoVector<N, uint16>;
|
||||
template <uint32 N> using GenoVectorNi = GenoVector<N, int32>;
|
||||
template <uint32 N> using GenoVectorNui = GenoVector<N, uint32>;
|
||||
template <uint32 N> using GenoVectorNl = GenoVector<N, int64>;
|
||||
template <uint32 N> using GenoVectorNul = GenoVector<N, uint64>;
|
||||
template <uint32 N> using GenoVectorNf = GenoVector<N, float >;
|
||||
template <uint32 N> using GenoVectorNd = GenoVector<N, double>;
|
||||
|
||||
#define GNARLY_GENOME_VECTOR_FORWARD
|
||||
#endif // GNARLY_GENOME_VECTOR
|
56
src/geno/math/linear/GenoVector1.h
Normal file
56
src/geno/math/linear/GenoVector1.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "../../GenoInts.h"
|
||||
|
||||
#ifndef GNARLY_GENOME_VECTOR_FORWARD
|
||||
#define GNARLY_GENOME_VECTOR_FORWARD
|
||||
|
||||
template <uint32 N, typename T>
|
||||
class GenoVector;
|
||||
|
||||
#endif // GNARLY_GENOME_VECTOR_FORWARD
|
||||
|
||||
#ifndef GNARLY_GENOME_VECTOR1
|
||||
#define GNARLY_GENOME_VECTOR1
|
||||
|
||||
#include "GenoVector.h"
|
||||
|
||||
template <typename T> using GenoVector1 = GenoVector<1, T>;
|
||||
|
||||
using GenoVector1b = GenoVector1< int8 >;
|
||||
using GenoVector1ub = GenoVector1<uint8 >;
|
||||
using GenoVector1s = GenoVector1< int16>;
|
||||
using GenoVector1us = GenoVector1<uint16>;
|
||||
using GenoVector1i = GenoVector1< int32>;
|
||||
using GenoVector1ui = GenoVector1<uint32>;
|
||||
using GenoVector1l = GenoVector1< int64>;
|
||||
using GenoVector1ul = GenoVector1<uint64>;
|
||||
using GenoVector1f = GenoVector1<float >;
|
||||
using GenoVector1d = GenoVector1<double>;
|
||||
|
||||
#define GNARLY_GENOME_VECTOR1_FORWARD
|
||||
#endif // GNARLY_GENOME_VECTOR1
|
1080
src/geno/math/linear/GenoVector2.h
Normal file
1080
src/geno/math/linear/GenoVector2.h
Normal file
File diff suppressed because it is too large
Load diff
3080
src/geno/math/linear/GenoVector3.h
Normal file
3080
src/geno/math/linear/GenoVector3.h
Normal file
File diff suppressed because it is too large
Load diff
7440
src/geno/math/linear/GenoVector4.h
Normal file
7440
src/geno/math/linear/GenoVector4.h
Normal file
File diff suppressed because it is too large
Load diff
34
src/geno/math/linear/GenoVectorDimensions.cpp
Normal file
34
src/geno/math/linear/GenoVectorDimensions.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "GenoVectorDimensions.h"
|
||||
|
||||
namespace GenoVectorDimensions {
|
||||
GenoVectorDimension<0> x;
|
||||
GenoVectorDimension<1> y;
|
||||
GenoVectorDimension<2> z;
|
||||
GenoVectorDimension<3> w;
|
||||
}
|
41
src/geno/math/linear/GenoVectorDimensions.h
Normal file
41
src/geno/math/linear/GenoVectorDimensions.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_VECTOR_DIMENSIONS
|
||||
#define GNARLY_GENOME_VECTOR_DIMENSIONS
|
||||
|
||||
#include "../../GenoInts.h"
|
||||
|
||||
namespace GenoVectorDimensions {
|
||||
|
||||
template <uint32 N>
|
||||
struct GenoVectorDimension {
|
||||
const static uint32 dimension = N;
|
||||
};
|
||||
}
|
||||
|
||||
#define GNARLY_GENOME_VECTOR_DIMENSIONS_FORWARD
|
||||
#endif // GNARLY_GENOME_VECTOR_DIMENSIONS
|
42
src/geno/shaders/GenoShader2c.cpp
Normal file
42
src/geno/shaders/GenoShader2c.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "../gl/GenoGL.h"
|
||||
|
||||
#include "GenoShader2c.h"
|
||||
|
||||
GenoShader2c::GenoShader2c() :
|
||||
GenoMvpShader("src/geno/shaders/src/Shader2c/Shader2cv.gls",
|
||||
"src/geno/shaders/src/Shader2c/Shader2cf.gls",
|
||||
GENO_SHADER_STRING_IS_PATH) {
|
||||
colorLoc = glGetUniformLocation(program, "inputColor");
|
||||
}
|
||||
|
||||
void GenoShader2c::setColor(float r, float g, float b, float a) {
|
||||
glUniform4f(colorLoc, r, g, b, a);
|
||||
}
|
||||
|
||||
GenoShader2c::~GenoShader2c() {}
|
43
src/geno/shaders/GenoShader2c.h
Normal file
43
src/geno/shaders/GenoShader2c.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_SHADER2C
|
||||
#define GNARLY_GENOME_SHADER2C
|
||||
|
||||
#include "../GenoInts.h"
|
||||
#include "../gl/GenoShader.h"
|
||||
|
||||
class GenoShader2c : public GenoMvpShader {
|
||||
private:
|
||||
uint32 colorLoc;
|
||||
public:
|
||||
GenoShader2c();
|
||||
void setColor(float r, float g, float b, float a);
|
||||
~GenoShader2c();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_SHADER2C_FORWARD
|
||||
#endif // GNARLY_GENOME_SHADER2C
|
42
src/geno/shaders/GenoShader2ss.cpp
Normal file
42
src/geno/shaders/GenoShader2ss.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "../gl/GenoGL.h"
|
||||
|
||||
#include "GenoShader2ss.h"
|
||||
|
||||
GenoShader2ss::GenoShader2ss() :
|
||||
GenoMvpShader("src/geno/shaders/src/Shader2ss/Shader2ssv.gls",
|
||||
"src/geno/shaders/src/Shader2ss/Shader2ssf.gls",
|
||||
GENO_SHADER_STRING_IS_PATH) {
|
||||
textureTransformLoc = glGetUniformLocation(program, "textureTransform");
|
||||
}
|
||||
|
||||
void GenoShader2ss::setTextureTransform(const GenoMatrix4f & matrix) {
|
||||
glUniformMatrix4fv(textureTransformLoc, 1, GL_FALSE, matrix.m);
|
||||
}
|
||||
|
||||
GenoShader2ss::~GenoShader2ss() {}
|
43
src/geno/shaders/GenoShader2ss.h
Normal file
43
src/geno/shaders/GenoShader2ss.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_SHADER2SS
|
||||
#define GNARLY_GENOME_SHADER2SS
|
||||
|
||||
#include "../GenoInts.h"
|
||||
#include "../gl/GenoShader.h"
|
||||
|
||||
class GenoShader2ss : public GenoMvpShader {
|
||||
private:
|
||||
uint32 textureTransformLoc;
|
||||
public:
|
||||
GenoShader2ss();
|
||||
void setTextureTransform(const GenoMatrix4f & matrix);
|
||||
~GenoShader2ss();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_SHADER2SS_FORWARD
|
||||
#endif // GNARLY_GENOME_SHADER2SS
|
37
src/geno/shaders/GenoShader2t.cpp
Normal file
37
src/geno/shaders/GenoShader2t.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "../gl/GenoGL.h"
|
||||
|
||||
#include "GenoShader2t.h"
|
||||
|
||||
GenoShader2t::GenoShader2t() :
|
||||
GenoMvpShader("src/geno/shaders/src/Shader2t/Shader2tv.gls",
|
||||
"src/geno/shaders/src/Shader2t/Shader2tf.gls",
|
||||
GENO_SHADER_STRING_IS_PATH) {
|
||||
}
|
||||
|
||||
GenoShader2t::~GenoShader2t() {}
|
39
src/geno/shaders/GenoShader2t.h
Normal file
39
src/geno/shaders/GenoShader2t.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_SHADER2T
|
||||
#define GNARLY_GENOME_SHADER2T
|
||||
|
||||
#include "../gl/GenoShader.h"
|
||||
|
||||
class GenoShader2t : public GenoMvpShader {
|
||||
public:
|
||||
GenoShader2t();
|
||||
~GenoShader2t();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_SHADER2T_FORWARD
|
||||
#endif // GNARLY_GENOME_SHADER2T
|
35
src/geno/shaders/src/Shader2c/Shader2cf.gls
Normal file
35
src/geno/shaders/src/Shader2c/Shader2cf.gls
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#version 330 core
|
||||
|
||||
uniform vec4 inputColor = vec4(1, 0.5, 0.9, 1);
|
||||
|
||||
layout (location = 0) out vec4 color;
|
||||
|
||||
void main() {
|
||||
color = inputColor;
|
||||
}
|
35
src/geno/shaders/src/Shader2c/Shader2cv.gls
Normal file
35
src/geno/shaders/src/Shader2c/Shader2cv.gls
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#version 330 core
|
||||
|
||||
uniform mat4 mvp;
|
||||
|
||||
layout (location = 0) in vec3 vertices;
|
||||
|
||||
void main() {
|
||||
gl_Position = mvp * vec4(vertices, 1);
|
||||
}
|
37
src/geno/shaders/src/Shader2ss/Shader2ssf.gls
Normal file
37
src/geno/shaders/src/Shader2ss/Shader2ssf.gls
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#version 330 core
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
in vec2 texCoords;
|
||||
|
||||
layout (location = 0) out vec4 color;
|
||||
|
||||
void main() {
|
||||
color = texture(tex, texCoords);
|
||||
}
|
40
src/geno/shaders/src/Shader2ss/Shader2ssv.gls
Normal file
40
src/geno/shaders/src/Shader2ss/Shader2ssv.gls
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#version 330 core
|
||||
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 textureTransform = mat4(1.0);
|
||||
|
||||
layout (location = 0) in vec3 vertices;
|
||||
layout (location = 1) in vec2 textureCoords;
|
||||
|
||||
out vec2 texCoords;
|
||||
|
||||
void main() {
|
||||
gl_Position = mvp * vec4(vertices, 1);
|
||||
texCoords = (textureTransform * vec4(textureCoords, 0, 1)).xy;
|
||||
}
|
37
src/geno/shaders/src/Shader2t/Shader2tf.gls
Normal file
37
src/geno/shaders/src/Shader2t/Shader2tf.gls
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#version 330 core
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
in vec2 texCoords;
|
||||
|
||||
layout (location = 0) out vec4 color;
|
||||
|
||||
void main() {
|
||||
color = texture(tex, texCoords);
|
||||
}
|
39
src/geno/shaders/src/Shader2t/Shader2tv.gls
Normal file
39
src/geno/shaders/src/Shader2t/Shader2tv.gls
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#version 330 core
|
||||
|
||||
uniform mat4 mvp;
|
||||
|
||||
layout (location = 0) in vec3 vertices;
|
||||
layout (location = 1) in vec2 textureCoords;
|
||||
|
||||
out vec2 texCoords;
|
||||
|
||||
void main() {
|
||||
gl_Position = mvp * vec4(vertices, 1);
|
||||
texCoords = textureCoords;
|
||||
}
|
168
src/geno/template/GenoArrayList.h
Normal file
168
src/geno/template/GenoArrayList.h
Normal file
|
@ -0,0 +1,168 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_ARRAY_LIST
|
||||
#define GNARLY_GENOME_ARRAY_LIST
|
||||
|
||||
#include <utility>
|
||||
#include <initializer_list>
|
||||
|
||||
#include "../GenoInts.h"
|
||||
#include "../exceptions/GenoMaxCapacityException.h"
|
||||
|
||||
template <typename T>
|
||||
class GenoArrayList {
|
||||
private:
|
||||
uint32 capacity;
|
||||
uint32 length;
|
||||
T * array;
|
||||
|
||||
void clean() noexcept {
|
||||
delete [] array;
|
||||
}
|
||||
|
||||
void reallocate(uint32 newCapacity) {
|
||||
capacity = newCapacity;
|
||||
auto newArray = new T[capacity];
|
||||
for (uint32 i = 0; i < length; ++i)
|
||||
newArray[i] = std::move(array[i]);
|
||||
clean();
|
||||
array = newArray;
|
||||
}
|
||||
|
||||
void checkCapacity() {
|
||||
if (length == capacity) {
|
||||
if (capacity == 0xFFFFFFFF)
|
||||
throw GenoMaxCapacityException();
|
||||
else if (capacity > 0x7FFFFFFF)
|
||||
reallocate(0xFFFFFFFF);
|
||||
else
|
||||
reallocate(capacity << 1);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
GenoArrayList(uint32 capacity = 16) :
|
||||
capacity(capacity),
|
||||
array(new T[capacity]) {}
|
||||
|
||||
GenoArrayList(std::initializer_list<T> list) :
|
||||
capacity(list.size() * 2),
|
||||
length(list.size()),
|
||||
array(new T[capacity]) {
|
||||
auto init = list.begin();
|
||||
for (uint32 i = 0; i < list.size(); ++i)
|
||||
array[i] = init[i];
|
||||
}
|
||||
|
||||
GenoArrayList(const GenoArrayList<T> & list) :
|
||||
capacity(list.capacity),
|
||||
length(list.length),
|
||||
array(new T[capacity]) {
|
||||
for (uint32 i = 0; i < list.length; ++i)
|
||||
array[i] = list.array[i];
|
||||
}
|
||||
|
||||
GenoArrayList(GenoArrayList<T> && list) noexcept :
|
||||
capacity(list.capacity),
|
||||
length(list.length),
|
||||
array(list.array) {
|
||||
list.array = 0;
|
||||
}
|
||||
|
||||
GenoArrayList<T> & operator=(const GenoArrayList<T> & list) {
|
||||
clean();
|
||||
capacity = list.capacity;
|
||||
length = list.length;
|
||||
array = new T[capacity];
|
||||
for (uint32 i = 0; i < list.length; ++i)
|
||||
array[i] = list.array[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoArrayList<T> & operator=(GenoArrayList<T> && list) noexcept {
|
||||
clean();
|
||||
capacity = list.capacity;
|
||||
length = list.length;
|
||||
array = list.array;
|
||||
list.array = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
T & operator[](uint32 index) noexcept {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
const T & operator[](uint32 index) const noexcept {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
uint32 getLength() const noexcept {
|
||||
return length;
|
||||
}
|
||||
|
||||
void add(const T & element) {
|
||||
checkCapacity();
|
||||
array[length] = element;
|
||||
++length;
|
||||
}
|
||||
|
||||
void add(uint32 index, const T & element) {
|
||||
checkCapacity();
|
||||
for (uint32 i = length; i > index; --i)
|
||||
array[i] = std::move(array[i - 1]);
|
||||
array[index] = element;
|
||||
++length;
|
||||
}
|
||||
|
||||
void remove(uint32 index) {
|
||||
--length;
|
||||
for (uint32 i = index; i < length; ++i)
|
||||
array[i] = std::move(array[i + 1]);
|
||||
}
|
||||
|
||||
void remove(uint32 begin, uint32 end) {
|
||||
auto distance = end - begin;
|
||||
length -= end;
|
||||
for (uint32 i = begin; i < length; ++i)
|
||||
array[i] = std::move(array[i + distance]);
|
||||
}
|
||||
|
||||
void clear() noexcept {
|
||||
length = 0;
|
||||
}
|
||||
|
||||
void pack() {
|
||||
reallocate(length);
|
||||
}
|
||||
|
||||
~GenoArrayList() {
|
||||
clean();
|
||||
}
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_ARRAY_LIST_FORWARD
|
||||
#endif // GNARLY_GENOME_ARRAY_LIST
|
150
src/geno/template/GenoQueue.h
Normal file
150
src/geno/template/GenoQueue.h
Normal file
|
@ -0,0 +1,150 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_QUEUE
|
||||
#define GNARLY_GENOME_QUEUE
|
||||
|
||||
#include <utility>
|
||||
#include <initializer_list>
|
||||
|
||||
#include "../GenoInts.h"
|
||||
#include "../exceptions/GenoMaxCapacityException.h"
|
||||
|
||||
template <typename T>
|
||||
class GenoQueue {
|
||||
private:
|
||||
uint32 capacity;
|
||||
uint32 read;
|
||||
uint32 write;
|
||||
uint32 length;
|
||||
T * array;
|
||||
|
||||
void clean() noexcept {
|
||||
delete [] array;
|
||||
}
|
||||
|
||||
void reallocate(uint32 newCapacity) {
|
||||
auto newArray = new T[newCapacity];
|
||||
for (uint32 i = 0, j = read - 1; i < length; ++i)
|
||||
newArray[i] = std::move(array[(++j) %= capacity]);
|
||||
clean();
|
||||
capacity = newCapacity;
|
||||
read = 0;
|
||||
write = length;
|
||||
array = newArray;
|
||||
}
|
||||
|
||||
void checkCapacity() {
|
||||
if (length == capacity) {
|
||||
if (capacity == 0xFFFFFFFF)
|
||||
throw GenoMaxCapacityException();
|
||||
else if (capacity > 0x7FFFFFFF)
|
||||
reallocate(0xFFFFFFFF);
|
||||
else
|
||||
reallocate(capacity << 1);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
GenoQueue(uint32 capacity = 16) :
|
||||
capacity(capacity),
|
||||
array(new T[capacity]) {}
|
||||
|
||||
GenoQueue(std::initializer_list<T> list) :
|
||||
capacity(list.size() * 2),
|
||||
write(list.size()),
|
||||
length(list.size()),
|
||||
array(new T[capacity]) {
|
||||
auto init = list.begin();
|
||||
for (uint32 i = 0; i < list.size(); ++i)
|
||||
array[i] = init[i];
|
||||
}
|
||||
|
||||
GenoQueue(const GenoQueue<T> & queue) :
|
||||
capacity(queue.capacity),
|
||||
read(queue.read),
|
||||
write(queue.write),
|
||||
length(queue.length),
|
||||
array(new T[capacity]) {
|
||||
for (uint32 i = read; i != write; (++i) %= capacity)
|
||||
array[i] = queue.array[i];
|
||||
}
|
||||
|
||||
GenoQueue(GenoQueue<T> && queue) noexcept :
|
||||
capacity(queue.capacity),
|
||||
read(queue.read),
|
||||
write(queue.write),
|
||||
length(queue.length),
|
||||
array(queue.array) {
|
||||
queue.array = 0;
|
||||
}
|
||||
|
||||
GenoQueue<T> & operator=(const GenoQueue<T> & queue) {
|
||||
clean();
|
||||
capacity = queue.capacity;
|
||||
length = queue.length;
|
||||
array = new T[capacity];
|
||||
for (uint32 i = read; i != write; (++i) %= capacity)
|
||||
array[i] = queue.array[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoQueue<T> & operator=(GenoQueue<T> && queue) noexcept {
|
||||
clean();
|
||||
capacity = queue.capacity;
|
||||
read = queue.read;
|
||||
write = queue.write;
|
||||
length = queue.length;
|
||||
array = queue.array;
|
||||
queue.array = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void enqueue(const T & element) {
|
||||
checkCapacity();
|
||||
array[write] = element;
|
||||
(++write) %= capacity;
|
||||
++length;
|
||||
}
|
||||
|
||||
T dequeue() {
|
||||
uint32 index = read;
|
||||
(++read) %= capacity;
|
||||
--length;
|
||||
return std::move(array[index]);
|
||||
}
|
||||
|
||||
void pack() {
|
||||
reallocate(length);
|
||||
}
|
||||
|
||||
~GenoQueue() {
|
||||
clean();
|
||||
}
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_QUEUE_FORWARD
|
||||
#endif // GNARLY_GENOME_QUEUE
|
131
src/geno/template/GenoStack.h
Normal file
131
src/geno/template/GenoStack.h
Normal file
|
@ -0,0 +1,131 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_STACK
|
||||
#define GNARLY_GENOME_STACK
|
||||
|
||||
#include <utility>
|
||||
#include <initializer_list>
|
||||
|
||||
#include "../GenoInts.h"
|
||||
#include "../exceptions/GenoMaxCapacityException.h"
|
||||
|
||||
template <typename T>
|
||||
class GenoStack {
|
||||
private:
|
||||
uint32 capacity;
|
||||
uint32 length;
|
||||
T * array;
|
||||
|
||||
void clean() noexcept {
|
||||
delete [] array;
|
||||
}
|
||||
|
||||
void reallocate(uint32 newCapacity) {
|
||||
capacity = newCapacity;
|
||||
auto newArray = new T[capacity];
|
||||
for (uint32 i = 0; i < length; ++i)
|
||||
newArray[i] = std::move(array[i]);
|
||||
clean();
|
||||
array = newArray;
|
||||
}
|
||||
|
||||
void checkCapacity() {
|
||||
if (length == capacity) {
|
||||
if (capacity == 0xFFFFFFFF)
|
||||
throw GenoMaxCapacityException();
|
||||
else if (capacity > 0x7FFFFFFF)
|
||||
reallocate(0xFFFFFFFF);
|
||||
else
|
||||
reallocate(capacity << 1);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
GenoStack(uint32 capacity = 16) :
|
||||
capacity(capacity),
|
||||
array(new T[capacity]) {}
|
||||
|
||||
GenoStack(std::initializer_list<T> list) :
|
||||
capacity(list.size() * 2),
|
||||
length(list.size()),
|
||||
array(new T[capacity]) {
|
||||
auto init = list.begin();
|
||||
for (uint32 i = 0; i < list.size(); ++i)
|
||||
array[i] = init[i];
|
||||
}
|
||||
|
||||
GenoStack(const GenoStack<T> & stack) :
|
||||
capacity(stack.capacity),
|
||||
length(stack.length),
|
||||
array(new T[capacity]) {
|
||||
for (uint32 i = 0; i < stack.length; ++i)
|
||||
array[i] = stack.array[i];
|
||||
}
|
||||
|
||||
GenoStack(GenoStack<T> && stack) noexcept :
|
||||
capacity(stack.capacity),
|
||||
length(stack.length),
|
||||
array(stack.array) {
|
||||
stack.array = 0;
|
||||
}
|
||||
|
||||
GenoStack<T> & operator=(const GenoStack<T> & stack) {
|
||||
clean();
|
||||
capacity = stack.capacity;
|
||||
length = stack.length;
|
||||
array = new T[capacity];
|
||||
for (uint32 i = 0; i < stack.length; ++i)
|
||||
array[i] = stack.array[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
GenoStack<T> & operator=(GenoArrayList<T> && stack) noexcept {
|
||||
clean();
|
||||
capacity = stack.capacity;
|
||||
length = stack.length;
|
||||
array = stack.array;
|
||||
stack.array = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void push(const T & element) {
|
||||
checkCapacity();
|
||||
array[length] = element;
|
||||
++length;
|
||||
}
|
||||
|
||||
T pop() {
|
||||
return std::move(array[--length]);
|
||||
}
|
||||
|
||||
~GenoStack() {
|
||||
clean();
|
||||
}
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_STACK_FORWARD
|
||||
#endif // GNARLY_GENOME_STACK
|
104
src/geno/thread/GenoThreadPool.cpp
Normal file
104
src/geno/thread/GenoThreadPool.cpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
|
||||
#include "GenoThreadPool.h"
|
||||
|
||||
void GenoThreadPool::threadLoop(uint32 threadId, GenoThreadPool * pool) {
|
||||
while (pool->isActive.load()) {
|
||||
GenoThreadPoolJobPackage * job = pool->requestJob(threadId);
|
||||
if (job != 0) {
|
||||
job->job(job->data);
|
||||
pool->activeThreads[threadId].store(false);
|
||||
}
|
||||
else
|
||||
std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(1));
|
||||
}
|
||||
}
|
||||
|
||||
GenoThreadPool::GenoThreadPoolJobPackage * GenoThreadPool::requestJob(uint32 threadId) {
|
||||
std::lock_guard<std::mutex> lock(jobMutex);
|
||||
if (jobCount > 0) {
|
||||
activeThreads[threadId].store(true);
|
||||
--jobCount;
|
||||
return &jobs[jobCount];
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32 GenoThreadPool::physicalThreadCount() {
|
||||
return std::thread::hardware_concurrency();
|
||||
}
|
||||
|
||||
GenoThreadPool::GenoThreadPool(uint32 numThreads, uint32 initialQueueCapacity) :
|
||||
isActive(true),
|
||||
numThreads(numThreads),
|
||||
threads(new std::thread[numThreads]),
|
||||
activeThreads(new std::atomic_bool[numThreads]),
|
||||
jobCount(0),
|
||||
jobCapacity(initialQueueCapacity == 0 ? 16 : initialQueueCapacity),
|
||||
jobs(new GenoThreadPoolJobPackage[jobCapacity]) {
|
||||
for (uint32 i = 0; i < numThreads; ++i) {
|
||||
threads[i] = std::thread(threadLoop, i, this);
|
||||
activeThreads[i].store(false);
|
||||
}
|
||||
}
|
||||
|
||||
void GenoThreadPool::submitJob(GenoThreadPoolJob job, GenoThreadPoolJobData data) {
|
||||
std::lock_guard<std::mutex> lock(jobMutex);
|
||||
if (jobCount >= jobCapacity) {
|
||||
jobCapacity *= 2;
|
||||
GenoThreadPoolJobPackage * newJobs = new GenoThreadPoolJobPackage[jobCapacity];
|
||||
memcpy(newJobs, jobs, sizeof(GenoThreadPoolJobPackage) * jobCount);
|
||||
delete [] jobs;
|
||||
jobs = newJobs;
|
||||
}
|
||||
jobs[jobCount] = { job, data };
|
||||
++jobCount;
|
||||
}
|
||||
|
||||
void GenoThreadPool::wait() {
|
||||
while (jobCount > 0)
|
||||
std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(1));
|
||||
for (uint32 i = 0; i < numThreads; ++i) {
|
||||
if (activeThreads[i].load()) {
|
||||
std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(1));
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GenoThreadPool::~GenoThreadPool() {
|
||||
isActive.store(false);
|
||||
for (uint32 i = 0; i < numThreads; ++i)
|
||||
threads[i].join();
|
||||
delete [] threads;
|
||||
delete [] activeThreads;
|
||||
delete [] jobs;
|
||||
}
|
98
src/geno/thread/GenoThreadPool.h
Normal file
98
src/geno/thread/GenoThreadPool.h
Normal file
|
@ -0,0 +1,98 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_THREAD_POOL
|
||||
#define GNARLY_GENOME_THREAD_POOL
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
typedef void * GenoThreadPoolJobData;
|
||||
typedef void (*GenoThreadPoolJob)(GenoThreadPoolJobData data);
|
||||
|
||||
/**
|
||||
* A thread pool
|
||||
**/
|
||||
class GenoThreadPool {
|
||||
private:
|
||||
struct GenoThreadPoolJobPackage {
|
||||
GenoThreadPoolJob job;
|
||||
GenoThreadPoolJobData data;
|
||||
};
|
||||
|
||||
std::atomic_bool isActive;
|
||||
uint32 numThreads;
|
||||
std::mutex jobMutex;
|
||||
std::thread * threads;
|
||||
std::atomic_bool * activeThreads;
|
||||
|
||||
uint32 jobCount;
|
||||
uint32 jobCapacity;
|
||||
GenoThreadPoolJobPackage * jobs;
|
||||
|
||||
static void threadLoop(uint32 threadId, GenoThreadPool * pool);
|
||||
|
||||
GenoThreadPoolJobPackage * requestJob(uint32 threadId);
|
||||
public:
|
||||
/**
|
||||
* Returns the number of physical threads the system has if possible
|
||||
**/
|
||||
static uint32 physicalThreadCount();
|
||||
|
||||
/**
|
||||
* Creates a thread pool
|
||||
*
|
||||
* @param numThreads - The number of threads in the pool, defaults to physicalThreadCount()
|
||||
* @param initialQueueCapacity - The initial capacity of the job queue. Queue will grow to fit but resizing is expensive
|
||||
**/
|
||||
GenoThreadPool(uint32 numThreads = physicalThreadCount(), uint32 initialQueueCapacity = 16);
|
||||
|
||||
/**
|
||||
* Submits a job to the thread pool
|
||||
*
|
||||
* @param job - The job to be queued
|
||||
* @param data - The data for the queued job
|
||||
**/
|
||||
void submitJob(GenoThreadPoolJob job, GenoThreadPoolJobData data = 0);
|
||||
|
||||
/**
|
||||
* Waits until all submitted jobs have finished
|
||||
**/
|
||||
void wait();
|
||||
|
||||
/**
|
||||
* Destroys the thread pool
|
||||
*
|
||||
* Waits until all jobs have been completed before exiting
|
||||
**/
|
||||
~GenoThreadPool();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_THREAD_POOL_FORWARD
|
||||
#endif // GNARLY_GENOME_THREAD_POOL
|
43
src/geno/thread/GenoTime.cpp
Normal file
43
src/geno/thread/GenoTime.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "GenoTime.h"
|
||||
|
||||
double GenoTime::getTime(GenoTimeScale scale) {
|
||||
return glfwGetTime() * scale;
|
||||
}
|
||||
|
||||
void GenoTime::sleep(double time, GenoTimeScale scale) {
|
||||
std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(time * milliseconds / scale));
|
||||
}
|
||||
|
||||
void GenoTime::sleepUntil(double time, GenoTimeScale scale) {
|
||||
std::this_thread::sleep_for(std::chrono::duration<double, std::milli>((time - getTime(scale)) * milliseconds / scale));
|
||||
}
|
60
src/geno/thread/GenoTime.h
Normal file
60
src/geno/thread/GenoTime.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GNARLY_GENOME_TIME
|
||||
#define GNARLY_GENOME_TIME
|
||||
|
||||
#include "../GenoInts.h"
|
||||
|
||||
enum GenoTimeScale : uint32 { seconds = 1, milliseconds = 1000, microseconds = 1000000, nanoseconds = 1000000000 };
|
||||
|
||||
class GenoTime final {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Returns the time since the initialization of the engine
|
||||
*
|
||||
* @param scale - The time scale in which to return the time
|
||||
**/
|
||||
static double getTime(GenoTimeScale scale = milliseconds);
|
||||
|
||||
/**
|
||||
* Sleeps the current thread for the specified amount of time
|
||||
*
|
||||
* @param scale - The time scale of the time provided
|
||||
**/
|
||||
static void sleep(double time, GenoTimeScale scale = milliseconds);
|
||||
|
||||
/**
|
||||
* Sleeps the current thread until the specified time
|
||||
*
|
||||
* @param scale - The time scale of the time provided
|
||||
**/
|
||||
static void sleepUntil(double time, GenoTimeScale scale = milliseconds);
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_TIME_FORWARD
|
||||
#endif // YOUR_DEFINE_HERE
|
156
src/main.cpp
Normal file
156
src/main.cpp
Normal file
|
@ -0,0 +1,156 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 Gnarly Narwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
#include "geno/GenoInts.h"
|
||||
#include "geno/GenoMacros.h"
|
||||
|
||||
#include "geno/thread/GenoTime.h"
|
||||
#include "geno/engine/GenoEngine.h"
|
||||
#include "geno/engine/GenoLoop.h"
|
||||
#include "geno/engine/GenoInput.h"
|
||||
#include "geno/engine/GenoWindow.h"
|
||||
#include "geno/engine/GenoCamera2D.h"
|
||||
#include "geno/gl/GenoFramebuffer.h"
|
||||
|
||||
bool init();
|
||||
void begin();
|
||||
void loop();
|
||||
void update();
|
||||
void render();
|
||||
void cleanup();
|
||||
|
||||
GenoWindow * window;
|
||||
GenoCamera2D * camera;
|
||||
|
||||
int32 main(int32 argc, char ** argv) {
|
||||
|
||||
init();
|
||||
begin();
|
||||
cleanup();
|
||||
|
||||
/////// TIME TRIALS - LEAVE FOR FUTURE USE ///////
|
||||
/*
|
||||
const uint32 NUM_ITERATIONS = 1000000;
|
||||
|
||||
auto begin1 = std::chrono::high_resolution_clock::now();
|
||||
auto end1 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
auto begin2 = std::chrono::high_resolution_clock::now();
|
||||
auto end2 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end1 - begin1).count() << std::endl;
|
||||
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end2 - begin2).count() << std::endl;
|
||||
*/
|
||||
//////// DO NOT REMOVE BELOW ////////
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
std::cout << "Press enter to continue . . ." << std::endl;
|
||||
std::cin.get();
|
||||
|
||||
#endif // _DEBUG
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool init() {
|
||||
GenoEngine::init();
|
||||
|
||||
GenoLoopCreateInfo loopInfo = {};
|
||||
loopInfo.targetFps = GenoMonitors::getPrimaryMonitor()->getDefaultVideoMode()->getRefreshRate();
|
||||
loopInfo.deltaScale = 1;
|
||||
loopInfo.callback = loop;
|
||||
loopInfo.numSubLoops = 0;
|
||||
loopInfo.subLoops = 0;
|
||||
|
||||
GenoEngine::setLoop(loopInfo);
|
||||
|
||||
int32 winHints[] = {
|
||||
GLFW_CONTEXT_VERSION_MAJOR, 3,
|
||||
GLFW_CONTEXT_VERSION_MINOR, 3,
|
||||
GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE,
|
||||
GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE
|
||||
};
|
||||
|
||||
GenoWindowCreateInfo winInfo = {};
|
||||
winInfo.defaultPosition = true;
|
||||
winInfo.fullscreen = true;
|
||||
winInfo.title = "Genome";
|
||||
winInfo.numHints = GENO_ARRAY_SIZE(winHints) / 2;
|
||||
winInfo.hints = winHints;
|
||||
winInfo.depth = true;
|
||||
winInfo.clearRed = 0;
|
||||
winInfo.clearGreen = 0;
|
||||
winInfo.clearBlue = 0;
|
||||
|
||||
window = GenoWindow::create(winInfo);
|
||||
if (window == 0) {
|
||||
std::cerr << "Window creation failed!" << std::endl;
|
||||
GenoEngine::stopLoop();
|
||||
return false;
|
||||
}
|
||||
window->activate();
|
||||
|
||||
GenoEngine::setSwapInterval(1);
|
||||
GenoEngine::initGlew();
|
||||
|
||||
camera = new GenoCamera2D(0, 1, 1, 0, 0, 1);
|
||||
|
||||
GenoFramebuffer::bindDefault();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void begin() {
|
||||
GenoEngine::startLoop();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
void update() {
|
||||
if (window->shouldClose())
|
||||
GenoEngine::stopLoop();
|
||||
|
||||
camera->update();
|
||||
}
|
||||
|
||||
void render() {
|
||||
GenoFramebuffer::clear();
|
||||
window->swap();
|
||||
}
|
||||
|
||||
void cleanup() {
|
||||
delete camera;
|
||||
delete window;
|
||||
|
||||
GenoEngine::destroy();
|
||||
}
|
Loading…
Reference in a new issue