mesa/tests: Sanity check the ES2 dispatch table
[mesa.git] / src / mesa / swrast / s_fragprog.c
index 1caa0ebc22697a94a217e873c14d3f6b85cf95e5..812189f094687b48e327e308b5b63f3fb078757e 100644 (file)
 
 #include "main/glheader.h"
 #include "main/colormac.h"
+#include "main/samplerobj.h"
 #include "program/prog_instruction.h"
 
 #include "s_context.h"
 #include "s_fragprog.h"
 #include "s_span.h"
 
+/**
+ * \brief Should swrast use a fragment program?
+ *
+ * \return true if the current fragment program exists and is not the fixed
+ *         function fragment program
+ */
+GLboolean
+_swrast_use_fragment_program(struct gl_context *ctx)
+{
+   struct gl_fragment_program *fp = ctx->FragmentProgram._Current;
+   return fp && !(fp == ctx->FragmentProgram._TexEnvProgram
+                  && fp->Base.NumInstructions == 0);
+}
 
 /**
  * Apply texture object's swizzle (X/Y/Z/W/0/1) to incoming 'texel'
@@ -70,11 +84,12 @@ fetch_texel_lod( struct gl_context *ctx, const GLfloat texcoord[4], GLfloat lamb
    if (texObj) {
       SWcontext *swrast = SWRAST_CONTEXT(ctx);
       GLfloat rgba[4];
+      const struct gl_sampler_object *samp = _mesa_get_samplerobj(ctx, unit);
 
-      lambda = CLAMP(lambda, texObj->Sampler.MinLod, texObj->Sampler.MaxLod);
+      lambda = CLAMP(lambda, samp->MinLod, samp->MaxLod);
 
-      swrast->TextureSample[unit](ctx, texObj, 1,
-                                  (const GLfloat (*)[4]) texcoord,
+      swrast->TextureSample[unit](ctx, samp, ctx->Texture.Unit[unit]._Current,
+                                  1, (const GLfloat (*)[4]) texcoord,
                                   &lambda, &rgba);
       swizzle_texel(rgba, color, texObj->_Swizzle);
    }
@@ -105,6 +120,7 @@ fetch_texel_deriv( struct gl_context *ctx, const GLfloat texcoord[4],
          texObj->Image[0][texObj->BaseLevel];
       const struct swrast_texture_image *swImg =
          swrast_texture_image_const(texImg);
+      const struct gl_sampler_object *samp = _mesa_get_samplerobj(ctx, unit);
       const GLfloat texW = (GLfloat) swImg->WidthScale;
       const GLfloat texH = (GLfloat) swImg->HeightScale;
       GLfloat lambda;
@@ -117,12 +133,12 @@ fetch_texel_deriv( struct gl_context *ctx, const GLfloat texcoord[4],
                                       texcoord[0], texcoord[1], texcoord[3],
                                       1.0F / texcoord[3]);
 
-      lambda += lodBias + texUnit->LodBias + texObj->Sampler.LodBias;
+      lambda += lodBias + texUnit->LodBias + samp->LodBias;
 
-      lambda = CLAMP(lambda, texObj->Sampler.MinLod, texObj->Sampler.MaxLod);
+      lambda = CLAMP(lambda, samp->MinLod, samp->MaxLod);
 
-      swrast->TextureSample[unit](ctx, texObj, 1,
-                                  (const GLfloat (*)[4]) texcoord,
+      swrast->TextureSample[unit](ctx, samp, ctx->Texture.Unit[unit]._Current,
+                                  1, (const GLfloat (*)[4]) texcoord,
                                   &lambda, &rgba);
       swizzle_texel(rgba, color, texObj->_Swizzle);
    }