Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Renamed of texture material classes to be more intuitivly named
The assumption is that most people will use QSGTextureMaterial
so this should be the one that works for both transparent
and opaque textures. QSGOpaqueTextureMaterial is an optimization
  • Loading branch information
Gunnar Sletta committed May 9, 2011
1 parent 743f8df commit 2aa66a6
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/declarative/items/qsgninepatchnode_p.h
Expand Up @@ -81,8 +81,8 @@ class QSGNinePatchNode : public QSGGeometryNode
void fillRow(QSGGeometry::TexturedPoint2D *&v, float y, float ty, int xChunkCount, float xChunkSize);
QRectF m_targetRect;
QRectF m_innerRect;
QSGTextureMaterial m_material;
QSGTextureMaterialWithOpacity m_materialO;
QSGOpaqueTextureMaterial m_material;
QSGTextureMaterial m_materialO;
QSGGeometry m_geometry;

uint m_horizontalTileMode : 2;
Expand Down
4 changes: 2 additions & 2 deletions src/declarative/scenegraph/qsgdefaultimagenode_p.h
Expand Up @@ -75,8 +75,8 @@ class QSGDefaultImageNode : public QSGImageNode
QRectF m_targetRect;
QRectF m_sourceRect;

QSGTextureMaterial m_material;
QSGTextureMaterialWithOpacity m_materialO;
QSGOpaqueTextureMaterial m_material;
QSGTextureMaterial m_materialO;

uint m_dirtyGeometry : 1;

Expand Down
4 changes: 2 additions & 2 deletions src/declarative/scenegraph/util/qsgpainternode_p.h
Expand Up @@ -118,8 +118,8 @@ class Q_DECLARATIVE_EXPORT QSGPainterNode : public QSGGeometryNode
QGLFramebufferObject *m_multisampledFbo;
QImage m_image;

QSGTextureMaterial m_material;
QSGTextureMaterialWithOpacity m_materialO;
QSGOpaqueTextureMaterial m_material;
QSGTextureMaterial m_materialO;
QSGGeometry m_geometry;
QSGPainterTexture *m_texture;

Expand Down
4 changes: 2 additions & 2 deletions src/declarative/scenegraph/util/qsgsimpletexturenode.h
Expand Up @@ -69,8 +69,8 @@ class Q_DECLARATIVE_EXPORT QSGSimpleTextureNode : public QSGGeometryNode

private:
QSGGeometry m_geometry;
QSGTextureMaterial m_opaque_material;
QSGTextureMaterialWithOpacity m_material;
QSGOpaqueTextureMaterial m_opaque_material;
QSGTextureMaterial m_material;

QRectF m_rect;
};
Expand Down
54 changes: 27 additions & 27 deletions src/declarative/scenegraph/util/qsgtexturematerial.cpp
Expand Up @@ -63,34 +63,34 @@ const char qt_scenegraph_texture_material_fragment[] =
"}";


const char *QSGTextureMaterialShader::vertexShader() const
const char *QSGOpaqueTextureMaterialShader::vertexShader() const
{
return qt_scenegraph_texture_material_vertex_code;
}

const char *QSGTextureMaterialShader::fragmentShader() const
const char *QSGOpaqueTextureMaterialShader::fragmentShader() const
{
return qt_scenegraph_texture_material_fragment;
}

QSGMaterialType QSGTextureMaterialShader::type;
QSGMaterialType QSGOpaqueTextureMaterialShader::type;

char const *const *QSGTextureMaterialShader::attributeNames() const
char const *const *QSGOpaqueTextureMaterialShader::attributeNames() const
{
static char const *const attr[] = { "qt_VertexPosition", "qt_VertexTexCoord", 0 };
return attr;
}

void QSGTextureMaterialShader::initialize()
void QSGOpaqueTextureMaterialShader::initialize()
{
m_matrix_id = m_program.uniformLocation("qt_Matrix");
}

void QSGTextureMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
{
Q_ASSERT(oldEffect == 0 || newEffect->type() == oldEffect->type());
QSGTextureMaterial *tx = static_cast<QSGTextureMaterial *>(newEffect);
QSGTextureMaterial *oldTx = static_cast<QSGTextureMaterial *>(oldEffect);
QSGOpaqueTextureMaterial *tx = static_cast<QSGOpaqueTextureMaterial *>(newEffect);
QSGOpaqueTextureMaterial *oldTx = static_cast<QSGOpaqueTextureMaterial *>(oldEffect);

QSGTexture *t = tx->texture();

Expand All @@ -109,7 +109,7 @@ void QSGTextureMaterialShader::updateState(const RenderState &state, QSGMaterial
}


QSGTextureMaterial::QSGTextureMaterial()
QSGOpaqueTextureMaterial::QSGOpaqueTextureMaterial()
: m_texture(0)
, m_filtering(QSGTexture::Nearest)
, m_mipmap_filtering(QSGTexture::Nearest)
Expand All @@ -120,34 +120,34 @@ QSGTextureMaterial::QSGTextureMaterial()



QSGMaterialType *QSGTextureMaterial::type() const
QSGMaterialType *QSGOpaqueTextureMaterial::type() const
{
return &QSGTextureMaterialShader::type;
return &QSGOpaqueTextureMaterialShader::type;
}

QSGMaterialShader *QSGTextureMaterial::createShader() const
QSGMaterialShader *QSGOpaqueTextureMaterial::createShader() const
{
return new QSGTextureMaterialShader;
return new QSGOpaqueTextureMaterialShader;
}


void QSGTextureMaterial::setTexture(QSGTexture *texture)
void QSGOpaqueTextureMaterial::setTexture(QSGTexture *texture)
{
m_texture = texture;
setFlag(Blending, m_texture ? m_texture->hasAlphaChannel() : false);
}


int QSGTextureMaterial::compare(const QSGMaterial *o) const
int QSGOpaqueTextureMaterial::compare(const QSGMaterial *o) const
{
Q_ASSERT(o && type() == o->type());
const QSGTextureMaterial *other = static_cast<const QSGTextureMaterial *>(o);
const QSGOpaqueTextureMaterial *other = static_cast<const QSGOpaqueTextureMaterial *>(o);
if (int diff = m_texture->textureId() - other->texture()->textureId())
return diff;
return int(m_filtering) - int(other->m_filtering);
}

// QSGTextureMaterialWithOpacity
// QSGTextureMaterial

static const char qt_scenegraph_texture_material_opacity_fragment[] =
"varying highp vec2 qt_TexCoord; \n"
Expand All @@ -157,7 +157,7 @@ static const char qt_scenegraph_texture_material_opacity_fragment[] =
" gl_FragColor = texture2D(qt_Texture, qt_TexCoord) * opacity; \n"
"}";

class TextureMaterialWithOpacityShader : public QSGTextureMaterialShader
class QSGTextureMaterialShader : public QSGOpaqueTextureMaterialShader
{
public:
virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect);
Expand All @@ -170,30 +170,30 @@ class TextureMaterialWithOpacityShader : public QSGTextureMaterialShader

int m_opacity_id;
};
QSGMaterialType TextureMaterialWithOpacityShader::type;
QSGMaterialType QSGTextureMaterialShader::type;

QSGMaterialType *QSGTextureMaterialWithOpacity::type() const
QSGMaterialType *QSGTextureMaterial::type() const
{
return &TextureMaterialWithOpacityShader::type;
return &QSGTextureMaterialShader::type;
}

QSGMaterialShader *QSGTextureMaterialWithOpacity::createShader() const
QSGMaterialShader *QSGTextureMaterial::createShader() const
{
return new TextureMaterialWithOpacityShader;
return new QSGTextureMaterialShader;
}

void TextureMaterialWithOpacityShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
void QSGTextureMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
{
Q_ASSERT(oldEffect == 0 || newEffect->type() == oldEffect->type());
if (state.isOpacityDirty())
m_program.setUniformValue(m_opacity_id, state.opacity());

QSGTextureMaterialShader::updateState(state, newEffect, oldEffect);
QSGOpaqueTextureMaterialShader::updateState(state, newEffect, oldEffect);
}

void TextureMaterialWithOpacityShader::initialize()
void QSGTextureMaterialShader::initialize()
{
QSGTextureMaterialShader::initialize();
QSGOpaqueTextureMaterialShader::initialize();
m_opacity_id = m_program.uniformLocation("opacity");
}

Expand Down
8 changes: 5 additions & 3 deletions src/declarative/scenegraph/util/qsgtexturematerial.h
Expand Up @@ -52,10 +52,10 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)


class Q_DECLARATIVE_EXPORT QSGTextureMaterial : public QSGMaterial
class Q_DECLARATIVE_EXPORT QSGOpaqueTextureMaterial : public QSGMaterial
{
public:
QSGTextureMaterial();
QSGOpaqueTextureMaterial();

virtual QSGMaterialType *type() const;
virtual QSGMaterialShader *createShader() const;
Expand Down Expand Up @@ -83,10 +83,12 @@ class Q_DECLARATIVE_EXPORT QSGTextureMaterial : public QSGMaterial
uint m_mipmap_filtering: 2;
uint m_horizontal_wrap : 1;
uint m_vertical_wrap: 1;

uint m_reserved : 26;
};


class Q_DECLARATIVE_EXPORT QSGTextureMaterialWithOpacity : public QSGTextureMaterial
class Q_DECLARATIVE_EXPORT QSGTextureMaterial : public QSGOpaqueTextureMaterial
{
public:
virtual QSGMaterialType *type() const;
Expand Down
2 changes: 1 addition & 1 deletion src/declarative/scenegraph/util/qsgtexturematerial_p.h
Expand Up @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE

QT_MODULE(Declarative)

class Q_DECLARATIVE_EXPORT QSGTextureMaterialShader : public QSGMaterialShader
class Q_DECLARATIVE_EXPORT QSGOpaqueTextureMaterialShader : public QSGMaterialShader
{
public:
virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect);
Expand Down

0 comments on commit 2aa66a6

Please sign in to comment.