check float texture extension, use float32 or float16 if available, show extension on title bar, add thread and render task for lightmap rendering
This commit is contained in:
@@ -1666,6 +1666,9 @@ Here's a list of what's available in this release.
|
|||||||
<border id="ext-fbf" height="20" width="30" color="0 0 0 1" align="center" justify="center" margin="0 5 0 0">
|
<border id="ext-fbf" height="20" width="30" color="0 0 0 1" align="center" justify="center" margin="0 5 0 0">
|
||||||
<text id="txt-rec" text="FbF" color="0 0 0 1"/>
|
<text id="txt-rec" text="FbF" color="0 0 0 1"/>
|
||||||
</border>
|
</border>
|
||||||
|
<border id="ext-flt" height="20" width="40" color="0 0 0 1" align="center" justify="center" margin="0 5 0 0">
|
||||||
|
<text id="ext-flt-text" text="flt" color="0 0 0 1"/>
|
||||||
|
</border>
|
||||||
<border id="ext-dpi" height="20" width="60" color=".2" align="center" justify="center" margin="0 5 0 0">
|
<border id="ext-dpi" height="20" width="60" color=".2" align="center" justify="center" margin="0 5 0 0">
|
||||||
<text id="txt-dpi" text="4x-dpi" color="1"/>
|
<text id="txt-dpi" text="4x-dpi" color="1"/>
|
||||||
</border>
|
</border>
|
||||||
|
|||||||
@@ -1237,6 +1237,23 @@ void App::initLayout()
|
|||||||
x->m_color = ShaderManager::ext_framebuffer_fetch ? glm::vec4(0, 1, 0, 1) : glm::vec4(1, 0, 0, 1);
|
x->m_color = ShaderManager::ext_framebuffer_fetch ? glm::vec4(0, 1, 0, 1) : glm::vec4(1, 0, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auto x = layout[main_id]->find<NodeBorder>("ext-flt"))
|
||||||
|
{
|
||||||
|
if (ShaderManager::ext_texture_float || ShaderManager::ext_half_float_pixel)
|
||||||
|
{
|
||||||
|
if (auto t = x->find<NodeText>("ext-flt-text"))
|
||||||
|
{
|
||||||
|
int bits = ShaderManager::ext_texture_float ? 32 : 16;
|
||||||
|
t->set_text_format("flt%d", bits);
|
||||||
|
}
|
||||||
|
x->m_color = glm::vec4(0, 1, 0, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x->m_color = glm::vec4(1, 0, 0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
brush_update();
|
brush_update();
|
||||||
|
|
||||||
// hacky thing to make the toolbar buttons not steal events when moving cursor fast
|
// hacky thing to make the toolbar buttons not steal events when moving cursor fast
|
||||||
|
|||||||
@@ -15,10 +15,18 @@ void App::initShaders()
|
|||||||
for (int i = 0; i < n_exts; i++)
|
for (int i = 0; i < n_exts; i++)
|
||||||
{
|
{
|
||||||
std::string ext = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
std::string ext = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
||||||
if (ext.find("shader_framebuffer_fetch") != std::string::npos)
|
if (GLAD_GL_EXT_shader_framebuffer_fetch || GLAD_GL_EXT_shader_framebuffer_fetch_non_coherent)
|
||||||
{
|
{
|
||||||
ShaderManager::ext_framebuffer_fetch = true;
|
ShaderManager::ext_framebuffer_fetch = true;
|
||||||
}
|
}
|
||||||
|
else if (GLAD_GL_ARB_texture_float || GLAD_GL_ATI_texture_float)
|
||||||
|
{
|
||||||
|
ShaderManager::ext_texture_float = true;
|
||||||
|
}
|
||||||
|
else if (GLAD_GL_NV_half_float || GLAD_GL_ARB_half_float_pixel)
|
||||||
|
{
|
||||||
|
ShaderManager::ext_half_float_pixel = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1494,15 +1494,24 @@ void Canvas::resize(int width, int height)
|
|||||||
m_size = { width, height };
|
m_size = { width, height };
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
//#if defined(__IOS__) || defined(__ANDROID__)
|
if (ShaderManager::ext_texture_float)
|
||||||
|
{
|
||||||
|
m_tmp[i].create(width, height, -1, GL_RGBA32F);
|
||||||
|
m_tmp_dual[i].create(width, height, -1, GL_RGBA32F);
|
||||||
|
m_tex[i].create(width, height, GL_RGBA32F);
|
||||||
|
}
|
||||||
|
else if (ShaderManager::ext_half_float_pixel)
|
||||||
|
{
|
||||||
|
m_tmp[i].create(width, height, -1, GL_RGBA16F);
|
||||||
|
m_tmp_dual[i].create(width, height, -1, GL_RGBA16F);
|
||||||
|
m_tex[i].create(width, height, GL_RGBA16F);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
m_tmp[i].create(width, height, -1, GL_RGBA8);
|
m_tmp[i].create(width, height, -1, GL_RGBA8);
|
||||||
m_tmp_dual[i].create(width, height, -1, GL_RGBA8);
|
m_tmp_dual[i].create(width, height, -1, GL_RGBA8);
|
||||||
m_tex[i].create(width, height, GL_RGBA8);
|
m_tex[i].create(width, height, GL_RGBA8);
|
||||||
//#else
|
}
|
||||||
// m_tmp[i].create(width, height, -1, GL_RGBA32F);
|
|
||||||
// m_tmp_dual[i].create(width, height, -1, GL_RGBA32F);
|
|
||||||
// m_tex[i].create(width, height, GL_RGBA32F);
|
|
||||||
//#endif
|
|
||||||
m_tex2[i].create(width, height, GL_RGBA8);
|
m_tex2[i].create(width, height, GL_RGBA8);
|
||||||
}
|
}
|
||||||
for (auto& l : m_layers)
|
for (auto& l : m_layers)
|
||||||
@@ -1539,15 +1548,24 @@ bool Canvas::create(int width, int height)
|
|||||||
m_size = { width, height };
|
m_size = { width, height };
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
//#if defined(__IOS__) || defined(__ANDROID__)
|
if (ShaderManager::ext_texture_float)
|
||||||
|
{
|
||||||
|
m_tmp[i].create(width, height, -1, GL_RGBA32F);
|
||||||
|
m_tmp_dual[i].create(width, height, -1, GL_RGBA32F);
|
||||||
|
m_tex[i].create(width, height, GL_RGBA32F);
|
||||||
|
}
|
||||||
|
else if (ShaderManager::ext_half_float_pixel)
|
||||||
|
{
|
||||||
|
m_tmp[i].create(width, height, -1, GL_RGBA16F);
|
||||||
|
m_tmp_dual[i].create(width, height, -1, GL_RGBA16F);
|
||||||
|
m_tex[i].create(width, height, GL_RGBA16F);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
m_tmp[i].create(width, height, -1, GL_RGBA8);
|
m_tmp[i].create(width, height, -1, GL_RGBA8);
|
||||||
m_tmp_dual[i].create(width, height, -1, GL_RGBA8);
|
m_tmp_dual[i].create(width, height, -1, GL_RGBA8);
|
||||||
m_tex[i].create(width, height, GL_RGBA8);
|
m_tex[i].create(width, height, GL_RGBA8);
|
||||||
//#else
|
}
|
||||||
// m_tmp[i].create(width, height, -1, GL_RGBA32F);
|
|
||||||
// m_tmp_dual[i].create(width, height, -1, GL_RGBA32F);
|
|
||||||
// m_tex[i].create(width, height, GL_RGBA32F);
|
|
||||||
//#endif
|
|
||||||
m_tex2[i].create(width, height, GL_RGBA8);
|
m_tex2[i].create(width, height, GL_RGBA8);
|
||||||
}
|
}
|
||||||
#if defined(__IOS__) || defined(__ANDROID__)
|
#if defined(__IOS__) || defined(__ANDROID__)
|
||||||
|
|||||||
@@ -121,12 +121,19 @@ void NodePanelGrid::init_controls()
|
|||||||
|
|
||||||
m_render->on_click = [this](Node*)
|
m_render->on_click = [this](Node*)
|
||||||
{
|
{
|
||||||
gl_state gl;
|
if (ShaderManager::ext_texture_float || ShaderManager::ext_half_float_pixel)
|
||||||
gl.save();
|
{
|
||||||
|
std::thread([this] {
|
||||||
bake_uvs();
|
bake_uvs();
|
||||||
m_hm_shading->set_index(3);
|
m_hm_shading->set_index(3);
|
||||||
m_shade_mode = ShadeMode::Textured;
|
m_shade_mode = ShadeMode::Textured;
|
||||||
gl.restore();
|
}).detach();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
App::I->message_box("Rendering failed",
|
||||||
|
"Your hardware does not support lightmap rendering.");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
m_commit->on_click = [this](Node*)
|
m_commit->on_click = [this](Node*)
|
||||||
{
|
{
|
||||||
@@ -213,6 +220,7 @@ float NodePanelGrid::get_offset() const
|
|||||||
|
|
||||||
void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camera, bool commit) const
|
void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camera, bool commit) const
|
||||||
{
|
{
|
||||||
|
assert(App::I->is_render_thread());
|
||||||
if (m_groud_opacity->get_value() > 0.f)
|
if (m_groud_opacity->get_value() > 0.f)
|
||||||
{
|
{
|
||||||
bool depth = glIsEnabled(GL_DEPTH_TEST);
|
bool depth = glIsEnabled(GL_DEPTH_TEST);
|
||||||
@@ -345,11 +353,18 @@ void NodePanelGrid::bake_uvs()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
RTT fb;
|
RTT fb;
|
||||||
#if defined(__IOS__) || defined(__ANDROID__)
|
if (ShaderManager::ext_texture_float)
|
||||||
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA16F);
|
{
|
||||||
#else
|
|
||||||
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA32F);
|
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA32F);
|
||||||
#endif
|
}
|
||||||
|
else if (ShaderManager::ext_half_float_pixel)
|
||||||
|
{
|
||||||
|
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA16F);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<float[]> data_nor;
|
||||||
|
std::unique_ptr<float[]> data_pos;
|
||||||
|
App::I->render_task([&]{
|
||||||
fb.bindFramebuffer();
|
fb.bindFramebuffer();
|
||||||
fb.clear({ 1, 0, 0, 1 });
|
fb.clear({ 1, 0, 0, 1 });
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
@@ -361,22 +376,20 @@ void NodePanelGrid::bake_uvs()
|
|||||||
// bake normal
|
// bake normal
|
||||||
ShaderManager::u_int(kShaderUniform::Mode, 0);
|
ShaderManager::u_int(kShaderUniform::Mode, 0);
|
||||||
m_hm_plane.draw_fill();
|
m_hm_plane.draw_fill();
|
||||||
std::unique_ptr<float[]> data_nor(fb.readTextureDataFloat());
|
data_nor.reset(fb.readTextureDataFloat());
|
||||||
//stbi_write_png("bake-nor.png", fb.getWidth(), fb.getHeight(), 4, fb.readTextureData(), 0);
|
//stbi_write_png("bake-nor.png", fb.getWidth(), fb.getHeight(), 4, fb.readTextureData(), 0);
|
||||||
|
|
||||||
// bake position
|
// bake position
|
||||||
ShaderManager::u_int(kShaderUniform::Mode, 1);
|
ShaderManager::u_int(kShaderUniform::Mode, 1);
|
||||||
m_hm_plane.draw_fill();
|
m_hm_plane.draw_fill();
|
||||||
std::unique_ptr<float[]> data_pos(fb.readTextureDataFloat());
|
data_pos.reset(fb.readTextureDataFloat());
|
||||||
//stbi_write_png("bake-pos.png", fb.getWidth(), fb.getHeight(), 4, fb.readTextureData(), 0);
|
//stbi_write_png("bake-pos.png", fb.getWidth(), fb.getHeight(), 4, fb.readTextureData(), 0);
|
||||||
|
|
||||||
fb.unbindFramebuffer();
|
fb.unbindFramebuffer();
|
||||||
fb.destroy();
|
fb.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
auto pb = root()->add_child<NodeProgressBar>();
|
auto pb = App::I->show_progress("Lightmap Rendering");
|
||||||
pb->m_progress->SetWidthP(0);
|
|
||||||
pb->m_title->set_text("Lightmap Rendering");
|
|
||||||
pb->btn_cancel->destroy();
|
|
||||||
|
|
||||||
if (m_rt_dirty)
|
if (m_rt_dirty)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
std::map<kShader, Shader> ShaderManager::m_shaders;
|
std::map<kShader, Shader> ShaderManager::m_shaders;
|
||||||
Shader* ShaderManager::m_current;
|
Shader* ShaderManager::m_current;
|
||||||
bool ShaderManager::ext_framebuffer_fetch = false;
|
bool ShaderManager::ext_framebuffer_fetch = false;
|
||||||
|
bool ShaderManager::ext_texture_float = false;
|
||||||
|
bool ShaderManager::ext_half_float_pixel = false;
|
||||||
|
|
||||||
std::string Shader::read(const std::string& path)
|
std::string Shader::read(const std::string& path)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ class ShaderManager
|
|||||||
static Shader* m_current;
|
static Shader* m_current;
|
||||||
public:
|
public:
|
||||||
static bool ext_framebuffer_fetch;
|
static bool ext_framebuffer_fetch;
|
||||||
|
static bool ext_texture_float;
|
||||||
|
static bool ext_half_float_pixel;
|
||||||
static bool load(kShader id, const std::string& path);
|
static bool load(kShader id, const std::string& path);
|
||||||
static bool reload();
|
static bool reload();
|
||||||
static bool create(kShader id, const std::string& vertex, const std::string& fragment);
|
static bool create(kShader id, const std::string& vertex, const std::string& fragment);
|
||||||
|
|||||||
@@ -740,6 +740,7 @@ void parallel_for(size_t nb_elements, std::function<void(size_t i)> functor, boo
|
|||||||
|
|
||||||
void gl_state::save()
|
void gl_state::save()
|
||||||
{
|
{
|
||||||
|
assert(App::I->is_render_thread());
|
||||||
blend = glIsEnabled(GL_BLEND);
|
blend = glIsEnabled(GL_BLEND);
|
||||||
depth_test = glIsEnabled(GL_DEPTH_TEST);
|
depth_test = glIsEnabled(GL_DEPTH_TEST);
|
||||||
scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
||||||
@@ -759,6 +760,7 @@ void gl_state::save()
|
|||||||
|
|
||||||
void gl_state::restore()
|
void gl_state::restore()
|
||||||
{
|
{
|
||||||
|
assert(App::I->is_render_thread());
|
||||||
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
|
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
|
||||||
depth_test ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
|
depth_test ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
|
||||||
scissor_test ? glEnable(GL_SCISSOR_TEST) : glDisable(GL_SCISSOR_TEST);
|
scissor_test ? glEnable(GL_SCISSOR_TEST) : glDisable(GL_SCISSOR_TEST);
|
||||||
|
|||||||
Reference in New Issue
Block a user