blob: 77a1422af173212a3bf7178295e2906929b5e875 [file] [log] [blame]
robertphillips@google.com0da37192012-03-19 14:42:13 +00001
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.comdd743fe2012-04-05 14:40:53 +000011#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"
bsalomon@google.comecd84842013-03-01 15:36:02 +000019#include "GrVertexArrayObj.h"
robertphillips@google.com670ff9a2012-04-12 19:53:31 +000020#include "SkFloatingPoint.h"
bsalomon@google.com8f943612013-02-26 14:34:43 +000021#include "../GrGLNoOpInterface.h"
robertphillips@google.com0da37192012-03-19 14:42:13 +000022
bsalomon@google.com8f943612013-02-26 14:34:43 +000023namespace { // suppress no previous prototype warning
caryclark@google.comcf6285b2012-06-06 12:09:01 +000024
robertphillips@google.com0da37192012-03-19 14:42:13 +000025////////////////////////////////////////////////////////////////////////////////
robertphillips@google.comf6f123d2012-03-21 17:57:55 +000026GrGLvoid GR_GL_FUNCTION_TYPE debugGLActiveTexture(GrGLenum texture) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +000027
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000028 // Ganesh offsets the texture unit indices
29 texture -= GR_GL_TEXTURE0;
30 GrAlwaysAssert(texture < GrDebugGL::getInstance()->getMaxTextureUnits());
robertphillips@google.com0da37192012-03-19 14:42:13 +000031
32 GrDebugGL::getInstance()->setCurTextureUnit(texture);
33}
34
35////////////////////////////////////////////////////////////////////////////////
rmistry@google.comfbfcd562012-08-23 18:09:54 +000036GrGLvoid GR_GL_FUNCTION_TYPE debugGLAttachShader(GrGLuint programID,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000037 GrGLuint shaderID) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000038
rmistry@google.comfbfcd562012-08-23 18:09:54 +000039 GrProgramObj *program = GR_FIND(programID, GrProgramObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000040 GrDebugGL::kProgram_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +000041 GrAlwaysAssert(program);
42
rmistry@google.comfbfcd562012-08-23 18:09:54 +000043 GrShaderObj *shader = GR_FIND(shaderID,
44 GrShaderObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000045 GrDebugGL::kShader_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +000046 GrAlwaysAssert(shader);
47
48 program->AttachShader(shader);
49}
50
robertphillips@google.comebde3e02012-07-13 17:45:17 +000051GrGLvoid GR_GL_FUNCTION_TYPE debugGLBeginQuery(GrGLenum target, GrGLuint id) {
52}
53
rmistry@google.comfbfcd562012-08-23 18:09:54 +000054GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindAttribLocation(GrGLuint program,
55 GrGLuint index,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000056 const char* name) {
57}
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000058
59////////////////////////////////////////////////////////////////////////////////
rmistry@google.comfbfcd562012-08-23 18:09:54 +000060GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindTexture(GrGLenum target,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000061 GrGLuint textureID) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000062
63 // we don't use cube maps
rmistry@google.comfbfcd562012-08-23 18:09:54 +000064 GrAlwaysAssert(target == GR_GL_TEXTURE_2D);
robertphillips@google.comebde3e02012-07-13 17:45:17 +000065 // || target == GR_GL_TEXTURE_CUBE_MAP);
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000066
67 // a textureID of 0 is acceptable - it binds to the default texture target
rmistry@google.comfbfcd562012-08-23 18:09:54 +000068 GrTextureObj *texture = GR_FIND(textureID, GrTextureObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000069 GrDebugGL::kTexture_ObjTypes);
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000070
71 GrDebugGL::getInstance()->setTexture(texture);
72}
73
robertphillips@google.com0da37192012-03-19 14:42:13 +000074
75////////////////////////////////////////////////////////////////////////////////
rmistry@google.comfbfcd562012-08-23 18:09:54 +000076GrGLvoid GR_GL_FUNCTION_TYPE debugGLBufferData(GrGLenum target,
77 GrGLsizeiptr size,
78 const GrGLvoid* data,
robertphillips@google.com409566a2012-06-26 20:19:41 +000079 GrGLenum usage) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +000080 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +000081 GR_GL_ELEMENT_ARRAY_BUFFER == target);
robertphillips@google.com0da37192012-03-19 14:42:13 +000082 GrAlwaysAssert(size >= 0);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000083 GrAlwaysAssert(GR_GL_STREAM_DRAW == usage ||
84 GR_GL_STATIC_DRAW == usage ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +000085 GR_GL_DYNAMIC_DRAW == usage);
robertphillips@google.com0da37192012-03-19 14:42:13 +000086
87 GrBufferObj *buffer = NULL;
88 switch (target) {
89 case GR_GL_ARRAY_BUFFER:
90 buffer = GrDebugGL::getInstance()->getArrayBuffer();
91 break;
92 case GR_GL_ELEMENT_ARRAY_BUFFER:
93 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
94 break;
95 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +000096 SkFAIL("Unexpected target to glBufferData");
robertphillips@google.com0da37192012-03-19 14:42:13 +000097 break;
98 }
99
100 GrAlwaysAssert(buffer);
101 GrAlwaysAssert(buffer->getBound());
102
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000103 buffer->allocate(size, reinterpret_cast<const GrGLchar *>(data));
robertphillips@google.com0da37192012-03-19 14:42:13 +0000104 buffer->setUsage(usage);
105}
106
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000107
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000108GrGLvoid GR_GL_FUNCTION_TYPE debugGLPixelStorei(GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000109 GrGLint param) {
robertphillips@google.com670ff9a2012-04-12 19:53:31 +0000110
111 switch (pname) {
112 case GR_GL_UNPACK_ROW_LENGTH:
113 GrDebugGL::getInstance()->setUnPackRowLength(param);
114 break;
115 case GR_GL_PACK_ROW_LENGTH:
116 GrDebugGL::getInstance()->setPackRowLength(param);
117 break;
118 case GR_GL_UNPACK_ALIGNMENT:
119 break;
120 case GR_GL_PACK_ALIGNMENT:
121 GrAlwaysAssert(false);
122 break;
123 default:
124 GrAlwaysAssert(false);
125 break;
126 }
127}
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000128
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000129GrGLvoid GR_GL_FUNCTION_TYPE debugGLReadPixels(GrGLint x,
130 GrGLint y,
131 GrGLsizei width,
132 GrGLsizei height,
133 GrGLenum format,
134 GrGLenum type,
robertphillips@google.com670ff9a2012-04-12 19:53:31 +0000135 GrGLvoid* pixels) {
136
137 GrGLint pixelsInRow = width;
138 if (0 < GrDebugGL::getInstance()->getPackRowLength()) {
139 pixelsInRow = GrDebugGL::getInstance()->getPackRowLength();
140 }
141
142 GrGLint componentsPerPixel = 0;
143
144 switch (format) {
145 case GR_GL_RGBA:
146 // fallthrough
147 case GR_GL_BGRA:
148 componentsPerPixel = 4;
149 break;
150 case GR_GL_RGB:
151 componentsPerPixel = 3;
152 break;
robertphillips@google.comd32369e2012-05-30 14:46:10 +0000153 case GR_GL_RED:
154 componentsPerPixel = 1;
155 break;
robertphillips@google.com670ff9a2012-04-12 19:53:31 +0000156 default:
157 GrAlwaysAssert(false);
158 break;
159 }
160
161 GrGLint alignment = 4; // the pack alignment (one of 1, 2, 4 or 8)
162 // Ganesh currently doesn't support setting GR_GL_PACK_ALIGNMENT
163
164 GrGLint componentSize = 0; // size (in bytes) of a single component
165
166 switch (type) {
167 case GR_GL_UNSIGNED_BYTE:
168 componentSize = 1;
169 break;
170 default:
171 GrAlwaysAssert(false);
172 break;
173 }
174
175 GrGLint rowStride = 0; // number of components (not bytes) to skip
176 if (componentSize >= alignment) {
177 rowStride = componentsPerPixel * pixelsInRow;
178 } else {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000179 float fTemp =
180 sk_float_ceil(componentSize * componentsPerPixel * pixelsInRow /
robertphillips@google.com670ff9a2012-04-12 19:53:31 +0000181 static_cast<float>(alignment));
182 rowStride = static_cast<GrGLint>(alignment * fTemp / componentSize);
183 }
184
185 GrGLchar *scanline = static_cast<GrGLchar *>(pixels);
186 for (int y = 0; y < height; ++y) {
187 memset(scanline, 0, componentsPerPixel * componentSize * width);
188 scanline += rowStride;
189 }
190}
robertphillips@google.com0da37192012-03-19 14:42:13 +0000191
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000192 GrGLvoid GR_GL_FUNCTION_TYPE debugGLUseProgram(GrGLuint programID) {
193
194 // A programID of 0 is legal
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000195 GrProgramObj *program = GR_FIND(programID,
196 GrProgramObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000197 GrDebugGL::kProgram_ObjTypes);
198
199 GrDebugGL::getInstance()->useProgram(program);
200 }
201
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000202 GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindFramebuffer(GrGLenum target,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000203 GrGLuint frameBufferID) {
204
robertphillips@google.com31975cf2013-04-11 23:25:36 +0000205 GrAlwaysAssert(GR_GL_FRAMEBUFFER == target ||
206 GR_GL_READ_FRAMEBUFFER == target ||
207 GR_GL_DRAW_FRAMEBUFFER);
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000208
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000209 // a frameBufferID of 0 is acceptable - it binds to the default
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000210 // frame buffer
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000211 GrFrameBufferObj *frameBuffer = GR_FIND(frameBufferID,
212 GrFrameBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000213 GrDebugGL::kFrameBuffer_ObjTypes);
214
215 GrDebugGL::getInstance()->setFrameBuffer(frameBuffer);
216 }
217
bsalomon@google.comecd84842013-03-01 15:36:02 +0000218 GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindRenderbuffer(GrGLenum target, GrGLuint renderBufferID) {
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000219
220 GrAlwaysAssert(GR_GL_RENDERBUFFER == target);
221
222 // a renderBufferID of 0 is acceptable - it unbinds the bound render buffer
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000223 GrRenderBufferObj *renderBuffer = GR_FIND(renderBufferID,
224 GrRenderBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000225 GrDebugGL::kRenderBuffer_ObjTypes);
226
227 GrDebugGL::getInstance()->setRenderBuffer(renderBuffer);
228 }
229
bsalomon@google.comecd84842013-03-01 15:36:02 +0000230 GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteTextures(GrGLsizei n, const GrGLuint* textures) {
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000231
232 // first potentially unbind the texture
233 // TODO: move this into GrDebugGL as unBindTexture?
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000234 for (unsigned int i = 0;
235 i < GrDebugGL::getInstance()->getMaxTextureUnits();
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000236 ++i) {
237 GrTextureUnitObj *pTU = GrDebugGL::getInstance()->getTextureUnit(i);
238
239 if (pTU->getTexture()) {
240 for (int j = 0; j < n; ++j) {
241
242 if (textures[j] == pTU->getTexture()->getID()) {
243 // this ID is the current texture - revert the binding to 0
244 pTU->setTexture(NULL);
245 }
246 }
247 }
248 }
249
250 // TODO: fuse the following block with DeleteRenderBuffers?
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000251 // Open GL will remove a deleted render buffer from the active
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000252 // frame buffer but not from any other frame buffer
253 if (GrDebugGL::getInstance()->getFrameBuffer()) {
254
255 GrFrameBufferObj *frameBuffer = GrDebugGL::getInstance()->getFrameBuffer();
256
257 for (int i = 0; i < n; ++i) {
258
bsalomon49f085d2014-09-05 13:34:00 -0700259 if (frameBuffer->getColor() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000260 textures[i] == frameBuffer->getColor()->getID()) {
261 frameBuffer->setColor(NULL);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000262 }
bsalomon49f085d2014-09-05 13:34:00 -0700263 if (frameBuffer->getDepth() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000264 textures[i] == frameBuffer->getDepth()->getID()) {
265 frameBuffer->setDepth(NULL);
266 }
bsalomon49f085d2014-09-05 13:34:00 -0700267 if (frameBuffer->getStencil() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000268 textures[i] == frameBuffer->getStencil()->getID()) {
269 frameBuffer->setStencil(NULL);
270 }
271 }
272 }
273
274 // then actually "delete" the buffers
275 for (int i = 0; i < n; ++i) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000276 GrTextureObj *buffer = GR_FIND(textures[i],
277 GrTextureObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000278 GrDebugGL::kTexture_ObjTypes);
279 GrAlwaysAssert(buffer);
280
281 // OpenGL gives no guarantees if a texture is deleted while attached to
282 // something other than the currently bound frame buffer
283 GrAlwaysAssert(!buffer->getBound());
284
285 GrAlwaysAssert(!buffer->getDeleted());
286 buffer->deleteAction();
287 }
288
289 }
290
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000291 GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteFramebuffers(GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000292 const GrGLuint *frameBuffers) {
293
294 // first potentially unbind the buffers
295 if (GrDebugGL::getInstance()->getFrameBuffer()) {
296 for (int i = 0; i < n; ++i) {
297
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000298 if (frameBuffers[i] ==
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000299 GrDebugGL::getInstance()->getFrameBuffer()->getID()) {
300 // this ID is the current frame buffer - rebind to the default
301 GrDebugGL::getInstance()->setFrameBuffer(NULL);
302 }
303 }
304 }
305
306 // then actually "delete" the buffers
307 for (int i = 0; i < n; ++i) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000308 GrFrameBufferObj *buffer = GR_FIND(frameBuffers[i],
309 GrFrameBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000310 GrDebugGL::kFrameBuffer_ObjTypes);
311 GrAlwaysAssert(buffer);
312
313 GrAlwaysAssert(!buffer->getDeleted());
314 buffer->deleteAction();
315 }
316 }
317
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000318 GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteRenderbuffers(GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000319 const GrGLuint *renderBuffers) {
320
321 // first potentially unbind the buffers
322 if (GrDebugGL::getInstance()->getRenderBuffer()) {
323 for (int i = 0; i < n; ++i) {
324
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000325 if (renderBuffers[i] ==
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000326 GrDebugGL::getInstance()->getRenderBuffer()->getID()) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000327 // this ID is the current render buffer - make no
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000328 // render buffer be bound
329 GrDebugGL::getInstance()->setRenderBuffer(NULL);
330 }
331 }
332 }
333
334 // TODO: fuse the following block with DeleteTextures?
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000335 // Open GL will remove a deleted render buffer from the active frame
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000336 // buffer but not from any other frame buffer
337 if (GrDebugGL::getInstance()->getFrameBuffer()) {
338
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000339 GrFrameBufferObj *frameBuffer =
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000340 GrDebugGL::getInstance()->getFrameBuffer();
341
342 for (int i = 0; i < n; ++i) {
343
bsalomon49f085d2014-09-05 13:34:00 -0700344 if (frameBuffer->getColor() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000345 renderBuffers[i] == frameBuffer->getColor()->getID()) {
346 frameBuffer->setColor(NULL);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000347 }
bsalomon49f085d2014-09-05 13:34:00 -0700348 if (frameBuffer->getDepth() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000349 renderBuffers[i] == frameBuffer->getDepth()->getID()) {
350 frameBuffer->setDepth(NULL);
351 }
bsalomon49f085d2014-09-05 13:34:00 -0700352 if (frameBuffer->getStencil() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000353 renderBuffers[i] == frameBuffer->getStencil()->getID()) {
354 frameBuffer->setStencil(NULL);
355 }
356 }
357 }
358
359 // then actually "delete" the buffers
360 for (int i = 0; i < n; ++i) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000361 GrRenderBufferObj *buffer = GR_FIND(renderBuffers[i],
362 GrRenderBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000363 GrDebugGL::kRenderBuffer_ObjTypes);
364 GrAlwaysAssert(buffer);
365
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000366 // OpenGL gives no guarantees if a render buffer is deleted
367 // while attached to something other than the currently
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000368 // bound frame buffer
369 GrAlwaysAssert(!buffer->getColorBound());
370 GrAlwaysAssert(!buffer->getDepthBound());
commit-bot@chromium.org1308f6e2013-06-03 20:09:08 +0000371 // However, at GrContext destroy time we release all GrRsources and so stencil buffers
372 // may get deleted before FBOs that refer to them.
373 //GrAlwaysAssert(!buffer->getStencilBound());
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000374
375 GrAlwaysAssert(!buffer->getDeleted());
376 buffer->deleteAction();
377 }
378 }
379
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000380 GrGLvoid GR_GL_FUNCTION_TYPE debugGLFramebufferRenderbuffer(GrGLenum target,
381 GrGLenum attachment,
382 GrGLenum renderbuffertarget,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000383 GrGLuint renderBufferID) {
384
385 GrAlwaysAssert(GR_GL_FRAMEBUFFER == target);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000386 GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment ||
387 GR_GL_DEPTH_ATTACHMENT == attachment ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000388 GR_GL_STENCIL_ATTACHMENT == attachment);
389 GrAlwaysAssert(GR_GL_RENDERBUFFER == renderbuffertarget);
390
391 GrFrameBufferObj *framebuffer = GrDebugGL::getInstance()->getFrameBuffer();
392 // A render buffer cannot be attached to the default framebuffer
bsalomon49f085d2014-09-05 13:34:00 -0700393 GrAlwaysAssert(framebuffer);
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000394
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000395 // a renderBufferID of 0 is acceptable - it unbinds the current
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000396 // render buffer
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000397 GrRenderBufferObj *renderbuffer = GR_FIND(renderBufferID,
398 GrRenderBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000399 GrDebugGL::kRenderBuffer_ObjTypes);
400
401 switch (attachment) {
402 case GR_GL_COLOR_ATTACHMENT0:
403 framebuffer->setColor(renderbuffer);
404 break;
405 case GR_GL_DEPTH_ATTACHMENT:
406 framebuffer->setDepth(renderbuffer);
407 break;
408 case GR_GL_STENCIL_ATTACHMENT:
409 framebuffer->setStencil(renderbuffer);
410 break;
411 default:
412 GrAlwaysAssert(false);
413 break;
414 };
415
416 }
417
418 ////////////////////////////////////////////////////////////////////////////////
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000419 GrGLvoid GR_GL_FUNCTION_TYPE debugGLFramebufferTexture2D(GrGLenum target,
420 GrGLenum attachment,
421 GrGLenum textarget,
422 GrGLuint textureID,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000423 GrGLint level) {
424
425 GrAlwaysAssert(GR_GL_FRAMEBUFFER == target);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000426 GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment ||
427 GR_GL_DEPTH_ATTACHMENT == attachment ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000428 GR_GL_STENCIL_ATTACHMENT == attachment);
429 GrAlwaysAssert(GR_GL_TEXTURE_2D == textarget);
430
431 GrFrameBufferObj *framebuffer = GrDebugGL::getInstance()->getFrameBuffer();
432 // A texture cannot be attached to the default framebuffer
bsalomon49f085d2014-09-05 13:34:00 -0700433 GrAlwaysAssert(framebuffer);
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000434
435 // A textureID of 0 is allowed - it unbinds the currently bound texture
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000436 GrTextureObj *texture = GR_FIND(textureID, GrTextureObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000437 GrDebugGL::kTexture_ObjTypes);
438 if (texture) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000439 // The texture shouldn't be bound to a texture unit - this
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000440 // could lead to a feedback loop
441 GrAlwaysAssert(!texture->getBound());
442 }
443
444 GrAlwaysAssert(0 == level);
445
446 switch (attachment) {
447 case GR_GL_COLOR_ATTACHMENT0:
448 framebuffer->setColor(texture);
449 break;
450 case GR_GL_DEPTH_ATTACHMENT:
451 framebuffer->setDepth(texture);
452 break;
453 case GR_GL_STENCIL_ATTACHMENT:
454 framebuffer->setStencil(texture);
455 break;
456 default:
457 GrAlwaysAssert(false);
458 break;
459 };
460 }
461
robertphillips@google.com0da37192012-03-19 14:42:13 +0000462GrGLuint GR_GL_FUNCTION_TYPE debugGLCreateProgram() {
463
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000464 GrProgramObj *program = GR_CREATE(GrProgramObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000465 GrDebugGL::kProgram_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000466
467 return program->getID();
468}
469
470GrGLuint GR_GL_FUNCTION_TYPE debugGLCreateShader(GrGLenum type) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000471
472 GrAlwaysAssert(GR_GL_VERTEX_SHADER == type ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000473 GR_GL_FRAGMENT_SHADER == type);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000474
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000475 GrShaderObj *shader = GR_CREATE(GrShaderObj, GrDebugGL::kShader_ObjTypes);
476 shader->setType(type);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000477
478 return shader->getID();
479}
480
481GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteProgram(GrGLuint programID) {
482
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000483 GrProgramObj *program = GR_FIND(programID,
484 GrProgramObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000485 GrDebugGL::kProgram_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000486 GrAlwaysAssert(program);
487
robertphillips@google.com0da37192012-03-19 14:42:13 +0000488 if (program->getRefCount()) {
489 // someone is still using this program so we can't delete it here
490 program->setMarkedForDeletion();
491 } else {
492 program->deleteAction();
493 }
494}
495
496GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteShader(GrGLuint shaderID) {
497
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000498 GrShaderObj *shader = GR_FIND(shaderID,
499 GrShaderObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000500 GrDebugGL::kShader_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000501 GrAlwaysAssert(shader);
502
robertphillips@google.com0da37192012-03-19 14:42:13 +0000503 if (shader->getRefCount()) {
504 // someone is still using this shader so we can't delete it here
505 shader->setMarkedForDeletion();
506 } else {
507 shader->deleteAction();
508 }
509}
510
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000511GrGLvoid debugGenObjs(GrDebugGL::GrObjTypes type,
512 GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000513 GrGLuint* ids) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000514
515 for (int i = 0; i < n; ++i) {
516 GrFakeRefObj *obj = GrDebugGL::getInstance()->createObj(type);
517 GrAlwaysAssert(obj);
518 ids[i] = obj->getID();
519 }
520}
521
robertphillips@google.com0da37192012-03-19 14:42:13 +0000522GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenBuffers(GrGLsizei n, GrGLuint* ids) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000523 debugGenObjs(GrDebugGL::kBuffer_ObjTypes, n, ids);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000524}
525
commit-bot@chromium.orgcffff792013-07-26 16:36:04 +0000526GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenerateMipmap(GrGLenum level) {
527}
528
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000529GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenFramebuffers(GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000530 GrGLuint* ids) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000531 debugGenObjs(GrDebugGL::kFrameBuffer_ObjTypes, n, ids);
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000532}
533
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000534GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenRenderbuffers(GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000535 GrGLuint* ids) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000536 debugGenObjs(GrDebugGL::kRenderBuffer_ObjTypes, n, ids);
537}
538
539GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenTextures(GrGLsizei n, GrGLuint* ids) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000540 debugGenObjs(GrDebugGL::kTexture_ObjTypes, n, ids);
robertphillips@google.com7c959422012-03-22 20:43:56 +0000541}
542
bsalomon@google.comecd84842013-03-01 15:36:02 +0000543GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenVertexArrays(GrGLsizei n, GrGLuint* ids) {
544 debugGenObjs(GrDebugGL::kVertexArray_ObjTypes, n, ids);
545}
robertphillips@google.com0da37192012-03-19 14:42:13 +0000546
bsalomon@google.comecd84842013-03-01 15:36:02 +0000547GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteVertexArrays(GrGLsizei n, const GrGLuint* ids) {
548 for (GrGLsizei i = 0; i < n; ++i) {
549 GrVertexArrayObj* array =
550 GR_FIND(ids[i], GrVertexArrayObj, GrDebugGL::kVertexArray_ObjTypes);
551 GrAlwaysAssert(array);
552
553 // Deleting the current vertex array binds object 0
554 if (GrDebugGL::getInstance()->getVertexArray() == array) {
555 GrDebugGL::getInstance()->setVertexArray(NULL);
556 }
557
558 if (array->getRefCount()) {
559 // someone is still using this vertex array so we can't delete it here
560 array->setMarkedForDeletion();
561 } else {
562 array->deleteAction();
563 }
564 }
565}
566
567GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindVertexArray(GrGLuint id) {
568 GrVertexArrayObj* array = GR_FIND(id, GrVertexArrayObj, GrDebugGL::kVertexArray_ObjTypes);
bsalomon49f085d2014-09-05 13:34:00 -0700569 GrAlwaysAssert((0 == id) || array);
bsalomon@google.comecd84842013-03-01 15:36:02 +0000570 GrDebugGL::getInstance()->setVertexArray(array);
571}
572
573GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindBuffer(GrGLenum target, GrGLuint bufferID) {
574 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || GR_GL_ELEMENT_ARRAY_BUFFER == target);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000575
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000576 GrBufferObj *buffer = GR_FIND(bufferID,
577 GrBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000578 GrDebugGL::kBuffer_ObjTypes);
bsalomon@google.com8f943612013-02-26 14:34:43 +0000579 // 0 is a permissible bufferID - it unbinds the current buffer
robertphillips@google.com0da37192012-03-19 14:42:13 +0000580
581 switch (target) {
582 case GR_GL_ARRAY_BUFFER:
robertphillips@google.com0da37192012-03-19 14:42:13 +0000583 GrDebugGL::getInstance()->setArrayBuffer(buffer);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000584 break;
585 case GR_GL_ELEMENT_ARRAY_BUFFER:
robertphillips@google.com0da37192012-03-19 14:42:13 +0000586 GrDebugGL::getInstance()->setElementArrayBuffer(buffer);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000587 break;
588 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000589 SkFAIL("Unexpected target to glBindBuffer");
robertphillips@google.com0da37192012-03-19 14:42:13 +0000590 break;
591 }
592}
593
594// deleting a bound buffer has the side effect of binding 0
bsalomon@google.comecd84842013-03-01 15:36:02 +0000595GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteBuffers(GrGLsizei n, const GrGLuint* ids) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000596 // first potentially unbind the buffers
597 for (int i = 0; i < n; ++i) {
598
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000599 if (GrDebugGL::getInstance()->getArrayBuffer() &&
robertphillips@google.com0da37192012-03-19 14:42:13 +0000600 ids[i] == GrDebugGL::getInstance()->getArrayBuffer()->getID()) {
601 // this ID is the current array buffer
robertphillips@google.com0da37192012-03-19 14:42:13 +0000602 GrDebugGL::getInstance()->setArrayBuffer(NULL);
603 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000604 if (GrDebugGL::getInstance()->getElementArrayBuffer() &&
605 ids[i] ==
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000606 GrDebugGL::getInstance()->getElementArrayBuffer()->getID()) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000607 // this ID is the current element array buffer
robertphillips@google.com0da37192012-03-19 14:42:13 +0000608 GrDebugGL::getInstance()->setElementArrayBuffer(NULL);
609 }
610 }
611
612 // then actually "delete" the buffers
613 for (int i = 0; i < n; ++i) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000614 GrBufferObj *buffer = GR_FIND(ids[i],
615 GrBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000616 GrDebugGL::kBuffer_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000617 GrAlwaysAssert(buffer);
618
619 GrAlwaysAssert(!buffer->getDeleted());
620 buffer->deleteAction();
621 }
622}
623
624// map a buffer to the caller's address space
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000625GrGLvoid* GR_GL_FUNCTION_TYPE debugGLMapBufferRange(GrGLenum target, GrGLintptr offset,
626 GrGLsizeiptr length, GrGLbitfield access) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000627 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000628 GR_GL_ELEMENT_ARRAY_BUFFER == target);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000629
630 // We only expect read access and we expect that the buffer or range is always invalidated.
631 GrAlwaysAssert(!SkToBool(GR_GL_MAP_READ_BIT & access));
632 GrAlwaysAssert((GR_GL_MAP_INVALIDATE_BUFFER_BIT | GR_GL_MAP_INVALIDATE_RANGE_BIT) & access);
633
634 GrBufferObj *buffer = NULL;
635 switch (target) {
636 case GR_GL_ARRAY_BUFFER:
637 buffer = GrDebugGL::getInstance()->getArrayBuffer();
638 break;
639 case GR_GL_ELEMENT_ARRAY_BUFFER:
640 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
641 break;
642 default:
643 SkFAIL("Unexpected target to glMapBufferRange");
644 break;
645 }
646
bsalomon49f085d2014-09-05 13:34:00 -0700647 if (buffer) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000648 GrAlwaysAssert(offset >= 0 && offset + length <= buffer->getSize());
649 GrAlwaysAssert(!buffer->getMapped());
650 buffer->setMapped(offset, length);
651 return buffer->getDataPtr() + offset;
652 }
653
654 GrAlwaysAssert(false);
655 return NULL; // no buffer bound to the target
656}
657
658GrGLvoid* GR_GL_FUNCTION_TYPE debugGLMapBuffer(GrGLenum target, GrGLenum access) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000659 GrAlwaysAssert(GR_GL_WRITE_ONLY == access);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000660
661 GrBufferObj *buffer = NULL;
662 switch (target) {
663 case GR_GL_ARRAY_BUFFER:
664 buffer = GrDebugGL::getInstance()->getArrayBuffer();
665 break;
666 case GR_GL_ELEMENT_ARRAY_BUFFER:
667 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
668 break;
669 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000670 SkFAIL("Unexpected target to glMapBuffer");
robertphillips@google.com0da37192012-03-19 14:42:13 +0000671 break;
672 }
673
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000674 return debugGLMapBufferRange(target, 0, buffer->getSize(),
675 GR_GL_MAP_WRITE_BIT | GR_GL_MAP_INVALIDATE_BUFFER_BIT);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000676}
677
678// remove a buffer from the caller's address space
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000679// TODO: check if the "access" method from "glMapBuffer" was honored
robertphillips@google.com0da37192012-03-19 14:42:13 +0000680GrGLboolean GR_GL_FUNCTION_TYPE debugGLUnmapBuffer(GrGLenum target) {
681
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000682 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000683 GR_GL_ELEMENT_ARRAY_BUFFER == target);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000684
685 GrBufferObj *buffer = NULL;
686 switch (target) {
687 case GR_GL_ARRAY_BUFFER:
688 buffer = GrDebugGL::getInstance()->getArrayBuffer();
689 break;
690 case GR_GL_ELEMENT_ARRAY_BUFFER:
691 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
692 break;
693 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000694 SkFAIL("Unexpected target to glUnmapBuffer");
robertphillips@google.com0da37192012-03-19 14:42:13 +0000695 break;
696 }
697
bsalomon49f085d2014-09-05 13:34:00 -0700698 if (buffer) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000699 GrAlwaysAssert(buffer->getMapped());
700 buffer->resetMapped();
701 return GR_GL_TRUE;
702 }
703
704 GrAlwaysAssert(false);
705 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION;
706}
707
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000708GrGLvoid GR_GL_FUNCTION_TYPE debugGLFlushMappedBufferRange(GrGLenum target,
709 GrGLintptr offset,
710 GrGLsizeiptr length) {
711 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
712 GR_GL_ELEMENT_ARRAY_BUFFER == target);
713
714 GrBufferObj *buffer = NULL;
715 switch (target) {
716 case GR_GL_ARRAY_BUFFER:
717 buffer = GrDebugGL::getInstance()->getArrayBuffer();
718 break;
719 case GR_GL_ELEMENT_ARRAY_BUFFER:
720 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
721 break;
722 default:
723 SkFAIL("Unexpected target to glUnmapBuffer");
724 break;
725 }
726
bsalomon49f085d2014-09-05 13:34:00 -0700727 if (buffer) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000728 GrAlwaysAssert(buffer->getMapped());
729 GrAlwaysAssert(offset >= 0 && (offset + length) <= buffer->getMappedLength());
730 } else {
731 GrAlwaysAssert(false);
732 }
733}
734
735
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000736GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetBufferParameteriv(GrGLenum target,
737 GrGLenum value,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000738 GrGLint* params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000739
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000740 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000741 GR_GL_ELEMENT_ARRAY_BUFFER == target);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000742 GrAlwaysAssert(GR_GL_BUFFER_SIZE == value ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000743 GR_GL_BUFFER_USAGE == value);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000744
745 GrBufferObj *buffer = NULL;
746 switch (target) {
747 case GR_GL_ARRAY_BUFFER:
748 buffer = GrDebugGL::getInstance()->getArrayBuffer();
749 break;
750 case GR_GL_ELEMENT_ARRAY_BUFFER:
751 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000752 break;
robertphillips@google.com0da37192012-03-19 14:42:13 +0000753 }
754
755 GrAlwaysAssert(buffer);
756
757 switch (value) {
758 case GR_GL_BUFFER_MAPPED:
759 *params = GR_GL_FALSE;
bsalomon49f085d2014-09-05 13:34:00 -0700760 if (buffer)
robertphillips@google.com0da37192012-03-19 14:42:13 +0000761 *params = buffer->getMapped() ? GR_GL_TRUE : GR_GL_FALSE;
762 break;
763 case GR_GL_BUFFER_SIZE:
764 *params = 0;
bsalomon49f085d2014-09-05 13:34:00 -0700765 if (buffer)
commit-bot@chromium.org2cfa3202014-04-19 22:00:40 +0000766 *params = SkToInt(buffer->getSize());
robertphillips@google.com0da37192012-03-19 14:42:13 +0000767 break;
768 case GR_GL_BUFFER_USAGE:
769 *params = GR_GL_STATIC_DRAW;
bsalomon49f085d2014-09-05 13:34:00 -0700770 if (buffer)
robertphillips@google.com0da37192012-03-19 14:42:13 +0000771 *params = buffer->getUsage();
772 break;
773 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000774 SkFAIL("Unexpected value to glGetBufferParamateriv");
robertphillips@google.com0da37192012-03-19 14:42:13 +0000775 break;
776 }
777};
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000778} // end of namespace
779
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000780////////////////////////////////////////////////////////////////////////////////
781struct GrDebugGLInterface : public GrGLInterface {
782
783public:
robertphillips@google.com409566a2012-06-26 20:19:41 +0000784 SK_DECLARE_INST_COUNT(GrDebugGLInterface)
785
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000786 GrDebugGLInterface()
787 : fWrapped(NULL) {
robertphillips@google.com622a1702012-07-31 19:23:02 +0000788 GrDebugGL::staticRef();
789 }
790
791 virtual ~GrDebugGLInterface() {
792 GrDebugGL::staticUnRef();
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000793 }
794
795 void setWrapped(GrGLInterface *interface) {
796 fWrapped.reset(interface);
797 }
798
mtklein72c9faa2015-01-09 10:06:39 -0800799 void abandon() const SK_OVERRIDE {
bsalomon944bcf02014-07-29 08:01:52 -0700800 GrDebugGL::abandon();
801 }
802
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000803 // TODO: there are some issues w/ wrapping another GL interface inside the
804 // debug interface:
805 // Since none of the "gl" methods are member functions they don't get
806 // a "this" pointer through which to access "fWrapped"
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000807 // This could be worked around by having all of them access the
808 // "glInterface" pointer - i.e., treating the debug interface as a
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000809 // true singleton
810 //
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000811 // The problem with this is that we also want to handle OpenGL
812 // contexts. The natural way to do this is to have multiple debug
813 // interfaces. Each of which represents a separate context. The
814 // static ID count would still uniquify IDs across all of them.
815 // The problem then is that we couldn't treat the debug GL
816 // interface as a singleton (since there would be one for each
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000817 // context).
818 //
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000819 // The solution to this is probably to alter SkDebugGlContext's
820 // "makeCurrent" method to make a call like "makeCurrent(this)" to
821 // the debug GL interface (assuming that the application will create
kkinnunen9e61bb72014-10-09 05:24:15 -0700822 // multiple SkGLContext's) to let it switch between the active
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000823 // context. Everything in the GrDebugGL object would then need to be
824 // moved to a GrContextObj and the GrDebugGL object would just switch
825 // between them. Note that this approach would also require that
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000826 // SkDebugGLContext wrap an arbitrary other context
827 // and then pass the wrapped interface to the debug GL interface.
828
829protected:
830private:
831
832 SkAutoTUnref<GrGLInterface> fWrapped;
833
834 typedef GrGLInterface INHERITED;
835};
836
837////////////////////////////////////////////////////////////////////////////////
robertphillips@google.com0da37192012-03-19 14:42:13 +0000838const GrGLInterface* GrGLCreateDebugInterface() {
robertphillips@google.com409566a2012-06-26 20:19:41 +0000839 GrGLInterface* interface = SkNEW(GrDebugGLInterface);
840
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000841 interface->fStandard = kGL_GrGLStandard;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000842
843 GrGLInterface::Functions* functions = &interface->fFunctions;
844 functions->fActiveTexture = debugGLActiveTexture;
845 functions->fAttachShader = debugGLAttachShader;
846 functions->fBeginQuery = debugGLBeginQuery;
847 functions->fBindAttribLocation = debugGLBindAttribLocation;
848 functions->fBindBuffer = debugGLBindBuffer;
849 functions->fBindFragDataLocation = noOpGLBindFragDataLocation;
850 functions->fBindTexture = debugGLBindTexture;
851 functions->fBindVertexArray = debugGLBindVertexArray;
852 functions->fBlendColor = noOpGLBlendColor;
853 functions->fBlendFunc = noOpGLBlendFunc;
854 functions->fBufferData = debugGLBufferData;
855 functions->fBufferSubData = noOpGLBufferSubData;
856 functions->fClear = noOpGLClear;
857 functions->fClearColor = noOpGLClearColor;
858 functions->fClearStencil = noOpGLClearStencil;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000859 functions->fColorMask = noOpGLColorMask;
860 functions->fCompileShader = noOpGLCompileShader;
861 functions->fCompressedTexImage2D = noOpGLCompressedTexImage2D;
krajcevski37d20f72014-06-11 10:38:47 -0700862 functions->fCompressedTexSubImage2D = noOpGLCompressedTexSubImage2D;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000863 functions->fCopyTexSubImage2D = noOpGLCopyTexSubImage2D;
864 functions->fCreateProgram = debugGLCreateProgram;
865 functions->fCreateShader = debugGLCreateShader;
866 functions->fCullFace = noOpGLCullFace;
867 functions->fDeleteBuffers = debugGLDeleteBuffers;
868 functions->fDeleteProgram = debugGLDeleteProgram;
869 functions->fDeleteQueries = noOpGLDeleteIds;
870 functions->fDeleteShader = debugGLDeleteShader;
871 functions->fDeleteTextures = debugGLDeleteTextures;
872 functions->fDeleteVertexArrays = debugGLDeleteVertexArrays;
873 functions->fDepthMask = noOpGLDepthMask;
874 functions->fDisable = noOpGLDisable;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000875 functions->fDisableVertexAttribArray = noOpGLDisableVertexAttribArray;
876 functions->fDrawArrays = noOpGLDrawArrays;
877 functions->fDrawBuffer = noOpGLDrawBuffer;
878 functions->fDrawBuffers = noOpGLDrawBuffers;
879 functions->fDrawElements = noOpGLDrawElements;
880 functions->fEnable = noOpGLEnable;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000881 functions->fEnableVertexAttribArray = noOpGLEnableVertexAttribArray;
882 functions->fEndQuery = noOpGLEndQuery;
883 functions->fFinish = noOpGLFinish;
884 functions->fFlush = noOpGLFlush;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000885 functions->fFlushMappedBufferRange = debugGLFlushMappedBufferRange;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000886 functions->fFrontFace = noOpGLFrontFace;
887 functions->fGenerateMipmap = debugGLGenerateMipmap;
888 functions->fGenBuffers = debugGLGenBuffers;
889 functions->fGenQueries = noOpGLGenIds;
890 functions->fGenTextures = debugGLGenTextures;
891 functions->fGetBufferParameteriv = debugGLGetBufferParameteriv;
892 functions->fGetError = noOpGLGetError;
893 functions->fGetIntegerv = noOpGLGetIntegerv;
894 functions->fGetQueryObjecti64v = noOpGLGetQueryObjecti64v;
895 functions->fGetQueryObjectiv = noOpGLGetQueryObjectiv;
896 functions->fGetQueryObjectui64v = noOpGLGetQueryObjectui64v;
897 functions->fGetQueryObjectuiv = noOpGLGetQueryObjectuiv;
898 functions->fGetQueryiv = noOpGLGetQueryiv;
899 functions->fGetProgramInfoLog = noOpGLGetInfoLog;
900 functions->fGetProgramiv = noOpGLGetShaderOrProgramiv;
901 functions->fGetShaderInfoLog = noOpGLGetInfoLog;
902 functions->fGetShaderiv = noOpGLGetShaderOrProgramiv;
903 functions->fGetString = noOpGLGetString;
904 functions->fGetStringi = noOpGLGetStringi;
905 functions->fGetTexLevelParameteriv = noOpGLGetTexLevelParameteriv;
906 functions->fGetUniformLocation = noOpGLGetUniformLocation;
907 functions->fGenVertexArrays = debugGLGenVertexArrays;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000908 functions->fLineWidth = noOpGLLineWidth;
909 functions->fLinkProgram = noOpGLLinkProgram;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000910 functions->fMapBuffer = debugGLMapBuffer;
911 functions->fMapBufferRange = debugGLMapBufferRange;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000912 functions->fPixelStorei = debugGLPixelStorei;
913 functions->fQueryCounter = noOpGLQueryCounter;
914 functions->fReadBuffer = noOpGLReadBuffer;
915 functions->fReadPixels = debugGLReadPixels;
916 functions->fScissor = noOpGLScissor;
917 functions->fShaderSource = noOpGLShaderSource;
918 functions->fStencilFunc = noOpGLStencilFunc;
919 functions->fStencilFuncSeparate = noOpGLStencilFuncSeparate;
920 functions->fStencilMask = noOpGLStencilMask;
921 functions->fStencilMaskSeparate = noOpGLStencilMaskSeparate;
922 functions->fStencilOp = noOpGLStencilOp;
923 functions->fStencilOpSeparate = noOpGLStencilOpSeparate;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000924 functions->fTexImage2D = noOpGLTexImage2D;
925 functions->fTexParameteri = noOpGLTexParameteri;
926 functions->fTexParameteriv = noOpGLTexParameteriv;
927 functions->fTexSubImage2D = noOpGLTexSubImage2D;
928 functions->fTexStorage2D = noOpGLTexStorage2D;
929 functions->fDiscardFramebuffer = noOpGLDiscardFramebuffer;
930 functions->fUniform1f = noOpGLUniform1f;
931 functions->fUniform1i = noOpGLUniform1i;
932 functions->fUniform1fv = noOpGLUniform1fv;
933 functions->fUniform1iv = noOpGLUniform1iv;
934 functions->fUniform2f = noOpGLUniform2f;
935 functions->fUniform2i = noOpGLUniform2i;
936 functions->fUniform2fv = noOpGLUniform2fv;
937 functions->fUniform2iv = noOpGLUniform2iv;
938 functions->fUniform3f = noOpGLUniform3f;
939 functions->fUniform3i = noOpGLUniform3i;
940 functions->fUniform3fv = noOpGLUniform3fv;
941 functions->fUniform3iv = noOpGLUniform3iv;
942 functions->fUniform4f = noOpGLUniform4f;
943 functions->fUniform4i = noOpGLUniform4i;
944 functions->fUniform4fv = noOpGLUniform4fv;
945 functions->fUniform4iv = noOpGLUniform4iv;
946 functions->fUniformMatrix2fv = noOpGLUniformMatrix2fv;
947 functions->fUniformMatrix3fv = noOpGLUniformMatrix3fv;
948 functions->fUniformMatrix4fv = noOpGLUniformMatrix4fv;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000949 functions->fUnmapBuffer = debugGLUnmapBuffer;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000950 functions->fUseProgram = debugGLUseProgram;
egdaniel27c15212014-10-24 15:00:50 -0700951 functions->fVertexAttrib1f = noOpGLVertexAttrib1f;
952 functions->fVertexAttrib2fv = noOpGLVertexAttrib2fv;
953 functions->fVertexAttrib3fv = noOpGLVertexAttrib3fv;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000954 functions->fVertexAttrib4fv = noOpGLVertexAttrib4fv;
955 functions->fVertexAttribPointer = noOpGLVertexAttribPointer;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000956 functions->fViewport = noOpGLViewport;
957 functions->fBindFramebuffer = debugGLBindFramebuffer;
958 functions->fBindRenderbuffer = debugGLBindRenderbuffer;
959 functions->fCheckFramebufferStatus = noOpGLCheckFramebufferStatus;
960 functions->fDeleteFramebuffers = debugGLDeleteFramebuffers;
961 functions->fDeleteRenderbuffers = debugGLDeleteRenderbuffers;
962 functions->fFramebufferRenderbuffer = debugGLFramebufferRenderbuffer;
963 functions->fFramebufferTexture2D = debugGLFramebufferTexture2D;
964 functions->fGenFramebuffers = debugGLGenFramebuffers;
965 functions->fGenRenderbuffers = debugGLGenRenderbuffers;
966 functions->fGetFramebufferAttachmentParameteriv =
bsalomon@google.com8f943612013-02-26 14:34:43 +0000967 noOpGLGetFramebufferAttachmentParameteriv;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000968 functions->fGetRenderbufferParameteriv = noOpGLGetRenderbufferParameteriv;
969 functions->fRenderbufferStorage = noOpGLRenderbufferStorage;
970 functions->fRenderbufferStorageMultisample =
bsalomon@google.com8f943612013-02-26 14:34:43 +0000971 noOpGLRenderbufferStorageMultisample;
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000972 functions->fBlitFramebuffer = noOpGLBlitFramebuffer;
973 functions->fResolveMultisampleFramebuffer =
bsalomon@google.com8f943612013-02-26 14:34:43 +0000974 noOpGLResolveMultisampleFramebuffer;
commit-bot@chromium.orgf6696722014-04-25 06:21:30 +0000975 functions->fMatrixLoadf = noOpGLMatrixLoadf;
976 functions->fMatrixLoadIdentity = noOpGLMatrixLoadIdentity;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000977
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000978 functions->fBindFragDataLocationIndexed =
bsalomon@google.com8f943612013-02-26 14:34:43 +0000979 noOpGLBindFragDataLocationIndexed;
robertphillips@google.com409566a2012-06-26 20:19:41 +0000980
commit-bot@chromium.orgf5355612014-02-28 20:28:50 +0000981 interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functions->fGetStringi,
982 functions->fGetIntegerv);
983
robertphillips@google.com409566a2012-06-26 20:19:41 +0000984 return interface;
robertphillips@google.com0da37192012-03-19 14:42:13 +0000985}