BGE Dome: Truncated Dome are back (Upright and Downright) + GLEW_EXT_framebuffer_obje...
authorDalai Felinto <dfelinto@gmail.com>
Fri, 8 May 2009 18:59:08 +0000 (18:59 +0000)
committerDalai Felinto <dfelinto@gmail.com>
Fri, 8 May 2009 18:59:08 +0000 (18:59 +0000)
After last commit (20099) warping meshes got slower (more quality == less performance). Since we don't need an extra warping for truncated domes, It's better to handle them directly in openGL without the need of warping it.

I'll talk with some Dome owners to see if we need both Upright and Downright modes. I may remove one of them by 2.49 them.

*) also: a proper GLEW_EXT_framebuffer_object check before generating FBO (for warping meshes).

**) next in line (maybe after RC2): tilt option to tilt the camera up to 90º upward.

source/gameengine/Ketsji/KX_Dome.cpp
source/gameengine/Ketsji/KX_Dome.h

index 4a6575ff412a5212d964c696d563a31deaf4558d..a302bf98cb85e80ac4438810af1d04f5174c1821 100644 (file)
@@ -124,6 +124,16 @@ KX_Dome::KX_Dome (
                        CreateMeshPanorama();
                        m_numfaces = 6;
                        break;
+               default: //DOME_TRUNCATED_DOWN and DOME_TRUNCATED_UP
+                       cubetop.resize(1);
+                       cubebottom.resize(1);
+                       cubeleft.resize(2);
+                       cuberight.resize(2);
+
+                       m_angle = 180;
+                       CreateMeshDome180();
+                       m_numfaces = 4;
+                       break;
        }
 
        m_numimages =(warp.usemesh?m_numfaces+1:m_numfaces);
@@ -255,7 +265,7 @@ http://projects.blender.org/tracker/?func=detail&aid=18655&group_id=9&atid=125
 bool KX_Dome::CreateDL(){
        dlistId = glGenLists((GLsizei) m_numimages);
        if (dlistId != 0) {
-               if(m_mode == DOME_FISHEYE){
+               if(m_mode == DOME_FISHEYE || m_mode == DOME_TRUNCATED_UP || m_mode == DOME_TRUNCATED_DOWN){
                        glNewList(dlistId, GL_COMPILE);
                                GLDrawTriangles(cubetop, nfacestop);
                        glEndList();
@@ -329,6 +339,12 @@ bool KX_Dome::CreateDL(){
 
 bool KX_Dome::CreateFBO(void)
 {
+       if (!GLEW_EXT_framebuffer_object)
+       {
+               printf("Dome Error: FrameBuffer unsupported. Using low resolution warp image.");
+               return false;
+       }
+
        glGenFramebuffersEXT(1, &warp.fboId);
        if(warp.fboId==0)
        {
@@ -345,7 +361,7 @@ bool KX_Dome::CreateFBO(void)
 
        if(status == GL_FRAMEBUFFER_UNSUPPORTED_EXT)
        {
-               printf("Dome Error: FrameBuffer unsupported. Using low resolution warp image.");
+               printf("Dome Error: FrameBuffer settings unsupported. Using low resolution warp image.");
                return false;
        }
        else if(status != GL_FRAMEBUFFER_COMPLETE_EXT)
@@ -1469,7 +1485,9 @@ Uses 6 cameras for angles up to 360
        MT_Scalar c = cos(deg45);
        MT_Scalar s = sin(deg45);
 
-       if ((m_mode == DOME_FISHEYE && m_angle <= 180)){
+       if ((m_mode == DOME_FISHEYE && m_angle <= 180)
+               || m_mode == DOME_TRUNCATED_UP 
+               || m_mode == DOME_TRUNCATED_DOWN){
 
                m_locRot[0] = MT_Matrix3x3( // 90º - Top
                                                c, -s, 0.0,
@@ -1597,6 +1615,12 @@ void KX_Dome::Draw(void)
                case DOME_PANORAM_SPH:
                        DrawPanorama();
                        break;
+               case DOME_TRUNCATED_UP:
+                       DrawDomeFisheye();
+                       break;
+               case DOME_TRUNCATED_DOWN:
+                       DrawDomeFisheye();
+                       break;
        }
 
        if(warp.usemesh)
@@ -1760,22 +1784,37 @@ void KX_Dome::DrawDomeFisheye(void)
 
        float ortho_width, ortho_height;
 
-       if (warp.usemesh)
-               glOrtho((-1.0), 1.0, (-1.0), 1.0, -20.0, 10.0); //stretch the image to reduce resolution lost
-
-       else {
-               if (can_width < can_height){
-                       ortho_width = 1.0;
-                       ortho_height = (float)can_height/can_width;
-               }else{
-                       ortho_width = (float)can_width/can_height;
-                       ortho_height = 1.0;
+       if(m_mode == DOME_FISHEYE) {
+               if (warp.usemesh)
+                       glOrtho((-1.0), 1.0, (-1.0), 1.0, -20.0, 10.0); //stretch the image to reduce resolution lost
+
+               else {
+                       if (can_width < can_height){
+                               ortho_width = 1.0;
+                               ortho_height = (float)can_height/can_width;
+                       }else{
+                               ortho_width = (float)can_width/can_height;
+                               ortho_height = 1.0;
+                       }
+                       
+                       ortho_width /= m_size;
+                       ortho_height /= m_size;
+                       
+                       glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_height, -20.0, 10.0);
                }
-               
-               ortho_width /= m_size;
-               ortho_height /= m_size;
-               
-               glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_height, -20.0, 10.0);
+       }
+       else if(m_mode == DOME_TRUNCATED_UP)
+       {
+               ortho_width = 1.0;
+               ortho_height = 2 * ((float)can_height/can_width) - 1.0 ;
+
+               glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_width, -20.0, 10.0);
+       }
+       else { //m_mode == DOME_TRUNCATED_DOWN
+               ortho_width = 1.0;
+               ortho_height = 2 * ((float)can_height/can_width) - 1.0 ;
+
+               glOrtho((-ortho_width), ortho_width, (-ortho_width), ortho_height, -20.0, 10.0);
        }
 
        glMatrixMode(GL_TEXTURE);
index 257172ac21533c196dd9a845215f47a8c635562d..30d02dce7a05ccd16c300a9d924e586ed8f5444f 100644 (file)
@@ -38,13 +38,14 @@ Developed as part of a Research and Development project for SAT - La Soci
 
 #include "MEM_guardedalloc.h"
 #include "BKE_text.h"
-//#include "BLI_blenlib.h"
 
 //Dome modes: limit hardcoded in buttons_scene.c
 #define DOME_FISHEYE           1
 #define DOME_ENVMAP                    2
 #define DOME_PANORAM_SPH       3
-#define DOME_NUM_MODES         4
+#define DOME_TRUNCATED_UP      4
+#define DOME_TRUNCATED_DOWN    5
+#define DOME_NUM_MODES         6
 
 
 /// class for render 3d scene
@@ -118,7 +119,7 @@ public:
        void CalculateFrustum(KX_Camera* cam);
        void RotateCamera(KX_Camera* cam, int i);
 
-       //Mesh  Creating Functions
+       //Mesh creation Functions
        void CreateMeshDome180(void);
        void CreateMeshDome250(void);
        void CreateMeshPanorama(void);