Entire project
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
x64/
|
||||
Debug/
|
||||
Release/
|
||||
*.vcxproj*
|
||||
*.sln
|
||||
.vs/
|
BIN
Comedy Crusade.zip
Normal file
4501
res/img/Cover Image.ai
Normal file
BIN
res/img/CoverImage.png
Normal file
After Width: | Height: | Size: 28 KiB |
3137
res/img/Door.ai
Normal file
BIN
res/img/Door1080p.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
res/img/Door1440p.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
res/img/Door4k.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
3715
res/img/End Screen.ai
Normal file
BIN
res/img/EndScreen1080p.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
res/img/EndScreen1440p.png
Normal file
After Width: | Height: | Size: 49 KiB |
BIN
res/img/EndScreen21080p.png
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
res/img/EndScreen21440p.png
Normal file
After Width: | Height: | Size: 118 KiB |
BIN
res/img/EndScreen24k.png
Normal file
After Width: | Height: | Size: 160 KiB |
BIN
res/img/EndScreen4k.png
Normal file
After Width: | Height: | Size: 66 KiB |
6615
res/img/Player.ai
Normal file
BIN
res/img/Player1080p.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
res/img/Player1440p.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
res/img/Player4k.png
Normal file
After Width: | Height: | Size: 52 KiB |
BIN
res/img/blocks/Wire/PoweredWire0001.png
Normal file
After Width: | Height: | Size: 242 B |
BIN
res/img/blocks/Wire/PoweredWire0010.png
Normal file
After Width: | Height: | Size: 272 B |
BIN
res/img/blocks/Wire/PoweredWire0011.png
Normal file
After Width: | Height: | Size: 290 B |
BIN
res/img/blocks/Wire/PoweredWire0100.png
Normal file
After Width: | Height: | Size: 238 B |
BIN
res/img/blocks/Wire/PoweredWire0101.png
Normal file
After Width: | Height: | Size: 217 B |
BIN
res/img/blocks/Wire/PoweredWire0110.png
Normal file
After Width: | Height: | Size: 306 B |
BIN
res/img/blocks/Wire/PoweredWire0111.png
Normal file
After Width: | Height: | Size: 310 B |
BIN
res/img/blocks/Wire/PoweredWire1000.png
Normal file
After Width: | Height: | Size: 279 B |
BIN
res/img/blocks/Wire/PoweredWire1001.png
Normal file
After Width: | Height: | Size: 298 B |
BIN
res/img/blocks/Wire/PoweredWire1010.png
Normal file
After Width: | Height: | Size: 294 B |
BIN
res/img/blocks/Wire/PoweredWire1011.png
Normal file
After Width: | Height: | Size: 329 B |
BIN
res/img/blocks/Wire/PoweredWire1100.png
Normal file
After Width: | Height: | Size: 306 B |
BIN
res/img/blocks/Wire/PoweredWire1101.png
Normal file
After Width: | Height: | Size: 312 B |
BIN
res/img/blocks/Wire/PoweredWire1110.png
Normal file
After Width: | Height: | Size: 337 B |
BIN
res/img/blocks/Wire/PoweredWire1111.png
Normal file
After Width: | Height: | Size: 345 B |
BIN
res/img/blocks/Wire/UnpoweredWire0001.png
Normal file
After Width: | Height: | Size: 215 B |
BIN
res/img/blocks/Wire/UnpoweredWire0010.png
Normal file
After Width: | Height: | Size: 242 B |
BIN
res/img/blocks/Wire/UnpoweredWire0011.png
Normal file
After Width: | Height: | Size: 306 B |
BIN
res/img/blocks/Wire/UnpoweredWire0100.png
Normal file
After Width: | Height: | Size: 205 B |
BIN
res/img/blocks/Wire/UnpoweredWire0101.png
Normal file
After Width: | Height: | Size: 199 B |
BIN
res/img/blocks/Wire/UnpoweredWire0110.png
Normal file
After Width: | Height: | Size: 286 B |
BIN
res/img/blocks/Wire/UnpoweredWire0111.png
Normal file
After Width: | Height: | Size: 310 B |
BIN
res/img/blocks/Wire/UnpoweredWire1000.png
Normal file
After Width: | Height: | Size: 252 B |
BIN
res/img/blocks/Wire/UnpoweredWire1001.png
Normal file
After Width: | Height: | Size: 315 B |
BIN
res/img/blocks/Wire/UnpoweredWire1010.png
Normal file
After Width: | Height: | Size: 251 B |
BIN
res/img/blocks/Wire/UnpoweredWire1011.png
Normal file
After Width: | Height: | Size: 351 B |
BIN
res/img/blocks/Wire/UnpoweredWire1100.png
Normal file
After Width: | Height: | Size: 298 B |
BIN
res/img/blocks/Wire/UnpoweredWire1101.png
Normal file
After Width: | Height: | Size: 321 B |
BIN
res/img/blocks/Wire/UnpoweredWire1110.png
Normal file
After Width: | Height: | Size: 334 B |
BIN
res/img/blocks/Wire/UnpoweredWire1111.png
Normal file
After Width: | Height: | Size: 357 B |
BIN
res/img/blocks/YenBlock/YenBlock0.png
Normal file
After Width: | Height: | Size: 277 B |
BIN
res/img/blocks/YenBlock/YenBlock1.png
Normal file
After Width: | Height: | Size: 284 B |
BIN
res/img/blocks/YenBlock/YenBlock2.png
Normal file
After Width: | Height: | Size: 284 B |
BIN
res/img/blocks/YenBlock/YenBlock3.png
Normal file
After Width: | Height: | Size: 279 B |
BIN
res/img/blocks/YenBlock/YenBlock4.png
Normal file
After Width: | Height: | Size: 277 B |
1
res/levels/count.txt
Normal file
|
@ -0,0 +1 @@
|
|||
4
|
9
res/levels/descriptor.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
numBlocks
|
||||
killFloor
|
||||
player.x,player.y
|
||||
goal.x,goal.y
|
||||
numPlatforms
|
||||
platform-n.x,platform-n.y,platform-n.width,platform-n.height
|
||||
.
|
||||
.
|
||||
.
|
7
res/levels/level0.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
2
|
||||
30
|
||||
1,0
|
||||
18,0
|
||||
2
|
||||
0,2,5,40
|
||||
15,2,5,40
|
7
res/levels/level1.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
2
|
||||
25
|
||||
1,10
|
||||
10,0
|
||||
2
|
||||
0,12,5,40
|
||||
7,2,5,50
|
9
res/levels/level2.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
2
|
||||
30
|
||||
1,0
|
||||
7,-30
|
||||
4
|
||||
0,2,3,40
|
||||
6,-8,3,50
|
||||
0,-18,3,1
|
||||
6,-28,3,1
|
15
res/levels/level3.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
2
|
||||
30
|
||||
1,0
|
||||
24,-2
|
||||
10
|
||||
0,2,3,40
|
||||
7,2,1,40
|
||||
7,-101,1,100
|
||||
11,4,1,40
|
||||
11,-99,1,100
|
||||
15,-4,1,40
|
||||
15,-107,1,100
|
||||
19,0,1,40
|
||||
19,-103,1,100
|
||||
23,0,3,40
|
35
res/shaders/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
res/shaders/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
res/shaders/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
res/shaders/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
res/shaders/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
res/shaders/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;
|
||||
}
|
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
|
@ -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
|
@ -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
|
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
|
@ -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
|
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
|
@ -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
|
124
src/geno/engine/GenoEngine.cpp
Normal file
|
@ -0,0 +1,124 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* 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 "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();
|
||||
|
||||
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;
|
||||
|
||||
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
|
@ -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
|
148
src/geno/engine/GenoInput.cpp
Normal file
|
@ -0,0 +1,148 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* 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 = {};
|
||||
|
||||
bool GenoInput::enabled = true;
|
||||
|
||||
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 enabled ? keyStates[key] : GENO_INPUT_UNPRESSED;
|
||||
}
|
||||
|
||||
double GenoInput::getKeyDuration(uint16 key) {
|
||||
return keyTimes[key];
|
||||
}
|
||||
|
||||
uint8 GenoInput::getMouseButtonState(uint8 key) {
|
||||
return enabled ? mouseButtonStates[key] : GENO_INPUT_UNPRESSED;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void GenoInput::setEnabled(bool enabled) {
|
||||
GenoInput::enabled = enabled;
|
||||
}
|
||||
|
||||
GenoInput::GenoInput() {}
|
||||
GenoInput::~GenoInput() {}
|
||||
|
||||
////// CALLBACKS //////
|
||||
|
||||
void GenoInput::keyCallback(GLFWwindow * window, int32 key, int32 scancode, int32 action, int32 mods) {
|
||||
if (key != GLFW_KEY_UNKNOWN && key > -1) {
|
||||
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;
|
||||
}
|
92
src/geno/engine/GenoInput.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_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;
|
||||
|
||||
static bool enabled;
|
||||
|
||||
////// 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);
|
||||
|
||||
static void setEnabled(bool enabled);
|
||||
|
||||
friend class GenoWindow;
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_INPUT_FORWARD
|
||||
#endif // GNARLY_GENOME_INPUT
|
137
src/geno/engine/GenoLoop.cpp
Normal file
|
@ -0,0 +1,137 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* 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 "../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);
|
||||
truePastTimes[i] = GenoTime::getTime(milliseconds);
|
||||
}
|
||||
pastTimes[callbackCount] = GenoTime::getTime(milliseconds);
|
||||
truePastTimes[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] / milliseconds;
|
||||
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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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();
|
||||
virtual ~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
|
173
src/geno/gl/GenoSpritesheet.cpp
Normal file
|
@ -0,0 +1,173 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* 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(uint8 textureNum) const {
|
||||
glActiveTexture(GL_TEXTURE0 + textureNum);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
GenoSpritesheet::~GenoSpritesheet() {}
|
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(uint8 textureNum = 0) const;
|
||||
|
||||
~GenoSpritesheet();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_SPRITESHEET_FORWARD
|
||||
#endif // GNARLY_GENOME_SPRITESHEET
|
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
|
@ -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(uint8 textureNum = 0) const = 0;
|
||||
virtual ~GenoTexture();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_TEXTURE_FORWARD
|
||||
#endif // GNARLY_GENOME_TEXTURE
|
95
src/geno/gl/GenoTexture2D.cpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* 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(uint8 textureNum) const {
|
||||
glActiveTexture(GL_TEXTURE0 + textureNum);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
GenoTexture2D::~GenoTexture2D() {}
|
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(uint8 textureNum = 0) const;
|
||||
~GenoTexture2D();
|
||||
|
||||
friend class GenoFramebuffer;
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_TEXTURE2D_FORWARD
|
||||
#endif // GNARLY_GENOME_TEXTURE2D
|
59
src/geno/gl/GenoVao.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* 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 "GenoVao.h"
|
||||
|
||||
GenoVao::GenoVao() {}
|
||||
|
||||
GenoVao::GenoVao(const GenoVao & vao) :
|
||||
vao(vao.vao),
|
||||
ibo(vao.ibo),
|
||||
count(vao.count),
|
||||
attribs(vao.attribs) {
|
||||
for (uint32 i = 0; i < attribs; ++i)
|
||||
vbos[i] = vao.vbos[i];
|
||||
}
|
||||
|
||||
GenoVao & GenoVao::operator=(const GenoVao & vao) {
|
||||
this->vao = vao.vao;
|
||||
for (uint32 i = 0; i < attribs; ++i)
|
||||
vbos[i] = vao.vbos[i];
|
||||
this->ibo = vao.ibo;
|
||||
this->count = vao.count;
|
||||
this->attribs = vao.attribs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void GenoVao::render() {
|
||||
glBindVertexArray(vao);
|
||||
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
||||
GenoVao::~GenoVao() {
|
||||
glDeleteBuffers(attribs, vbos);
|
||||
glDeleteBuffers(1, &ibo);
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
}
|
90
src/geno/gl/GenoVao.h
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* 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"
|
||||
#include "GenoGL.h"
|
||||
|
||||
class GenoVao {
|
||||
private:
|
||||
|
||||
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; };
|
||||
|
||||
uint32 vao;
|
||||
uint32 vbos[15];
|
||||
uint32 ibo;
|
||||
uint32 count;
|
||||
uint8 attribs = 0;
|
||||
|
||||
public:
|
||||
GenoVao();
|
||||
GenoVao(const GenoVao & vao);
|
||||
|
||||
template <typename T> GenoVao(uint32 num, const T * verts, uint32 count, const uint32 * indices) :
|
||||
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);
|
||||
}
|
||||
|
||||
GenoVao & operator=(const GenoVao & vao);
|
||||
|
||||
template <typename T> void addAttrib(uint32 num, uint32 stride, const 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;
|
||||
}
|
||||
|
||||
template <typename T> void rebuffer(uint32 attrib, uint32 num, uint32 stride, const T * data) {
|
||||
glBindVertexArray(vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbos[attribs]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, stride * num * sizeof(T), data);
|
||||
}
|
||||
|
||||
void render();
|
||||
~GenoVao();
|
||||
};
|
||||
|
||||
#define GNARLY_GENOME_VAO_FORWARD
|
||||
#endif // GNARLY_GENOME_VAO
|