state_buffer.c revision 061bebe04c5bfa05ed733d2a1204389c2a0c96a8
/* Copyright (c) 2001, Stanford University
* All rights reserved
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#include <stdio.h>
#include "state.h"
#include "state/cr_statetypes.h"
#include "state_internals.h"
{
b->indexLogicOp = GL_FALSE;
b->alphaTestFunc = GL_ALWAYS;
b->alphaTestRef = 0;
b->blendSrcRGB = GL_ONE;
b->blendDstRGB = GL_ZERO;
#ifdef CR_EXT_blend_func_separate
#endif
b->logicOpMode = GL_COPY;
b->drawBuffer = GL_BACK;
b->readBuffer = GL_BACK;
b->indexWriteMask = 0xffffffff;
b->colorWriteMask.r = GL_TRUE;
b->colorWriteMask.g = GL_TRUE;
b->colorWriteMask.b = GL_TRUE;
b->colorWriteMask.a = GL_TRUE;
b->colorClearValue = zero_colorf;
b->indexClearValue = 0;
b->accumClearValue = zero_colorf;
#ifdef CR_EXT_blend_color
b->blendColor = zero_colorf;
#endif
#if defined(CR_EXT_blend_minmax) || defined(CR_EXT_blend_subtract) || defined(CR_EXT_blend_logic_op)
b->blendEquation = GL_FUNC_ADD_EXT;
#endif
}
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
return;
}
FLUSH();
switch (func)
{
case GL_NEVER:
case GL_LESS:
case GL_EQUAL:
case GL_LEQUAL:
case GL_GREATER:
case GL_GEQUAL:
case GL_NOTEQUAL:
case GL_ALWAYS:
break;
default:
return;
}
b->alphaTestFunc = func;
b->alphaTestRef = ref;
}
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
return;
}
FLUSH();
switch (func)
{
case GL_NEVER:
case GL_LESS:
case GL_EQUAL:
case GL_LEQUAL:
case GL_GREATER:
case GL_NOTEQUAL:
case GL_GEQUAL:
case GL_ALWAYS:
break;
default:
return;
}
}
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
return;
}
FLUSH();
switch (sfactor)
{
case GL_ZERO:
case GL_ONE:
case GL_DST_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
case GL_SRC_ALPHA_SATURATE:
break; /* OK */
#ifdef CR_EXT_blend_color
case GL_CONSTANT_COLOR_EXT:
case GL_CONSTANT_ALPHA_EXT:
if (g->extensions.EXT_blend_color)
break; /* OK */
#endif
default:
crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactor passed to glBlendFunc: %d", sfactor);
return;
}
switch (dfactor)
{
case GL_ZERO:
case GL_ONE:
case GL_SRC_COLOR:
case GL_ONE_MINUS_SRC_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
break; /* OK */
#ifdef CR_EXT_blend_color
case GL_CONSTANT_COLOR_EXT:
case GL_CONSTANT_ALPHA_EXT:
if (g->extensions.EXT_blend_color)
break; /* OK */
#endif
default:
crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactor passed to glBlendFunc: %d", dfactor);
return;
}
b->blendSrcRGB = sfactor;
b->blendDstRGB = dfactor;
}
void STATE_APIENTRY crStateBlendColorEXT( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendColorEXT called inside a Begin/End" );
return;
}
b->blendColor.r = red;
b->blendColor.g = green;
b->blendColor.b = blue;
b->blendColor.a = alpha;
}
#ifdef CR_EXT_blend_func_separate
void STATE_APIENTRY crStateBlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorA, GLenum dfactorA )
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendFuncSeparateEXT called inside a Begin/End" );
return;
}
FLUSH();
switch (sfactorRGB)
{
case GL_ZERO:
case GL_ONE:
case GL_DST_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
case GL_SRC_ALPHA_SATURATE:
break; /* OK */
#ifdef CR_EXT_blend_color
case GL_CONSTANT_COLOR_EXT:
case GL_CONSTANT_ALPHA_EXT:
if (g->extensions.EXT_blend_color)
break; /* OK */
#endif
default:
crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactorRGB passed to glBlendFuncSeparateEXT: %d", sfactorRGB);
return;
}
switch (sfactorA)
{
case GL_ZERO:
case GL_ONE:
case GL_DST_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
case GL_SRC_ALPHA_SATURATE:
break; /* OK */
#ifdef CR_EXT_blend_color
case GL_CONSTANT_COLOR_EXT:
case GL_CONSTANT_ALPHA_EXT:
if (g->extensions.EXT_blend_color)
break; /* OK */
#endif
default:
crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid sfactorA passed to glBlendFuncSeparateEXT: %d", sfactorA);
return;
}
switch (dfactorRGB)
{
case GL_ZERO:
case GL_ONE:
case GL_SRC_COLOR:
case GL_DST_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_ONE_MINUS_SRC_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
case GL_SRC_ALPHA_SATURATE:
break; /* OK */
#ifdef CR_EXT_blend_color
case GL_CONSTANT_COLOR_EXT:
case GL_CONSTANT_ALPHA_EXT:
if (g->extensions.EXT_blend_color)
break; /* OK */
#endif
default:
crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactorRGB passed to glBlendFuncSeparateEXT: %d", dfactorRGB);
return;
}
switch (dfactorA)
{
case GL_ZERO:
case GL_ONE:
case GL_DST_COLOR:
case GL_SRC_COLOR:
case GL_ONE_MINUS_SRC_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
case GL_SRC_ALPHA_SATURATE:
break; /* OK */
#ifdef CR_EXT_blend_color
case GL_CONSTANT_COLOR_EXT:
case GL_CONSTANT_ALPHA_EXT:
if (g->extensions.EXT_blend_color)
break; /* OK */
#endif
default:
crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid dfactorA passed to glBlendFuncSeparateEXT: %d", dfactorA);
return;
}
b->blendSrcRGB = sfactorRGB;
b->blendDstRGB = dfactorRGB;
}
#endif
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if( g->current.inBeginEnd )
{
crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION, "BlendEquationEXT called inside a Begin/End" );
return;
}
switch( mode )
{
#if defined(CR_EXT_blend_minmax) || defined(CR_EXT_blend_subtract) || defined(CR_EXT_blend_logic_op)
case GL_FUNC_ADD_EXT:
#ifdef CR_EXT_blend_subtract
case GL_FUNC_SUBTRACT_EXT:
#endif /* CR_EXT_blend_subtract */
#ifdef CR_EXT_blend_minmax
case GL_MIN_EXT:
case GL_MAX_EXT:
#endif /* CR_EXT_blend_minmax */
#ifdef CR_EXT_blend_logic_op
case GL_LOGIC_OP:
#endif /* CR_EXT_blend_logic_op */
b->blendEquation = mode;
break;
#endif /* defined(CR_EXT_blend_minmax) || defined(CR_EXT_blend_subtract) || defined(CR_EXT_blend_logic_op) */
default:
return;
}
}
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
return;
}
FLUSH();
switch (opcode)
{
case GL_CLEAR:
case GL_SET:
case GL_COPY:
case GL_COPY_INVERTED:
case GL_NOOP:
case GL_INVERT:
case GL_AND:
case GL_NAND:
case GL_OR:
case GL_NOR:
case GL_XOR:
case GL_EQUIV:
case GL_AND_REVERSE:
case GL_AND_INVERTED:
case GL_OR_REVERSE:
case GL_OR_INVERTED:
break;
default:
crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glLogicOp called with bogus opcode: %d", opcode);
return;
}
b->logicOpMode = opcode;
}
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
return;
}
FLUSH();
switch (mode)
{
case GL_NONE:
case GL_FRONT_LEFT:
case GL_FRONT_RIGHT:
case GL_BACK_LEFT:
case GL_BACK_RIGHT:
case GL_FRONT:
case GL_BACK:
case GL_LEFT:
case GL_RIGHT:
case GL_FRONT_AND_BACK:
case GL_AUX0:
case GL_AUX1:
case GL_AUX2:
case GL_AUX3:
if (g->framebufferobject.drawFB)
{
crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer invalud mode while fbo is active");
return;
}
break;
default:
{
if (!g->framebufferobject.drawFB)
{
crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDrawBuffer invalud mode while fbo is inactive");
return;
}
}
else
{
return;
}
}
if (g->framebufferobject.drawFB)
{
}
else
{
b->drawBuffer = mode;
}
}
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
return;
}
FLUSH();
switch (mode)
{
case GL_NONE:
case GL_FRONT_LEFT:
case GL_FRONT_RIGHT:
case GL_BACK_LEFT:
case GL_BACK_RIGHT:
case GL_FRONT:
case GL_BACK:
case GL_LEFT:
case GL_RIGHT:
case GL_FRONT_AND_BACK:
case GL_AUX0:
case GL_AUX1:
case GL_AUX2:
case GL_AUX3:
if (g->framebufferobject.readFB)
{
crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer invalud mode while fbo is active");
return;
}
break;
default:
{
if (!g->framebufferobject.readFB)
{
crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glReadBuffer invalud mode while fbo is inactive");
return;
}
else
{
/*@todo, check if fbo binding is complete*/
}
}
else
{
return;
}
}
if (g->framebufferobject.readFB)
{
}
else
{
b->readBuffer = mode;
}
}
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
return;
}
FLUSH();
b->indexWriteMask = mask;
}
void STATE_APIENTRY crStateColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
return;
}
FLUSH();
b->colorWriteMask.r = red;
b->colorWriteMask.g = green;
b->colorWriteMask.b = blue;
b->colorWriteMask.a = alpha;
}
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
return;
}
FLUSH();
b->colorClearValue.r = red;
b->colorClearValue.g = green;
b->colorClearValue.b = blue;
b->colorClearValue.a = alpha;
}
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
return;
}
b->indexClearValue = c;
}
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
return;
}
FLUSH();
}
{
CRContext *g = GetCurrentContext();
CRBufferState *b = &(g->buffer);
if (g->current.inBeginEnd)
{
return;
}
FLUSH();
b->accumClearValue.r = red;
b->accumClearValue.g = green;
b->accumClearValue.b = blue;
b->accumClearValue.a = alpha;
}
{
CRContext *g = GetCurrentContext();
if (g->current.inBeginEnd)
{
return;
}
FLUSH();
}