2
0
Эх сурвалжийг харах

Bugfix: Properly create depth-stencil cubemaps when using the OpenGL 4.1 feature-set

BearishSun 7 жил өмнө
parent
commit
c3a61d2d7e

+ 1 - 1
Source/BansheeCore/Managers/BsTextureManager.cpp

@@ -85,7 +85,7 @@ namespace bs
 	namespace ct
 	namespace ct
 	{
 	{
 	void TextureManager::onStartUp()
 	void TextureManager::onStartUp()
-    {
+	{
 		TEXTURE_DESC desc;
 		TEXTURE_DESC desc;
 		desc.type = TEX_TYPE_2D;
 		desc.type = TEX_TYPE_2D;
 		desc.width = 2;
 		desc.width = 2;

+ 11 - 23
Source/BansheeGLRenderAPI/BsGLRenderAPI.cpp

@@ -342,10 +342,12 @@ namespace bs { namespace ct
 				// Set stencil buffer options
 				// Set stencil buffer options
 				setStencilCheckEnabled(stateProps.getStencilEnable());
 				setStencilCheckEnabled(stateProps.getStencilEnable());
 
 
-				setStencilBufferOperations(stateProps.getStencilFrontFailOp(), stateProps.getStencilFrontZFailOp(), stateProps.getStencilFrontPassOp(), true);
+				setStencilBufferOperations(stateProps.getStencilFrontFailOp(), stateProps.getStencilFrontZFailOp(), 
+					stateProps.getStencilFrontPassOp(), true);
 				setStencilBufferFunc(stateProps.getStencilFrontCompFunc(), stateProps.getStencilReadMask(), true);
 				setStencilBufferFunc(stateProps.getStencilFrontCompFunc(), stateProps.getStencilReadMask(), true);
 
 
-				setStencilBufferOperations(stateProps.getStencilBackFailOp(), stateProps.getStencilBackZFailOp(), stateProps.getStencilBackPassOp(), false);
+				setStencilBufferOperations(stateProps.getStencilBackFailOp(), stateProps.getStencilBackZFailOp(), 
+					stateProps.getStencilBackPassOp(), false);
 				setStencilBufferFunc(stateProps.getStencilBackCompFunc(), stateProps.getStencilReadMask(), false);
 				setStencilBufferFunc(stateProps.getStencilBackCompFunc(), stateProps.getStencilReadMask(), false);
 
 
 				setStencilBufferWriteMask(stateProps.getStencilWriteMask());
 				setStencilBufferWriteMask(stateProps.getStencilWriteMask());
@@ -2433,17 +2435,7 @@ namespace bs { namespace ct
 
 
 		GLRTTManager::startUp<GLRTTManager>();
 		GLRTTManager::startUp<GLRTTManager>();
 
 
-		UINT32 curTexUnitOffset = 0;
-		for (UINT32 i = 0; i < 6; i++)
-			curTexUnitOffset += caps->getNumTextureUnits((GpuProgramType)i);
-
-		UINT32 totalNumTexUnits = curTexUnitOffset;
-		UINT16 numCombinedTexUnits = caps->getNumCombinedTextureUnits();
-
-		if (totalNumTexUnits > numCombinedTexUnits)
-			BS_EXCEPT(InternalErrorException, "Number of combined texture units less than the number of individual units!?");
-
-		mNumTextureUnits = numCombinedTexUnits;
+		mNumTextureUnits = caps->getNumCombinedTextureUnits();
 		mTextureInfos = bs_newN<TextureInfo>(mNumTextureUnits);
 		mTextureInfos = bs_newN<TextureInfo>(mNumTextureUnits);
 		for (UINT16 i = 0; i < mNumTextureUnits; i++)
 		for (UINT16 i = 0; i < mNumTextureUnits; i++)
 			mTextureInfos[i].type = GL_TEXTURE_2D;
 			mTextureInfos[i].type = GL_TEXTURE_2D;
@@ -2454,21 +2446,17 @@ namespace bs { namespace ct
 
 
 	void GLRenderAPI::switchContext(const SPtr<GLContext>& context, const RenderWindow& window)
 	void GLRenderAPI::switchContext(const SPtr<GLContext>& context, const RenderWindow& window)
 	{
 	{
-		// Unbind GPU programs and rebind to new context later, because
-		// scene manager treat render system as ONE 'context' ONLY, and it
-		// cached the GPU programs using state.
+		// Unbind pipeline and rebind to new context later	
 		setGraphicsPipeline(nullptr);
 		setGraphicsPipeline(nullptr);
 
 
-		// It's ready for switching
 		if (mCurrentContext)
 		if (mCurrentContext)
 			mCurrentContext->endCurrent();
 			mCurrentContext->endCurrent();
 
 
 		mCurrentContext = context;
 		mCurrentContext = context;
 		mCurrentContext->setCurrent(window);
 		mCurrentContext->setCurrent(window);
 
 
-		// Must reset depth/colour write mask to according with user desired, otherwise,
-		// clearFrameBuffer would be wrong because the value we recorded may be
-		// different from the real state stored in GL context.
+		// Must reset depth/colour write mask to according with user desired, otherwise, clearFrameBuffer would be wrong 
+		// because the value we recorded may be different from the real state stored in GL context.
 		glDepthMask(mDepthWrite);
 		glDepthMask(mDepthWrite);
 		BS_CHECK_GL_ERROR();
 		BS_CHECK_GL_ERROR();
 
 
@@ -2495,12 +2483,12 @@ namespace bs { namespace ct
 		driverVersion.build = 0;
 		driverVersion.build = 0;
 
 
 		caps.setDriverVersion(driverVersion);
 		caps.setDriverVersion(driverVersion);
+		caps.setRenderAPIName(getName());
+
 		const char* deviceName = (const char*)glGetString(GL_RENDERER);
 		const char* deviceName = (const char*)glGetString(GL_RENDERER);
-		const char* vendorName = (const char*)glGetString(GL_VENDOR);
 		caps.setDeviceName(deviceName);
 		caps.setDeviceName(deviceName);
-		caps.setRenderAPIName(getName());
 
 
-		// determine vendor
+		const char* vendorName = (const char*)glGetString(GL_VENDOR);
 		if (strstr(vendorName, "NVIDIA"))
 		if (strstr(vendorName, "NVIDIA"))
 			caps.setVendor(GPU_NVIDIA);
 			caps.setVendor(GPU_NVIDIA);
 		else if (strstr(vendorName, "ATI"))
 		else if (strstr(vendorName, "ATI"))

+ 30 - 7
Source/BansheeGLRenderAPI/BsGLTexture.cpp

@@ -171,20 +171,43 @@ namespace bs { namespace ct
 				break;
 				break;
 			}
 			}
 #else
 #else
-			if((usage & TU_DEPTHSTENCIL) != 0 && mProperties.getTextureType() == TEX_TYPE_2D)
-			{
+			if((usage & TU_DEPTHSTENCIL) != 0)
+			{ 
 				GLenum depthStencilType = GLPixelUtil::getDepthStencilTypeFromPF(mInternalFormat);
 				GLenum depthStencilType = GLPixelUtil::getDepthStencilTypeFromPF(mInternalFormat);
 				GLenum depthStencilFormat = GLPixelUtil::getDepthStencilFormatFromPF(mInternalFormat);
 				GLenum depthStencilFormat = GLPixelUtil::getDepthStencilFormatFromPF(mInternalFormat);
 
 
-				if (numFaces <= 1)
+				if(texType == TEX_TYPE_2D)
+				{
+					if (numFaces <= 1)
+					{
+						glTexImage2D(GL_TEXTURE_2D, 0, mGLFormat, width, height, 0,
+							depthStencilFormat, depthStencilType, nullptr);
+					}
+					else
+					{
+						glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, mGLFormat, width, height, numFaces, 0,
+							depthStencilFormat, depthStencilType, nullptr);
+					}
+				}
+				else if(texType == TEX_TYPE_CUBE_MAP)
 				{
 				{
-					glTexImage2D(GL_TEXTURE_2D, 0, mGLFormat, width, height, 0,
-						depthStencilFormat, depthStencilType, nullptr);
+					if (numFaces <= 6)
+					{
+						for (UINT32 face = 0; face < 6; face++)
+						{
+							glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, mGLFormat,
+								width, height, 0, depthStencilFormat, depthStencilType, nullptr);
+						}
+					}
+					else
+					{
+						glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, mGLFormat,
+							width, height, numFaces, 0, depthStencilFormat, depthStencilType, nullptr);
+					}
 				}
 				}
 				else
 				else
 				{
 				{
-					glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, mGLFormat, width, height, numFaces, 0,
-						depthStencilFormat, depthStencilType, nullptr);
+					LOGERR("Unsupported texture type for depth-stencil attachment usage.");
 				}
 				}
 			}
 			}
 			else
 			else