Simplify setting texture filters & add anisotropic filtering
This commit is contained in:
parent
8a37d29b5e
commit
d7e0599556
2 changed files with 31 additions and 1 deletions
|
|
@ -103,6 +103,9 @@ namespace psemek::gfx
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_mipmap();
|
void generate_mipmap();
|
||||||
|
void nearest_filter();
|
||||||
|
void linear_filter();
|
||||||
|
void anisotropy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLuint id_;
|
GLuint id_;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include <psemek/gfx/texture.hpp>
|
#include <psemek/gfx/texture.hpp>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace psemek::gfx
|
namespace psemek::gfx
|
||||||
{
|
{
|
||||||
|
|
@ -56,7 +57,6 @@ namespace psemek::gfx
|
||||||
{
|
{
|
||||||
bind();
|
bind();
|
||||||
gl::TexImage2D(gl::TEXTURE_2D, 0, internal_format, width, height, 0, format, type, data);
|
gl::TexImage2D(gl::TEXTURE_2D, 0, internal_format, width, height, 0, format, type, data);
|
||||||
gl::GenerateMipmap(gl::TEXTURE_2D);
|
|
||||||
|
|
||||||
width_ = width;
|
width_ = width;
|
||||||
height_ = height;
|
height_ = height;
|
||||||
|
|
@ -81,4 +81,31 @@ namespace psemek::gfx
|
||||||
gl::GenerateMipmap(gl::TEXTURE_2D);
|
gl::GenerateMipmap(gl::TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void texture_2d::nearest_filter()
|
||||||
|
{
|
||||||
|
bind();
|
||||||
|
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST);
|
||||||
|
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR_MIPMAP_LINEAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
void texture_2d::linear_filter()
|
||||||
|
{
|
||||||
|
bind();
|
||||||
|
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR);
|
||||||
|
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR_MIPMAP_LINEAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
void texture_2d::anisotropy()
|
||||||
|
{
|
||||||
|
if (!gl::exts::var_EXT_texture_filter_anisotropic) return;
|
||||||
|
|
||||||
|
static std::optional<float> level;
|
||||||
|
if (!level)
|
||||||
|
{
|
||||||
|
level = 0;
|
||||||
|
gl::GetFloatv(gl::MAX_TEXTURE_MAX_ANISOTROPY_EXT, &(*level));
|
||||||
|
}
|
||||||
|
gl::TexParameterf(gl::TEXTURE_2D, gl::TEXTURE_MAX_ANISOTROPY_EXT, *level);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue