Revision: 49272
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49272
Author:   moguri
Date:     2012-07-27 01:36:07 +0000 (Fri, 27 Jul 2012)
Log Message:
-----------
The BGE spends a lot of time on glIsEnabled(), glGet, and state changes. This 
gets rid of unnecessary glGet calls for viewport information. Since we're the 
only ones makes calls to glViewport, we can cache the values.

Modified Paths:
--------------
    
branches/soc-2012-swiss_cheese/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
    
branches/soc-2012-swiss_cheese/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h
    
branches/soc-2012-swiss_cheese/source/gameengine/GamePlayer/common/GPC_Canvas.cpp
    
branches/soc-2012-swiss_cheese/source/gameengine/GamePlayer/common/GPC_Canvas.h
    branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Camera.cpp
    branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Dome.cpp
    branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Dome.h
    branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Scene.cpp
    
branches/soc-2012-swiss_cheese/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
    
branches/soc-2012-swiss_cheese/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
    
branches/soc-2012-swiss_cheese/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
    
branches/soc-2012-swiss_cheese/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
    
branches/soc-2012-swiss_cheese/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp
    branches/soc-2012-swiss_cheese/source/gameengine/Rasterizer/RAS_ICanvas.h

Modified: 
branches/soc-2012-swiss_cheese/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
===================================================================
--- 
branches/soc-2012-swiss_cheese/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
       2012-07-26 23:27:36 UTC (rev 49271)
+++ 
branches/soc-2012-swiss_cheese/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
       2012-07-27 01:36:07 UTC (rev 49272)
@@ -44,6 +44,8 @@
        // area boundaries needed for mouse coordinates in Letterbox framing 
mode
        m_area_left = ar->winrct.xmin;
        m_area_top = ar->winrct.ymax;
+
+       glGetIntegerv(GL_VIEWPORT, (GLint*)m_viewport);
 }
 
 KX_BlenderCanvas::~KX_BlenderCanvas()
@@ -166,10 +168,20 @@
        m_area_rect.SetRight(minx + x2);
        m_area_rect.SetTop(miny + y2);
 
+       m_viewport[0] = minx+x1;
+       m_viewport[1] = miny+y1;
+       m_viewport[2] = vp_width;
+       m_viewport[3] = vp_height;
+
        glViewport(minx + x1, miny + y1, vp_width, vp_height);
        glScissor(minx + x1, miny + y1, vp_width, vp_height);
 }
 
+       const int*
+KX_BlenderCanvas::
+GetViewPort() {
+       return m_viewport;
+}
 
 void KX_BlenderCanvas::SetMouseState(RAS_MouseState mousestate)
 {

Modified: 
branches/soc-2012-swiss_cheese/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h
===================================================================
--- 
branches/soc-2012-swiss_cheese/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h
 2012-07-26 23:27:36 UTC (rev 49271)
+++ 
branches/soc-2012-swiss_cheese/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h
 2012-07-27 01:36:07 UTC (rev 49272)
@@ -61,6 +61,7 @@
        /** Rect that defines the area used for rendering,
            relative to the context */
        RAS_Rect m_displayarea;
+       int m_viewport[4];
 
 public:
        /* Construct a new canvas.
@@ -150,6 +151,8 @@
                int x1, int y1,
                int x2, int y2
        );
+               const int*
+       GetViewPort();
 
                void 
        SetMouseState(

Modified: 
branches/soc-2012-swiss_cheese/source/gameengine/GamePlayer/common/GPC_Canvas.cpp
===================================================================
--- 
branches/soc-2012-swiss_cheese/source/gameengine/GamePlayer/common/GPC_Canvas.cpp
   2012-07-26 23:27:36 UTC (rev 49271)
+++ 
branches/soc-2012-swiss_cheese/source/gameengine/GamePlayer/common/GPC_Canvas.cpp
   2012-07-27 01:36:07 UTC (rev 49272)
@@ -62,6 +62,8 @@
        m_displayarea.m_y1 = 0;
        m_displayarea.m_x2 = width;
        m_displayarea.m_y2 = height;
+
+       glGetIntegerv(GL_VIEWPORT, (GLint*)m_viewport);
 }
 
 
@@ -129,12 +131,21 @@
                 */
 #include REAL_GL_MODE
        glEnable(GL_SCISSOR_TEST);
+       
+       m_viewport[0] = x1;
+       m_viewport[1] = y1;
+       m_viewport[2] = x2-x1 + 1;
+       m_viewport[3] = y2-y1 + 1;
 
        glViewport(x1,y1,x2-x1 + 1,y2-y1 + 1);
        glScissor(x1,y1,x2-x1 + 1,y2-y1 + 1);
 #include FAKE_GL_MODE
 };
 
+const int *GPC_Canvas::GetViewPort()
+{
+       return m_viewport;
+}
 
 void GPC_Canvas::ClearBuffer(
        int type

Modified: 
branches/soc-2012-swiss_cheese/source/gameengine/GamePlayer/common/GPC_Canvas.h
===================================================================
--- 
branches/soc-2012-swiss_cheese/source/gameengine/GamePlayer/common/GPC_Canvas.h 
    2012-07-26 23:27:36 UTC (rev 49271)
+++ 
branches/soc-2012-swiss_cheese/source/gameengine/GamePlayer/common/GPC_Canvas.h 
    2012-07-27 01:36:07 UTC (rev 49272)
@@ -91,6 +91,8 @@
         * relative to the context */
        RAS_Rect m_displayarea;
 
+       int *m_viewport;
+
        /** Storage for the banners to display. */
        TBannerMap m_banners;
        /** State of banner display. */
@@ -154,6 +156,7 @@
        );
        
        void SetViewPort(int x1, int y1, int x2, int y2);
+       const int *GetViewPort();
 
        void ClearColor(float r, float g, float b, float a);
 

Modified: branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Camera.cpp
===================================================================
--- branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Camera.cpp       
2012-07-26 23:27:36 UTC (rev 49271)
+++ branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Camera.cpp       
2012-07-27 01:36:07 UTC (rev 49272)
@@ -956,7 +956,7 @@
                }
        }
 
-       GLint viewport[4];
+       const GLint *viewport;
        GLdouble win[3];
        GLdouble modelmatrix[16];
        GLdouble projmatrix[16];
@@ -967,7 +967,7 @@
        m_modelmatrix.getValue(modelmatrix);
        m_projmatrix.getValue(projmatrix);
 
-       glGetIntegerv(GL_VIEWPORT, viewport);
+       viewport = KX_GetActiveEngine()->GetCanvas()->GetViewPort();
 
        gluProject(vect[0], vect[1], vect[2], modelmatrix, projmatrix, 
viewport, &win[0], &win[1], &win[2]);
 
@@ -999,7 +999,7 @@
        MT_Vector3 vect;
        MT_Point3 campos, screenpos;
 
-       GLint viewport[4];
+       const GLint *viewport;
        GLdouble win[3];
        GLdouble modelmatrix[16];
        GLdouble projmatrix[16];
@@ -1010,7 +1010,7 @@
        m_modelmatrix.getValue(modelmatrix);
        m_projmatrix.getValue(projmatrix);
 
-       glGetIntegerv(GL_VIEWPORT, viewport);
+       viewport = KX_GetActiveEngine()->GetCanvas()->GetViewPort();
 
        vect[0] = x * viewport[2];
        vect[1] = y * viewport[3];

Modified: branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Dome.cpp
===================================================================
--- branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Dome.cpp 
2012-07-26 23:27:36 UTC (rev 49271)
+++ branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Dome.cpp 
2012-07-27 01:36:07 UTC (rev 49272)
@@ -91,8 +91,7 @@
        }
 
        //setting the viewport size
-       GLuint  viewport[4]={0};
-       glGetIntegerv(GL_VIEWPORT,(GLint *)viewport);
+       const int *viewport = m_canvas->GetViewPort();
 
        SetViewPort(viewport);
 
@@ -179,7 +178,7 @@
                glDeleteLists(dlistId, (GLsizei) m_numimages);
 }
 
-void KX_Dome::SetViewPort(GLuint viewport[4])
+void KX_Dome::SetViewPort(const int *viewport)
 {
        if (canvaswidth != m_viewport.GetWidth() || canvasheight != 
m_viewport.GetHeight())
        {

Modified: branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Dome.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Dome.h   
2012-07-26 23:27:36 UTC (rev 49271)
+++ branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Dome.h   
2012-07-27 01:36:07 UTC (rev 49272)
@@ -119,7 +119,7 @@
        void RenderDomeFrame(KX_Scene* scene, KX_Camera* cam, int i);
        void BindImages(int i);
 
-       void SetViewPort(GLuint viewport[4]);
+       void SetViewPort(const int *viewport);
        void CalculateFrustum(KX_Camera* cam);
        void RotateCamera(KX_Camera* cam, int i);
 

Modified: 
branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
===================================================================
--- branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_KetsjiEngine.cpp 
2012-07-26 23:27:36 UTC (rev 49271)
+++ branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_KetsjiEngine.cpp 
2012-07-27 01:36:07 UTC (rev 49272)
@@ -279,8 +279,7 @@
 
 void KX_KetsjiEngine::RenderDome()
 {
-       GLuint  viewport[4]={0};
-       glGetIntegerv(GL_VIEWPORT,(GLint *)viewport);
+       const GLint *viewport = m_canvas->GetViewPort();
        
        m_dome->SetViewPort(viewport);
 

Modified: branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
--- branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Scene.cpp        
2012-07-26 23:27:36 UTC (rev 49271)
+++ branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_Scene.cpp        
2012-07-27 01:36:07 UTC (rev 49272)
@@ -1484,7 +1484,15 @@
                planes[4].setValue(cplanes[2].getValue());      // top
                planes[5].setValue(cplanes[3].getValue());      // bottom
                CullingInfo info(layer);
-               dbvt_culling = 
m_physicsEnvironment->cullingTest(PhysicsCullingCallback,&info,planes,5,m_dbvt_occlusion_res);
+
+               double mvmat[16] = {0};
+               cam->GetModelviewMatrix().getValue(mvmat);
+               double pmat[16] = {0};
+               cam->GetProjectionMatrix().getValue(pmat);
+
+               dbvt_culling = 
m_physicsEnvironment->cullingTest(PhysicsCullingCallback,&info,planes,5,m_dbvt_occlusion_res,
+                                                                               
                                
KX_GetActiveEngine()->GetCanvas()->GetViewPort(),
+                                                                               
                                mvmat, pmat);
        }
        if (!dbvt_culling) {
                // the physics engine couldn't help us, do it the hard way

Modified: 
branches/soc-2012-swiss_cheese/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
===================================================================
--- 
branches/soc-2012-swiss_cheese/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
   2012-07-26 23:27:36 UTC (rev 49271)
+++ 
branches/soc-2012-swiss_cheese/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
   2012-07-27 01:36:07 UTC (rev 49272)
@@ -57,7 +57,6 @@
 #include "LinearMath/btAabbUtil2.h"
 #include "MT_Matrix4x4.h"
 #include "MT_Vector3.h"
-#include <GL/glew.h>
 
 #ifdef WIN32
 void DrawRasterizerLine(const float* from,const float* to,int color);
@@ -1305,22 +1304,19 @@
                m[14] = btScalar(m1[ 2]*m2[12]+m1[ 
6]*m2[13]+m1[10]*m2[14]+m1[14]*m2[15]);
                m[15] = btScalar(m1[ 3]*m2[12]+m1[ 
7]*m2[13]+m1[11]*m2[14]+m1[15]*m2[15]);
        }
-       void            setup(int size)
+       void            setup(int size, const int *view, double modelview[16], 
double projection[16])
        {
                m_initialized=false;
                m_occlusion=false;
                // compute the size of the buffer
-               GLint           v[4];
-               GLdouble        m[16],p[16];
                int                     maxsize;
                double          ratio;
-               glGetIntegerv(GL_VIEWPORT,v);
-               maxsize = (v[2] > v[3]) ? v[2] : v[3];
+               maxsize = (view[2] > view[3]) ? view[2] : view[3];
                assert(maxsize > 0);
                ratio = 1.0/(2*maxsize);
                // ensure even number
-               m_sizes[0] = 2*((int)(size*v[2]*ratio+0.5));
-               m_sizes[1] = 2*((int)(size*v[3]*ratio+0.5));
+               m_sizes[0] = 2*((int)(size*view[2]*ratio+0.5));
+               m_sizes[1] = 2*((int)(size*view[3]*ratio+0.5));
                m_scales[0]=btScalar(m_sizes[0]/2);
                m_scales[1]=btScalar(m_sizes[1]/2);
                m_offsets[0]=m_scales[0]+0.5f;
@@ -1328,10 +1324,8 @@
                // prepare matrix
                // at this time of the rendering, the modelview matrix is the 
                // world to camera transformation and the projection matrix is
-               // camera to clip transformation. combine both so that 
-               glGetDoublev(GL_MODELVIEW_MATRIX,m);
-               glGetDoublev(GL_PROJECTION_MATRIX,p);
-               CMmat4mul(m_wtc,p,m);
+               // camera to clip transformation. combine both so that
+               CMmat4mul(m_wtc, projection, modelview);
        }
        void            initialize()
        {
@@ -1791,7 +1785,7 @@
 };
 
 static OcclusionBuffer gOcb;
-bool CcdPhysicsEnvironment::cullingTest(PHY_CullingCallback callback, void* 
userData, PHY__Vector4 *planes, int nplanes, int occlusionRes)

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to