src/opengl/qglshaderprogram.cpp
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
child 14 c0432d11811c
equal deleted inserted replaced
4:3b1da2848fc7 5:d3bac044e0f0
   104     With the above shader program active, we can draw a green triangle
   104     With the above shader program active, we can draw a green triangle
   105     as follows:
   105     as follows:
   106 
   106 
   107     \snippet doc/src/snippets/code/src_opengl_qglshaderprogram.cpp 2
   107     \snippet doc/src/snippets/code/src_opengl_qglshaderprogram.cpp 2
   108 
   108 
       
   109     \section1 Binary shaders and programs
       
   110 
       
   111     Binary shaders may be specified using \c{glShaderBinary()} on
       
   112     the return value from QGLShader::shaderId().  The QGLShader instance
       
   113     containing the binary can then be added to the shader program with
       
   114     addShader() and linked in the usual fashion with link().
       
   115 
       
   116     Binary programs may be specified using \c{glProgramBinaryOES()}
       
   117     on the return value from programId().  Then the application should
       
   118     call link(), which will notice that the program has already been
       
   119     specified and linked, allowing other operations to be performed
       
   120     on the shader program.
       
   121 
   109     \sa QGLShader
   122     \sa QGLShader
   110 */
   123 */
   111 
   124 
   112 /*!
   125 /*!
   113     \class QGLShader
   126     \class QGLShader
   630         if (!QGLContext::areSharing(shader->d_func()->shaderGuard.context(),
   643         if (!QGLContext::areSharing(shader->d_func()->shaderGuard.context(),
   631                                     d->programGuard.context())) {
   644                                     d->programGuard.context())) {
   632             qWarning("QGLShaderProgram::addShader: Program and shader are not associated with same context.");
   645             qWarning("QGLShaderProgram::addShader: Program and shader are not associated with same context.");
   633             return false;
   646             return false;
   634         }
   647         }
   635         if (!shader->d_func()->compiled)
       
   636             return false;
       
   637         if (!shader->d_func()->shaderGuard.id())
   648         if (!shader->d_func()->shaderGuard.id())
   638             return false;
   649             return false;
   639         glAttachShader(d->programGuard.id(), shader->d_func()->shaderGuard.id());
   650         glAttachShader(d->programGuard.id(), shader->d_func()->shaderGuard.id());
   640         d->linked = false;  // Program needs to be relinked.
   651         d->linked = false;  // Program needs to be relinked.
   641         d->shaders.append(shader);
   652         d->shaders.append(shader);
   818 {
   829 {
   819     Q_D(QGLShaderProgram);
   830     Q_D(QGLShaderProgram);
   820     GLuint program = d->programGuard.id();
   831     GLuint program = d->programGuard.id();
   821     if (!program)
   832     if (!program)
   822         return false;
   833         return false;
       
   834     GLint value;
       
   835     if (d->shaders.isEmpty()) {
       
   836         // If there are no explicit shaders, then it is possible that the
       
   837         // application added a program binary with glProgramBinaryOES(),
       
   838         // or otherwise populated the shaders itself.  Check to see if the
       
   839         // program is already linked and bail out if so.
       
   840         value = 0;
       
   841         glGetProgramiv(program, GL_LINK_STATUS, &value);
       
   842         d->linked = (value != 0);
       
   843         if (d->linked)
       
   844             return true;
       
   845     }
   823     glLinkProgram(program);
   846     glLinkProgram(program);
   824     GLint value = 0;
   847     value = 0;
   825     glGetProgramiv(program, GL_LINK_STATUS, &value);
   848     glGetProgramiv(program, GL_LINK_STATUS, &value);
   826     d->linked = (value != 0);
   849     d->linked = (value != 0);
   827     value = 0;
   850     value = 0;
   828     glGetProgramiv(program, GL_INFO_LOG_LENGTH, &value);
   851     glGetProgramiv(program, GL_INFO_LOG_LENGTH, &value);
   829     d->log = QString();
   852     d->log = QString();
   926     \sa QGLShader::shaderId()
   949     \sa QGLShader::shaderId()
   927 */
   950 */
   928 GLuint QGLShaderProgram::programId() const
   951 GLuint QGLShaderProgram::programId() const
   929 {
   952 {
   930     Q_D(const QGLShaderProgram);
   953     Q_D(const QGLShaderProgram);
       
   954     GLuint id = d->programGuard.id();
       
   955     if (id)
       
   956         return id;
       
   957 
       
   958     // Create the identifier if we don't have one yet.  This is for
       
   959     // applications that want to create the attached shader configuration
       
   960     // themselves, particularly those using program binaries.
       
   961     if (!const_cast<QGLShaderProgram *>(this)->init())
       
   962         return 0;
   931     return d->programGuard.id();
   963     return d->programGuard.id();
   932 }
   964 }
   933 
   965 
   934 /*!
   966 /*!
   935     Binds the attribute \a name to the specified \a location.  This
   967     Binds the attribute \a name to the specified \a location.  This