Annotate the OpenGL command stream better. Now using the new KHR_debug extension with

debug groups. Some functionality commented out until apitrace fixes a bug upstream.
For this functionality, GLEW version 1.10 or higher is required.
master
per 2014-01-25 13:39:07 +01:00
parent 55bf05d085
commit 9a6fdec2b5
6 changed files with 88 additions and 35 deletions

View File

@ -134,8 +134,6 @@ void pie_Skybox_Shutdown()
void pie_DrawSkybox(float scale)
{
GL_DEBUG("Drawing skybox");
glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_FOG_BIT);
// no use in updating the depth buffer
glDepthMask(GL_FALSE);

View File

@ -47,6 +47,8 @@
#include <vector>
#include <algorithm>
#include <GL/glext.h>
/* global used to indicate preferred internal OpenGL format */
int wz_texture_compression = 0;
@ -54,6 +56,9 @@ int wz_texture_compression = 0;
#ifndef GLEW_ARB_timer_query
#define GLEW_ARB_timer_query false
#endif
#ifndef GLEW_KHR_debug
#define GLEW_KHR_debug false
#endif
static bool bBackDrop = false;
static char screendump_filename[PATH_MAX];
@ -71,6 +76,7 @@ static int preview_width = 0, preview_height = 0;
static Vector2i player_pos[MAX_PLAYERS];
static bool mappreview = false;
OPENGL_DATA opengl;
static bool khr_debug = false;
/* Initialise the double buffered display */
bool screenInitialise()
@ -98,6 +104,15 @@ bool screenInitialise()
addDumpInfo(opengl.version);
debug(LOG_3D, "%s", opengl.version);
ssprintf(opengl.GLEWversion, "GLEW Version: %s", glewGetString(GLEW_VERSION));
if (strncmp(opengl.GLEWversion, "1.9.", 4) == 0) // work around known bug with KHR_debug extension support in this release
{
debug(LOG_WARNING, "Your version of GLEW is old and buggy, please upgrade to at least version 1.10.");
khr_debug = false;
}
else
{
khr_debug = GLEW_KHR_debug;
}
addDumpInfo(opengl.GLEWversion);
debug(LOG_3D, "%s", opengl.GLEWversion);
@ -151,6 +166,7 @@ bool screenInitialise()
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &glMaxTUs);
debug(LOG_3D, " * Total number of Texture Units (TUs) supported is %d.", (int) glMaxTUs);
debug(LOG_3D, " * GL_ARB_timer_query %s supported!", GLEW_ARB_timer_query ? "is" : "is NOT");
debug(LOG_3D, " * KHR_DEBUG support %s detected", khr_debug ? "was" : "was NOT");
if (!GLEW_VERSION_2_0)
{
@ -225,7 +241,7 @@ void wzPerfShutdown()
// write performance counter list to file
QFile perf(ourfile);
perf.open(QIODevice::WriteOnly);
perf.write("START, EFF, TERRAIN, LOAD, PRTCL, WATER, MODELS, MISC\n");
perf.write("START, EFF, TERRAIN, SKY, LOAD, PRTCL, WATER, MODELS, MISC, GUI\n");
for (int i = 0; i < perfList.size(); i++)
{
QString line;
@ -273,28 +289,58 @@ void wzPerfFrame()
GL_DEBUG("Performance sample complete");
}
static const char *sceneActive = NULL;
void _wzSceneBegin(const char *descr)
{
ASSERT(sceneActive == NULL, "Out of order scenes: Wanted to start %s, was in %s", descr, sceneActive);
if (khr_debug)
{
// enable when https://github.com/apitrace/apitrace/issues/218 has been fixed
//glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, PERF_COUNT, -1, descr);
}
sceneActive = descr;
}
void _wzSceneEnd(const char *descr)
{
ASSERT(descr == sceneActive, "Out of order scenes: Wanted to stop %s, was in %s", descr, sceneActive);
if (khr_debug)
{
// enable when https://github.com/apitrace/apitrace/issues/218 has been fixed
//glPopDebugGroup();
}
sceneActive = NULL;
}
void wzPerfBegin(PERF_POINT pp, const char *descr)
{
GL_DEBUG(descr);
ASSERT(queryActive == PERF_COUNT || pp > queryActive, "Out of order timer query call");
queryActive = pp;
if (khr_debug)
{
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, pp, -1, descr);
}
if (!perfStarted)
{
return;
}
ASSERT(queryActive == PERF_COUNT || pp > queryActive, "Out of order timer query call");
glBeginQuery(GL_TIME_ELAPSED, perfpos[pp]);
queryActive = pp;
glErrors();
}
void wzPerfEnd(PERF_POINT pp)
{
ASSERT(queryActive == pp, "Mismatched wzPerfBegin...End");
queryActive = PERF_COUNT;
if (khr_debug)
{
glPopDebugGroup();
}
if (!perfStarted)
{
return;
}
ASSERT(queryActive == pp, "Mismatched wzPerfBegin...End");
glEndQuery(GL_TIME_ELAPSED);
queryActive = PERF_COUNT;
}
void screenShutDown(void)

View File

@ -65,11 +65,13 @@ enum PERF_POINT
PERF_START_FRAME,
PERF_EFFECTS,
PERF_TERRAIN,
PERF_SKYBOX,
PERF_MODEL_INIT,
PERF_PARTICLES,
PERF_WATER,
PERF_MODELS,
PERF_MISC,
PERF_GUI,
PERF_COUNT
};
@ -84,6 +86,11 @@ void wzPerfFrame();
/// Are performance measurements available?
bool wzPerfAvailable();
#define wzSceneBegin(x) (WZ_ASSERT_STATIC_STRING(x), _wzSceneBegin(x))
void _wzSceneBegin(const char *descr);
#define wzSceneEnd(x) (WZ_ASSERT_STATIC_STRING(x), _wzSceneEnd(x))
void _wzSceneEnd(const char *descr);
struct OPENGL_DATA
{
char vendor[256];

View File

@ -108,7 +108,6 @@ static void locateMouse(void);
static bool renderWallSection(STRUCTURE *psStructure);
static void drawDragBox(void);
static void calcFlagPosScreenCoords(SDWORD *pX, SDWORD *pY, SDWORD *pR);
static void displayTerrain(void);
static void drawTiles(iView *player);
static void display3DProjectiles(void);
static void drawDroidSelections(void);
@ -700,12 +699,21 @@ void draw3DScene( void )
pie_Begin3DScene();
/* Set 3D world origins */
pie_SetGeometricOffset(rendSurface.width / 2, geoOffset);
wzPerfEnd(PERF_START_FRAME);
// draw terrain
displayTerrain();
/* Now, draw the terrain */
drawTiles(&player);
wzPerfBegin(PERF_MISC, "3D scene - misc and text");
/* Show the drag Box if necessary */
drawDragBox();
/* Have we released the drag box? */
if(dragBox3D.status == DRAG_RELEASED)
{
dragBox3D.status = DRAG_INACTIVE;
}
wzPerfBegin(PERF_MISC, "3D scene - misc text");
pie_BeginInterface();
drawDroidSelections();
@ -860,30 +868,9 @@ void draw3DScene( void )
}
wzPerfEnd(PERF_MISC);
GL_DEBUG("Draw 3D scene - end");
}
/// Draws the 3D textured terrain
static void displayTerrain(void)
{
pie_PerspectiveBegin();
/* Now, draw the terrain */
drawTiles(&player);
pie_PerspectiveEnd();
/* Show the drag Box if necessary */
drawDragBox();
/* Have we released the drag box? */
if(dragBox3D.status == DRAG_RELEASED)
{
dragBox3D.status = DRAG_INACTIVE;
}
}
/***************************************************************************/
bool doWeDrawProximitys( void )
{
@ -943,7 +930,8 @@ static void drawTiles(iView *player)
int idx, jdx;
Vector3f theSun;
GL_DEBUG("Draw 3D scene - drawTiles");
// draw terrain
pie_PerspectiveBegin();
/* ---------------------------------------------------------------- */
/* Do boundary and extent checking */
@ -1019,6 +1007,7 @@ static void drawTiles(iView *player)
tileScreenInfo[idx][jdx].y = screen.y;
}
}
wzPerfEnd(PERF_START_FRAME);
/* This is done here as effects can light the terrain - pause mode problems though */
wzPerfBegin(PERF_EFFECTS, "3D scene - effects");
@ -1043,7 +1032,9 @@ static void drawTiles(iView *player)
wzPerfEnd(PERF_TERRAIN);
// draw skybox
wzPerfBegin(PERF_SKYBOX, "3D scene - skybox");
renderSurroundings();
wzPerfEnd(PERF_SKYBOX);
// and prepare for rendering the models
wzPerfBegin(PERF_MODEL_INIT, "Draw 3D scene - model init");
@ -1099,6 +1090,9 @@ static void drawTiles(iView *player)
/* Clear the matrix stack */
pie_MatEnd();
locateMouse();
pie_PerspectiveEnd();
wzPerfEnd(PERF_MODELS);
}

View File

@ -688,6 +688,7 @@ bool systemInitialise(void)
}
// Initialize the iVis text rendering module
wzSceneBegin("Main menu loop");
iV_TextInit();
pie_InitRadar();
@ -710,6 +711,7 @@ void systemShutdown(void)
}
shutdownEffectsSystem();
wzSceneEnd("Main menu loop");
keyClearMappings();
// free up all the load functions (all the data should already have been freed)
@ -922,6 +924,8 @@ bool frontendShutdown(void)
bool stageOneInitialise(void)
{
debug(LOG_WZ, "== stageOneInitalise ==");
wzSceneEnd("Main menu loop");
wzSceneBegin("Main game loop");
// Initialise all globals and statics everwhere.
if(!InitialiseGlobals())
@ -1076,6 +1080,8 @@ bool stageOneShutDown(void)
pie_TexInit(); // restart it
initMiscVars();
wzSceneEnd("Main game loop");
wzSceneBegin("Main menu loop");
return true;
}

View File

@ -324,6 +324,7 @@ static GAMECODE renderLoop()
}
displayWorld();
}
wzPerfBegin(PERF_GUI, "User interface");
/* Display the in game interface */
pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON);
pie_SetFogStatus(false);
@ -340,6 +341,7 @@ static GAMECODE renderLoop()
}
pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
pie_SetFogStatus(true);
wzPerfEnd(PERF_GUI);
}
pie_GetResetCounts(&loopPieCount, &loopPolyCount, &loopStateChanges);