add support for high res brush textures, implement mipmaps on brush

This commit is contained in:
2017-09-30 16:35:12 +01:00
parent 763e446cc5
commit 964795b44d
17 changed files with 61 additions and 20 deletions

View File

@@ -5,12 +5,15 @@
std::map<uint16_t, Texture2D> TextureManager::m_textures;
bool TextureManager::load(const char* path)
bool TextureManager::load(const char* path, bool generate_mipmaps)
{
uint16_t id = const_hash(path);
if (m_textures.count(id) == 0 || !m_textures[id].ready())
{
return m_textures[id].load(path);
if (!m_textures[id].load(path))
return false;
if (generate_mipmaps)
m_textures[id].create_mipmaps();
}
return true;
}
@@ -54,6 +57,13 @@ bool Texture2D::create(const ui::Image& img)
return create(img.width, img.height, iformats[img.comp - 1], formats[img.comp - 1], img.data());
}
void Texture2D::create_mipmaps()
{
bind();
glGenerateMipmap(GL_TEXTURE_2D);
unbind();
}
void Texture2D::assign(GLuint tex, int w/* = -1*/, int h/* = -1*/, GLuint internal_format/* = GL_RGBA8*/, GLuint format/* = GL_RGBA*/)
{
m_tex = tex;
@@ -102,6 +112,13 @@ void Sampler::set(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*
glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, filter);
#endif // USE_SAMPLER
}
void Sampler::set_filter(GLint filter_min, GLint filter_mag)
{
#if USE_SAMPLER
glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, filter_min);
glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, filter_mag);
#endif // USE_SAMPLER
}
void Sampler::bind(int unit)
{
current_unit = unit;