diff --git a/effects/cube/data/cylinder.vert b/effects/cube/data/cylinder.vert index 9a520bb2b0..3c4ed0ada3 100644 --- a/effects/cube/data/cylinder.vert +++ b/effects/cube/data/cylinder.vert @@ -25,8 +25,6 @@ uniform float width; uniform float cubeAngle; uniform float xCoord; uniform float timeLine; -uniform float textureWidth; -uniform float textureHeight; attribute vec4 vertex; attribute vec2 texCoord; @@ -35,7 +33,7 @@ varying vec2 varyingTexCoords; void main() { - varyingTexCoords = texCoord / vec2(textureWidth, textureHeight); + varyingTexCoords = texCoord; vec4 transformedVertex = vec4(vertex.x - ( width - xCoord ), vertex.yzw); float radian = radians(cubeAngle); float radius = (width)*tan(radian); diff --git a/effects/cube/data/sphere.vert b/effects/cube/data/sphere.vert index cc37785498..8cf3a07b03 100644 --- a/effects/cube/data/sphere.vert +++ b/effects/cube/data/sphere.vert @@ -26,8 +26,6 @@ uniform float height; uniform float cubeAngle; uniform vec2 u_offset; uniform float timeLine; -uniform float textureWidth; -uniform float textureHeight; attribute vec4 vertex; attribute vec2 texCoord; @@ -36,7 +34,7 @@ varying vec2 varyingTexCoords; void main() { - varyingTexCoords = texCoord / vec2(textureWidth, textureHeight); + varyingTexCoords = texCoord; vec4 transformedVertex = vertex; transformedVertex.x = transformedVertex.x - width; transformedVertex.y = transformedVertex.y - height; diff --git a/effects/invert/data/invert.frag b/effects/invert/data/invert.frag index ec1a375237..3cf809db52 100644 --- a/effects/invert/data/invert.frag +++ b/effects/invert/data/invert.frag @@ -1,7 +1,5 @@ uniform sampler2D sampler; uniform vec4 modulation; -uniform float textureWidth; -uniform float textureHeight; uniform float saturation; uniform int u_forceAlpha; diff --git a/effects/presentwindows/presentwindows.cpp b/effects/presentwindows/presentwindows.cpp index 8381c9f371..a0e830600c 100755 --- a/effects/presentwindows/presentwindows.cpp +++ b/effects/presentwindows/presentwindows.cpp @@ -358,8 +358,6 @@ void PresentWindowsEffect::paintWindow(EffectWindow *w, int mask, QRegion region #ifdef KWIN_HAVE_OPENGL_COMPOSITING if (effects->compositingType() == KWin::OpenGLCompositing && data.shader) { const float a = 0.9 * data.opacity * m_decalOpacity * 0.75; - data.shader->setUniform(GLShader::TextureWidth, 1.0f); - data.shader->setUniform(GLShader::TextureHeight, 1.0f); data.shader->setUniform(GLShader::ModulationConstant, QVector4D(a, a, a, a)); } #endif @@ -372,8 +370,6 @@ void PresentWindowsEffect::paintWindow(EffectWindow *w, int mask, QRegion region #ifdef KWIN_HAVE_OPENGL_COMPOSITING if (effects->compositingType() == KWin::OpenGLCompositing && data.shader) { const float a = 0.9 * data.opacity * m_decalOpacity * 0.75; - data.shader->setUniform(GLShader::TextureWidth, 1.0f); - data.shader->setUniform(GLShader::TextureHeight, 1.0f); data.shader->setUniform(GLShader::ModulationConstant, QVector4D(a, a, a, a)); } #endif diff --git a/effects/startupfeedback/data/blinking-startup-fragment.glsl b/effects/startupfeedback/data/blinking-startup-fragment.glsl index df6c209db6..72200c0c98 100644 --- a/effects/startupfeedback/data/blinking-startup-fragment.glsl +++ b/effects/startupfeedback/data/blinking-startup-fragment.glsl @@ -1,6 +1,4 @@ uniform sampler2D sampler; -uniform float textureWidth; -uniform float textureHeight; uniform vec4 u_color; varying vec2 varyingTexCoords; diff --git a/effects/taskbarthumbnail/taskbarthumbnail.cpp b/effects/taskbarthumbnail/taskbarthumbnail.cpp index c1a8cde1c3..b453c37f7e 100644 --- a/effects/taskbarthumbnail/taskbarthumbnail.cpp +++ b/effects/taskbarthumbnail/taskbarthumbnail.cpp @@ -91,17 +91,7 @@ void TaskbarThumbnailEffect::paintWindow(EffectWindow* w, int mask, QRegion regi #ifdef KWIN_HAVE_OPENGL_COMPOSITING if (effects->compositingType() == KWin::OpenGLCompositing) { if (data.shader) { - // there is a shader - update texture width and height - int texw = thumbw->width(); - int texh = thumbw->height(); - if (!GLTexture::NPOTTextureSupported()) { - kWarning(1212) << "NPOT textures not supported, wasting some memory" ; - texw = nearestPowerOfTwo(texw); - texh = nearestPowerOfTwo(texh); - } thumbData.shader = data.shader; - thumbData.shader->setTextureWidth((float)texw); - thumbData.shader->setTextureHeight((float)texh); } } // if ( effects->compositingType() == KWin::OpenGLCompositing ) #endif diff --git a/libkwineffects/kwineffects.cpp b/libkwineffects/kwineffects.cpp index 484cd99364..ffaeebfe96 100644 --- a/libkwineffects/kwineffects.cpp +++ b/libkwineffects/kwineffects.cpp @@ -547,7 +547,7 @@ WindowQuadList WindowQuadList::makeRegularGrid(int xSubdivisions, int ySubdivisi return ret; } -void WindowQuadList::makeArrays(float** vertices, float** texcoords) const +void WindowQuadList::makeArrays(float** vertices, float** texcoords, const QSizeF& size, bool yInverted) const { *vertices = new float[ count() * 6 * 2 ]; *texcoords = new float[ count() * 6 * 2 ]; @@ -569,18 +569,33 @@ void WindowQuadList::makeArrays(float** vertices, float** texcoords) const *vpos++ = at(i)[ 1 ].x(); *vpos++ = at(i)[ 1 ].y(); - *tpos++ = at(i)[ 1 ].tx; - *tpos++ = at(i)[ 1 ].ty; - *tpos++ = at(i)[ 0 ].tx; - *tpos++ = at(i)[ 0 ].ty; - *tpos++ = at(i)[ 3 ].tx; - *tpos++ = at(i)[ 3 ].ty; - *tpos++ = at(i)[ 3 ].tx; - *tpos++ = at(i)[ 3 ].ty; - *tpos++ = at(i)[ 2 ].tx; - *tpos++ = at(i)[ 2 ].ty; - *tpos++ = at(i)[ 1 ].tx; - *tpos++ = at(i)[ 1 ].ty; + if (yInverted) { + *tpos++ = at(i)[ 1 ].tx / size.width(); + *tpos++ = at(i)[ 1 ].ty / size.height(); + *tpos++ = at(i)[ 0 ].tx / size.width(); + *tpos++ = at(i)[ 0 ].ty / size.height(); + *tpos++ = at(i)[ 3 ].tx / size.width(); + *tpos++ = at(i)[ 3 ].ty / size.height(); + *tpos++ = at(i)[ 3 ].tx / size.width(); + *tpos++ = at(i)[ 3 ].ty / size.height(); + *tpos++ = at(i)[ 2 ].tx / size.width(); + *tpos++ = at(i)[ 2 ].ty / size.height(); + *tpos++ = at(i)[ 1 ].tx / size.width(); + *tpos++ = at(i)[ 1 ].ty / size.height(); + } else { + *tpos++ = at(i)[ 1 ].tx / size.width(); + *tpos++ = 1.0f - at(i)[ 1 ].ty / size.height(); + *tpos++ = at(i)[ 0 ].tx / size.width(); + *tpos++ = 1.0f - at(i)[ 0 ].ty / size.height(); + *tpos++ = at(i)[ 3 ].tx / size.width(); + *tpos++ = 1.0f - at(i)[ 3 ].ty / size.height(); + *tpos++ = at(i)[ 3 ].tx / size.width(); + *tpos++ = 1.0f - at(i)[ 3 ].ty / size.height(); + *tpos++ = at(i)[ 2 ].tx / size.width(); + *tpos++ = 1.0f - at(i)[ 2 ].ty / size.height(); + *tpos++ = at(i)[ 1 ].tx / size.width(); + *tpos++ = 1.0f - at(i)[ 1 ].ty / size.height(); + } } } diff --git a/libkwineffects/kwineffects.h b/libkwineffects/kwineffects.h index 5bac98f860..75af204da9 100644 --- a/libkwineffects/kwineffects.h +++ b/libkwineffects/kwineffects.h @@ -1332,7 +1332,7 @@ public: WindowQuadList select(WindowQuadType type) const; WindowQuadList filterOut(WindowQuadType type) const; bool smoothNeeded() const; - void makeArrays(float** vertices, float** texcoords) const; + void makeArrays(float** vertices, float** texcoords, const QSizeF &size, bool yInverted) const; bool isTransformed() const; }; diff --git a/libkwineffects/kwinglutils.cpp b/libkwineffects/kwinglutils.cpp index 6eddb4ae8c..15597d48dd 100644 --- a/libkwineffects/kwinglutils.cpp +++ b/libkwineffects/kwinglutils.cpp @@ -458,8 +458,6 @@ void GLTexture::render(QRegion region, const QRect& rect) GLShader *shader = ShaderManager::instance()->getBoundShader(); shader->setUniform(GLShader::Offset, QVector2D(rect.x(), rect.y())); shader->setUniform(GLShader::WindowTransformation, translation); - shader->setUniform(GLShader::TextureWidth, 1.0f); - shader->setUniform(GLShader::TextureHeight, 1.0f); } else { pushMatrix(translation); } @@ -705,8 +703,6 @@ GLShader::GLShader() : mProgram(0) , mValid(false) , mLocationsResolved(false) - , mTextureWidth(-1.0f) - , mTextureHeight(-1.0f) { } @@ -714,8 +710,6 @@ GLShader::GLShader(const QString& vertexfile, const QString& fragmentfile) : mProgram(0) , mValid(false) , mLocationsResolved(false) - , mTextureWidth(-1.0f) - , mTextureHeight(-1.0f) { loadFromFiles(vertexfile, fragmentfile); } @@ -871,8 +865,6 @@ void GLShader::resolveLocations() mVec4Location[ModulationConstant] = uniformLocation("modulation"); mFloatLocation[Saturation] = uniformLocation("saturation"); - mFloatLocation[TextureWidth] = uniformLocation("textureWidth"); - mFloatLocation[TextureHeight] = uniformLocation("textureHeight"); mIntLocation[AlphaToOne] = uniformLocation("u_forceAlpha"); @@ -1034,26 +1026,6 @@ bool GLShader::setAttribute(const char* name, float value) return (location >= 0); } -void GLShader::setTextureHeight(float height) -{ - mTextureHeight = height; -} - -void GLShader::setTextureWidth(float width) -{ - mTextureWidth = width; -} - -float GLShader::textureHeight() -{ - return mTextureHeight; -} - -float GLShader::textureWidth() -{ - return mTextureWidth; -} - QMatrix4x4 GLShader::getUniformMatrix4x4(const char* name) { int location = uniformLocation(name); @@ -1335,10 +1307,6 @@ void ShaderManager::resetShader(ShaderType type) shader->setUniform(GLShader::Saturation, 1.0f); shader->setUniform(GLShader::AlphaToOne, 0); - - // TODO: has to become textureSize - shader->setUniform(GLShader::TextureWidth, 1.0f); - shader->setUniform(GLShader::TextureHeight, 1.0f); } /*** GLRenderTarget ***/ diff --git a/libkwineffects/kwinglutils.h b/libkwineffects/kwinglutils.h index e2982cffdb..2773fd0f2b 100644 --- a/libkwineffects/kwinglutils.h +++ b/libkwineffects/kwinglutils.h @@ -280,12 +280,6 @@ public: **/ QMatrix4x4 getUniformMatrix4x4(const char* name); - void setTextureWidth(float width); - void setTextureHeight(float height); - - float textureWidth(); - float textureHeight(); - enum MatrixUniform { TextureMatrix = 0, ProjectionMatrix, @@ -307,8 +301,6 @@ public: enum FloatUniform { Saturation, - TextureWidth, - TextureHeight, FloatUniformCount }; @@ -341,8 +333,6 @@ private: int mVec4Location[Vec4UniformCount]; int mFloatLocation[FloatUniformCount]; int mIntLocation[IntUniformCount]; - float mTextureWidth; - float mTextureHeight; friend class ShaderManager; }; diff --git a/scene-generic-vertex.glsl b/scene-generic-vertex.glsl index 1d93b76fb9..6b970c4888 100644 --- a/scene-generic-vertex.glsl +++ b/scene-generic-vertex.glsl @@ -3,9 +3,6 @@ uniform mat4 modelview; uniform mat4 screenTransformation; uniform mat4 windowTransformation; -uniform float textureWidth; -uniform float textureHeight; - // passed in vertex - only x and y are used attribute vec4 vertex; // passed in texCoords - to be forwarded @@ -15,6 +12,6 @@ attribute vec2 texCoord; varying vec2 varyingTexCoords; void main() { - varyingTexCoords = texCoord / vec2(textureWidth, textureHeight); + varyingTexCoords = texCoord; gl_Position = projection*(modelview*screenTransformation*windowTransformation)*vertex; } diff --git a/scene-vertex.glsl b/scene-vertex.glsl index 43bf297adc..1aab8a8b1a 100644 --- a/scene-vertex.glsl +++ b/scene-vertex.glsl @@ -2,9 +2,6 @@ uniform mat4 projection; // offset of the window/texture to be rendered uniform vec2 offset; -uniform float textureWidth; -uniform float textureHeight; - // passed in vertex - only x and y are used attribute vec4 vertex; // passed in texCoords - to be forwarded @@ -14,6 +11,6 @@ attribute vec2 texCoord; varying vec2 varyingTexCoords; void main() { - varyingTexCoords = texCoord / vec2(textureWidth, textureHeight); + varyingTexCoords = texCoord; gl_Position = projection*vec4(vertex.xy + offset, vertex.zw); } diff --git a/scene_opengl.cpp b/scene_opengl.cpp index b314587af7..4d248eb504 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -585,16 +585,14 @@ void SceneOpenGL::Window::performPaint(int mask, QRegion region, WindowPaintData // paint the content if (!(mask & PAINT_DECORATION_ONLY)) { texture.bind(); - texture.enableUnnormalizedTexCoords(); prepareStates(Content, data.opacity * data.contents_opacity, data.brightness, data.saturation, data.shader); - renderQuads(mask, region, data.quads.select(WindowQuadContents)); + renderQuads(mask, region, data.quads.select(WindowQuadContents), toplevel->size(), texture.getYInverted()); restoreStates(Content, data.opacity * data.contents_opacity, data.brightness, data.saturation, data.shader); - texture.disableUnnormalizedTexCoords(); texture.unbind(); #ifndef KWIN_HAVE_OPENGLES if (static_cast(scene)->debug) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - renderQuads(mask, region, data.quads.select(WindowQuadContents)); + renderQuads(mask, region, data.quads.select(WindowQuadContents), toplevel->size(), texture.getYInverted()); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } #endif @@ -649,10 +647,6 @@ void SceneOpenGL::Window::paintDecoration(const QPixmap* decoration, TextureType prepareStates(decorationType, data.opacity * data.decoration_opacity, data.brightness, data.saturation, data.shader); makeDecorationArrays(quads, rect, decorationTexture->getYInverted()); - if (data.shader) { - data.shader->setUniform(GLShader::TextureWidth, 1.0f); - data.shader->setUniform(GLShader::TextureHeight, 1.0f); - } GLVertexBuffer::streamingBuffer()->render(region, GL_TRIANGLES); restoreStates(decorationType, data.opacity * data.decoration_opacity, data.brightness, data.saturation, data.shader); decorationTexture->unbind(); @@ -679,17 +673,13 @@ void SceneOpenGL::Window::paintShadow(WindowQuadType type, const QRegion ®ion texture->setWrapMode(GL_CLAMP_TO_EDGE); texture->bind(); prepareStates(Shadow, data.opacity, data.brightness, data.saturation, data.shader, texture); - if (data.shader) { - data.shader->setUniform(GLShader::TextureWidth, 1.0f); - data.shader->setUniform(GLShader::TextureHeight, 1.0f); - } - renderQuads(0, region, quads); + renderQuads(0, region, quads, QSizeF(1.0, 1.0), texture->getYInverted()); restoreStates(Shadow, data.opacity, data.brightness, data.saturation, data.shader, texture); texture->unbind(); #ifndef KWIN_HAVE_OPENGLES if (static_cast(scene)->debug) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - renderQuads(0, region, quads); + renderQuads(0, region, quads, QSizeF(1.0, 1.0), texture->getYInverted()); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } #endif @@ -748,14 +738,14 @@ void SceneOpenGL::Window::makeDecorationArrays(const WindowQuadList& quads, cons GLVertexBuffer::streamingBuffer()->setData(quads.count() * 6, 2, vertices.data(), texcoords.data()); } -void SceneOpenGL::Window::renderQuads(int, const QRegion& region, const WindowQuadList& quads) +void SceneOpenGL::Window::renderQuads(int, const QRegion& region, const WindowQuadList& quads, const QSizeF &size, bool yInverted) { if (quads.isEmpty()) return; // Render geometry float* vertices; float* texcoords; - quads.makeArrays(&vertices, &texcoords); + quads.makeArrays(&vertices, &texcoords, size, yInverted); GLVertexBuffer::streamingBuffer()->setData(quads.count() * 6, 2, vertices, texcoords); GLVertexBuffer::streamingBuffer()->render(region, GL_TRIANGLES); delete[] vertices; @@ -826,14 +816,6 @@ void SceneOpenGL::Window::prepareShaderRenderStates(TextureType type, double opa shader->setUniform(GLShader::ModulationConstant, QVector4D(rgb, rgb, rgb, a)); shader->setUniform(GLShader::Saturation, saturation); shader->setUniform(GLShader::AlphaToOne, opaque ? 1 : 0); - - const float texw = shader->textureWidth(); - const float texh = shader->textureHeight(); - - // setting texture width and height stored in shader - // only set if it is set by an effect that is not negative - shader->setUniform(GLShader::TextureWidth, texw >= 0.0 ? texw : toplevel->width()); - shader->setUniform(GLShader::TextureHeight, texh >= 0.0 ? texh : toplevel->height()); } void SceneOpenGL::Window::prepareRenderStates(TextureType type, double opacity, double brightness, double saturation, Texture *tex) @@ -1167,9 +1149,6 @@ void SceneOpenGL::EffectFrame::render(QRegion region, double opacity, double fra shader->setUniform(GLShader::ModulationConstant, QVector4D(1.0, 1.0, 1.0, 1.0)); shader->setUniform(GLShader::Saturation, 1.0f); shader->setUniform(GLShader::AlphaToOne, 0); - - shader->setUniform(GLShader::TextureWidth, 1.0f); - shader->setUniform(GLShader::TextureHeight, 1.0f); } #ifndef KWIN_HAVE_OPENGLES diff --git a/scene_opengl.h b/scene_opengl.h index 4996b3592b..8a9ad55c11 100644 --- a/scene_opengl.h +++ b/scene_opengl.h @@ -169,7 +169,7 @@ protected: void paintDecoration(const QPixmap* decoration, TextureType decorationType, const QRegion& region, const QRect& rect, const WindowPaintData& data, const WindowQuadList& quads, bool updateDeco); void paintShadow(WindowQuadType type, const QRegion ®ion, const WindowPaintData &data); void makeDecorationArrays(const WindowQuadList& quads, const QRect& rect, bool y_inverted) const; - void renderQuads(int mask, const QRegion& region, const WindowQuadList& quads); + void renderQuads(int, const QRegion& region, const KWin::WindowQuadList& quads, const QSizeF& size, bool yInverted); void prepareStates(TextureType type, double opacity, double brightness, double saturation, GLShader* shader); void prepareStates(TextureType type, double opacity, double brightness, double saturation, GLShader* shader, Texture *texture); void prepareRenderStates(TextureType type, double opacity, double brightness, double saturation, Texture *tex);