This allows us to store per context variables whilst retracing.
Altered the various glretrace window system implementations to use this new context.
Updated the "activeProgram" tracking for profiling to use this.
namespace glretrace {
+struct Context {
+ Context(glws::Context* context)
+ : wsContext(context),
+ activeProgram(0)
+ {
+ }
+
+ ~Context()
+ {
+ delete wsContext;
+ }
+
+ glws::Context* wsContext;
+ GLuint activeProgram;
+};
extern bool insideList;
extern bool insideGlBeginEnd;
extern glws::Drawable *currentDrawable;
-extern glws::Context *currentContext;
+extern Context *currentContext;
glws::Drawable *
createDrawable(glws::Profile profile);
glws::Drawable *
createDrawable(void);
-glws::Context *
-createContext(glws::Context *shareContext, glws::Profile profile);
+Context *
+createContext(Context *shareContext, glws::Profile profile);
-glws::Context *
-createContext(glws::Context *shareContext = 0);
+Context *
+createContext(Context *shareContext = 0);
bool
-makeCurrent(trace::Call &call, glws::Drawable *drawable, glws::Context *context);
+makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context);
void
void beginProfile(trace::Call &call);
void endProfile(trace::Call &call);
-void setActiveProgram(GLuint program);
} /* namespace glretrace */
)
if function.name in ('glUseProgram', 'glUseProgramObjectARB'):
- print r' glretrace::setActiveProgram((call.arg(0)).toUInt());'
+ print r' if (glretrace::currentContext) {'
+ print r' glretrace::currentContext->activeProgram = call.arg(0).toUInt();'
+ print r' }'
# Only profile if not inside a list as the queries get inserted into list
if function.name == 'glNewList':
typedef std::map<unsigned long long, glws::Drawable *> DrawableMap;
-typedef std::map<unsigned long long, glws::Context *> ContextMap;
+typedef std::map<unsigned long long, Context *> ContextMap;
static DrawableMap drawable_map;
static ContextMap context_map;
-static glws::Context *sharedContext = NULL;
+static Context *sharedContext = NULL;
static glws::Drawable *
}
-static glws::Context *
+static Context *
getContext(unsigned long long ctx) {
if (ctx == 0) {
return NULL;
ContextMap::const_iterator it;
it = context_map.find(ctx);
if (it == context_map.end()) {
- glws::Context *context;
+ Context *context;
context_map[ctx] = context = glretrace::createContext(sharedContext);
if (!sharedContext) {
sharedContext = context;
unsigned long long ctx = call.arg(0).toUIntPtr();
glws::Drawable *new_drawable = getDrawable(ctx);
- glws::Context *new_context = getContext(ctx);
+ Context *new_context = getContext(ctx);
glretrace::makeCurrent(call, new_drawable, new_context);
}
typedef std::map<unsigned long long, glws::Drawable *> DrawableMap;
-typedef std::map<unsigned long long, glws::Context *> ContextMap;
+typedef std::map<unsigned long long, Context *> ContextMap;
typedef std::map<unsigned long long, glws::Profile> ProfileMap;
static DrawableMap drawable_map;
static ContextMap context_map;
return (it != drawable_map.end()) ? it->second : NULL;
}
-static glws::Context *
+static Context *
getContext(unsigned long long context_ptr) {
if (context_ptr == 0) {
return NULL;
static void retrace_eglCreateContext(trace::Call &call) {
unsigned long long orig_context = call.ret->toUIntPtr();
unsigned long long orig_config = call.arg(1).toUIntPtr();
- glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
+ Context *share_context = getContext(call.arg(2).toUIntPtr());
trace::Array *attrib_array = dynamic_cast<trace::Array *>(&call.arg(3));
glws::Profile profile;
}
- glws::Context *context = glretrace::createContext(share_context, profile);
+ Context *context = glretrace::createContext(share_context, profile);
if (!context) {
const char *name;
switch (profile) {
static void retrace_eglMakeCurrent(trace::Call &call) {
glws::Drawable *new_drawable = getDrawable(call.arg(1).toUIntPtr());
- glws::Context *new_context = getContext(call.arg(3).toUIntPtr());
+ Context *new_context = getContext(call.arg(3).toUIntPtr());
glretrace::makeCurrent(call, new_drawable, new_context);
}
typedef std::map<unsigned long, glws::Drawable *> DrawableMap;
-typedef std::map<unsigned long long, glws::Context *> ContextMap;
+typedef std::map<unsigned long long, Context *> ContextMap;
static DrawableMap drawable_map;
static ContextMap context_map;
return it->second;
}
-static glws::Context *
+static Context *
getContext(unsigned long long context_ptr) {
if (context_ptr == 0) {
return NULL;
static void retrace_glXCreateContext(trace::Call &call) {
unsigned long long orig_context = call.ret->toUIntPtr();
- glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
+ Context *share_context = getContext(call.arg(2).toUIntPtr());
- glws::Context *context = glretrace::createContext(share_context);
+ Context *context = glretrace::createContext(share_context);
context_map[orig_context] = context;
}
static void retrace_glXCreateContextAttribsARB(trace::Call &call) {
unsigned long long orig_context = call.ret->toUIntPtr();
- glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
+ Context *share_context = getContext(call.arg(2).toUIntPtr());
- glws::Context *context = glretrace::createContext(share_context);
+ Context *context = glretrace::createContext(share_context);
context_map[orig_context] = context;
}
static void retrace_glXMakeCurrent(trace::Call &call) {
glws::Drawable *new_drawable = getDrawable(call.arg(1).toUInt());
- glws::Context *new_context = getContext(call.arg(2).toUIntPtr());
+ Context *new_context = getContext(call.arg(2).toUIntPtr());
glretrace::makeCurrent(call, new_drawable, new_context);
}
static void retrace_glXDestroyContext(trace::Call &call) {
- glws::Context *context = getContext(call.arg(1).toUIntPtr());
+ Context *context = getContext(call.arg(1).toUIntPtr());
if (!context) {
return;
static void retrace_glXCreateNewContext(trace::Call &call) {
unsigned long long orig_context = call.ret->toUIntPtr();
- glws::Context *share_context = getContext(call.arg(3).toUIntPtr());
+ Context *share_context = getContext(call.arg(3).toUIntPtr());
- glws::Context *context = glretrace::createContext(share_context);
+ Context *context = glretrace::createContext(share_context);
context_map[orig_context] = context;
}
static void retrace_glXMakeContextCurrent(trace::Call &call) {
glws::Drawable *new_drawable = getDrawable(call.arg(1).toUInt());
- glws::Context *new_context = getContext(call.arg(3).toUIntPtr());
+ Context *new_context = getContext(call.arg(3).toUIntPtr());
glretrace::makeCurrent(call, new_drawable, new_context);
}
static bool firstFrame = true;
static std::list<CallQuery> callQueries;
-static std::map<glws::Context*, GLuint> activePrograms;
void
callQueries.clear();
}
-void setActiveProgram(GLuint program)
-{
- activePrograms[glretrace::currentContext] = program;
-}
-
-static GLuint
-getActiveProgram()
-{
- std::map<glws::Context*, GLuint>::iterator it;
- it = activePrograms.find(glretrace::currentContext);
- if (it == activePrograms.end())
- return 0;
-
- return it->second;
-}
-
void
beginProfile(trace::Call &call) {
if (firstFrame) {
CallQuery query;
query.call = call.no;
query.sig = call.sig;
- query.program = getActiveProgram();
+ query.program = glretrace::currentContext ? glretrace::currentContext->activeProgram : 0;
glGenQueries(3, query.ids);
typedef std::map<unsigned long long, glws::Drawable *> DrawableMap;
-typedef std::map<unsigned long long, glws::Context *> ContextMap;
+typedef std::map<unsigned long long, Context *> ContextMap;
static DrawableMap drawable_map;
static DrawableMap pbuffer_map;
static ContextMap context_map;
static void retrace_wglCreateContext(trace::Call &call) {
unsigned long long orig_context = call.ret->toUIntPtr();
- glws::Context *context = glretrace::createContext();
+ Context *context = glretrace::createContext();
context_map[orig_context] = context;
}
static void retrace_wglMakeCurrent(trace::Call &call) {
glws::Drawable *new_drawable = getDrawable(call.arg(0).toUIntPtr());
- glws::Context *new_context = context_map[call.arg(1).toUIntPtr()];
+ Context *new_context = context_map[call.arg(1).toUIntPtr()];
glretrace::makeCurrent(call, new_drawable, new_context);
}
unsigned long long hglrc1 = call.arg(0).toUIntPtr();
unsigned long long hglrc2 = call.arg(1).toUIntPtr();
- glws::Context *share_context = context_map[hglrc1];
- glws::Context *old_context = context_map[hglrc2];
+ Context *share_context = context_map[hglrc1];
+ Context *old_context = context_map[hglrc2];
- glws::Context *new_context = glretrace::createContext(share_context);
+ Context *new_context = glretrace::createContext(share_context);
if (new_context) {
if (currentContext == old_context) {
glretrace::makeCurrent(call, currentDrawable, new_context);
static void retrace_wglCreateContextAttribsARB(trace::Call &call) {
unsigned long long orig_context = call.ret->toUIntPtr();
- glws::Context *share_context = NULL;
+ Context *share_context = NULL;
if (call.arg(1).toPointer()) {
share_context = context_map[call.arg(1).toUIntPtr()];
}
- glws::Context *context = glretrace::createContext(share_context);
+ Context *context = glretrace::createContext(share_context);
context_map[orig_context] = context;
}
glws::Drawable *currentDrawable = NULL;
-glws::Context *currentContext = NULL;
+Context *currentContext = NULL;
static glws::Visual *
}
-glws::Context *
-createContext(glws::Context *shareContext, glws::Profile profile) {
- glws::Context *ctx = glws::createContext(getVisual(profile), shareContext, profile, retrace::debug);
+Context *
+createContext(Context *shareContext, glws::Profile profile) {
+ glws::Context *shareWsContext = shareContext ? shareContext->wsContext : NULL;
+ glws::Context *ctx = glws::createContext(getVisual(profile), shareWsContext, profile, retrace::debug);
if (!ctx) {
std::cerr << "error: failed to create OpenGL context\n";
exit(1);
return NULL;
}
- return ctx;
+ return new Context(ctx);
}
-glws::Context *
-createContext(glws::Context *shareContext) {
+Context *
+createContext(Context *shareContext) {
return createContext(shareContext, getDefaultProfile());
}
bool
-makeCurrent(trace::Call &call, glws::Drawable *drawable, glws::Context *context)
+makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
{
if (drawable == currentDrawable && context == currentContext) {
return true;
flushQueries();
- bool success = glws::makeCurrent(drawable, context);
+ bool success = glws::makeCurrent(drawable, context ? context->wsContext : NULL);
if (!success) {
std::cerr << "error: failed to make current OpenGL context and drawable\n";