diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2010-12-15 21:06:26 +0100 |
---|---|---|
committer | Gunnar Sletta <gunnar.sletta@nokia.com> | 2010-12-15 21:06:26 +0100 |
commit | 1ee64e326b037e3da4d68b21597939dbf4728bc4 (patch) | |
tree | dedbd05abd214302f97b343eaf64431060c9b0ca | |
parent | c9bc62ea78f6d75768213c5859df85facc667748 (diff) |
fix texture wrapping which lead to pixel errors on pixmap edges
-rw-r--r-- | src/adaptationlayers/default/default_texturenode.cpp | 3 | ||||
-rw-r--r-- | src/scenegraph/convenience/texturematerial.cpp | 18 | ||||
-rw-r--r-- | src/scenegraph/convenience/texturematerial.h | 12 |
3 files changed, 22 insertions, 11 deletions
diff --git a/src/adaptationlayers/default/default_texturenode.cpp b/src/adaptationlayers/default/default_texturenode.cpp index 077f7de..85c6eeb 100644 --- a/src/adaptationlayers/default/default_texturenode.cpp +++ b/src/adaptationlayers/default/default_texturenode.cpp @@ -227,4 +227,7 @@ void DefaultTextureNode::updateTexture() m_material.setTexture(m_texture, opaque); m_materialO.setTexture(m_texture, opaque); setMaterial(m_opacity == 1 ? &m_material : &m_materialO); // Indicate that the material state has changed. + + m_material.setClampToEdge(m_clamp_to_edge); + m_materialO.setClampToEdge(m_clamp_to_edge); } diff --git a/src/scenegraph/convenience/texturematerial.cpp b/src/scenegraph/convenience/texturematerial.cpp index 8e03884..2c431e7 100644 --- a/src/scenegraph/convenience/texturematerial.cpp +++ b/src/scenegraph/convenience/texturematerial.cpp @@ -128,6 +128,12 @@ void TextureMaterialData::updateEffectState(Renderer *renderer, AbstractEffect * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); } + + if (oldEffect == 0 || tx->clampToEdge() != oldTx->clampToEdge()) { + int wrapMode = tx->clampToEdge() ? GL_CLAMP_TO_EDGE : GL_REPEAT; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapMode); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapMode); + } } @@ -226,20 +232,12 @@ AbstractEffectProgram *TextureMaterialWithOpacity::createProgram() const void TextureMaterialWithOpacityData::updateEffectState(Renderer *renderer, AbstractEffect *newEffect, AbstractEffect *oldEffect) { + TextureMaterialData::updateEffectState(renderer, newEffect, oldEffect); + Q_ASSERT(oldEffect == 0 || newEffect->type() == oldEffect->type()); TextureMaterialWithOpacity *tx = static_cast<TextureMaterialWithOpacity *>(newEffect); TextureMaterialWithOpacity *oldTx = static_cast<TextureMaterialWithOpacity *>(oldEffect); - if (oldEffect == 0 || tx->texture().texture() != oldTx->texture().texture()) { - renderer->setTexture(0, tx->texture()); - oldEffect = 0; // Force filtering update. - } - if (oldEffect == 0 || tx->linearFiltering() != oldTx->linearFiltering()) { - int filtering = tx->linearFiltering() ? GL_LINEAR : GL_NEAREST; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); - } - if (oldTx == 0 || tx->opacity() != oldTx->opacity()) m_program.setUniformValue(m_opacity_id, (GLfloat) tx->opacity()); } diff --git a/src/scenegraph/convenience/texturematerial.h b/src/scenegraph/convenience/texturematerial.h index 166bca1..6a43cb5 100644 --- a/src/scenegraph/convenience/texturematerial.h +++ b/src/scenegraph/convenience/texturematerial.h @@ -48,7 +48,13 @@ class QT_SCENEGRAPH_EXPORT TextureMaterial : public AbstractEffect { public: - TextureMaterial() : m_texture(0), m_opaque(true), m_linear_filtering(false) { } + TextureMaterial() + : m_texture(0) + , m_opaque(true) + , m_linear_filtering(false) + , m_clamp_to_edge(true) + { + } virtual AbstractEffectType *type() const; virtual AbstractEffectProgram *createProgram() const; @@ -61,12 +67,16 @@ public: void setLinearFiltering(bool linearFiltering) { m_linear_filtering = linearFiltering; } bool linearFiltering() const { return m_linear_filtering; } + void setClampToEdge(bool clamp) { m_clamp_to_edge = clamp; } + bool clampToEdge() const { return m_clamp_to_edge; } + static bool is(const AbstractEffect *effect); protected: QSGTextureRef m_texture; bool m_opaque; bool m_linear_filtering; + bool m_clamp_to_edge; }; class TextureMaterialData : public AbstractShaderEffectProgram |