refactor export equirectangular

This commit is contained in:
2019-08-15 19:12:50 +02:00
parent e959fb4d91
commit 542e5a9c19
12 changed files with 223 additions and 206 deletions

View File

@@ -5,6 +5,75 @@
#include "app.h"
std::map<uint16_t, Texture2D> TextureManager::m_textures;
std::array<int, 6> TextureCube::m_faces_map {
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, // front
GL_TEXTURE_CUBE_MAP_NEGATIVE_X, // right
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, // back
GL_TEXTURE_CUBE_MAP_POSITIVE_X, // left
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, // top
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, // bottom
};
TextureCube::TextureCube(TextureCube&& other) noexcept
{
other.m_faces = std::move(other.m_faces);
m_cubetex_id = other.m_cubetex_id; other.m_cubetex_id = 0;
m_resolution = other.m_resolution; other.m_resolution = 0;
}
TextureCube::~TextureCube()
{
destroy();
}
void TextureCube::operator=(TextureCube&& other) noexcept
{
other.m_faces = std::move(other.m_faces);
m_cubetex_id = other.m_cubetex_id; other.m_cubetex_id = 0;
m_resolution = other.m_resolution; other.m_resolution = 0;
}
bool TextureCube::create(int resolution) noexcept
{
App::I->render_task([this, resolution]
{
destroy();
m_resolution = resolution;
glGenTextures(1, &m_cubetex_id);
if (!m_cubetex_id)
return;
glBindTexture(GL_TEXTURE_CUBE_MAP, m_cubetex_id);
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);
}
});
return m_cubetex_id != 0;
}
void TextureCube::destroy() noexcept
{
if (m_cubetex_id)
{
App::I->render_task([f=m_faces, id=m_cubetex_id]
{
glDeleteTextures(f.size(), f.data());
glDeleteTextures(1, &id);
});
m_cubetex_id = 0;
m_faces.fill(0);
m_resolution = 0;
}
}
void TextureCube::bind() const noexcept
{
assert(App::I->is_render_thread());
glBindTexture(GL_TEXTURE_CUBE_MAP, m_cubetex_id);
}
bool TextureManager::load(const char* path, bool generate_mipmaps)
{
@@ -39,6 +108,18 @@ void TextureManager::invalidate()
m_textures.clear();
}
Image Texture2D::get_image() const noexcept
{
Image ret;
ret.create(m_width, m_height);
App::I->render_task([&]
{
bind();
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, ret.m_data.get());
});
return ret;
}
bool Texture2D::create(int width, int height, GLint internal_format, GLint format, const uint8_t* data)
{
App::I->render_task([=]