...
This commit is contained in:
@@ -11,13 +11,13 @@
|
||||
namespace zgl
|
||||
{
|
||||
inline shader_program_data::shader_program_data(GLuint program_id)
|
||||
: m_handle{ program_id } {}
|
||||
: handle{ program_id } {}
|
||||
|
||||
|
||||
inline shader_program_data::shader_program_data(shader_program_data&& other) noexcept
|
||||
{
|
||||
m_handle = other.m_handle;
|
||||
other.m_handle.program_id = 0;
|
||||
handle = other.handle;
|
||||
other.handle.id = 0;
|
||||
}
|
||||
|
||||
inline shader_program_data& shader_program_data::operator=(shader_program_data&& other) noexcept
|
||||
@@ -25,21 +25,16 @@ inline shader_program_data& shader_program_data::operator=(shader_program_data&&
|
||||
if (&other != this)
|
||||
{
|
||||
this->~shader_program_data();
|
||||
m_handle = other.m_handle;
|
||||
other.m_handle.program_id = 0;
|
||||
handle = other.handle;
|
||||
other.handle.id = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline shader_program_data::~shader_program_data()
|
||||
{
|
||||
if (m_handle.program_id) {
|
||||
glDeleteProgram(m_handle.program_id);
|
||||
if (handle.id) {
|
||||
glDeleteProgram(handle.id);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] inline shader_program_handle shader_program_data::handle() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user