From 4c941419b4570b6fec807a3b86eb0a42e530509a Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 20 Oct 2023 02:42:52 +0200 Subject: [PATCH] ensure that texcoords are always updated when changing things that affect them --- Aquaria/Game.cpp | 2 +- Aquaria/SceneEditor.cpp | 6 +++--- Aquaria/ScriptInterface.cpp | 18 ++++++++++++------ Aquaria/WaterSurfaceRender.cpp | 8 +++----- BBGE/Quad.cpp | 29 ++++++++++++++++++----------- BBGE/Quad.h | 11 +++++++---- 6 files changed, 44 insertions(+), 30 deletions(-) diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index f2966f3..f60f475 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -3419,8 +3419,8 @@ void Game::toggleHelpScreen(bool on, const std::string &label) helpBG = new Quad; //helpBG->color = 0; helpBG->setTexture("brick"); + helpBG->setRepeatScale(Vector(2, 2)); helpBG->repeatTextureToFill(true); - helpBG->repeatToFillScale = Vector(2, 2); //helpBG->alphaMod = 0.75; helpBG->autoWidth = AUTO_VIRTUALWIDTH; helpBG->autoHeight = AUTO_VIRTUALHEIGHT; diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index fba1706..d919874 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -109,7 +109,7 @@ static void tileToQuad(Quad *q, const TileData& t) q->rotation.z = t.rotation; if(t.flags & TILEFLAG_REPEAT && t.rep) { - q->repeatToFillScale = Vector(t.rep->texscaleX, t.rep->texscaleY); + q->setRepeatScale(Vector(t.rep->texscaleX, t.rep->texscaleY)); q->repeatTextureToFill(true); } q->texcoords = t.getTexcoords(); @@ -193,8 +193,8 @@ public: void onUpdate(float dt) { - for(size_t i = 0; i < _quads.size(); ++i) - _quads[i]->refreshRepeatTextureToFill(); + //for(size_t i = 0; i < _quads.size(); ++i) + // _quads[i]->refreshRepeatTextureToFill(); } void finish() diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 159cef8..6d8b602 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -1889,13 +1889,19 @@ luaFunc(quad_setRepeatScale) { Quad *b = getQuad(L); if (b) - { - b->repeatToFillScale = Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)); - b->refreshRepeatTextureToFill(); - } + b->setRepeatScale(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3))); luaReturnNil(); } +luaFunc(quad_getRepeatScale) +{ + Vector s; + Quad *b = getQuad(L); + if (b) + s = b->getRepeatScale(); + luaReturnVec2(s.x, s.y); +} + luaFunc(quad_isRepeatTexture) { Quad *b = getQuad(L); @@ -1906,7 +1912,7 @@ luaFunc(quad_setTexOffset) { Quad *b = getQuad(L); if (b) - b->texOff = Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)); + b->setRepeatOffset(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3))); luaReturnNil(); } @@ -1915,7 +1921,7 @@ luaFunc(quad_getTexOffset) Quad *b = getQuad(L); Vector v; if (b) - v = b->texOff; + v = b->getRepeatOffset(); luaReturnVec2(v.x, v.y); } diff --git a/Aquaria/WaterSurfaceRender.cpp b/Aquaria/WaterSurfaceRender.cpp index 91f5789..df2ecdb 100644 --- a/Aquaria/WaterSurfaceRender.cpp +++ b/Aquaria/WaterSurfaceRender.cpp @@ -89,11 +89,9 @@ void WaterSurfaceRender::onUpdate(float dt) qSurface->setWidthHeight(width, height); float bit = core->cameraPos.x/300.0f; - - qLine->texOff.x = bit; - - qLine->refreshRepeatTextureToFill(); - + Vector texoff = qLine->getRepeatOffset(); + texoff.x = bit; + qLine->setRepeatOffset(texoff); if (dsq->useFrameBuffer && dsq->frameBuffer.isInited()) diff --git a/BBGE/Quad.cpp b/BBGE/Quad.cpp index 5464586..3bae54b 100644 --- a/BBGE/Quad.cpp +++ b/BBGE/Quad.cpp @@ -212,10 +212,22 @@ void Quad::renderGrid(const RenderState& rs) const void Quad::repeatTextureToFill(bool on) { repeatTexture = on; - refreshRepeatTextureToFill(); + updateTexCoords(); } +void Quad::setRepeatScale(const Vector& repscale) +{ + repeatToFillScale = repscale; + updateTexCoords(); +} + +void Quad::setRepeatOffset(const Vector& repoffs) +{ + texOff = repoffs; + updateTexCoords(); +} + void Quad::onRender(const RenderState& rs) const { if (!renderQuad) return; @@ -247,7 +259,7 @@ void Quad::onRender(const RenderState& rs) const glPopMatrix(); } -void Quad::refreshRepeatTextureToFill() +void Quad::updateTexCoords() { if (repeatTexture && texture) { @@ -255,7 +267,6 @@ void Quad::refreshRepeatTextureToFill() texcoords.v1 = texOff.y; texcoords.u2 = (width*scale.x*repeatToFillScale.x)/texture->width + texOff.x; texcoords.v2 = (height*scale.y*repeatToFillScale.y)/texture->height + texOff.y; - //texcoords.fixflip(); if(!grid) { @@ -265,14 +276,10 @@ void Quad::refreshRepeatTextureToFill() } else { - if (fabsf(texcoords.u2) > 1 || fabsf(texcoords.v2) > 1) - { - texcoords.u2 = 1; - texcoords.v2 = 1; - - if(grid && grid->gridType == GRID_UNDEFINED && texcoords.isStandard()) - deleteGrid(); - } + texcoords.setStandard(); + // don't delete when a wavy effect is going on, for example + if(grid && grid->gridType == GRID_UNDEFINED) + deleteGrid(); } } diff --git a/BBGE/Quad.h b/BBGE/Quad.h index 30e7d48..3d6877e 100644 --- a/BBGE/Quad.h +++ b/BBGE/Quad.h @@ -71,8 +71,11 @@ public: DynamicRenderGrid *setSegs(int x, int y, float dgox, float dgoy, float dgmx, float dgmy, float dgtm, bool dgo); void setDrawGridAlpha(size_t x, size_t y, float alpha); void repeatTextureToFill(bool on); - void refreshRepeatTextureToFill(); bool isRepeatingTextureToFill() const { return repeatTexture; } + void setRepeatScale(const Vector& repscale); + inline const Vector& getRepeatScale() const { return repeatToFillScale; } + void setRepeatOffset(const Vector& repoffs); + inline const Vector& getRepeatOffset() const { return texOff; } void setStripPoints(bool vert, const Vector *points, size_t n); DynamicRenderGrid *getGrid() { return grid; } const DynamicRenderGrid *getGrid() const { return grid; } @@ -87,14 +90,14 @@ public: char autoWidth, autoHeight; bool renderQuad, renderCenter, renderBorder; - Vector texOff; - float borderAlpha; Vector renderBorderColor; - Vector repeatToFillScale; protected: + void updateTexCoords(); + Vector repeatToFillScale; + Vector texOff; DynamicRenderGrid *grid;