Branimir Karadžić il y a 9 ans
Parent
commit
b1648aea1a
2 fichiers modifiés avec 47 ajouts et 43 suppressions
  1. 13 9
      src/renderer_d3d11.cpp
  2. 34 34
      src/renderer_gl.cpp

+ 13 - 9
src/renderer_d3d11.cpp

@@ -3564,7 +3564,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 		desc.BindFlags = ovrTextureBind_DX_RenderTarget;
 		desc.BindFlags = ovrTextureBind_DX_RenderTarget;
 		desc.StaticImage = ovrFalse;
 		desc.StaticImage = ovrFalse;
 
 
-		ovrResult result = ovr_CreateTextureSwapChainDX(_session, s_renderD3D11->m_device, &desc, &m_textureSwapChain);
+		ID3D11Device* device = s_renderD3D11->m_device;
+
+		ovrResult result = ovr_CreateTextureSwapChainDX(_session, device, &desc, &m_textureSwapChain);
 
 
 		if (!OVR_SUCCESS(result) )
 		if (!OVR_SUCCESS(result) )
 		{
 		{
@@ -3584,7 +3586,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 			rtvd.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
 			rtvd.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
 
 
 			ID3D11RenderTargetView* rtv;
 			ID3D11RenderTargetView* rtv;
-			DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(tex, &rtvd, &rtv) );
+			DX_CHECK(device->CreateRenderTargetView(tex, &rtvd, &rtv) );
 			m_eyeRtv[ii] = rtv;
 			m_eyeRtv[ii] = rtv;
 			DX_RELEASE(tex, 1);
 			DX_RELEASE(tex, 1);
 		}
 		}
@@ -3603,8 +3605,8 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 		dbDesc.MiscFlags = 0;
 		dbDesc.MiscFlags = 0;
 		dbDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
 		dbDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
 		ID3D11Texture2D* tex;
 		ID3D11Texture2D* tex;
-		DX_CHECK(s_renderD3D11->m_device->CreateTexture2D(&dbDesc, NULL, &tex) );
-		DX_CHECK(s_renderD3D11->m_device->CreateDepthStencilView(tex, NULL, &m_depthBuffer) );
+		DX_CHECK(device->CreateTexture2D(&dbDesc, NULL, &tex) );
+		DX_CHECK(device->CreateDepthStencilView(tex, NULL, &m_depthBuffer) );
 		DX_RELEASE(tex, 0);
 		DX_RELEASE(tex, 0);
 	}
 	}
 
 
@@ -3614,10 +3616,12 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 		int texIndex = 0;
 		int texIndex = 0;
 		ovr_GetTextureSwapChainCurrentIndex(_session, m_textureSwapChain, &texIndex);
 		ovr_GetTextureSwapChainCurrentIndex(_session, m_textureSwapChain, &texIndex);
 
 
-		float black[] = { 0.f, 0.f, 0.f, 0.f }; // Important that alpha=0, if want pixels to be transparent, for manual layers
-		s_renderD3D11->m_deviceCtx->OMSetRenderTargets(1, &m_eyeRtv[texIndex], m_depthBuffer);
-		s_renderD3D11->m_deviceCtx->ClearRenderTargetView(m_eyeRtv[texIndex], black);
-		s_renderD3D11->m_deviceCtx->ClearDepthStencilView(m_depthBuffer, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1, 0);
+		ID3D11DeviceContext* deviceCtx = s_renderD3D11->m_deviceCtx;
+
+		float black[] = { 0.0f, 0.0f, 0.0f, 0.0f }; // Important that alpha=0, if want pixels to be transparent, for manual layers
+		deviceCtx->OMSetRenderTargets(1, &m_eyeRtv[texIndex], m_depthBuffer);
+		deviceCtx->ClearRenderTargetView(m_eyeRtv[texIndex], black);
+		deviceCtx->ClearDepthStencilView(m_depthBuffer, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1, 0);
 
 
 		D3D11_VIEWPORT D3Dvp;
 		D3D11_VIEWPORT D3Dvp;
 		D3Dvp.TopLeftX = 0;
 		D3Dvp.TopLeftX = 0;
@@ -3626,7 +3630,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 		D3Dvp.Height = (FLOAT)m_eyeTextureSize.h;
 		D3Dvp.Height = (FLOAT)m_eyeTextureSize.h;
 		D3Dvp.MinDepth = 0;
 		D3Dvp.MinDepth = 0;
 		D3Dvp.MaxDepth = 1;
 		D3Dvp.MaxDepth = 1;
-		s_renderD3D11->m_deviceCtx->RSSetViewports(1, &D3Dvp);
+		deviceCtx->RSSetViewports(1, &D3Dvp);
 	}
 	}
 
 
 	void OVRBufferD3D11::destroy(const ovrSession& _session)
 	void OVRBufferD3D11::destroy(const ovrSession& _session)

+ 34 - 34
src/renderer_gl.cpp

@@ -3319,10 +3319,10 @@ namespace bgfx { namespace gl
 	}
 	}
 
 
 #if BGFX_CONFIG_USE_OVR
 #if BGFX_CONFIG_USE_OVR
-	void OVRBufferGL::create(const ovrSession& session, int eyeIdx)
+	void OVRBufferGL::create(const ovrSession& _session, int _eyeIdx)
 	{
 	{
-		ovrHmdDesc hmdDesc = ovr_GetHmdDesc(session);
-		m_eyeTextureSize = ovr_GetFovTextureSize(session, (ovrEyeType)eyeIdx, hmdDesc.DefaultEyeFov[eyeIdx], 1.0f);
+		ovrHmdDesc hmdDesc = ovr_GetHmdDesc(_session);
+		m_eyeTextureSize = ovr_GetFovTextureSize(_session, ovrEyeType(_eyeIdx), hmdDesc.DefaultEyeFov[_eyeIdx], 1.0f);
 
 
 		ovrTextureSwapChainDesc desc = {};
 		ovrTextureSwapChainDesc desc = {};
 		desc.Type = ovrTexture_2D;
 		desc.Type = ovrTexture_2D;
@@ -3334,15 +3334,15 @@ namespace bgfx { namespace gl
 		desc.SampleCount = 1;
 		desc.SampleCount = 1;
 		desc.StaticImage = ovrFalse;
 		desc.StaticImage = ovrFalse;
 
 
-		ovr_CreateTextureSwapChainGL(session, &desc, &m_textureSwapChain);
+		ovr_CreateTextureSwapChainGL(_session, &desc, &m_textureSwapChain);
 
 
 		int textureCount = 0;
 		int textureCount = 0;
-		ovr_GetTextureSwapChainLength(session, m_textureSwapChain, &textureCount);
+		ovr_GetTextureSwapChainLength(_session, m_textureSwapChain, &textureCount);
 
 
 		for (int j = 0; j < textureCount; ++j)
 		for (int j = 0; j < textureCount; ++j)
 		{
 		{
 			GLuint chainTexId;
 			GLuint chainTexId;
-			ovr_GetTextureSwapChainBufferGL(session, m_textureSwapChain, j, &chainTexId);
+			ovr_GetTextureSwapChainBufferGL(_session, m_textureSwapChain, j, &chainTexId);
 			GL_CHECK(glBindTexture(GL_TEXTURE_2D, chainTexId) );
 			GL_CHECK(glBindTexture(GL_TEXTURE_2D, chainTexId) );
 
 
 			GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) );
 			GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) );
@@ -3364,12 +3364,12 @@ namespace bgfx { namespace gl
 		GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, m_eyeTextureSize.w, m_eyeTextureSize.h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL) );
 		GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, m_eyeTextureSize.w, m_eyeTextureSize.h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL) );
 	}
 	}
 
 
-	void OVRBufferGL::render(const ovrSession& session)
+	void OVRBufferGL::render(const ovrSession& _session)
 	{
 	{
 		// set the current eye texture in swap chain
 		// set the current eye texture in swap chain
 		int curIndex;
 		int curIndex;
-		ovr_GetTextureSwapChainCurrentIndex(session, m_textureSwapChain, &curIndex);
-		ovr_GetTextureSwapChainBufferGL(session, m_textureSwapChain, curIndex, &m_eyeTexId);
+		ovr_GetTextureSwapChainCurrentIndex(_session, m_textureSwapChain, &curIndex);
+		ovr_GetTextureSwapChainBufferGL(_session, m_textureSwapChain, curIndex, &m_eyeTexId);
 
 
 		GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_eyeFbo) );
 		GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_eyeFbo) );
 		GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_eyeTexId, 0) );
 		GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_eyeTexId, 0) );
@@ -3379,22 +3379,22 @@ namespace bgfx { namespace gl
 		GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) );
 		GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) );
 	}
 	}
 
 
-	void OVRBufferGL::destroy(const ovrSession& session)
+	void OVRBufferGL::destroy(const ovrSession& _session)
 	{
 	{
 		GL_CHECK(glDeleteFramebuffers(1, &m_eyeFbo) );
 		GL_CHECK(glDeleteFramebuffers(1, &m_eyeFbo) );
 		GL_CHECK(glDeleteTextures(1, &m_depthBuffer) );
 		GL_CHECK(glDeleteTextures(1, &m_depthBuffer) );
 
 
-		ovr_DestroyTextureSwapChain(session, m_textureSwapChain);
+		ovr_DestroyTextureSwapChain(_session, m_textureSwapChain);
 	}
 	}
 
 
-	void OVRMirrorGL::create(const ovrSession& session, int windowWidth, int windowHeight)
+	void OVRMirrorGL::create(const ovrSession& _session, int _width, int _height)
 	{
 	{
 		memset(&m_mirrorTextureDesc, 0, sizeof(m_mirrorTextureDesc) );
 		memset(&m_mirrorTextureDesc, 0, sizeof(m_mirrorTextureDesc) );
-		m_mirrorTextureDesc.Width  = windowWidth;
-		m_mirrorTextureDesc.Height = windowHeight;
+		m_mirrorTextureDesc.Width  = _width;
+		m_mirrorTextureDesc.Height = _height;
 		m_mirrorTextureDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
 		m_mirrorTextureDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
 
 
-		ovr_CreateMirrorTextureGL(session, &m_mirrorTextureDesc, &m_mirrorTexture);
+		ovr_CreateMirrorTextureGL(_session, &m_mirrorTextureDesc, &m_mirrorTexture);
 
 
 		// Fallback to doing nothing if mirror was not created. This is to prevent errors with fast window resizes
 		// Fallback to doing nothing if mirror was not created. This is to prevent errors with fast window resizes
 		if (!m_mirrorTexture)
 		if (!m_mirrorTexture)
@@ -3402,7 +3402,7 @@ namespace bgfx { namespace gl
 
 
 		// Configure the mirror read buffer
 		// Configure the mirror read buffer
 		GLuint texId;
 		GLuint texId;
-		ovr_GetMirrorTextureBufferGL(session, m_mirrorTexture, &texId);
+		ovr_GetMirrorTextureBufferGL(_session, m_mirrorTexture, &texId);
 		GL_CHECK(glGenFramebuffers(1, &m_mirrorFBO) );
 		GL_CHECK(glGenFramebuffers(1, &m_mirrorFBO) );
 		GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_mirrorFBO) );
 		GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_mirrorFBO) );
 		GL_CHECK(glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texId, 0) );
 		GL_CHECK(glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texId, 0) );
@@ -3416,28 +3416,28 @@ namespace bgfx { namespace gl
 		}
 		}
 	}
 	}
 
 
-	void OVRMirrorGL::destroy(const ovrSession& session)
+	void OVRMirrorGL::destroy(const ovrSession& _session)
 	{
 	{
-		if (!m_mirrorTexture)
-			return;
-
-		GL_CHECK(glDeleteFramebuffers(1, &m_mirrorFBO) );
-		ovr_DestroyMirrorTexture(session, m_mirrorTexture);
-		m_mirrorTexture = NULL;
+		if (NULL != m_mirrorTexture)
+		{
+			GL_CHECK(glDeleteFramebuffers(1, &m_mirrorFBO) );
+			ovr_DestroyMirrorTexture(_session, m_mirrorTexture);
+			m_mirrorTexture = NULL;
+		}
 	}
 	}
 
 
-	void OVRMirrorGL::blit(const ovrSession& /*session*/)
+	void OVRMirrorGL::blit(const ovrSession& /*_session*/)
 	{
 	{
-		if (!m_mirrorTexture)
-			return;
-
-		// Blit mirror texture to back buffer
-		GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_mirrorFBO) );
-		GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) );
-		GLint width  = m_mirrorTextureDesc.Width;
-		GLint height = m_mirrorTextureDesc.Height;
-		GL_CHECK(glBlitFramebuffer(0, height, width, 0, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST) );
-		GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, 0) );
+		if (NULL != m_mirrorTexture)
+		{
+			// Blit mirror texture to back buffer
+			GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_mirrorFBO) );
+			GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) );
+			GLint width  = m_mirrorTextureDesc.Width;
+			GLint height = m_mirrorTextureDesc.Height;
+			GL_CHECK(glBlitFramebuffer(0, height, width, 0, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST) );
+			GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, 0) );
+		}
 	}
 	}
 #endif // BGFX_CONFIG_USE_OVR
 #endif // BGFX_CONFIG_USE_OVR