kwinglutils: use QSizeF instead of QRect
The method is ignoring the position of the rectangle, which is very unintuitive when using it
This commit is contained in:
parent
a7ffdef186
commit
9d353864a4
13 changed files with 30 additions and 37 deletions
|
@ -61,7 +61,7 @@ void CursorDelegateOpenGL::paint(RenderTarget *renderTarget, const QRegion ®i
|
|||
m_texture->bind();
|
||||
ShaderBinder binder(ShaderTrait::MapTexture);
|
||||
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
m_texture->render(region, QRect(0, 0, cursorRect.width(), cursorRect.height()), scale);
|
||||
m_texture->render(region, cursorRect.size(), scale);
|
||||
m_texture->unbind();
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
|
|
|
@ -1767,7 +1767,7 @@ void EffectsHandlerImpl::renderOffscreenQuickView(OffscreenQuickView *w) const
|
|||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
t->bind();
|
||||
t->render(w->geometry(), m_scene->renderer()->renderTargetScale());
|
||||
t->render(w->size(), m_scene->renderer()->renderTargetScale());
|
||||
t->unbind();
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ void MagnifierEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintDa
|
|||
mvp.ortho(0, size.width() * scale, size.height() * scale, 0, 0, 65535);
|
||||
mvp.translate(area.x() * scale, area.y() * scale);
|
||||
s->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
m_texture->render(area, scale);
|
||||
m_texture->render(area.size(), scale);
|
||||
ShaderManager::instance()->popShader();
|
||||
m_texture->unbind();
|
||||
QVector<float> verts;
|
||||
|
|
|
@ -87,7 +87,7 @@ void ScreenEdgeEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD
|
|||
QMatrix4x4 mvp = data.projectionMatrix();
|
||||
mvp.translate(glow->geometry.x() * scale, glow->geometry.y() * scale);
|
||||
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
texture->render(glow->geometry, scale);
|
||||
texture->render(glow->geometry.size(), scale);
|
||||
texture->unbind();
|
||||
glDisable(GL_BLEND);
|
||||
} else if (effects->compositingType() == QPainterCompositing) {
|
||||
|
|
|
@ -224,7 +224,7 @@ void StartupFeedbackEffect::paintScreen(int mask, const QRegion ®ion, ScreenP
|
|||
QMatrix4x4 mvp = data.projectionMatrix();
|
||||
mvp.translate(m_currentGeometry.x() * scale, m_currentGeometry.y() * scale);
|
||||
ShaderManager::instance()->getBoundShader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
texture->render(m_currentGeometry, scale);
|
||||
texture->render(m_currentGeometry.size(), scale);
|
||||
ShaderManager::instance()->popShader();
|
||||
texture->unbind();
|
||||
glDisable(GL_BLEND);
|
||||
|
|
|
@ -122,7 +122,7 @@ void TrackMouseEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD
|
|||
mvp.translate(m_lastRect[i].x() * scale, m_lastRect[i].y() * scale);
|
||||
shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
m_texture[i]->bind();
|
||||
m_texture[i]->render(m_lastRect[i], scale);
|
||||
m_texture[i]->render(m_lastRect[i].size(), scale);
|
||||
m_texture[i]->unbind();
|
||||
}
|
||||
glDisable(GL_BLEND);
|
||||
|
|
|
@ -391,22 +391,21 @@ void ZoomEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &d
|
|||
GLTexture *cursorTexture = ensureCursorTexture();
|
||||
if (cursorTexture) {
|
||||
const auto cursor = effects->cursorImage();
|
||||
QSize cursorSize = cursor.image().size() / cursor.image().devicePixelRatio();
|
||||
QSizeF cursorSize = QSizeF(cursor.image().size()) / cursor.image().devicePixelRatio();
|
||||
if (mousePointer == MousePointerScale) {
|
||||
cursorSize *= zoom;
|
||||
}
|
||||
|
||||
const QPoint p = effects->cursorPos() - cursor.hotSpot();
|
||||
QRect rect(p * zoom + QPoint(xTranslation, yTranslation), cursorSize);
|
||||
const QPoint p = (effects->cursorPos() - cursor.hotSpot()) * zoom + QPoint(xTranslation, yTranslation);
|
||||
|
||||
cursorTexture->bind();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
auto s = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
|
||||
QMatrix4x4 mvp = data.projectionMatrix();
|
||||
mvp.translate(rect.x() * scale, rect.y() * scale);
|
||||
mvp.translate(p.x() * scale, p.y() * scale);
|
||||
s->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
cursorTexture->render(rect, scale);
|
||||
cursorTexture->render(cursorSize, scale);
|
||||
ShaderManager::instance()->popShader();
|
||||
cursorTexture->unbind();
|
||||
glDisable(GL_BLEND);
|
||||
|
|
|
@ -506,33 +506,30 @@ void GLTexture::unbind()
|
|||
glBindTexture(d->m_target, 0);
|
||||
}
|
||||
|
||||
void GLTexture::render(const QRect &rect, qreal scale)
|
||||
void GLTexture::render(const QSizeF &size, qreal scale)
|
||||
{
|
||||
render(infiniteRegion(), rect, scale, false);
|
||||
render(infiniteRegion(), size, scale, false);
|
||||
}
|
||||
|
||||
void GLTexture::render(const QRegion ®ion, const QRect &rect, qreal scale, bool hardwareClipping)
|
||||
void GLTexture::render(const QRegion ®ion, const QSizeF &size, double scale, bool hardwareClipping)
|
||||
{
|
||||
Q_D(GLTexture);
|
||||
if (rect.isEmpty()) {
|
||||
if (size.isEmpty()) {
|
||||
return; // nothing to paint and m_vbo is likely nullptr and d->m_cachedSize empty as well, #337090
|
||||
}
|
||||
|
||||
QRect destinationRect = scaledRect(rect, scale).toRect();
|
||||
if (destinationRect.size() != d->m_cachedSize) {
|
||||
d->m_cachedSize = destinationRect.size();
|
||||
QRect r(destinationRect);
|
||||
r.moveTo(0, 0);
|
||||
QSizeF destinationSize = (size * scale).toSize();
|
||||
if (destinationSize != d->m_cachedSize) {
|
||||
d->m_cachedSize = destinationSize;
|
||||
if (!d->m_vbo) {
|
||||
d->m_vbo = std::make_unique<GLVertexBuffer>(KWin::GLVertexBuffer::Static);
|
||||
}
|
||||
|
||||
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() + 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())};
|
||||
0.0f, 0.0f,
|
||||
0.0f, float(destinationSize.height()),
|
||||
float(destinationSize.width()), 0,
|
||||
float(destinationSize.width()), float(destinationSize.height())};
|
||||
|
||||
const float texWidth = (target() == GL_TEXTURE_RECTANGLE_ARB) ? width() : 1.0f;
|
||||
const float texHeight = (target() == GL_TEXTURE_RECTANGLE_ARB) ? height() : 1.0f;
|
||||
|
|
|
@ -101,8 +101,8 @@ public:
|
|||
virtual void discard();
|
||||
void bind();
|
||||
void unbind();
|
||||
void render(const QRect &rect, qreal scale);
|
||||
void render(const QRegion ®ion, const QRect &rect, qreal scale, bool hardwareClipping = false);
|
||||
void render(const QSizeF &size, double scale);
|
||||
void render(const QRegion ®ion, const QSizeF &size, double scale, bool hardwareClipping = false);
|
||||
|
||||
GLuint texture() const;
|
||||
GLenum target() const;
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
int m_unnormalizeActive; // 0 - no, otherwise refcount
|
||||
int m_normalizeActive; // 0 - no, otherwise refcount
|
||||
std::unique_ptr<GLVertexBuffer> m_vbo;
|
||||
QSize m_cachedSize;
|
||||
QSizeF m_cachedSize;
|
||||
|
||||
static void initStatic();
|
||||
|
||||
|
|
|
@ -49,17 +49,15 @@ void OutputScreenCastSource::render(GLFramebuffer *target)
|
|||
return;
|
||||
}
|
||||
|
||||
const QRect geometry(QPoint(), textureSize());
|
||||
|
||||
ShaderBinder shaderBinder(ShaderTrait::MapTexture);
|
||||
QMatrix4x4 projectionMatrix;
|
||||
projectionMatrix.scale(1, -1);
|
||||
projectionMatrix.ortho(scaledRect(geometry, m_output->scale()));
|
||||
projectionMatrix.ortho(QRect(QPoint(), textureSize() * m_output->scale()));
|
||||
shaderBinder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, projectionMatrix);
|
||||
|
||||
GLFramebuffer::pushFramebuffer(target);
|
||||
outputTexture->bind();
|
||||
outputTexture->render(geometry, m_output->scale());
|
||||
outputTexture->render(textureSize(), m_output->scale());
|
||||
outputTexture->unbind();
|
||||
GLFramebuffer::popFramebuffer();
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ void RegionScreenCastSource::updateOutput(Output *output)
|
|||
shaderBinder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, projectionMatrix);
|
||||
|
||||
outputTexture->bind();
|
||||
outputTexture->render(output->geometry(), 1 / m_scale);
|
||||
outputTexture->render(output->geometry().size(), 1 / m_scale);
|
||||
outputTexture->unbind();
|
||||
GLFramebuffer::popFramebuffer();
|
||||
}
|
||||
|
@ -89,16 +89,15 @@ void RegionScreenCastSource::render(GLFramebuffer *target)
|
|||
ensureTexture();
|
||||
|
||||
GLFramebuffer::pushFramebuffer(target);
|
||||
QRect r(QPoint(), target->size());
|
||||
auto shader = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
|
||||
|
||||
QMatrix4x4 projectionMatrix;
|
||||
projectionMatrix.scale(1, -1);
|
||||
projectionMatrix.ortho(r);
|
||||
projectionMatrix.ortho(QRect(QPoint(), target->size()));
|
||||
shader->setUniform(GLShader::ModelViewProjectionMatrix, projectionMatrix);
|
||||
|
||||
m_renderedTexture->bind();
|
||||
m_renderedTexture->render(r, m_scale);
|
||||
m_renderedTexture->render(target->size(), m_scale);
|
||||
m_renderedTexture->unbind();
|
||||
|
||||
ShaderManager::instance()->popShader();
|
||||
|
|
|
@ -486,7 +486,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.scale);
|
||||
m_cursor.texture->render(cursorRect.size(), m_cursor.scale);
|
||||
glDisable(GL_BLEND);
|
||||
m_cursor.texture->unbind();
|
||||
|
||||
|
|
Loading…
Reference in a new issue