void RenderingContextGL::define_vertex_attribute(int attribIndex, gpu::AttributeType type, int compPerVertex, int stride, int offset) { // TODO: false stands for normalize which is in UploadFlags glVertexAttribPointer(attribIndex, compPerVertex, toGL(type), false, stride, reinterpret_cast<void*>(offset)); CHECK_GL_ERROR }
void RenderingContextGL::draw_arrays(gpu::DrawMode mode, int first, int count) { glDrawArrays(toGL(mode), first, count); CHECK_GL_ERROR }
gpu::Shader RenderingContextGL::create_shader(gpu::ShaderType type) { Shader s(glCreateShader(toGL(type))); CHECK_GL_ERROR return s; }
void RenderingContextGL::upload(const gpu::VertexBuffer& vbo, Range<byte> data, UploadFlags flags) { glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(byte), data.pointer(), toGL(vbo.update)); CHECK_GL_ERROR }
void RenderingContextGL::clear(TargetBuffer target) { glClear(toGL(target)); CHECK_GL_ERROR }
void InterleavedArraysShape::GLRender(SoGLRenderAction * action) { SoVertexProperty * vp = (SoVertexProperty*) this->vertexProperty.getValue(); if (!vp) return; SoState * state = action->getState(); Binding mbind = this->findMaterialBinding(state); SbBool transparency = FALSE; if (mbind == PER_VERTEX) { if (PRIVATE(this)->transparency == Pimpl::MAYBE) { PRIVATE(this)->transparency = Pimpl::NO; const uint32_t * rgba = vp->orderedRGBA.getValues(0); const int n = vp->orderedRGBA.getNum(); for (int i = 0; i < n; i++) { if ((rgba[i] & 0xff) != 0xff) { PRIVATE(this)->transparency = Pimpl::YES; break; } } } if (PRIVATE(this)->transparency == Pimpl::YES) { transparency = TRUE; } } if (transparency) { state->push(); SoShapeStyleElement::setTransparentMaterial(state, TRUE); } if (this->shouldGLRender(action)) { SoMaterialBundle mb(action); mb.sendFirst(); SbBool doTextures = vp->texCoord.getNum(); Binding nbind = this->findNormalBinding(state); uint32_t contextid = (uint32_t) action->getCacheContext(); const cc_glglue * glue = cc_glglue_instance((int) contextid); if (cc_glglue_has_vertex_array(glue) && cc_glglue_has_vertex_buffer_object(glue)) { if (!PRIVATE(this)->vbo || !PRIVATE(this)->vbo->hasVBO(contextid)) { this->createVBO(contextid); } PRIVATE(this)->vbo->bindBuffer(contextid); this->enableArrays(action, nbind == PER_VERTEX, mbind == PER_VERTEX, doTextures); if (this->vertexIndex.getNum()) { if (!PRIVATE(this)->indexvbo || !PRIVATE(this)->indexvbo->hasVBO(contextid)) { this->createIndexVBO(contextid); } PRIVATE(this)->indexvbo->bindBuffer(contextid); cc_glglue_glDrawElements(glue, toGL((Type) this->type.getValue()), this->vertexIndex.getNum(), PRIVATE(this)->useshorts ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, NULL); cc_glglue_glBindBuffer(glue, GL_ELEMENT_ARRAY_BUFFER, 0); } else { cc_glglue_glDrawArrays(glue, toGL((Type) this->type.getValue()), 0, vp->vertex.getNum()); } this->disableArrays(action, nbind == PER_VERTEX, mbind == PER_VERTEX, doTextures); cc_glglue_glBindBuffer(glue, GL_ARRAY_BUFFER, 0); SoGLCacheContextElement::shouldAutoCache(state, SoGLCacheContextElement::DONT_AUTO_CACHE); } else { // fall back to immediate mode rendering const SbVec3f * vptr = vp->vertex.getValues(0); const SbVec3f * nptr = NULL; const SbVec2f * tcptr = NULL; const uint32_t * cptr = NULL; const int nv = vp->vertex.getNum(); if (nbind == PER_VERTEX) { nptr = vp->normal.getValues(0); } if (mbind == PER_VERTEX) { cptr = vp->orderedRGBA.getValues(0); } if (vp->texCoord.getNum() >= nv) { tcptr = vp->texCoord.getValues(0); } glBegin(toGL((Type) this->type.getValue())); if (this->vertexIndex.getNum()) { const int n = this->vertexIndex.getNum(); const int32_t * idx = this->vertexIndex.getValues(0); for (int j = 0; j < n; j++) { const int i = idx[j]; if (cptr) { uint32_t c = cptr[i]; glColor4ub(c>>24, (c>>16)&0xff, (c>>8)&0xff, c&0xff); } if (tcptr) glTexCoord2fv((const GLfloat*) &tcptr[i]); if (nptr) glNormal3fv((const GLfloat*) &nptr[i]); glVertex3fv((const GLfloat*) &vptr[i]); } } else { for (int i = 0; i < nv; i++) { if (cptr) { uint32_t c = cptr[i]; glColor4ub(c>>24, (c>>16)&0xff, (c>>8)&0xff, c&0xff); } if (tcptr) glTexCoord2fv((const GLfloat*) &tcptr[i]); if (nptr) glNormal3fv((const GLfloat*) &nptr[i]); glVertex3fv((const GLfloat*) &vptr[i]); } } glEnd(); }