73 lines
1.5 KiB
C++
73 lines
1.5 KiB
C++
// Copyright (c) 2025 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "Mesh.hpp"
|
|
#include "assert/Assert.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
Mesh::Mesh(
|
|
const int32_t vertexCount,
|
|
const PrimitiveType primitiveType,
|
|
const MeshVertex *vertices
|
|
) :
|
|
vertexCount(vertexCount),
|
|
primitiveType(primitiveType),
|
|
vertices(vertices)
|
|
{
|
|
|
|
}
|
|
|
|
void Mesh::draw(
|
|
int32_t vertexOffset,
|
|
int32_t vertexCount
|
|
) const {
|
|
const int32_t offset = vertexOffset == -1 ? 0 : vertexOffset;
|
|
const int32_t count = vertexCount == -1 ? this->vertexCount : vertexCount;
|
|
|
|
assertNotNull(this->vertices, "Mesh cannot be NULL");
|
|
assertTrue(offset >= 0, "Vertex offset must be non-negative");
|
|
assertTrue(count >= 0, "Vertex count must be non-negative");
|
|
assertTrue(
|
|
offset + count <= this->vertexCount,
|
|
"Vertex offset + count must not exceed vertex count"
|
|
);
|
|
|
|
#if DISPLAY_SDL2
|
|
// PSP style pointer legacy OpenGL
|
|
const GLsizei stride = sizeof(MeshVertex);
|
|
|
|
glColorPointer(
|
|
MESH_VERTEX_COLOR_SIZE,
|
|
GL_UNSIGNED_BYTE,
|
|
stride,
|
|
(const GLvoid*)&this->vertices[offset].color[0]
|
|
);
|
|
|
|
glTexCoordPointer(
|
|
MESH_VERTEX_UV_SIZE,
|
|
GL_FLOAT,
|
|
stride,
|
|
(const GLvoid*)&this->vertices[offset].uv[0]
|
|
);
|
|
|
|
glVertexPointer(
|
|
MESH_VERTEX_POS_SIZE,
|
|
GL_FLOAT,
|
|
stride,
|
|
(const GLvoid*)&this->vertices[offset].pos[0]
|
|
);
|
|
|
|
glDrawArrays(
|
|
this->primitiveType,
|
|
0,
|
|
count
|
|
);
|
|
#endif
|
|
}
|
|
|
|
Mesh::~Mesh() {
|
|
|
|
} |