Disabling some fallbacks as they cause misc programs not to start and adding some...
[mesa.git] / src / mesa / drivers / dri / r300 / r300_tex.c
index 33a8fa1e5ca2022816768f349d7c3280e1c29f59..000b7be0b09d7e98e8ea67e52cffc29e693e9415 100644 (file)
@@ -65,41 +65,37 @@ static void r300SetTexWrap(r300TexObjPtr t, GLenum swrap, GLenum twrap,
                           GLenum rwrap)
 {
        GLboolean is_clamp = GL_FALSE;
-       GLboolean is_clamp_to_border = GL_FALSE;
-       
-/* Most of these seem to be incorrect so disable for now */
-#if 0  
+       unsigned long hw_swrap=0, hw_twrap=0, hw_qwrap=0;
+
        t->filter &=
-           ~(R200_CLAMP_S_MASK | R200_CLAMP_T_MASK | R200_BORDER_MODE_D3D);
+           ~(R300_TX_WRAP_S_MASK | R300_TX_WRAP_T_MASK | R300_TX_WRAP_Q_MASK);
 
        switch (swrap) {
        case GL_REPEAT:
-               t->filter |= R200_CLAMP_S_WRAP;
+               hw_swrap |= R300_TX_REPEAT;
                break;
        case GL_CLAMP:
-               t->filter |= R200_CLAMP_S_CLAMP_GL;
+               hw_swrap |= R300_TX_CLAMP;
                is_clamp = GL_TRUE;
                break;
        case GL_CLAMP_TO_EDGE:
-               t->filter |= R200_CLAMP_S_CLAMP_LAST;
+               hw_swrap |= R300_TX_CLAMP_TO_EDGE;
                break;
        case GL_CLAMP_TO_BORDER:
-               t->filter |= R200_CLAMP_S_CLAMP_GL;
-               is_clamp_to_border = GL_TRUE;
+               hw_swrap |= R300_TX_CLAMP_TO_BORDER;
                break;
        case GL_MIRRORED_REPEAT:
-               t->filter |= R200_CLAMP_S_MIRROR;
+               hw_swrap |= R300_TX_REPEAT | R300_TX_MIRRORED;
                break;
        case GL_MIRROR_CLAMP_EXT:
-               t->filter |= R200_CLAMP_S_MIRROR_CLAMP_GL;
+               hw_swrap |= R300_TX_CLAMP | R300_TX_MIRRORED;
                is_clamp = GL_TRUE;
                break;
        case GL_MIRROR_CLAMP_TO_EDGE_EXT:
-               t->filter |= R200_CLAMP_S_MIRROR_CLAMP_LAST;
+               hw_swrap |= R300_TX_CLAMP_TO_EDGE | R300_TX_MIRRORED;
                break;
        case GL_MIRROR_CLAMP_TO_BORDER_EXT:
-               t->filter |= R200_CLAMP_S_MIRROR_CLAMP_GL;
-               is_clamp_to_border = GL_TRUE;
+               hw_swrap |= R300_TX_CLAMP_TO_BORDER | R300_TX_MIRRORED;
                break;
        default:
                _mesa_problem(NULL, "bad S wrap mode in %s", __FUNCTION__);
@@ -107,99 +103,92 @@ static void r300SetTexWrap(r300TexObjPtr t, GLenum swrap, GLenum twrap,
 
        switch (twrap) {
        case GL_REPEAT:
-               t->filter |= R200_CLAMP_T_WRAP;
+               hw_twrap |= R300_TX_REPEAT;
                break;
        case GL_CLAMP:
-               t->filter |= R200_CLAMP_T_CLAMP_GL;
+               hw_twrap |= R300_TX_CLAMP;
                is_clamp = GL_TRUE;
                break;
        case GL_CLAMP_TO_EDGE:
-               t->filter |= R200_CLAMP_T_CLAMP_LAST;
+               hw_twrap |= R300_TX_CLAMP_TO_EDGE;
                break;
        case GL_CLAMP_TO_BORDER:
-               t->filter |= R200_CLAMP_T_CLAMP_GL | R200_BORDER_MODE_D3D;
-               is_clamp_to_border = GL_TRUE;
+               hw_twrap |= R300_TX_CLAMP_TO_BORDER;
                break;
        case GL_MIRRORED_REPEAT:
-               t->filter |= R200_CLAMP_T_MIRROR;
+               hw_twrap |= R300_TX_REPEAT | R300_TX_MIRRORED;
                break;
        case GL_MIRROR_CLAMP_EXT:
-               t->filter |= R200_CLAMP_T_MIRROR_CLAMP_GL;
+               hw_twrap |= R300_TX_CLAMP | R300_TX_MIRRORED;
                is_clamp = GL_TRUE;
                break;
        case GL_MIRROR_CLAMP_TO_EDGE_EXT:
-               t->filter |= R200_CLAMP_T_MIRROR_CLAMP_LAST;
+               hw_twrap |= R300_TX_CLAMP_TO_EDGE | R300_TX_MIRRORED;
                break;
        case GL_MIRROR_CLAMP_TO_BORDER_EXT:
-               t->filter |= R200_CLAMP_T_MIRROR_CLAMP_GL;
-               is_clamp_to_border = GL_TRUE;
+               hw_twrap |= R300_TX_CLAMP_TO_BORDER | R300_TX_MIRRORED;
                break;
        default:
                _mesa_problem(NULL, "bad T wrap mode in %s", __FUNCTION__);
        }
 
-       t->format_x &= ~R200_CLAMP_Q_MASK;
-
        switch (rwrap) {
        case GL_REPEAT:
-               t->format_x |= R200_CLAMP_Q_WRAP;
+               hw_qwrap |= R300_TX_REPEAT;
                break;
        case GL_CLAMP:
-               t->format_x |= R200_CLAMP_Q_CLAMP_GL;
+               hw_qwrap |= R300_TX_CLAMP;
                is_clamp = GL_TRUE;
                break;
        case GL_CLAMP_TO_EDGE:
-               t->format_x |= R200_CLAMP_Q_CLAMP_LAST;
+               hw_qwrap |= R300_TX_CLAMP_TO_EDGE;
                break;
        case GL_CLAMP_TO_BORDER:
-               t->format_x |= R200_CLAMP_Q_CLAMP_GL;
-               is_clamp_to_border = GL_TRUE;
+               hw_qwrap |= R300_TX_CLAMP_TO_BORDER;
                break;
        case GL_MIRRORED_REPEAT:
-               t->format_x |= R200_CLAMP_Q_MIRROR;
+               hw_qwrap |= R300_TX_REPEAT | R300_TX_MIRRORED;
                break;
        case GL_MIRROR_CLAMP_EXT:
-               t->format_x |= R200_CLAMP_Q_MIRROR_CLAMP_GL;
+               hw_qwrap |= R300_TX_CLAMP | R300_TX_MIRRORED;
                is_clamp = GL_TRUE;
                break;
        case GL_MIRROR_CLAMP_TO_EDGE_EXT:
-               t->format_x |= R200_CLAMP_Q_MIRROR_CLAMP_LAST;
+               hw_qwrap |= R300_TX_CLAMP_TO_EDGE | R300_TX_MIRRORED;
                break;
        case GL_MIRROR_CLAMP_TO_BORDER_EXT:
-               t->format_x |= R200_CLAMP_Q_MIRROR_CLAMP_GL;
-               is_clamp_to_border = GL_TRUE;
+               hw_qwrap |= R300_TX_CLAMP_TO_BORDER | R300_TX_MIRRORED;
                break;
        default:
                _mesa_problem(NULL, "bad R wrap mode in %s", __FUNCTION__);
        }
-       
-       if (is_clamp_to_border) {
-               t->filter |= R200_BORDER_MODE_D3D;
-       }
 
+       t->filter |= hw_swrap << R300_TX_WRAP_S_SHIFT;
+       t->filter |= hw_twrap << R300_TX_WRAP_T_SHIFT;
+       t->filter |= hw_qwrap << R300_TX_WRAP_Q_SHIFT;
+
+#if 0
+       t->format_x &= ~R200_CLAMP_Q_MASK;
        t->border_fallback = (is_clamp && is_clamp_to_border);
-#endif 
+#endif
 }
 
 static void r300SetTexMaxAnisotropy(r300TexObjPtr t, GLfloat max)
 {
-       
-/* Needs testing */    
-#if 0  
-       t->filter &= ~R200_MAX_ANISO_MASK;
 
-       if (max == 1.0) {
-               t->filter |= R200_MAX_ANISO_1_TO_1;
+       t->filter &= ~R300_TX_MAX_ANISO_MASK;
+
+       if (max <= 1.0) {
+               t->filter |= R300_TX_MAX_ANISO_1_TO_1;
        } else if (max <= 2.0) {
-               t->filter |= R200_MAX_ANISO_2_TO_1;
+               t->filter |= R300_TX_MAX_ANISO_2_TO_1;
        } else if (max <= 4.0) {
-               t->filter |= R200_MAX_ANISO_4_TO_1;
+               t->filter |= R300_TX_MAX_ANISO_4_TO_1;
        } else if (max <= 8.0) {
-               t->filter |= R200_MAX_ANISO_8_TO_1;
+               t->filter |= R300_TX_MAX_ANISO_8_TO_1;
        } else {
-               t->filter |= R200_MAX_ANISO_16_TO_1;
+               t->filter |= R300_TX_MAX_ANISO_16_TO_1;
        }
-#endif 
 }
 
 /**
@@ -212,14 +201,14 @@ static void r300SetTexMaxAnisotropy(r300TexObjPtr t, GLfloat max)
 
 static void r300SetTexFilter(r300TexObjPtr t, GLenum minf, GLenum magf)
 {
-       GLuint anisotropy = 0; //(t->filter & R200_MAX_ANISO_MASK);
+       GLuint anisotropy = (t->filter & R300_TX_MAX_ANISO_MASK);
 
        t->filter &= ~(R300_TX_MIN_FILTER_MASK | R300_TX_MAG_FILTER_MASK);
-#if 0  
+#if 0
        //t->format_x &= ~R200_VOLUME_FILTER_MASK;
-#endif 
-       
-       if (anisotropy == R200_MAX_ANISO_1_TO_1) {
+#endif
+
+       if (anisotropy == R300_TX_MAX_ANISO_1_TO_1) {
                switch (minf) {
                case GL_NEAREST:
                        t->filter |= R300_TX_MIN_FILTER_NEAREST;
@@ -278,7 +267,7 @@ static void r300SetTexFilter(r300TexObjPtr t, GLenum minf, GLenum magf)
 
 static void r300SetTexBorderColor(r300TexObjPtr t, GLubyte c[4])
 {
-       t->pp_border_color = radeonPackColor(4, c[0], c[1], c[2], c[3]);
+       t->pp_border_color = radeonPackColor(4, c[3], c[2], c[1], c[0]);
 }
 
 /**
@@ -327,7 +316,16 @@ static const struct gl_texture_format *r300ChooseTextureFormat(GLcontext * ctx,
        const GLboolean force16bpt =
            (rmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FORCE_16);
        (void)format;
-       
+
+#if 0
+       fprintf(stderr, "InternalFormat=%s(%d) type=%s format=%s\n",
+               _mesa_lookup_enum_by_nr(internalFormat), internalFormat,
+               _mesa_lookup_enum_by_nr(type),
+               _mesa_lookup_enum_by_nr(format));
+       fprintf(stderr, "do32bpt=%d force16bpt=%d\n",
+               do32bpt, force16bpt);
+#endif
+
        switch (internalFormat) {
        case 4:
        case GL_RGBA:
@@ -811,7 +809,7 @@ static void r300TexEnv(GLcontext * ctx, GLenum target,
                fprintf(stderr, "%s( %s )\n",
                        __FUNCTION__, _mesa_lookup_enum_by_nr(pname));
        }
-                       
+
        /* This is incorrect: Need to maintain this data for each of
         * GL_TEXTURE_{123}D, GL_TEXTURE_RECTANGLE_NV, etc, and switch
         * between them according to _ReallyEnabled.
@@ -836,7 +834,7 @@ static void r300TexEnv(GLcontext * ctx, GLenum target,
                        GLfloat bias, min;
                        GLuint b;
 
-                       /* The R200's LOD bias is a signed 2's complement value with a
+                       /* The R300's LOD bias is a signed 2's complement value with a
                         * range of -16.0 <= bias < 16.0.
                         *
                         * NOTE: Add a small bias to the bias for conform mipsel.c test.
@@ -846,16 +844,12 @@ static void r300TexEnv(GLcontext * ctx, GLenum target,
                            driQueryOptionb(&rmesa->radeon.optionCache,
                                            "no_neg_lod_bias") ? 0.0 : -16.0;
                        bias = CLAMP(bias, min, 16.0);
-                       
-#define R300_LOD_BIAS_MASK     0x1fff
-                       
-                       /* 1.0 is 0x00000100 and 10.0 is 0x00000a00 --aet */
 
+                       /* 0.0 - 16.0 == 0x0 - 0x1000 */
+                       /* 0.0 - -16.0 == 0x1001 - 0x1fff */
                        b = 0x1000 / 16.0 * bias;
-                       /* No clue about negative biases but this would 
-                          seem logical if positive max is 0x1000 */
                        b &= R300_LOD_BIAS_MASK;
-                       
+
                        if(b != (rmesa->hw.tex.unknown1.cmd[R300_TEX_VALUE_0+unit] & R300_LOD_BIAS_MASK)){
                                R300_STATECHANGE(rmesa, tex.unknown1);
                                rmesa->hw.tex.unknown1.cmd[R300_TEX_VALUE_0+unit] &= ~R300_LOD_BIAS_MASK;
@@ -980,10 +974,10 @@ static void r300TexGen(GLcontext * ctx,
 {
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
        GLuint unit = ctx->Texture.CurrentUnit;
-       #if 0 /* Disable this for now - looks like we will be recalculating everything
+#if 0 /* Disable this for now - looks like we will be recalculating everything
                 anyway */
        rmesa->recheck_texgen[unit] = GL_TRUE;
-       #endif
+#endif
 }
 
 /**
@@ -1005,6 +999,7 @@ static struct gl_texture_object *r300NewTextureObject(GLcontext * ctx,
        if (!obj)
                return NULL;
        obj->MaxAnisotropy = rmesa->initialMaxAnisotropy;
+
        r300AllocTexObj(obj);
        return obj;
 }