Bläddra i källkod

Enable vertical flips during blit, if requested

BearishSun 9 år sedan
förälder
incheckning
1807ea3adf

+ 4 - 2
Source/BansheeEngine/Include/BsRendererUtility.h

@@ -94,8 +94,9 @@ namespace bs { namespace ct
 		 * @param[in]	texture	Source texture to blit.
 		 * @param[in]	area	Area of the source texture to blit in pixels. If width or height is zero it is assumed
 		 *						the entire texture should be blitted.
+		 * @param[in]	flipUV If true, vertical UV coordinate will be flipped upside down.
 		 */
-		void blit(const SPtr<Texture>& texture, const Rect2I& area = Rect2I::EMPTY);
+		void blit(const SPtr<Texture>& texture, const Rect2I& area = Rect2I::EMPTY, bool flipUV = false);
 
 		/**
 		 * Draws a quad over the entire viewport in normalized device coordinates.
@@ -107,11 +108,12 @@ namespace bs { namespace ct
 		 *								internally.
 		 * @param[in]	numInstances	How many instances of the quad to draw (using instanced rendering). Useful when
 		 *								drawing to 3D textures.
+		 * @param[in]	flipUV			If true, vertical UV coordinate will be flipped upside down.
 		 * 			
 		 * @note	Core thread.
 		 */
 		void drawScreenQuad(const Rect2& uv, const Vector2I& textureSize = Vector2I(1, 1), 
-			UINT32 numInstances = 1);
+			UINT32 numInstances = 1, bool flipUV = false);
 
 		/**
 		 * Draws a quad over the entire viewport in normalized device coordinates.

+ 6 - 7
Source/BansheeEngine/Source/BsRendererUtility.cpp

@@ -251,7 +251,7 @@ namespace bs { namespace ct
 		mesh->_notifyUsedOnGPU();
 	}
 
-	void RendererUtility::blit(const SPtr<Texture>& texture, const Rect2I& area)
+	void RendererUtility::blit(const SPtr<Texture>& texture, const Rect2I& area, bool flipUV)
 	{
 		auto& texProps = texture->getProperties();
 		SPtr<Material> mat;
@@ -273,7 +273,7 @@ namespace bs { namespace ct
 		setPassParams(params);
 
 		Rect2 fArea((float)area.x, (float)area.y, (float)area.width, (float)area.height);
-		if(area.width == 0 || area.height == 0)
+		if (area.width == 0 || area.height == 0)
 		{
 			fArea.x = 0.0f;
 			fArea.y = 0.0f;
@@ -281,18 +281,17 @@ namespace bs { namespace ct
 			fArea.height = (float)texProps.getHeight();
 		}
 
-		drawScreenQuad(fArea);
+		drawScreenQuad(fArea, Vector2I(1, 1), 1, flipUV);
 	}
 
-	void RendererUtility::drawScreenQuad(const Rect2& uv, const Vector2I& textureSize, UINT32 numInstances)
+	void RendererUtility::drawScreenQuad(const Rect2& uv, const Vector2I& textureSize, UINT32 numInstances, bool flipUV)
 	{
 		// Note: Consider drawing the quad using a single large triangle for possibly better performance
 
 		const RenderAPIInfo& rapiInfo = RenderAPI::instance().getAPIInfo();
-
 		Vector3 vertices[4];
 
-		if(rapiInfo.getNDCYAxisDown())
+		if (rapiInfo.getNDCYAxisDown())
 		{
 			vertices[0] = Vector3(-1.0f, -1.0f, 0.0f);
 			vertices[1] = Vector3(1.0f, -1.0f, 0.0f);
@@ -308,7 +307,7 @@ namespace bs { namespace ct
 		}
 
 		Vector2 uvs[4];
-		if (rapiInfo.getUVYAxisUp())
+		if (rapiInfo.getUVYAxisUp() ^ flipUV)
 		{
 			uvs[0] = Vector2(uv.x, uv.y + uv.height);
 			uvs[1] = Vector2(uv.x + uv.width, uv.y + uv.height);