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