[Mesa-dev] [PATCH] mesa: Deal with size differences between GLuint and GLhandleARB in GetAttachedObjectsARB

Brian Paul brianp at vmware.com
Mon May 9 16:12:03 UTC 2016


On 05/08/2016 02:38 AM, Jeremy Huddleston Sequoia wrote:> Signed-off-by: 
Jeremy Huddleston Sequoia <jeremyhu at apple.com>
> CC: Nicolai Hähnle <nhaehnle at gmail.com>
> CC: Matt Turner <mattst88 at gmail.com>
> CC: Ian Romanick <idr at freedesktop.org>
> ---
>   src/mesa/main/shaderapi.c | 26 +++++++++++++++++++++++++-
>   1 file changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
> index 8c1fba8..0b630eb 100644
> --- a/src/mesa/main/shaderapi.c
> +++ b/src/mesa/main/shaderapi.c
> @@ -476,6 +476,30 @@ get_attached_shaders(struct gl_context *ctx, GLuint program, GLsizei maxCount,
>      }
>   }
>
> +static void
> +get_attached_shadersARB(struct gl_context *ctx, GLhandleARB container, GLsizei maxCount,
> +                        GLsizei *count, GLhandleARB *obj)
> +{
> +   struct gl_shader_program *shProg;
> +
> +   if (maxCount < 0) {
> +      _mesa_error(ctx, GL_INVALID_VALUE, "glGetAttachedShadersARB(maxCount < 0)");
> +      return;
> +   }
> +
> +   shProg =
> +      _mesa_lookup_shader_program_err(ctx, (GLuint)container, "glGetAttachedShaders");
> +
> +   if (shProg) {
> +      GLuint i;
> +      for (i = 0; i < (GLuint) maxCount && i < shProg->NumShaders; i++) {
> +         obj[i] = (GLhandleARB)shProg->Shaders[i]->Name;
> +      }
> +      if (count)
> +         *count = i;
> +   }
> +}
> +
>
>   /**
>    * glGetHandleARB() - return ID/name of currently bound shader program.
> @@ -1371,7 +1395,7 @@ _mesa_GetAttachedObjectsARB(GLhandleARB container, GLsizei maxCount,
>                               GLsizei * count, GLhandleARB * obj)
>   {
>      GET_CURRENT_CONTEXT(ctx);
> -   get_attached_shaders(ctx, container, maxCount, count, obj);
> +   get_attached_shadersARB(ctx, container, maxCount, count, obj);
>   }

Hey Jeremy,

How about something like this without the code duplication?

diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 8c1fba8..f893ee6 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -451,13 +451,18 @@ detach_shader(struct gl_context *ctx, GLuint 
program, GLuint shader)

  /**
   * Return list of shaders attached to shader program.
+ * Note that only one of objOut or handleOut can be non-null.
+ * \param objOut  returns GLuint ids
+ * \param handleOut  returns GLhandleARB handles
   */
  static void
  get_attached_shaders(struct gl_context *ctx, GLuint program, GLsizei 
maxCount,
-                     GLsizei *count, GLuint *obj)
+                     GLsizei *count, GLuint *objOut, GLhandleARB 
*handleOut)
  {
     struct gl_shader_program *shProg;

+   assert((objOut != NULL) ^ (handleOut != NULL));
+
     if (maxCount < 0) {
        _mesa_error(ctx, GL_INVALID_VALUE, 
"glGetAttachedShaders(maxCount < 0)");
        return;
@@ -469,7 +474,10 @@ get_attached_shaders(struct gl_context *ctx, GLuint 
program, GLsizei maxCount,
     if (shProg) {
        GLuint i;
        for (i = 0; i < (GLuint) maxCount && i < shProg->NumShaders; i++) {
-         obj[i] = shProg->Shaders[i]->Name;
+         if (objOut)
+            objOut[i] = shProg->Shaders[i]->Name;
+         else
+            handleOut[i] = (GLhandleARB) shProg->Shaders[i]->Name;
        }
        if (count)
           *count = i;
@@ -1371,7 +1379,7 @@ _mesa_GetAttachedObjectsARB(GLhandleARB container, 
GLsizei maxCount,
                              GLsizei * count, GLhandleARB * obj)
  {
     GET_CURRENT_CONTEXT(ctx);
-   get_attached_shaders(ctx, container, maxCount, count, obj);
+   get_attached_shaders(ctx, (GLuint) container, maxCount, count, NULL, 
obj);
  }


@@ -1380,7 +1388,7 @@ _mesa_GetAttachedShaders(GLuint program, GLsizei 
maxCount,
                           GLsizei *count, GLuint *obj)
  {
     GET_CURRENT_CONTEXT(ctx);
-   get_attached_shaders(ctx, program, maxCount, count, obj);
+   get_attached_shaders(ctx, program, maxCount, count, obj, NULL);
  }


-Brian



More information about the mesa-dev mailing list