[Bf-blender-cvs] [9bf3c963761] ge_2df_textures: BGE: Fix 1-pixel bug with viewport and aspect ratio.

Benoit Bolsee noreply at git.blender.org
Mon Apr 3 09:31:54 CEST 2017


Commit: 9bf3c963761c6d970a9c222da3091082c9b6f0f5
Author: Benoit Bolsee
Date:   Mon Apr 3 08:46:55 2017 +0200
Branches: ge_2df_textures
https://developer.blender.org/rB9bf3c963761c6d970a9c222da3091082c9b6f0f5

BGE: Fix 1-pixel bug with viewport and aspect ratio.

The canvas viewport is initially set as (0,0,width,height) but treated at
OGL level as (left,bottom,right,top), which differs by 1 pixel.
This was causing a wrong aspect ratio in the render.

===================================================================

M	source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
M	source/gameengine/GamePlayer/common/GPC_Canvas.cpp
M	source/gameengine/Ketsji/KX_Dome.cpp
M	source/gameengine/Rasterizer/RAS_2DFilterManager.cpp
M	source/gameengine/VideoTexture/ImageRender.cpp

===================================================================

diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
index 927b26faf8a..d52812021a1 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
+++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
@@ -210,8 +210,8 @@ SetViewPort(
 	 * the width,height is calculated including both pixels
 	 * therefore: max - min + 1
 	 */
-	int vp_width = (x2 - x1) + 1;
-	int vp_height = (y2 - y1) + 1;
+	int vp_width = (x2 - x1);
+	int vp_height = (y2 - y1);
 	int minx = m_frame_rect.GetLeft();
 	int miny = m_frame_rect.GetBottom();
 
diff --git a/source/gameengine/GamePlayer/common/GPC_Canvas.cpp b/source/gameengine/GamePlayer/common/GPC_Canvas.cpp
index 2b355407d46..b3963e9f8f2 100644
--- a/source/gameengine/GamePlayer/common/GPC_Canvas.cpp
+++ b/source/gameengine/GamePlayer/common/GPC_Canvas.cpp
@@ -97,11 +97,11 @@ void GPC_Canvas::SetViewPort(int x1, int y1, int x2, int y2)
 	
 	m_viewport[0] = x1;
 	m_viewport[1] = y1;
-	m_viewport[2] = x2-x1 + 1;
-	m_viewport[3] = y2-y1 + 1;
+	m_viewport[2] = x2-x1;
+	m_viewport[3] = y2-y1;
 
-	glViewport(x1,y1,x2-x1 + 1,y2-y1 + 1);
-	glScissor(x1,y1,x2-x1 + 1,y2-y1 + 1);
+	glViewport(x1,y1,x2-x1,y2-y1);
+	glScissor(x1,y1,x2-x1,y2-y1);
 }
 
 void GPC_Canvas::UpdateViewPort(int x1, int y1, int x2, int y2)
diff --git a/source/gameengine/Ketsji/KX_Dome.cpp b/source/gameengine/Ketsji/KX_Dome.cpp
index d08372e47d4..878e21d38b2 100644
--- a/source/gameengine/Ketsji/KX_Dome.cpp
+++ b/source/gameengine/Ketsji/KX_Dome.cpp
@@ -2018,7 +2018,7 @@ void KX_Dome::RenderDomeFrame(KX_Scene* scene, KX_Camera* cam, int i)
 	if (!cam)
 		return;
 
-	m_canvas->SetViewPort(0,0,m_buffersize-1,m_buffersize-1);
+	m_canvas->SetViewPort(0,0,m_buffersize,m_buffersize);
 
 //	m_rasterizer->SetAmbient();
 	m_rasterizer->DisplayFog();
diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp
index 780ff9ba13b..6709d7d0997 100644
--- a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp
+++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp
@@ -399,8 +399,8 @@ void RAS_2DFilterManager::SetupTextures(bool depth, bool luminance)
 void RAS_2DFilterManager::UpdateOffsetMatrix(RAS_ICanvas* canvas)
 {
 	/* RAS_Rect canvas_rect = canvas->GetWindowArea(); */ /* UNUSED */
-	texturewidth = canvas->GetWidth()+1;
-	textureheight = canvas->GetHeight()+1;
+	texturewidth = canvas->GetWidth();
+	textureheight = canvas->GetHeight();
 	GLint i,j;
 
 	if (!GL_ARB_texture_non_power_of_two)
@@ -508,8 +508,8 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas)
 
 	glScissor(scissor_rect.GetLeft() + viewport[0],
 	          scissor_rect.GetBottom() + viewport[1],
-	          scissor_rect.GetWidth() + 1,
-	          scissor_rect.GetHeight() + 1);
+	          scissor_rect.GetWidth(),
+	          scissor_rect.GetHeight());
 
 	glDisable(GL_DEPTH_TEST);
 	// in case the previous material was wire
diff --git a/source/gameengine/VideoTexture/ImageRender.cpp b/source/gameengine/VideoTexture/ImageRender.cpp
index 5147cb1fbb1..81721e2d5a4 100644
--- a/source/gameengine/VideoTexture/ImageRender.cpp
+++ b/source/gameengine/VideoTexture/ImageRender.cpp
@@ -268,7 +268,7 @@ bool ImageRender::Render()
 		m_canvas->UpdateViewPort(0, 0, m_offscreen->ofs->GetWidth(), m_offscreen->ofs->GetHeight());
 	}
 	else {
-		m_canvas->SetViewPort(m_position[0], m_position[1], m_position[0]+m_capSize[0]-1, m_position[1]+m_capSize[1]-1);
+		m_canvas->SetViewPort(m_position[0], m_position[1], m_position[0]+m_capSize[0], m_position[1]+m_capSize[1]);
 	}
 	m_canvas->ClearColor(m_background[0], m_background[1], m_background[2], m_background[3]);
 	m_canvas->ClearBuffer(RAS_ICanvas::COLOR_BUFFER|RAS_ICanvas::DEPTH_BUFFER);




More information about the Bf-blender-cvs mailing list