1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 17:53:47 +00:00
Aquaria/BBGE/RenderState.cpp
fgenesis 68b3c61852 Add RenderState to be passed through the scene graph
This will eventually handle all mutable state during rendering
2022-05-20 01:04:19 +02:00

49 lines
799 B
C++

#include "RenderState.h"
#include "Base.h"
#include "RenderBase.h"
RenderState::RenderState(GPUState &gpu)
: gpu(gpu), color(1,1,1), alpha(1)
{
}
struct BlendParams
{
GLenum src, dst;
};
static const BlendParams s_blendParams[] =
{
{ GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA },
{ GL_SRC_ALPHA, GL_ONE },
{ GL_ZERO, GL_SRC_ALPHA },
{ GL_ZERO, GL_SRC_COLOR },
};
GPUState::GPUState()
: _blendType(BLEND_DISABLED)
{
setBlend(BLEND_DEFAULT);
}
void GPUState::setBlend(BlendType bt)
{
compile_assert(Countof(s_blendParams) == _BLEND_MAXSIZE);
if(_blendType == bt)
return;
_blendType = bt;
if (bt >= BLEND_DEFAULT)
{
glEnable(GL_BLEND);
const BlendParams& bp = s_blendParams[bt];
glBlendFunc(bp.src, bp.dst);
}
else
{
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
}
}