Browse Source

Added blit to 08-update example.

Branimir Karadžić 10 years ago
parent
commit
9e8508b64d
4 changed files with 42 additions and 21 deletions
  1. 39 18
      examples/08-update/update.cpp
  2. 1 1
      src/renderer_d3d11.cpp
  3. 1 1
      src/renderer_d3d12.cpp
  4. 1 1
      src/renderer_gl.cpp

+ 39 - 18
examples/08-update/update.cpp

@@ -169,6 +169,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 
 
 	const bgfx::Caps* caps = bgfx::getCaps();
 	const bgfx::Caps* caps = bgfx::getCaps();
 	const bool texture3DSupported = !!(caps->supported & BGFX_CAPS_TEXTURE_3D);
 	const bool texture3DSupported = !!(caps->supported & BGFX_CAPS_TEXTURE_3D);
+	const bool blitSupported      = !!(caps->supported & BGFX_CAPS_BLIT);
 
 
 	uint32_t numTextures3d = 0;
 	uint32_t numTextures3d = 0;
 	bgfx::TextureHandle textures3d[3] = {};
 	bgfx::TextureHandle textures3d[3] = {};
@@ -215,11 +216,21 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 
 
 	const uint32_t textureSide = 2048;
 	const uint32_t textureSide = 2048;
 
 
-	bgfx::TextureHandle textureCube = bgfx::createTextureCube(textureSide, 1
+	bgfx::TextureHandle textureCube[2];
+
+	textureCube[0] = bgfx::createTextureCube(textureSide, 1
 		, bgfx::TextureFormat::BGRA8
 		, bgfx::TextureFormat::BGRA8
 		, BGFX_TEXTURE_MIN_POINT|BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIP_POINT
 		, BGFX_TEXTURE_MIN_POINT|BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIP_POINT
 		);
 		);
 
 
+	if (blitSupported)
+	{
+		textureCube[1] = bgfx::createTextureCube(textureSide, 1
+			, bgfx::TextureFormat::BGRA8
+			, BGFX_TEXTURE_MIN_POINT|BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIP_POINT|BGFX_TEXTURE_BLIT_DST
+			);
+	}
+
 	const uint32_t texture2dSize = 256;
 	const uint32_t texture2dSize = 256;
 
 
 	bgfx::TextureHandle texture2d = bgfx::createTexture2D(texture2dSize, texture2dSize, 1
 	bgfx::TextureHandle texture2d = bgfx::createTexture2D(texture2dSize, texture2dSize, 1
@@ -285,7 +296,11 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 				++hit;
 				++hit;
 				const Pack2D& rect = face.m_rect;
 				const Pack2D& rect = face.m_rect;
 
 
-				updateTextureCubeRectBgra8(textureCube, face.m_side, rect.m_x, rect.m_y, rect.m_width, rect.m_height, rr, gg, bb);
+				updateTextureCubeRectBgra8(textureCube[0], face.m_side, rect.m_x, rect.m_y, rect.m_width, rect.m_height, rr, gg, bb);
+				if (blitSupported)
+				{
+					bgfx::blit(0, textureCube[1], 0, rect.m_x, rect.m_y, face.m_side, textureCube[0], 0, rect.m_x, rect.m_y, face.m_side, rect.m_width, rect.m_height);
+				}
 
 
 				rr = rand()%255;
 				rr = rand()%255;
 				gg = rand()%255;
 				gg = rand()%255;
@@ -347,25 +362,27 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		// Set view and projection matrix for view 0.
 		// Set view and projection matrix for view 0.
 		bgfx::setViewTransform(0, view, proj);
 		bgfx::setViewTransform(0, view, proj);
 
 
-		float mtx[16];
-		bx::mtxRotateXY(mtx, time, time*0.37f);
-
-		// Set model matrix for rendering.
-		bgfx::setTransform(mtx);
+		for (uint32_t ii = 0; ii < 1 + uint32_t(blitSupported); ++ii)
+		{
+			float mtx[16];
+			bx::mtxSRT(mtx, 1.0f, 1.0f, 1.0f, time, time*0.37f, 0.0f, -1.5f*blitSupported + ii*3.0f, 0.0f, 0.0f);
 
 
-		// Set vertex and index buffer.
-		bgfx::setVertexBuffer(vbh);
-		bgfx::setIndexBuffer(ibh);
+			// Set model matrix for rendering.
+			bgfx::setTransform(mtx);
 
 
-		// Bind texture.
-		bgfx::setTexture(0, s_texCube, textureCube);
+			// Set vertex and index buffer.
+			bgfx::setVertexBuffer(vbh);
+			bgfx::setIndexBuffer(ibh);
 
 
-		// Set render states.
-		bgfx::setState(BGFX_STATE_DEFAULT);
+			// Bind texture.
+			bgfx::setTexture(0, s_texCube, textureCube[ii]);
 
 
-		// Submit primitive for rendering to view 0.
-		bgfx::submit(0, program);
+			// Set render states.
+			bgfx::setState(BGFX_STATE_DEFAULT);
 
 
+			// Submit primitive for rendering to view 0.
+			bgfx::submit(0, program);
+		}
 
 
 		// Set view and projection matrix for view 1.
 		// Set view and projection matrix for view 1.
 		const float aspectRatio = float(height)/float(width);
 		const float aspectRatio = float(height)/float(width);
@@ -373,7 +390,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		bx::mtxOrtho(proj, -size, size, size*aspectRatio, -size*aspectRatio, 0.0f, 1000.0f);
 		bx::mtxOrtho(proj, -size, size, size*aspectRatio, -size*aspectRatio, 0.0f, 1000.0f);
 		bgfx::setViewTransform(1, NULL, proj);
 		bgfx::setViewTransform(1, NULL, proj);
 
 
-
+		float mtx[16];
 		bx::mtxTranslate(mtx, -size+2.0f - BX_COUNTOF(textures)*0.1f*0.5f, 1.9f, 0.0f);
 		bx::mtxTranslate(mtx, -size+2.0f - BX_COUNTOF(textures)*0.1f*0.5f, 1.9f, 0.0f);
 
 
 		// Set model matrix for rendering.
 		// Set model matrix for rendering.
@@ -481,7 +498,11 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 	}
 	}
 
 
 	bgfx::destroyTexture(texture2d);
 	bgfx::destroyTexture(texture2d);
-	bgfx::destroyTexture(textureCube);
+	bgfx::destroyTexture(textureCube[0]);
+	if (blitSupported)
+	{
+		bgfx::destroyTexture(textureCube[1]);
+	}
 	bgfx::destroyIndexBuffer(ibh);
 	bgfx::destroyIndexBuffer(ibh);
 	bgfx::destroyVertexBuffer(vbh);
 	bgfx::destroyVertexBuffer(vbh);
 	if (bgfx::isValid(program3d) )
 	if (bgfx::isValid(program3d) )

+ 1 - 1
src/renderer_d3d11.cpp

@@ -4618,7 +4618,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 						box.front  = blit.m_srcZ;
 						box.front  = blit.m_srcZ;
 						box.right  = blit.m_srcX + width;
 						box.right  = blit.m_srcX + width;
 						box.bottom = blit.m_srcY + height;;
 						box.bottom = blit.m_srcY + height;;
-						box.back   = blit.m_srcZ + bx::uint32_max(1, depth);
+						box.back   = blit.m_srcZ + bx::uint32_imax(1, depth);
 
 
 						deviceCtx->CopySubresourceRegion(dst.m_ptr
 						deviceCtx->CopySubresourceRegion(dst.m_ptr
 							, blit.m_dstMip
 							, blit.m_dstMip

+ 1 - 1
src/renderer_d3d12.cpp

@@ -4419,7 +4419,7 @@ data.NumQualityLevels = 0;
  						box.front  = blit.m_srcZ;
  						box.front  = blit.m_srcZ;
  						box.right  = blit.m_srcX + width;
  						box.right  = blit.m_srcX + width;
  						box.bottom = blit.m_srcY + height;;
  						box.bottom = blit.m_srcY + height;;
- 						box.back   = blit.m_srcZ + bx::uint32_max(1, depth);
+ 						box.back   = blit.m_srcZ + bx::uint32_imax(1, depth);
 
 
 						D3D12_TEXTURE_COPY_LOCATION dstLocation = { dst.m_ptr, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, { 0 } };
 						D3D12_TEXTURE_COPY_LOCATION dstLocation = { dst.m_ptr, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, { 0 } };
 						D3D12_TEXTURE_COPY_LOCATION srcLocation = { src.m_ptr, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, { 0 } };
 						D3D12_TEXTURE_COPY_LOCATION srcLocation = { src.m_ptr, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, { 0 } };

+ 1 - 1
src/renderer_gl.cpp

@@ -5320,7 +5320,7 @@ namespace bgfx { namespace gl
 								, bi.m_dstZ
 								, bi.m_dstZ
 								, width
 								, width
 								, height
 								, height
-								, bx::uint32_max(depth, 1)
+								, bx::uint32_imax(depth, 1)
 								) );
 								) );
 						}
 						}
 					}
 					}