diff --git a/res/content/base/blocks/water.json b/res/content/base/blocks/water.json index c0d6b3e2..943640e8 100644 --- a/res/content/base/blocks/water.json +++ b/res/content/base/blocks/water.json @@ -1,6 +1,6 @@ { "texture": "water", - "overlay-texture": "water", + "overlay-texture": "blocks:water", "draw-group": 3, "light-passing": true, "sky-light-passing": false, diff --git a/src/assets/assets_util.cpp b/src/assets/assets_util.cpp index af7a90e2..bdd7795a 100644 --- a/src/assets/assets_util.cpp +++ b/src/assets/assets_util.cpp @@ -4,7 +4,7 @@ #include "graphics/core/Atlas.hpp" #include "graphics/core/Texture.hpp" -util::TextureRegion util::getTextureRegion( +util::TextureRegion util::get_texture_region( const Assets& assets, const std::string& name, const std::string& fallback ) { size_t sep = name.find(':'); @@ -16,7 +16,7 @@ util::TextureRegion util::getTextureRegion( if (auto reg = atlas->getIf(name.substr(sep+1))) { return {atlas->getTexture(), *reg}; } else if (!fallback.empty()){ - return util::getTextureRegion(assets, fallback, ""); + return util::get_texture_region(assets, fallback, ""); } } } diff --git a/src/assets/assets_util.hpp b/src/assets/assets_util.hpp index 69972e7b..db7dc361 100644 --- a/src/assets/assets_util.hpp +++ b/src/assets/assets_util.hpp @@ -13,7 +13,7 @@ namespace util { UVRegion region; }; - TextureRegion getTextureRegion( + TextureRegion get_texture_region( const Assets& assets, const std::string& name, const std::string& fallback diff --git a/src/graphics/core/Batch3D.cpp b/src/graphics/core/Batch3D.cpp index d3e369a0..dd6261e5 100644 --- a/src/graphics/core/Batch3D.cpp +++ b/src/graphics/core/Batch3D.cpp @@ -106,7 +106,7 @@ void Batch3D::face( tint.r, tint.g, tint.b, tint.a); } -void Batch3D::texture(Texture* new_texture){ +void Batch3D::texture(const Texture* new_texture){ if (currentTexture == new_texture) return; flush(); diff --git a/src/graphics/core/Batch3D.hpp b/src/graphics/core/Batch3D.hpp index 2cfe4bcc..bd5f7b4e 100644 --- a/src/graphics/core/Batch3D.hpp +++ b/src/graphics/core/Batch3D.hpp @@ -18,7 +18,7 @@ class Batch3D : public Flushable { std::unique_ptr blank; size_t index; - Texture* currentTexture; + const Texture* currentTexture; void vertex( float x, float y, float z, @@ -47,11 +47,36 @@ public: ~Batch3D(); void begin(); - void texture(Texture* texture); - void sprite(glm::vec3 pos, glm::vec3 up, glm::vec3 right, float w, float h, const UVRegion& uv, glm::vec4 tint); - void xSprite(float w, float h, const UVRegion& uv, const glm::vec4 tint, bool shading=true); - void cube(const glm::vec3 coords, const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true); - void blockCube(const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true); + void texture(const Texture* texture); + void sprite( + glm::vec3 pos, + glm::vec3 up, + glm::vec3 right, + float w, + float h, + const UVRegion& uv, + glm::vec4 tint + ); + void xSprite( + float w, + float h, + const UVRegion& uv, + const glm::vec4 tint, + bool shading = true + ); + void cube( + const glm::vec3 coords, + const glm::vec3 size, + const UVRegion (&texfaces)[6], + const glm::vec4 tint, + bool shading = true + ); + void blockCube( + const glm::vec3 size, + const UVRegion (&texfaces)[6], + const glm::vec4 tint, + bool shading = true + ); void vertex(glm::vec3 pos, glm::vec2 uv, glm::vec4 tint); void point(glm::vec3 pos, glm::vec4 tint); void flush() override; diff --git a/src/graphics/render/ModelBatch.cpp b/src/graphics/render/ModelBatch.cpp index 1d8ce2f1..f6a1b58b 100644 --- a/src/graphics/render/ModelBatch.cpp +++ b/src/graphics/render/ModelBatch.cpp @@ -154,7 +154,7 @@ void ModelBatch::setTexture(const std::string& name, } } - auto textureRegion = util::getTextureRegion(*assets, name, "blocks:notfound"); + auto textureRegion = util::get_texture_region(*assets, name, "blocks:notfound"); setTexture(textureRegion.texture); region = textureRegion.region; } diff --git a/src/graphics/render/WorldRenderer.cpp b/src/graphics/render/WorldRenderer.cpp index 266a8c2c..4b13a23f 100644 --- a/src/graphics/render/WorldRenderer.cpp +++ b/src/graphics/render/WorldRenderer.cpp @@ -9,6 +9,7 @@ #include #include "assets/Assets.hpp" +#include "assets/assets_util.hpp" #include "content/Content.hpp" #include "engine.hpp" #include "frontend/LevelFrontend.hpp" @@ -461,12 +462,14 @@ void WorldRenderer::renderBlockOverlay(const DrawContext& wctx, const Assets& as if (def.overlayTexture.empty()) { return; } + auto textureRegion = util::get_texture_region( + assets, def.overlayTexture, "blocks:notfound" + ); DrawContext ctx = wctx.sub(); ctx.setDepthTest(false); ctx.setCullFace(false); auto& shader = assets.require("ui3d"); - auto& atlas = assets.require("blocks"); shader.use(); batch3d->begin(); shader.uniformMatrix("u_projview", glm::mat4(1.0f)); @@ -479,14 +482,14 @@ void WorldRenderer::renderBlockOverlay(const DrawContext& wctx, const Assets& as glm::min(1.0f, Lightmap::extract(light, 2) / 15.0f + s), 1.0f ); - batch3d->texture(atlas.getTexture()); + batch3d->texture(textureRegion.texture); batch3d->sprite( glm::vec3(), glm::vec3(0, 1, 0), glm::vec3(1, 0, 0), 2, 2, - atlas.get(def.overlayTexture), + textureRegion.region, tint ); batch3d->flush(); diff --git a/src/graphics/ui/elements/InventoryView.cpp b/src/graphics/ui/elements/InventoryView.cpp index c9aefc96..fa3d836c 100644 --- a/src/graphics/ui/elements/InventoryView.cpp +++ b/src/graphics/ui/elements/InventoryView.cpp @@ -176,7 +176,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) { } case ItemIconType::SPRITE: { auto textureRegion = - util::getTextureRegion(*assets, item.icon, "blocks:notfound"); + util::get_texture_region(*assets, item.icon, "blocks:notfound"); batch->texture(textureRegion.texture); batch->rect(