Browse Source

replace instances of printf with new logging macro

main
cinnaboot 5 years ago
parent
commit
2461e499ee
  1. 16
      src/GLDebug.h
  2. 2
      src/asset.cpp
  3. 3
      src/entity.cpp
  4. 48
      src/shader.cpp
  5. 9
      src/tangerine.cpp
  6. 4
      src/tangerine.h
  7. 5
      src/util.h

16
src/GLDebug.h

@ -87,8 +87,8 @@ openglDebugCallback(GLenum source,
void void
dumpShader(GLuint prog_id) dumpShader(GLuint prog_id)
{ {
printf("------------------------\n"); LOGF(Debug, "------------------------\n");
printf("%s(), dumping shader info, program id: %d\n", LOGF(Debug, "%s(), dumping shader info, program id: %d\n",
__FUNCTION__, prog_id); __FUNCTION__, prog_id);
GLint active_uniforms; GLint active_uniforms;
@ -101,9 +101,9 @@ dumpShader(GLuint prog_id)
glGetProgramiv(prog_id, GL_ACTIVE_UNIFORM_BLOCKS, &active_uniform_blocks); glGetProgramiv(prog_id, GL_ACTIVE_UNIFORM_BLOCKS, &active_uniform_blocks);
glGetProgramiv(prog_id, GL_ACTIVE_ATTRIBUTES, &active_attribs); glGetProgramiv(prog_id, GL_ACTIVE_ATTRIBUTES, &active_attribs);
printf("active uniforms: %d\n", active_uniforms); LOGF(Debug, "active uniforms: %d\n", active_uniforms);
printf("active uniform blocks: %d\n", active_uniform_blocks); LOGF(Debug, "active uniform blocks: %d\n", active_uniform_blocks);
printf("active attributes: %d\n", active_attribs); LOGF(Debug, "active attributes: %d\n", active_attribs);
GLchar uni_name[256]; GLchar uni_name[256];
GLsizei length; GLsizei length;
@ -113,18 +113,18 @@ dumpShader(GLuint prog_id)
for (int i = 0; i < active_uniforms; i++) { for (int i = 0; i < active_uniforms; i++) {
glGetActiveUniform(prog_id, i, sizeof(uni_name), glGetActiveUniform(prog_id, i, sizeof(uni_name),
&length, &size, &type, uni_name); &length, &size, &type, uni_name);
printf("uniform idx: %d, type: %s, name: %s \n", LOGF(Debug, "uniform idx: %d, type: %s, name: %s \n",
i, glEnumToString(type), uni_name); i, glEnumToString(type), uni_name);
} }
for (int i = 0; i < active_attribs; i++) { for (int i = 0; i < active_attribs; i++) {
glGetActiveAttrib(prog_id, i, sizeof(uni_name), glGetActiveAttrib(prog_id, i, sizeof(uni_name),
&length, &size, &type, uni_name); &length, &size, &type, uni_name);
printf("attribute idx: %d, type: %s, name: %s \n", LOGF(Debug, "attribute idx: %d, type: %s, name: %s \n",
i, glEnumToString(type), uni_name); i, glEnumToString(type), uni_name);
} }
printf("------------------------\n"); LOGF(Debug, "------------------------\n");
} }
#endif // ifdef GL_DEBUG_IMPLEMENTATION #endif // ifdef GL_DEBUG_IMPLEMENTATION

2
src/asset.cpp

@ -80,7 +80,7 @@ getFreeTexture(Assets* assets)
if (assets->num_textures < assets->max_textures) if (assets->num_textures < assets->max_textures)
return &assets->textures[assets->num_textures++]; return &assets->textures[assets->num_textures++];
printf("%s(), no free textures\n", __FUNCTION__); LOGF(Error, "no free textures\n");
return nullptr; return nullptr;
} }

3
src/entity.cpp

@ -1,6 +1,7 @@
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include "dumbLog.h"
#include "entity.h" #include "entity.h"
@ -32,7 +33,7 @@ initEntity(Entity* e,
attrib_mappings); attrib_mappings);
if (glm->vao_id == 0) { if (glm->vao_id == 0) {
printf("%s(), error initializing entity\n", __FUNCTION__); LOGF(Error, "error initializing entity\n");
return false; return false;
} }
} }

48
src/shader.cpp

@ -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;
} }

9
src/tangerine.cpp

@ -1,6 +1,5 @@
#include <cassert> #include <cassert>
#include <cstdio> // NOTE: printf, TODO: can remove when we implement LOGF()
#include "tangerine.h" #include "tangerine.h"
#define UTIL_IMPLEMENTATION #define UTIL_IMPLEMENTATION
@ -26,6 +25,7 @@ initRenderState(u32 max_models,
u32 max_render_groups, u32 max_render_groups,
u32 max_ubos) u32 max_ubos)
{ {
LOGF(Info, "Initializing Renderer\n");
RenderState* rs = UTIL_ALLOC(1, RenderState); RenderState* rs = UTIL_ALLOC(1, RenderState);
if (rs) { if (rs) {
@ -93,8 +93,7 @@ initRenderGroup(RenderGroup* rg,
void void
freeRenderGroup(RenderGroup* rg, MemoryArena* arena) freeRenderGroup(RenderGroup* rg, MemoryArena* arena)
{ {
printf("%s(), should probably look into freeing arena memory?\n", LOGF(Info, "should probably look into freeing arena memory?\n");
__FUNCTION__);
assert(0); assert(0);
} }
@ -104,7 +103,7 @@ getFreeRenderGroup(RenderState* rs)
if (rs->num_render_groups < rs->max_render_groups) if (rs->num_render_groups < rs->max_render_groups)
return &rs->render_groups[rs->num_render_groups++]; return &rs->render_groups[rs->num_render_groups++];
printf("%s(), no free render group\n", __FUNCTION__); LOGF(Error, "no free render group\n");
return nullptr; return nullptr;
} }
@ -114,7 +113,7 @@ getFreeEntity(RenderGroup* rg)
if (rg->num_entities < rg->max_entities) if (rg->num_entities < rg->max_entities)
return &rg->entities[rg->num_entities++]; return &rg->entities[rg->num_entities++];
printf("%s(), render group full\n", __FUNCTION__); LOGF(Error, "render group full\n");
return nullptr; return nullptr;
} }

4
src/tangerine.h

@ -14,8 +14,6 @@
/* /*
* === TODO: === * === TODO: ===
* - add a LOGF macro for printf style logging
* - replace instances of printf
* - rename data structures to be in the new format, eg) UpperCaseStyleNames * - rename data structures to be in the new format, eg) UpperCaseStyleNames
* - rename instances of 'model_xform' that refer to a mesh node to something * - rename instances of 'model_xform' that refer to a mesh node to something
* like node_xform. model_xform should be reserved for the entity node * like node_xform. model_xform should be reserved for the entity node
@ -45,6 +43,8 @@
* - pass result GLTexture to loadGLMesh() * - pass result GLTexture to loadGLMesh()
* - update loadScene function with textured models, and test texture loading * - update loadScene function with textured models, and test texture loading
* - work on cleaner interface for initEntity and loadScene... * - work on cleaner interface for initEntity and loadScene...
* - add a LOGF macro for printf style logging
* - replace instances of printf
*/ */

5
src/util.h

@ -7,6 +7,7 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include "dumbLog.h"
#include "types.h" #include "types.h"
@ -138,7 +139,7 @@ utilAllocateCStr(const char* str, u32 max_len)
u32 len = strlen(str) + 1; u32 len = strlen(str) + 1;
if (len > max_len) { if (len > max_len) {
printf("%s(), %s , longer than %i\n", __FUNCTION__, str, max_len); LOGF(Error, "%s , longer than %i\n", str, max_len);
return nullptr; return nullptr;
} }
@ -153,7 +154,7 @@ utilSafeFree(void* p)
if (p) if (p)
free(p); free(p);
else else
printf("%s(), free called on nullptr\n", __FUNCTION__); LOGF(Error, "free called on nullptr\n");
} }
#endif #endif

Loading…
Cancel
Save