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 70b8e69402 remove last traces of GL_BLEND/glBlendFunc() manipulation
everything goes through RenderState now
some calls are left in FTGL but properly invalidated afterwards
2024-01-11 23:05:47 +01:00

57 lines
1 KiB
C++

#include "RenderState.h"
#include "Base.h"
#include "RenderBase.h"
#include "RenderObject.h"
RenderState::RenderState(GPUState &gpu)
: gpu(gpu), color(1,1,1), scale(1,1), alpha(1), pass(RenderObject::RENDER_ALL)
, forceRenderBorder(false), forceRenderCenter(false), renderBorderAlpha(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 (unsigned(bt) < _BLEND_MAXSIZE)
{
glEnable(GL_BLEND);
const BlendParams& bp = s_blendParams[bt];
glBlendFunc(bp.src, bp.dst);
}
else
{
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
}
}
void GPUState::invalidateBlend()
{
_blendType = _BLEND_MAXSIZE;
}