├── LICENSE.txt ├── Makefile.mingw ├── Makefile.osx ├── README.txt ├── SConstruct ├── camera.h ├── drawer2D.cpp ├── drawer2D.h ├── glew-1.7.0 ├── LICENSE.txt ├── include │ └── GL │ │ ├── glew.h │ │ ├── glxew.h │ │ └── wglew.h ├── lib-osx │ └── libGLEW.a └── lib-win32 │ ├── glew32.dll │ └── glew32.lib ├── glew32.dll ├── glfw-2.7.5 ├── COPYING.txt ├── include │ └── GL │ │ └── glfw.h ├── lib-cocoa │ └── libglfw.a ├── lib-mingw │ └── libglfw.a └── lib-msvc100 │ └── GLFW.lib ├── glprofiler.config ├── glprofiler.creator ├── glprofiler.files ├── glprofiler.includes ├── glprofiler.sln ├── glprofiler.vcxproj ├── glprofiler.vcxproj.filters ├── grid.cpp ├── grid.h ├── hole_array.h ├── hp_timer.cpp ├── hp_timer.h ├── main.cpp ├── math_utils.cpp ├── math_utils.h ├── media ├── color.frag ├── color.vert ├── font.frag ├── font.vert ├── grid.frag ├── grid.vert └── times_new_roman.tga ├── profiler.cpp ├── profiler.h ├── scene.cpp ├── scene.h ├── tgaloader.cpp ├── tgaloader.h ├── thread.cpp ├── thread.h ├── utils.cpp └── utils.h /LICENSE.txt: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | 15 | -------------------------------------------------------------------------------- /Makefile.mingw: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CFLAGS=-Wall -g 3 | CPPFLAGS=-Iglew-1.7.0/include -Iglfw-2.7.5/include 4 | LDFLAGS=-Lglfw-2.7.5/lib-mingw glew-1.7.0/lib-win32/glew32.dll -lglfw -lopengl32 -lgdi32 5 | EXEC=glprofiler 6 | SRC= $(wildcard *.cpp) 7 | OBJ= $(SRC:.cpp=.o) 8 | 9 | all: $(EXEC) 10 | 11 | glprofiler: $(OBJ) 12 | $(CC) -o $@ $^ $(LDFLAGS) 13 | 14 | %.o: %.h 15 | 16 | %.o: %.cpp 17 | $(CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS) 18 | 19 | clean: 20 | rm -f *.o $(EXEC) 21 | 22 | # --- includes --- 23 | camera.h: math_utils.h 24 | drawer2D.o: drawer2D.h utils.h tgaloader.h 25 | drawer2D.h: utils.h 26 | grid.o: grid.h utils.h 27 | grid.h: camera.h utils.h 28 | main.o: scene.h hp_timer.h profiler.h drawer2D.h thread.h math_utils.h 29 | profiler.o: profiler.h hp_timer.h drawer2D.h thread.h 30 | profiler.h: hole_array.h thread.h utils.h 31 | scene.o: scene.h utils.h profiler.h math_utils.h 32 | scene.h: camera.h grid.h thread.h utils.h 33 | -------------------------------------------------------------------------------- /Makefile.osx: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CFLAGS=-Wall -g 3 | CPPFLAGS=-Iglew-1.7.0/include -Iglfw-2.7.5/include 4 | LDFLAGS=./glfw-2.7.5/lib-cocoa/libglfw.a -framework Cocoa -framework OpenGL ./glew-1.7.0/lib-osx/libGLEW.a 5 | EXEC=glprofiler 6 | SRC= $(wildcard *.cpp) 7 | OBJ= $(SRC:.cpp=.o) 8 | 9 | all: $(EXEC) 10 | 11 | glprofiler: $(OBJ) 12 | $(CC) -o $@ $^ $(LDFLAGS) 13 | 14 | %.o: %.h 15 | 16 | %.o: %.cpp 17 | $(CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS) 18 | 19 | clean: 20 | rm -f *.o $(EXEC) 21 | 22 | # --- includes --- 23 | camera.h: math_utils.h 24 | drawer2D.o: drawer2D.h utils.h tgaloader.h 25 | drawer2D.h: utils.h 26 | grid.o: grid.h utils.h 27 | grid.h: camera.h utils.h 28 | main.o: scene.h hp_timer.h profiler.h drawer2D.h thread.h math_utils.h 29 | profiler.o: profiler.h hp_timer.h drawer2D.h thread.h 30 | profiler.h: hole_array.h thread.h utils.h 31 | scene.o: scene.h utils.h profiler.h math_utils.h 32 | scene.h: camera.h grid.h thread.h utils.h 33 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | 4 | This code is an implementation of the graphical real-time profiler using OpenGL timer queries and precise OS-specific CPU time queries that is described in the chapter "A real-time profiling tool" from the book "OpenGL Insights". 5 | This code is provided in the hope that it will be useful. 6 | Patches and improvements are welcome. The code is also available on the following Git repository: 7 | https://github.com/Funto/OpenGL-Timestamp-Profiler 8 | 9 | Licensing 10 | --------- 11 | This code is covered by the WTFPL (Do What The Fuck You Want To Public License). 12 | 13 | Hardware and driver requirements 14 | -------------------------------- 15 | You need at least an OpenGL 3.2 compatible GPU and driver with the ARB_timer_query extension to run the demo. 16 | 17 | Dependencies 18 | ------------ 19 | This code depends on the libraries GLEW and GLFW, which are part of the source tree. 20 | 21 | Compiling 22 | --------- 23 | 24 | * Windows: 25 | To compile with Visual C++ 2010, use the provided project files. 26 | To compile with the MinGW compiler, use the command: 27 | make -f Makefile.mingw 28 | 29 | * MacOS X: 30 | To compile on MacOS X, use the command: 31 | make -f Makefile.osx 32 | 33 | * Linux: 34 | To compile on Linux, you need to install SCons, GLEW and GLFW, and type: 35 | scons 36 | 37 | Authors 38 | ------- 39 | 40 | Lionel Fuentes: main contributor 41 | Robert Menzel: patches for MacOS X support 42 | -------------------------------------------------------------------------------- /SConstruct: -------------------------------------------------------------------------------- 1 | src_list = Split(""" 2 | drawer2D.cpp 3 | hp_timer.cpp 4 | main.cpp 5 | scene.cpp 6 | thread.cpp 7 | utils.cpp 8 | math_utils.cpp 9 | grid.cpp 10 | tgaloader.cpp 11 | profiler.cpp 12 | """) 13 | 14 | env = Environment() 15 | env.ParseConfig('pkg-config glew libglfw --cflags --libs') 16 | env.Append(LIBS=['GLU']) 17 | env.Append(CCFLAGS=['-g', '-Wall']) 18 | env.Program('profiler', src_list) 19 | -------------------------------------------------------------------------------- /camera.h: -------------------------------------------------------------------------------- 1 | // Camera.h 2 | 3 | #ifndef CAMERA_H 4 | #define CAMERA_H 5 | 6 | #include "math_utils.h" 7 | 8 | struct Camera 9 | { 10 | float view_matrix[16]; 11 | float proj_matrix[16]; 12 | 13 | void setPerspective(float fovy_degrees, float aspect_ratio, 14 | float znear, float zfar) 15 | { 16 | matrixPerspective(proj_matrix, fovy_degrees, aspect_ratio, 1.0f, 100.0f); 17 | } 18 | 19 | void lookAt(const float eye[3], 20 | const float target[3], 21 | const float up[3]) 22 | { 23 | matrixLookAt(view_matrix, eye, target, up); 24 | } 25 | }; 26 | 27 | #endif // CAMERA_H 28 | -------------------------------------------------------------------------------- /drawer2D.cpp: -------------------------------------------------------------------------------- 1 | // drawer2D.cpp 2 | 3 | #include "drawer2D.h" 4 | #include "utils.h" 5 | #include "tgaloader.h" 6 | #include 7 | #include 8 | 9 | #define FONT_FILENAME "media/times_new_roman.tga" 10 | #define ATTRIB_VERTEX 0 11 | #define ATTRIB_UV 1 12 | 13 | Drawer2D drawer2D; 14 | 15 | //----------------------------------------------------------------------------- 16 | bool Drawer2D::init(int win_w, int win_h) 17 | { 18 | m_win_w = win_w; 19 | m_win_h = win_h; 20 | 21 | if(!loadShaders("media/color.vert", "media/color.frag", m_id_vert_color, m_id_frag_color, m_id_prog_color)) 22 | { 23 | fprintf(stderr, "*** Drawer2D: FAILED loading shaders for uniform color\n"); 24 | return false; 25 | } 26 | 27 | m_id_uniform_color = glGetUniformLocation(m_id_prog_color, "color"); 28 | if(m_id_uniform_color < 0) 29 | { 30 | fprintf(stderr, "*** Drawer2D: FAILED retrieving uniform location\n"); 31 | return false; 32 | } 33 | 34 | glGenBuffers(1, &m_id_vbo); 35 | 36 | if(!initFont()) 37 | return false; 38 | 39 | return true; 40 | } 41 | 42 | //----------------------------------------------------------------------------- 43 | void Drawer2D::shut() 44 | { 45 | glDeleteProgram(m_id_prog_color); 46 | glDeleteShader(m_id_frag_color); 47 | glDeleteShader(m_id_vert_color); 48 | glDeleteBuffers(1, &m_id_vbo); 49 | } 50 | 51 | //----------------------------------------------------------------------------- 52 | void Drawer2D::drawRect(const Rect& rect, const Color& color, float alpha) 53 | { 54 | glEnableVertexAttribArray(ATTRIB_VERTEX); 55 | 56 | glBindBuffer(GL_ARRAY_BUFFER, m_id_vbo); 57 | 58 | float x1 = rect.x; 59 | float y1 = rect.y; 60 | float x2 = rect.x + rect.w; 61 | float y2 = rect.y + rect.h; 62 | 63 | GLfloat vertices[] = { 64 | x1, y1, 65 | x2, y1, 66 | x2, y2, 67 | x2, y2, 68 | x1, y2, 69 | x1, y1 70 | }; 71 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), (const GLvoid*)vertices, GL_DYNAMIC_DRAW); 72 | glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, (void*)0 ); 73 | 74 | glUseProgram(m_id_prog_color); 75 | 76 | float color_array[] = {(float)(color.r) / 255.0f, 77 | (float)(color.g) / 255.0f, 78 | (float)(color.b) / 255.0f, 79 | alpha 80 | }; 81 | glUniform4fv(m_id_uniform_color, 1, color_array); 82 | 83 | glDrawArrays(GL_TRIANGLES, 0, 6); 84 | 85 | glDisableVertexAttribArray(ATTRIB_VERTEX); 86 | } 87 | 88 | //----------------------------------------------------------------------------- 89 | void Drawer2D::drawString(const char* str, float x, float y, const Color& color) 90 | { 91 | glEnableVertexAttribArray(ATTRIB_VERTEX); 92 | glEnableVertexAttribArray(ATTRIB_UV); 93 | 94 | glBindBuffer(GL_ARRAY_BUFFER, m_id_vbo); 95 | 96 | const int nb_chars_side = 16; // we got 16 characters on one side of our squared image 97 | const int char_size = 16; // in the original image, one character is 16x16 pixels 98 | 99 | const float uv_stride = 1.0f / (float)nb_chars_side; // 0.0625: how much we need to add to the UV 100 | // coordinates to go to the next character 101 | 102 | const float screen_char_width = (float)char_size / (float)m_win_w; // size of one character in the 103 | const float screen_char_height = (float)char_size / (float)m_win_h; // [0;1]x[0;1] screen-space basis 104 | 105 | glUseProgram(m_id_prog_font); 106 | 107 | glActiveTexture(GL_TEXTURE0); 108 | glBindTexture(GL_TEXTURE_2D, m_id_tex_font); 109 | 110 | glUniform1i(m_id_uniform_tex_font, 0); 111 | glUniform3f(m_id_uniform_font_color, 112 | ((float)color.r) / 255.0f, 113 | ((float)color.g) / 255.0f, 114 | ((float)color.b) / 255.0f); 115 | 116 | float cur_x = x; 117 | float cur_y = y; 118 | 119 | const char* p = str; 120 | while(*p) 121 | { 122 | char c = *p; 123 | float u = (float)(((int)c % nb_chars_side) * uv_stride); 124 | float v = (float)(((nb_chars_side-1) - (int)floor(float((int)c * uv_stride))) * uv_stride); 125 | 126 | if(c == '\n') 127 | { 128 | cur_x = x; 129 | cur_y -= screen_char_height; 130 | } 131 | else 132 | { 133 | float u1 = u; 134 | float v1 = v; 135 | float u2 = u + uv_stride; 136 | float v2 = v + uv_stride; 137 | 138 | float x1 = cur_x; 139 | float y1 = cur_y; 140 | float x2 = cur_x + screen_char_width; 141 | float y2 = cur_y + screen_char_height; 142 | 143 | GLfloat vertices[] = { 144 | x1, y1, 145 | x2, y1, 146 | x2, y2, 147 | x2, y2, 148 | x1, y2, 149 | x1, y1, 150 | 151 | u1, v1, 152 | u2, v1, 153 | u2, v2, 154 | u2, v2, 155 | u1, v2, 156 | u1, v1, 157 | }; 158 | 159 | 160 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), (const GLvoid*)vertices, GL_DYNAMIC_DRAW); 161 | glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, (void*)0 ); 162 | glVertexAttribPointer(ATTRIB_UV, 2, GL_FLOAT, GL_FALSE, 0, (void*)(6*2*sizeof(GLfloat)) ); 163 | 164 | glDrawArrays(GL_TRIANGLES, 0, 6); 165 | 166 | //cur_x += screen_char_width; 167 | cur_x += 0.9f*screen_char_width; // HACK 168 | } 169 | 170 | p++; 171 | } 172 | 173 | 174 | glDisableVertexAttribArray(ATTRIB_UV); 175 | glDisableVertexAttribArray(ATTRIB_VERTEX); 176 | } 177 | 178 | //----------------------------------------------------------------------------- 179 | bool Drawer2D::initFont() 180 | { 181 | // Load the TGA image 182 | TGALoader tga; 183 | TGAErrorCode error = tga.loadFile(FONT_FILENAME); 184 | if(error != TGA_OK) 185 | { 186 | fprintf(stderr, "*** Drawer2D: FAILED loading font " FONT_FILENAME "\n"); 187 | return false; 188 | } 189 | 190 | // Create the texture 191 | glGenTextures(1, &m_id_tex_font); 192 | glBindTexture(GL_TEXTURE_2D, m_id_tex_font); 193 | 194 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 195 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 196 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 197 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 198 | 199 | glTexImage2D( 200 | GL_TEXTURE_2D, 201 | 0, 202 | GL_RGBA8, 203 | tga.getWidth(), tga.getHeight(), 204 | 0, 205 | GL_RGBA, 206 | GL_UNSIGNED_BYTE, 207 | (const GLvoid*)tga.getData()); 208 | 209 | // Create the shader 210 | if(!loadShaders("media/font.vert", "media/font.frag", m_id_vert_font, m_id_frag_font, m_id_prog_font)) 211 | { 212 | fprintf(stderr, "*** Drawer2D: FAILED loading shaders for font\n"); 213 | return false; 214 | } 215 | 216 | // Uniform retrieval 217 | m_id_uniform_tex_font = glGetUniformLocation(m_id_prog_font, "tex_font"); 218 | if(m_id_uniform_tex_font < 0) 219 | { 220 | fprintf(stderr, "*** Drawer2D: FAILED retrieving uniform location\n"); 221 | return false; 222 | } 223 | 224 | m_id_uniform_font_color = glGetUniformLocation(m_id_prog_font, "font_color"); 225 | if(m_id_uniform_font_color < 0) 226 | { 227 | fprintf(stderr, "*** Drawer2D: FAILED retrieving uniform location\n"); 228 | return false; 229 | } 230 | 231 | return true; 232 | } 233 | -------------------------------------------------------------------------------- /drawer2D.h: -------------------------------------------------------------------------------- 1 | // drawer2D.h 2 | 3 | #ifndef __DRAWER2D_H__ 4 | #define __DRAWER2D_H__ 5 | 6 | #include 7 | #include "utils.h" 8 | 9 | // Simple class to draw strings in a [-1;1]x[-1;1] coordinates system 10 | class Drawer2D 11 | { 12 | private: 13 | GLuint m_id_vbo; // General-purpose VBO 14 | 15 | // Unicolor shader 16 | GLuint m_id_vert_color; 17 | GLuint m_id_frag_color; 18 | GLuint m_id_prog_color; 19 | 20 | GLint m_id_uniform_color; 21 | 22 | // Font 23 | GLuint m_id_tex_font; 24 | GLint m_id_uniform_tex_font; 25 | GLint m_id_uniform_font_color; 26 | 27 | GLuint m_id_vert_font; 28 | GLuint m_id_frag_font; 29 | GLuint m_id_prog_font; 30 | 31 | // Window size 32 | int m_win_w; 33 | int m_win_h; 34 | 35 | public: 36 | Drawer2D() {} 37 | 38 | bool init(int win_w, int win_h); 39 | void shut(); 40 | 41 | void onResize(int win_w, int win_h) {m_win_w = win_w; m_win_h = win_h; } 42 | 43 | void drawRect(const Rect& rect, const Color& color=COLOR_WHITE, float alpha=1.0f); 44 | void drawString(const char* str, float x, float y, const Color& color=COLOR_WHITE); 45 | 46 | private: 47 | bool initFont(); 48 | }; 49 | 50 | extern Drawer2D drawer2D; 51 | 52 | #endif // __DRAWER2D_H__ 53 | -------------------------------------------------------------------------------- /glew-1.7.0/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The OpenGL Extension Wrangler Library 2 | Copyright (C) 2002-2007, Milan Ikits 3 | Copyright (C) 2002-2007, Marcelo E. Magallon 4 | Copyright (C) 2002, Lev Povalahev 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | * The name of the author may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | Mesa 3-D graphics library 32 | Version: 7.0 33 | 34 | Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a 37 | copy of this software and associated documentation files (the "Software"), 38 | to deal in the Software without restriction, including without limitation 39 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 40 | and/or sell copies of the Software, and to permit persons to whom the 41 | Software is furnished to do so, subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included 44 | in all copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 47 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 50 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 51 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 52 | 53 | 54 | Copyright (c) 2007 The Khronos Group Inc. 55 | 56 | Permission is hereby granted, free of charge, to any person obtaining a 57 | copy of this software and/or associated documentation files (the 58 | "Materials"), to deal in the Materials without restriction, including 59 | without limitation the rights to use, copy, modify, merge, publish, 60 | distribute, sublicense, and/or sell copies of the Materials, and to 61 | permit persons to whom the Materials are furnished to do so, subject to 62 | the following conditions: 63 | 64 | The above copyright notice and this permission notice shall be included 65 | in all copies or substantial portions of the Materials. 66 | 67 | THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 68 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 69 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 70 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 71 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 72 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 73 | MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 74 | -------------------------------------------------------------------------------- /glew-1.7.0/include/GL/wglew.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** The OpenGL Extension Wrangler Library 3 | ** Copyright (C) 2002-2008, Milan Ikits 4 | ** Copyright (C) 2002-2008, Marcelo E. Magallon 5 | ** Copyright (C) 2002, Lev Povalahev 6 | ** All rights reserved. 7 | ** 8 | ** Redistribution and use in source and binary forms, with or without 9 | ** modification, are permitted provided that the following conditions are met: 10 | ** 11 | ** * Redistributions of source code must retain the above copyright notice, 12 | ** this list of conditions and the following disclaimer. 13 | ** * Redistributions in binary form must reproduce the above copyright notice, 14 | ** this list of conditions and the following disclaimer in the documentation 15 | ** and/or other materials provided with the distribution. 16 | ** * The name of the author may be used to endorse or promote products 17 | ** derived from this software without specific prior written permission. 18 | ** 19 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 29 | ** THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /* 33 | ** Copyright (c) 2007 The Khronos Group Inc. 34 | ** 35 | ** Permission is hereby granted, free of charge, to any person obtaining a 36 | ** copy of this software and/or associated documentation files (the 37 | ** "Materials"), to deal in the Materials without restriction, including 38 | ** without limitation the rights to use, copy, modify, merge, publish, 39 | ** distribute, sublicense, and/or sell copies of the Materials, and to 40 | ** permit persons to whom the Materials are furnished to do so, subject to 41 | ** the following conditions: 42 | ** 43 | ** The above copyright notice and this permission notice shall be included 44 | ** in all copies or substantial portions of the Materials. 45 | ** 46 | ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 47 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 48 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 49 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 50 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 51 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 52 | ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 53 | */ 54 | 55 | #ifndef __wglew_h__ 56 | #define __wglew_h__ 57 | #define __WGLEW_H__ 58 | 59 | #ifdef __wglext_h_ 60 | #error wglext.h included before wglew.h 61 | #endif 62 | 63 | #define __wglext_h_ 64 | 65 | #if !defined(WINAPI) 66 | # ifndef WIN32_LEAN_AND_MEAN 67 | # define WIN32_LEAN_AND_MEAN 1 68 | # endif 69 | #include 70 | # undef WIN32_LEAN_AND_MEAN 71 | #endif 72 | 73 | /* 74 | * GLEW_STATIC needs to be set when using the static version. 75 | * GLEW_BUILD is set when building the DLL version. 76 | */ 77 | #ifdef GLEW_STATIC 78 | # define GLEWAPI extern 79 | #else 80 | # ifdef GLEW_BUILD 81 | # define GLEWAPI extern __declspec(dllexport) 82 | # else 83 | # define GLEWAPI extern __declspec(dllimport) 84 | # endif 85 | #endif 86 | 87 | #ifdef __cplusplus 88 | extern "C" { 89 | #endif 90 | 91 | /* -------------------------- WGL_3DFX_multisample ------------------------- */ 92 | 93 | #ifndef WGL_3DFX_multisample 94 | #define WGL_3DFX_multisample 1 95 | 96 | #define WGL_SAMPLE_BUFFERS_3DFX 0x2060 97 | #define WGL_SAMPLES_3DFX 0x2061 98 | 99 | #define WGLEW_3DFX_multisample WGLEW_GET_VAR(__WGLEW_3DFX_multisample) 100 | 101 | #endif /* WGL_3DFX_multisample */ 102 | 103 | /* ------------------------- WGL_3DL_stereo_control ------------------------ */ 104 | 105 | #ifndef WGL_3DL_stereo_control 106 | #define WGL_3DL_stereo_control 1 107 | 108 | #define WGL_STEREO_EMITTER_ENABLE_3DL 0x2055 109 | #define WGL_STEREO_EMITTER_DISABLE_3DL 0x2056 110 | #define WGL_STEREO_POLARITY_NORMAL_3DL 0x2057 111 | #define WGL_STEREO_POLARITY_INVERT_3DL 0x2058 112 | 113 | typedef BOOL (WINAPI * PFNWGLSETSTEREOEMITTERSTATE3DLPROC) (HDC hDC, UINT uState); 114 | 115 | #define wglSetStereoEmitterState3DL WGLEW_GET_FUN(__wglewSetStereoEmitterState3DL) 116 | 117 | #define WGLEW_3DL_stereo_control WGLEW_GET_VAR(__WGLEW_3DL_stereo_control) 118 | 119 | #endif /* WGL_3DL_stereo_control */ 120 | 121 | /* ------------------------ WGL_AMD_gpu_association ------------------------ */ 122 | 123 | #ifndef WGL_AMD_gpu_association 124 | #define WGL_AMD_gpu_association 1 125 | 126 | #define WGL_GPU_VENDOR_AMD 0x1F00 127 | #define WGL_GPU_RENDERER_STRING_AMD 0x1F01 128 | #define WGL_GPU_OPENGL_VERSION_STRING_AMD 0x1F02 129 | #define WGL_GPU_FASTEST_TARGET_GPUS_AMD 0x21A2 130 | #define WGL_GPU_RAM_AMD 0x21A3 131 | #define WGL_GPU_CLOCK_AMD 0x21A4 132 | #define WGL_GPU_NUM_PIPES_AMD 0x21A5 133 | #define WGL_GPU_NUM_SIMD_AMD 0x21A6 134 | #define WGL_GPU_NUM_RB_AMD 0x21A7 135 | #define WGL_GPU_NUM_SPI_AMD 0x21A8 136 | 137 | typedef VOID (WINAPI * PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC) (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); 138 | typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC) (UINT id); 139 | typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTATTRIBSAMDPROC) (UINT id, HGLRC hShareContext, const int* attribList); 140 | typedef BOOL (WINAPI * PFNWGLDELETEASSOCIATEDCONTEXTAMDPROC) (HGLRC hglrc); 141 | typedef UINT (WINAPI * PFNWGLGETCONTEXTGPUIDAMDPROC) (HGLRC hglrc); 142 | typedef HGLRC (WINAPI * PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC) (void); 143 | typedef UINT (WINAPI * PFNWGLGETGPUIDSAMDPROC) (UINT maxCount, UINT* ids); 144 | typedef INT (WINAPI * PFNWGLGETGPUINFOAMDPROC) (UINT id, INT property, GLenum dataType, UINT size, void* data); 145 | typedef BOOL (WINAPI * PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC) (HGLRC hglrc); 146 | 147 | #define wglBlitContextFramebufferAMD WGLEW_GET_FUN(__wglewBlitContextFramebufferAMD) 148 | #define wglCreateAssociatedContextAMD WGLEW_GET_FUN(__wglewCreateAssociatedContextAMD) 149 | #define wglCreateAssociatedContextAttribsAMD WGLEW_GET_FUN(__wglewCreateAssociatedContextAttribsAMD) 150 | #define wglDeleteAssociatedContextAMD WGLEW_GET_FUN(__wglewDeleteAssociatedContextAMD) 151 | #define wglGetContextGPUIDAMD WGLEW_GET_FUN(__wglewGetContextGPUIDAMD) 152 | #define wglGetCurrentAssociatedContextAMD WGLEW_GET_FUN(__wglewGetCurrentAssociatedContextAMD) 153 | #define wglGetGPUIDsAMD WGLEW_GET_FUN(__wglewGetGPUIDsAMD) 154 | #define wglGetGPUInfoAMD WGLEW_GET_FUN(__wglewGetGPUInfoAMD) 155 | #define wglMakeAssociatedContextCurrentAMD WGLEW_GET_FUN(__wglewMakeAssociatedContextCurrentAMD) 156 | 157 | #define WGLEW_AMD_gpu_association WGLEW_GET_VAR(__WGLEW_AMD_gpu_association) 158 | 159 | #endif /* WGL_AMD_gpu_association */ 160 | 161 | /* ------------------------- WGL_ARB_buffer_region ------------------------- */ 162 | 163 | #ifndef WGL_ARB_buffer_region 164 | #define WGL_ARB_buffer_region 1 165 | 166 | #define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001 167 | #define WGL_BACK_COLOR_BUFFER_BIT_ARB 0x00000002 168 | #define WGL_DEPTH_BUFFER_BIT_ARB 0x00000004 169 | #define WGL_STENCIL_BUFFER_BIT_ARB 0x00000008 170 | 171 | typedef HANDLE (WINAPI * PFNWGLCREATEBUFFERREGIONARBPROC) (HDC hDC, int iLayerPlane, UINT uType); 172 | typedef VOID (WINAPI * PFNWGLDELETEBUFFERREGIONARBPROC) (HANDLE hRegion); 173 | typedef BOOL (WINAPI * PFNWGLRESTOREBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc); 174 | typedef BOOL (WINAPI * PFNWGLSAVEBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height); 175 | 176 | #define wglCreateBufferRegionARB WGLEW_GET_FUN(__wglewCreateBufferRegionARB) 177 | #define wglDeleteBufferRegionARB WGLEW_GET_FUN(__wglewDeleteBufferRegionARB) 178 | #define wglRestoreBufferRegionARB WGLEW_GET_FUN(__wglewRestoreBufferRegionARB) 179 | #define wglSaveBufferRegionARB WGLEW_GET_FUN(__wglewSaveBufferRegionARB) 180 | 181 | #define WGLEW_ARB_buffer_region WGLEW_GET_VAR(__WGLEW_ARB_buffer_region) 182 | 183 | #endif /* WGL_ARB_buffer_region */ 184 | 185 | /* ------------------------- WGL_ARB_create_context ------------------------ */ 186 | 187 | #ifndef WGL_ARB_create_context 188 | #define WGL_ARB_create_context 1 189 | 190 | #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 191 | #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002 192 | #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 193 | #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 194 | #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 195 | #define WGL_CONTEXT_FLAGS_ARB 0x2094 196 | #define ERROR_INVALID_VERSION_ARB 0x2095 197 | #define ERROR_INVALID_PROFILE_ARB 0x2096 198 | 199 | typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int* attribList); 200 | 201 | #define wglCreateContextAttribsARB WGLEW_GET_FUN(__wglewCreateContextAttribsARB) 202 | 203 | #define WGLEW_ARB_create_context WGLEW_GET_VAR(__WGLEW_ARB_create_context) 204 | 205 | #endif /* WGL_ARB_create_context */ 206 | 207 | /* --------------------- WGL_ARB_create_context_profile -------------------- */ 208 | 209 | #ifndef WGL_ARB_create_context_profile 210 | #define WGL_ARB_create_context_profile 1 211 | 212 | #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 213 | #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 214 | #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 215 | 216 | #define WGLEW_ARB_create_context_profile WGLEW_GET_VAR(__WGLEW_ARB_create_context_profile) 217 | 218 | #endif /* WGL_ARB_create_context_profile */ 219 | 220 | /* ------------------- WGL_ARB_create_context_robustness ------------------- */ 221 | 222 | #ifndef WGL_ARB_create_context_robustness 223 | #define WGL_ARB_create_context_robustness 1 224 | 225 | #define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 226 | #define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 227 | #define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 228 | #define WGL_NO_RESET_NOTIFICATION_ARB 0x8261 229 | 230 | #define WGLEW_ARB_create_context_robustness WGLEW_GET_VAR(__WGLEW_ARB_create_context_robustness) 231 | 232 | #endif /* WGL_ARB_create_context_robustness */ 233 | 234 | /* ----------------------- WGL_ARB_extensions_string ----------------------- */ 235 | 236 | #ifndef WGL_ARB_extensions_string 237 | #define WGL_ARB_extensions_string 1 238 | 239 | typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc); 240 | 241 | #define wglGetExtensionsStringARB WGLEW_GET_FUN(__wglewGetExtensionsStringARB) 242 | 243 | #define WGLEW_ARB_extensions_string WGLEW_GET_VAR(__WGLEW_ARB_extensions_string) 244 | 245 | #endif /* WGL_ARB_extensions_string */ 246 | 247 | /* ------------------------ WGL_ARB_framebuffer_sRGB ----------------------- */ 248 | 249 | #ifndef WGL_ARB_framebuffer_sRGB 250 | #define WGL_ARB_framebuffer_sRGB 1 251 | 252 | #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9 253 | 254 | #define WGLEW_ARB_framebuffer_sRGB WGLEW_GET_VAR(__WGLEW_ARB_framebuffer_sRGB) 255 | 256 | #endif /* WGL_ARB_framebuffer_sRGB */ 257 | 258 | /* ----------------------- WGL_ARB_make_current_read ----------------------- */ 259 | 260 | #ifndef WGL_ARB_make_current_read 261 | #define WGL_ARB_make_current_read 1 262 | 263 | #define ERROR_INVALID_PIXEL_TYPE_ARB 0x2043 264 | #define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054 265 | 266 | typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCARBPROC) (VOID); 267 | typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTARBPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); 268 | 269 | #define wglGetCurrentReadDCARB WGLEW_GET_FUN(__wglewGetCurrentReadDCARB) 270 | #define wglMakeContextCurrentARB WGLEW_GET_FUN(__wglewMakeContextCurrentARB) 271 | 272 | #define WGLEW_ARB_make_current_read WGLEW_GET_VAR(__WGLEW_ARB_make_current_read) 273 | 274 | #endif /* WGL_ARB_make_current_read */ 275 | 276 | /* -------------------------- WGL_ARB_multisample -------------------------- */ 277 | 278 | #ifndef WGL_ARB_multisample 279 | #define WGL_ARB_multisample 1 280 | 281 | #define WGL_SAMPLE_BUFFERS_ARB 0x2041 282 | #define WGL_SAMPLES_ARB 0x2042 283 | 284 | #define WGLEW_ARB_multisample WGLEW_GET_VAR(__WGLEW_ARB_multisample) 285 | 286 | #endif /* WGL_ARB_multisample */ 287 | 288 | /* ---------------------------- WGL_ARB_pbuffer ---------------------------- */ 289 | 290 | #ifndef WGL_ARB_pbuffer 291 | #define WGL_ARB_pbuffer 1 292 | 293 | #define WGL_DRAW_TO_PBUFFER_ARB 0x202D 294 | #define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E 295 | #define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F 296 | #define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030 297 | #define WGL_PBUFFER_LARGEST_ARB 0x2033 298 | #define WGL_PBUFFER_WIDTH_ARB 0x2034 299 | #define WGL_PBUFFER_HEIGHT_ARB 0x2035 300 | #define WGL_PBUFFER_LOST_ARB 0x2036 301 | 302 | DECLARE_HANDLE(HPBUFFERARB); 303 | 304 | typedef HPBUFFERARB (WINAPI * PFNWGLCREATEPBUFFERARBPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int* piAttribList); 305 | typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFERARBPROC) (HPBUFFERARB hPbuffer); 306 | typedef HDC (WINAPI * PFNWGLGETPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer); 307 | typedef BOOL (WINAPI * PFNWGLQUERYPBUFFERARBPROC) (HPBUFFERARB hPbuffer, int iAttribute, int* piValue); 308 | typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer, HDC hDC); 309 | 310 | #define wglCreatePbufferARB WGLEW_GET_FUN(__wglewCreatePbufferARB) 311 | #define wglDestroyPbufferARB WGLEW_GET_FUN(__wglewDestroyPbufferARB) 312 | #define wglGetPbufferDCARB WGLEW_GET_FUN(__wglewGetPbufferDCARB) 313 | #define wglQueryPbufferARB WGLEW_GET_FUN(__wglewQueryPbufferARB) 314 | #define wglReleasePbufferDCARB WGLEW_GET_FUN(__wglewReleasePbufferDCARB) 315 | 316 | #define WGLEW_ARB_pbuffer WGLEW_GET_VAR(__WGLEW_ARB_pbuffer) 317 | 318 | #endif /* WGL_ARB_pbuffer */ 319 | 320 | /* -------------------------- WGL_ARB_pixel_format ------------------------- */ 321 | 322 | #ifndef WGL_ARB_pixel_format 323 | #define WGL_ARB_pixel_format 1 324 | 325 | #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 326 | #define WGL_DRAW_TO_WINDOW_ARB 0x2001 327 | #define WGL_DRAW_TO_BITMAP_ARB 0x2002 328 | #define WGL_ACCELERATION_ARB 0x2003 329 | #define WGL_NEED_PALETTE_ARB 0x2004 330 | #define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 331 | #define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 332 | #define WGL_SWAP_METHOD_ARB 0x2007 333 | #define WGL_NUMBER_OVERLAYS_ARB 0x2008 334 | #define WGL_NUMBER_UNDERLAYS_ARB 0x2009 335 | #define WGL_TRANSPARENT_ARB 0x200A 336 | #define WGL_SHARE_DEPTH_ARB 0x200C 337 | #define WGL_SHARE_STENCIL_ARB 0x200D 338 | #define WGL_SHARE_ACCUM_ARB 0x200E 339 | #define WGL_SUPPORT_GDI_ARB 0x200F 340 | #define WGL_SUPPORT_OPENGL_ARB 0x2010 341 | #define WGL_DOUBLE_BUFFER_ARB 0x2011 342 | #define WGL_STEREO_ARB 0x2012 343 | #define WGL_PIXEL_TYPE_ARB 0x2013 344 | #define WGL_COLOR_BITS_ARB 0x2014 345 | #define WGL_RED_BITS_ARB 0x2015 346 | #define WGL_RED_SHIFT_ARB 0x2016 347 | #define WGL_GREEN_BITS_ARB 0x2017 348 | #define WGL_GREEN_SHIFT_ARB 0x2018 349 | #define WGL_BLUE_BITS_ARB 0x2019 350 | #define WGL_BLUE_SHIFT_ARB 0x201A 351 | #define WGL_ALPHA_BITS_ARB 0x201B 352 | #define WGL_ALPHA_SHIFT_ARB 0x201C 353 | #define WGL_ACCUM_BITS_ARB 0x201D 354 | #define WGL_ACCUM_RED_BITS_ARB 0x201E 355 | #define WGL_ACCUM_GREEN_BITS_ARB 0x201F 356 | #define WGL_ACCUM_BLUE_BITS_ARB 0x2020 357 | #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 358 | #define WGL_DEPTH_BITS_ARB 0x2022 359 | #define WGL_STENCIL_BITS_ARB 0x2023 360 | #define WGL_AUX_BUFFERS_ARB 0x2024 361 | #define WGL_NO_ACCELERATION_ARB 0x2025 362 | #define WGL_GENERIC_ACCELERATION_ARB 0x2026 363 | #define WGL_FULL_ACCELERATION_ARB 0x2027 364 | #define WGL_SWAP_EXCHANGE_ARB 0x2028 365 | #define WGL_SWAP_COPY_ARB 0x2029 366 | #define WGL_SWAP_UNDEFINED_ARB 0x202A 367 | #define WGL_TYPE_RGBA_ARB 0x202B 368 | #define WGL_TYPE_COLORINDEX_ARB 0x202C 369 | #define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 370 | #define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 371 | #define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 372 | #define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A 373 | #define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B 374 | 375 | typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); 376 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int* piAttributes, FLOAT *pfValues); 377 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int* piAttributes, int *piValues); 378 | 379 | #define wglChoosePixelFormatARB WGLEW_GET_FUN(__wglewChoosePixelFormatARB) 380 | #define wglGetPixelFormatAttribfvARB WGLEW_GET_FUN(__wglewGetPixelFormatAttribfvARB) 381 | #define wglGetPixelFormatAttribivARB WGLEW_GET_FUN(__wglewGetPixelFormatAttribivARB) 382 | 383 | #define WGLEW_ARB_pixel_format WGLEW_GET_VAR(__WGLEW_ARB_pixel_format) 384 | 385 | #endif /* WGL_ARB_pixel_format */ 386 | 387 | /* ----------------------- WGL_ARB_pixel_format_float ---------------------- */ 388 | 389 | #ifndef WGL_ARB_pixel_format_float 390 | #define WGL_ARB_pixel_format_float 1 391 | 392 | #define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0 393 | 394 | #define WGLEW_ARB_pixel_format_float WGLEW_GET_VAR(__WGLEW_ARB_pixel_format_float) 395 | 396 | #endif /* WGL_ARB_pixel_format_float */ 397 | 398 | /* ------------------------- WGL_ARB_render_texture ------------------------ */ 399 | 400 | #ifndef WGL_ARB_render_texture 401 | #define WGL_ARB_render_texture 1 402 | 403 | #define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070 404 | #define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071 405 | #define WGL_TEXTURE_FORMAT_ARB 0x2072 406 | #define WGL_TEXTURE_TARGET_ARB 0x2073 407 | #define WGL_MIPMAP_TEXTURE_ARB 0x2074 408 | #define WGL_TEXTURE_RGB_ARB 0x2075 409 | #define WGL_TEXTURE_RGBA_ARB 0x2076 410 | #define WGL_NO_TEXTURE_ARB 0x2077 411 | #define WGL_TEXTURE_CUBE_MAP_ARB 0x2078 412 | #define WGL_TEXTURE_1D_ARB 0x2079 413 | #define WGL_TEXTURE_2D_ARB 0x207A 414 | #define WGL_MIPMAP_LEVEL_ARB 0x207B 415 | #define WGL_CUBE_MAP_FACE_ARB 0x207C 416 | #define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D 417 | #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E 418 | #define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F 419 | #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080 420 | #define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081 421 | #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082 422 | #define WGL_FRONT_LEFT_ARB 0x2083 423 | #define WGL_FRONT_RIGHT_ARB 0x2084 424 | #define WGL_BACK_LEFT_ARB 0x2085 425 | #define WGL_BACK_RIGHT_ARB 0x2086 426 | #define WGL_AUX0_ARB 0x2087 427 | #define WGL_AUX1_ARB 0x2088 428 | #define WGL_AUX2_ARB 0x2089 429 | #define WGL_AUX3_ARB 0x208A 430 | #define WGL_AUX4_ARB 0x208B 431 | #define WGL_AUX5_ARB 0x208C 432 | #define WGL_AUX6_ARB 0x208D 433 | #define WGL_AUX7_ARB 0x208E 434 | #define WGL_AUX8_ARB 0x208F 435 | #define WGL_AUX9_ARB 0x2090 436 | 437 | typedef BOOL (WINAPI * PFNWGLBINDTEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); 438 | typedef BOOL (WINAPI * PFNWGLRELEASETEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); 439 | typedef BOOL (WINAPI * PFNWGLSETPBUFFERATTRIBARBPROC) (HPBUFFERARB hPbuffer, const int* piAttribList); 440 | 441 | #define wglBindTexImageARB WGLEW_GET_FUN(__wglewBindTexImageARB) 442 | #define wglReleaseTexImageARB WGLEW_GET_FUN(__wglewReleaseTexImageARB) 443 | #define wglSetPbufferAttribARB WGLEW_GET_FUN(__wglewSetPbufferAttribARB) 444 | 445 | #define WGLEW_ARB_render_texture WGLEW_GET_VAR(__WGLEW_ARB_render_texture) 446 | 447 | #endif /* WGL_ARB_render_texture */ 448 | 449 | /* ----------------------- WGL_ATI_pixel_format_float ---------------------- */ 450 | 451 | #ifndef WGL_ATI_pixel_format_float 452 | #define WGL_ATI_pixel_format_float 1 453 | 454 | #define WGL_TYPE_RGBA_FLOAT_ATI 0x21A0 455 | #define GL_RGBA_FLOAT_MODE_ATI 0x8820 456 | #define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835 457 | 458 | #define WGLEW_ATI_pixel_format_float WGLEW_GET_VAR(__WGLEW_ATI_pixel_format_float) 459 | 460 | #endif /* WGL_ATI_pixel_format_float */ 461 | 462 | /* -------------------- WGL_ATI_render_texture_rectangle ------------------- */ 463 | 464 | #ifndef WGL_ATI_render_texture_rectangle 465 | #define WGL_ATI_render_texture_rectangle 1 466 | 467 | #define WGL_TEXTURE_RECTANGLE_ATI 0x21A5 468 | 469 | #define WGLEW_ATI_render_texture_rectangle WGLEW_GET_VAR(__WGLEW_ATI_render_texture_rectangle) 470 | 471 | #endif /* WGL_ATI_render_texture_rectangle */ 472 | 473 | /* ------------------- WGL_EXT_create_context_es2_profile ------------------ */ 474 | 475 | #ifndef WGL_EXT_create_context_es2_profile 476 | #define WGL_EXT_create_context_es2_profile 1 477 | 478 | #define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 479 | 480 | #define WGLEW_EXT_create_context_es2_profile WGLEW_GET_VAR(__WGLEW_EXT_create_context_es2_profile) 481 | 482 | #endif /* WGL_EXT_create_context_es2_profile */ 483 | 484 | /* -------------------------- WGL_EXT_depth_float -------------------------- */ 485 | 486 | #ifndef WGL_EXT_depth_float 487 | #define WGL_EXT_depth_float 1 488 | 489 | #define WGL_DEPTH_FLOAT_EXT 0x2040 490 | 491 | #define WGLEW_EXT_depth_float WGLEW_GET_VAR(__WGLEW_EXT_depth_float) 492 | 493 | #endif /* WGL_EXT_depth_float */ 494 | 495 | /* ---------------------- WGL_EXT_display_color_table ---------------------- */ 496 | 497 | #ifndef WGL_EXT_display_color_table 498 | #define WGL_EXT_display_color_table 1 499 | 500 | typedef GLboolean (WINAPI * PFNWGLBINDDISPLAYCOLORTABLEEXTPROC) (GLushort id); 501 | typedef GLboolean (WINAPI * PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC) (GLushort id); 502 | typedef void (WINAPI * PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC) (GLushort id); 503 | typedef GLboolean (WINAPI * PFNWGLLOADDISPLAYCOLORTABLEEXTPROC) (GLushort* table, GLuint length); 504 | 505 | #define wglBindDisplayColorTableEXT WGLEW_GET_FUN(__wglewBindDisplayColorTableEXT) 506 | #define wglCreateDisplayColorTableEXT WGLEW_GET_FUN(__wglewCreateDisplayColorTableEXT) 507 | #define wglDestroyDisplayColorTableEXT WGLEW_GET_FUN(__wglewDestroyDisplayColorTableEXT) 508 | #define wglLoadDisplayColorTableEXT WGLEW_GET_FUN(__wglewLoadDisplayColorTableEXT) 509 | 510 | #define WGLEW_EXT_display_color_table WGLEW_GET_VAR(__WGLEW_EXT_display_color_table) 511 | 512 | #endif /* WGL_EXT_display_color_table */ 513 | 514 | /* ----------------------- WGL_EXT_extensions_string ----------------------- */ 515 | 516 | #ifndef WGL_EXT_extensions_string 517 | #define WGL_EXT_extensions_string 1 518 | 519 | typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC) (void); 520 | 521 | #define wglGetExtensionsStringEXT WGLEW_GET_FUN(__wglewGetExtensionsStringEXT) 522 | 523 | #define WGLEW_EXT_extensions_string WGLEW_GET_VAR(__WGLEW_EXT_extensions_string) 524 | 525 | #endif /* WGL_EXT_extensions_string */ 526 | 527 | /* ------------------------ WGL_EXT_framebuffer_sRGB ----------------------- */ 528 | 529 | #ifndef WGL_EXT_framebuffer_sRGB 530 | #define WGL_EXT_framebuffer_sRGB 1 531 | 532 | #define WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20A9 533 | 534 | #define WGLEW_EXT_framebuffer_sRGB WGLEW_GET_VAR(__WGLEW_EXT_framebuffer_sRGB) 535 | 536 | #endif /* WGL_EXT_framebuffer_sRGB */ 537 | 538 | /* ----------------------- WGL_EXT_make_current_read ----------------------- */ 539 | 540 | #ifndef WGL_EXT_make_current_read 541 | #define WGL_EXT_make_current_read 1 542 | 543 | #define ERROR_INVALID_PIXEL_TYPE_EXT 0x2043 544 | 545 | typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCEXTPROC) (VOID); 546 | typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTEXTPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); 547 | 548 | #define wglGetCurrentReadDCEXT WGLEW_GET_FUN(__wglewGetCurrentReadDCEXT) 549 | #define wglMakeContextCurrentEXT WGLEW_GET_FUN(__wglewMakeContextCurrentEXT) 550 | 551 | #define WGLEW_EXT_make_current_read WGLEW_GET_VAR(__WGLEW_EXT_make_current_read) 552 | 553 | #endif /* WGL_EXT_make_current_read */ 554 | 555 | /* -------------------------- WGL_EXT_multisample -------------------------- */ 556 | 557 | #ifndef WGL_EXT_multisample 558 | #define WGL_EXT_multisample 1 559 | 560 | #define WGL_SAMPLE_BUFFERS_EXT 0x2041 561 | #define WGL_SAMPLES_EXT 0x2042 562 | 563 | #define WGLEW_EXT_multisample WGLEW_GET_VAR(__WGLEW_EXT_multisample) 564 | 565 | #endif /* WGL_EXT_multisample */ 566 | 567 | /* ---------------------------- WGL_EXT_pbuffer ---------------------------- */ 568 | 569 | #ifndef WGL_EXT_pbuffer 570 | #define WGL_EXT_pbuffer 1 571 | 572 | #define WGL_DRAW_TO_PBUFFER_EXT 0x202D 573 | #define WGL_MAX_PBUFFER_PIXELS_EXT 0x202E 574 | #define WGL_MAX_PBUFFER_WIDTH_EXT 0x202F 575 | #define WGL_MAX_PBUFFER_HEIGHT_EXT 0x2030 576 | #define WGL_OPTIMAL_PBUFFER_WIDTH_EXT 0x2031 577 | #define WGL_OPTIMAL_PBUFFER_HEIGHT_EXT 0x2032 578 | #define WGL_PBUFFER_LARGEST_EXT 0x2033 579 | #define WGL_PBUFFER_WIDTH_EXT 0x2034 580 | #define WGL_PBUFFER_HEIGHT_EXT 0x2035 581 | 582 | DECLARE_HANDLE(HPBUFFEREXT); 583 | 584 | typedef HPBUFFEREXT (WINAPI * PFNWGLCREATEPBUFFEREXTPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int* piAttribList); 585 | typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer); 586 | typedef HDC (WINAPI * PFNWGLGETPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer); 587 | typedef BOOL (WINAPI * PFNWGLQUERYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer, int iAttribute, int* piValue); 588 | typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer, HDC hDC); 589 | 590 | #define wglCreatePbufferEXT WGLEW_GET_FUN(__wglewCreatePbufferEXT) 591 | #define wglDestroyPbufferEXT WGLEW_GET_FUN(__wglewDestroyPbufferEXT) 592 | #define wglGetPbufferDCEXT WGLEW_GET_FUN(__wglewGetPbufferDCEXT) 593 | #define wglQueryPbufferEXT WGLEW_GET_FUN(__wglewQueryPbufferEXT) 594 | #define wglReleasePbufferDCEXT WGLEW_GET_FUN(__wglewReleasePbufferDCEXT) 595 | 596 | #define WGLEW_EXT_pbuffer WGLEW_GET_VAR(__WGLEW_EXT_pbuffer) 597 | 598 | #endif /* WGL_EXT_pbuffer */ 599 | 600 | /* -------------------------- WGL_EXT_pixel_format ------------------------- */ 601 | 602 | #ifndef WGL_EXT_pixel_format 603 | #define WGL_EXT_pixel_format 1 604 | 605 | #define WGL_NUMBER_PIXEL_FORMATS_EXT 0x2000 606 | #define WGL_DRAW_TO_WINDOW_EXT 0x2001 607 | #define WGL_DRAW_TO_BITMAP_EXT 0x2002 608 | #define WGL_ACCELERATION_EXT 0x2003 609 | #define WGL_NEED_PALETTE_EXT 0x2004 610 | #define WGL_NEED_SYSTEM_PALETTE_EXT 0x2005 611 | #define WGL_SWAP_LAYER_BUFFERS_EXT 0x2006 612 | #define WGL_SWAP_METHOD_EXT 0x2007 613 | #define WGL_NUMBER_OVERLAYS_EXT 0x2008 614 | #define WGL_NUMBER_UNDERLAYS_EXT 0x2009 615 | #define WGL_TRANSPARENT_EXT 0x200A 616 | #define WGL_TRANSPARENT_VALUE_EXT 0x200B 617 | #define WGL_SHARE_DEPTH_EXT 0x200C 618 | #define WGL_SHARE_STENCIL_EXT 0x200D 619 | #define WGL_SHARE_ACCUM_EXT 0x200E 620 | #define WGL_SUPPORT_GDI_EXT 0x200F 621 | #define WGL_SUPPORT_OPENGL_EXT 0x2010 622 | #define WGL_DOUBLE_BUFFER_EXT 0x2011 623 | #define WGL_STEREO_EXT 0x2012 624 | #define WGL_PIXEL_TYPE_EXT 0x2013 625 | #define WGL_COLOR_BITS_EXT 0x2014 626 | #define WGL_RED_BITS_EXT 0x2015 627 | #define WGL_RED_SHIFT_EXT 0x2016 628 | #define WGL_GREEN_BITS_EXT 0x2017 629 | #define WGL_GREEN_SHIFT_EXT 0x2018 630 | #define WGL_BLUE_BITS_EXT 0x2019 631 | #define WGL_BLUE_SHIFT_EXT 0x201A 632 | #define WGL_ALPHA_BITS_EXT 0x201B 633 | #define WGL_ALPHA_SHIFT_EXT 0x201C 634 | #define WGL_ACCUM_BITS_EXT 0x201D 635 | #define WGL_ACCUM_RED_BITS_EXT 0x201E 636 | #define WGL_ACCUM_GREEN_BITS_EXT 0x201F 637 | #define WGL_ACCUM_BLUE_BITS_EXT 0x2020 638 | #define WGL_ACCUM_ALPHA_BITS_EXT 0x2021 639 | #define WGL_DEPTH_BITS_EXT 0x2022 640 | #define WGL_STENCIL_BITS_EXT 0x2023 641 | #define WGL_AUX_BUFFERS_EXT 0x2024 642 | #define WGL_NO_ACCELERATION_EXT 0x2025 643 | #define WGL_GENERIC_ACCELERATION_EXT 0x2026 644 | #define WGL_FULL_ACCELERATION_EXT 0x2027 645 | #define WGL_SWAP_EXCHANGE_EXT 0x2028 646 | #define WGL_SWAP_COPY_EXT 0x2029 647 | #define WGL_SWAP_UNDEFINED_EXT 0x202A 648 | #define WGL_TYPE_RGBA_EXT 0x202B 649 | #define WGL_TYPE_COLORINDEX_EXT 0x202C 650 | 651 | typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATEXTPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); 652 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, FLOAT *pfValues); 653 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, int *piValues); 654 | 655 | #define wglChoosePixelFormatEXT WGLEW_GET_FUN(__wglewChoosePixelFormatEXT) 656 | #define wglGetPixelFormatAttribfvEXT WGLEW_GET_FUN(__wglewGetPixelFormatAttribfvEXT) 657 | #define wglGetPixelFormatAttribivEXT WGLEW_GET_FUN(__wglewGetPixelFormatAttribivEXT) 658 | 659 | #define WGLEW_EXT_pixel_format WGLEW_GET_VAR(__WGLEW_EXT_pixel_format) 660 | 661 | #endif /* WGL_EXT_pixel_format */ 662 | 663 | /* ------------------- WGL_EXT_pixel_format_packed_float ------------------- */ 664 | 665 | #ifndef WGL_EXT_pixel_format_packed_float 666 | #define WGL_EXT_pixel_format_packed_float 1 667 | 668 | #define WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT 0x20A8 669 | 670 | #define WGLEW_EXT_pixel_format_packed_float WGLEW_GET_VAR(__WGLEW_EXT_pixel_format_packed_float) 671 | 672 | #endif /* WGL_EXT_pixel_format_packed_float */ 673 | 674 | /* -------------------------- WGL_EXT_swap_control ------------------------- */ 675 | 676 | #ifndef WGL_EXT_swap_control 677 | #define WGL_EXT_swap_control 1 678 | 679 | typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void); 680 | typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval); 681 | 682 | #define wglGetSwapIntervalEXT WGLEW_GET_FUN(__wglewGetSwapIntervalEXT) 683 | #define wglSwapIntervalEXT WGLEW_GET_FUN(__wglewSwapIntervalEXT) 684 | 685 | #define WGLEW_EXT_swap_control WGLEW_GET_VAR(__WGLEW_EXT_swap_control) 686 | 687 | #endif /* WGL_EXT_swap_control */ 688 | 689 | /* --------------------- WGL_I3D_digital_video_control --------------------- */ 690 | 691 | #ifndef WGL_I3D_digital_video_control 692 | #define WGL_I3D_digital_video_control 1 693 | 694 | #define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D 0x2050 695 | #define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D 0x2051 696 | #define WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D 0x2052 697 | #define WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D 0x2053 698 | 699 | typedef BOOL (WINAPI * PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int* piValue); 700 | typedef BOOL (WINAPI * PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int* piValue); 701 | 702 | #define wglGetDigitalVideoParametersI3D WGLEW_GET_FUN(__wglewGetDigitalVideoParametersI3D) 703 | #define wglSetDigitalVideoParametersI3D WGLEW_GET_FUN(__wglewSetDigitalVideoParametersI3D) 704 | 705 | #define WGLEW_I3D_digital_video_control WGLEW_GET_VAR(__WGLEW_I3D_digital_video_control) 706 | 707 | #endif /* WGL_I3D_digital_video_control */ 708 | 709 | /* ----------------------------- WGL_I3D_gamma ----------------------------- */ 710 | 711 | #ifndef WGL_I3D_gamma 712 | #define WGL_I3D_gamma 1 713 | 714 | #define WGL_GAMMA_TABLE_SIZE_I3D 0x204E 715 | #define WGL_GAMMA_EXCLUDE_DESKTOP_I3D 0x204F 716 | 717 | typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, USHORT* puRed, USHORT *puGreen, USHORT *puBlue); 718 | typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int* piValue); 719 | typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, const USHORT* puRed, const USHORT *puGreen, const USHORT *puBlue); 720 | typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int* piValue); 721 | 722 | #define wglGetGammaTableI3D WGLEW_GET_FUN(__wglewGetGammaTableI3D) 723 | #define wglGetGammaTableParametersI3D WGLEW_GET_FUN(__wglewGetGammaTableParametersI3D) 724 | #define wglSetGammaTableI3D WGLEW_GET_FUN(__wglewSetGammaTableI3D) 725 | #define wglSetGammaTableParametersI3D WGLEW_GET_FUN(__wglewSetGammaTableParametersI3D) 726 | 727 | #define WGLEW_I3D_gamma WGLEW_GET_VAR(__WGLEW_I3D_gamma) 728 | 729 | #endif /* WGL_I3D_gamma */ 730 | 731 | /* ---------------------------- WGL_I3D_genlock ---------------------------- */ 732 | 733 | #ifndef WGL_I3D_genlock 734 | #define WGL_I3D_genlock 1 735 | 736 | #define WGL_GENLOCK_SOURCE_MULTIVIEW_I3D 0x2044 737 | #define WGL_GENLOCK_SOURCE_EXTERNAL_SYNC_I3D 0x2045 738 | #define WGL_GENLOCK_SOURCE_EXTERNAL_FIELD_I3D 0x2046 739 | #define WGL_GENLOCK_SOURCE_EXTERNAL_TTL_I3D 0x2047 740 | #define WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D 0x2048 741 | #define WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D 0x2049 742 | #define WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D 0x204A 743 | #define WGL_GENLOCK_SOURCE_EDGE_RISING_I3D 0x204B 744 | #define WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D 0x204C 745 | 746 | typedef BOOL (WINAPI * PFNWGLDISABLEGENLOCKI3DPROC) (HDC hDC); 747 | typedef BOOL (WINAPI * PFNWGLENABLEGENLOCKI3DPROC) (HDC hDC); 748 | typedef BOOL (WINAPI * PFNWGLGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT uRate); 749 | typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT uDelay); 750 | typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT uEdge); 751 | typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEI3DPROC) (HDC hDC, UINT uSource); 752 | typedef BOOL (WINAPI * PFNWGLGETGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT* uRate); 753 | typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT* uDelay); 754 | typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT* uEdge); 755 | typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEI3DPROC) (HDC hDC, UINT* uSource); 756 | typedef BOOL (WINAPI * PFNWGLISENABLEDGENLOCKI3DPROC) (HDC hDC, BOOL* pFlag); 757 | typedef BOOL (WINAPI * PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC) (HDC hDC, UINT* uMaxLineDelay, UINT *uMaxPixelDelay); 758 | 759 | #define wglDisableGenlockI3D WGLEW_GET_FUN(__wglewDisableGenlockI3D) 760 | #define wglEnableGenlockI3D WGLEW_GET_FUN(__wglewEnableGenlockI3D) 761 | #define wglGenlockSampleRateI3D WGLEW_GET_FUN(__wglewGenlockSampleRateI3D) 762 | #define wglGenlockSourceDelayI3D WGLEW_GET_FUN(__wglewGenlockSourceDelayI3D) 763 | #define wglGenlockSourceEdgeI3D WGLEW_GET_FUN(__wglewGenlockSourceEdgeI3D) 764 | #define wglGenlockSourceI3D WGLEW_GET_FUN(__wglewGenlockSourceI3D) 765 | #define wglGetGenlockSampleRateI3D WGLEW_GET_FUN(__wglewGetGenlockSampleRateI3D) 766 | #define wglGetGenlockSourceDelayI3D WGLEW_GET_FUN(__wglewGetGenlockSourceDelayI3D) 767 | #define wglGetGenlockSourceEdgeI3D WGLEW_GET_FUN(__wglewGetGenlockSourceEdgeI3D) 768 | #define wglGetGenlockSourceI3D WGLEW_GET_FUN(__wglewGetGenlockSourceI3D) 769 | #define wglIsEnabledGenlockI3D WGLEW_GET_FUN(__wglewIsEnabledGenlockI3D) 770 | #define wglQueryGenlockMaxSourceDelayI3D WGLEW_GET_FUN(__wglewQueryGenlockMaxSourceDelayI3D) 771 | 772 | #define WGLEW_I3D_genlock WGLEW_GET_VAR(__WGLEW_I3D_genlock) 773 | 774 | #endif /* WGL_I3D_genlock */ 775 | 776 | /* -------------------------- WGL_I3D_image_buffer ------------------------- */ 777 | 778 | #ifndef WGL_I3D_image_buffer 779 | #define WGL_I3D_image_buffer 1 780 | 781 | #define WGL_IMAGE_BUFFER_MIN_ACCESS_I3D 0x00000001 782 | #define WGL_IMAGE_BUFFER_LOCK_I3D 0x00000002 783 | 784 | typedef BOOL (WINAPI * PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC) (HDC hdc, HANDLE* pEvent, LPVOID *pAddress, DWORD *pSize, UINT count); 785 | typedef LPVOID (WINAPI * PFNWGLCREATEIMAGEBUFFERI3DPROC) (HDC hDC, DWORD dwSize, UINT uFlags); 786 | typedef BOOL (WINAPI * PFNWGLDESTROYIMAGEBUFFERI3DPROC) (HDC hDC, LPVOID pAddress); 787 | typedef BOOL (WINAPI * PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC) (HDC hdc, LPVOID* pAddress, UINT count); 788 | 789 | #define wglAssociateImageBufferEventsI3D WGLEW_GET_FUN(__wglewAssociateImageBufferEventsI3D) 790 | #define wglCreateImageBufferI3D WGLEW_GET_FUN(__wglewCreateImageBufferI3D) 791 | #define wglDestroyImageBufferI3D WGLEW_GET_FUN(__wglewDestroyImageBufferI3D) 792 | #define wglReleaseImageBufferEventsI3D WGLEW_GET_FUN(__wglewReleaseImageBufferEventsI3D) 793 | 794 | #define WGLEW_I3D_image_buffer WGLEW_GET_VAR(__WGLEW_I3D_image_buffer) 795 | 796 | #endif /* WGL_I3D_image_buffer */ 797 | 798 | /* ------------------------ WGL_I3D_swap_frame_lock ------------------------ */ 799 | 800 | #ifndef WGL_I3D_swap_frame_lock 801 | #define WGL_I3D_swap_frame_lock 1 802 | 803 | typedef BOOL (WINAPI * PFNWGLDISABLEFRAMELOCKI3DPROC) (VOID); 804 | typedef BOOL (WINAPI * PFNWGLENABLEFRAMELOCKI3DPROC) (VOID); 805 | typedef BOOL (WINAPI * PFNWGLISENABLEDFRAMELOCKI3DPROC) (BOOL* pFlag); 806 | typedef BOOL (WINAPI * PFNWGLQUERYFRAMELOCKMASTERI3DPROC) (BOOL* pFlag); 807 | 808 | #define wglDisableFrameLockI3D WGLEW_GET_FUN(__wglewDisableFrameLockI3D) 809 | #define wglEnableFrameLockI3D WGLEW_GET_FUN(__wglewEnableFrameLockI3D) 810 | #define wglIsEnabledFrameLockI3D WGLEW_GET_FUN(__wglewIsEnabledFrameLockI3D) 811 | #define wglQueryFrameLockMasterI3D WGLEW_GET_FUN(__wglewQueryFrameLockMasterI3D) 812 | 813 | #define WGLEW_I3D_swap_frame_lock WGLEW_GET_VAR(__WGLEW_I3D_swap_frame_lock) 814 | 815 | #endif /* WGL_I3D_swap_frame_lock */ 816 | 817 | /* ------------------------ WGL_I3D_swap_frame_usage ----------------------- */ 818 | 819 | #ifndef WGL_I3D_swap_frame_usage 820 | #define WGL_I3D_swap_frame_usage 1 821 | 822 | typedef BOOL (WINAPI * PFNWGLBEGINFRAMETRACKINGI3DPROC) (void); 823 | typedef BOOL (WINAPI * PFNWGLENDFRAMETRACKINGI3DPROC) (void); 824 | typedef BOOL (WINAPI * PFNWGLGETFRAMEUSAGEI3DPROC) (float* pUsage); 825 | typedef BOOL (WINAPI * PFNWGLQUERYFRAMETRACKINGI3DPROC) (DWORD* pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage); 826 | 827 | #define wglBeginFrameTrackingI3D WGLEW_GET_FUN(__wglewBeginFrameTrackingI3D) 828 | #define wglEndFrameTrackingI3D WGLEW_GET_FUN(__wglewEndFrameTrackingI3D) 829 | #define wglGetFrameUsageI3D WGLEW_GET_FUN(__wglewGetFrameUsageI3D) 830 | #define wglQueryFrameTrackingI3D WGLEW_GET_FUN(__wglewQueryFrameTrackingI3D) 831 | 832 | #define WGLEW_I3D_swap_frame_usage WGLEW_GET_VAR(__WGLEW_I3D_swap_frame_usage) 833 | 834 | #endif /* WGL_I3D_swap_frame_usage */ 835 | 836 | /* --------------------------- WGL_NV_DX_interop --------------------------- */ 837 | 838 | #ifndef WGL_NV_DX_interop 839 | #define WGL_NV_DX_interop 1 840 | 841 | #define WGL_ACCESS_READ_ONLY_NV 0x0000 842 | #define WGL_ACCESS_READ_WRITE_NV 0x0001 843 | #define WGL_ACCESS_WRITE_DISCARD_NV 0x0002 844 | 845 | typedef BOOL (WINAPI * PFNWGLDXCLOSEDEVICENVPROC) (HANDLE hDevice); 846 | typedef BOOL (WINAPI * PFNWGLDXLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE* hObjects); 847 | typedef BOOL (WINAPI * PFNWGLDXOBJECTACCESSNVPROC) (HANDLE hObject, GLenum access); 848 | typedef HANDLE (WINAPI * PFNWGLDXOPENDEVICENVPROC) (void* dxDevice); 849 | typedef HANDLE (WINAPI * PFNWGLDXREGISTEROBJECTNVPROC) (HANDLE hDevice, void* dxObject, GLuint name, GLenum type, GLenum access); 850 | typedef BOOL (WINAPI * PFNWGLDXSETRESOURCESHAREHANDLENVPROC) (void* dxObject, HANDLE shareHandle); 851 | typedef BOOL (WINAPI * PFNWGLDXUNLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE* hObjects); 852 | typedef BOOL (WINAPI * PFNWGLDXUNREGISTEROBJECTNVPROC) (HANDLE hDevice, HANDLE hObject); 853 | 854 | #define wglDXCloseDeviceNV WGLEW_GET_FUN(__wglewDXCloseDeviceNV) 855 | #define wglDXLockObjectsNV WGLEW_GET_FUN(__wglewDXLockObjectsNV) 856 | #define wglDXObjectAccessNV WGLEW_GET_FUN(__wglewDXObjectAccessNV) 857 | #define wglDXOpenDeviceNV WGLEW_GET_FUN(__wglewDXOpenDeviceNV) 858 | #define wglDXRegisterObjectNV WGLEW_GET_FUN(__wglewDXRegisterObjectNV) 859 | #define wglDXSetResourceShareHandleNV WGLEW_GET_FUN(__wglewDXSetResourceShareHandleNV) 860 | #define wglDXUnlockObjectsNV WGLEW_GET_FUN(__wglewDXUnlockObjectsNV) 861 | #define wglDXUnregisterObjectNV WGLEW_GET_FUN(__wglewDXUnregisterObjectNV) 862 | 863 | #define WGLEW_NV_DX_interop WGLEW_GET_VAR(__WGLEW_NV_DX_interop) 864 | 865 | #endif /* WGL_NV_DX_interop */ 866 | 867 | /* --------------------------- WGL_NV_copy_image --------------------------- */ 868 | 869 | #ifndef WGL_NV_copy_image 870 | #define WGL_NV_copy_image 1 871 | 872 | typedef BOOL (WINAPI * PFNWGLCOPYIMAGESUBDATANVPROC) (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); 873 | 874 | #define wglCopyImageSubDataNV WGLEW_GET_FUN(__wglewCopyImageSubDataNV) 875 | 876 | #define WGLEW_NV_copy_image WGLEW_GET_VAR(__WGLEW_NV_copy_image) 877 | 878 | #endif /* WGL_NV_copy_image */ 879 | 880 | /* -------------------------- WGL_NV_float_buffer -------------------------- */ 881 | 882 | #ifndef WGL_NV_float_buffer 883 | #define WGL_NV_float_buffer 1 884 | 885 | #define WGL_FLOAT_COMPONENTS_NV 0x20B0 886 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1 887 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2 888 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3 889 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4 890 | #define WGL_TEXTURE_FLOAT_R_NV 0x20B5 891 | #define WGL_TEXTURE_FLOAT_RG_NV 0x20B6 892 | #define WGL_TEXTURE_FLOAT_RGB_NV 0x20B7 893 | #define WGL_TEXTURE_FLOAT_RGBA_NV 0x20B8 894 | 895 | #define WGLEW_NV_float_buffer WGLEW_GET_VAR(__WGLEW_NV_float_buffer) 896 | 897 | #endif /* WGL_NV_float_buffer */ 898 | 899 | /* -------------------------- WGL_NV_gpu_affinity -------------------------- */ 900 | 901 | #ifndef WGL_NV_gpu_affinity 902 | #define WGL_NV_gpu_affinity 1 903 | 904 | #define WGL_ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV 0x20D0 905 | #define WGL_ERROR_MISSING_AFFINITY_MASK_NV 0x20D1 906 | 907 | DECLARE_HANDLE(HGPUNV); 908 | typedef struct _GPU_DEVICE { 909 | DWORD cb; 910 | CHAR DeviceName[32]; 911 | CHAR DeviceString[128]; 912 | DWORD Flags; 913 | RECT rcVirtualScreen; 914 | } GPU_DEVICE, *PGPU_DEVICE; 915 | 916 | typedef HDC (WINAPI * PFNWGLCREATEAFFINITYDCNVPROC) (const HGPUNV *phGpuList); 917 | typedef BOOL (WINAPI * PFNWGLDELETEDCNVPROC) (HDC hdc); 918 | typedef BOOL (WINAPI * PFNWGLENUMGPUDEVICESNVPROC) (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice); 919 | typedef BOOL (WINAPI * PFNWGLENUMGPUSFROMAFFINITYDCNVPROC) (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu); 920 | typedef BOOL (WINAPI * PFNWGLENUMGPUSNVPROC) (UINT iGpuIndex, HGPUNV *phGpu); 921 | 922 | #define wglCreateAffinityDCNV WGLEW_GET_FUN(__wglewCreateAffinityDCNV) 923 | #define wglDeleteDCNV WGLEW_GET_FUN(__wglewDeleteDCNV) 924 | #define wglEnumGpuDevicesNV WGLEW_GET_FUN(__wglewEnumGpuDevicesNV) 925 | #define wglEnumGpusFromAffinityDCNV WGLEW_GET_FUN(__wglewEnumGpusFromAffinityDCNV) 926 | #define wglEnumGpusNV WGLEW_GET_FUN(__wglewEnumGpusNV) 927 | 928 | #define WGLEW_NV_gpu_affinity WGLEW_GET_VAR(__WGLEW_NV_gpu_affinity) 929 | 930 | #endif /* WGL_NV_gpu_affinity */ 931 | 932 | /* ---------------------- WGL_NV_multisample_coverage ---------------------- */ 933 | 934 | #ifndef WGL_NV_multisample_coverage 935 | #define WGL_NV_multisample_coverage 1 936 | 937 | #define WGL_COVERAGE_SAMPLES_NV 0x2042 938 | #define WGL_COLOR_SAMPLES_NV 0x20B9 939 | 940 | #define WGLEW_NV_multisample_coverage WGLEW_GET_VAR(__WGLEW_NV_multisample_coverage) 941 | 942 | #endif /* WGL_NV_multisample_coverage */ 943 | 944 | /* -------------------------- WGL_NV_present_video ------------------------- */ 945 | 946 | #ifndef WGL_NV_present_video 947 | #define WGL_NV_present_video 1 948 | 949 | #define WGL_NUM_VIDEO_SLOTS_NV 0x20F0 950 | 951 | DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV); 952 | 953 | typedef BOOL (WINAPI * PFNWGLBINDVIDEODEVICENVPROC) (HDC hDc, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int* piAttribList); 954 | typedef int (WINAPI * PFNWGLENUMERATEVIDEODEVICESNVPROC) (HDC hDc, HVIDEOOUTPUTDEVICENV* phDeviceList); 955 | typedef BOOL (WINAPI * PFNWGLQUERYCURRENTCONTEXTNVPROC) (int iAttribute, int* piValue); 956 | 957 | #define wglBindVideoDeviceNV WGLEW_GET_FUN(__wglewBindVideoDeviceNV) 958 | #define wglEnumerateVideoDevicesNV WGLEW_GET_FUN(__wglewEnumerateVideoDevicesNV) 959 | #define wglQueryCurrentContextNV WGLEW_GET_FUN(__wglewQueryCurrentContextNV) 960 | 961 | #define WGLEW_NV_present_video WGLEW_GET_VAR(__WGLEW_NV_present_video) 962 | 963 | #endif /* WGL_NV_present_video */ 964 | 965 | /* ---------------------- WGL_NV_render_depth_texture ---------------------- */ 966 | 967 | #ifndef WGL_NV_render_depth_texture 968 | #define WGL_NV_render_depth_texture 1 969 | 970 | #define WGL_NO_TEXTURE_ARB 0x2077 971 | #define WGL_BIND_TO_TEXTURE_DEPTH_NV 0x20A3 972 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4 973 | #define WGL_DEPTH_TEXTURE_FORMAT_NV 0x20A5 974 | #define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6 975 | #define WGL_DEPTH_COMPONENT_NV 0x20A7 976 | 977 | #define WGLEW_NV_render_depth_texture WGLEW_GET_VAR(__WGLEW_NV_render_depth_texture) 978 | 979 | #endif /* WGL_NV_render_depth_texture */ 980 | 981 | /* -------------------- WGL_NV_render_texture_rectangle -------------------- */ 982 | 983 | #ifndef WGL_NV_render_texture_rectangle 984 | #define WGL_NV_render_texture_rectangle 1 985 | 986 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0 987 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1 988 | #define WGL_TEXTURE_RECTANGLE_NV 0x20A2 989 | 990 | #define WGLEW_NV_render_texture_rectangle WGLEW_GET_VAR(__WGLEW_NV_render_texture_rectangle) 991 | 992 | #endif /* WGL_NV_render_texture_rectangle */ 993 | 994 | /* --------------------------- WGL_NV_swap_group --------------------------- */ 995 | 996 | #ifndef WGL_NV_swap_group 997 | #define WGL_NV_swap_group 1 998 | 999 | typedef BOOL (WINAPI * PFNWGLBINDSWAPBARRIERNVPROC) (GLuint group, GLuint barrier); 1000 | typedef BOOL (WINAPI * PFNWGLJOINSWAPGROUPNVPROC) (HDC hDC, GLuint group); 1001 | typedef BOOL (WINAPI * PFNWGLQUERYFRAMECOUNTNVPROC) (HDC hDC, GLuint* count); 1002 | typedef BOOL (WINAPI * PFNWGLQUERYMAXSWAPGROUPSNVPROC) (HDC hDC, GLuint* maxGroups, GLuint *maxBarriers); 1003 | typedef BOOL (WINAPI * PFNWGLQUERYSWAPGROUPNVPROC) (HDC hDC, GLuint* group, GLuint *barrier); 1004 | typedef BOOL (WINAPI * PFNWGLRESETFRAMECOUNTNVPROC) (HDC hDC); 1005 | 1006 | #define wglBindSwapBarrierNV WGLEW_GET_FUN(__wglewBindSwapBarrierNV) 1007 | #define wglJoinSwapGroupNV WGLEW_GET_FUN(__wglewJoinSwapGroupNV) 1008 | #define wglQueryFrameCountNV WGLEW_GET_FUN(__wglewQueryFrameCountNV) 1009 | #define wglQueryMaxSwapGroupsNV WGLEW_GET_FUN(__wglewQueryMaxSwapGroupsNV) 1010 | #define wglQuerySwapGroupNV WGLEW_GET_FUN(__wglewQuerySwapGroupNV) 1011 | #define wglResetFrameCountNV WGLEW_GET_FUN(__wglewResetFrameCountNV) 1012 | 1013 | #define WGLEW_NV_swap_group WGLEW_GET_VAR(__WGLEW_NV_swap_group) 1014 | 1015 | #endif /* WGL_NV_swap_group */ 1016 | 1017 | /* ----------------------- WGL_NV_vertex_array_range ----------------------- */ 1018 | 1019 | #ifndef WGL_NV_vertex_array_range 1020 | #define WGL_NV_vertex_array_range 1 1021 | 1022 | typedef void * (WINAPI * PFNWGLALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readFrequency, GLfloat writeFrequency, GLfloat priority); 1023 | typedef void (WINAPI * PFNWGLFREEMEMORYNVPROC) (void *pointer); 1024 | 1025 | #define wglAllocateMemoryNV WGLEW_GET_FUN(__wglewAllocateMemoryNV) 1026 | #define wglFreeMemoryNV WGLEW_GET_FUN(__wglewFreeMemoryNV) 1027 | 1028 | #define WGLEW_NV_vertex_array_range WGLEW_GET_VAR(__WGLEW_NV_vertex_array_range) 1029 | 1030 | #endif /* WGL_NV_vertex_array_range */ 1031 | 1032 | /* -------------------------- WGL_NV_video_capture ------------------------- */ 1033 | 1034 | #ifndef WGL_NV_video_capture 1035 | #define WGL_NV_video_capture 1 1036 | 1037 | #define WGL_UNIQUE_ID_NV 0x20CE 1038 | #define WGL_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF 1039 | 1040 | DECLARE_HANDLE(HVIDEOINPUTDEVICENV); 1041 | 1042 | typedef BOOL (WINAPI * PFNWGLBINDVIDEOCAPTUREDEVICENVPROC) (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice); 1043 | typedef UINT (WINAPI * PFNWGLENUMERATEVIDEOCAPTUREDEVICESNVPROC) (HDC hDc, HVIDEOINPUTDEVICENV* phDeviceList); 1044 | typedef BOOL (WINAPI * PFNWGLLOCKVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice); 1045 | typedef BOOL (WINAPI * PFNWGLQUERYVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int* piValue); 1046 | typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice); 1047 | 1048 | #define wglBindVideoCaptureDeviceNV WGLEW_GET_FUN(__wglewBindVideoCaptureDeviceNV) 1049 | #define wglEnumerateVideoCaptureDevicesNV WGLEW_GET_FUN(__wglewEnumerateVideoCaptureDevicesNV) 1050 | #define wglLockVideoCaptureDeviceNV WGLEW_GET_FUN(__wglewLockVideoCaptureDeviceNV) 1051 | #define wglQueryVideoCaptureDeviceNV WGLEW_GET_FUN(__wglewQueryVideoCaptureDeviceNV) 1052 | #define wglReleaseVideoCaptureDeviceNV WGLEW_GET_FUN(__wglewReleaseVideoCaptureDeviceNV) 1053 | 1054 | #define WGLEW_NV_video_capture WGLEW_GET_VAR(__WGLEW_NV_video_capture) 1055 | 1056 | #endif /* WGL_NV_video_capture */ 1057 | 1058 | /* -------------------------- WGL_NV_video_output -------------------------- */ 1059 | 1060 | #ifndef WGL_NV_video_output 1061 | #define WGL_NV_video_output 1 1062 | 1063 | #define WGL_BIND_TO_VIDEO_RGB_NV 0x20C0 1064 | #define WGL_BIND_TO_VIDEO_RGBA_NV 0x20C1 1065 | #define WGL_BIND_TO_VIDEO_RGB_AND_DEPTH_NV 0x20C2 1066 | #define WGL_VIDEO_OUT_COLOR_NV 0x20C3 1067 | #define WGL_VIDEO_OUT_ALPHA_NV 0x20C4 1068 | #define WGL_VIDEO_OUT_DEPTH_NV 0x20C5 1069 | #define WGL_VIDEO_OUT_COLOR_AND_ALPHA_NV 0x20C6 1070 | #define WGL_VIDEO_OUT_COLOR_AND_DEPTH_NV 0x20C7 1071 | #define WGL_VIDEO_OUT_FRAME 0x20C8 1072 | #define WGL_VIDEO_OUT_FIELD_1 0x20C9 1073 | #define WGL_VIDEO_OUT_FIELD_2 0x20CA 1074 | #define WGL_VIDEO_OUT_STACKED_FIELDS_1_2 0x20CB 1075 | #define WGL_VIDEO_OUT_STACKED_FIELDS_2_1 0x20CC 1076 | 1077 | DECLARE_HANDLE(HPVIDEODEV); 1078 | 1079 | typedef BOOL (WINAPI * PFNWGLBINDVIDEOIMAGENVPROC) (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer); 1080 | typedef BOOL (WINAPI * PFNWGLGETVIDEODEVICENVPROC) (HDC hDC, int numDevices, HPVIDEODEV* hVideoDevice); 1081 | typedef BOOL (WINAPI * PFNWGLGETVIDEOINFONVPROC) (HPVIDEODEV hpVideoDevice, unsigned long* pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); 1082 | typedef BOOL (WINAPI * PFNWGLRELEASEVIDEODEVICENVPROC) (HPVIDEODEV hVideoDevice); 1083 | typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOIMAGENVPROC) (HPBUFFERARB hPbuffer, int iVideoBuffer); 1084 | typedef BOOL (WINAPI * PFNWGLSENDPBUFFERTOVIDEONVPROC) (HPBUFFERARB hPbuffer, int iBufferType, unsigned long* pulCounterPbuffer, BOOL bBlock); 1085 | 1086 | #define wglBindVideoImageNV WGLEW_GET_FUN(__wglewBindVideoImageNV) 1087 | #define wglGetVideoDeviceNV WGLEW_GET_FUN(__wglewGetVideoDeviceNV) 1088 | #define wglGetVideoInfoNV WGLEW_GET_FUN(__wglewGetVideoInfoNV) 1089 | #define wglReleaseVideoDeviceNV WGLEW_GET_FUN(__wglewReleaseVideoDeviceNV) 1090 | #define wglReleaseVideoImageNV WGLEW_GET_FUN(__wglewReleaseVideoImageNV) 1091 | #define wglSendPbufferToVideoNV WGLEW_GET_FUN(__wglewSendPbufferToVideoNV) 1092 | 1093 | #define WGLEW_NV_video_output WGLEW_GET_VAR(__WGLEW_NV_video_output) 1094 | 1095 | #endif /* WGL_NV_video_output */ 1096 | 1097 | /* -------------------------- WGL_OML_sync_control ------------------------- */ 1098 | 1099 | #ifndef WGL_OML_sync_control 1100 | #define WGL_OML_sync_control 1 1101 | 1102 | typedef BOOL (WINAPI * PFNWGLGETMSCRATEOMLPROC) (HDC hdc, INT32* numerator, INT32 *denominator); 1103 | typedef BOOL (WINAPI * PFNWGLGETSYNCVALUESOMLPROC) (HDC hdc, INT64* ust, INT64 *msc, INT64 *sbc); 1104 | typedef INT64 (WINAPI * PFNWGLSWAPBUFFERSMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder); 1105 | typedef INT64 (WINAPI * PFNWGLSWAPLAYERBUFFERSMSCOMLPROC) (HDC hdc, INT fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder); 1106 | typedef BOOL (WINAPI * PFNWGLWAITFORMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64* ust, INT64 *msc, INT64 *sbc); 1107 | typedef BOOL (WINAPI * PFNWGLWAITFORSBCOMLPROC) (HDC hdc, INT64 target_sbc, INT64* ust, INT64 *msc, INT64 *sbc); 1108 | 1109 | #define wglGetMscRateOML WGLEW_GET_FUN(__wglewGetMscRateOML) 1110 | #define wglGetSyncValuesOML WGLEW_GET_FUN(__wglewGetSyncValuesOML) 1111 | #define wglSwapBuffersMscOML WGLEW_GET_FUN(__wglewSwapBuffersMscOML) 1112 | #define wglSwapLayerBuffersMscOML WGLEW_GET_FUN(__wglewSwapLayerBuffersMscOML) 1113 | #define wglWaitForMscOML WGLEW_GET_FUN(__wglewWaitForMscOML) 1114 | #define wglWaitForSbcOML WGLEW_GET_FUN(__wglewWaitForSbcOML) 1115 | 1116 | #define WGLEW_OML_sync_control WGLEW_GET_VAR(__WGLEW_OML_sync_control) 1117 | 1118 | #endif /* WGL_OML_sync_control */ 1119 | 1120 | /* ------------------------------------------------------------------------- */ 1121 | 1122 | #ifdef GLEW_MX 1123 | #define WGLEW_EXPORT 1124 | #else 1125 | #define WGLEW_EXPORT GLEWAPI 1126 | #endif /* GLEW_MX */ 1127 | 1128 | #ifdef GLEW_MX 1129 | struct WGLEWContextStruct 1130 | { 1131 | #endif /* GLEW_MX */ 1132 | 1133 | WGLEW_EXPORT PFNWGLSETSTEREOEMITTERSTATE3DLPROC __wglewSetStereoEmitterState3DL; 1134 | 1135 | WGLEW_EXPORT PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC __wglewBlitContextFramebufferAMD; 1136 | WGLEW_EXPORT PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC __wglewCreateAssociatedContextAMD; 1137 | WGLEW_EXPORT PFNWGLCREATEASSOCIATEDCONTEXTATTRIBSAMDPROC __wglewCreateAssociatedContextAttribsAMD; 1138 | WGLEW_EXPORT PFNWGLDELETEASSOCIATEDCONTEXTAMDPROC __wglewDeleteAssociatedContextAMD; 1139 | WGLEW_EXPORT PFNWGLGETCONTEXTGPUIDAMDPROC __wglewGetContextGPUIDAMD; 1140 | WGLEW_EXPORT PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC __wglewGetCurrentAssociatedContextAMD; 1141 | WGLEW_EXPORT PFNWGLGETGPUIDSAMDPROC __wglewGetGPUIDsAMD; 1142 | WGLEW_EXPORT PFNWGLGETGPUINFOAMDPROC __wglewGetGPUInfoAMD; 1143 | WGLEW_EXPORT PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC __wglewMakeAssociatedContextCurrentAMD; 1144 | 1145 | WGLEW_EXPORT PFNWGLCREATEBUFFERREGIONARBPROC __wglewCreateBufferRegionARB; 1146 | WGLEW_EXPORT PFNWGLDELETEBUFFERREGIONARBPROC __wglewDeleteBufferRegionARB; 1147 | WGLEW_EXPORT PFNWGLRESTOREBUFFERREGIONARBPROC __wglewRestoreBufferRegionARB; 1148 | WGLEW_EXPORT PFNWGLSAVEBUFFERREGIONARBPROC __wglewSaveBufferRegionARB; 1149 | 1150 | WGLEW_EXPORT PFNWGLCREATECONTEXTATTRIBSARBPROC __wglewCreateContextAttribsARB; 1151 | 1152 | WGLEW_EXPORT PFNWGLGETEXTENSIONSSTRINGARBPROC __wglewGetExtensionsStringARB; 1153 | 1154 | WGLEW_EXPORT PFNWGLGETCURRENTREADDCARBPROC __wglewGetCurrentReadDCARB; 1155 | WGLEW_EXPORT PFNWGLMAKECONTEXTCURRENTARBPROC __wglewMakeContextCurrentARB; 1156 | 1157 | WGLEW_EXPORT PFNWGLCREATEPBUFFERARBPROC __wglewCreatePbufferARB; 1158 | WGLEW_EXPORT PFNWGLDESTROYPBUFFERARBPROC __wglewDestroyPbufferARB; 1159 | WGLEW_EXPORT PFNWGLGETPBUFFERDCARBPROC __wglewGetPbufferDCARB; 1160 | WGLEW_EXPORT PFNWGLQUERYPBUFFERARBPROC __wglewQueryPbufferARB; 1161 | WGLEW_EXPORT PFNWGLRELEASEPBUFFERDCARBPROC __wglewReleasePbufferDCARB; 1162 | 1163 | WGLEW_EXPORT PFNWGLCHOOSEPIXELFORMATARBPROC __wglewChoosePixelFormatARB; 1164 | WGLEW_EXPORT PFNWGLGETPIXELFORMATATTRIBFVARBPROC __wglewGetPixelFormatAttribfvARB; 1165 | WGLEW_EXPORT PFNWGLGETPIXELFORMATATTRIBIVARBPROC __wglewGetPixelFormatAttribivARB; 1166 | 1167 | WGLEW_EXPORT PFNWGLBINDTEXIMAGEARBPROC __wglewBindTexImageARB; 1168 | WGLEW_EXPORT PFNWGLRELEASETEXIMAGEARBPROC __wglewReleaseTexImageARB; 1169 | WGLEW_EXPORT PFNWGLSETPBUFFERATTRIBARBPROC __wglewSetPbufferAttribARB; 1170 | 1171 | WGLEW_EXPORT PFNWGLBINDDISPLAYCOLORTABLEEXTPROC __wglewBindDisplayColorTableEXT; 1172 | WGLEW_EXPORT PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC __wglewCreateDisplayColorTableEXT; 1173 | WGLEW_EXPORT PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC __wglewDestroyDisplayColorTableEXT; 1174 | WGLEW_EXPORT PFNWGLLOADDISPLAYCOLORTABLEEXTPROC __wglewLoadDisplayColorTableEXT; 1175 | 1176 | WGLEW_EXPORT PFNWGLGETEXTENSIONSSTRINGEXTPROC __wglewGetExtensionsStringEXT; 1177 | 1178 | WGLEW_EXPORT PFNWGLGETCURRENTREADDCEXTPROC __wglewGetCurrentReadDCEXT; 1179 | WGLEW_EXPORT PFNWGLMAKECONTEXTCURRENTEXTPROC __wglewMakeContextCurrentEXT; 1180 | 1181 | WGLEW_EXPORT PFNWGLCREATEPBUFFEREXTPROC __wglewCreatePbufferEXT; 1182 | WGLEW_EXPORT PFNWGLDESTROYPBUFFEREXTPROC __wglewDestroyPbufferEXT; 1183 | WGLEW_EXPORT PFNWGLGETPBUFFERDCEXTPROC __wglewGetPbufferDCEXT; 1184 | WGLEW_EXPORT PFNWGLQUERYPBUFFEREXTPROC __wglewQueryPbufferEXT; 1185 | WGLEW_EXPORT PFNWGLRELEASEPBUFFERDCEXTPROC __wglewReleasePbufferDCEXT; 1186 | 1187 | WGLEW_EXPORT PFNWGLCHOOSEPIXELFORMATEXTPROC __wglewChoosePixelFormatEXT; 1188 | WGLEW_EXPORT PFNWGLGETPIXELFORMATATTRIBFVEXTPROC __wglewGetPixelFormatAttribfvEXT; 1189 | WGLEW_EXPORT PFNWGLGETPIXELFORMATATTRIBIVEXTPROC __wglewGetPixelFormatAttribivEXT; 1190 | 1191 | WGLEW_EXPORT PFNWGLGETSWAPINTERVALEXTPROC __wglewGetSwapIntervalEXT; 1192 | WGLEW_EXPORT PFNWGLSWAPINTERVALEXTPROC __wglewSwapIntervalEXT; 1193 | 1194 | WGLEW_EXPORT PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC __wglewGetDigitalVideoParametersI3D; 1195 | WGLEW_EXPORT PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC __wglewSetDigitalVideoParametersI3D; 1196 | 1197 | WGLEW_EXPORT PFNWGLGETGAMMATABLEI3DPROC __wglewGetGammaTableI3D; 1198 | WGLEW_EXPORT PFNWGLGETGAMMATABLEPARAMETERSI3DPROC __wglewGetGammaTableParametersI3D; 1199 | WGLEW_EXPORT PFNWGLSETGAMMATABLEI3DPROC __wglewSetGammaTableI3D; 1200 | WGLEW_EXPORT PFNWGLSETGAMMATABLEPARAMETERSI3DPROC __wglewSetGammaTableParametersI3D; 1201 | 1202 | WGLEW_EXPORT PFNWGLDISABLEGENLOCKI3DPROC __wglewDisableGenlockI3D; 1203 | WGLEW_EXPORT PFNWGLENABLEGENLOCKI3DPROC __wglewEnableGenlockI3D; 1204 | WGLEW_EXPORT PFNWGLGENLOCKSAMPLERATEI3DPROC __wglewGenlockSampleRateI3D; 1205 | WGLEW_EXPORT PFNWGLGENLOCKSOURCEDELAYI3DPROC __wglewGenlockSourceDelayI3D; 1206 | WGLEW_EXPORT PFNWGLGENLOCKSOURCEEDGEI3DPROC __wglewGenlockSourceEdgeI3D; 1207 | WGLEW_EXPORT PFNWGLGENLOCKSOURCEI3DPROC __wglewGenlockSourceI3D; 1208 | WGLEW_EXPORT PFNWGLGETGENLOCKSAMPLERATEI3DPROC __wglewGetGenlockSampleRateI3D; 1209 | WGLEW_EXPORT PFNWGLGETGENLOCKSOURCEDELAYI3DPROC __wglewGetGenlockSourceDelayI3D; 1210 | WGLEW_EXPORT PFNWGLGETGENLOCKSOURCEEDGEI3DPROC __wglewGetGenlockSourceEdgeI3D; 1211 | WGLEW_EXPORT PFNWGLGETGENLOCKSOURCEI3DPROC __wglewGetGenlockSourceI3D; 1212 | WGLEW_EXPORT PFNWGLISENABLEDGENLOCKI3DPROC __wglewIsEnabledGenlockI3D; 1213 | WGLEW_EXPORT PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC __wglewQueryGenlockMaxSourceDelayI3D; 1214 | 1215 | WGLEW_EXPORT PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC __wglewAssociateImageBufferEventsI3D; 1216 | WGLEW_EXPORT PFNWGLCREATEIMAGEBUFFERI3DPROC __wglewCreateImageBufferI3D; 1217 | WGLEW_EXPORT PFNWGLDESTROYIMAGEBUFFERI3DPROC __wglewDestroyImageBufferI3D; 1218 | WGLEW_EXPORT PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC __wglewReleaseImageBufferEventsI3D; 1219 | 1220 | WGLEW_EXPORT PFNWGLDISABLEFRAMELOCKI3DPROC __wglewDisableFrameLockI3D; 1221 | WGLEW_EXPORT PFNWGLENABLEFRAMELOCKI3DPROC __wglewEnableFrameLockI3D; 1222 | WGLEW_EXPORT PFNWGLISENABLEDFRAMELOCKI3DPROC __wglewIsEnabledFrameLockI3D; 1223 | WGLEW_EXPORT PFNWGLQUERYFRAMELOCKMASTERI3DPROC __wglewQueryFrameLockMasterI3D; 1224 | 1225 | WGLEW_EXPORT PFNWGLBEGINFRAMETRACKINGI3DPROC __wglewBeginFrameTrackingI3D; 1226 | WGLEW_EXPORT PFNWGLENDFRAMETRACKINGI3DPROC __wglewEndFrameTrackingI3D; 1227 | WGLEW_EXPORT PFNWGLGETFRAMEUSAGEI3DPROC __wglewGetFrameUsageI3D; 1228 | WGLEW_EXPORT PFNWGLQUERYFRAMETRACKINGI3DPROC __wglewQueryFrameTrackingI3D; 1229 | 1230 | WGLEW_EXPORT PFNWGLDXCLOSEDEVICENVPROC __wglewDXCloseDeviceNV; 1231 | WGLEW_EXPORT PFNWGLDXLOCKOBJECTSNVPROC __wglewDXLockObjectsNV; 1232 | WGLEW_EXPORT PFNWGLDXOBJECTACCESSNVPROC __wglewDXObjectAccessNV; 1233 | WGLEW_EXPORT PFNWGLDXOPENDEVICENVPROC __wglewDXOpenDeviceNV; 1234 | WGLEW_EXPORT PFNWGLDXREGISTEROBJECTNVPROC __wglewDXRegisterObjectNV; 1235 | WGLEW_EXPORT PFNWGLDXSETRESOURCESHAREHANDLENVPROC __wglewDXSetResourceShareHandleNV; 1236 | WGLEW_EXPORT PFNWGLDXUNLOCKOBJECTSNVPROC __wglewDXUnlockObjectsNV; 1237 | WGLEW_EXPORT PFNWGLDXUNREGISTEROBJECTNVPROC __wglewDXUnregisterObjectNV; 1238 | 1239 | WGLEW_EXPORT PFNWGLCOPYIMAGESUBDATANVPROC __wglewCopyImageSubDataNV; 1240 | 1241 | WGLEW_EXPORT PFNWGLCREATEAFFINITYDCNVPROC __wglewCreateAffinityDCNV; 1242 | WGLEW_EXPORT PFNWGLDELETEDCNVPROC __wglewDeleteDCNV; 1243 | WGLEW_EXPORT PFNWGLENUMGPUDEVICESNVPROC __wglewEnumGpuDevicesNV; 1244 | WGLEW_EXPORT PFNWGLENUMGPUSFROMAFFINITYDCNVPROC __wglewEnumGpusFromAffinityDCNV; 1245 | WGLEW_EXPORT PFNWGLENUMGPUSNVPROC __wglewEnumGpusNV; 1246 | 1247 | WGLEW_EXPORT PFNWGLBINDVIDEODEVICENVPROC __wglewBindVideoDeviceNV; 1248 | WGLEW_EXPORT PFNWGLENUMERATEVIDEODEVICESNVPROC __wglewEnumerateVideoDevicesNV; 1249 | WGLEW_EXPORT PFNWGLQUERYCURRENTCONTEXTNVPROC __wglewQueryCurrentContextNV; 1250 | 1251 | WGLEW_EXPORT PFNWGLBINDSWAPBARRIERNVPROC __wglewBindSwapBarrierNV; 1252 | WGLEW_EXPORT PFNWGLJOINSWAPGROUPNVPROC __wglewJoinSwapGroupNV; 1253 | WGLEW_EXPORT PFNWGLQUERYFRAMECOUNTNVPROC __wglewQueryFrameCountNV; 1254 | WGLEW_EXPORT PFNWGLQUERYMAXSWAPGROUPSNVPROC __wglewQueryMaxSwapGroupsNV; 1255 | WGLEW_EXPORT PFNWGLQUERYSWAPGROUPNVPROC __wglewQuerySwapGroupNV; 1256 | WGLEW_EXPORT PFNWGLRESETFRAMECOUNTNVPROC __wglewResetFrameCountNV; 1257 | 1258 | WGLEW_EXPORT PFNWGLALLOCATEMEMORYNVPROC __wglewAllocateMemoryNV; 1259 | WGLEW_EXPORT PFNWGLFREEMEMORYNVPROC __wglewFreeMemoryNV; 1260 | 1261 | WGLEW_EXPORT PFNWGLBINDVIDEOCAPTUREDEVICENVPROC __wglewBindVideoCaptureDeviceNV; 1262 | WGLEW_EXPORT PFNWGLENUMERATEVIDEOCAPTUREDEVICESNVPROC __wglewEnumerateVideoCaptureDevicesNV; 1263 | WGLEW_EXPORT PFNWGLLOCKVIDEOCAPTUREDEVICENVPROC __wglewLockVideoCaptureDeviceNV; 1264 | WGLEW_EXPORT PFNWGLQUERYVIDEOCAPTUREDEVICENVPROC __wglewQueryVideoCaptureDeviceNV; 1265 | WGLEW_EXPORT PFNWGLRELEASEVIDEOCAPTUREDEVICENVPROC __wglewReleaseVideoCaptureDeviceNV; 1266 | 1267 | WGLEW_EXPORT PFNWGLBINDVIDEOIMAGENVPROC __wglewBindVideoImageNV; 1268 | WGLEW_EXPORT PFNWGLGETVIDEODEVICENVPROC __wglewGetVideoDeviceNV; 1269 | WGLEW_EXPORT PFNWGLGETVIDEOINFONVPROC __wglewGetVideoInfoNV; 1270 | WGLEW_EXPORT PFNWGLRELEASEVIDEODEVICENVPROC __wglewReleaseVideoDeviceNV; 1271 | WGLEW_EXPORT PFNWGLRELEASEVIDEOIMAGENVPROC __wglewReleaseVideoImageNV; 1272 | WGLEW_EXPORT PFNWGLSENDPBUFFERTOVIDEONVPROC __wglewSendPbufferToVideoNV; 1273 | 1274 | WGLEW_EXPORT PFNWGLGETMSCRATEOMLPROC __wglewGetMscRateOML; 1275 | WGLEW_EXPORT PFNWGLGETSYNCVALUESOMLPROC __wglewGetSyncValuesOML; 1276 | WGLEW_EXPORT PFNWGLSWAPBUFFERSMSCOMLPROC __wglewSwapBuffersMscOML; 1277 | WGLEW_EXPORT PFNWGLSWAPLAYERBUFFERSMSCOMLPROC __wglewSwapLayerBuffersMscOML; 1278 | WGLEW_EXPORT PFNWGLWAITFORMSCOMLPROC __wglewWaitForMscOML; 1279 | WGLEW_EXPORT PFNWGLWAITFORSBCOMLPROC __wglewWaitForSbcOML; 1280 | WGLEW_EXPORT GLboolean __WGLEW_3DFX_multisample; 1281 | WGLEW_EXPORT GLboolean __WGLEW_3DL_stereo_control; 1282 | WGLEW_EXPORT GLboolean __WGLEW_AMD_gpu_association; 1283 | WGLEW_EXPORT GLboolean __WGLEW_ARB_buffer_region; 1284 | WGLEW_EXPORT GLboolean __WGLEW_ARB_create_context; 1285 | WGLEW_EXPORT GLboolean __WGLEW_ARB_create_context_profile; 1286 | WGLEW_EXPORT GLboolean __WGLEW_ARB_create_context_robustness; 1287 | WGLEW_EXPORT GLboolean __WGLEW_ARB_extensions_string; 1288 | WGLEW_EXPORT GLboolean __WGLEW_ARB_framebuffer_sRGB; 1289 | WGLEW_EXPORT GLboolean __WGLEW_ARB_make_current_read; 1290 | WGLEW_EXPORT GLboolean __WGLEW_ARB_multisample; 1291 | WGLEW_EXPORT GLboolean __WGLEW_ARB_pbuffer; 1292 | WGLEW_EXPORT GLboolean __WGLEW_ARB_pixel_format; 1293 | WGLEW_EXPORT GLboolean __WGLEW_ARB_pixel_format_float; 1294 | WGLEW_EXPORT GLboolean __WGLEW_ARB_render_texture; 1295 | WGLEW_EXPORT GLboolean __WGLEW_ATI_pixel_format_float; 1296 | WGLEW_EXPORT GLboolean __WGLEW_ATI_render_texture_rectangle; 1297 | WGLEW_EXPORT GLboolean __WGLEW_EXT_create_context_es2_profile; 1298 | WGLEW_EXPORT GLboolean __WGLEW_EXT_depth_float; 1299 | WGLEW_EXPORT GLboolean __WGLEW_EXT_display_color_table; 1300 | WGLEW_EXPORT GLboolean __WGLEW_EXT_extensions_string; 1301 | WGLEW_EXPORT GLboolean __WGLEW_EXT_framebuffer_sRGB; 1302 | WGLEW_EXPORT GLboolean __WGLEW_EXT_make_current_read; 1303 | WGLEW_EXPORT GLboolean __WGLEW_EXT_multisample; 1304 | WGLEW_EXPORT GLboolean __WGLEW_EXT_pbuffer; 1305 | WGLEW_EXPORT GLboolean __WGLEW_EXT_pixel_format; 1306 | WGLEW_EXPORT GLboolean __WGLEW_EXT_pixel_format_packed_float; 1307 | WGLEW_EXPORT GLboolean __WGLEW_EXT_swap_control; 1308 | WGLEW_EXPORT GLboolean __WGLEW_I3D_digital_video_control; 1309 | WGLEW_EXPORT GLboolean __WGLEW_I3D_gamma; 1310 | WGLEW_EXPORT GLboolean __WGLEW_I3D_genlock; 1311 | WGLEW_EXPORT GLboolean __WGLEW_I3D_image_buffer; 1312 | WGLEW_EXPORT GLboolean __WGLEW_I3D_swap_frame_lock; 1313 | WGLEW_EXPORT GLboolean __WGLEW_I3D_swap_frame_usage; 1314 | WGLEW_EXPORT GLboolean __WGLEW_NV_DX_interop; 1315 | WGLEW_EXPORT GLboolean __WGLEW_NV_copy_image; 1316 | WGLEW_EXPORT GLboolean __WGLEW_NV_float_buffer; 1317 | WGLEW_EXPORT GLboolean __WGLEW_NV_gpu_affinity; 1318 | WGLEW_EXPORT GLboolean __WGLEW_NV_multisample_coverage; 1319 | WGLEW_EXPORT GLboolean __WGLEW_NV_present_video; 1320 | WGLEW_EXPORT GLboolean __WGLEW_NV_render_depth_texture; 1321 | WGLEW_EXPORT GLboolean __WGLEW_NV_render_texture_rectangle; 1322 | WGLEW_EXPORT GLboolean __WGLEW_NV_swap_group; 1323 | WGLEW_EXPORT GLboolean __WGLEW_NV_vertex_array_range; 1324 | WGLEW_EXPORT GLboolean __WGLEW_NV_video_capture; 1325 | WGLEW_EXPORT GLboolean __WGLEW_NV_video_output; 1326 | WGLEW_EXPORT GLboolean __WGLEW_OML_sync_control; 1327 | 1328 | #ifdef GLEW_MX 1329 | }; /* WGLEWContextStruct */ 1330 | #endif /* GLEW_MX */ 1331 | 1332 | /* ------------------------------------------------------------------------- */ 1333 | 1334 | #ifdef GLEW_MX 1335 | 1336 | typedef struct WGLEWContextStruct WGLEWContext; 1337 | GLEWAPI GLenum wglewContextInit (WGLEWContext* ctx); 1338 | GLEWAPI GLboolean wglewContextIsSupported (const WGLEWContext* ctx, const char* name); 1339 | 1340 | #define wglewInit() wglewContextInit(wglewGetContext()) 1341 | #define wglewIsSupported(x) wglewContextIsSupported(wglewGetContext(), x) 1342 | 1343 | #define WGLEW_GET_VAR(x) (*(const GLboolean*)&(wglewGetContext()->x)) 1344 | #define WGLEW_GET_FUN(x) wglewGetContext()->x 1345 | 1346 | #else /* GLEW_MX */ 1347 | 1348 | #define WGLEW_GET_VAR(x) (*(const GLboolean*)&x) 1349 | #define WGLEW_GET_FUN(x) x 1350 | 1351 | GLEWAPI GLboolean wglewIsSupported (const char* name); 1352 | 1353 | #endif /* GLEW_MX */ 1354 | 1355 | GLEWAPI GLboolean wglewGetExtension (const char* name); 1356 | 1357 | #ifdef __cplusplus 1358 | } 1359 | #endif 1360 | 1361 | #undef GLEWAPI 1362 | 1363 | #endif /* __wglew_h__ */ 1364 | -------------------------------------------------------------------------------- /glew-1.7.0/lib-osx/libGLEW.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Funto/OpenGL-Timestamp-Profiler/cdcdb56b3895ededab8ee6fd55d73e6bb01d183c/glew-1.7.0/lib-osx/libGLEW.a -------------------------------------------------------------------------------- /glew-1.7.0/lib-win32/glew32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Funto/OpenGL-Timestamp-Profiler/cdcdb56b3895ededab8ee6fd55d73e6bb01d183c/glew-1.7.0/lib-win32/glew32.dll -------------------------------------------------------------------------------- /glew-1.7.0/lib-win32/glew32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Funto/OpenGL-Timestamp-Profiler/cdcdb56b3895ededab8ee6fd55d73e6bb01d183c/glew-1.7.0/lib-win32/glew32.lib -------------------------------------------------------------------------------- /glew32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Funto/OpenGL-Timestamp-Profiler/cdcdb56b3895ededab8ee6fd55d73e6bb01d183c/glew32.dll -------------------------------------------------------------------------------- /glfw-2.7.5/COPYING.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006 Marcus Geelnard 2 | Copyright (c) 2006-2010 Camilla Berglund 3 | 4 | This software is provided 'as-is', without any express or implied 5 | warranty. In no event will the authors be held liable for any damages 6 | arising from the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it 10 | freely, subject to the following restrictions: 11 | 12 | 1. The origin of this software must not be misrepresented; you must not 13 | claim that you wrote the original software. If you use this software 14 | in a product, an acknowledgment in the product documentation would 15 | be appreciated but is not required. 16 | 17 | 2. Altered source versions must be plainly marked as such, and must not 18 | be misrepresented as being the original software. 19 | 20 | 3. This notice may not be removed or altered from any source 21 | distribution. 22 | 23 | -------------------------------------------------------------------------------- /glfw-2.7.5/include/GL/glfw.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * GLFW - An OpenGL framework 3 | * API version: 2.7 4 | * WWW: http://www.glfw.org/ 5 | *------------------------------------------------------------------------ 6 | * Copyright (c) 2002-2006 Marcus Geelnard 7 | * Copyright (c) 2006-2010 Camilla Berglund 8 | * 9 | * This software is provided 'as-is', without any express or implied 10 | * warranty. In no event will the authors be held liable for any damages 11 | * arising from the use of this software. 12 | * 13 | * Permission is granted to anyone to use this software for any purpose, 14 | * including commercial applications, and to alter it and redistribute it 15 | * freely, subject to the following restrictions: 16 | * 17 | * 1. The origin of this software must not be misrepresented; you must not 18 | * claim that you wrote the original software. If you use this software 19 | * in a product, an acknowledgment in the product documentation would 20 | * be appreciated but is not required. 21 | * 22 | * 2. Altered source versions must be plainly marked as such, and must not 23 | * be misrepresented as being the original software. 24 | * 25 | * 3. This notice may not be removed or altered from any source 26 | * distribution. 27 | * 28 | *************************************************************************/ 29 | 30 | #ifndef __glfw_h_ 31 | #define __glfw_h_ 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | 38 | /************************************************************************* 39 | * Global definitions 40 | *************************************************************************/ 41 | 42 | /* We need a NULL pointer from time to time */ 43 | #ifndef NULL 44 | #ifdef __cplusplus 45 | #define NULL 0 46 | #else 47 | #define NULL ((void *)0) 48 | #endif 49 | #endif /* NULL */ 50 | 51 | 52 | /* ------------------- BEGIN SYSTEM/COMPILER SPECIFIC -------------------- */ 53 | 54 | /* Please report any probles that you find with your compiler, which may 55 | * be solved in this section! There are several compilers that I have not 56 | * been able to test this file with yet. 57 | * 58 | * First: If we are we on Windows, we want a single define for it (_WIN32) 59 | * (Note: For Cygwin the compiler flag -mwin32 should be used, but to 60 | * make sure that things run smoothly for Cygwin users, we add __CYGWIN__ 61 | * to the list of "valid Win32 identifiers", which removes the need for 62 | * -mwin32) 63 | */ 64 | #if !defined(_WIN32) && (defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__)) 65 | #define _WIN32 66 | #endif /* _WIN32 */ 67 | 68 | /* In order for extension support to be portable, we need to define an 69 | * OpenGL function call method. We use the keyword APIENTRY, which is 70 | * defined for Win32. (Note: Windows also needs this for ) 71 | */ 72 | #ifndef APIENTRY 73 | #ifdef _WIN32 74 | #define APIENTRY __stdcall 75 | #else 76 | #define APIENTRY 77 | #endif 78 | #define GL_APIENTRY_DEFINED 79 | #endif /* APIENTRY */ 80 | 81 | 82 | /* The following three defines are here solely to make some Windows-based 83 | * files happy. Theoretically we could include , but 84 | * it has the major drawback of severely polluting our namespace. 85 | */ 86 | 87 | /* Under Windows, we need WINGDIAPI defined */ 88 | #if !defined(WINGDIAPI) && defined(_WIN32) 89 | #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__POCC__) 90 | /* Microsoft Visual C++, Borland C++ Builder and Pelles C */ 91 | #define WINGDIAPI __declspec(dllimport) 92 | #elif defined(__LCC__) 93 | /* LCC-Win32 */ 94 | #define WINGDIAPI __stdcall 95 | #else 96 | /* Others (e.g. MinGW, Cygwin) */ 97 | #define WINGDIAPI extern 98 | #endif 99 | #define GL_WINGDIAPI_DEFINED 100 | #endif /* WINGDIAPI */ 101 | 102 | /* Some files also need CALLBACK defined */ 103 | #if !defined(CALLBACK) && defined(_WIN32) 104 | #if defined(_MSC_VER) 105 | /* Microsoft Visual C++ */ 106 | #if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS) 107 | #define CALLBACK __stdcall 108 | #else 109 | #define CALLBACK 110 | #endif 111 | #else 112 | /* Other Windows compilers */ 113 | #define CALLBACK __stdcall 114 | #endif 115 | #define GLU_CALLBACK_DEFINED 116 | #endif /* CALLBACK */ 117 | 118 | /* Microsoft Visual C++, Borland C++ and Pelles C needs wchar_t */ 119 | #if defined(_WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__) || defined(__POCC__)) && !defined(_WCHAR_T_DEFINED) 120 | typedef unsigned short wchar_t; 121 | #define _WCHAR_T_DEFINED 122 | #endif /* _WCHAR_T_DEFINED */ 123 | 124 | 125 | /* ---------------- GLFW related system specific defines ----------------- */ 126 | 127 | #if defined(_WIN32) && defined(GLFW_BUILD_DLL) 128 | 129 | /* We are building a Win32 DLL */ 130 | #define GLFWAPI __declspec(dllexport) 131 | #define GLFWAPIENTRY __stdcall 132 | #define GLFWCALL __stdcall 133 | 134 | #elif defined(_WIN32) && defined(GLFW_DLL) 135 | 136 | /* We are calling a Win32 DLL */ 137 | #if defined(__LCC__) 138 | #define GLFWAPI extern 139 | #else 140 | #define GLFWAPI __declspec(dllimport) 141 | #endif 142 | #define GLFWAPIENTRY __stdcall 143 | #define GLFWCALL __stdcall 144 | 145 | #else 146 | 147 | /* We are either building/calling a static lib or we are non-win32 */ 148 | #define GLFWAPIENTRY 149 | #define GLFWAPI 150 | #define GLFWCALL 151 | 152 | #endif 153 | 154 | /* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */ 155 | 156 | /* Include standard OpenGL headers: GLFW uses GL_FALSE/GL_TRUE, and it is 157 | * convenient for the user to only have to include . This also 158 | * solves the problem with Windows and needing some 159 | * special defines which normally requires the user to include 160 | * (which is not a nice solution for portable programs). 161 | */ 162 | #if defined(__APPLE_CC__) 163 | #if defined(GLFW_INCLUDE_GL3) 164 | #include 165 | #else 166 | #define GL_GLEXT_LEGACY 167 | #include 168 | #endif 169 | #ifndef GLFW_NO_GLU 170 | #include 171 | #endif 172 | #else 173 | #if defined(GLFW_INCLUDE_GL3) 174 | #include 175 | #else 176 | #include 177 | #endif 178 | #ifndef GLFW_NO_GLU 179 | #include 180 | #endif 181 | #endif 182 | 183 | 184 | /************************************************************************* 185 | * GLFW version 186 | *************************************************************************/ 187 | 188 | #define GLFW_VERSION_MAJOR 2 189 | #define GLFW_VERSION_MINOR 7 190 | #define GLFW_VERSION_REVISION 5 191 | 192 | 193 | /************************************************************************* 194 | * Input handling definitions 195 | *************************************************************************/ 196 | 197 | /* Key and button state/action definitions */ 198 | #define GLFW_RELEASE 0 199 | #define GLFW_PRESS 1 200 | 201 | /* Keyboard key definitions: 8-bit ISO-8859-1 (Latin 1) encoding is used 202 | * for printable keys (such as A-Z, 0-9 etc), and values above 256 203 | * represent special (non-printable) keys (e.g. F1, Page Up etc). 204 | */ 205 | #define GLFW_KEY_UNKNOWN -1 206 | #define GLFW_KEY_SPACE 32 207 | #define GLFW_KEY_SPECIAL 256 208 | #define GLFW_KEY_ESC (GLFW_KEY_SPECIAL+1) 209 | #define GLFW_KEY_F1 (GLFW_KEY_SPECIAL+2) 210 | #define GLFW_KEY_F2 (GLFW_KEY_SPECIAL+3) 211 | #define GLFW_KEY_F3 (GLFW_KEY_SPECIAL+4) 212 | #define GLFW_KEY_F4 (GLFW_KEY_SPECIAL+5) 213 | #define GLFW_KEY_F5 (GLFW_KEY_SPECIAL+6) 214 | #define GLFW_KEY_F6 (GLFW_KEY_SPECIAL+7) 215 | #define GLFW_KEY_F7 (GLFW_KEY_SPECIAL+8) 216 | #define GLFW_KEY_F8 (GLFW_KEY_SPECIAL+9) 217 | #define GLFW_KEY_F9 (GLFW_KEY_SPECIAL+10) 218 | #define GLFW_KEY_F10 (GLFW_KEY_SPECIAL+11) 219 | #define GLFW_KEY_F11 (GLFW_KEY_SPECIAL+12) 220 | #define GLFW_KEY_F12 (GLFW_KEY_SPECIAL+13) 221 | #define GLFW_KEY_F13 (GLFW_KEY_SPECIAL+14) 222 | #define GLFW_KEY_F14 (GLFW_KEY_SPECIAL+15) 223 | #define GLFW_KEY_F15 (GLFW_KEY_SPECIAL+16) 224 | #define GLFW_KEY_F16 (GLFW_KEY_SPECIAL+17) 225 | #define GLFW_KEY_F17 (GLFW_KEY_SPECIAL+18) 226 | #define GLFW_KEY_F18 (GLFW_KEY_SPECIAL+19) 227 | #define GLFW_KEY_F19 (GLFW_KEY_SPECIAL+20) 228 | #define GLFW_KEY_F20 (GLFW_KEY_SPECIAL+21) 229 | #define GLFW_KEY_F21 (GLFW_KEY_SPECIAL+22) 230 | #define GLFW_KEY_F22 (GLFW_KEY_SPECIAL+23) 231 | #define GLFW_KEY_F23 (GLFW_KEY_SPECIAL+24) 232 | #define GLFW_KEY_F24 (GLFW_KEY_SPECIAL+25) 233 | #define GLFW_KEY_F25 (GLFW_KEY_SPECIAL+26) 234 | #define GLFW_KEY_UP (GLFW_KEY_SPECIAL+27) 235 | #define GLFW_KEY_DOWN (GLFW_KEY_SPECIAL+28) 236 | #define GLFW_KEY_LEFT (GLFW_KEY_SPECIAL+29) 237 | #define GLFW_KEY_RIGHT (GLFW_KEY_SPECIAL+30) 238 | #define GLFW_KEY_LSHIFT (GLFW_KEY_SPECIAL+31) 239 | #define GLFW_KEY_RSHIFT (GLFW_KEY_SPECIAL+32) 240 | #define GLFW_KEY_LCTRL (GLFW_KEY_SPECIAL+33) 241 | #define GLFW_KEY_RCTRL (GLFW_KEY_SPECIAL+34) 242 | #define GLFW_KEY_LALT (GLFW_KEY_SPECIAL+35) 243 | #define GLFW_KEY_RALT (GLFW_KEY_SPECIAL+36) 244 | #define GLFW_KEY_TAB (GLFW_KEY_SPECIAL+37) 245 | #define GLFW_KEY_ENTER (GLFW_KEY_SPECIAL+38) 246 | #define GLFW_KEY_BACKSPACE (GLFW_KEY_SPECIAL+39) 247 | #define GLFW_KEY_INSERT (GLFW_KEY_SPECIAL+40) 248 | #define GLFW_KEY_DEL (GLFW_KEY_SPECIAL+41) 249 | #define GLFW_KEY_PAGEUP (GLFW_KEY_SPECIAL+42) 250 | #define GLFW_KEY_PAGEDOWN (GLFW_KEY_SPECIAL+43) 251 | #define GLFW_KEY_HOME (GLFW_KEY_SPECIAL+44) 252 | #define GLFW_KEY_END (GLFW_KEY_SPECIAL+45) 253 | #define GLFW_KEY_KP_0 (GLFW_KEY_SPECIAL+46) 254 | #define GLFW_KEY_KP_1 (GLFW_KEY_SPECIAL+47) 255 | #define GLFW_KEY_KP_2 (GLFW_KEY_SPECIAL+48) 256 | #define GLFW_KEY_KP_3 (GLFW_KEY_SPECIAL+49) 257 | #define GLFW_KEY_KP_4 (GLFW_KEY_SPECIAL+50) 258 | #define GLFW_KEY_KP_5 (GLFW_KEY_SPECIAL+51) 259 | #define GLFW_KEY_KP_6 (GLFW_KEY_SPECIAL+52) 260 | #define GLFW_KEY_KP_7 (GLFW_KEY_SPECIAL+53) 261 | #define GLFW_KEY_KP_8 (GLFW_KEY_SPECIAL+54) 262 | #define GLFW_KEY_KP_9 (GLFW_KEY_SPECIAL+55) 263 | #define GLFW_KEY_KP_DIVIDE (GLFW_KEY_SPECIAL+56) 264 | #define GLFW_KEY_KP_MULTIPLY (GLFW_KEY_SPECIAL+57) 265 | #define GLFW_KEY_KP_SUBTRACT (GLFW_KEY_SPECIAL+58) 266 | #define GLFW_KEY_KP_ADD (GLFW_KEY_SPECIAL+59) 267 | #define GLFW_KEY_KP_DECIMAL (GLFW_KEY_SPECIAL+60) 268 | #define GLFW_KEY_KP_EQUAL (GLFW_KEY_SPECIAL+61) 269 | #define GLFW_KEY_KP_ENTER (GLFW_KEY_SPECIAL+62) 270 | #define GLFW_KEY_KP_NUM_LOCK (GLFW_KEY_SPECIAL+63) 271 | #define GLFW_KEY_CAPS_LOCK (GLFW_KEY_SPECIAL+64) 272 | #define GLFW_KEY_SCROLL_LOCK (GLFW_KEY_SPECIAL+65) 273 | #define GLFW_KEY_PAUSE (GLFW_KEY_SPECIAL+66) 274 | #define GLFW_KEY_LSUPER (GLFW_KEY_SPECIAL+67) 275 | #define GLFW_KEY_RSUPER (GLFW_KEY_SPECIAL+68) 276 | #define GLFW_KEY_MENU (GLFW_KEY_SPECIAL+69) 277 | #define GLFW_KEY_LAST GLFW_KEY_MENU 278 | 279 | /* Mouse button definitions */ 280 | #define GLFW_MOUSE_BUTTON_1 0 281 | #define GLFW_MOUSE_BUTTON_2 1 282 | #define GLFW_MOUSE_BUTTON_3 2 283 | #define GLFW_MOUSE_BUTTON_4 3 284 | #define GLFW_MOUSE_BUTTON_5 4 285 | #define GLFW_MOUSE_BUTTON_6 5 286 | #define GLFW_MOUSE_BUTTON_7 6 287 | #define GLFW_MOUSE_BUTTON_8 7 288 | #define GLFW_MOUSE_BUTTON_LAST GLFW_MOUSE_BUTTON_8 289 | 290 | /* Mouse button aliases */ 291 | #define GLFW_MOUSE_BUTTON_LEFT GLFW_MOUSE_BUTTON_1 292 | #define GLFW_MOUSE_BUTTON_RIGHT GLFW_MOUSE_BUTTON_2 293 | #define GLFW_MOUSE_BUTTON_MIDDLE GLFW_MOUSE_BUTTON_3 294 | 295 | 296 | /* Joystick identifiers */ 297 | #define GLFW_JOYSTICK_1 0 298 | #define GLFW_JOYSTICK_2 1 299 | #define GLFW_JOYSTICK_3 2 300 | #define GLFW_JOYSTICK_4 3 301 | #define GLFW_JOYSTICK_5 4 302 | #define GLFW_JOYSTICK_6 5 303 | #define GLFW_JOYSTICK_7 6 304 | #define GLFW_JOYSTICK_8 7 305 | #define GLFW_JOYSTICK_9 8 306 | #define GLFW_JOYSTICK_10 9 307 | #define GLFW_JOYSTICK_11 10 308 | #define GLFW_JOYSTICK_12 11 309 | #define GLFW_JOYSTICK_13 12 310 | #define GLFW_JOYSTICK_14 13 311 | #define GLFW_JOYSTICK_15 14 312 | #define GLFW_JOYSTICK_16 15 313 | #define GLFW_JOYSTICK_LAST GLFW_JOYSTICK_16 314 | 315 | 316 | /************************************************************************* 317 | * Other definitions 318 | *************************************************************************/ 319 | 320 | /* glfwOpenWindow modes */ 321 | #define GLFW_WINDOW 0x00010001 322 | #define GLFW_FULLSCREEN 0x00010002 323 | 324 | /* glfwGetWindowParam tokens */ 325 | #define GLFW_OPENED 0x00020001 326 | #define GLFW_ACTIVE 0x00020002 327 | #define GLFW_ICONIFIED 0x00020003 328 | #define GLFW_ACCELERATED 0x00020004 329 | #define GLFW_RED_BITS 0x00020005 330 | #define GLFW_GREEN_BITS 0x00020006 331 | #define GLFW_BLUE_BITS 0x00020007 332 | #define GLFW_ALPHA_BITS 0x00020008 333 | #define GLFW_DEPTH_BITS 0x00020009 334 | #define GLFW_STENCIL_BITS 0x0002000A 335 | 336 | /* The following constants are used for both glfwGetWindowParam 337 | * and glfwOpenWindowHint 338 | */ 339 | #define GLFW_REFRESH_RATE 0x0002000B 340 | #define GLFW_ACCUM_RED_BITS 0x0002000C 341 | #define GLFW_ACCUM_GREEN_BITS 0x0002000D 342 | #define GLFW_ACCUM_BLUE_BITS 0x0002000E 343 | #define GLFW_ACCUM_ALPHA_BITS 0x0002000F 344 | #define GLFW_AUX_BUFFERS 0x00020010 345 | #define GLFW_STEREO 0x00020011 346 | #define GLFW_WINDOW_NO_RESIZE 0x00020012 347 | #define GLFW_FSAA_SAMPLES 0x00020013 348 | #define GLFW_OPENGL_VERSION_MAJOR 0x00020014 349 | #define GLFW_OPENGL_VERSION_MINOR 0x00020015 350 | #define GLFW_OPENGL_FORWARD_COMPAT 0x00020016 351 | #define GLFW_OPENGL_DEBUG_CONTEXT 0x00020017 352 | #define GLFW_OPENGL_PROFILE 0x00020018 353 | 354 | /* GLFW_OPENGL_PROFILE tokens */ 355 | #define GLFW_OPENGL_CORE_PROFILE 0x00050001 356 | #define GLFW_OPENGL_COMPAT_PROFILE 0x00050002 357 | 358 | /* glfwEnable/glfwDisable tokens */ 359 | #define GLFW_MOUSE_CURSOR 0x00030001 360 | #define GLFW_STICKY_KEYS 0x00030002 361 | #define GLFW_STICKY_MOUSE_BUTTONS 0x00030003 362 | #define GLFW_SYSTEM_KEYS 0x00030004 363 | #define GLFW_KEY_REPEAT 0x00030005 364 | #define GLFW_AUTO_POLL_EVENTS 0x00030006 365 | 366 | /* glfwWaitThread wait modes */ 367 | #define GLFW_WAIT 0x00040001 368 | #define GLFW_NOWAIT 0x00040002 369 | 370 | /* glfwGetJoystickParam tokens */ 371 | #define GLFW_PRESENT 0x00050001 372 | #define GLFW_AXES 0x00050002 373 | #define GLFW_BUTTONS 0x00050003 374 | 375 | /* glfwReadImage/glfwLoadTexture2D flags */ 376 | #define GLFW_NO_RESCALE_BIT 0x00000001 /* Only for glfwReadImage */ 377 | #define GLFW_ORIGIN_UL_BIT 0x00000002 378 | #define GLFW_BUILD_MIPMAPS_BIT 0x00000004 /* Only for glfwLoadTexture2D */ 379 | #define GLFW_ALPHA_MAP_BIT 0x00000008 380 | 381 | /* Time spans longer than this (seconds) are considered to be infinity */ 382 | #define GLFW_INFINITY 100000.0 383 | 384 | 385 | /************************************************************************* 386 | * Typedefs 387 | *************************************************************************/ 388 | 389 | /* The video mode structure used by glfwGetVideoModes() */ 390 | typedef struct { 391 | int Width, Height; 392 | int RedBits, BlueBits, GreenBits; 393 | } GLFWvidmode; 394 | 395 | /* Image/texture information */ 396 | typedef struct { 397 | int Width, Height; 398 | int Format; 399 | int BytesPerPixel; 400 | unsigned char *Data; 401 | } GLFWimage; 402 | 403 | /* Thread ID */ 404 | typedef int GLFWthread; 405 | 406 | /* Mutex object */ 407 | typedef void * GLFWmutex; 408 | 409 | /* Condition variable object */ 410 | typedef void * GLFWcond; 411 | 412 | /* Function pointer types */ 413 | typedef void (GLFWCALL * GLFWwindowsizefun)(int,int); 414 | typedef int (GLFWCALL * GLFWwindowclosefun)(void); 415 | typedef void (GLFWCALL * GLFWwindowrefreshfun)(void); 416 | typedef void (GLFWCALL * GLFWmousebuttonfun)(int,int); 417 | typedef void (GLFWCALL * GLFWmouseposfun)(int,int); 418 | typedef void (GLFWCALL * GLFWmousewheelfun)(int); 419 | typedef void (GLFWCALL * GLFWkeyfun)(int,int); 420 | typedef void (GLFWCALL * GLFWcharfun)(int,int); 421 | typedef void (GLFWCALL * GLFWthreadfun)(void *); 422 | 423 | 424 | /************************************************************************* 425 | * Prototypes 426 | *************************************************************************/ 427 | 428 | /* GLFW initialization, termination and version querying */ 429 | GLFWAPI int GLFWAPIENTRY glfwInit( void ); 430 | GLFWAPI void GLFWAPIENTRY glfwTerminate( void ); 431 | GLFWAPI void GLFWAPIENTRY glfwGetVersion( int *major, int *minor, int *rev ); 432 | 433 | /* Window handling */ 434 | GLFWAPI int GLFWAPIENTRY glfwOpenWindow( int width, int height, int redbits, int greenbits, int bluebits, int alphabits, int depthbits, int stencilbits, int mode ); 435 | GLFWAPI void GLFWAPIENTRY glfwOpenWindowHint( int target, int hint ); 436 | GLFWAPI void GLFWAPIENTRY glfwCloseWindow( void ); 437 | GLFWAPI void GLFWAPIENTRY glfwSetWindowTitle( const char *title ); 438 | GLFWAPI void GLFWAPIENTRY glfwGetWindowSize( int *width, int *height ); 439 | GLFWAPI void GLFWAPIENTRY glfwSetWindowSize( int width, int height ); 440 | GLFWAPI void GLFWAPIENTRY glfwSetWindowPos( int x, int y ); 441 | GLFWAPI void GLFWAPIENTRY glfwIconifyWindow( void ); 442 | GLFWAPI void GLFWAPIENTRY glfwRestoreWindow( void ); 443 | GLFWAPI void GLFWAPIENTRY glfwSwapBuffers( void ); 444 | GLFWAPI void GLFWAPIENTRY glfwSwapInterval( int interval ); 445 | GLFWAPI int GLFWAPIENTRY glfwGetWindowParam( int param ); 446 | GLFWAPI void GLFWAPIENTRY glfwSetWindowSizeCallback( GLFWwindowsizefun cbfun ); 447 | GLFWAPI void GLFWAPIENTRY glfwSetWindowCloseCallback( GLFWwindowclosefun cbfun ); 448 | GLFWAPI void GLFWAPIENTRY glfwSetWindowRefreshCallback( GLFWwindowrefreshfun cbfun ); 449 | 450 | /* Video mode functions */ 451 | GLFWAPI int GLFWAPIENTRY glfwGetVideoModes( GLFWvidmode *list, int maxcount ); 452 | GLFWAPI void GLFWAPIENTRY glfwGetDesktopMode( GLFWvidmode *mode ); 453 | 454 | /* Input handling */ 455 | GLFWAPI void GLFWAPIENTRY glfwPollEvents( void ); 456 | GLFWAPI void GLFWAPIENTRY glfwWaitEvents( void ); 457 | GLFWAPI int GLFWAPIENTRY glfwGetKey( int key ); 458 | GLFWAPI int GLFWAPIENTRY glfwGetMouseButton( int button ); 459 | GLFWAPI void GLFWAPIENTRY glfwGetMousePos( int *xpos, int *ypos ); 460 | GLFWAPI void GLFWAPIENTRY glfwSetMousePos( int xpos, int ypos ); 461 | GLFWAPI int GLFWAPIENTRY glfwGetMouseWheel( void ); 462 | GLFWAPI void GLFWAPIENTRY glfwSetMouseWheel( int pos ); 463 | GLFWAPI void GLFWAPIENTRY glfwSetKeyCallback( GLFWkeyfun cbfun ); 464 | GLFWAPI void GLFWAPIENTRY glfwSetCharCallback( GLFWcharfun cbfun ); 465 | GLFWAPI void GLFWAPIENTRY glfwSetMouseButtonCallback( GLFWmousebuttonfun cbfun ); 466 | GLFWAPI void GLFWAPIENTRY glfwSetMousePosCallback( GLFWmouseposfun cbfun ); 467 | GLFWAPI void GLFWAPIENTRY glfwSetMouseWheelCallback( GLFWmousewheelfun cbfun ); 468 | 469 | /* Joystick input */ 470 | GLFWAPI int GLFWAPIENTRY glfwGetJoystickParam( int joy, int param ); 471 | GLFWAPI int GLFWAPIENTRY glfwGetJoystickPos( int joy, float *pos, int numaxes ); 472 | GLFWAPI int GLFWAPIENTRY glfwGetJoystickButtons( int joy, unsigned char *buttons, int numbuttons ); 473 | 474 | /* Time */ 475 | GLFWAPI double GLFWAPIENTRY glfwGetTime( void ); 476 | GLFWAPI void GLFWAPIENTRY glfwSetTime( double time ); 477 | GLFWAPI void GLFWAPIENTRY glfwSleep( double time ); 478 | 479 | /* Extension support */ 480 | GLFWAPI int GLFWAPIENTRY glfwExtensionSupported( const char *extension ); 481 | GLFWAPI void* GLFWAPIENTRY glfwGetProcAddress( const char *procname ); 482 | GLFWAPI void GLFWAPIENTRY glfwGetGLVersion( int *major, int *minor, int *rev ); 483 | 484 | /* Threading support */ 485 | GLFWAPI GLFWthread GLFWAPIENTRY glfwCreateThread( GLFWthreadfun fun, void *arg ); 486 | GLFWAPI void GLFWAPIENTRY glfwDestroyThread( GLFWthread ID ); 487 | GLFWAPI int GLFWAPIENTRY glfwWaitThread( GLFWthread ID, int waitmode ); 488 | GLFWAPI GLFWthread GLFWAPIENTRY glfwGetThreadID( void ); 489 | GLFWAPI GLFWmutex GLFWAPIENTRY glfwCreateMutex( void ); 490 | GLFWAPI void GLFWAPIENTRY glfwDestroyMutex( GLFWmutex mutex ); 491 | GLFWAPI void GLFWAPIENTRY glfwLockMutex( GLFWmutex mutex ); 492 | GLFWAPI void GLFWAPIENTRY glfwUnlockMutex( GLFWmutex mutex ); 493 | GLFWAPI GLFWcond GLFWAPIENTRY glfwCreateCond( void ); 494 | GLFWAPI void GLFWAPIENTRY glfwDestroyCond( GLFWcond cond ); 495 | GLFWAPI void GLFWAPIENTRY glfwWaitCond( GLFWcond cond, GLFWmutex mutex, double timeout ); 496 | GLFWAPI void GLFWAPIENTRY glfwSignalCond( GLFWcond cond ); 497 | GLFWAPI void GLFWAPIENTRY glfwBroadcastCond( GLFWcond cond ); 498 | GLFWAPI int GLFWAPIENTRY glfwGetNumberOfProcessors( void ); 499 | 500 | /* Enable/disable functions */ 501 | GLFWAPI void GLFWAPIENTRY glfwEnable( int token ); 502 | GLFWAPI void GLFWAPIENTRY glfwDisable( int token ); 503 | 504 | /* Image/texture I/O support */ 505 | GLFWAPI int GLFWAPIENTRY glfwReadImage( const char *name, GLFWimage *img, int flags ); 506 | GLFWAPI int GLFWAPIENTRY glfwReadMemoryImage( const void *data, long size, GLFWimage *img, int flags ); 507 | GLFWAPI void GLFWAPIENTRY glfwFreeImage( GLFWimage *img ); 508 | GLFWAPI int GLFWAPIENTRY glfwLoadTexture2D( const char *name, int flags ); 509 | GLFWAPI int GLFWAPIENTRY glfwLoadMemoryTexture2D( const void *data, long size, int flags ); 510 | GLFWAPI int GLFWAPIENTRY glfwLoadTextureImage2D( GLFWimage *img, int flags ); 511 | 512 | 513 | #ifdef __cplusplus 514 | } 515 | #endif 516 | 517 | #endif /* __glfw_h_ */ 518 | 519 | -------------------------------------------------------------------------------- /glfw-2.7.5/lib-cocoa/libglfw.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Funto/OpenGL-Timestamp-Profiler/cdcdb56b3895ededab8ee6fd55d73e6bb01d183c/glfw-2.7.5/lib-cocoa/libglfw.a -------------------------------------------------------------------------------- /glfw-2.7.5/lib-mingw/libglfw.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Funto/OpenGL-Timestamp-Profiler/cdcdb56b3895ededab8ee6fd55d73e6bb01d183c/glfw-2.7.5/lib-mingw/libglfw.a -------------------------------------------------------------------------------- /glfw-2.7.5/lib-msvc100/GLFW.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Funto/OpenGL-Timestamp-Profiler/cdcdb56b3895ededab8ee6fd55d73e6bb01d183c/glfw-2.7.5/lib-msvc100/GLFW.lib -------------------------------------------------------------------------------- /glprofiler.config: -------------------------------------------------------------------------------- 1 | // ADD PREDEFINED MACROS HERE! 2 | #define size_t unsigned 3 | -------------------------------------------------------------------------------- /glprofiler.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /glprofiler.files: -------------------------------------------------------------------------------- 1 | glprofiler.files 2 | SConstruct 3 | Makefile.mingw 4 | 5 | drawer2D.cpp 6 | grid.cpp 7 | hp_timer.cpp 8 | main.cpp 9 | math_utils.cpp 10 | profiler.cpp 11 | scene.cpp 12 | tgaloader.cpp 13 | thread.cpp 14 | utils.cpp 15 | 16 | drawer2D.h 17 | tgaloader.h 18 | utils.h 19 | grid.h 20 | camera.h 21 | hp_timer.h 22 | scene.h 23 | thread.h 24 | hole_array.h 25 | profiler.h 26 | math_utils.h 27 | -------------------------------------------------------------------------------- /glprofiler.includes: -------------------------------------------------------------------------------- 1 | C:\Users\Funto\Desktop\Projets\glprofiler\git\glew-1.7.0\include 2 | C:\Users\Funto\Desktop\Projets\glprofiler\git\glfw-2.7.5.bin.WIN32\include 3 | -------------------------------------------------------------------------------- /glprofiler.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glprofiler", "glprofiler.vcxproj", "{08F01B7A-3ECF-4A15-A7D2-024DFFD23202}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {08F01B7A-3ECF-4A15-A7D2-024DFFD23202}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {08F01B7A-3ECF-4A15-A7D2-024DFFD23202}.Debug|Win32.Build.0 = Debug|Win32 14 | {08F01B7A-3ECF-4A15-A7D2-024DFFD23202}.Release|Win32.ActiveCfg = Release|Win32 15 | {08F01B7A-3ECF-4A15-A7D2-024DFFD23202}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /glprofiler.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {08F01B7A-3ECF-4A15-A7D2-024DFFD23202} 15 | Win32Proj 16 | glprofiler 17 | 18 | 19 | 20 | Application 21 | true 22 | Unicode 23 | 24 | 25 | Application 26 | false 27 | true 28 | Unicode 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | true 42 | $(SolutionDir)\ 43 | $(ProjectName)_vc10_d 44 | 45 | 46 | false 47 | $(SolutionDir)\ 48 | $(ProjectName)_vc10_r 49 | 50 | 51 | 52 | 53 | 54 | Level3 55 | Disabled 56 | _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 57 | glew-1.7.0\include;glfw-2.7.5\include;%(AdditionalIncludeDirectories) 58 | 59 | 60 | Console 61 | true 62 | opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 63 | 64 | 65 | 66 | 67 | Level3 68 | 69 | 70 | MaxSpeed 71 | true 72 | true 73 | _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 74 | glew-1.7.0\include;glfw-2.7.5\include;%(AdditionalIncludeDirectories) 75 | 76 | 77 | Console 78 | true 79 | true 80 | true 81 | opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /glprofiler.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {fb275b89-d14a-49d4-83d4-064c9c1217a2} 6 | 7 | 8 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 9 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 10 | 11 | 12 | {a717e8d0-01bc-4c3f-aa31-5f3560cd44f6} 13 | 14 | 15 | 16 | 17 | Sources 18 | 19 | 20 | Sources 21 | 22 | 23 | Sources 24 | 25 | 26 | Sources 27 | 28 | 29 | Sources 30 | 31 | 32 | Sources 33 | 34 | 35 | Sources 36 | 37 | 38 | Sources 39 | 40 | 41 | Sources 42 | 43 | 44 | Sources 45 | 46 | 47 | 48 | 49 | Sources 50 | 51 | 52 | Sources 53 | 54 | 55 | Sources 56 | 57 | 58 | Sources 59 | 60 | 61 | Sources 62 | 63 | 64 | Sources 65 | 66 | 67 | Sources 68 | 69 | 70 | Sources 71 | 72 | 73 | Sources 74 | 75 | 76 | Sources 77 | 78 | 79 | Sources 80 | 81 | 82 | 83 | 84 | Libraries 85 | 86 | 87 | Libraries 88 | 89 | 90 | 91 | 92 | Shaders 93 | 94 | 95 | Shaders 96 | 97 | 98 | Shaders 99 | 100 | 101 | Shaders 102 | 103 | 104 | Shaders 105 | 106 | 107 | Shaders 108 | 109 | 110 | -------------------------------------------------------------------------------- /grid.cpp: -------------------------------------------------------------------------------- 1 | // grid.cpp 2 | 3 | #include "grid.h" 4 | #include "utils.h" 5 | #include 6 | #include 7 | #include 8 | 9 | const int Grid::GRID_WIDTH = 300; 10 | const int Grid::GRID_HEIGHT = 300; 11 | 12 | const int Grid::GRID_NB_INDICES = 6 * (GRID_WIDTH-1) * (GRID_HEIGHT-1); 13 | 14 | const float Grid::GRID_WORLD_SIZE = 10.0f; 15 | 16 | const float Grid::GRID_Y_FLOOR = -3.0f; 17 | const float Grid::GRID_Y_DISTO = 0.5f; 18 | 19 | Grid::Grid() 20 | { 21 | m_time_offset = 0.0f; 22 | } 23 | 24 | bool Grid::init(float time_offset, const Color& color) 25 | { 26 | m_time_offset = time_offset; 27 | m_color = color; 28 | 29 | // Load the shaders 30 | if(!loadShaders("media/grid.vert", "media/grid.frag", m_id_vert_grid, m_id_frag_grid, m_id_prog_grid)) 31 | { 32 | fprintf(stderr, "*** ERROR: failed loading shaders for the grid\n"); 33 | return false; 34 | } 35 | 36 | // Get the uniforms 37 | m_id_uniform_mvp = glGetUniformLocation(m_id_prog_grid, "MVP"); 38 | if(m_id_uniform_mvp < 0) 39 | { 40 | fprintf(stderr, "*** Scene::init: FAILED retrieving uniform location\n"); 41 | return false; 42 | } 43 | 44 | // Initialize the positions and colors for the grid 45 | m_grid_vertices = new Vertex[GRID_WIDTH * GRID_HEIGHT]; 46 | 47 | float r = float(color.r) / 255.0f; 48 | float g = float(color.g) / 255.0f; 49 | float b = float(color.b) / 255.0f; 50 | 51 | for(int x=0 ; x < GRID_WIDTH ; x++) 52 | { 53 | for(int y=0 ; y < GRID_HEIGHT ; y++) 54 | { 55 | int i = x + y*GRID_WIDTH; 56 | 57 | m_grid_vertices[i].pos[0] = GRID_WORLD_SIZE * (float(x-GRID_WIDTH/2) / float(GRID_WIDTH)); 58 | m_grid_vertices[i].pos[1] = GRID_Y_FLOOR; 59 | m_grid_vertices[i].pos[2] = GRID_WORLD_SIZE * (float(y-GRID_HEIGHT/2) / float(GRID_HEIGHT)); 60 | 61 | //float fx = float(x) / float(GRID_WIDTH); 62 | float fy = float(y) / float(GRID_HEIGHT); 63 | 64 | float fr = fy*r; 65 | float fg = fy*g; 66 | float fb = fy*b; 67 | 68 | m_grid_vertices[i].col[0] = fr; 69 | m_grid_vertices[i].col[1] = fg; 70 | m_grid_vertices[i].col[2] = fb; 71 | } 72 | } 73 | 74 | // Initialize the indices 75 | m_grid_indices = new GLuint[GRID_NB_INDICES]; 76 | 77 | int i = 0; 78 | for(GLuint x=0 ; x < (GLuint)(GRID_WIDTH-1) ; x++) 79 | { 80 | for(GLuint y=0 ; y < (GLuint)(GRID_HEIGHT-1) ; y++) 81 | { 82 | GLuint bottom_left = x + y *(GLuint)(GRID_WIDTH); 83 | GLuint bottom_right = (x+1) + y *(GLuint)(GRID_WIDTH); 84 | GLuint top_right = (x+1) + (y+1)*(GLuint)(GRID_WIDTH); 85 | GLuint top_left = x + (y+1)*(GLuint)(GRID_WIDTH); 86 | 87 | m_grid_indices[i++] = bottom_left; 88 | m_grid_indices[i++] = bottom_right; 89 | m_grid_indices[i++] = top_right; 90 | 91 | m_grid_indices[i++] = bottom_left; 92 | m_grid_indices[i++] = top_right; 93 | m_grid_indices[i++] = top_left; 94 | } 95 | } 96 | 97 | // Temporary buffer used for the simulation 98 | m_grid_temp_buffer = new float[GRID_WIDTH * GRID_HEIGHT]; 99 | for(int i=0 ; i < GRID_WIDTH * GRID_HEIGHT ; i++) 100 | m_grid_temp_buffer[i] = GRID_Y_FLOOR; 101 | 102 | // IBO/VBO 103 | glGenBuffers(1, &m_id_ibo_grid); 104 | glGenBuffers(1, &m_id_vbo_grid); 105 | 106 | return true; 107 | } 108 | 109 | void Grid::shut() 110 | { 111 | delete [] m_grid_indices; 112 | delete [] m_grid_vertices; 113 | delete [] m_grid_temp_buffer; 114 | } 115 | 116 | void Grid::update(double elapsed, double t) 117 | { 118 | float shifted_t = (float)t + m_time_offset; 119 | 120 | for(int x=0 ; x < GRID_WIDTH ; x++) 121 | { 122 | float fx = float(x) / float(GRID_WIDTH); 123 | 124 | for(int y=0 ; y < GRID_HEIGHT ; y++) 125 | { 126 | float fy = float(y) / float(GRID_HEIGHT); 127 | 128 | int index = x + y*GRID_WIDTH; 129 | 130 | float f = 0.0f; 131 | f += cosf(10.0f*fx + 10.0f*shifted_t); 132 | f += sinf(13.0f*fy + 8.0f*shifted_t); 133 | m_grid_vertices[index].pos[1] = GRID_Y_FLOOR + f*GRID_Y_DISTO; 134 | } 135 | } 136 | } 137 | 138 | void Grid::draw(const float mvp_matrix[16]) 139 | { 140 | // Setup shader 141 | glUseProgram(m_id_prog_grid); 142 | glUniformMatrix4fv(m_id_uniform_mvp, 1, GL_FALSE, mvp_matrix); 143 | 144 | // Setup IBO 145 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id_ibo_grid); 146 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)*GRID_NB_INDICES, (const GLvoid*)m_grid_indices, GL_DYNAMIC_DRAW); 147 | 148 | // Setup VBO 149 | glBindBuffer(GL_ARRAY_BUFFER, m_id_vbo_grid); 150 | glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * GRID_WIDTH * GRID_HEIGHT, (const GLvoid*)m_grid_vertices, GL_DYNAMIC_DRAW); 151 | 152 | glEnableVertexAttribArray(0); // vertices 153 | glEnableVertexAttribArray(1); // color 154 | 155 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0 ); // vertices 156 | glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(3*sizeof(GLfloat))); // colors 157 | 158 | glDrawElements(GL_TRIANGLES, GRID_NB_INDICES, GL_UNSIGNED_INT, (const GLvoid*)0); 159 | 160 | glDisableVertexAttribArray(0); // vertices 161 | glDisableVertexAttribArray(1); // color 162 | } 163 | -------------------------------------------------------------------------------- /grid.h: -------------------------------------------------------------------------------- 1 | // grid.h 2 | 3 | #ifndef GRID_H 4 | #define GRID_H 5 | 6 | #include 7 | 8 | #include "camera.h" 9 | #include "utils.h" 10 | 11 | class Grid 12 | { 13 | private: 14 | static const int GRID_WIDTH; 15 | static const int GRID_HEIGHT; 16 | 17 | static const int GRID_NB_INDICES; 18 | 19 | static const float GRID_WORLD_SIZE; 20 | 21 | static const float GRID_Y_FLOOR; 22 | static const float GRID_Y_DISTO; 23 | 24 | struct Vertex 25 | { 26 | GLfloat pos[3]; 27 | GLfloat col[3]; 28 | }; 29 | 30 | Vertex* m_grid_vertices; 31 | GLuint* m_grid_indices; 32 | float* m_grid_temp_buffer; 33 | 34 | float m_time_offset; 35 | 36 | // Shader IDs 37 | GLuint m_id_vert_grid; 38 | GLuint m_id_frag_grid; 39 | GLuint m_id_prog_grid; 40 | 41 | // Shader uniforms 42 | GLint m_id_uniform_mvp; 43 | 44 | // VBO/IBO 45 | GLuint m_id_ibo_grid; 46 | GLuint m_id_vbo_grid; 47 | 48 | Camera m_camera; 49 | 50 | Color m_color; 51 | 52 | public: 53 | Grid(); 54 | bool init(float time_offset, const Color& color); 55 | void shut(); 56 | 57 | const Color& getColor() const {return m_color;} 58 | 59 | const Camera& getCamera() const {return m_camera;} 60 | Camera& getCamera() {return m_camera;} 61 | 62 | void update(double elapsed, double t); 63 | void draw(const float mvp_matrix[16]); 64 | }; 65 | 66 | #endif // GRID_H 67 | -------------------------------------------------------------------------------- /hole_array.h: -------------------------------------------------------------------------------- 1 | // hole_array.h 2 | 3 | #ifndef HOLE_ARRAY_H 4 | #define HOLE_ARRAY_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | template 11 | class HoleArray 12 | { 13 | public: 14 | static const size_t MAX_SIZE = max_size; 15 | private: 16 | T m_elements[MAX_SIZE]; 17 | std::vector m_used; // vector is optimized for space 18 | volatile size_t m_size; 19 | public: 20 | 21 | HoleArray() : m_used(MAX_SIZE, false), m_size(0) 22 | { 23 | } 24 | 25 | size_t getSize()const {return m_size;} 26 | size_t getMaxSize() const {return MAX_SIZE;} 27 | 28 | T* getPtr() {return m_elements;} 29 | const T* getPtr() const {return m_elements;} 30 | 31 | T& operator[](size_t i) { assert(m_used[i]); return m_elements[i];} 32 | const T& operator[](size_t i) const { assert(m_used[i]); return m_elements[i];} 33 | 34 | T& get(size_t i) { assert(m_used[i]); return m_elements[i];} 35 | const T& get(size_t i) const { assert(m_used[i]); return m_elements[i];} 36 | 37 | bool isUsed(size_t i) const {return m_used[i];} 38 | 39 | size_t add() 40 | { 41 | assert(m_size+1 < MAX_SIZE); 42 | 43 | size_t i = 0; 44 | while(m_used[i]) 45 | i++; 46 | m_used[i] = true; 47 | m_size++; 48 | return i; 49 | } 50 | 51 | void remove(size_t i) 52 | { 53 | assert(i < MAX_SIZE); 54 | m_used[i] = false; 55 | m_size--; 56 | } 57 | 58 | // Usage: for(size_t i = array.begin(); i != array.getMaxSize() ; i = array.next(i)) 59 | size_t begin() const 60 | { 61 | if(m_size == 0) 62 | return MAX_SIZE; 63 | 64 | size_t i = 0; 65 | while(i < MAX_SIZE && !m_used[i]) 66 | i++; 67 | return i; 68 | } 69 | 70 | size_t next(size_t i) const 71 | { 72 | i++; 73 | while(i < MAX_SIZE && !m_used[i]) 74 | i++; 75 | return i; 76 | } 77 | }; 78 | 79 | #endif // HOLE_ARRAY_H 80 | -------------------------------------------------------------------------------- /hp_timer.cpp: -------------------------------------------------------------------------------- 1 | // hp_timer.cpp 2 | 3 | #include "hp_timer.h" 4 | #include 5 | 6 | #ifdef _WIN32 7 | int64_t __freq; 8 | int64_t __time_at_init; 9 | 10 | void initTimer() 11 | { 12 | LARGE_INTEGER freq; 13 | QueryPerformanceFrequency(&freq); 14 | __freq = freq.QuadPart; 15 | 16 | LARGE_INTEGER now; 17 | QueryPerformanceCounter(&now); 18 | __time_at_init = now.QuadPart; 19 | } 20 | 21 | void shutTimer() {} 22 | 23 | #elif defined(__MACH__) 24 | 25 | clock_serv_t __clock_rt; 26 | unsigned int __tv_sec_at_init; 27 | 28 | void initTimer() 29 | { 30 | host_get_clock_service(mach_host_self(), REALTIME_CLOCK, &__clock_rt); 31 | 32 | // natural_t attributes[4]; 33 | // mach_msg_type_number_t count; 34 | // clock_get_attributes(__clock_rt, CLOCK_GET_TIME_RES, 35 | // (clock_attr_t)&attributes, &count); 36 | // printf("MacOS X: realtime clock resolution: %u ns\n", attributes[0]); 37 | 38 | mach_timespec_t mts; 39 | clock_get_time(__clock_rt, &mts); 40 | __tv_sec_at_init = mts.tv_sec; 41 | } 42 | 43 | void shutTimer() 44 | { 45 | mach_port_deallocate(mach_task_self(), __clock_rt); 46 | } 47 | 48 | #elif defined(__linux__) 49 | time_t __tv_sec_at_init = 0; 50 | 51 | void initTimer() 52 | { 53 | struct timespec ts; 54 | clock_gettime(CLOCK_REALTIME, &ts); 55 | __tv_sec_at_init = ts.tv_sec; 56 | } 57 | 58 | void shutTimer() {} 59 | 60 | #else 61 | time_t __tv_sec_at_init = 0; 62 | 63 | void initTimer() 64 | { 65 | struct timeval tv; 66 | gettimeofday(&tv, NULL); 67 | __tv_sec_at_init = ts.tv_sec; 68 | } 69 | 70 | void shutTimer() {} 71 | #endif 72 | -------------------------------------------------------------------------------- /hp_timer.h: -------------------------------------------------------------------------------- 1 | // hp_timer.h 2 | 3 | #ifndef __HP_TIMER_H__ 4 | #define __HP_TIMER_H__ 5 | 6 | #include 7 | 8 | void initTimer(); 9 | void shutTimer(); 10 | 11 | #ifdef _WIN32 // Windows 32 bits and 64 bits: use QueryPerformanceCounter() 12 | #include 13 | 14 | extern int64_t __freq; 15 | extern int64_t __time_at_init; 16 | 17 | inline uint64_t getTimeNs() 18 | { 19 | LARGE_INTEGER now; 20 | QueryPerformanceCounter(&now); 21 | static const uint64_t factor = 1000000000; 22 | return (uint64_t)( factor*(now.QuadPart-__time_at_init) / __freq ); 23 | } 24 | 25 | #elif defined(__MACH__) // OSX: use clock_get_time 26 | #include 27 | #include 28 | #include 29 | 30 | extern clock_serv_t __clock_rt; 31 | extern unsigned int __tv_sec_at_init; 32 | 33 | inline uint64_t getTimeNs() 34 | { 35 | // http://pastebin.com/89qJQsCw 36 | // http://www.opensource.apple.com/source/xnu/xnu-344/osfmk/i386/rtclock.c 37 | // http://opensource.apple.com/source/xnu/xnu-1456.1.26/osfmk/man/host_get_clock_service.html -> HIGHRES_CLOCK 38 | 39 | mach_timespec_t mts; 40 | clock_get_time(__clock_rt, &mts); 41 | 42 | uint64_t time_sec = (uint64_t)(mts.tv_sec - __tv_sec_at_init); 43 | uint64_t time_ns = time_sec * (uint64_t)(1000000000); 44 | time_ns += (uint64_t)(mts.tv_nsec); 45 | return time_ns; 46 | } 47 | 48 | #elif defined(__linux__) // Linux: use clock_gettime() 49 | 50 | #include 51 | 52 | extern time_t __tv_sec_at_init; 53 | 54 | inline uint64_t getTimeNs() 55 | { 56 | struct timespec ts; 57 | clock_gettime(CLOCK_REALTIME, &ts); 58 | uint64_t time_sec = (uint64_t)(ts.tv_sec - __tv_sec_at_init); 59 | uint64_t time_ns = time_sec * (uint64_t)(1000000000); 60 | time_ns += (uint64_t)(ts.tv_nsec); 61 | return time_ns; 62 | } 63 | 64 | #else // Fallback for other UN*X systems: use gettimeofday() 65 | // http://stackoverflow.com/questions/275004/c-timer-function-to-provide-time-in-nano-seconds 66 | 67 | extern time_t __tv_sec_at_init; 68 | 69 | #include 70 | inline uint64_t getTimeNs() 71 | { 72 | struct timeval tv; 73 | gettimeofday(&tv, NULL); 74 | uint64_t time_sec = (uint64_t)(ts.tv_sec - __tv_sec_at_init); 75 | uint64_t time_ns = time_sec * (uint64_t)(1000000000); 76 | time_ns += (uint64_t)(ts.tv_nsec); 77 | return time_ns; 78 | } 79 | #endif 80 | 81 | #endif // __HP_TIMER_H__ 82 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | // main.cpp 2 | 3 | #include 4 | #include "scene.h" 5 | 6 | #include 7 | 8 | #ifdef __APPLE__ 9 | #include 10 | #include 11 | #else 12 | #include 13 | #include 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include "hp_timer.h" 20 | #include "profiler.h" 21 | #include "drawer2D.h" 22 | #include "thread.h" 23 | #include "math_utils.h" 24 | 25 | //#define USE_FORWARD_COMPATIBLE_CONTEXT_GL_3_3 26 | //#define USE_FORWARD_COMPATIBLE_CONTEXT_GL_4 27 | //#define USE_DEBUG_CONTEXT 28 | 29 | #define BASE_TITLE "Profiler - OpenGL Insights" 30 | #define WIN_WIDTH 640 31 | #define WIN_HEIGHT 480 32 | 33 | static volatile bool done = false; 34 | Scene scene; 35 | bool help_visible = true; 36 | 37 | void GLFWCALL onMouseClick(int x, int y); 38 | void GLFWCALL onKey(int key, int action); 39 | void drawHelp(); 40 | 41 | void debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, 42 | GLsizei length, const GLchar* message, GLvoid* userParam) 43 | { 44 | fprintf(stderr, "GL debug: %s\n", message); 45 | } 46 | 47 | void fpsCount(const char* base_title) 48 | { 49 | static bool first_time = false; 50 | static double t, t0; 51 | static int fps = 0, frames = 0; 52 | 53 | if(first_time) 54 | { 55 | t0 = glfwGetTime(); 56 | first_time = true; 57 | } 58 | 59 | t = glfwGetTime(); 60 | 61 | if( (t-t0) > 1.0) 62 | { 63 | fps = (int)((double)frames / (double)(t-t0)); 64 | char buffer[256] = ""; 65 | sprintf(buffer, "%s - FPS : %d", base_title, fps); 66 | glfwSetWindowTitle(buffer); 67 | t0 = t; 68 | frames = 0; 69 | } 70 | frames++; 71 | } 72 | 73 | int main() 74 | { 75 | int win_w, win_h; 76 | int prev_win_w, prev_win_h; 77 | int mouse_x, mouse_y; 78 | int prev_mouse_x, prev_mouse_y; 79 | 80 | initTimer(); 81 | 82 | // Initialize GLFW 83 | if( !glfwInit() ) 84 | { 85 | fprintf( stderr, "Failed to initialize GLFW\n" ); 86 | return EXIT_FAILURE; 87 | } 88 | 89 | // Open a window and create its OpenGL context 90 | #ifdef USE_FORWARD_COMPATIBLE_CONTEXT_GL_3_3 91 | glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); 92 | glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); 93 | glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 94 | #ifdef __APPLE__ 95 | #warning "MacOS X might not yet support OpenGL 3.3 (3.2 was the maximum for 10.8)" 96 | #endif 97 | #elif defined USE_FORWARD_COMPATIBLE_CONTEXT_GL_4 98 | glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); 99 | glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 0); 100 | glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 101 | #ifdef __APPLE__ 102 | #warning "MacOS X might not yet support OpenGL 3.3 (3.2 was the maximum for 10.8)" 103 | #endif 104 | #else 105 | #ifdef __APPLE__ 106 | glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); 107 | glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); 108 | glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 109 | #endif 110 | #endif 111 | 112 | #ifdef USE_DEBUG_CONTEXT 113 | glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); 114 | #endif 115 | 116 | if( !glfwOpenWindow( WIN_WIDTH, WIN_HEIGHT, 0,0,0,0, 0,0, GLFW_WINDOW ) ) 117 | { 118 | fprintf(stderr, "Failed to open GLFW window\n"); 119 | 120 | glfwTerminate(); 121 | return EXIT_FAILURE; 122 | } 123 | 124 | glfwSetWindowTitle( BASE_TITLE ); 125 | 126 | // Check OpenGL version 127 | // in case of GL 1.x or 2.x we have to check with glGetString: 128 | const GLubyte *version = glGetString(GL_VERSION); 129 | if ((version[0] == '2' || version[0] == '1') && version[1] == '.') 130 | { 131 | fprintf(stderr, "*** OpenGL version too low, need at least 3.2 for ARB_timer_query (%s)\n", version); 132 | return EXIT_FAILURE; 133 | } 134 | 135 | // getting the version with glGetInteger needs gl >= 3.0 136 | GLint major, minor; 137 | glGetIntegerv(GL_MAJOR_VERSION, &major); 138 | glGetIntegerv(GL_MINOR_VERSION, &minor); 139 | 140 | if(major == 3 && minor < 2) 141 | { 142 | fprintf(stderr, "*** OpenGL version too low, need at least 3.2 for ARB_timer_query (%d.%d)\n",major, minor); 143 | return EXIT_FAILURE; 144 | } 145 | printf("OpenGL version: %d.%d\n", major, minor); 146 | 147 | // Load the OpenGL implementation + available extensions 148 | #ifdef __APPLE__ 149 | glewExperimental = GL_TRUE; // needed for core profiles 150 | #endif 151 | GLenum error = glewInit(); 152 | if(error != GL_NO_ERROR) 153 | { 154 | fprintf(stderr, "Failed to initialize GLEW: error=%d\n", (int)error); 155 | glfwTerminate(); 156 | return EXIT_FAILURE; 157 | } 158 | 159 | // Register a debug callback if supported by the driver 160 | if(GLEW_ARB_debug_output) 161 | { 162 | glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); 163 | glDebugMessageCallbackARB((GLDEBUGPROCARB)&debugCallback, NULL); 164 | } 165 | 166 | // Setup a VAO for the whole time the program is executed 167 | GLuint id_vao; 168 | glGenVertexArrays(1, &id_vao); 169 | glBindVertexArray(id_vao); 170 | 171 | // Set the default OpenGL state 172 | glEnable(GL_DEPTH_TEST); 173 | glEnable(GL_BLEND); 174 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 175 | 176 | // Mouse and window size 177 | glfwGetMousePos(&mouse_x, &mouse_y); 178 | glfwGetWindowSize(&win_w, &win_h); 179 | 180 | glfwSetMouseButtonCallback(&onMouseClick); 181 | glfwSetKeyCallback(&onKey); 182 | 183 | // Initialize the 2D drawer 184 | if(!drawer2D.init(win_w, win_h)) 185 | { 186 | fprintf(stderr, "*** FAILED initializing the Drawer2D\n"); 187 | return EXIT_FAILURE; 188 | } 189 | 190 | // Initialize the profiler 191 | PROFILER_INIT(win_w, win_h, mouse_x, mouse_y); 192 | 193 | // Initialize the example scene 194 | if(!scene.init()) 195 | { 196 | fprintf(stderr, "*** FAILED initializing the scene\n"); 197 | return EXIT_FAILURE; 198 | } 199 | printf("Multithreaded update: %s\n", scene.isMultithreaded() ? "yes" : "no"); 200 | 201 | // Enable vertical sync 202 | glfwSwapInterval( 1 ); 203 | 204 | // Main loop 205 | double elapsed = 0.0; 206 | double t = glfwGetTime(); 207 | double last_t = t; 208 | do 209 | { 210 | last_t = t; 211 | t = glfwGetTime(); 212 | elapsed = t - last_t; 213 | 214 | PROFILER_SYNC_FRAME(); 215 | PROFILER_PUSH_CPU_MARKER("Full frame", COLOR_GRAY); 216 | 217 | // Update mouse and window size 218 | prev_mouse_x = mouse_x; prev_mouse_y = mouse_y; 219 | glfwGetMousePos( &mouse_x, &mouse_y); 220 | 221 | prev_win_w = win_w; prev_win_h = win_h; 222 | win_h = win_h > 0 ? win_h : 1; 223 | 224 | glfwGetWindowSize(&win_w, &win_h); 225 | 226 | // Detect and notify changes in the mouse position or the window size 227 | if(prev_mouse_x != mouse_x || prev_mouse_y != mouse_y) 228 | { 229 | PROFILER_ON_MOUSE_POS(mouse_x, mouse_y); 230 | } 231 | if(prev_win_w != win_w || prev_win_h != win_h) 232 | { 233 | PROFILER_ON_RESIZE(win_w, win_h); 234 | drawer2D.onResize(win_w, win_h); 235 | } 236 | 237 | glViewport( 0, 0, win_w, win_h ); 238 | 239 | // Clear color buffer to black 240 | glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); 241 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 242 | 243 | glEnable(GL_DEPTH_TEST); 244 | 245 | PROFILER_PUSH_CPU_MARKER("Update scene", COLOR_GREEN); 246 | scene.update(elapsed, t); 247 | PROFILER_POP_CPU_MARKER(); 248 | 249 | PROFILER_PUSH_CPU_MARKER("Draw scene", COLOR_RED); 250 | scene.draw(win_w, win_h); 251 | PROFILER_POP_CPU_MARKER(); 252 | 253 | glDisable(GL_DEPTH_TEST); 254 | 255 | PROFILER_PUSH_GPU_MARKER("Draw profiler", COLOR_DARK_BLUE); 256 | PROFILER_DRAW(); 257 | PROFILER_POP_GPU_MARKER(); 258 | 259 | if(help_visible) 260 | { 261 | PROFILER_PUSH_CPU_MARKER("Draw help", COLOR_MAGENTA); 262 | drawHelp(); 263 | PROFILER_POP_CPU_MARKER(); 264 | } 265 | 266 | checkGLError(); 267 | 268 | fpsCount(BASE_TITLE); 269 | 270 | // Swap buffers 271 | glfwSwapBuffers(); 272 | 273 | PROFILER_POP_CPU_MARKER(); 274 | 275 | } // Check if the ESC key was pressed or the window was closed 276 | while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && glfwGetWindowParam( GLFW_OPENED ) ); 277 | 278 | done = true; 279 | 280 | scene.shut(); 281 | 282 | PROFILER_SHUT(); 283 | 284 | drawer2D.shut(); 285 | 286 | // Close OpenGL window and terminate GLFW 287 | glfwTerminate(); 288 | 289 | shutTimer(); 290 | 291 | return EXIT_SUCCESS; 292 | } 293 | 294 | void GLFWCALL onMouseClick(int button, int action) 295 | { 296 | if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE) 297 | { 298 | PROFILER_ON_LEFT_CLICK(); 299 | } 300 | } 301 | 302 | void GLFWCALL onKey(int key, int action) 303 | { 304 | if(action == GLFW_RELEASE) 305 | { 306 | switch(key) 307 | { 308 | case 'H': 309 | help_visible = !help_visible; 310 | break; 311 | case 'P': 312 | profiler.setVisible(!profiler.isVisible()); 313 | break; 314 | case 'M': 315 | scene.setMultithreaded(!scene.isMultithreaded()); 316 | printf("Multithreaded update: %s\n", scene.isMultithreaded() ? "yes" : "no"); 317 | break; 318 | } 319 | } 320 | } 321 | 322 | void drawHelp() 323 | { 324 | drawer2D.drawRect(Rect(0.1f, 0.1f, 0.8f, 0.8f), Color(0xC0, 0xC0, 0xC0), 0.5f); 325 | drawer2D.drawString( 326 | "Commands:\n" 327 | "[H]: display this help message\n" 328 | "[P]: profiler visiblity\n" 329 | "[M]: mono/multi threaded update\n" 330 | "[ESC]: quit\n" 331 | "click on the profiler to freeze it\n", 332 | 0.12f, 1.0f-0.15f, COLOR_WHITE); 333 | } 334 | -------------------------------------------------------------------------------- /math_utils.cpp: -------------------------------------------------------------------------------- 1 | // math_utils.cpp 2 | 3 | #include "math_utils.h" 4 | 5 | // result = a*b 6 | void matrixMult(float result[16], const float* a, const float* b) 7 | { 8 | for(int i=0 ; i<4 ; i++) 9 | { 10 | for(int j=0 ; j<4 ; j++) 11 | { 12 | float val = 0.0f; 13 | 14 | for(int k=0 ; k<4 ; k++) 15 | val += a[i + 4*k] * b[k + 4*j]; 16 | 17 | result[i + 4*j] = val; 18 | } 19 | } 20 | } 21 | 22 | // Translation 23 | void matrixTranslate(float result[16], const float v[3]) 24 | { 25 | result[0] = 1.0f; result[4] = 0.0f; result[8] = 0.0f; result[12] = v[0]; 26 | result[1] = 0.0f; result[5] = 1.0f; result[9] = 0.0f; result[13] = v[1]; 27 | result[2] = 0.0f; result[6] = 0.0f; result[10] = 1.0f; result[14] = v[2]; 28 | result[3] = 0.0f; result[7] = 0.0f; result[11] = 0.0f; result[15] = 1.0f; 29 | } 30 | 31 | // Rotation 32 | 33 | void matrixRotateX(float result[16], float theta_degrees) 34 | { 35 | theta_degrees *= (PI_FLOAT / 180.0f); 36 | float s = sinf(theta_degrees); 37 | float c = cosf(theta_degrees); 38 | 39 | result[0] = 1.0f; result[4] = 0.0f; result[8] = 0.0f; result[12] = 0.0f; 40 | result[1] = 0.0f; result[5] = c; result[9] = -s; result[13] = 0.0f; 41 | result[2] = 0.0f; result[6] = s; result[10] = c; result[14] = 0.0f; 42 | result[3] = 0.0f; result[7] = 0.0f; result[11] = 0.0f; result[15] = 1.0f; 43 | } 44 | 45 | void matrixRotateY(float result[16], float theta_degrees) 46 | { 47 | theta_degrees *= (PI_FLOAT / 180.0f); 48 | float s = sinf(theta_degrees); 49 | float c = cosf(theta_degrees); 50 | 51 | result[0] = c; result[4] = 0.0f; result[8] = s; result[12] = 0.0f; 52 | result[1] = 0.0f; result[5] = 1.0f; result[9] = 0.0f; result[13] = 0.0f; 53 | result[2] = -s; result[6] = 0.0f; result[10] = c; result[14] = 0.0f; 54 | result[3] = 0.0f; result[7] = 0.0f; result[11] = 0.0f; result[15] = 1.0f; 55 | } 56 | 57 | void matrixRotateZ(float result[16], float theta_degrees) 58 | { 59 | theta_degrees *= (PI_FLOAT / 180.0f); 60 | float s = sinf(theta_degrees); 61 | float c = cosf(theta_degrees); 62 | 63 | result[0] = c; result[4] = -s; result[8] = 0.0f; result[12] = 0.0f; 64 | result[1] = s; result[5] = c; result[9] = 0.0f; result[13] = 0.0f; 65 | result[2] = 0.0f; result[6] = 0.0f; result[10] = 1.0f; result[14] = 0.0f; 66 | result[3] = 0.0f; result[7] = 0.0f; result[11] = 0.0f; result[15] = 1.0f; 67 | } 68 | 69 | // Projection matrix handling - see http://www.opengl.org/wiki/GluPerspective_code 70 | void matrixPerspective(float result[16], float fovy_degrees, float aspect_ratio, 71 | float znear, float zfar) 72 | { 73 | float ymax, xmax; 74 | ymax = znear * tanf(fovy_degrees * PI_FLOAT / 360.0f); 75 | xmax = ymax * aspect_ratio; 76 | matrixFrustum(result, -xmax, xmax, -ymax, ymax, znear, zfar); 77 | } 78 | 79 | // glFrustum() equivalent 80 | void matrixFrustum( float result[16], 81 | float left, float right, 82 | float bottom, float top, 83 | float znear, float zfar) 84 | { 85 | float temp, temp2, temp3, temp4; 86 | temp = 2.0f * znear; 87 | temp2 = right - left; 88 | temp3 = top - bottom; 89 | temp4 = zfar - znear; 90 | result[0] = temp / temp2; 91 | result[1] = 0.0f; 92 | result[2] = 0.0f; 93 | result[3] = 0.0f; 94 | result[4] = 0.0f; 95 | result[5] = temp / temp3; 96 | result[6] = 0.0f; 97 | result[7] = 0.0f; 98 | result[8] = (right + left) / temp2; 99 | result[9] = (top + bottom) / temp3; 100 | result[10] = (-zfar - znear) / temp4; 101 | result[11] = -1.0f; 102 | result[12] = 0.0f; 103 | result[13] = 0.0f; 104 | result[14] = (-temp * zfar) / temp4; 105 | result[15] = 0.0f; 106 | } 107 | 108 | // gluLookAt() equivalent 109 | void matrixLookAt( float result[16], 110 | const float eye[3], 111 | const float target[3], 112 | const float up[3]) 113 | { 114 | float forward[3] = { target[0] - eye[0], 115 | target[1] - eye[1], 116 | target[2] - eye[2] }; 117 | vecNormalize(forward); 118 | 119 | float side[3]; 120 | vecCross(side, forward, up); 121 | 122 | float up_after[3]; 123 | vecCross(up_after, side, forward); 124 | 125 | float view_matrix[16] = MATRIX_IDENTITY; 126 | 127 | view_matrix[0] = side[0]; 128 | view_matrix[4] = side[1]; 129 | view_matrix[8] = side[2]; 130 | 131 | view_matrix[1] = up_after[0]; 132 | view_matrix[5] = up_after[1]; 133 | view_matrix[9] = up_after[2]; 134 | 135 | view_matrix[2] = -forward[0]; 136 | view_matrix[6] = -forward[1]; 137 | view_matrix[10] = -forward[2]; 138 | 139 | // Final translation 140 | float trans_matrix[16]; 141 | float minus_eye[3] = {-eye[0], -eye[1], -eye[2]}; 142 | matrixTranslate(trans_matrix, minus_eye); 143 | 144 | matrixMult(result, view_matrix, trans_matrix); 145 | } 146 | -------------------------------------------------------------------------------- /math_utils.h: -------------------------------------------------------------------------------- 1 | // math_utils.h 2 | 3 | #ifndef MAT_UTILS_H 4 | #define MAT_UTILS_H 5 | 6 | #include 7 | 8 | #ifndef PI_FLOAT 9 | #define PI_FLOAT 3.14159265358979323846f 10 | #endif 11 | 12 | // ----------------------------------------- 13 | // Vectors 14 | inline float vecLength(const float v[3]) 15 | { 16 | return sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); 17 | } 18 | 19 | inline float vecNormalize(float v[3]) 20 | { 21 | float len = vecLength(v); 22 | v[0] /= len; 23 | v[1] /= len; 24 | v[2] /= len; 25 | return len; 26 | } 27 | 28 | inline void vecCross(float result[3], const float a[3], const float b[3]) 29 | { 30 | result[0] = a[1] * b[2] - a[2] * b[1]; 31 | result[1] = - (a[0] * b[2] - a[2] * b[0]); 32 | result[2] = a[0] * b[1] - a[1] * b[0]; 33 | } 34 | 35 | inline float vecDot(const float a[3], const float b[3]) 36 | { 37 | return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; 38 | } 39 | 40 | // ----------------------------------------- 41 | // Matrices are stored following the OpenGL convention: 42 | // float mat[16]; -> "column-major order": mat[0..3] is the first column, etc. 43 | // 44 | // 0 4 8 12 45 | // 1 5 9 13 46 | // 2 6 10 14 47 | // 3 7 11 15 48 | // 49 | // mat[i] -> ith column 50 | 51 | #define MATRIX_IDENTITY { 1.0f, 0.0f, 0.0f, 0.0f, \ 52 | 0.0f, 1.0f, 0.0f, 0.0f, \ 53 | 0.0f, 0.0f, 1.0f, 0.0f, \ 54 | 0.0f, 0.0f, 0.0f, 1.0f } 55 | 56 | // result = a*b 57 | void matrixMult(float result[16], const float* a, const float* b); 58 | 59 | // Translation 60 | void matrixTranslate(float result[16], const float v[3]); 61 | 62 | // Rotation 63 | void matrixRotateX(float result[16], float theta_degrees); 64 | void matrixRotateY(float result[16], float theta_degrees); 65 | void matrixRotateZ(float result[16], float theta_degrees); 66 | 67 | // Projection matrix handling - see http://www.opengl.org/wiki/GluPerspective_code 68 | void matrixPerspective(float result[16], float fovy_degrees, float aspect_ratio, 69 | float znear, float zfar); 70 | 71 | // glFrustum() equivalent 72 | void matrixFrustum( float result[16], 73 | float left, float right, 74 | float bottom, float top, 75 | float znear, float zfar); 76 | 77 | // gluLookAt() equivalent 78 | void matrixLookAt( float result[16], 79 | const float eye[3], 80 | const float target[3], 81 | const float up[3]); 82 | 83 | #endif // MAT_UTILS_H 84 | -------------------------------------------------------------------------------- /media/color.frag: -------------------------------------------------------------------------------- 1 | // color.frag 2 | 3 | //#version 330 core 4 | #version 330 5 | 6 | // --------------------------------------------------------------------- 7 | // Default precision: 8 | //precision highp float; 9 | //precision mediump int; 10 | 11 | // --------------------------------------------------------------------- 12 | uniform vec4 color; 13 | 14 | // --------------------------------------------------------------------- 15 | out vec4 frag_color; 16 | 17 | // --------------------------------------------------------------------- 18 | void main() 19 | { 20 | frag_color = color; 21 | // gl_FragColor = color; 22 | } 23 | -------------------------------------------------------------------------------- /media/color.vert: -------------------------------------------------------------------------------- 1 | // color.vert 2 | 3 | #version 330 core 4 | 5 | // --------------------------------------------------------------------- 6 | // Default precision 7 | //precision highp float; 8 | //precision highp int; 9 | 10 | // --------------------------------------------------------------------- 11 | //in vec2 vertex_position; 12 | layout(location = 0) in vec2 vertex_position; 13 | 14 | // --------------------------------------------------------------------- 15 | void main() 16 | { 17 | vec2 xy = 2.0*vertex_position - vec2(1.0); 18 | gl_Position = vec4(xy, 0.0, 1.0); 19 | } 20 | -------------------------------------------------------------------------------- /media/font.frag: -------------------------------------------------------------------------------- 1 | // font.frag 2 | 3 | //#version 330 core 4 | #version 330 5 | 6 | // --------------------------------------------------------------------- 7 | // Default precision: 8 | //precision highp float; 9 | //precision mediump int; 10 | 11 | // --------------------------------------------------------------------- 12 | uniform vec3 font_color; 13 | uniform sampler2D tex_font; 14 | 15 | // --------------------------------------------------------------------- 16 | in vec2 uv; 17 | 18 | // --------------------------------------------------------------------- 19 | out vec4 frag_color; 20 | 21 | // --------------------------------------------------------------------- 22 | void main() 23 | { 24 | float a = texture(tex_font, uv).a; 25 | vec3 color = font_color; 26 | frag_color = vec4(color,a); 27 | } 28 | -------------------------------------------------------------------------------- /media/font.vert: -------------------------------------------------------------------------------- 1 | // font.vert 2 | 3 | #version 330 core 4 | 5 | // --------------------------------------------------------------------- 6 | // Default precision 7 | //precision highp float; 8 | //precision highp int; 9 | 10 | // --------------------------------------------------------------------- 11 | //in vec2 vertex_position; 12 | layout(location = 0) in vec2 vertex_position; 13 | layout(location = 1) in vec2 vertex_uv; 14 | 15 | out vec2 uv; 16 | 17 | // --------------------------------------------------------------------- 18 | void main() 19 | { 20 | vec2 xy = 2.0*vertex_position - vec2(1.0); 21 | 22 | uv = vertex_uv; // TODO: bug where we see a part of the letter above... 23 | 24 | gl_Position = vec4(xy, 0.0, 1.0); 25 | } 26 | -------------------------------------------------------------------------------- /media/grid.frag: -------------------------------------------------------------------------------- 1 | // grid.frag 2 | 3 | #version 330 core 4 | 5 | // --------------------------------------------------------------------- 6 | // Default precision: 7 | //precision highp float; 8 | //precision mediump int; 9 | 10 | // --------------------------------------------------------------------- 11 | in vec3 var_color; 12 | 13 | out vec4 frag_color; 14 | 15 | // --------------------------------------------------------------------- 16 | void main() 17 | { 18 | frag_color = vec4(var_color, 1.0); 19 | } 20 | -------------------------------------------------------------------------------- /media/grid.vert: -------------------------------------------------------------------------------- 1 | // grid.vert 2 | 3 | #version 330 core 4 | 5 | // --------------------------------------------------------------------- 6 | // Default precision 7 | //precision highp float; 8 | //precision highp int; 9 | 10 | uniform mat4 MVP; 11 | 12 | // --------------------------------------------------------------------- 13 | layout(location = 0) in vec3 vertex_position; 14 | layout(location = 1) in vec3 vertex_color; 15 | 16 | out vec3 var_color; 17 | 18 | // --------------------------------------------------------------------- 19 | void main() 20 | { 21 | var_color = vertex_color; 22 | 23 | gl_Position = MVP * vec4(vertex_position, 1.0); 24 | } 25 | -------------------------------------------------------------------------------- /media/times_new_roman.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Funto/OpenGL-Timestamp-Profiler/cdcdb56b3895ededab8ee6fd55d73e6bb01d183c/media/times_new_roman.tga -------------------------------------------------------------------------------- /profiler.cpp: -------------------------------------------------------------------------------- 1 | // profiler.cpp 2 | 3 | #include "profiler.h" 4 | 5 | #ifdef ENABLE_PROFILER 6 | 7 | #include "hp_timer.h" 8 | #include "drawer2D.h" 9 | #include "thread.h" 10 | #include 11 | #include 12 | 13 | Profiler profiler; 14 | 15 | // Unit: percentage of the screen dimensions 16 | #define MARGIN_X 0.02f // left and right margin 17 | #define MARGIN_Y 0.02f // bottom margin 18 | #define LINE_HEIGHT 0.01f // height of a line representing a thread 19 | 20 | //#define TIME_DRAWN_MS 30.0 // the width of the profiler corresponds to TIME_DRAWN_MS milliseconds 21 | //#define TIME_DRAWN_MS 60.0 // the width of the profiler corresponds to TIME_DRAWN_MS milliseconds 22 | #define TIME_DRAWN_MS 120.0 // the width of the profiler corresponds to TIME_DRAWN_MS milliseconds 23 | 24 | #define GPU_COUNT 1 // TODO: multiple GPUs are not supported 25 | 26 | // ----- 27 | #define PROFILER_WIDTH (1.0f - 2.0f*MARGIN_X) 28 | #define X_OFFSET MARGIN_X 29 | #define Y_OFFSET (MARGIN_Y + LINE_HEIGHT) 30 | #define X_FACTOR ( (float)(PROFILER_WIDTH / (TIME_DRAWN_MS * 1000000.0)) ) 31 | 32 | #define Y_SCALE_OFFSET 0.002f // By how much do we reduce the height when displaying 33 | // a marker that is lower in the hierarchy 34 | 35 | #define NB_MAX_TEXT_LINES 20 36 | #define Y_TEXT_MARGIN 0.05f // size between 2 lines of text 37 | 38 | #define COLOR_FROZEN Color(0xD0, 0xD0, 0xD0) 39 | 40 | //----------------------------------------------------------------------------- 41 | void Profiler::init(int win_w, int win_h, int mouse_x, int mouse_y) 42 | { 43 | m_cur_frame = 0; 44 | m_freeze_state = UNFROZEN; 45 | m_visible = true; 46 | 47 | updateBackgroundRect(); 48 | 49 | m_win_w = win_w; 50 | m_win_h = win_h; 51 | m_mouse_x = mouse_x; 52 | m_mouse_y = mouse_y; 53 | 54 | mutexCreate(&m_cpu_mutex); 55 | 56 | for(size_t i=0 ; i < NB_RECORDED_FRAMES ; i++) 57 | { 58 | m_frame_info[i].frame = -1; 59 | m_frame_info[i].time_sync_start = INVALID_TIME; 60 | m_frame_info[i].time_sync_end = INVALID_TIME; 61 | } 62 | } 63 | 64 | //----------------------------------------------------------------------------- 65 | void Profiler::shut() 66 | { 67 | // Release GPU timer queries 68 | for(size_t i=0 ; i < NB_GPU_MARKERS ; i++) 69 | { 70 | GpuMarker& marker = m_gpu_thread_info.markers[i]; 71 | if(marker.id_query_start != INVALID_QUERY) 72 | { 73 | glDeleteQueries(1, &marker.id_query_start); 74 | marker.id_query_start = INVALID_QUERY; 75 | } 76 | if(marker.id_query_end != INVALID_QUERY) 77 | { 78 | glDeleteQueries(1, &marker.id_query_end); 79 | marker.id_query_end = INVALID_QUERY; 80 | } 81 | } 82 | 83 | mutexDestroy(&m_cpu_mutex); 84 | } 85 | 86 | //----------------------------------------------------------------------------- 87 | /// Push a new marker that starts now 88 | void Profiler::pushCpuMarker(const char* name, const Color& color) 89 | { 90 | // Don't do anything when frozen 91 | if(isFrozen()) 92 | return; 93 | 94 | CpuThreadInfo& ti = getOrAddCpuThreadInfo(); 95 | 96 | Marker& marker = ti.markers[ti.cur_write_id]; 97 | assert(marker.frame != m_cur_frame && "looping: too many markers, no free slots available"); 98 | 99 | marker.start = getTimeNs(); 100 | marker.end = INVALID_TIME; 101 | marker.layer = ti.nb_pushed_markers; 102 | strncpy(marker.name, name, MARKER_NAME_MAX_LENGTH); 103 | marker.color = color; 104 | marker.frame = m_cur_frame; 105 | 106 | incrementCycle(&ti.cur_write_id, NB_MARKERS_PER_CPU_THREAD); 107 | ti.nb_pushed_markers++; 108 | } 109 | 110 | //----------------------------------------------------------------------------- 111 | /// Stop the last pushed marker 112 | void Profiler::popCpuMarker() 113 | { 114 | // Don't do anything when frozen 115 | if(isFrozen()) 116 | return; 117 | 118 | CpuThreadInfo& ti = getOrAddCpuThreadInfo(); 119 | assert(ti.nb_pushed_markers != 0); 120 | 121 | // Get the most recent marker that has not been closed yet 122 | int index = ti.cur_write_id-1; 123 | while(ti.markers[index].end != INVALID_TIME) // skip closed markers 124 | decrementCycle(&index, NB_MARKERS_PER_CPU_THREAD); 125 | 126 | Marker& marker = ti.markers[index]; 127 | assert(marker.end == INVALID_TIME); 128 | marker.end = getTimeNs(); 129 | 130 | ti.nb_pushed_markers--; 131 | } 132 | 133 | //----------------------------------------------------------------------------- 134 | /// Push a new GPU marker that starts when the previously issued commands are processed 135 | void Profiler::pushGpuMarker(const char* name, const Color& color) 136 | { 137 | // Don't do anything when frozen 138 | if(isFrozen()) 139 | return; 140 | 141 | GpuThreadInfo& ti = m_gpu_thread_info; 142 | GpuMarker& marker = ti.markers[ti.cur_write_id]; 143 | 144 | assert(marker.frame != m_cur_frame && "looping: too many markers, no free slots available"); 145 | 146 | // Issue timer query 147 | if(marker.id_query_start == INVALID_QUERY) 148 | glGenQueries(1, &marker.id_query_start); 149 | glQueryCounter(marker.id_query_start, GL_TIMESTAMP); 150 | 151 | // Fill in marker 152 | marker.start = INVALID_TIME; 153 | marker.end = INVALID_TIME; 154 | marker.layer = ti.nb_pushed_markers; 155 | strncpy(marker.name, name, MARKER_NAME_MAX_LENGTH); 156 | marker.color = color; 157 | marker.frame = m_cur_frame; 158 | 159 | incrementCycle(&ti.cur_write_id, NB_GPU_MARKERS); 160 | ti.nb_pushed_markers++; 161 | } 162 | 163 | //----------------------------------------------------------------------------- 164 | /// Stop the last pushed GPU marker when the previously issued commands are processed 165 | void Profiler::popGpuMarker() 166 | { 167 | // Don't do anything when frozen 168 | if(isFrozen()) 169 | return; 170 | 171 | GpuThreadInfo& ti = m_gpu_thread_info; 172 | 173 | // Get the most recent marker that has not been closed yet 174 | int index = ti.cur_write_id-1; 175 | while(ti.markers[index].end != INVALID_TIME) // skip closed markers 176 | decrementCycle(&index, NB_GPU_MARKERS); 177 | 178 | GpuMarker& marker = ti.markers[index]; 179 | 180 | // Issue timer query 181 | if(marker.id_query_end == INVALID_QUERY) 182 | glGenQueries(1, &marker.id_query_end); 183 | glQueryCounter(marker.id_query_end, GL_TIMESTAMP); 184 | 185 | ti.nb_pushed_markers--; 186 | } 187 | 188 | //----------------------------------------------------------------------------- 189 | /// Update frame information and frame counter 190 | void Profiler::synchronizeFrame() 191 | { 192 | // Freeze/unfreeze as needed 193 | if(m_freeze_state == WAITING_FOR_FREEZE) 194 | m_freeze_state = FROZEN; 195 | else if(m_freeze_state == WAITING_FOR_UNFREEZE) 196 | m_freeze_state = UNFROZEN; 197 | 198 | // Don't do anything when frozen 199 | if(isFrozen()) 200 | return; 201 | 202 | // Next frame 203 | m_cur_frame++; 204 | 205 | // Copy: cur_read_id <- next_read_id 206 | // -> GPU: 207 | m_gpu_thread_info.cur_read_id = m_gpu_thread_info.next_read_id; 208 | // -> CPUs: 209 | for(size_t i=m_cpu_thread_infos.begin() ; 210 | i != m_cpu_thread_infos.getMaxSize() ; 211 | i = m_cpu_thread_infos.next(i)) 212 | { 213 | CpuThreadInfo &ti = m_cpu_thread_infos.get(i); 214 | ti.cur_read_id = ti.next_read_id; 215 | } 216 | 217 | // Frame time information 218 | uint64_t now = getTimeNs(); 219 | 220 | size_t index_oldest = 0; 221 | for(size_t i=0 ; i < NB_RECORDED_FRAMES ; i++) 222 | { 223 | if(m_frame_info[i].frame < m_frame_info[index_oldest].frame) 224 | index_oldest = i; 225 | if(m_frame_info[i].frame == m_cur_frame-1) 226 | m_frame_info[i].time_sync_end = now; 227 | } 228 | 229 | FrameInfo &new_frame = m_frame_info[index_oldest]; 230 | new_frame.time_sync_start = now; 231 | new_frame.time_sync_end = INVALID_TIME; 232 | new_frame.frame = m_cur_frame; 233 | } 234 | 235 | //----------------------------------------------------------------------------- 236 | /// Draw the markers 237 | void Profiler::draw() 238 | { 239 | if(m_visible) 240 | drawBackground(); 241 | 242 | int displayed_frame = m_cur_frame - int(NB_RECORDED_FRAMES-1); 243 | if(displayed_frame < 0) // don't draw anything during the first frames 244 | return; 245 | 246 | // Used when drawing information on the markers hovered by the mouse 247 | int read_indices[GPU_COUNT + NB_MAX_CPU_THREADS]; // indices of the first drawn markers, per thread 248 | int thread_index = 0; // read_indices[thread_index] 249 | 250 | // --- Find the FrameInfo (start and end times) for the frame we want to display --- 251 | FrameInfo* frame_info = NULL; 252 | for(int index_frame_info = 0 ; index_frame_info < int(NB_RECORDED_FRAMES) ; index_frame_info++) 253 | { 254 | if(m_frame_info[index_frame_info].frame == displayed_frame) 255 | { 256 | frame_info = &m_frame_info[index_frame_info]; 257 | break; 258 | } 259 | } 260 | if(!frame_info || frame_info->time_sync_end == INVALID_TIME) 261 | return; 262 | 263 | const uint64_t frame_delta_time = frame_info->time_sync_end - frame_info->time_sync_start; 264 | 265 | // --- Draw the end of the frame --- 266 | { 267 | Rect rect_end; 268 | rect_end.x = X_OFFSET + X_FACTOR*frame_delta_time; 269 | rect_end.y = m_back_rect.y; 270 | rect_end.w = 0.003f; 271 | rect_end.h = m_back_rect.h; 272 | 273 | if(m_visible) 274 | drawer2D.drawRect(rect_end, COLOR_BLACK); 275 | } 276 | 277 | // ---- Draw the GPU markers ---- 278 | { 279 | GpuThreadInfo& ti = m_gpu_thread_info; 280 | int read_id = ti.cur_read_id; 281 | 282 | read_indices[thread_index++] = read_id; 283 | 284 | // Get the times and draw the markers 285 | uint64_t first_start = INVALID_TIME; 286 | 287 | // Select only the markers that belong to this frame. 288 | // As GPU times are not synchronized with CPU times, we can't cleanly handle markers that started 289 | // in the previous frame and finish in this one, so we just display the GPU markers that belong 290 | // to the displayed frame. 291 | while(ti.markers[read_id].frame == displayed_frame) 292 | { 293 | GpuMarker& marker = ti.markers[read_id]; 294 | 295 | bool ok = true; 296 | if(marker.id_query_start == INVALID_QUERY || 297 | marker.id_query_end == INVALID_QUERY) 298 | ok = false; 299 | 300 | if(ok) 301 | { 302 | GLint start_ok = 0; 303 | GLint end_ok = 0; 304 | glGetQueryObjectiv(marker.id_query_start, GL_QUERY_RESULT_AVAILABLE, &start_ok); 305 | glGetQueryObjectiv(marker.id_query_end, GL_QUERY_RESULT_AVAILABLE, &end_ok); 306 | ok = (bool)(start_ok && end_ok); 307 | } 308 | 309 | if(ok) 310 | { 311 | uint64_t start, end; 312 | 313 | glGetQueryObjectui64v(marker.id_query_start, GL_QUERY_RESULT, &marker.start); 314 | glGetQueryObjectui64v(marker.id_query_end, GL_QUERY_RESULT, &marker.end); 315 | 316 | start = marker.start; 317 | end = marker.end; 318 | 319 | if(first_start == INVALID_TIME) 320 | first_start = start; 321 | 322 | start -= first_start; 323 | end -= first_start; 324 | 325 | Rect rect; 326 | rect.x = X_OFFSET + X_FACTOR * (float)(start); 327 | rect.y = Y_OFFSET; 328 | rect.w = X_FACTOR * (float)(end - start); 329 | rect.h = LINE_HEIGHT; 330 | 331 | // Reduce vertically the size of the markers according to their layer 332 | rect.y += Y_SCALE_OFFSET *marker.layer; 333 | rect.h -= (2.0f*Y_SCALE_OFFSET) *marker.layer; 334 | 335 | if(m_visible) 336 | drawer2D.drawRect(rect, marker.color); 337 | } 338 | 339 | incrementCycle(&read_id, NB_GPU_MARKERS); 340 | } 341 | 342 | ti.next_read_id = read_id; 343 | } 344 | 345 | // ---- Draw the CPU markers ---- 346 | // For each thread: 347 | for(size_t i=m_cpu_thread_infos.begin() ; 348 | i != m_cpu_thread_infos.getMaxSize() ; 349 | i = m_cpu_thread_infos.next(i)) 350 | { 351 | CpuThreadInfo &ti = m_cpu_thread_infos.get(i); 352 | 353 | // Jump back to the last marker that ends after the start of this frame. 354 | // Avoid going to a frame older than displayed_frame-1. 355 | // -> handle markers that overlap the previous and the displayed frame 356 | int read_id = ti.cur_read_id; 357 | while(true) 358 | { 359 | int candidate_id = read_id; 360 | decrementCycle(&candidate_id, NB_MARKERS_PER_CPU_THREAD); 361 | 362 | if(ti.markers[candidate_id].frame >= displayed_frame-1 && 363 | ti.markers[candidate_id].end > frame_info->time_sync_start) 364 | { 365 | read_id = candidate_id; 366 | continue; 367 | } 368 | 369 | break; 370 | } 371 | 372 | // In the worst case, we try to draw a marker that is out of this frame: 373 | // it just gets clamped and nothing is visible 374 | 375 | read_indices[thread_index++] = read_id; 376 | 377 | // Draw the markers 378 | while(ti.markers[read_id].frame >= displayed_frame-1 && // - for markers that started in the previous frame and finished 379 | // in this frame 380 | ti.markers[read_id].frame <= displayed_frame) // - for "regular" markers, that started in this frame 381 | { 382 | CpuMarker &marker = ti.markers[read_id]; 383 | 384 | uint64_t start, end; 385 | start = clamp(marker.start, frame_info->time_sync_start, frame_info->time_sync_end); 386 | end = clamp(marker.end, frame_info->time_sync_start, frame_info->time_sync_end); 387 | 388 | start -= frame_info->time_sync_start; 389 | end -= frame_info->time_sync_start; 390 | 391 | Rect rect; 392 | rect.x = X_OFFSET + X_FACTOR * (float)(start); 393 | rect.y = Y_OFFSET + (i+GPU_COUNT)*LINE_HEIGHT; 394 | rect.w = X_FACTOR * (float)(end - start); 395 | rect.h = LINE_HEIGHT; 396 | 397 | // Reduce vertically the size of the markers according to their layer 398 | rect.y += Y_SCALE_OFFSET*marker.layer; 399 | rect.h -= (2.0f*Y_SCALE_OFFSET)*marker.layer; 400 | 401 | if(m_visible) 402 | drawer2D.drawRect(rect, marker.color); 403 | incrementCycle(&read_id, NB_MARKERS_PER_CPU_THREAD); 404 | } 405 | 406 | ti.next_read_id = read_id; 407 | } 408 | 409 | if(m_visible) 410 | drawHoveredMarkersText(read_indices, frame_info); 411 | } 412 | 413 | //----------------------------------------------------------------------------- 414 | /// Handle freeze/unfreeze 415 | void Profiler::onLeftClick() 416 | { 417 | if(!m_visible) 418 | return; 419 | 420 | float fx = float(m_mouse_x) / float(m_win_w); 421 | float fy = float(m_win_h-1 - m_mouse_y) / float(m_win_h); 422 | 423 | if(m_back_rect.isPointInside(fx, fy)) 424 | { 425 | switch(m_freeze_state) 426 | { 427 | case UNFROZEN: 428 | m_freeze_state = WAITING_FOR_FREEZE; 429 | break; 430 | 431 | case FROZEN: 432 | m_freeze_state = WAITING_FOR_UNFREEZE; 433 | break; 434 | 435 | case WAITING_FOR_FREEZE: 436 | case WAITING_FOR_UNFREEZE: 437 | assert(false && "should not happen - synchronizeFrame() should be called between 2 calls to onLeftClick()"); 438 | break; 439 | } 440 | } 441 | } 442 | 443 | //----------------------------------------------------------------------------- 444 | // Get the CpuThreadInfo corresponding to the calling thread 445 | Profiler::CpuThreadInfo& Profiler::getOrAddCpuThreadInfo() 446 | { 447 | ThreadId thread_id = threadGetCurrentId(); 448 | 449 | for(size_t i = m_cpu_thread_infos.begin(); 450 | i != m_cpu_thread_infos.getMaxSize() ; 451 | i = m_cpu_thread_infos.next(i)) 452 | { 453 | if(m_cpu_thread_infos.isUsed(i) && 454 | m_cpu_thread_infos.get(i).thread_id == thread_id) 455 | { 456 | return m_cpu_thread_infos.get(i); 457 | } 458 | } 459 | 460 | mutexLock(&m_cpu_mutex); 461 | size_t i = m_cpu_thread_infos.add(); 462 | mutexUnlock(&m_cpu_mutex); 463 | 464 | CpuThreadInfo &ti = m_cpu_thread_infos.get(i); 465 | ti.init(thread_id); 466 | 467 | updateBackgroundRect(); 468 | 469 | return ti; 470 | } 471 | 472 | //----------------------------------------------------------------------------- 473 | void Profiler::drawBackground() 474 | { 475 | drawer2D.drawRect(m_back_rect, isFrozen() ? COLOR_FROZEN : COLOR_WHITE); 476 | } 477 | 478 | /// Draw text information for the markers that are hovered by the mouse pointer 479 | void Profiler::drawHoveredMarkersText(const int *read_indices, const FrameInfo* frame_info) 480 | { 481 | // Compute some values for drawing 482 | float fx = float(m_mouse_x) / float(m_win_w); 483 | float fy = float(m_win_h-1 - m_mouse_y) / float(m_win_h); 484 | 485 | size_t nb_max_markers = 0; 486 | const Marker *markers = NULL; 487 | int read_id = -1; 488 | uint64_t start_time = 0; 489 | size_t sizeof_marker = 0; 490 | 491 | #define GET_MARKER(__i) (const Marker*)(((const uint8_t*)markers) + (__i)*sizeof_marker) 492 | 493 | Rect rect; 494 | rect.x = X_OFFSET; 495 | rect.y = Y_OFFSET; 496 | rect.w = PROFILER_WIDTH; 497 | rect.h = LINE_HEIGHT; 498 | 499 | // --- Which list of markers is hovered by the mouse pointer? --- 500 | if(rect.isPointInside(fx, fy)) 501 | { 502 | // Hovering the GPU line 503 | nb_max_markers = NB_GPU_MARKERS; 504 | markers = &m_gpu_thread_info.markers[0]; 505 | read_id = read_indices[0]; 506 | start_time = m_gpu_thread_info.markers[read_id].start; 507 | sizeof_marker = sizeof(GpuMarker); 508 | } 509 | else 510 | { 511 | // CPUs 512 | for(size_t i=m_cpu_thread_infos.begin() ; 513 | i != m_cpu_thread_infos.getMaxSize() ; 514 | i = m_cpu_thread_infos.next(i)) 515 | { 516 | rect.y += LINE_HEIGHT; 517 | 518 | if(rect.isPointInside(fx, fy)) 519 | { 520 | // Hovering a CPU line 521 | nb_max_markers = NB_MARKERS_PER_CPU_THREAD; 522 | markers = &m_cpu_thread_infos[i].markers[0]; 523 | read_id = read_indices[i+GPU_COUNT]; 524 | start_time = frame_info->time_sync_start; 525 | sizeof_marker = sizeof(CpuMarker); 526 | break; 527 | } 528 | } 529 | } 530 | 531 | if(!markers) 532 | return; // mouse pointer doesn't hover any line 533 | 534 | // --- Choose the markers that are to be displayed --- 535 | const Marker *chosen_markers[NB_MAX_TEXT_LINES]; 536 | int nb_chosen_markers = 0; 537 | { 538 | int counter = 0; 539 | const Marker* m = GET_MARKER(read_id); 540 | while( m->frame >= frame_info->frame-1 && 541 | m->frame <= frame_info->frame && 542 | nb_chosen_markers < NB_MAX_TEXT_LINES) 543 | { 544 | // Get the relative start and end of the marker 545 | uint64_t start = m->start - start_time; 546 | uint64_t end = m->end - start_time; 547 | 548 | rect.x = X_OFFSET + X_FACTOR * (float)(start); 549 | rect.w = X_FACTOR * (float)(end - start); 550 | if(rect.isPointInside(fx, fy)) 551 | { 552 | chosen_markers[nb_chosen_markers++] = m; 553 | counter++; 554 | } 555 | 556 | // Next 557 | incrementCycle(&read_id, nb_max_markers); 558 | m = GET_MARKER(read_id); 559 | } 560 | } 561 | 562 | // --- Draw information on the chosen markers --- 563 | { 564 | char str[256]; 565 | float y_text = m_back_rect.y + m_back_rect.h + Y_TEXT_MARGIN; 566 | for(int i=nb_chosen_markers-1 ; i >= 0 ; i--) 567 | { 568 | const Marker* m = chosen_markers[i]; 569 | 570 | uint64_t marker_time_us = (m->end - m->start) / (uint64_t)(1000); 571 | double marker_time_ms = double(marker_time_us) / 1000.0; 572 | 573 | sprintf(str, "[%2.1lfms] ", marker_time_ms); 574 | size_t len=strlen(str); 575 | for(size_t layer=0 ; layer < m->layer ; layer++) 576 | str[len++] = '+'; 577 | str[len] = '\0'; 578 | strcat(str, m->name); 579 | 580 | drawer2D.drawString(str, 0.01f, y_text, m->color); 581 | y_text += Y_TEXT_MARGIN; 582 | } 583 | } 584 | #undef GET_MARKER 585 | } 586 | 587 | void Profiler::updateBackgroundRect() 588 | { 589 | size_t nb_threads = m_cpu_thread_infos.getSize(); 590 | nb_threads += GPU_COUNT; 591 | 592 | m_back_rect.x = MARGIN_X; 593 | m_back_rect.y = MARGIN_Y; 594 | m_back_rect.w = 1.0f-2.0f*MARGIN_X; 595 | m_back_rect.h = ((float)(nb_threads) + 2.0f)*LINE_HEIGHT; 596 | } 597 | 598 | #endif // defined(ENABLE_PROFILER) 599 | -------------------------------------------------------------------------------- /profiler.h: -------------------------------------------------------------------------------- 1 | // profiler.h 2 | 3 | #ifndef PROFILER_H 4 | #define PROFILER_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "hole_array.h" 11 | #include "thread.h" 12 | #include "utils.h" 13 | 14 | #define ENABLE_PROFILER // comment this to disable the profiler 15 | 16 | #define INVALID_TIME ((uint64_t)(-1)) 17 | #define INVALID_QUERY ((GLuint)0) 18 | 19 | #ifndef ENABLE_PROFILER 20 | #define PROFILER_INIT(win_w, win_h, mouse_x, mouse_y) 21 | #define PROFILER_SHUT() 22 | 23 | #define PROFILER_ON_MOUSE_POS(mouse_x, mouse_y) 24 | #define PROFILER_ON_RESIZE(win_w, win_h) 25 | #define PROFILER_ON_LEFT_CLICK() 26 | 27 | #define PROFILER_PUSH_CPU_MARKER(name, color) 28 | #define PROFILER_POP_CPU_MARKER() 29 | #define PROFILER_PUSH_GPU_MARKER(name, color) 30 | #define PROFILER_POP_GPU_MARKER() 31 | 32 | #define PROFILER_DRAW() 33 | #define PROFILER_SYNC_FRAME() 34 | 35 | #else 36 | class Profiler; 37 | extern Profiler profiler; 38 | 39 | #define PROFILER_INIT(win_w, win_h, mouse_x, mouse_y) profiler.init(win_w, win_h, mouse_x, mouse_y) 40 | #define PROFILER_SHUT() profiler.shut() 41 | 42 | #define PROFILER_ON_MOUSE_POS(mouse_x, mouse_y) profiler.onMousePos(mouse_x, mouse_y) 43 | #define PROFILER_ON_RESIZE(win_w, win_h) profiler.onResize(win_w, win_h) 44 | #define PROFILER_ON_LEFT_CLICK() profiler.onLeftClick() 45 | 46 | #define PROFILER_PUSH_CPU_MARKER(name, color) profiler.pushCpuMarker(name, color) 47 | #define PROFILER_POP_CPU_MARKER() profiler.popCpuMarker() 48 | #define PROFILER_PUSH_GPU_MARKER(name, color) profiler.pushGpuMarker(name, color) 49 | #define PROFILER_POP_GPU_MARKER() profiler.popGpuMarker() 50 | 51 | #define PROFILER_DRAW() profiler.draw() 52 | #define PROFILER_SYNC_FRAME() profiler.synchronizeFrame() 53 | 54 | class Profiler 55 | { 56 | private: 57 | static const size_t NB_RECORDED_FRAMES = 3; 58 | 59 | static const size_t NB_MAX_CPU_MARKERS_PER_FRAME = 100; 60 | static const size_t NB_MARKERS_PER_CPU_THREAD = NB_RECORDED_FRAMES * NB_MAX_CPU_MARKERS_PER_FRAME; 61 | 62 | static const size_t NB_MAX_GPU_MARKERS_PER_FRAME = 10; 63 | static const size_t NB_GPU_MARKERS = NB_RECORDED_FRAMES * NB_MAX_GPU_MARKERS_PER_FRAME; 64 | 65 | static const size_t NB_MAX_CPU_THREADS = 32; 66 | //static const size_t NB_FRAMES_BEFORE_KICK_CPU_THREAD = 4; // TODO: remove threads that are not used anymore 67 | 68 | static const size_t MARKER_NAME_MAX_LENGTH = 32; 69 | 70 | struct Marker 71 | { 72 | uint64_t start; // Times of start and end, in nanoseconds, 73 | uint64_t end; // relatively to the time of last synchronization 74 | 75 | size_t layer; // Number of markers pushed at the time this one is pushed 76 | int frame; // Frame at which the marker was started 77 | 78 | char name[MARKER_NAME_MAX_LENGTH]; 79 | Color color; 80 | 81 | Marker() : start(INVALID_TIME), end(INVALID_TIME), frame(-1) {} // unused by default 82 | }; 83 | 84 | // --- Device-specific markers --- 85 | typedef Marker CpuMarker; 86 | 87 | struct GpuMarker : public Marker 88 | { 89 | GLuint id_query_start; 90 | GLuint id_query_end; 91 | 92 | GpuMarker() : Marker(), id_query_start(INVALID_QUERY), id_query_end(INVALID_QUERY) {} 93 | }; 94 | 95 | // Markers for a CPU thread 96 | struct CpuThreadInfo 97 | { 98 | ThreadId thread_id; 99 | CpuMarker markers[NB_MARKERS_PER_CPU_THREAD]; 100 | 101 | int cur_read_id; // Index of the last pushed marker in the previous frame 102 | int cur_write_id; // Index of the next cell we will write to 103 | 104 | int next_read_id; // draw() writes next_read_id, synchronizeFrame() copies cur_read_id <- next_read_id 105 | // This deferring is needed for handling freeze/unfreeze. 106 | 107 | size_t nb_pushed_markers; 108 | 109 | void init(ThreadId id) {cur_read_id=cur_write_id=next_read_id=0; thread_id = id; nb_pushed_markers=0;} 110 | }; 111 | 112 | // Markers for the GPU 113 | struct GpuThreadInfo 114 | { 115 | GpuMarker markers[NB_GPU_MARKERS]; 116 | 117 | int cur_read_id; // Index of the last pushed marker in the previous frame 118 | int cur_write_id; // Index of the next cell we will write to 119 | 120 | int next_read_id; // draw() writes next_read_id, synchronizeFrame() copies cur_read_id <- next_read_id. 121 | // This deferring is needed for handling freeze/unfreeze. 122 | 123 | size_t nb_pushed_markers; 124 | 125 | void init() {cur_read_id=cur_write_id=next_read_id=0; nb_pushed_markers=0;} 126 | }; 127 | 128 | typedef HoleArray CpuThreadInfoList; 129 | 130 | CpuThreadInfoList m_cpu_thread_infos; 131 | Mutex m_cpu_mutex; 132 | 133 | GpuThreadInfo m_gpu_thread_info; 134 | 135 | volatile int m_cur_frame; // Global frame counter 136 | 137 | // Frame time information 138 | struct FrameInfo 139 | { 140 | int frame; 141 | uint64_t time_sync_start; 142 | uint64_t time_sync_end; 143 | }; 144 | FrameInfo m_frame_info[NB_RECORDED_FRAMES]; 145 | 146 | // Handling freeze/unfreeze by clicking on the displayed profiler 147 | enum FreezeState 148 | { 149 | UNFROZEN, 150 | WAITING_FOR_FREEZE, 151 | FROZEN, 152 | WAITING_FOR_UNFREEZE, 153 | }; 154 | 155 | FreezeState m_freeze_state; 156 | 157 | bool m_visible; 158 | 159 | // Handling interaction with the mouse 160 | int m_mouse_x, m_mouse_y; 161 | int m_win_w, m_win_h; 162 | 163 | Rect m_back_rect; // Background 164 | 165 | public: 166 | Profiler() {} 167 | virtual ~Profiler() {} 168 | 169 | void init(int win_w, int win_h, int mouse_x, int mouse_y); 170 | void shut(); 171 | 172 | void pushCpuMarker(const char* name, const Color& color); 173 | void popCpuMarker(); 174 | 175 | void pushGpuMarker(const char* name, const Color& color); 176 | void popGpuMarker(); 177 | 178 | void synchronizeFrame(); 179 | 180 | void draw(); 181 | 182 | void setVisible(bool visible) {m_visible=visible;} 183 | bool isVisible() const {return m_visible;} 184 | 185 | bool isFrozen() const {return m_freeze_state == FROZEN || m_freeze_state == WAITING_FOR_UNFREEZE;} 186 | 187 | // Input handling 188 | void onMousePos(int x, int y) {m_mouse_x=x; m_mouse_y=y;} 189 | void onLeftClick(); 190 | void onResize(int w, int h) {m_win_w=w; m_win_h=h;} 191 | 192 | protected: 193 | // Get the CpuThreadInfo corresponding to the calling thread 194 | CpuThreadInfo& getOrAddCpuThreadInfo(); 195 | 196 | void drawBackground(); 197 | void drawHoveredMarkersText(const int *read_indices, const FrameInfo* frame_info); 198 | void updateBackgroundRect(); 199 | }; 200 | 201 | #endif // defined(ENABLE_PROFILER) 202 | 203 | #endif // PROFILER_H 204 | -------------------------------------------------------------------------------- /scene.cpp: -------------------------------------------------------------------------------- 1 | // scene.cpp 2 | 3 | #include 4 | #include "utils.h" 5 | #include "profiler.h" 6 | 7 | #include "scene.h" 8 | #include "math_utils.h" 9 | 10 | //#define _DEBUG_PRINTF 11 | 12 | #ifdef _DEBUG_PRINTF 13 | #define DbgPrintf printf 14 | #else 15 | #define DbgPrintf(...) 16 | #endif 17 | 18 | bool Scene::init() 19 | { 20 | m_multithread = false; 21 | m_shut = false; 22 | m_elapsed_time = 0.0; 23 | m_update_time = 0.0; 24 | 25 | m_colors[0] = COLOR_DARK_RED; 26 | m_colors[1] = COLOR_DARK_GREEN; 27 | m_colors[2] = COLOR_DARK_BLUE; 28 | m_colors[3] = COLOR_GRAY; 29 | 30 | bool ok = true; 31 | 32 | // Launch the threads 33 | for(int i=0 ; i < NB_THREADS ; i++) 34 | { 35 | m_thread_data[i].p_scene = this; 36 | ok = ok && m_thread_data[i].grid.init((float)i, m_colors[i]); 37 | if(!ok) 38 | return false; 39 | 40 | eventCreate(&m_thread_data[i].update_event); 41 | eventCreate(&m_thread_data[i].main_event); 42 | m_thread_data[i].index = i; 43 | m_thread_data[i].thread_handle = threadCreate(&threadUpdateWrapper, &m_thread_data[i]); 44 | } 45 | 46 | return ok; 47 | } 48 | 49 | void Scene::shut() 50 | { 51 | DbgPrintf("[main] shut\n"); 52 | m_shut = true; 53 | for(int i=0 ; i < NB_THREADS ; i++) 54 | { 55 | DbgPrintf("[main] trigger update %d\n", i); 56 | eventTrigger(&m_thread_data[i].update_event); 57 | 58 | DbgPrintf("[main] join %d\n", i); 59 | 60 | threadJoin(m_thread_data[i].thread_handle); 61 | 62 | DbgPrintf("[main] destroy update event %d\n", i); 63 | eventDestroy(&m_thread_data[i].update_event); 64 | 65 | DbgPrintf("[main] destroy main event %d\n", i); 66 | eventDestroy(&m_thread_data[i].main_event); 67 | 68 | m_thread_data[i].grid.shut(); 69 | } 70 | } 71 | 72 | void Scene::update(double elapsed, double t) 73 | { 74 | if(m_multithread) 75 | { 76 | // Trigger update on multiple threads and wait for completion 77 | PROFILER_PUSH_CPU_MARKER("Multithread update", COLOR_CYAN); 78 | 79 | DbgPrintf("--- [main] begin update ---\n"); 80 | m_elapsed_time = elapsed; 81 | m_update_time = t; 82 | for(int i=0 ; i < NB_THREADS ; i++) 83 | { 84 | DbgPrintf("[main] trigger update event %d\n", i); 85 | eventTrigger(&m_thread_data[i].update_event); 86 | } 87 | 88 | PROFILER_POP_CPU_MARKER(); 89 | 90 | PROFILER_PUSH_CPU_MARKER("Wait for update", COLOR_YELLOW); 91 | DbgPrintf("[main] wait and reset all main events...\n"); 92 | for(int i=0 ; i < NB_THREADS ; i++) 93 | { 94 | DbgPrintf("[main] wait for main event %d\n", i); 95 | eventWait(&m_thread_data[i].main_event); 96 | 97 | DbgPrintf("[main] reset main event %d\n", i); 98 | eventReset(&m_thread_data[i].main_event); 99 | } 100 | 101 | DbgPrintf("--- [main] end update ---\n"); 102 | PROFILER_POP_CPU_MARKER(); 103 | } 104 | else 105 | { 106 | // Sequential update 107 | for(int i=0 ; i < NB_THREADS ; i++) 108 | { 109 | char str_marker[32]; 110 | sprintf(str_marker, "Multithread update %d", i); 111 | PROFILER_PUSH_CPU_MARKER(str_marker, m_colors[i]); 112 | m_thread_data[i].grid.update(elapsed, t); 113 | PROFILER_POP_CPU_MARKER(); 114 | } 115 | } 116 | } 117 | 118 | void Scene::draw(int win_w, int win_h) 119 | { 120 | // Select and setup the projection matrix 121 | m_camera.setPerspective(65.0f, (float)win_w/(float)win_h, 1.0f, 100.0f); 122 | 123 | // Select and setup the modelview matrix 124 | float eye[3] = { 0.0f, 5.0f, 4.0f }; 125 | float view[3] = { 0.0f, 0.0f, 0.0f }; 126 | float up[3] = { 0.0f, 1.0f, 0.0f }; 127 | matrixLookAt(m_camera.view_matrix, eye, view, up); 128 | 129 | float proj_view_matrix[16]; 130 | matrixMult(proj_view_matrix, m_camera.proj_matrix, m_camera.view_matrix); 131 | 132 | const float start_x = -6.0f; 133 | const float start_y = -6.0f; 134 | const float step_x = 12.0f; 135 | const float step_y = -12.0f; 136 | 137 | float mvp_matrix[16]; 138 | float trans_matrix[16]; 139 | float trans_vec[3]; 140 | 141 | for(int x=0 ; x < NB_GRIDS_X ; x++) 142 | { 143 | for(int y=0 ; y < NB_GRIDS_Y ; y++) 144 | { 145 | Color debug_color = COLOR_DARK_RED; 146 | if(x == 0 && y == 1) 147 | debug_color = COLOR_DARK_GREEN; 148 | else if(x == 1 && y == 0) 149 | debug_color = COLOR_DARK_BLUE; 150 | else if(x == 1 && y == 1) 151 | debug_color = COLOR_GRAY; 152 | 153 | trans_vec[0] = start_x + float(x)*step_x; 154 | trans_vec[1] = 0; 155 | trans_vec[2] = start_y + float(y)*step_y; 156 | matrixTranslate(trans_matrix, trans_vec); 157 | matrixMult(mvp_matrix, proj_view_matrix, trans_matrix); 158 | 159 | Grid& grid = m_thread_data[x + y*NB_GRIDS_X].grid; 160 | char str_marker[32]; 161 | sprintf(str_marker, "[GPU] draw grid %d,%d", x, y); 162 | 163 | Color color = grid.getColor(); 164 | 165 | PROFILER_PUSH_GPU_MARKER(str_marker, color); 166 | grid.draw(mvp_matrix); 167 | PROFILER_POP_GPU_MARKER(); 168 | } 169 | 170 | } 171 | } 172 | 173 | void Scene::threadUpdate(ThreadData *data) 174 | { 175 | while(!m_shut) 176 | { 177 | DbgPrintf("(%d) wait update event %d\n", data->index, data->index); 178 | eventWait(&data->update_event); 179 | 180 | DbgPrintf("(%d) reset update event %d\n", data->index, data->index); 181 | eventReset(&data->update_event); 182 | 183 | PROFILER_PUSH_CPU_MARKER("Thread update", data->grid.getColor()); 184 | 185 | DbgPrintf("(%d) update\n", data->index); 186 | data->grid.update(m_elapsed_time, m_update_time); 187 | 188 | PROFILER_POP_CPU_MARKER(); 189 | 190 | DbgPrintf("(%d) trigger main event %d\n", data->index, data->index); 191 | eventTrigger(&data->main_event); 192 | } 193 | DbgPrintf("(%d): done\n", data->index); 194 | } 195 | 196 | void* Scene::threadUpdateWrapper(void* user_data) 197 | { 198 | ThreadData* data = (ThreadData*)user_data; 199 | data->p_scene->threadUpdate(data); 200 | return NULL; 201 | } 202 | -------------------------------------------------------------------------------- /scene.h: -------------------------------------------------------------------------------- 1 | // scene.h 2 | 3 | #ifndef SCENE_H 4 | #define SCENE_H 5 | 6 | #include "camera.h" 7 | #include "grid.h" 8 | #include "thread.h" 9 | #include "utils.h" 10 | 11 | class Scene 12 | { 13 | private: 14 | static const int NB_GRIDS_X = 2; 15 | static const int NB_GRIDS_Y = 2; 16 | static const int NB_THREADS = NB_GRIDS_X * NB_GRIDS_Y; 17 | 18 | Camera m_camera; 19 | 20 | // Multithread update 21 | struct ThreadData 22 | { 23 | Scene* p_scene; 24 | Grid grid; 25 | ThreadHandle thread_handle; 26 | Event update_event; 27 | Event main_event; 28 | int index; 29 | }; 30 | 31 | Color m_colors[NB_THREADS]; 32 | 33 | bool m_multithread; 34 | ThreadData m_thread_data[NB_THREADS]; 35 | volatile bool m_shut; 36 | volatile double m_elapsed_time; 37 | volatile double m_update_time; 38 | 39 | public: 40 | bool init(); 41 | void shut(); 42 | void update(double elapsed, double t); 43 | void draw(int win_w, int win_h); 44 | 45 | void setMultithreaded(bool multithread) {m_multithread = multithread;} 46 | bool isMultithreaded() const {return m_multithread;} 47 | 48 | private: 49 | void threadUpdate(ThreadData* data); 50 | 51 | static void* threadUpdateWrapper(void* user_data); 52 | }; 53 | 54 | #endif // SCENE_H 55 | -------------------------------------------------------------------------------- /tgaloader.cpp: -------------------------------------------------------------------------------- 1 | // tgaloader.cpp 2 | // Version 2.1 3 | 4 | #include "tgaloader.h" 5 | 6 | #ifdef TGA_USE_LOG_H 7 | #include "../log/Log.h" 8 | #endif 9 | 10 | using namespace std; 11 | 12 | TGALoader::TGALoader() 13 | : data(NULL), loaded(false), width(0), height(0), bpp(0) 14 | { 15 | } 16 | 17 | TGALoader::TGALoader(const TGALoader& ref) 18 | : loaded(ref.loaded), width(ref.width), height(ref.height), bpp(ref.bpp) 19 | { 20 | if(loaded) 21 | { 22 | data = new unsigned char[width*height*bpp]; 23 | for(unsigned int i=0; ifree(); 40 | } 41 | 42 | TGAErrorCode TGALoader::loadFile(const char* path) 43 | { 44 | unsigned char header[18]; 45 | ifstream file((const char*)path, ios::in | ios::binary); 46 | unsigned int i=0, j=0; 47 | bool origin_non_bottoleft=false; // Indicates if the origin of the image is 48 | // bottom left (default) or top left. 49 | 50 | #ifdef TGA_USE_LOG_H 51 | logInfo("loading \"", path, "\"..."); 52 | #endif 53 | 54 | #ifdef TGA_USE_LOG_IOSTREAM 55 | cout << "loading \"" << path << "\"..." << endl; 56 | #endif 57 | 58 | if (!file) 59 | { 60 | #ifdef TGA_USE_LOG_H 61 | logFailed(TGA_FILE_NOT_FOUND); 62 | #endif 63 | #ifdef TGA_USE_LOG_IOSTREAM 64 | cerr << "TGA_FILE_NOT_FOUND" << endl; 65 | #endif 66 | return TGA_FILE_NOT_FOUND; 67 | } 68 | 69 | file.read((char*)header, 18); 70 | 71 | this->free(); 72 | 73 | width = ((unsigned int)header[13] << 8) + (unsigned int)header[12]; 74 | height = ((unsigned int)header[15] << 8) + (unsigned int)header[14]; 75 | bpp = ((unsigned int)header[16])>>3; // (x>>3 is the same as x/8) 76 | 77 | // Bit 5 from byte 17 78 | origin_non_bottoleft = ((header[17] & 0x20) == 0x20 ? true : false); 79 | 80 | if ((data = (unsigned char*)malloc(height*width*bpp)) == NULL) 81 | { 82 | loaded = false; 83 | #ifdef TGA_USE_LOG_H 84 | logFailed(TGA_NOT_ENOUGH_MEMORY); 85 | #endif 86 | #ifdef TGA_USE_LOG_IOSTREAM 87 | cerr << "TGA_NOT_ENOUGH_MEMORY" << endl; 88 | #endif 89 | return TGA_NOT_ENOUGH_MEMORY; 90 | } 91 | 92 | // Put the file pointer after the header (18 first bytes) and after the 93 | // identification field, which size is indicated in header[0]. 94 | file.seekg(18+(long)header[0], ios::beg); 95 | 96 | // header[2] determines the type of image: 97 | // 1 -> uncompressed, uses a palette 98 | // 2 -> uncompressed, true colors 99 | // 9 -> RLE compressed, uses a palette 100 | // 10 -> RLE compressed, doesn't use a palette 101 | // Other image types are not supported. 102 | 103 | // TYPE 2 - uncompressed, true colors, 24 or 32 bits 104 | if (header[2] == 2 && (bpp == 3 || bpp == 4)) 105 | { 106 | for(i=0 ; ifree(); 212 | 213 | width = ((unsigned int)data[13] << 8) + (unsigned int)data[12]; 214 | height = ((unsigned int)data[15] << 8) + (unsigned int)data[14]; 215 | bpp = ((unsigned int)data[16])>>3; // (x>>3 is the same as x/8) 216 | 217 | // Bit 5 from byte 17 218 | origin_non_bottoleft = ((data[17] & 0x20) == 0x20 ? true : false); 219 | 220 | if ((this->data = (unsigned char*)malloc(height*width*bpp)) == NULL) 221 | { 222 | loaded = false; 223 | #ifdef TGA_USE_LOG_H 224 | logFailed(TGA_NOT_ENOUGH_MEMORY); 225 | #endif 226 | #ifdef TGA_USE_LOG_IOSTREAM 227 | cerr << TGA_NOT_ENOUGH_MEMORY << endl; 228 | #endif 229 | return TGA_NOT_ENOUGH_MEMORY; 230 | } 231 | 232 | // Put the file pointer after the header (18 first bytes) and after the 233 | // identification field, which size is indicated in header[0]. 234 | pos_data = 18+(unsigned int)data[0]; 235 | 236 | // data[2] determines the type of image: 237 | // 1 -> uncompressed, uses a palette 238 | // 2 -> uncompressed, true colors 239 | // 9 -> RLE compressed, uses a palette 240 | // 10 -> RLE compressed, doesn't use a palette 241 | // Other image types are not supported. 242 | 243 | // TYPE 2 - uncompressed, true colors, 24 or 32 bits 244 | if (data[2] == 2 && (bpp == 3 || bpp == 4)) 245 | { 246 | for(i=0 ; idata[i+2] = data[pos_data]; pos_data++; // R 249 | this->data[i+1] =data[pos_data]; pos_data++; // G 250 | this->data[i] = data[pos_data]; pos_data++; // B 251 | if(bpp == 4) { this->data[i+3] = data[pos_data]; pos_data++; } // A 252 | } 253 | } 254 | 255 | // TYPE 10 - RLE, true colors, 24 or 32 bits 256 | else if (data[2] == 10 && (bpp == 3 || bpp == 4)) 257 | { 258 | unsigned char packet_header, red, green, blue, alpha=0; 259 | unsigned int nb_pixels; // Number of pixels represented by one packet 260 | for(i=0 ; idata[i+j] = red; 276 | this->data[i+j+1] = green; 277 | this->data[i+j+2] = blue; 278 | if(bpp == 4) this->data[i+j+3] = alpha; 279 | } 280 | } 281 | // Raw packet: 282 | else 283 | { 284 | for(j=0 ; jdata[i+j+2] = data[pos_data]; pos_data++; // B 287 | this->data[i+j+1] = data[pos_data]; pos_data++; // G 288 | this->data[i+j] = data[pos_data]; pos_data++; // R 289 | if(bpp == 4) { this->data[i+j+3] = data[pos_data]; pos_data++; } // A 290 | } 291 | } 292 | } 293 | } 294 | 295 | // For images of an unsupported type, return an error and load nothing 296 | else 297 | { 298 | ::free(this->data); 299 | this->data = NULL; 300 | loaded = false; 301 | #ifdef TGA_USE_LOG_H 302 | logFailed(TGA_UNSUPPORTED_TYPE); 303 | #endif 304 | #ifdef TGA_USE_LOG_IOSTREAM 305 | cerr << TGA_UNSUPPORTED_TYPE << endl; 306 | #endif 307 | return TGA_UNSUPPORTED_TYPE; 308 | } 309 | 310 | // Flip vertically for images where the origin is in the top left 311 | if (origin_non_bottoleft) 312 | { 313 | unsigned char temp; 314 | for(i=0 ; idata[i*width*bpp + j] = data[(height-i-1)*width*bpp + j]; 320 | this->data[(height-i-1)*width*bpp + j] = temp; 321 | } 322 | } 323 | } 324 | 325 | loaded = true; 326 | 327 | #ifdef TGA_USE_LOG_H 328 | logSuccess(TGA_OK); 329 | #endif 330 | #ifdef TGA_USE_LOG_IOSTREAM 331 | cout << TGA_OK << endl; 332 | #endif 333 | return TGA_OK; 334 | } 335 | 336 | TGALoader& TGALoader::operator=(const TGALoader& ref) 337 | { 338 | loaded = ref.loaded; 339 | width = ref.width; 340 | height = ref.height; 341 | bpp = ref.bpp; 342 | 343 | if(loaded) 344 | { 345 | data = new unsigned char[width*height*bpp]; 346 | for(unsigned int i=0; ifree(); 458 | } 459 | return ret; 460 | } 461 | 462 | TGAErrorCode TGALoader::loadOpenGLTextureWithID( 463 | const char* path, 464 | GLuint ID, 465 | TGAFiltering filtering //=TGA_NO_FILTER 466 | ) 467 | { 468 | TGAErrorCode ret = loadFile(path); 469 | if(ret == TGA_OK) 470 | { 471 | sendToOpenGLWithID(ID, filtering); 472 | this->free(); 473 | } 474 | return ret; 475 | } 476 | 477 | TGAErrorCode TGALoader::loadOpenGLTextureFromData( 478 | unsigned char* data, 479 | GLuint* pID, //=NULL 480 | TGAFiltering filtering //=TGA_NO_FILTER 481 | ) 482 | { 483 | TGAErrorCode ret = loadFromData(data); 484 | if(ret == TGA_OK) 485 | { 486 | if(pID != NULL) 487 | (*pID) = sendToOpenGL(filtering); 488 | else 489 | sendToOpenGL(filtering); 490 | this->free(); 491 | } 492 | return ret; 493 | } 494 | 495 | TGAErrorCode TGALoader::loadOpenGLTextureFromDataWithID( 496 | unsigned char* data, 497 | GLuint ID, 498 | TGAFiltering filtering //=TGA_NO_FILTER 499 | ) 500 | { 501 | TGAErrorCode ret = loadFromData(data); 502 | if(ret == TGA_OK) 503 | { 504 | sendToOpenGLWithID(ID, filtering); 505 | this->free(); 506 | } 507 | return ret; 508 | } 509 | 510 | #endif // defined TGA_OPENGL_SUPPORT 511 | 512 | void TGALoader::free() 513 | { 514 | if (loaded) 515 | { 516 | ::free(data); 517 | data = NULL; 518 | loaded = false; 519 | height = 0; 520 | width = 0; 521 | bpp = 0; 522 | } 523 | } 524 | -------------------------------------------------------------------------------- /tgaloader.h: -------------------------------------------------------------------------------- 1 | // tgaloader.h 2 | // Version 2.1 3 | 4 | #ifndef TGA_LOADER_H 5 | #define TGA_LOADER_H 6 | 7 | // Configuration: 8 | #define TGA_LOADER_INCLUDE_GLEW // Define this if the project uses GLEW, 9 | // for including GL/glew.h before GL/gl.h 10 | //#define TGA_OPENGL_SUPPORT 11 | //#define TGA_USE_LOG_H // Define this to use log/Log.h for logging (logError(), etc) 12 | #define TGA_USE_LOG_IOSTREAM // Define this to use std::cout/std::cerr for logging 13 | 14 | // --------------------------------------------------------------------- 15 | #ifdef TGA_LOADER_INCLUDE_GLEW 16 | #include 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #ifdef TGA_OPENGL_SUPPORT 25 | #ifdef WIN32 26 | #include 27 | #endif 28 | #include 29 | #include 30 | #endif // defined TGA_OPENGL_SUPPORT 31 | 32 | enum TGAErrorCode 33 | { 34 | TGA_OK, 35 | TGA_FILE_NOT_FOUND, 36 | TGA_UNSUPPORTED_TYPE, 37 | TGA_NOT_ENOUGH_MEMORY 38 | }; 39 | 40 | #ifdef TGA_OPENGL_SUPPORT 41 | enum TGAFiltering 42 | { 43 | TGA_NO_FILTER, 44 | TGA_LINEAR, 45 | TGA_BILINEAR, 46 | TGA_TRILINEAR 47 | #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT 48 | ,TGA_ANISOTROPIC 49 | #endif 50 | }; 51 | #endif 52 | 53 | class TGALoader 54 | { 55 | private: 56 | unsigned char* data; 57 | bool loaded; 58 | unsigned int width, height; 59 | unsigned int bpp; // Bytes Per Pixel : 0, 3 or 4 60 | 61 | public: 62 | TGALoader(); 63 | TGALoader(const TGALoader& ref); 64 | TGALoader(const char* path, TGAErrorCode* error=NULL); 65 | virtual ~TGALoader(); 66 | TGAErrorCode loadFile(const char* path); 67 | TGAErrorCode loadFromData(unsigned char *data); 68 | 69 | TGALoader& operator=(const TGALoader& ref); 70 | 71 | // Convert an error to an explicit string 72 | static std::string errorToString(TGAErrorCode error); 73 | 74 | #ifdef TGA_OPENGL_SUPPORT 75 | GLuint sendToOpenGL(TGAFiltering filtering=TGA_NO_FILTER); 76 | 77 | void sendToOpenGLWithID(GLuint ID, TGAFiltering filtering=TGA_NO_FILTER); 78 | 79 | TGAErrorCode loadOpenGLTexture(const char* path, GLuint* pID=NULL, 80 | TGAFiltering filtering=TGA_NO_FILTER); 81 | 82 | TGAErrorCode loadOpenGLTextureWithID(const char* path, GLuint ID, 83 | TGAFiltering filtering=TGA_NO_FILTER); 84 | 85 | TGAErrorCode loadOpenGLTextureFromData(unsigned char *data, GLuint* pID=NULL, 86 | TGAFiltering filtering=TGA_NO_FILTER); 87 | 88 | TGAErrorCode loadOpenGLTextureFromDataWithID(unsigned char *data, GLuint ID, 89 | TGAFiltering filtering=TGA_NO_FILTER); 90 | 91 | #endif 92 | 93 | void free(); 94 | 95 | inline unsigned char* getData() {return data;} 96 | inline bool isLoaded() {return loaded;} 97 | inline unsigned int getHeight() {return height;} 98 | inline unsigned int getWidth() {return width;} 99 | inline unsigned int getBpp() {return bpp;} 100 | }; 101 | 102 | // Overloading << for printing error codes using iostream 103 | inline std::ostream& operator<<(std::ostream& os, const TGAErrorCode& error) 104 | { 105 | return os << TGALoader::errorToString(error); 106 | } 107 | 108 | #endif // !defined TGA_LOADER_H 109 | -------------------------------------------------------------------------------- /thread.cpp: -------------------------------------------------------------------------------- 1 | // thread.cpp 2 | 3 | #include "thread.h" 4 | #include 5 | 6 | // ------------------------- Windows API implementation----------------------- 7 | // http://www.flipcode.com/archives/Simple_Win32_Thread_Class.shtml 8 | #ifdef WIN32 9 | 10 | // --- Thread --- 11 | ThreadHandle threadCreate(ThreadProc proc, void* arg) 12 | { 13 | return (ThreadHandle)CreateThread(0, 0, (LPTHREAD_START_ROUTINE)proc, arg, 0, 0); 14 | } 15 | 16 | ThreadId threadGetCurrentId() 17 | { 18 | return (ThreadId)GetCurrentThreadId(); 19 | } 20 | 21 | void threadJoin(ThreadHandle thread_handle) 22 | { 23 | DWORD dwWaitResult = WaitForSingleObject(thread_handle, INFINITE); 24 | assert(dwWaitResult == WAIT_OBJECT_0); 25 | } 26 | 27 | // --- Mutex --- 28 | void mutexCreate(Mutex* mutex) 29 | { 30 | InitializeCriticalSection((LPCRITICAL_SECTION)mutex); 31 | } 32 | 33 | void mutexDestroy(Mutex* mutex) 34 | { 35 | DeleteCriticalSection((LPCRITICAL_SECTION)mutex); 36 | } 37 | 38 | void mutexLock(Mutex* mutex) 39 | { 40 | EnterCriticalSection((LPCRITICAL_SECTION)mutex); 41 | } 42 | 43 | void mutexUnlock(Mutex* mutex) 44 | { 45 | LeaveCriticalSection((LPCRITICAL_SECTION)mutex); 46 | } 47 | 48 | // --- Event --- 49 | void eventCreate(Event* event) 50 | { 51 | *event = CreateEvent( 52 | NULL, // security attributes 53 | TRUE, // manual reset event 54 | FALSE, // initial state is non-signaled 55 | NULL); // no name 56 | } 57 | 58 | void eventDestroy(Event* event) 59 | { 60 | CloseHandle(*event); 61 | } 62 | 63 | void eventTrigger(Event* event) 64 | { 65 | SetEvent(*event); 66 | } 67 | 68 | void eventReset(Event *event) 69 | { 70 | ResetEvent(*event); 71 | } 72 | 73 | void eventWait(Event* event) 74 | { 75 | DWORD dwWaitResult = WaitForSingleObject(*event, INFINITE); 76 | assert(dwWaitResult == WAIT_OBJECT_0); 77 | } 78 | // ---------------- pthread implementation: MacOS X, Linux, BSD... -------- 79 | #else 80 | 81 | // --- Thread --- 82 | ThreadHandle threadCreate(ThreadProc proc, void* arg) 83 | { 84 | ThreadHandle thread_handle; 85 | pthread_create((pthread_t*)(&thread_handle), NULL, proc, arg); 86 | return thread_handle; 87 | } 88 | 89 | ThreadId threadGetCurrentId() 90 | { 91 | return (ThreadId)pthread_self(); 92 | } 93 | 94 | void threadJoin(ThreadHandle thread_handle) 95 | { 96 | pthread_join(thread_handle, NULL); 97 | } 98 | 99 | // --- Mutex --- 100 | void mutexCreate(Mutex* mutex) 101 | { 102 | pthread_mutex_init((pthread_mutex_t*)mutex, NULL); 103 | } 104 | 105 | void mutexDestroy(Mutex* mutex) 106 | { 107 | pthread_mutex_destroy((pthread_mutex_t*)mutex); 108 | } 109 | 110 | void mutexLock(Mutex* mutex) 111 | { 112 | pthread_mutex_lock((pthread_mutex_t*)mutex); 113 | } 114 | 115 | void mutexUnlock(Mutex* mutex) 116 | { 117 | pthread_mutex_unlock((pthread_mutex_t*)mutex); 118 | } 119 | 120 | // --- Event --- 121 | void eventCreate(Event* event) 122 | { 123 | pthread_mutex_init(&event->mutex, NULL); 124 | pthread_cond_init(&event->cond, NULL); 125 | event->triggered = false; 126 | } 127 | 128 | void eventDestroy(Event* event) 129 | { 130 | pthread_cond_destroy(&event->cond); 131 | pthread_mutex_destroy(&event->mutex); 132 | } 133 | 134 | void eventTrigger(Event* event) 135 | { 136 | pthread_mutex_lock(&event->mutex); 137 | event->triggered = true; 138 | pthread_cond_signal(&event->cond); 139 | pthread_mutex_unlock(&event->mutex); 140 | } 141 | 142 | void eventReset(Event *event) 143 | { 144 | pthread_mutex_lock(&event->mutex); 145 | event->triggered = false; 146 | pthread_mutex_unlock(&event->mutex); 147 | } 148 | 149 | void eventWait(Event* event) 150 | { 151 | pthread_mutex_lock(&event->mutex); 152 | while (!event->triggered) 153 | pthread_cond_wait(&event->cond, &event->mutex); 154 | pthread_mutex_unlock(&event->mutex); 155 | } 156 | 157 | #endif 158 | -------------------------------------------------------------------------------- /thread.h: -------------------------------------------------------------------------------- 1 | // thread.h 2 | // Thin interface over the Windows Threads API and pthread. 3 | 4 | #ifndef __THREAD_H__ 5 | #define __THREAD_H__ 6 | 7 | // Basic types: ThreadHandle, ThreadId, Mutex, Event 8 | #ifdef WIN32 9 | #include 10 | typedef HANDLE ThreadHandle; 11 | typedef DWORD ThreadId; 12 | typedef CRITICAL_SECTION Mutex; 13 | typedef HANDLE Event; 14 | #else 15 | #include 16 | typedef pthread_t ThreadHandle; 17 | typedef pthread_t ThreadId; 18 | typedef pthread_mutex_t Mutex; 19 | struct Event 20 | { 21 | pthread_mutex_t mutex; 22 | pthread_cond_t cond; 23 | bool triggered; 24 | }; 25 | #endif 26 | 27 | typedef void* (*ThreadProc)(void* arg); 28 | 29 | ThreadHandle threadCreate(ThreadProc proc, void* arg); 30 | ThreadId threadGetCurrentId(); 31 | void threadJoin(ThreadHandle id); 32 | 33 | void mutexCreate(Mutex* mutex); 34 | void mutexDestroy(Mutex* mutex); 35 | void mutexLock(Mutex* mutex); 36 | void mutexUnlock(Mutex* mutex); 37 | 38 | void eventCreate(Event* event); 39 | void eventDestroy(Event* event); 40 | void eventTrigger(Event* event); 41 | void eventReset(Event* event); 42 | void eventWait(Event* event); 43 | 44 | #endif // __THREAD_H__ 45 | -------------------------------------------------------------------------------- /utils.cpp: -------------------------------------------------------------------------------- 1 | // utils.cpp 2 | 3 | #include "utils.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | const Color COLOR_WHITE = Color(0xFF, 0xFF, 0xFF); 10 | const Color COLOR_BLACK = Color(0x00, 0x00, 0x00); 11 | const Color COLOR_GRAY = Color(0x7F, 0x7F, 0x7F); 12 | const Color COLOR_LIGHT_GRAY = Color(0xC0, 0xC0, 0xC0); 13 | 14 | const Color COLOR_RED = Color(0xFF, 0x00, 0x00); 15 | const Color COLOR_GREEN = Color(0x00, 0xFF, 0x00); 16 | const Color COLOR_BLUE = Color(0x00, 0x00, 0xFF); 17 | 18 | const Color COLOR_DARK_RED = Color(0x7F, 0x00, 0x00); 19 | const Color COLOR_DARK_GREEN = Color(0x00, 0x7F, 0x00); 20 | const Color COLOR_DARK_BLUE = Color(0x00, 0x00, 0x7F); 21 | 22 | const Color COLOR_LIGHT_RED = Color(0xFF, 0x7F, 0x7F); 23 | const Color COLOR_LIGHT_GREEN = Color(0x7F, 0xFF, 0x7F); 24 | const Color COLOR_LIGHT_BLUE = Color(0x7F, 0x7F, 0xFF); 25 | 26 | const Color COLOR_CYAN = Color(0x00, 0xFF, 0xFF); 27 | const Color COLOR_MAGENTA = Color(0xFF, 0x00, 0xFF); 28 | const Color COLOR_YELLOW = Color(0xFF, 0xFF, 0x00); 29 | 30 | #ifdef WIN32 31 | #include 32 | void msleep(int ms) 33 | { 34 | Sleep(ms); 35 | } 36 | #else 37 | #include 38 | void msleep(int ms) 39 | { 40 | usleep(ms*1000); 41 | } 42 | #endif 43 | 44 | // --------------------------------------------------------------------- 45 | // Load a text file: 46 | const char* loadText(const char* filename) 47 | { 48 | std::ifstream f(filename); 49 | if(!f) 50 | { 51 | fprintf(stderr, "impossible to read the file \"%s\"\n", filename); 52 | return NULL; 53 | } 54 | 55 | int filesize = 0; 56 | char* buf = NULL; 57 | 58 | // Get the file size 59 | f.seekg(0, std::ios::end); 60 | filesize = (int)f.tellg(); 61 | 62 | // Allocate memory for the text and get the file's contents 63 | buf = new char[filesize+1]; 64 | memset(buf, 0, filesize); 65 | f.seekg(0, std::ios::beg); 66 | f.read(buf, filesize); 67 | buf[filesize] = '\0'; 68 | 69 | f.close(); 70 | 71 | return buf; 72 | } 73 | 74 | bool loadShaders(const char *vert_filename, const char *frag_filename, 75 | GLuint &id_vert, GLuint &id_frag, GLuint &id_prog) 76 | { 77 | const char* src; 78 | GLchar* buf; 79 | GLint len; 80 | GLint status; 81 | 82 | // --- Vertex shader --- 83 | src = loadText(vert_filename); 84 | if(!src) 85 | { 86 | id_vert = id_frag = id_prog = 0; 87 | fprintf(stderr, "*** FAILED: file %s not found\n", vert_filename); 88 | return false; 89 | } 90 | 91 | id_vert = glCreateShader(GL_VERTEX_SHADER); 92 | glShaderSource(id_vert, 1, &src, NULL); 93 | glCompileShader(id_vert); 94 | delete [] src; 95 | 96 | // Print the log: 97 | glGetShaderiv(id_vert, GL_INFO_LOG_LENGTH, &len); 98 | 99 | buf = new GLchar[len]; 100 | glGetShaderInfoLog(id_vert, len, &len, buf); 101 | printf("[%s]: vertex shader log:\n%s\n", vert_filename, buf); 102 | delete [] buf; 103 | 104 | // Check if it compiled 105 | glGetShaderiv(id_vert, GL_COMPILE_STATUS, &status); 106 | if(status != GL_TRUE) 107 | { 108 | glDeleteShader(id_vert); 109 | id_vert = id_frag = id_prog = 0; 110 | fprintf(stderr, "*** FAILED compiling vertex shader %s\n", vert_filename); 111 | return false; 112 | } 113 | 114 | // --- Fragment shader --- 115 | src = loadText(frag_filename); 116 | if(!src) 117 | { 118 | glDeleteShader(id_vert); 119 | id_vert = id_frag = id_prog = 0; 120 | fprintf(stderr, "*** FAILED: file %s not found\n", frag_filename); 121 | return false; 122 | } 123 | 124 | id_frag = glCreateShader(GL_FRAGMENT_SHADER); 125 | glShaderSource(id_frag, 1, &src, NULL); 126 | glCompileShader(id_frag); 127 | delete [] src; 128 | 129 | // Print the log: 130 | glGetShaderiv(id_frag, GL_INFO_LOG_LENGTH, &len); 131 | 132 | buf = new GLchar[len]; 133 | glGetShaderInfoLog(id_frag, len, &len, buf); 134 | printf("[%s]: fragment shader log:\n%s\n", frag_filename, buf); 135 | delete [] buf; 136 | 137 | // Check if it compiled 138 | glGetShaderiv(id_vert, GL_COMPILE_STATUS, &status); 139 | if(status != GL_TRUE) 140 | { 141 | glDeleteShader(id_frag); 142 | glDeleteShader(id_vert); 143 | id_vert = id_frag = id_prog = 0; 144 | fprintf(stderr, "*** FAILED compiling fragment shader %s\n", frag_filename); 145 | return false; 146 | } 147 | 148 | // --- Program --- 149 | id_prog = glCreateProgram(); 150 | glAttachShader(id_prog, id_vert); 151 | glAttachShader(id_prog, id_frag); 152 | glLinkProgram(id_prog); 153 | 154 | // Print the log: 155 | glGetProgramiv(id_prog, GL_INFO_LOG_LENGTH, &len); 156 | 157 | buf = new GLchar[len]; 158 | glGetProgramInfoLog(id_prog, len, &len, buf); 159 | printf("[%s][%s]: program log:\n%s\n", vert_filename, frag_filename, buf); 160 | delete [] buf; 161 | 162 | // Check if the linkage was successful 163 | glGetProgramiv(id_prog, GL_LINK_STATUS, &status); 164 | if(status != GL_TRUE) 165 | { 166 | glDeleteProgram(id_prog); 167 | glDeleteShader(id_frag); 168 | glDeleteShader(id_vert); 169 | } 170 | 171 | return true; 172 | } 173 | 174 | bool checkGLError() 175 | { 176 | GLenum error = glGetError(); 177 | if(error != GL_NO_ERROR) 178 | { 179 | const char* error_msg = NULL; 180 | switch(error) 181 | { 182 | case GL_INVALID_ENUM: error_msg = "GL_INVALID_ENUM"; break; 183 | case GL_INVALID_VALUE: error_msg = "GL_INVALID_VALUE"; break; 184 | case GL_INVALID_OPERATION: error_msg = "GL_INVALID_OPERATION"; break; 185 | case GL_OUT_OF_MEMORY: error_msg = "GL_OUT_OF_MEMORY"; break; 186 | case GL_INVALID_FRAMEBUFFER_OPERATION: error_msg = "GL_INVALID_FRAMEBUFFER_OPERATION"; break; 187 | default: 188 | fprintf(stderr, "*** OpenGL ERROR: unknown error: 0x%x\n", error); 189 | return false; 190 | } 191 | 192 | fprintf(stderr, "*** OpenGL ERROR: %s\n", error_msg); 193 | } 194 | return true; 195 | } 196 | -------------------------------------------------------------------------------- /utils.h: -------------------------------------------------------------------------------- 1 | // utils.h 2 | 3 | #ifndef UTILS_H 4 | #define UTILS_H 5 | 6 | #include 7 | 8 | void msleep(int ms); 9 | const char* loadText(const char* filename); 10 | bool loadShaders(const char* vert_filename, const char* frag_filename, 11 | GLuint& id_vert, GLuint& id_frag, GLuint& id_prog); 12 | bool checkGLError(); 13 | 14 | template 15 | T clamp(T val, T min_val, T max_val) 16 | { 17 | if(val < min_val) 18 | val = min_val; 19 | if(val > max_val) 20 | val = max_val; 21 | return val; 22 | } 23 | 24 | inline void incrementCycle(int* pval, size_t array_size) 25 | { 26 | int val = *pval; 27 | val++; 28 | if(val >= (int)(array_size)) 29 | val = 0; 30 | *pval = val; 31 | } 32 | 33 | inline void decrementCycle(int* pval, size_t array_size) 34 | { 35 | int val = *pval; 36 | val--; 37 | if(val < 0) 38 | val = (int)(array_size-1); 39 | *pval = val; 40 | } 41 | 42 | struct Rect 43 | { 44 | float x, y; 45 | float w, h; 46 | 47 | Rect() : x(0.0f), y(0.0f), w(0.0f), h(0.0f) {} 48 | Rect(float x, float y, float w, float h) : x(x), y(y), w(w), h(h) {} 49 | 50 | void set(float _x, float _y, float _w, float _h) 51 | { 52 | x = _x; y = _y; w = _w; h = _h; 53 | } 54 | 55 | bool isPointInside(float _x, float _y) const 56 | { 57 | return (_x >= x && _x < x+w && 58 | _y >= y && _y < y+h ); 59 | } 60 | }; 61 | 62 | struct Color 63 | { 64 | unsigned char r; 65 | unsigned char g; 66 | unsigned char b; 67 | 68 | Color() : r(0xFF), g(0xFF), b(0xFF) {} 69 | Color(unsigned char r, unsigned char g, unsigned char b) : r(r), g(g), b(b) {} 70 | 71 | void set(unsigned char _r, unsigned char _g, unsigned char _b) 72 | { 73 | r = _r; g = _g; b = _b; 74 | } 75 | 76 | void set(const Color& color) 77 | { 78 | r = color.r; 79 | g = color.g; 80 | b = color.b; 81 | } 82 | }; 83 | 84 | extern const Color COLOR_WHITE; 85 | extern const Color COLOR_BLACK; 86 | extern const Color COLOR_GRAY; 87 | extern const Color COLOR_LIGHT_GRAY; 88 | 89 | extern const Color COLOR_RED; 90 | extern const Color COLOR_GREEN; 91 | extern const Color COLOR_BLUE; 92 | 93 | extern const Color COLOR_DARK_RED; 94 | extern const Color COLOR_DARK_GREEN; 95 | extern const Color COLOR_DARK_BLUE; 96 | 97 | extern const Color COLOR_LIGHT_RED; 98 | extern const Color COLOR_LIGHT_GREEN; 99 | extern const Color COLOR_LIGHT_BLUE; 100 | 101 | extern const Color COLOR_CYAN; 102 | extern const Color COLOR_MAGENTA; 103 | extern const Color COLOR_YELLOW; 104 | 105 | 106 | #endif // UTILS_H 107 | --------------------------------------------------------------------------------