i965: Mostly fix glsl-max-varyings.
[mesa.git] / src / mesa / drivers / dri / r300 / r300_tex.c
index 11e89ffd0f0bc6ef13d45d4fb58517bed808bd0f..baef206bc26e256563a4a27a3393cb97c77781e0 100644 (file)
@@ -40,21 +40,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "main/image.h"
 #include "main/mipmap.h"
 #include "main/simple_list.h"
-#include "main/texformat.h"
 #include "main/texstore.h"
-#include "main/teximage.h"
 #include "main/texobj.h"
 
 #include "texmem.h"
 
 #include "r300_context.h"
-#include "r300_state.h"
-#include "r300_ioctl.h"
 #include "radeon_mipmap_tree.h"
 #include "r300_tex.h"
 
-#include "xmlpool.h"
-
 
 static unsigned int translate_wrap_mode(GLenum wrapmode)
 {
@@ -137,7 +131,7 @@ static void r300SetTexFilter(radeonTexObjPtr t, GLenum minf, GLenum magf, GLfloa
                        | R300_TX_MIN_FILTER_ANISO
                        | R300_TX_MIN_FILTER_MIP_LINEAR
                        | aniso_filter(anisotropy);
-               if (RADEON_DEBUG & DEBUG_TEXTURE)
+               if (RADEON_DEBUG & RADEON_TEXTURE)
                        fprintf(stderr, "Using maximum anisotropy of %f\n", anisotropy);
                return;
        }
@@ -176,8 +170,13 @@ static void r300SetTexFilter(radeonTexObjPtr t, GLenum minf, GLenum magf, GLfloa
        }
 }
 
-static void r300SetTexBorderColor(radeonTexObjPtr t, GLubyte c[4])
+static void r300SetTexBorderColor(radeonTexObjPtr t, const GLfloat color[4])
 {
+       GLubyte c[4];
+       CLAMPED_FLOAT_TO_UBYTE(c[0], color[0]);
+       CLAMPED_FLOAT_TO_UBYTE(c[1], color[1]);
+       CLAMPED_FLOAT_TO_UBYTE(c[2], color[2]);
+       CLAMPED_FLOAT_TO_UBYTE(c[3], color[3]);
        t->pp_border_color = PACK_COLOR_8888(c[3], c[0], c[1], c[2]);
 }
 
@@ -191,8 +190,9 @@ static void r300TexParameter(GLcontext * ctx, GLenum target,
                             GLenum pname, const GLfloat * params)
 {
        radeonTexObj* t = radeon_tex_obj(texObj);
+       GLenum texBaseFormat;
 
-       if (RADEON_DEBUG & (DEBUG_STATE | DEBUG_TEXTURE)) {
+       if (RADEON_DEBUG & (RADEON_STATE | RADEON_TEXTURE)) {
                fprintf(stderr, "%s( %s )\n", __FUNCTION__,
                        _mesa_lookup_enum_by_nr(pname));
        }
@@ -211,30 +211,23 @@ static void r300TexParameter(GLcontext * ctx, GLenum target,
                break;
 
        case GL_TEXTURE_BORDER_COLOR:
-               r300SetTexBorderColor(t, texObj->_BorderChan);
+               r300SetTexBorderColor(t, texObj->BorderColor.f);
                break;
 
        case GL_TEXTURE_BASE_LEVEL:
        case GL_TEXTURE_MAX_LEVEL:
        case GL_TEXTURE_MIN_LOD:
        case GL_TEXTURE_MAX_LOD:
-               /* This isn't the most efficient solution but there doesn't appear to
-                * be a nice alternative.  Since there's no LOD clamping,
-                * we just have to rely on loading the right subset of mipmap levels
-                * to simulate a clamped LOD.
-                */
-               if (t->mt) {
-                       radeon_miptree_unreference(t->mt);
-                       t->mt = 0;
-                       t->validated = GL_FALSE;
-               }
+               t->validated = GL_FALSE;
                break;
 
        case GL_DEPTH_TEXTURE_MODE:
                if (!texObj->Image[0][texObj->BaseLevel])
                        return;
-               if (texObj->Image[0][texObj->BaseLevel]->TexFormat->BaseFormat
-                   == GL_DEPTH_COMPONENT) {
+               texBaseFormat = texObj->Image[0][texObj->BaseLevel]->_BaseFormat;
+
+               if (texBaseFormat == GL_DEPTH_COMPONENT ||
+                       texBaseFormat == GL_DEPTH_STENCIL) {
                        r300SetDepthTexMode(texObj);
                        break;
                } else {
@@ -255,7 +248,7 @@ static void r300DeleteTexture(GLcontext * ctx, struct gl_texture_object *texObj)
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
        radeonTexObj* t = radeon_tex_obj(texObj);
 
-       if (RADEON_DEBUG & (DEBUG_STATE | DEBUG_TEXTURE)) {
+       if (RADEON_DEBUG & (RADEON_STATE | RADEON_TEXTURE)) {
                fprintf(stderr, "%s( %p (target = %s) )\n", __FUNCTION__,
                        (void *)texObj,
                        _mesa_lookup_enum_by_nr(texObj->Target));
@@ -263,17 +256,24 @@ static void r300DeleteTexture(GLcontext * ctx, struct gl_texture_object *texObj)
 
        if (rmesa) {
                int i;
-               R300_FIREVERTICES(rmesa);
+               struct radeon_bo *bo;
+               bo = !t->mt ? t->bo : t->mt->bo;
+               if (bo && radeon_bo_is_referenced_by_cs(bo, rmesa->radeon.cmdbuf.cs)) {
+                       radeon_firevertices(&rmesa->radeon);
+               }
 
                for(i = 0; i < R300_MAX_TEXTURE_UNITS; ++i)
                        if (rmesa->hw.textures[i] == t)
                                rmesa->hw.textures[i] = 0;
        }
 
-       if (t->mt) {
-               radeon_miptree_unreference(t->mt);
-               t->mt = 0;
+       if (t->bo) {
+               radeon_bo_unref(t->bo);
+               t->bo = NULL;
        }
+
+       radeon_miptree_unreference(&t->mt);
+
        _mesa_delete_texture_object(ctx, texObj);
 }
 
@@ -292,7 +292,7 @@ static struct gl_texture_object *r300NewTextureObject(GLcontext * ctx,
        radeonTexObj* t = CALLOC_STRUCT(radeon_tex_obj);
 
 
-       if (RADEON_DEBUG & (DEBUG_STATE | DEBUG_TEXTURE)) {
+       if (RADEON_DEBUG & (RADEON_STATE | RADEON_TEXTURE)) {
                fprintf(stderr, "%s( %p (target = %s) )\n", __FUNCTION__,
                        t, _mesa_lookup_enum_by_nr(target));
        }
@@ -303,12 +303,51 @@ static struct gl_texture_object *r300NewTextureObject(GLcontext * ctx,
        /* Initialize hardware state */
        r300UpdateTexWrap(t);
        r300SetTexFilter(t, t->base.MinFilter, t->base.MagFilter, t->base.MaxAnisotropy);
-       r300SetTexBorderColor(t, t->base._BorderChan);
+       r300SetTexBorderColor(t, t->base.BorderColor.f);
 
        return &t->base;
 }
 
-void r300InitTextureFuncs(struct dd_function_table *functions)
+unsigned r300IsFormatRenderable(gl_format mesa_format)
+{
+       switch (mesa_format)
+       {
+               case MESA_FORMAT_RGB565:
+               case MESA_FORMAT_RGBA5551:
+               case MESA_FORMAT_RGBA8888:
+               case MESA_FORMAT_RGB565_REV:
+               case MESA_FORMAT_RGBA8888_REV:
+               case MESA_FORMAT_ARGB4444:
+               case MESA_FORMAT_ARGB1555:
+               case MESA_FORMAT_XRGB8888:
+               case MESA_FORMAT_ARGB8888:
+               case MESA_FORMAT_ARGB4444_REV:
+               case MESA_FORMAT_ARGB1555_REV:
+               case MESA_FORMAT_XRGB8888_REV:
+               case MESA_FORMAT_ARGB8888_REV:
+               case MESA_FORMAT_SRGBA8:
+               case MESA_FORMAT_SARGB8:
+               case MESA_FORMAT_SL8:
+               case MESA_FORMAT_A8:
+               case MESA_FORMAT_L8:
+               case MESA_FORMAT_I8:
+               case MESA_FORMAT_Z16:
+                       return 1;
+               default:
+                       return 0;
+       }
+}
+
+unsigned r500IsFormatRenderable(gl_format mesa_format)
+{
+       if (mesa_format == MESA_FORMAT_S8_Z24) {
+               return 1;
+       } else {
+               return r300IsFormatRenderable(mesa_format);
+       }
+}
+
+void r300InitTextureFuncs(radeonContextPtr radeon, struct dd_function_table *functions)
 {
        /* Note: we only plug in the functions we implement in the driver
         * since _mesa_init_driver_functions() was already called.
@@ -318,13 +357,15 @@ void r300InitTextureFuncs(struct dd_function_table *functions)
        functions->MapTexture = radeonMapTexture;
        functions->UnmapTexture = radeonUnmapTexture;
 
-       functions->ChooseTextureFormat = radeonChooseTextureFormat;
+       functions->ChooseTextureFormat = radeonChooseTextureFormat_mesa;
        functions->TexImage1D = radeonTexImage1D;
        functions->TexImage2D = radeonTexImage2D;
        functions->TexImage3D = radeonTexImage3D;
        functions->TexSubImage1D = radeonTexSubImage1D;
        functions->TexSubImage2D = radeonTexSubImage2D;
        functions->TexSubImage3D = radeonTexSubImage3D;
+       functions->GetTexImage = radeonGetTexImage;
+       functions->GetCompressedTexImage = radeonGetCompressedTexImage;
        functions->NewTextureObject = r300NewTextureObject;
        functions->DeleteTexture = r300DeleteTexture;
        functions->IsTextureResident = driIsTextureResident;
@@ -334,7 +375,12 @@ void r300InitTextureFuncs(struct dd_function_table *functions)
        functions->CompressedTexImage2D = radeonCompressedTexImage2D;
        functions->CompressedTexSubImage2D = radeonCompressedTexSubImage2D;
 
-       functions->GenerateMipmap = radeon_generate_mipmap;
+       if (radeon->radeonScreen->kernel_mm) {
+               functions->CopyTexImage2D = radeonCopyTexImage2D;
+               functions->CopyTexSubImage2D = radeonCopyTexSubImage2D;
+       }
+
+       functions->GenerateMipmap = radeonGenerateMipmap;
 
        driInitTextureFormats();
 }