From b5801e3f55037abe79a3465d8b053ae47bd49de1 Mon Sep 17 00:00:00 2001 From: James Benton Date: Thu, 9 Aug 2012 14:22:24 +0100 Subject: [PATCH] Add initContext to glretrace. Used to do per context setup. Moved the extension support checking to initContext. --- retrace/glretrace.hpp | 6 +++- retrace/glretrace_main.cpp | 57 ++++++++++++++++++++------------------ retrace/glretrace_ws.cpp | 7 +++++ 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/retrace/glretrace.hpp b/retrace/glretrace.hpp index 76f47db..27085d4 100644 --- a/retrace/glretrace.hpp +++ b/retrace/glretrace.hpp @@ -35,7 +35,8 @@ namespace glretrace { struct Context { Context(glws::Context* context) : wsContext(context), - activeProgram(0) + activeProgram(0), + used(false) { } @@ -46,6 +47,7 @@ struct Context { glws::Context* wsContext; GLuint activeProgram; + bool used; }; extern bool insideList; @@ -82,6 +84,8 @@ extern const retrace::Entry egl_callbacks[]; void frame_start(); void frame_complete(trace::Call &call); +void initContext(); + void updateDrawable(int width, int height); diff --git a/retrace/glretrace_main.cpp b/retrace/glretrace_main.cpp index ca7f9b7..9d551af 100644 --- a/retrace/glretrace_main.cpp +++ b/retrace/glretrace_main.cpp @@ -162,33 +162,6 @@ flushQueries() { void beginProfile(trace::Call &call) { if (firstFrame) { - /* Check for extension support */ - const char* extensions = (const char*)glGetString(GL_EXTENSIONS); - GLint bits; - - supportsTimestamp = glws::checkExtension("GL_ARB_timer_query", extensions); - supportsElapsed = glws::checkExtension("GL_EXT_timer_query", extensions) || supportsTimestamp; - supportsOcclusion = glws::checkExtension("GL_ARB_occlusion_query", extensions); - - if (retrace::profilingGpuTimes) { - if (!supportsTimestamp && !supportsElapsed) { - std::cout << "Error: Cannot run profile, GL_EXT_timer_query extension is not supported." << std::endl; - exit(-1); - } - - glGetQueryiv(GL_TIME_ELAPSED, GL_QUERY_COUNTER_BITS, &bits); - - if (!bits) { - std::cout << "Error: Cannot run profile, GL_QUERY_COUNTER_BITS == 0." << std::endl; - exit(-1); - } - } - - if (retrace::profilingPixelsDrawn && !supportsOcclusion) { - std::cout << "Error: Cannot run profile, GL_ARB_occlusion_query extension is not supported." << std::endl; - exit(-1); - } - frame_start(); } @@ -237,6 +210,36 @@ endProfile(trace::Call &call) { } } +void +initContext() { + /* Check for extension support */ + const char* extensions = (const char*)glGetString(GL_EXTENSIONS); + GLint bits; + + supportsTimestamp = glws::checkExtension("GL_ARB_timer_query", extensions); + supportsElapsed = glws::checkExtension("GL_EXT_timer_query", extensions) || supportsTimestamp; + supportsOcclusion = glws::checkExtension("GL_ARB_occlusion_query", extensions); + + if (retrace::profilingGpuTimes) { + if (!supportsTimestamp && !supportsElapsed) { + std::cout << "Error: Cannot run profile, GL_EXT_timer_query extension is not supported." << std::endl; + exit(-1); + } + + glGetQueryiv(GL_TIME_ELAPSED, GL_QUERY_COUNTER_BITS, &bits); + + if (!bits) { + std::cout << "Error: Cannot run profile, GL_QUERY_COUNTER_BITS == 0." << std::endl; + exit(-1); + } + } + + if (retrace::profilingPixelsDrawn && !supportsOcclusion) { + std::cout << "Error: Cannot run profile, GL_ARB_occlusion_query extension is not supported." << std::endl; + exit(-1); + } +} + void frame_start() { firstFrame = false; diff --git a/retrace/glretrace_ws.cpp b/retrace/glretrace_ws.cpp index ffba524..bead54e 100644 --- a/retrace/glretrace_ws.cpp +++ b/retrace/glretrace_ws.cpp @@ -132,6 +132,13 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context) return false; } + if (context) { + if (!context->used) { + initContext(); + context->used = true; + } + } + if (drawable && context) { currentDrawable = drawable; currentContext = context; -- 2.43.0