1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // capture_gles2_params.cpp:
7 // Pointer parameter capture functions for the OpenGL ES 2.0 entry points.
8
9 #include "libANGLE/capture/capture_gles_2_0_autogen.h"
10
11 #include "libANGLE/Context.h"
12 #include "libANGLE/Shader.h"
13 #include "libANGLE/formatutils.h"
14 #include "libGLESv2/global_state.h"
15
16 using namespace angle;
17
18 namespace gl
19 {
20 // Parameter Captures
21
CaptureBindAttribLocation_name(const State & glState,bool isCallValid,ShaderProgramID program,GLuint index,const GLchar * name,ParamCapture * paramCapture)22 void CaptureBindAttribLocation_name(const State &glState,
23 bool isCallValid,
24 ShaderProgramID program,
25 GLuint index,
26 const GLchar *name,
27 ParamCapture *paramCapture)
28 {
29 CaptureString(name, paramCapture);
30 }
31
CaptureBufferData_data(const State & glState,bool isCallValid,BufferBinding targetPacked,GLsizeiptr size,const void * data,BufferUsage usagePacked,ParamCapture * paramCapture)32 void CaptureBufferData_data(const State &glState,
33 bool isCallValid,
34 BufferBinding targetPacked,
35 GLsizeiptr size,
36 const void *data,
37 BufferUsage usagePacked,
38 ParamCapture *paramCapture)
39 {
40 if (data)
41 {
42 CaptureMemory(data, size, paramCapture);
43 }
44 }
45
CaptureBufferSubData_data(const State & glState,bool isCallValid,BufferBinding targetPacked,GLintptr offset,GLsizeiptr size,const void * data,ParamCapture * paramCapture)46 void CaptureBufferSubData_data(const State &glState,
47 bool isCallValid,
48 BufferBinding targetPacked,
49 GLintptr offset,
50 GLsizeiptr size,
51 const void *data,
52 ParamCapture *paramCapture)
53 {
54 CaptureMemory(data, size, paramCapture);
55 }
56
CaptureCompressedTexImage2D_data(const State & glState,bool isCallValid,TextureTarget targetPacked,GLint level,GLenum internalformat,GLsizei width,GLsizei height,GLint border,GLsizei imageSize,const void * data,ParamCapture * paramCapture)57 void CaptureCompressedTexImage2D_data(const State &glState,
58 bool isCallValid,
59 TextureTarget targetPacked,
60 GLint level,
61 GLenum internalformat,
62 GLsizei width,
63 GLsizei height,
64 GLint border,
65 GLsizei imageSize,
66 const void *data,
67 ParamCapture *paramCapture)
68 {
69 if (glState.getTargetBuffer(gl::BufferBinding::PixelUnpack))
70 {
71 return;
72 }
73
74 if (!data)
75 {
76 return;
77 }
78
79 CaptureMemory(data, imageSize, paramCapture);
80 }
81
CaptureCompressedTexSubImage2D_data(const State & glState,bool isCallValid,TextureTarget targetPacked,GLint level,GLint xoffset,GLint yoffset,GLsizei width,GLsizei height,GLenum format,GLsizei imageSize,const void * data,ParamCapture * paramCapture)82 void CaptureCompressedTexSubImage2D_data(const State &glState,
83 bool isCallValid,
84 TextureTarget targetPacked,
85 GLint level,
86 GLint xoffset,
87 GLint yoffset,
88 GLsizei width,
89 GLsizei height,
90 GLenum format,
91 GLsizei imageSize,
92 const void *data,
93 ParamCapture *paramCapture)
94 {
95 CaptureCompressedTexImage2D_data(glState, isCallValid, targetPacked, level, 0, width, height, 0,
96 imageSize, data, paramCapture);
97 }
98
CaptureDeleteBuffers_buffersPacked(const State & glState,bool isCallValid,GLsizei n,const BufferID * buffers,ParamCapture * paramCapture)99 void CaptureDeleteBuffers_buffersPacked(const State &glState,
100 bool isCallValid,
101 GLsizei n,
102 const BufferID *buffers,
103 ParamCapture *paramCapture)
104 {
105 CaptureArray(buffers, n, paramCapture);
106 }
107
CaptureDeleteFramebuffers_framebuffersPacked(const State & glState,bool isCallValid,GLsizei n,const FramebufferID * framebuffers,ParamCapture * paramCapture)108 void CaptureDeleteFramebuffers_framebuffersPacked(const State &glState,
109 bool isCallValid,
110 GLsizei n,
111 const FramebufferID *framebuffers,
112 ParamCapture *paramCapture)
113 {
114 CaptureArray(framebuffers, n, paramCapture);
115 }
116
CaptureDeleteRenderbuffers_renderbuffersPacked(const State & glState,bool isCallValid,GLsizei n,const RenderbufferID * renderbuffers,ParamCapture * paramCapture)117 void CaptureDeleteRenderbuffers_renderbuffersPacked(const State &glState,
118 bool isCallValid,
119 GLsizei n,
120 const RenderbufferID *renderbuffers,
121 ParamCapture *paramCapture)
122 {
123 CaptureArray(renderbuffers, n, paramCapture);
124 }
125
CaptureDeleteTextures_texturesPacked(const State & glState,bool isCallValid,GLsizei n,const TextureID * textures,ParamCapture * paramCapture)126 void CaptureDeleteTextures_texturesPacked(const State &glState,
127 bool isCallValid,
128 GLsizei n,
129 const TextureID *textures,
130 ParamCapture *paramCapture)
131 {
132 CaptureArray(textures, n, paramCapture);
133 }
134
CaptureDrawElements_indices(const State & glState,bool isCallValid,PrimitiveMode modePacked,GLsizei count,DrawElementsType typePacked,const void * indices,ParamCapture * paramCapture)135 void CaptureDrawElements_indices(const State &glState,
136 bool isCallValid,
137 PrimitiveMode modePacked,
138 GLsizei count,
139 DrawElementsType typePacked,
140 const void *indices,
141 ParamCapture *paramCapture)
142 {
143 if (glState.getVertexArray()->getElementArrayBuffer())
144 {
145 paramCapture->value.voidConstPointerVal = indices;
146 }
147 else
148 {
149 GLuint typeSize = gl::GetDrawElementsTypeSize(typePacked);
150 CaptureMemory(indices, typeSize * count, paramCapture);
151 paramCapture->value.voidConstPointerVal = paramCapture->data[0].data();
152 }
153 }
154
CaptureGenBuffers_buffersPacked(const State & glState,bool isCallValid,GLsizei n,BufferID * buffers,ParamCapture * paramCapture)155 void CaptureGenBuffers_buffersPacked(const State &glState,
156 bool isCallValid,
157 GLsizei n,
158 BufferID *buffers,
159 ParamCapture *paramCapture)
160 {
161 CaptureGenHandles(n, buffers, paramCapture);
162 }
163
CaptureGenFramebuffers_framebuffersPacked(const State & glState,bool isCallValid,GLsizei n,FramebufferID * framebuffers,ParamCapture * paramCapture)164 void CaptureGenFramebuffers_framebuffersPacked(const State &glState,
165 bool isCallValid,
166 GLsizei n,
167 FramebufferID *framebuffers,
168 ParamCapture *paramCapture)
169 {
170 CaptureGenHandles(n, framebuffers, paramCapture);
171 }
172
CaptureGenRenderbuffers_renderbuffersPacked(const State & glState,bool isCallValid,GLsizei n,RenderbufferID * renderbuffers,ParamCapture * paramCapture)173 void CaptureGenRenderbuffers_renderbuffersPacked(const State &glState,
174 bool isCallValid,
175 GLsizei n,
176 RenderbufferID *renderbuffers,
177 ParamCapture *paramCapture)
178 {
179 CaptureGenHandles(n, renderbuffers, paramCapture);
180 }
181
CaptureGenTextures_texturesPacked(const State & glState,bool isCallValid,GLsizei n,TextureID * textures,ParamCapture * paramCapture)182 void CaptureGenTextures_texturesPacked(const State &glState,
183 bool isCallValid,
184 GLsizei n,
185 TextureID *textures,
186 ParamCapture *paramCapture)
187 {
188 CaptureGenHandles(n, textures, paramCapture);
189 }
190
CaptureGetActiveAttrib_length(const State & glState,bool isCallValid,ShaderProgramID program,GLuint index,GLsizei bufSize,GLsizei * length,GLint * size,GLenum * type,GLchar * name,ParamCapture * paramCapture)191 void CaptureGetActiveAttrib_length(const State &glState,
192 bool isCallValid,
193 ShaderProgramID program,
194 GLuint index,
195 GLsizei bufSize,
196 GLsizei *length,
197 GLint *size,
198 GLenum *type,
199 GLchar *name,
200 ParamCapture *paramCapture)
201 {
202 paramCapture->readBufferSizeBytes = sizeof(GLsizei);
203 }
204
CaptureGetActiveAttrib_size(const State & glState,bool isCallValid,ShaderProgramID program,GLuint index,GLsizei bufSize,GLsizei * length,GLint * size,GLenum * type,GLchar * name,ParamCapture * paramCapture)205 void CaptureGetActiveAttrib_size(const State &glState,
206 bool isCallValid,
207 ShaderProgramID program,
208 GLuint index,
209 GLsizei bufSize,
210 GLsizei *length,
211 GLint *size,
212 GLenum *type,
213 GLchar *name,
214 ParamCapture *paramCapture)
215 {
216 paramCapture->readBufferSizeBytes = sizeof(GLint);
217 }
218
CaptureGetActiveAttrib_type(const State & glState,bool isCallValid,ShaderProgramID program,GLuint index,GLsizei bufSize,GLsizei * length,GLint * size,GLenum * type,GLchar * name,ParamCapture * paramCapture)219 void CaptureGetActiveAttrib_type(const State &glState,
220 bool isCallValid,
221 ShaderProgramID program,
222 GLuint index,
223 GLsizei bufSize,
224 GLsizei *length,
225 GLint *size,
226 GLenum *type,
227 GLchar *name,
228 ParamCapture *paramCapture)
229 {
230 paramCapture->readBufferSizeBytes = sizeof(GLenum);
231 }
232
CaptureGetActiveAttrib_name(const State & glState,bool isCallValid,ShaderProgramID program,GLuint index,GLsizei bufSize,GLsizei * length,GLint * size,GLenum * type,GLchar * name,ParamCapture * paramCapture)233 void CaptureGetActiveAttrib_name(const State &glState,
234 bool isCallValid,
235 ShaderProgramID program,
236 GLuint index,
237 GLsizei bufSize,
238 GLsizei *length,
239 GLint *size,
240 GLenum *type,
241 GLchar *name,
242 ParamCapture *paramCapture)
243 {
244 CaptureStringLimit(name, bufSize, paramCapture);
245 }
246
CaptureGetActiveUniform_length(const State & glState,bool isCallValid,ShaderProgramID program,GLuint index,GLsizei bufSize,GLsizei * length,GLint * size,GLenum * type,GLchar * name,ParamCapture * paramCapture)247 void CaptureGetActiveUniform_length(const State &glState,
248 bool isCallValid,
249 ShaderProgramID program,
250 GLuint index,
251 GLsizei bufSize,
252 GLsizei *length,
253 GLint *size,
254 GLenum *type,
255 GLchar *name,
256 ParamCapture *paramCapture)
257 {
258 paramCapture->readBufferSizeBytes = sizeof(GLsizei);
259 }
260
CaptureGetActiveUniform_size(const State & glState,bool isCallValid,ShaderProgramID program,GLuint index,GLsizei bufSize,GLsizei * length,GLint * size,GLenum * type,GLchar * name,ParamCapture * paramCapture)261 void CaptureGetActiveUniform_size(const State &glState,
262 bool isCallValid,
263 ShaderProgramID program,
264 GLuint index,
265 GLsizei bufSize,
266 GLsizei *length,
267 GLint *size,
268 GLenum *type,
269 GLchar *name,
270 ParamCapture *paramCapture)
271 {
272 paramCapture->readBufferSizeBytes = sizeof(GLint);
273 }
274
CaptureGetActiveUniform_type(const State & glState,bool isCallValid,ShaderProgramID program,GLuint index,GLsizei bufSize,GLsizei * length,GLint * size,GLenum * type,GLchar * name,ParamCapture * paramCapture)275 void CaptureGetActiveUniform_type(const State &glState,
276 bool isCallValid,
277 ShaderProgramID program,
278 GLuint index,
279 GLsizei bufSize,
280 GLsizei *length,
281 GLint *size,
282 GLenum *type,
283 GLchar *name,
284 ParamCapture *paramCapture)
285 {
286 paramCapture->readBufferSizeBytes = sizeof(GLenum);
287 }
288
CaptureGetActiveUniform_name(const State & glState,bool isCallValid,ShaderProgramID program,GLuint index,GLsizei bufSize,GLsizei * length,GLint * size,GLenum * type,GLchar * name,ParamCapture * paramCapture)289 void CaptureGetActiveUniform_name(const State &glState,
290 bool isCallValid,
291 ShaderProgramID program,
292 GLuint index,
293 GLsizei bufSize,
294 GLsizei *length,
295 GLint *size,
296 GLenum *type,
297 GLchar *name,
298 ParamCapture *paramCapture)
299 {
300 CaptureStringLimit(name, bufSize, paramCapture);
301 }
302
CaptureGetAttachedShaders_count(const State & glState,bool isCallValid,ShaderProgramID program,GLsizei maxCount,GLsizei * count,ShaderProgramID * shaders,ParamCapture * paramCapture)303 void CaptureGetAttachedShaders_count(const State &glState,
304 bool isCallValid,
305 ShaderProgramID program,
306 GLsizei maxCount,
307 GLsizei *count,
308 ShaderProgramID *shaders,
309 ParamCapture *paramCapture)
310 {
311 paramCapture->readBufferSizeBytes = sizeof(GLsizei);
312 }
313
CaptureGetAttachedShaders_shadersPacked(const State & glState,bool isCallValid,ShaderProgramID program,GLsizei maxCount,GLsizei * count,ShaderProgramID * shaders,ParamCapture * paramCapture)314 void CaptureGetAttachedShaders_shadersPacked(const State &glState,
315 bool isCallValid,
316 ShaderProgramID program,
317 GLsizei maxCount,
318 GLsizei *count,
319 ShaderProgramID *shaders,
320 ParamCapture *paramCapture)
321 {
322 paramCapture->readBufferSizeBytes = sizeof(ShaderProgramID) * maxCount;
323 }
324
CaptureGetAttribLocation_name(const State & glState,bool isCallValid,ShaderProgramID program,const GLchar * name,ParamCapture * paramCapture)325 void CaptureGetAttribLocation_name(const State &glState,
326 bool isCallValid,
327 ShaderProgramID program,
328 const GLchar *name,
329 ParamCapture *paramCapture)
330 {
331 CaptureString(name, paramCapture);
332 }
333
CaptureGetBooleanv_data(const State & glState,bool isCallValid,GLenum pname,GLboolean * data,ParamCapture * paramCapture)334 void CaptureGetBooleanv_data(const State &glState,
335 bool isCallValid,
336 GLenum pname,
337 GLboolean *data,
338 ParamCapture *paramCapture)
339 {
340 CaptureGetParameter(glState, pname, sizeof(GLboolean), paramCapture);
341 }
342
CaptureGetBufferParameteriv_params(const State & glState,bool isCallValid,BufferBinding targetPacked,GLenum pname,GLint * params,ParamCapture * paramCapture)343 void CaptureGetBufferParameteriv_params(const State &glState,
344 bool isCallValid,
345 BufferBinding targetPacked,
346 GLenum pname,
347 GLint *params,
348 ParamCapture *paramCapture)
349 {
350 paramCapture->readBufferSizeBytes = 8;
351 }
352
CaptureGetFloatv_data(const State & glState,bool isCallValid,GLenum pname,GLfloat * data,ParamCapture * paramCapture)353 void CaptureGetFloatv_data(const State &glState,
354 bool isCallValid,
355 GLenum pname,
356 GLfloat *data,
357 ParamCapture *paramCapture)
358 {
359 CaptureGetParameter(glState, pname, sizeof(GLfloat), paramCapture);
360 }
361
CaptureGetFramebufferAttachmentParameteriv_params(const State & glState,bool isCallValid,GLenum target,GLenum attachment,GLenum pname,GLint * params,ParamCapture * paramCapture)362 void CaptureGetFramebufferAttachmentParameteriv_params(const State &glState,
363 bool isCallValid,
364 GLenum target,
365 GLenum attachment,
366 GLenum pname,
367 GLint *params,
368 ParamCapture *paramCapture)
369 {
370 // All ES 2.0 queries only return one value.
371 paramCapture->readBufferSizeBytes = sizeof(GLint);
372 }
373
CaptureGetIntegerv_data(const State & glState,bool isCallValid,GLenum pname,GLint * data,ParamCapture * paramCapture)374 void CaptureGetIntegerv_data(const State &glState,
375 bool isCallValid,
376 GLenum pname,
377 GLint *data,
378 ParamCapture *paramCapture)
379 {
380 CaptureGetParameter(glState, pname, sizeof(GLint), paramCapture);
381 }
382
CaptureGetProgramInfoLog_length(const State & glState,bool isCallValid,ShaderProgramID program,GLsizei bufSize,GLsizei * length,GLchar * infoLog,ParamCapture * paramCapture)383 void CaptureGetProgramInfoLog_length(const State &glState,
384 bool isCallValid,
385 ShaderProgramID program,
386 GLsizei bufSize,
387 GLsizei *length,
388 GLchar *infoLog,
389 ParamCapture *paramCapture)
390 {
391 paramCapture->readBufferSizeBytes = sizeof(GLsizei);
392 }
393
CaptureGetProgramInfoLog_infoLog(const State & glState,bool isCallValid,ShaderProgramID program,GLsizei bufSize,GLsizei * length,GLchar * infoLog,ParamCapture * paramCapture)394 void CaptureGetProgramInfoLog_infoLog(const State &glState,
395 bool isCallValid,
396 ShaderProgramID program,
397 GLsizei bufSize,
398 GLsizei *length,
399 GLchar *infoLog,
400 ParamCapture *paramCapture)
401 {
402 gl::Program *programObj = GetProgramForCapture(glState, program);
403 ASSERT(programObj);
404 paramCapture->readBufferSizeBytes = programObj->getExecutable().getInfoLogLength() + 1;
405 }
406
CaptureGetProgramiv_params(const State & glState,bool isCallValid,ShaderProgramID program,GLenum pname,GLint * params,ParamCapture * paramCapture)407 void CaptureGetProgramiv_params(const State &glState,
408 bool isCallValid,
409 ShaderProgramID program,
410 GLenum pname,
411 GLint *params,
412 ParamCapture *paramCapture)
413 {
414 if (params)
415 {
416 paramCapture->readBufferSizeBytes = sizeof(GLint);
417 }
418 }
419
CaptureGetRenderbufferParameteriv_params(const State & glState,bool isCallValid,GLenum target,GLenum pname,GLint * params,ParamCapture * paramCapture)420 void CaptureGetRenderbufferParameteriv_params(const State &glState,
421 bool isCallValid,
422 GLenum target,
423 GLenum pname,
424 GLint *params,
425 ParamCapture *paramCapture)
426 {
427 paramCapture->readBufferSizeBytes = sizeof(GLint);
428 }
429
CaptureGetShaderInfoLog_length(const State & glState,bool isCallValid,ShaderProgramID shader,GLsizei bufSize,GLsizei * length,GLchar * infoLog,ParamCapture * paramCapture)430 void CaptureGetShaderInfoLog_length(const State &glState,
431 bool isCallValid,
432 ShaderProgramID shader,
433 GLsizei bufSize,
434 GLsizei *length,
435 GLchar *infoLog,
436 ParamCapture *paramCapture)
437 {
438 paramCapture->readBufferSizeBytes = sizeof(GLsizei);
439 }
440
CaptureGetShaderInfoLog_infoLog(const State & glState,bool isCallValid,ShaderProgramID shader,GLsizei bufSize,GLsizei * length,GLchar * infoLog,ParamCapture * paramCapture)441 void CaptureGetShaderInfoLog_infoLog(const State &glState,
442 bool isCallValid,
443 ShaderProgramID shader,
444 GLsizei bufSize,
445 GLsizei *length,
446 GLchar *infoLog,
447 ParamCapture *paramCapture)
448 {
449 gl::Shader *shaderObj = glState.getShaderProgramManagerForCapture().getShader(shader);
450 ASSERT(shaderObj);
451 paramCapture->readBufferSizeBytes = shaderObj->getInfoLogLength(GetValidGlobalContext()) + 1;
452 }
453
CaptureGetShaderPrecisionFormat_range(const State & glState,bool isCallValid,GLenum shadertype,GLenum precisiontype,GLint * range,GLint * precision,ParamCapture * paramCapture)454 void CaptureGetShaderPrecisionFormat_range(const State &glState,
455 bool isCallValid,
456 GLenum shadertype,
457 GLenum precisiontype,
458 GLint *range,
459 GLint *precision,
460 ParamCapture *paramCapture)
461 {
462 // range specifies a pointer to two-element array containing log2 of min and max
463 paramCapture->readBufferSizeBytes = 2 * sizeof(GLint);
464 }
465
CaptureGetShaderPrecisionFormat_precision(const State & glState,bool isCallValid,GLenum shadertype,GLenum precisiontype,GLint * range,GLint * precision,ParamCapture * paramCapture)466 void CaptureGetShaderPrecisionFormat_precision(const State &glState,
467 bool isCallValid,
468 GLenum shadertype,
469 GLenum precisiontype,
470 GLint *range,
471 GLint *precision,
472 ParamCapture *paramCapture)
473 {
474 paramCapture->readBufferSizeBytes = sizeof(GLint);
475 }
476
CaptureGetShaderSource_length(const State & glState,bool isCallValid,ShaderProgramID shader,GLsizei bufSize,GLsizei * length,GLchar * source,ParamCapture * paramCapture)477 void CaptureGetShaderSource_length(const State &glState,
478 bool isCallValid,
479 ShaderProgramID shader,
480 GLsizei bufSize,
481 GLsizei *length,
482 GLchar *source,
483 ParamCapture *paramCapture)
484 {
485 UNIMPLEMENTED();
486 }
487
CaptureGetShaderSource_source(const State & glState,bool isCallValid,ShaderProgramID shader,GLsizei bufSize,GLsizei * length,GLchar * source,ParamCapture * paramCapture)488 void CaptureGetShaderSource_source(const State &glState,
489 bool isCallValid,
490 ShaderProgramID shader,
491 GLsizei bufSize,
492 GLsizei *length,
493 GLchar *source,
494 ParamCapture *paramCapture)
495 {
496 UNIMPLEMENTED();
497 }
498
CaptureGetShaderiv_params(const State & glState,bool isCallValid,ShaderProgramID shader,GLenum pname,GLint * params,ParamCapture * paramCapture)499 void CaptureGetShaderiv_params(const State &glState,
500 bool isCallValid,
501 ShaderProgramID shader,
502 GLenum pname,
503 GLint *params,
504 ParamCapture *paramCapture)
505 {
506 if (params)
507 {
508 paramCapture->readBufferSizeBytes = sizeof(GLint);
509 }
510 }
511
CaptureGetTexParameterfv_params(const State & glState,bool isCallValid,TextureType targetPacked,GLenum pname,GLfloat * params,ParamCapture * paramCapture)512 void CaptureGetTexParameterfv_params(const State &glState,
513 bool isCallValid,
514 TextureType targetPacked,
515 GLenum pname,
516 GLfloat *params,
517 ParamCapture *paramCapture)
518 {
519 // page 190 https://www.khronos.org/registry/OpenGL/specs/es/3.2/es_spec_3.2.pdf
520 // TEXTURE_BORDER_COLOR: 4 floats, ints, uints
521 paramCapture->readBufferSizeBytes = sizeof(GLfloat) * 4;
522 }
523
CaptureGetTexParameteriv_params(const State & glState,bool isCallValid,TextureType targetPacked,GLenum pname,GLint * params,ParamCapture * paramCapture)524 void CaptureGetTexParameteriv_params(const State &glState,
525 bool isCallValid,
526 TextureType targetPacked,
527 GLenum pname,
528 GLint *params,
529 ParamCapture *paramCapture)
530 {
531 // page 190 https://www.khronos.org/registry/OpenGL/specs/es/3.2/es_spec_3.2.pdf
532 // TEXTURE_BORDER_COLOR: 4 floats, ints, uints
533 paramCapture->readBufferSizeBytes = sizeof(GLint) * 4;
534 }
535
CaptureGetUniformLocation_name(const State & glState,bool isCallValid,ShaderProgramID program,const GLchar * name,ParamCapture * paramCapture)536 void CaptureGetUniformLocation_name(const State &glState,
537 bool isCallValid,
538 ShaderProgramID program,
539 const GLchar *name,
540 ParamCapture *paramCapture)
541 {
542 CaptureString(name, paramCapture);
543 }
544
CaptureGetUniformfv_params(const State & glState,bool isCallValid,ShaderProgramID program,UniformLocation location,GLfloat * params,ParamCapture * paramCapture)545 void CaptureGetUniformfv_params(const State &glState,
546 bool isCallValid,
547 ShaderProgramID program,
548 UniformLocation location,
549 GLfloat *params,
550 ParamCapture *paramCapture)
551 {
552 // the value returned cannot have size larger than a mat4 of floats
553 paramCapture->readBufferSizeBytes = 64;
554 }
555
CaptureGetUniformiv_params(const State & glState,bool isCallValid,ShaderProgramID program,UniformLocation location,GLint * params,ParamCapture * paramCapture)556 void CaptureGetUniformiv_params(const State &glState,
557 bool isCallValid,
558 ShaderProgramID program,
559 UniformLocation location,
560 GLint *params,
561 ParamCapture *paramCapture)
562 {
563 // the value returned cannot have size larger than a mat4 of ints
564 paramCapture->readBufferSizeBytes = 64;
565 }
566
CaptureGetVertexAttribPointerv_pointer(const State & glState,bool isCallValid,GLuint index,GLenum pname,void ** pointer,ParamCapture * paramCapture)567 void CaptureGetVertexAttribPointerv_pointer(const State &glState,
568 bool isCallValid,
569 GLuint index,
570 GLenum pname,
571 void **pointer,
572 ParamCapture *paramCapture)
573 {
574 paramCapture->readBufferSizeBytes = sizeof(void *);
575 }
576
CaptureGetVertexAttribfv_params(const State & glState,bool isCallValid,GLuint index,GLenum pname,GLfloat * params,ParamCapture * paramCapture)577 void CaptureGetVertexAttribfv_params(const State &glState,
578 bool isCallValid,
579 GLuint index,
580 GLenum pname,
581 GLfloat *params,
582 ParamCapture *paramCapture)
583 {
584 // Can be up to 4 current state values.
585 paramCapture->readBufferSizeBytes = sizeof(GLfloat) * 4;
586 }
587
CaptureGetVertexAttribiv_params(const State & glState,bool isCallValid,GLuint index,GLenum pname,GLint * params,ParamCapture * paramCapture)588 void CaptureGetVertexAttribiv_params(const State &glState,
589 bool isCallValid,
590 GLuint index,
591 GLenum pname,
592 GLint *params,
593 ParamCapture *paramCapture)
594 {
595 // Can be up to 4 current state values.
596 paramCapture->readBufferSizeBytes = sizeof(GLint) * 4;
597 }
598
CaptureReadPixels_pixels(const State & glState,bool isCallValid,GLint x,GLint y,GLsizei width,GLsizei height,GLenum format,GLenum type,void * pixels,ParamCapture * paramCapture)599 void CaptureReadPixels_pixels(const State &glState,
600 bool isCallValid,
601 GLint x,
602 GLint y,
603 GLsizei width,
604 GLsizei height,
605 GLenum format,
606 GLenum type,
607 void *pixels,
608 ParamCapture *paramCapture)
609 {
610 if (glState.getTargetBuffer(gl::BufferBinding::PixelPack))
611 {
612 // If a pixel pack buffer is bound, this is an offset, not a pointer
613 paramCapture->value.voidPointerVal = pixels;
614 return;
615 }
616 // Use a conservative upper bound instead of an exact size to be simple.
617 static constexpr GLsizei kMaxPixelSize = 32;
618 paramCapture->readBufferSizeBytes = kMaxPixelSize * width * height;
619 }
620
CaptureShaderBinary_shadersPacked(const State & glState,bool isCallValid,GLsizei count,const ShaderProgramID * shaders,GLenum binaryformat,const void * binary,GLsizei length,ParamCapture * paramCapture)621 void CaptureShaderBinary_shadersPacked(const State &glState,
622 bool isCallValid,
623 GLsizei count,
624 const ShaderProgramID *shaders,
625 GLenum binaryformat,
626 const void *binary,
627 GLsizei length,
628 ParamCapture *paramCapture)
629 {
630 UNIMPLEMENTED();
631 }
632
CaptureShaderBinary_binary(const State & glState,bool isCallValid,GLsizei count,const ShaderProgramID * shaders,GLenum binaryformat,const void * binary,GLsizei length,ParamCapture * paramCapture)633 void CaptureShaderBinary_binary(const State &glState,
634 bool isCallValid,
635 GLsizei count,
636 const ShaderProgramID *shaders,
637 GLenum binaryformat,
638 const void *binary,
639 GLsizei length,
640 ParamCapture *paramCapture)
641 {
642 UNIMPLEMENTED();
643 }
644
CaptureShaderSource_string(const State & glState,bool isCallValid,ShaderProgramID shader,GLsizei count,const GLchar * const * string,const GLint * length,ParamCapture * paramCapture)645 void CaptureShaderSource_string(const State &glState,
646 bool isCallValid,
647 ShaderProgramID shader,
648 GLsizei count,
649 const GLchar *const *string,
650 const GLint *length,
651 ParamCapture *paramCapture)
652 {
653 CaptureShaderStrings(count, string, length, paramCapture);
654 }
655
CaptureShaderSource_length(const State & glState,bool isCallValid,ShaderProgramID shader,GLsizei count,const GLchar * const * string,const GLint * length,ParamCapture * paramCapture)656 void CaptureShaderSource_length(const State &glState,
657 bool isCallValid,
658 ShaderProgramID shader,
659 GLsizei count,
660 const GLchar *const *string,
661 const GLint *length,
662 ParamCapture *paramCapture)
663 {
664 if (!length)
665 {
666 return;
667 }
668
669 CaptureMemory(length, count * sizeof(GLint), paramCapture);
670 }
671
CaptureTexImage2D_pixels(const State & glState,bool isCallValid,TextureTarget targetPacked,GLint level,GLint internalformat,GLsizei width,GLsizei height,GLint border,GLenum format,GLenum type,const void * pixels,ParamCapture * paramCapture)672 void CaptureTexImage2D_pixels(const State &glState,
673 bool isCallValid,
674 TextureTarget targetPacked,
675 GLint level,
676 GLint internalformat,
677 GLsizei width,
678 GLsizei height,
679 GLint border,
680 GLenum format,
681 GLenum type,
682 const void *pixels,
683 ParamCapture *paramCapture)
684 {
685 if (glState.getTargetBuffer(gl::BufferBinding::PixelUnpack))
686 {
687 return;
688 }
689
690 if (!pixels)
691 {
692 return;
693 }
694
695 // Because GL_HALF_FLOAT and GL_HALF_FLOAT_OES have different values, and the
696 // format table created by BuildInternalFormatInfoMap() and queried here
697 // uses GL_HALF_FLOAT_OES for legacy formats, we have to override the type here.
698 //
699 // BuildInternalFormatInfoMap() can't have entries of the same format for
700 // GL_HALF_FLOAT and GL_ALPHA_FLOAT_OES, and formats like R16F use GL_HALF_FLOAT,
701 // but legacy formats like ALPHA16F use GL_HALF_FLOAT_OES, so overriding
702 // GL_HALF_FLOAT only based on the GLES version, like it is done in
703 // getReadPixelsType, will not work, we also have to check the format when doing so.
704 //
705 // Better would be to actually use the (sized) internal format to do the lookup,
706 // but this doesn't work when calling this function from CaptureTexSubImage2D_pixels,
707 // because there the internal format is not known.
708
709 if (type == GL_HALF_FLOAT &&
710 (format == GL_ALPHA || format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA))
711 {
712 type = GL_HALF_FLOAT_OES;
713 }
714
715 const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(format, type);
716 const gl::PixelUnpackState &unpack = glState.getUnpackState();
717
718 GLuint srcRowPitch = 0;
719 (void)internalFormatInfo.computeRowPitch(type, width, unpack.alignment, unpack.rowLength,
720 &srcRowPitch);
721 GLuint srcDepthPitch = 0;
722 (void)internalFormatInfo.computeDepthPitch(height, unpack.imageHeight, srcRowPitch,
723 &srcDepthPitch);
724 GLuint srcSkipBytes = 0;
725 (void)internalFormatInfo.computeSkipBytes(type, srcRowPitch, srcDepthPitch, unpack, false,
726 &srcSkipBytes);
727
728 // For the last row of pixels, we don't round up to the unpack alignment. This often affects
729 // 1x1 sized textures because they may be 1 or 2 bytes wide with an alignment of 4 bytes.
730 size_t allRowSizeMinusLastRowSize = height == 0 ? 0 : (srcRowPitch * (height - 1));
731 size_t lastRowSize = width * internalFormatInfo.pixelBytes;
732 size_t captureSize = allRowSizeMinusLastRowSize + lastRowSize + srcSkipBytes;
733
734 if (captureSize > 0)
735 {
736 CaptureMemory(pixels, captureSize, paramCapture);
737 }
738 }
739
CaptureTexParameterfv_params(const State & glState,bool isCallValid,TextureType targetPacked,GLenum pname,const GLfloat * params,ParamCapture * paramCapture)740 void CaptureTexParameterfv_params(const State &glState,
741 bool isCallValid,
742 TextureType targetPacked,
743 GLenum pname,
744 const GLfloat *params,
745 ParamCapture *paramCapture)
746 {
747 CaptureTextureAndSamplerParameter_params<GLfloat>(pname, params, paramCapture);
748 }
749
CaptureTexParameteriv_params(const State & glState,bool isCallValid,TextureType targetPacked,GLenum pname,const GLint * params,ParamCapture * paramCapture)750 void CaptureTexParameteriv_params(const State &glState,
751 bool isCallValid,
752 TextureType targetPacked,
753 GLenum pname,
754 const GLint *params,
755 ParamCapture *paramCapture)
756 {
757 CaptureTextureAndSamplerParameter_params<GLint>(pname, params, paramCapture);
758 }
759
CaptureTexSubImage2D_pixels(const State & glState,bool isCallValid,TextureTarget targetPacked,GLint level,GLint xoffset,GLint yoffset,GLsizei width,GLsizei height,GLenum format,GLenum type,const void * pixels,ParamCapture * paramCapture)760 void CaptureTexSubImage2D_pixels(const State &glState,
761 bool isCallValid,
762 TextureTarget targetPacked,
763 GLint level,
764 GLint xoffset,
765 GLint yoffset,
766 GLsizei width,
767 GLsizei height,
768 GLenum format,
769 GLenum type,
770 const void *pixels,
771 ParamCapture *paramCapture)
772 {
773 CaptureTexImage2D_pixels(glState, isCallValid, targetPacked, level, 0, width, height, 0, format,
774 type, pixels, paramCapture);
775 }
776
CaptureUniform1fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLfloat * value,ParamCapture * paramCapture)777 void CaptureUniform1fv_value(const State &glState,
778 bool isCallValid,
779 UniformLocation location,
780 GLsizei count,
781 const GLfloat *value,
782 ParamCapture *paramCapture)
783 {
784 CaptureMemory(value, count * sizeof(GLfloat), paramCapture);
785 }
786
CaptureUniform1iv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLint * value,ParamCapture * paramCapture)787 void CaptureUniform1iv_value(const State &glState,
788 bool isCallValid,
789 UniformLocation location,
790 GLsizei count,
791 const GLint *value,
792 ParamCapture *paramCapture)
793 {
794 CaptureMemory(value, count * sizeof(GLint), paramCapture);
795 }
796
CaptureUniform2fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLfloat * value,ParamCapture * paramCapture)797 void CaptureUniform2fv_value(const State &glState,
798 bool isCallValid,
799 UniformLocation location,
800 GLsizei count,
801 const GLfloat *value,
802 ParamCapture *paramCapture)
803 {
804 CaptureMemory(value, count * sizeof(GLfloat) * 2, paramCapture);
805 }
806
CaptureUniform2iv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLint * value,ParamCapture * paramCapture)807 void CaptureUniform2iv_value(const State &glState,
808 bool isCallValid,
809 UniformLocation location,
810 GLsizei count,
811 const GLint *value,
812 ParamCapture *paramCapture)
813 {
814 CaptureMemory(value, count * sizeof(GLint) * 2, paramCapture);
815 }
816
CaptureUniform3fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLfloat * value,ParamCapture * paramCapture)817 void CaptureUniform3fv_value(const State &glState,
818 bool isCallValid,
819 UniformLocation location,
820 GLsizei count,
821 const GLfloat *value,
822 ParamCapture *paramCapture)
823 {
824 CaptureMemory(value, count * sizeof(GLfloat) * 3, paramCapture);
825 }
826
CaptureUniform3iv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLint * value,ParamCapture * paramCapture)827 void CaptureUniform3iv_value(const State &glState,
828 bool isCallValid,
829 UniformLocation location,
830 GLsizei count,
831 const GLint *value,
832 ParamCapture *paramCapture)
833 {
834 CaptureMemory(value, count * sizeof(GLint) * 3, paramCapture);
835 }
836
CaptureUniform4fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLfloat * value,ParamCapture * paramCapture)837 void CaptureUniform4fv_value(const State &glState,
838 bool isCallValid,
839 UniformLocation location,
840 GLsizei count,
841 const GLfloat *value,
842 ParamCapture *paramCapture)
843 {
844 CaptureMemory(value, count * sizeof(GLfloat) * 4, paramCapture);
845 }
846
CaptureUniform4iv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLint * value,ParamCapture * paramCapture)847 void CaptureUniform4iv_value(const State &glState,
848 bool isCallValid,
849 UniformLocation location,
850 GLsizei count,
851 const GLint *value,
852 ParamCapture *paramCapture)
853 {
854 CaptureMemory(value, count * sizeof(GLint) * 4, paramCapture);
855 }
856
CaptureUniformMatrix2fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,GLboolean transpose,const GLfloat * value,ParamCapture * paramCapture)857 void CaptureUniformMatrix2fv_value(const State &glState,
858 bool isCallValid,
859 UniformLocation location,
860 GLsizei count,
861 GLboolean transpose,
862 const GLfloat *value,
863 ParamCapture *paramCapture)
864 {
865 CaptureMemory(value, count * sizeof(GLfloat) * 4, paramCapture);
866 }
867
CaptureUniformMatrix3fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,GLboolean transpose,const GLfloat * value,ParamCapture * paramCapture)868 void CaptureUniformMatrix3fv_value(const State &glState,
869 bool isCallValid,
870 UniformLocation location,
871 GLsizei count,
872 GLboolean transpose,
873 const GLfloat *value,
874 ParamCapture *paramCapture)
875 {
876 CaptureMemory(value, count * sizeof(GLfloat) * 9, paramCapture);
877 }
878
CaptureUniformMatrix4fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,GLboolean transpose,const GLfloat * value,ParamCapture * paramCapture)879 void CaptureUniformMatrix4fv_value(const State &glState,
880 bool isCallValid,
881 UniformLocation location,
882 GLsizei count,
883 GLboolean transpose,
884 const GLfloat *value,
885 ParamCapture *paramCapture)
886 {
887 CaptureMemory(value, count * sizeof(GLfloat) * 16, paramCapture);
888 }
889
CaptureVertexAttrib1fv_v(const State & glState,bool isCallValid,GLuint index,const GLfloat * v,ParamCapture * paramCapture)890 void CaptureVertexAttrib1fv_v(const State &glState,
891 bool isCallValid,
892 GLuint index,
893 const GLfloat *v,
894 ParamCapture *paramCapture)
895 {
896 CaptureMemory(v, sizeof(GLfloat), paramCapture);
897 }
898
CaptureVertexAttrib2fv_v(const State & glState,bool isCallValid,GLuint index,const GLfloat * v,ParamCapture * paramCapture)899 void CaptureVertexAttrib2fv_v(const State &glState,
900 bool isCallValid,
901 GLuint index,
902 const GLfloat *v,
903 ParamCapture *paramCapture)
904 {
905 CaptureMemory(v, sizeof(GLfloat) * 2, paramCapture);
906 }
907
CaptureVertexAttrib3fv_v(const State & glState,bool isCallValid,GLuint index,const GLfloat * v,ParamCapture * paramCapture)908 void CaptureVertexAttrib3fv_v(const State &glState,
909 bool isCallValid,
910 GLuint index,
911 const GLfloat *v,
912 ParamCapture *paramCapture)
913 {
914 CaptureMemory(v, sizeof(GLfloat) * 3, paramCapture);
915 }
916
CaptureVertexAttrib4fv_v(const State & glState,bool isCallValid,GLuint index,const GLfloat * v,ParamCapture * paramCapture)917 void CaptureVertexAttrib4fv_v(const State &glState,
918 bool isCallValid,
919 GLuint index,
920 const GLfloat *v,
921 ParamCapture *paramCapture)
922 {
923 CaptureMemory(v, sizeof(GLfloat) * 4, paramCapture);
924 }
925
CaptureVertexAttribPointer_pointer(const State & glState,bool isCallValid,GLuint index,GLint size,VertexAttribType typePacked,GLboolean normalized,GLsizei stride,const void * pointer,ParamCapture * paramCapture)926 void CaptureVertexAttribPointer_pointer(const State &glState,
927 bool isCallValid,
928 GLuint index,
929 GLint size,
930 VertexAttribType typePacked,
931 GLboolean normalized,
932 GLsizei stride,
933 const void *pointer,
934 ParamCapture *paramCapture)
935 {
936 paramCapture->value.voidConstPointerVal = pointer;
937 if (!glState.getTargetBuffer(gl::BufferBinding::Array))
938 {
939 paramCapture->arrayClientPointerIndex = index;
940 }
941 }
942 } // namespace gl
943