From c4cf0c7e4762a781f2b2be7815f845eae9c838af Mon Sep 17 00:00:00 2001 From: omigamedev Date: Fri, 17 May 2019 00:37:35 +0200 Subject: [PATCH] fix canvas on hdpi --- src/app_layout.cpp | 2 +- src/canvas_modes.cpp | 2 +- src/node_canvas.cpp | 2 +- src/rtt.cpp | 15 +++++++++------ src/rtt.h | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/app_layout.cpp b/src/app_layout.cpp index 8d43c2c..bd817ef 100644 --- a/src/app_layout.cpp +++ b/src/app_layout.cpp @@ -1082,7 +1082,7 @@ void App::brush_update() quick->m_slider_size->set_value(stroke->m_tip_size->get_value()); *quick->m_button_brush_current_preview->m_brush = *Canvas::I->m_current_brush; quick->m_button_brush_current_preview->draw_stroke(); - //quick->m_button_color_current_inner->m_color = Canvas::I->m_current_brush->m_tip_color; + quick->m_button_color_current_inner->m_color = Canvas::I->m_current_brush->m_tip_color; if (floating_picker) floating_picker->set_color(Canvas::I->m_current_brush->m_tip_color); if (floating_color) diff --git a/src/canvas_modes.cpp b/src/canvas_modes.cpp index 876a053..d1e57e9 100644 --- a/src/canvas_modes.cpp +++ b/src/canvas_modes.cpp @@ -243,7 +243,7 @@ void CanvasModePen::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const } } glm::u8vec4 pixel; - glReadPixels(pos.x, App::I.height - pos.y - 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel); + glReadPixels(pos.x / App::I.zoom, (App::I.height - pos.y - 1) / App::I.zoom, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel); bool outline = glm::min(tip_scale.x, tip_scale.y) < 20 || m_resizing ? false : m_draw_outline; ShaderManager::u_int(kShaderUniform::DrawOutline, outline); ShaderManager::u_vec4(kShaderUniform::Col, outline ? glm::vec4(1.f - glm::vec3(pixel) / 255.f, 1.f) : tip_color); diff --git a/src/node_canvas.cpp b/src/node_canvas.cpp index 68045f7..960d371 100644 --- a/src/node_canvas.cpp +++ b/src/node_canvas.cpp @@ -500,7 +500,7 @@ void NodeCanvas::handle_resize(glm::vec2 old_size, glm::vec2 new_size) //#endif m_blender_rtt.create((int)new_size.x, (int)new_size.y, -1, GL_RGBA8); m_cache_rtt.create((int)new_size.x, (int)new_size.y, -1, GL_RGBA8); - m_rtt.create((int)new_size.x, (int)new_size.y, -1, GL_RGBA8); + m_rtt.create((int)new_size.x, (int)new_size.y, -1, GL_RGBA8, true); m_blender_bg.create((int)new_size.x, (int)new_size.y, GL_RGBA8); if (auto img = root()->find("tex-debug")) img->tex.assign(m_canvas->m_mixer.getTextureID()); diff --git a/src/rtt.cpp b/src/rtt.cpp index 0e40bc5..9f4a8aa 100644 --- a/src/rtt.cpp +++ b/src/rtt.cpp @@ -41,7 +41,7 @@ void RTT::resize(int width, int height) glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDFboID); glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldRFboID); - new_rtt.create(width, height, -1, int_fmt); + new_rtt.create(width, height, -1, int_fmt, rboID != 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, new_rtt.fboID); glBindFramebuffer(GL_READ_FRAMEBUFFER, fboID); @@ -100,7 +100,7 @@ void RTT::copy(const RTT & source) glBindFramebuffer(GL_READ_FRAMEBUFFER, oldRFboID); } -bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format) +bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format, bool depth_buffer /*= false*/) { // Destroy any previously created object destroy(); @@ -133,10 +133,13 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format) glBindTexture(GL_TEXTURE_2D, 0); // Create a renderbuffer object to store depth info -// glGenRenderbuffers(1, &rboID); -// glBindRenderbuffer(GL_RENDERBUFFER, rboID); -// glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); -// glBindRenderbuffer(GL_RENDERBUFFER, 0); + if (depth_buffer) + { + glGenRenderbuffers(1, &rboID); + glBindRenderbuffer(GL_RENDERBUFFER, rboID); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); + glBindRenderbuffer(GL_RENDERBUFFER, 0); + } GLint oldFboID; glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldFboID); diff --git a/src/rtt.h b/src/rtt.h index 6c84b18..a15d2dd 100644 --- a/src/rtt.h +++ b/src/rtt.h @@ -21,7 +21,7 @@ public: void destroy(); void copy(const RTT& source); void resize(int width, int height); - bool create(int width, int height, int tex = -1, GLint internal_format = GL_RGBA8); + bool create(int width, int height, int tex = -1, GLint internal_format = GL_RGBA8, bool depth_buffer = false); bool recreate() { return create(w, h); } void clear(glm::vec4 color = glm::vec4(0)); glm::ivec4 calc_bounds();