robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #include "gl/GrGLInterface.h" |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame^] | 11 | #include "GrDebugGL.h" |
| 12 | #include "GrShaderObj.h" |
| 13 | #include "GrProgramObj.h" |
| 14 | #include "GrBufferObj.h" |
| 15 | #include "GrTextureUnitObj.h" |
| 16 | #include "GrTextureObj.h" |
| 17 | #include "GrFrameBufferObj.h" |
| 18 | #include "GrRenderBufferObj.h" |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 19 | |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 20 | // the OpenGLES 2.0 spec says this must be >= 128 |
| 21 | static const GrGLint kDefaultMaxVertexUniformVectors = 128; |
| 22 | |
| 23 | // the OpenGLES 2.0 spec says this must be >=16 |
| 24 | static const GrGLint kDefaultMaxFragmentUniformVectors = 16; |
| 25 | |
| 26 | // the OpenGLES 2.0 spec says this must be >= 8 |
| 27 | static const GrGLint kDefaultMaxVertexAttribs = 8; |
| 28 | |
| 29 | // the OpenGLES 2.0 spec says this must be >= 8 |
| 30 | static const GrGLint kDefaultMaxVaryingVectors = 8; |
| 31 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 32 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 33 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLActiveTexture(GrGLenum texture) { |
robertphillips@google.com | d41a1dc | 2012-03-19 17:33:58 +0000 | [diff] [blame] | 34 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 35 | // Ganesh offsets the texture unit indices |
| 36 | texture -= GR_GL_TEXTURE0; |
| 37 | GrAlwaysAssert(texture < GrDebugGL::getInstance()->getMaxTextureUnits()); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 38 | |
| 39 | GrDebugGL::getInstance()->setCurTextureUnit(texture); |
| 40 | } |
| 41 | |
| 42 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 43 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLAttachShader(GrGLuint programID, GrGLuint shaderID) { |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 44 | |
| 45 | GrProgramObj *program = GR_FIND(programID, GrProgramObj, GrDebugGL::kProgram_ObjTypes); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 46 | GrAlwaysAssert(program); |
| 47 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 48 | GrShaderObj *shader = GR_FIND(shaderID, GrShaderObj, GrDebugGL::kShader_ObjTypes); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 49 | GrAlwaysAssert(shader); |
| 50 | |
| 51 | program->AttachShader(shader); |
| 52 | } |
| 53 | |
| 54 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBeginQuery(GrGLenum target, GrGLuint id) {} |
| 55 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindAttribLocation(GrGLuint program, GrGLuint index, const char* name) {} |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 56 | |
| 57 | //////////////////////////////////////////////////////////////////////////////// |
| 58 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindTexture(GrGLenum target, GrGLuint textureID) { |
| 59 | |
| 60 | // we don't use cube maps |
| 61 | GrAlwaysAssert(target == GR_GL_TEXTURE_2D); // || target == GR_GL_TEXTURE_CUBE_MAP); |
| 62 | |
| 63 | // a textureID of 0 is acceptable - it binds to the default texture target |
| 64 | GrTextureObj *texture = GR_FIND(textureID, GrTextureObj, GrDebugGL::kTexture_ObjTypes); |
| 65 | |
| 66 | GrDebugGL::getInstance()->setTexture(texture); |
| 67 | } |
| 68 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 69 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBlendColor(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha) {} |
| 70 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindFragDataLocation(GrGLuint program, GrGLuint colorNumber, const GrGLchar* name) {} |
| 71 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBlendFunc(GrGLenum sfactor, GrGLenum dfactor) {} |
| 72 | |
| 73 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 74 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBufferData(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data, GrGLenum usage) { |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 75 | GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || GR_GL_ELEMENT_ARRAY_BUFFER == target); |
| 76 | GrAlwaysAssert(size >= 0); |
| 77 | GrAlwaysAssert(GR_GL_STREAM_DRAW == usage || GR_GL_STATIC_DRAW == usage || GR_GL_DYNAMIC_DRAW == usage); |
| 78 | |
| 79 | GrBufferObj *buffer = NULL; |
| 80 | switch (target) { |
| 81 | case GR_GL_ARRAY_BUFFER: |
| 82 | buffer = GrDebugGL::getInstance()->getArrayBuffer(); |
| 83 | break; |
| 84 | case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 85 | buffer = GrDebugGL::getInstance()->getElementArrayBuffer(); |
| 86 | break; |
| 87 | default: |
| 88 | GrCrash("Unexpected target to glBufferData"); |
| 89 | break; |
| 90 | } |
| 91 | |
| 92 | GrAlwaysAssert(buffer); |
| 93 | GrAlwaysAssert(buffer->getBound()); |
| 94 | |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 95 | buffer->allocate(size, reinterpret_cast<const GrGLchar *>(data)); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 96 | buffer->setUsage(usage); |
| 97 | } |
| 98 | |
| 99 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBufferSubData(GrGLenum target, GrGLintptr offset, GrGLsizeiptr size, const GrGLvoid* data) {} |
| 100 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLClear(GrGLbitfield mask) {} |
| 101 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLClearColor(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha) {} |
| 102 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLClearStencil(GrGLint s) {} |
| 103 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLColorMask(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha) {} |
| 104 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLCompileShader(GrGLuint shader) {} |
| 105 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLCompressedTexImage2D(GrGLenum target, GrGLint level, GrGLenum internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLsizei imageSize, const GrGLvoid* data) {} |
| 106 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLCullFace(GrGLenum mode) {} |
| 107 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDepthMask(GrGLboolean flag) {} |
| 108 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDisable(GrGLenum cap) {} |
| 109 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDisableVertexAttribArray(GrGLuint index) {} |
| 110 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDrawArrays(GrGLenum mode, GrGLint first, GrGLsizei count) {} |
| 111 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDrawBuffer(GrGLenum mode) {} |
| 112 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDrawBuffers(GrGLsizei n, const GrGLenum* bufs) {} |
| 113 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDrawElements(GrGLenum mode, GrGLsizei count, GrGLenum type, const GrGLvoid* indices) {} |
| 114 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLEnable(GrGLenum cap) {} |
| 115 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLEnableVertexAttribArray(GrGLuint index) {} |
| 116 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLEndQuery(GrGLenum target) {} |
| 117 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLFinish() {} |
| 118 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLFlush() {} |
| 119 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLFrontFace(GrGLenum mode) {} |
| 120 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLLineWidth(GrGLfloat width) {} |
| 121 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLLinkProgram(GrGLuint program) {} |
| 122 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLPixelStorei(GrGLenum pname, GrGLint param) {} |
| 123 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLQueryCounter(GrGLuint id, GrGLenum target) {} |
| 124 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLReadBuffer(GrGLenum src) {} |
| 125 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLReadPixels(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {} |
| 126 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLScissor(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height) {} |
| 127 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLShaderSource(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length) {} |
| 128 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilFunc(GrGLenum func, GrGLint ref, GrGLuint mask) {} |
| 129 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilFuncSeparate(GrGLenum face, GrGLenum func, GrGLint ref, GrGLuint mask) {} |
| 130 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilMask(GrGLuint mask) {} |
| 131 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilMaskSeparate(GrGLenum face, GrGLuint mask) {} |
| 132 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilOp(GrGLenum fail, GrGLenum zfail, GrGLenum zpass) {} |
| 133 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilOpSeparate(GrGLenum face, GrGLenum fail, GrGLenum zfail, GrGLenum zpass) {} |
| 134 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexImage2D(GrGLenum target, GrGLint level, GrGLint internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLenum format, GrGLenum type, const GrGLvoid* pixels) {} |
| 135 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexParameteri(GrGLenum target, GrGLenum pname, GrGLint param) {} |
| 136 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexStorage2D(GrGLenum target, GrGLsizei levels, GrGLenum internalformat, GrGLsizei width, GrGLsizei height) {} |
| 137 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexSubImage2D(GrGLenum target, GrGLint level, GrGLint xoffset, GrGLint yoffset, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, const GrGLvoid* pixels) {} |
| 138 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform1f(GrGLint location, GrGLfloat v0) {} |
| 139 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform1i(GrGLint location, GrGLint v0) {} |
| 140 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform1fv(GrGLint location, GrGLsizei count, const GrGLfloat* v) {} |
| 141 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform1iv(GrGLint location, GrGLsizei count, const GrGLint* v) {} |
| 142 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform2f(GrGLint location, GrGLfloat v0, GrGLfloat v1) {} |
| 143 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform2i(GrGLint location, GrGLint v0, GrGLint v1) {} |
| 144 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform2fv(GrGLint location, GrGLsizei count, const GrGLfloat* v) {} |
| 145 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform2iv(GrGLint location, GrGLsizei count, const GrGLint* v) {} |
| 146 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform3f(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2) {} |
| 147 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform3i(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2) {} |
| 148 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform3fv(GrGLint location, GrGLsizei count, const GrGLfloat* v) {} |
| 149 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform3iv(GrGLint location, GrGLsizei count, const GrGLint* v) {} |
| 150 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform4f(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2, GrGLfloat v3) {} |
| 151 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform4i(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2, GrGLint v3) {} |
| 152 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform4fv(GrGLint location, GrGLsizei count, const GrGLfloat* v) {} |
| 153 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform4iv(GrGLint location, GrGLsizei count, const GrGLint* v) {} |
| 154 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniformMatrix2fv(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value) {} |
| 155 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniformMatrix3fv(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value) {} |
| 156 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniformMatrix4fv(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value) {} |
| 157 | |
| 158 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLUseProgram(GrGLuint programID) { |
| 159 | |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 160 | // A programID of 0 is legal |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 161 | GrProgramObj *program = GR_FIND(programID, GrProgramObj, GrDebugGL::kProgram_ObjTypes); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 162 | |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 163 | GrDebugGL::getInstance()->useProgram(program); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 164 | } |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 165 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 166 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLVertexAttrib4fv(GrGLuint indx, const GrGLfloat* values) {} |
| 167 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLVertexAttribPointer(GrGLuint indx, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const GrGLvoid* ptr) {} |
| 168 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLViewport(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height) {} |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 169 | |
| 170 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindFramebuffer(GrGLenum target, GrGLuint frameBufferID) { |
| 171 | |
| 172 | GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); |
| 173 | |
| 174 | // a frameBufferID of 0 is acceptable - it binds to the default frame buffer |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 175 | GrFrameBufferObj *frameBuffer = GR_FIND(frameBufferID, GrFrameBufferObj, GrDebugGL::kFrameBuffer_ObjTypes); |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 176 | |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 177 | GrDebugGL::getInstance()->setFrameBuffer(frameBuffer); |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 178 | } |
| 179 | |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 180 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindRenderbuffer(GrGLenum target, GrGLuint renderBufferID) { |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 181 | |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 182 | GrAlwaysAssert(GR_GL_RENDERBUFFER == target); |
| 183 | |
| 184 | // a renderBufferID of 0 is acceptable - it unbinds the bound render buffer |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 185 | GrRenderBufferObj *renderBuffer = GR_FIND(renderBufferID, GrRenderBufferObj, GrDebugGL::kRenderBuffer_ObjTypes); |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 186 | |
| 187 | GrDebugGL::getInstance()->setRenderBuffer(renderBuffer); |
| 188 | } |
| 189 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 190 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteTextures(GrGLsizei n, const GrGLuint* textures) { |
| 191 | |
| 192 | // first potentially unbind the texture |
| 193 | // TODO: move this into GrDebugGL as unBindTexture? |
| 194 | for (unsigned int i = 0; i < GrDebugGL::getInstance()->getMaxTextureUnits(); ++i) |
| 195 | { |
| 196 | GrTextureUnitObj *pTU = GrDebugGL::getInstance()->getTextureUnit(i); |
| 197 | |
| 198 | if (pTU->getTexture()) { |
| 199 | for (int j = 0; j < n; ++j) { |
| 200 | |
| 201 | if (textures[j] == pTU->getTexture()->getID()) { |
| 202 | // this ID is the current texture - revert the binding to 0 |
| 203 | pTU->setTexture(NULL); |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | // TODO: fuse the following block with DeleteRenderBuffers? |
| 210 | // Open GL will remove a deleted render buffer from the active frame buffer but not |
| 211 | // from any other frame buffer |
| 212 | if (GrDebugGL::getInstance()->getFrameBuffer()) { |
| 213 | |
| 214 | GrFrameBufferObj *frameBuffer = GrDebugGL::getInstance()->getFrameBuffer(); |
| 215 | |
| 216 | for (int i = 0; i < n; ++i) { |
| 217 | |
| 218 | if (NULL != frameBuffer->getColor() && textures[i] == frameBuffer->getColor()->getID()) { |
| 219 | frameBuffer->setColor(NULL); |
| 220 | } |
| 221 | if (NULL != frameBuffer->getDepth() && textures[i] == frameBuffer->getDepth()->getID()) { |
| 222 | frameBuffer->setDepth(NULL); |
| 223 | } |
| 224 | if (NULL != frameBuffer->getStencil() && textures[i] == frameBuffer->getStencil()->getID()) { |
| 225 | frameBuffer->setStencil(NULL); |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | // then actually "delete" the buffers |
| 231 | for (int i = 0; i < n; ++i) { |
| 232 | GrTextureObj *buffer = GR_FIND(textures[i], GrTextureObj, GrDebugGL::kTexture_ObjTypes); |
| 233 | GrAlwaysAssert(buffer); |
| 234 | |
| 235 | // OpenGL gives no guarantees if a texture is deleted while attached to |
| 236 | // something other than the currently bound frame buffer |
| 237 | GrAlwaysAssert(!buffer->getBound()); |
| 238 | |
| 239 | GrAlwaysAssert(!buffer->getDeleted()); |
| 240 | buffer->deleteAction(); |
| 241 | } |
| 242 | |
| 243 | } |
| 244 | |
| 245 | |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 246 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteFramebuffers(GrGLsizei n, const GrGLuint *frameBuffers) { |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 247 | |
| 248 | // first potentially unbind the buffers |
| 249 | if (GrDebugGL::getInstance()->getFrameBuffer()) { |
| 250 | for (int i = 0; i < n; ++i) { |
| 251 | |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 252 | if (frameBuffers[i] == GrDebugGL::getInstance()->getFrameBuffer()->getID()) { |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 253 | // this ID is the current frame buffer - rebind to the default |
| 254 | GrDebugGL::getInstance()->setFrameBuffer(NULL); |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | // then actually "delete" the buffers |
| 260 | for (int i = 0; i < n; ++i) { |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 261 | GrFrameBufferObj *buffer = GR_FIND(frameBuffers[i], GrFrameBufferObj, GrDebugGL::kFrameBuffer_ObjTypes); |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 262 | GrAlwaysAssert(buffer); |
| 263 | |
| 264 | GrAlwaysAssert(!buffer->getDeleted()); |
| 265 | buffer->deleteAction(); |
| 266 | } |
| 267 | } |
| 268 | |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 269 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteRenderbuffers(GrGLsizei n, const GrGLuint *renderBuffers) { |
| 270 | |
| 271 | // first potentially unbind the buffers |
| 272 | if (GrDebugGL::getInstance()->getRenderBuffer()) { |
| 273 | for (int i = 0; i < n; ++i) { |
| 274 | |
| 275 | if (renderBuffers[i] == GrDebugGL::getInstance()->getRenderBuffer()->getID()) { |
| 276 | // this ID is the current render buffer - make no render buffer be bound |
| 277 | GrDebugGL::getInstance()->setRenderBuffer(NULL); |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 282 | // TODO: fuse the following block with DeleteTextures? |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 283 | // Open GL will remove a deleted render buffer from the active frame buffer but not |
| 284 | // from any other frame buffer |
| 285 | if (GrDebugGL::getInstance()->getFrameBuffer()) { |
| 286 | |
| 287 | GrFrameBufferObj *frameBuffer = GrDebugGL::getInstance()->getFrameBuffer(); |
| 288 | |
| 289 | for (int i = 0; i < n; ++i) { |
| 290 | |
| 291 | if (NULL != frameBuffer->getColor() && renderBuffers[i] == frameBuffer->getColor()->getID()) { |
| 292 | frameBuffer->setColor(NULL); |
| 293 | } |
| 294 | if (NULL != frameBuffer->getDepth() && renderBuffers[i] == frameBuffer->getDepth()->getID()) { |
| 295 | frameBuffer->setDepth(NULL); |
| 296 | } |
| 297 | if (NULL != frameBuffer->getStencil() && renderBuffers[i] == frameBuffer->getStencil()->getID()) { |
| 298 | frameBuffer->setStencil(NULL); |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | // then actually "delete" the buffers |
| 304 | for (int i = 0; i < n; ++i) { |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 305 | GrRenderBufferObj *buffer = GR_FIND(renderBuffers[i], GrRenderBufferObj, GrDebugGL::kRenderBuffer_ObjTypes); |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 306 | GrAlwaysAssert(buffer); |
| 307 | |
| 308 | // OpenGL gives no guarantees if a render buffer is deleted while attached to |
| 309 | // something other than the currently bound frame buffer |
| 310 | GrAlwaysAssert(!buffer->getColorBound()); |
| 311 | GrAlwaysAssert(!buffer->getDepthBound()); |
| 312 | GrAlwaysAssert(!buffer->getStencilBound()); |
| 313 | |
| 314 | GrAlwaysAssert(!buffer->getDeleted()); |
| 315 | buffer->deleteAction(); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLFramebufferRenderbuffer(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderBufferID) { |
| 320 | |
| 321 | GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); |
| 322 | GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment || |
| 323 | GR_GL_DEPTH_ATTACHMENT == attachment || |
| 324 | GR_GL_STENCIL_ATTACHMENT == attachment); |
| 325 | GrAlwaysAssert(GR_GL_RENDERBUFFER == renderbuffertarget); |
| 326 | |
| 327 | GrFrameBufferObj *framebuffer = GrDebugGL::getInstance()->getFrameBuffer(); |
| 328 | // A render buffer cannot be attached to the default framebuffer |
| 329 | GrAlwaysAssert(NULL != framebuffer); |
| 330 | |
| 331 | // a renderBufferID of 0 is acceptable - it unbinds the current render buffer |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 332 | GrRenderBufferObj *renderbuffer = GR_FIND(renderBufferID, GrRenderBufferObj, GrDebugGL::kRenderBuffer_ObjTypes); |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 333 | |
| 334 | switch (attachment) { |
| 335 | case GR_GL_COLOR_ATTACHMENT0: |
| 336 | framebuffer->setColor(renderbuffer); |
| 337 | break; |
| 338 | case GR_GL_DEPTH_ATTACHMENT: |
| 339 | framebuffer->setDepth(renderbuffer); |
| 340 | break; |
| 341 | case GR_GL_STENCIL_ATTACHMENT: |
| 342 | framebuffer->setStencil(renderbuffer); |
| 343 | break; |
| 344 | default: |
| 345 | GrAlwaysAssert(false); |
| 346 | break; |
| 347 | }; |
| 348 | |
| 349 | } |
| 350 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 351 | //////////////////////////////////////////////////////////////////////////////// |
| 352 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLFramebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint textureID, GrGLint level) { |
| 353 | |
| 354 | GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); |
| 355 | GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment || |
| 356 | GR_GL_DEPTH_ATTACHMENT == attachment || |
| 357 | GR_GL_STENCIL_ATTACHMENT == attachment); |
| 358 | GrAlwaysAssert(GR_GL_TEXTURE_2D == textarget); |
| 359 | |
| 360 | GrFrameBufferObj *framebuffer = GrDebugGL::getInstance()->getFrameBuffer(); |
| 361 | // A texture cannot be attached to the default framebuffer |
| 362 | GrAlwaysAssert(NULL != framebuffer); |
| 363 | |
| 364 | // A textureID of 0 is allowed - it unbinds the currently bound texture |
| 365 | GrTextureObj *texture = GR_FIND(textureID, GrTextureObj, GrDebugGL::kTexture_ObjTypes); |
| 366 | if (texture) { |
| 367 | // The texture shouldn't be bound to a texture unit - this could lead to a feedback loop |
| 368 | GrAlwaysAssert(!texture->getBound()); |
| 369 | } |
| 370 | |
| 371 | GrAlwaysAssert(0 == level); |
| 372 | |
| 373 | switch (attachment) { |
| 374 | case GR_GL_COLOR_ATTACHMENT0: |
| 375 | framebuffer->setColor(texture); |
| 376 | break; |
| 377 | case GR_GL_DEPTH_ATTACHMENT: |
| 378 | framebuffer->setDepth(texture); |
| 379 | break; |
| 380 | case GR_GL_STENCIL_ATTACHMENT: |
| 381 | framebuffer->setStencil(texture); |
| 382 | break; |
| 383 | default: |
| 384 | GrAlwaysAssert(false); |
| 385 | break; |
| 386 | }; |
| 387 | } |
| 388 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 389 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetFramebufferAttachmentParameteriv(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params) {} |
| 390 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetRenderbufferParameteriv(GrGLenum target, GrGLenum pname, GrGLint* params) {} |
| 391 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLRenderbufferStorage(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height) {} |
| 392 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLRenderbufferStorageMultisample(GrGLenum target, GrGLsizei samples, GrGLenum internalformat, GrGLsizei width, GrGLsizei height) {} |
| 393 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBlitFramebuffer(GrGLint srcX0, GrGLint srcY0, GrGLint srcX1, GrGLint srcY1, GrGLint dstX0, GrGLint dstY0, GrGLint dstX1, GrGLint dstY1, GrGLbitfield mask, GrGLenum filter) {} |
| 394 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLResolveMultisampleFramebuffer() {} |
| 395 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindFragDataLocationIndexed(GrGLuint program, GrGLuint colorNumber, GrGLuint index, const GrGLchar * name) {} |
| 396 | |
| 397 | GrGLenum GR_GL_FUNCTION_TYPE debugGLCheckFramebufferStatus(GrGLenum target) { |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 398 | |
| 399 | GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); |
| 400 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 401 | return GR_GL_FRAMEBUFFER_COMPLETE; |
| 402 | } |
| 403 | |
| 404 | GrGLuint GR_GL_FUNCTION_TYPE debugGLCreateProgram() { |
| 405 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 406 | GrProgramObj *program = GR_CREATE(GrProgramObj, GrDebugGL::kProgram_ObjTypes); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 407 | |
| 408 | return program->getID(); |
| 409 | } |
| 410 | |
| 411 | GrGLuint GR_GL_FUNCTION_TYPE debugGLCreateShader(GrGLenum type) { |
| 412 | |
| 413 | GrAlwaysAssert(GR_GL_VERTEX_SHADER == type || GR_GL_FRAGMENT_SHADER == type); |
| 414 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 415 | GrShaderObj *shader = GR_CREATE(GrShaderObj, GrDebugGL::kShader_ObjTypes); |
| 416 | shader->setType(type); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 417 | |
| 418 | return shader->getID(); |
| 419 | } |
| 420 | |
| 421 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteProgram(GrGLuint programID) { |
| 422 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 423 | GrProgramObj *program = GR_FIND(programID, GrProgramObj, GrDebugGL::kProgram_ObjTypes); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 424 | GrAlwaysAssert(program); |
| 425 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 426 | if (program->getRefCount()) { |
| 427 | // someone is still using this program so we can't delete it here |
| 428 | program->setMarkedForDeletion(); |
| 429 | } else { |
| 430 | program->deleteAction(); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteShader(GrGLuint shaderID) { |
| 435 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 436 | GrShaderObj *shader = GR_FIND(shaderID, GrShaderObj, GrDebugGL::kShader_ObjTypes); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 437 | GrAlwaysAssert(shader); |
| 438 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 439 | if (shader->getRefCount()) { |
| 440 | // someone is still using this shader so we can't delete it here |
| 441 | shader->setMarkedForDeletion(); |
| 442 | } else { |
| 443 | shader->deleteAction(); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | // same function used for all glGen*(GLsize i, GLuint*) functions |
| 448 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenIds(GrGLsizei n, GrGLuint* ids) { |
| 449 | static int gCurrID = 1; |
| 450 | for (int i = 0; i < n; ++i) { |
| 451 | ids[i] = ++gCurrID; |
| 452 | } |
| 453 | } |
| 454 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 455 | GrGLvoid debugGenObjs(GrDebugGL::GrObjTypes type, GrGLsizei n, GrGLuint* ids) { |
| 456 | |
| 457 | for (int i = 0; i < n; ++i) { |
| 458 | GrFakeRefObj *obj = GrDebugGL::getInstance()->createObj(type); |
| 459 | GrAlwaysAssert(obj); |
| 460 | ids[i] = obj->getID(); |
| 461 | } |
| 462 | } |
| 463 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 464 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenBuffers(GrGLsizei n, GrGLuint* ids) { |
| 465 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 466 | debugGenObjs(GrDebugGL::kBuffer_ObjTypes, n, ids); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 467 | } |
| 468 | |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 469 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenFramebuffers(GrGLsizei n, GrGLuint* ids) { |
| 470 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 471 | debugGenObjs(GrDebugGL::kFrameBuffer_ObjTypes, n, ids); |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 472 | } |
| 473 | |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 474 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenRenderbuffers(GrGLsizei n, GrGLuint* ids) { |
| 475 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 476 | debugGenObjs(GrDebugGL::kRenderBuffer_ObjTypes, n, ids); |
| 477 | } |
| 478 | |
| 479 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenTextures(GrGLsizei n, GrGLuint* ids) { |
| 480 | |
| 481 | debugGenObjs(GrDebugGL::kTexture_ObjTypes, n, ids); |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 482 | } |
| 483 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 484 | // same delete function for all glDelete*(GLsize i, const GLuint*) except buffers |
| 485 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteIds(GrGLsizei n, const GrGLuint* ids) {} |
| 486 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 487 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindBuffer(GrGLenum target, GrGLuint bufferID) { |
| 488 | |
| 489 | GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || GR_GL_ELEMENT_ARRAY_BUFFER == target); |
| 490 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 491 | GrBufferObj *buffer = GR_FIND(bufferID, GrBufferObj, GrDebugGL::kBuffer_ObjTypes); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 492 | // 0 is a permissable bufferID - it unbinds the current buffer |
| 493 | |
| 494 | switch (target) { |
| 495 | case GR_GL_ARRAY_BUFFER: |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 496 | GrDebugGL::getInstance()->setArrayBuffer(buffer); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 497 | break; |
| 498 | case GR_GL_ELEMENT_ARRAY_BUFFER: |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 499 | GrDebugGL::getInstance()->setElementArrayBuffer(buffer); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 500 | break; |
| 501 | default: |
| 502 | GrCrash("Unexpected target to glBindBuffer"); |
| 503 | break; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | // deleting a bound buffer has the side effect of binding 0 |
| 508 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteBuffers(GrGLsizei n, const GrGLuint* ids) { |
| 509 | // first potentially unbind the buffers |
| 510 | for (int i = 0; i < n; ++i) { |
| 511 | |
| 512 | if (GrDebugGL::getInstance()->getArrayBuffer() && |
| 513 | ids[i] == GrDebugGL::getInstance()->getArrayBuffer()->getID()) { |
| 514 | // this ID is the current array buffer |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 515 | GrDebugGL::getInstance()->setArrayBuffer(NULL); |
| 516 | } |
| 517 | if (GrDebugGL::getInstance()->getElementArrayBuffer() && |
| 518 | ids[i] == GrDebugGL::getInstance()->getElementArrayBuffer()->getID()) { |
| 519 | // this ID is the current element array buffer |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 520 | GrDebugGL::getInstance()->setElementArrayBuffer(NULL); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | // then actually "delete" the buffers |
| 525 | for (int i = 0; i < n; ++i) { |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 526 | GrBufferObj *buffer = GR_FIND(ids[i], GrBufferObj, GrDebugGL::kBuffer_ObjTypes); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 527 | GrAlwaysAssert(buffer); |
| 528 | |
| 529 | GrAlwaysAssert(!buffer->getDeleted()); |
| 530 | buffer->deleteAction(); |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | // map a buffer to the caller's address space |
| 535 | GrGLvoid* GR_GL_FUNCTION_TYPE debugGLMapBuffer(GrGLenum target, GrGLenum access) { |
| 536 | |
| 537 | GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || GR_GL_ELEMENT_ARRAY_BUFFER == target); |
| 538 | GrAlwaysAssert(GR_GL_WRITE_ONLY == access); // GR_GL_READ_ONLY == access || || GR_GL_READ_WRIT == access); |
| 539 | |
| 540 | GrBufferObj *buffer = NULL; |
| 541 | switch (target) { |
| 542 | case GR_GL_ARRAY_BUFFER: |
| 543 | buffer = GrDebugGL::getInstance()->getArrayBuffer(); |
| 544 | break; |
| 545 | case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 546 | buffer = GrDebugGL::getInstance()->getElementArrayBuffer(); |
| 547 | break; |
| 548 | default: |
| 549 | GrCrash("Unexpected target to glMapBuffer"); |
| 550 | break; |
| 551 | } |
| 552 | |
| 553 | if (buffer) { |
| 554 | GrAlwaysAssert(!buffer->getMapped()); |
| 555 | buffer->setMapped(); |
| 556 | return buffer->getDataPtr(); |
| 557 | } |
| 558 | |
| 559 | GrAlwaysAssert(false); |
| 560 | return NULL; // no buffer bound to the target |
| 561 | } |
| 562 | |
| 563 | // remove a buffer from the caller's address space |
| 564 | // TODO: check if the "access" method from "glMapBuffer" was honored |
| 565 | GrGLboolean GR_GL_FUNCTION_TYPE debugGLUnmapBuffer(GrGLenum target) { |
| 566 | |
| 567 | GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || GR_GL_ELEMENT_ARRAY_BUFFER == target); |
| 568 | |
| 569 | GrBufferObj *buffer = NULL; |
| 570 | switch (target) { |
| 571 | case GR_GL_ARRAY_BUFFER: |
| 572 | buffer = GrDebugGL::getInstance()->getArrayBuffer(); |
| 573 | break; |
| 574 | case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 575 | buffer = GrDebugGL::getInstance()->getElementArrayBuffer(); |
| 576 | break; |
| 577 | default: |
| 578 | GrCrash("Unexpected target to glUnmapBuffer"); |
| 579 | break; |
| 580 | } |
| 581 | |
| 582 | if (buffer) { |
| 583 | GrAlwaysAssert(buffer->getMapped()); |
| 584 | buffer->resetMapped(); |
| 585 | return GR_GL_TRUE; |
| 586 | } |
| 587 | |
| 588 | GrAlwaysAssert(false); |
| 589 | return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; |
| 590 | } |
| 591 | |
| 592 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetBufferParameteriv(GrGLenum target, GrGLenum value, GrGLint* params) { |
| 593 | |
| 594 | GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || GR_GL_ELEMENT_ARRAY_BUFFER == target); |
| 595 | GrAlwaysAssert(GR_GL_BUFFER_SIZE == value || GR_GL_BUFFER_USAGE == value); |
| 596 | |
| 597 | GrBufferObj *buffer = NULL; |
| 598 | switch (target) { |
| 599 | case GR_GL_ARRAY_BUFFER: |
| 600 | buffer = GrDebugGL::getInstance()->getArrayBuffer(); |
| 601 | break; |
| 602 | case GR_GL_ELEMENT_ARRAY_BUFFER: |
| 603 | buffer = GrDebugGL::getInstance()->getElementArrayBuffer(); |
| 604 | break; |
| 605 | } |
| 606 | |
| 607 | GrAlwaysAssert(buffer); |
| 608 | |
| 609 | switch (value) { |
| 610 | case GR_GL_BUFFER_MAPPED: |
| 611 | *params = GR_GL_FALSE; |
| 612 | if (buffer) |
| 613 | *params = buffer->getMapped() ? GR_GL_TRUE : GR_GL_FALSE; |
| 614 | break; |
| 615 | case GR_GL_BUFFER_SIZE: |
| 616 | *params = 0; |
| 617 | if (buffer) |
| 618 | *params = buffer->getSize(); |
| 619 | break; |
| 620 | case GR_GL_BUFFER_USAGE: |
| 621 | *params = GR_GL_STATIC_DRAW; |
| 622 | if (buffer) |
| 623 | *params = buffer->getUsage(); |
| 624 | break; |
| 625 | default: |
| 626 | GrCrash("Unexpected value to glGetBufferParamateriv"); |
| 627 | break; |
| 628 | } |
| 629 | }; |
| 630 | |
| 631 | GrGLenum GR_GL_FUNCTION_TYPE debugGLGetError() { |
| 632 | return GR_GL_NO_ERROR; |
| 633 | } |
| 634 | |
| 635 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetIntegerv(GrGLenum pname, GrGLint* params) { |
| 636 | // TODO: remove from Ganesh the #defines for gets we don't use. |
| 637 | // We would like to minimize gets overall due to performance issues |
| 638 | switch (pname) { |
| 639 | case GR_GL_STENCIL_BITS: |
| 640 | *params = 8; |
| 641 | break; |
| 642 | case GR_GL_SAMPLES: |
| 643 | *params = 1; |
| 644 | break; |
| 645 | case GR_GL_FRAMEBUFFER_BINDING: |
| 646 | *params = 0; |
| 647 | break; |
| 648 | case GR_GL_VIEWPORT: |
| 649 | params[0] = 0; |
| 650 | params[1] = 0; |
| 651 | params[2] = 800; |
| 652 | params[3] = 600; |
| 653 | break; |
| 654 | case GR_GL_MAX_TEXTURE_IMAGE_UNITS: |
| 655 | *params = 8; |
| 656 | break; |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 657 | case GR_GL_MAX_VERTEX_UNIFORM_VECTORS: |
| 658 | *params = kDefaultMaxVertexUniformVectors; |
| 659 | break; |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 660 | case GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS: |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 661 | *params = kDefaultMaxFragmentUniformVectors; |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 662 | break; |
| 663 | case GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS: |
| 664 | *params = 16 * 4; |
| 665 | break; |
| 666 | case GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 667 | *params = 0; |
| 668 | break; |
| 669 | case GR_GL_COMPRESSED_TEXTURE_FORMATS: |
| 670 | break; |
| 671 | case GR_GL_MAX_TEXTURE_SIZE: |
| 672 | *params = 8192; |
| 673 | break; |
| 674 | case GR_GL_MAX_RENDERBUFFER_SIZE: |
| 675 | *params = 8192; |
| 676 | break; |
| 677 | case GR_GL_MAX_SAMPLES: |
| 678 | *params = 32; |
| 679 | break; |
| 680 | case GR_GL_MAX_VERTEX_ATTRIBS: |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 681 | *params = kDefaultMaxVertexAttribs; |
| 682 | break; |
| 683 | case GR_GL_MAX_VARYING_VECTORS: |
| 684 | *params = kDefaultMaxVaryingVectors; |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 685 | break; |
| 686 | case GR_GL_MAX_TEXTURE_UNITS: |
| 687 | *params = GrDebugGL::getInstance()->getMaxTextureUnits(); |
| 688 | break; |
| 689 | default: |
| 690 | GrCrash("Unexpected pname to GetIntegerv"); |
| 691 | } |
| 692 | } |
| 693 | // used for both the program and shader info logs |
| 694 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetInfoLog(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, char* infolog) { |
| 695 | if (length) { |
| 696 | *length = 0; |
| 697 | } |
| 698 | if (bufsize > 0) { |
| 699 | *infolog = 0; |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | // used for both the program and shader params |
| 704 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetShaderOrProgramiv(GrGLuint program, GrGLenum pname, GrGLint* params) { |
| 705 | switch (pname) { |
| 706 | case GR_GL_LINK_STATUS: // fallthru |
| 707 | case GR_GL_COMPILE_STATUS: |
| 708 | *params = GR_GL_TRUE; |
| 709 | break; |
| 710 | case GR_GL_INFO_LOG_LENGTH: |
| 711 | *params = 0; |
| 712 | break; |
| 713 | // we don't expect any other pnames |
| 714 | default: |
| 715 | GrCrash("Unexpected pname to GetProgramiv"); |
| 716 | break; |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | namespace { |
| 721 | template <typename T> |
| 722 | void query_result(GrGLenum GLtarget, GrGLenum pname, T *params) { |
| 723 | switch (pname) { |
| 724 | case GR_GL_QUERY_RESULT_AVAILABLE: |
| 725 | *params = GR_GL_TRUE; |
| 726 | break; |
| 727 | case GR_GL_QUERY_RESULT: |
| 728 | *params = 0; |
| 729 | break; |
| 730 | default: |
| 731 | GrCrash("Unexpected pname passed to GetQueryObject."); |
| 732 | break; |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | // Queries on the null GL just don't do anything at all. We could potentially make |
| 738 | // the timers work. |
| 739 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryiv(GrGLenum GLtarget, GrGLenum pname, GrGLint *params) { |
| 740 | switch (pname) { |
| 741 | case GR_GL_CURRENT_QUERY: |
| 742 | *params = 0; |
| 743 | break; |
| 744 | case GR_GL_QUERY_COUNTER_BITS: |
| 745 | *params = 32; |
| 746 | break; |
| 747 | default: |
| 748 | GrCrash("Unexpected pname passed GetQueryiv."); |
| 749 | } |
| 750 | } |
| 751 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryObjecti64v(GrGLuint id, GrGLenum pname, GrGLint64 *params) { |
| 752 | query_result(id, pname, params); |
| 753 | } |
| 754 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryObjectiv(GrGLuint id, GrGLenum pname, GrGLint *params) { |
| 755 | query_result(id, pname, params); |
| 756 | } |
| 757 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryObjectui64v(GrGLuint id, GrGLenum pname, GrGLuint64 *params) { |
| 758 | query_result(id, pname, params); |
| 759 | } |
| 760 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryObjectuiv(GrGLuint id, GrGLenum pname, GrGLuint *params) { |
| 761 | query_result(id, pname, params); |
| 762 | } |
| 763 | |
| 764 | const GrGLubyte* GR_GL_FUNCTION_TYPE debugGLGetString(GrGLenum name) { |
| 765 | switch (name) { |
| 766 | case GR_GL_EXTENSIONS: |
| 767 | return (const GrGLubyte*)"GL_ARB_framebuffer_object GL_ARB_blend_func_extended GL_ARB_timer_query GL_ARB_draw_buffers GL_ARB_occlusion_query GL_EXT_blend_color GL_EXT_stencil_wrap"; |
| 768 | case GR_GL_VERSION: |
| 769 | return (const GrGLubyte*)"4.0 Null GL"; |
| 770 | case GR_GL_SHADING_LANGUAGE_VERSION: |
| 771 | return (const GrGLubyte*)"4.20.8 Null GLSL"; |
| 772 | default: |
| 773 | GrCrash("Unexpected name to GetString"); |
| 774 | return NULL; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | // we used to use this to query stuff about externally created textures, now we just |
| 779 | // require clients to tell us everything about the texture. |
| 780 | GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetTexLevelParameteriv(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint* params) { |
| 781 | GrCrash("Should never query texture parameters."); |
| 782 | } |
| 783 | |
| 784 | GrGLint GR_GL_FUNCTION_TYPE debugGLGetUniformLocation(GrGLuint program, const char* name) { |
| 785 | static int gUniLocation = 0; |
| 786 | return ++gUniLocation; |
| 787 | } |
| 788 | |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 789 | //////////////////////////////////////////////////////////////////////////////// |
| 790 | struct GrDebugGLInterface : public GrGLInterface { |
| 791 | |
| 792 | public: |
| 793 | GrDebugGLInterface() |
| 794 | : fWrapped(NULL) { |
| 795 | } |
| 796 | |
| 797 | void setWrapped(GrGLInterface *interface) { |
| 798 | fWrapped.reset(interface); |
| 799 | } |
| 800 | |
| 801 | // TODO: there are some issues w/ wrapping another GL interface inside the |
| 802 | // debug interface: |
| 803 | // Since none of the "gl" methods are member functions they don't get |
| 804 | // a "this" pointer through which to access "fWrapped" |
| 805 | // This could be worked around by having all of them access the |
| 806 | // "glInterface" pointer - i.e., treating the debug interface as a |
| 807 | // true singleton |
| 808 | // |
| 809 | // The problem with this is that we also want to handle OpenGL |
| 810 | // contexts. The natural way to do this is to have multiple debug |
| 811 | // interfaces. Each of which represents a separate context. The |
| 812 | // static ID count would still uniquify IDs across all of them. |
| 813 | // The problem then is that we couldn't treat the debug GL |
| 814 | // interface as a singleton (since there would be one for each |
| 815 | // context). |
| 816 | // |
| 817 | // The solution to this is probably to alter SkDebugGlContext's |
| 818 | // "makeCurrent" method to make a call like "makeCurrent(this)" to |
| 819 | // the debug GL interface (assuming that the application will create |
| 820 | // multiple SkGLContext's) to let it switch between the active |
| 821 | // context. Everything in the GrDebugGL object would then need to be |
| 822 | // moved to a GrContextObj and the GrDebugGL object would just switch |
| 823 | // between them. Note that this approach would also require that |
| 824 | // SkDebugGLContext wrap an arbitrary other context |
| 825 | // and then pass the wrapped interface to the debug GL interface. |
| 826 | |
| 827 | protected: |
| 828 | private: |
| 829 | |
| 830 | SkAutoTUnref<GrGLInterface> fWrapped; |
| 831 | |
| 832 | typedef GrGLInterface INHERITED; |
| 833 | }; |
| 834 | |
| 835 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 836 | const GrGLInterface* GrGLCreateDebugInterface() { |
| 837 | // The gl functions are not context-specific so we create one global |
| 838 | // interface |
| 839 | static SkAutoTUnref<GrGLInterface> glInterface; |
| 840 | if (!glInterface.get()) { |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 841 | GrGLInterface* interface = new GrDebugGLInterface; |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 842 | glInterface.reset(interface); |
| 843 | interface->fBindingsExported = kDesktop_GrGLBinding; |
| 844 | interface->fActiveTexture = debugGLActiveTexture; |
| 845 | interface->fAttachShader = debugGLAttachShader; |
| 846 | interface->fBeginQuery = debugGLBeginQuery; |
| 847 | interface->fBindAttribLocation = debugGLBindAttribLocation; |
| 848 | interface->fBindBuffer = debugGLBindBuffer; |
| 849 | interface->fBindFragDataLocation = debugGLBindFragDataLocation; |
| 850 | interface->fBindTexture = debugGLBindTexture; |
| 851 | interface->fBlendColor = debugGLBlendColor; |
| 852 | interface->fBlendFunc = debugGLBlendFunc; |
| 853 | interface->fBufferData = debugGLBufferData; |
| 854 | interface->fBufferSubData = debugGLBufferSubData; |
| 855 | interface->fClear = debugGLClear; |
| 856 | interface->fClearColor = debugGLClearColor; |
| 857 | interface->fClearStencil = debugGLClearStencil; |
| 858 | interface->fColorMask = debugGLColorMask; |
| 859 | interface->fCompileShader = debugGLCompileShader; |
| 860 | interface->fCompressedTexImage2D = debugGLCompressedTexImage2D; |
| 861 | interface->fCreateProgram = debugGLCreateProgram; |
| 862 | interface->fCreateShader = debugGLCreateShader; |
| 863 | interface->fCullFace = debugGLCullFace; |
| 864 | interface->fDeleteBuffers = debugGLDeleteBuffers; |
| 865 | interface->fDeleteProgram = debugGLDeleteProgram; |
| 866 | interface->fDeleteQueries = debugGLDeleteIds; |
| 867 | interface->fDeleteShader = debugGLDeleteShader; |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 868 | interface->fDeleteTextures = debugGLDeleteTextures; |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 869 | interface->fDepthMask = debugGLDepthMask; |
| 870 | interface->fDisable = debugGLDisable; |
| 871 | interface->fDisableVertexAttribArray = debugGLDisableVertexAttribArray; |
| 872 | interface->fDrawArrays = debugGLDrawArrays; |
| 873 | interface->fDrawBuffer = debugGLDrawBuffer; |
| 874 | interface->fDrawBuffers = debugGLDrawBuffers; |
| 875 | interface->fDrawElements = debugGLDrawElements; |
| 876 | interface->fEnable = debugGLEnable; |
| 877 | interface->fEnableVertexAttribArray = debugGLEnableVertexAttribArray; |
| 878 | interface->fEndQuery = debugGLEndQuery; |
| 879 | interface->fFinish = debugGLFinish; |
| 880 | interface->fFlush = debugGLFlush; |
| 881 | interface->fFrontFace = debugGLFrontFace; |
| 882 | interface->fGenBuffers = debugGLGenBuffers; |
| 883 | interface->fGenQueries = debugGLGenIds; |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 884 | interface->fGenTextures = debugGLGenTextures; |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 885 | interface->fGetBufferParameteriv = debugGLGetBufferParameteriv; |
| 886 | interface->fGetError = debugGLGetError; |
| 887 | interface->fGetIntegerv = debugGLGetIntegerv; |
| 888 | interface->fGetQueryObjecti64v = debugGLGetQueryObjecti64v; |
| 889 | interface->fGetQueryObjectiv = debugGLGetQueryObjectiv; |
| 890 | interface->fGetQueryObjectui64v = debugGLGetQueryObjectui64v; |
| 891 | interface->fGetQueryObjectuiv = debugGLGetQueryObjectuiv; |
| 892 | interface->fGetQueryiv = debugGLGetQueryiv; |
| 893 | interface->fGetProgramInfoLog = debugGLGetInfoLog; |
| 894 | interface->fGetProgramiv = debugGLGetShaderOrProgramiv; |
| 895 | interface->fGetShaderInfoLog = debugGLGetInfoLog; |
| 896 | interface->fGetShaderiv = debugGLGetShaderOrProgramiv; |
| 897 | interface->fGetString = debugGLGetString; |
| 898 | interface->fGetTexLevelParameteriv = debugGLGetTexLevelParameteriv; |
| 899 | interface->fGetUniformLocation = debugGLGetUniformLocation; |
| 900 | interface->fLineWidth = debugGLLineWidth; |
| 901 | interface->fLinkProgram = debugGLLinkProgram; |
| 902 | interface->fPixelStorei = debugGLPixelStorei; |
| 903 | interface->fQueryCounter = debugGLQueryCounter; |
| 904 | interface->fReadBuffer = debugGLReadBuffer; |
| 905 | interface->fReadPixels = debugGLReadPixels; |
| 906 | interface->fScissor = debugGLScissor; |
| 907 | interface->fShaderSource = debugGLShaderSource; |
| 908 | interface->fStencilFunc = debugGLStencilFunc; |
| 909 | interface->fStencilFuncSeparate = debugGLStencilFuncSeparate; |
| 910 | interface->fStencilMask = debugGLStencilMask; |
| 911 | interface->fStencilMaskSeparate = debugGLStencilMaskSeparate; |
| 912 | interface->fStencilOp = debugGLStencilOp; |
| 913 | interface->fStencilOpSeparate = debugGLStencilOpSeparate; |
| 914 | interface->fTexImage2D = debugGLTexImage2D; |
| 915 | interface->fTexParameteri = debugGLTexParameteri; |
| 916 | interface->fTexSubImage2D = debugGLTexSubImage2D; |
| 917 | interface->fTexStorage2D = debugGLTexStorage2D; |
| 918 | interface->fUniform1f = debugGLUniform1f; |
| 919 | interface->fUniform1i = debugGLUniform1i; |
| 920 | interface->fUniform1fv = debugGLUniform1fv; |
| 921 | interface->fUniform1iv = debugGLUniform1iv; |
| 922 | interface->fUniform2f = debugGLUniform2f; |
| 923 | interface->fUniform2i = debugGLUniform2i; |
| 924 | interface->fUniform2fv = debugGLUniform2fv; |
| 925 | interface->fUniform2iv = debugGLUniform2iv; |
| 926 | interface->fUniform3f = debugGLUniform3f; |
| 927 | interface->fUniform3i = debugGLUniform3i; |
| 928 | interface->fUniform3fv = debugGLUniform3fv; |
| 929 | interface->fUniform3iv = debugGLUniform3iv; |
| 930 | interface->fUniform4f = debugGLUniform4f; |
| 931 | interface->fUniform4i = debugGLUniform4i; |
| 932 | interface->fUniform4fv = debugGLUniform4fv; |
| 933 | interface->fUniform4iv = debugGLUniform4iv; |
| 934 | interface->fUniformMatrix2fv = debugGLUniformMatrix2fv; |
| 935 | interface->fUniformMatrix3fv = debugGLUniformMatrix3fv; |
| 936 | interface->fUniformMatrix4fv = debugGLUniformMatrix4fv; |
| 937 | interface->fUseProgram = debugGLUseProgram; |
| 938 | interface->fVertexAttrib4fv = debugGLVertexAttrib4fv; |
| 939 | interface->fVertexAttribPointer = debugGLVertexAttribPointer; |
| 940 | interface->fViewport = debugGLViewport; |
| 941 | interface->fBindFramebuffer = debugGLBindFramebuffer; |
| 942 | interface->fBindRenderbuffer = debugGLBindRenderbuffer; |
| 943 | interface->fCheckFramebufferStatus = debugGLCheckFramebufferStatus; |
| 944 | interface->fDeleteFramebuffers = debugGLDeleteFramebuffers; |
| 945 | interface->fDeleteRenderbuffers = debugGLDeleteRenderbuffers; |
| 946 | interface->fFramebufferRenderbuffer = debugGLFramebufferRenderbuffer; |
| 947 | interface->fFramebufferTexture2D = debugGLFramebufferTexture2D; |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 948 | interface->fGenFramebuffers = debugGLGenFramebuffers; |
robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 949 | interface->fGenRenderbuffers = debugGLGenRenderbuffers; |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 950 | interface->fGetFramebufferAttachmentParameteriv = debugGLGetFramebufferAttachmentParameteriv; |
| 951 | interface->fGetRenderbufferParameteriv = debugGLGetRenderbufferParameteriv; |
| 952 | interface->fRenderbufferStorage = debugGLRenderbufferStorage; |
| 953 | interface->fRenderbufferStorageMultisample = debugGLRenderbufferStorageMultisample; |
| 954 | interface->fBlitFramebuffer = debugGLBlitFramebuffer; |
| 955 | interface->fResolveMultisampleFramebuffer = debugGLResolveMultisampleFramebuffer; |
| 956 | interface->fMapBuffer = debugGLMapBuffer; |
| 957 | interface->fUnmapBuffer = debugGLUnmapBuffer; |
| 958 | interface->fBindFragDataLocationIndexed = debugGLBindFragDataLocationIndexed; |
| 959 | } |
| 960 | glInterface.get()->ref(); |
| 961 | return glInterface.get(); |
| 962 | } |