void VboMesh::draw(Shader& _shader) { if (!m_isUploaded) { upload(); } else if (m_dirty) { subDataUpload(); } // if VAO not yet created, initialized it and capture related states if (!m_vao) { m_vao = std::unique_ptr<Vao>(new Vao()); const auto& locations = m_vertexLayout->getLocations(); m_vao->init(m_glVertexBuffer, m_glIndexBuffer, *m_vertexLayout, locations); } _shader.bindVertexLayout(*m_vertexLayout); _shader.use(); m_vao->bind(); if (m_nIndices > 0) { GL_CHECK(glDrawElements(m_drawMode, m_nIndices, GL_UNSIGNED_INT, NULL)); } else if (m_nVertices > 0) { GL_CHECK(glDrawArrays(m_drawMode, 0, m_nVertices)); } m_vao->unbind(); }
void LabelMesh::draw(ShaderProgram& _shader) { checkValidity(); if (!m_isCompiled) { return; } if (m_nVertices == 0) { return; } bool bound = false; // Ensure that geometry is buffered into GPU if (!m_isUploaded) { bound = upload(); } else if (m_dirty) { bound = subDataUpload(); } if (!bound) { // Bind buffers for drawing glBindBuffer(GL_ARRAY_BUFFER, m_glVertexBuffer); } loadQuadIndices(); // Enable shader program _shader.use(); size_t vertexOffset = 0; for (auto& o : m_vertexOffsets) { uint32_t nIndices = o.first; uint32_t nVertices = o.second; size_t byteOffset = vertexOffset * m_vertexLayout->getStride(); // Enable vertex attribs via vertex layout object m_vertexLayout->enable(_shader, byteOffset); glDrawElements(m_drawMode, nIndices, GL_UNSIGNED_SHORT, 0); vertexOffset += nVertices; } }
void LabelMesh::draw(ShaderProgram& _shader) { bool valid = checkValidity(); if (!m_isCompiled) { return; } if (m_nVertices == 0) { return; } // Ensure that geometry is buffered into GPU if (!m_isUploaded) { upload(); } else if (m_dirty) { subDataUpload(); } if (!valid) { loadQuadIndices(); } // Bind buffers for drawing RenderState::vertexBuffer(m_glVertexBuffer); RenderState::indexBuffer(s_quadIndexBuffer); // Enable shader program _shader.use(); size_t vertexOffset = 0; for (size_t i = 0; i < m_vertexOffsets.size(); ++i) { auto& o = m_vertexOffsets[i]; uint32_t nIndices = o.first; uint32_t nVertices = o.second; size_t byteOffset = vertexOffset * m_vertexLayout->getStride(); m_vertexLayout->enable(_shader, byteOffset); glDrawElements(m_drawMode, nIndices, GL_UNSIGNED_SHORT, 0); vertexOffset += nVertices; } }
void VboMesh::draw(ShaderProgram& _shader) { checkValidity(); if (!m_isCompiled) { return; } if (m_nVertices == 0) { return; } // Enable shader program if (!_shader.use()) { return; } // Ensure that geometry is buffered into GPU if (!m_isUploaded) { upload(); } else if (m_dirty) { subDataUpload(); } if (GLExtensions::supportsVAOs) { if (!m_vaos) { m_vaos = std::make_unique<Vao>(); // Capture vao state m_vaos->init(_shader, m_vertexOffsets, *m_vertexLayout, m_glVertexBuffer, m_glIndexBuffer); } } else { // Bind buffers for drawing RenderState::vertexBuffer(m_glVertexBuffer); if (m_nIndices > 0) { RenderState::indexBuffer(m_glIndexBuffer); } } size_t indiceOffset = 0; size_t vertexOffset = 0; for (size_t i = 0; i < m_vertexOffsets.size(); ++i) { auto& o = m_vertexOffsets[i]; uint32_t nIndices = o.first; uint32_t nVertices = o.second; if (!GLExtensions::supportsVAOs) { // Enable vertex attribs via vertex layout object size_t byteOffset = vertexOffset * m_vertexLayout->getStride(); m_vertexLayout->enable(_shader, byteOffset); } else { // Bind the corresponding vao relative to the current offset m_vaos->bind(i); } // Draw as elements or arrays if (nIndices > 0) { glDrawElements(m_drawMode, nIndices, GL_UNSIGNED_SHORT, (void*)(indiceOffset * sizeof(GLushort))); } else if (nVertices > 0) { glDrawArrays(m_drawMode, 0, nVertices); } vertexOffset += nVertices; indiceOffset += nIndices; } if (GLExtensions::supportsVAOs) { m_vaos->unbind(); } }