浏览代码

VR: Fix skewed viewports with buffered eye textures

Bug fix for #419

Viewport calculations need to take VR eye buffer size into
account. Noticable at the older 100px boundary. Skewing still
exists at newer 8px buffer, but is harder to notice.
Eventually causes pretty bad eye strain, though.

Easily reproduced by setting the buffer to something obscenely
large, such as 2048.
Matthew Endsley 10 年之前
父节点
当前提交
05d70ea99d
共有 4 个文件被更改,包括 31 次插入4 次删除
  1. 8 0
      src/ovr.cpp
  2. 1 0
      src/ovr.h
  3. 11 2
      src/renderer_d3d11.cpp
  4. 11 2
      src/renderer_gl.cpp

+ 8 - 0
src/ovr.cpp

@@ -69,6 +69,14 @@ namespace bgfx
 		ovr_Shutdown();
 		ovr_Shutdown();
 	}
 	}
 
 
+	void OVR::getViewport(uint8_t _eye, Rect* _viewport)
+	{
+		_viewport->m_width = (m_rtSize.w - s_eyeBuffer)/2;
+		_viewport->m_height = m_rtSize.h;
+		_viewport->m_x = _eye * (m_rtSize.w + s_eyeBuffer + 1)/2;
+		_viewport->m_y = 0;
+	}
+
 	bool OVR::postReset(void* _nwh, ovrRenderAPIConfig* _config, bool _debug)
 	bool OVR::postReset(void* _nwh, ovrRenderAPIConfig* _config, bool _debug)
 	{
 	{
 		if (_debug)
 		if (_debug)

+ 1 - 0
src/ovr.h

@@ -67,6 +67,7 @@ namespace bgfx
 		void init();
 		void init();
 		void shutdown();
 		void shutdown();
 
 
+		void getViewport(uint8_t _eye, Rect* _viewport);
 		bool postReset(void* _nwh, ovrRenderAPIConfig* _config, bool _debug = false);
 		bool postReset(void* _nwh, ovrRenderAPIConfig* _config, bool _debug = false);
 		void postReset(const ovrTexture& _texture);
 		void postReset(const ovrTexture& _texture);
 		void preReset();
 		void preReset();

+ 11 - 2
src/renderer_d3d11.cpp

@@ -3844,8 +3844,17 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 							PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW);
 							PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW);
 						}
 						}
 
 
-						viewState.m_rect.m_x = eye * (viewState.m_rect.m_width+1)/2;
-						viewState.m_rect.m_width /= 2;
+#if BGFX_CONFIG_USE_OVR
+						if (m_ovr.isEnabled())
+						{
+							m_ovr.getViewport(eye, &viewState.m_rect);
+						}
+						else
+#endif // BGFX_CONFIG_USE_OVR
+						{
+							viewState.m_rect.m_x = eye * (viewState.m_rect.m_width+1)/2;
+							viewState.m_rect.m_width /= 2;
+						}
 					}
 					}
 					else
 					else
 					{
 					{

+ 11 - 2
src/renderer_gl.cpp

@@ -4955,8 +4955,17 @@ namespace bgfx { namespace gl
 							GL_CHECK(glInsertEventMarker(0, viewName) );
 							GL_CHECK(glInsertEventMarker(0, viewName) );
 						}
 						}
 
 
-						viewState.m_rect.m_x = eye * (viewState.m_rect.m_width+1)/2;
-						viewState.m_rect.m_width /= 2;
+#if BGFX_CONFIG_USE_OVR
+						if (m_ovr.isEnabled())
+						{
+							m_ovr.getViewport(eye, &viewState.m_rect);
+						}
+						else
+#endif // BGFX_CONFIG_USE_OVR
+						{
+							viewState.m_rect.m_x = eye * (viewState.m_rect.m_width+1)/2;
+							viewState.m_rect.m_width /= 2;
+						}
 					}
 					}
 					else
 					else
 					{
 					{