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) {
69 // Start with default state
71 pack_image_height = 0;
72 pack_lsb_first = GL_FALSE;
77 pack_swap_bytes = GL_FALSE;
78 pixel_pack_buffer_binding = 0;
81 glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment);
83 glGetIntegerv(GL_PACK_IMAGE_HEIGHT, &pack_image_height);
84 glGetIntegerv(GL_PACK_LSB_FIRST, &pack_lsb_first);
85 glGetIntegerv(GL_PACK_ROW_LENGTH, &pack_row_length);
86 glGetIntegerv(GL_PACK_SKIP_IMAGES, &pack_skip_images);
87 glGetIntegerv(GL_PACK_SKIP_PIXELS, &pack_skip_pixels);
88 glGetIntegerv(GL_PACK_SKIP_ROWS, &pack_skip_rows);
89 glGetIntegerv(GL_PACK_SWAP_BYTES, &pack_swap_bytes);
90 glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &pixel_pack_buffer_binding);
93 // Reset state for compact images
94 glPixelStorei(GL_PACK_ALIGNMENT, 1);
96 glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
97 glPixelStorei(GL_PACK_LSB_FIRST, GL_FALSE);
98 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
99 glPixelStorei(GL_PACK_SKIP_IMAGES, 0);
100 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
101 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
102 glPixelStorei(GL_PACK_SWAP_BYTES, GL_FALSE);
103 glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
108 Context::restorePixelPackState(void) {
109 glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment);
111 glPixelStorei(GL_PACK_IMAGE_HEIGHT, pack_image_height);
112 glPixelStorei(GL_PACK_LSB_FIRST, pack_lsb_first);
113 glPixelStorei(GL_PACK_ROW_LENGTH, pack_row_length);
114 glPixelStorei(GL_PACK_SKIP_IMAGES, pack_skip_images);
115 glPixelStorei(GL_PACK_SKIP_PIXELS, pack_skip_pixels);
116 glPixelStorei(GL_PACK_SKIP_ROWS, pack_skip_rows);
117 glPixelStorei(GL_PACK_SWAP_BYTES, pack_swap_bytes);
118 glBindBuffer(GL_PIXEL_PACK_BUFFER, pixel_pack_buffer_binding);
123 static const GLenum bindings[] = {
126 GL_PIXEL_PACK_BUFFER_BINDING,
127 GL_PIXEL_UNPACK_BUFFER_BINDING,
128 GL_TEXTURE_BINDING_1D,
129 GL_TEXTURE_BINDING_1D_ARRAY,
130 GL_TEXTURE_BINDING_2D,
131 GL_TEXTURE_BINDING_2D_ARRAY,
132 GL_TEXTURE_BINDING_2D_MULTISAMPLE,
133 GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY,
134 GL_TEXTURE_BINDING_3D,
135 GL_TEXTURE_BINDING_RECTANGLE,
136 GL_TEXTURE_BINDING_CUBE_MAP,
137 GL_TEXTURE_BINDING_CUBE_MAP_ARRAY,
138 GL_DRAW_FRAMEBUFFER_BINDING,
139 GL_READ_FRAMEBUFFER_BINDING,
140 GL_RENDERBUFFER_BINDING,
152 #define NUM_BINDINGS sizeof(bindings)/sizeof(bindings[0])
155 void dumpCurrentContext(std::ostream &os)
160 GLint old_bindings[NUM_BINDINGS];
161 for (unsigned i = 0; i < NUM_BINDINGS; ++i) {
163 glGetIntegerv(bindings[i], &old_bindings[i]);
169 dumpParameters(json, context);
170 dumpShadersUniforms(json, context);
171 dumpTextures(json, context);
172 dumpFramebuffer(json, context);
175 for (unsigned i = 0; i < NUM_BINDINGS; ++i) {
176 GLint new_binding = 0;
177 glGetIntegerv(bindings[i], &new_binding);
178 if (new_binding != old_bindings[i]) {
179 std::cerr << "warning: " << enumToString(bindings[i]) << " was clobbered\n";
187 } /* namespace glstate */