add MainBatch & refactor ModelBatch, Batch3D

This commit is contained in:
MihailRis
2024-11-02 19:37:39 +03:00
parent 316de42cca
commit bbd13f1825
6 changed files with 159 additions and 110 deletions
+3 -36
View File
@@ -13,6 +13,7 @@ class Texture;
class Chunks;
class Assets;
struct EngineSettings;
class MainBatch;
namespace model {
struct Mesh;
@@ -22,47 +23,15 @@ namespace model {
using texture_names_map = std::unordered_map<std::string, std::string>;
class ModelBatch {
std::unique_ptr<float[]> const buffer;
size_t const capacity;
size_t index;
std::unique_ptr<Mesh> mesh;
std::unique_ptr<Texture> blank;
Assets* assets;
Chunks* chunks;
const Texture* texture = nullptr;
UVRegion region {0.0f, 0.0f, 1.0f, 1.0f};
const EngineSettings* settings;
glm::vec3 lightsOffset {};
static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f};
inline void vertex(
glm::vec3 pos, glm::vec2 uv, glm::vec4 light, glm::vec3 tint
) {
float* buffer = this->buffer.get();
buffer[index++] = pos.x;
buffer[index++] = pos.y;
buffer[index++] = pos.z;
buffer[index++] = uv.x * region.getWidth() + region.u1;
buffer[index++] = uv.y * region.getHeight() + region.v1;
buffer[index++] = tint.x;
buffer[index++] = tint.y;
buffer[index++] = tint.z;
union {
float floating;
uint32_t integer;
} compressed;
compressed.integer = (static_cast<uint32_t>(light.r * 255) & 0xff) << 24;
compressed.integer |= (static_cast<uint32_t>(light.g * 255) & 0xff) << 16;
compressed.integer |= (static_cast<uint32_t>(light.b * 255) & 0xff) << 8;
compressed.integer |= (static_cast<uint32_t>(light.a * 255) & 0xff);
buffer[index++] = compressed.floating;
}
std::unique_ptr<MainBatch> batch;
void draw(const model::Mesh& mesh,
const glm::mat4& matrix,
@@ -72,8 +41,6 @@ class ModelBatch {
bool backlight);
void setTexture(const std::string& name,
const texture_names_map* varTextures);
void setTexture(const Texture* texture);
void flush();
struct DrawEntry {
glm::mat4 matrix;