-/**
- * \file buffers.c
- * Frame buffer management.
- */
-
/*
* Mesa 3-D graphics library
- * Version: 6.5
+ * Version: 6.5.2
*
- * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
*/
+/**
+ * \file buffers.c
+ * General framebuffer-related functions, like glClear, glScissor, etc.
+ */
+
+
+
#include "glheader.h"
#include "buffers.h"
#include "colormac.h"
_mesa_update_state( ctx ); /* update _Xmin, etc */
}
+ if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+ "glClear(incomplete framebuffer)");
+ return;
+ }
+
if (ctx->RenderMode == GL_RENDER) {
- const GLint x = ctx->DrawBuffer->_Xmin;
- const GLint y = ctx->DrawBuffer->_Ymin;
- const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
- const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
GLbitfield bufferMask;
/* don't clear depth buffer if depth writing disabled */
}
ASSERT(ctx->Driver.Clear);
- ctx->Driver.Clear( ctx, bufferMask, (GLboolean) !ctx->Scissor.Enabled,
- x, y, width, height );
+ ctx->Driver.Clear(ctx, bufferMask);
}
}
* framebuffers we look at the framebuffer's visual. But for user-
* create framebuffers we look at the number of supported color attachments.
*/
-static GLuint
+static GLbitfield
supported_buffer_bitmask(const GLcontext *ctx, GLuint framebufferID)
{
- GLuint mask = 0x0;
- GLint i;
+ GLbitfield mask = 0x0;
if (framebufferID > 0) {
/* A user-created renderbuffer */
+ GLuint i;
ASSERT(ctx->Extensions.EXT_framebuffer_object);
for (i = 0; i < ctx->Const.MaxColorAttachments; i++) {
mask |= (BUFFER_BIT_COLOR0 << i);
}
else {
/* A window system renderbuffer */
+ GLint i;
mask = BUFFER_BIT_FRONT_LEFT; /* always have this */
if (ctx->Visual.stereoMode) {
mask |= BUFFER_BIT_FRONT_RIGHT;
* Given a GLenum naming one or more color buffers (such as
* GL_FRONT_AND_BACK), return the corresponding bitmask of BUFFER_BIT_* flags.
*/
-static GLuint
+static GLbitfield
draw_buffer_enum_to_bitmask(GLenum buffer)
{
switch (buffer) {
/**
* Helper routine used by glReadBuffer.
- * Given a GLenum naming (a) color buffer(s), return the corresponding
- * bitmask of DD_* flags.
+ * Given a GLenum naming a color buffer, return the index of the corresponding
+ * renderbuffer (a BUFFER_* value).
+ * return -1 for an invalid buffer.
*/
-static GLuint
-read_buffer_enum_to_bitmask(GLenum buffer)
+static GLint
+read_buffer_enum_to_index(GLenum buffer)
{
switch (buffer) {
case GL_FRONT:
- return BUFFER_BIT_FRONT_LEFT;
+ return BUFFER_FRONT_LEFT;
case GL_BACK:
- return BUFFER_BIT_BACK_LEFT;
+ return BUFFER_BACK_LEFT;
case GL_RIGHT:
- return BUFFER_BIT_FRONT_RIGHT;
+ return BUFFER_FRONT_RIGHT;
case GL_FRONT_RIGHT:
- return BUFFER_BIT_FRONT_RIGHT;
+ return BUFFER_FRONT_RIGHT;
case GL_BACK_RIGHT:
- return BUFFER_BIT_BACK_RIGHT;
+ return BUFFER_BACK_RIGHT;
case GL_BACK_LEFT:
- return BUFFER_BIT_BACK_LEFT;
+ return BUFFER_BACK_LEFT;
case GL_LEFT:
- return BUFFER_BIT_FRONT_LEFT;
+ return BUFFER_FRONT_LEFT;
case GL_FRONT_LEFT:
- return BUFFER_BIT_FRONT_LEFT;
+ return BUFFER_FRONT_LEFT;
case GL_AUX0:
- return BUFFER_BIT_AUX0;
+ return BUFFER_AUX0;
case GL_AUX1:
- return BUFFER_BIT_AUX1;
+ return BUFFER_AUX1;
case GL_AUX2:
- return BUFFER_BIT_AUX2;
+ return BUFFER_AUX2;
case GL_AUX3:
- return BUFFER_BIT_AUX3;
+ return BUFFER_AUX3;
case GL_COLOR_ATTACHMENT0_EXT:
- return BUFFER_BIT_COLOR0;
+ return BUFFER_COLOR0;
case GL_COLOR_ATTACHMENT1_EXT:
- return BUFFER_BIT_COLOR1;
+ return BUFFER_COLOR1;
case GL_COLOR_ATTACHMENT2_EXT:
- return BUFFER_BIT_COLOR2;
+ return BUFFER_COLOR2;
case GL_COLOR_ATTACHMENT3_EXT:
- return BUFFER_BIT_COLOR3;
+ return BUFFER_COLOR3;
default:
/* error */
- return BAD_MASK;
+ return -1;
}
}
_mesa_DrawBuffer(GLenum buffer)
{
GLuint bufferID;
- GLuint destMask;
+ GLbitfield destMask;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex... */
destMask = 0x0;
}
else {
- const GLuint supportedMask = supported_buffer_bitmask(ctx, bufferID);
+ const GLbitfield supportedMask = supported_buffer_bitmask(ctx, bufferID);
destMask = draw_buffer_enum_to_bitmask(buffer);
if (destMask == BAD_MASK) {
/* totally bogus buffer */
_mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers)
{
GLint output;
- GLuint usedBufferMask, supportedMask;
GLuint bufferID;
- GLuint destMask[MAX_DRAW_BUFFERS];
+ GLbitfield usedBufferMask, supportedMask;
+ GLbitfield destMask[MAX_DRAW_BUFFERS];
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
* (like BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT).
*/
static void
-set_color_output(GLcontext *ctx, GLuint output, GLenum buffer, GLuint destMask)
+set_color_output(GLcontext *ctx, GLuint output, GLenum buffer,
+ GLbitfield destMask)
{
struct gl_framebuffer *fb = ctx->DrawBuffer;
ASSERT(output < ctx->Const.MaxDrawBuffers);
+ /* Set per-FBO state */
fb->ColorDrawBuffer[output] = buffer;
fb->_ColorDrawBufferMask[output] = destMask;
-
- if (fb->Name == 0) {
- /* Set traditional state var */
- ctx->Color.DrawBuffer[output] = buffer;
- }
-
/* not really needed, will be set later */
fb->_NumColorDrawBuffers[output] = 0;
+
+ /* Set traditional state var */
+ ctx->Color.DrawBuffer[output] = buffer;
}
* BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT).
*/
void
-_mesa_drawbuffers(GLcontext *ctx, GLsizei n, const GLenum *buffers,
- const GLuint *destMask)
+_mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers,
+ const GLbitfield *destMask)
{
- GLuint mask[MAX_DRAW_BUFFERS];
- GLint output;
+ GLbitfield mask[MAX_DRAW_BUFFERS];
+ GLuint output;
if (!destMask) {
/* compute destMask values now */
const GLuint bufferID = ctx->DrawBuffer->Name;
- const GLuint supportedMask = supported_buffer_bitmask(ctx, bufferID);
+ const GLbitfield supportedMask = supported_buffer_bitmask(ctx, bufferID);
for (output = 0; output < n; output++) {
mask[output] = draw_buffer_enum_to_bitmask(buffers[output]);
ASSERT(mask[output] != BAD_MASK);
_mesa_ReadBuffer(GLenum buffer)
{
struct gl_framebuffer *fb;
- GLuint srcMask, supportedMask;
+ GLbitfield supportedMask;
+ GLint srcBuffer;
GLuint bufferID;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
_mesa_debug(ctx, "glReadBuffer %s\n", _mesa_lookup_enum_by_nr(buffer));
if (bufferID > 0 && buffer == GL_NONE) {
- /* legal! */
- srcMask = 0x0;
+ /* This is legal for user-created framebuffer objects */
+ srcBuffer = -1;
}
else {
- /* general case */
- srcMask = read_buffer_enum_to_bitmask(buffer);
- if (srcMask == BAD_MASK) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glReadBuffer(buffer)");
+ /* general case / window-system framebuffer */
+ srcBuffer = read_buffer_enum_to_index(buffer);
+ if (srcBuffer == -1) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glReadBuffer(buffer=0x%x)", buffer);
return;
}
supportedMask = supported_buffer_bitmask(ctx, bufferID);
- if ((srcMask & supportedMask) == 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glReadBuffer(buffer)");
+ if (((1 << srcBuffer) & supportedMask) == 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glReadBuffer(buffer=0x%x)", buffer);
return;
}
}
ctx->Pixel.ReadBuffer = buffer;
}
fb->ColorReadBuffer = buffer;
- fb->_ColorReadBufferMask = srcMask;
+ fb->_ColorReadBufferIndex = srcBuffer;
ctx->NewState |= _NEW_PIXEL;
#if _HAVE_FULL_GL
/**
+ * XXX THIS IS OBSOLETE - drivers should take care of detecting window
+ * size changes and act accordingly, likely calling _mesa_resize_framebuffer().
+ *
* GL_MESA_resize_buffers extension.
*
* When this function is called, we'll ask the window system how large
* ResizeBuffers function. The driver will then resize its color buffers
* as needed, and maybe call the swrast's routine for reallocating
* swrast-managed depth/stencil/accum/etc buffers.
- * \note This function may be called from within Mesa or called by the
- * user directly (see the GL_MESA_resize_buffers extension).
+ * \note This function should only be called through the GL API, not
+ * from device drivers (as was done in the past).
*/
-void GLAPIENTRY
-_mesa_ResizeBuffersMESA( void )
-{
- GET_CURRENT_CONTEXT(ctx);
+void _mesa_resizebuffers( GLcontext *ctx )
+{
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx );
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(ctx, "glResizeBuffersMESA\n");
+ if (!ctx->Driver.GetBufferSize) {
+ return;
+ }
+
if (ctx->WinSysDrawBuffer) {
GLuint newWidth, newHeight;
GLframebuffer *buffer = ctx->WinSysDrawBuffer;
}
+/*
+ * XXX THIS IS OBSOLETE
+ */
+void GLAPIENTRY
+_mesa_ResizeBuffersMESA( void )
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (ctx->Extensions.MESA_resize_buffers)
+ _mesa_resizebuffers( ctx );
+}
+
+
/*
* XXX move somewhere else someday?
*/
* change flushes the vertices and notifies the driver via
* the dd_function_table::Scissor callback.
*/
-void GLAPIENTRY
-_mesa_Scissor( GLint x, GLint y, GLsizei width, GLsizei height )
+void
+_mesa_set_scissor(GLcontext *ctx,
+ GLint x, GLint y, GLsizei width, GLsizei height)
{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (width < 0 || height < 0) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glScissor" );
- return;
- }
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glScissor %d %d %d %d\n", x, y, width, height);
-
if (x == ctx->Scissor.X &&
y == ctx->Scissor.Y &&
width == ctx->Scissor.Width &&
}
+void GLAPIENTRY
+_mesa_Scissor( GLint x, GLint y, GLsizei width, GLsizei height )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (width < 0 || height < 0) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glScissor" );
+ return;
+ }
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glScissor %d %d %d %d\n", x, y, width, height);
+
+ _mesa_set_scissor(ctx, x, y, width, height);
+}
+
+
/**********************************************************************/
/** \name Initialization */