mesa: replace gl_texture_format with gl_format
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_fbo.c
index f62ca7f9eb397dc5eaed6e520064358d1d59db78..90ea2ec335ca242f6abe78db5f3b56c04f0f4d67 100644 (file)
 #include "main/context.h"
 #include "main/texformat.h"
 #include "main/texrender.h"
+#include "drivers/common/meta.h"
 
 #include "radeon_common.h"
 #include "radeon_mipmap_tree.h"
 
-#define FILE_DEBUG_FLAG DEBUG_TEXTURE
+#define FILE_DEBUG_FLAG RADEON_TEXTURE
 #define DBG(...) do {                                           \
         if (RADEON_DEBUG & FILE_DEBUG_FLAG)                      \
                 _mesa_printf(__VA_ARGS__);                      \
@@ -146,8 +147,8 @@ radeon_alloc_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
    case GL_DEPTH_COMPONENT:
    case GL_DEPTH_COMPONENT24:
    case GL_DEPTH_COMPONENT32:
-      rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT;
-      rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
+      rb->_ActualFormat = GL_DEPTH_COMPONENT24;
+      rb->DataType = GL_UNSIGNED_INT;
       rb->DepthBits = 24;
       cpp = 4;
       break;
@@ -165,7 +166,8 @@ radeon_alloc_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
       return GL_FALSE;
    }
 
-  radeonFlush(ctx);
+  if (ctx->Driver.Flush)
+         ctx->Driver.Flush(ctx); /* +r6/r7 */
 
   if (rrb->bo)
     radeon_bo_unref(rrb->bo);
@@ -176,12 +178,13 @@ radeon_alloc_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
                                              width, height);
    }
    else {
-     uint32_t size = width * height * cpp;
+     uint32_t size;
      uint32_t pitch = ((cpp * width + 63) & ~63) / cpp;
 
      fprintf(stderr,"Allocating %d x %d radeon RBO (pitch %d)\n", width,
          height, pitch);
 
+     size = pitch * height * cpp;
      rrb->pitch = pitch * cpp;
      rrb->cpp = cpp;
      rrb->bo = radeon_bo_open(radeon->radeonScreen->bom,
@@ -280,7 +283,7 @@ radeon_create_renderbuffer(GLenum format, __DRIdrawablePrivate *driDrawPriv)
            rrb->base.RedBits = 8;
            rrb->base.GreenBits = 8;
            rrb->base.BlueBits = 8;
-           rrb->base.AlphaBits = 8;
+           rrb->base.AlphaBits = 0;
            rrb->base.DataType = GL_UNSIGNED_BYTE;
            break;
        case GL_RGBA8:
@@ -305,7 +308,7 @@ radeon_create_renderbuffer(GLenum format, __DRIdrawablePrivate *driDrawPriv)
            rrb->base.DataType = GL_UNSIGNED_SHORT;
            break;
        case GL_DEPTH_COMPONENT24:
-           rrb->base._ActualFormat = GL_DEPTH24_STENCIL8_EXT;
+           rrb->base._ActualFormat = GL_DEPTH_COMPONENT24;
            rrb->base._BaseFormat = GL_DEPTH_COMPONENT;
            rrb->base.DepthBits = 24;
            rrb->base.DataType = GL_UNSIGNED_INT;
@@ -371,7 +374,8 @@ radeon_framebuffer_renderbuffer(GLcontext * ctx,
                                GLenum attachment, struct gl_renderbuffer *rb)
 {
 
-   radeonFlush(ctx);
+       if (ctx->Driver.Flush)
+               ctx->Driver.Flush(ctx); /* +r6/r7 */
 
    _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb);
    radeon_draw_buffer(ctx, fb);
@@ -383,29 +387,45 @@ radeon_update_wrapper(GLcontext *ctx, struct radeon_renderbuffer *rrb,
                     struct gl_texture_image *texImage)
 {
        int retry = 0;
+       gl_format texFormat;
+
 restart:
-       if (texImage->TexFormat == &_mesa_texformat_argb8888) {
+       if (texImage->TexFormat == MESA_FORMAT_ARGB8888) {
                rrb->cpp = 4;
                rrb->base._ActualFormat = GL_RGBA8;
                rrb->base._BaseFormat = GL_RGBA;
                rrb->base.DataType = GL_UNSIGNED_BYTE;
                DBG("Render to RGBA8 texture OK\n");
        }
-       else if (texImage->TexFormat == &_mesa_texformat_rgb565) {
+       else if (texImage->TexFormat == MESA_FORMAT_RGB565) {
                rrb->cpp = 2;
                rrb->base._ActualFormat = GL_RGB5;
                rrb->base._BaseFormat = GL_RGB;
-               rrb->base.DataType = GL_UNSIGNED_SHORT;
+               rrb->base.DataType = GL_UNSIGNED_BYTE;
                DBG("Render to RGB5 texture OK\n");
        }
-       else if (texImage->TexFormat == &_mesa_texformat_z16) {
+       else if (texImage->TexFormat == MESA_FORMAT_ARGB1555) {
+               rrb->cpp = 2;
+               rrb->base._ActualFormat = GL_RGB5_A1;
+               rrb->base._BaseFormat = GL_RGBA;
+               rrb->base.DataType = GL_UNSIGNED_BYTE;
+               DBG("Render to ARGB1555 texture OK\n");
+       }
+       else if (texImage->TexFormat == MESA_FORMAT_ARGB4444) {
+               rrb->cpp = 2;
+               rrb->base._ActualFormat = GL_RGBA4;
+               rrb->base._BaseFormat = GL_RGBA;
+               rrb->base.DataType = GL_UNSIGNED_BYTE;
+               DBG("Render to ARGB1555 texture OK\n");
+       }
+       else if (texImage->TexFormat == MESA_FORMAT_Z16) {
                rrb->cpp = 2;
                rrb->base._ActualFormat = GL_DEPTH_COMPONENT16;
                rrb->base._BaseFormat = GL_DEPTH_COMPONENT;
                rrb->base.DataType = GL_UNSIGNED_SHORT;
                DBG("Render to DEPTH16 texture OK\n");
        }
-       else if (texImage->TexFormat == &_mesa_texformat_s8_z24) {
+       else if (texImage->TexFormat == MESA_FORMAT_S8_Z24) {
                rrb->cpp = 4;
                rrb->base._ActualFormat = GL_DEPTH24_STENCIL8_EXT;
                rrb->base._BaseFormat = GL_DEPTH_STENCIL_EXT;
@@ -416,26 +436,29 @@ restart:
                /* try redoing the FBO */
                if (retry == 1) {
                        DBG("Render to texture BAD FORMAT %d\n",
-                           texImage->TexFormat->MesaFormat);
+                           texImage->TexFormat);
                        return GL_FALSE;
                }
                texImage->TexFormat = radeonChooseTextureFormat(ctx, texImage->InternalFormat, 0,
-                                                               texImage->TexFormat->DataType,
+                                                               _mesa_get_format_datatype(texImage->TexFormat),
                                                                1);
 
                retry++;
                goto restart;
        }
        
+       texFormat = texImage->TexFormat;
+
        rrb->pitch = texImage->Width * rrb->cpp;
        rrb->base.InternalFormat = rrb->base._ActualFormat;
        rrb->base.Width = texImage->Width;
        rrb->base.Height = texImage->Height;
-       rrb->base.RedBits = texImage->TexFormat->RedBits;
-       rrb->base.GreenBits = texImage->TexFormat->GreenBits;
-       rrb->base.BlueBits = texImage->TexFormat->BlueBits;
-       rrb->base.AlphaBits = texImage->TexFormat->AlphaBits;
-       rrb->base.DepthBits = texImage->TexFormat->DepthBits;
+       rrb->base.RedBits = _mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE);
+       rrb->base.GreenBits = _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE);
+       rrb->base.BlueBits = _mesa_get_format_bits(texFormat, GL_TEXTURE_BLUE_SIZE);
+       rrb->base.AlphaBits = _mesa_get_format_bits(texFormat, GL_TEXTURE_ALPHA_SIZE);
+       rrb->base.DepthBits = _mesa_get_format_bits(texFormat, GL_TEXTURE_DEPTH_SIZE_ARB);
+       rrb->base.StencilBits = _mesa_get_format_bits(texFormat, GL_TEXTURE_STENCIL_SIZE_EXT);
        
        rrb->base.Delete = radeon_delete_renderbuffer;
        rrb->base.AllocStorage = radeon_nop_alloc_storage;
@@ -554,14 +577,6 @@ radeon_validate_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb)
 {
 }
 
-static void
-radeon_blit_framebuffer(GLcontext *ctx,
-                       GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
-                       GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
-                       GLbitfield mask, GLenum filter)
-{
-}
-
 void radeon_fbo_init(struct radeon_context *radeon)
 {
   radeon->glCtx->Driver.NewFramebuffer = radeon_new_framebuffer;
@@ -572,7 +587,7 @@ void radeon_fbo_init(struct radeon_context *radeon)
   radeon->glCtx->Driver.FinishRenderTexture = radeon_finish_render_texture;
   radeon->glCtx->Driver.ResizeBuffers = radeon_resize_buffers;
   radeon->glCtx->Driver.ValidateFramebuffer = radeon_validate_framebuffer;
-  radeon->glCtx->Driver.BlitFramebuffer = radeon_blit_framebuffer;
+  radeon->glCtx->Driver.BlitFramebuffer = _mesa_meta_BlitFramebuffer;
 }