Move canvas resource formats to renderer gl
This commit is contained in:
134
src/canvas.cpp
134
src/canvas.cpp
@@ -4,8 +4,10 @@
|
||||
#include "app.h"
|
||||
#include "texture.h"
|
||||
#include "node_progress_bar.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include <thread>
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <numeric>
|
||||
|
||||
#ifdef __APPLE__
|
||||
@@ -15,6 +17,69 @@
|
||||
void webgl_sync();
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
GLint current_canvas_stroke_internal_format()
|
||||
{
|
||||
if (ShaderManager::ext_float32_linear)
|
||||
return static_cast<GLint>(pp::renderer::gl::rgba32f_internal_format());
|
||||
if (ShaderManager::ext_float16)
|
||||
return static_cast<GLint>(pp::renderer::gl::rgba16f_internal_format());
|
||||
return static_cast<GLint>(pp::renderer::gl::rgba8_internal_format());
|
||||
}
|
||||
|
||||
GLint rgba8_internal_format()
|
||||
{
|
||||
return static_cast<GLint>(pp::renderer::gl::rgba8_internal_format());
|
||||
}
|
||||
|
||||
GLenum texture_2d_target()
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::texture_2d_target());
|
||||
}
|
||||
|
||||
GLenum rgba_pixel_format()
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::rgba_pixel_format());
|
||||
}
|
||||
|
||||
GLenum unsigned_byte_component_type()
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::unsigned_byte_component_type());
|
||||
}
|
||||
|
||||
GLint texture_filter_linear()
|
||||
{
|
||||
return static_cast<GLint>(pp::renderer::gl::linear_texture_filter());
|
||||
}
|
||||
|
||||
GLint texture_filter_linear_mipmap_linear()
|
||||
{
|
||||
return static_cast<GLint>(pp::renderer::gl::linear_mipmap_linear_texture_filter());
|
||||
}
|
||||
|
||||
GLint texture_filter_nearest()
|
||||
{
|
||||
return static_cast<GLint>(pp::renderer::gl::nearest_texture_filter());
|
||||
}
|
||||
|
||||
GLint texture_wrap_repeat()
|
||||
{
|
||||
return static_cast<GLint>(pp::renderer::gl::repeat_texture_wrap());
|
||||
}
|
||||
|
||||
GLint texture_wrap_clamp_to_border()
|
||||
{
|
||||
return static_cast<GLint>(pp::renderer::gl::clamp_to_border_texture_wrap());
|
||||
}
|
||||
|
||||
pp::renderer::gl::OpenGlPixelFormat texture_format_for_image_channels(int channel_count)
|
||||
{
|
||||
return pp::renderer::gl::texture_format_for_channel_count(static_cast<std::uint32_t>(channel_count));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Canvas* Canvas::I;
|
||||
std::vector<CanvasMode*> Canvas::modes[] = {
|
||||
@@ -1571,8 +1636,8 @@ void Canvas::FloodData::apply()
|
||||
App::I->render_task([&]
|
||||
{
|
||||
rtt.bindTexture();
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rtt.getWidth(), rtt.getHeight(),
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, rgb[plane].get());
|
||||
glTexSubImage2D(texture_2d_target(), 0, 0, 0, rtt.getWidth(), rtt.getHeight(),
|
||||
rgba_pixel_format(), unsigned_byte_component_type(), rgb[plane].get());
|
||||
rtt.unbindTexture();
|
||||
});
|
||||
layer->face(plane) = true;
|
||||
@@ -1588,23 +1653,11 @@ void Canvas::resize(int width, int height)
|
||||
m_size = { width, height };
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (ShaderManager::ext_float32_linear)
|
||||
{
|
||||
m_tmp[i].create(width, height, -1, GL_RGBA32F);
|
||||
m_tmp_dual[i].create(width, height, -1, GL_RGBA32F);
|
||||
}
|
||||
else if (ShaderManager::ext_float16)
|
||||
{
|
||||
m_tmp[i].create(width, height, -1, GL_RGBA16F);
|
||||
m_tmp_dual[i].create(width, height, -1, GL_RGBA16F);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tmp[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_tex2[i].create(width, height, GL_RGBA8);
|
||||
const auto stroke_format = current_canvas_stroke_internal_format();
|
||||
m_tmp[i].create(width, height, -1, stroke_format);
|
||||
m_tmp_dual[i].create(width, height, -1, stroke_format);
|
||||
m_tex[i].create(width, height, rgba8_internal_format());
|
||||
m_tex2[i].create(width, height, rgba8_internal_format());
|
||||
}
|
||||
for (auto& l : m_layers)
|
||||
l->resize(width, height);
|
||||
@@ -1640,35 +1693,23 @@ bool Canvas::create(int width, int height)
|
||||
m_size = { width, height };
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (ShaderManager::ext_float32_linear)
|
||||
{
|
||||
m_tmp[i].create(width, height, -1, GL_RGBA32F);
|
||||
m_tmp_dual[i].create(width, height, -1, GL_RGBA32F);
|
||||
}
|
||||
else if (ShaderManager::ext_float16)
|
||||
{
|
||||
m_tmp[i].create(width, height, -1, GL_RGBA16F);
|
||||
m_tmp_dual[i].create(width, height, -1, GL_RGBA16F);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tmp[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_tex2[i].create(width, height, GL_RGBA8);
|
||||
const auto stroke_format = current_canvas_stroke_internal_format();
|
||||
m_tmp[i].create(width, height, -1, stroke_format);
|
||||
m_tmp_dual[i].create(width, height, -1, stroke_format);
|
||||
m_tex[i].create(width, height, rgba8_internal_format());
|
||||
m_tex2[i].create(width, height, rgba8_internal_format());
|
||||
}
|
||||
#if defined(__GLES__)
|
||||
m_sampler_brush.create();
|
||||
#else
|
||||
m_sampler_brush.create(GL_LINEAR, GL_CLAMP_TO_BORDER);
|
||||
m_sampler_brush.create(texture_filter_linear(), texture_wrap_clamp_to_border());
|
||||
#endif
|
||||
m_sampler.create(GL_LINEAR);
|
||||
m_sampler_nearest.create(GL_NEAREST);
|
||||
m_sampler_brush.set_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
|
||||
m_sampler.create(texture_filter_linear());
|
||||
m_sampler_nearest.create(texture_filter_nearest());
|
||||
m_sampler_brush.set_filter(texture_filter_linear_mipmap_linear(), texture_filter_linear());
|
||||
m_sampler_brush.set_border({ 1, 1, 1, 1 });
|
||||
m_sampler_stencil.create(GL_LINEAR, GL_REPEAT);
|
||||
m_sampler_mix.create(GL_NEAREST, GL_REPEAT);
|
||||
m_sampler_stencil.create(texture_filter_linear(), texture_wrap_repeat());
|
||||
m_sampler_mix.create(texture_filter_nearest(), texture_wrap_repeat());
|
||||
m_sampler_linear.create();
|
||||
m_plane.create<1>(1, 1);
|
||||
m_plane_brush.create<1>(1, 1);
|
||||
@@ -1754,9 +1795,12 @@ void Canvas::import_equirectangular_thread(std::string file_path, std::shared_pt
|
||||
{
|
||||
Texture2D tex;
|
||||
static const GLint indices[] = { 5, 0, 4, 1, 2, 3 };
|
||||
static const GLint formats[] = { GL_RED, GL_RG, GL_RGB, GL_RGBA };
|
||||
static const GLint iformats[] = { GL_R8, GL_RG8, GL_RGB8, GL_RGBA8 };
|
||||
tex.create(img.width, img.width, iformats[img.comp - 1], formats[img.comp - 1]);
|
||||
const auto texture_format = texture_format_for_image_channels(img.comp);
|
||||
tex.create(
|
||||
img.width,
|
||||
img.width,
|
||||
static_cast<GLint>(texture_format.internal_format),
|
||||
static_cast<GLint>(texture_format.pixel_format));
|
||||
int stride = img.width * img.width * img.comp;
|
||||
Plane plane;
|
||||
plane.create<1>(2, 2);
|
||||
|
||||
Reference in New Issue
Block a user