Added clipping support, clip windows on slide anim

This commit is contained in:
Vaxry 2022-10-07 10:35:17 +01:00
parent fd379db846
commit 7faa3c367d
3 changed files with 96 additions and 20 deletions

View file

@ -351,6 +351,21 @@ void CHyprOpenGLImpl::renderRectWithDamage(wlr_box* box, const CColor& col, pixm
glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shQUAD.posAttrib); glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shQUAD.posAttrib);
glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shQUAD.texAttrib); glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shQUAD.texAttrib);
if (m_RenderData.clipBox.width != 0 && m_RenderData.clipBox.height != 0) {
pixman_region32_t damageClip;
pixman_region32_init(&damageClip);
pixman_region32_intersect_rect(&damageClip, damage, m_RenderData.clipBox.x, m_RenderData.clipBox.y, m_RenderData.clipBox.width, m_RenderData.clipBox.height);
if (pixman_region32_not_empty(&damageClip)) {
PIXMAN_DAMAGE_FOREACH(&damageClip) {
const auto RECT = RECTSARR[i];
scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
}
pixman_region32_fini(&damageClip);
} else {
if (pixman_region32_not_empty(damage)) { if (pixman_region32_not_empty(damage)) {
PIXMAN_DAMAGE_FOREACH(damage) { PIXMAN_DAMAGE_FOREACH(damage) {
const auto RECT = RECTSARR[i]; const auto RECT = RECTSARR[i];
@ -358,6 +373,7 @@ void CHyprOpenGLImpl::renderRectWithDamage(wlr_box* box, const CColor& col, pixm
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} }
} }
}
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shQUAD.posAttrib); glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shQUAD.posAttrib);
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shQUAD.texAttrib); glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shQUAD.texAttrib);
@ -467,14 +483,30 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, wlr_b
glEnableVertexAttribArray(shader->posAttrib); glEnableVertexAttribArray(shader->posAttrib);
glEnableVertexAttribArray(shader->texAttrib); glEnableVertexAttribArray(shader->texAttrib);
if (pixman_region32_not_empty(m_RenderData.pDamage)) { if (m_RenderData.clipBox.width != 0 && m_RenderData.clipBox.height != 0) {
PIXMAN_DAMAGE_FOREACH(m_RenderData.pDamage) { pixman_region32_t damageClip;
pixman_region32_init(&damageClip);
pixman_region32_intersect_rect(&damageClip, damage, m_RenderData.clipBox.x, m_RenderData.clipBox.y, m_RenderData.clipBox.width, m_RenderData.clipBox.height);
if (pixman_region32_not_empty(&damageClip)) {
PIXMAN_DAMAGE_FOREACH(&damageClip) {
const auto RECT = RECTSARR[i]; const auto RECT = RECTSARR[i];
scissor(&RECT); scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} }
} }
pixman_region32_fini(&damageClip);
} else {
if (pixman_region32_not_empty(damage)) {
PIXMAN_DAMAGE_FOREACH(damage) {
const auto RECT = RECTSARR[i];
scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
}
}
glDisableVertexAttribArray(shader->posAttrib); glDisableVertexAttribArray(shader->posAttrib);
glDisableVertexAttribArray(shader->texAttrib); glDisableVertexAttribArray(shader->texAttrib);
@ -832,6 +864,21 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CColor& col, int round) {
glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.posAttrib); glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.posAttrib);
glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.texAttrib); glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.texAttrib);
if (m_RenderData.clipBox.width != 0 && m_RenderData.clipBox.height != 0) {
pixman_region32_t damageClip;
pixman_region32_init(&damageClip);
pixman_region32_intersect_rect(&damageClip, m_RenderData.pDamage, m_RenderData.clipBox.x, m_RenderData.clipBox.y, m_RenderData.clipBox.width, m_RenderData.clipBox.height);
if (pixman_region32_not_empty(&damageClip)) {
PIXMAN_DAMAGE_FOREACH(&damageClip) {
const auto RECT = RECTSARR[i];
scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
}
pixman_region32_fini(&damageClip);
} else {
if (pixman_region32_not_empty(m_RenderData.pDamage)) { if (pixman_region32_not_empty(m_RenderData.pDamage)) {
PIXMAN_DAMAGE_FOREACH(m_RenderData.pDamage) { PIXMAN_DAMAGE_FOREACH(m_RenderData.pDamage) {
const auto RECT = RECTSARR[i]; const auto RECT = RECTSARR[i];
@ -839,6 +886,7 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CColor& col, int round) {
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} }
} }
}
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.posAttrib); glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.posAttrib);
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.texAttrib); glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.texAttrib);
@ -1074,6 +1122,21 @@ void CHyprOpenGLImpl::renderRoundedShadow(wlr_box* box, int round, int range, fl
glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shSHADOW.posAttrib); glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shSHADOW.posAttrib);
glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shSHADOW.texAttrib); glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shSHADOW.texAttrib);
if (m_RenderData.clipBox.width != 0 && m_RenderData.clipBox.height != 0) {
pixman_region32_t damageClip;
pixman_region32_init(&damageClip);
pixman_region32_intersect_rect(&damageClip, m_RenderData.pDamage, m_RenderData.clipBox.x, m_RenderData.clipBox.y, m_RenderData.clipBox.width, m_RenderData.clipBox.height);
if (pixman_region32_not_empty(&damageClip)) {
PIXMAN_DAMAGE_FOREACH(&damageClip) {
const auto RECT = RECTSARR[i];
scissor(&RECT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
}
pixman_region32_fini(&damageClip);
} else {
if (pixman_region32_not_empty(m_RenderData.pDamage)) { if (pixman_region32_not_empty(m_RenderData.pDamage)) {
PIXMAN_DAMAGE_FOREACH(m_RenderData.pDamage) { PIXMAN_DAMAGE_FOREACH(m_RenderData.pDamage) {
const auto RECT = RECTSARR[i]; const auto RECT = RECTSARR[i];
@ -1081,6 +1144,7 @@ void CHyprOpenGLImpl::renderRoundedShadow(wlr_box* box, int round, int range, fl
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
} }
} }
}
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shSHADOW.posAttrib); glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shSHADOW.posAttrib);
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shSHADOW.texAttrib); glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shSHADOW.texAttrib);

View file

@ -67,6 +67,8 @@ struct SCurrentRenderData {
Vector2D primarySurfaceUVTopLeft = Vector2D(-1, -1); Vector2D primarySurfaceUVTopLeft = Vector2D(-1, -1);
Vector2D primarySurfaceUVBottomRight = Vector2D(-1, -1); Vector2D primarySurfaceUVBottomRight = Vector2D(-1, -1);
wlr_box clipBox = {};
}; };
class CHyprOpenGLImpl { class CHyprOpenGLImpl {

View file

@ -248,6 +248,15 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec*
g_pHyprOpenGL->m_pCurrentWindow = pWindow; g_pHyprOpenGL->m_pCurrentWindow = pWindow;
// clip box for animated offsets
if (const auto OFFVEC = PWORKSPACE->m_vRenderOffset.vec(); OFFVEC != Vector2D()) {
g_pHyprOpenGL->m_RenderData.clipBox = {(int)OFFVEC.x, (int)OFFVEC.y, (int)pMonitor->vecTransformedSize.x, (int)pMonitor->vecTransformedSize.y };
scaleBox(&g_pHyprOpenGL->m_RenderData.clipBox, pMonitor->scale);
} else {
g_pHyprOpenGL->m_RenderData.clipBox = {0, 0, 0, 0};
}
// render window decorations first, if not fullscreen full // render window decorations first, if not fullscreen full
if (mode == RENDER_PASS_ALL || mode == RENDER_PASS_MAIN) { if (mode == RENDER_PASS_ALL || mode == RENDER_PASS_MAIN) {
@ -289,6 +298,7 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec*
} }
g_pHyprOpenGL->m_pCurrentWindow = nullptr; g_pHyprOpenGL->m_pCurrentWindow = nullptr;
g_pHyprOpenGL->m_RenderData.clipBox = { 0, 0, 0, 0 };
} }
void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, timespec* time) { void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, timespec* time) {