Skip to content

Commit

Permalink
v2.2.2 - removed debug data from config
Browse files Browse the repository at this point in the history
  • Loading branch information
inanevin committed Oct 12, 2024
1 parent f974db6 commit aa372f6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 90 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ add_library(Lina::VG ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_compile_definitions(${PROJECT_NAME} PUBLIC LINAVG_VERSION_MAJOR=2)
target_compile_definitions(${PROJECT_NAME} PUBLIC LINAVG_VERSION_MINOR=2)
target_compile_definitions(${PROJECT_NAME} PUBLIC LINAVG_VERSION_PATCH=1)
target_compile_definitions(${PROJECT_NAME} PUBLIC LINAVG_VERSION_PATCH=2)

#--------------------------------------------------------------------
# Subdirectories & linking
Expand Down
43 changes: 43 additions & 0 deletions Example/include/Backends/GL/GLBackend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ struct Texture
static unsigned int s_displayPosY;
static unsigned int s_displayWidth;
static unsigned int s_displayHeight;
static bool s_debugWireframe;
static int s_debugTriCount;
static int s_debugVtxCount;
static int s_debugDrawCalls;
static float s_debugZoom;
static Vec2 s_debugOffset;

SDFMaterial* GetSDFMaterialPointer(unsigned int index)
{
Expand All @@ -129,4 +135,41 @@ struct Texture
LINAVG_VEC<SDFMaterial> m_demoSDFMaterials;
};


/// <summary>
/// For debugging purposes, sets to draw polygon/wireframe mode.
/// Unused while using custom backends, you can fill with your own data.
/// </summary>
bool debugWireframeEnabled = false;

/// <summary>
/// For debugging purposes, current count of the trianlges being drawn.
/// Unused while using custom backends, you can fill with your own data.
/// </summary>
int debugCurrentTriangleCount = 0;

/// <summary>
/// For debugging purposes, current count of the vertices sent to backend buffers.
/// Unused while using custom backends, you can fill with your own data.
/// </summary>
int debugCurrentVertexCount = 0;

/// <summary>
/// For debugging purposes, current draw calls.
/// Unused while using custom backends, you can fill with your own data.
/// </summary>
int debugCurrentDrawCalls = 0;

/// <summary>
/// For debugging purposes, zooms the rendering ortho projection.
/// Unused while using custom backends, you can fill with your own data.
/// </summary>
float debugOrthoProjectionZoom = 1.0f;

/// <summary>
/// For debugging purposes, offsets the rendering ortho projection.
/// Unused while using custom backends, you can fill with your own data.
/// </summary>
Vec2 debugOrthoOffset = Vec2(0.0f, 0.0f);

} // namespace LinaVG::Examples
64 changes: 18 additions & 46 deletions Example/src/Backends/GL/GLBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ namespace LinaVG::Examples
unsigned int GLBackend::s_displayPosY = 0;
unsigned int GLBackend::s_displayWidth = 0;
unsigned int GLBackend::s_displayHeight = 0;
static bool GLBackend::s_debugWireframe = 0;
static int GLBackend::s_debugTriCount = 0;
static int GLBackend::s_debugVtxCount = 0;
static int GLBackend::s_debugDrawCalls = 0;
static float GLBackend::s_debugZoom = 1.0f;
static Vec2 GLBackend::s_debugOffset = Vec2(0.0f, 0.0f);

#define FONT_ATLAS_WIDTH 2048
#define FONT_ATLAS_HEIGHT 2048
Expand Down Expand Up @@ -178,9 +184,9 @@ namespace LinaVG::Examples

void GLBackend::StartFrame()
{
Config.debugCurrentDrawCalls = 0;
Config.debugCurrentTriangleCount = 0;
Config.debugCurrentVertexCount = 0;
s_debugDrawCalls = 0;
s_debugTriCount = 0;
s_debugVtxCount = 0;

// Save GL state
SaveAPIState();
Expand All @@ -194,7 +200,7 @@ namespace LinaVG::Examples
glDisable(GL_STENCIL_TEST);
glEnable(GL_SCISSOR_TEST);

if (Config.debugWireframeEnabled)
if (s_debugWireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
else
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
Expand All @@ -216,17 +222,17 @@ namespace LinaVG::Examples
float R = static_cast<float>(s_displayPosX + s_displayWidth);
float T = static_cast<float>(s_displayPosY);
float B = static_cast<float>(s_displayPosY + s_displayHeight);
const float zoom = Config.debugOrthoProjectionZoom;
const float zoom = s_debugZoom;

L *= zoom;
R *= zoom;
T *= zoom;
B *= zoom;

L += Config.debugOrthoOffset.x;
R += Config.debugOrthoOffset.x;
T += Config.debugOrthoOffset.y;
B += Config.debugOrthoOffset.y;
L += s_debugOffset.x;
R += s_debugOffset.x;
T += s_debugOffset.y;
B += s_debugOffset.y;

m_backendData.m_proj[0][0] = 2.0f / (R - L);
m_backendData.m_proj[0][1] = 0.0f;
Expand Down Expand Up @@ -309,45 +315,11 @@ namespace LinaVG::Examples

glBindBuffer(GL_ARRAY_BUFFER, 0);
glDrawElements(GL_TRIANGLES, (GLsizei)buf->indexBuffer.m_size, sizeof(Index) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, 0);
Config.debugCurrentDrawCalls++;
Config.debugCurrentTriangleCount += int((float)buf->indexBuffer.m_size / 3.0f);
Config.debugCurrentVertexCount += buf->vertexBuffer.m_size;
s_debugDrawCalls++;
s_debugTriCount += int((float)buf->indexBuffer.m_size / 3.0f);
s_debugVtxCount += buf->vertexBuffer.m_size;
}
/*
void GLBackend::DrawText(DrawBufferText* buf)
{
if (m_backendData.m_skipDraw)
return;
SetScissors(buf->clipPosX, buf->clipPosY, buf->clipSizeX, buf->clipSizeY);
ShaderData& data = m_backendData.m_simpleTextShaderData;
glUseProgram(data.m_handle);
glUniformMatrix4fv(data.m_uniformMap["proj"], 1, GL_FALSE, &m_backendData.m_proj[0][0]);
glUniform1i(data.m_uniformMap["isSDF"], buf->isSDF);
glUniform1i(data.m_uniformMap["diffuse"], 0);
if(buf->isSDF)
{
}

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fontTexture);
glBindBuffer(GL_ARRAY_BUFFER, m_backendData.m_vbo);
glBufferData(GL_ARRAY_BUFFER, buf->vertexBuffer.m_size * sizeof(Vertex), (const GLvoid*)buf->vertexBuffer.begin(), GL_STREAM_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_backendData.m_ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, buf->indexBuffer.m_size * sizeof(Index), (const GLvoid*)buf->indexBuffer.begin(), GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDrawElements(GL_TRIANGLES, (GLsizei)buf->indexBuffer.m_size, sizeof(Index) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, 0);
Config.debugCurrentDrawCalls++;
Config.debugCurrentTriangleCount += int((float)buf->indexBuffer.m_size / 3.0f);
Config.debugCurrentVertexCount += buf->vertexBuffer.m_size;
}*/

void GLBackend::SetScissors(BackendHandle x, BackendHandle y, BackendHandle width, BackendHandle height)
{
if (width == 0 || height == 0)
Expand Down
6 changes: 3 additions & 3 deletions Example/src/DemoScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1312,9 +1312,9 @@ namespace LinaVG
if (m_rotate)
m_rotateAngle += ExampleApp::Get()->GetFrameTime() * 20;

m_drawCount = Config.debugCurrentDrawCalls;
m_triangleCount = Config.debugCurrentTriangleCount;
m_vertexCount = Config.debugCurrentVertexCount;
m_drawCount = GLBackend::s_debugDrawCalls;
m_triangleCount = GLBackend::s_debugTriCount;
m_vertexCount = GLBackend::s_debugVtxCount;
}
} // namespace Examples
} // namespace LinaVG
8 changes: 4 additions & 4 deletions Example/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ namespace LinaVG

void ExampleApp::OnHorizontalKeyCallback(float input)
{
LinaVG::Config.debugOrthoOffset.x += input * m_deltaTime * 1000;
GLBackend::s_debugOffset.x += input * m_deltaTime * 1000;
}

void ExampleApp::OnVerticalKeyCallback(float input)
{
LinaVG::Config.debugOrthoOffset.y -= input * m_deltaTime * 1000;
GLBackend::s_debugOffset.y -= input * m_deltaTime * 1000;
}

void ExampleApp::OnNumKeyCallback(int key)
Expand All @@ -213,7 +213,7 @@ namespace LinaVG

void ExampleApp::OnFCallback()
{
LinaVG::Config.debugWireframeEnabled = !LinaVG::Config.debugWireframeEnabled;
GLBackend::s_debugWireframe = !GLBackend::s_debugWireframe;
}

void ExampleApp::OnCCallback()
Expand All @@ -229,7 +229,7 @@ namespace LinaVG

void ExampleApp::OnMouseScrollCallback(float val)
{
LinaVG::Config.debugOrthoProjectionZoom -= val * m_deltaTime * 10;
GLBackend::s_debugZoom -= val * m_deltaTime * 10;
}

void ExampleApp::OnWindowResizeCallback(int width, int height)
Expand Down
36 changes: 0 additions & 36 deletions include/LinaVG/Core/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,42 +653,6 @@ namespace LinaVG
/// </summary>
std::function<void(const LINAVG_STRING&)> logCallback;

/// <summary>
/// For debugging purposes, sets to draw polygon/wireframe mode.
/// Unused while using custom backends, you can fill with your own data.
/// </summary>
bool debugWireframeEnabled = false;

/// <summary>
/// For debugging purposes, current count of the trianlges being drawn.
/// Unused while using custom backends, you can fill with your own data.
/// </summary>
int debugCurrentTriangleCount = 0;

/// <summary>
/// For debugging purposes, current count of the vertices sent to backend buffers.
/// Unused while using custom backends, you can fill with your own data.
/// </summary>
int debugCurrentVertexCount = 0;

/// <summary>
/// For debugging purposes, current draw calls.
/// Unused while using custom backends, you can fill with your own data.
/// </summary>
int debugCurrentDrawCalls = 0;

/// <summary>
/// For debugging purposes, zooms the rendering ortho projection.
/// Unused while using custom backends, you can fill with your own data.
/// </summary>
float debugOrthoProjectionZoom = 1.0f;

/// <summary>
/// For debugging purposes, offsets the rendering ortho projection.
/// Unused while using custom backends, you can fill with your own data.
/// </summary>
Vec2 debugOrthoOffset = Vec2(0.0f, 0.0f);

/// <summary>
/// Enabling caching allows faster text rendering in exchange for more memory consumption.
/// Note: dynamic texts you render will not benefit from this.
Expand Down

0 comments on commit aa372f6

Please sign in to comment.