diff options
author | brianp <brianp> | 2002-11-25 19:56:26 +0000 |
---|---|---|
committer | brianp <brianp> | 2002-11-25 19:56:26 +0000 |
commit | 26abccdbf563c1626601f996995aa62baa590c86 (patch) | |
tree | 280398898ccc711a77f8dc1700c924c7ed6aa363 /xc/extras/Mesa/src/buffers.c | |
parent | 89e41d84ab6ff27e035dca8d9ef02c0ca692a4cb (diff) |
merge from mesa-4-1-branch (Mesa 5.0)
Diffstat (limited to 'xc/extras/Mesa/src/buffers.c')
-rw-r--r-- | xc/extras/Mesa/src/buffers.c | 227 |
1 files changed, 134 insertions, 93 deletions
diff --git a/xc/extras/Mesa/src/buffers.c b/xc/extras/Mesa/src/buffers.c index c5a459d91..a6713c880 100644 --- a/xc/extras/Mesa/src/buffers.c +++ b/xc/extras/Mesa/src/buffers.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 4.0.3 + * Version: 4.1 * * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. * @@ -24,10 +24,8 @@ */ -#ifdef PC_HEADER -#include "all.h" -#else #include "glheader.h" +#include "imports.h" #include "accum.h" #include "buffers.h" #include "colormac.h" @@ -35,11 +33,9 @@ #include "depth.h" #include "enums.h" #include "macros.h" -#include "mem.h" #include "stencil.h" #include "state.h" #include "mtypes.h" -#endif @@ -66,20 +62,20 @@ _mesa_ClearIndex( GLfloat c ) void _mesa_ClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ) { - GLchan tmp[4]; + GLfloat tmp[4]; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END(ctx); - UNCLAMPED_FLOAT_TO_CHAN(tmp[0], red); - UNCLAMPED_FLOAT_TO_CHAN(tmp[1], green); - UNCLAMPED_FLOAT_TO_CHAN(tmp[2], blue); - UNCLAMPED_FLOAT_TO_CHAN(tmp[3], alpha); + tmp[0] = CLAMP(red, 0.0F, 1.0F); + tmp[1] = CLAMP(green, 0.0F, 1.0F); + tmp[2] = CLAMP(blue, 0.0F, 1.0F); + tmp[3] = CLAMP(alpha, 0.0F, 1.0F); if (TEST_EQ_4V(tmp, ctx->Color.ClearColor)) - return; + return; /* no change */ FLUSH_VERTICES(ctx, _NEW_COLOR); - COPY_CHAN4(ctx->Color.ClearColor, tmp); + COPY_4V(ctx->Color.ClearColor, tmp); if (ctx->Visual.rgbMode && ctx->Driver.ClearColor) { /* it's OK to call glClearColor in CI mode but it should be a NOP */ @@ -96,7 +92,16 @@ _mesa_Clear( GLbitfield mask ) ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); if (MESA_VERBOSE & VERBOSE_API) - fprintf(stderr, "glClear 0x%x\n", mask); + _mesa_debug(ctx, "glClear 0x%x\n", mask); + + if (mask & ~(GL_COLOR_BUFFER_BIT | + GL_DEPTH_BUFFER_BIT | + GL_STENCIL_BUFFER_BIT | + GL_ACCUM_BUFFER_BIT)) { + /* invalid bit set */ + _mesa_error( ctx, GL_INVALID_VALUE, "glClear(mask)"); + return; + } if (ctx->NewState) { _mesa_update_state( ctx ); /* update _Xmin, etc */ @@ -111,14 +116,14 @@ _mesa_Clear( GLbitfield mask ) /* don't clear depth buffer if depth writing disabled */ if (!ctx->Depth.Mask) - CLEAR_BITS(mask, GL_DEPTH_BUFFER_BIT); + mask &= ~GL_DEPTH_BUFFER_BIT; /* Build bitmask to send to driver Clear function */ ddMask = mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_ACCUM_BUFFER_BIT); if (mask & GL_COLOR_BUFFER_BIT) { - ddMask |= ctx->Color.DrawDestMask; + ddMask |= ctx->Color._DrawDestMask; } ASSERT(ctx->Driver.Clear); @@ -134,51 +139,42 @@ _mesa_DrawBuffer( GLenum mode ) GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex... */ - if (MESA_VERBOSE & VERBOSE_API) - fprintf(stderr, "glDrawBuffer %s\n", _mesa_lookup_enum_by_nr(mode)); + _mesa_debug(ctx, "glDrawBuffer %s\n", _mesa_lookup_enum_by_nr(mode)); + /* + * Do error checking and compute the _DrawDestMask bitfield. + */ switch (mode) { - case GL_AUX0: - case GL_AUX1: - case GL_AUX2: - case GL_AUX3: - /* AUX buffers not implemented in Mesa at this time */ - _mesa_error( ctx, GL_INVALID_OPERATION, "glDrawBuffer" ); - return; case GL_RIGHT: if (!ctx->Visual.stereoMode) { _mesa_error( ctx, GL_INVALID_OPERATION, "glDrawBuffer" ); return;} if (ctx->Visual.doubleBufferMode) - ctx->Color.DrawDestMask = FRONT_RIGHT_BIT | BACK_RIGHT_BIT; + ctx->Color._DrawDestMask = FRONT_RIGHT_BIT | BACK_RIGHT_BIT; else - ctx->Color.DrawDestMask = FRONT_RIGHT_BIT; + ctx->Color._DrawDestMask = FRONT_RIGHT_BIT; break; case GL_FRONT_RIGHT: if (!ctx->Visual.stereoMode) { _mesa_error( ctx, GL_INVALID_OPERATION, "glDrawBuffer" ); return; } - ctx->Color.DrawDestMask = FRONT_RIGHT_BIT; + ctx->Color._DrawDestMask = FRONT_RIGHT_BIT; break; case GL_BACK_RIGHT: - if (!ctx->Visual.stereoMode) { - _mesa_error( ctx, GL_INVALID_OPERATION, "glDrawBuffer" ); - return; - } - if (!ctx->Visual.doubleBufferMode) { + if (!ctx->Visual.stereoMode || !ctx->Visual.doubleBufferMode) { _mesa_error( ctx, GL_INVALID_OPERATION, "glDrawBuffer" ); return; } - ctx->Color.DrawDestMask = BACK_RIGHT_BIT; + ctx->Color._DrawDestMask = BACK_RIGHT_BIT; break; case GL_BACK_LEFT: if (!ctx->Visual.doubleBufferMode) { _mesa_error( ctx, GL_INVALID_OPERATION, "glDrawBuffer" ); return; } - ctx->Color.DrawDestMask = BACK_LEFT_BIT; + ctx->Color._DrawDestMask = BACK_LEFT_BIT; break; case GL_FRONT_AND_BACK: if (!ctx->Visual.doubleBufferMode) { @@ -186,10 +182,10 @@ _mesa_DrawBuffer( GLenum mode ) return; } if (ctx->Visual.stereoMode) - ctx->Color.DrawDestMask = FRONT_LEFT_BIT | BACK_LEFT_BIT + ctx->Color._DrawDestMask = FRONT_LEFT_BIT | BACK_LEFT_BIT | FRONT_RIGHT_BIT | BACK_RIGHT_BIT; else - ctx->Color.DrawDestMask = FRONT_LEFT_BIT | BACK_LEFT_BIT; + ctx->Color._DrawDestMask = FRONT_LEFT_BIT | BACK_LEFT_BIT; break; case GL_BACK: if (!ctx->Visual.doubleBufferMode) { @@ -197,74 +193,81 @@ _mesa_DrawBuffer( GLenum mode ) return; } if (ctx->Visual.stereoMode) - ctx->Color.DrawDestMask = BACK_LEFT_BIT | BACK_RIGHT_BIT; + ctx->Color._DrawDestMask = BACK_LEFT_BIT | BACK_RIGHT_BIT; else - ctx->Color.DrawDestMask = BACK_LEFT_BIT; + ctx->Color._DrawDestMask = BACK_LEFT_BIT; break; case GL_LEFT: /* never an error */ if (ctx->Visual.doubleBufferMode) - ctx->Color.DrawDestMask = FRONT_LEFT_BIT | BACK_LEFT_BIT; + ctx->Color._DrawDestMask = FRONT_LEFT_BIT | BACK_LEFT_BIT; else - ctx->Color.DrawDestMask = FRONT_LEFT_BIT; + ctx->Color._DrawDestMask = FRONT_LEFT_BIT; break; case GL_FRONT_LEFT: /* never an error */ - ctx->Color.DrawDestMask = FRONT_LEFT_BIT; + ctx->Color._DrawDestMask = FRONT_LEFT_BIT; break; case GL_FRONT: /* never an error */ if (ctx->Visual.stereoMode) - ctx->Color.DrawDestMask = FRONT_LEFT_BIT | FRONT_RIGHT_BIT; + ctx->Color._DrawDestMask = FRONT_LEFT_BIT | FRONT_RIGHT_BIT; else - ctx->Color.DrawDestMask = FRONT_LEFT_BIT; + ctx->Color._DrawDestMask = FRONT_LEFT_BIT; break; case GL_NONE: /* never an error */ - ctx->Color.DrawDestMask = 0; + ctx->Color._DrawDestMask = 0; + break; + case GL_AUX0: + if (ctx->Const.NumAuxBuffers >= 1) { + ctx->Color._DrawDestMask = AUX0_BIT; + } + else { + _mesa_error( ctx, GL_INVALID_OPERATION, "glDrawBuffer(GL_AUX0)" ); + return; + } + break; + case GL_AUX1: + if (ctx->Const.NumAuxBuffers >= 2) { + ctx->Color._DrawDestMask = AUX1_BIT; + } + else { + _mesa_error( ctx, GL_INVALID_OPERATION, "glDrawBuffer(GL_AUX1)" ); + return; + } + break; + case GL_AUX2: + if (ctx->Const.NumAuxBuffers >= 3) { + ctx->Color._DrawDestMask = AUX2_BIT; + } + else { + _mesa_error( ctx, GL_INVALID_OPERATION, "glDrawBuffer(GL_AUX2)" ); + return; + } + break; + case GL_AUX3: + if (ctx->Const.NumAuxBuffers >= 4) { + ctx->Color._DrawDestMask = AUX3_BIT; + } + else { + _mesa_error( ctx, GL_INVALID_OPERATION, "glDrawBuffer(GL_AUX3)" ); + return; + } break; default: _mesa_error( ctx, GL_INVALID_ENUM, "glDrawBuffer" ); return; } - /* - * Make the dest buffer mode more precise if possible - */ - if (mode == GL_LEFT && !ctx->Visual.doubleBufferMode) - ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT; - else if (mode == GL_RIGHT && !ctx->Visual.doubleBufferMode) - ctx->Color.DriverDrawBuffer = GL_FRONT_RIGHT; - else if (mode == GL_FRONT && !ctx->Visual.stereoMode) - ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT; - else if (mode == GL_BACK && !ctx->Visual.stereoMode) - ctx->Color.DriverDrawBuffer = GL_BACK_LEFT; - else - ctx->Color.DriverDrawBuffer = mode; - - /* - * Set current alpha buffer pointer - */ - if (ctx->DrawBuffer->UseSoftwareAlphaBuffers) { - if (ctx->Color.DriverDrawBuffer == GL_FRONT_LEFT) - ctx->DrawBuffer->Alpha = ctx->DrawBuffer->FrontLeftAlpha; - else if (ctx->Color.DriverDrawBuffer == GL_BACK_LEFT) - ctx->DrawBuffer->Alpha = ctx->DrawBuffer->BackLeftAlpha; - else if (ctx->Color.DriverDrawBuffer == GL_FRONT_RIGHT) - ctx->DrawBuffer->Alpha = ctx->DrawBuffer->FrontRightAlpha; - else if (ctx->Color.DriverDrawBuffer == GL_BACK_RIGHT) - ctx->DrawBuffer->Alpha = ctx->DrawBuffer->BackRightAlpha; - } + ctx->Color.DrawBuffer = mode; + ctx->NewState |= _NEW_COLOR; /* - * If we get here there can't have been an error. Now tell the - * device driver about it. + * Call device driver function. */ - ASSERT(ctx->Driver.SetDrawBuffer); - (*ctx->Driver.SetDrawBuffer)(ctx, ctx->Color.DriverDrawBuffer); - - ctx->Color.DrawBuffer = mode; - ctx->NewState |= _NEW_COLOR; + if (ctx->Driver.DrawBuffer) + (*ctx->Driver.DrawBuffer)(ctx, mode); } @@ -276,21 +279,17 @@ _mesa_ReadBuffer( GLenum mode ) ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); if (MESA_VERBOSE & VERBOSE_API) - fprintf(stderr, "glReadBuffer %s\n", _mesa_lookup_enum_by_nr(mode)); + _mesa_debug(ctx, "glReadBuffer %s\n", _mesa_lookup_enum_by_nr(mode)); + /* + * Do error checking and compute ctx->Pixel._ReadSrcMask. + */ switch (mode) { - case GL_AUX0: - case GL_AUX1: - case GL_AUX2: - case GL_AUX3: - /* AUX buffers not implemented in Mesa at this time */ - _mesa_error( ctx, GL_INVALID_OPERATION, "glReadBuffer" ); - return; case GL_LEFT: case GL_FRONT: case GL_FRONT_LEFT: /* Front-Left buffer, always exists */ - ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT; + ctx->Pixel._ReadSrcMask = FRONT_LEFT_BIT; break; case GL_BACK: case GL_BACK_LEFT: @@ -299,7 +298,7 @@ _mesa_ReadBuffer( GLenum mode ) _mesa_error( ctx, GL_INVALID_OPERATION, "glReadBuffer" ); return; } - ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT; + ctx->Pixel._ReadSrcMask = BACK_LEFT_BIT; break; case GL_FRONT_RIGHT: case GL_RIGHT: @@ -307,14 +306,50 @@ _mesa_ReadBuffer( GLenum mode ) _mesa_error( ctx, GL_INVALID_OPERATION, "glReadBuffer" ); return; } - ctx->Pixel.DriverReadBuffer = GL_FRONT_RIGHT; + ctx->Pixel._ReadSrcMask = FRONT_RIGHT_BIT; break; case GL_BACK_RIGHT: if (!ctx->Visual.stereoMode || !ctx->Visual.doubleBufferMode) { _mesa_error( ctx, GL_INVALID_OPERATION, "glReadBuffer" ); return; } - ctx->Pixel.DriverReadBuffer = GL_BACK_RIGHT; + ctx->Pixel._ReadSrcMask = BACK_RIGHT_BIT; + break; + case GL_AUX0: + if (ctx->Const.NumAuxBuffers >= 1) { + ctx->Pixel._ReadSrcMask = AUX0_BIT; + } + else { + _mesa_error( ctx, GL_INVALID_OPERATION, "glReadBuffer(GL_AUX0)" ); + return; + } + break; + case GL_AUX1: + if (ctx->Const.NumAuxBuffers >= 2) { + ctx->Pixel._ReadSrcMask = AUX1_BIT; + } + else { + _mesa_error( ctx, GL_INVALID_OPERATION, "glReadBuffer(GL_AUX1)" ); + return; + } + break; + case GL_AUX2: + if (ctx->Const.NumAuxBuffers >= 3) { + ctx->Pixel._ReadSrcMask = AUX2_BIT; + } + else { + _mesa_error( ctx, GL_INVALID_OPERATION, "glReadBuffer(GL_AUX2)" ); + return; + } + break; + case GL_AUX3: + if (ctx->Const.NumAuxBuffers >= 4) { + ctx->Pixel._ReadSrcMask = AUX3_BIT; + } + else { + _mesa_error( ctx, GL_INVALID_OPERATION, "glReadBuffer(GL_AUX3)" ); + return; + } break; default: _mesa_error( ctx, GL_INVALID_ENUM, "glReadBuffer" ); @@ -323,6 +358,12 @@ _mesa_ReadBuffer( GLenum mode ) ctx->Pixel.ReadBuffer = mode; ctx->NewState |= _NEW_PIXEL; + + /* + * Call device driver function. + */ + if (ctx->Driver.ReadBuffer) + (*ctx->Driver.ReadBuffer)(ctx, mode); } @@ -338,7 +379,7 @@ _mesa_ResizeBuffersMESA( void ) GLcontext *ctx = _mesa_get_current_context(); if (MESA_VERBOSE & VERBOSE_API) - fprintf(stderr, "glResizeBuffersMESA\n"); + _mesa_debug(ctx, "glResizeBuffersMESA\n"); if (ctx) { ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx ); @@ -394,7 +435,7 @@ _mesa_Scissor( GLint x, GLint y, GLsizei width, GLsizei height ) } if (MESA_VERBOSE & VERBOSE_API) - fprintf(stderr, "glScissor %d %d %d %d\n", x, y, width, height); + _mesa_debug(ctx, "glScissor %d %d %d %d\n", x, y, width, height); if (x == ctx->Scissor.X && y == ctx->Scissor.Y && |