Update debug display for render groups

This commit is contained in:
Doyle Thai 2016-09-23 21:15:22 +10:00
parent 82421ca64c
commit 85b757aaa7
4 changed files with 53 additions and 17 deletions

View File

@ -8,6 +8,7 @@
typedef struct DebugState
{
b32 init;
Font font;
i32 *callCount;
f32 stringLineGap;
@ -76,9 +77,9 @@ inline char *debug_entityattack_string(i32 val)
void debug_init(MemoryArena *arena, v2 windowSize, Font font)
{
GLOBAL_debug.font = font;
GLOBAL_debug.callCount = PLATFORM_MEM_ALLOC(arena, debugcallcount_num, i32);
GLOBAL_debug.stringLineGap = CAST(f32)font.verticalSpacing;
GLOBAL_debug.font = font;
GLOBAL_debug.callCount = PLATFORM_MEM_ALLOC(arena, debugcount_num, i32);
GLOBAL_debug.stringLineGap = CAST(f32) font.verticalSpacing;
/* Init debug string stack */
GLOBAL_debug.numDebugStrings = 0;
@ -98,6 +99,8 @@ void debug_init(MemoryArena *arena, v2 windowSize, Font font)
f32 consoleXPos = font.maxSize.w * 20;
f32 consoleYPos = windowSize.h - 1.8f * GLOBAL_debug.stringLineGap;
GLOBAL_debug.initialConsoleP = V2(consoleXPos, consoleYPos);
GLOBAL_debug.init = TRUE;
}
void debug_recursivePrintXmlTree(XmlNode *root, i32 levelsDeep)
@ -130,15 +133,17 @@ void debug_recursivePrintXmlTree(XmlNode *root, i32 levelsDeep)
}
}
void debug_callCountIncrement(i32 id)
void debug_countIncrement(i32 id)
{
ASSERT(id < debugcallcount_num);
if (GLOBAL_debug.init == FALSE) return;
ASSERT(id < debugcount_num);
GLOBAL_debug.callCount[id]++;
}
void debug_clearCallCounter()
void debug_clearCounter()
{
for (i32 i = 0; i < debugcallcount_num; i++)
for (i32 i = 0; i < debugcount_num; i++)
GLOBAL_debug.callCount[i] = 0;
}
@ -471,8 +476,26 @@ void debug_drawUi(GameState *state, f32 dt)
DEBUG_PUSH_STRING("== State Properties == ");
DEBUG_PUSH_VAR("FreeEntityIndex: %d", world->freeEntityIndex, "i32");
DEBUG_PUSH_VAR("glDrawArray Calls: %d",
GLOBAL_debug.callCount[debugcallcount_drawArrays], "i32");
DEBUG_PUSH_VAR("GLDrawArray Calls: %d",
GLOBAL_debug.callCount[debugcount_drawArrays], "i32");
DEBUG_PUSH_VAR("PlatformMemAlloc Calls: %d",
GLOBAL_debug.callCount[debugcount_platformMemAlloc], "i32");
DEBUG_PUSH_VAR("PlatformMemFree Calls: %d",
GLOBAL_debug.callCount[debugcount_platformMemFree], "i32");
i32 vertexesUsed = GLOBAL_debug.callCount[debugcount_numVertex];
i32 vertexesAvail =
(ARRAY_COUNT(state->renderer.groups) * state->renderer.groupCapacity);
i32 vertexesLeft = vertexesAvail - vertexesUsed;
v2 vertexData = V2i(vertexesUsed, vertexesAvail);
DEBUG_PUSH_VAR("Vertexes Rendered: %1.0f/%1.0f", vertexData, "v2");
DEBUG_PUSH_VAR("Vertexes Left: %d", vertexesLeft, "i32");
i32 groupsUsed = GLOBAL_debug.callCount[debugcount_renderGroups];
i32 groupsAvail = ARRAY_COUNT(state->renderer.groups);
v2 groupData = V2i(groupsUsed, groupsAvail);
DEBUG_PUSH_VAR("Render Groups Used: %1.0f/%1.0f", groupData, "v2");
DEBUG_PUSH_VAR("Mouse Pos: %06.2f, %06.2f", state->input.mouseP, "v2");
i32 debug_bAllocated = state->arena.bytesAllocated;
@ -512,5 +535,5 @@ void debug_drawUi(GameState *state, f32 dt)
updateAndRenderDebugStack(&state->renderer, &state->arena, dt);
renderConsole(&state->renderer, &state->arena);
debug_clearCallCounter();
debug_clearCounter();
}

View File

@ -4,12 +4,14 @@
#include "Dengine/Platform.h"
#include "Dengine/MemoryArena.h"
#include "Dengine/Debug.h"
void platform_memoryFree(MemoryArena *arena, void *data, i32 numBytes)
{
if (data) free(data);
#ifdef DENGINE_DEBUG
debug_countIncrement(debugcount_platformMemFree);
arena->bytesAllocated -= numBytes;
#endif
}
@ -19,6 +21,7 @@ void *platform_memoryAlloc(MemoryArena *arena, i32 numBytes)
void *result = calloc(1, numBytes);
#ifdef DENGINE_DEBUG
debug_countIncrement(debugcount_platformMemAlloc);
if (result)
arena->bytesAllocated += numBytes;
#endif

View File

@ -16,13 +16,16 @@ INTERNAL void addVertexToRenderGroup(Renderer *renderer, Texture *tex, v4 color,
#ifdef DENGINE_DEBUG
ASSERT(numVertexes > 0);
for (i32 i = 0; i < numVertexes; i++)
debug_countIncrement(debugcount_numVertex);
#endif
/* Find vacant/matching render group */
RenderGroup *targetGroup = NULL;
for (i32 i = 0; i < ARRAY_COUNT(renderer->groups); i++)
{
RenderGroup *group = &renderer->groups[i];
RenderGroup *group = &renderer->groups[i];
b32 groupIsValid = FALSE;
if (group->tex)
{
@ -44,6 +47,9 @@ INTERNAL void addVertexToRenderGroup(Renderer *renderer, Texture *tex, v4 color,
group->tex = tex;
group->color = color;
#ifdef DENGINE_DEBUG
debug_countIncrement(debugcount_renderGroups);
#endif
}
if (groupIsValid)
@ -269,7 +275,7 @@ INTERNAL void renderGLBufferedData(Renderer *renderer, RenderGroup *renderGroup)
glDrawArrays(GL_TRIANGLE_STRIP, 0, renderer->numVertexesInVbo);
#ifdef DENGINE_DEBUG
debug_callCountIncrement(debugcallcount_drawArrays);
debug_countIncrement(debugcount_drawArrays);
#endif
/* Unbind */

View File

@ -10,10 +10,14 @@ typedef struct GameState GameState;
typedef struct MemoryArena MemoryArena;
#define INVALID_CODE_PATH 0
enum DebugCallCount
enum DebugCount
{
debugcallcount_drawArrays,
debugcallcount_num,
debugcount_drawArrays,
debugcount_platformMemAlloc,
debugcount_platformMemFree,
debugcount_numVertex,
debugcount_renderGroups,
debugcount_num,
};
void debug_init(MemoryArena *arena, v2 windowSize, Font font);
@ -21,8 +25,8 @@ void debug_init(MemoryArena *arena, v2 windowSize, Font font);
#define DEBUG_RECURSIVE_PRINT_XML_TREE(sig) debug_recursivePrintXmlTree(sig, 1)
void debug_recursivePrintXmlTree(XmlNode *root, i32 levelsDeep);
void debug_callCountIncrement(enum DebugCallCount id);
void debug_clearCallCounter();
void debug_countIncrement(enum DebugCount id);
void debug_clearCounter();
#define DEBUG_LOG(string) debug_consoleLog(string, __FILE__, __LINE__);
void debug_consoleLog(char *string, char *file, int lineNum);