X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=retrace%2Fglretrace_ws.cpp;h=d4b0817bfdf0b1852a619a81e41926eadfb73023;hb=39a9f3650233206061134772417bfada16cd07be;hp=66ef10534cdc00d2dad79309ac9dd4688387d2d7;hpb=04f42b803c60b593359322b80af4003361ccd097;p=apitrace diff --git a/retrace/glretrace_ws.cpp b/retrace/glretrace_ws.cpp index 66ef105..d4b0817 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; } @@ -68,29 +70,42 @@ getDefaultProfile(void) } -glws::Drawable * -createDrawable(glws::Profile profile) { - glws::Drawable *draw = glws::createDrawable(getVisual(profile)); +static glws::Drawable * +createDrawableHelper(glws::Profile profile, int width = 32, int height = 32, bool pbuffer = false) { + 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; } +glws::Drawable * +createDrawable(glws::Profile profile) { + return createDrawableHelper(profile); +} + + glws::Drawable * createDrawable(void) { - return glretrace::createDrawable(getDefaultProfile()); + return createDrawable(getDefaultProfile()); +} + + +glws::Drawable * +createPbuffer(int width, int height) { + return createDrawableHelper(getDefaultProfile(), width, height, true); } 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); @@ -107,14 +122,14 @@ createContext(Context *shareContext) { } -typedef Context * CurrentData; -static os::thread_specific_ptr currentData; +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) { @@ -142,22 +157,14 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context) currentContext->drawable = NULL; } - CurrentData *currentDataPtr = currentData.get(); - if (!currentDataPtr) { - currentDataPtr = new CurrentData; - currentData.reset(currentDataPtr); - } - if (drawable && context) { context->drawable = drawable; - *currentData = context; + currentContextPtr = context; if (!context->used) { initContext(); context->used = true; } - } else { - *currentData = NULL; } return true; @@ -166,16 +173,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. * @@ -192,6 +193,10 @@ updateDrawable(int width, int height) { glws::Drawable *currentDrawable = currentContext->drawable; assert(currentDrawable); + if (currentDrawable->pbuffer) { + return; + } + if (currentDrawable->visible && width <= currentDrawable->width && height <= currentDrawable->height) {