Merge branch 'master' into r300g-glsl
[mesa.git] / src / mesa / state_tracker / st_cb_fbo.c
index ecdb988033cdff4e9e3529fffd761a38e87b9be7..864f5d3ca3f2617092d3489da2d4c1ff3ef4f671 100644 (file)
@@ -93,7 +93,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
    if (strb->format != PIPE_FORMAT_NONE)
       format = strb->format;
    else
-      format = st_choose_renderbuffer_format(pipe, internalFormat);
+      format = st_choose_renderbuffer_format(pipe->screen, internalFormat);
       
    /* init renderbuffer fields */
    strb->Base.Width  = width;
@@ -165,12 +165,12 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
                                                      strb->texture,
                                                      0, 0, 0,
                                                      surface_usage );
-
-      assert(strb->surface->texture);
-      assert(strb->surface->format);
-      assert(strb->surface->width == width);
-      assert(strb->surface->height == height);
-
+      if (strb->surface) {
+         assert(strb->surface->texture);
+         assert(strb->surface->format);
+         assert(strb->surface->width == width);
+         assert(strb->surface->height == height);
+      }
 
       return strb->surface != NULL;
    }
@@ -258,6 +258,7 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw)
    strb->Base.ClassID = 0x4242; /* just a unique value */
    strb->Base.NumSamples = samples;
    strb->format = format;
+   init_renderbuffer_bits(strb, format);
    strb->software = sw;
    
    switch (format) {
@@ -297,6 +298,7 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw)
    default:
       _mesa_problem(NULL,
                    "Unexpected format in st_new_renderbuffer_fb");
+      _mesa_free(strb);
       return NULL;
    }
 
@@ -382,6 +384,7 @@ st_render_texture(GLcontext *ctx,
 
    rb->Width = texImage->Width2;
    rb->Height = texImage->Height2;
+   rb->_BaseFormat = texImage->_BaseFormat;
    /*printf("***** render to texture level %d: %d x %d\n", att->TextureLevel, rb->Width, rb->Height);*/
 
    /*printf("***** pipe texture %d x %d\n", pt->width[0], pt->height[0]);*/
@@ -445,6 +448,35 @@ st_finish_render_texture(GLcontext *ctx,
 }
 
 
+/**
+ * Validate a renderbuffer attachment for a particular usage.
+ */
+
+static GLboolean
+st_validate_attachment(struct pipe_screen *screen,
+                      const struct gl_renderbuffer_attachment *att,
+                      GLuint usage)
+{
+   const struct st_texture_object *stObj =
+      st_texture_object(att->Texture);
+
+   /**
+    * Only validate texture attachments for now, since
+    * st_renderbuffer_alloc_storage makes sure that
+    * the format is supported.
+    */
+
+   if (att->Type != GL_TEXTURE)
+      return GL_TRUE;
+
+   if (!stObj)
+      return GL_FALSE;
+
+   return screen->is_format_supported(screen, stObj->pt->format,
+                                     PIPE_TEXTURE_2D,
+                                     usage, 0);
+}
+
 /**
  * Check that the framebuffer configuration is valid in terms of what
  * the driver can support.
@@ -454,13 +486,37 @@ st_finish_render_texture(GLcontext *ctx,
 static void
 st_validate_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb)
 {
+   struct pipe_screen *screen = ctx->st->pipe->screen;
    const struct gl_renderbuffer *depthRb =
       fb->Attachment[BUFFER_DEPTH].Renderbuffer;
    const struct gl_renderbuffer *stencilRb =
       fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+   GLuint i;
 
    if (stencilRb && depthRb && stencilRb != depthRb) {
       fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
+      return;
+   }
+
+   if (!st_validate_attachment(screen,
+                              &fb->Attachment[BUFFER_DEPTH],
+                              PIPE_TEXTURE_USAGE_DEPTH_STENCIL)) {
+      fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
+      return;
+   }
+   if (!st_validate_attachment(screen,
+                              &fb->Attachment[BUFFER_STENCIL],
+                              PIPE_TEXTURE_USAGE_DEPTH_STENCIL)) {
+      fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
+      return;
+   }
+   for (i = 0; i < ctx->Const.MaxColorAttachments; i++) {
+      if (!st_validate_attachment(screen,
+                                 &fb->Attachment[BUFFER_COLOR0 + i],
+                                 PIPE_TEXTURE_USAGE_RENDER_TARGET)) {
+        fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
+        return;
+      }
    }
 }