[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19393] branches/ge_dome/source/gameengine /Ketsji: missing files from last review
Dalai Felinto
dfelinto at gmail.com
Tue Mar 24 06:49:44 CET 2009
Revision: 19393
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19393
Author: dfelinto
Date: 2009-03-24 06:49:42 +0100 (Tue, 24 Mar 2009)
Log Message:
-----------
missing files from last review
Modified Paths:
--------------
branches/ge_dome/source/gameengine/Ketsji/KX_Dome.cpp
Added Paths:
-----------
branches/ge_dome/source/gameengine/Ketsji/KX_Dome.h
Property Changed:
----------------
branches/ge_dome/source/gameengine/Ketsji/KX_Dome.cpp
Modified: branches/ge_dome/source/gameengine/Ketsji/KX_Dome.cpp
===================================================================
--- branches/ge_dome/source/gameengine/Ketsji/KX_Dome.cpp 2009-03-24 05:43:20 UTC (rev 19392)
+++ branches/ge_dome/source/gameengine/Ketsji/KX_Dome.cpp 2009-03-24 05:49:42 UTC (rev 19393)
@@ -1,1766 +1,1766 @@
-/* $Id$
------------------------------------------------------------------------------
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU Lesser General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place - Suite 330, Boston, MA 02111-1307, USA, or go to
-http://www.gnu.org/copyleft/lesser.txt.
-
-Contributor(s): Dalai Felinto
-
-This code is originally inspired on some of the ideas and codes from Paul Bourke.
-Developed as part of a Research and Development project for SAT - La Soci\xE9t\xE9 des arts technologiques.
------------------------------------------------------------------------------
-*/
-
-#include <PyObjectPlus.h>
-#include <structmember.h>
-#include <float.h>
-#include <math.h>
-
-
-#include <BIF_gl.h>
-
-#include "KX_PythonInit.h"
-#include "DNA_scene_types.h"
-#include "RAS_CameraData.h"
-#include "BLI_arithb.h"
-
-#include "KX_Dome.h"
-
-#include "GL/glew.h"
-#include "GPU_extensions.h"
-#include "GL/glu.h" //XXX temporary, I don't think Blender can use glu.h in its files!!!
-
-// constructor
-KX_Dome::KX_Dome (
- RAS_ICanvas* canvas,
- /// rasterizer
- RAS_IRasterizer* rasterizer,
- /// render tools
- RAS_IRenderTools* rendertools,
- /// engine
- KX_KetsjiEngine* engine,
-
- float size, //size for adjustments
- short res, //resolution
- short mode, //mode - fisheye, truncated, warped, panoramic, ...
- short angle
-// float offset //offset distance of the camera
-
-):
- m_canvas(canvas),
- m_rasterizer(rasterizer),
- m_rendertools(rendertools),
- m_engine(engine),
- m_clip(100.f),
- m_drawingmode(engine->GetDrawType()),
- m_size(size),
- m_resolution(res),
- m_mode(mode),
- m_angle(angle)
-// m_offset(offset)
-
-{
- if (mode > DOME_NUM_MODES)
- m_mode = DOME_FISHEYE;
-
- //setting the viewport size
- GLuint viewport[4]={0};
- glGetIntegerv(GL_VIEWPORT,(GLint *)viewport);
-
- SetViewPort(viewport);
- CalculateImageSize(); //it could be called from m_dome->SetViewPort()
-
- //4 == 180\xBA; 5 == 250\xBA; 6 == 360\xBA
- m_numfaces = 5;
-// if (m_angle > 250)
-// m_angle = 250;
-
- switch(m_mode){
- case DOME_FISHEYE:
- if (m_angle <= 180){
- cubetop.resize(1);
- cubebottom.resize(1);
- cubeleft.resize(2);
- cuberight.resize(2);
-
- CreateMeshDome180(m_resolution);
- m_numfaces = 4;
- }else if (m_angle > 180 && m_angle <= 250){
- cubetop.resize(2);
- cubebottom.resize(2);
- cubeleft.resize(2);
- cubefront.resize(2);
- cuberight.resize(2);
-
- CreateMeshDome250(m_resolution);
- m_numfaces = 5;
- }else{
- cubetop.resize(2);
- cubebottom.resize(2);
- cubeleft.resize(2);
- cubefront.resize(2);
- cuberight.resize(2);
- cubeback.resize(2);
-
- CreateMeshDome250(m_resolution);
- m_numfaces = 6;
- }
- break;
- case DOME_TRUNCATED:
- cubetop.resize(1);
- cubebottom.resize(1);
- cubeleft.resize(2);
- cuberight.resize(2);
-
- m_angle = 180;
- CreateMeshDome180(m_resolution);
- m_numfaces = 4;
- break;
- case DOME_PANORAM_SPH:
- cubeleft.resize(2);
- cubeleftback.resize(2);
- cuberight.resize(2);
- cuberightback.resize(2);
-
- m_angle = 360;
- CreateMeshPanorama();
- m_numfaces = 4;
- break;
- case DOME_OFFSET:
- //the same as DOME_FISHEYE > 250\xBA
- cubetop.resize(2);
- cubebottom.resize(2);
- cubeleft.resize(2);
- cubefront.resize(2);
- cuberight.resize(2);
- cubeback.resize(2);
-
-// m_offset = 0.99;
- m_angle = 360;
- CreateMeshDome250(m_resolution);
- m_numfaces = 6;
- break;
- default: // temporary
- cubetop.resize(1);
- cubebottom.resize(1);
- cubeleft.resize(2);
- cuberight.resize(2);
- m_numfaces = 4;
- break;
- }
-
- CalculateCameraOrientation();
-
- CreateGLImages();
- //openGL check
- //XXX to-do: check if fbo and display list are supported
- if(GLEW_VERSION_1_1)
- dlistSupported=true;
-
- if(GPU_extensions_minimum_support())
- fboSupported=true;
-
- fboSupported = false;//not implemented yet
-
- if(fboSupported)
- CreateFBO();
-
- if(dlistSupported)
- CreateDL();
-}
-
-// destructor
-KX_Dome::~KX_Dome (void)
-{
-// if(glIsTexture(domefacesId[0]))
- glDeleteTextures(m_numfaces, (GLuint*)&domefacesId);
-
- // clean up FBO, RBO
- if(fboSupported)
- {
- //XXX fix it
- for (int i=0; i< m_numfaces;i++){
- glDeleteFramebuffersEXT(m_numfaces, &fboId[0]);
- glDeleteRenderbuffersEXT(m_numfaces, &rboId[0]);
- }
- }
- if(dlistSupported)
- glDeleteLists(dlistId, (GLsizei) m_numfaces);
-}
-
-void KX_Dome::CreateGLImages(){
- glGenTextures(m_numfaces, (GLuint*)&domefacesId);
-
- for (int j=0;j<m_numfaces;j++){
- glBindTexture(GL_TEXTURE_2D, domefacesId[j]);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, m_imagesize, m_imagesize, 0, GL_RGBA,
- GL_UNSIGNED_BYTE, 0);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- }
-}
-
-void KX_Dome::CalculateImageSize(void)
-{
- // find the closest power of 2 smaller than the viewport size
- // this is a cheap solution when FBO is not supported
-
- short canvaswidth = m_canvas->GetWidth();
- short canvasheight = m_canvas->GetHeight();
- short texturewidth=0, textureheight =0;
-
- GLint i;
- i = 0;
- while ((1 << i) < canvaswidth)
- i++;
- texturewidth = (1 << (i-1));
-
- // Now for height
- i = 0;
- while ((1 << i) < canvasheight)
- i++;
- textureheight = (1 << (i-1));
-
- m_imagesize = (texturewidth > textureheight?textureheight:texturewidth);
-}
-
-/*
-void KX_Dome::CalculateImageSize(void)
-{
- // higher resolution than the uncommented CalculateImageSize function. Using non-power of 2 textures. not using it
-
- short canvas_width = m_viewport.GetWidth();
- short canvas_height = m_viewport.GetHeight();
-
- m_imagesize = (canvas_width > canvas_height?canvas_height:canvas_width);
-}
-//*/
-void KX_Dome::CreateFBO(){
-// not using it right now. I had performance issues when trying to use that. I should try again later.
-// create a framebuffer object, you need to delete them when program exits.
-
- glGenFramebuffersEXT(m_numfaces, &fboId[0]);
- glGenRenderbuffersEXT(m_numfaces, &rboId[0]);
-
- for (int i=0;i<m_numfaces;i++){
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId[i]);
-
- // create a renderbuffer object to store depth info
- // NOTE: A depth renderable image should be attached the FBO for depth test.
- // If we don't attach a depth renderable image to the FBO, then
- // the rendering output will be corrupted because of missing depth test.
- // If you also need stencil test for your rendering, then you must
- // attach additional image to the stencil attachement point, too.
-// glGenRenderbuffersEXT(1, &rboId);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboId[i]);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, m_imagesize, m_imagesize);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
-
- // attach a texture to FBO color attachment
- // I wanna change this per render, pre bindimage I guess
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, domefacesId[i], 0);
-
- // attach a renderbuffer to depth attachment point
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboId[i]);
-
- //@ disable color buffer if you don't attach any color buffer image,
- //@ for example, rendering depth buffer only to a texture.
- //@ Otherwise, glCheckFramebufferStatusEXT will not be complete.
- //glDrawBuffer(GL_NONE);
- //glReadBuffer(GL_NONE);
-
- // check FBO status
- /*
- printFramebufferInfo();
- bool status = checkFramebufferStatus();
- if(!status)
- fboUsed = false;
- */
- }
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-}
-
-void KX_Dome::CreateDL(){
- int i,j;
-
- dlistId = glGenLists((GLsizei) m_numfaces);
- if (dlistId != 0) {
- if(m_mode == DOME_FISHEYE || m_mode == DOME_TRUNCATED || m_mode == DOME_WARPED || m_mode == DOME_OFFSET){
- glNewList(dlistId, GL_COMPILE);
- GLDrawTriangles(cubetop, nfacestop);
- glEndList();
-
- glNewList(dlistId+1, GL_COMPILE);
- GLDrawTriangles(cubebottom, nfacesbottom);
- glEndList();
-
- glNewList(dlistId+2, GL_COMPILE);
- GLDrawTriangles(cubeleft, nfacesleft);
- glEndList();
-
- glNewList(dlistId+3, GL_COMPILE);
- GLDrawTriangles(cuberight, nfacesright);
- glEndList();
-
- if (m_angle > 180){
- glNewList(dlistId+4, GL_COMPILE);
- GLDrawTriangles(cubefront, nfacesfront);
- glEndList();
- }
- }
- else if (m_mode == DOME_PANORAM_SPH){
- glNewList(dlistId, GL_COMPILE);
- GLDrawTriangles(cubeleft, nfacesleft);
- glEndList();
-
- glNewList(dlistId+1, GL_COMPILE);
- GLDrawTriangles(cuberight, nfacesright);
- glEndList();
-
- glNewList(dlistId+3, GL_COMPILE);
- GLDrawTriangles(cubeleftback, nfacesleftback);
- glEndList();
-
- glNewList(dlistId+2, GL_COMPILE);
- GLDrawTriangles(cuberightback, nfacesrightback);
- glEndList();
- }
-
- //clearing the vectors
- cubetop.clear();
- cubebottom.clear();
- cuberight.clear();
- cubeleft.clear();
- cubefront.clear();
- cubeback.clear();
- cubeleftback.clear();
- cuberightback.clear();
-
- } else // genList failed
- dlistSupported = false;
-}
-
-void KX_Dome::GLDrawTriangles(vector <DomeFace>& face, int nfaces)
-{
- int i,j;
- glBegin(GL_TRIANGLES);
- for (i=0;i<nfaces;i++) {
- for (j=0;j<3;j++) {
- glTexCoord2f(face[i].u[j],face[i].v[j]);
- glVertex3f((GLfloat)face[i].verts[j][0],(GLfloat)face[i].verts[j][1],(GLfloat)face[i].verts[j][2]);
- }
- }
- glEnd();
-}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list