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_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     CaptureMemory(buffers, sizeof(BufferID) * 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     CaptureMemory(framebuffers, sizeof(FramebufferID) * 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     CaptureMemory(renderbuffers, sizeof(RenderbufferID) * 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     CaptureMemory(textures, sizeof(TextureID) * 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     for (GLsizei index = 0; index < count; ++index)
653     {
654         size_t len = ((length && length[index] >= 0) ? length[index] : strlen(string[index]));
655         // includes the '\0' suffix
656         std::vector<uint8_t> data(len + 1, 0);
657         memcpy(data.data(), string[index], len);
658         paramCapture->data.emplace_back(std::move(data));
659     }
660 }
661 
CaptureShaderSource_length(const State & glState,bool isCallValid,ShaderProgramID shader,GLsizei count,const GLchar * const * string,const GLint * length,ParamCapture * paramCapture)662 void CaptureShaderSource_length(const State &glState,
663                                 bool isCallValid,
664                                 ShaderProgramID shader,
665                                 GLsizei count,
666                                 const GLchar *const *string,
667                                 const GLint *length,
668                                 ParamCapture *paramCapture)
669 {
670     if (!length)
671         return;
672 
673     CaptureMemory(length, count * sizeof(GLint), paramCapture);
674 }
675 
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)676 void CaptureTexImage2D_pixels(const State &glState,
677                               bool isCallValid,
678                               TextureTarget targetPacked,
679                               GLint level,
680                               GLint internalformat,
681                               GLsizei width,
682                               GLsizei height,
683                               GLint border,
684                               GLenum format,
685                               GLenum type,
686                               const void *pixels,
687                               ParamCapture *paramCapture)
688 {
689     if (glState.getTargetBuffer(gl::BufferBinding::PixelUnpack))
690     {
691         return;
692     }
693 
694     if (!pixels)
695     {
696         return;
697     }
698 
699     const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(format, type);
700     const gl::PixelUnpackState &unpack           = glState.getUnpackState();
701 
702     GLuint srcRowPitch = 0;
703     (void)internalFormatInfo.computeRowPitch(type, width, unpack.alignment, unpack.rowLength,
704                                              &srcRowPitch);
705     GLuint srcDepthPitch = 0;
706     (void)internalFormatInfo.computeDepthPitch(height, unpack.imageHeight, srcRowPitch,
707                                                &srcDepthPitch);
708     GLuint srcSkipBytes = 0;
709     (void)internalFormatInfo.computeSkipBytes(type, srcRowPitch, srcDepthPitch, unpack, false,
710                                               &srcSkipBytes);
711 
712     size_t captureSize = srcRowPitch * height + srcSkipBytes;
713     CaptureMemory(pixels, captureSize, paramCapture);
714 }
715 
CaptureTexParameterfv_params(const State & glState,bool isCallValid,TextureType targetPacked,GLenum pname,const GLfloat * params,ParamCapture * paramCapture)716 void CaptureTexParameterfv_params(const State &glState,
717                                   bool isCallValid,
718                                   TextureType targetPacked,
719                                   GLenum pname,
720                                   const GLfloat *params,
721                                   ParamCapture *paramCapture)
722 {
723     CaptureTextureAndSamplerParameter_params<GLfloat>(pname, params, paramCapture);
724 }
725 
CaptureTexParameteriv_params(const State & glState,bool isCallValid,TextureType targetPacked,GLenum pname,const GLint * params,ParamCapture * paramCapture)726 void CaptureTexParameteriv_params(const State &glState,
727                                   bool isCallValid,
728                                   TextureType targetPacked,
729                                   GLenum pname,
730                                   const GLint *params,
731                                   ParamCapture *paramCapture)
732 {
733     CaptureTextureAndSamplerParameter_params<GLint>(pname, params, paramCapture);
734 }
735 
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)736 void CaptureTexSubImage2D_pixels(const State &glState,
737                                  bool isCallValid,
738                                  TextureTarget targetPacked,
739                                  GLint level,
740                                  GLint xoffset,
741                                  GLint yoffset,
742                                  GLsizei width,
743                                  GLsizei height,
744                                  GLenum format,
745                                  GLenum type,
746                                  const void *pixels,
747                                  ParamCapture *paramCapture)
748 {
749     CaptureTexImage2D_pixels(glState, isCallValid, targetPacked, level, 0, width, height, 0, format,
750                              type, pixels, paramCapture);
751 }
752 
CaptureUniform1fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLfloat * value,ParamCapture * paramCapture)753 void CaptureUniform1fv_value(const State &glState,
754                              bool isCallValid,
755                              UniformLocation location,
756                              GLsizei count,
757                              const GLfloat *value,
758                              ParamCapture *paramCapture)
759 {
760     CaptureMemory(value, count * sizeof(GLfloat), paramCapture);
761 }
762 
CaptureUniform1iv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLint * value,ParamCapture * paramCapture)763 void CaptureUniform1iv_value(const State &glState,
764                              bool isCallValid,
765                              UniformLocation location,
766                              GLsizei count,
767                              const GLint *value,
768                              ParamCapture *paramCapture)
769 {
770     CaptureMemory(value, count * sizeof(GLint), paramCapture);
771 }
772 
CaptureUniform2fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLfloat * value,ParamCapture * paramCapture)773 void CaptureUniform2fv_value(const State &glState,
774                              bool isCallValid,
775                              UniformLocation location,
776                              GLsizei count,
777                              const GLfloat *value,
778                              ParamCapture *paramCapture)
779 {
780     CaptureMemory(value, count * sizeof(GLfloat) * 2, paramCapture);
781 }
782 
CaptureUniform2iv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLint * value,ParamCapture * paramCapture)783 void CaptureUniform2iv_value(const State &glState,
784                              bool isCallValid,
785                              UniformLocation location,
786                              GLsizei count,
787                              const GLint *value,
788                              ParamCapture *paramCapture)
789 {
790     CaptureMemory(value, count * sizeof(GLint) * 2, paramCapture);
791 }
792 
CaptureUniform3fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLfloat * value,ParamCapture * paramCapture)793 void CaptureUniform3fv_value(const State &glState,
794                              bool isCallValid,
795                              UniformLocation location,
796                              GLsizei count,
797                              const GLfloat *value,
798                              ParamCapture *paramCapture)
799 {
800     CaptureMemory(value, count * sizeof(GLfloat) * 3, paramCapture);
801 }
802 
CaptureUniform3iv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLint * value,ParamCapture * paramCapture)803 void CaptureUniform3iv_value(const State &glState,
804                              bool isCallValid,
805                              UniformLocation location,
806                              GLsizei count,
807                              const GLint *value,
808                              ParamCapture *paramCapture)
809 {
810     CaptureMemory(value, count * sizeof(GLint) * 3, paramCapture);
811 }
812 
CaptureUniform4fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLfloat * value,ParamCapture * paramCapture)813 void CaptureUniform4fv_value(const State &glState,
814                              bool isCallValid,
815                              UniformLocation location,
816                              GLsizei count,
817                              const GLfloat *value,
818                              ParamCapture *paramCapture)
819 {
820     CaptureMemory(value, count * sizeof(GLfloat) * 4, paramCapture);
821 }
822 
CaptureUniform4iv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLint * value,ParamCapture * paramCapture)823 void CaptureUniform4iv_value(const State &glState,
824                              bool isCallValid,
825                              UniformLocation location,
826                              GLsizei count,
827                              const GLint *value,
828                              ParamCapture *paramCapture)
829 {
830     CaptureMemory(value, count * sizeof(GLint) * 4, paramCapture);
831 }
832 
CaptureUniformMatrix2fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,GLboolean transpose,const GLfloat * value,ParamCapture * paramCapture)833 void CaptureUniformMatrix2fv_value(const State &glState,
834                                    bool isCallValid,
835                                    UniformLocation location,
836                                    GLsizei count,
837                                    GLboolean transpose,
838                                    const GLfloat *value,
839                                    ParamCapture *paramCapture)
840 {
841     CaptureMemory(value, count * sizeof(GLfloat) * 4, paramCapture);
842 }
843 
CaptureUniformMatrix3fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,GLboolean transpose,const GLfloat * value,ParamCapture * paramCapture)844 void CaptureUniformMatrix3fv_value(const State &glState,
845                                    bool isCallValid,
846                                    UniformLocation location,
847                                    GLsizei count,
848                                    GLboolean transpose,
849                                    const GLfloat *value,
850                                    ParamCapture *paramCapture)
851 {
852     CaptureMemory(value, count * sizeof(GLfloat) * 9, paramCapture);
853 }
854 
CaptureUniformMatrix4fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,GLboolean transpose,const GLfloat * value,ParamCapture * paramCapture)855 void CaptureUniformMatrix4fv_value(const State &glState,
856                                    bool isCallValid,
857                                    UniformLocation location,
858                                    GLsizei count,
859                                    GLboolean transpose,
860                                    const GLfloat *value,
861                                    ParamCapture *paramCapture)
862 {
863     CaptureMemory(value, count * sizeof(GLfloat) * 16, paramCapture);
864 }
865 
CaptureVertexAttrib1fv_v(const State & glState,bool isCallValid,GLuint index,const GLfloat * v,ParamCapture * paramCapture)866 void CaptureVertexAttrib1fv_v(const State &glState,
867                               bool isCallValid,
868                               GLuint index,
869                               const GLfloat *v,
870                               ParamCapture *paramCapture)
871 {
872     CaptureMemory(v, sizeof(GLfloat), paramCapture);
873 }
874 
CaptureVertexAttrib2fv_v(const State & glState,bool isCallValid,GLuint index,const GLfloat * v,ParamCapture * paramCapture)875 void CaptureVertexAttrib2fv_v(const State &glState,
876                               bool isCallValid,
877                               GLuint index,
878                               const GLfloat *v,
879                               ParamCapture *paramCapture)
880 {
881     CaptureMemory(v, sizeof(GLfloat) * 2, paramCapture);
882 }
883 
CaptureVertexAttrib3fv_v(const State & glState,bool isCallValid,GLuint index,const GLfloat * v,ParamCapture * paramCapture)884 void CaptureVertexAttrib3fv_v(const State &glState,
885                               bool isCallValid,
886                               GLuint index,
887                               const GLfloat *v,
888                               ParamCapture *paramCapture)
889 {
890     CaptureMemory(v, sizeof(GLfloat) * 3, paramCapture);
891 }
892 
CaptureVertexAttrib4fv_v(const State & glState,bool isCallValid,GLuint index,const GLfloat * v,ParamCapture * paramCapture)893 void CaptureVertexAttrib4fv_v(const State &glState,
894                               bool isCallValid,
895                               GLuint index,
896                               const GLfloat *v,
897                               ParamCapture *paramCapture)
898 {
899     CaptureMemory(v, sizeof(GLfloat) * 4, paramCapture);
900 }
901 
CaptureVertexAttribPointer_pointer(const State & glState,bool isCallValid,GLuint index,GLint size,VertexAttribType typePacked,GLboolean normalized,GLsizei stride,const void * pointer,ParamCapture * paramCapture)902 void CaptureVertexAttribPointer_pointer(const State &glState,
903                                         bool isCallValid,
904                                         GLuint index,
905                                         GLint size,
906                                         VertexAttribType typePacked,
907                                         GLboolean normalized,
908                                         GLsizei stride,
909                                         const void *pointer,
910                                         ParamCapture *paramCapture)
911 {
912     paramCapture->value.voidConstPointerVal = pointer;
913     if (!glState.getTargetBuffer(gl::BufferBinding::Array))
914     {
915         paramCapture->arrayClientPointerIndex = index;
916     }
917 }
918 }  // namespace gl
919