Files
Z3D/source/opengl/data/mesh_data.ipp
2024-12-22 16:58:40 +01:00

91 lines
2.0 KiB
C++

#ifndef INCLUDE_MESH_DATA_IMPLEMENTATION
# error Never include this file directly include 'mesh_data.hpp'
#endif
namespace zgl
{
inline mesh_data::mesh_data(
const GLuint vertex_vbo_id,
const GLuint index_vbo_id,
const GLuint vao_id,
const ztu::u32 material_id,
const components::mesh_vertex::flags components,
const GLsizei index_count
) :
m_handle{
.vao_id = vao_id,
.index_count = index_count
},
m_vertex_vbo_id{ vertex_vbo_id },
m_index_vbo_id{ index_vbo_id },
m_material_id{ material_id },
m_component_types{ components } {}
inline mesh_data& mesh_data::operator=(mesh_data&& other) noexcept
{
if (&other != this)
{
this->~mesh_data();
m_handle = other.m_handle;
m_vertex_vbo_id = other.m_vertex_vbo_id;
m_index_vbo_id = other.m_index_vbo_id;
m_material_id = other.m_material_id;
m_component_types = other.m_component_types;
other.m_handle.vao_id = 0;
other.m_handle.index_count = 0;
other.m_vertex_vbo_id = 0;
other.m_index_vbo_id = 0;
other.m_material_id = 0;
other.m_component_types = components::mesh_vertex::flags::none;
}
return *this;
}
inline mesh_data::mesh_data(mesh_data&& other) noexcept :
m_handle{ other.m_handle },
m_vertex_vbo_id{ other.m_vertex_vbo_id },
m_index_vbo_id{ other.m_index_vbo_id },
m_material_id{ other.m_material_id },
m_component_types{ other.m_component_types }
{
other.m_handle.vao_id = 0;
other.m_handle.index_count = 0;
other.m_vertex_vbo_id = 0;
other.m_index_vbo_id = 0;
other.m_material_id = 0;
other.m_component_types = components::mesh_vertex::flags::none;
}
inline mesh_data::~mesh_data() {
if (m_vertex_vbo_id) {
glDeleteBuffers(1, &m_vertex_vbo_id);
}
if (m_index_vbo_id) {
glDeleteBuffers(1, &m_index_vbo_id);
}
if (m_handle.vao_id) {
glDeleteVertexArrays(1, &m_handle.vao_id);
}
}
inline mesh_handle mesh_data::handle() const
{
return m_handle;
}
inline components::mesh_vertex::flags mesh_data::components() const
{
return m_component_types;
}
inline ztu::u32 mesh_data::material_id() const
{
return m_material_id;
}
}