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


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

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


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

示例1: enable

void VertexLayout::enable(RenderState& rs, ShaderProgram& _program, size_t _byteOffset, void* _ptr) {

    GLuint glProgram = _program.getGlProgram();

    // Enable all attributes for this layout
    for (auto& attrib : m_attribs) {

        GLint location = _program.getAttribLocation(attrib.name);

        if (location != -1) {
            auto& loc = rs.attributeBindings[location];
            // Track currently enabled attribs by the program to which they are bound
            if (loc != glProgram) {
                GL::enableVertexAttribArray(location);
                loc = glProgram;
            }

            void* data = (unsigned char*)_ptr + attrib.offset + _byteOffset;
            GL::vertexAttribPointer(location, attrib.size, attrib.type, attrib.normalized, m_stride, data);
        }
    }

    // Disable previously bound and now-unneeded attributes
    for (size_t i = 0; i < RenderState::MAX_ATTRIBUTES; ++i) {

        GLuint& boundProgram = rs.attributeBindings[i];

        if (boundProgram != glProgram && boundProgram != 0) {
            GL::disableVertexAttribArray(i);
            boundProgram = 0;
        }
    }
}
开发者ID:enterstudio,项目名称:tangram-es,代码行数:33,代码来源:vertexLayout.cpp

示例2: enable

void VertexLayout::enable(ShaderProgram& _program, size_t _byteOffset, void* _ptr) {

    GLuint glProgram = _program.getGlProgram();

    // Enable all attributes for this layout
    for (auto& attrib : m_attribs) {

        GLint location = _program.getAttribLocation(attrib.name);

        if (location != -1) {
            auto& loc = s_enabledAttribs[location];
            // Track currently enabled attribs by the program to which they are bound
            if (loc != glProgram) {
                glEnableVertexAttribArray(location);
                loc = glProgram;
            }

            void* data = _ptr ? _ptr : ((unsigned char*) attrib.offset) + _byteOffset;
            glVertexAttribPointer(location, attrib.size, attrib.type, attrib.normalized, m_stride, data);
        }
    }

    // Disable previously bound and now-unneeded attributes
    for (auto& locationProgramPair : s_enabledAttribs) {

        const GLint& location = locationProgramPair.first;
        GLuint& boundProgram = locationProgramPair.second;

        if (boundProgram != glProgram && boundProgram != 0) {
            glDisableVertexAttribArray(location);
            boundProgram = 0;
        }
    }
}
开发者ID:fangjianming,项目名称:tangram-es,代码行数:34,代码来源:vertexLayout.cpp

示例3: vsFile

TEST_F(TransformFeedbackTest, test)
{
    std::ifstream       vsFile("data/transform_feedback.vert");
    std::ifstream       gsFile("data/transform_feedback.geom");
    Shader              vertex(GL_VERTEX_SHADER);
    Shader              geometry(GL_GEOMETRY_SHADER);
    ShaderProgram       shader;
    Query               query(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
    VAO                 vao;
    VBO                 vbo;
    TFBO                tfbo;
    const GLchar*       feedbackVaryings[] = { "outValue" };
    GLfloat             data[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
    GLfloat             feedback[15];
    GLuint              primitives;

    ASSERT_TRUE(vertex.compile(vsFile));
    ASSERT_TRUE(geometry.compile(gsFile));
    shader.attach(vertex);
    shader.attach(geometry);

    shader.setTransformFeedbackVaryings(1, feedbackVaryings, GL_INTERLEAVED_ATTRIBS);
    ASSERT_TRUE(shader.link());
    shader.use();
    shader.printDebug();

    vao.bind();

    vbo.bind();
    vbo.setData(sizeof(data), data, GL_STATIC_DRAW);

    GLint inputAttrib = shader.getAttribLocation("inValue");

    vao.enableAttrib(inputAttrib);
    glVertexAttribPointer(inputAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0);

    tfbo.setData(sizeof(data) * 3, nullptr, GL_STATIC_READ);
    tfbo.bindBufferBase(0);

    mogl::enable(GL_RASTERIZER_DISCARD);
    query.begin();
    TransformFeedback::begin(GL_TRIANGLES);
    glDrawArrays(GL_POINTS, 0, 5);
    TransformFeedback::end();
    query.end();
    mogl::disable(GL_RASTERIZER_DISCARD);
    mogl::Sync::flush();

    primitives = query.get<GLuint>(GL_QUERY_RESULT);
    tfbo.getSubData(0, sizeof(feedback), feedback);
    std::cout << primitives << " primitives written" << std::endl;
    for (unsigned int i = 0; i < 15; ++i)
        std::cout << feedback[i] << std::endl;
}
开发者ID:Ryp,项目名称:moGL,代码行数:54,代码来源:transform_feedback.cpp

示例4: uploadVaoData

void Cube::uploadVaoData(const ShaderProgram &shader)
{
	glBindVertexArray(vao);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	
	GLint positionAttribLocation = shader.getAttribLocation( "position" );
	glEnableVertexAttribArray(positionAttribLocation);
	glVertexAttribPointer(positionAttribLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
	
	//-- Unbind target, and restore default values:
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindVertexArray(0);
	
	CHECK_GL_ERRORS;
}
开发者ID:chinux23,项目名称:CS488-Ray-Tracer,代码行数:15,代码来源:cube.cpp

示例5: initialize

void Vao::initialize(RenderState& rs, ShaderProgram& _program, const VertexOffsets& _vertexOffsets,
                     VertexLayout& _layout, GLuint _vertexBuffer, GLuint _indexBuffer) {

    m_glVAOs.resize(_vertexOffsets.size());

    GL::genVertexArrays(m_glVAOs.size(), m_glVAOs.data());

    fastmap<std::string, GLuint> locations;

    // FIXME (use a bindAttrib instead of getLocation) to make those locations shader independent
    for (auto& attrib : _layout.getAttribs()) {
        GLint location = _program.getAttribLocation(attrib.name);
        locations[attrib.name] = location;
    }

    rs.vertexBuffer(_vertexBuffer);

    int vertexOffset = 0;
    for (size_t i = 0; i < _vertexOffsets.size(); ++i) {
        auto vertexIndexOffset = _vertexOffsets[i];
        int nVerts = vertexIndexOffset.second;
        GL::bindVertexArray(m_glVAOs[i]);

        // ELEMENT_ARRAY_BUFFER must be bound after bindVertexArray to be used by VAO
        if (_indexBuffer != 0) {
            rs.indexBufferUnset(_indexBuffer);
            rs.indexBuffer(_indexBuffer);
        }

        // Enable vertex layout on the specified locations
        _layout.enable(locations, vertexOffset * _layout.getStride());

        vertexOffset += nVerts;
    }

    GL::bindVertexArray(0);

    rs.vertexBuffer(0);
    rs.indexBuffer(0);
}
开发者ID:enterstudio,项目名称:tangram-es,代码行数:40,代码来源:vao.cpp

示例6: draw

// Draw the skybox using the skybox shader
void Skybox::draw(ShaderProgram& s){


  GLint posAttrib = s.getAttribLocation( "position" );

  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_CUBE_MAP,tex);
  GLint cube = s.getUniformLocation("cubeMap");
  glUniform1i(cube,0);

  glEnableVertexAttribArray(posAttrib);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glVertexAttribPointer( posAttrib, 3, GL_FLOAT, GL_FALSE, 0, (void*)0 );

  glDrawArrays (GL_TRIANGLES, 0, 36);

  glBindBuffer(GL_ARRAY_BUFFER,0);




}
开发者ID:11Alex11,项目名称:CS488-A5,代码行数:23,代码来源:Skybox.cpp

示例7:

Model::Model(std::string filename, ShaderProgram &s, std::string positionName, std::string normalName, std::string uvName) {
	loadModel(filename, s.getAttribLocation(positionName), s.getAttribLocation(normalName), s.getAttribLocation(uvName));
}
开发者ID:,项目名称:,代码行数:3,代码来源:


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