|
|
|
@ -10,6 +10,7 @@ |
|
|
|
#include <glm/gtc/matrix_transform.hpp> |
|
|
|
#include <glm/gtc/matrix_transform.hpp> |
|
|
|
|
|
|
|
|
|
|
|
#include "asset.h" |
|
|
|
#include "asset.h" |
|
|
|
|
|
|
|
#include "dumbLog.h" |
|
|
|
#define GL_DEBUG_IMPLEMENTATION |
|
|
|
#define GL_DEBUG_IMPLEMENTATION |
|
|
|
#include "GLDebug.h" |
|
|
|
#include "GLDebug.h" |
|
|
|
#include "shader.h" |
|
|
|
#include "shader.h" |
|
|
|
@ -41,13 +42,14 @@ addShaderProgram(MemoryArena* arena, |
|
|
|
const char* fs, |
|
|
|
const char* fs, |
|
|
|
const char* name) |
|
|
|
const char* name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
LOGF(Info, "loading shader, %s\n", name); |
|
|
|
// TODO: replace std::string w/ utilAllocCStr() ?
|
|
|
|
// TODO: replace std::string w/ utilAllocCStr() ?
|
|
|
|
std::string hash_str = std::string(vs) + std::string(fs); |
|
|
|
std::string hash_str = std::string(vs) + std::string(fs); |
|
|
|
const u32 max_len = 256; |
|
|
|
const u32 max_len = 256; |
|
|
|
u64 hash = utilFNV64a_str(hash_str.substr(0, max_len).c_str()); |
|
|
|
u64 hash = utilFNV64a_str(hash_str.substr(0, max_len).c_str()); |
|
|
|
|
|
|
|
|
|
|
|
if (getShaderByHash(gl_ctx, hash)) { |
|
|
|
if (getShaderByHash(gl_ctx, hash)) { |
|
|
|
printf("%s(), shader is already loaded\n", __FUNCTION__); |
|
|
|
LOGF(Error, "shader is already loaded\n"); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -77,11 +79,11 @@ addShaderProgram(MemoryArena* arena, |
|
|
|
return parseShader(arena, gl_ctx, s); |
|
|
|
return parseShader(arena, gl_ctx, s); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
printf("%s(), Error linking shader\n", __FUNCTION__); |
|
|
|
LOGF(Error, "Error linking shader\n"); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
printf("%s(), error loading shader\n", __FUNCTION__); |
|
|
|
LOGF(Error, "error loading shader\n"); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -89,7 +91,7 @@ shader_program* |
|
|
|
getFreeShader(GLContext* gl_ctx) |
|
|
|
getFreeShader(GLContext* gl_ctx) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (gl_ctx->num_shaders >= gl_ctx->max_shaders) { |
|
|
|
if (gl_ctx->num_shaders >= gl_ctx->max_shaders) { |
|
|
|
printf("%s(), GLContext->shaders full\n", __FUNCTION__); |
|
|
|
LOGF(Error, "GLContext->shaders full\n"); |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -119,7 +121,7 @@ getShaderByName(const char* name, GLContext* gl_ctx) |
|
|
|
return &gl_ctx->shaders[i]; |
|
|
|
return &gl_ctx->shaders[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
printf("%s(), shader not found, %s\n", __FUNCTION__, name); |
|
|
|
LOGF(Error, "shader not found, %s\n", name); |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -131,7 +133,7 @@ getShaderByID(GLContext* gl_ctx, GLuint prog_id) |
|
|
|
return &gl_ctx->shaders[i]; |
|
|
|
return &gl_ctx->shaders[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
printf("%s(), shader not found, %d\n", __FUNCTION__, prog_id); |
|
|
|
LOGF(Error, "shader not found, %d\n", prog_id); |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -158,7 +160,7 @@ getGLTexture(GLContext* gl_ctx, util_image* diffuse_img) |
|
|
|
if (loadGLTexture(diffuse_img, glt->id)) |
|
|
|
if (loadGLTexture(diffuse_img, glt->id)) |
|
|
|
return glt; |
|
|
|
return glt; |
|
|
|
|
|
|
|
|
|
|
|
printf("%s(), Error, unable to load texture\n", __FUNCTION__); |
|
|
|
LOGF(Error, "Error, unable to load texture\n"); |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -221,8 +223,7 @@ getVertexAttribByName(shader_program* shader, const char* name) |
|
|
|
return &shader->vertex_attribs[i]; |
|
|
|
return &shader->vertex_attribs[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
printf("%s, attribute: %s, not found on shader: %s\n", |
|
|
|
LOGF(Debug, "attribute: %s, not found on shader: %s\n", name, shader->name); |
|
|
|
__FUNCTION__, name, shader->name); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -338,7 +339,7 @@ getFreeGLTexture(GLContext* gl_ctx) |
|
|
|
if (gl_ctx->num_textures < gl_ctx->max_textures) |
|
|
|
if (gl_ctx->num_textures < gl_ctx->max_textures) |
|
|
|
return &gl_ctx->textures[gl_ctx->num_textures++]; |
|
|
|
return &gl_ctx->textures[gl_ctx->num_textures++]; |
|
|
|
|
|
|
|
|
|
|
|
printf("%s(), no free textures\n", __FUNCTION__); |
|
|
|
LOGF(Error, "no free textures\n"); |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -387,8 +388,7 @@ compileAndLinkShader(shader_program* shader, |
|
|
|
return (is_linked == GL_TRUE); |
|
|
|
return (is_linked == GL_TRUE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: make another logging macro for printf style logging
|
|
|
|
LOGF(Error, "empty shader source\n"); |
|
|
|
printf("%s(), empty shader source\n", __FUNCTION__); |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -415,7 +415,7 @@ getGLTypeSize(GLenum e) |
|
|
|
case GL_FLOAT_VEC4: return 4 * sizeof(GLfloat); |
|
|
|
case GL_FLOAT_VEC4: return 4 * sizeof(GLfloat); |
|
|
|
case GL_FLOAT_MAT4: return 16 * sizeof(GLfloat); |
|
|
|
case GL_FLOAT_MAT4: return 16 * sizeof(GLfloat); |
|
|
|
default: |
|
|
|
default: |
|
|
|
printf("%s(), unknown GLenum\n", __FUNCTION__); |
|
|
|
LOGF(Error, "unknown GLenum\n"); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -430,7 +430,7 @@ getGLTypeSizeStd140(GLenum e) |
|
|
|
case GL_FLOAT_VEC4: return 4 * sizeof(GLfloat); |
|
|
|
case GL_FLOAT_VEC4: return 4 * sizeof(GLfloat); |
|
|
|
case GL_FLOAT_MAT4: return 16 * sizeof(GLfloat); |
|
|
|
case GL_FLOAT_MAT4: return 16 * sizeof(GLfloat); |
|
|
|
default: |
|
|
|
default: |
|
|
|
printf("%s(), unknown GLenum\n", __FUNCTION__); |
|
|
|
LOGF(Error, "unknown GLenum\n"); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -502,16 +502,16 @@ initCTXSizes(GLContext* gl_ctx) |
|
|
|
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &gl_ctx->max_vertex_attribs); |
|
|
|
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &gl_ctx->max_vertex_attribs); |
|
|
|
|
|
|
|
|
|
|
|
#if 1 |
|
|
|
#if 1 |
|
|
|
printf("%s(), context size info set\n", __FUNCTION__); |
|
|
|
LOGF(Debug, "context size info set\n"); |
|
|
|
printf("GL_MAX_UNIFORM_BUFFER_BINDINGS: %d\n", |
|
|
|
LOGF(Debug, "GL_MAX_UNIFORM_BUFFER_BINDINGS: %d\n", |
|
|
|
gl_ctx->max_binding_points); |
|
|
|
gl_ctx->max_binding_points); |
|
|
|
printf("GL_MAX_VERTEX_UNIFORM_BLOCKS: %d\n", |
|
|
|
LOGF(Debug, "GL_MAX_VERTEX_UNIFORM_BLOCKS: %d\n", |
|
|
|
gl_ctx->max_vertex_blocks); |
|
|
|
gl_ctx->max_vertex_blocks); |
|
|
|
printf("GL_MAX_FRAGMENT_UNIFORM_BLOCKS: %d\n", |
|
|
|
LOGF(Debug, "GL_MAX_FRAGMENT_UNIFORM_BLOCKS: %d\n", |
|
|
|
gl_ctx->max_fragment_blocks); |
|
|
|
gl_ctx->max_fragment_blocks); |
|
|
|
printf("GL_MAX_UNIFORM_BLOCK_SIZE: %d\n", |
|
|
|
LOGF(Debug, "GL_MAX_UNIFORM_BLOCK_SIZE: %d\n", |
|
|
|
gl_ctx->max_ublock_size); |
|
|
|
gl_ctx->max_ublock_size); |
|
|
|
printf("GL_MAX_VERTEX_ATTRIBS: %d\n", gl_ctx->max_vertex_attribs); |
|
|
|
LOGF(Debug, "GL_MAX_VERTEX_ATTRIBS: %d\n", gl_ctx->max_vertex_attribs); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -526,7 +526,7 @@ ctxGetUniformBlockBinding(GLContext* gl_ctx, const char* name) |
|
|
|
return ubo.binding_idx; |
|
|
|
return ubo.binding_idx; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
printf("%s(), no buffer found with name: %s\n", __FUNCTION__, name); |
|
|
|
LOGF(Error, "no buffer found with name: %s\n", name); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -580,7 +580,7 @@ getNumAttribComponents(GLenum type) |
|
|
|
case GL_FLOAT_VEC3: return 3; |
|
|
|
case GL_FLOAT_VEC3: return 3; |
|
|
|
case GL_FLOAT_VEC2: return 2; |
|
|
|
case GL_FLOAT_VEC2: return 2; |
|
|
|
default: |
|
|
|
default: |
|
|
|
printf("%s(), unknown GLenum\n", __FUNCTION__); |
|
|
|
LOGF(Error, "unknown GLenum\n"); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -592,7 +592,7 @@ getAttribComponentType(GLenum type) |
|
|
|
case GL_FLOAT_VEC3: return GL_FLOAT; |
|
|
|
case GL_FLOAT_VEC3: return GL_FLOAT; |
|
|
|
case GL_FLOAT_VEC2: return GL_FLOAT; |
|
|
|
case GL_FLOAT_VEC2: return GL_FLOAT; |
|
|
|
default: |
|
|
|
default: |
|
|
|
printf("%s(), unknown GLenum\n", __FUNCTION__); |
|
|
|
LOGF(Error, "unknown GLenum\n"); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -639,7 +639,7 @@ parseShader(MemoryArena* arena, GLContext* gl_ctx, shader_program* s) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
printf("%s(), Error parsing shader\n", __FUNCTION__); |
|
|
|
LOGF(Error, "%Error parsing shader\n"); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|