Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion SimpleHydrology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Vertexpool<Vertex> 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;
Expand Down
2 changes: 1 addition & 1 deletion source/shader/default.fs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions source/shader/default.vs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion source/shader/depth.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 430 core
#version 410 core
void main() {
//...there appears to be nothing here...
}
2 changes: 1 addition & 1 deletion source/shader/depth.vs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 430 core
#version 410 core

layout(location = 0) in vec3 in_Position;

Expand Down
6 changes: 3 additions & 3 deletions source/shader/image.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 430 core
#version 410 core

in vec2 ex_Tex;

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source/shader/image.vs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 430 core
#version 410 core

layout(location = 0) in vec2 in_Quad;
layout(location = 1) in vec2 in_Tex;
Expand Down
2 changes: 1 addition & 1 deletion source/shader/map.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 430 core
#version 410 core

in vec2 ex_Tex;

Expand Down
2 changes: 1 addition & 1 deletion source/shader/map.vs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 430 core
#version 410 core

layout(location = 0) in vec2 in_Quad;
layout(location = 1) in vec2 in_Tex;
Expand Down
2 changes: 1 addition & 1 deletion source/shader/ssao.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 430 core
#version 410 core

in vec2 ex_Tex;

Expand Down
2 changes: 1 addition & 1 deletion source/shader/ssao.vs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 430 core
#version 410 core

layout(location = 0) in vec2 in_Quad;
layout(location = 1) in vec2 in_Tex;
Expand Down
2 changes: 1 addition & 1 deletion source/shader/tree.fs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions source/shader/tree.vs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 430 core
#version 410 core

layout(location = 0) in vec4 in_Pos;
layout(location = 1) in vec3 in_Normal;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion source/shader/treedepth.fs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#version 430 core
#version 410 core
void main(){}
2 changes: 1 addition & 1 deletion source/shader/treedepth.vs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 430 core
#version 410 core

layout(location = 0) in vec4 in_Pos;
layout(location = 1) in vec3 in_Normal;
Expand Down
44 changes: 40 additions & 4 deletions source/vertexpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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

}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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

}

Expand Down