1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-29 03:33:48 +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 void Element::render(const RenderState& rs) const
{ {
if (!elementActive) return; if (!elementActive) return;
const RenderState *rsp = &rs;
if (dsq->game->isSceneEditorActive() && this->bgLayer == dsq->game->sceneEditor.bgLayer if (dsq->game->isSceneEditorActive() && this->bgLayer == dsq->game->sceneEditor.bgLayer
&& dsq->game->sceneEditor.editType == ET_ELEMENTS) && 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()) if (!dsq->game->sceneEditor.selectedElements.empty())
{ {
for (size_t i = 0; i < dsq->game->sceneEditor.selectedElements.size(); i++) for (size_t i = 0; i < dsq->game->sceneEditor.selectedElements.size(); i++)
{ {
if (this == dsq->game->sceneEditor.selectedElements[i]) if (this == dsq->game->sceneEditor.selectedElements[i])
renderBorderColor = Vector(1,1,1); rs2.renderBorderColor = Vector(1,1,1);
} }
} }
else else
{ {
if (dsq->game->sceneEditor.editingElement == this) if (dsq->game->sceneEditor.editingElement == this)
renderBorderColor = Vector(1,1,1); rs2.renderBorderColor = Vector(1,1,1);
} }
renderBorder = true;
} }
Quad::render(rs); Quad::render(*rsp);
renderBorder = false;
} }
void Element::fillGrid() void Element::fillGrid()

View file

@ -2479,15 +2479,7 @@ void Entity::render(const RenderState& rsold) const
scale *= flipScale; 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); RenderState rs(rsold);
rs.color *= color; rs.color *= color;
@ -2495,6 +2487,16 @@ void Entity::render(const RenderState& rsold) const
rs.color *= multColor; rs.color *= multColor;
rs.alpha *= alpha.x; 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: // if we have an override render pass set:
// from this point, render all children in this pass // from this point, render all children in this pass
// regardless of what they specify // regardless of what they specify
@ -2503,7 +2505,6 @@ void Entity::render(const RenderState& rsold) const
Quad::render(rs); Quad::render(rs);
renderBorder = false;
scale = bscale; scale = bscale;
} }

View file

@ -23,11 +23,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "RenderBase.h" #include "RenderBase.h"
#include <assert.h> #include <assert.h>
Vector Quad::renderBorderColor = Vector(1,1,1);
Quad::Quad(const std::string &tex, const Vector &pos) Quad::Quad(const std::string &tex, const Vector &pos)
: RenderObject() : RenderObject()
{ {
renderBorderColor = Vector(1,1,1);
initQuad(); initQuad();
position = pos; position = pos;
setTexture(tex); 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() Quad::Quad() : RenderObject()
{ {
addType(SCO_QUAD); addType(SCO_QUAD);
@ -409,35 +438,11 @@ void Quad::onRender(const RenderState& rs) const
renderGrid(rs); renderGrid(rs);
} }
if (renderBorder) if(renderBorder)
{ _renderBorder(rs, renderBorderColor, borderAlpha);
glLineWidth(2); 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 char autoWidth, autoHeight; // char to save space
bool renderQuad, renderCenter; bool renderQuad, renderCenter, renderBorder;
mutable bool renderBorder; // TODO: should be part of render state
Vector texOff; Vector texOff;
float borderAlpha; float borderAlpha;
Vector renderBorderColor;
Vector repeatToFillScale; Vector repeatToFillScale;
static void ResetGrid(Vector *dst, size_t w, size_t h); static void ResetGrid(Vector *dst, size_t w, size_t h);
@ -113,14 +113,13 @@ protected:
float drawGridTimeMultiplier; float drawGridTimeMultiplier;
bool drawGridOut; bool drawGridOut;
static Vector renderBorderColor;
void onSetTexture(); void onSetTexture();
void onRender(const RenderState& rs) const OVERRIDE; void onRender(const RenderState& rs) const OVERRIDE;
void onUpdate(float dt); void onUpdate(float dt);
private: private:
bool doUpdateGrid; bool doUpdateGrid;
void initQuad(); void initQuad();
void _renderBorder(const RenderState& rs, Vector color, float borderalpha) const;
}; };
class PauseQuad : public Quad class PauseQuad : public Quad

View file

@ -5,6 +5,7 @@
RenderState::RenderState(GPUState &gpu) RenderState::RenderState(GPUState &gpu)
: gpu(gpu), color(1,1,1), alpha(1), pass(0) : 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; float alpha;
int pass; int pass;
bool forceRenderBorder;
bool forceRenderCenter;
Vector renderBorderColor;
float renderBorderAlpha;
protected: protected:
RenderState(GPUState& gpu); RenderState(GPUState& gpu);
}; };