当前位置: 首页>>代码示例>>C++>>正文


C++ GlslProg::getAttribLocation方法代码示例

本文整理汇总了C++中gl::GlslProg::getAttribLocation方法的典型用法代码示例。如果您正苦于以下问题:C++ GlslProg::getAttribLocation方法的具体用法?C++ GlslProg::getAttribLocation怎么用?C++ GlslProg::getAttribLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gl::GlslProg的用法示例。


在下文中一共展示了GlslProg::getAttribLocation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: initializeBuffer

void HexagonMirrorApp::initializeBuffer()
{
    // To pass the model matrix for each instance, we will use
    // a custom vertex shader attribute. Using an attribute will
    // give us more freedom and more storage capacity than using
    // a uniform buffer, which often has a capacity limit of 64KB
    // or less, which is just enough for 1024 instances.
    //
    // Because we want the attribute to stay the same for all
    // vertices of an instance, we set the divisor to '1' instead
    // of '0', so the attribute will only change after all
    // vertices of the instance have been drawn.
    //
    // See for more information: http://ogldev.atspace.co.uk/www/tutorial33/tutorial33.html

    // initialize transforms for every instance
    std::vector< Matrix44f > matrices;
    matrices.reserve( NUM_INSTANCES );

    for(size_t i=0; i<NUM_INSTANCES; ++i)
    {
        // determine position for this hexagon
        float x = math<float>::fmod( float(i), INSTANCES_PER_ROW );
        float y = math<float>::floor( float(i) / INSTANCES_PER_ROW );

        // create transform matrix, then rotate and translate it
        Matrix44f model;
        model.translate( Vec3f( 3.0f * x + 1.5f * math<float>::fmod( y, 2.0f ) , 0.866025f * y, 0.0f ) );
        matrices.push_back( model );
    }

    // retrieve attribute location from the shader
    // (note: make sure the shader is loaded and compiled before calling this function)
    GLint ulocation = mShaderInstanced.getAttribLocation( "model_matrix" );

    // if found...
    if( ulocation != -1 )
    {
        // create vertex array object to hold our buffer
        // (note: this is required for OpenGL 3.1 and above)
        glGenVertexArrays(1, &mVAO);
        glBindVertexArray(mVAO);

        // create array buffer to store model matrices
        mBuffer = gl::Vbo( GL_ARRAY_BUFFER );

        // setup the buffer to contain space for all matrices.
        // we need 4 attributes to contain the 16 floats of a single matrix,
        // because the maximum size of an attribute is 4 floats (16 bytes).
        // When adding a 'mat4' attribute, OpenGL will make sure that
        // the attribute locations are sequential, e.g.: 3, 4, 5 and 6
        mBuffer.bind();
        for (unsigned int i = 0; i < 4 ; i++) {
            glEnableVertexAttribArray(ulocation + i);
            glVertexAttribPointer( ulocation + i, 4, GL_FLOAT, GL_FALSE, sizeof(Matrix44f), (const GLvoid*) (4 * sizeof(GLfloat) * i) );

            // get the next matrix after each instance, instead of each vertex
            glVertexAttribDivisor( ulocation + i, 1 );
        }

        // fill the buffer with our data
        mBuffer.bufferData( matrices.size() * sizeof(Matrix44f), &matrices.front(), GL_STATIC_READ );
        mBuffer.unbind();

        // unbind the VAO
        glBindVertexArray(0);
    }
}
开发者ID:audionerd,项目名称:Cinder-Samples,代码行数:68,代码来源:HexagonMirrorApp.cpp


注:本文中的gl::GlslProg::getAttribLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。