mesa: Allow setting GL_TEXTURE_MAX_LEVEL to 0 with GL_TEXTURE_RECTANGLE.
[mesa.git] / src / mesa / main / texenv.c
index c2044a8c2c0ebac0111e602c3786faa9b9e5834f..4848208f574f8a283c6d8bd581c2eda8fbf0938f 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.5
  *
  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 /** 
@@ -32,6 +32,7 @@
 
 #include "main/glheader.h"
 #include "main/context.h"
+#include "main/blend.h"
 #include "main/enums.h"
 #include "main/macros.h"
 #include "main/mtypes.h"
@@ -122,7 +123,7 @@ set_combiner_mode(struct gl_context *ctx,
       break;
    case GL_DOT3_RGB_EXT:
    case GL_DOT3_RGBA_EXT:
-      legal = (ctx->API == API_OPENGL &&
+      legal = (ctx->API == API_OPENGL_COMPAT &&
                ctx->Extensions.EXT_texture_env_dot3 &&
                pname == GL_COMBINE_RGB);
       break;
@@ -134,11 +135,11 @@ set_combiner_mode(struct gl_context *ctx,
    case GL_MODULATE_ADD_ATI:
    case GL_MODULATE_SIGNED_ADD_ATI:
    case GL_MODULATE_SUBTRACT_ATI:
-      legal = (ctx->API == API_OPENGL &&
+      legal = (ctx->API == API_OPENGL_COMPAT &&
                ctx->Extensions.ATI_texture_env_combine3);
       break;
    case GL_BUMP_ENVMAP_ATI:
-      legal = (ctx->API == API_OPENGL &&
+      legal = (ctx->API == API_OPENGL_COMPAT &&
                ctx->Extensions.ATI_envmap_bumpmap &&
                pname == GL_COMBINE_RGB);
       break;
@@ -206,7 +207,7 @@ set_combiner_source(struct gl_context *ctx,
       return;
    }
 
-   if ((term == 3) && (ctx->API != API_OPENGL
+   if ((term == 3) && (ctx->API != API_OPENGL_COMPAT
                        || !ctx->Extensions.NV_texture_env_combine4)) {
       TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
       return;
@@ -236,12 +237,12 @@ set_combiner_source(struct gl_context *ctx,
                param - GL_TEXTURE0 < ctx->Const.MaxTextureUnits);
       break;
    case GL_ZERO:
-      legal = (ctx->API == API_OPENGL &&
+      legal = (ctx->API == API_OPENGL_COMPAT &&
                (ctx->Extensions.ATI_texture_env_combine3 ||
                 ctx->Extensions.NV_texture_env_combine4));
       break;
    case GL_ONE:
-      legal = (ctx->API == API_OPENGL &&
+      legal = (ctx->API == API_OPENGL_COMPAT &&
                ctx->Extensions.ATI_texture_env_combine3);
       break;
    default:
@@ -293,7 +294,7 @@ set_combiner_operand(struct gl_context *ctx,
       return;
    }
 
-   if ((term == 3) && (ctx->API != API_OPENGL
+   if ((term == 3) && (ctx->API != API_OPENGL_COMPAT
                        || !ctx->Extensions.NV_texture_env_combine4)) {
       TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
       return;
@@ -392,9 +393,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
    const GLint iparam0 = (GLint) param[0];
    struct gl_texture_unit *texUnit;
    GLuint maxUnit;
-
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    maxUnit = (target == GL_POINT_SPRITE_NV && pname == GL_COORD_REPLACE_NV)
       ? ctx->Const.MaxTextureCoordUnits : ctx->Const.MaxCombinedTextureImageUnits;
@@ -442,7 +441,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
          set_combiner_scale(ctx, texUnit, pname, param[0]);
         break;
       case GL_BUMP_TARGET_ATI:
-         if (ctx->API != API_OPENGL || !ctx->Extensions.ATI_envmap_bumpmap) {
+         if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ATI_envmap_bumpmap) {
            _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname=0x%x)", pname );
            return;
         }
@@ -507,7 +506,8 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
       }
    }
    else {
-      _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)",target );
+      _mesa_error(ctx, GL_INVALID_ENUM, "glTexEnv(target=%s)",
+                  _mesa_lookup_enum_by_nr(target));
       return;
    }
 
@@ -588,7 +588,7 @@ get_texenvi(struct gl_context *ctx, const struct gl_texture_unit *texUnit,
       return texUnit->Combine.SourceRGB[rgb_idx];
    }
    case GL_SOURCE3_RGB_NV:
-      if (ctx->Extensions.NV_texture_env_combine4) {
+      if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.NV_texture_env_combine4) {
          return texUnit->Combine.SourceRGB[3];
       }
       else {
@@ -602,7 +602,7 @@ get_texenvi(struct gl_context *ctx, const struct gl_texture_unit *texUnit,
       return texUnit->Combine.SourceA[alpha_idx];
    }
    case GL_SOURCE3_ALPHA_NV:
-      if (ctx->Extensions.NV_texture_env_combine4) {
+      if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.NV_texture_env_combine4) {
          return texUnit->Combine.SourceA[3];
       }
       else {
@@ -616,7 +616,7 @@ get_texenvi(struct gl_context *ctx, const struct gl_texture_unit *texUnit,
       return texUnit->Combine.OperandRGB[op_rgb];
    }
    case GL_OPERAND3_RGB_NV:
-      if (ctx->Extensions.NV_texture_env_combine4) {
+      if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.NV_texture_env_combine4) {
          return texUnit->Combine.OperandRGB[3];
       }
       else {
@@ -630,7 +630,7 @@ get_texenvi(struct gl_context *ctx, const struct gl_texture_unit *texUnit,
       return texUnit->Combine.OperandA[op_alpha];
    }
    case GL_OPERAND3_ALPHA_NV:
-      if (ctx->Extensions.NV_texture_env_combine4) {
+      if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.NV_texture_env_combine4) {
          return texUnit->Combine.OperandA[3];
       }
       else {
@@ -643,7 +643,7 @@ get_texenvi(struct gl_context *ctx, const struct gl_texture_unit *texUnit,
       return 1 << texUnit->Combine.ScaleShiftA;
    case GL_BUMP_TARGET_ATI:
       /* spec doesn't say so, but I think this should be queryable */
-      if (ctx->Extensions.ATI_envmap_bumpmap) {
+      if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ATI_envmap_bumpmap) {
          return texUnit->BumpTarget;
       }
       else {
@@ -667,7 +667,6 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
    GLuint maxUnit;
    const struct gl_texture_unit *texUnit;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    maxUnit = (target == GL_POINT_SPRITE_NV && pname == GL_COORD_REPLACE_NV)
       ? ctx->Const.MaxTextureCoordUnits : ctx->Const.MaxCombinedTextureImageUnits;
@@ -682,7 +681,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
       if (pname == GL_TEXTURE_ENV_COLOR) {
          if(ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
             _mesa_update_state(ctx);
-         if(ctx->Color._ClampFragmentColor)
+         if (_mesa_get_clamp_fragment_color(ctx))
             COPY_4FV( params, texUnit->EnvColor );
          else
             COPY_4FV( params, texUnit->EnvColorUnclamped );
@@ -731,7 +730,6 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
    GLuint maxUnit;
    const struct gl_texture_unit *texUnit;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    maxUnit = (target == GL_POINT_SPRITE_NV && pname == GL_COORD_REPLACE_NV)
       ? ctx->Const.MaxTextureCoordUnits : ctx->Const.MaxCombinedTextureImageUnits;
@@ -796,7 +794,6 @@ _mesa_TexBumpParameterivATI( GLenum pname, const GLint *param )
 {
    GLfloat p[4];
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (!ctx->Extensions.ATI_envmap_bumpmap) {
       /* This isn't an "official" error case, but let's tell the user
@@ -826,7 +823,6 @@ _mesa_TexBumpParameterfvATI( GLenum pname, const GLfloat *param )
 {
    struct gl_texture_unit *texUnit;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (!ctx->Extensions.ATI_envmap_bumpmap) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBumpParameterfvATI");
@@ -859,7 +855,6 @@ _mesa_GetTexBumpParameterivATI( GLenum pname, GLint *param )
    const struct gl_texture_unit *texUnit;
    GLuint i;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (!ctx->Extensions.ATI_envmap_bumpmap) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexBumpParameterivATI");
@@ -884,7 +879,7 @@ _mesa_GetTexBumpParameterivATI( GLenum pname, GLint *param )
    }
    else if (pname == GL_BUMP_NUM_TEX_UNITS_ATI) {
       GLint count = 0;
-      for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
+      for (i = 0; i < ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits; i++) {
          if (ctx->Const.SupportedBumpUnits & (1 << i)) {
             count++;
          }
@@ -892,7 +887,7 @@ _mesa_GetTexBumpParameterivATI( GLenum pname, GLint *param )
       *param = count;
    }
    else if (pname == GL_BUMP_TEX_UNITS_ATI) {
-      for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
+      for (i = 0; i < ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits; i++) {
          if (ctx->Const.SupportedBumpUnits & (1 << i)) {
             *param++ = i + GL_TEXTURE0;
          }
@@ -911,7 +906,6 @@ _mesa_GetTexBumpParameterfvATI( GLenum pname, GLfloat *param )
    const struct gl_texture_unit *texUnit;
    GLuint i;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (!ctx->Extensions.ATI_envmap_bumpmap) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexBumpParameterfvATI");
@@ -934,7 +928,7 @@ _mesa_GetTexBumpParameterfvATI( GLenum pname, GLfloat *param )
    }
    else if (pname == GL_BUMP_NUM_TEX_UNITS_ATI) {
       GLint count = 0;
-      for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
+      for (i = 0; i < ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits; i++) {
          if (ctx->Const.SupportedBumpUnits & (1 << i)) {
             count++;
          }
@@ -942,7 +936,7 @@ _mesa_GetTexBumpParameterfvATI( GLenum pname, GLfloat *param )
       *param = (GLfloat) count;
    }
    else if (pname == GL_BUMP_TEX_UNITS_ATI) {
-      for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
+      for (i = 0; i < ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits; i++) {
          if (ctx->Const.SupportedBumpUnits & (1 << i)) {
             *param++ = (GLfloat) (i + GL_TEXTURE0);
          }