From 27c06758e4e2fb9cc06233ec967bde62f447de0f Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Tue, 5 Apr 2022 15:50:47 +0200 Subject: basic window rounded corners --- src/render/OpenGL.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/render/OpenGL.cpp') diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index b86a69d7..330b2578 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -163,13 +163,13 @@ void CHyprOpenGLImpl::renderRect(wlr_box* box, const CColor& col) { glDisableVertexAttribArray(m_shQUAD.posAttrib); } -void CHyprOpenGLImpl::renderTexture(wlr_texture* tex,float matrix[9], float alpha) { +void CHyprOpenGLImpl::renderTexture(wlr_texture* tex,float matrix[9], float alpha, int round) { RASSERT(m_RenderData.pMonitor, "Tried to render texture without begin()!"); - renderTexture(CTexture(tex), matrix, alpha); + renderTexture(CTexture(tex), matrix, alpha, round); } -void CHyprOpenGLImpl::renderTexture(const CTexture& tex, float matrix[9], float alpha) { +void CHyprOpenGLImpl::renderTexture(const CTexture& tex, float matrix[9], float alpha, int round) { RASSERT(m_RenderData.pMonitor, "Tried to render texture without begin()!"); RASSERT((tex.m_iTexID > 0), "Attempted to draw NULL texture!"); @@ -210,6 +210,19 @@ void CHyprOpenGLImpl::renderTexture(const CTexture& tex, float matrix[9], float glUniform1i(shader->tex, 0); glUniform1f(shader->alpha, alpha / 255.f); + // round is in px + // so we need to do some maf + + const auto TOPLEFT = Vector2D(round, round); + const auto BOTTOMRIGHT = Vector2D(tex.m_vSize.x - round, tex.m_vSize.y - round); + const auto FULLSIZE = tex.m_vSize; + + // Rounded corners + glUniform2f(glGetUniformLocation(shader->program, "topLeft"), (float)TOPLEFT.x, (float)TOPLEFT.y); + glUniform2f(glGetUniformLocation(shader->program, "bottomRight"), (float)BOTTOMRIGHT.x, (float)BOTTOMRIGHT.y); + glUniform2f(glGetUniformLocation(shader->program, "fullSize"), (float)FULLSIZE.x, (float)FULLSIZE.y); + glUniform1f(glGetUniformLocation(shader->program, "radius"), round); + glVertexAttribPointer(shader->posAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts); glVertexAttribPointer(shader->texAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts); -- cgit v1.2.3