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

Remove RenderObject::setColorMult() hack and related members

This commit is contained in:
fgenesis 2022-05-21 16:31:10 +02:00
parent cec6bc5ebf
commit 5c558c122f
9 changed files with 36 additions and 113 deletions

View file

@ -4452,10 +4452,10 @@ void Avatar::render(const RenderState& rs) const
if (dsq->continuity.form == FORM_SPIRIT && !skeletalSprite.getParent()) 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.position = bodyPosition+bodyOffset;
skeletalSprite.color = Vector(0.2f, 0.3f, 0.6f); skeletalSprite.render(rx);
skeletalSprite.render(rs);
skeletalSprite.color = Vector(1,1,1);
} }
Entity::render(rs); Entity::render(rs);

View file

@ -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; InterpolatedVector bscale = scale;
scale *= flipScale; scale *= flipScale;
if (multColor.isInterpolating())
{
color *= multColor;
}
if (dsq->game->isSceneEditorActive() && dsq->game->sceneEditor.editType == ET_ENTITIES) 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 RenderState rs(rsold);
skeletalSprite.setColorMult(this->color, this->alpha.x); rs.color *= color;
if (multColor.isInterpolating())
rs.color *= multColor;
rs.alpha *= alpha.x;
Quad::render(rs); Quad::render(rs);
renderBorder = false; renderBorder = false;
skeletalSprite.clearColorMult();
color = bcolor;
scale = bscale; scale = bscale;
} }

View file

@ -164,8 +164,6 @@ public:
bool update; bool update;
Vector color;
protected: protected:
inline void renderOneObject(const RenderState& rs, const RenderObject *robj); inline void renderOneObject(const RenderState& rs, const RenderObject *robj);

View file

@ -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) if (xDivs < 2 || yDivs < 2)
return; return;
@ -340,10 +340,10 @@ void Quad::renderGrid() const
const float w = this->getWidth(); const float w = this->getWidth();
const float h = this->getHeight(); const float h = this->getHeight();
const float red = this->color.x; const float red = rs.color.x * this->color.x;
const float green = this->color.y; const float green = rs.color.y * this->color.y;
const float blue = this->color.z; const float blue = rs.color.z * this->color.z;
const float alpha = this->alpha.x * this->alphaMod; const float alpha = rs.alpha * this->alpha.x * this->alphaMod;
glBegin(GL_QUADS); glBegin(GL_QUADS);
@ -422,8 +422,8 @@ void Quad::onRender(const RenderState& rs) const
if (!renderQuad) return; if (!renderQuad) return;
float _w2 = width/2.0f; float _w2 = width*0.5f;
float _h2 = height/2.0f; float _h2 = height*0.5f;
if (!strip.empty()) if (!strip.empty())
{ {
@ -480,7 +480,7 @@ void Quad::onRender(const RenderState& rs) const
} }
else else
{ {
renderGrid(); renderGrid(rs);
} }
} }

View file

@ -30,7 +30,6 @@ public:
void setWidthHeight(int w, int h); void setWidthHeight(int w, int h);
void setLineSize(int ls); void setLineSize(int ls);
bool renderCenter;
protected: protected:
int w, h, w2, h2; int w, h, w2, h2;
@ -103,7 +102,7 @@ protected:
void resetGrid(); void resetGrid();
void updateGrid(float dt); void updateGrid(float dt);
void renderGrid() const; void renderGrid(const RenderState& rs) const;
float drawGridOffsetX; float drawGridOffsetX;

View file

@ -55,44 +55,6 @@ int RenderObject::getTopLayer() const
return layer; 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() RenderObject::RenderObject()
{ {
addType(SCO_RENDEROBJECT); addType(SCO_RENDEROBJECT);
@ -136,8 +98,6 @@ RenderObject::RenderObject()
renderBeforeParent = false; renderBeforeParent = false;
colorIsSaved = false;
shareAlphaWithChildren = false; shareAlphaWithChildren = false;
shareColorWithChildren = false; shareColorWithChildren = false;
} }
@ -500,21 +460,20 @@ void RenderObject::render(const RenderState& rs) const
if (MotionBlurData *mb = this->motionBlur) if (MotionBlurData *mb = this->motionBlur)
{ {
RenderState rx(rs);
const Vector oldPos = position; const Vector oldPos = position;
const float oldAlpha = alpha.x;
const float oldRotZ = rotation.z; const float oldRotZ = rotation.z;
const size_t sz = mb->positions.size(); const size_t sz = mb->positions.size();
const float m = 1.0f / float(sz); 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++) for (size_t i = 0; i < sz; i++)
{ {
position = mb->positions[i].position; position = mb->positions[i].position;
rotation.z = mb->positions[i].rotz; rotation.z = mb->positions[i].rotz;
alpha = (1.0f-(float(i) * m)) * m2; rx.alpha = (1.0f-(float(i) * m)) * m2;
renderCall(rs); renderCall(rx);
} }
position = oldPos; position = oldPos;
alpha.x = oldAlpha;
rotation.z = oldRotZ; rotation.z = oldRotZ;
} }
@ -608,22 +567,12 @@ void RenderObject::renderCall(const RenderState& rs) const
glScalef(scale.x, scale.y, 1); glScalef(scale.x, scale.y, 1);
glTranslatef(internalOffset.x, internalOffset.y, internalOffset.z); glTranslatef(internalOffset.x, internalOffset.y, internalOffset.z);
for (Children::const_iterator i = children.begin(); i != children.end(); i++) for (Children::const_iterator i = children.begin(); i != children.end(); i++)
{ {
if (!(*i)->isDead() && (*i)->renderBeforeParent) if (!(*i)->isDead() && (*i)->renderBeforeParent)
(*i)->render(rs); (*i)->render(rs);
} }
{
Vector col = color;
if (rlayer)
col *= rlayer->color;
glColor4f(col.x, col.y, col.z, alpha.x*alphaMod);
}
if (texture) if (texture)
{ {
@ -644,8 +593,6 @@ void RenderObject::renderCall(const RenderState& rs) const
} }
} }
rs.gpu.setBlend(getBlendType());
bool doRender = true; bool doRender = true;
int pass = renderPass; int pass = renderPass;
@ -661,12 +608,21 @@ void RenderObject::renderCall(const RenderState& rs) const
doRender = (core->currentLayerPass == pass); doRender = (core->currentLayerPass == pass);
} }
if (renderCollisionShape)
renderCollision(rs);
if (doRender) 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); onRender(rs);
if (renderCollisionShape)
renderCollision(rs);
}
for (Children::const_iterator i = children.begin(); i != children.end(); i++) for (Children::const_iterator i = children.begin(); i != children.end(); i++)
{ {

View file

@ -164,9 +164,6 @@ public:
int getTopLayer() const; 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 enableMotionBlur(int sz=10, int off=5);
void disableMotionBlur(); void disableMotionBlur();
@ -254,7 +251,7 @@ public:
mutable InterpolatedVector position, scale; mutable InterpolatedVector position, scale;
mutable InterpolatedVector color, alpha; // HACK: mutable should go! this is for setColorMult() InterpolatedVector color, alpha;
mutable InterpolatedVector rotation; mutable InterpolatedVector rotation;
InterpolatedVector offset, rotationOffset, internalOffset, beforeScaleOffset; InterpolatedVector offset, rotationOffset, internalOffset, beforeScaleOffset;
InterpolatedVector velocity, gravity; InterpolatedVector velocity, gravity;
@ -275,11 +272,6 @@ public:
int renderPass; int renderPass;
float overrideCullRadiusSqr; 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() float width, height; // Only used by Quads, but stored here for getCullRadius()

View file

@ -32,8 +32,6 @@ RenderObjectLayer::RenderObjectLayer()
followCameraLock = FCL_NONE; followCameraLock = FCL_NONE;
update = true; update = true;
color = Vector(1,1,1);
const int size = renderObjects.size(); const int size = renderObjects.size();
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
renderObjects[i] = 0; renderObjects[i] = 0;

View file

@ -24,7 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
OutlineRect::OutlineRect() : RenderObject() OutlineRect::OutlineRect() : RenderObject()
{ {
lineSize = 1; lineSize = 1;
renderCenter = false;
} }
void OutlineRect::setWidthHeight(int w, int h) void OutlineRect::setWidthHeight(int w, int h)
@ -57,19 +56,6 @@ void OutlineRect::onRender(const RenderState& rs) const
glVertex2f(-w2,h2); glVertex2f(-w2,h2);
glVertex2f(w2,h2); glVertex2f(w2,h2);
glEnd(); 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();
}
} }