From 04b8e50bb89ed167fcaea0ac87c00ee0a09d9412 Mon Sep 17 00:00:00 2001
From: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Date: Thu, 1 Aug 2019 12:05:52 +0200
Subject: mesa: add _mesa_(get)texenvi(f)v_indexed helpers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

They are exactly like _mesa_GetTexEnvfv/_mesa_GetTexEnviv except they take
a GLuint texunit parameter instead of relying of ctx->Texture.CurrentUnit.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
---
 src/mesa/main/texenv.c | 77 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 50 insertions(+), 27 deletions(-)

diff --git a/src/mesa/main/texenv.c b/src/mesa/main/texenv.c
index 95b44004c32..8274b0b88a8 100644
--- a/src/mesa/main/texenv.c
+++ b/src/mesa/main/texenv.c
@@ -391,24 +391,23 @@ set_combiner_scale(struct gl_context *ctx,
 }
 
 
-
-void GLAPIENTRY
-_mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
+static void
+_mesa_texenvfv_indexed( struct gl_context* ctx, GLuint texunit, GLenum target,
+                        GLenum pname, const GLfloat *param )
 {
    const GLint iparam0 = (GLint) param[0];
    GLuint maxUnit;
-   GET_CURRENT_CONTEXT(ctx);
 
    maxUnit = (target == GL_POINT_SPRITE_NV && pname == GL_COORD_REPLACE_NV)
       ? ctx->Const.MaxTextureCoordUnits : ctx->Const.MaxCombinedTextureImageUnits;
-   if (ctx->Texture.CurrentUnit >= maxUnit) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glTexEnvfv(current unit)");
+   if (texunit >= maxUnit) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glTexEnvfv(texunit=%d)", texunit);
       return;
    }
 
    if (target == GL_TEXTURE_ENV) {
       struct gl_fixedfunc_texture_unit *texUnit =
-         _mesa_get_fixedfunc_tex_unit(ctx, ctx->Texture.CurrentUnit);
+         _mesa_get_fixedfunc_tex_unit(ctx, texunit);
 
       /* The GL spec says that we should report an error if the unit is greater
        * than GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, but in practice, only
@@ -465,7 +464,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
    }
    else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
       struct gl_texture_unit *texUnit =
-         _mesa_get_current_tex_unit(ctx);
+         _mesa_get_tex_unit(ctx, texunit);
 
       if (pname == GL_TEXTURE_LOD_BIAS_EXT) {
 	 if (texUnit->LodBias == param[0])
@@ -490,13 +489,13 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
           * but that's what the spec calls for.
           */
          if (iparam0 == GL_TRUE) {
-            if (ctx->Point.CoordReplace & (1u << ctx->Texture.CurrentUnit))
+            if (ctx->Point.CoordReplace & (1u << texunit))
                return;
-            ctx->Point.CoordReplace |= (1u << ctx->Texture.CurrentUnit);
+            ctx->Point.CoordReplace |= (1u << texunit);
          } else if (iparam0 == GL_FALSE) {
-            if (~(ctx->Point.CoordReplace) & (1u << ctx->Texture.CurrentUnit))
+            if (~(ctx->Point.CoordReplace) & (1u << texunit))
                return;
-            ctx->Point.CoordReplace &= ~(1u << ctx->Texture.CurrentUnit);
+            ctx->Point.CoordReplace &= ~(1u << texunit);
          } else {
             _mesa_error( ctx, GL_INVALID_VALUE, "glTexEnv(param=0x%x)", iparam0);
             return;
@@ -528,6 +527,14 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
 }
 
 
+void GLAPIENTRY
+_mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_texenvfv_indexed(ctx, ctx->Texture.CurrentUnit, target, pname, param);
+}
+
+
 void GLAPIENTRY
 _mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param )
 {
@@ -654,23 +661,22 @@ get_texenvi(struct gl_context *ctx,
 }
 
 
-
-void GLAPIENTRY
-_mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
+static void
+_mesa_gettexenvfv_indexed( GLuint texunit, GLenum target, GLenum pname, GLfloat *params )
 {
    GLuint maxUnit;
    GET_CURRENT_CONTEXT(ctx);
 
    maxUnit = (target == GL_POINT_SPRITE_NV && pname == GL_COORD_REPLACE_NV)
       ? ctx->Const.MaxTextureCoordUnits : ctx->Const.MaxCombinedTextureImageUnits;
-   if (ctx->Texture.CurrentUnit >= maxUnit) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexEnvfv(current unit)");
+   if (texunit >= maxUnit) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexEnvfv(texunit=%d)", texunit);
       return;
    }
 
    if (target == GL_TEXTURE_ENV) {
       struct gl_fixedfunc_texture_unit *texUnit =
-         _mesa_get_fixedfunc_tex_unit(ctx, ctx->Texture.CurrentUnit);
+         _mesa_get_fixedfunc_tex_unit(ctx, texunit);
 
       /* The GL spec says that we should report an error if the unit is greater
        * than GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, but in practice, only
@@ -697,7 +703,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
       }
    }
    else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
-      const struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
+      const struct gl_texture_unit *texUnit = _mesa_get_tex_unit(ctx, texunit);
 
       if (pname == GL_TEXTURE_LOD_BIAS_EXT) {
          *params = texUnit->LodBias;
@@ -715,7 +721,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
          return;
       }
       if (pname == GL_COORD_REPLACE_NV) {
-         if (ctx->Point.CoordReplace & (1u << ctx->Texture.CurrentUnit))
+         if (ctx->Point.CoordReplace & (1u << texunit))
             *params = 1.0f;
          else
             *params = 0.0f;
@@ -732,22 +738,24 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
 }
 
 
-void GLAPIENTRY
-_mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
+static void
+_mesa_gettexenviv_indexed( GLuint texunit, GLenum target,
+                           GLenum pname, GLint *params )
 {
    GLuint maxUnit;
    GET_CURRENT_CONTEXT(ctx);
 
    maxUnit = (target == GL_POINT_SPRITE_NV && pname == GL_COORD_REPLACE_NV)
       ? ctx->Const.MaxTextureCoordUnits : ctx->Const.MaxCombinedTextureImageUnits;
-   if (ctx->Texture.CurrentUnit >= maxUnit) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexEnviv(current unit)");
+   if (texunit >= maxUnit) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexEnviv(texunit=%d)",
+                  texunit);
       return;
    }
 
    if (target == GL_TEXTURE_ENV) {
       struct gl_fixedfunc_texture_unit *texUnit =
-         _mesa_get_fixedfunc_tex_unit(ctx, ctx->Texture.CurrentUnit);
+         _mesa_get_fixedfunc_tex_unit(ctx, texunit);
 
       /* The GL spec says that we should report an error if the unit is greater
        * than GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, but in practice, only
@@ -772,7 +780,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
       }
    }
    else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
-      const struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
+      const struct gl_texture_unit *texUnit = _mesa_get_tex_unit(ctx, texunit);
 
       if (pname == GL_TEXTURE_LOD_BIAS_EXT) {
          *params = (GLint) texUnit->LodBias;
@@ -790,7 +798,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
          return;
       }
       if (pname == GL_COORD_REPLACE_NV) {
-         if (ctx->Point.CoordReplace & (1u << ctx->Texture.CurrentUnit))
+         if (ctx->Point.CoordReplace & (1u << texunit))
             *params = GL_TRUE;
          else
             *params = GL_FALSE;
@@ -806,3 +814,18 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
    }
 }
 
+
+void GLAPIENTRY
+_mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_gettexenvfv_indexed(ctx->Texture.CurrentUnit, target, pname, params);
+}
+
+
+void GLAPIENTRY
+_mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_gettexenviv_indexed(ctx->Texture.CurrentUnit, target, pname, params);
+}
-- 
cgit v1.2.3