1 /**************************************************************************
3 * Copyright 2011-2012 Jose Fonseca
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
28 * Window system helpers for glretrace.
34 #include "retrace.hpp"
36 #include "glstate.hpp"
37 #include "glretrace.hpp"
43 glws::Drawable *currentDrawable = NULL;
44 glws::Context *currentContext = NULL;
48 visuals[glws::PROFILE_MAX];
52 getVisual(glws::Profile profile) {
53 glws::Visual * & visual = visuals[profile];
55 visual = glws::createVisual(retrace::doubleBuffer, profile);
62 getDefaultProfile(void)
64 if (retrace::coreProfile) {
65 return glws::PROFILE_CORE;
67 return glws::PROFILE_COMPAT;
73 createDrawable(glws::Profile profile) {
74 glws::Drawable *draw = glws::createDrawable(getVisual(profile));
76 std::cerr << "error: failed to create OpenGL drawable\n";
86 createDrawable(void) {
87 return glretrace::createDrawable(getDefaultProfile());
92 createContext(glws::Context *shareContext, glws::Profile profile) {
93 glws::Context *ctx = glws::createContext(getVisual(profile), shareContext, profile, retrace::debug);
95 std::cerr << "error: failed to create OpenGL context\n";
105 createContext(glws::Context *shareContext) {
106 return createContext(shareContext, getDefaultProfile());
111 makeCurrent(trace::Call &call, glws::Drawable *drawable, glws::Context *context)
113 if (drawable == currentDrawable && context == currentContext) {
117 if (currentDrawable && currentContext) {
119 if (!retrace::doubleBuffer) {
120 frame_complete(call);
126 bool success = glws::makeCurrent(drawable, context);
129 std::cerr << "error: failed to make current OpenGL context and drawable\n";
134 if (drawable && context) {
135 currentDrawable = drawable;
136 currentContext = context;
138 currentDrawable = NULL;
139 currentContext = NULL;
149 * Grow the current drawble.
151 * We need to infer the drawable size from GL calls because the drawable sizes
152 * are specified by OS specific calls which we do not trace.
155 updateDrawable(int width, int height) {
156 if (!currentDrawable) {
160 if (currentDrawable->visible &&
161 width <= currentDrawable->width &&
162 height <= currentDrawable->height) {
166 // Ignore zero area viewports
167 if (width == 0 || height == 0) {
171 // Check for bound framebuffer last, as this may have a performance impact.
172 GLint draw_framebuffer = 0;
173 glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_framebuffer);
174 if (draw_framebuffer != 0) {
178 currentDrawable->resize(width, height);
179 currentDrawable->show();
181 glScissor(0, 0, width, height);
185 } /* namespace glretrace */