add Sampler class, add attributes system
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include "texture.hpp"
|
||||
#include "image.hpp"
|
||||
|
||||
bool Texture2D::create(int width, int height, GLint format, const uint8_t* data, GLint filter, GLint wrap)
|
||||
bool Texture2D::create(int width, int height, GLint format, const uint8_t* data)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
@@ -10,10 +10,6 @@ bool Texture2D::create(int width, int height, GLint format, const uint8_t* data,
|
||||
glGenTextures(1, &m_tex);
|
||||
bind();
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
|
||||
unbind();
|
||||
return true;
|
||||
}
|
||||
@@ -34,3 +30,28 @@ void Texture2D::update(const uint8_t* data)
|
||||
bind();
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, m_format, GL_UNSIGNED_BYTE, data);
|
||||
}
|
||||
|
||||
bool Sampler::create(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*/)
|
||||
{
|
||||
glGenSamplers(1, &id);
|
||||
if (id == 0)
|
||||
return false;
|
||||
set(filter, wrap);
|
||||
return true;
|
||||
}
|
||||
void Sampler::set(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*/)
|
||||
{
|
||||
glSamplerParameteri(id, GL_TEXTURE_WRAP_S, wrap);
|
||||
glSamplerParameteri(id, GL_TEXTURE_WRAP_T, wrap);
|
||||
glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, filter);
|
||||
glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, filter);
|
||||
}
|
||||
void Sampler::bind(int unit)
|
||||
{
|
||||
current_unit = unit;
|
||||
glBindSampler(unit, id);
|
||||
}
|
||||
void Sampler::unbind()
|
||||
{
|
||||
glBindSampler(current_unit, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user