mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 22:11:51 +00:00
cleanup a bit
This commit is contained in:
parent
ae082abaa2
commit
dbeeef90a8
3 changed files with 95 additions and 81 deletions
|
|
@ -82,6 +82,69 @@ inline glm::vec4 do_tint(float value) {
|
||||||
return {value, value, value, 1.0f};
|
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(
|
void MainBatch::cube(
|
||||||
const glm::vec3& coord,
|
const glm::vec3& coord,
|
||||||
const glm::vec3& size,
|
const glm::vec3& size,
|
||||||
|
|
|
||||||
|
|
@ -31,16 +31,6 @@ struct MainBatchVertex {
|
||||||
};
|
};
|
||||||
|
|
||||||
class MainBatch {
|
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:
|
public:
|
||||||
/// xyz, uv, color, compressed lights
|
/// xyz, uv, color, compressed lights
|
||||||
|
|
||||||
|
|
@ -84,7 +74,7 @@ public:
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void quad(
|
void quad(
|
||||||
const glm::vec3& pos,
|
const glm::vec3& pos,
|
||||||
const glm::vec3& right,
|
const glm::vec3& right,
|
||||||
const glm::vec3& up,
|
const glm::vec3& up,
|
||||||
|
|
@ -94,58 +84,7 @@ public:
|
||||||
const glm::vec4& tint,
|
const glm::vec4& tint,
|
||||||
const UVRegion& subregion,
|
const UVRegion& subregion,
|
||||||
float emission = 0.0f
|
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(
|
void cube(
|
||||||
const glm::vec3& coord,
|
const glm::vec3& coord,
|
||||||
|
|
@ -156,4 +95,15 @@ public:
|
||||||
float emission,
|
float emission,
|
||||||
uint8_t cullingBits = 0xFF
|
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;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,25 @@ namespace model {
|
||||||
using TextureNamesMap = std::unordered_map<std::string, std::string>;
|
using TextureNamesMap = std::unordered_map<std::string, std::string>;
|
||||||
|
|
||||||
class ModelBatch {
|
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 Assets& assets;
|
||||||
const Chunks& chunks;
|
const Chunks& chunks;
|
||||||
|
|
||||||
|
|
@ -51,22 +70,4 @@ class ModelBatch {
|
||||||
const TextureNamesMap* varTextures;
|
const TextureNamesMap* varTextures;
|
||||||
};
|
};
|
||||||
std::vector<DrawEntry> entries;
|
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);
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue