2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #include "renderbuffer.h"
36 * Initialize the fields of a gl_renderbuffer to default values.
39 _mesa_init_renderbuffer(struct gl_renderbuffer
*rb
, GLuint name
)
41 _glthread_INIT_MUTEX(rb
->Mutex
);
46 rb
->Delete
= _mesa_delete_renderbuffer
;
48 /* The rest of these should be set later by the caller of this function or
49 * the AllocStorage method:
51 rb
->AllocStorage
= NULL
;
55 rb
->InternalFormat
= GL_RGBA
;
56 rb
->Format
= MESA_FORMAT_NONE
;
58 rb
->DataType
= GL_NONE
;
61 /* Point back to ourself so that we don't have to check for Wrapped==NULL
62 * all over the drivers.
69 * Allocate a new gl_renderbuffer object. This can be used for user-created
70 * renderbuffers or window-system renderbuffers.
72 struct gl_renderbuffer
*
73 _mesa_new_renderbuffer(struct gl_context
*ctx
, GLuint name
)
75 struct gl_renderbuffer
*rb
= CALLOC_STRUCT(gl_renderbuffer
);
77 _mesa_init_renderbuffer(rb
, name
);
84 * Delete a gl_framebuffer.
85 * This is the default function for renderbuffer->Delete().
88 _mesa_delete_renderbuffer(struct gl_renderbuffer
*rb
)
98 * Attach a renderbuffer to a framebuffer.
99 * \param bufferName one of the BUFFER_x tokens
102 _mesa_add_renderbuffer(struct gl_framebuffer
*fb
,
103 gl_buffer_index bufferName
, struct gl_renderbuffer
*rb
)
107 assert(bufferName
< BUFFER_COUNT
);
109 /* There should be no previous renderbuffer on this attachment point,
110 * with the exception of depth/stencil since the same renderbuffer may
113 assert(bufferName
== BUFFER_DEPTH
||
114 bufferName
== BUFFER_STENCIL
||
115 fb
->Attachment
[bufferName
].Renderbuffer
== NULL
);
117 /* winsys vs. user-created buffer cross check */
118 if (_mesa_is_user_fbo(fb
)) {
125 fb
->Attachment
[bufferName
].Type
= GL_RENDERBUFFER_EXT
;
126 fb
->Attachment
[bufferName
].Complete
= GL_TRUE
;
127 _mesa_reference_renderbuffer(&fb
->Attachment
[bufferName
].Renderbuffer
, rb
);
132 * Remove the named renderbuffer from the given framebuffer.
133 * \param bufferName one of the BUFFER_x tokens
136 _mesa_remove_renderbuffer(struct gl_framebuffer
*fb
,
137 gl_buffer_index bufferName
)
139 assert(bufferName
< BUFFER_COUNT
);
140 _mesa_reference_renderbuffer(&fb
->Attachment
[bufferName
].Renderbuffer
,
146 * Set *ptr to point to rb. If *ptr points to another renderbuffer,
147 * dereference that buffer first. The new renderbuffer's refcount will
148 * be incremented. The old renderbuffer's refcount will be decremented.
149 * This is normally only called from the _mesa_reference_renderbuffer() macro
150 * when there's a real pointer change.
153 _mesa_reference_renderbuffer_(struct gl_renderbuffer
**ptr
,
154 struct gl_renderbuffer
*rb
)
157 /* Unreference the old renderbuffer */
158 GLboolean deleteFlag
= GL_FALSE
;
159 struct gl_renderbuffer
*oldRb
= *ptr
;
161 _glthread_LOCK_MUTEX(oldRb
->Mutex
);
162 ASSERT(oldRb
->RefCount
> 0);
164 /*printf("RB DECR %p (%d) to %d\n", (void*) oldRb, oldRb->Name, oldRb->RefCount);*/
165 deleteFlag
= (oldRb
->RefCount
== 0);
166 _glthread_UNLOCK_MUTEX(oldRb
->Mutex
);
169 oldRb
->Delete(oldRb
);
177 /* reference new renderbuffer */
178 _glthread_LOCK_MUTEX(rb
->Mutex
);
180 /*printf("RB INCR %p (%d) to %d\n", (void*) rb, rb->Name, rb->RefCount);*/
181 _glthread_UNLOCK_MUTEX(rb
->Mutex
);