cleanup a bit

This commit is contained in:
MihailRis 2026-09-16 23:31:37 +03:00
parent ae082abaa2
commit dbeeef90a8
3 changed files with 95 additions and 81 deletions

View file

@ -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,

View file

@ -31,16 +31,6 @@ struct MainBatchVertex {
};
class MainBatch {
std::unique_ptr<MainBatchVertex[]> const buffer;
size_t const capacity;
size_t index;
UVRegion region {0.0f, 0.0f, 1.0f, 1.0f};
std::unique_ptr<Mesh<MainBatchVertex>> mesh;
std::unique_ptr<Texture> 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<MainBatchVertex[]> const buffer;
size_t const capacity;
size_t index;
UVRegion region {0.0f, 0.0f, 1.0f, 1.0f};
std::unique_ptr<Mesh<MainBatchVertex>> mesh;
std::unique_ptr<Texture> blank;
const Texture* texture = nullptr;
};

View file

@ -21,6 +21,25 @@ namespace model {
using TextureNamesMap = std::unordered_map<std::string, std::string>;
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<DrawEntry> 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);
};