X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Ffbobject.c;h=de1b524c0b5db57fbfcd4d023a2fa1bbb905083f;hp=13f49da5a78f2bb47a83fc7f105d4482176ae77f;hb=43867acb6afc7fad26cdc2f22b2a3bb6eeefb2da;hpb=ecf3091cc78638919f1977ccc0307c51b6731385 diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index 13f49da5a78..de1b524c0b5 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -34,21 +34,24 @@ #include "buffers.h" #include "context.h" +#include "enums.h" #include "fbobject.h" +#include "formats.h" #include "framebuffer.h" #include "hash.h" #include "macros.h" -#include "mipmap.h" #include "renderbuffer.h" #include "state.h" #include "teximage.h" #include "texobj.h" -#include "texstore.h" /** Set this to 1 to help debug FBO incompleteness problems */ #define DEBUG_FBO 0 +/** Set this to 1 to debug/log glBlitFramebuffer() calls */ +#define DEBUG_BLIT 0 + /** * Notes: @@ -227,9 +230,13 @@ _mesa_set_texture_attachment(GLcontext *ctx, if (att->Texture == texObj) { /* re-attaching same texture */ ASSERT(att->Type == GL_TEXTURE); + if (ctx->Driver.FinishRenderTexture) + ctx->Driver.FinishRenderTexture(ctx, att); } else { /* new attachment */ + if (ctx->Driver.FinishRenderTexture && att->Texture) + ctx->Driver.FinishRenderTexture(ctx, att); _mesa_remove_attachment(ctx, att); att->Type = GL_TEXTURE; assert(!att->Texture); @@ -238,12 +245,7 @@ _mesa_set_texture_attachment(GLcontext *ctx, /* always update these fields */ att->TextureLevel = level; - if (IS_CUBE_FACE(texTarget)) { - att->CubeMapFace = texTarget - GL_TEXTURE_CUBE_MAP_POSITIVE_X; - } - else { - att->CubeMapFace = 0; - } + att->CubeMapFace = _mesa_tex_target_to_face(texTarget); att->Zoffset = zoffset; att->Complete = GL_FALSE; @@ -356,6 +358,7 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format, if (att->Type == GL_TEXTURE) { const struct gl_texture_object *texObj = att->Texture; struct gl_texture_image *texImage; + GLenum baseFormat; if (!texObj) { att_incomplete("no texobj"); @@ -382,26 +385,28 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format, return; } + baseFormat = _mesa_get_format_base_format(texImage->TexFormat); + if (format == GL_COLOR) { - if (texImage->TexFormat->BaseFormat != GL_RGB && - texImage->TexFormat->BaseFormat != GL_RGBA) { + if (baseFormat != GL_RGB && + baseFormat != GL_RGBA) { att_incomplete("bad format"); att->Complete = GL_FALSE; return; } - if (texImage->TexFormat->TexelBytes == 0) { + if (_mesa_is_format_compressed(texImage->TexFormat)) { att_incomplete("compressed internalformat"); att->Complete = GL_FALSE; return; } } else if (format == GL_DEPTH) { - if (texImage->TexFormat->BaseFormat == GL_DEPTH_COMPONENT) { + if (baseFormat == GL_DEPTH_COMPONENT) { /* OK */ } else if (ctx->Extensions.EXT_packed_depth_stencil && ctx->Extensions.ARB_depth_texture && - texImage->TexFormat->BaseFormat == GL_DEPTH_STENCIL_EXT) { + baseFormat == GL_DEPTH_STENCIL_EXT) { /* OK */ } else { @@ -412,10 +417,9 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format, } else { ASSERT(format == GL_STENCIL); - ASSERT(att->Renderbuffer->StencilBits); if (ctx->Extensions.EXT_packed_depth_stencil && ctx->Extensions.ARB_depth_texture && - att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL_EXT) { + baseFormat == GL_DEPTH_STENCIL_EXT) { /* OK */ } else { @@ -427,6 +431,9 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format, } } else if (att->Type == GL_RENDERBUFFER_EXT) { + const GLenum baseFormat = + _mesa_get_format_base_format(att->Renderbuffer->Format); + ASSERT(att->Renderbuffer); if (!att->Renderbuffer->InternalFormat || att->Renderbuffer->Width < 1 || @@ -436,24 +443,19 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format, return; } if (format == GL_COLOR) { - if (att->Renderbuffer->_BaseFormat != GL_RGB && - att->Renderbuffer->_BaseFormat != GL_RGBA) { + if (baseFormat != GL_RGB && + baseFormat != GL_RGBA) { att_incomplete("bad renderbuffer color format"); att->Complete = GL_FALSE; return; } - ASSERT(att->Renderbuffer->RedBits); - ASSERT(att->Renderbuffer->GreenBits); - ASSERT(att->Renderbuffer->BlueBits); } else if (format == GL_DEPTH) { - if (att->Renderbuffer->_BaseFormat == GL_DEPTH_COMPONENT) { - ASSERT(att->Renderbuffer->DepthBits); + if (baseFormat == GL_DEPTH_COMPONENT) { /* OK */ } else if (ctx->Extensions.EXT_packed_depth_stencil && - att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL_EXT) { - ASSERT(att->Renderbuffer->DepthBits); + baseFormat == GL_DEPTH_STENCIL_EXT) { /* OK */ } else { @@ -464,13 +466,11 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format, } else { assert(format == GL_STENCIL); - if (att->Renderbuffer->_BaseFormat == GL_STENCIL_INDEX) { - ASSERT(att->Renderbuffer->StencilBits); + if (baseFormat == GL_STENCIL_INDEX) { /* OK */ } else if (ctx->Extensions.EXT_packed_depth_stencil && - att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL_EXT) { - ASSERT(att->Renderbuffer->StencilBits); + baseFormat == GL_DEPTH_STENCIL_EXT) { /* OK */ } else { @@ -651,6 +651,8 @@ _mesa_test_framebuffer_completeness(GLcontext *ctx, struct gl_framebuffer *fb) return; } } +#else + (void) j; #endif if (numImages == 0) { @@ -711,18 +713,13 @@ _mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer) ASSERT_OUTSIDE_BEGIN_END(ctx); if (target != GL_RENDERBUFFER_EXT) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glBindRenderbufferEXT(target)"); + _mesa_error(ctx, GL_INVALID_ENUM, "glBindRenderbufferEXT(target)"); return; } - FLUSH_CURRENT(ctx, _NEW_BUFFERS); - /* The above doesn't fully flush the drivers in the way that a - * glFlush does, but that is required here: + /* No need to flush here since the render buffer binding has no + * effect on rendering state. */ - if (ctx->Driver.Flush) - ctx->Driver.Flush(ctx); - if (renderbuffer) { newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer); @@ -861,6 +858,9 @@ _mesa_GenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers) * * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT * GL_DEPTH_STENCIL_EXT or zero if error. + * + * XXX in the future when we support red-only and red-green formats + * we'll also return GL_RED and GL_RG. */ GLenum _mesa_base_fbo_format(GLcontext *ctx, GLenum internalFormat) @@ -976,42 +976,27 @@ renderbuffer_storage(GLenum target, GLenum internalFormat, } /* These MUST get set by the AllocStorage func */ - rb->_ActualFormat = 0; - rb->RedBits = - rb->GreenBits = - rb->BlueBits = - rb->AlphaBits = - rb->IndexBits = - rb->DepthBits = - rb->StencilBits = 0; + rb->Format = MESA_FORMAT_NONE; rb->NumSamples = samples; /* Now allocate the storage */ ASSERT(rb->AllocStorage); if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) { /* No error - check/set fields now */ - assert(rb->_ActualFormat); + assert(rb->Format != MESA_FORMAT_NONE); assert(rb->Width == (GLuint) width); assert(rb->Height == (GLuint) height); - assert(rb->RedBits || rb->GreenBits || rb->BlueBits || rb->AlphaBits || - rb->DepthBits || rb->StencilBits || rb->IndexBits); rb->InternalFormat = internalFormat; - rb->_BaseFormat = baseFormat; + rb->_BaseFormat = _mesa_base_fbo_format(ctx, internalFormat); + assert(rb->_BaseFormat != 0); } else { /* Probably ran out of memory - clear the fields */ rb->Width = 0; rb->Height = 0; + rb->Format = MESA_FORMAT_NONE; rb->InternalFormat = GL_NONE; - rb->_ActualFormat = GL_NONE; rb->_BaseFormat = GL_NONE; - rb->RedBits = - rb->GreenBits = - rb->BlueBits = - rb->AlphaBits = - rb->IndexBits = - rb->DepthBits = - rb->StencilBits = rb->NumSamples = 0; } @@ -1024,6 +1009,53 @@ renderbuffer_storage(GLenum target, GLenum internalFormat, } +/** + * Helper function for _mesa_GetRenderbufferParameterivEXT() and + * _mesa_GetFramebufferAttachmentParameterivEXT() + * We have to be careful to respect the base format. For example, if a + * renderbuffer/texture was created with internalFormat=GL_RGB but the + * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE + * we need to return zero. + */ +static GLint +get_component_bits(GLenum pname, GLenum baseFormat, gl_format format) +{ + switch (pname) { + case GL_RENDERBUFFER_RED_SIZE_EXT: + case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: + case GL_RENDERBUFFER_GREEN_SIZE_EXT: + case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: + case GL_RENDERBUFFER_BLUE_SIZE_EXT: + case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: + if (baseFormat == GL_RGB || baseFormat == GL_RGBA) + return _mesa_get_format_bits(format, pname); + else + return 0; + case GL_RENDERBUFFER_ALPHA_SIZE_EXT: + case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: + if (baseFormat == GL_RGBA || baseFormat == GL_ALPHA) + return _mesa_get_format_bits(format, pname); + else + return 0; + case GL_RENDERBUFFER_DEPTH_SIZE_EXT: + case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: + if (baseFormat == GL_DEPTH_COMPONENT || baseFormat == GL_DEPTH_STENCIL) + return _mesa_get_format_bits(format, pname); + else + return 0; + case GL_RENDERBUFFER_STENCIL_SIZE_EXT: + case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: + if (baseFormat == GL_STENCIL_INDEX || baseFormat == GL_DEPTH_STENCIL) + return _mesa_get_format_bits(format, pname); + else + return 0; + default: + return 0; + } +} + + + void GLAPIENTRY _mesa_RenderbufferStorageEXT(GLenum target, GLenum internalFormat, GLsizei width, GLsizei height) @@ -1067,7 +1099,9 @@ _mesa_GetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params) return; } - FLUSH_VERTICES(ctx, _NEW_BUFFERS); + /* No need to flush here since we're just quering state which is + * not effected by rendering. + */ switch (pname) { case GL_RENDERBUFFER_WIDTH_EXT: @@ -1080,22 +1114,12 @@ _mesa_GetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params) *params = rb->InternalFormat; return; case GL_RENDERBUFFER_RED_SIZE_EXT: - *params = rb->RedBits; - break; case GL_RENDERBUFFER_GREEN_SIZE_EXT: - *params = rb->GreenBits; - break; case GL_RENDERBUFFER_BLUE_SIZE_EXT: - *params = rb->BlueBits; - break; case GL_RENDERBUFFER_ALPHA_SIZE_EXT: - *params = rb->AlphaBits; - break; case GL_RENDERBUFFER_DEPTH_SIZE_EXT: - *params = rb->DepthBits; - break; case GL_RENDERBUFFER_STENCIL_SIZE_EXT: - *params = rb->StencilBits; + *params = get_component_bits(pname, rb->_BaseFormat, rb->Format); break; case GL_RENDERBUFFER_SAMPLES: if (ctx->Extensions.ARB_framebuffer_object) { @@ -1125,16 +1149,25 @@ _mesa_IsFramebufferEXT(GLuint framebuffer) } +/** + * Check if any of the attachments of the given framebuffer are textures + * (render to texture). Call ctx->Driver.RenderTexture() for such + * attachments. + */ static void check_begin_texture_render(GLcontext *ctx, struct gl_framebuffer *fb) { GLuint i; ASSERT(ctx->Driver.RenderTexture); + + if (fb->Name == 0) + return; /* can't render to texture with winsys framebuffers */ + for (i = 0; i < BUFFER_COUNT; i++) { struct gl_renderbuffer_attachment *att = fb->Attachment + i; struct gl_texture_object *texObj = att->Texture; if (texObj - && att->Texture->Image[att->CubeMapFace][att->TextureLevel]) { + && texObj->Image[att->CubeMapFace][att->TextureLevel]) { ctx->Driver.RenderTexture(ctx, fb, att); } } @@ -1149,6 +1182,9 @@ check_begin_texture_render(GLcontext *ctx, struct gl_framebuffer *fb) static void check_end_texture_render(GLcontext *ctx, struct gl_framebuffer *fb) { + if (fb->Name == 0) + return; /* can't render to texture with winsys framebuffers */ + if (ctx->Driver.FinishRenderTexture) { GLuint i; for (i = 0; i < BUFFER_COUNT; i++) { @@ -1164,7 +1200,8 @@ check_end_texture_render(GLcontext *ctx, struct gl_framebuffer *fb) void GLAPIENTRY _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer) { - struct gl_framebuffer *newFb, *newFbread; + struct gl_framebuffer *newDrawFb, *newReadFb; + struct gl_framebuffer *oldDrawFb, *oldReadFb; GLboolean bindReadBuf, bindDrawBuf; GET_CURRENT_CONTEXT(ctx); @@ -1211,76 +1248,90 @@ _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer) return; } - FLUSH_CURRENT(ctx, _NEW_BUFFERS); - if (ctx->Driver.Flush) { - ctx->Driver.Flush(ctx); - } - if (framebuffer) { /* Binding a user-created framebuffer object */ - newFb = _mesa_lookup_framebuffer(ctx, framebuffer); - if (newFb == &DummyFramebuffer) { + newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer); + if (newDrawFb == &DummyFramebuffer) { /* ID was reserved, but no real framebuffer object made yet */ - newFb = NULL; + newDrawFb = NULL; } - else if (!newFb && ctx->Extensions.ARB_framebuffer_object) { + else if (!newDrawFb && ctx->Extensions.ARB_framebuffer_object) { /* All FBO IDs must be Gen'd */ _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)"); return; } - if (!newFb) { + if (!newDrawFb) { /* create new framebuffer object */ - newFb = ctx->Driver.NewFramebuffer(ctx, framebuffer); - if (!newFb) { + newDrawFb = ctx->Driver.NewFramebuffer(ctx, framebuffer); + if (!newDrawFb) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT"); return; } - _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newFb); + _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb); } - newFbread = newFb; + newReadFb = newDrawFb; } else { /* Binding the window system framebuffer (which was originally set * with MakeCurrent). */ - newFb = ctx->WinSysDrawBuffer; - newFbread = ctx->WinSysReadBuffer; + newDrawFb = ctx->WinSysDrawBuffer; + newReadFb = ctx->WinSysReadBuffer; } - ASSERT(newFb); - ASSERT(newFb != &DummyFramebuffer); + ASSERT(newDrawFb); + ASSERT(newDrawFb != &DummyFramebuffer); + + /* save pointers to current/old framebuffers */ + oldDrawFb = ctx->DrawBuffer; + oldReadFb = ctx->ReadBuffer; + + /* check if really changing bindings */ + if (oldDrawFb == newDrawFb) + bindDrawBuf = GL_FALSE; + if (oldReadFb == newReadFb) + bindReadBuf = GL_FALSE; /* * OK, now bind the new Draw/Read framebuffers, if they're changing. + * + * We also check if we're beginning and/or ending render-to-texture. + * When a framebuffer with texture attachments is unbound, call + * ctx->Driver.FinishRenderTexture(). + * When a framebuffer with texture attachments is bound, call + * ctx->Driver.RenderTexture(). + * + * Note that if the ReadBuffer has texture attachments we don't consider + * that a render-to-texture case. */ - if (bindReadBuf) { - if (ctx->ReadBuffer == newFbread) - bindReadBuf = GL_FALSE; /* no change */ - else - _mesa_reference_framebuffer(&ctx->ReadBuffer, newFbread); + FLUSH_VERTICES(ctx, _NEW_BUFFERS); + + /* check if old readbuffer was render-to-texture */ + check_end_texture_render(ctx, oldReadFb); + + _mesa_reference_framebuffer(&ctx->ReadBuffer, newReadFb); } if (bindDrawBuf) { - /* check if old FB had any texture attachments */ - if (ctx->DrawBuffer->Name != 0) { - check_end_texture_render(ctx, ctx->DrawBuffer); - } + FLUSH_VERTICES(ctx, _NEW_BUFFERS); - if (ctx->DrawBuffer == newFb) - bindDrawBuf = GL_FALSE; /* no change */ - else - _mesa_reference_framebuffer(&ctx->DrawBuffer, newFb); + /* check if old read/draw buffers were render-to-texture */ + if (!bindReadBuf) + check_end_texture_render(ctx, oldReadFb); - if (newFb->Name != 0) { - /* check if newly bound framebuffer has any texture attachments */ - check_begin_texture_render(ctx, newFb); - } + if (oldDrawFb != oldReadFb) + check_end_texture_render(ctx, oldDrawFb); + + /* check if newly bound framebuffer has any texture attachments */ + check_begin_texture_render(ctx, newDrawFb); + + _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb); } if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) { - ctx->Driver.BindFramebuffer(ctx, target, newFb, newFbread); + ctx->Driver.BindFramebuffer(ctx, target, newDrawFb, newReadFb); } } @@ -1292,12 +1343,7 @@ _mesa_DeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers) GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END(ctx); - FLUSH_CURRENT(ctx, _NEW_BUFFERS); - /* The above doesn't fully flush the drivers in the way that a - * glFlush does, but that is required here: - */ - if (ctx->Driver.Flush) - ctx->Driver.Flush(ctx); + FLUSH_VERTICES(ctx, _NEW_BUFFERS); for (i = 0; i < n; i++) { if (framebuffers[i] > 0) { @@ -1307,15 +1353,26 @@ _mesa_DeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers) ASSERT(fb == &DummyFramebuffer || fb->Name == framebuffers[i]); /* check if deleting currently bound framebuffer object */ - if (fb == ctx->DrawBuffer) { - /* bind default */ - ASSERT(fb->RefCount >= 2); - _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); + if (ctx->Extensions.EXT_framebuffer_blit) { + /* separate draw/read binding points */ + if (fb == ctx->DrawBuffer) { + /* bind default */ + ASSERT(fb->RefCount >= 2); + _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); + } + if (fb == ctx->ReadBuffer) { + /* bind default */ + ASSERT(fb->RefCount >= 2); + _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); + } } - if (fb == ctx->ReadBuffer) { - /* bind default */ - ASSERT(fb->RefCount >= 2); - _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); + else { + /* only one binding point for read/draw buffers */ + if (fb == ctx->DrawBuffer || fb == ctx->ReadBuffer) { + /* bind default */ + ASSERT(fb->RefCount >= 2); + _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + } } /* remove from hash table immediately, to free the ID */ @@ -1402,7 +1459,7 @@ _mesa_CheckFramebufferStatusEXT(GLenum target) return GL_FRAMEBUFFER_COMPLETE_EXT; } - FLUSH_VERTICES(ctx, _NEW_BUFFERS); + /* No need to flush here */ if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) { _mesa_test_framebuffer_completeness(ctx, buffer); @@ -1518,24 +1575,7 @@ framebuffer_texture(GLcontext *ctx, const char *caller, GLenum target, return; } - if (texObj && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { - /* the texture format must be depth+stencil */ - const struct gl_texture_image *texImg; - texImg = texObj->Image[0][texObj->BaseLevel]; - if (!texImg || texImg->_BaseFormat != GL_DEPTH_STENCIL) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "glFramebufferTexture%sEXT(texture is not" - " DEPTH_STENCIL format)", caller); - return; - } - } - - FLUSH_CURRENT(ctx, _NEW_BUFFERS); - /* The above doesn't fully flush the drivers in the way that a - * glFlush does, but that is required here: - */ - if (ctx->Driver.Flush) - ctx->Driver.Flush(ctx); + FLUSH_VERTICES(ctx, _NEW_BUFFERS); _glthread_LOCK_MUTEX(fb->Mutex); if (texObj) { @@ -1683,7 +1723,8 @@ _mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment, att = _mesa_get_attachment(ctx, fb, attachment); if (att == NULL) { _mesa_error(ctx, GL_INVALID_ENUM, - "glFramebufferRenderbufferEXT(attachment)"); + "glFramebufferRenderbufferEXT(invalid attachment %s)", + _mesa_lookup_enum_by_nr(attachment)); return; } @@ -1691,7 +1732,8 @@ _mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment, rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); if (!rb) { _mesa_error(ctx, GL_INVALID_OPERATION, - "glFramebufferRenderbufferEXT(renderbuffer)"); + "glFramebufferRenderbufferEXT(non-existant" + " renderbuffer %u)", renderbuffer); return; } } @@ -1702,7 +1744,9 @@ _mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment, if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { /* make sure the renderbuffer is a depth/stencil format */ - if (rb->_BaseFormat != GL_DEPTH_STENCIL) { + const GLenum baseFormat = + _mesa_get_format_base_format(att->Renderbuffer->Format); + if (baseFormat != GL_DEPTH_STENCIL) { _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbufferEXT(renderbuffer" " is not DEPTH_STENCIL format)"); @@ -1711,12 +1755,7 @@ _mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment, } - FLUSH_CURRENT(ctx, _NEW_BUFFERS); - /* The above doesn't fully flush the drivers in the way that a - * glFlush does, but that is required here: - */ - if (ctx->Driver.Flush) - ctx->Driver.Flush(ctx); + FLUSH_VERTICES(ctx, _NEW_BUFFERS); assert(ctx->Driver.FramebufferRenderbuffer); ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb); @@ -1792,12 +1831,7 @@ _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, } } - FLUSH_CURRENT(ctx, _NEW_BUFFERS); - /* The above doesn't fully flush the drivers in the way that a - * glFlush does, but that is required here: - */ - if (ctx->Driver.Flush) - ctx->Driver.Flush(ctx); + /* No need to flush here */ switch (pname) { case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT: @@ -1858,7 +1892,7 @@ _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, "glGetFramebufferAttachmentParameterivEXT(pname)"); } else { - *params = att->Renderbuffer->ColorEncoding; + *params = _mesa_get_format_color_encoding(att->Renderbuffer->Format); } return; case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: @@ -1868,61 +1902,44 @@ _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, return; } else { - *params = att->Renderbuffer->ComponentType; + gl_format format = att->Renderbuffer->Format; + if (format == MESA_FORMAT_CI8 || format == MESA_FORMAT_S8) { + /* special cases */ + *params = GL_INDEX; + } + else { + *params = _mesa_get_format_datatype(format); + } } return; case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: - if (!ctx->Extensions.ARB_framebuffer_object) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glGetFramebufferAttachmentParameterivEXT(pname)"); - } - else { - *params = att->Renderbuffer->RedBits; - } - return; case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: - if (!ctx->Extensions.ARB_framebuffer_object) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glGetFramebufferAttachmentParameterivEXT(pname)"); - } - else { - *params = att->Renderbuffer->GreenBits; - } - return; case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: - if (!ctx->Extensions.ARB_framebuffer_object) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glGetFramebufferAttachmentParameterivEXT(pname)"); - } - else { - *params = att->Renderbuffer->BlueBits; - } - return; case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: - if (!ctx->Extensions.ARB_framebuffer_object) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glGetFramebufferAttachmentParameterivEXT(pname)"); - } - else { - *params = att->Renderbuffer->AlphaBits; - } - return; case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: + case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: if (!ctx->Extensions.ARB_framebuffer_object) { _mesa_error(ctx, GL_INVALID_ENUM, "glGetFramebufferAttachmentParameterivEXT(pname)"); } - else { - *params = att->Renderbuffer->DepthBits; + else if (att->Texture) { + const struct gl_texture_image *texImage = + _mesa_select_tex_image(ctx, att->Texture, att->Texture->Target, + att->TextureLevel); + if (texImage) { + *params = get_component_bits(pname, texImage->_BaseFormat, + texImage->TexFormat); + } + else { + *params = 0; + } } - return; - case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: - if (!ctx->Extensions.ARB_framebuffer_object) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glGetFramebufferAttachmentParameterivEXT(pname)"); + else if (att->Renderbuffer) { + *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat, + att->Renderbuffer->Format); } else { - *params = att->Renderbuffer->StencilBits; + *params = 0; } return; default: @@ -1936,7 +1953,6 @@ _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, void GLAPIENTRY _mesa_GenerateMipmapEXT(GLenum target) { - struct gl_texture_unit *texUnit; struct gl_texture_object *texObj; GET_CURRENT_CONTEXT(ctx); @@ -1955,8 +1971,12 @@ _mesa_GenerateMipmapEXT(GLenum target) return; } - texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; - texObj = _mesa_select_tex_object(ctx, texUnit, target); + texObj = _mesa_get_current_tex_object(ctx, target); + + if (texObj->BaseLevel >= texObj->MaxLevel) { + /* nothing to do */ + return; + } _mesa_lock_texture(ctx, texObj); if (target == GL_TEXTURE_CUBE_MAP) { @@ -1974,6 +1994,20 @@ _mesa_GenerateMipmapEXT(GLenum target) #if FEATURE_EXT_framebuffer_blit + +static const struct gl_renderbuffer_attachment * +find_attachment(const struct gl_framebuffer *fb, const struct gl_renderbuffer *rb) +{ + GLuint i; + for (i = 0; i < Elements(fb->Attachment); i++) { + if (fb->Attachment[i].Renderbuffer == rb) + return &fb->Attachment[i]; + } + return NULL; +} + + + /** * Blit rectangular region, optionally from one framebuffer to another. * @@ -2049,7 +2083,8 @@ _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, struct gl_renderbuffer *drawRb = drawFb->_StencilBuffer; if (!readRb || !drawRb || - readRb->StencilBits != drawRb->StencilBits) { + _mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS) != + _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT(stencil buffer size mismatch"); return; @@ -2061,7 +2096,8 @@ _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, struct gl_renderbuffer *drawRb = drawFb->_DepthBuffer; if (!readRb || !drawRb || - readRb->DepthBits != drawRb->DepthBits) { + _mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) != + _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT(depth buffer size mismatch"); return; @@ -2089,7 +2125,7 @@ _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, /* color formats must match */ if (colorReadRb && colorDrawRb && - colorReadRb->_ActualFormat != colorDrawRb->_ActualFormat) { + colorReadRb->Format != colorDrawRb->Format) { _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT(bad src/dst multisample pixel formats"); return; @@ -2101,6 +2137,44 @@ _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, return; } + /* Debug code */ + if (DEBUG_BLIT) { + _mesa_printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d," + " 0x%x, 0x%x)\n", + srcX0, srcY0, srcX1, srcY1, + dstX0, dstY0, dstX1, dstY1, + mask, filter); + if (colorReadRb) { + const struct gl_renderbuffer_attachment *att; + + att = find_attachment(readFb, colorReadRb); + _mesa_printf(" Src FBO %u RB %u (%dx%d) ", + readFb->Name, colorReadRb->Name, + colorReadRb->Width, colorReadRb->Height); + if (att && att->Texture) { + _mesa_printf("Tex %u tgt 0x%x level %u face %u", + att->Texture->Name, + att->Texture->Target, + att->TextureLevel, + att->CubeMapFace); + } + _mesa_printf("\n"); + + att = find_attachment(drawFb, colorDrawRb); + _mesa_printf(" Dst FBO %u RB %u (%dx%d) ", + drawFb->Name, colorDrawRb->Name, + colorDrawRb->Width, colorDrawRb->Height); + if (att && att->Texture) { + _mesa_printf("Tex %u tgt 0x%x level %u face %u", + att->Texture->Name, + att->Texture->Target, + att->TextureLevel, + att->CubeMapFace); + } + _mesa_printf("\n"); + } + } + ASSERT(ctx->Driver.BlitFramebuffer); ctx->Driver.BlitFramebuffer(ctx, srcX0, srcY0, srcX1, srcY1,