72 lines
1.6 KiB
C++
72 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <glad/glad.h>
|
|
#include <glm/glm.hpp>
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
#include "shader.hpp"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
struct Vertex {
|
|
glm::vec3 position;
|
|
glm::vec3 normal;
|
|
glm::vec2 tex_coords;
|
|
};
|
|
|
|
struct TextureCounts {
|
|
unsigned int diffuseNr = 1;
|
|
unsigned int specularNr = 1;
|
|
unsigned int normalNr = 1;
|
|
unsigned int heightNr = 1;
|
|
};
|
|
|
|
struct Texture {
|
|
unsigned int id;
|
|
std::string type;
|
|
std::string path;
|
|
std::string target;
|
|
int uniform_id=-1;
|
|
|
|
Texture(unsigned int id, const std::string& type, const std::string& path, TextureCounts& count) :
|
|
id(id), type(type)
|
|
{
|
|
unsigned int number = 0;
|
|
|
|
if(type == "texture_diffuse") {
|
|
number = count.diffuseNr++;
|
|
} else if(type == "texture_specular") {
|
|
number = count.specularNr++;
|
|
} else if(type == "texture_normal") {
|
|
number = count.normalNr++;
|
|
} else if(type == "texture_height") {
|
|
number = count.heightNr++;
|
|
} else {
|
|
dbc::sentinel($F("Invalid texture type={} for file={}", type, path));
|
|
}
|
|
|
|
target = std::format("{}{}", type, number);
|
|
}
|
|
};
|
|
|
|
struct Mesh {
|
|
std::vector<Vertex> vertices;
|
|
std::vector<unsigned int> indices;
|
|
std::vector<Texture> textures;
|
|
unsigned int VAO = 0;
|
|
unsigned int VBO = 0;
|
|
unsigned int EBO = 0;
|
|
|
|
Mesh(std::vector<Vertex>& vertices, std::vector<unsigned int>& indices, std::vector<Texture>& textures) :
|
|
vertices(vertices),
|
|
indices(indices),
|
|
textures(textures)
|
|
{
|
|
setup_mesh();
|
|
}
|
|
|
|
void draw(Shader &shader);
|
|
void setup_mesh();
|
|
void apply_textures(const Shader& shader);
|
|
};
|