• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(format, type);
695     const gl::PixelUnpackState &unpack           = glState.getUnpackState();
696 
697     GLuint srcRowPitch = 0;
698     (void)internalFormatInfo.computeRowPitch(type, width, unpack.alignment, unpack.rowLength,
699                                              &srcRowPitch);
700     GLuint srcDepthPitch = 0;
701     (void)internalFormatInfo.computeDepthPitch(height, unpack.imageHeight, srcRowPitch,
702                                                &srcDepthPitch);
703     GLuint srcSkipBytes = 0;
704     (void)internalFormatInfo.computeSkipBytes(type, srcRowPitch, srcDepthPitch, unpack, false,
705                                               &srcSkipBytes);
706 
707     size_t captureSize = srcRowPitch * height + srcSkipBytes;
708     CaptureMemory(pixels, captureSize, paramCapture);
709 }
710 
CaptureTexParameterfv_params(const State & glState,bool isCallValid,TextureType targetPacked,GLenum pname,const GLfloat * params,ParamCapture * paramCapture)711 void CaptureTexParameterfv_params(const State &glState,
712                                   bool isCallValid,
713                                   TextureType targetPacked,
714                                   GLenum pname,
715                                   const GLfloat *params,
716                                   ParamCapture *paramCapture)
717 {
718     CaptureTextureAndSamplerParameter_params<GLfloat>(pname, params, paramCapture);
719 }
720 
CaptureTexParameteriv_params(const State & glState,bool isCallValid,TextureType targetPacked,GLenum pname,const GLint * params,ParamCapture * paramCapture)721 void CaptureTexParameteriv_params(const State &glState,
722                                   bool isCallValid,
723                                   TextureType targetPacked,
724                                   GLenum pname,
725                                   const GLint *params,
726                                   ParamCapture *paramCapture)
727 {
728     CaptureTextureAndSamplerParameter_params<GLint>(pname, params, paramCapture);
729 }
730 
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)731 void CaptureTexSubImage2D_pixels(const State &glState,
732                                  bool isCallValid,
733                                  TextureTarget targetPacked,
734                                  GLint level,
735                                  GLint xoffset,
736                                  GLint yoffset,
737                                  GLsizei width,
738                                  GLsizei height,
739                                  GLenum format,
740                                  GLenum type,
741                                  const void *pixels,
742                                  ParamCapture *paramCapture)
743 {
744     CaptureTexImage2D_pixels(glState, isCallValid, targetPacked, level, 0, width, height, 0, format,
745                              type, pixels, paramCapture);
746 }
747 
CaptureUniform1fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLfloat * value,ParamCapture * paramCapture)748 void CaptureUniform1fv_value(const State &glState,
749                              bool isCallValid,
750                              UniformLocation location,
751                              GLsizei count,
752                              const GLfloat *value,
753                              ParamCapture *paramCapture)
754 {
755     CaptureMemory(value, count * sizeof(GLfloat), paramCapture);
756 }
757 
CaptureUniform1iv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLint * value,ParamCapture * paramCapture)758 void CaptureUniform1iv_value(const State &glState,
759                              bool isCallValid,
760                              UniformLocation location,
761                              GLsizei count,
762                              const GLint *value,
763                              ParamCapture *paramCapture)
764 {
765     CaptureMemory(value, count * sizeof(GLint), paramCapture);
766 }
767 
CaptureUniform2fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLfloat * value,ParamCapture * paramCapture)768 void CaptureUniform2fv_value(const State &glState,
769                              bool isCallValid,
770                              UniformLocation location,
771                              GLsizei count,
772                              const GLfloat *value,
773                              ParamCapture *paramCapture)
774 {
775     CaptureMemory(value, count * sizeof(GLfloat) * 2, paramCapture);
776 }
777 
CaptureUniform2iv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLint * value,ParamCapture * paramCapture)778 void CaptureUniform2iv_value(const State &glState,
779                              bool isCallValid,
780                              UniformLocation location,
781                              GLsizei count,
782                              const GLint *value,
783                              ParamCapture *paramCapture)
784 {
785     CaptureMemory(value, count * sizeof(GLint) * 2, paramCapture);
786 }
787 
CaptureUniform3fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLfloat * value,ParamCapture * paramCapture)788 void CaptureUniform3fv_value(const State &glState,
789                              bool isCallValid,
790                              UniformLocation location,
791                              GLsizei count,
792                              const GLfloat *value,
793                              ParamCapture *paramCapture)
794 {
795     CaptureMemory(value, count * sizeof(GLfloat) * 3, paramCapture);
796 }
797 
CaptureUniform3iv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLint * value,ParamCapture * paramCapture)798 void CaptureUniform3iv_value(const State &glState,
799                              bool isCallValid,
800                              UniformLocation location,
801                              GLsizei count,
802                              const GLint *value,
803                              ParamCapture *paramCapture)
804 {
805     CaptureMemory(value, count * sizeof(GLint) * 3, paramCapture);
806 }
807 
CaptureUniform4fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLfloat * value,ParamCapture * paramCapture)808 void CaptureUniform4fv_value(const State &glState,
809                              bool isCallValid,
810                              UniformLocation location,
811                              GLsizei count,
812                              const GLfloat *value,
813                              ParamCapture *paramCapture)
814 {
815     CaptureMemory(value, count * sizeof(GLfloat) * 4, paramCapture);
816 }
817 
CaptureUniform4iv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,const GLint * value,ParamCapture * paramCapture)818 void CaptureUniform4iv_value(const State &glState,
819                              bool isCallValid,
820                              UniformLocation location,
821                              GLsizei count,
822                              const GLint *value,
823                              ParamCapture *paramCapture)
824 {
825     CaptureMemory(value, count * sizeof(GLint) * 4, paramCapture);
826 }
827 
CaptureUniformMatrix2fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,GLboolean transpose,const GLfloat * value,ParamCapture * paramCapture)828 void CaptureUniformMatrix2fv_value(const State &glState,
829                                    bool isCallValid,
830                                    UniformLocation location,
831                                    GLsizei count,
832                                    GLboolean transpose,
833                                    const GLfloat *value,
834                                    ParamCapture *paramCapture)
835 {
836     CaptureMemory(value, count * sizeof(GLfloat) * 4, paramCapture);
837 }
838 
CaptureUniformMatrix3fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,GLboolean transpose,const GLfloat * value,ParamCapture * paramCapture)839 void CaptureUniformMatrix3fv_value(const State &glState,
840                                    bool isCallValid,
841                                    UniformLocation location,
842                                    GLsizei count,
843                                    GLboolean transpose,
844                                    const GLfloat *value,
845                                    ParamCapture *paramCapture)
846 {
847     CaptureMemory(value, count * sizeof(GLfloat) * 9, paramCapture);
848 }
849 
CaptureUniformMatrix4fv_value(const State & glState,bool isCallValid,UniformLocation location,GLsizei count,GLboolean transpose,const GLfloat * value,ParamCapture * paramCapture)850 void CaptureUniformMatrix4fv_value(const State &glState,
851                                    bool isCallValid,
852                                    UniformLocation location,
853                                    GLsizei count,
854                                    GLboolean transpose,
855                                    const GLfloat *value,
856                                    ParamCapture *paramCapture)
857 {
858     CaptureMemory(value, count * sizeof(GLfloat) * 16, paramCapture);
859 }
860 
CaptureVertexAttrib1fv_v(const State & glState,bool isCallValid,GLuint index,const GLfloat * v,ParamCapture * paramCapture)861 void CaptureVertexAttrib1fv_v(const State &glState,
862                               bool isCallValid,
863                               GLuint index,
864                               const GLfloat *v,
865                               ParamCapture *paramCapture)
866 {
867     CaptureMemory(v, sizeof(GLfloat), paramCapture);
868 }
869 
CaptureVertexAttrib2fv_v(const State & glState,bool isCallValid,GLuint index,const GLfloat * v,ParamCapture * paramCapture)870 void CaptureVertexAttrib2fv_v(const State &glState,
871                               bool isCallValid,
872                               GLuint index,
873                               const GLfloat *v,
874                               ParamCapture *paramCapture)
875 {
876     CaptureMemory(v, sizeof(GLfloat) * 2, paramCapture);
877 }
878 
CaptureVertexAttrib3fv_v(const State & glState,bool isCallValid,GLuint index,const GLfloat * v,ParamCapture * paramCapture)879 void CaptureVertexAttrib3fv_v(const State &glState,
880                               bool isCallValid,
881                               GLuint index,
882                               const GLfloat *v,
883                               ParamCapture *paramCapture)
884 {
885     CaptureMemory(v, sizeof(GLfloat) * 3, paramCapture);
886 }
887 
CaptureVertexAttrib4fv_v(const State & glState,bool isCallValid,GLuint index,const GLfloat * v,ParamCapture * paramCapture)888 void CaptureVertexAttrib4fv_v(const State &glState,
889                               bool isCallValid,
890                               GLuint index,
891                               const GLfloat *v,
892                               ParamCapture *paramCapture)
893 {
894     CaptureMemory(v, sizeof(GLfloat) * 4, paramCapture);
895 }
896 
CaptureVertexAttribPointer_pointer(const State & glState,bool isCallValid,GLuint index,GLint size,VertexAttribType typePacked,GLboolean normalized,GLsizei stride,const void * pointer,ParamCapture * paramCapture)897 void CaptureVertexAttribPointer_pointer(const State &glState,
898                                         bool isCallValid,
899                                         GLuint index,
900                                         GLint size,
901                                         VertexAttribType typePacked,
902                                         GLboolean normalized,
903                                         GLsizei stride,
904                                         const void *pointer,
905                                         ParamCapture *paramCapture)
906 {
907     paramCapture->value.voidConstPointerVal = pointer;
908     if (!glState.getTargetBuffer(gl::BufferBinding::Array))
909     {
910         paramCapture->arrayClientPointerIndex = index;
911     }
912 }
913 }  // namespace gl
914