diff --git a/Makefile b/Makefile index 21f9746..1471347 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,18 @@ +UNAME := $(shell uname) + +ifeq ($(UNAME), Darwin) +CC = clang++ -std=c++20 -DTINYENGINE_OS_MAC +TINYOS = -framework OpenGL +LF = -I/opt/homebrew/include -L/opt/homebrew/lib -L$(HOME)/.local/lib +TINYLINK = -lpthread -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lGLEW -lboost_filesystem +else +CC = g++-10 -std=c++20 +TINYOS = +LF = -I$(HOME)/.local/include -L$(HOME)/.local/lib TINYLINK = -lX11 -lpthread -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lGL -lGLEW -lboost_system -lboost_filesystem +endif -CC = g++-10 -std=c++20 -ggdb3 CF = -Wfatal-errors -O2 -LF = -I$(HOME)/.local/include -L$(HOME)/.local/lib all: SimpleHydrology.cpp - $(CC) SimpleHydrology.cpp $(CF) $(LF) -lTinyEngine $(TINYLINK) -o hydrology + $(CC) SimpleHydrology.cpp $(CF) $(LF) -lTinyEngine $(TINYOS) $(TINYLINK) -o hydrology diff --git a/SimpleHydrology.cpp b/SimpleHydrology.cpp index 18a4e41..9f5947f 100644 --- a/SimpleHydrology.cpp +++ b/SimpleHydrology.cpp @@ -13,7 +13,7 @@ Vertexpool vertexpool; int main( int argc, char* args[] ) { - assert(TINYENGINE_VERSION == "1.7"); + assert(strcmp(TINYENGINE_VERSION, "1.7") == 0); Tiny::view.vsync = false; Tiny::view.blend = false; diff --git a/source/shader/default.fs b/source/shader/default.fs index 0d7d60e..e651485 100644 --- a/source/shader/default.fs +++ b/source/shader/default.fs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core layout (location = 0) out vec3 gPosition; layout (location = 1) out vec3 gNormal; layout (location = 2) out vec4 gColor; diff --git a/source/shader/default.vs b/source/shader/default.vs index ef47118..9ff8801 100644 --- a/source/shader/default.vs +++ b/source/shader/default.vs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core layout (location = 0) in vec3 in_Position; layout (location = 1) in vec3 in_Normal; layout (location = 2) in vec3 in_Tangent; @@ -48,7 +48,7 @@ void main() { // Color-Computation float steepness = 1.0f-pow(clamp((in_Normal.y-0.4)/0.6, 0.0, 1.0), 2); - const ivec2 size = textureSize(dischargeMap, 0); + ivec2 size = textureSize(dischargeMap, 0); float discharge = texture(dischargeMap, in_Position.xz/size).a; ex_Color = flatColor; diff --git a/source/shader/depth.fs b/source/shader/depth.fs index 8bcff36..8776f46 100644 --- a/source/shader/depth.fs +++ b/source/shader/depth.fs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core void main() { //...there appears to be nothing here... } diff --git a/source/shader/depth.vs b/source/shader/depth.vs index fe56d5b..910d0f6 100644 --- a/source/shader/depth.vs +++ b/source/shader/depth.vs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core layout(location = 0) in vec3 in_Position; diff --git a/source/shader/image.fs b/source/shader/image.fs index b8b2cbf..315375c 100644 --- a/source/shader/image.fs +++ b/source/shader/image.fs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core in vec2 ex_Tex; @@ -29,7 +29,7 @@ vec4 ex_Shadow; float gridSample(const int size){ - const float area = ((1 + 2*size)*(1 + 2*size)); + float area = float((1 + 2*size)*(1 + 2*size)); //Stuff float shadow = 0.0; @@ -56,7 +56,7 @@ float gridSample(const int size){ float shade(){ float shadow = 0.0; - const int size = 1; + int size = 1; if(greaterThanEqual(ex_Shadow.xy, vec2(0.0f)) == bvec2(true) && lessThanEqual(ex_Shadow.xy, vec2(1.0f)) == bvec2(true)) shadow = gridSample(size); diff --git a/source/shader/image.vs b/source/shader/image.vs index 8a64909..e2baba8 100644 --- a/source/shader/image.vs +++ b/source/shader/image.vs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core layout(location = 0) in vec2 in_Quad; layout(location = 1) in vec2 in_Tex; diff --git a/source/shader/map.fs b/source/shader/map.fs index 61ad9df..b91d420 100644 --- a/source/shader/map.fs +++ b/source/shader/map.fs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core in vec2 ex_Tex; diff --git a/source/shader/map.vs b/source/shader/map.vs index 7ffca78..c1a0172 100644 --- a/source/shader/map.vs +++ b/source/shader/map.vs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core layout(location = 0) in vec2 in_Quad; layout(location = 1) in vec2 in_Tex; diff --git a/source/shader/ssao.fs b/source/shader/ssao.fs index 3493a08..6c95aa7 100644 --- a/source/shader/ssao.fs +++ b/source/shader/ssao.fs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core in vec2 ex_Tex; diff --git a/source/shader/ssao.vs b/source/shader/ssao.vs index 8a64909..e2baba8 100644 --- a/source/shader/ssao.vs +++ b/source/shader/ssao.vs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core layout(location = 0) in vec2 in_Quad; layout(location = 1) in vec2 in_Tex; diff --git a/source/shader/tree.fs b/source/shader/tree.fs index e1a8731..5863695 100644 --- a/source/shader/tree.fs +++ b/source/shader/tree.fs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core layout (location = 0) out vec3 gPosition; layout (location = 1) out vec3 gNormal; layout (location = 2) out vec4 gColor; diff --git a/source/shader/tree.vs b/source/shader/tree.vs index cd83cea..2b6cbca 100644 --- a/source/shader/tree.vs +++ b/source/shader/tree.vs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core layout(location = 0) in vec4 in_Pos; layout(location = 1) in vec3 in_Normal; @@ -12,7 +12,7 @@ out vec3 ex_Normal; void main(void) { - const vec4 v_Position = view * in_Model * in_Pos; + vec4 v_Position = view * in_Model * in_Pos; ex_Position = v_Position; ex_Normal = transpose(inverse(mat3(view * in_Model))) * normalize(in_Normal); gl_Position = proj*v_Position; diff --git a/source/shader/treedepth.fs b/source/shader/treedepth.fs index 7907634..e33b8cb 100644 --- a/source/shader/treedepth.fs +++ b/source/shader/treedepth.fs @@ -1,2 +1,2 @@ -#version 430 core +#version 410 core void main(){} diff --git a/source/shader/treedepth.vs b/source/shader/treedepth.vs index 0d23527..3e9d7fc 100644 --- a/source/shader/treedepth.vs +++ b/source/shader/treedepth.vs @@ -1,4 +1,4 @@ -#version 430 core +#version 410 core layout(location = 0) in vec4 in_Pos; layout(location = 1) in vec3 in_Normal; diff --git a/source/vertexpool.h b/source/vertexpool.h index 946539c..f8a220e 100644 --- a/source/vertexpool.h +++ b/source/vertexpool.h @@ -5,6 +5,7 @@ using namespace glm; struct Vertex { + Vertex() = default; Vertex(vec3 p, vec3 n, vec3 t, vec3 b){ position[0] = p.x; position[1] = p.y; @@ -32,6 +33,13 @@ struct Vertex { glEnableVertexAttribArray(2); glEnableVertexAttribArray(3); +#ifdef TINYENGINE_OS_MAC + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position)); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, normal)); + glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, tangent)); + glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, bitangent)); +#else glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, 0); glVertexAttribFormat(1, 3, GL_FLOAT, GL_FALSE, 0); glVertexAttribFormat(2, 3, GL_FLOAT, GL_FALSE, 0); @@ -51,6 +59,7 @@ struct Vertex { glBindVertexBuffer(1, vbo, offsetof(Vertex, normal), sizeof(Vertex)); glBindVertexBuffer(2, vbo, offsetof(Vertex, tangent), sizeof(Vertex)); glBindVertexBuffer(3, vbo, offsetof(Vertex, bitangent), sizeof(Vertex)); +#endif } @@ -128,8 +137,13 @@ Vertexpool(int k, int n):Vertexpool(){ for(size_t i = 0; i < indirect.size();) unsection(indirect[i].index); +#ifdef TINYENGINE_OS_MAC + delete[] start; + start = NULL; +#else glBindVertexArray(vao); glUnmapBuffer(vbo); +#endif glDeleteBuffers(1, &vbo); glDeleteBuffers(1, &ebo); glDeleteBuffers(1, &indbo); @@ -157,14 +171,21 @@ void reserve(const int k, const int n){ init(); K = k; N = n; M = 0; + MAXSIZE = N*K; + + glBindBuffer(GL_ARRAY_BUFFER, vbo); + +#ifdef TINYENGINE_OS_MAC + // CPU-side buffer with manual upload (no persistent mapping on macOS GL 4.1) + start = new T[MAXSIZE]; + glBufferData(GL_ARRAY_BUFFER, MAXSIZE*sizeof(T), NULL, GL_DYNAMIC_DRAW); +#else const GLbitfield flag = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT; - - glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferStorage(GL_ARRAY_BUFFER, N*K*sizeof(T), NULL, flag); start = (T*)glMapBufferRange( GL_ARRAY_BUFFER, 0, N*K*sizeof(T), flag ); - MAXSIZE = N*K; +#endif for(int i = 0; i < N; i++) free.push_front(start+i*K); @@ -325,6 +346,13 @@ void update(){ ================================================================================ */ +#ifdef TINYENGINE_OS_MAC +void upload(){ + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glBufferSubData(GL_ARRAY_BUFFER, 0, MAXSIZE*sizeof(T), start); +} +#endif + void render(const GLenum mode = GL_TRIANGLES, size_t first = 0, size_t length = 0){ if(indirect.size() == 0) @@ -336,9 +364,17 @@ void render(const GLenum mode = GL_TRIANGLES, size_t first = 0, size_t length = glBindVertexArray(vao); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); - glBindBuffer(GL_DRAW_INDIRECT_BUFFER, indbo); +#ifdef TINYENGINE_OS_MAC + upload(); + for(size_t i = first; i < first + length; i++){ + glDrawElementsBaseVertex(mode, indirect[i].cnt, GL_UNSIGNED_INT, + (void*)(indirect[i].start * sizeof(GLuint)), indirect[i].baseVert); + } +#else + glBindBuffer(GL_DRAW_INDIRECT_BUFFER, indbo); glMultiDrawElementsIndirect(mode, GL_UNSIGNED_INT, (void*)(first*(sizeof(DAIC))), length, sizeof(DAIC)); +#endif }