diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/AssetManager.cpp | 18 | ||||
-rw-r--r-- | src/AssetManager.hpp | 7 | ||||
-rw-r--r-- | src/Render.cpp | 4 | ||||
-rw-r--r-- | src/RendererSection.cpp | 11 | ||||
-rw-r--r-- | src/RendererSection.hpp | 1 | ||||
-rw-r--r-- | src/RendererSectionData.cpp | 2 | ||||
-rw-r--r-- | src/RendererSectionData.hpp | 1 |
7 files changed, 34 insertions, 10 deletions
diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index 9e360c0..0579b5d 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -366,10 +366,10 @@ void AssetManager::ParseBlockModels() { break; } parsedFace.transform = faceTransform; - glm::vec4 texture; + TextureCoord texture; textureName = face.second.texture; if (model.Textures.empty()) { - texture = GetTextureByAssetName("minecraft/texture/blocks/tnt_side"); + texture = GetTexture("minecraft/texture/blocks/tnt_side"); } else { while (textureName[0] == '#') { @@ -378,7 +378,7 @@ void AssetManager::ParseBlockModels() { textureName = textureIt != model.Textures.end() ? textureIt->second : "minecraft/texture/blocks/tnt_side"; } textureName.insert(0, "minecraft/textures/"); - texture = GetTextureByAssetName(textureName); + texture = GetTexture(textureName); if (!(face.second.uv == BlockModel::ElementData::FaceData::Uv{ 0,16,0,16 }) && !(face.second.uv == BlockModel::ElementData::FaceData::Uv{ 0,0,0,0 }) && !(face.second.uv == BlockModel::ElementData::FaceData::Uv{ 0,0,16,16 })) { @@ -392,13 +392,17 @@ void AssetManager::ParseBlockModels() { h /= 16.0; double X = texture.x; double Y = texture.y; - double W = texture.z; - double H = texture.w; + double W = texture.w; + double H = texture.h; - texture = glm::vec4{ X + x * W, Y + y * H, w * W , h * H }; + texture.x = X + x * W; + texture.y = Y + y * H; + texture.w = w * W; + texture.h = h * H; } } - parsedFace.texture = texture; + parsedFace.texture = glm::vec4{ texture.x,texture.y,texture.w,texture.h }; + parsedFace.layer = texture.layer; if (face.second.tintIndex) parsedFace.color = glm::vec3(0.275, 0.63, 0.1); else diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp index 1b64215..0663f48 100644 --- a/src/AssetManager.hpp +++ b/src/AssetManager.hpp @@ -132,6 +132,7 @@ struct BlockModel { ElementData::FaceDirection visibility; glm::mat4 transform; glm::vec4 texture; + float layer; glm::vec3 color; }; @@ -204,7 +205,11 @@ public: template <typename T> T *GetAsset(const std::string &assetName) { - AssetTreeNode *node = GetAssetByAssetName(assetName); + AssetTreeNode *node; + if (assetName[0] != '/') + node = GetAssetByAssetName('/'+assetName); + else + node = GetAssetByAssetName(assetName); if (!node) return nullptr; return dynamic_cast<T*>(node->asset.get()); diff --git a/src/Render.cpp b/src/Render.cpp index ba8d0ed..1bd5273 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -92,8 +92,8 @@ void Render::InitGlew() { void Render::PrepareToRendering() { //TextureAtlas texture - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, AssetManager::Instance().GetTextureAtlas()); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D_ARRAY, AssetManager::Instance().GetTextureAtlasId()); AssetManager::Instance().GetTextureAtlasIndexes(); ImGui_ImplSdlGL3_Init(window); diff --git a/src/RendererSection.cpp b/src/RendererSection.cpp index 21c2714..bbf24ff 100644 --- a/src/RendererSection.cpp +++ b/src/RendererSection.cpp @@ -73,6 +73,14 @@ RendererSection::RendererSection(const RendererSectionData &data) { glVertexAttribDivisor(textureAttribPos, 1); glCheckError(); + //TextureLayers + GLuint layerAttribPos = 14; + glBindBuffer(GL_ARRAY_BUFFER, Vbo[LAYERS]); + glVertexAttribPointer(layerAttribPos, 1, GL_FLOAT, GL_FALSE, sizeof(GLfloat), nullptr); + glEnableVertexAttribArray(layerAttribPos); + glVertexAttribDivisor(layerAttribPos, 1); + glCheckError(); + //Blocks models GLuint matAttribPos = 8; size_t sizeOfMat4 = 4 * 4 * sizeof(GLfloat); @@ -156,6 +164,9 @@ void RendererSection::UpdateData(const RendererSectionData & data) { glBindBuffer(GL_ARRAY_BUFFER, Vbo[TEXTURES]); glBufferData(GL_ARRAY_BUFFER, data.textures.size() * sizeof(glm::vec4), data.textures.data(), GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, Vbo[LAYERS]); + glBufferData(GL_ARRAY_BUFFER, data.textureLayers.size() * 1* sizeof(GLfloat), data.textureLayers.data(), GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, Vbo[MODELS]); glBufferData(GL_ARRAY_BUFFER, data.models.size() * sizeof(glm::mat4), data.models.data(), GL_DYNAMIC_DRAW); diff --git a/src/RendererSection.hpp b/src/RendererSection.hpp index f172a12..c760678 100644 --- a/src/RendererSection.hpp +++ b/src/RendererSection.hpp @@ -12,6 +12,7 @@ class RendererSection { enum Vbos { MODELS = 0, TEXTURES, + LAYERS, COLORS, LIGHTS, VBOCOUNT, diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp index ab3812d..de79da4 100644 --- a/src/RendererSectionData.cpp +++ b/src/RendererSectionData.cpp @@ -48,6 +48,7 @@ void AddFacesByBlockModel(RendererSectionData &data, const BlockModel &model, co data.models.push_back(transform * face.transform); data.textures.push_back(face.texture); + data.textureLayers.push_back(face.layer); data.colors.push_back(face.color); data.lights.push_back(glm::vec2(light, skyLight)); } @@ -188,6 +189,7 @@ RendererSectionData ParseSection(const SectionsData §ions) } } data.textures.shrink_to_fit(); + data.textureLayers.shrink_to_fit(); data.models.shrink_to_fit(); data.colors.shrink_to_fit(); diff --git a/src/RendererSectionData.hpp b/src/RendererSectionData.hpp index 134eef6..a60f671 100644 --- a/src/RendererSectionData.hpp +++ b/src/RendererSectionData.hpp @@ -26,6 +26,7 @@ struct SectionsData { struct RendererSectionData { std::vector<glm::mat4> models; std::vector<glm::vec4> textures; + std::vector<float> textureLayers; std::vector<glm::vec3> colors; std::vector<glm::vec2> lights; size_t hash = 0; |