Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QSGSimpleMaterialShader Class

The QSGSimpleMaterialShader provides a convenient way of building custom materials for the scene graph. More...

 #include <QSGSimpleMaterialShader>

Inherits: QSGMaterialShader.

Public Types

class RenderState

Public Functions

QSGMaterialShader()
virtual ~QSGMaterialShader()
virtual void activate()
virtual char const * const * attributeNames() const = 0
virtual QList<QByteArray> attributes() const = 0
virtual void deactivate()
QOpenGLShaderProgram * program()
virtual void resolveUniforms()
const char * uniformMatrixName() const
const char * uniformOpacityName() const
virtual void updateState(const RenderState & state, QSGMaterial * newMaterial, QSGMaterial * oldMaterial)
virtual void updateState(const State * newState, const State * oldState) = 0

Reimplemented Public Functions

virtual char const * const * attributeNames() const
virtual void initialize()
virtual void updateState(const RenderState & state, QSGMaterial * newMaterial, QSGMaterial * oldMaterial)

Protected Functions

virtual void compile()
virtual const char * fragmentShader() const = 0
virtual void initialize()
virtual const char * vertexShader() const = 0

Detailed Description

The QSGSimpleMaterialShader provides a convenient way of building custom materials for the scene graph.

Where the QSGMaterial and QSGMaterialShader API requires a bit of boilerplate code to create a functioning material, the QSGSimpleMaterialShader tries to hide some of this through the use of templates.

QSGSimpleMaterialShader::vertexShader() and QSGSimpleMaterialShader::fragmentShader() are used to specify the actual shader source code. The names of the vertex attributes should be listed in the QSGSimpleMaterialShader::attributes()

QSGSimpleMaterialShader::updateState() is used to push the material state to the OpenGL shader program.

The actual OpenGL shader program is accessible through the QSGSimpleMaterialShader::program() function.

Each QSGSimpleMaterialShader implementation operates on a unique state struct. The state struct must be declared using the QSG_DECLARE_SIMPLE_SHADER macro.

Here is a simple example of a custom solid-color:

 struct Color
 {
     float r, g, b, a;
 };

 class MinimalShader : public QSGSimpleMaterialShader<Color>
 {
     QSG_DECLARE_SIMPLE_SHADER(MinimalShader, Color)
 public:

     const char *vertexShader() const {
         return
         "attribute highp vec4 vertex;               \n"
         "uniform highp mat4 qt_Matrix;              \n"
         "void main() {                              \n"
         "    gl_Position = qt_Matrix * vertex;      \n"
         "}";
     }

     const char *fragmentShader() const {
         return
         "uniform lowp float qt_Opacity;             \n"
         "uniform lowp vec4 color;                   \n"
         "void main() {                              \n"
         "    gl_FragColor = color * qt_Opacity;     \n"
         "}";
     }

     QList<QByteArray> attributes() const {
         return QList<QByteArray>() << "vertex";
     }

     void updateState(const Color *color, const Color *) {
         program()->setUniformValue("color", color->r, color->g, color->b, color->a);
     }

 };

Instances of materials using this shader can be created using the createMaterial() function which will be defined by the QSG_DECLARE_SIMPLE_SHADER macro.

     QSGSimpleMaterial<Color> *material = MinimalShader::createMaterial();
     material->state()->r = 1;
     material->state()->g = 0;
     material->state()->b = 0;
     material->state()->a = 1;

     node->setMaterial(material);

The scene graph will often try to find materials that have the same or at least similar state so that these can be batched together inside the renderer, which gives better performance. To specify sortable material states, use QSG_DECLARE_SIMPLE_COMPARABLE_SHADER instead of QSG_DECLARE_SIMPLE_SHADER. The state struct must then also define the function:

 int compare(const Type *other) const;

Warning: The QSGSimpleMaterialShader relies on template instantiation to create a QSGMaterialType which the scene graph renderer internally uses to identify this shader. For this reason, the unique QSGSimpleMaterialShader implemenation must be instantiated with a unique C++ type.

Member Function Documentation

char const * const * QSGSimpleMaterialShader::attributeNames() const [virtual]

QList<QByteArray> QSGSimpleMaterialShader::attributes() const [pure virtual]

Returns a list of names, declaring the vertex attributes in the vertex shader.

void QSGSimpleMaterialShader::initialize() [virtual]

void QSGSimpleMaterialShader::resolveUniforms() [virtual]

const char * QSGSimpleMaterialShader::uniformMatrixName() const

const char * QSGSimpleMaterialShader::uniformOpacityName() const

void QSGSimpleMaterialShader::updateState(const RenderState & state, QSGMaterial * newMaterial, QSGMaterial * oldMaterial) [virtual]

void QSGSimpleMaterialShader::updateState(const State * newState, const State * oldState) [pure virtual]

Called whenever the state of this shader should be updated, typical for each new set of geometries being drawn.

Both the old and the new state are passed in so that the implementation can compare and minimize the state changes when applicable.

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web