Inspired on Imre's similar change.
extern bool insideGlBeginEnd;
-extern Context *currentContext;
+Context *
+getCurrentContext(void);
int
print ' glretrace::insideGlBeginEnd = false;'
if function.name.startswith('gl') and not function.name.startswith('glX'):
- print r' if (retrace::debug && !glretrace::currentContext) {'
+ print r' if (retrace::debug && !glretrace::getCurrentContext()) {'
print r' retrace::warning(call) << "no current context\n";'
print r' }'
)
if function.name in ('glUseProgram', 'glUseProgramObjectARB'):
- print r' if (glretrace::currentContext) {'
- print r' glretrace::currentContext->activeProgram = call.arg(0).toUInt();'
+ print r' glretrace::Context *currentContext = glretrace::getCurrentContext();'
+ print r' if (currentContext) {'
+ print r' currentContext->activeProgram = call.arg(0).toUInt();'
print r' }'
# Only profile if not inside a list as the queries get inserted into list
print ' GLint program = -1;'
print ' if (glretrace::insideList) {'
print ' // glUseProgram & glUseProgramObjectARB are display-list-able'
- print ' program = _program_map[glretrace::currentContext->activeProgram];'
+ print r' glretrace::Context *currentContext = glretrace::getCurrentContext();'
+ print ' program = _program_map[currentContext->activeProgram];'
print ' } else {'
print ' GLint pipeline = 0;'
print ' if (_pipelineHasBeenBound) {'
GLvoid * pixels = NULL;
- if (glretrace::currentContext != context) {
+ if (glretrace::getCurrentContext() != context) {
if (retrace::debug) {
retrace::warning(call) << "current context mismatch\n";
}
it = drawable_map.find(orig_surface);
if (it != drawable_map.end()) {
+ glretrace::Context *currentContext = glretrace::getCurrentContext();
if (!currentContext || it->second != currentContext->drawable) {
// TODO: reference count
delete it->second;
void
beginProfile(trace::Call &call, bool isDraw) {
+ glretrace::Context *currentContext = glretrace::getCurrentContext();
+
/* Create call query */
CallQuery query;
query.isDraw = isDraw;
query.call = call.no;
query.sig = call.sig;
- query.program = glretrace::currentContext ? glretrace::currentContext->activeProgram : 0;
+ query.program = currentContext ? currentContext->activeProgram : 0;
/* GPU profiling only for draw calls */
if (isDraw) {
void
initContext() {
+ glretrace::Context *currentContext = glretrace::getCurrentContext();
+
/* Ensure we have adequate extension support */
assert(currentContext);
supportsTimestamp = currentContext->hasExtension("GL_ARB_timer_query");
/* Setup debug message call back */
if (retrace::debug && supportsDebugOutput) {
+ glretrace::Context *currentContext = glretrace::getCurrentContext();
glDebugMessageCallbackARB(&debugOutputCallback, currentContext);
if (DEBUG_OUTPUT_SYNCHRONOUS) {
retrace::frameComplete(call);
+ glretrace::Context *currentContext = glretrace::getCurrentContext();
if (!currentContext) {
return;
}
image::Image *
retrace::getSnapshot(void) {
- if (!glretrace::currentContext) {
+ if (!glretrace::getCurrentContext()) {
return NULL;
}
bool
retrace::dumpState(std::ostream &os)
{
+ glretrace::Context *currentContext = glretrace::getCurrentContext();
+
if (glretrace::insideGlBeginEnd ||
- !glretrace::currentContext) {
+ !currentContext) {
return false;
}
if (retrace::doubleBuffer) {
if (drawable) {
drawable->swapBuffers();
- } else if (currentContext) {
- currentContext->drawable->swapBuffers();
+ } else {
+ glretrace::Context *currentContext = glretrace::getCurrentContext();
+ if (currentContext) {
+ currentContext->drawable->swapBuffers();
+ }
}
} else {
glFlush();
Context *new_context = glretrace::createContext(share_context);
if (new_context) {
+ glretrace::Context *currentContext = glretrace::getCurrentContext();
if (currentContext == old_context) {
glretrace::makeCurrent(call, currentContext->drawable, new_context);
}
#include <string.h>
+#include "os_thread.hpp"
#include "retrace.hpp"
#include "glproc.hpp"
#include "glstate.hpp"
namespace glretrace {
-Context *currentContext = NULL;
static glws::Visual *
}
+typedef Context * CurrentData;
+static os::thread_specific_ptr<CurrentData> currentData;
+
+
bool
makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
{
+ Context *currentContext = getCurrentContext();
glws::Drawable *currentDrawable = currentContext ? currentContext->drawable : NULL;
if (drawable == currentDrawable && context == currentContext) {
currentContext->drawable = NULL;
}
+ CurrentData *currentDataPtr = currentData.get();
+ if (!currentDataPtr) {
+ currentDataPtr = new CurrentData;
+ currentData.reset(currentDataPtr);
+ }
+
if (drawable && context) {
- currentContext = context;
- currentContext->drawable = drawable;
+ context->drawable = drawable;
+ *currentData = context;
if (!context->used) {
initContext();
context->used = true;
}
} else {
- currentContext = NULL;
+ *currentData = NULL;
}
return true;
}
+Context *
+getCurrentContext(void) {
+ CurrentData *currentDataPtr = currentData.get();
+ if (!currentDataPtr) {
+ return NULL;
+ }
+ return *currentDataPtr;
+}
+
+
/**
*/
void
updateDrawable(int width, int height) {
+ Context *currentContext = getCurrentContext();
if (!currentContext) {
return;
}
GLlocation = Handle("location", GLint, key=('program', GLhandleARB))
GLlocationARB = Handle("location", GLint, key=('programObj', GLhandleARB))
-contextKey = ('reinterpret_cast<uintptr_t>(glretrace::currentContext)', UIntPtr)
+contextKey = ('reinterpret_cast<uintptr_t>(glretrace::getCurrentContext())', UIntPtr)
GLprogramARB = Handle("programARB", GLuint)
GLframebuffer = Handle("framebuffer", GLuint)