Procházet zdrojové kódy

OpenGL: Rendering to sRGB texture now properly de-linearizes written values

BearishSun před 9 roky
rodič
revize
e3472f8f9b

+ 2 - 1
Source/BansheeCore/Include/BsRenderTexture.h

@@ -30,7 +30,8 @@ namespace bs
 		virtual ~RenderTextureProperties() { }
 
 	private:
-		void construct(const TextureProperties* textureProps, UINT32 numSlices, UINT32 mipLevel, bool requiresFlipping);
+		void construct(const TextureProperties* textureProps, UINT32 numSlices, UINT32 mipLevel, bool requiresFlipping, 
+					   bool hwGamma);
 
 		friend class ct::RenderTexture;
 		friend class RenderTexture;

+ 51 - 9
Source/BansheeCore/Source/BsRenderTexture.cpp

@@ -12,38 +12,80 @@ namespace bs
 {
 	RenderTextureProperties::RenderTextureProperties(const RENDER_TEXTURE_DESC& desc, bool requiresFlipping)
 	{
+		UINT32 firstIdx = -1;
+		bool requiresHwGamma = false;
 		for (UINT32 i = 0; i < BS_MAX_MULTIPLE_RENDER_TARGETS; i++)
 		{
 			HTexture texture = desc.colorSurfaces[i].texture;
 
+			if (!texture.isLoaded())
+				continue;
+
+			if (firstIdx == -1)
+				firstIdx = i;
+
+			requiresHwGamma |= texture->getProperties().isHardwareGammaEnabled();
+		}
+
+		if (firstIdx == -1)
+		{
+			HTexture texture = desc.depthStencilSurface.texture;
 			if (texture.isLoaded())
 			{
 				const TextureProperties& texProps = texture->getProperties();
-				construct(&texProps, desc.colorSurfaces[i].numFaces, desc.colorSurfaces[i].mipLevel, requiresFlipping);
-
-				break;
+				construct(&texProps, desc.depthStencilSurface.numFaces, desc.depthStencilSurface.mipLevel,
+						  requiresFlipping, false);
 			}
 		}
+		else
+		{
+			HTexture texture = desc.colorSurfaces[firstIdx].texture;
+
+			const TextureProperties& texProps = texture->getProperties();
+			construct(&texProps, desc.colorSurfaces[firstIdx].numFaces, desc.colorSurfaces[firstIdx].mipLevel,
+					  requiresFlipping, requiresHwGamma);
+		}
 	}
 
 	RenderTextureProperties::RenderTextureProperties(const ct::RENDER_TEXTURE_DESC& desc, bool requiresFlipping)
 	{
+		UINT32 firstIdx = -1;
+		bool requiresHwGamma = false;
 		for (UINT32 i = 0; i < BS_MAX_MULTIPLE_RENDER_TARGETS; i++)
 		{
 			SPtr<ct::Texture> texture = desc.colorSurfaces[i].texture;
 
-			if (texture != nullptr)
+			if (texture == nullptr)
+				continue;
+
+			if (firstIdx == -1)
+				firstIdx = i;
+
+			requiresHwGamma |= texture->getProperties().isHardwareGammaEnabled();
+		}
+
+		if(firstIdx == -1)
+		{
+			SPtr<ct::Texture> texture = desc.depthStencilSurface.texture;
+			if(texture != nullptr)
 			{
 				const TextureProperties& texProps = texture->getProperties();
-				construct(&texProps, desc.colorSurfaces[i].numFaces, desc.colorSurfaces[i].mipLevel, requiresFlipping);
-
-				break;
+				construct(&texProps, desc.depthStencilSurface.numFaces, desc.depthStencilSurface.mipLevel, 
+						  requiresFlipping, false);
 			}
 		}
+		else
+		{
+			SPtr<ct::Texture> texture = desc.colorSurfaces[firstIdx].texture;
+
+			const TextureProperties& texProps = texture->getProperties();
+			construct(&texProps, desc.colorSurfaces[firstIdx].numFaces, desc.colorSurfaces[firstIdx].mipLevel, 
+					  requiresFlipping, requiresHwGamma);
+		}
 	}
 
 	void RenderTextureProperties::construct(const TextureProperties* textureProps, UINT32 numSlices, 
-											UINT32 mipLevel, bool requiresFlipping)
+											UINT32 mipLevel, bool requiresFlipping, bool hwGamma)
 	{
 		if (textureProps != nullptr)
 		{
@@ -52,13 +94,13 @@ namespace bs
 
 			mNumSlices *= numSlices;
 			mColorDepth = bs::PixelUtil::getNumElemBits(textureProps->getFormat());
-			mHwGamma = textureProps->isHardwareGammaEnabled();
 			mMultisampleCount = textureProps->getNumSamples();
 		}
 
 		mActive = true;
 		mIsWindow = false;
 		mRequiresTextureFlipping = requiresFlipping;
+		mHwGamma = hwGamma;
 	}
 
 	SPtr<RenderTexture> RenderTexture::create(const TEXTURE_DESC& desc,