GLRender.cc

Go to the documentation of this file.
00001 #include <gra/render/GLRender.h>
00002 #include <gra/camera/CameraGL.h>
00003 #include <esg/spacesorting/Heap.h>
00004 #include <esg/geometry/FDH6.h>
00005 #include <esg/explorer/ObjsExplorer.h>
00006 #include <GL/glu.h>
00007 
00008 #ifdef HAVE_FREE_GLUT
00009 #include <GL/freeglut.h>
00010 #else
00011 #include <GL/glut.h>
00012 #endif
00013 
00014 using namespace gra;
00015 
00016 void GLRender::_render(Shader&      shader,
00017                        FrameBuffer& fb,
00018                        Camera&      camera,
00019                        Scene&       scene)
00020 {
00021     /*
00022      * This render requires an OpenGL camera (CameraGL class).
00023      * Therefore we have to instantiate it from the general camera.
00024      * Although the OpenGL camera is not furher used, its instantiation
00025      * updates the OpenGL projection and transformation matrices.
00026      */
00027     CameraGL cameraGL(camera);
00028 
00029     if (_useDisplayList && _displayList) {
00030         glCallList(_displayList);
00031         return;
00032     }
00033 
00034     if (_useDisplayList) {
00035         _displayList = glGenLists(1);
00036         glNewList(_displayList, GL_COMPILE_AND_EXECUTE);
00037     }
00038 
00039     SceneGraphObject  *  pObj;
00040     ObjsExplorer         explorer;
00041     Matrix4              trMat;
00042     bool                 tr;
00043     List<TranslucentObj> translucentObjects;
00044     MatVisitor           visitor;
00045     
00046     explorer.explore(*(scene.root()));
00047     while ((pObj = explorer.result(trMat, tr))) {
00048         visitor.init();
00049         pObj->inspectMaterials(visitor);
00050         if (visitor.avgTransparency() > 0.0) {
00051             TranslucentObj * t = new TranslucentObj();
00052             t->pObject = pObj;
00053             t->transformed = tr;
00054             if (tr) t->trMat.set(trMat);
00055             translucentObjects.append(t);
00056         } else {
00057             shader.setRenderedShape(pObj, (tr) ? &trMat : NULL);
00058             // The shader.illuminatePoint() does nothing here
00059         }
00060     }
00061 
00062     /*
00063      * Translucent objects are rendered after opaque objects.
00064      * TO DO: sort traslucent objects in accord to camera direction
00065      *        and render them begining with the fartherest.
00066      */
00067 
00068     GLboolean        depthMask;
00069     TranslucentObj * pTrObj;
00070 
00071     glEnable(GL_BLEND);
00072     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00073     glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask);
00074     glDepthMask(GL_FALSE);
00075 
00076     while ((pTrObj=translucentObjects.remove(translucentObjects.firstItem()))){
00077         shader.setRenderedShape(pTrObj->pObject,
00078                                 (pTrObj->transformed)?&(pTrObj->trMat):NULL);
00079         delete pTrObj;
00080     }
00081 
00082     glDisable(GL_BLEND);
00083     glDepthMask(depthMask);
00084     
00085     if (_useDisplayList) glEndList();
00086 }
00087 

Generated on Tue Nov 21 15:11:42 2006 for gra by  doxygen 1.4.6