This commit is contained in:
ZY4N
2025-03-23 21:11:22 +01:00
parent 510398423a
commit c609d49f0d
49 changed files with 1412 additions and 924 deletions

View File

@@ -4,13 +4,10 @@
namespace zgl
{
inline texture_data::texture_data(const GLuint texture_id)
: m_handle{ texture_id } {}
inline texture_data::texture_data(texture_data&& other) noexcept
: m_handle{ other.m_handle }
: handle{ other.handle }
{
other.m_handle.texture_id = 0;
other.handle.id = 0;
}
inline texture_data& texture_data::operator=(texture_data&& other) noexcept
@@ -19,61 +16,24 @@ inline texture_data& texture_data::operator=(texture_data&& other) noexcept
{
this->~texture_data();
m_handle = other.m_handle;
handle = other.handle;
other.m_handle.texture_id = 0;
other.handle.id = 0;
}
return *this;
}
template<typename T>
std::error_code texture_data::build_from(
std::span<const T> buffer,
const GLenum format,
const GLenum type,
const GLsizei width,
const GLsizei height,
texture_data& data
) {
GLuint texture_id;
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(
GL_TEXTURE_2D, 0,
GL_RGBA8,
width,
height,
0,
format, type,
buffer.data()
);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
data = texture_data(texture_id);
return {};
}
inline texture_data::~texture_data()
{
if (m_handle.texture_id)
if (handle.id)
{
glDeleteTextures(1, &m_handle.texture_id);
glDeleteTextures(1, &handle.id);
}
}
inline texture_handle texture_data::handle() const
{
return { m_handle.texture_id };
return { handle.id };
}
}