1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-29 03:33:48 +00:00
Aquaria/BBGE/RenderState.cpp
fgenesis 1a90625979 refactor rendering logic to be a lot less wasteful
Observations:
- Entity::renderPass was never set to RENDER_ALL -> can simplify some things
- The initial pass check in RenderObject::render() was constant for each pass
-> All logic that is per-pass-constant can be moved to a renderability pre-check
- Core::overrideStartLayer, Core::overrideEndLayer, Core::rlayer were never used
- Should be possible eventually to prepare & render layers in parallel

I am not sure if the changes in this commit are 100% correct, but layer passes
are still working and the hug looks like it should.

Thinking about it, the overrideRenderPass functionality should never have existed.
The game scripts don't actually use entity_setRenderPass
(which in turn calls Entity::setOverrideRenderPass())
so I might remove that function in a future commit,
together with the rest of the "override" functionality.
2022-05-22 17:26:16 +02:00

50 lines
915 B
C++

#include "RenderState.h"
#include "Base.h"
#include "RenderBase.h"
RenderState::RenderState(GPUState &gpu)
: gpu(gpu), color(1,1,1), alpha(1), pass(0)
{
}
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);
// FIXME: comment this back in once ALL other occurances of glBlendFunc() have been removed
//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);
}
}