1 /**************************************************************************
3 * Copyright 2011 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 **************************************************************************/
36 #include "glstate.hpp"
37 #include "glstate_internal.hpp"
43 Context::Context(void) {
44 memset(this, 0, sizeof *this);
46 const char *version = (const char *)glGetString(GL_VERSION);
48 if (version[0] == 'O' &&
57 (version[9] == ' ' || version[9] == '-')) {
62 ARB_draw_buffers = !ES;
64 // TODO: Check extensions we use below
68 Context::resetPixelPackState(void) {
70 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
71 glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
72 glPixelStorei(GL_PACK_SWAP_BYTES, GL_FALSE);
73 glPixelStorei(GL_PACK_LSB_FIRST, GL_FALSE);
74 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
75 glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
76 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
77 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
78 glPixelStorei(GL_PACK_SKIP_IMAGES, 0);
81 glGetIntegerv(GL_PACK_ALIGNMENT, &packAlignment);
83 glPixelStorei(GL_PACK_ALIGNMENT, 1);
87 Context::restorePixelPackState(void) {
91 glPixelStorei(GL_PACK_ALIGNMENT, packAlignment);
96 static const GLenum bindings[] = {
99 GL_PIXEL_PACK_BUFFER_BINDING,
100 GL_PIXEL_UNPACK_BUFFER_BINDING,
101 GL_TEXTURE_BINDING_1D,
102 GL_TEXTURE_BINDING_2D,
103 GL_TEXTURE_BINDING_3D,
104 GL_TEXTURE_BINDING_RECTANGLE,
105 GL_TEXTURE_BINDING_CUBE_MAP,
106 GL_DRAW_FRAMEBUFFER_BINDING,
107 GL_READ_FRAMEBUFFER_BINDING,
108 GL_RENDERBUFFER_BINDING,
120 #define NUM_BINDINGS sizeof(bindings)/sizeof(bindings[0])
123 void dumpCurrentContext(std::ostream &os)
128 GLint old_bindings[NUM_BINDINGS];
129 for (unsigned i = 0; i < NUM_BINDINGS; ++i) {
131 glGetIntegerv(bindings[i], &old_bindings[i]);
137 dumpParameters(json, context);
138 dumpShadersUniforms(json, context);
139 dumpTextures(json, context);
140 dumpFramebuffer(json, context);
143 for (unsigned i = 0; i < NUM_BINDINGS; ++i) {
144 GLint new_binding = 0;
145 glGetIntegerv(bindings[i], &new_binding);
146 if (new_binding != old_bindings[i]) {
147 std::cerr << "warning: " << enumToString(bindings[i]) << " was clobbered\n";
155 } /* namespace glstate */