blob: 1af17b2f88153b60b6dc3e2843b4e42887616716 [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) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +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////////////////////////////////////////////////////////////////////////////////
rmistry@google.comfbfcd562012-08-23 18:09:54 +000046GrGLvoid GR_GL_FUNCTION_TYPE debugGLAttachShader(GrGLuint programID,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000047 GrGLuint shaderID) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000048
rmistry@google.comfbfcd562012-08-23 18:09:54 +000049 GrProgramObj *program = GR_FIND(programID, GrProgramObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000050 GrDebugGL::kProgram_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +000051 GrAlwaysAssert(program);
52
rmistry@google.comfbfcd562012-08-23 18:09:54 +000053 GrShaderObj *shader = GR_FIND(shaderID,
54 GrShaderObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000055 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
rmistry@google.comfbfcd562012-08-23 18:09:54 +000064GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindAttribLocation(GrGLuint program,
65 GrGLuint index,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000066 const char* name) {
67}
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000068
69////////////////////////////////////////////////////////////////////////////////
rmistry@google.comfbfcd562012-08-23 18:09:54 +000070GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindTexture(GrGLenum target,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000071 GrGLuint textureID) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000072
73 // we don't use cube maps
rmistry@google.comfbfcd562012-08-23 18:09:54 +000074 GrAlwaysAssert(target == GR_GL_TEXTURE_2D);
robertphillips@google.comebde3e02012-07-13 17:45:17 +000075 // || 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
rmistry@google.comfbfcd562012-08-23 18:09:54 +000078 GrTextureObj *texture = GR_FIND(textureID, GrTextureObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000079 GrDebugGL::kTexture_ObjTypes);
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +000080
81 GrDebugGL::getInstance()->setTexture(texture);
82}
83
rmistry@google.comfbfcd562012-08-23 18:09:54 +000084GrGLvoid GR_GL_FUNCTION_TYPE debugGLBlendColor(GrGLclampf red,
85 GrGLclampf green,
86 GrGLclampf blue,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000087 GrGLclampf alpha) {
88}
89
rmistry@google.comfbfcd562012-08-23 18:09:54 +000090GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindFragDataLocation(GrGLuint program,
91 GrGLuint colorNumber,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000092 const GrGLchar* name) {
93}
94
rmistry@google.comfbfcd562012-08-23 18:09:54 +000095GrGLvoid GR_GL_FUNCTION_TYPE debugGLBlendFunc(GrGLenum sfactor,
robertphillips@google.comebde3e02012-07-13 17:45:17 +000096 GrGLenum dfactor) {
97}
robertphillips@google.com0da37192012-03-19 14:42:13 +000098
99////////////////////////////////////////////////////////////////////////////////
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000100GrGLvoid GR_GL_FUNCTION_TYPE debugGLBufferData(GrGLenum target,
101 GrGLsizeiptr size,
102 const GrGLvoid* data,
robertphillips@google.com409566a2012-06-26 20:19:41 +0000103 GrGLenum usage) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000104 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000105 GR_GL_ELEMENT_ARRAY_BUFFER == target);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000106 GrAlwaysAssert(size >= 0);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000107 GrAlwaysAssert(GR_GL_STREAM_DRAW == usage ||
108 GR_GL_STATIC_DRAW == usage ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000109 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
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000131GrGLvoid GR_GL_FUNCTION_TYPE debugGLBufferSubData(GrGLenum target,
132 GrGLintptr offset,
133 GrGLsizeiptr size,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000134 const GrGLvoid* data) {
135}
136
137GrGLvoid GR_GL_FUNCTION_TYPE debugGLClear(GrGLbitfield mask) {
138}
139
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000140GrGLvoid GR_GL_FUNCTION_TYPE debugGLClearColor(GrGLclampf red,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000141 GrGLclampf green,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000142 GrGLclampf blue,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000143 GrGLclampf alpha) {
144}
145
146GrGLvoid GR_GL_FUNCTION_TYPE debugGLClearStencil(GrGLint s) {
147}
148
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000149GrGLvoid GR_GL_FUNCTION_TYPE debugGLColorMask(GrGLboolean red,
150 GrGLboolean green,
151 GrGLboolean blue,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000152 GrGLboolean alpha) {
153}
154
155GrGLvoid GR_GL_FUNCTION_TYPE debugGLCompileShader(GrGLuint shader) {
156}
157
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000158GrGLvoid 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,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000165 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
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000180GrGLvoid GR_GL_FUNCTION_TYPE debugGLDrawArrays(GrGLenum mode,
181 GrGLint first,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000182 GrGLsizei count) {
183}
184
185GrGLvoid GR_GL_FUNCTION_TYPE debugGLDrawBuffer(GrGLenum mode) {
186}
187
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000188GrGLvoid GR_GL_FUNCTION_TYPE debugGLDrawBuffers(GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000189 const GrGLenum* bufs) {
190}
191
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000192GrGLvoid GR_GL_FUNCTION_TYPE debugGLDrawElements(GrGLenum mode,
193 GrGLsizei count,
194 GrGLenum type,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000195 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
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000222GrGLvoid GR_GL_FUNCTION_TYPE debugGLPixelStorei(GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000223 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
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000243GrGLvoid GR_GL_FUNCTION_TYPE debugGLQueryCounter(GrGLuint id,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000244 GrGLenum target) {
245}
246
247GrGLvoid GR_GL_FUNCTION_TYPE debugGLReadBuffer(GrGLenum src) {
248}
249
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000250GrGLvoid 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 {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000300 float fTemp =
301 sk_float_ceil(componentSize * componentsPerPixel * pixelsInRow /
robertphillips@google.com670ff9a2012-04-12 19:53:31 +0000302 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
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000313GrGLvoid GR_GL_FUNCTION_TYPE debugGLScissor(GrGLint x,
314 GrGLint y,
315 GrGLsizei width,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000316 GrGLsizei height) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000317}
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000318
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000319GrGLvoid GR_GL_FUNCTION_TYPE debugGLShaderSource(GrGLuint shader,
320 GrGLsizei count,
senorblanco@chromium.orge0d44ff2012-11-19 20:43:10 +0000321#if GR_USE_NEW_GL_SHADER_SOURCE_SIGNATURE
322 const char* const * str,
323#else
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000324 const char** str,
senorblanco@chromium.orge0d44ff2012-11-19 20:43:10 +0000325#endif
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000326 const GrGLint* length) {
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000327}
328
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000329GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilFunc(GrGLenum func,
330 GrGLint ref,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000331 GrGLuint mask) {
robertphillips@google.com7c959422012-03-22 20:43:56 +0000332}
333
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000334GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilFuncSeparate(GrGLenum face,
335 GrGLenum func,
336 GrGLint ref,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000337 GrGLuint mask) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000338}
339
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000340GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilMask(GrGLuint mask) {
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000341}
342
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000343GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilMaskSeparate(GrGLenum face,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000344 GrGLuint mask) {
robertphillips@google.com7c959422012-03-22 20:43:56 +0000345}
346
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000347GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilOp(GrGLenum fail,
348 GrGLenum zfail,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000349 GrGLenum zpass) {
robertphillips@google.com7c959422012-03-22 20:43:56 +0000350}
351
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000352GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilOpSeparate(GrGLenum face,
353 GrGLenum fail,
354 GrGLenum zfail,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000355 GrGLenum zpass) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000356}
357
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000358GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexImage2D(GrGLenum target,
359 GrGLint level,
360 GrGLint internalformat,
361 GrGLsizei width,
362 GrGLsizei height,
363 GrGLint border,
364 GrGLenum format,
365 GrGLenum type,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000366 const GrGLvoid* pixels) {
367}
368
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000369GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexParameteri(GrGLenum target,
370 GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000371 GrGLint param) {
372}
373
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000374GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexParameteriv(GrGLenum target,
375 GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000376 const GrGLint* params) {
377}
378
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000379GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexStorage2D(GrGLenum target,
380 GrGLsizei levels,
381 GrGLenum internalformat,
382 GrGLsizei width,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000383 GrGLsizei height) {
384}
385
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000386GrGLvoid GR_GL_FUNCTION_TYPE debugGLTexSubImage2D(GrGLenum target,
387 GrGLint level,
388 GrGLint xoffset,
389 GrGLint yoffset,
390 GrGLsizei width,
391 GrGLsizei height,
392 GrGLenum format,
393 GrGLenum type,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000394 const GrGLvoid* pixels) {
395}
396
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000397GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform1f(GrGLint location,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000398 GrGLfloat v0) {
399}
400
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000401GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform1i(GrGLint location,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000402 GrGLint v0) {
403}
404
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000405GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform1fv(GrGLint location,
406 GrGLsizei count,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000407 const GrGLfloat* v) {
408}
409
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000410GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform1iv(GrGLint location,
411 GrGLsizei count,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000412 const GrGLint* v) {
413}
414
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000415GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform2f(GrGLint location,
416 GrGLfloat v0,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000417 GrGLfloat v1) {
418}
419
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000420GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform2i(GrGLint location,
421 GrGLint v0,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000422 GrGLint v1) {
423}
424
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000425GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform2fv(GrGLint location,
426 GrGLsizei count,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000427 const GrGLfloat* v) {
428}
429
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000430GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform2iv(GrGLint location,
431 GrGLsizei count,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000432 const GrGLint* v) {
433}
434
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000435GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform3f(GrGLint location,
436 GrGLfloat v0,
437 GrGLfloat v1,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000438 GrGLfloat v2) {
439}
440
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000441GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform3i(GrGLint location,
442 GrGLint v0,
443 GrGLint v1,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000444 GrGLint v2) {
445}
446
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000447GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform3fv(GrGLint location,
448 GrGLsizei count,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000449 const GrGLfloat* v) {
450}
451
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000452GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform3iv(GrGLint location,
453 GrGLsizei count,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000454 const GrGLint* v) {
455}
456
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000457GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform4f(GrGLint location,
458 GrGLfloat v0,
459 GrGLfloat v1,
460 GrGLfloat v2,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000461 GrGLfloat v3) {
462}
463
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000464GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform4i(GrGLint location,
465 GrGLint v0,
466 GrGLint v1,
467 GrGLint v2,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000468 GrGLint v3) {
469}
470
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000471GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform4fv(GrGLint location,
472 GrGLsizei count,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000473 const GrGLfloat* v) {
474 }
475
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000476 GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniform4iv(GrGLint location,
477 GrGLsizei count,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000478 const GrGLint* v) {
479 }
480
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000481 GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniformMatrix2fv(GrGLint location,
482 GrGLsizei count,
483 GrGLboolean transpose,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000484 const GrGLfloat* value) {
485 }
486
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000487 GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniformMatrix3fv(GrGLint location,
488 GrGLsizei count,
489 GrGLboolean transpose,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000490 const GrGLfloat* value) {
491 }
492
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000493 GrGLvoid GR_GL_FUNCTION_TYPE debugGLUniformMatrix4fv(GrGLint location,
494 GrGLsizei count,
495 GrGLboolean transpose,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000496 const GrGLfloat* value) {
497 }
498
499 GrGLvoid GR_GL_FUNCTION_TYPE debugGLUseProgram(GrGLuint programID) {
500
501 // A programID of 0 is legal
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000502 GrProgramObj *program = GR_FIND(programID,
503 GrProgramObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000504 GrDebugGL::kProgram_ObjTypes);
505
506 GrDebugGL::getInstance()->useProgram(program);
507 }
508
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000509 GrGLvoid GR_GL_FUNCTION_TYPE debugGLVertexAttrib4fv(GrGLuint indx,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000510 const GrGLfloat* values) {
511 }
512
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000513 GrGLvoid GR_GL_FUNCTION_TYPE debugGLVertexAttribPointer(GrGLuint indx,
514 GrGLint size,
515 GrGLenum type,
516 GrGLboolean normalized,
517 GrGLsizei stride,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000518 const GrGLvoid* ptr) {
519 }
520
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000521 GrGLvoid GR_GL_FUNCTION_TYPE debugGLViewport(GrGLint x,
522 GrGLint y,
523 GrGLsizei width,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000524 GrGLsizei height) {
525 }
526
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000527 GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindFramebuffer(GrGLenum target,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000528 GrGLuint frameBufferID) {
529
530 GrAlwaysAssert(GR_GL_FRAMEBUFFER == target);
531
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000532 // a frameBufferID of 0 is acceptable - it binds to the default
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000533 // frame buffer
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000534 GrFrameBufferObj *frameBuffer = GR_FIND(frameBufferID,
535 GrFrameBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000536 GrDebugGL::kFrameBuffer_ObjTypes);
537
538 GrDebugGL::getInstance()->setFrameBuffer(frameBuffer);
539 }
540
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000541 GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindRenderbuffer(GrGLenum target,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000542 GrGLuint renderBufferID) {
543
544 GrAlwaysAssert(GR_GL_RENDERBUFFER == target);
545
546 // a renderBufferID of 0 is acceptable - it unbinds the bound render buffer
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000547 GrRenderBufferObj *renderBuffer = GR_FIND(renderBufferID,
548 GrRenderBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000549 GrDebugGL::kRenderBuffer_ObjTypes);
550
551 GrDebugGL::getInstance()->setRenderBuffer(renderBuffer);
552 }
553
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000554 GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteTextures(GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000555 const GrGLuint* textures) {
556
557 // first potentially unbind the texture
558 // TODO: move this into GrDebugGL as unBindTexture?
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000559 for (unsigned int i = 0;
560 i < GrDebugGL::getInstance()->getMaxTextureUnits();
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000561 ++i) {
562 GrTextureUnitObj *pTU = GrDebugGL::getInstance()->getTextureUnit(i);
563
564 if (pTU->getTexture()) {
565 for (int j = 0; j < n; ++j) {
566
567 if (textures[j] == pTU->getTexture()->getID()) {
568 // this ID is the current texture - revert the binding to 0
569 pTU->setTexture(NULL);
570 }
571 }
572 }
573 }
574
575 // TODO: fuse the following block with DeleteRenderBuffers?
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000576 // Open GL will remove a deleted render buffer from the active
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000577 // frame buffer but not from any other frame buffer
578 if (GrDebugGL::getInstance()->getFrameBuffer()) {
579
580 GrFrameBufferObj *frameBuffer = GrDebugGL::getInstance()->getFrameBuffer();
581
582 for (int i = 0; i < n; ++i) {
583
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000584 if (NULL != frameBuffer->getColor() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000585 textures[i] == frameBuffer->getColor()->getID()) {
586 frameBuffer->setColor(NULL);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000587 }
588 if (NULL != frameBuffer->getDepth() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000589 textures[i] == frameBuffer->getDepth()->getID()) {
590 frameBuffer->setDepth(NULL);
591 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000592 if (NULL != frameBuffer->getStencil() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000593 textures[i] == frameBuffer->getStencil()->getID()) {
594 frameBuffer->setStencil(NULL);
595 }
596 }
597 }
598
599 // then actually "delete" the buffers
600 for (int i = 0; i < n; ++i) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000601 GrTextureObj *buffer = GR_FIND(textures[i],
602 GrTextureObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000603 GrDebugGL::kTexture_ObjTypes);
604 GrAlwaysAssert(buffer);
605
606 // OpenGL gives no guarantees if a texture is deleted while attached to
607 // something other than the currently bound frame buffer
608 GrAlwaysAssert(!buffer->getBound());
609
610 GrAlwaysAssert(!buffer->getDeleted());
611 buffer->deleteAction();
612 }
613
614 }
615
616
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000617 GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteFramebuffers(GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000618 const GrGLuint *frameBuffers) {
619
620 // first potentially unbind the buffers
621 if (GrDebugGL::getInstance()->getFrameBuffer()) {
622 for (int i = 0; i < n; ++i) {
623
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000624 if (frameBuffers[i] ==
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000625 GrDebugGL::getInstance()->getFrameBuffer()->getID()) {
626 // this ID is the current frame buffer - rebind to the default
627 GrDebugGL::getInstance()->setFrameBuffer(NULL);
628 }
629 }
630 }
631
632 // then actually "delete" the buffers
633 for (int i = 0; i < n; ++i) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000634 GrFrameBufferObj *buffer = GR_FIND(frameBuffers[i],
635 GrFrameBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000636 GrDebugGL::kFrameBuffer_ObjTypes);
637 GrAlwaysAssert(buffer);
638
639 GrAlwaysAssert(!buffer->getDeleted());
640 buffer->deleteAction();
641 }
642 }
643
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000644 GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteRenderbuffers(GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000645 const GrGLuint *renderBuffers) {
646
647 // first potentially unbind the buffers
648 if (GrDebugGL::getInstance()->getRenderBuffer()) {
649 for (int i = 0; i < n; ++i) {
650
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000651 if (renderBuffers[i] ==
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000652 GrDebugGL::getInstance()->getRenderBuffer()->getID()) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000653 // this ID is the current render buffer - make no
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000654 // render buffer be bound
655 GrDebugGL::getInstance()->setRenderBuffer(NULL);
656 }
657 }
658 }
659
660 // TODO: fuse the following block with DeleteTextures?
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000661 // Open GL will remove a deleted render buffer from the active frame
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000662 // buffer but not from any other frame buffer
663 if (GrDebugGL::getInstance()->getFrameBuffer()) {
664
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000665 GrFrameBufferObj *frameBuffer =
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000666 GrDebugGL::getInstance()->getFrameBuffer();
667
668 for (int i = 0; i < n; ++i) {
669
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000670 if (NULL != frameBuffer->getColor() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000671 renderBuffers[i] == frameBuffer->getColor()->getID()) {
672 frameBuffer->setColor(NULL);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000673 }
674 if (NULL != frameBuffer->getDepth() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000675 renderBuffers[i] == frameBuffer->getDepth()->getID()) {
676 frameBuffer->setDepth(NULL);
677 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000678 if (NULL != frameBuffer->getStencil() &&
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000679 renderBuffers[i] == frameBuffer->getStencil()->getID()) {
680 frameBuffer->setStencil(NULL);
681 }
682 }
683 }
684
685 // then actually "delete" the buffers
686 for (int i = 0; i < n; ++i) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000687 GrRenderBufferObj *buffer = GR_FIND(renderBuffers[i],
688 GrRenderBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000689 GrDebugGL::kRenderBuffer_ObjTypes);
690 GrAlwaysAssert(buffer);
691
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000692 // OpenGL gives no guarantees if a render buffer is deleted
693 // while attached to something other than the currently
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000694 // bound frame buffer
695 GrAlwaysAssert(!buffer->getColorBound());
696 GrAlwaysAssert(!buffer->getDepthBound());
697 GrAlwaysAssert(!buffer->getStencilBound());
698
699 GrAlwaysAssert(!buffer->getDeleted());
700 buffer->deleteAction();
701 }
702 }
703
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000704 GrGLvoid GR_GL_FUNCTION_TYPE debugGLFramebufferRenderbuffer(GrGLenum target,
705 GrGLenum attachment,
706 GrGLenum renderbuffertarget,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000707 GrGLuint renderBufferID) {
708
709 GrAlwaysAssert(GR_GL_FRAMEBUFFER == target);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000710 GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment ||
711 GR_GL_DEPTH_ATTACHMENT == attachment ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000712 GR_GL_STENCIL_ATTACHMENT == attachment);
713 GrAlwaysAssert(GR_GL_RENDERBUFFER == renderbuffertarget);
714
715 GrFrameBufferObj *framebuffer = GrDebugGL::getInstance()->getFrameBuffer();
716 // A render buffer cannot be attached to the default framebuffer
717 GrAlwaysAssert(NULL != framebuffer);
718
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000719 // a renderBufferID of 0 is acceptable - it unbinds the current
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000720 // render buffer
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000721 GrRenderBufferObj *renderbuffer = GR_FIND(renderBufferID,
722 GrRenderBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000723 GrDebugGL::kRenderBuffer_ObjTypes);
724
725 switch (attachment) {
726 case GR_GL_COLOR_ATTACHMENT0:
727 framebuffer->setColor(renderbuffer);
728 break;
729 case GR_GL_DEPTH_ATTACHMENT:
730 framebuffer->setDepth(renderbuffer);
731 break;
732 case GR_GL_STENCIL_ATTACHMENT:
733 framebuffer->setStencil(renderbuffer);
734 break;
735 default:
736 GrAlwaysAssert(false);
737 break;
738 };
739
740 }
741
742 ////////////////////////////////////////////////////////////////////////////////
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000743 GrGLvoid GR_GL_FUNCTION_TYPE debugGLFramebufferTexture2D(GrGLenum target,
744 GrGLenum attachment,
745 GrGLenum textarget,
746 GrGLuint textureID,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000747 GrGLint level) {
748
749 GrAlwaysAssert(GR_GL_FRAMEBUFFER == target);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000750 GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment ||
751 GR_GL_DEPTH_ATTACHMENT == attachment ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000752 GR_GL_STENCIL_ATTACHMENT == attachment);
753 GrAlwaysAssert(GR_GL_TEXTURE_2D == textarget);
754
755 GrFrameBufferObj *framebuffer = GrDebugGL::getInstance()->getFrameBuffer();
756 // A texture cannot be attached to the default framebuffer
757 GrAlwaysAssert(NULL != framebuffer);
758
759 // A textureID of 0 is allowed - it unbinds the currently bound texture
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000760 GrTextureObj *texture = GR_FIND(textureID, GrTextureObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000761 GrDebugGL::kTexture_ObjTypes);
762 if (texture) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000763 // The texture shouldn't be bound to a texture unit - this
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000764 // could lead to a feedback loop
765 GrAlwaysAssert(!texture->getBound());
766 }
767
768 GrAlwaysAssert(0 == level);
769
770 switch (attachment) {
771 case GR_GL_COLOR_ATTACHMENT0:
772 framebuffer->setColor(texture);
773 break;
774 case GR_GL_DEPTH_ATTACHMENT:
775 framebuffer->setDepth(texture);
776 break;
777 case GR_GL_STENCIL_ATTACHMENT:
778 framebuffer->setStencil(texture);
779 break;
780 default:
781 GrAlwaysAssert(false);
782 break;
783 };
784 }
785
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000786 GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetFramebufferAttachmentParameteriv(GrGLenum target,
787 GrGLenum attachment,
788 GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000789 GrGLint* params) {
790 }
791
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000792 GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetRenderbufferParameteriv(GrGLenum target,
793 GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000794 GrGLint* params) {
795 }
796
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000797 GrGLvoid GR_GL_FUNCTION_TYPE debugGLRenderbufferStorage(GrGLenum target,
798 GrGLenum internalformat,
799 GrGLsizei width,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000800 GrGLsizei height) {
801 }
802
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000803 GrGLvoid GR_GL_FUNCTION_TYPE debugGLRenderbufferStorageMultisample(GrGLenum target,
804 GrGLsizei samples,
805 GrGLenum internalformat,
806 GrGLsizei width,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000807 GrGLsizei height) {
808 }
809
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000810 GrGLvoid GR_GL_FUNCTION_TYPE debugGLBlitFramebuffer(GrGLint srcX0,
811 GrGLint srcY0,
812 GrGLint srcX1,
813 GrGLint srcY1,
814 GrGLint dstX0,
815 GrGLint dstY0,
816 GrGLint dstX1,
817 GrGLint dstY1,
818 GrGLbitfield mask,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000819 GrGLenum filter) {
820}
821
822GrGLvoid GR_GL_FUNCTION_TYPE debugGLResolveMultisampleFramebuffer() {
823}
824
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000825GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindFragDataLocationIndexed(GrGLuint program,
826 GrGLuint colorNumber,
827 GrGLuint index,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000828 const GrGLchar * name) {
829}
robertphillips@google.com0da37192012-03-19 14:42:13 +0000830
831GrGLenum GR_GL_FUNCTION_TYPE debugGLCheckFramebufferStatus(GrGLenum target) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000832
833 GrAlwaysAssert(GR_GL_FRAMEBUFFER == target);
834
robertphillips@google.com0da37192012-03-19 14:42:13 +0000835 return GR_GL_FRAMEBUFFER_COMPLETE;
836}
837
838GrGLuint GR_GL_FUNCTION_TYPE debugGLCreateProgram() {
839
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000840 GrProgramObj *program = GR_CREATE(GrProgramObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000841 GrDebugGL::kProgram_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000842
843 return program->getID();
844}
845
846GrGLuint GR_GL_FUNCTION_TYPE debugGLCreateShader(GrGLenum type) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000847
848 GrAlwaysAssert(GR_GL_VERTEX_SHADER == type ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000849 GR_GL_FRAGMENT_SHADER == type);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000850
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000851 GrShaderObj *shader = GR_CREATE(GrShaderObj, GrDebugGL::kShader_ObjTypes);
852 shader->setType(type);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000853
854 return shader->getID();
855}
856
857GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteProgram(GrGLuint programID) {
858
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000859 GrProgramObj *program = GR_FIND(programID,
860 GrProgramObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000861 GrDebugGL::kProgram_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000862 GrAlwaysAssert(program);
863
robertphillips@google.com0da37192012-03-19 14:42:13 +0000864 if (program->getRefCount()) {
865 // someone is still using this program so we can't delete it here
866 program->setMarkedForDeletion();
867 } else {
868 program->deleteAction();
869 }
870}
871
872GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteShader(GrGLuint shaderID) {
873
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000874 GrShaderObj *shader = GR_FIND(shaderID,
875 GrShaderObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000876 GrDebugGL::kShader_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000877 GrAlwaysAssert(shader);
878
robertphillips@google.com0da37192012-03-19 14:42:13 +0000879 if (shader->getRefCount()) {
880 // someone is still using this shader so we can't delete it here
881 shader->setMarkedForDeletion();
882 } else {
883 shader->deleteAction();
884 }
885}
886
887// same function used for all glGen*(GLsize i, GLuint*) functions
888GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenIds(GrGLsizei n, GrGLuint* ids) {
889 static int gCurrID = 1;
890 for (int i = 0; i < n; ++i) {
891 ids[i] = ++gCurrID;
892 }
893}
894
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000895GrGLvoid debugGenObjs(GrDebugGL::GrObjTypes type,
896 GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000897 GrGLuint* ids) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000898
899 for (int i = 0; i < n; ++i) {
900 GrFakeRefObj *obj = GrDebugGL::getInstance()->createObj(type);
901 GrAlwaysAssert(obj);
902 ids[i] = obj->getID();
903 }
904}
905
robertphillips@google.com0da37192012-03-19 14:42:13 +0000906GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenBuffers(GrGLsizei n, GrGLuint* ids) {
907
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000908 debugGenObjs(GrDebugGL::kBuffer_ObjTypes, n, ids);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000909}
910
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000911GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenFramebuffers(GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000912 GrGLuint* ids) {
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000913
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000914 debugGenObjs(GrDebugGL::kFrameBuffer_ObjTypes, n, ids);
robertphillips@google.comf6f123d2012-03-21 17:57:55 +0000915}
916
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000917GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenRenderbuffers(GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000918 GrGLuint* ids) {
robertphillips@google.com7c959422012-03-22 20:43:56 +0000919
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +0000920 debugGenObjs(GrDebugGL::kRenderBuffer_ObjTypes, n, ids);
921}
922
923GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenTextures(GrGLsizei n, GrGLuint* ids) {
924
925 debugGenObjs(GrDebugGL::kTexture_ObjTypes, n, ids);
robertphillips@google.com7c959422012-03-22 20:43:56 +0000926}
927
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000928// same delete function for all glDelete*(GLsize i, const GLuint*) except
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000929// buffers
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000930GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteIds(GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000931 const GrGLuint* ids) {
932}
robertphillips@google.com0da37192012-03-19 14:42:13 +0000933
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000934GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindBuffer(GrGLenum target,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000935 GrGLuint bufferID) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000936
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000937 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000938 GR_GL_ELEMENT_ARRAY_BUFFER == target);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000939
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000940 GrBufferObj *buffer = GR_FIND(bufferID,
941 GrBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000942 GrDebugGL::kBuffer_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000943 // 0 is a permissable bufferID - it unbinds the current buffer
944
945 switch (target) {
946 case GR_GL_ARRAY_BUFFER:
robertphillips@google.com0da37192012-03-19 14:42:13 +0000947 GrDebugGL::getInstance()->setArrayBuffer(buffer);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000948 break;
949 case GR_GL_ELEMENT_ARRAY_BUFFER:
robertphillips@google.com0da37192012-03-19 14:42:13 +0000950 GrDebugGL::getInstance()->setElementArrayBuffer(buffer);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000951 break;
952 default:
953 GrCrash("Unexpected target to glBindBuffer");
954 break;
955 }
956}
957
958// deleting a bound buffer has the side effect of binding 0
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000959GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteBuffers(GrGLsizei n,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000960 const GrGLuint* ids) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000961 // first potentially unbind the buffers
962 for (int i = 0; i < n; ++i) {
963
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000964 if (GrDebugGL::getInstance()->getArrayBuffer() &&
robertphillips@google.com0da37192012-03-19 14:42:13 +0000965 ids[i] == GrDebugGL::getInstance()->getArrayBuffer()->getID()) {
966 // this ID is the current array buffer
robertphillips@google.com0da37192012-03-19 14:42:13 +0000967 GrDebugGL::getInstance()->setArrayBuffer(NULL);
968 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000969 if (GrDebugGL::getInstance()->getElementArrayBuffer() &&
970 ids[i] ==
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000971 GrDebugGL::getInstance()->getElementArrayBuffer()->getID()) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000972 // this ID is the current element array buffer
robertphillips@google.com0da37192012-03-19 14:42:13 +0000973 GrDebugGL::getInstance()->setElementArrayBuffer(NULL);
974 }
975 }
976
977 // then actually "delete" the buffers
978 for (int i = 0; i < n; ++i) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000979 GrBufferObj *buffer = GR_FIND(ids[i],
980 GrBufferObj,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000981 GrDebugGL::kBuffer_ObjTypes);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000982 GrAlwaysAssert(buffer);
983
984 GrAlwaysAssert(!buffer->getDeleted());
985 buffer->deleteAction();
986 }
987}
988
989// map a buffer to the caller's address space
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000990GrGLvoid* GR_GL_FUNCTION_TYPE debugGLMapBuffer(GrGLenum target,
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000991 GrGLenum access) {
robertphillips@google.com0da37192012-03-19 14:42:13 +0000992
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000993 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +0000994 GR_GL_ELEMENT_ARRAY_BUFFER == target);
995 // GR_GL_READ_ONLY == access || || GR_GL_READ_WRIT == access);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000996 GrAlwaysAssert(GR_GL_WRITE_ONLY == access);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000997
998 GrBufferObj *buffer = NULL;
999 switch (target) {
1000 case GR_GL_ARRAY_BUFFER:
1001 buffer = GrDebugGL::getInstance()->getArrayBuffer();
1002 break;
1003 case GR_GL_ELEMENT_ARRAY_BUFFER:
1004 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
1005 break;
1006 default:
1007 GrCrash("Unexpected target to glMapBuffer");
1008 break;
1009 }
1010
1011 if (buffer) {
1012 GrAlwaysAssert(!buffer->getMapped());
1013 buffer->setMapped();
1014 return buffer->getDataPtr();
1015 }
1016
1017 GrAlwaysAssert(false);
1018 return NULL; // no buffer bound to the target
1019}
1020
1021// remove a buffer from the caller's address space
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001022// TODO: check if the "access" method from "glMapBuffer" was honored
robertphillips@google.com0da37192012-03-19 14:42:13 +00001023GrGLboolean GR_GL_FUNCTION_TYPE debugGLUnmapBuffer(GrGLenum target) {
1024
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001025 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001026 GR_GL_ELEMENT_ARRAY_BUFFER == target);
robertphillips@google.com0da37192012-03-19 14:42:13 +00001027
1028 GrBufferObj *buffer = NULL;
1029 switch (target) {
1030 case GR_GL_ARRAY_BUFFER:
1031 buffer = GrDebugGL::getInstance()->getArrayBuffer();
1032 break;
1033 case GR_GL_ELEMENT_ARRAY_BUFFER:
1034 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
1035 break;
1036 default:
1037 GrCrash("Unexpected target to glUnmapBuffer");
1038 break;
1039 }
1040
1041 if (buffer) {
1042 GrAlwaysAssert(buffer->getMapped());
1043 buffer->resetMapped();
1044 return GR_GL_TRUE;
1045 }
1046
1047 GrAlwaysAssert(false);
1048 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION;
1049}
1050
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001051GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetBufferParameteriv(GrGLenum target,
1052 GrGLenum value,
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001053 GrGLint* params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001054
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001055 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001056 GR_GL_ELEMENT_ARRAY_BUFFER == target);
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001057 GrAlwaysAssert(GR_GL_BUFFER_SIZE == value ||
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001058 GR_GL_BUFFER_USAGE == value);
robertphillips@google.com0da37192012-03-19 14:42:13 +00001059
1060 GrBufferObj *buffer = NULL;
1061 switch (target) {
1062 case GR_GL_ARRAY_BUFFER:
1063 buffer = GrDebugGL::getInstance()->getArrayBuffer();
1064 break;
1065 case GR_GL_ELEMENT_ARRAY_BUFFER:
1066 buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001067 break;
robertphillips@google.com0da37192012-03-19 14:42:13 +00001068 }
1069
1070 GrAlwaysAssert(buffer);
1071
1072 switch (value) {
1073 case GR_GL_BUFFER_MAPPED:
1074 *params = GR_GL_FALSE;
1075 if (buffer)
1076 *params = buffer->getMapped() ? GR_GL_TRUE : GR_GL_FALSE;
1077 break;
1078 case GR_GL_BUFFER_SIZE:
1079 *params = 0;
1080 if (buffer)
1081 *params = buffer->getSize();
1082 break;
1083 case GR_GL_BUFFER_USAGE:
1084 *params = GR_GL_STATIC_DRAW;
1085 if (buffer)
1086 *params = buffer->getUsage();
1087 break;
1088 default:
1089 GrCrash("Unexpected value to glGetBufferParamateriv");
1090 break;
1091 }
1092};
1093
1094GrGLenum GR_GL_FUNCTION_TYPE debugGLGetError() {
1095 return GR_GL_NO_ERROR;
1096}
1097
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001098GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetIntegerv(GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001099 GrGLint* params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001100 // TODO: remove from Ganesh the #defines for gets we don't use.
1101 // We would like to minimize gets overall due to performance issues
1102 switch (pname) {
1103 case GR_GL_STENCIL_BITS:
1104 *params = 8;
1105 break;
1106 case GR_GL_SAMPLES:
1107 *params = 1;
1108 break;
1109 case GR_GL_FRAMEBUFFER_BINDING:
1110 *params = 0;
1111 break;
1112 case GR_GL_VIEWPORT:
1113 params[0] = 0;
1114 params[1] = 0;
1115 params[2] = 800;
1116 params[3] = 600;
1117 break;
1118 case GR_GL_MAX_TEXTURE_IMAGE_UNITS:
1119 *params = 8;
1120 break;
robertphillips@google.comf6f123d2012-03-21 17:57:55 +00001121 case GR_GL_MAX_VERTEX_UNIFORM_VECTORS:
1122 *params = kDefaultMaxVertexUniformVectors;
1123 break;
robertphillips@google.com0da37192012-03-19 14:42:13 +00001124 case GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS:
robertphillips@google.comf6f123d2012-03-21 17:57:55 +00001125 *params = kDefaultMaxFragmentUniformVectors;
robertphillips@google.com0da37192012-03-19 14:42:13 +00001126 break;
1127 case GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1128 *params = 16 * 4;
1129 break;
1130 case GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1131 *params = 0;
1132 break;
1133 case GR_GL_COMPRESSED_TEXTURE_FORMATS:
1134 break;
1135 case GR_GL_MAX_TEXTURE_SIZE:
1136 *params = 8192;
1137 break;
1138 case GR_GL_MAX_RENDERBUFFER_SIZE:
1139 *params = 8192;
1140 break;
1141 case GR_GL_MAX_SAMPLES:
1142 *params = 32;
1143 break;
1144 case GR_GL_MAX_VERTEX_ATTRIBS:
robertphillips@google.comf6f123d2012-03-21 17:57:55 +00001145 *params = kDefaultMaxVertexAttribs;
1146 break;
1147 case GR_GL_MAX_VARYING_VECTORS:
1148 *params = kDefaultMaxVaryingVectors;
robertphillips@google.com0da37192012-03-19 14:42:13 +00001149 break;
robertphillips@google.com0da37192012-03-19 14:42:13 +00001150 default:
1151 GrCrash("Unexpected pname to GetIntegerv");
1152 }
1153}
1154// used for both the program and shader info logs
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001155GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetInfoLog(GrGLuint program,
1156 GrGLsizei bufsize,
1157 GrGLsizei* length,
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001158 char* infolog) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001159 if (length) {
1160 *length = 0;
1161 }
1162 if (bufsize > 0) {
1163 *infolog = 0;
1164 }
1165}
1166
1167// used for both the program and shader params
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001168GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetShaderOrProgramiv(GrGLuint program,
1169 GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001170 GrGLint* params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001171 switch (pname) {
1172 case GR_GL_LINK_STATUS: // fallthru
1173 case GR_GL_COMPILE_STATUS:
1174 *params = GR_GL_TRUE;
1175 break;
1176 case GR_GL_INFO_LOG_LENGTH:
1177 *params = 0;
1178 break;
1179 // we don't expect any other pnames
1180 default:
1181 GrCrash("Unexpected pname to GetProgramiv");
1182 break;
1183 }
1184}
1185
1186namespace {
1187template <typename T>
1188void query_result(GrGLenum GLtarget, GrGLenum pname, T *params) {
1189 switch (pname) {
1190 case GR_GL_QUERY_RESULT_AVAILABLE:
1191 *params = GR_GL_TRUE;
1192 break;
1193 case GR_GL_QUERY_RESULT:
1194 *params = 0;
1195 break;
1196 default:
1197 GrCrash("Unexpected pname passed to GetQueryObject.");
1198 break;
1199 }
1200}
1201}
1202
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001203// Queries on the null GL just don't do anything at all. We could potentially
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001204// make the timers work.
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001205GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryiv(GrGLenum GLtarget,
1206 GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001207 GrGLint *params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001208 switch (pname) {
1209 case GR_GL_CURRENT_QUERY:
1210 *params = 0;
1211 break;
1212 case GR_GL_QUERY_COUNTER_BITS:
1213 *params = 32;
1214 break;
1215 default:
1216 GrCrash("Unexpected pname passed GetQueryiv.");
1217 }
1218}
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001219
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001220GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryObjecti64v(GrGLuint id,
1221 GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001222 GrGLint64 *params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001223 query_result(id, pname, params);
1224}
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001225
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001226GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryObjectiv(GrGLuint id,
1227 GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001228 GrGLint *params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001229 query_result(id, pname, params);
1230}
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001231
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001232GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryObjectui64v(GrGLuint id,
1233 GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001234 GrGLuint64 *params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001235 query_result(id, pname, params);
1236}
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001237
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001238GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetQueryObjectuiv(GrGLuint id,
1239 GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001240 GrGLuint *params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001241 query_result(id, pname, params);
1242}
1243
1244const GrGLubyte* GR_GL_FUNCTION_TYPE debugGLGetString(GrGLenum name) {
1245 switch (name) {
1246 case GR_GL_EXTENSIONS:
1247 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";
1248 case GR_GL_VERSION:
bsalomon@google.comc345c422012-06-15 14:16:00 +00001249 return (const GrGLubyte*)"4.0 Debug GL";
robertphillips@google.com0da37192012-03-19 14:42:13 +00001250 case GR_GL_SHADING_LANGUAGE_VERSION:
bsalomon@google.comc345c422012-06-15 14:16:00 +00001251 return (const GrGLubyte*)"4.20.8 Debug GLSL";
1252 case GR_GL_VENDOR:
1253 return (const GrGLubyte*)"Debug Vendor";
1254 case GR_GL_RENDERER:
1255 return (const GrGLubyte*)"The Debug (Non-)Renderer";
robertphillips@google.com0da37192012-03-19 14:42:13 +00001256 default:
1257 GrCrash("Unexpected name to GetString");
1258 return NULL;
1259 }
1260}
1261
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001262// we used to use this to query stuff about externally created textures,
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001263// now we just require clients to tell us everything about the texture.
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001264GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetTexLevelParameteriv(GrGLenum target,
1265 GrGLint level,
1266 GrGLenum pname,
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001267 GrGLint* params) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001268 GrCrash("Should never query texture parameters.");
1269}
1270
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001271GrGLint GR_GL_FUNCTION_TYPE debugGLGetUniformLocation(GrGLuint program,
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001272 const char* name) {
robertphillips@google.com0da37192012-03-19 14:42:13 +00001273 static int gUniLocation = 0;
1274 return ++gUniLocation;
1275}
1276
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001277} // end of namespace
1278
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +00001279////////////////////////////////////////////////////////////////////////////////
1280struct GrDebugGLInterface : public GrGLInterface {
1281
1282public:
robertphillips@google.com409566a2012-06-26 20:19:41 +00001283 SK_DECLARE_INST_COUNT(GrDebugGLInterface)
1284
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +00001285 GrDebugGLInterface()
1286 : fWrapped(NULL) {
robertphillips@google.com622a1702012-07-31 19:23:02 +00001287 GrDebugGL::staticRef();
1288 }
1289
1290 virtual ~GrDebugGLInterface() {
1291 GrDebugGL::staticUnRef();
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +00001292 }
1293
1294 void setWrapped(GrGLInterface *interface) {
1295 fWrapped.reset(interface);
1296 }
1297
1298 // TODO: there are some issues w/ wrapping another GL interface inside the
1299 // debug interface:
1300 // Since none of the "gl" methods are member functions they don't get
1301 // a "this" pointer through which to access "fWrapped"
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001302 // This could be worked around by having all of them access the
1303 // "glInterface" pointer - i.e., treating the debug interface as a
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +00001304 // true singleton
1305 //
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001306 // The problem with this is that we also want to handle OpenGL
1307 // contexts. The natural way to do this is to have multiple debug
1308 // interfaces. Each of which represents a separate context. The
1309 // static ID count would still uniquify IDs across all of them.
1310 // The problem then is that we couldn't treat the debug GL
1311 // interface as a singleton (since there would be one for each
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +00001312 // context).
1313 //
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001314 // The solution to this is probably to alter SkDebugGlContext's
1315 // "makeCurrent" method to make a call like "makeCurrent(this)" to
1316 // the debug GL interface (assuming that the application will create
1317 // multiple SkGLContext's) to let it switch between the active
1318 // context. Everything in the GrDebugGL object would then need to be
1319 // moved to a GrContextObj and the GrDebugGL object would just switch
1320 // between them. Note that this approach would also require that
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +00001321 // SkDebugGLContext wrap an arbitrary other context
1322 // and then pass the wrapped interface to the debug GL interface.
1323
1324protected:
1325private:
1326
1327 SkAutoTUnref<GrGLInterface> fWrapped;
1328
1329 typedef GrGLInterface INHERITED;
1330};
1331
robertphillips@google.com409566a2012-06-26 20:19:41 +00001332SK_DEFINE_INST_COUNT(GrDebugGLInterface)
1333
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +00001334////////////////////////////////////////////////////////////////////////////////
robertphillips@google.com0da37192012-03-19 14:42:13 +00001335const GrGLInterface* GrGLCreateDebugInterface() {
robertphillips@google.com409566a2012-06-26 20:19:41 +00001336 GrGLInterface* interface = SkNEW(GrDebugGLInterface);
1337
1338 interface->fBindingsExported = kDesktop_GrGLBinding;
1339 interface->fActiveTexture = debugGLActiveTexture;
1340 interface->fAttachShader = debugGLAttachShader;
1341 interface->fBeginQuery = debugGLBeginQuery;
1342 interface->fBindAttribLocation = debugGLBindAttribLocation;
1343 interface->fBindBuffer = debugGLBindBuffer;
1344 interface->fBindFragDataLocation = debugGLBindFragDataLocation;
1345 interface->fBindTexture = debugGLBindTexture;
1346 interface->fBlendColor = debugGLBlendColor;
1347 interface->fBlendFunc = debugGLBlendFunc;
1348 interface->fBufferData = debugGLBufferData;
1349 interface->fBufferSubData = debugGLBufferSubData;
1350 interface->fClear = debugGLClear;
1351 interface->fClearColor = debugGLClearColor;
1352 interface->fClearStencil = debugGLClearStencil;
1353 interface->fColorMask = debugGLColorMask;
1354 interface->fCompileShader = debugGLCompileShader;
1355 interface->fCompressedTexImage2D = debugGLCompressedTexImage2D;
1356 interface->fCreateProgram = debugGLCreateProgram;
1357 interface->fCreateShader = debugGLCreateShader;
1358 interface->fCullFace = debugGLCullFace;
1359 interface->fDeleteBuffers = debugGLDeleteBuffers;
1360 interface->fDeleteProgram = debugGLDeleteProgram;
1361 interface->fDeleteQueries = debugGLDeleteIds;
1362 interface->fDeleteShader = debugGLDeleteShader;
1363 interface->fDeleteTextures = debugGLDeleteTextures;
1364 interface->fDepthMask = debugGLDepthMask;
1365 interface->fDisable = debugGLDisable;
1366 interface->fDisableVertexAttribArray = debugGLDisableVertexAttribArray;
1367 interface->fDrawArrays = debugGLDrawArrays;
1368 interface->fDrawBuffer = debugGLDrawBuffer;
1369 interface->fDrawBuffers = debugGLDrawBuffers;
1370 interface->fDrawElements = debugGLDrawElements;
1371 interface->fEnable = debugGLEnable;
1372 interface->fEnableVertexAttribArray = debugGLEnableVertexAttribArray;
1373 interface->fEndQuery = debugGLEndQuery;
1374 interface->fFinish = debugGLFinish;
1375 interface->fFlush = debugGLFlush;
1376 interface->fFrontFace = debugGLFrontFace;
1377 interface->fGenBuffers = debugGLGenBuffers;
1378 interface->fGenQueries = debugGLGenIds;
1379 interface->fGenTextures = debugGLGenTextures;
1380 interface->fGetBufferParameteriv = debugGLGetBufferParameteriv;
1381 interface->fGetError = debugGLGetError;
1382 interface->fGetIntegerv = debugGLGetIntegerv;
1383 interface->fGetQueryObjecti64v = debugGLGetQueryObjecti64v;
1384 interface->fGetQueryObjectiv = debugGLGetQueryObjectiv;
1385 interface->fGetQueryObjectui64v = debugGLGetQueryObjectui64v;
1386 interface->fGetQueryObjectuiv = debugGLGetQueryObjectuiv;
1387 interface->fGetQueryiv = debugGLGetQueryiv;
1388 interface->fGetProgramInfoLog = debugGLGetInfoLog;
1389 interface->fGetProgramiv = debugGLGetShaderOrProgramiv;
1390 interface->fGetShaderInfoLog = debugGLGetInfoLog;
1391 interface->fGetShaderiv = debugGLGetShaderOrProgramiv;
1392 interface->fGetString = debugGLGetString;
1393 interface->fGetTexLevelParameteriv = debugGLGetTexLevelParameteriv;
1394 interface->fGetUniformLocation = debugGLGetUniformLocation;
1395 interface->fLineWidth = debugGLLineWidth;
1396 interface->fLinkProgram = debugGLLinkProgram;
1397 interface->fPixelStorei = debugGLPixelStorei;
1398 interface->fQueryCounter = debugGLQueryCounter;
1399 interface->fReadBuffer = debugGLReadBuffer;
1400 interface->fReadPixels = debugGLReadPixels;
1401 interface->fScissor = debugGLScissor;
1402 interface->fShaderSource = debugGLShaderSource;
1403 interface->fStencilFunc = debugGLStencilFunc;
1404 interface->fStencilFuncSeparate = debugGLStencilFuncSeparate;
1405 interface->fStencilMask = debugGLStencilMask;
1406 interface->fStencilMaskSeparate = debugGLStencilMaskSeparate;
1407 interface->fStencilOp = debugGLStencilOp;
1408 interface->fStencilOpSeparate = debugGLStencilOpSeparate;
1409 interface->fTexImage2D = debugGLTexImage2D;
1410 interface->fTexParameteri = debugGLTexParameteri;
1411 interface->fTexParameteriv = debugGLTexParameteriv;
1412 interface->fTexSubImage2D = debugGLTexSubImage2D;
1413 interface->fTexStorage2D = debugGLTexStorage2D;
1414 interface->fUniform1f = debugGLUniform1f;
1415 interface->fUniform1i = debugGLUniform1i;
1416 interface->fUniform1fv = debugGLUniform1fv;
1417 interface->fUniform1iv = debugGLUniform1iv;
1418 interface->fUniform2f = debugGLUniform2f;
1419 interface->fUniform2i = debugGLUniform2i;
1420 interface->fUniform2fv = debugGLUniform2fv;
1421 interface->fUniform2iv = debugGLUniform2iv;
1422 interface->fUniform3f = debugGLUniform3f;
1423 interface->fUniform3i = debugGLUniform3i;
1424 interface->fUniform3fv = debugGLUniform3fv;
1425 interface->fUniform3iv = debugGLUniform3iv;
1426 interface->fUniform4f = debugGLUniform4f;
1427 interface->fUniform4i = debugGLUniform4i;
1428 interface->fUniform4fv = debugGLUniform4fv;
1429 interface->fUniform4iv = debugGLUniform4iv;
1430 interface->fUniformMatrix2fv = debugGLUniformMatrix2fv;
1431 interface->fUniformMatrix3fv = debugGLUniformMatrix3fv;
1432 interface->fUniformMatrix4fv = debugGLUniformMatrix4fv;
1433 interface->fUseProgram = debugGLUseProgram;
1434 interface->fVertexAttrib4fv = debugGLVertexAttrib4fv;
1435 interface->fVertexAttribPointer = debugGLVertexAttribPointer;
1436 interface->fViewport = debugGLViewport;
1437 interface->fBindFramebuffer = debugGLBindFramebuffer;
1438 interface->fBindRenderbuffer = debugGLBindRenderbuffer;
1439 interface->fCheckFramebufferStatus = debugGLCheckFramebufferStatus;
1440 interface->fDeleteFramebuffers = debugGLDeleteFramebuffers;
1441 interface->fDeleteRenderbuffers = debugGLDeleteRenderbuffers;
1442 interface->fFramebufferRenderbuffer = debugGLFramebufferRenderbuffer;
1443 interface->fFramebufferTexture2D = debugGLFramebufferTexture2D;
1444 interface->fGenFramebuffers = debugGLGenFramebuffers;
1445 interface->fGenRenderbuffers = debugGLGenRenderbuffers;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001446 interface->fGetFramebufferAttachmentParameteriv =
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001447 debugGLGetFramebufferAttachmentParameteriv;
robertphillips@google.com409566a2012-06-26 20:19:41 +00001448 interface->fGetRenderbufferParameteriv = debugGLGetRenderbufferParameteriv;
1449 interface->fRenderbufferStorage = debugGLRenderbufferStorage;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001450 interface->fRenderbufferStorageMultisample =
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001451 debugGLRenderbufferStorageMultisample;
robertphillips@google.com409566a2012-06-26 20:19:41 +00001452 interface->fBlitFramebuffer = debugGLBlitFramebuffer;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001453 interface->fResolveMultisampleFramebuffer =
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001454 debugGLResolveMultisampleFramebuffer;
robertphillips@google.com409566a2012-06-26 20:19:41 +00001455 interface->fMapBuffer = debugGLMapBuffer;
1456 interface->fUnmapBuffer = debugGLUnmapBuffer;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001457 interface->fBindFragDataLocationIndexed =
robertphillips@google.comebde3e02012-07-13 17:45:17 +00001458 debugGLBindFragDataLocationIndexed;
robertphillips@google.com409566a2012-06-26 20:19:41 +00001459
1460 return interface;
robertphillips@google.com0da37192012-03-19 14:42:13 +00001461}