diff --git a/src/graphics/render/MainBatch.cpp b/src/graphics/render/MainBatch.cpp index 0bb6900dd..70d4af6f7 100644 --- a/src/graphics/render/MainBatch.cpp +++ b/src/graphics/render/MainBatch.cpp @@ -82,6 +82,69 @@ inline glm::vec4 do_tint(float value) { return {value, value, value, 1.0f}; } +void MainBatch::quad( + const glm::vec3& pos, + const glm::vec3& right, + const glm::vec3& up, + const glm::vec3& normal, + const glm::vec2& size, + const glm::vec4& light, + const glm::vec4& tint, + const UVRegion& subregion, + float emission +) { + prepare(6); + vertex( + pos - right * size.x * 0.5f - up * size.y * 0.5f, + {subregion.u1, subregion.v1}, + light, + tint, + normal, + emission + ); + vertex( + pos + right * size.x * 0.5f - up * size.y * 0.5f, + {subregion.u2, subregion.v1}, + light, + tint, + normal, + emission + ); + vertex( + pos + right * size.x * 0.5f + up * size.y * 0.5f, + {subregion.u2, subregion.v2}, + light, + tint, + normal, + emission + ); + + vertex( + pos - right * size.x * 0.5f - up * size.y * 0.5f, + {subregion.u1, subregion.v1}, + light, + tint, + normal, + emission + ); + vertex( + pos + right * size.x * 0.5f + up * size.y * 0.5f, + {subregion.u2, subregion.v2}, + light, + tint, + normal, + emission + ); + vertex( + pos - right * size.x * 0.5f + up * size.y * 0.5f, + {subregion.u1, subregion.v2}, + light, + tint, + normal, + emission + ); +} + void MainBatch::cube( const glm::vec3& coord, const glm::vec3& size, diff --git a/src/graphics/render/MainBatch.hpp b/src/graphics/render/MainBatch.hpp index 86397f36f..d51b2d05b 100644 --- a/src/graphics/render/MainBatch.hpp +++ b/src/graphics/render/MainBatch.hpp @@ -31,16 +31,6 @@ struct MainBatchVertex { }; class MainBatch { - std::unique_ptr const buffer; - size_t const capacity; - size_t index; - - UVRegion region {0.0f, 0.0f, 1.0f, 1.0f}; - - std::unique_ptr> mesh; - std::unique_ptr blank; - - const Texture* texture = nullptr; public: /// xyz, uv, color, compressed lights @@ -84,7 +74,7 @@ public: index++; } - inline void quad( + void quad( const glm::vec3& pos, const glm::vec3& right, const glm::vec3& up, @@ -94,58 +84,7 @@ public: const glm::vec4& tint, const UVRegion& subregion, float emission = 0.0f - ) { - prepare(6); - vertex( - pos - right * size.x * 0.5f - up * size.y * 0.5f, - {subregion.u1, subregion.v1}, - light, - tint, - normal, - emission - ); - vertex( - pos + right * size.x * 0.5f - up * size.y * 0.5f, - {subregion.u2, subregion.v1}, - light, - tint, - normal, - emission - ); - vertex( - pos + right * size.x * 0.5f + up * size.y * 0.5f, - {subregion.u2, subregion.v2}, - light, - tint, - normal, - emission - ); - - vertex( - pos - right * size.x * 0.5f - up * size.y * 0.5f, - {subregion.u1, subregion.v1}, - light, - tint, - normal, - emission - ); - vertex( - pos + right * size.x * 0.5f + up * size.y * 0.5f, - {subregion.u2, subregion.v2}, - light, - tint, - normal, - emission - ); - vertex( - pos - right * size.x * 0.5f + up * size.y * 0.5f, - {subregion.u1, subregion.v2}, - light, - tint, - normal, - emission - ); - } + ); void cube( const glm::vec3& coord, @@ -156,4 +95,15 @@ public: float emission, uint8_t cullingBits = 0xFF ); +private: + std::unique_ptr const buffer; + size_t const capacity; + size_t index; + + UVRegion region {0.0f, 0.0f, 1.0f, 1.0f}; + + std::unique_ptr> mesh; + std::unique_ptr blank; + + const Texture* texture = nullptr; }; diff --git a/src/graphics/render/ModelBatch.hpp b/src/graphics/render/ModelBatch.hpp index 460b8e13b..84b182c83 100644 --- a/src/graphics/render/ModelBatch.hpp +++ b/src/graphics/render/ModelBatch.hpp @@ -21,6 +21,25 @@ namespace model { using TextureNamesMap = std::unordered_map; class ModelBatch { +public: + ModelBatch( + size_t capacity, + const Assets& assets, + const Chunks& chunks, + const EngineSettings& settings + ); + ~ModelBatch(); + + void draw( + const glm::mat4& matrix, + const glm::vec4& tint, + const model::Model* model, + const TextureNamesMap* varTextures + ); + void render(); + + void setLightsOffset(const glm::vec3& offset); +private: const Assets& assets; const Chunks& chunks; @@ -51,22 +70,4 @@ class ModelBatch { const TextureNamesMap* varTextures; }; std::vector entries; -public: - ModelBatch( - size_t capacity, - const Assets& assets, - const Chunks& chunks, - const EngineSettings& settings - ); - ~ModelBatch(); - - void draw( - const glm::mat4& matrix, - const glm::vec4& tint, - const model::Model* model, - const TextureNamesMap* varTextures - ); - void render(); - - void setLightsOffset(const glm::vec3& offset); };