radeon: Don't crash generating mipmaps when pixels=NULL
[mesa.git] / src / mesa / swrast / s_context.c
index 719e6b82964b6cc23ba1b4d1999ddb5ab8b7f38b..f24f4fc59b2cc5e3a6aa761fc1342c9ca2e99d19 100644 (file)
@@ -61,7 +61,7 @@ _swrast_update_rasterflags( GLcontext *ctx )
    if (ctx->Depth.Test)                   rasterMask |= DEPTH_BIT;
    if (swrast->_FogEnabled)               rasterMask |= FOG_BIT;
    if (ctx->Scissor.Enabled)              rasterMask |= CLIP_BIT;
-   if (ctx->Stencil.Enabled)              rasterMask |= STENCIL_BIT;
+   if (ctx->Stencil._Enabled)             rasterMask |= STENCIL_BIT;
    if (ctx->Visual.rgbMode) {
       const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask);
       if (colorMask != 0xffffffff)        rasterMask |= MASKING_BIT;
@@ -172,19 +172,29 @@ _swrast_update_fog_hint( GLcontext *ctx )
 
 
 /**
- * Update the swrast->_AnyTextureCombine flag.
+ * Update the swrast->_TextureCombinePrimary flag.
  */
 static void
 _swrast_update_texture_env( GLcontext *ctx )
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLuint i;
-   swrast->_AnyTextureCombine = GL_FALSE;
+
+   swrast->_TextureCombinePrimary = 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;
+      const struct gl_tex_env_combine_state *combine =
+         ctx->Texture.Unit[i]._CurrentCombine;
+      GLuint term;
+      for (term = 0; term < combine->_NumArgsRGB; term++) {
+         if (combine->SourceRGB[term] == GL_PRIMARY_COLOR) {
+            swrast->_TextureCombinePrimary = GL_TRUE;
+            return;
+         }
+         if (combine->SourceA[term] == GL_PRIMARY_COLOR) {
+            swrast->_TextureCombinePrimary = GL_TRUE;
+            return;
+         }
       }
    }
 }
@@ -254,17 +264,29 @@ _swrast_update_fragment_program(GLcontext *ctx, GLbitfield newState)
 {
    const struct gl_fragment_program *fp = ctx->FragmentProgram._Current;
    if (fp) {
-#if 0
-      /* XXX Need a way to trigger the initial loading of parameters
-       * even when there's no recent state changes.
-       */
-      if (fp->Base.Parameters->StateFlags & newState)
-#endif
-         _mesa_load_state_parameters(ctx, fp->Base.Parameters);
+      _mesa_load_state_parameters(ctx, fp->Base.Parameters);
    }
 }
 
 
+/**
+ * See if we can do early diffuse+specular (primary+secondary) color
+ * add per vertex instead of per-fragment.
+ */
+static void
+_swrast_update_specular_vertex_add(GLcontext *ctx)
+{
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   GLboolean separateSpecular = ctx->Fog.ColorSumEnabled ||
+      (ctx->Light.Enabled &&
+       ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR);
+
+   swrast->SpecularVertexAdd = (separateSpecular
+                                && ctx->Texture._EnabledUnits == 0x0
+                                && !ctx->FragmentProgram._Current
+                                && !ctx->ATIFragmentShader._Enabled);
+}
+
 
 #define _SWRAST_NEW_DERIVED (_SWRAST_NEW_RASTERMASK |  \
                             _NEW_TEXTURE |             \
@@ -326,9 +348,7 @@ _swrast_validate_triangle( GLcontext *ctx,
    swrast->choose_triangle( ctx );
    ASSERT(swrast->Triangle);
 
-   if (ctx->Texture._EnabledUnits == 0
-       && NEED_SECONDARY_COLOR(ctx)
-       && !ctx->FragmentProgram._Current) {
+   if (swrast->SpecularVertexAdd) {
       /* separate specular color, but no texture */
       swrast->SpecTriangle = swrast->Triangle;
       swrast->Triangle = _swrast_add_spec_terms_triangle;
@@ -350,9 +370,7 @@ _swrast_validate_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 )
    swrast->choose_line( ctx );
    ASSERT(swrast->Line);
 
-   if (ctx->Texture._EnabledUnits == 0
-       && NEED_SECONDARY_COLOR(ctx)
-       && !ctx->FragmentProgram._Current) {
+   if (swrast->SpecularVertexAdd) {
       swrast->SpecLine = swrast->Line;
       swrast->Line = _swrast_add_spec_terms_line;
    }
@@ -372,9 +390,7 @@ _swrast_validate_point( GLcontext *ctx, const SWvertex *v0 )
    _swrast_validate_derived( ctx );
    swrast->choose_point( ctx );
 
-   if (ctx->Texture._EnabledUnits == 0
-       && NEED_SECONDARY_COLOR(ctx)
-       && !ctx->FragmentProgram._Current) {
+   if (swrast->SpecularVertexAdd) {
       swrast->SpecPoint = swrast->Point;
       swrast->Point = _swrast_add_spec_terms_point;
    }
@@ -502,13 +518,6 @@ _swrast_invalidate_state( GLcontext *ctx, GLbitfield new_state )
       new_state = ~0;
    }
 
-   {
-      const struct gl_fragment_program *fp = ctx->FragmentProgram._Current;
-      if (fp && (fp->Base.Parameters->StateFlags & new_state)) {
-         _mesa_load_state_parameters(ctx, fp->Base.Parameters);
-      }
-   }
-
    if (new_state & swrast->InvalidateTriangleMask)
       swrast->Triangle = _swrast_validate_triangle;
 
@@ -625,17 +634,7 @@ _swrast_validate_derived( GLcontext *ctx )
       if (swrast->NewState & (_NEW_FOG | _NEW_PROGRAM))
          _swrast_update_fog_state( ctx );
 
-      if (swrast->NewState & (_NEW_MODELVIEW |
-                              _NEW_PROJECTION |
-                              _NEW_TEXTURE_MATRIX |
-                              _NEW_FOG |
-                              _NEW_LIGHT |
-                              _NEW_LINE |
-                              _NEW_TEXTURE |
-                              _NEW_TRANSFORM |
-                              _NEW_POINT |
-                              _NEW_VIEWPORT |
-                              _NEW_PROGRAM))
+      if (swrast->NewState & (_NEW_PROGRAM_CONSTANTS | _NEW_PROGRAM))
         _swrast_update_fragment_program( ctx, swrast->NewState );
 
       if (swrast->NewState & (_NEW_TEXTURE | _NEW_PROGRAM)) {
@@ -656,6 +655,12 @@ _swrast_validate_derived( GLcontext *ctx )
                               _NEW_TEXTURE))
          _swrast_update_active_attribs(ctx);
 
+      if (swrast->NewState & (_NEW_FOG | 
+                              _NEW_PROGRAM |
+                              _NEW_LIGHT |
+                              _NEW_TEXTURE))
+         _swrast_update_specular_vertex_add(ctx);
+
       swrast->NewState = 0;
       swrast->StateChanges = 0;
       swrast->InvalidateState = _swrast_invalidate_state;
@@ -820,8 +825,8 @@ _swrast_CreateContext( GLcontext *ctx )
    swrast->PointSpan.facing = 0;
    swrast->PointSpan.array = swrast->SpanArrays;
 
-   swrast->TexelBuffer = (GLchan *) MALLOC(ctx->Const.MaxTextureImageUnits *
-                                           MAX_WIDTH * 4 * sizeof(GLchan));
+   swrast->TexelBuffer = (GLfloat *) MALLOC(ctx->Const.MaxTextureImageUnits *
+                                           MAX_WIDTH * 4 * sizeof(GLfloat));
    if (!swrast->TexelBuffer) {
       FREE(swrast->SpanArrays);
       FREE(swrast);