Procházet zdrojové kódy

Bugfix: Object picking in editor scene view now works properly on OpenGL

BearishSun před 8 roky
rodič
revize
b9a107bd99

+ 17 - 37
Source/BansheeEditor/SceneView/BsScenePicking.cpp

@@ -401,50 +401,30 @@ namespace bs
 
 
 		outputTexture->readData(*outputPixelData);
 		outputTexture->readData(*outputPixelData);
 
 
-		Map<UINT32, UINT32> selectionScores;
-		UINT32 maxWidth = std::min((UINT32)(position.x + area.x), outputPixelData->getWidth());
-		UINT32 maxHeight = std::min((UINT32)(position.y + area.y), outputPixelData->getHeight());
 
 
-		if (rtProps.requiresTextureFlipping)
-		{
-			UINT32 vertOffset = outputPixelData->getHeight();
+		Vector2I pickPosition = position;
+		if(rtProps.requiresTextureFlipping)
+			pickPosition.y = rtProps.height - (position.y + area.y);
 
 
-			for (UINT32 y = maxHeight; y > (UINT32)position.y; y--)
-			{
-				for (UINT32 x = (UINT32)position.x; x < maxWidth; x++)
-				{
-					Color color = outputPixelData->getColorAt(x, vertOffset - y);
-					UINT32 index = bs::ScenePicking::decodeIndex(color);
+		UINT32 maxWidth = std::min((UINT32)(pickPosition.x + area.x), outputPixelData->getWidth());
+		UINT32 maxHeight = std::min((UINT32)(pickPosition.y + area.y), outputPixelData->getHeight());
 
 
-					if (index == 0x00FFFFFF) // Nothing selected
-						continue;
-
-					auto iterFind = selectionScores.find(index);
-					if (iterFind == selectionScores.end())
-						selectionScores[index] = 1;
-					else
-						iterFind->second++;
-				}
-			}
-		}
-		else
+		Map<UINT32, UINT32> selectionScores;
+		for (UINT32 y = (UINT32)pickPosition.y; y < maxHeight; y++)
 		{
 		{
-			for (UINT32 y = (UINT32)position.y; y < maxHeight; y++)
+			for (UINT32 x = (UINT32)pickPosition.x; x < maxWidth; x++)
 			{
 			{
-				for (UINT32 x = (UINT32)position.x; x < maxWidth; x++)
-				{
-					Color color = outputPixelData->getColorAt(x, y);
-					UINT32 index = bs::ScenePicking::decodeIndex(color);
+				Color color = outputPixelData->getColorAt(x, y);
+				UINT32 index = bs::ScenePicking::decodeIndex(color);
 
 
-					if (index == 0x00FFFFFF) // Nothing selected
-						continue;
+				if (index == 0x00FFFFFF) // Nothing selected
+					continue;
 
 
-					auto iterFind = selectionScores.find(index);
-					if (iterFind == selectionScores.end())
-						selectionScores[index] = 1;
-					else
-						iterFind->second++;
-				}
+				auto iterFind = selectionScores.find(index);
+				if (iterFind == selectionScores.end())
+					selectionScores[index] = 1;
+				else
+					iterFind->second++;
 			}
 			}
 		}
 		}
 
 

+ 5 - 6
Source/BansheeGLRenderAPI/BsGLRenderAPI.cpp

@@ -1779,16 +1779,15 @@ namespace bs { namespace ct
 		if (mActiveRenderTarget == nullptr)
 		if (mActiveRenderTarget == nullptr)
 			return;
 			return;
 
 
-		// Calculate the "lower-left" corner of the viewport
-		GLsizei x = 0, y = 0, w = 0, h = 0;
-
+		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
+		GLsizei x, y, w, h;
 		if (enable)
 		if (enable)
 		{
 		{
 			glEnable(GL_SCISSOR_TEST);
 			glEnable(GL_SCISSOR_TEST);
 			BS_CHECK_GL_ERROR();
 			BS_CHECK_GL_ERROR();
 
 
 			x = mScissorLeft;
 			x = mScissorLeft;
-			y = mScissorTop;
+			y = rtProps.height - mScissorBottom;
 			w = mScissorRight - mScissorLeft;
 			w = mScissorRight - mScissorLeft;
 			h = mScissorBottom - mScissorTop;
 			h = mScissorBottom - mScissorTop;
 
 
@@ -1801,10 +1800,10 @@ namespace bs { namespace ct
 			BS_CHECK_GL_ERROR();
 			BS_CHECK_GL_ERROR();
 
 
 			// GL requires you to reset the scissor when disabling
 			// GL requires you to reset the scissor when disabling
+			x = mViewportLeft;
+			y = rtProps.height - (mViewportTop + mViewportHeight); 
 			w = mViewportWidth;
 			w = mViewportWidth;
 			h = mViewportHeight;
 			h = mViewportHeight;
-			x = mViewportLeft;
-			y = mViewportTop; 
 
 
 			glScissor(x, y, w, h);
 			glScissor(x, y, w, h);
 			BS_CHECK_GL_ERROR();
 			BS_CHECK_GL_ERROR();