From ae423964d8b9e4cae2a180e20879205aeeeca27f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 8 Apr 2013 19:13:51 +0100 Subject: [PATCH] gltrace: Handle negative lengths in glShaderSource* (issue #116). --- helpers/glsize.hpp | 16 ++++++++++++++++ specs/glapi.py | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/helpers/glsize.hpp b/helpers/glsize.hpp index c4fe9bf..2da217f 100644 --- a/helpers/glsize.hpp +++ b/helpers/glsize.hpp @@ -815,6 +815,22 @@ _glClearBuffer_size(GLenum buffer) } } + +/** + * Helper function for determining the string lengths for glShaderSource and + * glShaderSourceARB, which is a tad too complex to inline in the specs. + */ +template +static inline size_t +_glShaderSource_length(const T * const * string, const GLint *length, GLsizei index) +{ + if (length != NULL && length[index] >= 0) { + return (size_t)length[index]; + } else { + return strlen(string[index]); + } +} + /* * attribute list, terminated by the given terminator. */ diff --git a/specs/glapi.py b/specs/glapi.py index c198854..1c63d4f 100644 --- a/specs/glapi.py +++ b/specs/glapi.py @@ -589,7 +589,7 @@ glapi.addFunctions([ GlFunction(GLboolean, "glIsProgram", [(GLprogram, "program")], sideeffects=False), GlFunction(GLboolean, "glIsShader", [(GLshader, "shader")], sideeffects=False), GlFunction(Void, "glLinkProgram", [(GLprogram, "program")]), - GlFunction(Void, "glShaderSource", [(GLshader, "shader"), (GLsizei, "count"), (Array(Const(String(Const(GLchar), "length ? length[{i}] : strlen(string[{i}])")), "count"), "string"), (Array(Const(GLint), "count"), "length")]), + GlFunction(Void, "glShaderSource", [(GLshader, "shader"), (GLsizei, "count"), (Array(Const(String(Const(GLchar), "_glShaderSource_length(string, length, {i})")), "count"), "string"), (Array(Const(GLint), "count"), "length")]), GlFunction(Void, "glUseProgram", [(GLprogram, "program")]), GlFunction(Void, "glUniform1f", [(GLlocation, "location"), (GLfloat, "v0")]), GlFunction(Void, "glUniform2f", [(GLlocation, "location"), (GLfloat, "v0"), (GLfloat, "v1")]), @@ -925,7 +925,7 @@ glapi.addFunctions([ GlFunction(GLhandleARB, "glGetHandleARB", [(GLenum, "pname")], sideeffects=False), GlFunction(Void, "glDetachObjectARB", [(GLhandleARB, "containerObj"), (GLhandleARB, "attachedObj")]), GlFunction(GLhandleARB, "glCreateShaderObjectARB", [(GLenum, "shaderType")]), - GlFunction(Void, "glShaderSourceARB", [(GLhandleARB, "shaderObj"), (GLsizei, "count"), (Const(Array(String(Const(GLcharARB), "length ? length[{i}] : strlen(string[{i}])"), "count")), "string"), (Array(Const(GLint), "count"), "length")]), + GlFunction(Void, "glShaderSourceARB", [(GLhandleARB, "shaderObj"), (GLsizei, "count"), (Const(Array(String(Const(GLcharARB), "_glShaderSource_length(string, length, {i})"), "count")), "string"), (Array(Const(GLint), "count"), "length")]), GlFunction(Void, "glCompileShaderARB", [(GLhandleARB, "shaderObj")]), GlFunction(GLhandleARB, "glCreateProgramObjectARB", []), GlFunction(Void, "glAttachObjectARB", [(GLhandleARB, "containerObj"), (GLhandleARB, "obj")]), -- 2.43.0