1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 09:44:02 +00:00

render: remove one mutable hack, border color is now per-quad

This commit is contained in:
fgenesis 2022-09-24 04:57:08 +02:00
parent e47d253945
commit cfa5d45932
6 changed files with 65 additions and 50 deletions

View file

@ -283,30 +283,34 @@ void Element::setElementEffectByIndex(int eidx)
void Element::render(const RenderState& rs) const
{
if (!elementActive) return;
const RenderState *rsp = &rs;
if (dsq->game->isSceneEditorActive() && this->bgLayer == dsq->game->sceneEditor.bgLayer
&& dsq->game->sceneEditor.editType == ET_ELEMENTS)
{
renderBorderColor = Vector(0.5,0.5,0.5);
RenderState rs2(rs);
rsp = &rs2;
rs2.forceRenderBorder = true;
rs2.forceRenderCenter = true;
rs2.renderBorderColor = Vector(0.5f, 0.5f, 0.5f);
if (!dsq->game->sceneEditor.selectedElements.empty())
{
for (size_t i = 0; i < dsq->game->sceneEditor.selectedElements.size(); i++)
{
if (this == dsq->game->sceneEditor.selectedElements[i])
renderBorderColor = Vector(1,1,1);
rs2.renderBorderColor = Vector(1,1,1);
}
}
else
{
if (dsq->game->sceneEditor.editingElement == this)
renderBorderColor = Vector(1,1,1);
rs2.renderBorderColor = Vector(1,1,1);
}
renderBorder = true;
}
Quad::render(rs);
renderBorder = false;
Quad::render(*rsp);
}
void Element::fillGrid()

View file

@ -2479,15 +2479,7 @@ void Entity::render(const RenderState& rsold) const
scale *= flipScale;
if (dsq->game->isSceneEditorActive() && dsq->game->sceneEditor.editType == ET_ENTITIES)
{
if (dsq->game->sceneEditor.editingEntity == this)
renderBorderColor = Vector(1,1,1);
else
renderBorderColor = Vector(0.5,0.5,0.5);
renderBorder = true;
}
RenderState rs(rsold);
rs.color *= color;
@ -2495,6 +2487,16 @@ void Entity::render(const RenderState& rsold) const
rs.color *= multColor;
rs.alpha *= alpha.x;
if (dsq->game->isSceneEditorActive() && dsq->game->sceneEditor.editType == ET_ENTITIES)
{
if (dsq->game->sceneEditor.editingEntity == this)
rs.renderBorderColor = Vector(1,1,1);
else
rs.renderBorderColor = Vector(0.5,0.5,0.5);
rs.forceRenderBorder = true;
}
// if we have an override render pass set:
// from this point, render all children in this pass
// regardless of what they specify
@ -2503,7 +2505,6 @@ void Entity::render(const RenderState& rsold) const
Quad::render(rs);
renderBorder = false;
scale = bscale;
}

View file

@ -23,11 +23,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "RenderBase.h"
#include <assert.h>
Vector Quad::renderBorderColor = Vector(1,1,1);
Quad::Quad(const std::string &tex, const Vector &pos)
: RenderObject()
{
renderBorderColor = Vector(1,1,1);
initQuad();
position = pos;
setTexture(tex);
@ -166,6 +165,36 @@ void Quad::initQuad()
}
void Quad::_renderBorder(const RenderState& rs, Vector color, float borderalpha) const
{
glBindTexture(GL_TEXTURE_2D, 0);
if (rs.forceRenderCenter || renderCenter)
{
glColor4f(color.x, color.y, color.z, borderalpha*alpha.x*alphaMod);
glPointSize(16);
glBegin(GL_POINTS);
glVertex2f(0,0);
glEnd();
}
glColor4f(color.x, color.y, color.z, alpha.x*alphaMod);
glLineWidth(2);
const float _w2 = width*0.5f;
const float _h2 = height*0.5f;
glBegin(GL_LINES);
glVertex2f(-_w2, _h2);
glVertex2f(_w2, _h2);
glVertex2f(_w2, -_h2);
glVertex2f(_w2, _h2);
glVertex2f(-_w2, -_h2);
glVertex2f(-_w2, _h2);
glVertex2f(-_w2, -_h2);
glVertex2f(_w2, -_h2);
glEnd();
RenderObject::lastTextureApplied = 0;
}
Quad::Quad() : RenderObject()
{
addType(SCO_QUAD);
@ -409,35 +438,11 @@ void Quad::onRender(const RenderState& rs) const
renderGrid(rs);
}
if (renderBorder)
{
glLineWidth(2);
if(renderBorder)
_renderBorder(rs, renderBorderColor, borderAlpha);
else if(rs.forceRenderBorder)
_renderBorder(rs, rs.renderBorderColor, rs.renderBorderAlpha);
glBindTexture(GL_TEXTURE_2D, 0);
glColor4f(renderBorderColor.x, renderBorderColor.y, renderBorderColor.z, borderAlpha*alpha.x*alphaMod);
if (renderCenter)
{
glPointSize(16);
glBegin(GL_POINTS);
glVertex2f(0,0);
glEnd();
}
glColor4f(renderBorderColor.x, renderBorderColor.y, renderBorderColor.z, 1*alpha.x*alphaMod);
glBegin(GL_LINES);
glVertex2f(-_w2, _h2);
glVertex2f(_w2, _h2);
glVertex2f(_w2, -_h2);
glVertex2f(_w2, _h2);
glVertex2f(-_w2, -_h2);
glVertex2f(-_w2, _h2);
glVertex2f(-_w2, -_h2);
glVertex2f(_w2, -_h2);
glEnd();
RenderObject::lastTextureApplied = 0;
}
}

View file

@ -86,11 +86,11 @@ public:
char autoWidth, autoHeight; // char to save space
bool renderQuad, renderCenter;
mutable bool renderBorder; // TODO: should be part of render state
bool renderQuad, renderCenter, renderBorder;
Vector texOff;
float borderAlpha;
Vector renderBorderColor;
Vector repeatToFillScale;
static void ResetGrid(Vector *dst, size_t w, size_t h);
@ -113,14 +113,13 @@ protected:
float drawGridTimeMultiplier;
bool drawGridOut;
static Vector renderBorderColor;
void onSetTexture();
void onRender(const RenderState& rs) const OVERRIDE;
void onUpdate(float dt);
private:
bool doUpdateGrid;
void initQuad();
void _renderBorder(const RenderState& rs, Vector color, float borderalpha) const;
};
class PauseQuad : public Quad

View file

@ -5,6 +5,7 @@
RenderState::RenderState(GPUState &gpu)
: gpu(gpu), color(1,1,1), alpha(1), pass(0)
, forceRenderBorder(false), forceRenderCenter(false), renderBorderAlpha(1)
{
}

View file

@ -29,6 +29,11 @@ struct RenderState
float alpha;
int pass;
bool forceRenderBorder;
bool forceRenderCenter;
Vector renderBorderColor;
float renderBorderAlpha;
protected:
RenderState(GPUState& gpu);
};