Commit 83703b6e authored by hybrid's avatar hybrid

Fix OpenGL user clip plane adaption to view matrix changes.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@943 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 4997e7d7
...@@ -306,6 +306,14 @@ bool COpenGLDriver::genericDriverInit(const core::dimension2d<s32>& screenSize, ...@@ -306,6 +306,14 @@ bool COpenGLDriver::genericDriverInit(const core::dimension2d<s32>& screenSize,
if (AntiAlias && MultiSamplingExtension) if (AntiAlias && MultiSamplingExtension)
glEnable(GL_MULTISAMPLE_ARB); glEnable(GL_MULTISAMPLE_ARB);
UserClipPlane.reallocate(MaxUserClipPlanes);
UserClipPlaneEnabled.reallocate(MaxUserClipPlanes);
for (u32 i=0; i<MaxUserClipPlanes; ++i)
{
UserClipPlane.push_back(core::plane3df());
UserClipPlaneEnabled.push_back(false);
}
// create material renderers // create material renderers
createMaterialRenderers(); createMaterialRenderers();
...@@ -441,10 +449,16 @@ void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matri ...@@ -441,10 +449,16 @@ void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matri
{ {
case ETS_VIEW: case ETS_VIEW:
case ETS_WORLD: case ETS_WORLD:
// OpenGL only has a model matrix, view and world is not existent. so lets fake these two. {
createGLMatrix(glmat, Matrices[ETS_VIEW] * Matrices[ETS_WORLD]); // OpenGL only has a model matrix, view and world is not existent. so lets fake these two.
glMatrixMode(GL_MODELVIEW); createGLMatrix(glmat, Matrices[ETS_VIEW] * Matrices[ETS_WORLD]);
glLoadMatrixf(glmat); glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(glmat);
// we have to update the clip planes to the latest view matrix
for (u32 i=0; i<MaxUserClipPlanes; ++i)
if (UserClipPlaneEnabled[i])
uploadClipPlane(i);
}
break; break;
case ETS_PROJECTION: case ETS_PROJECTION:
createGLMatrix(glmat, mat); createGLMatrix(glmat, mat);
...@@ -2312,17 +2326,21 @@ bool COpenGLDriver::setClipPlane(u32 index, const core::plane3df& plane, bool en ...@@ -2312,17 +2326,21 @@ bool COpenGLDriver::setClipPlane(u32 index, const core::plane3df& plane, bool en
if (index >= MaxUserClipPlanes) if (index >= MaxUserClipPlanes)
return false; return false;
// opengl needs an array of doubles for the plane equation UserClipPlane[index]=plane;
double clip_plane[4];
clip_plane[0] = plane.Normal.X;
clip_plane[1] = plane.Normal.Y;
clip_plane[2] = plane.Normal.Z;
clip_plane[3] = plane.D;
glClipPlane(GL_CLIP_PLANE0 + index, clip_plane);
enableClipPlane(index, enable); enableClipPlane(index, enable);
return true; return true;
} }
void COpenGLDriver::uploadClipPlane(u32 index)
{
// opengl needs an array of doubles for the plane equation
double clip_plane[4];
clip_plane[0] = UserClipPlane[index].Normal.X;
clip_plane[1] = UserClipPlane[index].Normal.Y;
clip_plane[2] = UserClipPlane[index].Normal.Z;
clip_plane[3] = UserClipPlane[index].D;
glClipPlane(GL_CLIP_PLANE0 + index, clip_plane);
}
//! Enable/disable a clipping plane. //! Enable/disable a clipping plane.
//! There are at least 6 clipping planes available for the user to set at will. //! There are at least 6 clipping planes available for the user to set at will.
...@@ -2333,9 +2351,17 @@ void COpenGLDriver::enableClipPlane(u32 index, bool enable) ...@@ -2333,9 +2351,17 @@ void COpenGLDriver::enableClipPlane(u32 index, bool enable)
if (index >= MaxUserClipPlanes) if (index >= MaxUserClipPlanes)
return; return;
if (enable) if (enable)
glEnable(GL_CLIP_PLANE0 + index); {
if (!UserClipPlaneEnabled[index])
{
uploadClipPlane(index);
glEnable(GL_CLIP_PLANE0 + index);
}
}
else else
glDisable(GL_CLIP_PLANE0 + index); glDisable(GL_CLIP_PLANE0 + index);
UserClipPlaneEnabled[index]=enable;
} }
......
...@@ -299,6 +299,8 @@ namespace video ...@@ -299,6 +299,8 @@ namespace video
private: private:
void uploadClipPlane(u32 index);
//! inits the parts of the open gl driver used on all platforms //! inits the parts of the open gl driver used on all platforms
bool genericDriverInit(const core::dimension2d<s32>& screenSize, bool stencilBuffer); bool genericDriverInit(const core::dimension2d<s32>& screenSize, bool stencilBuffer);
//! returns a device dependent texture from a software surface (IImage) //! returns a device dependent texture from a software surface (IImage)
...@@ -341,6 +343,8 @@ namespace video ...@@ -341,6 +343,8 @@ namespace video
COpenGLTexture* RenderTargetTexture; COpenGLTexture* RenderTargetTexture;
ITexture* CurrentTexture[MATERIAL_MAX_TEXTURES]; ITexture* CurrentTexture[MATERIAL_MAX_TEXTURES];
s32 LastSetLight; s32 LastSetLight;
core::array<core::plane3df> UserClipPlane;
core::array<bool> UserClipPlaneEnabled;
core::dimension2d<s32> CurrentRendertargetSize; core::dimension2d<s32> CurrentRendertargetSize;
//! bool to see if we are using clockwise or counter-clockwise winding, //! bool to see if we are using clockwise or counter-clockwise winding,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment