add MeshData
This commit is contained in:
parent
d41ec3a019
commit
5c6b73ee2b
@ -4,6 +4,19 @@
|
||||
int Mesh::meshesCount = 0;
|
||||
int Mesh::drawCalls = 0;
|
||||
|
||||
inline size_t calc_vertex_size(const vattr* attrs) {
|
||||
size_t vertexSize = 0;
|
||||
for (int i = 0; attrs[i].size; i++) {
|
||||
vertexSize += attrs[i].size;
|
||||
}
|
||||
return vertexSize;
|
||||
}
|
||||
|
||||
Mesh::Mesh(const MeshData& data)
|
||||
: Mesh(data.vertices.data(),
|
||||
data.vertices.size() / calc_vertex_size(data.attrs.data()),
|
||||
data.attrs.data()) {}
|
||||
|
||||
Mesh::Mesh(const float* vertexBuffer, size_t vertices, const int* indexBuffer, size_t indices, const vattr* attrs) :
|
||||
ibo(0),
|
||||
vertices(vertices),
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "typedefs.hpp"
|
||||
|
||||
struct vattr {
|
||||
ubyte size;
|
||||
};
|
||||
#include "typedefs.hpp"
|
||||
#include "MeshData.hpp"
|
||||
|
||||
class Mesh {
|
||||
unsigned int vao;
|
||||
@ -15,6 +13,7 @@ class Mesh {
|
||||
size_t indices;
|
||||
size_t vertexSize;
|
||||
public:
|
||||
Mesh(const MeshData& data);
|
||||
Mesh(const float* vertexBuffer, size_t vertices, const int* indexBuffer, size_t indices, const vattr* attrs);
|
||||
Mesh(const float* vertexBuffer, size_t vertices, const vattr* attrs) :
|
||||
Mesh(vertexBuffer, vertices, nullptr, 0, attrs) {};
|
||||
|
||||
29
src/graphics/core/MeshData.hpp
Normal file
29
src/graphics/core/MeshData.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "typedefs.hpp"
|
||||
#include "util/Buffer.hpp"
|
||||
|
||||
/// @brief Vertex attribute info
|
||||
struct vattr {
|
||||
ubyte size;
|
||||
};
|
||||
|
||||
/// @brief Raw mesh data structure
|
||||
struct MeshData {
|
||||
util::Buffer<float> vertices;
|
||||
util::Buffer<int> indices;
|
||||
util::Buffer<vattr> attrs;
|
||||
|
||||
/// @param vertices vertex data buffer
|
||||
/// @param indices nullable indices buffer
|
||||
/// @param attrs vertex attribute sizes (must be null-terminated)
|
||||
MeshData(
|
||||
util::Buffer<float> vertices,
|
||||
util::Buffer<int> indices,
|
||||
util::Buffer<vattr> attrs
|
||||
) : vertices(std::move(vertices)),
|
||||
indices(std::move(indices)),
|
||||
attrs(std::move(attrs)) {}
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user