void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const { llassert(mRequestedNumVerts >= 0); if (start >= (U32) mRequestedNumVerts || end >= (U32) mRequestedNumVerts) { llerrs << "Bad vertex buffer draw range: [" << start << ", " << end << "]" << llendl; } llassert(mRequestedNumIndices >= 0); if (indices_offset >= (U32) mRequestedNumIndices || indices_offset + count > (U32) mRequestedNumIndices) { llerrs << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << llendl; } if (mGLIndices != sGLRenderIndices) { llerrs << "Wrong index buffer bound." << llendl; } if (mGLBuffer != sGLRenderBuffer) { llerrs << "Wrong vertex buffer bound." << llendl; } if (mode >= LLRender::NUM_MODES) { llerrs << "Invalid draw mode: " << mode << llendl; return; } stop_glerror(); glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, ((U16*) getIndicesPointer()) + indices_offset); stop_glerror(); }
void LLVOWLSky::drawDome(void) { if (mStripsVerts.empty()) { updateGeometry(mDrawable); } LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); const U32 data_mask = LLDrawPoolWLSky::SKY_VERTEX_DATA_MASK; #if DOME_SLICES std::vector< LLPointer<LLVertexBuffer> >::const_iterator strips_vbo_iter, end_strips; end_strips = mStripsVerts.end(); for(strips_vbo_iter = mStripsVerts.begin(); strips_vbo_iter != end_strips; ++strips_vbo_iter) { LLVertexBuffer * strips_segment = strips_vbo_iter->get(); strips_segment->setBuffer(data_mask); strips_segment->drawRange( LLRender::TRIANGLE_STRIP, 0, strips_segment->getNumVerts()-1, strips_segment->getNumIndices(), 0); gPipeline.addTrianglesDrawn(strips_segment->getNumIndices(), LLRender::TRIANGLE_STRIP); } #else mStripsVerts->setBuffer(data_mask); gGL.syncMatrices(); glDrawRangeElements( GL_TRIANGLES, 0, mStripsVerts->getNumVerts()-1, mStripsVerts->getNumIndices(), GL_UNSIGNED_SHORT, mStripsVerts->getIndicesPointer()); #endif LLVertexBuffer::unbind(); }
void VertexManager::Draw(u32 stride) { u32 index_size = IndexGenerator::GetIndexLen(); u32 max_index = IndexGenerator::GetNumVerts(); GLenum primitive_mode = 0; switch (m_current_primitive_type) { case PRIMITIVE_POINTS: primitive_mode = GL_POINTS; glDisable(GL_CULL_FACE); break; case PRIMITIVE_LINES: primitive_mode = GL_LINES; glDisable(GL_CULL_FACE); break; case PRIMITIVE_TRIANGLES: primitive_mode = g_ActiveConfig.backend_info.bSupportsPrimitiveRestart ? GL_TRIANGLE_STRIP : GL_TRIANGLES; break; } if (g_ogl_config.bSupportsGLBaseVertex) { glDrawRangeElementsBaseVertex(primitive_mode, 0, max_index, index_size, GL_UNSIGNED_SHORT, (u8*)nullptr + s_index_offset, (GLint)s_baseVertex); } else { glDrawRangeElements(primitive_mode, 0, max_index, index_size, GL_UNSIGNED_SHORT, (u8*)nullptr + s_index_offset); } INCSTAT(stats.thisFrame.numDrawCalls); if (m_current_primitive_type != PRIMITIVE_TRIANGLES) static_cast<Renderer*>(g_renderer.get())->SetGenerationMode(); }
void RangedAppendOnlyIndexBuffer::RenderRange(const IndexRange& range) const { ATLASSERT(OpenGL::IsRenderThread()); // must be called in render thread ATLASSERT(m_spIndexBuffer != NULL); if (glDrawRangeElements == NULL) { const_cast<RangedAppendOnlyIndexBuffer&>(*this).glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSWINPROC)wglGetProcAddress("glDrawRangeElements"); } ATLASSERT(glDrawRangeElements != NULL); glDrawRangeElements(GL_TRIANGLES, range.m_uiFirstIndex, range.m_uiLastIndex, range.m_uiSize, GL_UNSIGNED_INT, reinterpret_cast<const GLvoid*>(range.m_uiStart*sizeof(unsigned int)) ); glTraceError("glDrawRangeElements"); }
void VisSurface::draw(){ if (!sharedInfo->valid){ build(); } else { glBindBuffer(GL_ARRAY_BUFFER, sharedInfo->vtx_buf_id); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, sharedInfo->idx_buf_id); } glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, 0); glColor3d(1,1,1); Vec2i dicing = sharedInfo->dicing; for (int strip = 0; strip < dicing.y - 1; strip++){ GLuint offs = dicing.x * strip * 2 * sizeof(int); glDrawRangeElements(GL_TRIANGLE_STRIP, dicing.x * strip, (dicing.x + 2) * strip, dicing.x * 2, GL_UNSIGNED_INT, (char*)NULL + offs); } //clean up glDisableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }
//-------------------------------------------------------------------------------------------------- /// Render primitives in this primitive set using vertex arrays /// /// \warning Requires at least OpenGL 1.5 //-------------------------------------------------------------------------------------------------- void PrimitiveSetIndexedUInt::render(OpenGLContext* oglContext) const { CVF_CALLSITE_OPENGL(oglContext); CVF_TIGHT_ASSERT(oglContext); CVF_TIGHT_ASSERT(BufferObjectManaged::supportedOpenGL(oglContext)); if (m_indices.isNull()) { return; } GLsizei numIndices = static_cast<GLsizei>(m_indices->size()); if (numIndices <= 0) { return; } const GLvoid* ptrOrOffset = 0; if (m_indicesBO.notNull() && m_indicesBO->isUploaded()) { m_indicesBO->bindBuffer(oglContext); } else { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); ptrOrOffset = m_indices->ptr(); } #ifdef CVF_OPENGL_ES glDrawElements(primitiveTypeOpenGL(), numIndices, GL_UNSIGNED_INT, ptrOrOffset); #else glDrawRangeElements(primitiveTypeOpenGL(), m_minIndex, m_maxIndex, numIndices, GL_UNSIGNED_INT, ptrOrOffset); #endif CVF_CHECK_OGL(oglContext); }
void Mesh::drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount) #endif { /* Nothing to draw */ if(!vertexCount && !indexCount) return; (this->*bindImplementation)(); /* Non-indexed mesh */ if(!indexCount) glDrawArrays(GLenum(_primitive), firstVertex, vertexCount); #ifndef MAGNUM_TARGET_GLES2 /* Indexed mesh with specified range */ else if(indexEnd) glDrawRangeElements(GLenum(_primitive), indexStart, indexEnd, indexCount, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset)); #endif /* Indexed mesh without specified range */ else glDrawElements(GLenum(_primitive), indexCount, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset)); (this->*unbindImplementation)(); }
void CMeshP3NT2::Draw(IRenderer3D &renderer) const { // Выполняем привязку vertex array, normal array, tex coord 2d array const size_t stride = sizeof(SVertexP3NT2); const size_t positionOffset = size_t(offsetof(SVertexP3NT2, position)); const size_t normalOffset = size_t(offsetof(SVertexP3NT2, normal)); const size_t texCoordOffset = size_t(offsetof(SVertexP3NT2, texCoord)); m_attributesBuffer.Bind(); m_indexesBuffer.Bind(); renderer.SetPosition3DOffset(positionOffset, stride); renderer.SetNormalOffset(normalOffset, stride); renderer.SetTexCoord2DOffset(texCoordOffset, stride); const GLenum primitive = GetPrimitiveType(m_meshType); const GLvoid *indexOffset = reinterpret_cast<const GLvoid *>(0); const GLuint minIndex = 0; const GLuint maxIndex = GLuint(m_verticiesCount); const GLsizei size = GLsizei(m_indiciesCount); glDrawRangeElements(primitive, minIndex, maxIndex, size, GL_UNSIGNED_INT, indexOffset); }
void OpenGLRenderer::drawIndexed(Primitive primitive, const TexturedVertex * vertices, size_t nvertices, unsigned short * indices, size_t nindices) { beforeDraw<TexturedVertex>(); if(useVertexArrays && shader) { bindBuffer(GL_NONE); setVertexArray(vertices, vertices); glDrawRangeElements(arxToGlPrimitiveType[primitive], 0, nvertices - 1, nindices, GL_UNSIGNED_SHORT, indices); } else { glBegin(arxToGlPrimitiveType[primitive]); for(size_t i = 0; i < nindices; i++) { renderVertex(vertices[indices[i]]); } glEnd(); } }
void go_glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices) { glDrawRangeElements(mode, start, end, count, type, indices); }
void MeshGeometry::render(const Camera& camera) { if (m_indices.empty() || m_vertices.empty()) return; // Prepare the VBOs, IBOs and shader program if necessary. update(); if (!d->program.bind()) cout << d->program.error() << endl; d->vbo.bind(); d->ibo.bind(); // Set up our attribute arrays. if (!d->program.enableAttributeArray("vertex")) cout << d->program.error() << endl; if (!d->program.useAttributeArray("vertex", PackedVertex::vertexOffset(), sizeof(PackedVertex), FloatType, 3, ShaderProgram::NoNormalize)) { cout << d->program.error() << endl; } if (!d->program.enableAttributeArray("color")) cout << d->program.error() << endl; if (!d->program.useAttributeArray("color", PackedVertex::colorOffset(), sizeof(PackedVertex), UCharType, 4, ShaderProgram::Normalize)) { cout << d->program.error() << endl; } if (!d->program.enableAttributeArray("normal")) cout << d->program.error() << endl; if (!d->program.useAttributeArray("normal", PackedVertex::normalOffset(), sizeof(PackedVertex), FloatType, 3, ShaderProgram::NoNormalize)) { cout << d->program.error() << endl; } // Set up our uniforms (model-view and projection matrices right now). if (!d->program.setUniformValue("modelView", camera.modelView().matrix())) { cout << d->program.error() << endl; } if (!d->program.setUniformValue("projection", camera.projection().matrix())) { cout << d->program.error() << endl; } Matrix3f normalMatrix = camera.modelView().linear().inverse().transpose(); if (!d->program.setUniformValue("normalMatrix", normalMatrix)) std::cout << d->program.error() << std::endl; // Render the loaded spheres using the shader and bound VBO. glDrawRangeElements(GL_TRIANGLES, 0, static_cast<GLuint>(d->numberOfVertices - 1), static_cast<GLsizei>(d->numberOfIndices), GL_UNSIGNED_INT, reinterpret_cast<const GLvoid*>(0)); d->vbo.release(); d->ibo.release(); d->program.disableAttributeArray("vector"); d->program.disableAttributeArray("color"); d->program.disableAttributeArray("normal"); d->program.release(); }
int main(int argc, char *argv[]) { SDL_Surface *screen; if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); return 1; } SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); screen = SDL_SetVideoMode( 640, 480, 24, SDL_OPENGL ); if ( !screen ) { printf("Unable to set video mode: %s\n", SDL_GetError()); return 1; } glClearColor( 0, 0, 0, 0 ); glClear( GL_COLOR_BUFFER_BIT ); // Create a texture GLuint texture; glGenTextures( 1, &texture ); glBindTexture( GL_TEXTURE_2D, texture ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); GLubyte textureData[16*16*4]; for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { *((int*)&textureData[(x*16 + y) * 4]) = x*16 + ((y*16) << 8); } } glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData ); // Create a second texture GLuint texture2; glGenTextures( 1, &texture2 ); glBindTexture( GL_TEXTURE_2D, texture2 ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); GLubyte texture2Data[] = { 0xff, 0, 0, 0xff, 0, 0xff, 0, 0xaa, 0, 0, 0xff, 0x55, 0x80, 0x90, 0x70, 0 }; glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture2Data ); // BEGIN #if USE_GLEW glewInit(); #endif glMatrixMode(GL_PROJECTION); glLoadIdentity(); // original: glFrustum(-0.6435469817188064, 0.6435469817188064 ,-0.48266022190470925, 0.48266022190470925 ,0.5400000214576721, 2048); glFrustum(-0.6435469817188064, 0.1435469817188064 ,-0.48266022190470925, 0.88266022190470925 ,0.5400000214576721, 2048); glRotatef(-30, 1, 1, 1); //GLfloat pm[] = { 1.372136116027832, 0, 0, 0, 0, 0.7910231351852417, 0, 0, -0.6352481842041016, 0.29297152161598206, -1.0005275011062622, -1, 0, 0, -1.080284833908081, 0 }; //glLoadMatrixf(pm); glMatrixMode(GL_MODELVIEW); GLfloat matrixData[] = { -1, 0, 0, 0, 0, 0,-1, 0, 0, 1, 0, 0, 0, 0, 0, 1 }; glLoadMatrixf(matrixData); //glTranslated(-512,-512,-527); // XXX this should be uncommented, but if it is then nothing is shown glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glClear(GL_DEPTH_BUFFER_BIT); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glActiveTexture(GL_TEXTURE0); glEnableClientState(GL_VERTEX_ARRAY); GLubyte arrayData[] = { /* [0, 0, 0, 67] ==> 128 float [0, 0, 128, 67] ==> 256 float [0, 0, 0, 68] ==> 512 float [0, 0, 128, 68] ==> 1024 float [vertex x ] [vertex y ] [vertex z ] [nr] [texture u ] [texture v ] [lm u ] [lm v ] [color r,g,b,a ] */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, // ignorable ones 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 68, 11, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, // 0 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 68, 23, 20, 0, 0, 0, 0, 0, 67, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, // 1 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 35, 30, 0, 0, 0, 0, 0, 67, 0, 0, 0, 67, 0, 0, 0, 0, 128, 128, 128, 128, // 2 0, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 68, 47, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67, 0, 0, 0, 0, 128, 128, 128, 128, // 3 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 68, 51, 50, 0, 0, 0, 0, 0, 67, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, // 4 0, 0, 128, 68, 0, 0, 0, 0, 0, 0, 0, 68, 64, 60, 0, 0, 0, 0, 128, 67, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, // 5 0, 0, 128, 68, 0, 0, 0, 68, 0, 0, 0, 68, 70, 70, 0, 0, 0, 0, 128, 67, 0, 0, 0, 67, 0, 0, 0, 0, 128, 128, 128, 128, // 6 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 89, 80, 0, 0, 0, 0, 0, 67, 0, 0, 0, 67, 0, 0, 0, 0, 128, 128, 128, 128, // 7 0, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 68, 94, 90, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67, 0, 0, 0, 0, 128, 128, 128, 128, // 8 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 20, 10, 0, 0, 0, 0, 0, 67, 0, 0, 0, 67, 0, 0, 0, 0, 128, 128, 128, 128, // 9 0, 0, 0, 68, 0, 0, 128, 68, 0, 0, 0, 68, 31, 20, 0, 0, 0, 0, 0, 67, 0, 0, 128, 67, 0, 0, 0, 0, 128, 128, 128, 128, // 10 0, 0, 0, 0, 0, 0, 128, 68, 0, 0, 0, 68, 42, 30, 0, 0, 0, 0, 0, 0, 0, 0, 128, 67, 0, 0, 0, 0, 128, 128, 128, 128, // 11 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 53, 40, 0, 0, 0, 0, 0, 67, 0, 0, 0, 67, 0, 0, 0, 0, 128, 128, 128, 128, // 12 0, 0, 128, 68, 0, 0, 0, 68, 0, 0, 0, 68, 64, 50, 0, 0, 0, 0, 128, 67, 0, 0, 0, 67, 0, 0, 0, 0, 128, 128, 128, 128, // 13 0, 0, 128, 68, 0, 0, 128, 68, 0, 0, 0, 68, 75, 60, 0, 0, 0, 0, 128, 67, 0, 0, 128, 67, 0, 0, 0, 0, 128, 128, 128, 128, // 14 0, 0, 0, 68, 0, 0, 128, 68, 0, 0, 0, 68, 86, 70, 0, 0, 0, 0, 0, 67, 0, 0, 128, 67, 0, 0, 0, 0, 128, 128, 128, 128, // 15 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 128, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 128, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 68, 0, 0, 128, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 128, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 128, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 128, 68, 0, 0, 0, 68, 0, 0, 128, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 128, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 128, 68, 0, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 68, 0, 0, 128, 68, 0, 0, 128, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 128, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, }; GLushort elementData[] = { 1, 2, 0, 2, 3, 0, 5, 6, 4, 6, 7, 4, 9, 10, 8, 10, 11, 8, 13, 14, 12, 14, 15, 12 }; assert(sizeof(elementData) == 48); for (int i = 0; i < 24; i++) { elementData[i] += 16; } // sauer vertex data is apparently 0-12: V3F, 12: N1B, 16-24: T2F, 24-28: T2S, 28-32: C4B glVertexPointer(3, GL_FLOAT, 32, (void*)&arrayData[0]); glTexCoordPointer(2, GL_FLOAT, 32, (void*)&arrayData[16]); glClientActiveTexture(GL_TEXTURE1); // XXX seems to be ignored in native build glTexCoordPointer(2, GL_SHORT, 32, (void*)&arrayData[24]); glClientActiveTexture(GL_TEXTURE0); // likely not needed, it is a cleanup glNormalPointer(GL_BYTE, 32, (void*)&arrayData[12]); glColorPointer(4, GL_UNSIGNED_BYTE, 32, (void*)&arrayData[28]); glBindTexture(GL_TEXTURE_2D, texture); // diffuse? glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture2); // lightmap? glActiveTexture(GL_TEXTURE0); GLint ok; const char *vertexShader = "uniform vec4 texgenscroll;\n" "void main(void)\n" "{\n" " gl_Position = ftransform();\n" " gl_TexCoord[0].xy = gl_MultiTexCoord0.xy/10000.0 + (0.001*texgenscroll.xy) + gl_Normal.xy;\n" // added /100 here " gl_TexCoord[1].xy = gl_MultiTexCoord1.xy/100.0 * 3.051851e-05;\n" "}\n"; const char *fragmentShader = "uniform vec4 colorparams;\n" "uniform sampler2D diffusemap, lightmap;\n" "void main(void)\n" "{\n" " vec4 diffuse = texture2D(diffusemap, gl_TexCoord[0].xy);\n" " vec4 lm = texture2D(lightmap, gl_TexCoord[1].xy);\n" " diffuse *= colorparams;\n" " gl_FragColor = diffuse * lm;\n" "}\n"; GLuint vs = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vs, 1, &vertexShader, NULL); glCompileShader(vs); glGetShaderiv(vs, GL_COMPILE_STATUS, &ok); assert(ok); GLuint fs = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fs, 1, &fragmentShader, NULL); glCompileShader(fs); glGetShaderiv(fs, GL_COMPILE_STATUS, &ok); assert(ok); GLuint program = glCreateProgram(); glAttachShader(program, vs); glAttachShader(program, fs); glLinkProgram(program); glGetProgramiv(program, GL_LINK_STATUS, &ok); assert(ok); glUseProgram(program); GLint lightmapLocation = glGetUniformLocation(program, "lightmap"); assert(lightmapLocation >= 0); glUniform1i(lightmapLocation, 1); // sampler2D? Is it the texture unit? GLint diffusemapLocation = glGetUniformLocation(program, "diffusemap"); assert(diffusemapLocation >= 0); glUniform1i(diffusemapLocation, 0); GLint texgenscrollLocation = glGetUniformLocation(program, "texgenscroll"); assert(texgenscrollLocation >= 0); GLint colorparamsLocation = glGetUniformLocation(program, "colorparams"); assert(colorparamsLocation >= 0); GLfloat texgenscrollData[] = { 0, 0, 0, 0 }; glUniform4fv(texgenscrollLocation, 1, texgenscrollData); GLfloat colorparamsData[] = { 2, 2, 2, 1 }; glUniform4fv(colorparamsLocation, 1, colorparamsData); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (void*)&elementData[12/sizeof(GLushort)]); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (void*)&elementData[ 0/sizeof(GLushort)]); glDrawRangeElements(GL_TRIANGLES, 8+16, 11+16, 6, GL_UNSIGNED_SHORT, (void*)&elementData[24/sizeof(GLushort)]); glDrawRangeElements(GL_TRIANGLES, 12+16, 15+16, 6, GL_UNSIGNED_SHORT, (void*)&elementData[36/sizeof(GLushort)]); // END SDL_GL_SwapBuffers(); #ifndef __EMSCRIPTEN__ SDL_Delay(1500); #endif SDL_Quit(); return 0; }
void SceneDrawer::DrawDepthMapTextureWithShaders() { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); XnUInt16 g_nXRes; XnUInt16 g_nYRes; m_pUserTrackerObj->GetImageRes(g_nXRes,g_nYRes); if (g_bDrawPixels) { m_pUserTrackerObj->FillTexture(pDepthTexBuf,texWidth,texHeight,g_bDrawBackground); //cout << "FILLING TEXTURE" << endl; } else { xnOSMemSet(pDepthTexBuf, 0, 3*2*g_nXRes*g_nYRes); // makes the texture empty. } // makes sure we draw the relevant texture glBindTexture(GL_TEXTURE_2D, depthTexID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texWidth, texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, pDepthTexBuf); glBindTexture( GL_TEXTURE_2D, 0 ); // Designate the desired shader program glUseProgram( g_programHandle_Background ); // Set the uniforms glBindTexture(GL_TEXTURE_2D, depthTexID); glUniform1i( g_textureLocation_Background, 0); // DEBUG Determine the number of active attributes //char *name; //GLint active_attribs; //glGetProgramiv(g_programHandle_Background, GL_ACTIVE_ATTRIBUTES, &active_attribs); //glGetProgramiv(g_programHandle_Background, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength ); //std::cout << active_attribs << std::endl; // Bind the buffers to the program glBindVertexArray( g_vao[0] ); // **************************************** // Draw the geometry glDrawRangeElements( GL_TRIANGLE_STRIP, // Type of Geometry 0, // Start index g_numberIndices_Background, // End index g_numberIndices_Background, // Count of indices GL_UNSIGNED_INT, // Type of index NULL // Pointer to the indices ); glFlush(); // Cleanup the shader code glBindTexture( GL_TEXTURE_2D, 0 ); glBindVertexArray( 0 ); glUseProgram(0); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL12_nglDrawRangeElementsBO(JNIEnv *env, jclass clazz, jint mode, jint start, jint end, jint count, jint type, jlong indices_buffer_offset, jlong function_pointer) { const GLvoid *indices_address = ((const GLvoid *)offsetToPointer(indices_buffer_offset)); glDrawRangeElementsPROC glDrawRangeElements = (glDrawRangeElementsPROC)((intptr_t)function_pointer); glDrawRangeElements(mode, start, end, count, type, indices_address); }
void ogl::mesh::draw_faces() const { glDrawRangeElements(GL_TRIANGLES, min, max, faces.size() * 3, GL_UNSIGNED_INT, faces_pointer); }
void QuadSurfaces::draw() { GL_Error_Check; if (view->sort) redraw = true; //Recalc cross section order //Draw, calls update when required Geometry::draw(); if (drawcount == 0) return; GL_Error_Check; // Draw using vertex buffer object clock_t t0 = clock(); double time; int stride = 8 * sizeof(float) + sizeof(Colour); //3+3+2 vertices, normals, texCoord + 32-bit colour glBindBuffer(GL_ARRAY_BUFFER, vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexvbo); if (geom.size() > 0 && elements > 0 && glIsBuffer(vbo) && glIsBuffer(indexvbo)) { glVertexPointer(3, GL_FLOAT, stride, (GLvoid*)0); // Load vertex x,y,z only glNormalPointer(GL_FLOAT, stride, (GLvoid*)(3*sizeof(float))); // Load normal x,y,z, offset 3 float glTexCoordPointer(2, GL_FLOAT, stride, (GLvoid*)(6*sizeof(float))); // Load texcoord x,y glColorPointer(4, GL_UNSIGNED_BYTE, stride, (GLvoid*)(8*sizeof(float))); // Load rgba, offset 6 float glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); //Render in reverse sorted order for (int i=geom.size()-1; i>=0; i--) { unsigned int id = surf_sort[i].id; //if (!drawable(id)) continue; if (hiddencache[id]) continue; //Get the offset unsigned int start = 0; for (unsigned int g=0; g<geom.size(); g++) { if (g == id) break; start += 4 * (geom[g]->width-1) * (geom[g]->height-1); //geom[g]->indices.size(); } //int id = i; //Sorting disabled setState(id, prog); //Set draw state settings for this object //fprintf(stderr, "(%d) DRAWING QUADS: %d (%d to %d) elements: %d\n", i, geom[i]->indices.size()/4, start/4, (start+geom[i]->indices.size())/4, elements); glDrawRangeElements(GL_QUADS, 0, elements, 4 * (geom[id]->width-1) * (geom[id]->height-1), GL_UNSIGNED_INT, (GLvoid*)(start*sizeof(GLuint))); //printf("%d) rendered, distance = %f (%f)\n", id, geom[id]->distance, surf_sort[i].distance); } //fprintf(stderr, "DRAWING ALL QUADS: %d\n", elements); //glDrawElements(GL_QUADS, elements, GL_UNSIGNED_INT, (GLvoid*)(0)); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); GL_Error_Check; //Restore state //glEnable(GL_LIGHTING); //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //glDisable(GL_CULL_FACE); glBindTexture(GL_TEXTURE_2D, 0); time = ((clock()-t0)/(double)CLOCKS_PER_SEC); if (time > 0.05) debug_print(" %.4lf seconds to draw quads\n", time); GL_Error_Check; }
void ogl::mesh::draw_lines() const { glDrawRangeElements(GL_LINES, min, max, lines.size() * 2, GL_UNSIGNED_INT, lines_pointer); }
void CommandBuffer::drawIndexed(const unsigned indexCount, const unsigned startIndexLocation, const int baseVertexLocation) { flushDrawStates(); glDrawRangeElements(m_topology, startIndexLocation, startIndexLocation + indexCount, indexCount, GL_UNSIGNED_SHORT, 0); }
void shadow_render_mesh(int mesh_idx) { int n,k,poly_count; float f_dist; double dx,dy,dz,d_alpha; float *vertex_ptr,*vl,*cl; d3vct ray_move; d3pnt *pt,*spt,*ept,*hpt; map_mesh_type *mesh; map_mesh_poly_type *poly; view_light_spot_type *lspot; // for now, leverage the model shadow // arrays and only allow meshes with a limited // number of vertexes mesh=&map.mesh.meshes[mesh_idx]; if (mesh->nvertex>=max_model_vertex) return; // find all polys the shadow ray hits poly_count=shadow_build_poly_set_mesh(mesh_idx); if (poly_count==0) return; // get light and draw distance lspot=shadow_get_light_spot(&mesh->box.mid,(mesh->box.max.y-mesh->box.min.y)); f_dist=(float)lspot->intensity; // get distance alpha factor d_alpha=(double)lspot->intensity; d_alpha=1.0/(d_alpha*d_alpha); // start stenciling // never write to the depth buffer during this operation glEnable(GL_STENCIL_TEST); glDisable(GL_ALPHA_TEST); glDepthMask(GL_FALSE); // setup blending glColor4f(0.0f,0.0f,0.0f,1.0f); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // run through all the stenciled polygons // and ray trace against their planes // to create the shadow polygons for (k=0;k!=poly_count;k++) { // stencil the poly we are going // to draw a shadow on shadow_stencil_mesh_poly(shadow_poly_ptrs[k].mesh_idx,shadow_poly_ptrs[k].poly_idx); // run through all the vertexes of this mesh spt=shadow_spt; ept=shadow_ept; pt=mesh->vertexes; for (n=0;n!=mesh->nvertex;n++) { spt->x=pt->x; spt->y=pt->y; spt->z=pt->z; vector_create(&ray_move,lspot->pnt.x,lspot->pnt.y,lspot->pnt.z,spt->x,spt->y,spt->z); ept->x=spt->x-(int)(ray_move.x*f_dist); ept->y=spt->y-(int)(ray_move.y*f_dist); ept->z=spt->z-(int)(ray_move.z*f_dist); spt++; ept++; pt++; } ray_trace_mesh_poly_plane(mesh->nvertex,shadow_spt,shadow_ept,shadow_hpt,shadow_hits,shadow_poly_ptrs[k].mesh_idx,shadow_poly_ptrs[k].poly_idx); // setup the vertex objects vertex_ptr=view_bind_map_next_vertex_object(mesh->nvertex*(3+4)); if (vertex_ptr==NULL) { glDisable(GL_STENCIL_TEST); glDepthMask(GL_TRUE); return; } vl=vertex_ptr; cl=vertex_ptr+(mesh->nvertex*3); // vertexes hpt=shadow_hpt; for (n=0;n!=mesh->nvertex;n++) { // vertex *vl++=(float)hpt->x; *vl++=(float)hpt->y; *vl++=(float)hpt->z; // color dx=(hpt->x-lspot->pnt.x); dy=(hpt->y-lspot->pnt.y); dz=(hpt->z-lspot->pnt.z); hpt++; *cl++=0.0f; *cl++=0.0f; *cl++=0.0f; *cl++=1.0f-(float)(((dx*dx)+(dy*dy)+(dz*dz))*d_alpha); } view_unmap_current_vertex_object(); // shadows are blended and stenciled // we clear the stencil as we draw so // we can maintain the alpha levels glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glStencilOp(GL_KEEP,GL_KEEP,GL_ZERO); glStencilFunc(GL_EQUAL,stencil_shadow,0xFF); // ray trace the polygon against // the plane of the polygon glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3,GL_FLOAT,0,0); glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4,GL_FLOAT,0,(void*)((mesh->nvertex*3)*sizeof(float))); poly=mesh->polys; for (n=0;n!=mesh->npoly;n++) { glDrawRangeElements(GL_POLYGON,0,mesh->nvertex,poly->ptsz,GL_UNSIGNED_INT,(GLvoid*)poly->v); poly++; } glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); // unbind the vertex object view_unbind_current_vertex_object(); // erase the stencil shadow_stencil_clear_mesh_poly(); } // restore depth buffer and turn // off stenciling glDepthMask(GL_TRUE); glDisable(GL_STENCIL_TEST); }
void shadow_render_model(model_draw *draw) { int n,k,t,poly_count,trig_count; float f_dist; double dx,dy,dz,d_alpha; float *vp,*vertex_ptr,*vl,*cl; unsigned short *index_ptr; d3vct ray_move; d3pnt *spt,*ept,*hpt; model_trig_type *trig; model_mesh_type *mesh; model_type *mdl; view_light_spot_type *lspot; // get model mdl=model_find_uid(draw->uid); if (mdl==NULL) return; // find all polys the shadow ray hits poly_count=shadow_build_poly_set_model(mdl,draw); if (poly_count==0) return; // get light and draw distance lspot=shadow_get_light_spot(&draw->pnt,draw->size.y); f_dist=(float)lspot->intensity; // get distance alpha factor d_alpha=(double)lspot->intensity; d_alpha=1.0/(d_alpha*d_alpha); // start stenciling // never write to the depth buffer during this operation glEnable(GL_STENCIL_TEST); glDisable(GL_ALPHA_TEST); glDepthMask(GL_FALSE); // setup blending glColor4f(0.0f,0.0f,0.0f,1.0f); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // run through all the stenciled polygons // and ray trace against their planes // to create the shadow polygons for (k=0;k!=poly_count;k++) { // stencil the poly we are going // to draw a shadow on shadow_stencil_mesh_poly(shadow_poly_ptrs[k].mesh_idx,shadow_poly_ptrs[k].poly_idx); // shadows are blended and stenciled // we clear the stencil as we draw so // we can maintain the alpha levels glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glStencilOp(GL_KEEP,GL_KEEP,GL_ZERO); glStencilFunc(GL_EQUAL,stencil_shadow,0xFF); // run through all the meshes of this model for (n=0;n!=mdl->nmesh;n++) { if ((draw->render_mesh_mask&(0x1<<n))==0) continue; // ray trace the mesh against // the plane of the polygon mesh=&mdl->meshes[n]; vp=draw->setup.mesh_arrays[n].gl_vertex_array; spt=shadow_spt; ept=shadow_ept; for (t=0;t!=mesh->nvertex;t++) { spt->x=(int)*vp++; spt->y=(int)*vp++; spt->z=(int)*vp++; vector_create(&ray_move,lspot->pnt.x,lspot->pnt.y,lspot->pnt.z,spt->x,spt->y,spt->z); ept->x=spt->x-(int)(ray_move.x*f_dist); ept->y=spt->y-(int)(ray_move.y*f_dist); ept->z=spt->z-(int)(ray_move.z*f_dist); spt++; ept++; } ray_trace_mesh_poly_plane(mesh->nvertex,shadow_spt,shadow_ept,shadow_hpt,shadow_hits,shadow_poly_ptrs[k].mesh_idx,shadow_poly_ptrs[k].poly_idx); // setup the vertex objects vertex_ptr=view_bind_map_next_vertex_object(mesh->nvertex*(3+4)); if (vertex_ptr==NULL) { glDisable(GL_STENCIL_TEST); glDepthMask(GL_TRUE); return; } vl=vertex_ptr; cl=vertex_ptr+(mesh->nvertex*3); // vertexes hpt=shadow_hpt; for (t=0;t!=mesh->nvertex;t++) { // vertex *vl++=(float)hpt->x; *vl++=(float)hpt->y; *vl++=(float)hpt->z; // color dx=(hpt->x-lspot->pnt.x); dy=(hpt->y-lspot->pnt.y); dz=(hpt->z-lspot->pnt.z); hpt++; *cl++=0.0f; *cl++=0.0f; *cl++=0.0f; *cl++=1.0f-(float)(((dx*dx)+(dy*dy)+(dz*dz))*d_alpha); } view_unmap_current_vertex_object(); // create the index object index_ptr=view_bind_map_next_index_object(mesh->ntrig*3); if (index_ptr==NULL) { view_unbind_current_vertex_object(); glDisable(GL_STENCIL_TEST); glDepthMask(GL_TRUE); return; } trig_count=0; trig=mesh->trigs; for (t=0;t!=mesh->ntrig;t++) { if ((shadow_hits[trig->v[0]]) && (shadow_hits[trig->v[1]]) && (shadow_hits[trig->v[2]])) { *index_ptr++=trig->v[0]; *index_ptr++=trig->v[1]; *index_ptr++=trig->v[2]; trig_count++; } trig++; } view_unmap_current_index_object(); // draw the shadow trigs glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3,GL_FLOAT,0,0); glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4,GL_FLOAT,0,(void*)((mesh->nvertex*3)*sizeof(float))); glDrawRangeElements(GL_TRIANGLES,0,mesh->nvertex,(trig_count*3),GL_UNSIGNED_SHORT,(GLvoid*)0); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); // unbind the vertex and index object view_unbind_current_vertex_object(); view_unbind_current_index_object(); } shadow_stencil_clear_mesh_poly(); } // restore depth buffer and turn // off stenciling glDepthMask(GL_TRUE); glDisable(GL_STENCIL_TEST); }
void VertexArray::drawRangeElements(const GLenum mode, const GLuint start, const GLuint end, const GLsizei count, const GLenum type, const void* indices) const { bind(); glDrawRangeElements(mode, start, end, count, type, indices); }
void ModelRendererGl::renderMesh(Mesh *mesh,int renderMode) { if(renderMode==rmSelection && mesh->getNoSelect()==true) {// don't render this and do nothing return; } //assertions assertGl(); //glPolygonOffset(0.05f, 0.0f); //set cull face if(mesh->getTwoSided()) { glDisable(GL_CULL_FACE); } else{ glEnable(GL_CULL_FACE); } if(this->colorPickingMode == false) { //set color if(renderColors) { Vec4f color(mesh->getDiffuseColor(), mesh->getOpacity()); glColor4fv(color.ptr()); } //texture state const Texture2DGl *texture= static_cast<const Texture2DGl*>(mesh->getTexture(mtDiffuse)); if(texture != NULL && renderTextures) { if(lastTexture != texture->getHandle()){ //assert(glIsTexture(texture->getHandle())); //throw megaglest_runtime_error("glIsTexture(texture->getHandle()) == false for texture: " + texture->getPath()); if(glIsTexture(texture->getHandle()) == GL_TRUE) { glBindTexture(GL_TEXTURE_2D, texture->getHandle()); lastTexture= texture->getHandle(); } else { glBindTexture(GL_TEXTURE_2D, 0); lastTexture= 0; } } } else{ glBindTexture(GL_TEXTURE_2D, 0); lastTexture= 0; } if(meshCallback != NULL) { meshCallback->execute(mesh); } } //misc vars uint32 vertexCount= mesh->getVertexCount(); uint32 indexCount= mesh->getIndexCount(); //assertions assertGl(); if(getVBOSupported() == true && mesh->getFrameCount() == 1) { if(mesh->hasBuiltVBOEntities() == false) { mesh->BuildVBOs(); } //printf("Rendering Mesh with VBO's\n"); //vertices glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh->getVBOVertices() ); glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL ); // Set The Vertex Pointer To The Vertex Buffer //glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); //normals if(renderNormals) { glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh->getVBONormals() ); glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, (char *) NULL); //glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); } else{ glDisableClientState(GL_NORMAL_ARRAY); } //tex coords if(renderTextures && mesh->getTexture(mtDiffuse) != NULL ) { if(duplicateTexCoords) { glActiveTexture(GL_TEXTURE0 + secondaryTexCoordUnit); glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh->getVBOTexCoords() ); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer //glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); } glActiveTexture(GL_TEXTURE0); glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh->getVBOTexCoords() ); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer //glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); } else { if(duplicateTexCoords) { glActiveTexture(GL_TEXTURE0 + secondaryTexCoordUnit); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } glActiveTexture(GL_TEXTURE0); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } } else { //printf("Rendering Mesh WITHOUT VBO's\n"); //vertices glVertexPointer(3, GL_FLOAT, 0, mesh->getInterpolationData()->getVertices()); //normals if(renderNormals) { glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, mesh->getInterpolationData()->getNormals()); } else{ glDisableClientState(GL_NORMAL_ARRAY); } //tex coords if(renderTextures && mesh->getTexture(mtDiffuse)!=NULL ) { if(duplicateTexCoords) { glActiveTexture(GL_TEXTURE0 + secondaryTexCoordUnit); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, mesh->getTexCoords()); } glActiveTexture(GL_TEXTURE0); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, mesh->getTexCoords()); } else { if(duplicateTexCoords) { glActiveTexture(GL_TEXTURE0 + secondaryTexCoordUnit); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } glActiveTexture(GL_TEXTURE0); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } } if(getVBOSupported() == true && mesh->getFrameCount() == 1) { glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, mesh->getVBOIndexes() ); glDrawRangeElements(GL_TRIANGLES, 0, vertexCount-1, indexCount, GL_UNSIGNED_INT, (char *)NULL); glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 ); glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); //glDrawRangeElements(GL_TRIANGLES, 0, vertexCount-1, indexCount, GL_UNSIGNED_INT, mesh->getIndices()); } else { //draw model glDrawRangeElements(GL_TRIANGLES, 0, vertexCount-1, indexCount, GL_UNSIGNED_INT, mesh->getIndices()); } //assertions assertGl(); }
void draw() const { // Bail out if there's nothing to draw if (empty()) return; // Pass all of our triangle data glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); assert((textureCount == 0 || _VertexArray.size() == _TexCoordArrays[0].size()) && _VertexArray.size() == _NormalArray.size()); // Pass the VertexArray _VertexArray.draw(); _NormalArray.draw(); // Pass texture data for all texture units /* NOTE: Although the single loop would suffice, to allow the * compiler to optimise this code (by removing unreachable * code in case of <= 1 texture) this switch statement is * required. */ switch (textureCount) { case 0: break; case 1: glEnableClientState(GL_TEXTURE_COORD_ARRAY); _TexCoordArrays[0].draw(); break; default: { GLenum unit = GL_TEXTURE0; for (size_t i = 0; i < textureCount; ++i) { if (GLEE_VERSION_1_3) glClientActiveTexture(unit++); else if (GLEE_ARB_multitexture) glClientActiveTextureARB(unit++); else assert(!"Shouldn't ever get here!"); glEnableClientState(GL_TEXTURE_COORD_ARRAY); _TexCoordArrays[i].draw(); } break; } } if (_indices) { #ifndef NDEBUG if (_indices_modified) { for (typename std::vector<IndexIntegerType>::const_iterator i = _indices->begin(); i != _indices->end(); ++i) assert(*i < _VertexArray.size()); _indices_modified = false; } #endif // Draw all contained triangles based on the array of indices if (GLEE_VERSION_1_2) glDrawRangeElements(GL_TRIANGLES, 0, _VertexArray.size() - 1, _indices->size(), OpenGLTypeConstant<IndexIntegerType>::constant, &(*_indices)[0]); else if (GLEE_EXT_draw_range_elements) glDrawRangeElementsEXT(GL_TRIANGLES, 0, _VertexArray.size() - 1, _indices->size(), OpenGLTypeConstant<IndexIntegerType>::constant, &(*_indices)[0]); else glDrawElements(GL_TRIANGLES, _indices->size(), OpenGLTypeConstant<IndexIntegerType>::constant, &(*_indices)[0]); } else { glDrawArrays(GL_TRIANGLES, 0, _VertexArray.size()); } // Disable the GL_VERTEX_ARRAY client state to prevent strange behaviour glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); /* NOTE: Although the single loop would suffice, to allow the * compiler to optimise this code (by removing unreachable * code in case of <= 1 texture) this switch statement is * required. */ switch (textureCount) { case 0: break; case 1: glDisableClientState(GL_TEXTURE_COORD_ARRAY); break; default: { GLenum unit = GL_TEXTURE0; for (size_t i = 0; i < textureCount; ++i) { if (GLEE_VERSION_1_3) glClientActiveTexture(unit++); else if (GLEE_ARB_multitexture) glClientActiveTextureARB(unit++); else assert(!"Shouldn't ever get here!"); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } if (GLEE_VERSION_1_3) glClientActiveTexture(GL_TEXTURE0); else if (GLEE_ARB_multitexture) glClientActiveTextureARB(GL_TEXTURE0); else assert(!"Shouldn't ever get here!"); break; } } }
void SceneDrawer::DrawSkeletonWithShaders( XnUserID nUserId ) { XnUInt16 numJoints = MAX_JOINTS; // TODO: Write 3D function if( m_pUserTrackerObj->GetJoints( nUserId, pJointsPosArr, pConfidenceArr, numJoints ) != XN_STATUS_OK ) return; // no limbs to draw if( numJoints == 0 ) return; // no limbs to draw static GLfloat skeletonJoints[MAX_JOINTS][3]; for( XnUInt16 j = 0; j < MAX_JOINTS; j++ ){ skeletonJoints[j][0] = pJointsPosArr[j].X; skeletonJoints[j][1] = pJointsPosArr[j].Y; skeletonJoints[j][2] = pJointsPosArr[j].Z; //cout << j << '\t' << pJointsPosArr[j].X << '\t' << pJointsPosArr[j].Y << '\t' << pJointsPosArr[j].Z << endl; //cout << j << '\t' << skeletonJoints[j][0] << '\t' << skeletonJoints[j][1] << '\t' << skeletonJoints[j][2] << endl; } //cout << endl; // Designate the desired shader program glUseProgram( g_programHandle_Skeleton ); // Bind the buffers, fill with data, and attach to the program glBindVertexArray( g_vao[1] ); // Refill the array glBindBuffer( GL_ARRAY_BUFFER, g_verticesVBO_Skeleton ); glBufferSubData( GL_ARRAY_BUFFER, 0, 3 * MAX_JOINTS * sizeof(GLfloat), &skeletonJoints ); /* // Skeleton Array from UserTracker.cpp { XN_SKEL_HEAD, XN_SKEL_NECK }, { XN_SKEL_NECK, XN_SKEL_LEFT_SHOULDER }, { XN_SKEL_LEFT_SHOULDER, XN_SKEL_LEFT_ELBOW }, { XN_SKEL_LEFT_ELBOW, XN_SKEL_LEFT_HAND }, { XN_SKEL_NECK, XN_SKEL_RIGHT_SHOULDER }, { XN_SKEL_RIGHT_SHOULDER, XN_SKEL_RIGHT_ELBOW }, { XN_SKEL_RIGHT_ELBOW, XN_SKEL_RIGHT_HAND }, { XN_SKEL_LEFT_SHOULDER, XN_SKEL_TORSO }, { XN_SKEL_RIGHT_SHOULDER, XN_SKEL_TORSO }, { XN_SKEL_TORSO, XN_SKEL_LEFT_HIP }, { XN_SKEL_LEFT_HIP, XN_SKEL_LEFT_KNEE }, { XN_SKEL_LEFT_KNEE, XN_SKEL_LEFT_FOOT }, { XN_SKEL_TORSO, XN_SKEL_RIGHT_HIP }, { XN_SKEL_RIGHT_HIP, XN_SKEL_RIGHT_KNEE }, { XN_SKEL_RIGHT_KNEE, XN_SKEL_RIGHT_FOOT }, { XN_SKEL_LEFT_HIP, XN_SKEL_RIGHT_HIP }, */ static GLuint indices_Skeleton[] = { 0, 1, 1, 2, 2, 3, 3, 4, 1, 5, 5, 6, 6, 7, 2, 8, 5, 8, 8, 9, 9, 10, 10, 11, 8, 12, 12, 13, 13, 14, 9, 12 }; int numberIndices_Skeleton = SizeOfArray(indices_Skeleton); // **************************************** // Draw the geometry glDrawRangeElements( GL_LINES, // Type of Geometry 0, // Start index numberIndices_Skeleton, // End index numberIndices_Skeleton, // Count of indices GL_UNSIGNED_INT, // Type of index indices_Skeleton // Pointer to the indices ); glFlush(); // Return control to pipeline glUseProgram(0); glBindBuffer( GL_ARRAY_BUFFER, 0 ); glBindVertexArray( 0 ); }
void SAssPiece::DrawForList() const { if (!hasGeometryData) return; vboAttributes.Bind(GL_ARRAY_BUFFER); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, pos))); glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, normal))); // primary and secondary texture use first UV channel for (unsigned int n = 0; n < NUM_MODEL_TEXTURES; n++) { glClientActiveTexture(GL_TEXTURE0 + n); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, texCoords) + (0 * sizeof(float2)))); } // extra UV channels (currently at most one) for (unsigned int n = 1; n < GetNumTexCoorChannels(); n++) { glClientActiveTexture(GL_TEXTURE0 + NUM_MODEL_TEXTURES + (n - 1)); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, texCoords) + (n * sizeof(float2)))); } glClientActiveTexture(GL_TEXTURE5); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(3, GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, sTangent))); glClientActiveTexture(GL_TEXTURE6); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(3, GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, tTangent))); vboAttributes.Unbind(); vboIndices.Bind(GL_ELEMENT_ARRAY_BUFFER); /* * since aiProcess_SortByPType is being used, * we're sure we'll get only 1 type here, * so combination check isn't needed, also * anything more complex than triangles is * being split thanks to aiProcess_Triangulate */ glDrawRangeElements(GL_TRIANGLES, 0, vertices.size() - 1, vertexDrawIndices.size(), GL_UNSIGNED_INT, vboIndices.GetPtr()); vboIndices.Unbind(); glClientActiveTexture(GL_TEXTURE6); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glClientActiveTexture(GL_TEXTURE5); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glClientActiveTexture(GL_TEXTURE2); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glClientActiveTexture(GL_TEXTURE1); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glClientActiveTexture(GL_TEXTURE0); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL12_nglDrawRangeElements(JNIEnv *env, jclass clazz, jint mode, jint start, jint end, jint count, jint type, jobject indices, jint indices_position, jlong function_pointer) { const GLvoid *indices_address = ((const GLvoid *)(((char *)(*env)->GetDirectBufferAddress(env, indices)) + indices_position)); glDrawRangeElementsPROC glDrawRangeElements = (glDrawRangeElementsPROC)((intptr_t)function_pointer); glDrawRangeElements(mode, start, end, count, type, indices_address); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void DrawableVectors::render(OpenGLContext* oglContext, ShaderProgram* shaderProgram, const MatrixState&) { CVF_CALLSITE_OPENGL(oglContext); CVF_ASSERT(shaderProgram); CVF_ASSERT(shaderProgram->isProgramUsed(oglContext)); CVF_ASSERT(m_vertexArray->size() == m_vectorArray->size()); CVF_ASSERT(m_colorArray.isNull() || (m_colorArray->size() == m_vectorArray->size())); CVF_ASSERT(m_vectorGlyph.notNull()); CVF_ASSERT(m_vectorGlyph->primitiveSetCount() == 1); // Setup Vertex Arrays/vbos const GLvoid* ptrOrOffset = 0; if (m_renderWithVBO && m_glyphVerticesAndNormalsBO.notNull() && m_glyphVerticesAndNormalsBO->isUploaded()) { // Bind VBO for vertex and normal data m_glyphVerticesAndNormalsBO->bindBuffer(oglContext); glVertexAttribPointer(ShaderProgram::NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(float)*6, (void*)(sizeof(float)*3)); glVertexAttribPointer(ShaderProgram::VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(float)*6, 0); glEnableVertexAttribArray(ShaderProgram::NORMAL); glEnableVertexAttribArray(ShaderProgram::VERTEX); m_indicesBO->bindBuffer(oglContext); } else { glBindBuffer(GL_ARRAY_BUFFER, 0); glVertexAttribPointer(ShaderProgram::NORMAL, 3, GL_FLOAT, GL_FALSE, 0, m_vectorGlyph->normalArray()->ptr()->ptr()); glEnableVertexAttribArray(ShaderProgram::NORMAL); glVertexAttribPointer(ShaderProgram::VERTEX, 3, GL_FLOAT, GL_FALSE, 0, m_vectorGlyph->vertexArray()->ptr()->ptr()); glEnableVertexAttribArray(ShaderProgram::VERTEX); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); ptrOrOffset = m_vectorGlyphPrimSet->indices()->ptr(); } // Must use manual uniform setting, as setting the uniform through the Uniform* class requires a lookup for location // every time, and this is always the same GLint vectorMatrixUniformLocation = shaderProgram->uniformLocation(m_vectorMatrixUniformName.toAscii().ptr()); CVF_ASSERT(vectorMatrixUniformLocation != -1); GLint colorUniformLocation = shaderProgram->uniformLocation(m_colorUniformName.toAscii().ptr()); CVF_ASSERT(colorUniformLocation != -1); #ifndef CVF_OPENGL_ES uint minIndex = m_vectorGlyphPrimSet->minIndex(); uint maxIndex = m_vectorGlyphPrimSet->maxIndex(); #endif GLsizei indexCount = static_cast<GLsizei>(m_vectorGlyphPrimSet->indexCount()); // Set the single color to use if (m_colorArray.isNull()) { glUniform3fv(colorUniformLocation, 1, m_singleColor.ptr()); } float vectorMat[16]; size_t numVectors = m_vectorArray->size(); size_t i; for (i = 0; i < numVectors; i++) { // Compute the transformation matrix vectorMatrix(i, vectorMat); // Set this as a uniform to the shader program glUniformMatrix4fv(vectorMatrixUniformLocation, 1, GL_FALSE, vectorMat); if (m_colorArray.notNull()) { glUniform3fv(colorUniformLocation, 1, m_colorArray->get(i).ptr()); } // Draw the arrow #ifdef CVF_OPENGL_ES glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, ptrOrOffset); #else glDrawRangeElements(GL_TRIANGLES, minIndex, maxIndex, indexCount, GL_UNSIGNED_SHORT, ptrOrOffset); #endif } // Cleanup glDisableVertexAttribArray(ShaderProgram::VERTEX); glDisableVertexAttribArray(ShaderProgram::NORMAL); CVF_CHECK_OGL(oglContext); // Things to consider for performance: // 1) Uniform arrays evt. Uniform buffer objects // 2) Texture // 3) Texture array // GL_ARB_draw_instanced(); // glDrawElementsInstanced }
void Camera::renderGraph(const Node *graph) { if (!graph || dynamic_cast<const osg::Camera*>(graph)) return; const osg::BoundingSphered &bound = computeBoundsOf(graph); const double r = bound.radius(); const Vec3d view_center = bound.center() * qMatrix.back(); if (-view_center.z() + r < znear || -view_center.z() - r > zfar) return; bool bPopMatrix = false; const osg::StateSet *stateset = graph->getStateSet(); if (stateset) { qStateSet.push_back(qStateSet.back()); processStateSet(stateset, qStateSet.back()); } const PositionAttitudeTransform *ptrans = dynamic_cast<const PositionAttitudeTransform*>(graph); if (ptrans) { const Matrixd mat = Matrixd::translate(-ptrans->getPivotPoint()) * Matrixd::rotate(ptrans->getAttitude()) * Matrixd::scale(ptrans->getScale()) * Matrixd::translate(ptrans->getPosition()); pushMatrix(mat); bPopMatrix = true; } const MatrixTransform *mtrans = dynamic_cast<const MatrixTransform*>(graph); if (mtrans) { pushMatrix(mtrans->getMatrix()); bPopMatrix = true; } const Switch* sgroup = dynamic_cast<const Switch*>(graph); if (sgroup) { for(unsigned int i = 0, nb = sgroup->getNumChildren() ; i < nb ; ++i) if (sgroup->getValue(i)) renderGraph(sgroup->getChild(i)); } else { const Group* group = dynamic_cast<const Group*>(graph); if (group) { for(unsigned int i = 0, nb = group->getNumChildren() ; i < nb ; ++i) renderGraph(group->getChild(i)); } } const Geode *geode = dynamic_cast<const Geode*>(graph); if (geode) { glEnableClientState(GL_VERTEX_ARRAY); CHECK_GL(); bool bParentStateApplied = false; for(unsigned int i = 0, nb = geode->getNumDrawables() ; i < nb ; ++i) { const Geometry * const geom = geode->getDrawable(i)->asGeometry(); if (!geom) { LOG_ERROR() << "[Camera] unsupported drawable : " << geode->getDrawable(i)->className() << std::endl; continue; } const Array * const vtx = geom->getVertexArray(); const Array * const normals = geom->getNormalArray(); const Array * const tcoord = geom->getTexCoordArray(0); if (!vtx) { LOG_ERROR() << "[Camera] no vertex array in Geometry object" << std::endl; continue; } StateSet *local_state = NULL; char tmp[sizeof(StateSet)]; //! Avoid dynamic allocation const osg::StateSet *geom_state = geom->getStateSet(); if (geom_state) { local_state = new(tmp) StateSet(qStateSet.back()); processStateSet(geom_state, *local_state); } if (local_state) { local_state->apply(); bParentStateApplied = false; } else if (!bParentStateApplied) { bParentStateApplied = true; qStateSet.back().apply(); } if (bDoublePrecisionMode) { if (processed_vertex_array.size() < vtx->getNumElements()) processed_vertex_array.resize(vtx->getNumElements()); const void * const ptr = vtx->getDataPointer(); const osg::Matrixd &mat = qMatrix.back() * projectionMatrix; switch(vtx->getDataType()) { case GL_FLOAT: if (vtx->getDataSize() == 4) { const size_t nb = vtx->getNumElements(); for(size_t i = 0 ; i < nb ; ++i) { const Vec4d &p = Vec4d(((const Vec4f*)ptr)[i]) * mat; processed_vertex_array[i] = p / p.w(); } } else if (vtx->getDataSize() == 3) { const size_t nb = vtx->getNumElements(); for(size_t i = 0 ; i < nb ; ++i) { const Vec4d &p = Vec4d(((const Vec3f*)ptr)[i], 1.0) * mat; processed_vertex_array[i] = p / p.w(); } } break; } glEnableClientState(GL_COLOR_ARRAY); CHECK_GL(); if (pContext->hasVBOSupport()) { glBindBuffer(GL_ARRAY_BUFFER, 0); CHECK_GL(); } glColorPointer(4, GL_FLOAT, 0, &(processed_vertex_array.front())); CHECK_GL(); } if (pContext->hasVBOSupport()) { glBindBuffer(GL_ARRAY_BUFFER, pContext->getDataVBOID(vtx->getDataPointer(), vtx->getTotalDataSize())); CHECK_GL(); glVertexPointer(vtx->getDataSize(), vtx->getDataType(), 0, 0); CHECK_GL(); if (normals) { glEnableClientState(GL_NORMAL_ARRAY); CHECK_GL(); glBindBuffer(GL_ARRAY_BUFFER, pContext->getDataVBOID(normals->getDataPointer(), normals->getTotalDataSize())); CHECK_GL(); glNormalPointer(normals->getDataType(), 0, 0); CHECK_GL(); } else { glDisableClientState(GL_NORMAL_ARRAY); CHECK_GL(); } if (tcoord) { glEnableClientState(GL_TEXTURE_COORD_ARRAY); CHECK_GL(); glBindBuffer(GL_ARRAY_BUFFER, pContext->getDataVBOID(tcoord->getDataPointer(), tcoord->getTotalDataSize())); CHECK_GL(); glTexCoordPointer(tcoord->getDataSize(), tcoord->getDataType(), 0, 0); CHECK_GL(); } else { glDisableClientState(GL_TEXTURE_COORD_ARRAY); CHECK_GL(); } const size_t nb_prim_set = geom->getNumPrimitiveSets(); for(size_t j = 0 ; j < nb_prim_set ; ++j) { const PrimitiveSet * const pset = geom->getPrimitiveSet(j); const DrawElements * const elts = pset->getDrawElements(); switch(pset->getType()) { case DrawElements::PrimitiveType: break; case DrawElements::DrawArraysPrimitiveType: glDrawArrays(pset->getMode(), pset->index(0), pset->getNumIndices()); CHECK_GL(); break; case DrawElements::DrawArrayLengthsPrimitiveType: break; case DrawElements::DrawElementsUBytePrimitiveType: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pContext->getIndexVBOID(elts->getDataPointer(), elts->getTotalDataSize())); CHECK_GL(); glDrawRangeElements(elts->getMode(), 0, vtx->getNumElements() - 1, elts->getNumIndices(), GL_UNSIGNED_BYTE, 0); CHECK_GL(); break; case DrawElements::DrawElementsUShortPrimitiveType: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pContext->getIndexVBOID(elts->getDataPointer(), elts->getTotalDataSize())); CHECK_GL(); glDrawRangeElements(elts->getMode(), 0, vtx->getNumElements() - 1, elts->getNumIndices(), GL_UNSIGNED_SHORT, 0); CHECK_GL(); break; case DrawElements::DrawElementsUIntPrimitiveType: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pContext->getIndexVBOID(elts->getDataPointer(), elts->getTotalDataSize())); CHECK_GL(); glDrawRangeElements(elts->getMode(), 0, vtx->getNumElements() - 1, elts->getNumIndices(), GL_UNSIGNED_INT, 0); CHECK_GL(); break; } } } else { glVertexPointer(vtx->getDataSize(), vtx->getDataType(), 0, vtx->getDataPointer()); CHECK_GL(); if (normals) { glEnableClientState(GL_NORMAL_ARRAY); CHECK_GL(); glNormalPointer(normals->getDataType(), 0, normals->getDataPointer()); CHECK_GL(); } else { glDisableClientState(GL_NORMAL_ARRAY); CHECK_GL(); } if (tcoord) { glEnableClientState(GL_TEXTURE_COORD_ARRAY); CHECK_GL(); glTexCoordPointer(tcoord->getDataSize(), tcoord->getDataType(), 0, tcoord->getDataPointer()); CHECK_GL(); } else { glDisableClientState(GL_TEXTURE_COORD_ARRAY); CHECK_GL(); } const size_t nb_prim_set = geom->getNumPrimitiveSets(); for(size_t j = 0 ; j < nb_prim_set ; ++j) { const PrimitiveSet * const pset = geom->getPrimitiveSet(j); const DrawElements * const elts = pset->getDrawElements(); switch(pset->getType()) { case DrawElements::PrimitiveType: break; case DrawElements::DrawArraysPrimitiveType: glDrawArrays(pset->getMode(), pset->index(0), pset->getNumIndices()); CHECK_GL(); break; case DrawElements::DrawArrayLengthsPrimitiveType: break; case DrawElements::DrawElementsUBytePrimitiveType: glDrawRangeElements(elts->getMode(), 0, vtx->getNumElements() - 1, elts->getNumIndices(), GL_UNSIGNED_BYTE, elts->getDataPointer()); CHECK_GL(); break; case DrawElements::DrawElementsUShortPrimitiveType: glDrawRangeElements(elts->getMode(), 0, vtx->getNumElements() - 1, elts->getNumIndices(), GL_UNSIGNED_SHORT, elts->getDataPointer()); CHECK_GL(); break; case DrawElements::DrawElementsUIntPrimitiveType: glDrawRangeElements(elts->getMode(), 0, vtx->getNumElements() - 1, elts->getNumIndices(), GL_UNSIGNED_INT, elts->getDataPointer()); CHECK_GL(); break; } } } if (local_state) local_state->~StateSet(); } } if (bPopMatrix) popMatrix(); if (stateset) qStateSet.pop_back(); }
void SAssPiece::DrawForList() const { if (isEmpty) return; LOG_SL(LOG_SECTION_PIECE, L_DEBUG, "Compiling piece %s", name.c_str()); vboAttributes.Bind(GL_ARRAY_BUFFER); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, pos))); glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, normal))); glClientActiveTexture(GL_TEXTURE0); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, texCoord))); glClientActiveTexture(GL_TEXTURE1); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, texCoord))); if (hasTexCoord2) { glClientActiveTexture(GL_TEXTURE2); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, texCoord2))); } glClientActiveTexture(GL_TEXTURE5); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(3, GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, sTangent))); glClientActiveTexture(GL_TEXTURE6); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(3, GL_FLOAT, sizeof(SAssVertex), vboAttributes.GetPtr(offsetof(SAssVertex, tTangent))); vboAttributes.Unbind(); vboIndices.Bind(GL_ELEMENT_ARRAY_BUFFER); /* * since aiProcess_SortByPType is being used, * we're sure we'll get only 1 type here, * so combination check isn't needed, also * anything more complex than triangles is * being split thanks to aiProcess_Triangulate */ glDrawRangeElements(GL_TRIANGLES, 0, vertices.size() - 1, vertexDrawIndices.size(), GL_UNSIGNED_INT, vboIndices.GetPtr()); vboIndices.Unbind(); glClientActiveTexture(GL_TEXTURE6); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glClientActiveTexture(GL_TEXTURE5); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glClientActiveTexture(GL_TEXTURE2); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glClientActiveTexture(GL_TEXTURE1); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glClientActiveTexture(GL_TEXTURE0); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); LOG_SL(LOG_SECTION_PIECE, L_DEBUG, "Completed compiling piece %s", name.c_str()); }
static void _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) { ScreenPtr screen = pixmap->drawable.pScreen; glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap); GLfloat xscale, yscale; float vertices[32]; float *pvertices = vertices; int valid_nbox = ARRAY_SIZE(vertices); glamor_set_destination_pixmap_priv_nc(pixmap_priv); glamor_get_context(glamor_priv); glUseProgram(glamor_priv->solid_prog); glUniform4fv(glamor_priv->solid_color_uniform_location, 1, color); pixmap_priv_get_dest_scale(pixmap_priv, &xscale, &yscale); if (_X_UNLIKELY(nbox * 4 * 2 > ARRAY_SIZE(vertices))) { int allocated_box; if (nbox * 6 > GLAMOR_COMPOSITE_VBO_VERT_CNT) { allocated_box = GLAMOR_COMPOSITE_VBO_VERT_CNT / 6; } else allocated_box = nbox; pvertices = malloc(allocated_box * 4 * 2 * sizeof(float)); if (pvertices) valid_nbox = allocated_box; else { pvertices = vertices; valid_nbox = ARRAY_SIZE(vertices) / (4 * 2); } } if (_X_UNLIKELY(nbox > 1)) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo); glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), pvertices); glEnableVertexAttribArray(GLAMOR_VERTEX_POS); while (nbox) { int box_cnt, i; float *valid_vertices; valid_vertices = pvertices; box_cnt = nbox > valid_nbox ? valid_nbox : nbox; for (i = 0; i < box_cnt; i++) { glamor_set_normalize_vcoords(pixmap_priv, xscale, yscale, box[i].x1, box[i].y1, box[i].x2, box[i].y2, glamor_priv->yInverted, valid_vertices); valid_vertices += 4 * 2; } if (box_cnt == 1) glDrawArrays(GL_TRIANGLE_FAN, 0, box_cnt * 4); else { if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { glDrawRangeElements(GL_TRIANGLES, 0, box_cnt * 4, box_cnt * 6, GL_UNSIGNED_SHORT, NULL); } else { glDrawElements(GL_TRIANGLES, box_cnt * 6, GL_UNSIGNED_SHORT, NULL); } } nbox -= box_cnt; box += box_cnt; } if (pvertices != vertices) free(pvertices); glDisableVertexAttribArray(GLAMOR_VERTEX_POS); glUseProgram(0); glamor_put_context(glamor_priv); glamor_priv->state = RENDER_STATE; glamor_priv->render_idle_cnt = 0; }