leocad/common/debug.cpp

92 lines
1.8 KiB
C++
Raw Normal View History

#include "lc_global.h"
2011-09-07 23:06:51 +02:00
#include "opengl.h"
#include "debug.h"
#ifdef LC_DEBUG
#define LC_MAX_DEBUG_LINES 100
2012-06-29 23:47:22 +02:00
struct LC_DEBUG_LINE
2011-09-07 23:06:51 +02:00
{
2012-06-29 23:47:22 +02:00
lcVector3 pt1;
lcVector3 pt2;
lcVector3 color;
};
2011-09-07 23:06:51 +02:00
static LC_DEBUG_LINE DebugLines[LC_MAX_DEBUG_LINES];
static int NumDebugLines;
void ClearDebugLines()
{
NumDebugLines = 0;
}
2012-06-29 23:47:22 +02:00
void AddDebugLine(const lcVector3& pt1, const lcVector3& pt2, const lcVector3& Color)
2011-09-07 23:06:51 +02:00
{
if (NumDebugLines == LC_MAX_DEBUG_LINES-1)
return;
DebugLines[NumDebugLines].pt1 = pt1;
DebugLines[NumDebugLines].pt2 = pt2;
DebugLines[NumDebugLines].color = Color;
NumDebugLines++;
}
#define LC_MAX_DEBUG_QUADS 100
2012-06-29 23:47:22 +02:00
struct LC_DEBUG_QUAD
2011-09-07 23:06:51 +02:00
{
2012-06-29 23:47:22 +02:00
lcVector3 pt1;
lcVector3 pt2;
lcVector3 pt3;
lcVector3 pt4;
lcVector4 color;
};
2011-09-07 23:06:51 +02:00
static LC_DEBUG_QUAD DebugQuads[LC_MAX_DEBUG_QUADS];
static int NumDebugQuads;
void ClearDebugQuads()
{
NumDebugQuads = 0;
}
2012-06-29 23:47:22 +02:00
void AddDebugQuad(const lcVector3& pt1, const lcVector3& pt2, const lcVector3& pt3, const lcVector3& pt4, const lcVector4& Color)
2011-09-07 23:06:51 +02:00
{
if (NumDebugQuads == LC_MAX_DEBUG_QUADS-1)
return;
DebugQuads[NumDebugQuads].pt1 = pt1;
DebugQuads[NumDebugQuads].pt2 = pt2;
DebugQuads[NumDebugQuads].pt3 = pt3;
DebugQuads[NumDebugQuads].pt4 = pt4;
DebugQuads[NumDebugQuads].color = Color;
NumDebugQuads++;
}
void RenderDebugPrimitives()
{
for (int i = 0; i < NumDebugLines; i++)
{
2013-01-11 22:02:55 +01:00
glVertexPointer(3, GL_FLOAT, 0, &DebugLines[i].pt1);
2011-09-07 23:06:51 +02:00
glColor3fv((float*)&DebugLines[i].color);
2013-01-11 22:02:55 +01:00
glDrawArrays(GL_LINES, 0, 2);
2011-09-07 23:06:51 +02:00
}
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
for (int i = 0; i < NumDebugQuads; i++)
{
2013-01-11 22:02:55 +01:00
glVertexPointer(3, GL_FLOAT, 0, &DebugQuads[i].pt1);
2011-09-07 23:06:51 +02:00
glColor4fv((float*)&DebugQuads[i].color);
2013-01-11 22:02:55 +01:00
glDrawArrays(GL_QUADS, 0, 4);
2011-09-07 23:06:51 +02:00
}
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
}
#endif // LC_DEBUG