1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-07-03 06:24:32 +00:00

remove RenderObject::blendEnabled and cleanup the blend code a bit

This commit is contained in:
fgenesis 2022-05-19 01:34:31 +02:00
parent 06270eaac0
commit 46010244f5
26 changed files with 111 additions and 79 deletions

View file

@ -40,6 +40,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define OVERRIDE
#endif
namespace internal
{
template <typename T, size_t N>
char (&_ArraySizeHelper( T (&a)[N]))[N];
template<size_t n>
struct NotZero { static const size_t value = n; };
template<>
struct NotZero<0> {};
}
#define Countof(a) (internal::NotZero<(sizeof(internal::_ArraySizeHelper(a)))>::value)
#ifdef _MSC_VER
//#pragma warning(disable:4786)

View file

@ -26,6 +26,7 @@ set(BBGE_SRCS
Effects.cpp
Effects.h
Emitter.cpp
EngineEnums.h
Event.cpp
Event.h
FmodOpenALBridge.cpp

6
BBGE/EngineEnums.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef BBGE_ENGINE_ENUMS_H
#define BBGE_ENGINE_ENUMS_H
enum BlendType { BLEND_DISABLED = -1, BLEND_DEFAULT = 0, BLEND_ADD, BLEND_SUB, BLEND_MULT, _BLEND_MAXSIZE };
#endif

View file

@ -330,7 +330,7 @@ void ParticleEffect::bankLoad(const std::string &file, const std::string &path)
if (blendType == "Add")
currentEmitter->data.blendType = BLEND_ADD;
else if (blendType == "Sub")
currentEmitter->data.blendType = RenderObject::BLEND_SUB;
currentEmitter->data.blendType = BLEND_SUB;
}
else if (token == "Width")
{

View file

@ -65,7 +65,7 @@ struct SpawnParticleData
float life;
InterpolatedVector spawnRate;
std::string texture;
RenderObject::BlendTypes blendType;
BlendType blendType;
float counter;
float spawnTimeOffset;
bool spawnLocal;

View file

@ -55,26 +55,27 @@ int RenderObject::getTopLayer()
return layer;
}
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 },
};
void RenderObject::applyBlendType()
{
if (blendEnabled)
compile_assert(Countof(s_blendParams) == _BLEND_MAXSIZE);
if (_blendType >= BLEND_DEFAULT)
{
glEnable(GL_BLEND);
switch (blendType)
{
case BLEND_DEFAULT:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
break;
case BLEND_ADD:
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
break;
case BLEND_SUB:
glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
break;
case BLEND_MULT:
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
break;
}
const BlendParams& bp = s_blendParams[_blendType];
glBlendFunc(bp.src, bp.dst);
}
else
{
@ -145,7 +146,6 @@ RenderObject::RenderObject()
pm = PM_NONE;
blendEnabled = true;
texture = 0;
width = 0;
height = 0;
@ -158,7 +158,7 @@ RenderObject::RenderObject()
_dead = false;
_hidden = false;
fadeAlphaWithLife = false;
blendType = BLEND_DEFAULT;
_blendType = BLEND_DEFAULT;
followCamera = 0;
stateData = 0;

View file

@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define RENDER_OBJECT_H
#include "Base.h"
#include "EngineEnums.h"
#include "Texture.h"
#include "ScriptObject.h"
#include <list>
@ -117,9 +118,13 @@ public:
{
this->decayRate = newdecayRate;
}
void setBlendType (unsigned char bt)
void setBlendType (BlendType bt)
{
blendType = bt;
_blendType = bt;
}
inline BlendType getBlendType() const
{
return (BlendType)_blendType;
}
@ -228,7 +233,6 @@ public:
// TODO: this should be a bitmask
bool fadeAlphaWithLife;
bool blendEnabled;
bool renderBeforeParent;
bool updateAfterParent;
bool shareAlphaWithChildren;
@ -244,6 +248,8 @@ public:
unsigned char pm; // unsigned char to save space
char _blendType;
InterpolatedVector position, scale, color, alpha, rotation;
InterpolatedVector offset, rotationOffset, internalOffset, beforeScaleOffset;
@ -251,11 +257,6 @@ public:
CountedPtr<Texture> texture;
enum BlendTypes { BLEND_DEFAULT = 0, BLEND_ADD, BLEND_SUB, BLEND_MULT };
unsigned char blendType;
float life;
float followCamera;
float alphaMod;

View file

@ -1492,7 +1492,8 @@ void SkeletalSprite::loadSkeletal(const std::string &fn)
if (bone->Attribute("blend"))
{
//if (bone->Attribute("blend")=="add")
newb->blendType = blendType = BLEND_ADD;
newb->setBlendType(BLEND_ADD);
//this->setBlendType(BLEND_ADD); // FIXME: seems wrong to do this here -- fg
}
if (bone->Attribute("alpha"))

View file

@ -34,7 +34,7 @@ SpawnParticleData::SpawnParticleData()
useSpawnRate = false;
counter = 0;
life = 1;
blendType = RenderObject::BLEND_DEFAULT;
blendType = BLEND_DEFAULT;
spawnRate = 1;
scale = Vector(1,1,1);
width = 64;