namespace glretrace {
-
-
static glws::Visual *
visuals[glws::PROFILE_MAX];
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;
}
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;
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);
}
-typedef Context * CurrentData;
-static os::thread_specific_ptr<CurrentData> currentData;
+Context::~Context()
+{
+ //assert(this != getCurrentContext());
+ if (this != getCurrentContext()) {
+ delete wsContext;
+ }
+}
+
+
+static OS_THREAD_SPECIFIC_PTR(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) {
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;
Context *
getCurrentContext(void) {
- CurrentData *currentDataPtr = currentData.get();
- if (!currentDataPtr) {
- return NULL;
- }
- return *currentDataPtr;
+ return currentContextPtr;
}
-
-
/**
* Grow the current drawble.
*
return;
}
+ width = std::max(width, currentDrawable->width);
+ height = std::max(height, currentDrawable->height);
+
// Check for bound framebuffer last, as this may have a performance impact.
GLint draw_framebuffer = 0;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_framebuffer);
int
parseAttrib(const trace::Value *attribs, int param, int default_ = 0) {
- const trace::Array *attribs_ = dynamic_cast<const trace::Array *>(attribs);
+ const trace::Array *attribs_ = attribs ? attribs->toArray() : NULL;
if (attribs_) {
for (size_t i = 0; i + 1 < attribs_->values.size(); i += 2) {