Require GLTexture::render() to provide an output scale
This ensures we render the texture at the right scale while providing geometry information in logical coordinates.
This commit is contained in:
parent
74ff3bf082
commit
6cfeb3e3e8
13 changed files with 31 additions and 24 deletions
|
@ -517,7 +517,7 @@ void DrmOutput::renderCursorOpengl(const RenderTarget &renderTarget, const QSize
|
|||
m_cursorTexture->bind();
|
||||
ShaderBinder binder(ShaderTrait::MapTexture);
|
||||
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
m_cursorTexture->render(QRect(0, 0, cursorSize.width(), cursorSize.height()));
|
||||
m_cursorTexture->render(QRect(0, 0, cursorSize.width(), cursorSize.height()), renderTarget.devicePixelRatio());
|
||||
m_cursorTexture->unbind();
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ void CursorDelegateOpenGL::paint(RenderTarget *renderTarget, const QRegion ®i
|
|||
m_cursorTexture->bind();
|
||||
ShaderBinder binder(ShaderTrait::MapTexture);
|
||||
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
m_cursorTexture->render(region, QRect(0, 0, cursorRect.width(), cursorRect.height()));
|
||||
m_cursorTexture->render(region, QRect(0, 0, cursorRect.width(), cursorRect.height()), renderTarget->devicePixelRatio());
|
||||
m_cursorTexture->unbind();
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
|
|
@ -119,6 +119,7 @@ void MagnifierEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintDa
|
|||
// get the right area from the current rendered screen
|
||||
const QRect area = magnifierArea();
|
||||
const QPoint cursor = cursorPos();
|
||||
const auto scale = effects->renderTargetScale();
|
||||
|
||||
QRect srcArea(cursor.x() - (double)area.width() / (m_zoom * 2),
|
||||
cursor.y() - (double)area.height() / (m_zoom * 2),
|
||||
|
@ -133,7 +134,7 @@ void MagnifierEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintDa
|
|||
mvp.ortho(0, size.width(), size.height(), 0, 0, 65535);
|
||||
mvp.translate(area.x(), area.y());
|
||||
s->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
m_texture->render(area);
|
||||
m_texture->render(area, scale);
|
||||
ShaderManager::instance()->popShader();
|
||||
m_texture->unbind();
|
||||
QVector<float> verts;
|
||||
|
|
|
@ -83,10 +83,11 @@ void ScreenEdgeEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD
|
|||
ShaderBinder binder(ShaderTrait::MapTexture | ShaderTrait::Modulate);
|
||||
const QVector4D constant(opacity, opacity, opacity, opacity);
|
||||
binder.shader()->setUniform(GLShader::ModulationConstant, constant);
|
||||
const auto scale = effects->renderTargetScale();
|
||||
QMatrix4x4 mvp = data.projectionMatrix();
|
||||
mvp.translate(glow->geometry.x(), glow->geometry.y());
|
||||
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
texture->render(glow->geometry);
|
||||
texture->render(glow->geometry, scale);
|
||||
texture->unbind();
|
||||
glDisable(GL_BLEND);
|
||||
} else if (effects->compositingType() == QPainterCompositing) {
|
||||
|
|
|
@ -222,10 +222,11 @@ void StartupFeedbackEffect::paintScreen(int mask, const QRegion ®ion, ScreenP
|
|||
} else {
|
||||
ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
|
||||
}
|
||||
const auto scale = effects->renderTargetScale();
|
||||
QMatrix4x4 mvp = data.projectionMatrix();
|
||||
mvp.translate(m_currentGeometry.x(), m_currentGeometry.y());
|
||||
mvp.translate(m_currentGeometry.x() * scale, m_currentGeometry.y() * scale);
|
||||
ShaderManager::instance()->getBoundShader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
texture->render(m_currentGeometry);
|
||||
texture->render(m_currentGeometry, scale);
|
||||
ShaderManager::instance()->popShader();
|
||||
texture->unbind();
|
||||
glDisable(GL_BLEND);
|
||||
|
|
|
@ -114,6 +114,7 @@ void TrackMouseEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD
|
|||
const QPointF p = m_lastRect[0].topLeft() + QPoint(m_lastRect[0].width() / 2.0, m_lastRect[0].height() / 2.0);
|
||||
const float x = p.x();
|
||||
const float y = p.y();
|
||||
const auto scale = effects->renderTargetScale();
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
matrix.translate(x, y, 0.0);
|
||||
matrix.rotate(i ? -2 * m_angle : m_angle, 0, 0, 1.0);
|
||||
|
@ -122,7 +123,7 @@ void TrackMouseEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD
|
|||
mvp.translate(m_lastRect[i].x(), m_lastRect[i].y());
|
||||
shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
m_texture[i]->bind();
|
||||
m_texture[i]->render(m_lastRect[i]);
|
||||
m_texture[i]->render(m_lastRect[i], scale);
|
||||
m_texture[i]->unbind();
|
||||
}
|
||||
glDisable(GL_BLEND);
|
||||
|
|
|
@ -414,7 +414,7 @@ void ZoomEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &d
|
|||
QMatrix4x4 mvp = data.projectionMatrix();
|
||||
mvp.translate(rect.x(), rect.y());
|
||||
s->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
cursorTexture->render(rect);
|
||||
cursorTexture->render(rect, effects->renderTargetScale());
|
||||
ShaderManager::instance()->popShader();
|
||||
cursorTexture->unbind();
|
||||
glDisable(GL_BLEND);
|
||||
|
|
|
@ -506,20 +506,22 @@ void GLTexture::unbind()
|
|||
glBindTexture(d->m_target, 0);
|
||||
}
|
||||
|
||||
void GLTexture::render(const QRect &rect)
|
||||
void GLTexture::render(const QRect &rect, qreal scale)
|
||||
{
|
||||
render(infiniteRegion(), rect, false);
|
||||
render(infiniteRegion(), rect, scale, false);
|
||||
}
|
||||
|
||||
void GLTexture::render(const QRegion ®ion, const QRect &rect, bool hardwareClipping)
|
||||
void GLTexture::render(const QRegion ®ion, const QRect &rect, qreal scale, bool hardwareClipping)
|
||||
{
|
||||
Q_D(GLTexture);
|
||||
if (rect.isEmpty()) {
|
||||
return; // nothing to paint and m_vbo is likely nullptr and d->m_cachedSize empty as well, #337090
|
||||
}
|
||||
if (rect.size() != d->m_cachedSize) {
|
||||
d->m_cachedSize = rect.size();
|
||||
QRect r(rect);
|
||||
|
||||
QRect destinationRect = scaledRect(rect, scale).toRect();
|
||||
if (destinationRect.size() != d->m_cachedSize) {
|
||||
d->m_cachedSize = destinationRect.size();
|
||||
QRect r(destinationRect);
|
||||
r.moveTo(0, 0);
|
||||
if (!d->m_vbo) {
|
||||
d->m_vbo = std::make_unique<GLVertexBuffer>(KWin::GLVertexBuffer::Static);
|
||||
|
@ -528,9 +530,9 @@ void GLTexture::render(const QRegion ®ion, const QRect &rect, bool hardwareCl
|
|||
const float verts[4 * 2] = {
|
||||
// NOTICE: r.x/y could be replaced by "0", but that would make it unreadable...
|
||||
static_cast<float>(r.x()), static_cast<float>(r.y()),
|
||||
static_cast<float>(r.x()), static_cast<float>(r.y() + rect.height()),
|
||||
static_cast<float>(r.x() + rect.width()), static_cast<float>(r.y()),
|
||||
static_cast<float>(r.x() + rect.width()), static_cast<float>(r.y() + rect.height())};
|
||||
static_cast<float>(r.x()), static_cast<float>(r.y() + destinationRect.height()),
|
||||
static_cast<float>(r.x() + destinationRect.width()), static_cast<float>(r.y()),
|
||||
static_cast<float>(r.x() + destinationRect.width()), static_cast<float>(r.y() + destinationRect.height())};
|
||||
|
||||
const float texWidth = (target() == GL_TEXTURE_RECTANGLE_ARB) ? width() : 1.0f;
|
||||
const float texHeight = (target() == GL_TEXTURE_RECTANGLE_ARB) ? height() : 1.0f;
|
||||
|
|
|
@ -102,8 +102,8 @@ public:
|
|||
virtual void discard();
|
||||
void bind();
|
||||
void unbind();
|
||||
void render(const QRect &rect);
|
||||
void render(const QRegion ®ion, const QRect &rect, bool hardwareClipping = false);
|
||||
void render(const QRect &rect, qreal scale);
|
||||
void render(const QRegion ®ion, const QRect &rect, qreal scale, bool hardwareClipping = false);
|
||||
|
||||
GLuint texture() const;
|
||||
GLenum target() const;
|
||||
|
|
|
@ -58,7 +58,7 @@ void OutputScreenCastSource::render(GLFramebuffer *target)
|
|||
|
||||
GLFramebuffer::pushFramebuffer(target);
|
||||
outputTexture->bind();
|
||||
outputTexture->render(geometry);
|
||||
outputTexture->render(geometry, m_output->scale());
|
||||
outputTexture->unbind();
|
||||
GLFramebuffer::popFramebuffer();
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ void RegionScreenCastSource::updateOutput(Output *output)
|
|||
if (m_renderedTexture) {
|
||||
const std::shared_ptr<GLTexture> outputTexture = Compositor::self()->scene()->textureForOutput(output);
|
||||
const auto outputGeometry = output->geometry();
|
||||
const auto outputScale = output->scale();
|
||||
if (!outputTexture || !m_region.intersects(output->geometry())) {
|
||||
return;
|
||||
}
|
||||
|
@ -62,7 +63,7 @@ void RegionScreenCastSource::updateOutput(Output *output)
|
|||
shaderBinder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, projectionMatrix);
|
||||
|
||||
outputTexture->bind();
|
||||
outputTexture->render(output->geometry());
|
||||
outputTexture->render(output->geometry(), outputScale);
|
||||
outputTexture->unbind();
|
||||
GLFramebuffer::popFramebuffer();
|
||||
}
|
||||
|
@ -95,7 +96,7 @@ void RegionScreenCastSource::render(GLFramebuffer *target)
|
|||
shader->setUniform(GLShader::ModelViewProjectionMatrix, projectionMatrix);
|
||||
|
||||
m_renderedTexture->bind();
|
||||
m_renderedTexture->render(r);
|
||||
m_renderedTexture->render(r, m_scale);
|
||||
m_renderedTexture->unbind();
|
||||
|
||||
ShaderManager::instance()->popShader();
|
||||
|
|
|
@ -484,7 +484,7 @@ void ScreenCastStream::recordFrame(const QRegion &_damagedRegion)
|
|||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
m_cursor.texture->render(cursorRect);
|
||||
m_cursor.texture->render(cursorRect, m_cursor.scale);
|
||||
glDisable(GL_BLEND);
|
||||
m_cursor.texture->unbind();
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ void SceneOpenGL::paintOffscreenQuickView(OffscreenQuickView *w)
|
|||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
t->bind();
|
||||
t->render(rect.toRect());
|
||||
t->render(w->geometry(), renderTargetScale());
|
||||
t->unbind();
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
|
|
Loading…
Reference in a new issue