u_upload_mgr: keep the upload buffer mapped until it is flushed
[mesa.git] / src / mesa / main / texenv.c
index 4442fb8cf8e9877a55bc085d313bcdb2a1d6f3ce..194bcbea9831ccc463411221edf9bc8eeeb5f158 100644 (file)
@@ -34,6 +34,7 @@
 #include "main/context.h"
 #include "main/enums.h"
 #include "main/macros.h"
+#include "main/mtypes.h"
 #include "main/texenv.h"
 #include "main/texstate.h"
 
@@ -44,7 +45,7 @@
 
 /** Set texture env mode */
 static void
-set_env_mode(GLcontext *ctx,
+set_env_mode(struct gl_context *ctx,
              struct gl_texture_unit *texUnit,
              GLenum mode)
 {
@@ -89,7 +90,7 @@ set_env_mode(GLcontext *ctx,
 
 
 static void
-set_env_color(GLcontext *ctx,
+set_env_color(struct gl_context *ctx,
               struct gl_texture_unit *texUnit,
               const GLfloat *color)
 {
@@ -107,7 +108,7 @@ set_env_color(GLcontext *ctx,
 
 /** Set an RGB or A combiner mode/function */
 static void
-set_combiner_mode(GLcontext *ctx,
+set_combiner_mode(struct gl_context *ctx,
                   struct gl_texture_unit *texUnit,
                   GLenum pname, GLenum mode)
 {
@@ -181,7 +182,7 @@ set_combiner_mode(GLcontext *ctx,
 
 /** Set an RGB or A combiner source term */
 static void
-set_combiner_source(GLcontext *ctx,
+set_combiner_source(struct gl_context *ctx,
                     struct gl_texture_unit *texUnit,
                     GLenum pname, GLenum param)
 {
@@ -196,57 +197,34 @@ set_combiner_source(GLcontext *ctx,
 
    /*
     * Translate pname to (term, alpha).
+    *
+    * The enums were given sequential values for a reason.
     */
    switch (pname) {
    case GL_SOURCE0_RGB:
-      term = 0;
-      alpha = GL_FALSE;
-      break;
    case GL_SOURCE1_RGB:
-      term = 1;
-      alpha = GL_FALSE;
-      break;
    case GL_SOURCE2_RGB:
-      term = 2;
-      alpha = GL_FALSE;
-      break;
    case GL_SOURCE3_RGB_NV:
-      if (ctx->Extensions.NV_texture_env_combine4) {
-         term = 3;
-         alpha = GL_FALSE;
-      }
-      else {
-         TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
-         return;
-      }
+      term = pname - GL_SOURCE0_RGB;
+      alpha = GL_FALSE;
       break;
    case GL_SOURCE0_ALPHA:
-      term = 0;
-      alpha = GL_TRUE;
-      break;
    case GL_SOURCE1_ALPHA:
-      term = 1;
-      alpha = GL_TRUE;
-      break;
    case GL_SOURCE2_ALPHA:
-      term = 2;
-      alpha = GL_TRUE;
-      break;
    case GL_SOURCE3_ALPHA_NV:
-      if (ctx->Extensions.NV_texture_env_combine4) {
-         term = 3;
-         alpha = GL_TRUE;
-      }
-      else {
-         TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
-         return;
-      }
+      term = pname - GL_SOURCE0_ALPHA;
+      alpha = GL_TRUE;
       break;
    default:
       TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
       return;
    }
 
+   if ((term == 3) && !ctx->Extensions.NV_texture_env_combine4) {
+      TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
+      return;
+   }
+
    assert(term < MAX_COMBINER_TERMS);
 
    /*
@@ -297,7 +275,7 @@ set_combiner_source(GLcontext *ctx,
 
 /** Set an RGB or A combiner operand term */
 static void
-set_combiner_operand(GLcontext *ctx,
+set_combiner_operand(struct gl_context *ctx,
                      struct gl_texture_unit *texUnit,
                      GLenum pname, GLenum param)
 {
@@ -310,68 +288,33 @@ set_combiner_operand(GLcontext *ctx,
       return;
    }
 
+   /* The enums were given sequential values for a reason.
+    */
    switch (pname) {
    case GL_OPERAND0_RGB:
-      term = 0;
-      alpha = GL_FALSE;
-      break;
    case GL_OPERAND1_RGB:
-      term = 1;
-      alpha = GL_FALSE;
-      break;
    case GL_OPERAND2_RGB:
-      if (ctx->Extensions.ARB_texture_env_combine) {
-         term = 2;
-         alpha = GL_FALSE;
-      }
-      else {
-         TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
-         return;
-      }
-      break;
    case GL_OPERAND3_RGB_NV:
-      if (ctx->Extensions.NV_texture_env_combine4) {
-         term = 3;
-         alpha = GL_FALSE;
-      }
-      else {
-         TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
-         return;
-      }
+      term = pname - GL_OPERAND0_RGB;
+      alpha = GL_FALSE;
       break;
    case GL_OPERAND0_ALPHA:
-      term = 0;
-      alpha = GL_TRUE;
-      break;
    case GL_OPERAND1_ALPHA:
-      term = 1;
-      alpha = GL_TRUE;
-      break;
    case GL_OPERAND2_ALPHA:
-      if (ctx->Extensions.ARB_texture_env_combine) {
-         term = 2;
-         alpha = GL_TRUE;
-      }
-      else {
-         TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
-         return;
-      }
-      break;
    case GL_OPERAND3_ALPHA_NV:
-      if (ctx->Extensions.NV_texture_env_combine4) {
-         term = 3;
-         alpha = GL_TRUE;
-      }
-      else {
-         TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
-         return;
-      }
+      term = pname - GL_OPERAND0_ALPHA;
+      alpha = GL_TRUE;
       break;
    default:
       TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
       return;
    }
 
+   if ((term == 3) && !ctx->Extensions.NV_texture_env_combine4) {
+      TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
+      return;
+   }
+
    assert(term < MAX_COMBINER_TERMS);
 
    /*
@@ -380,10 +323,23 @@ set_combiner_operand(GLcontext *ctx,
    switch (param) {
    case GL_SRC_COLOR:
    case GL_ONE_MINUS_SRC_COLOR:
-      legal = !alpha;
+      /* The color input can only be used with GL_OPERAND[01]_RGB in the EXT
+       * version.  In the ARB and NV versions they can be used for any RGB
+       * operand.
+       */
+      legal = !alpha
+        && ((term < 2) || ctx->Extensions.ARB_texture_env_combine
+            || ctx->Extensions.NV_texture_env_combine4);
       break;
-   case GL_SRC_ALPHA:
    case GL_ONE_MINUS_SRC_ALPHA:
+      /* GL_ONE_MINUS_SRC_ALPHA can only be used with
+       * GL_OPERAND[01]_(RGB|ALPHA) in the EXT version.  In the ARB and NV
+       * versions it can be used for any operand.
+       */
+      legal = (term < 2) || ctx->Extensions.ARB_texture_env_combine
+        || ctx->Extensions.NV_texture_env_combine4;
+      break;
+   case GL_SRC_ALPHA:
       legal = GL_TRUE;
       break;
    default:
@@ -405,7 +361,7 @@ set_combiner_operand(GLcontext *ctx,
 
 
 static void
-set_combiner_scale(GLcontext *ctx,
+set_combiner_scale(struct gl_context *ctx,
                    struct gl_texture_unit *texUnit,
                    GLenum pname, GLfloat scale)
 {
@@ -640,7 +596,7 @@ _mesa_TexEnviv( GLenum target, GLenum pname, const GLint *param )
  * \return  value of queried pname or -1 if error.
  */
 static GLint
-get_texenvi(GLcontext *ctx, const struct gl_texture_unit *texUnit,
+get_texenvi(struct gl_context *ctx, const struct gl_texture_unit *texUnit,
             GLenum pname)
 {
    switch (pname) {