diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2012-07-27 05:36:07 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2012-07-27 05:36:07 +0400 |
commit | 3dd081706a36961d3c09ac2f97a9e2f6fd029635 (patch) | |
tree | 1a37e4367623377119ebd752ceeba5819e4ae666 /source/gameengine/Physics | |
parent | e0f6f0facfd492174953b3e8a05aa71338731ef3 (diff) |
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.
Diffstat (limited to 'source/gameengine/Physics')
4 files changed, 11 insertions, 17 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 8a6fbe7d900..9058c5b9dbd 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -57,7 +57,6 @@ btRaycastVehicle::btVehicleTuning gTuning; #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 @@ struct OcclusionBuffer 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 @@ struct OcclusionBuffer // 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 @@ struct DbvtCullingCallback : btDbvt::ICollide }; static OcclusionBuffer gOcb; -bool CcdPhysicsEnvironment::cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4 *planes, int nplanes, int occlusionRes) +bool CcdPhysicsEnvironment::cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4 *planes, int nplanes, int occlusionRes, const int *viewport, double modelview[16], double projection[16]) { if (!m_cullingTree) return false; @@ -1808,7 +1802,7 @@ bool CcdPhysicsEnvironment::cullingTest(PHY_CullingCallback callback, void* user // if occlusionRes != 0 => occlusion culling if (occlusionRes) { - gOcb.setup(occlusionRes); + gOcb.setup(occlusionRes, viewport, modelview, projection); dispatcher.m_ocb = &gOcb; // occlusion culling, the direction of the view is taken from the first plan which MUST be the near plane btDbvt::collideOCL(m_cullingTree->m_sets[1].m_root,planes_n,planes_o,planes_n[0],nplanes,dispatcher); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index 8d9c770b8c3..8f26b07badc 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -185,7 +185,7 @@ protected: btTypedConstraint* getConstraintById(int constraintId); virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ); - virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes, int occlusionRes); + virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes, int occlusionRes, const int *viewport, double modelview[16], double projection[16]); //Methods for gamelogic collision/physics callbacks diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h index 9c109168b18..4ddfe4d69e0 100644 --- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h +++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h @@ -73,7 +73,7 @@ public: } virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ); - virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes, int occlusionRes) { return false; } + virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes, int occlusionRes, const int *viewport, double modelview[16], double projection[16]) { return false; } //gamelogic callbacks diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h index 8fde9e289dc..0e26440597a 100644 --- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h +++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h @@ -161,7 +161,7 @@ class PHY_IPhysicsEnvironment //culling based on physical broad phase // the plane number must be set as follow: near, far, left, right, top, botton // the near plane must be the first one and must always be present, it is used to get the direction of the view - virtual bool cullingTest(PHY_CullingCallback callback, void *userData, PHY__Vector4* planeNormals, int planeNumber, int occlusionRes) = 0; + virtual bool cullingTest(PHY_CullingCallback callback, void *userData, PHY__Vector4* planeNormals, int planeNumber, int occlusionRes, const int *viewport, double modelview[16], double projection[16]) = 0; //Methods for gamelogic collision/physics callbacks //todo: |