X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Frenderbuffer.c;h=0e017125ac08142e3391a7efa3bbc4bfa83e486e;hb=a96e946d25d4518d1c73c5d9d0f3d147f42bc416;hp=2f284432994b20f5b191eb1c9cd7eacc10af9374;hpb=c73245882c7ff1277b190b97f093f7b423a22f10;p=mesa.git diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c index 2f284432994..0e017125ac0 100644 --- a/src/mesa/main/renderbuffer.c +++ b/src/mesa/main/renderbuffer.c @@ -1,6 +1,5 @@ /* * Mesa 3-D graphics library - * Version: 6.5 * * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. * @@ -17,9 +16,10 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. */ @@ -38,11 +38,13 @@ void _mesa_init_renderbuffer(struct gl_renderbuffer *rb, GLuint name) { - _glthread_INIT_MUTEX(rb->Mutex); + GET_CURRENT_CONTEXT(ctx); + + simple_mtx_init(&rb->Mutex, mtx_plain); rb->ClassID = 0; rb->Name = name; - rb->RefCount = 0; + rb->RefCount = 1; rb->Delete = _mesa_delete_renderbuffer; /* The rest of these should be set later by the caller of this function or @@ -52,7 +54,24 @@ _mesa_init_renderbuffer(struct gl_renderbuffer *rb, GLuint name) rb->Width = 0; rb->Height = 0; - rb->InternalFormat = GL_RGBA; + rb->Depth = 0; + + /* In GL 3, the initial format is GL_RGBA according to Table 6.26 + * on page 302 of the GL 3.3 spec. + * + * In GLES 3, the initial format is GL_RGBA4 according to Table 6.15 + * on page 258 of the GLES 3.0.4 spec. + * + * If the context is current, set the initial format based on the + * specs. If the context is not current, we cannot determine the + * API, so default to GL_RGBA. + */ + if (ctx && _mesa_is_gles(ctx)) { + rb->InternalFormat = GL_RGBA4; + } else { + rb->InternalFormat = GL_RGBA; + } + rb->Format = MESA_FORMAT_NONE; } @@ -82,18 +101,15 @@ _mesa_new_renderbuffer(struct gl_context *ctx, GLuint name) void _mesa_delete_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb) { - _glthread_DESTROY_MUTEX(rb->Mutex); + simple_mtx_destroy(&rb->Mutex); + free(rb->Label); free(rb); } - -/** - * Attach a renderbuffer to a framebuffer. - * \param bufferName one of the BUFFER_x tokens - */ -void -_mesa_add_renderbuffer(struct gl_framebuffer *fb, - gl_buffer_index bufferName, struct gl_renderbuffer *rb) +static void +validate_and_init_renderbuffer_attachment(struct gl_framebuffer *fb, + gl_buffer_index bufferName, + struct gl_renderbuffer *rb) { assert(fb); assert(rb); @@ -117,6 +133,40 @@ _mesa_add_renderbuffer(struct gl_framebuffer *fb, fb->Attachment[bufferName].Type = GL_RENDERBUFFER_EXT; fb->Attachment[bufferName].Complete = GL_TRUE; +} + + +/** + * Attach a renderbuffer to a framebuffer. + * \param bufferName one of the BUFFER_x tokens + * + * This function avoids adding a reference and is therefore intended to be + * used with a freshly created renderbuffer. + */ +void +_mesa_attach_and_own_rb(struct gl_framebuffer *fb, + gl_buffer_index bufferName, + struct gl_renderbuffer *rb) +{ + assert(rb->RefCount == 1); + + validate_and_init_renderbuffer_attachment(fb, bufferName, rb); + + _mesa_reference_renderbuffer(&fb->Attachment[bufferName].Renderbuffer, + NULL); + fb->Attachment[bufferName].Renderbuffer = rb; +} + +/** + * Attach a renderbuffer to a framebuffer. + * \param bufferName one of the BUFFER_x tokens + */ +void +_mesa_attach_and_reference_rb(struct gl_framebuffer *fb, + gl_buffer_index bufferName, + struct gl_renderbuffer *rb) +{ + validate_and_init_renderbuffer_attachment(fb, bufferName, rb); _mesa_reference_renderbuffer(&fb->Attachment[bufferName].Renderbuffer, rb); } @@ -151,19 +201,15 @@ _mesa_reference_renderbuffer_(struct gl_renderbuffer **ptr, GLboolean deleteFlag = GL_FALSE; struct gl_renderbuffer *oldRb = *ptr; - _glthread_LOCK_MUTEX(oldRb->Mutex); - ASSERT(oldRb->RefCount > 0); + simple_mtx_lock(&oldRb->Mutex); + assert(oldRb->RefCount > 0); oldRb->RefCount--; - /*printf("RB DECR %p (%d) to %d\n", (void*) oldRb, oldRb->Name, oldRb->RefCount);*/ deleteFlag = (oldRb->RefCount == 0); - _glthread_UNLOCK_MUTEX(oldRb->Mutex); + simple_mtx_unlock(&oldRb->Mutex); if (deleteFlag) { GET_CURRENT_CONTEXT(ctx); - if (ctx) - oldRb->Delete(ctx, oldRb); - else - _mesa_problem(NULL, "Unable to delete renderbuffer, no context"); + oldRb->Delete(ctx, oldRb); } *ptr = NULL; @@ -172,10 +218,9 @@ _mesa_reference_renderbuffer_(struct gl_renderbuffer **ptr, if (rb) { /* reference new renderbuffer */ - _glthread_LOCK_MUTEX(rb->Mutex); + simple_mtx_lock(&rb->Mutex); rb->RefCount++; - /*printf("RB INCR %p (%d) to %d\n", (void*) rb, rb->Name, rb->RefCount);*/ - _glthread_UNLOCK_MUTEX(rb->Mutex); + simple_mtx_unlock(&rb->Mutex); *ptr = rb; } }