/*
* Mesa 3-D graphics library
- * Version: 6.5
*
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
* 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.
*/
#include "renderbuffer.h"
-/**
- * Default GetPointer routine. Always return NULL to indicate that
- * direct buffer access is not supported.
- */
-static void *
-nop_get_pointer(struct gl_context *ctx, struct gl_renderbuffer *rb, GLint x, GLint y)
-{
- return NULL;
-}
-
-
/**
* Initialize the fields of a gl_renderbuffer to default values.
*/
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
rb->Width = 0;
rb->Height = 0;
- rb->InternalFormat = GL_RGBA;
- rb->Format = MESA_FORMAT_NONE;
-
- rb->DataType = GL_NONE;
- rb->Data = NULL;
-
- /* Point back to ourself so that we don't have to check for Wrapped==NULL
- * all over the drivers.
+ 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.
*/
- rb->Wrapped = rb;
-
- rb->GetPointer = nop_get_pointer;
- rb->GetRow = NULL;
- rb->GetValues = NULL;
- rb->PutRow = NULL;
- rb->PutRowRGB = NULL;
- rb->PutValues = NULL;
+ if (ctx && _mesa_is_gles(ctx)) {
+ rb->InternalFormat = GL_RGBA4;
+ } else {
+ rb->InternalFormat = GL_RGBA;
+ }
+
+ rb->Format = MESA_FORMAT_NONE;
}
/**
* Delete a gl_framebuffer.
* This is the default function for renderbuffer->Delete().
+ * Drivers which subclass gl_renderbuffer should probably implement their
+ * own delete function. But the driver might also call this function to
+ * free the object in the end.
*/
void
-_mesa_delete_renderbuffer(struct gl_renderbuffer *rb)
+_mesa_delete_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
{
- if (rb->Data) {
- free(rb->Data);
- }
+ 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);
fb->Attachment[bufferName].Renderbuffer == NULL);
/* winsys vs. user-created buffer cross check */
- if (fb->Name) {
+ if (_mesa_is_user_fbo(fb)) {
assert(rb->Name);
}
else {
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);
}
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) {
- oldRb->Delete(oldRb);
+ GET_CURRENT_CONTEXT(ctx);
+ oldRb->Delete(ctx, oldRb);
}
*ptr = NULL;
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;
}
}