r3xx/r5xx: Enable ARB_point_parameters.
[mesa.git] / src / mesa / drivers / dri / r300 / r300_state.c
index 1d4472d59ef9eff70e234f9686a7fba786fd6112..592ee9ccc1024e473b0c40ef1f9aa9fb59bc3679 100644 (file)
@@ -827,6 +827,31 @@ static void r300PointSize(GLcontext * ctx, GLfloat size)
            ((int)(size * 6) << R300_POINTSIZE_Y_SHIFT);
 }
 
+static void r300PointParameter(GLcontext * ctx, GLenum pname, const GLfloat * param)
+{
+       r300ContextPtr r300 = R300_CONTEXT(ctx);
+
+       switch (pname) {
+       case GL_POINT_SIZE_MIN:
+               R300_STATECHANGE(r300, ga_point_minmax);
+               r300->hw.ga_point_minmax.cmd[1] &= ~R300_GA_POINT_MINMAX_MIN_MASK;
+               r300->hw.ga_point_minmax.cmd[1] |= (GLuint)(ctx->Point.MinSize * 16.0);
+               break;
+       case GL_POINT_SIZE_MAX:
+               R300_STATECHANGE(r300, ga_point_minmax);
+               r300->hw.ga_point_minmax.cmd[1] &= ~R300_GA_POINT_MINMAX_MAX_MASK;
+               r300->hw.ga_point_minmax.cmd[1] |= (GLuint)(ctx->Point.MaxSize * 16.0)
+                       << R300_GA_POINT_MINMAX_MAX_SHIFT;
+               break;
+       case GL_POINT_DISTANCE_ATTENUATION:
+               break;
+       case GL_POINT_FADE_THRESHOLD_SIZE:
+               break;
+       default:
+               break;
+       }
+}
+
 /* =============================================================
  * Line state
  */
@@ -1381,16 +1406,14 @@ static void r500SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
        }
 }
 
-static GLuint r300CalculateTexLodBias(GLfloat bias)
+static GLuint translate_lod_bias(GLfloat bias)
 {
-       GLuint b;
-       b = (unsigned int)fabsf(ceilf(bias*31));
-       if (signbit(bias)) {
-               b ^= 0x3ff; /* 10 bits */
-       }
-       b <<= 3;
-       b &= R300_LOD_BIAS_MASK;
-       return b;
+       GLint b = (int)(bias*32);
+       if (b >= (1 << 9))
+               b = (1 << 9)-1;
+       else if (b < -(1 << 9))
+               b = -(1 << 9);
+       return (((GLuint)b) << R300_LOD_BIAS_SHIFT) & R300_LOD_BIAS_MASK;
 }
 
 static void r300SetupTextures(GLcontext * ctx)
@@ -1456,8 +1479,14 @@ static void r300SetupTextures(GLcontext * ctx)
                        r300->hw.tex.filter.cmd[R300_TEX_VALUE_0 +
                                                hw_tmu] =
                            gen_fixed_filter(t->filter) | (hw_tmu << 28);
-                       r300->hw.tex.filter_1.cmd[R300_TEX_VALUE_0 + hw_tmu] = t->filter_1
-                               | r300CalculateTexLodBias(r300->LODBias);
+                       /* Note: There is a LOD bias per texture unit and a LOD bias
+                        * per texture object. We add them here to get the correct behaviour.
+                        * (The per-texture object LOD bias was introduced in OpenGL 1.4
+                        * and is not present in the EXT_texture_object extension).
+                        */
+                       r300->hw.tex.filter_1.cmd[R300_TEX_VALUE_0 + hw_tmu] =
+                               t->filter_1 |
+                               translate_lod_bias(ctx->Texture.Unit[i].LodBias + t->base.tObj->LodBias);
                        r300->hw.tex.size.cmd[R300_TEX_VALUE_0 + hw_tmu] =
                            t->size;
                        r300->hw.tex.format.cmd[R300_TEX_VALUE_0 +
@@ -2702,6 +2731,9 @@ void r300InitStateFuncs(struct dd_function_table *functions)
        functions->FrontFace = r300FrontFace;
        functions->ShadeModel = r300ShadeModel;
 
+       /* ARB_point_parameters */
+       functions->PointParameterfv = r300PointParameter;
+
        /* Stencil related */
        functions->StencilFuncSeparate = r300StencilFuncSeparate;
        functions->StencilMaskSeparate = r300StencilMaskSeparate;