refactor export equirectangular
This commit is contained in:
@@ -1,8 +1,74 @@
|
||||
#include "pch.h"
|
||||
#include "canvas_layer.h"
|
||||
#include "app.h"
|
||||
#include "rtt.h"
|
||||
|
||||
uint32_t Layer::s_count = 0;
|
||||
|
||||
TextureCube Layer::gen_cube()
|
||||
{
|
||||
TextureCube ret;
|
||||
App::I->render_task([&]
|
||||
{
|
||||
ret.create(w);
|
||||
ret.bind();
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_rtt[i].bindFramebuffer();
|
||||
glCopyTexSubImage2D(TextureCube::m_faces_map[i], 0, 0, 0, 0, 0, w, w);
|
||||
m_rtt[i].unbindFramebuffer();
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
Texture2D Layer::gen_equirect()
|
||||
{
|
||||
Texture2D ret;
|
||||
|
||||
App::I->render_task([&]
|
||||
{
|
||||
gl_state gl;
|
||||
gl.save();
|
||||
|
||||
TextureCube cube;
|
||||
RTT latlong;
|
||||
|
||||
cube = gen_cube();
|
||||
latlong.create(w * 4, h * 2);
|
||||
ret.create(w * 4, h * 2);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
latlong.bindFramebuffer();
|
||||
|
||||
latlong.clear({ 0, 1, 1, 1 });
|
||||
|
||||
glViewport(0, 0, latlong.getWidth(), latlong.getHeight());
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cube.m_cubetex_id);
|
||||
|
||||
ShaderManager::use(kShader::Equirect);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
Canvas::I->m_sampler.bind(0);
|
||||
Canvas::I->m_plane.draw_fill();
|
||||
|
||||
ret.bind();
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, latlong.getWidth(), latlong.getHeight());
|
||||
|
||||
latlong.unbindFramebuffer();
|
||||
|
||||
latlong.destroy();
|
||||
cube.destroy();
|
||||
|
||||
gl.restore();
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Layer::Snapshot::create(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
|
||||
Reference in New Issue
Block a user