1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-03 10:04:01 +00:00

Add RenderState to be passed through the scene graph

This will eventually handle all mutable state during rendering
This commit is contained in:
fgenesis 2022-05-20 01:04:19 +02:00
parent b6c5d90d3a
commit 68b3c61852
57 changed files with 201 additions and 150 deletions

View file

@ -35,7 +35,7 @@ const int KEYFRAME_POS_Y = 570;
class TimelineRender : public RenderObject
{
void onRender() const OVERRIDE
void onRender(const RenderState& rs) const OVERRIDE
{
glLineWidth(1);
glBegin(GL_LINES);

View file

@ -4447,18 +4447,18 @@ void Avatar::doShieldSong()
activateAura(AURA_SHIELD);
}
void Avatar::render() const
void Avatar::render(const RenderState& rs) const
{
if (dsq->continuity.form == FORM_SPIRIT && !skeletalSprite.getParent())
{
skeletalSprite.position = bodyPosition+bodyOffset;
skeletalSprite.color = Vector(0.2f, 0.3f, 0.6f);
skeletalSprite.render();
skeletalSprite.render(rs);
skeletalSprite.color = Vector(1,1,1);
}
Entity::render();
Entity::render(rs);
}

View file

@ -211,7 +211,7 @@ public:
float biteDelay, urchinDelay, jellyDelay;
bool movingOn;
void render() const OVERRIDE;
void render(const RenderState& rs) const OVERRIDE;
void activateAura(AuraType aura);
void stopAura();
void setHeadTexture(const std::string &name, float t=0);

View file

@ -105,7 +105,7 @@ void Beam::trace()
}
void Beam::onRender() const
void Beam::onRender(const RenderState& rs) const
{
Vector diff = endPos - position;

View file

@ -27,7 +27,7 @@ public:
void setBeamWidth(float w);
protected:
float beamWidth;
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
void onEndOfLife();
void onUpdate(float dt);
};

View file

@ -30,11 +30,11 @@ CurrentRender::CurrentRender() : RenderObject()
cull = false;
setTexture("Particles/Current");
texture->repeat = true;
repeatTexture = true;
rippleDelay = 2;
}
void CurrentRender::onRender() const
void CurrentRender::onRender(const RenderState& rs) const
{
// note: Leave cull_face disabled!?
//glDisable(GL_CULL_FACE);

View file

@ -283,7 +283,7 @@ void Element::setElementEffectByIndex(int eidx)
}
}
void Element::render() const
void Element::render(const RenderState& rs) const
{
if (!elementActive) return;
if (dsq->game->isSceneEditorActive() && this->bgLayer == dsq->game->sceneEditor.bgLayer
@ -307,7 +307,7 @@ void Element::render() const
}
Quad::render();
Quad::render(rs);
renderBorder = false;
}

View file

@ -66,7 +66,7 @@ public:
size_t templateIdx;
int bgLayer;
Element *bgLayerNext;
void render() const OVERRIDE;
void render(const RenderState& rs) const OVERRIDE;
ElementFlag elementFlag;
void fillGrid();
bool isElementActive() { return elementActive; }

View file

@ -2474,7 +2474,7 @@ void Entity::doEntityAvoidance(float dt, int range, float mod, Entity *ignore)
}
}
void Entity::render() const
void Entity::render(const RenderState& rs) const
{
InterpolatedVector bcolor = color;
InterpolatedVector bscale = scale;
@ -2499,7 +2499,7 @@ void Entity::render() const
skeletalSprite.setColorMult(this->color, this->alpha.x);
Quad::render();
Quad::render(rs);

View file

@ -73,7 +73,7 @@ public:
Vector vel;
InterpolatedVector vel2;
float activationRadius;
void render() const OVERRIDE;
void render(const RenderState& rs) const OVERRIDE;
void update(float dt);
void spawnParticlesFromCollisionMask(const char *p, unsigned intv=1, int layer = LR_PARTICLES, float rotz = 0);

View file

@ -4160,7 +4160,7 @@ void Game::setParallaxTextureCoordinates(Quad *q, float speed)
{
//int backgroundImageRepeat = 1.2;
q->followCamera = 1;
q->texture->repeat = true;
q->repeatTexture = true;
float camx = (core->cameraPos.x/800.0f)*speed;
float camy = -(core->cameraPos.y/600.0f)*speed;

View file

@ -53,7 +53,7 @@ inline static void doRenderGrid(int x, int startCol, int endCol)
}
void GridRender::onRender() const
void GridRender::onRender(const RenderState& rs) const
{
const signed char obsType = this->obsType;
Vector camPos = core->cameraPos;
@ -145,7 +145,7 @@ void SongLineRender::clear()
pts.clear();
}
void SongLineRender::onRender() const
void SongLineRender::onRender(const RenderState& rs) const
{
int w=core->getWindowWidth();

View file

@ -39,7 +39,7 @@ public:
protected:
ObsType obsType;
void onUpdate(float dt);
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
};
class MiniMapRender : public RenderObject
@ -67,7 +67,7 @@ protected:
bool doRender;
float lightLevel;
void onUpdate(float dt);
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
void renderIcon(const MinimapIcon *ico, const Vector& pos) const;
InterpolatedVector lerp;
@ -127,7 +127,7 @@ class PathRender : public RenderObject
public:
PathRender();
protected:
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
};
class CurrentRender : public RenderObject
@ -136,7 +136,7 @@ public:
CurrentRender();
protected:
float rippleDelay;
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
};
class SteamRender : public RenderObject
@ -145,7 +145,7 @@ public:
SteamRender();
protected:
float rippleDelay;
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
};
struct SongLinePoint
@ -161,7 +161,7 @@ public:
void newPoint(const Vector &pt, const Vector &color);
void clear();
protected:
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
std::vector<SongLinePoint> pts;
};

View file

@ -73,7 +73,7 @@ HairNode *Hair::getHairNode(int idx)
return h;
}
void Hair::onRender() const
void Hair::onRender(const RenderState& rs) const
{

View file

@ -56,7 +56,7 @@ public:
protected:
float segmentLength;
void onUpdate(float dt);
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
};
#endif

View file

@ -474,7 +474,7 @@ void MiniMapRender::onUpdate(float dt)
toggleOn && dsq->game->avatar && dsq->game->avatar->getState() != Entity::STATE_TITLE && !(dsq->disableMiniMapOnNoInput && !dsq->game->avatar->isInputEnabled());
}
void MiniMapRender::onRender() const
void MiniMapRender::onRender(const RenderState& rs) const
{
glBindTexture(GL_TEXTURE_2D, 0);

View file

@ -30,7 +30,7 @@ PathRender::PathRender() : RenderObject()
alpha = 0.5f;
}
void PathRender::onRender() const
void PathRender::onRender(const RenderState& rs) const
{
const size_t pathcount = dsq->game->getNumPaths();
if (pathcount == 0)

View file

@ -51,7 +51,7 @@ public:
void destroy();
protected:
void onUpdate(float dt);
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
};
#endif

View file

@ -29,12 +29,12 @@ SteamRender::SteamRender() : RenderObject()
alpha = 0.7f;
setTexture("Particles/Steam");
texture->repeat = true;
repeatTexture = true;
rippleDelay = 2;
setBlendType(BLEND_ADD);
}
void SteamRender::onRender() const
void SteamRender::onRender(const RenderState& rs) const
{

View file

@ -49,7 +49,7 @@ void Strand::onUpdate(float dt)
updateSegments(position);
}
void Strand::onRender() const
void Strand::onRender(const RenderState& rs) const
{
const int numSegments = segments.size();
if (numSegments == 0) return;

View file

@ -129,10 +129,10 @@ void ToolTip::onUpdate(float dt)
}
}
void ToolTip::render() const
void ToolTip::render(const RenderState& rs) const
{
if (!game->getInGameMenu()->recipeMenu.on && toolTipsOn)
{
RenderObject::render();
RenderObject::render(rs);
}
}

View file

@ -35,7 +35,7 @@ public:
void setAreaFromCenter(const Vector &center, int width, int height);
void setCircularAreaFromCenter(const Vector &center, int diameter);
void render() const OVERRIDE;
void render(const RenderState& rs) const OVERRIDE;
static bool toolTipsOn;

View file

@ -99,8 +99,6 @@ void WaterSurfaceRender::onUpdate(float dt)
{
qSurface->alphaMod = 0.5;
}
Quad::render();
}
else
{
@ -130,13 +128,13 @@ void WaterSurfaceRender::onUpdate(float dt)
}
}
void WaterSurfaceRender::render() const
void WaterSurfaceRender::render(const RenderState& rs) const
{
if (dsq->game->waterLevel.x > 0)
Quad::render();
Quad::render(rs);
}
void WaterSurfaceRender::onRender() const
void WaterSurfaceRender::onRender(const RenderState& rs) const
{
if (dsq->game->waterLevel == 0) return;
if (dsq->useFrameBuffer && dsq->frameBuffer.isInited())
@ -149,7 +147,7 @@ void WaterSurfaceRender::onRender() const
glColor4f(0.4f, 0.7f, 0.8f, 0.2f);
}
Quad::onRender();
Quad::onRender(rs);
glBindTexture(GL_TEXTURE_2D, 0);

View file

@ -27,10 +27,10 @@ class WaterSurfaceRender : public Quad
{
public:
WaterSurfaceRender();
void render() const OVERRIDE;
void render(const RenderState& rs) const OVERRIDE;
protected:
Quad *qSurface, *qLine, *qLine2;
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
void onUpdate(float dt) OVERRIDE;
};

View file

@ -135,7 +135,7 @@ void Web::onUpdate(float dt)
}
}
void Web::onRender() const
void Web::onRender(const RenderState& rs) const
{
glBindTexture(GL_TEXTURE_2D, 0);

View file

@ -44,7 +44,7 @@ protected:
void onEndOfLife();
std::vector<Vector> points;
void onUpdate(float dt);
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
};
#endif

View file

@ -266,7 +266,7 @@ Vector BitmapText::getColorIndex(size_t i, size_t j)
return c;
}
void BitmapText::onRender() const
void BitmapText::onRender(const RenderState& rs) const
{
if (!bmpFont) return;
float top_color[3] = {bmpFont->fontTopColor.x*color.x, bmpFont->fontTopColor.y*color.y, bmpFont->fontTopColor.z*color.z};

View file

@ -82,7 +82,7 @@ protected:
float alignWidth;
void formatText();
float fontDrawSize;
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
typedef std::vector<std::string> Lines;
Lines lines;
typedef std::vector<Vector> ColorIndices;

View file

@ -75,6 +75,8 @@ set(BBGE_SRCS
RenderObject_inline.h
RenderObjectLayer.cpp
RenderRect.cpp
RenderState.cpp
RenderState.h
RoundedRect.cpp
RoundedRect.h
ScreenTransition.cpp

View file

@ -1761,6 +1761,8 @@ void Core::render(int startLayer, int endLayer, bool useFrameBufferIfAvail)
processedRenderObjectCount = 0;
totalRenderObjectCount = 0;
CombinedRenderAndGPUState rgstate;
glBindTexture(GL_TEXTURE_2D, 0);
glLoadIdentity(); // Reset The View
@ -1818,13 +1820,13 @@ void Core::render(int startLayer, int endLayer, bool useFrameBufferIfAvail)
{
if (r->startPass == r->endPass)
{
r->renderPass(RenderObject::RENDER_ALL);
r->renderPass(rgstate, RenderObject::RENDER_ALL);
}
else
{
for (int pass = r->startPass; pass <= r->endPass; pass++)
{
r->renderPass(pass);
r->renderPass(rgstate, pass);
}
}
}

View file

@ -119,7 +119,7 @@ public:
void remove(RenderObject* r);
void moveToFront(RenderObject *r);
void moveToBack(RenderObject *r);
void renderPass(int pass);
void renderPass(const RenderState& rs, int pass);
void reloadDevice();
inline bool empty()
@ -167,7 +167,7 @@ public:
Vector color;
protected:
inline void renderOneObject(const RenderObject *robj);
inline void renderOneObject(const RenderState& rs, const RenderObject *robj);
RenderObjects renderObjects;
size_t objectCount;

View file

@ -130,7 +130,7 @@ void DebugFont::setText(const std::string &text)
formatText();
}
void DebugFont::onRender() const
void DebugFont::onRender(const RenderState& rs) const
{
const float vspc = 1.5;

View file

@ -40,7 +40,7 @@ public:
protected:
float fontDrawSize, textWidth;
void formatText();
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
std::string text;
std::vector<std::string> lines;
Align align;

View file

@ -222,7 +222,7 @@ void Emitter::removeParticle(Particle *p)
}
void Emitter::onRender() const
void Emitter::onRender(const RenderState& rs) const
{
if (particles.empty()) return;

View file

@ -58,7 +58,7 @@ void Gradient::makeHorizontal(Vector c1, Vector c2)
ulc3 = c1;
}
void Gradient::onRender() const
void Gradient::onRender(const RenderState& rs) const
{

View file

@ -35,7 +35,7 @@ public:
int autoWidth, autoHeight;
protected:
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
Vector ulc0, ulc1, ulc2, ulc3;
};

View file

@ -136,7 +136,7 @@ public:
bool hasRot;
protected:
Vector currentSpawn, lastSpawn;
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
void spawnParticle(float perc=1);
void onUpdate(float dt);

View file

@ -422,7 +422,7 @@ void Quad::repeatTextureToFill(bool on)
}
void Quad::onRender() const
void Quad::onRender(const RenderState& rs) const
{
if (!renderQuad) return;
@ -657,7 +657,7 @@ CollideQuad::~CollideQuad()
{
}
void CollideQuad::renderCollision() const
void CollideQuad::renderCollision(const RenderState& rs) const
{
if (collideRadius > 0)
{

View file

@ -36,7 +36,7 @@ protected:
int w, h, w2, h2;
int lineSize;
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
};
class Quad : public RenderObject
@ -117,7 +117,7 @@ protected:
static Vector renderBorderColor;
void onSetTexture();
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
void onUpdate(float dt);
private:
bool doUpdateGrid;
@ -143,7 +143,7 @@ class CollideQuad : public Quad
public:
CollideQuad();
virtual ~CollideQuad();
virtual void renderCollision() const OVERRIDE;
virtual void renderCollision(const RenderState& rs) const OVERRIDE;
float collideRadius;
};

View file

@ -75,7 +75,7 @@ static inline void drawOnePoint(const QuadGrid::Point& p, float ox, float oy)
}
void QuadGrid::onRender() const
void QuadGrid::onRender(const RenderState& rs) const
{
glColor4f(color.x, color.y, color.z, alpha.x * alphaMod);

View file

@ -42,7 +42,7 @@ public:
return _points[y * _w + x];
}
virtual void onRender() const OVERRIDE;
virtual void onRender(const RenderState& rs) const OVERRIDE;
virtual void onUpdate(float dt);
virtual void onSetTexture();

View file

@ -55,35 +55,6 @@ int RenderObject::getTopLayer() const
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() const
{
compile_assert(Countof(s_blendParams) == _BLEND_MAXSIZE);
if (_blendType >= BLEND_DEFAULT)
{
glEnable(GL_BLEND);
const BlendParams& bp = s_blendParams[_blendType];
glBlendFunc(bp.src, bp.dst);
}
else
{
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
}
}
void RenderObject::setColorMult(const Vector &color, const float alpha) const
{
if (colorIsSaved)
@ -502,7 +473,7 @@ bool RenderObject::hasRenderPass(const int pass) const
return false;
}
void RenderObject::render() const
void RenderObject::render(const RenderState& rs) const
{
if (isHidden()) return;
@ -547,17 +518,17 @@ void RenderObject::render() const
position = mb->positions[i].position;
rotation.z = mb->positions[i].rotz;
alpha = (1.0f-(float(i) * m)) * m2;
renderCall();
renderCall(rs);
}
position = oldPos;
alpha.x = oldAlpha;
rotation.z = oldRotZ;
}
renderCall();
renderCall(rs);
}
void RenderObject::renderCall() const
void RenderObject::renderCall(const RenderState& rs) const
{
position += offset;
@ -648,7 +619,7 @@ void RenderObject::renderCall() const
for (Children::const_iterator i = children.begin(); i != children.end(); i++)
{
if (!(*i)->isDead() && (*i)->renderBeforeParent)
(*i)->render();
(*i)->render(rs);
}
@ -680,7 +651,7 @@ void RenderObject::renderCall() const
}
}
applyBlendType();
rs.gpu.setBlend(getBlendType());
bool doRender = true;
@ -698,16 +669,16 @@ void RenderObject::renderCall() const
}
if (renderCollisionShape)
renderCollision();
renderCollision(rs);
if (doRender)
onRender();
onRender(rs);
for (Children::const_iterator i = children.begin(); i != children.end(); i++)
{
if (!(*i)->isDead() && !(*i)->renderBeforeParent)
(*i)->render();
(*i)->render(rs);
}
@ -717,7 +688,7 @@ void RenderObject::renderCall() const
position -= offset;
}
void RenderObject::renderCollision() const
void RenderObject::renderCollision(const RenderState& rs) const
{
}

View file

@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "EngineEnums.h"
#include "Texture.h"
#include "ScriptObject.h"
#include "RenderState.h"
#include <list>
class Core;
@ -93,7 +94,7 @@ public:
friend class Core;
RenderObject();
virtual ~RenderObject();
virtual void render() const;
virtual void render(const RenderState& rs) const;
void setTexturePointer(CountedPtr<Texture> t)
{
@ -213,7 +214,6 @@ public:
void lookAt(const Vector &pos, float t, float minAngle, float maxAngle, float offset=0);
inline RenderObject *getParent() const {return parent;}
void applyBlendType() const;
void fhTo(bool fh);
void addDeathNotify(RenderObject *r);
virtual void unloadDevice();
@ -295,7 +295,7 @@ protected:
virtual void onFH(){}
virtual void onFV(){}
virtual void onSetTexture(){}
virtual void onRender() const {}
virtual void onRender(const RenderState& rs) const {}
virtual void onUpdate(float dt);
virtual void deathNotify(RenderObject *r);
virtual void onEndOfLife() {}
@ -305,8 +305,8 @@ protected:
// Is this object or any of its children rendered in pass "pass"?
bool hasRenderPass(const int pass) const;
inline void renderCall() const;
virtual void renderCollision() const;
inline void renderCall(const RenderState& rs) const;
virtual void renderCollision(const RenderState& rs) const;
typedef std::list<RenderObject*> RenderObjectList;
RenderObjectList deathNotifications;

View file

@ -212,14 +212,13 @@ void RenderObjectLayer::moveToBack(RenderObject *r)
}
}
void RenderObjectLayer::renderPass(int pass)
void RenderObjectLayer::renderPass(const RenderState& rs, int pass)
{
core->currentLayerPass = pass;
for (RenderObject *robj = getFirst(); robj; robj = getNext())
{
renderOneObject(robj);
renderOneObject(rs, robj);
}
}
@ -227,8 +226,7 @@ void RenderObjectLayer::reloadDevice()
{
}
inline void RenderObjectLayer::renderOneObject(const RenderObject *robj)
inline void RenderObjectLayer::renderOneObject(const RenderState& rs, const RenderObject *robj)
{
core->totalRenderObjectCount++;
if (robj->getParent() || robj->alpha.x == 0)
@ -236,7 +234,7 @@ inline void RenderObjectLayer::renderOneObject(const RenderObject *robj)
if (!robj->cull || robj->isOnScreen())
{
robj->render();
robj->render(rs);
core->renderObjectCount++;
}
core->processedRenderObjectCount++;

View file

@ -40,7 +40,7 @@ void OutlineRect::setLineSize(int ls)
lineSize = ls;
}
void OutlineRect::onRender() const
void OutlineRect::onRender(const RenderState& rs) const
{
glLineWidth(lineSize);
glBegin(GL_LINES);

49
BBGE/RenderState.cpp Normal file
View file

@ -0,0 +1,49 @@
#include "RenderState.h"
#include "Base.h"
#include "RenderBase.h"
RenderState::RenderState(GPUState &gpu)
: gpu(gpu), color(1,1,1), alpha(1)
{
}
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 },
};
GPUState::GPUState()
: _blendType(BLEND_DISABLED)
{
setBlend(BLEND_DEFAULT);
}
void GPUState::setBlend(BlendType bt)
{
compile_assert(Countof(s_blendParams) == _BLEND_MAXSIZE);
if(_blendType == bt)
return;
_blendType = bt;
if (bt >= BLEND_DEFAULT)
{
glEnable(GL_BLEND);
const BlendParams& bp = s_blendParams[bt];
glBlendFunc(bp.src, bp.dst);
}
else
{
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
}
}

43
BBGE/RenderState.h Normal file
View file

@ -0,0 +1,43 @@
#ifndef BBGE_RENDERSTATE_H
#define BBGE_RENDERSTATE_H
#include "Vector.h"
#include "EngineEnums.h"
struct CombinedRenderAndGPUState;
// Only once of these exists at any time.
// It stores the known GPU state so that we don't need so many futile state changes
struct GPUState
{
friend struct CombinedRenderAndGPUState;
GPUState();
void setBlend(BlendType bt);
private:
BlendType _blendType;
};
// The RenderState is passed through the scene graph as each layer is rendered
// TODO: what needs to end up here? matrix stack too?
struct RenderState
{
GPUState& gpu;
Vector color;
float alpha;
protected:
RenderState(GPUState& gpu);
};
struct CombinedRenderAndGPUState : public RenderState
{
GPUState gpu;
CombinedRenderAndGPUState() : RenderState(gpu) {}
};
#endif

View file

@ -101,7 +101,7 @@ void RoundedRect::onUpdate(float dt)
}
}
void RoundedRect::onRender() const
void RoundedRect::onRender(const RenderState& rs) const
{
int w2 = width/2;
@ -257,7 +257,7 @@ void RoundButton::onUpdate(float dt)
}
}
void RoundButton::onRender() const
void RoundButton::onRender(const RenderState& rs) const
{
int w2 = width/2, h2 = height/2;
glLineWidth(1);

View file

@ -43,7 +43,7 @@ public:
protected:
void onUpdate(float dt);
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
bool canMove;
static RoundedRect *moving;
@ -61,7 +61,7 @@ public:
EventPtr event;
protected:
void onUpdate(float dt);
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
TTFText *label;
int width, height, radius;

View file

@ -111,7 +111,7 @@ bool ScreenTransition::isGoing()
return alpha.isInterpolating();
}
void ScreenTransition::onRender() const
void ScreenTransition::onRender(const RenderState& rs) const
{
if (alpha.x == 0) return;

View file

@ -38,7 +38,7 @@ protected:
void destroyTexture();
int textureWidth, textureHeight;
int windowWidth, windowHeight;
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
float width, height;

View file

@ -297,7 +297,7 @@ void Bone::spawnParticlesFromCollisionMask(const char *p, unsigned intv, int lay
}
}
void Bone::renderCollision() const
void Bone::renderCollision(const RenderState& rs) const
{
if (!collisionMask.empty())
{
@ -332,7 +332,7 @@ void Bone::renderCollision() const
glPopAttrib();
}
else
CollideQuad::renderCollision();
CollideQuad::renderCollision(rs);
}
Vector Bone::getCollisionMaskNormal(size_t index)

View file

@ -94,7 +94,7 @@ public:
void spawnParticlesFromCollisionMask(const char *p, unsigned intv, int layer, float rotz = 0);
Vector getCollisionMaskNormal(size_t index);
virtual void renderCollision() const OVERRIDE;
virtual void renderCollision(const RenderState& rs) const OVERRIDE;
protected:
std::vector<ParticleEffect*> emitters;

View file

@ -240,7 +240,7 @@ int TTFText::findLine(const std::string &label)
return 0;
}
void TTFText::onRender() const
void TTFText::onRender(const RenderState& rs) const
{

View file

@ -58,7 +58,7 @@ protected:
float lineHeight;
void updateAlign();
Align align;
void onRender() const OVERRIDE;
void onRender(const RenderState& rs) const OVERRIDE;
void updateFormatting();
std::string originalText;

View file

@ -34,8 +34,7 @@ Texture::Texture()
textures[0] = 0;
width = height = 0;
repeat = false;
repeating = false;
_repeating = false;
ow = oh = -1;
loadResult = TEX_FAILED;
_mipmap = false;
@ -218,7 +217,6 @@ bool Texture::load(std::string file, bool mipmap)
file = adjustFilenameCase(file);
loadName = file;
repeating = false;
_mipmap = mipmap;
size_t pos = file.find_last_of('.');
@ -284,26 +282,16 @@ bool Texture::load(std::string file, bool mipmap)
return ok;
}
void Texture::apply(bool repeatOverride) const
static const GLenum repeatLUT[] = { GL_CLAMP_TO_EDGE, GL_REPEAT };
void Texture::apply(bool repeat) const
{
glBindTexture(GL_TEXTURE_2D, textures[0]);
if (repeat || repeatOverride)
if(repeat != _repeating)
{
if (!repeating)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
repeating = true;
}
}
else
{
if (repeating)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
repeating = false;
}
_repeating = repeat;
GLenum rep = repeatLUT[repeat];
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, rep);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, rep);
}
}
@ -338,6 +326,7 @@ bool Texture::loadInternal(const ImageData& img, bool mipmap)
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
_repeating = false;
const GlTexFormat& f = formatLUT[img.channels - 1];

View file

@ -40,7 +40,7 @@ public:
~Texture();
bool load(std::string file, bool mipmap);
void apply(bool repeatOverride=false) const;
void apply(bool repeat = false) const;
void unload();
int getPixelWidth();
@ -50,9 +50,6 @@ public:
int width, height;
bool repeat;
mutable bool repeating; // modified during rendering
unsigned textures[1];
void reload();
@ -74,6 +71,8 @@ protected:
int ow, oh;
TextureLoadResult loadResult;
bool _mipmap;
private:
mutable bool _repeating; // modified during rendering
};
#define UNREFTEX(x) if (x) {x = NULL;}