diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 4f3d653..0aa7d9b 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -247,7 +247,7 @@ SongIconParticle::SongIconParticle(Vector color, Vector pos, size_t note) setDecayRate(1); //if (rand()%6 <= 2) - setBlendType(RenderObject::BLEND_ADD); + setBlendType(BLEND_ADD); float smallestDist = HUGE_VALF; SongIcon *closest = 0; @@ -322,7 +322,7 @@ SongIcon::SongIcon(size_t note) : Quad(), note(note) glow->followCamera = 1; glow->rotation.interpolateTo(Vector(0,0,360), 10, -1); glow->alpha = 0; - glow->setBlendType(RenderObject::BLEND_ADD); + glow->setBlendType(BLEND_ADD); glow->scale = Vector(0.5, 0.5); glow->color = dsq->getNoteColor(note); dsq->game->addRenderObject(glow, LR_PARTICLES2); @@ -507,7 +507,7 @@ void SongIcon::openNote() q->alpha.data->path.addPathNode(0,1); q->alpha.startPath(glowLife); q->color = dsq->getNoteColor(note); //*0.5f + Vector(0.5, 0.5, 0.5) - q->setBlendType(RenderObject::BLEND_ADD); + q->setBlendType(BLEND_ADD); q->followCamera = 1; dsq->game->addRenderObject(q, LR_HUD); q->setDecayRate(1/(glowLife+0.1f)); @@ -527,7 +527,7 @@ void SongIcon::openNote() q->alpha.data->path.addPathNode(0.5f,0.2f); q->alpha.data->path.addPathNode(0,1); q->alpha.startPath(glowLife); - //q->setBlendType(RenderObject::BLEND_ADD); + //q->setBlendType(BLEND_ADD); q->followCamera = 1; dsq->game->addRenderObject(q, LR_HUD); q->setDecayRate(1/(glowLife+0.1f)); diff --git a/Aquaria/Credits.cpp b/Aquaria/Credits.cpp index d357ccd..12e1bc0 100644 --- a/Aquaria/Credits.cpp +++ b/Aquaria/Credits.cpp @@ -132,7 +132,7 @@ void Credits::applyState() slides[i] = new Quad("credits/slide-" + numToZeroString(i, 4), Vector(400, 300)); slides[i]->alpha = 0; slides[i]->followCamera = 1; - slides[i]->setBlendType(RenderObject::BLEND_ADD); + slides[i]->setBlendType(BLEND_ADD); addRenderObject(slides[i], LR_ENTITIES); } diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index 4c1774a..069f586 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -311,8 +311,10 @@ void DSQ::loadElementEffects() { efxType = EFX_ALPHA; float to_x, time, loop, pingPong, ease; - is >> e.blendType >> e.alpha.x >> to_x >> time >> loop >> pingPong >> ease; + int blend; + is >> blend >> e.alpha.x >> to_x >> time >> loop >> pingPong >> ease; e.alpha.interpolateTo(to_x, time, loop, pingPong, ease); + e.blendType = blend < _BLEND_MAXSIZE ? (BlendType)blend : BLEND_DISABLED; } e.type = efxType; elementEffects.push_back(e); @@ -330,7 +332,7 @@ ElementEffect DSQ::getElementEffectByIndex(size_t e) ElementEffect empty; empty.type = EFX_NONE; empty.alpha = 0; - empty.blendType = 0; + empty.blendType = BLEND_DEFAULT; empty.color = 0; empty.segsx = empty.segsy = 0; empty.segs_dgmx = empty.segs_dgmy = 0; @@ -1135,7 +1137,7 @@ void DSQ::init() cursorGlow->setTexture("glow"); cursorGlow->setWidthHeight(48, 48); cursorGlow->alpha = 0; - cursorGlow->setBlendType(RenderObject::BLEND_ADD); + cursorGlow->setBlendType(BLEND_ADD); } cursor->addChild(cursorGlow, PM_NONE, RBP_OFF); addRenderObject(cursorGlow, LR_CURSOR); @@ -1207,7 +1209,7 @@ void DSQ::init() sceneColorOverlay->position = Vector(400,300); sceneColorOverlay->color = Vector(1,1,1); sceneColorOverlay->alpha = 1; - sceneColorOverlay->setBlendType(RenderObject::BLEND_MULT); + sceneColorOverlay->setBlendType(BLEND_MULT); sceneColorOverlay->autoWidth = AUTO_VIRTUALWIDTH; sceneColorOverlay->autoHeight = AUTO_VIRTUALHEIGHT; sceneColorOverlay->followCamera = 1; @@ -2135,7 +2137,7 @@ void DSQ::clickRingEffect(Vector pos, int type, Vector color, float ut) q->color = color; - q->setBlendType(RenderObject::BLEND_ADD); + q->setBlendType(BLEND_ADD); q->alpha.ensureData(); q->alpha.data->path.addPathNode(0, 0); @@ -2163,7 +2165,7 @@ void DSQ::clickRingEffect(Vector pos, int type, Vector color, float ut) q->scale = Vector(5,5); q->scale.interpolateTo(Vector(1,1), t); - q->setBlendType(RenderObject::BLEND_ADD); + q->setBlendType(BLEND_ADD); q->color = color; @@ -2250,7 +2252,7 @@ void DSQ::doSavePoint(const Vector &position) glow->setTexture("save-point-glow"); glow->alpha = 0; glow->alpha.interpolateTo(0.5f, 1, 1, true, true); - glow->setBlendType(RenderObject::BLEND_ADD); + glow->setBlendType(BLEND_ADD); glow->position = position; glow->scale = Vector(1,1)*1.25f; glow->setLife(3); @@ -4008,7 +4010,7 @@ void DSQ::playVisualEffect(int vfx, Vector position, Entity *target) q->alpha.data->path.addPathNode(0.75f, 0.75f); q->alpha.data->path.addPathNode(0, 1); q->alpha.startPath(t); - q->setBlendType(RenderObject::BLEND_ADD); + q->setBlendType(BLEND_ADD); q->setTexture("particles/EnergyRing"); if (target) q->setPositionSnapTo(&target->position); @@ -4031,7 +4033,7 @@ void DSQ::playVisualEffect(int vfx, Vector position, Entity *target) q->alpha.data->path.addPathNode(0.75f, 0.75f); q->alpha.data->path.addPathNode(0, 1); q->alpha.startPath(t); - q->setBlendType(RenderObject::BLEND_ADD); + q->setBlendType(BLEND_ADD); q->setTexture("particles/EnergyPart"); if (target) q->setPositionSnapTo(&target->position); @@ -4054,7 +4056,7 @@ void DSQ::playVisualEffect(int vfx, Vector position, Entity *target) q->alpha.data->path.addPathNode(0, 1); q->alpha.startPath(t); - q->setBlendType(RenderObject::BLEND_ADD); + q->setBlendType(BLEND_ADD); q->rotation.z = rand()%360; q->setTexture("particles/EnergyRing"); @@ -4074,7 +4076,7 @@ void DSQ::playVisualEffect(int vfx, Vector position, Entity *target) q->alpha.data->path.addPathNode(0, 1); q->alpha.startPath(t); - q->setBlendType(RenderObject::BLEND_ADD); + q->setBlendType(BLEND_ADD); q->setTexture("particles/EnergyDeltas"); q->rotation.z = rand()%360; diff --git a/Aquaria/Element.cpp b/Aquaria/Element.cpp index 00ad9ca..1e24746 100644 --- a/Aquaria/Element.cpp +++ b/Aquaria/Element.cpp @@ -233,7 +233,7 @@ void Element::setElementEffectByIndex(int eidx) { deleteGrid(); - setBlendType(RenderObject::BLEND_DEFAULT); + setBlendType(BLEND_DEFAULT); alpha.stop(); alpha = 1; diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index ec40ff3..4fed3cb 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -2509,7 +2509,7 @@ void Entity::render() scale = bscale; } -void Entity::doGlint(const Vector &position, const Vector &scale, const std::string &tex, RenderObject::BlendTypes bt) +void Entity::doGlint(const Vector &position, const Vector &scale, const std::string &tex, BlendType bt) { float glintTime = 0.4f; Quad *glint = new Quad; diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 083cf49..faae225 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -182,7 +182,7 @@ public: bool hasTarget(int t=0); bool isTargetInRange(int range, size_t t=0); - void doGlint(const Vector &position, const Vector &scale=Vector(2,2), const std::string &tex="Glint", RenderObject::BlendTypes bt=BLEND_DEFAULT); + void doGlint(const Vector &position, const Vector &scale=Vector(2,2), const std::string &tex="Glint", BlendType bt=BLEND_DEFAULT); Entity *getTargetEntity(int t=0); void setTargetEntity(Entity *e, int t=0); diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 17125bb..bd21ea8 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -1507,7 +1507,7 @@ bool Game::loadSceneXML(std::string scene) std::string backdrop = level->Attribute("backdrop"); backdropQuad = new Quad; backdropQuad->setTexture(backdrop); - backdropQuad->blendEnabled = false; + backdropQuad->setBlendType(BLEND_DISABLED); if (level->Attribute("bd-x") && level->Attribute("bd-y")) { @@ -2242,9 +2242,9 @@ void Game::createGradient() } addRenderObject(grad, LR_BACKDROP); if (bg) - bg->blendEnabled = true; + bg->setBlendType(BLEND_DEFAULT); if (bg2) - bg2->blendEnabled = true; + bg2->setBlendType(BLEND_DEFAULT); } } @@ -2711,7 +2711,7 @@ void Game::applyState() bg = new Quad; { - bg->blendEnabled = false; + bg->setBlendType(BLEND_DISABLED); bg->position = Vector(400, 300, -2/*-0.09f*/); //bg->color = Vector(0.9, 0.9, 0.9); bg->setTexture("missingImage"); @@ -2805,7 +2805,7 @@ void Game::applyState() controlHint_shine->alphaMod = 0.3f; controlHint_shine->setWidthHeight(core->getVirtualWidth(), 100); controlHint_shine->alpha = 0; - controlHint_shine->setBlendType(RenderObject::BLEND_ADD); + controlHint_shine->setBlendType(BLEND_ADD); } addRenderObject(controlHint_shine, LR_HELP); @@ -2906,7 +2906,7 @@ void Game::applyState() GridRender *blackRender = new GridRender(OT_BLACK); blackRender->color = Vector(0, 0, 0); //blackRender->alpha = 0; - blackRender->blendEnabled = false; + blackRender->setBlendType(BLEND_DISABLED); addRenderObject(blackRender, LR_ELEMENTS4); miniMapRender = new MiniMapRender; diff --git a/Aquaria/GameEnums.h b/Aquaria/GameEnums.h index 8f671e6..c2c06f7 100644 --- a/Aquaria/GameEnums.h +++ b/Aquaria/GameEnums.h @@ -1,6 +1,8 @@ #ifndef GAMEENUMS_H #define GAMEENUMS_H +#include "EngineEnums.h" + // Note: although this is a bitmask, only one of these values may be set at a time! // This is because GridRender and most Lua scripts check via ==, not for bits set (Lua 5.1 doesn't have bit ops) diff --git a/Aquaria/GameStructs.h b/Aquaria/GameStructs.h index d74ef53..3e39094 100644 --- a/Aquaria/GameStructs.h +++ b/Aquaria/GameStructs.h @@ -16,7 +16,7 @@ public: bool wavy_flip; InterpolatedVector alpha; InterpolatedVector color; - int blendType; + BlendType blendType; }; struct EmoteData diff --git a/Aquaria/GridRender.cpp b/Aquaria/GridRender.cpp index 0548097..d58632f 100644 --- a/Aquaria/GridRender.cpp +++ b/Aquaria/GridRender.cpp @@ -30,14 +30,11 @@ GridRender::GridRender(ObsType obsType) : RenderObject() cull = false; alpha = 0.5f; this->obsType = obsType; - blendEnabled = false; - } void GridRender::onUpdate(float dt) { RenderObject::onUpdate(dt); - if (obsType != OT_BLACK) { blendEnabled = true; } } inline static void doRenderGrid(int x, int startCol, int endCol) diff --git a/Aquaria/InGameMenu.cpp b/Aquaria/InGameMenu.cpp index e30903f..3901365 100644 --- a/Aquaria/InGameMenu.cpp +++ b/Aquaria/InGameMenu.cpp @@ -712,7 +712,7 @@ SongSlot::SongSlot(int songSlot) : AquariaGuiQuad(), songSlot(songSlot) glow = new Quad("particles/glow", Vector(0,0)); glow->setWidthHeight(128, 128); - glow->setBlendType(RenderObject::BLEND_ADD); + glow->setBlendType(BLEND_ADD); glow->alpha = 0; addChild(glow, PM_POINTER); @@ -2512,7 +2512,7 @@ void InGameMenu::create() menuIconGlow->alphaMod = 0.4f; menuIconGlow->alpha = 0; menuIconGlow->setWidthHeight(80, 80); - menuIconGlow->setBlendType(RenderObject::BLEND_ADD); + menuIconGlow->setBlendType(BLEND_ADD); menuIconGlow->followCamera = 1; game->addRenderObject(menuIconGlow, LR_MENU); @@ -4153,7 +4153,7 @@ void InGameMenu::update(float dt) float t = 0.5; Quad *q = new Quad("particles/glow", Vector(400+237*menuBg->scale.x,300-52*menuBg->scale.x)+notePos); - q->setBlendType(RenderObject::BLEND_ADD); + q->setBlendType(BLEND_ADD); q->scale = Vector(5,5); q->alpha.ensureData(); q->alpha.data->path.addPathNode(0, 0); diff --git a/Aquaria/Intro.cpp b/Aquaria/Intro.cpp index 645f610..4153496 100644 --- a/Aquaria/Intro.cpp +++ b/Aquaria/Intro.cpp @@ -139,7 +139,7 @@ void Intro::createMeteor(int layer, Vector pos, Vector off, Vector sz) m->rotationOffset.interpolateTo(Vector(0,0,-360), 2.5, -1); m->rotation.z = rand()%360; Quad *g = new Quad("particles/glow", Vector(0,0)); - g->setBlendType(RenderObject::BLEND_ADD); + g->setBlendType(BLEND_ADD); g->scale = Vector(24, 24); g->alpha = 0.5; g->color = Vector(1, 0.5, 0.5); @@ -800,7 +800,7 @@ void Intro::update(float dt) Quad *mom = new Quad("gameover-0004", Vector(400,300)); mom->setWidthHeight(600,600); mom->alphaMod = 0.035f; - mom->setBlendType(RenderObject::BLEND_ADD); + mom->setBlendType(BLEND_ADD); mom->alpha = 0; mom->alpha.interpolateTo(1, 5); mom->followCamera = 1; diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index 4ac7a60..0d3fb2d 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -158,7 +158,7 @@ public: addChild(glow, PM_POINTER, RBP_ON); glow->setWidthHeight(48, 64); glow->alpha = 0; - glow->setBlendType(RenderObject::BLEND_ADD); + glow->setBlendType(BLEND_ADD); scale = Vector(0.5, 0.5); scale.interpolateTo(Vector(1,1), 0.5, 0, 0, 1); diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 2340800..8effd81 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -599,6 +599,13 @@ Bone *bone(lua_State *L, int slot = 1) return b; } +static inline +BlendType getBlendType(lua_State *L, int slot = 1) +{ + int bt = lua_tointeger(L, slot); + return (BlendType)((bt >= BLEND_DEFAULT && bt < _BLEND_MAXSIZE) ? bt : BLEND_DISABLED); +} + static inline Path *pathFromName(lua_State *L, int slot = 1) { @@ -1230,14 +1237,16 @@ luaFunc(obj_setBlendType) { RenderObject *r = robj(L); if (r) - r->setBlendType(lua_tointeger(L, 2)); + { + r->setBlendType(getBlendType(L, 2)); + } luaReturnNil(); } luaFunc(obj_getBlendType) { RenderObject *r = robj(L); - luaReturnInt(r ? r->blendType : 0); + luaReturnInt(r ? r->getBlendType() : 0); } luaFunc(obj_setTexture) @@ -8134,7 +8143,7 @@ luaFunc(entity_partBlendType) { ScriptedEntity *e = scriptedEntity(L); if (e) - e->partMap[getString(L, 2)]->setBlendType(lua_tointeger(L, 3)); + e->partMap[getString(L, 2)]->setBlendType(getBlendType(L, 3)); luaReturnNil(); } @@ -8338,7 +8347,7 @@ luaFunc(entity_doGlint) { Entity *e = entity(L); if (e) - e->doGlint(e->position, Vector(2,2), getString(L,2), (RenderObject::BlendTypes)lua_tointeger(L, 3)); + e->doGlint(e->position, Vector(2,2), getString(L,2), getBlendType(L, 3)); luaReturnNil(); } @@ -11302,11 +11311,12 @@ static const struct { luaConstant(SONG_ANIMA), luaConstant(SONG_MAX), - luaConstantFromClass(BLEND_DEFAULT, RenderObject), - luaConstantFromClass(BLEND_ADD, RenderObject), - {"BLEND_ADDITIVE", RenderObject::BLEND_ADD}, - luaConstantFromClass(BLEND_SUB, RenderObject), - luaConstantFromClass(BLEND_MULT, RenderObject), + luaConstant(BLEND_DISABLED), + luaConstant(BLEND_DEFAULT), + luaConstant(BLEND_ADD), + {"BLEND_ADDITIVE", BLEND_ADD}, + luaConstant(BLEND_SUB), + luaConstant(BLEND_MULT), {"ENDING_NAIJACAVE", 10}, {"ENDING_NAIJACAVEDONE", 11}, diff --git a/Aquaria/Shot.cpp b/Aquaria/Shot.cpp index ba23315..f91241b 100644 --- a/Aquaria/Shot.cpp +++ b/Aquaria/Shot.cpp @@ -50,7 +50,7 @@ ShotData::ShotData() segScale = Vector(1,1); numSegs = 0; segDist = 16; - blendType = RenderObject::BLEND_DEFAULT; + blendType = BLEND_DEFAULT; collideRadius = 8; damageType = DT_ENEMY_ENERGYBLAST; lifeTime = 8; @@ -177,7 +177,7 @@ void ShotData::bankLoad(const std::string &file, const std::string &path) std::string bt; inf >> bt; if (bt == "BLEND_ADD") - blendType = RenderObject::BLEND_ADD; + blendType = BLEND_ADD; } else if (token == "Damage") { @@ -386,7 +386,7 @@ void Shot::applyShotData(ShotData *shotData) Quad *flame = new Quad; flame->setTexture(shotData->segTexture); flame->scale = shotData->segScale - Vector(shotData->segTaper, shotData->segTaper)*(i); - flame->setBlendType(this->blendType); + flame->setBlendType(this->getBlendType()); flame->alpha = 0.5; dsq->game->addRenderObject(flame, LR_PARTICLES); segments[i] = flame; diff --git a/Aquaria/Shot.h b/Aquaria/Shot.h index 90a0cc4..c58fce5 100644 --- a/Aquaria/Shot.h +++ b/Aquaria/Shot.h @@ -36,7 +36,7 @@ struct ShotData std::string hitPrt, trailPrt, firePrt, bouncePrt; std::string spawnEntity; BounceType bounceType; - int blendType; + BlendType blendType; bool segments; float damage; float maxSpeed, homing, homingMax; diff --git a/Aquaria/States.cpp b/Aquaria/States.cpp index 2ed1ac7..05f48f2 100644 --- a/Aquaria/States.cpp +++ b/Aquaria/States.cpp @@ -200,7 +200,7 @@ void GameOver::applyState() shockLines->setTexture("shock-lines"); shockLines->position = Vector(400,300); shockLines->setWidthHeight(800, 600); - shockLines->setBlendType(RenderObject::BLEND_ADD); + shockLines->setBlendType(BLEND_ADD); shockLines->scale.interpolateTo(Vector(4,4), 1); } addRenderObject(shockLines, LR_BACKGROUND); diff --git a/BBGE/Base.h b/BBGE/Base.h index fa8bf3a..63b7c30 100644 --- a/BBGE/Base.h +++ b/BBGE/Base.h @@ -40,6 +40,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define OVERRIDE #endif +namespace internal +{ + template + char (&_ArraySizeHelper( T (&a)[N]))[N]; + + template + 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) diff --git a/BBGE/CMakeLists.txt b/BBGE/CMakeLists.txt index 221128b..f887859 100644 --- a/BBGE/CMakeLists.txt +++ b/BBGE/CMakeLists.txt @@ -26,6 +26,7 @@ set(BBGE_SRCS Effects.cpp Effects.h Emitter.cpp + EngineEnums.h Event.cpp Event.h FmodOpenALBridge.cpp diff --git a/BBGE/EngineEnums.h b/BBGE/EngineEnums.h new file mode 100644 index 0000000..3794a2b --- /dev/null +++ b/BBGE/EngineEnums.h @@ -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 diff --git a/BBGE/ParticleEffect.cpp b/BBGE/ParticleEffect.cpp index 1c7c58a..7140146 100644 --- a/BBGE/ParticleEffect.cpp +++ b/BBGE/ParticleEffect.cpp @@ -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") { diff --git a/BBGE/Particles.h b/BBGE/Particles.h index edf445e..636b766 100644 --- a/BBGE/Particles.h +++ b/BBGE/Particles.h @@ -65,7 +65,7 @@ struct SpawnParticleData float life; InterpolatedVector spawnRate; std::string texture; - RenderObject::BlendTypes blendType; + BlendType blendType; float counter; float spawnTimeOffset; bool spawnLocal; diff --git a/BBGE/RenderObject.cpp b/BBGE/RenderObject.cpp index 4fbf16a..f353024 100644 --- a/BBGE/RenderObject.cpp +++ b/BBGE/RenderObject.cpp @@ -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; diff --git a/BBGE/RenderObject.h b/BBGE/RenderObject.h index 85254a9..61a2c99 100644 --- a/BBGE/RenderObject.h +++ b/BBGE/RenderObject.h @@ -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 @@ -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; - - enum BlendTypes { BLEND_DEFAULT = 0, BLEND_ADD, BLEND_SUB, BLEND_MULT }; - unsigned char blendType; - - float life; float followCamera; float alphaMod; diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index 89328bd..5ab3986 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -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")) diff --git a/BBGE/SpawnParticleData.cpp b/BBGE/SpawnParticleData.cpp index 60f3169..c02a216 100644 --- a/BBGE/SpawnParticleData.cpp +++ b/BBGE/SpawnParticleData.cpp @@ -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;