void Raycaster::glRenderAction(GLContextData& contextData) const { /* Get the OpenGL-dependent application data from the GLContextData object: */ DataItem* dataItem=contextData.retrieveDataItem<DataItem>(this); /* Save OpenGL state: */ glPushAttrib(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ENABLE_BIT|GL_LIGHTING_BIT|GL_POLYGON_BIT); /* Initialize the ray termination depth frame buffer: */ dataItem->initDepthBuffer(); /* Bind the ray termination framebuffer: */ GLint currentFramebuffer; glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT,¤tFramebuffer); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,dataItem->depthFramebufferID); /* Get the projection and modelview matrices: */ PTransform mv=glGetModelviewMatrix<Scalar>(); PTransform pmv=glGetProjectionMatrix<Scalar>(); pmv*=mv; /* Clip the render domain against the view frustum's front plane and all clipping planes: */ Polyhedron<Scalar>* clippedDomain=clipDomain(pmv,mv); /* Draw the clipped domain's back faces to the depth buffer as ray termination conditions: */ glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); clippedDomain->drawFaces(); /* Unbind the depth framebuffer: */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,currentFramebuffer); /* Install the GLSL shader program: */ dataItem->shader.useProgram(); bindShader(pmv,mv,dataItem); /* Draw the clipped domain's front faces: */ glEnable(GL_BLEND); glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA); glDepthMask(GL_FALSE); glCullFace(GL_BACK); if(clippedDomain!=0) clippedDomain->drawFaces(); /* Uninstall the GLSL shader program: */ unbindShader(dataItem); GLShader::disablePrograms(); /* Clean up: */ delete clippedDomain; /* Restore OpenGL state: */ glPopAttrib(); }
void TextureShader::compile() { Shader::compile(); bindShader(); texCoordAttributeHandle = glGetAttribLocation(program, "a_texCoord"); if (texCoordAttributeHandle < 0) { LOGE("*** Couldn't get shader's a_texCoord location."); ABORT_GAME; } samplerHandle = glGetUniformLocation(program, "s_texture"); if (samplerHandle < 0) { LOGE("*** Couldn't get shader's s_texture location."); ABORT_GAME; } unbindShader(); }