From 5c558c122f4036f31f4136051b4638e87b43e518 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 21 May 2022 16:31:10 +0200 Subject: [PATCH] Remove RenderObject::setColorMult() hack and related members --- Aquaria/Avatar.cpp | 6 +-- Aquaria/Entity.cpp | 20 ++++------ BBGE/Core.h | 2 - BBGE/Quad.cpp | 16 ++++---- BBGE/Quad.h | 3 +- BBGE/RenderObject.cpp | 76 ++++++++------------------------------ BBGE/RenderObject.h | 10 +---- BBGE/RenderObjectLayer.cpp | 2 - BBGE/RenderRect.cpp | 14 ------- 9 files changed, 36 insertions(+), 113 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index bedd1ef..9dd6c57 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -4452,10 +4452,10 @@ void Avatar::render(const RenderState& rs) const if (dsq->continuity.form == FORM_SPIRIT && !skeletalSprite.getParent()) { + RenderState rx(rs); + rx.color = Vector(0.2f, 0.3f, 0.6f); skeletalSprite.position = bodyPosition+bodyOffset; - skeletalSprite.color = Vector(0.2f, 0.3f, 0.6f); - skeletalSprite.render(rs); - skeletalSprite.color = Vector(1,1,1); + skeletalSprite.render(rx); } Entity::render(rs); diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index c5f9346..9600515 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -2477,16 +2477,12 @@ void Entity::doEntityAvoidance(float dt, int range, float mod, Entity *ignore) } } -void Entity::render(const RenderState& rs) const +void Entity::render(const RenderState& rsold) const { - InterpolatedVector bcolor = color; InterpolatedVector bscale = scale; scale *= flipScale; - if (multColor.isInterpolating()) - { - color *= multColor; - } + if (dsq->game->isSceneEditorActive() && dsq->game->sceneEditor.editType == ET_ENTITIES) { @@ -2498,17 +2494,15 @@ void Entity::render(const RenderState& rs) const } - // HACK: need to multiply base + etc - skeletalSprite.setColorMult(this->color, this->alpha.x); - + RenderState rs(rsold); + rs.color *= color; + if (multColor.isInterpolating()) + rs.color *= multColor; + rs.alpha *= alpha.x; Quad::render(rs); - - renderBorder = false; - skeletalSprite.clearColorMult(); - color = bcolor; scale = bscale; } diff --git a/BBGE/Core.h b/BBGE/Core.h index c69fb21..6bd8312 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -164,8 +164,6 @@ public: bool update; - Vector color; - protected: inline void renderOneObject(const RenderState& rs, const RenderObject *robj); diff --git a/BBGE/Quad.cpp b/BBGE/Quad.cpp index 385bc24..e670d58 100644 --- a/BBGE/Quad.cpp +++ b/BBGE/Quad.cpp @@ -315,7 +315,7 @@ void Quad::updateGrid(float dt) } } -void Quad::renderGrid() const +void Quad::renderGrid(const RenderState& rs) const { if (xDivs < 2 || yDivs < 2) return; @@ -340,10 +340,10 @@ void Quad::renderGrid() const const float w = this->getWidth(); const float h = this->getHeight(); - const float red = this->color.x; - const float green = this->color.y; - const float blue = this->color.z; - const float alpha = this->alpha.x * this->alphaMod; + const float red = rs.color.x * this->color.x; + const float green = rs.color.y * this->color.y; + const float blue = rs.color.z * this->color.z; + const float alpha = rs.alpha * this->alpha.x * this->alphaMod; glBegin(GL_QUADS); @@ -422,8 +422,8 @@ void Quad::onRender(const RenderState& rs) const if (!renderQuad) return; - float _w2 = width/2.0f; - float _h2 = height/2.0f; + float _w2 = width*0.5f; + float _h2 = height*0.5f; if (!strip.empty()) { @@ -480,7 +480,7 @@ void Quad::onRender(const RenderState& rs) const } else { - renderGrid(); + renderGrid(rs); } } diff --git a/BBGE/Quad.h b/BBGE/Quad.h index fe8a7f5..a02273e 100644 --- a/BBGE/Quad.h +++ b/BBGE/Quad.h @@ -30,7 +30,6 @@ public: void setWidthHeight(int w, int h); void setLineSize(int ls); - bool renderCenter; protected: int w, h, w2, h2; @@ -103,7 +102,7 @@ protected: void resetGrid(); void updateGrid(float dt); - void renderGrid() const; + void renderGrid(const RenderState& rs) const; float drawGridOffsetX; diff --git a/BBGE/RenderObject.cpp b/BBGE/RenderObject.cpp index ff2715e..bec0234 100644 --- a/BBGE/RenderObject.cpp +++ b/BBGE/RenderObject.cpp @@ -55,44 +55,6 @@ int RenderObject::getTopLayer() const return layer; } -void RenderObject::setColorMult(const Vector &color, const float alpha) const -{ - if (colorIsSaved) - { - debugLog("setColorMult() WARNING: can't do nested multiplies"); - return; - } - this->colorIsSaved = true; - this->savedColor.x = this->color.x; - this->savedColor.y = this->color.y; - this->savedColor.z = this->color.z; - this->savedAlpha = this->alpha.x; - this->color *= color; - this->alpha.x *= alpha; - for (Children::const_iterator i = children.begin(); i != children.end(); i++) - { - (*i)->setColorMult(color, alpha); - } -} - -void RenderObject::clearColorMult() const -{ - if (!colorIsSaved) - { - debugLog("clearColorMult() WARNING: no saved color to restore"); - return; - } - this->color.x = this->savedColor.x; - this->color.y = this->savedColor.y; - this->color.z = this->savedColor.z; - this->alpha.x = this->savedAlpha; - this->colorIsSaved = false; - for (Children::const_iterator i = children.begin(); i != children.end(); i++) - { - (*i)->clearColorMult(); - } -} - RenderObject::RenderObject() { addType(SCO_RENDEROBJECT); @@ -136,8 +98,6 @@ RenderObject::RenderObject() renderBeforeParent = false; - - colorIsSaved = false; shareAlphaWithChildren = false; shareColorWithChildren = false; } @@ -500,21 +460,20 @@ void RenderObject::render(const RenderState& rs) const if (MotionBlurData *mb = this->motionBlur) { + RenderState rx(rs); const Vector oldPos = position; - const float oldAlpha = alpha.x; const float oldRotZ = rotation.z; const size_t sz = mb->positions.size(); const float m = 1.0f / float(sz); - const float m2 = 0.5f * (mb->transition ? mb->transitionTimer : 1.0f); + const float m2 = alpha.x * 0.5f * (mb->transition ? mb->transitionTimer : 1.0f); for (size_t i = 0; i < sz; i++) { position = mb->positions[i].position; rotation.z = mb->positions[i].rotz; - alpha = (1.0f-(float(i) * m)) * m2; - renderCall(rs); + rx.alpha = (1.0f-(float(i) * m)) * m2; + renderCall(rx); } position = oldPos; - alpha.x = oldAlpha; rotation.z = oldRotZ; } @@ -608,22 +567,12 @@ void RenderObject::renderCall(const RenderState& rs) const glScalef(scale.x, scale.y, 1); glTranslatef(internalOffset.x, internalOffset.y, internalOffset.z); - for (Children::const_iterator i = children.begin(); i != children.end(); i++) { if (!(*i)->isDead() && (*i)->renderBeforeParent) (*i)->render(rs); } - - { - Vector col = color; - if (rlayer) - col *= rlayer->color; - - glColor4f(col.x, col.y, col.z, alpha.x*alphaMod); - } - if (texture) { @@ -644,8 +593,6 @@ void RenderObject::renderCall(const RenderState& rs) const } } - rs.gpu.setBlend(getBlendType()); - bool doRender = true; int pass = renderPass; @@ -661,12 +608,21 @@ void RenderObject::renderCall(const RenderState& rs) const doRender = (core->currentLayerPass == pass); } - if (renderCollisionShape) - renderCollision(rs); - if (doRender) + { + // RenderState color applies to everything in the scene graph, + // so that needs to be multiplied in unconditionally + { + Vector col = this->color * rs.color; + glColor4f(color.x, color.y, color.z, rs.alpha*alpha.x*alphaMod); + } + rs.gpu.setBlend(getBlendType()); onRender(rs); + if (renderCollisionShape) + renderCollision(rs); + } + for (Children::const_iterator i = children.begin(); i != children.end(); i++) { diff --git a/BBGE/RenderObject.h b/BBGE/RenderObject.h index 8e7c22b..55a1047 100644 --- a/BBGE/RenderObject.h +++ b/BBGE/RenderObject.h @@ -164,9 +164,6 @@ public: int getTopLayer() const; - void setColorMult(const Vector &color, const float alpha) const; // HACK: const - void clearColorMult() const; // HACK: const - void enableMotionBlur(int sz=10, int off=5); void disableMotionBlur(); @@ -254,7 +251,7 @@ public: mutable InterpolatedVector position, scale; - mutable InterpolatedVector color, alpha; // HACK: mutable should go! this is for setColorMult() + InterpolatedVector color, alpha; mutable InterpolatedVector rotation; InterpolatedVector offset, rotationOffset, internalOffset, beforeScaleOffset; InterpolatedVector velocity, gravity; @@ -275,11 +272,6 @@ public: int renderPass; float overrideCullRadiusSqr; - // --- This is hack and should not exist --- - mutable bool colorIsSaved; // Used for both color and alpha - mutable Vector savedColor; // Saved values from setColorMult() - mutable float savedAlpha; - float width, height; // Only used by Quads, but stored here for getCullRadius() diff --git a/BBGE/RenderObjectLayer.cpp b/BBGE/RenderObjectLayer.cpp index bc27f80..6adea99 100644 --- a/BBGE/RenderObjectLayer.cpp +++ b/BBGE/RenderObjectLayer.cpp @@ -32,8 +32,6 @@ RenderObjectLayer::RenderObjectLayer() followCameraLock = FCL_NONE; update = true; - color = Vector(1,1,1); - const int size = renderObjects.size(); for (int i = 0; i < size; i++) renderObjects[i] = 0; diff --git a/BBGE/RenderRect.cpp b/BBGE/RenderRect.cpp index 77a616e..21ddb7b 100644 --- a/BBGE/RenderRect.cpp +++ b/BBGE/RenderRect.cpp @@ -24,7 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. OutlineRect::OutlineRect() : RenderObject() { lineSize = 1; - renderCenter = false; } void OutlineRect::setWidthHeight(int w, int h) @@ -57,19 +56,6 @@ void OutlineRect::onRender(const RenderState& rs) const glVertex2f(-w2,h2); glVertex2f(w2,h2); glEnd(); - - if (renderCenter) - { - glColor3f(0.9f, 0.9f, 1); - glBegin(GL_LINES); - // lr - glVertex2f(-w2,0); - glVertex2f(w2,0); - // ud - glVertex2f(0,-h2); - glVertex2f(0,h2); - glEnd(); - } }