[856] | 1 | #ifndef __IMDEBUGGL_H__
|
---|
| 2 | #define __IMDEBUGGL_H__
|
---|
| 3 |
|
---|
| 4 | #include <imdebug.h>
|
---|
| 5 | #include <gl/gl.h>
|
---|
| 6 | #include <string>
|
---|
| 7 |
|
---|
| 8 | int format2components(GLenum format);
|
---|
| 9 | std::string format2string(GLenum format);
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | //-----------------------------------------------------------------------------
|
---|
| 13 | // Function : imdebugTexImage
|
---|
| 14 | // Description :
|
---|
| 15 | //-----------------------------------------------------------------------------
|
---|
| 16 | /**
|
---|
| 17 | * @brief Gets a texture level from OpenGL, and displays it using imdebug.
|
---|
| 18 | *
|
---|
| 19 | * If argstring is non-NULL, then it is prepended to the string " w=%d h=%d %p"
|
---|
| 20 | * and passed as the imdebug format string. Otherwise, the correct format
|
---|
| 21 | * ("rgb", "lum", etc.) is determined from the @a format argument, and
|
---|
| 22 | * prepended to the same string and used as the imdebug format string.
|
---|
| 23 | */
|
---|
| 24 | inline void imdebugTexImage(GLenum target, GLuint texture,
|
---|
| 25 | GLenum format = GL_RGB,
|
---|
| 26 | GLint level = 0, char *argstring = NULL)
|
---|
| 27 | {
|
---|
| 28 | int w, h;
|
---|
| 29 | int prevTexBind;
|
---|
| 30 | glGetIntegerv(target, &prevTexBind);
|
---|
| 31 |
|
---|
| 32 | glBindTexture(target, texture);
|
---|
| 33 | glGetTexLevelParameteriv(target, 0, GL_TEXTURE_WIDTH, &w);
|
---|
| 34 | glGetTexLevelParameteriv(target, 0, GL_TEXTURE_HEIGHT, &h);
|
---|
| 35 | GLubyte *p = new GLubyte[w * h * format2components(format)];
|
---|
| 36 |
|
---|
| 37 | glGetTexImage(target, level, format, GL_UNSIGNED_BYTE, p);
|
---|
| 38 |
|
---|
| 39 | std::string s = (NULL == argstring) ? format2string(format) : argstring;
|
---|
| 40 | imdebug(s.append(" w=%d h=%d %p").c_str(), w, h, p);
|
---|
| 41 |
|
---|
| 42 | delete [] p;
|
---|
| 43 |
|
---|
| 44 | glBindTexture(target, prevTexBind);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | //-----------------------------------------------------------------------------
|
---|
| 48 | // Function : imdebugTexImagef
|
---|
| 49 | // Description :
|
---|
| 50 | //-----------------------------------------------------------------------------
|
---|
| 51 | /**
|
---|
| 52 | * @brief Gets a texture level from OpenGL, and displays it as floats using imdebug.
|
---|
| 53 | *
|
---|
| 54 | * If argstring is non-NULL, then it is prepended to the string " w=%d h=%d %p"
|
---|
| 55 | * and passed as the imdebug format string. Otherwise, the correct format
|
---|
| 56 | * ("rgb", "lum", etc.) is determined from the @a format argument, and
|
---|
| 57 | * prepended to the same string and used as the imdebug format string.
|
---|
| 58 | */
|
---|
| 59 | inline void imdebugTexImagef(GLenum target, GLuint texture,
|
---|
| 60 | GLenum format = GL_RGB,
|
---|
| 61 | GLint level = 0, char *argstring = NULL)
|
---|
| 62 | {
|
---|
| 63 | int w, h;
|
---|
| 64 | int prevTexBind;
|
---|
| 65 | glGetIntegerv(target, &prevTexBind);
|
---|
| 66 |
|
---|
| 67 | glBindTexture(target, texture);
|
---|
| 68 | glGetTexLevelParameteriv(target, 0, GL_TEXTURE_WIDTH, &w);
|
---|
| 69 | glGetTexLevelParameteriv(target, 0, GL_TEXTURE_HEIGHT, &h);
|
---|
| 70 | float *p = new float[w * h * format2components(format)];
|
---|
| 71 |
|
---|
| 72 | glGetTexImage(target, level, format, GL_FLOAT, p);
|
---|
| 73 |
|
---|
| 74 | std::string s = (NULL == argstring) ? format2string(format) : argstring;
|
---|
| 75 | imdebug(s.append(" b=32f w=%d h=%d %p").c_str(), w, h, p);
|
---|
| 76 |
|
---|
| 77 | delete [] p;
|
---|
| 78 |
|
---|
| 79 | glBindTexture(target, prevTexBind);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | //-----------------------------------------------------------------------------
|
---|
| 84 | // Function : imdebugPixels
|
---|
| 85 | // Description :
|
---|
| 86 | //-----------------------------------------------------------------------------
|
---|
| 87 | /**
|
---|
| 88 | * @brief performs a glReadPixels(), and then displays the results in imdebug.
|
---|
| 89 | *
|
---|
| 90 | * If argstring is non-NULL, then it is prepended to the string " w=%d h=%d %p"
|
---|
| 91 | * and passed as the imdebug format string. Otherwise, the correct format
|
---|
| 92 | * ("rgb", "lum", etc.) is determined from the @a format argument, and
|
---|
| 93 | * prepended to the same string and used as the imdebug format string.
|
---|
| 94 | */
|
---|
| 95 | inline void imdebugPixels(GLint x, GLint y, GLsizei width, GLsizei height,
|
---|
| 96 | GLenum format = GL_RGB, char *argstring = NULL)
|
---|
| 97 | {
|
---|
| 98 | GLubyte *p = new GLubyte[width * height * format2components(format)];
|
---|
| 99 | glReadPixels(x, y, width, height, format, GL_UNSIGNED_BYTE, p);
|
---|
| 100 |
|
---|
| 101 | std::string s = (NULL == argstring) ? format2string(format) : argstring;
|
---|
| 102 | imdebug(s.append(" w=%d h=%d %p").c_str(), width, height, p);
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | delete [] p;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | //-----------------------------------------------------------------------------
|
---|
| 109 | // Function : imdebugPixelsf
|
---|
| 110 | // Description :
|
---|
| 111 | //-----------------------------------------------------------------------------
|
---|
| 112 | /**
|
---|
| 113 | * @brief performs a glReadPixels(), and then displays the results in imdebug.
|
---|
| 114 | *
|
---|
| 115 | * If argstring is non-NULL, then it is prepended to the string " w=%d h=%d %p"
|
---|
| 116 | * and passed as the imdebug format string. Otherwise, the correct format
|
---|
| 117 | * ("rgb", "lum", etc.) is determined from the @a format argument, and
|
---|
| 118 | * prepended to the same string and used as the imdebug format string.
|
---|
| 119 | */
|
---|
| 120 | inline void imdebugPixelsf(GLint x, GLint y, GLsizei width, GLsizei height,
|
---|
| 121 | GLenum format = GL_RGB, char *argstring = NULL)
|
---|
| 122 | {
|
---|
| 123 | float *p = new float[width * height * format2components(format)];
|
---|
| 124 | glReadPixels(x, y, width, height, format, GL_FLOAT, p);
|
---|
| 125 |
|
---|
| 126 | std::string s = (NULL == argstring) ? format2string(format) : argstring;
|
---|
| 127 | imdebug(s.append(" b=32f w=%d h=%d %p").c_str(), width, height, p);
|
---|
| 128 |
|
---|
| 129 | delete [] p;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | //-----------------------------------------------------------------------------
|
---|
| 133 | // Function : imdebugDepth
|
---|
| 134 | // Description :
|
---|
| 135 | //-----------------------------------------------------------------------------
|
---|
| 136 | /**
|
---|
| 137 | * @brief performs a glReadPixels() on depth, and then displays the results in imdebug.
|
---|
| 138 | *
|
---|
| 139 | * If argstring is non-NULL, then it is prepended to the string " w=%d h=%d %p"
|
---|
| 140 | * and passed as the imdebug format string.
|
---|
| 141 | */
|
---|
| 142 | inline void imdebugDepth(GLint x, GLint y, GLsizei width, GLsizei height,
|
---|
| 143 | char *argstring = NULL)
|
---|
| 144 | {
|
---|
| 145 | GLuint *p = new GLuint[width * height];
|
---|
| 146 | glReadPixels(x, y, width, height, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, p);
|
---|
| 147 |
|
---|
| 148 | std::string s = (NULL == argstring) ? "" : argstring;
|
---|
| 149 | imdebug(s.append("lum b=32 w=%d h=%d %p").c_str(), width, height, p);
|
---|
| 150 |
|
---|
| 151 | delete [] p;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | //-----------------------------------------------------------------------------
|
---|
| 155 | // Function : imdebugDepthf
|
---|
| 156 | // Description :
|
---|
| 157 | //-----------------------------------------------------------------------------
|
---|
| 158 | /**
|
---|
| 159 | * @brief performs a glReadPixels() on depth, and then displays the results in imdebug.
|
---|
| 160 | *
|
---|
| 161 | * If argstring is non-NULL, then it is prepended to the string
|
---|
| 162 | * " lum b=32f w=%d h=%d %p"
|
---|
| 163 | * and passed as the imdebug format string.
|
---|
| 164 | */
|
---|
| 165 | inline void imdebugDepthf(GLint x, GLint y, GLsizei width, GLsizei height,
|
---|
| 166 | char *argstring = NULL)
|
---|
| 167 | {
|
---|
| 168 | float *p = new float[width * height];
|
---|
| 169 | glReadPixels(x, y, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, p);
|
---|
| 170 |
|
---|
| 171 | std::string s = (NULL == argstring) ? "" : argstring;
|
---|
| 172 | imdebug(s.append(" lum b=32f w=%d h=%d %p").c_str(), width, height, p);
|
---|
| 173 |
|
---|
| 174 | delete [] p;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | //-----------------------------------------------------------------------------
|
---|
| 178 | // Function : imdebugStencil
|
---|
| 179 | // Description :
|
---|
| 180 | //-----------------------------------------------------------------------------
|
---|
| 181 | /**
|
---|
| 182 | * @brief performs a glReadPixels() on stencil, and then displays the results in imdebug.
|
---|
| 183 | *
|
---|
| 184 | * If argstring is non-NULL, then it is prepended to the string
|
---|
| 185 | * " lum w=%d h=%d %p"
|
---|
| 186 | * and passed as the imdebug format string.
|
---|
| 187 | */
|
---|
| 188 | inline void imdebugStencil(GLint x, GLint y, GLsizei width, GLsizei height,
|
---|
| 189 | char *argstring = NULL)
|
---|
| 190 | {
|
---|
| 191 | GLubyte *p = new GLubyte[width * height];
|
---|
| 192 | glReadPixels(x, y, width, height, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, p);
|
---|
| 193 |
|
---|
| 194 | std::string s = (NULL == argstring) ? "" : argstring;
|
---|
| 195 | imdebug(s.append(" lum w=%d h=%d %p").c_str(), width, height, p);
|
---|
| 196 |
|
---|
| 197 | delete [] p;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 |
|
---|
| 201 | inline int format2components(GLenum format)
|
---|
| 202 | {
|
---|
| 203 | switch(format)
|
---|
| 204 | {
|
---|
| 205 | case GL_LUMINANCE:
|
---|
| 206 | case GL_INTENSITY:
|
---|
| 207 | case GL_ALPHA:
|
---|
| 208 | return 1;
|
---|
| 209 | break;
|
---|
| 210 | case GL_LUMINANCE_ALPHA:
|
---|
| 211 | return 2;
|
---|
| 212 | break;
|
---|
| 213 | case GL_RGB:
|
---|
| 214 | case GL_BGR:
|
---|
| 215 | return 3;
|
---|
| 216 | break;
|
---|
| 217 | case GL_RGBA:
|
---|
| 218 | case GL_BGRA:
|
---|
| 219 | case GL_ABGR_EXT:
|
---|
| 220 | return 4;
|
---|
| 221 | break;
|
---|
| 222 | default:
|
---|
| 223 | return 4;
|
---|
| 224 | break;
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | inline std::string format2string(GLenum format)
|
---|
| 229 | {
|
---|
| 230 | switch(format)
|
---|
| 231 | {
|
---|
| 232 | case GL_LUMINANCE:
|
---|
| 233 | case GL_INTENSITY:
|
---|
| 234 | case GL_ALPHA:
|
---|
| 235 | return "lum";
|
---|
| 236 | break;
|
---|
| 237 | case GL_LUMINANCE_ALPHA:
|
---|
| 238 | return "luma";
|
---|
| 239 | break;
|
---|
| 240 | case GL_RGB:
|
---|
| 241 | case GL_BGR:
|
---|
| 242 | return "rgb";
|
---|
| 243 | break;
|
---|
| 244 | case GL_RGBA:
|
---|
| 245 | case GL_BGRA:
|
---|
| 246 | case GL_ABGR_EXT:
|
---|
| 247 | return "rgba";
|
---|
| 248 | break;
|
---|
| 249 | default:
|
---|
| 250 | return "rgb";
|
---|
| 251 | break;
|
---|
| 252 | }
|
---|
| 253 | }
|
---|
| 254 | #endif //__IMDEBUGGL_H__
|
---|