#include "fbobject.h"
#include "feedback.h"
#include "fog.h"
+#include "framebuffer.h"
#include "get.h"
#include "glthread.h"
#include "glapioffsets.h"
_mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
GLframebuffer *readBuffer )
{
+ GET_CURRENT_CONTEXT(oldCtx);
+
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(newCtx, "_mesa_make_current()\n");
_glapi_set_context((void *) newCtx);
ASSERT(_mesa_get_current_context() == newCtx);
+ if (oldCtx) {
+ if (oldCtx->WinSysDrawBuffer) {
+ _mesa_dereference_framebuffer(&oldCtx->WinSysDrawBuffer);
+ }
+ if (oldCtx->WinSysReadBuffer) {
+ _mesa_dereference_framebuffer(&oldCtx->WinSysReadBuffer);
+ }
+ }
+
if (!newCtx) {
_glapi_set_dispatch(NULL); /* none current */
}
ASSERT(readBuffer->Name == 0);
newCtx->WinSysDrawBuffer = drawBuffer;
newCtx->WinSysReadBuffer = readBuffer;
+ drawBuffer->RefCount++;
+ readBuffer->RefCount++;
/*
* Only set the context's Draw/ReadBuffer fields if they're NULL
_glthread_INIT_MUTEX(fb->Mutex);
+ fb->RefCount = 1;
+
/* save the visual */
fb->Visual = *visual;
_mesa_destroy_framebuffer(struct gl_framebuffer *fb)
{
if (fb) {
- _glthread_DESTROY_MUTEX(fb->Mutex);
_mesa_free_framebuffer_data(fb);
_mesa_free(fb);
}
assert(fb);
+ _glthread_DESTROY_MUTEX(fb->Mutex);
+
for (i = 0; i < BUFFER_COUNT; i++) {
struct gl_renderbuffer_attachment *att = &fb->Attachment[i];
if (att->Renderbuffer) {
GLbitfield bufferMask = fb->_ColorDrawBufferMask[output];
GLuint count = 0;
GLuint i;
- /* We need the inner loop here because glDrawBuffer(GL_FRONT_AND_BACK)
- * can specify writing to two or four color buffers (for example).
- */
- for (i = 0; bufferMask && i < BUFFER_COUNT; i++) {
- const GLuint bufferBit = 1 << i;
- if (bufferBit & bufferMask) {
- struct gl_renderbuffer *rb = fb->Attachment[i].Renderbuffer;
- if (rb) {
- fb->_ColorDrawBuffers[output][count] = rb;
- count++;
- }
- else {
- /*_mesa_warning(ctx, "DrawBuffer names a missing buffer!\n");*/
+ if (!fb->DeletePending) {
+ /* We need the inner loop here because glDrawBuffer(GL_FRONT_AND_BACK)
+ * can specify writing to two or four color buffers (for example).
+ */
+ for (i = 0; bufferMask && i < BUFFER_COUNT; i++) {
+ const GLuint bufferBit = 1 << i;
+ if (bufferBit & bufferMask) {
+ struct gl_renderbuffer *rb = fb->Attachment[i].Renderbuffer;
+ if (rb) {
+ fb->_ColorDrawBuffers[output][count] = rb;
+ count++;
+ }
+ else {
+ /*
+ _mesa_warning(ctx, "DrawBuffer names a missing buffer!\n");
+ */
+ }
+ bufferMask &= ~bufferBit;
}
- bufferMask &= ~bufferBit;
}
}
fb->_NumColorDrawBuffers[output] = count;
update_color_read_buffer(GLcontext *ctx, struct gl_framebuffer *fb)
{
(void) ctx;
- if (fb->_ColorReadBufferIndex == -1) {
+ if (fb->_ColorReadBufferIndex == -1 || fb->DeletePending) {
fb->_ColorReadBuffer = NULL; /* legal! */
}
else {