|
|
|
@ -16,7 +16,8 @@ |
|
|
|
// Interface
|
|
|
|
// Interface
|
|
|
|
|
|
|
|
|
|
|
|
bool initRenderer(SDL_Handles &handles, v2i vpDims); |
|
|
|
bool initRenderer(SDL_Handles &handles, v2i vpDims); |
|
|
|
// TODO: re-implement debug erender
|
|
|
|
bool createScene(std::vector<hex_info>* hexes); |
|
|
|
|
|
|
|
// TODO: re-implement debug renderer
|
|
|
|
void debugRender(HexDrawMode mode, hex_info *startHex, hex_info *currentHex); |
|
|
|
void debugRender(HexDrawMode mode, hex_info *startHex, hex_info *currentHex); |
|
|
|
void renderFrame(const std::vector<hex_info> *hexes); |
|
|
|
void renderFrame(const std::vector<hex_info> *hexes); |
|
|
|
void freeBuffers(); |
|
|
|
void freeBuffers(); |
|
|
|
@ -52,6 +53,15 @@ const char * LINE_FRAGMENT_SHADER_CODE = |
|
|
|
"}"; |
|
|
|
"}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct clear_col |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
real32 R; |
|
|
|
|
|
|
|
real32 G; |
|
|
|
|
|
|
|
real32 B; |
|
|
|
|
|
|
|
real32 A; |
|
|
|
|
|
|
|
} clear_col; |
|
|
|
|
|
|
|
clear_col g_clear_col { 75.f / 255.f, 135.f / 255.f, 135.f / 255.f, 1.f }; |
|
|
|
|
|
|
|
|
|
|
|
typedef struct gl_matrix_info |
|
|
|
typedef struct gl_matrix_info |
|
|
|
{ |
|
|
|
{ |
|
|
|
glm::mat4 projection; |
|
|
|
glm::mat4 projection; |
|
|
|
@ -89,9 +99,9 @@ bool initShaderProgram(gl_render_group &rg, const char * vertex_code, const char |
|
|
|
// enable debug output https://www.khronos.org/opengl/wiki/OpenGL_Error
|
|
|
|
// enable debug output https://www.khronos.org/opengl/wiki/OpenGL_Error
|
|
|
|
void openglDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, |
|
|
|
void openglDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, |
|
|
|
GLsizei length, const GLchar* message, const void* userParam); |
|
|
|
GLsizei length, const GLchar* message, const void* userParam); |
|
|
|
void createScene(std::vector<hex_info>* hexes); |
|
|
|
|
|
|
|
void parseHexToGLBuffer(GLfloat buf[], int idx, const hex_info &hex); |
|
|
|
void parseHexToGLBuffer(GLfloat buf[], int idx, const hex_info &hex); |
|
|
|
bool fillColorBuffer(GLfloat* buf, int len, std::vector<hex_info> *hexes); |
|
|
|
bool fillColorBuffer(GLfloat buf[], int len, std::vector<hex_info> *hexes); |
|
|
|
|
|
|
|
bool checkGLBufferSize(GLenum buf_type, int expected_size, int line_num); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool |
|
|
|
bool |
|
|
|
@ -183,7 +193,7 @@ initShaderProgram(gl_render_group &rg, const char * vertex_code, const char * fr |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
bool |
|
|
|
createScene(std::vector<hex_info>* hexes) |
|
|
|
createScene(std::vector<hex_info>* hexes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
////////////////////
|
|
|
|
////////////////////
|
|
|
|
@ -224,6 +234,9 @@ createScene(std::vector<hex_info>* hexes) |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, g_filled_hex_render_group.vertex_buffer.buffer_id); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, g_filled_hex_render_group.vertex_buffer.buffer_id); |
|
|
|
glBufferData(GL_ARRAY_BUFFER, vertex_buffer->buffer_len * sizeof(GLfloat), vertex_buffer->buffer, GL_DYNAMIC_DRAW); |
|
|
|
glBufferData(GL_ARRAY_BUFFER, vertex_buffer->buffer_len * sizeof(GLfloat), vertex_buffer->buffer, GL_DYNAMIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!checkGLBufferSize(GL_ARRAY_BUFFER, vertex_buffer->buffer_len * sizeof(GLfloat), __LINE__)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
// color data for hex vertices
|
|
|
|
// color data for hex vertices
|
|
|
|
|
|
|
|
|
|
|
|
gl_buffer *color_buffer = &g_filled_hex_render_group.color_buffer; |
|
|
|
gl_buffer *color_buffer = &g_filled_hex_render_group.color_buffer; |
|
|
|
@ -231,21 +244,18 @@ createScene(std::vector<hex_info>* hexes) |
|
|
|
color_buffer->buffer = (GLfloat*) std::calloc(color_buffer->buffer_len, sizeof(GLfloat)); |
|
|
|
color_buffer->buffer = (GLfloat*) std::calloc(color_buffer->buffer_len, sizeof(GLfloat)); |
|
|
|
|
|
|
|
|
|
|
|
if (!fillColorBuffer(color_buffer->buffer, color_buffer->buffer_len, hexes)) |
|
|
|
if (!fillColorBuffer(color_buffer->buffer, color_buffer->buffer_len, hexes)) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
//freeBuffers();
|
|
|
|
|
|
|
|
//return false;
|
|
|
|
|
|
|
|
// TODO: check for retval in main() and run cleanUp()
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glGenBuffers(1, &color_buffer->buffer_id); |
|
|
|
glGenBuffers(1, &color_buffer->buffer_id); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, color_buffer->buffer_id); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, color_buffer->buffer_id); |
|
|
|
glBufferData(GL_ARRAY_BUFFER, color_buffer->buffer_len * sizeof(GLfloat), color_buffer->buffer, GL_DYNAMIC_DRAW); |
|
|
|
glBufferData(GL_ARRAY_BUFFER, color_buffer->buffer_len * sizeof(GLfloat), color_buffer->buffer, GL_DYNAMIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!checkGLBufferSize(GL_ARRAY_BUFFER, color_buffer->buffer_len * sizeof(GLfloat), __LINE__)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
// hex line vertex data
|
|
|
|
// hex line vertex data
|
|
|
|
|
|
|
|
|
|
|
|
// todo: surely there's a way to use indexed drawing for line vertices eg) line_loop
|
|
|
|
// TODO: surely there's a way to use indexed drawing for line vertices eg) line_loop
|
|
|
|
// and still use one buffer for multiple shapes/paths gldrawarraysintanced?, gldrawelements?
|
|
|
|
// and still use one buffer for multiple shapes/paths gldrawarraysintanced?, gldrawelements?
|
|
|
|
// https://gamedev.stackexchange.com/questions/104310/opengl-4-5-primitive-restart-vs-base-index
|
|
|
|
// https://gamedev.stackexchange.com/questions/104310/opengl-4-5-primitive-restart-vs-base-index
|
|
|
|
int line_vertices_per_hex = 6 * 2; // 12 vertices since we're using line segments atm
|
|
|
|
int line_vertices_per_hex = 6 * 2; // 12 vertices since we're using line segments atm
|
|
|
|
@ -285,6 +295,11 @@ createScene(std::vector<hex_info>* hexes) |
|
|
|
glGenBuffers(1, &line_vertex_buffer->buffer_id); |
|
|
|
glGenBuffers(1, &line_vertex_buffer->buffer_id); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, line_vertex_buffer->buffer_id); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, line_vertex_buffer->buffer_id); |
|
|
|
glBufferData(GL_ARRAY_BUFFER, line_vertex_buffer->buffer_len * sizeof(GLfloat), line_vertex_buffer->buffer, GL_STATIC_DRAW); |
|
|
|
glBufferData(GL_ARRAY_BUFFER, line_vertex_buffer->buffer_len * sizeof(GLfloat), line_vertex_buffer->buffer, GL_STATIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!checkGLBufferSize(GL_ARRAY_BUFFER, line_vertex_buffer->buffer_len * sizeof(GLfloat), __LINE__)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
@ -338,20 +353,20 @@ fillColorBuffer(GLfloat buf[], int len, std::vector<hex_info> *hexes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!buf || len < 1) |
|
|
|
if (!buf || len < 1) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// TODO: log fatal error
|
|
|
|
LOG(ERROR) << "buffer length mismatch\n"; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!hexes || hexes->size() == 0) |
|
|
|
if (!hexes || hexes->size() == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// TODO: log fatal error
|
|
|
|
LOG(ERROR) << "hex_info input error\n"; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3 floats per vertex, 3 vertexes per triangle, 6 triangles per hex
|
|
|
|
// 3 floats per vertex, 3 vertexes per triangle, 6 triangles per hex
|
|
|
|
if (len != (int) hexes->size() * 3 * 3 * 6) |
|
|
|
if (len != (int) hexes->size() * 3 * 3 * 6) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// TODO: log fatal error
|
|
|
|
LOG(ERROR) << "hex_info input error\n"; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -372,14 +387,21 @@ fillColorBuffer(GLfloat buf[], int len, std::vector<hex_info> *hexes) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
typedef struct clear_col |
|
|
|
// NOTE: this will only work after a call to glBindBuffer
|
|
|
|
|
|
|
|
bool |
|
|
|
|
|
|
|
checkGLBufferSize(GLenum buf_type, int expected_size, int line_num) |
|
|
|
{ |
|
|
|
{ |
|
|
|
real32 R; |
|
|
|
GLint gl_size; |
|
|
|
real32 G; |
|
|
|
glGetBufferParameteriv(buf_type, GL_BUFFER_SIZE ,&gl_size); |
|
|
|
real32 B; |
|
|
|
|
|
|
|
real32 A; |
|
|
|
if (expected_size != gl_size) |
|
|
|
} clear_col; |
|
|
|
{ |
|
|
|
clear_col g_clear_col { 75.f / 255.f, 135.f / 255.f, 135.f / 255.f, 1.f }; |
|
|
|
LOG(ERROR) << "line: " << line_num << "gl buffer size mismatch\n"; |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
openglDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, |
|
|
|
openglDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, |
|
|
|
|