Move texture defaults behind renderer gl

This commit is contained in:
2026-06-02 08:51:34 +02:00
parent 8a92bc973b
commit a12a3454c4
9 changed files with 118 additions and 10 deletions

View File

@@ -126,11 +126,22 @@ bool TextureManager::load(const char* path, bool generate_mipmaps)
return true;
}
void TextureManager::assign(uint16_t id, GLuint tex, int w/* = -1*/, int h/* = -1*/, GLuint internal_format/* = GL_RGBA8*/, GLuint format/* = GL_RGBA*/)
void TextureManager::assign(uint16_t id, GLuint tex, int w, int h, GLuint internal_format, GLuint format)
{
m_textures[id].assign(tex, w, h, internal_format, format);
}
void TextureManager::assign(uint16_t id, GLuint tex, int w, int h)
{
assign(
id,
tex,
w,
h,
pp::renderer::gl::rgba8_internal_format(),
pp::renderer::gl::rgba_pixel_format());
}
Texture2D& TextureManager::get(uint16_t id)
{
return m_textures[id];
@@ -215,6 +226,24 @@ void Texture2D::operator=(Texture2D&& other) noexcept
other.m_tex = false;
}
bool Texture2D::create(int width, int height)
{
return create(
width,
height,
static_cast<GLint>(pp::renderer::gl::rgba8_internal_format()),
static_cast<GLint>(pp::renderer::gl::rgba_pixel_format()));
}
bool Texture2D::create(int width, int height, GLint internal_format)
{
return create(
width,
height,
internal_format,
static_cast<GLint>(pp::renderer::gl::rgba_pixel_format()));
}
bool Texture2D::create(int width, int height, GLint internal_format, GLint format, const uint8_t* data)
{
App::I->render_task([=]
@@ -259,7 +288,7 @@ void Texture2D::create_mipmaps()
});
}
void Texture2D::assign(GLuint tex, int w/* = -1*/, int h/* = -1*/, GLuint internal_format/* = GL_RGBA8*/, GLuint format/* = GL_RGBA*/)
void Texture2D::assign(GLuint tex, int w, int h, GLuint internal_format, GLuint format)
{
m_tex = tex;
m_width = w;
@@ -268,6 +297,16 @@ void Texture2D::assign(GLuint tex, int w/* = -1*/, int h/* = -1*/, GLuint intern
m_iformat = internal_format;
}
void Texture2D::assign(GLuint tex, int w, int h)
{
assign(
tex,
w,
h,
pp::renderer::gl::rgba8_internal_format(),
pp::renderer::gl::rgba_pixel_format());
}
bool Texture2D::load(std::string filename)
{
LOG("load texture %s", filename.c_str());
@@ -338,7 +377,7 @@ Texture2D::~Texture2D()
destroy();
}
bool Sampler::create(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*/)
bool Sampler::create(GLint filter, GLint wrap)
{
bool ret = false;
App::I->render_task([this, &ret, filter, wrap]
@@ -356,7 +395,20 @@ bool Sampler::create(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_ED
});
return ret;
}
void Sampler::set(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*/)
bool Sampler::create()
{
return create(
static_cast<GLint>(pp::renderer::gl::linear_texture_filter()),
static_cast<GLint>(pp::renderer::gl::clamp_to_edge_texture_wrap()));
}
bool Sampler::create(GLint filter)
{
return create(filter, static_cast<GLint>(pp::renderer::gl::clamp_to_edge_texture_wrap()));
}
void Sampler::set(GLint filter, GLint wrap)
{
App::I->render_task([=]
{
@@ -370,6 +422,19 @@ void Sampler::set(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*
#endif // USE_SAMPLER
});
}
void Sampler::set()
{
set(
static_cast<GLint>(pp::renderer::gl::linear_texture_filter()),
static_cast<GLint>(pp::renderer::gl::clamp_to_edge_texture_wrap()));
}
void Sampler::set(GLint filter)
{
set(filter, static_cast<GLint>(pp::renderer::gl::clamp_to_edge_texture_wrap()));
}
void Sampler::set_filter(GLint filter_min, GLint filter_mag)
{
App::I->render_task([=]