fix enable per-variant custom model caching
This commit is contained in:
parent
ed9cf8800a
commit
2a1d2f9354
@ -62,7 +62,7 @@ void ContentGfxCache::refreshVariant(
|
||||
}
|
||||
}
|
||||
}
|
||||
models[def.rt.id] = std::move(model);
|
||||
models[modelKey(def.rt.id, variantIndex)] = std::move(model);
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,8 +94,8 @@ void ContentGfxCache::refresh() {
|
||||
|
||||
ContentGfxCache::~ContentGfxCache() = default;
|
||||
|
||||
const model::Model& ContentGfxCache::getModel(blockid_t id) const {
|
||||
const auto& found = models.find(id);
|
||||
const model::Model& ContentGfxCache::getModel(blockid_t id, uint8_t variant) const {
|
||||
const auto& found = models.find(modelKey(id, variant));
|
||||
if (found == models.end()) {
|
||||
throw std::runtime_error("model not found");
|
||||
}
|
||||
|
||||
@ -27,7 +27,11 @@ class ContentGfxCache {
|
||||
|
||||
// array of block sides uv regions (6 per block)
|
||||
std::unique_ptr<UVRegion[]> sideregions;
|
||||
std::unordered_map<blockid_t, model::Model> models;
|
||||
std::unordered_map<uint64_t, model::Model> models;
|
||||
|
||||
static inline uint64_t modelKey(blockid_t id, uint8_t variant) {
|
||||
return (uint64_t(id) << 8) | uint64_t(variant & 0xFF);
|
||||
}
|
||||
|
||||
void refreshVariant(
|
||||
const Block& def,
|
||||
@ -53,7 +57,7 @@ public:
|
||||
return sideregions[getRegionIndex(id, variant, side, !dense)];
|
||||
}
|
||||
|
||||
const model::Model& getModel(blockid_t id) const;
|
||||
const model::Model& getModel(blockid_t id, uint8_t variant) const;
|
||||
|
||||
void refresh(const Block& block, const Atlas& atlas);
|
||||
|
||||
|
||||
@ -67,7 +67,7 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
|
||||
glm::vec3 poff = glm::vec3(0.0f, 0.0f, 1.0f);
|
||||
offset.y += (1.0f - hitbox).y * 0.5f;
|
||||
shader.uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
|
||||
const auto& model = cache.getModel(def.rt.id);
|
||||
const auto& model = cache.getModel(def.rt.id, 0);
|
||||
|
||||
for (const auto& mesh : model.meshes) {
|
||||
for (const auto& vertex : mesh.vertices) {
|
||||
|
||||
@ -308,7 +308,7 @@ void BlocksRenderer::blockCustomModel(
|
||||
Z = orient.axes[2];
|
||||
}
|
||||
|
||||
const auto& model = cache.getModel(block.rt.id);
|
||||
const auto& model = cache.getModel(block.rt.id, block.getVariantIndex(states.userbits));
|
||||
for (const auto& mesh : model.meshes) {
|
||||
if (vertexCount + mesh.vertices.size() >= capacity) {
|
||||
overflow = true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user