add modeltree:set_texture

This commit is contained in:
MihailRis
2024-07-03 03:33:39 +03:00
parent 8add39e506
commit 39d850a48c
7 changed files with 68 additions and 14 deletions
+15 -4
View File
@@ -1,9 +1,12 @@
#ifndef GRAPHICS_RENDER_MODEL_BATCH_HPP_
#define GRAPHICS_RENDER_MODEL_BATCH_HPP_
#include "../../maths/UVRegion.hpp"
#include <memory>
#include <vector>
#include <glm/glm.hpp>
#include <unordered_map>
class Mesh;
class Texture;
@@ -15,6 +18,8 @@ namespace model {
struct Model;
}
using texture_names_map = std::unordered_map<std::string, std::string>;
class ModelBatch {
std::unique_ptr<float[]> const buffer;
size_t const capacity;
@@ -30,6 +35,7 @@ class ModelBatch {
Assets* assets;
Chunks* chunks;
Texture* texture = nullptr;
UVRegion region {0.0f, 0.0f, 1.0f, 1.0f};
static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f};
@@ -40,8 +46,8 @@ class ModelBatch {
buffer[index++] = pos.x;
buffer[index++] = pos.y;
buffer[index++] = pos.z;
buffer[index++] = uv.x;
buffer[index++] = uv.y;
buffer[index++] = uv.x * region.getWidth() + region.u1;
buffer[index++] = uv.y * region.getHeight() + region.v1;
union {
float floating;
@@ -72,8 +78,11 @@ class ModelBatch {
vertex(pos-right+up, {0,1}, color);
}
void draw(const model::Mesh& mesh, const glm::mat4& matrix, const glm::mat3& rotation);
void draw(const model::Mesh& mesh, const glm::mat4& matrix,
const glm::mat3& rotation, const texture_names_map* varTextures);
void box(glm::vec3 pos, glm::vec3 size, glm::vec4 lights);
void setTexture(const std::string& name,
const texture_names_map* varTextures);
void setTexture(Texture* texture);
void flush();
@@ -81,6 +90,7 @@ class ModelBatch {
glm::mat4 matrix;
glm::mat3 rotation;
const model::Mesh* mesh;
const texture_names_map* varTextures;
};
std::vector<DrawEntry> entries;
public:
@@ -93,7 +103,8 @@ public:
void pushMatrix(glm::mat4 matrix);
void popMatrix();
void draw(const model::Model* model);
void draw(const model::Model* model,
const texture_names_map* varTextures);
void render();
};