Move texture cube mapping to renderer gl

This commit is contained in:
2026-06-02 06:43:51 +02:00
parent 85a5d19a3e
commit 0d2a1bd0ae
6 changed files with 53 additions and 9 deletions

View File

@@ -14,6 +14,11 @@ namespace {
return static_cast<GLenum>(pp::renderer::gl::texture_2d_target());
}
[[nodiscard]] GLenum texture_cube_map_target() noexcept
{
return static_cast<GLenum>(pp::renderer::gl::texture_cube_map_target());
}
[[nodiscard]] GLenum framebuffer_target() noexcept
{
return static_cast<GLenum>(pp::renderer::gl::framebuffer_target());
@@ -66,11 +71,21 @@ bool TextureCube::create(int resolution) noexcept
if (!m_cubetex_id)
return;
glBindTexture(GL_TEXTURE_CUBE_MAP, m_cubetex_id);
glBindTexture(texture_cube_map_target(), m_cubetex_id);
const auto format = pp::renderer::gl::texture_format_for_channel_count(4U);
const auto component_type = static_cast<GLenum>(pp::renderer::gl::unsigned_byte_component_type());
for (GLuint i = 0; i < 6; i++)
{
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA8,
m_resolution, m_resolution, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexImage2D(
static_cast<GLenum>(pp::renderer::gl::cube_map_allocation_face_texture_target(i)),
0,
static_cast<GLint>(format.internal_format),
m_resolution,
m_resolution,
0,
static_cast<GLenum>(format.pixel_format),
component_type,
nullptr);
}
});
return m_cubetex_id != 0;
@@ -82,7 +97,7 @@ void TextureCube::destroy() noexcept
{
App::I->render_task([f=m_faces, id=m_cubetex_id]
{
glDeleteTextures(f.size(), f.data());
glDeleteTextures(static_cast<GLsizei>(f.size()), f.data());
glDeleteTextures(1, &id);
});
m_cubetex_id = 0;
@@ -94,7 +109,7 @@ void TextureCube::destroy() noexcept
void TextureCube::bind() const noexcept
{
assert(App::I->is_render_thread());
glBindTexture(GL_TEXTURE_CUBE_MAP, m_cubetex_id);
glBindTexture(texture_cube_map_target(), m_cubetex_id);
}
bool TextureManager::load(const char* path, bool generate_mipmaps)