Commit 4d738b86 authored by Fredrik Höglund's avatar Fredrik Höglund

Add an internalFormat parameter to the GLTexture ctor

This parameter is ignored on GLES.
parent 20a1cb2e
......@@ -363,7 +363,7 @@ void ContrastEffect::doContrast(const QRegion& shape, const QRect& screen, const
// Create a scratch texture and copy the area in the back buffer that we're
// going to blur into it
GLTexture scratch(r.width(), r.height());
GLTexture scratch(GL_RGBA8, r.width(), r.height());
scratch.setFilter(GL_LINEAR);
scratch.setWrapMode(GL_CLAMP_TO_EDGE);
scratch.bind();
......
......@@ -37,7 +37,7 @@ BlurEffect::BlurEffect()
// Offscreen texture that's used as the target for the horizontal blur pass
// and the source for the vertical pass.
tex = GLTexture(effects->virtualScreenSize());
tex = GLTexture(GL_RGBA8, effects->virtualScreenSize());
tex.setFilter(GL_LINEAR);
tex.setWrapMode(GL_CLAMP_TO_EDGE);
......@@ -438,7 +438,7 @@ void BlurEffect::doBlur(const QRegion& shape, const QRect& screen, const float o
// Create a scratch texture and copy the area in the back buffer that we're
// going to blur into it
GLTexture scratch(r.width(), r.height());
GLTexture scratch(GL_RGBA8, r.width(), r.height());
scratch.setFilter(GL_LINEAR);
scratch.setWrapMode(GL_CLAMP_TO_EDGE);
scratch.bind();
......@@ -511,13 +511,13 @@ void BlurEffect::doCachedBlur(EffectWindow *w, const QRegion& region, const floa
CacheEntry it = windows.find(w);
if (it == windows.end()) {
BlurWindowInfo bwi;
bwi.blurredBackground = GLTexture(r.width(),r.height());
bwi.blurredBackground = GLTexture(GL_RGBA8, r.width(),r.height());
bwi.damagedRegion = expanded;
bwi.dropCache = false;
bwi.windowPos = w->pos();
it = windows.insert(w, bwi);
} else if (it->blurredBackground.size() != r.size()) {
it->blurredBackground = GLTexture(r.width(),r.height());
it->blurredBackground = GLTexture(GL_RGBA8, r.width(),r.height());
it->dropCache = false;
it->windowPos = w->pos();
} else if (it->windowPos != w->pos()) {
......
......@@ -112,7 +112,7 @@ void LogoutEffect::prePaintScreen(ScreenPrePaintData& data, int time)
const QSize size = effects->virtualScreenSize();
// The fragment shader uses a LOD bias of 1.75, so we need 3 mipmap levels.
blurTexture = new GLTexture(size, 3);
blurTexture = new GLTexture(GL_RGBA8, size, 3);
blurTexture->setFilter(GL_LINEAR_MIPMAP_LINEAR);
blurTexture->setWrapMode(GL_CLAMP_TO_EDGE);
......
......@@ -102,7 +102,7 @@ bool LookingGlassEffect::loadData()
// Create texture and render target
const int levels = std::log2(qMin(texw, texh)) + 1;
m_texture = new GLTexture(texw, texh, levels);
m_texture = new GLTexture(GL_RGBA8, texw, texh, levels);
m_texture->setFilter(GL_LINEAR_MIPMAP_LINEAR);
m_texture->setWrapMode(GL_CLAMP_TO_EDGE);
......
......@@ -261,7 +261,7 @@ void MagnifierEffect::zoomIn()
}
if (effects->isOpenGLCompositing() && !m_texture) {
effects->makeOpenGLContextCurrent();
m_texture = new GLTexture(magnifier_size.width(), magnifier_size.height());
m_texture = new GLTexture(GL_RGBA8, magnifier_size.width(), magnifier_size.height());
m_texture->setYInverted(false);
m_fbo = new GLRenderTarget(*m_texture);
}
......@@ -301,7 +301,7 @@ void MagnifierEffect::toggle()
}
if (effects->isOpenGLCompositing() && !m_texture) {
effects->makeOpenGLContextCurrent();
m_texture = new GLTexture(magnifier_size.width(), magnifier_size.height());
m_texture = new GLTexture(GL_RGBA8, magnifier_size.width(), magnifier_size.height());
m_texture->setYInverted(false);
m_fbo = new GLRenderTarget(*m_texture);
}
......
......@@ -110,7 +110,7 @@ void ScreenShotEffect::postPaintScreen()
QScopedPointer<GLTexture> offscreenTexture;
QScopedPointer<GLRenderTarget> target;
if (effects->isOpenGLCompositing()) {
offscreenTexture.reset(new GLTexture(width, height));
offscreenTexture.reset(new GLTexture(GL_RGBA8, width, height));
offscreenTexture->setFilter(GL_LINEAR);
offscreenTexture->setWrapMode(GL_CLAMP_TO_EDGE);
target.reset(new GLRenderTarget(*offscreenTexture));
......@@ -236,7 +236,7 @@ QString ScreenShotEffect::blitScreenshot(const QRect &geometry)
qCDebug(KWINEFFECTS) << "Framebuffer Blit not supported";
return QString();
}
GLTexture tex(geometry.width(), geometry.height());
GLTexture tex(GL_RGBA8, geometry.width(), geometry.height());
GLRenderTarget target(tex);
target.blitFromFramebuffer(geometry);
// copy content from framebuffer into image
......
......@@ -111,7 +111,7 @@ void LanczosFilter::updateOffscreenSurfaces()
delete m_offscreenTex;
delete m_offscreenTarget;
}
m_offscreenTex = new GLTexture(w, h);
m_offscreenTex = new GLTexture(GL_RGBA8, w, h);
m_offscreenTex->setFilter(GL_LINEAR);
m_offscreenTex->setWrapMode(GL_CLAMP_TO_EDGE);
m_offscreenTarget = new GLRenderTarget(*m_offscreenTex);
......@@ -254,7 +254,7 @@ void LanczosFilter::performPaint(EffectWindowImpl* w, int mask, QRegion region,
w->sceneWindow()->performPaint(mask, infiniteRegion(), thumbData);
// Create a scratch texture and copy the rendered window into it
GLTexture tex(sw, sh);
GLTexture tex(GL_RGBA8, sw, sh);
tex.setFilter(GL_LINEAR);
tex.setWrapMode(GL_CLAMP_TO_EDGE);
tex.bind();
......@@ -293,7 +293,7 @@ void LanczosFilter::performPaint(EffectWindowImpl* w, int mask, QRegion region,
tex.discard();
// create scratch texture for second rendering pass
GLTexture tex2(tw, sh);
GLTexture tex2(GL_RGBA8, tw, sh);
tex2.setFilter(GL_LINEAR);
tex2.setWrapMode(GL_CLAMP_TO_EDGE);
tex2.bind();
......@@ -326,7 +326,7 @@ void LanczosFilter::performPaint(EffectWindowImpl* w, int mask, QRegion region,
ShaderManager::instance()->popShader();
// create cache texture
GLTexture *cache = new GLTexture(tw, th);
GLTexture *cache = new GLTexture(GL_RGBA8, tw, th);
cache->setFilter(GL_LINEAR);
cache->setWrapMode(GL_CLAMP_TO_EDGE);
......
......@@ -74,6 +74,7 @@ GLTexture::GLTexture(const QImage& image, GLenum target)
return;
d->m_target = target;
d->m_internalFormat = GL_RGBA8;
if (d->m_target != GL_TEXTURE_RECTANGLE_ARB) {
d->m_scale.setWidth(1.0 / image.width());
......@@ -132,7 +133,7 @@ GLTexture::GLTexture(const QString& fileName)
{
}
GLTexture::GLTexture(int width, int height, int levels)
GLTexture::GLTexture(GLenum internalFormat, int width, int height, int levels)
: d_ptr(new GLTexturePrivate())
{
Q_D(GLTexture);
......@@ -153,13 +154,14 @@ GLTexture::GLTexture(int width, int height, int levels)
if (!GLPlatform::instance()->isGLES()) {
if (d->s_supportsTextureStorage) {
glTexStorage2D(d->m_target, levels, GL_RGBA8, width, height);
glTexStorage2D(d->m_target, levels, internalFormat, width, height);
d->m_immutable = true;
} else {
glTexParameteri(d->m_target, GL_TEXTURE_MAX_LEVEL, levels - 1);
glTexImage2D(d->m_target, 0, GL_RGBA8, width, height, 0,
glTexImage2D(d->m_target, 0, internalFormat, width, height, 0,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr);
}
d->m_internalFormat = internalFormat;
} else {
// The format parameter in glTexSubImage() must match the internal format
// of the texture, so it's important that we allocate the texture with
......@@ -167,13 +169,17 @@ GLTexture::GLTexture(int width, int height, int levels)
const GLenum format = d->s_supportsARGB32 ? GL_BGRA_EXT : GL_RGBA;
glTexImage2D(d->m_target, 0, format, width, height, 0,
format, GL_UNSIGNED_BYTE, nullptr);
// This is technically not true, but it means that code that calls
// internalFormat() won't need to be specialized for GLES2.
d->m_internalFormat = GL_RGBA8;
}
unbind();
}
GLTexture::GLTexture(const QSize &size, int levels)
: GLTexture(size.width(), size.height(), levels)
GLTexture::GLTexture(GLenum internalFormat, const QSize &size, int levels)
: GLTexture(internalFormat, size.width(), size.height(), levels)
{
}
......@@ -191,6 +197,7 @@ GLTexturePrivate::GLTexturePrivate()
{
m_texture = 0;
m_target = 0;
m_internalFormat = 0;
m_filter = GL_NEAREST;
m_wrapMode = GL_REPEAT;
m_yInverted = false;
......@@ -438,6 +445,12 @@ GLenum GLTexture::filter() const
return d->m_filter;
}
GLenum GLTexture::internalFormat() const
{
Q_D(const GLTexture);
return d->m_internalFormat;
}
void GLTexture::clear()
{
Q_D(GLTexture);
......
......@@ -55,8 +55,8 @@ public:
explicit GLTexture(const QImage& image, GLenum target = GL_TEXTURE_2D);
explicit GLTexture(const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D);
explicit GLTexture(const QString& fileName);
GLTexture(int width, int height, int levels = 1);
explicit GLTexture(const QSize &size, int levels = 1);
GLTexture(GLenum internalFormat, int width, int height, int levels = 1);
explicit GLTexture(GLenum internalFormat, const QSize &size, int levels = 1);
virtual ~GLTexture();
GLTexture & operator = (const GLTexture& tex);
......@@ -91,6 +91,8 @@ public:
GLuint texture() const;
GLenum target() const;
GLenum filter() const;
GLenum internalFormat() const;
/** @short
* Make the texture fully transparent
* Warning: this clobbers the current framebuffer binding except on fglrx
......
......@@ -48,6 +48,7 @@ public:
GLuint m_texture;
GLenum m_target;
GLenum m_internalFormat;
GLenum m_filter;
GLenum m_wrapMode;
QSize m_size;
......
......@@ -720,7 +720,7 @@ bool ShaderManager::selfTest()
src.setFilter(GL_NEAREST);
// Create the render target
GLTexture dst(32, 32);
GLTexture dst(GL_RGBA8, 32, 32);
GLRenderTarget fbo(dst);
GLRenderTarget::pushRenderTarget(&fbo);
......
......@@ -2372,7 +2372,7 @@ void SceneOpenGLDecorationRenderer::resizeTexture()
return;
if (!size.isEmpty()) {
m_texture.reset(new GLTexture(size.width(), size.height()));
m_texture.reset(new GLTexture(GL_RGBA8, size.width(), size.height()));
m_texture->setYInverted(true);
m_texture->setWrapMode(GL_CLAMP_TO_EDGE);
m_texture->clear();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment