1515 */
1616
1717#include < cutils/log.h>
18+ #include < GLES/gl.h>
19+ #include < GLES/glext.h>
1820#include < GLES2/gl2.h>
21+ #include < GLES2/gl2ext.h>
1922
2023#include " gltrace.pb.h"
24+ #include " gltrace_api.h"
2125#include " gltrace_context.h"
2226#include " gltrace_fixup.h"
2327
@@ -198,6 +202,20 @@ void fixup_glShaderSource(GLMessage *glmsg) {
198202 arg_strpp->add_charvalue (src);
199203}
200204
205+ void fixup_glUniformGenericInteger (int argIndex, int nIntegers, GLMessage *glmsg) {
206+ /* void glUniform?iv(GLint location, GLsizei count, const GLint *value); */
207+ GLMessage_DataType *arg_values = glmsg->mutable_args (argIndex);
208+ GLint *src = (GLint*)arg_values->intvalue (0 );
209+
210+ arg_values->set_type (GLMessage::DataType::INT);
211+ arg_values->set_isarray (true );
212+ arg_values->clear_intvalue ();
213+
214+ for (int i = 0 ; i < nIntegers; i++) {
215+ arg_values->add_intvalue (*src++);
216+ }
217+ }
218+
201219void fixup_glUniformGeneric (int argIndex, int nFloats, GLMessage *glmsg) {
202220 GLMessage_DataType *arg_values = glmsg->mutable_args (argIndex);
203221 GLfloat *src = (GLfloat*)arg_values->intvalue (0 );
@@ -223,6 +241,10 @@ void fixup_GenericIntArray(int argIndex, int nInts, GLMessage *glmsg) {
223241 GLMessage_DataType *arg_intarray = glmsg->mutable_args (argIndex);
224242 GLint *intp = (GLint *)arg_intarray->intvalue (0 );
225243
244+ if (intp == NULL ) {
245+ return ;
246+ }
247+
226248 arg_intarray->set_type (GLMessage::DataType::INT);
227249 arg_intarray->set_isarray (true );
228250 arg_intarray->clear_intvalue ();
@@ -232,6 +254,15 @@ void fixup_GenericIntArray(int argIndex, int nInts, GLMessage *glmsg) {
232254 }
233255}
234256
257+ void fixup_GenericEnumArray (int argIndex, int nEnums, GLMessage *glmsg) {
258+ // fixup as if they were ints
259+ fixup_GenericIntArray (argIndex, nEnums, glmsg);
260+
261+ // and then set the data type to be enum
262+ GLMessage_DataType *arg_enumarray = glmsg->mutable_args (argIndex);
263+ arg_enumarray->set_type (GLMessage::DataType::ENUM);
264+ }
265+
235266void fixup_glGenGeneric (GLMessage *glmsg) {
236267 /* void glGen*(GLsizei n, GLuint * buffers); */
237268 GLMessage_DataType arg_n = glmsg->args (0 );
@@ -270,6 +301,84 @@ void fixup_glGetFloatv(GLMessage *glmsg) {
270301 arg_params->add_floatvalue (*src);
271302}
272303
304+ void fixup_glLinkProgram (GLMessage *glmsg) {
305+ /* void glLinkProgram(GLuint program); */
306+ GLuint program = glmsg->args (0 ).intvalue (0 );
307+
308+ /* We don't have to fixup this call, but as soon as a program is linked,
309+ we obtain information about all active attributes and uniforms to
310+ pass on to the debugger. Note that in order to pass this info to
311+ the debugger, all we need to do is call the trace versions of the
312+ necessary calls. */
313+
314+ GLint n, maxNameLength;
315+ GLchar *name;
316+ GLint size;
317+ GLenum type;
318+
319+ // obtain info regarding active attributes
320+ GLTrace_glGetProgramiv (program, GL_ACTIVE_ATTRIBUTES, &n);
321+ GLTrace_glGetProgramiv (program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxNameLength);
322+
323+ name = (GLchar *) malloc (maxNameLength);
324+ for (int i = 0 ; i < n; i++) {
325+ GLTrace_glGetActiveAttrib (program, i, maxNameLength, NULL , &size, &type, name);
326+ }
327+ free (name);
328+
329+ // obtain info regarding active uniforms
330+ GLTrace_glGetProgramiv (program, GL_ACTIVE_UNIFORMS, &n);
331+ GLTrace_glGetProgramiv (program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameLength);
332+
333+ name = (GLchar *) malloc (maxNameLength);
334+ for (int i = 0 ; i < n; i++) {
335+ GLTrace_glGetActiveUniform (program, i, maxNameLength, NULL , &size, &type, name);
336+ }
337+ free (name);
338+ }
339+
340+ /* * Given a glGetActive[Uniform|Attrib] call, obtain the location
341+ * of the variable in the call.
342+ */
343+ int getShaderVariableLocation (GLTraceContext *context, GLMessage *glmsg) {
344+ GLMessage_Function func = glmsg->function ();
345+ if (func != GLMessage::glGetActiveAttrib && func != GLMessage::glGetActiveUniform) {
346+ return -1 ;
347+ }
348+
349+ int program = glmsg->args (0 ).intvalue (0 );
350+ GLchar *name = (GLchar*) glmsg->args (6 ).intvalue (0 );
351+
352+ if (func == GLMessage::glGetActiveAttrib) {
353+ return context->hooks ->gl .glGetAttribLocation (program, name);
354+ } else {
355+ return context->hooks ->gl .glGetUniformLocation (program, name);
356+ }
357+ }
358+
359+ void fixup_glGetActiveAttribOrUniform (GLMessage *glmsg, int location) {
360+ /* void glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize,
361+ GLsizei* length, GLint* size, GLenum* type, GLchar* name); */
362+ /* void glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize,
363+ GLsizei* length, GLint* size, GLenum* type, GLchar* name) */
364+
365+ fixup_GenericIntArray (3 , 1 , glmsg); // length
366+ fixup_GenericIntArray (4 , 1 , glmsg); // size
367+ fixup_GenericEnumArray (5 , 1 , glmsg); // type
368+ fixup_CStringPtr (6 , glmsg); // name
369+
370+ // The index argument in the glGetActive[Attrib|Uniform] functions
371+ // does not correspond to the actual location index as used in
372+ // glUniform*() or glVertexAttrib*() to actually upload the data.
373+ // In order to make things simpler for the debugger, we also pass
374+ // a hidden location argument that stores the actual location.
375+ // append the location value to the end of the argument list
376+ GLMessage_DataType *arg_location = glmsg->add_args ();
377+ arg_location->set_isarray (false );
378+ arg_location->set_type (GLMessage::DataType::INT);
379+ arg_location->add_intvalue (location);
380+ }
381+
273382void fixupGLMessage (GLTraceContext *context, nsecs_t start, nsecs_t end, GLMessage *glmsg) {
274383 // for all messages, set the current context id
275384 glmsg->set_context_id (context->getId ());
@@ -292,6 +401,19 @@ void fixupGLMessage(GLTraceContext *context, nsecs_t start, nsecs_t end, GLMessa
292401 case GLMessage::glGenTextures: /* void glGenTextures(GLsizei n, GLuint *textures); */
293402 fixup_glGenGeneric (glmsg);
294403 break ;
404+ case GLMessage::glLinkProgram: /* void glLinkProgram(GLuint program); */
405+ fixup_glLinkProgram (glmsg);
406+ break ;
407+ case GLMessage::glGetActiveAttrib:
408+ fixup_glGetActiveAttribOrUniform (glmsg, getShaderVariableLocation (context, glmsg));
409+ break ;
410+ case GLMessage::glGetActiveUniform:
411+ fixup_glGetActiveAttribOrUniform (glmsg, getShaderVariableLocation (context, glmsg));
412+ break ;
413+ case GLMessage::glBindAttribLocation:
414+ /* void glBindAttribLocation(GLuint program, GLuint index, const GLchar* name); */
415+ fixup_CStringPtr (2 , glmsg);
416+ break ;
295417 case GLMessage::glGetAttribLocation:
296418 case GLMessage::glGetUniformLocation:
297419 /* int glGetAttribLocation(GLuint program, const GLchar* name) */
@@ -331,6 +453,38 @@ void fixupGLMessage(GLTraceContext *context, nsecs_t start, nsecs_t end, GLMessa
331453 case GLMessage::glShaderSource:
332454 fixup_glShaderSource (glmsg);
333455 break ;
456+ case GLMessage::glUniform1iv:
457+ /* void glUniform1iv(GLint location, GLsizei count, const GLint *value); */
458+ fixup_glUniformGenericInteger (2 , 1 , glmsg);
459+ break ;
460+ case GLMessage::glUniform2iv:
461+ /* void glUniform2iv(GLint location, GLsizei count, const GLint *value); */
462+ fixup_glUniformGenericInteger (2 , 2 , glmsg);
463+ break ;
464+ case GLMessage::glUniform3iv:
465+ /* void glUniform3iv(GLint location, GLsizei count, const GLint *value); */
466+ fixup_glUniformGenericInteger (2 , 3 , glmsg);
467+ break ;
468+ case GLMessage::glUniform4iv:
469+ /* void glUniform4iv(GLint location, GLsizei count, const GLint *value); */
470+ fixup_glUniformGenericInteger (2 , 4 , glmsg);
471+ break ;
472+ case GLMessage::glUniform1fv:
473+ /* void glUniform1fv(GLint location, GLsizei count, const GLfloat *value); */
474+ fixup_glUniformGeneric (2 , 1 , glmsg);
475+ break ;
476+ case GLMessage::glUniform2fv:
477+ /* void glUniform2fv(GLint location, GLsizei count, const GLfloat *value); */
478+ fixup_glUniformGeneric (2 , 2 , glmsg);
479+ break ;
480+ case GLMessage::glUniform3fv:
481+ /* void glUniform3fv(GLint location, GLsizei count, const GLfloat *value); */
482+ fixup_glUniformGeneric (2 , 3 , glmsg);
483+ break ;
484+ case GLMessage::glUniform4fv:
485+ /* void glUniform4fv(GLint location, GLsizei count, const GLfloat *value); */
486+ fixup_glUniformGeneric (2 , 4 , glmsg);
487+ break ;
334488 case GLMessage::glUniformMatrix2fv:
335489 /* void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose,
336490 const GLfloat* value) */
0 commit comments