Implemented GL_ARB_texture_env_crossbar.
[mesa.git] / src / mesa / swrast / s_context.c
index e10f8a3bb3d054fbb33293ecbfd075b66a306454..809ee6812235c553f549399c5f1f1c67b030ce9b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: s_context.c,v 1.29 2002/02/02 21:40:33 brianp Exp $ */
+/* $Id: s_context.c,v 1.32 2002/05/02 00:59:20 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -40,9 +40,6 @@
 #include "s_texture.h"
 
 
-
-
-
 /*
  * Recompute the value of swrast->_RasterMask, etc. according to
  * the current context.
@@ -75,9 +72,9 @@ _swrast_update_rasterflags( GLcontext *ctx )
       RasterMask |= ALPHABUF_BIT;
 
    if (   ctx->Viewport.X < 0
-       || ctx->Viewport.X + ctx->Viewport.Width > ctx->DrawBuffer->Width
+       || ctx->Viewport.X + ctx->Viewport.Width > (GLint) ctx->DrawBuffer->Width
        || ctx->Viewport.Y < 0
-       || ctx->Viewport.Y + ctx->Viewport.Height > ctx->DrawBuffer->Height) {
+       || ctx->Viewport.Y + ctx->Viewport.Height > (GLint) ctx->DrawBuffer->Height) {
       RasterMask |= CLIP_BIT;
    }
 
@@ -145,6 +142,26 @@ _swrast_update_hint( GLcontext *ctx )
                               swrast->AllowPixelFog));
 }
 
+
+/*
+ * Update the swrast->_AnyTextureCombine flag.
+ */
+static void
+_swrast_update_texture_env( GLcontext *ctx )
+{
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   GLuint i;
+   swrast->_AnyTextureCombine = GL_FALSE;
+   for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
+      if (ctx->Texture.Unit[i].EnvMode == GL_COMBINE_EXT ||
+          ctx->Texture.Unit[i].EnvMode == GL_COMBINE4_NV) {
+         swrast->_AnyTextureCombine = GL_TRUE;
+         return;
+      }
+   }
+}
+
+
 #define _SWRAST_NEW_DERIVED (_SWRAST_NEW_RASTERMASK |  \
                             _NEW_TEXTURE |             \
                             _NEW_HINT |                \
@@ -183,6 +200,8 @@ _swrast_update_hint( GLcontext *ctx )
 
 #define _SWRAST_NEW_TEXTURE_SAMPLE_FUNC _NEW_TEXTURE
 
+#define _SWRAST_NEW_TEXTURE_ENV_MODE _NEW_TEXTURE
+
 #define _SWRAST_NEW_BLEND_FUNC _NEW_COLOR
 
 
@@ -315,7 +334,6 @@ _swrast_invalidate_state( GLcontext *ctx, GLuint new_state )
       for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
         swrast->TextureSample[i] = _swrast_validate_texture_sample;
 
-
    if (ctx->Visual.rgbMode) {
       ASSERT(swrast->Driver.WriteRGBASpan);
       ASSERT(swrast->Driver.WriteRGBSpan);
@@ -334,18 +352,15 @@ _swrast_invalidate_state( GLcontext *ctx, GLuint new_state )
       ASSERT(swrast->Driver.ReadCI32Span);
       ASSERT(swrast->Driver.ReadCI32Pixels);
    }
-
 }
 
 
-
 void
 _swrast_validate_derived( GLcontext *ctx )
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
 
-   if (swrast->NewState)
-   {
+   if (swrast->NewState) {
       if (swrast->NewState & _SWRAST_NEW_RASTERMASK)
         _swrast_update_rasterflags( ctx );
 
@@ -355,6 +370,9 @@ _swrast_validate_derived( GLcontext *ctx )
       if (swrast->NewState & _NEW_HINT)
         _swrast_update_hint( ctx );
 
+      if (swrast->NewState & _SWRAST_NEW_TEXTURE_ENV_MODE)
+        _swrast_update_texture_env( ctx );
+
       swrast->NewState = 0;
       swrast->StateChanges = 0;
       swrast->InvalidateState = _swrast_invalidate_state;
@@ -490,11 +508,28 @@ _swrast_CreateContext( GLcontext *ctx )
    swrast->_IntegerAccumMode = GL_TRUE;
    swrast->_IntegerAccumScaler = 0.0;
 
-
    for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++)
       swrast->TextureSample[i] = _swrast_validate_texture_sample;
 
+   swrast->span = (struct sw_span *) MALLOC(sizeof(struct sw_span));
+   if (!swrast->span) {
+     FREE(swrast);
+     return GL_FALSE;
+   }
+
+   assert(ctx->Const.MaxTextureUnits > 0);
+   assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_UNITS);
+
+   swrast->TexelBuffer = (GLchan *) MALLOC(ctx->Const.MaxTextureUnits *
+                                           MAX_WIDTH * 4 * sizeof(GLchan));
+   if (!swrast->TexelBuffer) {
+      FREE(swrast->span);
+      FREE(swrast);
+      return GL_FALSE;
+   }
+
    ctx->swrast_context = swrast;
+
    return GL_TRUE;
 }
 
@@ -507,6 +542,8 @@ _swrast_DestroyContext( GLcontext *ctx )
       fprintf(stderr, "_swrast_DestroyContext\n");
    }
 
+   FREE( swrast->span );
+   FREE( swrast->TexelBuffer );
    FREE( swrast );
 
    ctx->swrast_context = 0;