mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-31 00:40:19 +02:00
#23 frame time query
This commit is contained in:
74
src/core.h
74
src/core.h
@@ -102,6 +102,11 @@
|
|||||||
PFNGLOBJECTLABELPROC glObjectLabel;
|
PFNGLOBJECTLABELPROC glObjectLabel;
|
||||||
PFNGLPUSHDEBUGGROUPPROC glPushDebugGroup;
|
PFNGLPUSHDEBUGGROUPPROC glPushDebugGroup;
|
||||||
PFNGLPOPDEBUGGROUPPROC glPopDebugGroup;
|
PFNGLPOPDEBUGGROUPPROC glPopDebugGroup;
|
||||||
|
PFNGLGENQUERIESPROC glGenQueries;
|
||||||
|
PFNGLDELETEQUERIESPROC glDeleteQueries;
|
||||||
|
PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv;
|
||||||
|
PFNGLBEGINQUERYPROC glBeginQuery;
|
||||||
|
PFNGLENDQUERYPROC glEndQuery;
|
||||||
#endif
|
#endif
|
||||||
// Shader
|
// Shader
|
||||||
PFNGLCREATEPROGRAMPROC glCreateProgram;
|
PFNGLCREATEPROGRAMPROC glCreateProgram;
|
||||||
@@ -161,26 +166,63 @@
|
|||||||
struct Shader;
|
struct Shader;
|
||||||
struct Texture;
|
struct Texture;
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
struct {
|
||||||
|
bool VAO;
|
||||||
|
bool depthTexture;
|
||||||
|
bool shadowSampler;
|
||||||
|
bool discardFrame;
|
||||||
|
bool texNPOT;
|
||||||
|
bool texFloat, texFloatLinear;
|
||||||
|
bool texHalf, texHalfLinear;
|
||||||
|
bool shaderBinary;
|
||||||
|
#ifdef PROFILE
|
||||||
|
bool profMarker;
|
||||||
|
bool profTiming;
|
||||||
|
#endif
|
||||||
|
} support;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PROFILE
|
#ifdef PROFILE
|
||||||
struct Marker {
|
struct Marker {
|
||||||
Marker(const char *title) {
|
Marker(const char *title) {
|
||||||
if (glPushDebugGroup) glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 1, -1, title);
|
if (Core::support.profMarker) glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 1, -1, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
~Marker() {
|
~Marker() {
|
||||||
if (glPopDebugGroup) glPopDebugGroup();
|
if (Core::support.profMarker) glPopDebugGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setLabel(GLenum id, GLuint name, const char *label) {
|
static void setLabel(GLenum id, GLuint name, const char *label) {
|
||||||
if (glObjectLabel) glObjectLabel(id, name, -1, label);
|
if (Core::support.profMarker) glObjectLabel(id, name, -1, label);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Timing {
|
||||||
|
GLuint ID;
|
||||||
|
int &result;
|
||||||
|
|
||||||
|
Timing(int &result) : result(result) {
|
||||||
|
if (!Core::support.profTiming) return;
|
||||||
|
glGenQueries(1, &ID);
|
||||||
|
glBeginQuery(GL_TIME_ELAPSED, ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
~Timing() {
|
||||||
|
if (!Core::support.profTiming) return;
|
||||||
|
glEndQuery(GL_TIME_ELAPSED);
|
||||||
|
glGetQueryObjectiv(ID, GL_QUERY_RESULT, (GLint*)&result);
|
||||||
|
glDeleteQueries(1, &ID);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PROFILE_MARKER(title) Marker marker(title)
|
#define PROFILE_MARKER(title) Marker marker(title)
|
||||||
#define PROFILE_LABEL(id, name, label) Marker::setLabel(GL_##id, name, label)
|
#define PROFILE_LABEL(id, name, label) Marker::setLabel(GL_##id, name, label)
|
||||||
|
#define PROFILE_TIMING(result) Timing timing(result)
|
||||||
#else
|
#else
|
||||||
#define PROFILE_MARKER(title)
|
#define PROFILE_MARKER(title)
|
||||||
#define PROFILE_LABEL(id, name, label)
|
#define PROFILE_LABEL(id, name, label)
|
||||||
|
#define PROFILE_TIMING(time)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum CullMode { cfNone, cfBack, cfFront };
|
enum CullMode { cfNone, cfBack, cfFront };
|
||||||
@@ -224,6 +266,9 @@ namespace Core {
|
|||||||
|
|
||||||
struct Stats {
|
struct Stats {
|
||||||
int dips, tris, frame, fps, fpsTime;
|
int dips, tris, frame, fps, fpsTime;
|
||||||
|
#ifdef PROFILE
|
||||||
|
int tFrame;
|
||||||
|
#endif
|
||||||
|
|
||||||
Stats() : frame(0), fps(0), fpsTime(0) {}
|
Stats() : frame(0), fps(0), fpsTime(0) {}
|
||||||
|
|
||||||
@@ -234,6 +279,9 @@ namespace Core {
|
|||||||
void stop() {
|
void stop() {
|
||||||
if (fpsTime < getTime()) {
|
if (fpsTime < getTime()) {
|
||||||
LOG("FPS: %d DIP: %d TRI: %d\n", fps, dips, tris);
|
LOG("FPS: %d DIP: %d TRI: %d\n", fps, dips, tris);
|
||||||
|
#ifdef PROFILE
|
||||||
|
LOG("frame time: %d mcs\n", tFrame / 1000);
|
||||||
|
#endif
|
||||||
fps = frame;
|
fps = frame;
|
||||||
frame = 0;
|
frame = 0;
|
||||||
fpsTime = getTime() + 1000;
|
fpsTime = getTime() + 1000;
|
||||||
@@ -242,17 +290,6 @@ namespace Core {
|
|||||||
}
|
}
|
||||||
} stats;
|
} stats;
|
||||||
|
|
||||||
struct {
|
|
||||||
bool VAO;
|
|
||||||
bool depthTexture;
|
|
||||||
bool shadowSampler;
|
|
||||||
bool discardFrame;
|
|
||||||
bool texNPOT;
|
|
||||||
bool texFloat, texFloatLinear;
|
|
||||||
bool texHalf, texHalfLinear;
|
|
||||||
bool shaderBinary;
|
|
||||||
} support;
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
bool ambient;
|
bool ambient;
|
||||||
bool lighting;
|
bool lighting;
|
||||||
@@ -286,6 +323,11 @@ namespace Core {
|
|||||||
GetProcOGL(glObjectLabel);
|
GetProcOGL(glObjectLabel);
|
||||||
GetProcOGL(glPushDebugGroup);
|
GetProcOGL(glPushDebugGroup);
|
||||||
GetProcOGL(glPopDebugGroup);
|
GetProcOGL(glPopDebugGroup);
|
||||||
|
GetProcOGL(glGenQueries);
|
||||||
|
GetProcOGL(glDeleteQueries);
|
||||||
|
GetProcOGL(glGetQueryObjectiv);
|
||||||
|
GetProcOGL(glBeginQuery);
|
||||||
|
GetProcOGL(glEndQuery);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GetProcOGL(glCreateProgram);
|
GetProcOGL(glCreateProgram);
|
||||||
@@ -351,6 +393,10 @@ namespace Core {
|
|||||||
support.texFloat = support.texFloatLinear || extSupport(ext, "_texture_float");
|
support.texFloat = support.texFloatLinear || extSupport(ext, "_texture_float");
|
||||||
support.texHalfLinear = extSupport(ext, "GL_ARB_texture_float") || extSupport(ext, "_texture_half_float_linear");
|
support.texHalfLinear = extSupport(ext, "GL_ARB_texture_float") || extSupport(ext, "_texture_half_float_linear");
|
||||||
support.texHalf = support.texHalfLinear || extSupport(ext, "_texture_half_float");
|
support.texHalf = support.texHalfLinear || extSupport(ext, "_texture_half_float");
|
||||||
|
#ifdef PROFILE
|
||||||
|
support.profMarker = extSupport(ext, "_KHR_debug");
|
||||||
|
support.profTiming = extSupport(ext, "_timer_query");
|
||||||
|
#endif
|
||||||
|
|
||||||
char *vendor = (char*)glGetString(GL_VENDOR);
|
char *vendor = (char*)glGetString(GL_VENDOR);
|
||||||
LOG("Vendor : %s\n", vendor);
|
LOG("Vendor : %s\n", vendor);
|
||||||
|
@@ -68,6 +68,7 @@ namespace Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void render() {
|
void render() {
|
||||||
|
PROFILE_TIMING(Core::stats.tFrame);
|
||||||
Core::beginFrame();
|
Core::beginFrame();
|
||||||
level->render();
|
level->render();
|
||||||
Core::endFrame();
|
Core::endFrame();
|
||||||
|
Reference in New Issue
Block a user