blob: 3f58cc69da16990108747c78cdfc7f17736099e9 [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"
robertphillips@google.com670ff9a2012-04-12 19:53:31 +000019#include "SkFloatingPoint.h"
robertphillips@google.com0da37192012-03-19 14:42:13 +000020
robertphillips@google.comf6f123d2012-03-21 17:57:55 +000021// the OpenGLES 2.0 spec says this must be >= 128
22static const GrGLint kDefaultMaxVertexUniformVectors = 128;
23
24// the OpenGLES 2.0 spec says this must be >=16
25static const GrGLint kDefaultMaxFragmentUniformVectors = 16;
26
27// the OpenGLES 2.0 spec says this must be >= 8
28static const GrGLint kDefaultMaxVertexAttribs = 8;
29
30// the OpenGLES 2.0 spec says this must be >= 8
31static const GrGLint kDefaultMaxVaryingVectors = 8;
32
caryclark@google.comcf6285b2012-06-06 12:09:01 +000033namespace { // suppress no previsous prototype warning
34
robertphillips@google.com0da37192012-03-19 14:42:13 +000035////////////////////////////////////////////////////////////////////////////////
robertphillips@google.comf6f123d2012-03-21 17:57:55 +000036GrGLvoid GR_GL_FUNCTION_TYPE debugGLActiveTexture(GrGLenum texture) {
robertphillips@google.comd41a1dc2012-03-19 17:33:58 +000037
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000038 // Ganesh offsets the texture unit indices
39 texture -= GR_GL_TEXTURE0;
40 GrAlwaysAssert(texture < GrDebugGL::getInstance()->getMaxTextureUnits());
robertphillips@google.com0da37192012-03-19 14:42:13 +000041
42 GrDebugGL::getInstance()->setCurTextureUnit(texture);
43}
44
45////////////////////////////////////////////////////////////////////////////////
robertphillips@google.comebde3e02012-07-13 17:45:17 +000046GrGLvoid GR_GL_FUNCTION_TYPE debugGLAttachShader(GrGLuint programID,
47 GrGLuint shaderID) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000048
robertphillips@google.comebde3e02012-07-13 17:45:17 +000049 GrProgramObj *program = GR_FIND(programID, GrProgramObj,
50 GrDebugGL::kProgram_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +000051 GrAlwaysAssert(program);
52
robertphillips@google.comebde3e02012-07-13 17:45:17 +000053 GrShaderObj *shader = GR_FIND(shaderID,
54 GrShaderObj,
55 GrDebugGL::kShader_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +000056 GrAlwaysAssert(shader);
57
58 program->AttachShader(shader);
59}
60
robertphillips@google.comebde3e02012-07-13 17:45:17 +000061GrGLvoid GR_GL_FUNCTION_TYPE debugGLBeginQuery(GrGLenum target, GrGLuint id) {
62}
63
64GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindAttribLocation(GrGLuint program,
65 GrGLuint index,
66 const char* name) {
67}
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000068
69////////////////////////////////////////////////////////////////////////////////
robertphillips@google.comebde3e02012-07-13 17:45:17 +000070GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindTexture(GrGLenum target,
71 GrGLuint textureID) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000072
73 // we don't use cube maps
robertphillips@google.comebde3e02012-07-13 17:45:17 +000074 GrAlwaysAssert(target == GR_GL_TEXTURE_2D);
75 // || target == GR_GL_TEXTURE_CUBE_MAP);
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000076
77 // a textureID of 0 is acceptable - it binds to the default texture target
robertphillips@google.comebde3e02012-07-13 17:45:17 +000078 GrTextureObj *texture = GR_FIND(textureID, GrTextureObj,
79 GrDebugGL::kTexture_ObjTypes);
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000080
81 GrDebugGL::getInstance()->setTexture(texture);
82}
83
robertphillips@google.comebde3e02012-07-13 17:45:17 +000084GrGLvoid GR_GL_FUNCTION_TYPE debugGLBlendColor(GrGLclampf red,
85 GrGLclampf green,
86 GrGLclampf blue,
87 GrGLclampf alpha) {
88}
89
90GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindFragDataLocation(GrGLuint program,
91 GrGLuint colorNumber,
92 const GrGLchar* name) {
93}
94
95GrGLvoid GR_GL_FUNCTION_TYPE debugGLBlendFunc(GrGLenum sfactor,
96 GrGLenum dfactor) {
97}
robertphillips@google.com0da37192012-03-19 14:42:13 +000098
99////////////////////////////////////////////////////////////////////////////////
robertphillips@google.com409566a2012-06-26 20:19:41 +0000100GrGLvoid GR_GL_FUNCTION_TYPE debugGLBufferData(GrGLenum target,
101 GrGLsizeiptr size,
102 const GrGLvoid* data,
103 GrGLenum usage) {
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000104 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
105 GR_GL_ELEMENT_ARRAY_BUFFER == target);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000106 GrAlwaysAssert(size >= 0);
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000107 GrAlwaysAssert(GR_GL_STREAM_DRAW == usage ||
108 GR_GL_STATIC_DRAW == usage ||
109 GR_GL_DYNAMIC_DRAW == usage);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000110
111 GrBufferObj *buffer = NULL;
112 switch (target) {
113 case GR_GL_ARRAY_BUFFER:
114 buffer = GrDebugGL::getInstance()->getArrayBuffer();
115 break;
116 case GR_GL_ELEMENT_ARRAY_BUFFER:
117 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
118 break;
119 default:
120 GrCrash("Unexpected target to glBufferData");
121 break;
122 }
123
124 GrAlwaysAssert(buffer);
125 GrAlwaysAssert(buffer->getBound());
126
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000127 buffer->allocate(size, reinterpret_cast<const GrGLchar *>(data));
robertphillips@google.com0da37192012-03-19 14:42:13 +0000128 buffer->setUsage(usage);
129}
130
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000131GrGLvoid GR_GL_FUNCTION_TYPE debugGLBufferSubData(GrGLenum target,
132 GrGLintptr offset,
133 GrGLsizeiptr size,
134 const GrGLvoid* data) {
135}
136
137GrGLvoid GR_GL_FUNCTION_TYPE debugGLClear(GrGLbitfield mask) {
138}
139
140GrGLvoid GR_GL_FUNCTION_TYPE debugGLClearColor(GrGLclampf red,
141 GrGLclampf green,
142 GrGLclampf blue,
143 GrGLclampf alpha) {
144}
145
146GrGLvoid GR_GL_FUNCTION_TYPE debugGLClearStencil(GrGLint s) {
147}
148
149GrGLvoid GR_GL_FUNCTION_TYPE debugGLColorMask(GrGLboolean red,
150 GrGLboolean green,
151 GrGLboolean blue,
152 GrGLboolean alpha) {
153}
154
155GrGLvoid GR_GL_FUNCTION_TYPE debugGLCompileShader(GrGLuint shader) {
156}
157
158GrGLvoid GR_GL_FUNCTION_TYPE debugGLCompressedTexImage2D(GrGLenum target,
159 GrGLint level,
160 GrGLenum internalformat,
161 GrGLsizei width,
162 GrGLsizei height,
163 GrGLint border,
164 GrGLsizei imageSize,
165 const GrGLvoid* data) {
166}
167
168GrGLvoid GR_GL_FUNCTION_TYPE debugGLCullFace(GrGLenum mode) {
169}
170
171GrGLvoid GR_GL_FUNCTION_TYPE debugGLDepthMask(GrGLboolean flag) {
172}
173
174GrGLvoid GR_GL_FUNCTION_TYPE debugGLDisable(GrGLenum cap) {
175}
176
177GrGLvoid GR_GL_FUNCTION_TYPE debugGLDisableVertexAttribArray(GrGLuint index) {
178}
179
180GrGLvoid GR_GL_FUNCTION_TYPE debugGLDrawArrays(GrGLenum mode,
181 GrGLint first,
182 GrGLsizei count) {
183}
184
185GrGLvoid GR_GL_FUNCTION_TYPE debugGLDrawBuffer(GrGLenum mode) {
186}
187
188GrGLvoid GR_GL_FUNCTION_TYPE debugGLDrawBuffers(GrGLsizei n,
189 const GrGLenum* bufs) {
190}
191
192GrGLvoid GR_GL_FUNCTION_TYPE debugGLDrawElements(GrGLenum mode,
193 GrGLsizei count,
194 GrGLenum type,
195 const GrGLvoid* indices) {
196}
197
198GrGLvoid GR_GL_FUNCTION_TYPE debugGLEnable(GrGLenum cap) {
199}
200
201GrGLvoid GR_GL_FUNCTION_TYPE debugGLEnableVertexAttribArray(GrGLuint index) {
202}
203
204GrGLvoid GR_GL_FUNCTION_TYPE debugGLEndQuery(GrGLenum target) {
205}
206
207GrGLvoid GR_GL_FUNCTION_TYPE debugGLFinish() {
208}
209
210GrGLvoid GR_GL_FUNCTION_TYPE debugGLFlush() {
211}
212
213GrGLvoid GR_GL_FUNCTION_TYPE debugGLFrontFace(GrGLenum mode) {
214}
215
216GrGLvoid GR_GL_FUNCTION_TYPE debugGLLineWidth(GrGLfloat width) {
217}
218
219GrGLvoid GR_GL_FUNCTION_TYPE debugGLLinkProgram(GrGLuint program) {
220}
221
222GrGLvoid GR_GL_FUNCTION_TYPE debugGLPixelStorei(GrGLenum pname,
223 GrGLint param) {
robertphillips@google.com670ff9a2012-04-12 19:53:31 +0000224
225 switch (pname) {
226 case GR_GL_UNPACK_ROW_LENGTH:
227 GrDebugGL::getInstance()->setUnPackRowLength(param);
228 break;
229 case GR_GL_PACK_ROW_LENGTH:
230 GrDebugGL::getInstance()->setPackRowLength(param);
231 break;
232 case GR_GL_UNPACK_ALIGNMENT:
233 break;
234 case GR_GL_PACK_ALIGNMENT:
235 GrAlwaysAssert(false);
236 break;
237 default:
238 GrAlwaysAssert(false);
239 break;
240 }
241}
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000242
243GrGLvoid GR_GL_FUNCTION_TYPE debugGLQueryCounter(GrGLuint id,
244 GrGLenum target) {
245}
246
247GrGLvoid GR_GL_FUNCTION_TYPE debugGLReadBuffer(GrGLenum src) {
248}
249
250GrGLvoid GR_GL_FUNCTION_TYPE debugGLReadPixels(GrGLint x,
251 GrGLint y,
252 GrGLsizei width,
253 GrGLsizei height,
254 GrGLenum format,
255 GrGLenum type,
robertphillips@google.com670ff9a2012-04-12 19:53:31 +0000256 GrGLvoid* pixels) {
257
258 GrGLint pixelsInRow = width;
259 if (0 < GrDebugGL::getInstance()->getPackRowLength()) {
260 pixelsInRow = GrDebugGL::getInstance()->getPackRowLength();
261 }
262
263 GrGLint componentsPerPixel = 0;
264
265 switch (format) {
266 case GR_GL_RGBA:
267 // fallthrough
268 case GR_GL_BGRA:
269 componentsPerPixel = 4;
270 break;
271 case GR_GL_RGB:
272 componentsPerPixel = 3;
273 break;
robertphillips@google.comd32369e2012-05-30 14:46:10 +0000274 case GR_GL_RED:
275 componentsPerPixel = 1;
276 break;
robertphillips@google.com670ff9a2012-04-12 19:53:31 +0000277 default:
278 GrAlwaysAssert(false);
279 break;
280 }
281
282 GrGLint alignment = 4; // the pack alignment (one of 1, 2, 4 or 8)
283 // Ganesh currently doesn't support setting GR_GL_PACK_ALIGNMENT
284
285 GrGLint componentSize = 0; // size (in bytes) of a single component
286
287 switch (type) {
288 case GR_GL_UNSIGNED_BYTE:
289 componentSize = 1;
290 break;
291 default:
292 GrAlwaysAssert(false);
293 break;
294 }
295
296 GrGLint rowStride = 0; // number of components (not bytes) to skip
297 if (componentSize >= alignment) {
298 rowStride = componentsPerPixel * pixelsInRow;
299 } else {
300 float fTemp =
301 sk_float_ceil(componentSize * componentsPerPixel * pixelsInRow /
302 static_cast<float>(alignment));
303 rowStride = static_cast<GrGLint>(alignment * fTemp / componentSize);
304 }
305
306 GrGLchar *scanline = static_cast<GrGLchar *>(pixels);
307 for (int y = 0; y < height; ++y) {
308 memset(scanline, 0, componentsPerPixel * componentSize * width);
309 scanline += rowStride;
310 }
311}
robertphillips@google.com0da37192012-03-19 14:42:13 +0000312
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000313GrGLvoid GR_GL_FUNCTION_TYPE debugGLScissor(GrGLint x,
314 GrGLint y,
315 GrGLsizei width,
316 GrGLsizei height) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000317}
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000318
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000319GrGLvoid GR_GL_FUNCTION_TYPE debugGLShaderSource(GrGLuint shader,
320 GrGLsizei count,
321 const char** str,
322 const GrGLint* length) {
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000323}
324
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000325GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilFunc(GrGLenum func,
326 GrGLint ref,
327 GrGLuint mask) {
robertphillips@google.com7c959422012-03-22 20:43:56 +0000328}
329
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000330GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilFuncSeparate(GrGLenum face,
331 GrGLenum func,
332 GrGLint ref,
333 GrGLuint mask) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000334}
335
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000336GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilMask(GrGLuint mask) {
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000337}
338
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000339GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilMaskSeparate(GrGLenum face,
340 GrGLuint mask) {
robertphillips@google.com7c959422012-03-22 20:43:56 +0000341}
342
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000343GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilOp(GrGLenum fail,
344 GrGLenum zfail,
345 GrGLenum zpass) {
robertphillips@google.com7c959422012-03-22 20:43:56 +0000346}
347
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000348GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilOpSeparate(GrGLenum face,
349 GrGLenum fail,
350 GrGLenum zfail,
351 GrGLenum zpass) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000352}
353
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000354GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexImage2D(GrGLenum target,
355 GrGLint level,
356 GrGLint internalformat,
357 GrGLsizei width,
358 GrGLsizei height,
359 GrGLint border,
360 GrGLenum format,
361 GrGLenum type,
362 const GrGLvoid* pixels) {
363}
364
365GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexParameteri(GrGLenum target,
366 GrGLenum pname,
367 GrGLint param) {
368}
369
370GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexParameteriv(GrGLenum target,
371 GrGLenum pname,
372 const GrGLint* params) {
373}
374
375GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexStorage2D(GrGLenum target,
376 GrGLsizei levels,
377 GrGLenum internalformat,
378 GrGLsizei width,
379 GrGLsizei height) {
380}
381
382GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexSubImage2D(GrGLenum target,
383 GrGLint level,
384 GrGLint xoffset,
385 GrGLint yoffset,
386 GrGLsizei width,
387 GrGLsizei height,
388 GrGLenum format,
389 GrGLenum type,
390 const GrGLvoid* pixels) {
391}
392
393GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform1f(GrGLint location,
394 GrGLfloat v0) {
395}
396
397GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform1i(GrGLint location,
398 GrGLint v0) {
399}
400
401GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform1fv(GrGLint location,
402 GrGLsizei count,
403 const GrGLfloat* v) {
404}
405
406GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform1iv(GrGLint location,
407 GrGLsizei count,
408 const GrGLint* v) {
409}
410
411GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform2f(GrGLint location,
412 GrGLfloat v0,
413 GrGLfloat v1) {
414}
415
416GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform2i(GrGLint location,
417 GrGLint v0,
418 GrGLint v1) {
419}
420
421GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform2fv(GrGLint location,
422 GrGLsizei count,
423 const GrGLfloat* v) {
424}
425
426GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform2iv(GrGLint location,
427 GrGLsizei count,
428 const GrGLint* v) {
429}
430
431GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform3f(GrGLint location,
432 GrGLfloat v0,
433 GrGLfloat v1,
434 GrGLfloat v2) {
435}
436
437GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform3i(GrGLint location,
438 GrGLint v0,
439 GrGLint v1,
440 GrGLint v2) {
441}
442
443GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform3fv(GrGLint location,
444 GrGLsizei count,
445 const GrGLfloat* v) {
446}
447
448GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform3iv(GrGLint location,
449 GrGLsizei count,
450 const GrGLint* v) {
451}
452
453GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform4f(GrGLint location,
454 GrGLfloat v0,
455 GrGLfloat v1,
456 GrGLfloat v2,
457 GrGLfloat v3) {
458}
459
460GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform4i(GrGLint location,
461 GrGLint v0,
462 GrGLint v1,
463 GrGLint v2,
464 GrGLint v3) {
465}
466
467GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform4fv(GrGLint location,
468 GrGLsizei count,
469 const GrGLfloat* v) {
470 }
471
472 GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform4iv(GrGLint location,
473 GrGLsizei count,
474 const GrGLint* v) {
475 }
476
477 GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniformMatrix2fv(GrGLint location,
478 GrGLsizei count,
479 GrGLboolean transpose,
480 const GrGLfloat* value) {
481 }
482
483 GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniformMatrix3fv(GrGLint location,
484 GrGLsizei count,
485 GrGLboolean transpose,
486 const GrGLfloat* value) {
487 }
488
489 GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniformMatrix4fv(GrGLint location,
490 GrGLsizei count,
491 GrGLboolean transpose,
492 const GrGLfloat* value) {
493 }
494
495 GrGLvoid GR_GL_FUNCTION_TYPE debugGLUseProgram(GrGLuint programID) {
496
497 // A programID of 0 is legal
498 GrProgramObj *program = GR_FIND(programID,
499 GrProgramObj,
500 GrDebugGL::kProgram_ObjTypes);
501
502 GrDebugGL::getInstance()->useProgram(program);
503 }
504
505 GrGLvoid GR_GL_FUNCTION_TYPE debugGLVertexAttrib4fv(GrGLuint indx,
506 const GrGLfloat* values) {
507 }
508
509 GrGLvoid GR_GL_FUNCTION_TYPE debugGLVertexAttribPointer(GrGLuint indx,
510 GrGLint size,
511 GrGLenum type,
512 GrGLboolean normalized,
513 GrGLsizei stride,
514 const GrGLvoid* ptr) {
515 }
516
517 GrGLvoid GR_GL_FUNCTION_TYPE debugGLViewport(GrGLint x,
518 GrGLint y,
519 GrGLsizei width,
520 GrGLsizei height) {
521 }
522
523 GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindFramebuffer(GrGLenum target,
524 GrGLuint frameBufferID) {
525
526 GrAlwaysAssert(GR_GL_FRAMEBUFFER == target);
527
528 // a frameBufferID of 0 is acceptable - it binds to the default
529 // frame buffer
530 GrFrameBufferObj *frameBuffer = GR_FIND(frameBufferID,
531 GrFrameBufferObj,
532 GrDebugGL::kFrameBuffer_ObjTypes);
533
534 GrDebugGL::getInstance()->setFrameBuffer(frameBuffer);
535 }
536
537 GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindRenderbuffer(GrGLenum target,
538 GrGLuint renderBufferID) {
539
540 GrAlwaysAssert(GR_GL_RENDERBUFFER == target);
541
542 // a renderBufferID of 0 is acceptable - it unbinds the bound render buffer
543 GrRenderBufferObj *renderBuffer = GR_FIND(renderBufferID,
544 GrRenderBufferObj,
545 GrDebugGL::kRenderBuffer_ObjTypes);
546
547 GrDebugGL::getInstance()->setRenderBuffer(renderBuffer);
548 }
549
550 GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteTextures(GrGLsizei n,
551 const GrGLuint* textures) {
552
553 // first potentially unbind the texture
554 // TODO: move this into GrDebugGL as unBindTexture?
555 for (unsigned int i = 0;
556 i < GrDebugGL::getInstance()->getMaxTextureUnits();
557 ++i) {
558 GrTextureUnitObj *pTU = GrDebugGL::getInstance()->getTextureUnit(i);
559
560 if (pTU->getTexture()) {
561 for (int j = 0; j < n; ++j) {
562
563 if (textures[j] == pTU->getTexture()->getID()) {
564 // this ID is the current texture - revert the binding to 0
565 pTU->setTexture(NULL);
566 }
567 }
568 }
569 }
570
571 // TODO: fuse the following block with DeleteRenderBuffers?
572 // Open GL will remove a deleted render buffer from the active
573 // frame buffer but not from any other frame buffer
574 if (GrDebugGL::getInstance()->getFrameBuffer()) {
575
576 GrFrameBufferObj *frameBuffer = GrDebugGL::getInstance()->getFrameBuffer();
577
578 for (int i = 0; i < n; ++i) {
579
580 if (NULL != frameBuffer->getColor() &&
581 textures[i] == frameBuffer->getColor()->getID()) {
582 frameBuffer->setColor(NULL);
583 }
584 if (NULL != frameBuffer->getDepth() &&
585 textures[i] == frameBuffer->getDepth()->getID()) {
586 frameBuffer->setDepth(NULL);
587 }
588 if (NULL != frameBuffer->getStencil() &&
589 textures[i] == frameBuffer->getStencil()->getID()) {
590 frameBuffer->setStencil(NULL);
591 }
592 }
593 }
594
595 // then actually "delete" the buffers
596 for (int i = 0; i < n; ++i) {
597 GrTextureObj *buffer = GR_FIND(textures[i],
598 GrTextureObj,
599 GrDebugGL::kTexture_ObjTypes);
600 GrAlwaysAssert(buffer);
601
602 // OpenGL gives no guarantees if a texture is deleted while attached to
603 // something other than the currently bound frame buffer
604 GrAlwaysAssert(!buffer->getBound());
605
606 GrAlwaysAssert(!buffer->getDeleted());
607 buffer->deleteAction();
608 }
609
610 }
611
612
613 GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteFramebuffers(GrGLsizei n,
614 const GrGLuint *frameBuffers) {
615
616 // first potentially unbind the buffers
617 if (GrDebugGL::getInstance()->getFrameBuffer()) {
618 for (int i = 0; i < n; ++i) {
619
620 if (frameBuffers[i] ==
621 GrDebugGL::getInstance()->getFrameBuffer()->getID()) {
622 // this ID is the current frame buffer - rebind to the default
623 GrDebugGL::getInstance()->setFrameBuffer(NULL);
624 }
625 }
626 }
627
628 // then actually "delete" the buffers
629 for (int i = 0; i < n; ++i) {
630 GrFrameBufferObj *buffer = GR_FIND(frameBuffers[i],
631 GrFrameBufferObj,
632 GrDebugGL::kFrameBuffer_ObjTypes);
633 GrAlwaysAssert(buffer);
634
635 GrAlwaysAssert(!buffer->getDeleted());
636 buffer->deleteAction();
637 }
638 }
639
640 GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteRenderbuffers(GrGLsizei n,
641 const GrGLuint *renderBuffers) {
642
643 // first potentially unbind the buffers
644 if (GrDebugGL::getInstance()->getRenderBuffer()) {
645 for (int i = 0; i < n; ++i) {
646
647 if (renderBuffers[i] ==
648 GrDebugGL::getInstance()->getRenderBuffer()->getID()) {
649 // this ID is the current render buffer - make no
650 // render buffer be bound
651 GrDebugGL::getInstance()->setRenderBuffer(NULL);
652 }
653 }
654 }
655
656 // TODO: fuse the following block with DeleteTextures?
657 // Open GL will remove a deleted render buffer from the active frame
658 // buffer but not from any other frame buffer
659 if (GrDebugGL::getInstance()->getFrameBuffer()) {
660
661 GrFrameBufferObj *frameBuffer =
662 GrDebugGL::getInstance()->getFrameBuffer();
663
664 for (int i = 0; i < n; ++i) {
665
666 if (NULL != frameBuffer->getColor() &&
667 renderBuffers[i] == frameBuffer->getColor()->getID()) {
668 frameBuffer->setColor(NULL);
669 }
670 if (NULL != frameBuffer->getDepth() &&
671 renderBuffers[i] == frameBuffer->getDepth()->getID()) {
672 frameBuffer->setDepth(NULL);
673 }
674 if (NULL != frameBuffer->getStencil() &&
675 renderBuffers[i] == frameBuffer->getStencil()->getID()) {
676 frameBuffer->setStencil(NULL);
677 }
678 }
679 }
680
681 // then actually "delete" the buffers
682 for (int i = 0; i < n; ++i) {
683 GrRenderBufferObj *buffer = GR_FIND(renderBuffers[i],
684 GrRenderBufferObj,
685 GrDebugGL::kRenderBuffer_ObjTypes);
686 GrAlwaysAssert(buffer);
687
688 // OpenGL gives no guarantees if a render buffer is deleted
689 // while attached to something other than the currently
690 // bound frame buffer
691 GrAlwaysAssert(!buffer->getColorBound());
692 GrAlwaysAssert(!buffer->getDepthBound());
693 GrAlwaysAssert(!buffer->getStencilBound());
694
695 GrAlwaysAssert(!buffer->getDeleted());
696 buffer->deleteAction();
697 }
698 }
699
700 GrGLvoid GR_GL_FUNCTION_TYPE debugGLFramebufferRenderbuffer(GrGLenum target,
701 GrGLenum attachment,
702 GrGLenum renderbuffertarget,
703 GrGLuint renderBufferID) {
704
705 GrAlwaysAssert(GR_GL_FRAMEBUFFER == target);
706 GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment ||
707 GR_GL_DEPTH_ATTACHMENT == attachment ||
708 GR_GL_STENCIL_ATTACHMENT == attachment);
709 GrAlwaysAssert(GR_GL_RENDERBUFFER == renderbuffertarget);
710
711 GrFrameBufferObj *framebuffer = GrDebugGL::getInstance()->getFrameBuffer();
712 // A render buffer cannot be attached to the default framebuffer
713 GrAlwaysAssert(NULL != framebuffer);
714
715 // a renderBufferID of 0 is acceptable - it unbinds the current
716 // render buffer
717 GrRenderBufferObj *renderbuffer = GR_FIND(renderBufferID,
718 GrRenderBufferObj,
719 GrDebugGL::kRenderBuffer_ObjTypes);
720
721 switch (attachment) {
722 case GR_GL_COLOR_ATTACHMENT0:
723 framebuffer->setColor(renderbuffer);
724 break;
725 case GR_GL_DEPTH_ATTACHMENT:
726 framebuffer->setDepth(renderbuffer);
727 break;
728 case GR_GL_STENCIL_ATTACHMENT:
729 framebuffer->setStencil(renderbuffer);
730 break;
731 default:
732 GrAlwaysAssert(false);
733 break;
734 };
735
736 }
737
738 ////////////////////////////////////////////////////////////////////////////////
739 GrGLvoid GR_GL_FUNCTION_TYPE debugGLFramebufferTexture2D(GrGLenum target,
740 GrGLenum attachment,
741 GrGLenum textarget,
742 GrGLuint textureID,
743 GrGLint level) {
744
745 GrAlwaysAssert(GR_GL_FRAMEBUFFER == target);
746 GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment ||
747 GR_GL_DEPTH_ATTACHMENT == attachment ||
748 GR_GL_STENCIL_ATTACHMENT == attachment);
749 GrAlwaysAssert(GR_GL_TEXTURE_2D == textarget);
750
751 GrFrameBufferObj *framebuffer = GrDebugGL::getInstance()->getFrameBuffer();
752 // A texture cannot be attached to the default framebuffer
753 GrAlwaysAssert(NULL != framebuffer);
754
755 // A textureID of 0 is allowed - it unbinds the currently bound texture
756 GrTextureObj *texture = GR_FIND(textureID, GrTextureObj,
757 GrDebugGL::kTexture_ObjTypes);
758 if (texture) {
759 // The texture shouldn't be bound to a texture unit - this
760 // could lead to a feedback loop
761 GrAlwaysAssert(!texture->getBound());
762 }
763
764 GrAlwaysAssert(0 == level);
765
766 switch (attachment) {
767 case GR_GL_COLOR_ATTACHMENT0:
768 framebuffer->setColor(texture);
769 break;
770 case GR_GL_DEPTH_ATTACHMENT:
771 framebuffer->setDepth(texture);
772 break;
773 case GR_GL_STENCIL_ATTACHMENT:
774 framebuffer->setStencil(texture);
775 break;
776 default:
777 GrAlwaysAssert(false);
778 break;
779 };
780 }
781
782 GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetFramebufferAttachmentParameteriv(GrGLenum target,
783 GrGLenum attachment,
784 GrGLenum pname,
785 GrGLint* params) {
786 }
787
788 GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetRenderbufferParameteriv(GrGLenum target,
789 GrGLenum pname,
790 GrGLint* params) {
791 }
792
793 GrGLvoid GR_GL_FUNCTION_TYPE debugGLRenderbufferStorage(GrGLenum target,
794 GrGLenum internalformat,
795 GrGLsizei width,
796 GrGLsizei height) {
797 }
798
799 GrGLvoid GR_GL_FUNCTION_TYPE debugGLRenderbufferStorageMultisample(GrGLenum target,
800 GrGLsizei samples,
801 GrGLenum internalformat,
802 GrGLsizei width,
803 GrGLsizei height) {
804 }
805
806 GrGLvoid GR_GL_FUNCTION_TYPE debugGLBlitFramebuffer(GrGLint srcX0,
807 GrGLint srcY0,
808 GrGLint srcX1,
809 GrGLint srcY1,
810 GrGLint dstX0,
811 GrGLint dstY0,
812 GrGLint dstX1,
813 GrGLint dstY1,
814 GrGLbitfield mask,
815 GrGLenum filter) {
816}
817
818GrGLvoid GR_GL_FUNCTION_TYPE debugGLResolveMultisampleFramebuffer() {
819}
820
821GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindFragDataLocationIndexed(GrGLuint program,
822 GrGLuint colorNumber,
823 GrGLuint index,
824 const GrGLchar * name) {
825}
robertphillips@google.com0da37192012-03-19 14:42:13 +0000826
827GrGLenum GR_GL_FUNCTION_TYPE debugGLCheckFramebufferStatus(GrGLenum target) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000828
829 GrAlwaysAssert(GR_GL_FRAMEBUFFER == target);
830
robertphillips@google.com0da37192012-03-19 14:42:13 +0000831 return GR_GL_FRAMEBUFFER_COMPLETE;
832}
833
834GrGLuint GR_GL_FUNCTION_TYPE debugGLCreateProgram() {
835
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000836 GrProgramObj *program = GR_CREATE(GrProgramObj,
837 GrDebugGL::kProgram_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000838
839 return program->getID();
840}
841
842GrGLuint GR_GL_FUNCTION_TYPE debugGLCreateShader(GrGLenum type) {
843
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000844 GrAlwaysAssert(GR_GL_VERTEX_SHADER == type ||
845 GR_GL_FRAGMENT_SHADER == type);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000846
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000847 GrShaderObj *shader = GR_CREATE(GrShaderObj, GrDebugGL::kShader_ObjTypes);
848 shader->setType(type);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000849
850 return shader->getID();
851}
852
853GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteProgram(GrGLuint programID) {
854
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000855 GrProgramObj *program = GR_FIND(programID,
856 GrProgramObj,
857 GrDebugGL::kProgram_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000858 GrAlwaysAssert(program);
859
robertphillips@google.com0da37192012-03-19 14:42:13 +0000860 if (program->getRefCount()) {
861 // someone is still using this program so we can't delete it here
862 program->setMarkedForDeletion();
863 } else {
864 program->deleteAction();
865 }
866}
867
868GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteShader(GrGLuint shaderID) {
869
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000870 GrShaderObj *shader = GR_FIND(shaderID,
871 GrShaderObj,
872 GrDebugGL::kShader_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000873 GrAlwaysAssert(shader);
874
robertphillips@google.com0da37192012-03-19 14:42:13 +0000875 if (shader->getRefCount()) {
876 // someone is still using this shader so we can't delete it here
877 shader->setMarkedForDeletion();
878 } else {
879 shader->deleteAction();
880 }
881}
882
883// same function used for all glGen*(GLsize i, GLuint*) functions
884GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenIds(GrGLsizei n, GrGLuint* ids) {
885 static int gCurrID = 1;
886 for (int i = 0; i < n; ++i) {
887 ids[i] = ++gCurrID;
888 }
889}
890
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000891GrGLvoid debugGenObjs(GrDebugGL::GrObjTypes type,
892 GrGLsizei n,
893 GrGLuint* ids) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000894
895 for (int i = 0; i < n; ++i) {
896 GrFakeRefObj *obj = GrDebugGL::getInstance()->createObj(type);
897 GrAlwaysAssert(obj);
898 ids[i] = obj->getID();
899 }
900}
901
robertphillips@google.com0da37192012-03-19 14:42:13 +0000902GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenBuffers(GrGLsizei n, GrGLuint* ids) {
903
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000904 debugGenObjs(GrDebugGL::kBuffer_ObjTypes, n, ids);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000905}
906
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000907GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenFramebuffers(GrGLsizei n,
908 GrGLuint* ids) {
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000909
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000910 debugGenObjs(GrDebugGL::kFrameBuffer_ObjTypes, n, ids);
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000911}
912
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000913GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenRenderbuffers(GrGLsizei n,
914 GrGLuint* ids) {
robertphillips@google.com7c959422012-03-22 20:43:56 +0000915
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000916 debugGenObjs(GrDebugGL::kRenderBuffer_ObjTypes, n, ids);
917}
918
919GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenTextures(GrGLsizei n, GrGLuint* ids) {
920
921 debugGenObjs(GrDebugGL::kTexture_ObjTypes, n, ids);
robertphillips@google.com7c959422012-03-22 20:43:56 +0000922}
923
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000924// same delete function for all glDelete*(GLsize i, const GLuint*) except
925// buffers
926GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteIds(GrGLsizei n,
927 const GrGLuint* ids) {
928}
robertphillips@google.com0da37192012-03-19 14:42:13 +0000929
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000930GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindBuffer(GrGLenum target,
931 GrGLuint bufferID) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000932
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000933 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
934 GR_GL_ELEMENT_ARRAY_BUFFER == target);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000935
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000936 GrBufferObj *buffer = GR_FIND(bufferID,
937 GrBufferObj,
938 GrDebugGL::kBuffer_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000939 // 0 is a permissable bufferID - it unbinds the current buffer
940
941 switch (target) {
942 case GR_GL_ARRAY_BUFFER:
robertphillips@google.com0da37192012-03-19 14:42:13 +0000943 GrDebugGL::getInstance()->setArrayBuffer(buffer);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000944 break;
945 case GR_GL_ELEMENT_ARRAY_BUFFER:
robertphillips@google.com0da37192012-03-19 14:42:13 +0000946 GrDebugGL::getInstance()->setElementArrayBuffer(buffer);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000947 break;
948 default:
949 GrCrash("Unexpected target to glBindBuffer");
950 break;
951 }
952}
953
954// deleting a bound buffer has the side effect of binding 0
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000955GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteBuffers(GrGLsizei n,
956 const GrGLuint* ids) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000957 // first potentially unbind the buffers
958 for (int i = 0; i < n; ++i) {
959
960 if (GrDebugGL::getInstance()->getArrayBuffer() &&
961 ids[i] == GrDebugGL::getInstance()->getArrayBuffer()->getID()) {
962 // this ID is the current array buffer
robertphillips@google.com0da37192012-03-19 14:42:13 +0000963 GrDebugGL::getInstance()->setArrayBuffer(NULL);
964 }
965 if (GrDebugGL::getInstance()->getElementArrayBuffer() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000966 ids[i] ==
967 GrDebugGL::getInstance()->getElementArrayBuffer()->getID()) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000968 // this ID is the current element array buffer
robertphillips@google.com0da37192012-03-19 14:42:13 +0000969 GrDebugGL::getInstance()->setElementArrayBuffer(NULL);
970 }
971 }
972
973 // then actually "delete" the buffers
974 for (int i = 0; i < n; ++i) {
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000975 GrBufferObj *buffer = GR_FIND(ids[i],
976 GrBufferObj,
977 GrDebugGL::kBuffer_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000978 GrAlwaysAssert(buffer);
979
980 GrAlwaysAssert(!buffer->getDeleted());
981 buffer->deleteAction();
982 }
983}
984
985// map a buffer to the caller's address space
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000986GrGLvoid* GR_GL_FUNCTION_TYPE debugGLMapBuffer(GrGLenum target,
987 GrGLenum access) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000988
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000989 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
990 GR_GL_ELEMENT_ARRAY_BUFFER == target);
991 // GR_GL_READ_ONLY == access || || GR_GL_READ_WRIT == access);
992 GrAlwaysAssert(GR_GL_WRITE_ONLY == access);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000993
994 GrBufferObj *buffer = NULL;
995 switch (target) {
996 case GR_GL_ARRAY_BUFFER:
997 buffer = GrDebugGL::getInstance()->getArrayBuffer();
998 break;
999 case GR_GL_ELEMENT_ARRAY_BUFFER:
1000 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
1001 break;
1002 default:
1003 GrCrash("Unexpected target to glMapBuffer");
1004 break;
1005 }
1006
1007 if (buffer) {
1008 GrAlwaysAssert(!buffer->getMapped());
1009 buffer->setMapped();
1010 return buffer->getDataPtr();
1011 }
1012
1013 GrAlwaysAssert(false);
1014 return NULL; // no buffer bound to the target
1015}
1016
1017// remove a buffer from the caller's address space
1018// TODO: check if the "access" method from "glMapBuffer" was honored
1019GrGLboolean GR_GL_FUNCTION_TYPE debugGLUnmapBuffer(GrGLenum target) {
1020
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001021 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
1022 GR_GL_ELEMENT_ARRAY_BUFFER == target);
robertphillips@google.com0da37192012-03-19 14:42:13 +00001023
1024 GrBufferObj *buffer = NULL;
1025 switch (target) {
1026 case GR_GL_ARRAY_BUFFER:
1027 buffer = GrDebugGL::getInstance()->getArrayBuffer();
1028 break;
1029 case GR_GL_ELEMENT_ARRAY_BUFFER:
1030 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
1031 break;
1032 default:
1033 GrCrash("Unexpected target to glUnmapBuffer");
1034 break;
1035 }
1036
1037 if (buffer) {
1038 GrAlwaysAssert(buffer->getMapped());
1039 buffer->resetMapped();
1040 return GR_GL_TRUE;
1041 }
1042
1043 GrAlwaysAssert(false);
1044 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION;
1045}
1046
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001047GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetBufferParameteriv(GrGLenum target,
1048 GrGLenum value,
1049 GrGLint* params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001050
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001051 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
1052 GR_GL_ELEMENT_ARRAY_BUFFER == target);
1053 GrAlwaysAssert(GR_GL_BUFFER_SIZE == value ||
1054 GR_GL_BUFFER_USAGE == value);
robertphillips@google.com0da37192012-03-19 14:42:13 +00001055
1056 GrBufferObj *buffer = NULL;
1057 switch (target) {
1058 case GR_GL_ARRAY_BUFFER:
1059 buffer = GrDebugGL::getInstance()->getArrayBuffer();
1060 break;
1061 case GR_GL_ELEMENT_ARRAY_BUFFER:
1062 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
1063 break;
1064 }
1065
1066 GrAlwaysAssert(buffer);
1067
1068 switch (value) {
1069 case GR_GL_BUFFER_MAPPED:
1070 *params = GR_GL_FALSE;
1071 if (buffer)
1072 *params = buffer->getMapped() ? GR_GL_TRUE : GR_GL_FALSE;
1073 break;
1074 case GR_GL_BUFFER_SIZE:
1075 *params = 0;
1076 if (buffer)
1077 *params = buffer->getSize();
1078 break;
1079 case GR_GL_BUFFER_USAGE:
1080 *params = GR_GL_STATIC_DRAW;
1081 if (buffer)
1082 *params = buffer->getUsage();
1083 break;
1084 default:
1085 GrCrash("Unexpected value to glGetBufferParamateriv");
1086 break;
1087 }
1088};
1089
1090GrGLenum GR_GL_FUNCTION_TYPE debugGLGetError() {
1091 return GR_GL_NO_ERROR;
1092}
1093
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001094GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetIntegerv(GrGLenum pname,
1095 GrGLint* params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001096 // TODO: remove from Ganesh the #defines for gets we don't use.
1097 // We would like to minimize gets overall due to performance issues
1098 switch (pname) {
1099 case GR_GL_STENCIL_BITS:
1100 *params = 8;
1101 break;
1102 case GR_GL_SAMPLES:
1103 *params = 1;
1104 break;
1105 case GR_GL_FRAMEBUFFER_BINDING:
1106 *params = 0;
1107 break;
1108 case GR_GL_VIEWPORT:
1109 params[0] = 0;
1110 params[1] = 0;
1111 params[2] = 800;
1112 params[3] = 600;
1113 break;
1114 case GR_GL_MAX_TEXTURE_IMAGE_UNITS:
1115 *params = 8;
1116 break;
robertphillips@google.comf6f123d2012-03-21 17:57:55 +00001117 case GR_GL_MAX_VERTEX_UNIFORM_VECTORS:
1118 *params = kDefaultMaxVertexUniformVectors;
1119 break;
robertphillips@google.com0da37192012-03-19 14:42:13 +00001120 case GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS:
robertphillips@google.comf6f123d2012-03-21 17:57:55 +00001121 *params = kDefaultMaxFragmentUniformVectors;
robertphillips@google.com0da37192012-03-19 14:42:13 +00001122 break;
1123 case GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1124 *params = 16 * 4;
1125 break;
1126 case GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1127 *params = 0;
1128 break;
1129 case GR_GL_COMPRESSED_TEXTURE_FORMATS:
1130 break;
1131 case GR_GL_MAX_TEXTURE_SIZE:
1132 *params = 8192;
1133 break;
1134 case GR_GL_MAX_RENDERBUFFER_SIZE:
1135 *params = 8192;
1136 break;
1137 case GR_GL_MAX_SAMPLES:
1138 *params = 32;
1139 break;
1140 case GR_GL_MAX_VERTEX_ATTRIBS:
robertphillips@google.comf6f123d2012-03-21 17:57:55 +00001141 *params = kDefaultMaxVertexAttribs;
1142 break;
1143 case GR_GL_MAX_VARYING_VECTORS:
1144 *params = kDefaultMaxVaryingVectors;
robertphillips@google.com0da37192012-03-19 14:42:13 +00001145 break;
robertphillips@google.com0da37192012-03-19 14:42:13 +00001146 default:
1147 GrCrash("Unexpected pname to GetIntegerv");
1148 }
1149}
1150// used for both the program and shader info logs
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001151GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetInfoLog(GrGLuint program,
1152 GrGLsizei bufsize,
1153 GrGLsizei* length,
1154 char* infolog) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001155 if (length) {
1156 *length = 0;
1157 }
1158 if (bufsize > 0) {
1159 *infolog = 0;
1160 }
1161}
1162
1163// used for both the program and shader params
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001164GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetShaderOrProgramiv(GrGLuint program,
1165 GrGLenum pname,
1166 GrGLint* params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001167 switch (pname) {
1168 case GR_GL_LINK_STATUS: // fallthru
1169 case GR_GL_COMPILE_STATUS:
1170 *params = GR_GL_TRUE;
1171 break;
1172 case GR_GL_INFO_LOG_LENGTH:
1173 *params = 0;
1174 break;
1175 // we don't expect any other pnames
1176 default:
1177 GrCrash("Unexpected pname to GetProgramiv");
1178 break;
1179 }
1180}
1181
1182namespace {
1183template <typename T>
1184void query_result(GrGLenum GLtarget, GrGLenum pname, T *params) {
1185 switch (pname) {
1186 case GR_GL_QUERY_RESULT_AVAILABLE:
1187 *params = GR_GL_TRUE;
1188 break;
1189 case GR_GL_QUERY_RESULT:
1190 *params = 0;
1191 break;
1192 default:
1193 GrCrash("Unexpected pname passed to GetQueryObject.");
1194 break;
1195 }
1196}
1197}
1198
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001199// Queries on the null GL just don't do anything at all. We could potentially
1200// make the timers work.
1201GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryiv(GrGLenum GLtarget,
1202 GrGLenum pname,
1203 GrGLint *params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001204 switch (pname) {
1205 case GR_GL_CURRENT_QUERY:
1206 *params = 0;
1207 break;
1208 case GR_GL_QUERY_COUNTER_BITS:
1209 *params = 32;
1210 break;
1211 default:
1212 GrCrash("Unexpected pname passed GetQueryiv.");
1213 }
1214}
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001215
1216GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryObjecti64v(GrGLuint id,
1217 GrGLenum pname,
1218 GrGLint64 *params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001219 query_result(id, pname, params);
1220}
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001221
1222GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryObjectiv(GrGLuint id,
1223 GrGLenum pname,
1224 GrGLint *params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001225 query_result(id, pname, params);
1226}
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001227
1228GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryObjectui64v(GrGLuint id,
1229 GrGLenum pname,
1230 GrGLuint64 *params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001231 query_result(id, pname, params);
1232}
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001233
1234GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryObjectuiv(GrGLuint id,
1235 GrGLenum pname,
1236 GrGLuint *params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001237 query_result(id, pname, params);
1238}
1239
1240const GrGLubyte* GR_GL_FUNCTION_TYPE debugGLGetString(GrGLenum name) {
1241 switch (name) {
1242 case GR_GL_EXTENSIONS:
1243 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";
1244 case GR_GL_VERSION:
bsalomon@google.comc345c422012-06-15 14:16:00 +00001245 return (const GrGLubyte*)"4.0 Debug GL";
robertphillips@google.com0da37192012-03-19 14:42:13 +00001246 case GR_GL_SHADING_LANGUAGE_VERSION:
bsalomon@google.comc345c422012-06-15 14:16:00 +00001247 return (const GrGLubyte*)"4.20.8 Debug GLSL";
1248 case GR_GL_VENDOR:
1249 return (const GrGLubyte*)"Debug Vendor";
1250 case GR_GL_RENDERER:
1251 return (const GrGLubyte*)"The Debug (Non-)Renderer";
robertphillips@google.com0da37192012-03-19 14:42:13 +00001252 default:
1253 GrCrash("Unexpected name to GetString");
1254 return NULL;
1255 }
1256}
1257
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001258// we used to use this to query stuff about externally created textures,
1259// now we just require clients to tell us everything about the texture.
1260GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetTexLevelParameteriv(GrGLenum target,
1261 GrGLint level,
1262 GrGLenum pname,
1263 GrGLint* params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001264 GrCrash("Should never query texture parameters.");
1265}
1266
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001267GrGLint GR_GL_FUNCTION_TYPE debugGLGetUniformLocation(GrGLuint program,
1268 const char* name) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001269 static int gUniLocation = 0;
1270 return ++gUniLocation;
1271}
1272
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001273} // end of namespace
1274
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +00001275////////////////////////////////////////////////////////////////////////////////
1276struct GrDebugGLInterface : public GrGLInterface {
1277
1278public:
robertphillips@google.com409566a2012-06-26 20:19:41 +00001279 SK_DECLARE_INST_COUNT(GrDebugGLInterface)
1280
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +00001281 GrDebugGLInterface()
1282 : fWrapped(NULL) {
robertphillips@google.com622a1702012-07-31 19:23:02 +00001283 GrDebugGL::staticRef();
1284 }
1285
1286 virtual ~GrDebugGLInterface() {
1287 GrDebugGL::staticUnRef();
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +00001288 }
1289
1290 void setWrapped(GrGLInterface *interface) {
1291 fWrapped.reset(interface);
1292 }
1293
1294 // TODO: there are some issues w/ wrapping another GL interface inside the
1295 // debug interface:
1296 // Since none of the "gl" methods are member functions they don't get
1297 // a "this" pointer through which to access "fWrapped"
1298 // This could be worked around by having all of them access the
1299 // "glInterface" pointer - i.e., treating the debug interface as a
1300 // true singleton
1301 //
1302 // The problem with this is that we also want to handle OpenGL
1303 // contexts. The natural way to do this is to have multiple debug
1304 // interfaces. Each of which represents a separate context. The
1305 // static ID count would still uniquify IDs across all of them.
1306 // The problem then is that we couldn't treat the debug GL
1307 // interface as a singleton (since there would be one for each
1308 // context).
1309 //
1310 // The solution to this is probably to alter SkDebugGlContext's
1311 // "makeCurrent" method to make a call like "makeCurrent(this)" to
1312 // the debug GL interface (assuming that the application will create
1313 // multiple SkGLContext's) to let it switch between the active
1314 // context. Everything in the GrDebugGL object would then need to be
1315 // moved to a GrContextObj and the GrDebugGL object would just switch
1316 // between them. Note that this approach would also require that
1317 // SkDebugGLContext wrap an arbitrary other context
1318 // and then pass the wrapped interface to the debug GL interface.
1319
1320protected:
1321private:
1322
1323 SkAutoTUnref<GrGLInterface> fWrapped;
1324
1325 typedef GrGLInterface INHERITED;
1326};
1327
robertphillips@google.com409566a2012-06-26 20:19:41 +00001328SK_DEFINE_INST_COUNT(GrDebugGLInterface)
1329
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +00001330////////////////////////////////////////////////////////////////////////////////
robertphillips@google.com0da37192012-03-19 14:42:13 +00001331const GrGLInterface* GrGLCreateDebugInterface() {
robertphillips@google.com409566a2012-06-26 20:19:41 +00001332 GrGLInterface* interface = SkNEW(GrDebugGLInterface);
1333
1334 interface->fBindingsExported = kDesktop_GrGLBinding;
1335 interface->fActiveTexture = debugGLActiveTexture;
1336 interface->fAttachShader = debugGLAttachShader;
1337 interface->fBeginQuery = debugGLBeginQuery;
1338 interface->fBindAttribLocation = debugGLBindAttribLocation;
1339 interface->fBindBuffer = debugGLBindBuffer;
1340 interface->fBindFragDataLocation = debugGLBindFragDataLocation;
1341 interface->fBindTexture = debugGLBindTexture;
1342 interface->fBlendColor = debugGLBlendColor;
1343 interface->fBlendFunc = debugGLBlendFunc;
1344 interface->fBufferData = debugGLBufferData;
1345 interface->fBufferSubData = debugGLBufferSubData;
1346 interface->fClear = debugGLClear;
1347 interface->fClearColor = debugGLClearColor;
1348 interface->fClearStencil = debugGLClearStencil;
1349 interface->fColorMask = debugGLColorMask;
1350 interface->fCompileShader = debugGLCompileShader;
1351 interface->fCompressedTexImage2D = debugGLCompressedTexImage2D;
1352 interface->fCreateProgram = debugGLCreateProgram;
1353 interface->fCreateShader = debugGLCreateShader;
1354 interface->fCullFace = debugGLCullFace;
1355 interface->fDeleteBuffers = debugGLDeleteBuffers;
1356 interface->fDeleteProgram = debugGLDeleteProgram;
1357 interface->fDeleteQueries = debugGLDeleteIds;
1358 interface->fDeleteShader = debugGLDeleteShader;
1359 interface->fDeleteTextures = debugGLDeleteTextures;
1360 interface->fDepthMask = debugGLDepthMask;
1361 interface->fDisable = debugGLDisable;
1362 interface->fDisableVertexAttribArray = debugGLDisableVertexAttribArray;
1363 interface->fDrawArrays = debugGLDrawArrays;
1364 interface->fDrawBuffer = debugGLDrawBuffer;
1365 interface->fDrawBuffers = debugGLDrawBuffers;
1366 interface->fDrawElements = debugGLDrawElements;
1367 interface->fEnable = debugGLEnable;
1368 interface->fEnableVertexAttribArray = debugGLEnableVertexAttribArray;
1369 interface->fEndQuery = debugGLEndQuery;
1370 interface->fFinish = debugGLFinish;
1371 interface->fFlush = debugGLFlush;
1372 interface->fFrontFace = debugGLFrontFace;
1373 interface->fGenBuffers = debugGLGenBuffers;
1374 interface->fGenQueries = debugGLGenIds;
1375 interface->fGenTextures = debugGLGenTextures;
1376 interface->fGetBufferParameteriv = debugGLGetBufferParameteriv;
1377 interface->fGetError = debugGLGetError;
1378 interface->fGetIntegerv = debugGLGetIntegerv;
1379 interface->fGetQueryObjecti64v = debugGLGetQueryObjecti64v;
1380 interface->fGetQueryObjectiv = debugGLGetQueryObjectiv;
1381 interface->fGetQueryObjectui64v = debugGLGetQueryObjectui64v;
1382 interface->fGetQueryObjectuiv = debugGLGetQueryObjectuiv;
1383 interface->fGetQueryiv = debugGLGetQueryiv;
1384 interface->fGetProgramInfoLog = debugGLGetInfoLog;
1385 interface->fGetProgramiv = debugGLGetShaderOrProgramiv;
1386 interface->fGetShaderInfoLog = debugGLGetInfoLog;
1387 interface->fGetShaderiv = debugGLGetShaderOrProgramiv;
1388 interface->fGetString = debugGLGetString;
1389 interface->fGetTexLevelParameteriv = debugGLGetTexLevelParameteriv;
1390 interface->fGetUniformLocation = debugGLGetUniformLocation;
1391 interface->fLineWidth = debugGLLineWidth;
1392 interface->fLinkProgram = debugGLLinkProgram;
1393 interface->fPixelStorei = debugGLPixelStorei;
1394 interface->fQueryCounter = debugGLQueryCounter;
1395 interface->fReadBuffer = debugGLReadBuffer;
1396 interface->fReadPixels = debugGLReadPixels;
1397 interface->fScissor = debugGLScissor;
1398 interface->fShaderSource = debugGLShaderSource;
1399 interface->fStencilFunc = debugGLStencilFunc;
1400 interface->fStencilFuncSeparate = debugGLStencilFuncSeparate;
1401 interface->fStencilMask = debugGLStencilMask;
1402 interface->fStencilMaskSeparate = debugGLStencilMaskSeparate;
1403 interface->fStencilOp = debugGLStencilOp;
1404 interface->fStencilOpSeparate = debugGLStencilOpSeparate;
1405 interface->fTexImage2D = debugGLTexImage2D;
1406 interface->fTexParameteri = debugGLTexParameteri;
1407 interface->fTexParameteriv = debugGLTexParameteriv;
1408 interface->fTexSubImage2D = debugGLTexSubImage2D;
1409 interface->fTexStorage2D = debugGLTexStorage2D;
1410 interface->fUniform1f = debugGLUniform1f;
1411 interface->fUniform1i = debugGLUniform1i;
1412 interface->fUniform1fv = debugGLUniform1fv;
1413 interface->fUniform1iv = debugGLUniform1iv;
1414 interface->fUniform2f = debugGLUniform2f;
1415 interface->fUniform2i = debugGLUniform2i;
1416 interface->fUniform2fv = debugGLUniform2fv;
1417 interface->fUniform2iv = debugGLUniform2iv;
1418 interface->fUniform3f = debugGLUniform3f;
1419 interface->fUniform3i = debugGLUniform3i;
1420 interface->fUniform3fv = debugGLUniform3fv;
1421 interface->fUniform3iv = debugGLUniform3iv;
1422 interface->fUniform4f = debugGLUniform4f;
1423 interface->fUniform4i = debugGLUniform4i;
1424 interface->fUniform4fv = debugGLUniform4fv;
1425 interface->fUniform4iv = debugGLUniform4iv;
1426 interface->fUniformMatrix2fv = debugGLUniformMatrix2fv;
1427 interface->fUniformMatrix3fv = debugGLUniformMatrix3fv;
1428 interface->fUniformMatrix4fv = debugGLUniformMatrix4fv;
1429 interface->fUseProgram = debugGLUseProgram;
1430 interface->fVertexAttrib4fv = debugGLVertexAttrib4fv;
1431 interface->fVertexAttribPointer = debugGLVertexAttribPointer;
1432 interface->fViewport = debugGLViewport;
1433 interface->fBindFramebuffer = debugGLBindFramebuffer;
1434 interface->fBindRenderbuffer = debugGLBindRenderbuffer;
1435 interface->fCheckFramebufferStatus = debugGLCheckFramebufferStatus;
1436 interface->fDeleteFramebuffers = debugGLDeleteFramebuffers;
1437 interface->fDeleteRenderbuffers = debugGLDeleteRenderbuffers;
1438 interface->fFramebufferRenderbuffer = debugGLFramebufferRenderbuffer;
1439 interface->fFramebufferTexture2D = debugGLFramebufferTexture2D;
1440 interface->fGenFramebuffers = debugGLGenFramebuffers;
1441 interface->fGenRenderbuffers = debugGLGenRenderbuffers;
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001442 interface->fGetFramebufferAttachmentParameteriv =
1443 debugGLGetFramebufferAttachmentParameteriv;
robertphillips@google.com409566a2012-06-26 20:19:41 +00001444 interface->fGetRenderbufferParameteriv = debugGLGetRenderbufferParameteriv;
1445 interface->fRenderbufferStorage = debugGLRenderbufferStorage;
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001446 interface->fRenderbufferStorageMultisample =
1447 debugGLRenderbufferStorageMultisample;
robertphillips@google.com409566a2012-06-26 20:19:41 +00001448 interface->fBlitFramebuffer = debugGLBlitFramebuffer;
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001449 interface->fResolveMultisampleFramebuffer =
1450 debugGLResolveMultisampleFramebuffer;
robertphillips@google.com409566a2012-06-26 20:19:41 +00001451 interface->fMapBuffer = debugGLMapBuffer;
1452 interface->fUnmapBuffer = debugGLUnmapBuffer;
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001453 interface->fBindFragDataLocationIndexed =
1454 debugGLBindFragDataLocationIndexed;
robertphillips@google.com409566a2012-06-26 20:19:41 +00001455
1456 return interface;
robertphillips@google.com0da37192012-03-19 14:42:13 +00001457}