update 'overlay-texture' block property behaviour
This commit is contained in:
parent
4f377b2056
commit
9b5c693027
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"texture": "water",
|
"texture": "water",
|
||||||
"overlay-texture": "water",
|
"overlay-texture": "blocks:water",
|
||||||
"draw-group": 3,
|
"draw-group": 3,
|
||||||
"light-passing": true,
|
"light-passing": true,
|
||||||
"sky-light-passing": false,
|
"sky-light-passing": false,
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include "graphics/core/Atlas.hpp"
|
#include "graphics/core/Atlas.hpp"
|
||||||
#include "graphics/core/Texture.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
|
const Assets& assets, const std::string& name, const std::string& fallback
|
||||||
) {
|
) {
|
||||||
size_t sep = name.find(':');
|
size_t sep = name.find(':');
|
||||||
@ -16,7 +16,7 @@ util::TextureRegion util::getTextureRegion(
|
|||||||
if (auto reg = atlas->getIf(name.substr(sep+1))) {
|
if (auto reg = atlas->getIf(name.substr(sep+1))) {
|
||||||
return {atlas->getTexture(), *reg};
|
return {atlas->getTexture(), *reg};
|
||||||
} else if (!fallback.empty()){
|
} else if (!fallback.empty()){
|
||||||
return util::getTextureRegion(assets, fallback, "");
|
return util::get_texture_region(assets, fallback, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ namespace util {
|
|||||||
UVRegion region;
|
UVRegion region;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextureRegion getTextureRegion(
|
TextureRegion get_texture_region(
|
||||||
const Assets& assets,
|
const Assets& assets,
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const std::string& fallback
|
const std::string& fallback
|
||||||
|
|||||||
@ -106,7 +106,7 @@ void Batch3D::face(
|
|||||||
tint.r, tint.g, tint.b, tint.a);
|
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)
|
if (currentTexture == new_texture)
|
||||||
return;
|
return;
|
||||||
flush();
|
flush();
|
||||||
|
|||||||
@ -18,7 +18,7 @@ class Batch3D : public Flushable {
|
|||||||
std::unique_ptr<Texture> blank;
|
std::unique_ptr<Texture> blank;
|
||||||
size_t index;
|
size_t index;
|
||||||
|
|
||||||
Texture* currentTexture;
|
const Texture* currentTexture;
|
||||||
|
|
||||||
void vertex(
|
void vertex(
|
||||||
float x, float y, float z,
|
float x, float y, float z,
|
||||||
@ -47,11 +47,36 @@ public:
|
|||||||
~Batch3D();
|
~Batch3D();
|
||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
void texture(Texture* texture);
|
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 sprite(
|
||||||
void xSprite(float w, float h, const UVRegion& uv, const glm::vec4 tint, bool shading=true);
|
glm::vec3 pos,
|
||||||
void cube(const glm::vec3 coords, const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true);
|
glm::vec3 up,
|
||||||
void blockCube(const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true);
|
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 vertex(glm::vec3 pos, glm::vec2 uv, glm::vec4 tint);
|
||||||
void point(glm::vec3 pos, glm::vec4 tint);
|
void point(glm::vec3 pos, glm::vec4 tint);
|
||||||
void flush() override;
|
void flush() override;
|
||||||
|
|||||||
@ -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);
|
setTexture(textureRegion.texture);
|
||||||
region = textureRegion.region;
|
region = textureRegion.region;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "assets/Assets.hpp"
|
#include "assets/Assets.hpp"
|
||||||
|
#include "assets/assets_util.hpp"
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "engine.hpp"
|
#include "engine.hpp"
|
||||||
#include "frontend/LevelFrontend.hpp"
|
#include "frontend/LevelFrontend.hpp"
|
||||||
@ -461,12 +462,14 @@ void WorldRenderer::renderBlockOverlay(const DrawContext& wctx, const Assets& as
|
|||||||
if (def.overlayTexture.empty()) {
|
if (def.overlayTexture.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto textureRegion = util::get_texture_region(
|
||||||
|
assets, def.overlayTexture, "blocks:notfound"
|
||||||
|
);
|
||||||
DrawContext ctx = wctx.sub();
|
DrawContext ctx = wctx.sub();
|
||||||
ctx.setDepthTest(false);
|
ctx.setDepthTest(false);
|
||||||
ctx.setCullFace(false);
|
ctx.setCullFace(false);
|
||||||
|
|
||||||
auto& shader = assets.require<Shader>("ui3d");
|
auto& shader = assets.require<Shader>("ui3d");
|
||||||
auto& atlas = assets.require<Atlas>("blocks");
|
|
||||||
shader.use();
|
shader.use();
|
||||||
batch3d->begin();
|
batch3d->begin();
|
||||||
shader.uniformMatrix("u_projview", glm::mat4(1.0f));
|
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),
|
glm::min(1.0f, Lightmap::extract(light, 2) / 15.0f + s),
|
||||||
1.0f
|
1.0f
|
||||||
);
|
);
|
||||||
batch3d->texture(atlas.getTexture());
|
batch3d->texture(textureRegion.texture);
|
||||||
batch3d->sprite(
|
batch3d->sprite(
|
||||||
glm::vec3(),
|
glm::vec3(),
|
||||||
glm::vec3(0, 1, 0),
|
glm::vec3(0, 1, 0),
|
||||||
glm::vec3(1, 0, 0),
|
glm::vec3(1, 0, 0),
|
||||||
2,
|
2,
|
||||||
2,
|
2,
|
||||||
atlas.get(def.overlayTexture),
|
textureRegion.region,
|
||||||
tint
|
tint
|
||||||
);
|
);
|
||||||
batch3d->flush();
|
batch3d->flush();
|
||||||
|
|||||||
@ -176,7 +176,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
|||||||
}
|
}
|
||||||
case ItemIconType::SPRITE: {
|
case ItemIconType::SPRITE: {
|
||||||
auto textureRegion =
|
auto textureRegion =
|
||||||
util::getTextureRegion(*assets, item.icon, "blocks:notfound");
|
util::get_texture_region(*assets, item.icon, "blocks:notfound");
|
||||||
|
|
||||||
batch->texture(textureRegion.texture);
|
batch->texture(textureRegion.texture);
|
||||||
batch->rect(
|
batch->rect(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user