void Mesh::render() const { m_vao->bind(); unsigned int size=m_entries.size(); for (unsigned int i = 0 ; i < size; ++i) { // whist we have the data stored in our VAO structure we only need to bind to re-activate the // attribute data, then we draw using ElemetsBaseVertex. This is similar to how the // sponza demo works, really if you were dealing with different model textures etc this would // also be switched here for each of the different mesh entries. glDrawElementsBaseVertex(GL_TRIANGLES, m_entries[i].NumIndices, GL_UNSIGNED_INT, (void*)(sizeof(unsigned int) * m_entries[i].BaseIndex), m_entries[i].BaseVertex ); // seems that BaseVertex isn't under linux (not sure why) this works as well but doesn't // cope with embedded meshes so well // glDrawElements(GL_TRIANGLES, // m_entries[i].NumIndices, // GL_UNSIGNED_INT, // (void*)(sizeof(unsigned int) * m_entries[i].BaseIndex) // ); } m_vao->unbind(); }
inline void VL_glDrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, int basevertex) { if (glDrawElementsBaseVertex) glDrawElementsBaseVertex(mode, count, type, (void*)indices, basevertex); else VL_UNSUPPORTED_FUNC(); }
void Mesh::Render() { glBindVertexArray(m_VAO); uint Topology = m_withAdjacencies ? GL_TRIANGLES_ADJACENCY : GL_TRIANGLES; for (uint i = 0 ; i < m_Entries.size() ; i++) { const uint MaterialIndex = m_Entries[i].MaterialIndex; assert(MaterialIndex < m_Textures.size()); if (m_Textures[MaterialIndex]) { m_Textures[MaterialIndex]->Bind(COLOR_TEXTURE_UNIT); } glDrawElementsBaseVertex(Topology, m_Entries[i].NumIndices, GL_UNSIGNED_INT, (void*)(sizeof(uint) * m_Entries[i].BaseIndex), m_Entries[i].BaseVertex); } // Make sure the VAO is not changed from the outside glBindVertexArray(0); }
void MultiDrawIndirect::DrawAsSingleCalls() { unsigned int j; NvModel* pData; unsigned int VertexOffset; unsigned int IndexOffset; VertexOffset = 0; IndexOffset = 0; glBindVertexArray(m_VertexArrayObject); pData = m_Model->getModel(); for (j = 0; j < m_GridSize * m_GridSize; j++) { VertexOffset = (j % MAX_MODEL_INSTANCES) * pData->getCompiledVertexCount(); glUniform2f(m_SceneShader->m_PositionUHandle, m_Offsets[2 * j], m_Offsets[(2 * j) + 1]); glDrawElementsBaseVertex( GL_TRIANGLES, pData->getCompiledIndexCount(NvModelPrimType::TRIANGLES), GL_UNSIGNED_INT, (GLvoid *) (IndexOffset * sizeof(IndexOffset)), VertexOffset); } IndexOffset += pData->getCompiledIndexCount(); glBindVertexArray(0); CHECK_GL_ERROR(); }
//Draw single object, can loop soon //TODO: make drawall //TODO: make seperate from gob void RenderEngine::DrawIndexedObject(GraphicalObject * gob ) { //TODO: set attribs elsewhere RenderInfo * renderInfo = gob->GetRenderInfoPtr(); //TODO: assign offsets elsewhere //static unsigned int colOffset = ColorVertex::GetColorOffset(); //static unsigned int posOffset = ColorVertex::GetPositionOffset(); //static GLint numPosits = 3; //static GLint numCols = 3; //glEnableVertexAttribArray(m_positionAttrib); //glEnableVertexAttribArray(m_colorAttrib); //glBindBuffer(GL_ARRAY_BUFFER, renderInfo->m_vertBufferID); //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, renderInfo->m_indBufferID); //SetAttributes(gob, &(renderInfo->m_vertexFormat), renderInfo->m_stride); //glVertexAttribPointer(m_positionAttrib, numPosits, GL_FLOAT, GL_FALSE, renderInfo->m_stride, (void*)posOffset); // glVertexAttribPointer(m_colorAttrib, numCols, GL_FLOAT, GL_FALSE, renderInfo->m_stride, (void*)colOffset); //----------------------------HANDLE ELSEWHERE--------------------------- //glUniform3fv(15, 1, (GLfloat*)gob->GetTint()); //glUniformMatrix4fv(16, 1, GL_FALSE, &screenMat[0][0]); //----------------------------------------------------------------------- //GLuint * buffData = new GLuint[renderInfo->m_indexSizeBytes]{ 0 }; //GLuint * buffDataPtr = buffData; //glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, renderInfo->m_indexOffsetBytes, renderInfo->m_indexSizeBytes, buffData); //for (int i = 0; i < renderInfo->m_indexSizeBytes; i++) //{ // //printf("Element %d [%u]\n", i, *buffDataPtr); // GameLogger::Log(LogMsgType::Debug, "Element %d: [%u]", i, *buffDataPtr); // ++buffDataPtr; //} //delete[] buffData; //GLfloat * buffData = new GLfloat[renderInfo->m_numVerts * 6]{ 0 }; //GLfloat * buffDataPtr = buffData; //glGetBufferSubData(GL_ARRAY_BUFFER, renderInfo->m_vertOffset*sizeof(GLfloat)*6, renderInfo->m_numVerts * sizeof(GLfloat) * 6, buffData); //for (int i = 0; i < renderInfo->m_numVerts * 6; i++) //{ // //printf("Element %d [%u]\n", i, *buffDataPtr); // GameLogger::Log(LogMsgType::Debug, "Element %d: [%f]", i, *buffDataPtr); // ++buffDataPtr; //} //delete[] buffData; glDrawElementsBaseVertex(renderInfo->m_draw_mode, renderInfo->m_numIndices, GetIndexType(renderInfo->m_isb),(void *)renderInfo->m_indexOffsetBytes,renderInfo->m_vertOffset); }
void VertexArray::render(const Mesh& mesh) const { glDrawElementsBaseVertex( GL_TRIANGLES, mesh.index_count, GL_UNSIGNED_INT, (void*) (mesh.index_start * sizeof(unsigned int)), mesh.vertex_start ); }
void SceneShaderInterface::draw(int baseVertex) { glUseProgram(shaderProgram); glBindVertexArray(vao); //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVbo); glDrawElementsBaseVertex(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, NULL, baseVertex); }
void STKMeshSceneNode::drawGlow(const GLMesh &mesh) { assert(mesh.VAOType == video::EVT_STANDARD); GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; MeshShader::ColorizeShader::getInstance()->setUniforms(AbsoluteTransformation, video::SColorf(glowcolor.getRed() / 255.f, glowcolor.getGreen() / 255.f, glowcolor.getBlue() / 255.f)); glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex); }
void BasicMesh::RenderWithoutBind(void) { for (unsigned int i = 0; i < m_Entries.size(); i++) { glDrawElementsBaseVertex(GL_TRIANGLES, m_Entries[i].NumIndices, GL_UNSIGNED_INT, (void*)(sizeof(unsigned int) * m_Entries[i].BaseIndex), m_Entries[i].BaseVertex); } }
void DrawBloomPass::CombineGaussianBlur() { m_GaussianCombineBuffer.Bind(); m_GaussianCombineProgram->Bind(); glUniform1i(glGetUniformLocation(m_GaussianCombineProgram->GetHandle(), "MaxMipMap"), m_BloomLod); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert); glBindVertexArray(m_ScreenQuad->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); }
inline void drawElementsBaseVertex( DrawElementsBaseVertexMode mode, GLsizei count, DrawElementsBaseVertexType type= DrawElementsBaseVertexType::UNSIGNED_SHORT, GLvoid * indices =0 , GLint basevertex = 0) { glDrawElementsBaseVertex( (GLenum)mode, count, (GLenum)type, indices, basevertex ); }
void Mesh::drawInternal(Int count, Int baseVertex, Int instanceCount, GLintptr indexOffset) #endif { const Implementation::MeshState& state = *Context::current()->state().mesh; /* Nothing to draw */ if(!count || !instanceCount) return; (this->*state.bindImplementation)(); /* Non-instanced mesh */ if(instanceCount == 1) { /* Non-indexed mesh */ if(!_indexBuffer) { glDrawArrays(GLenum(_primitive), baseVertex, count); /* Indexed mesh with base vertex */ } else if(baseVertex) { #ifndef MAGNUM_TARGET_GLES /* Indexed mesh with specified range */ if(indexEnd) { glDrawRangeElementsBaseVertex(GLenum(_primitive), indexStart, indexEnd, count, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset), baseVertex); /* Indexed mesh */ } else glDrawElementsBaseVertex(GLenum(_primitive), count, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset), baseVertex); #else CORRADE_ASSERT(false, "Mesh::draw(): desktop OpenGL is required for base vertex specification in indexed meshes", ); #endif /* Indexed mesh */ } else { /** @todo re-enable for WebGL 2.0 when glDrawRangeElements() no longer crashes Firefox */ #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) /* Indexed mesh with specified range */ if(indexEnd) { glDrawRangeElements(GLenum(_primitive), indexStart, indexEnd, count, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset)); /* Indexed mesh */ } else #endif { glDrawElements(GLenum(_primitive), count, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset)); } } /* Instanced mesh */ } else {
void opengl_render_model_program(model_material* material_info, indexed_vertex_source *vert_source, vertex_buffer* bufferp, buffer_data *datap) { GL_state.Texture.SetShaderMode(GL_TRUE); opengl_tnl_set_model_material(material_info); GLubyte *ibuffer = reinterpret_cast<GLubyte*>(vert_source->Index_offset); GLenum element_type = (datap->flags & VB_FLAG_LARGE_INDEX) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT; Assert(vert_source); Assertion(vert_source->Vbuffer_handle >= 0, "The vertex data must be located in a GPU buffer!"); Assertion(vert_source->Ibuffer_handle >= 0, "The index values must be located in a GPU buffer!"); // basic setup of all data opengl_bind_vertex_layout(bufferp->layout, opengl_buffer_get_id(GL_ARRAY_BUFFER, vert_source->Vbuffer_handle), opengl_buffer_get_id(GL_ELEMENT_ARRAY_BUFFER, vert_source->Ibuffer_handle)); // If GL_ARB_gpu_shader5 is supprted then the instancing is handled by the geometry shader if ( !GLAD_GL_ARB_gpu_shader5 && Rendering_to_shadow_map ) { glDrawElementsInstancedBaseVertex(GL_TRIANGLES, (GLsizei) datap->n_verts, element_type, ibuffer + datap->index_offset, 4, (GLint) (vert_source->Base_vertex_offset + bufferp->vertex_num_offset)); } else { if (Cmdline_drawelements) { glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei) datap->n_verts, element_type, ibuffer + datap->index_offset, (GLint) (vert_source->Base_vertex_offset + bufferp->vertex_num_offset)); } else { glDrawRangeElementsBaseVertex(GL_TRIANGLES, datap->i_first, datap->i_last, (GLsizei) datap->n_verts, element_type, ibuffer + datap->index_offset, (GLint) (vert_source->Base_vertex_offset + bufferp->vertex_num_offset)); } } GL_state.Texture.SetShaderMode(GL_FALSE); }
void drawBubble(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix) { irr_driver->IncreaseObjectCount(); const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f; float transparency = 1.; GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; compressTexture(mesh.textures[0], true); setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); MeshShader::BubbleShader::setUniforms(ModelViewProjectionMatrix, 0, time, transparency); glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex); }
void GLModel::Draw(std::shared_ptr<GLUniform> fragment, GLuint program) { GLint face_offset = 0; GLint vertex_offset = 0; glBindVertexArray(this->vao); bool texture, color; color = (fragment->getId() != UINT_MAX); if(color) { glBindBuffer(GL_UNIFORM_BUFFER, fragment->getId()); } //Draw Model for(size_t i=0; i< this->faces->size(); i++) { texture = this->textures->at(this->mtlIndices.at(i)).first; if(texture) this->textures->at(this->mtlIndices.at(i)).second.Bind(GL_TEXTURE0); if(color) { glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(this->materials->at(this->mtlIndices.at(i)).second), &(this->materials->at(this->mtlIndices.at(i)).second) ); } if( (color && !texture) || (!color && texture) ) { glDrawElementsBaseVertex(GL_TRIANGLES, this->faces->at(i).size(), GL_UNSIGNED_INT, (void*)(sizeof(GLuint) * face_offset), vertex_offset); } face_offset += this->faces->at(i).size(); vertex_offset += this->positions->at(i).size(); } glBindBuffer(GL_UNIFORM_BUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); glBindVertexArray(0); }
void BasicMesh::Render(void) { glBindVertexArray(m_VAO); for (unsigned int i = 0; i < m_Entries.size(); i++) { glDrawElementsBaseVertex(GL_TRIANGLES, m_Entries[i].NumIndices, GL_UNSIGNED_INT, (void*)(sizeof(unsigned int) * m_Entries[i].BaseIndex), m_Entries[i].BaseVertex); } // Make sure the VAO is not changed from the outside glBindVertexArray(0); }
void Mesh::RenderModel() { glBindVertexArray(_VAO); for(unsigned int i=0; i< _entries.size(); i++) { // glDrawElements(GL_TRIANGLES, _entries[i].numIdx, GL_UNSIGNED_INT, 0); glDrawElementsBaseVertex(GL_TRIANGLES, _entries[i].numIdx, GL_UNSIGNED_INT, (void*)(sizeof(unsigned int) * _entries[i].baseIdx), _entries[i].baseVtx); } glBindVertexArray(0); }
void display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(theProgram); glBindVertexArray(vao); glUniform3f(offsetUniform, 0.0f, 0.0f, 0.5f); glDrawElements(GL_TRIANGLES, ARRAY_COUNT(indexData), GL_UNSIGNED_SHORT, 0); glUniform3f(offsetUniform, 0.0f, 0.0f, -1.0f); glDrawElementsBaseVertex(GL_TRIANGLES, ARRAY_COUNT(indexData), GL_UNSIGNED_SHORT, 0, numberOfVertices / 2); glBindVertexArray(0); glUseProgram(0); }
void WavingGrass::OnRender() { glClearColor(1, 1, 1, 1); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glUseProgram(mFinProg); mGrassTex.Bind(GL_TEXTURE0); GLint gSampler = glGetUniformLocation(mFinProg, "gSampler"); glUniform1i(gSampler, mGrassTex.GetTex()); GLint gAngle = glGetUniformLocation(mFinProg, "gAngle"); GLint gHalfWidth = glGetUniformLocation(mFinProg, "gHalfWidth"); GLint gHalfHeight = glGetUniformLocation(mFinProg, "gHalfHeight"); glUniform1f(gAngle, glm::pi<float>()/3); glUniform1f(gHalfWidth, ((float)w)/2); glUniform1f(gHalfHeight, ((float)h)/2); GLint gUp = glGetUniformLocation(mFinProg, "gUp"); GLint gRight = glGetUniformLocation(mFinProg, "gRight"); glUniform3fv(gUp, 1, glm::value_ptr(mUp)); glUniform3fv(gRight, 1, glm::value_ptr(mRight)); GLint gTimeStamp = glGetUniformLocation(mFinProg, "gTimeStamp"); GLint gWindDirection = glGetUniformLocation(mFinProg, "gWindDirection"); GLint gWindStrength = glGetUniformLocation(mFinProg, "gWindStrength"); glUniform3fv(gWindDirection, 1, glm::value_ptr(glm::vec3(1, 1, -1))); glUniform1f(gWindStrength, 1); glUniform1f(gTimeStamp, glfwGetTime()); GLint gWorldMat = glGetUniformLocation(mFinProg, "gWorldMat"); GLint gViewMat = glGetUniformLocation(mFinProg, "gViewMat"); GLint gProjMat = glGetUniformLocation(mFinProg, "gProjMat"); glUniformMatrix4fv(gWorldMat, 1, GL_FALSE, glm::value_ptr(glm::mat4(1))); glUniformMatrix4fv(gViewMat, 1, GL_FALSE, glm::value_ptr(gCamera.GetViewMat())); glUniformMatrix4fv(gProjMat, 1, GL_FALSE, glm::value_ptr(gPipeline.GetProjMat())); glBindVertexArray(mVAO); for (int i = 0; i < n; ++i) { glDrawElementsBaseVertex(GL_POINTS, m, GL_UNSIGNED_SHORT, (GLvoid*)(m*i*sizeof(GLushort)), m*i); } glBindVertexArray(0); glUseProgram(0); }
void renderText( const char *text, float scale, glm::vec2 pos, const glm::vec4 &color, TextRenderer::Alignment align) { glBindVertexArray(m_vao); glUseProgram(m_program_id); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_texture_id); glUniform1i(m_texture_uniform, 0); glUniform4fv(m_color_uniform, 1, &color[0]); glUniform1f(m_scale_uniform, scale); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if(align == TextRenderer::RIGHT) { float xoff = 0; const char *s = text; while(*s) { const CharDescription &chr = m_charmap[*s]; xoff += chr.width; ++s; } pos.x -= xoff * scale; } const char *s = text; while(*s) { const CharDescription &chr = m_charmap[*s]; glUniform2fv(m_offset_uniform, 1, &pos[0]); glDrawElementsBaseVertex(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, 0, chr.index); pos.x += chr.width * scale; ++s; } glDisable(GL_BLEND); }
/** * Draw a mesh. * * Returns nonzero if the mesh was drawn, 0 if this mesh has no buffers to draw * from. **/ int mesh_draw(mesh_t *mesh) { if (! mesh->vbuf) return 0; if (! mesh->ebuf) return 0; vbuf_activate(mesh->vbuf); ebuf_activate(mesh->ebuf); texmap_end_unit_generation(); glDrawElementsBaseVertex(mesh->type, mesh->elems, GL_UNSIGNED_SHORT, (void *)(mesh->ebuf_pos * sizeof(uint16_t)), mesh->vbuf_pos); return 1; }
void Geometry::draw(Primitive primitive, unsigned int offset, unsigned int count, unsigned int baseVertexIndex) { glBindVertexArray(id); if (indexBuffer) { assert(indexBuffer->getElementSize() == 2 || indexBuffer->getElementSize() == 4); GLenum indexType = (indexBuffer->getElementSize() == 2) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT; glDrawElementsBaseVertex(kGeometryPrimitive[primitive], count, indexType, reinterpret_cast<const void*>(offset * indexBuffer->getElementSize()), baseVertexIndex); } else { assert(baseVertexIndex == 0); glDrawArrays(kGeometryPrimitive[primitive], offset, count); } glBindVertexArray(0); }
void Triangle::Render() { //Bind the vao, which manage status we when to render glUseProgram(program); glBindVertexArray(vao); static glm::mat4 model = glm::mat4(1.0f); static glm::mat4 view = glm::lookAt(glm::vec3(0.0, 0.0, 5.0), glm::vec3(0.0, 0.0, -4.0), glm::vec3(0.0, 1.0, 0.0)); static glm::mat4 proj = glm::perspective(45.0f, 1.0f, 1.0f, 1000.0f); static glm::mat4 projView = proj * view; static glm::mat4 mvp = glm::mat4(1.0f); ////////////////Update the model matrix when draw the every triangle/////////////// // DrawArrays model = glm::translate(glm::mat4(1.0f), glm::vec3(-3.0, 0.0, -5.0)); mvp = projView * model; glUniformMatrix4fv(mvp_loc, 1, GL_FALSE, glm::value_ptr(mvp)); glDrawArrays(GL_TRIANGLES, 0, 3); // DrawElements model = glm::translate(glm::mat4(1.0f), glm::vec3(-1.0, 0.0, -5.0)); mvp = projView * model; glUniformMatrix4fv(mvp_loc, 1, GL_FALSE, glm::value_ptr(mvp)); glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, NULL); // DrawElementsBaseVertex model = glm::translate(glm::mat4(1.0f), glm::vec3(1.0, 0.0, -5.0)); mvp = projView * model; glUniformMatrix4fv(mvp_loc, 1, GL_FALSE, glm::value_ptr(mvp)); glDrawElementsBaseVertex(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, NULL, 0); //the indices[i] + base vertex(the last element) //DrawArraysInstanced model = glm::translate(glm::mat4(1.0f), glm::vec3(3.0, 0.0, -5.0)); mvp = projView * model; glUniformMatrix4fv(mvp_loc, 1, GL_FALSE, glm::value_ptr(mvp)); glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1); glBindVertexArray(0); glUseProgram(0); }
void GFXGLDevice::drawIndexedPrimitive( GFXPrimitiveType primType, U32 startVertex, U32 minIndex, U32 numVerts, U32 startIndex, U32 primitiveCount ) { preDrawPrimitive(); U16* buf = (U16*)static_cast<GFXGLPrimitiveBuffer*>(mCurrentPrimitiveBuffer.getPointer())->getBuffer() + startIndex + mCurrentPrimitiveBuffer->mVolatileStart; const U32 baseVertex = mCurrentVB[0]->mBufferVertexOffset + startVertex; if(mDrawInstancesCount) glDrawElementsInstancedBaseVertex(GFXGLPrimType[primType], primCountToIndexCount(primType, primitiveCount), GL_UNSIGNED_SHORT, buf, mDrawInstancesCount, baseVertex); else glDrawElementsBaseVertex(GFXGLPrimType[primType], primCountToIndexCount(primType, primitiveCount), GL_UNSIGNED_SHORT, buf, baseVertex); postDrawPrimitive(primitiveCount); }
void opengl_render_model_program(model_material* material_info, indexed_vertex_source *vert_source, vertex_buffer* bufferp, buffer_data *datap) { GL_state.Texture.SetShaderMode(GL_TRUE); opengl_tnl_set_model_material(material_info); GLubyte *ibuffer = NULL; size_t start = 0; size_t end = (datap->n_verts - 1); size_t count = (end - (start * 3) + 1); GLenum element_type = (datap->flags & VB_FLAG_LARGE_INDEX) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT; Assert(vert_source); // basic setup of all data opengl_init_arrays(vert_source, bufferp); if ( vert_source->Ibuffer_handle >= 0 ) { opengl_bind_buffer_object(vert_source->Ibuffer_handle); } else { ibuffer = (GLubyte*)vert_source->Index_list; } if ( Rendering_to_shadow_map ) { glDrawElementsInstancedBaseVertex(GL_TRIANGLES, (GLsizei) count, element_type, ibuffer + (datap->index_offset + start), 4, (GLint)bufferp->vertex_num_offset); } else { if ( Cmdline_drawelements ) { glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei) count, element_type, ibuffer + (datap->index_offset + start), (GLint)bufferp->vertex_num_offset); } else { glDrawRangeElementsBaseVertex(GL_TRIANGLES, datap->i_first, datap->i_last, (GLsizei) count, element_type, ibuffer + (datap->index_offset + start), (GLint)bufferp->vertex_num_offset); } } GL_state.Texture.SetShaderMode(GL_FALSE); }
enum piglit_result piglit_display(void) { GLboolean pass = GL_TRUE; GLuint indices[] = { 1, 2, 0, 3, 0, 1 }; static GLfloat test_colors[][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 1, 1, 1 }, }; glViewport(0, 0, piglit_width, piglit_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1, 1, -1, 1, -0.5, 1000); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0.3, 0.3, 0.3, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_VERTEX_PROGRAM_ARB); /* draw elements 3,4,5 ->verts 3,0,1 (lower-right tri) */ glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices + 3); /* draw elements 0,1,2 ->verts (1+1),(2+1),(0+1) (upper-left tri) */ glDrawElementsBaseVertex(GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices, 1); glFlush(); pass = piglit_probe_pixel_rgb(0, 0, test_colors[0]) && pass; pass = piglit_probe_pixel_rgb(piglit_width - 1, 0, test_colors[1]) && pass; pass = piglit_probe_pixel_rgb(piglit_width - 1, piglit_height - 1, test_colors[2]) && pass; pass = piglit_probe_pixel_rgb(0, piglit_height - 1, test_colors[3]) && pass; piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
void BasicMesh::Render() { glBindVertexArray(m_VAO); for (unsigned int i = 0 ; i < m_Entries.size() ; i++) { const unsigned int MaterialIndex = m_Entries[i].MaterialIndex; assert(MaterialIndex < m_Textures.size()); if (m_Textures[MaterialIndex]) { m_Textures[MaterialIndex]->Bind(COLOR_TEXTURE_UNIT); } glDrawElementsBaseVertex(GL_TRIANGLES, m_Entries[i].NumIndices, GL_UNSIGNED_INT, (void*)(sizeof(unsigned int) * m_Entries[i].BaseIndex), m_Entries[i].BaseVertex); } // Make sure the VAO is not changed from the outside glBindVertexArray(0); }
void Mesh::Draw() { glBindVertexArrayAPPLE(m_vertexArrayObject); //glDrawElements(GL_TRIANGLES, m_numIndices, GL_UNSIGNED_INT, 0); glDrawElementsBaseVertex(GL_TRIANGLES, m_numIndices, GL_UNSIGNED_INT, 0, 0); glBindVertexArrayAPPLE(0); }
void Mesh::Draw() { // bind vao glBindVertexArray(vertexArrayObject); { //glDrawElements(GL_TRIANGLES, m_numIndices, GL_UNSIGNED_INT, 0); // draw triangles in mesh glDrawElementsBaseVertex(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0, 0); } glBindVertexArray(NULL); }
void Mesh::RenderMesh() { glBindVertexArray(_VAO); // glDrawElements(GL_TRIANGLES, _entries[i].numIdx, GL_UNSIGNED_INT, 0); glDrawElementsBaseVertex(GL_TRIANGLES, mNumIdx, GL_UNSIGNED_INT, (void*) 0, 0); glBindVertexArray(0); }