From bccb6e0112f9a0c351fbb1707ee742cee87c0189 Mon Sep 17 00:00:00 2001 From: hybrid Date: Thu, 23 Apr 2009 13:15:39 +0000 Subject: [PATCH] Merged from 1.5 branch revisions 2333:2347. Fix depthbuffer under d3d, renderstates under OpenGL, stencilshadow under OpenGL. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2349 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CD3D9Driver.cpp | 16 +++++++++++++--- source/Irrlicht/CD3D9Driver.h | 7 ++++++- source/Irrlicht/CIrrDeviceWin32.cpp | 2 +- source/Irrlicht/CIrrDeviceWinCE.cpp | 2 +- source/Irrlicht/COpenGLDriver.cpp | 17 +++++++++++++---- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/source/Irrlicht/CD3D9Driver.cpp b/source/Irrlicht/CD3D9Driver.cpp index cef0901a..1028ade5 100644 --- a/source/Irrlicht/CD3D9Driver.cpp +++ b/source/Irrlicht/CD3D9Driver.cpp @@ -439,8 +439,17 @@ bool CD3D9Driver::initDriver(const core::dimension2d& screenSize, // store the screen's depth buffer DepthBuffers.push_back(new SDepthSurface()); - pID3DDevice->GetDepthStencilSurface(&(DepthBuffers[0]->Surface)); - DepthBuffers[0]->Size=ScreenSize; + if (SUCCEEDED(pID3DDevice->GetDepthStencilSurface(&(DepthBuffers[0]->Surface)))) + { + D3DSURFACE_DESC desc; + DepthBuffers[0]->Surface->GetDesc(&desc); + DepthBuffers[0]->Size.set(desc.Width, desc.Height); + } + else + { + os::Printer::log("Was not able to get main depth buffer.", ELL_ERROR); + return false; + } D3DColorFormat = D3DFMT_A8R8G8B8; IDirect3DSurface9* bb=0; @@ -2814,7 +2823,8 @@ void CD3D9Driver::checkDepthBuffer(ITexture* tex) if (SUCCEEDED(hr)) { depth=DepthBuffers.getLast(); - depth->Size=optSize; + depth->Surface->GetDesc(&desc); + depth->Size.set(desc.Width, desc.Height); } else { diff --git a/source/Irrlicht/CD3D9Driver.h b/source/Irrlicht/CD3D9Driver.h index 708d7c67..67c6de42 100644 --- a/source/Irrlicht/CD3D9Driver.h +++ b/source/Irrlicht/CD3D9Driver.h @@ -24,7 +24,12 @@ namespace video { struct SDepthSurface : public IReferenceCounted { - SDepthSurface() : Surface(0) {} + SDepthSurface() : Surface(0) + { + #ifdef _DEBUG + setDebugName("SDepthSurface"); + #endif + } virtual ~SDepthSurface() { if (Surface) diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp index c5e72e00..be9d406a 100644 --- a/source/Irrlicht/CIrrDeviceWin32.cpp +++ b/source/Irrlicht/CIrrDeviceWin32.cpp @@ -278,7 +278,7 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params) WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = (WNDPROC)WndProc; + wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; diff --git a/source/Irrlicht/CIrrDeviceWinCE.cpp b/source/Irrlicht/CIrrDeviceWinCE.cpp index fece1931..e280cd51 100644 --- a/source/Irrlicht/CIrrDeviceWinCE.cpp +++ b/source/Irrlicht/CIrrDeviceWinCE.cpp @@ -297,7 +297,7 @@ CIrrDeviceWinCE::CIrrDeviceWinCE(const SIrrlichtCreationParameters& params) // Register Class WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = (WNDPROC)WndProc; + wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index d59beb6d..1b7cd6c9 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -555,6 +555,10 @@ bool COpenGLDriver::genericDriverInit(const core::dimension2d& screenSize, // create matrix for flipping textures TextureFlipMatrix.buildTextureTransform(0.0f, core::vector2df(0,0), core::vector2df(0,1.0f), core::vector2df(1.0f,-1.0f)); + // We need to reset once more at the beginning of the first rendering. + // This fixes problems with intermediate changes to the material during texture load. + ResetRenderStates = true; + return true; } @@ -2707,20 +2711,23 @@ void COpenGLDriver::drawStencilShadow(bool clearStencilBuffer, video::SColor lef glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); glBegin(GL_QUADS); glColor4ub(leftDownEdge.getRed(), leftDownEdge.getGreen(), leftDownEdge.getBlue(), leftDownEdge.getAlpha()); - glVertex3f(-1.1f,-1.1f,0.9f); + glVertex3f(-1.f,-1.f,-0.9f); glColor4ub(leftUpEdge.getRed(), leftUpEdge.getGreen(), leftUpEdge.getBlue(), leftUpEdge.getAlpha()); - glVertex3f(-1.1f, 1.1f,0.9f); + glVertex3f(-1.f, 1.f,-0.9f); glColor4ub(rightUpEdge.getRed(), rightUpEdge.getGreen(), rightUpEdge.getBlue(), rightUpEdge.getAlpha()); - glVertex3f(1.1f, 1.1f,0.9f); + glVertex3f(1.f, 1.f,-0.9f); glColor4ub(rightDownEdge.getRed(), rightDownEdge.getGreen(), rightDownEdge.getBlue(), rightDownEdge.getAlpha()); - glVertex3f(1.1f,-1.1f,0.9f); + glVertex3f(1.f,-1.f,-0.9f); glEnd(); @@ -2728,6 +2735,8 @@ void COpenGLDriver::drawStencilShadow(bool clearStencilBuffer, video::SColor lef // restore settings glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); glPopAttrib(); }