X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=retrace%2Fglretrace_ws.cpp;h=ac03fcc97de6d56390f807a3b1661e6571d489c1;hb=2b46364c974c95b8e2568f1e3f13e888c46c9d04;hp=8dff68e823ac12f2aa204eb9ca74097c9de81a15;hpb=e23365e771016117473a2efbbf535372f5a5070e;p=apitrace diff --git a/retrace/glretrace_ws.cpp b/retrace/glretrace_ws.cpp index 8dff68e..ac03fcc 100644 --- a/retrace/glretrace_ws.cpp +++ b/retrace/glretrace_ws.cpp @@ -41,8 +41,6 @@ namespace glretrace { - - static glws::Visual * visuals[glws::PROFILE_MAX]; @@ -52,6 +50,10 @@ getVisual(glws::Profile profile) { glws::Visual * & visual = visuals[profile]; if (!visual) { visual = glws::createVisual(retrace::doubleBuffer, profile); + if (!visual) { + std::cerr << "error: failed to create OpenGL visual\n"; + exit(1); + } } return visual; } @@ -70,11 +72,11 @@ getDefaultProfile(void) static glws::Drawable * createDrawableHelper(glws::Profile profile, int width = 32, int height = 32, bool pbuffer = false) { - glws::Drawable *draw = glws::createDrawable(getVisual(profile), width, height, pbuffer); + glws::Visual *visual = getVisual(profile); + glws::Drawable *draw = glws::createDrawable(visual, width, height, pbuffer); if (!draw) { std::cerr << "error: failed to create OpenGL drawable\n"; exit(1); - return NULL; } return draw; @@ -101,8 +103,9 @@ createPbuffer(int width, int height) { Context * createContext(Context *shareContext, glws::Profile profile) { + glws::Visual *visual = getVisual(profile); glws::Context *shareWsContext = shareContext ? shareContext->wsContext : NULL; - glws::Context *ctx = glws::createContext(getVisual(profile), shareWsContext, profile, retrace::debug); + glws::Context *ctx = glws::createContext(visual, shareWsContext, profile, retrace::debug); if (!ctx) { std::cerr << "error: failed to create OpenGL context\n"; exit(1); @@ -119,14 +122,23 @@ createContext(Context *shareContext) { } -typedef Context * CurrentData; -static os::thread_specific_ptr currentData; +Context::~Context() +{ + //assert(this != getCurrentContext()); + if (this != getCurrentContext()) { + delete wsContext; + } +} + + +static thread_specific Context * +currentContextPtr; bool makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context) { - Context *currentContext = getCurrentContext(); + Context *currentContext = currentContextPtr; glws::Drawable *currentDrawable = currentContext ? currentContext->drawable : NULL; if (drawable == currentDrawable && context == currentContext) { @@ -150,26 +162,15 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context) return false; } - if (currentContext) { - currentContext->drawable = NULL; - } - - CurrentData *currentDataPtr = currentData.get(); - if (!currentDataPtr) { - currentDataPtr = new CurrentData; - currentData.reset(currentDataPtr); - } + currentContextPtr = context; if (drawable && context) { context->drawable = drawable; - *currentData = context; if (!context->used) { initContext(); context->used = true; } - } else { - *currentData = NULL; } return true; @@ -178,16 +179,10 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context) Context * getCurrentContext(void) { - CurrentData *currentDataPtr = currentData.get(); - if (!currentDataPtr) { - return NULL; - } - return *currentDataPtr; + return currentContextPtr; } - - /** * Grow the current drawble. *