added GL_SGIX/SGIS_pixel_texture
[mesa.git] / src / mesa / main / texstate.c
index 7e5ce3085a03f869fd61d250d436fd4199e2c6a4..2993be45220a8f73605eeb56847fd8b86835605d 100644 (file)
@@ -1,10 +1,10 @@
-/* $Id: texstate.c,v 1.5 1999/11/11 01:22:28 brianp Exp $ */
+/* $Id: texstate.c,v 1.9 2000/03/07 17:54:58 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
  * Version:  3.3
  * 
- * Copyright (C) 1999  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -31,6 +31,7 @@
 #include "glheader.h"
 #include "context.h"
 #include "enums.h"
+#include "extensions.h"
 #include "macros.h"
 #include "matrix.h"
 #include "texobj.h"
@@ -68,29 +69,24 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
 
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexEnv");
 
-   if (target!=GL_TEXTURE_ENV) {
-      gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(target)" );
-      return;
-   }
-
-   if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
-      fprintf(stderr, "glTexEnv %s %s %.1f(%s) ...\n",  
-             gl_lookup_enum_by_nr(target),
-             gl_lookup_enum_by_nr(pname),
-             *param,
-             gl_lookup_enum_by_nr((GLenum) (GLint) *param));
-
+   if (target==GL_TEXTURE_ENV) {
 
-   if (pname==GL_TEXTURE_ENV_MODE) {
-      GLenum mode = (GLenum) (GLint) *param;
-      switch (mode) {
+      if (pname==GL_TEXTURE_ENV_MODE) {
+        GLenum mode = (GLenum) (GLint) *param;
+        switch (mode) {
+        case GL_ADD:
+           if (!ctx->Extensions.HaveTextureEnvAdd) {
+              gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(param)");
+              return;
+           }
+           /* FALL-THROUGH */
         case GL_MODULATE:
         case GL_BLEND:
         case GL_DECAL:
         case GL_REPLACE:
            /* A small optimization for drivers */ 
            if (texUnit->EnvMode == mode)
-               return;
+              return;
 
            if (MESA_VERBOSE & (VERBOSE_STATE|VERBOSE_TEXTURE))
               fprintf(stderr, "glTexEnv: old mode %s, new mode %s\n",
@@ -103,23 +99,53 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
         default:
            gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" );
            return;
+        }
+      }
+      else if (pname==GL_TEXTURE_ENV_COLOR) {
+        texUnit->EnvColor[0] = CLAMP( param[0], 0.0F, 1.0F );
+        texUnit->EnvColor[1] = CLAMP( param[1], 0.0F, 1.0F );
+        texUnit->EnvColor[2] = CLAMP( param[2], 0.0F, 1.0F );
+        texUnit->EnvColor[3] = CLAMP( param[3], 0.0F, 1.0F );
       }
+      else {
+        gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
+        return;
+      }
+
    }
-   else if (pname==GL_TEXTURE_ENV_COLOR) {
-      texUnit->EnvColor[0] = CLAMP( param[0], 0.0F, 1.0F );
-      texUnit->EnvColor[1] = CLAMP( param[1], 0.0F, 1.0F );
-      texUnit->EnvColor[2] = CLAMP( param[2], 0.0F, 1.0F );
-      texUnit->EnvColor[3] = CLAMP( param[3], 0.0F, 1.0F );
+   else if (target==GL_TEXTURE_FILTER_CONTROL_EXT) {
+
+      if (!ctx->Extensions.HaveTextureLodBias) {
+        gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
+        return;
+      }
+
+      if (pname==GL_TEXTURE_LOD_BIAS_EXT) {
+        texUnit->LodBias = param[0];
+      }
+      else {
+        gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
+        return;
+      }
+
    }
    else {
-      gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
+      gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(target)" );
       return;
    }
 
+   if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
+      fprintf(stderr, "glTexEnv %s %s %.1f(%s) ...\n",  
+             gl_lookup_enum_by_nr(target),
+             gl_lookup_enum_by_nr(pname),
+             *param,
+             gl_lookup_enum_by_nr((GLenum) (GLint) *param));
+
    /* Tell device driver about the new texture environment */
    if (ctx->Driver.TexEnv) {
-      (*ctx->Driver.TexEnv)( ctx, pname, param );
+      (*ctx->Driver.TexEnv)( ctx, target, pname, param );
    }
+
 }
 
 
@@ -158,6 +184,9 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexEnvfv");
+
    if (target!=GL_TEXTURE_ENV) {
       gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
       return;
@@ -180,6 +209,9 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexEnviv");
+
    if (target!=GL_TEXTURE_ENV) {
       gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
       return;
@@ -222,6 +254,8 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
    GLenum eparam = (GLenum) (GLint) params[0];
    struct gl_texture_object *texObj;
 
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexParameterfv");
+
    if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
       fprintf(stderr, "texPARAM %s %s %d...\n", 
              gl_lookup_enum_by_nr(target),
@@ -401,6 +435,8 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
    const struct gl_texture_image *img = NULL;
    GLuint dimensions;
 
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexLevelParameter");
+
    if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
       gl_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
       return;
@@ -508,6 +544,8 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    struct gl_texture_object *obj;
 
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexParameterfv");
+
    switch (target) {
       case GL_TEXTURE_1D:
          obj = texUnit->CurrentD[1];
@@ -576,6 +614,8 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    struct gl_texture_object *obj;
 
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexParameteriv");
+
    switch (target) {
       case GL_TEXTURE_1D:
          obj = texUnit->CurrentD[1];
@@ -587,7 +627,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
          obj = texUnit->CurrentD[3];
          break;
       default:
-         gl_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)");
+         gl_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(target)");
          return;
    }
 
@@ -1262,7 +1302,7 @@ void gl_remove_texobj_from_dirty_list( struct gl_shared_state *shared,
 
 /*
  * This is called by gl_update_state() if the NEW_TEXTURING bit in
- * ctx->NewState is unit.
+ * ctx->NewState is set.
  */
 void gl_update_dirty_texobjs( GLcontext *ctx )
 {