Browse Source

WIP: Texture array support.

Branimir Karadžić 9 years ago
parent
commit
c98be90bf5

+ 17 - 7
examples/08-update/update.cpp

@@ -96,7 +96,7 @@ static const uint16_t s_m_cubeIndices[36] =
 static void updateTextureCubeRectBgra8(bgfx::TextureHandle _handle, uint8_t _side, uint32_t _x, uint32_t _y, uint32_t _width, uint32_t _height, uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 0xff)
 static void updateTextureCubeRectBgra8(bgfx::TextureHandle _handle, uint8_t _side, uint32_t _x, uint32_t _y, uint32_t _width, uint32_t _height, uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 0xff)
 {
 {
 	bgfx::TextureInfo ti;
 	bgfx::TextureInfo ti;
-	bgfx::calcTextureSize(ti, _width, _height, 1, 1, false, bgfx::TextureFormat::BGRA8);
+	bgfx::calcTextureSize(ti, _width, _height, 1, false, false, 1, bgfx::TextureFormat::BGRA8);
 
 
 	const bgfx::Memory* mem = bgfx::alloc(ti.storageSize);
 	const bgfx::Memory* mem = bgfx::alloc(ti.storageSize);
 	uint8_t* data = (uint8_t*)mem->data;
 	uint8_t* data = (uint8_t*)mem->data;
@@ -186,17 +186,17 @@ public:
 
 
 			if (0 != (BGFX_CAPS_FORMAT_TEXTURE_2D & caps->formats[bgfx::TextureFormat::R8]) )
 			if (0 != (BGFX_CAPS_FORMAT_TEXTURE_2D & caps->formats[bgfx::TextureFormat::R8]) )
 			{
 			{
-				m_textures3d[m_numm_textures3d++] = bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R8,   BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem8);
+				m_textures3d[m_numm_textures3d++] = bgfx::createTexture3D(32, 32, 32, false, bgfx::TextureFormat::R8,   BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem8);
 			}
 			}
 
 
 			if (0 != (BGFX_CAPS_FORMAT_TEXTURE_2D & caps->formats[bgfx::TextureFormat::R16F]) )
 			if (0 != (BGFX_CAPS_FORMAT_TEXTURE_2D & caps->formats[bgfx::TextureFormat::R16F]) )
 			{
 			{
-				m_textures3d[m_numm_textures3d++] = bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R16F, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem16f);
+				m_textures3d[m_numm_textures3d++] = bgfx::createTexture3D(32, 32, 32, false, bgfx::TextureFormat::R16F, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem16f);
 			}
 			}
 
 
 			if (0 != (BGFX_CAPS_FORMAT_TEXTURE_2D & caps->formats[bgfx::TextureFormat::R32F]) )
 			if (0 != (BGFX_CAPS_FORMAT_TEXTURE_2D & caps->formats[bgfx::TextureFormat::R32F]) )
 			{
 			{
-				m_textures3d[m_numm_textures3d++] = bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R32F, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem32f);
+				m_textures3d[m_numm_textures3d++] = bgfx::createTexture3D(32, 32, 32, false, bgfx::TextureFormat::R32F, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem32f);
 			}
 			}
 		}
 		}
 
 
@@ -222,20 +222,30 @@ public:
 		// Create time uniform.
 		// Create time uniform.
 		u_time = bgfx::createUniform("u_time", bgfx::UniformType::Vec4);
 		u_time = bgfx::createUniform("u_time", bgfx::UniformType::Vec4);
 
 
-		m_textureCube[0] = bgfx::createTextureCube(m_textureside, 1
+		m_textureCube[0] = bgfx::createTextureCube(
+				  m_textureside
+				, false
+				, 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 (m_blitSupported)
 		if (m_blitSupported)
 		{
 		{
-			m_textureCube[1] = bgfx::createTextureCube(m_textureside, 1
+			m_textureCube[1] = bgfx::createTextureCube(
+					  m_textureside
+					, false
+					, 1
 					, bgfx::TextureFormat::BGRA8
 					, bgfx::TextureFormat::BGRA8
 					, BGFX_TEXTURE_MIN_POINT|BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIP_POINT|BGFX_TEXTURE_BLIT_DST
 					, BGFX_TEXTURE_MIN_POINT|BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIP_POINT|BGFX_TEXTURE_BLIT_DST
 					);
 					);
 		}
 		}
 
 
-		m_texture2d = bgfx::createTexture2D(m_texture2dSize, m_texture2dSize, 1
+		m_texture2d = bgfx::createTexture2D(
+				  m_texture2dSize
+				, m_texture2dSize
+				, false
+				, 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
 				);
 				);

+ 5 - 5
examples/09-hdr/hdr.cpp

@@ -203,8 +203,8 @@ class ExampleHDR : public entry::AppI
 
 
 		m_mesh = meshLoad("meshes/bunny.bin");
 		m_mesh = meshLoad("meshes/bunny.bin");
 
 
-		m_fbtextures[0] = bgfx::createTexture2D(m_width, m_height, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT|BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP);
-		m_fbtextures[1] = bgfx::createTexture2D(m_width, m_height, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_WRITE_ONLY);
+		m_fbtextures[0] = bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT|BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP);
+		m_fbtextures[1] = bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_WRITE_ONLY);
 		m_fbh = bgfx::createFrameBuffer(BX_COUNTOF(m_fbtextures), m_fbtextures, true);
 		m_fbh = bgfx::createFrameBuffer(BX_COUNTOF(m_fbtextures), m_fbtextures, true);
 
 
 		m_lum[0] = bgfx::createFrameBuffer(128, 128, bgfx::TextureFormat::BGRA8);
 		m_lum[0] = bgfx::createFrameBuffer(128, 128, bgfx::TextureFormat::BGRA8);
@@ -219,7 +219,7 @@ class ExampleHDR : public entry::AppI
 		m_lumBgra8 = 0;
 		m_lumBgra8 = 0;
 		if ( (BGFX_CAPS_TEXTURE_BLIT|BGFX_CAPS_TEXTURE_READ_BACK) == (bgfx::getCaps()->supported & (BGFX_CAPS_TEXTURE_BLIT|BGFX_CAPS_TEXTURE_READ_BACK) ) )
 		if ( (BGFX_CAPS_TEXTURE_BLIT|BGFX_CAPS_TEXTURE_READ_BACK) == (bgfx::getCaps()->supported & (BGFX_CAPS_TEXTURE_BLIT|BGFX_CAPS_TEXTURE_READ_BACK) ) )
 		{
 		{
-			m_rb = bgfx::createTexture2D(1, 1, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_READ_BACK);
+			m_rb = bgfx::createTexture2D(1, 1, false, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_READ_BACK);
 		}
 		}
 		else
 		else
 		{
 		{
@@ -305,8 +305,8 @@ class ExampleHDR : public entry::AppI
 
 
 				bgfx::destroyFrameBuffer(m_fbh);
 				bgfx::destroyFrameBuffer(m_fbh);
 
 
-				m_fbtextures[0] = bgfx::createTexture2D(m_width, m_height, 1, bgfx::TextureFormat::BGRA8, ( (msaa+1)<<BGFX_TEXTURE_RT_MSAA_SHIFT)|BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP);
-				m_fbtextures[1] = bgfx::createTexture2D(m_width, m_height, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_WRITE_ONLY|( (msaa+1)<<BGFX_TEXTURE_RT_MSAA_SHIFT) );
+				m_fbtextures[0] = bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::BGRA8, ( (msaa+1)<<BGFX_TEXTURE_RT_MSAA_SHIFT)|BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP);
+				m_fbtextures[1] = bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_WRITE_ONLY|( (msaa+1)<<BGFX_TEXTURE_RT_MSAA_SHIFT) );
 				m_fbh = bgfx::createFrameBuffer(BX_COUNTOF(m_fbtextures), m_fbtextures, true);
 				m_fbh = bgfx::createFrameBuffer(BX_COUNTOF(m_fbtextures), m_fbtextures, true);
 			}
 			}
 
 

+ 1 - 1
examples/12-lod/lod.cpp

@@ -65,7 +65,7 @@ class ExampleLod : public entry::AppI
 			stippleTex->data[knightTour[ii].m_y * 8 + knightTour[ii].m_x] = ii*4;
 			stippleTex->data[knightTour[ii].m_y * 8 + knightTour[ii].m_x] = ii*4;
 		}
 		}
 
 
-		m_textureStipple = bgfx::createTexture2D(8, 4, 1
+		m_textureStipple = bgfx::createTexture2D(8, 4, false, 1
 			, bgfx::TextureFormat::R8
 			, bgfx::TextureFormat::R8
 			, BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIN_POINT
 			, BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIN_POINT
 			, stippleTex
 			, stippleTex

+ 4 - 4
examples/14-shadowvolumes/shadowvolumes.cpp

@@ -1884,8 +1884,8 @@ int _main_(int _argc, char** _argv)
 
 
 	bgfx::TextureHandle fbtextures[] =
 	bgfx::TextureHandle fbtextures[] =
 	{
 	{
-		bgfx::createTexture2D(viewState.m_width, viewState.m_height, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_RT),
-		bgfx::createTexture2D(viewState.m_width, viewState.m_height, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_WRITE_ONLY),
+		bgfx::createTexture2D(viewState.m_width, viewState.m_height, false, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_RT),
+		bgfx::createTexture2D(viewState.m_width, viewState.m_height, false, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_WRITE_ONLY),
 	};
 	};
 	s_stencilFb  = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 	s_stencilFb  = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 
 
@@ -2078,8 +2078,8 @@ int _main_(int _argc, char** _argv)
 
 
 			bgfx::destroyFrameBuffer(s_stencilFb);
 			bgfx::destroyFrameBuffer(s_stencilFb);
 
 
-			fbtextures[0] = bgfx::createTexture2D(viewState.m_width, viewState.m_height, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_RT);
-			fbtextures[1] = bgfx::createTexture2D(viewState.m_width, viewState.m_height, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_WRITE_ONLY);
+			fbtextures[0] = bgfx::createTexture2D(viewState.m_width, viewState.m_height, false, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_RT);
+			fbtextures[1] = bgfx::createTexture2D(viewState.m_width, viewState.m_height, false, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_WRITE_ONLY);
 			s_stencilFb = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 			s_stencilFb = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 		}
 		}
 
 

+ 3 - 3
examples/15-shadowmaps-simple/shadowmaps_simple.cpp

@@ -140,7 +140,7 @@ int _main_(int _argc, char** _argv)
 		progShadow = loadProgram("vs_sms_shadow", "fs_sms_shadow");
 		progShadow = loadProgram("vs_sms_shadow", "fs_sms_shadow");
 		progMesh   = loadProgram("vs_sms_mesh",   "fs_sms_mesh");
 		progMesh   = loadProgram("vs_sms_mesh",   "fs_sms_mesh");
 
 
-		shadowMapTexture = bgfx::createTexture2D(shadowMapSize, shadowMapSize, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT | BGFX_TEXTURE_COMPARE_LEQUAL);
+		shadowMapTexture = bgfx::createTexture2D(shadowMapSize, shadowMapSize, false, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT | BGFX_TEXTURE_COMPARE_LEQUAL);
 		bgfx::TextureHandle fbtextures[] = { shadowMapTexture };
 		bgfx::TextureHandle fbtextures[] = { shadowMapTexture };
 		shadowMapFB = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 		shadowMapFB = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 	}
 	}
@@ -151,11 +151,11 @@ int _main_(int _argc, char** _argv)
 		progShadow = loadProgram("vs_sms_shadow_pd", "fs_sms_shadow_pd");
 		progShadow = loadProgram("vs_sms_shadow_pd", "fs_sms_shadow_pd");
 		progMesh   = loadProgram("vs_sms_mesh",      "fs_sms_mesh_pd");
 		progMesh   = loadProgram("vs_sms_mesh",      "fs_sms_mesh_pd");
 
 
-		shadowMapTexture = bgfx::createTexture2D(shadowMapSize, shadowMapSize, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT);
+		shadowMapTexture = bgfx::createTexture2D(shadowMapSize, shadowMapSize, false, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT);
 		bgfx::TextureHandle fbtextures[] =
 		bgfx::TextureHandle fbtextures[] =
 		{
 		{
 			shadowMapTexture,
 			shadowMapTexture,
-			bgfx::createTexture2D(shadowMapSize, shadowMapSize, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_WRITE_ONLY),
+			bgfx::createTexture2D(shadowMapSize, shadowMapSize, false, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_WRITE_ONLY),
 		};
 		};
 		shadowMapFB = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 		shadowMapFB = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 	}
 	}

+ 6 - 6
examples/16-shadowmaps/shadowmaps.cpp

@@ -1944,8 +1944,8 @@ int _main_(int _argc, char** _argv)
 	{
 	{
 		bgfx::TextureHandle fbtextures[] =
 		bgfx::TextureHandle fbtextures[] =
 		{
 		{
-			bgfx::createTexture2D(currentShadowMapSize, currentShadowMapSize, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT),
-			bgfx::createTexture2D(currentShadowMapSize, currentShadowMapSize, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT),
+			bgfx::createTexture2D(currentShadowMapSize, currentShadowMapSize, false, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT),
+			bgfx::createTexture2D(currentShadowMapSize, currentShadowMapSize, false, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT),
 		};
 		};
 		s_rtShadowMap[ii] = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 		s_rtShadowMap[ii] = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 	}
 	}
@@ -3108,8 +3108,8 @@ int _main_(int _argc, char** _argv)
 
 
 				bgfx::TextureHandle fbtextures[] =
 				bgfx::TextureHandle fbtextures[] =
 				{
 				{
-					bgfx::createTexture2D(currentShadowMapSize, currentShadowMapSize, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT),
-					bgfx::createTexture2D(currentShadowMapSize, currentShadowMapSize, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT),
+					bgfx::createTexture2D(currentShadowMapSize, currentShadowMapSize, false, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT),
+					bgfx::createTexture2D(currentShadowMapSize, currentShadowMapSize, false, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT),
 				};
 				};
 				s_rtShadowMap[0] = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 				s_rtShadowMap[0] = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 			}
 			}
@@ -3123,8 +3123,8 @@ int _main_(int _argc, char** _argv)
 
 
 						bgfx::TextureHandle fbtextures[] =
 						bgfx::TextureHandle fbtextures[] =
 						{
 						{
-							bgfx::createTexture2D(currentShadowMapSize, currentShadowMapSize, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT),
-							bgfx::createTexture2D(currentShadowMapSize, currentShadowMapSize, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT),
+							bgfx::createTexture2D(currentShadowMapSize, currentShadowMapSize, false, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT),
+							bgfx::createTexture2D(currentShadowMapSize, currentShadowMapSize, false, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT),
 						};
 						};
 						s_rtShadowMap[ii] = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 						s_rtShadowMap[ii] = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
 					}
 					}

+ 3 - 3
examples/19-oit/oit.cpp

@@ -264,8 +264,8 @@ class ExampleOIT : public entry::AppI
 					bgfx::destroyFrameBuffer(m_fbh);
 					bgfx::destroyFrameBuffer(m_fbh);
 				}
 				}
 
 
-				m_fbtextures[0] = bgfx::createTexture2D(m_width, m_height, 1, bgfx::TextureFormat::RGBA16F, BGFX_TEXTURE_RT);
-				m_fbtextures[1] = bgfx::createTexture2D(m_width, m_height, 1, bgfx::TextureFormat::R16F,    BGFX_TEXTURE_RT);
+				m_fbtextures[0] = bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::RGBA16F, BGFX_TEXTURE_RT);
+				m_fbtextures[1] = bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::R16F,    BGFX_TEXTURE_RT);
 				m_fbh = bgfx::createFrameBuffer(BX_COUNTOF(m_fbtextures), m_fbtextures, true);
 				m_fbh = bgfx::createFrameBuffer(BX_COUNTOF(m_fbtextures), m_fbtextures, true);
 			}
 			}
 
 
@@ -417,7 +417,7 @@ class ExampleOIT : public entry::AppI
 						| BGFX_STATE_DEPTH_TEST_ALWAYS
 						| BGFX_STATE_DEPTH_TEST_ALWAYS
 						| BGFX_STATE_MSAA
 						| BGFX_STATE_MSAA
 						;
 						;
-						
+
 						bgfx::ProgramHandle program = BGFX_INVALID_HANDLE;
 						bgfx::ProgramHandle program = BGFX_INVALID_HANDLE;
 						switch (m_mode)
 						switch (m_mode)
 						{
 						{

+ 3 - 3
examples/21-deferred/deferred.cpp

@@ -432,9 +432,9 @@ class ExampleDeferred : public entry::AppI
 						| BGFX_TEXTURE_U_CLAMP
 						| BGFX_TEXTURE_U_CLAMP
 						| BGFX_TEXTURE_V_CLAMP
 						| BGFX_TEXTURE_V_CLAMP
 						;
 						;
-					m_gbufferTex[0] = bgfx::createTexture2D(m_width, m_height, 1, bgfx::TextureFormat::BGRA8, samplerFlags);
-					m_gbufferTex[1] = bgfx::createTexture2D(m_width, m_height, 1, bgfx::TextureFormat::BGRA8, samplerFlags);
-					m_gbufferTex[2] = bgfx::createTexture2D(m_width, m_height, 1, bgfx::TextureFormat::D24,   samplerFlags);
+					m_gbufferTex[0] = bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::BGRA8, samplerFlags);
+					m_gbufferTex[1] = bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::BGRA8, samplerFlags);
+					m_gbufferTex[2] = bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::D24,   samplerFlags);
 					m_gbuffer = bgfx::createFrameBuffer(BX_COUNTOF(m_gbufferTex), m_gbufferTex, true);
 					m_gbuffer = bgfx::createFrameBuffer(BX_COUNTOF(m_gbufferTex), m_gbufferTex, true);
 
 
 					if (bgfx::isValid(m_lightBuffer) )
 					if (bgfx::isValid(m_lightBuffer) )

+ 1 - 1
examples/23-vectordisplay/vectordisplay.cpp

@@ -857,7 +857,7 @@ void VectorDisplay::genLinetex()                                    // generate
 		| BGFX_TEXTURE_MAG_POINT
 		| BGFX_TEXTURE_MAG_POINT
 		;
 		;
 
 
-	m_lineTexId = bgfx::createTexture2D(TEXTURE_SIZE, TEXTURE_SIZE, 1, bgfx::TextureFormat::BGRA8, flags, mem);
+	m_lineTexId = bgfx::createTexture2D(TEXTURE_SIZE, TEXTURE_SIZE, false, 1, bgfx::TextureFormat::BGRA8, flags, mem);
 }
 }
 
 
 static const int8_t simplex[95][112] =
 static const int8_t simplex[95][112] =

+ 1 - 1
examples/27-terrain/terrain.cpp

@@ -274,7 +274,7 @@ class ExampleTerrain : public entry::AppI
 
 
 			if (!bgfx::isValid(m_heightTexture) )
 			if (!bgfx::isValid(m_heightTexture) )
 			{
 			{
-				m_heightTexture = bgfx::createTexture2D(s_terrainSize, s_terrainSize, 1, bgfx::TextureFormat::R8);
+				m_heightTexture = bgfx::createTexture2D(s_terrainSize, s_terrainSize, false, 1, bgfx::TextureFormat::R8);
 			}
 			}
 
 
 			mem = bgfx::makeRef(&m_terrain.m_heightMap[0], sizeof(uint8_t) * s_terrainSize * s_terrainSize);
 			mem = bgfx::makeRef(&m_terrain.m_heightMap[0], sizeof(uint8_t) * s_terrainSize * s_terrainSize);

+ 3 - 3
examples/30-picking/picking.cpp

@@ -103,7 +103,7 @@ class ExamplePicking : public entry::AppI
 		m_timeOffset = bx::getHPCounter();
 		m_timeOffset = bx::getHPCounter();
 
 
 		// Set up ID buffer, which has a color target and depth buffer
 		// Set up ID buffer, which has a color target and depth buffer
-		m_pickingRT = bgfx::createTexture2D(ID_DIM, ID_DIM, 1, bgfx::TextureFormat::RGBA8, 0
+		m_pickingRT = bgfx::createTexture2D(ID_DIM, ID_DIM, false, 1, bgfx::TextureFormat::RGBA8, 0
 			| BGFX_TEXTURE_RT
 			| BGFX_TEXTURE_RT
 			| BGFX_TEXTURE_MIN_POINT
 			| BGFX_TEXTURE_MIN_POINT
 			| BGFX_TEXTURE_MAG_POINT
 			| BGFX_TEXTURE_MAG_POINT
@@ -111,7 +111,7 @@ class ExamplePicking : public entry::AppI
 			| BGFX_TEXTURE_U_CLAMP
 			| BGFX_TEXTURE_U_CLAMP
 			| BGFX_TEXTURE_V_CLAMP
 			| BGFX_TEXTURE_V_CLAMP
 			);
 			);
-		m_pickingRTDepth = bgfx::createTexture2D(ID_DIM, ID_DIM, 1, bgfx::TextureFormat::D24S8, 0
+		m_pickingRTDepth = bgfx::createTexture2D(ID_DIM, ID_DIM, false, 1, bgfx::TextureFormat::D24S8, 0
 			| BGFX_TEXTURE_RT
 			| BGFX_TEXTURE_RT
 			| BGFX_TEXTURE_MIN_POINT
 			| BGFX_TEXTURE_MIN_POINT
 			| BGFX_TEXTURE_MAG_POINT
 			| BGFX_TEXTURE_MAG_POINT
@@ -124,7 +124,7 @@ class ExamplePicking : public entry::AppI
 		// Impossible to read directly from a render target, you *must* blit to a CPU texture
 		// Impossible to read directly from a render target, you *must* blit to a CPU texture
 		// first. Algorithm Overview: Render on GPU -> Blit to CPU texture -> Read from CPU
 		// first. Algorithm Overview: Render on GPU -> Blit to CPU texture -> Read from CPU
 		// texture.
 		// texture.
-		m_blitTex = bgfx::createTexture2D(ID_DIM, ID_DIM, 1, bgfx::TextureFormat::RGBA8, 0
+		m_blitTex = bgfx::createTexture2D(ID_DIM, ID_DIM, false, 1, bgfx::TextureFormat::RGBA8, 0
 			| BGFX_TEXTURE_BLIT_DST
 			| BGFX_TEXTURE_BLIT_DST
 			| BGFX_TEXTURE_READ_BACK
 			| BGFX_TEXTURE_READ_BACK
 			| BGFX_TEXTURE_MIN_POINT
 			| BGFX_TEXTURE_MIN_POINT

+ 8 - 6
examples/31-rsm/reflectiveshadowmap.cpp

@@ -304,13 +304,13 @@ public:
 			;
 			;
 
 
 		// Make gbuffer and related textures
 		// Make gbuffer and related textures
-		m_gbufferTex[GBUFFER_RT_NORMAL] = bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, 1, bgfx::TextureFormat::BGRA8, samplerFlags);
-		m_gbufferTex[GBUFFER_RT_COLOR]  = bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, 1, bgfx::TextureFormat::BGRA8, samplerFlags);
-		m_gbufferTex[GBUFFER_RT_DEPTH]  = bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, 1, bgfx::TextureFormat::D24,   samplerFlags);
+		m_gbufferTex[GBUFFER_RT_NORMAL] = bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, false, 1, bgfx::TextureFormat::BGRA8, samplerFlags);
+		m_gbufferTex[GBUFFER_RT_COLOR]  = bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, false, 1, bgfx::TextureFormat::BGRA8, samplerFlags);
+		m_gbufferTex[GBUFFER_RT_DEPTH]  = bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, false, 1, bgfx::TextureFormat::D24,   samplerFlags);
 		m_gbuffer = bgfx::createFrameBuffer(BX_COUNTOF(m_gbufferTex), m_gbufferTex, true);
 		m_gbuffer = bgfx::createFrameBuffer(BX_COUNTOF(m_gbufferTex), m_gbufferTex, true);
 
 
 		// Make light buffer
 		// Make light buffer
-		m_lightBufferTex = bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, 1, bgfx::TextureFormat::BGRA8, samplerFlags);
+		m_lightBufferTex = bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, false, 1, bgfx::TextureFormat::BGRA8, samplerFlags);
 		bgfx::TextureHandle lightBufferRTs[] =  {
 		bgfx::TextureHandle lightBufferRTs[] =  {
 			m_lightBufferTex
 			m_lightBufferTex
 		};
 		};
@@ -328,8 +328,9 @@ public:
 
 
 		// Reflective shadow map
 		// Reflective shadow map
 		m_shadowBufferTex[SHADOW_RT_RSM] = bgfx::createTexture2D(
 		m_shadowBufferTex[SHADOW_RT_RSM] = bgfx::createTexture2D(
-				SHADOW_MAP_DIM
+				  SHADOW_MAP_DIM
 				, SHADOW_MAP_DIM
 				, SHADOW_MAP_DIM
+				, false
 				, 1
 				, 1
 				, bgfx::TextureFormat::BGRA8,
 				, bgfx::TextureFormat::BGRA8,
 				rsmFlags
 				rsmFlags
@@ -337,8 +338,9 @@ public:
 
 
 		// Typical shadow map
 		// Typical shadow map
 		m_shadowBufferTex[SHADOW_RT_DEPTH] = bgfx::createTexture2D(
 		m_shadowBufferTex[SHADOW_RT_DEPTH] = bgfx::createTexture2D(
-				SHADOW_MAP_DIM
+				  SHADOW_MAP_DIM
 				, SHADOW_MAP_DIM
 				, SHADOW_MAP_DIM
+				, false
 				, 1
 				, 1
 				, bgfx::TextureFormat::D16,
 				, bgfx::TextureFormat::D16,
 				BGFX_TEXTURE_RT/* | BGFX_TEXTURE_COMPARE_LEQUAL*/
 				BGFX_TEXTURE_RT/* | BGFX_TEXTURE_COMPARE_LEQUAL*/

+ 2 - 1
examples/common/bgfx_utils.cpp

@@ -304,7 +304,7 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _filePath,
 
 
 		if (NULL != out)
 		if (NULL != out)
 		{
 		{
-			handle = bgfx::createTexture2D(uint16_t(width), uint16_t(height), 1
+			handle = bgfx::createTexture2D(uint16_t(width), uint16_t(height), false, 1
 											, format
 											, format
 											, _flags
 											, _flags
 											, bgfx::copy(out, width*height*bpp/8)
 											, bgfx::copy(out, width*height*bpp/8)
@@ -318,6 +318,7 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _filePath,
 					, uint16_t(height)
 					, uint16_t(height)
 					, 0
 					, 0
 					, false
 					, false
+					, false
 					, 1
 					, 1
 					, format
 					, format
 					);
 					);

+ 2 - 0
examples/common/cube_atlas.cpp

@@ -273,6 +273,7 @@ Atlas::Atlas(uint16_t _textureSize, uint16_t _maxRegionsCount)
 	memset(m_textureBuffer, 0, _textureSize * _textureSize * 6 * 4);
 	memset(m_textureBuffer, 0, _textureSize * _textureSize * 6 * 4);
 
 
 	m_textureHandle = bgfx::createTextureCube(_textureSize
 	m_textureHandle = bgfx::createTextureCube(_textureSize
+		, false
 		, 1
 		, 1
 		, bgfx::TextureFormat::BGRA8
 		, bgfx::TextureFormat::BGRA8
 		);
 		);
@@ -296,6 +297,7 @@ Atlas::Atlas(uint16_t _textureSize, const uint8_t* _textureBuffer, uint16_t _reg
 	memcpy(m_textureBuffer, _textureBuffer, getTextureBufferSize() );
 	memcpy(m_textureBuffer, _textureBuffer, getTextureBufferSize() );
 
 
 	m_textureHandle = bgfx::createTextureCube(_textureSize
 	m_textureHandle = bgfx::createTextureCube(_textureSize
+		, false
 		, 1
 		, 1
 		, bgfx::TextureFormat::BGRA8
 		, bgfx::TextureFormat::BGRA8
 		, BGFX_TEXTURE_NONE
 		, BGFX_TEXTURE_NONE

+ 18 - 2
examples/common/imgui/imgui.cpp

@@ -410,7 +410,15 @@ struct Imgui
 		const ImguiFontHandle handle = { m_fontHandle.alloc() };
 		const ImguiFontHandle handle = { m_fontHandle.alloc() };
 		const bgfx::Memory* mem = bgfx::alloc(m_textureWidth * m_textureHeight);
 		const bgfx::Memory* mem = bgfx::alloc(m_textureWidth * m_textureHeight);
 		stbtt_BakeFontBitmap( (uint8_t*)_data, 0, _fontSize, mem->data, m_textureWidth, m_textureHeight, 32, 96, m_fonts[handle.idx].m_cdata);
 		stbtt_BakeFontBitmap( (uint8_t*)_data, 0, _fontSize, mem->data, m_textureWidth, m_textureHeight, 32, 96, m_fonts[handle.idx].m_cdata);
-		m_fonts[handle.idx].m_texture = bgfx::createTexture2D(m_textureWidth, m_textureHeight, 1, bgfx::TextureFormat::R8, BGFX_TEXTURE_NONE, mem);
+		m_fonts[handle.idx].m_texture = bgfx::createTexture2D(
+			  m_textureWidth
+			, m_textureHeight
+			, false
+			, 1
+			, bgfx::TextureFormat::R8
+			, BGFX_TEXTURE_NONE
+			, mem
+			);
 		m_fonts[handle.idx].m_size = _fontSize;
 		m_fonts[handle.idx].m_size = _fontSize;
 #else
 #else
 		const ImguiFontHandle handle = { bgfx::invalidHandle };
 		const ImguiFontHandle handle = { bgfx::invalidHandle };
@@ -448,7 +456,15 @@ struct Imgui
 			}
 			}
 		}
 		}
 
 
-		return bgfx::createTexture2D(uint16_t(_width), uint16_t(_height), 0, bgfx::TextureFormat::BGRA8, 0, mem);
+		return bgfx::createTexture2D(
+					  uint16_t(_width)
+					, uint16_t(_height)
+					, false
+					, 1
+					, bgfx::TextureFormat::BGRA8
+					, 0
+					, mem
+					);
 	}
 	}
 
 
 	ImguiFontHandle create(float _fontSize, bx::AllocatorI* _allocator)
 	ImguiFontHandle create(float _fontSize, bx::AllocatorI* _allocator)

+ 3 - 1
examples/common/imgui/ocornut_imgui.cpp

@@ -473,8 +473,10 @@ struct OcornutImguiContext
 
 
 		io.Fonts->GetTexDataAsRGBA32(&data, &width, &height);
 		io.Fonts->GetTexDataAsRGBA32(&data, &width, &height);
 
 
-		m_texture = bgfx::createTexture2D( (uint16_t)width
+		m_texture = bgfx::createTexture2D(
+			  (uint16_t)width
 			, (uint16_t)height
 			, (uint16_t)height
+			, false
 			, 1
 			, 1
 			, bgfx::TextureFormat::BGRA8
 			, bgfx::TextureFormat::BGRA8
 			, 0
 			, 0

+ 4 - 2
examples/common/nanovg/nanovg_bgfx.cpp

@@ -269,7 +269,7 @@ namespace
 		const bgfx::Memory* mem = bgfx::alloc(4*4*4);
 		const bgfx::Memory* mem = bgfx::alloc(4*4*4);
 		uint32_t* bgra8 = (uint32_t*)mem->data;
 		uint32_t* bgra8 = (uint32_t*)mem->data;
 		memset(bgra8, 0, 4*4*4);
 		memset(bgra8, 0, 4*4*4);
-		gl->texMissing = bgfx::createTexture2D(4, 4, 0, bgfx::TextureFormat::BGRA8, 0, mem);
+		gl->texMissing = bgfx::createTexture2D(4, 4, false, 1, bgfx::TextureFormat::BGRA8, 0, mem);
 
 
 		gl->u_scissorMat      = bgfx::createUniform("u_scissorMat",      bgfx::UniformType::Mat3);
 		gl->u_scissorMat      = bgfx::createUniform("u_scissorMat",      bgfx::UniformType::Mat3);
 		gl->u_paintMat        = bgfx::createUniform("u_paintMat",        bgfx::UniformType::Mat3);
 		gl->u_paintMat        = bgfx::createUniform("u_paintMat",        bgfx::UniformType::Mat3);
@@ -326,8 +326,10 @@ namespace
 			mem = bgfx::copy(_rgba, tex->height * pitch);
 			mem = bgfx::copy(_rgba, tex->height * pitch);
 		}
 		}
 
 
-		tex->id = bgfx::createTexture2D(tex->width
+		tex->id = bgfx::createTexture2D(
+						  tex->width
 						, tex->height
 						, tex->height
+						, false
 						, 1
 						, 1
 						, NVG_TEXTURE_RGBA == _type ? bgfx::TextureFormat::RGBA8 : bgfx::TextureFormat::R8
 						, NVG_TEXTURE_RGBA == _type ? bgfx::TextureFormat::RGBA8 : bgfx::TextureFormat::R8
 						, BGFX_TEXTURE_NONE
 						, BGFX_TEXTURE_NONE

+ 27 - 9
include/bgfx/bgfx.h

@@ -1516,6 +1516,14 @@ namespace bgfx
 
 
 	/// Calculate amount of memory required for texture.
 	/// Calculate amount of memory required for texture.
 	///
 	///
+	/// @param[in] _width Width.
+	/// @param[in] _height Height.
+	/// @param[in] _depth Depth.
+	/// @param[in] _cubeMap Indicates that texture contains cubemap.
+	/// @param[in] _hasMips Indicates that texture contains full mip-map chain.
+	/// @param[in] _numLayers Number of layers in texture array.
+	/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
+	///
 	/// @attention C99 equivalent is `bgfx_calc_texture_size`.
 	/// @attention C99 equivalent is `bgfx_calc_texture_size`.
 	///
 	///
 	void calcTextureSize(
 	void calcTextureSize(
@@ -1524,7 +1532,8 @@ namespace bgfx
 		, uint16_t _height
 		, uint16_t _height
 		, uint16_t _depth
 		, uint16_t _depth
 		, bool _cubeMap
 		, bool _cubeMap
-		, uint8_t _numMips
+		, bool _hasMips
+		, uint16_t _numLayers
 		, TextureFormat::Enum _format
 		, TextureFormat::Enum _format
 		);
 		);
 
 
@@ -1555,7 +1564,9 @@ namespace bgfx
 	///
 	///
 	/// @param[in] _width Width.
 	/// @param[in] _width Width.
 	/// @param[in] _height Height.
 	/// @param[in] _height Height.
-	/// @param[in] _numMips Number of mip-maps.
+	/// @param[in] _hasMips Indicates that texture contains full mip-map chain.
+	/// @param[in] _numLayers Number of layers in texture array. Must be 1 if caps
+	///   `BGFX_CAPS_TEXTURE_2D_ARRAY` flag is not set.
 	/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
 	/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
 	/// @param[in] _flags Default texture sampling mode is linear, and wrap mode
 	/// @param[in] _flags Default texture sampling mode is linear, and wrap mode
 	///   is repeat.
 	///   is repeat.
@@ -1571,7 +1582,8 @@ namespace bgfx
 	TextureHandle createTexture2D(
 	TextureHandle createTexture2D(
 		  uint16_t _width
 		  uint16_t _width
 		, uint16_t _height
 		, uint16_t _height
-		, uint8_t _numMips
+		, bool     _hasMips
+		, uint16_t _numLayers
 		, TextureFormat::Enum _format
 		, TextureFormat::Enum _format
 		, uint32_t _flags = BGFX_TEXTURE_NONE
 		, uint32_t _flags = BGFX_TEXTURE_NONE
 		, const Memory* _mem = NULL
 		, const Memory* _mem = NULL
@@ -1582,7 +1594,9 @@ namespace bgfx
 	///
 	///
 	/// @param[in] _ratio Frame buffer size in respect to back-buffer size. See:
 	/// @param[in] _ratio Frame buffer size in respect to back-buffer size. See:
 	///   `BackbufferRatio::Enum`.
 	///   `BackbufferRatio::Enum`.
-	/// @param[in] _numMips Number of mip-maps.
+	/// @param[in] _hasMips Indicates that texture contains full mip-map chain.
+	/// @param[in] _numLayers Number of layers in texture array. Must be 1 if caps
+	///   `BGFX_CAPS_TEXTURE_2D_ARRAY` flag is not set.
 	/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
 	/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
 	/// @param[in] _flags Default texture sampling mode is linear, and wrap mode
 	/// @param[in] _flags Default texture sampling mode is linear, and wrap mode
 	///   is repeat.
 	///   is repeat.
@@ -1595,7 +1609,8 @@ namespace bgfx
 	///
 	///
 	TextureHandle createTexture2D(
 	TextureHandle createTexture2D(
 		  BackbufferRatio::Enum _ratio
 		  BackbufferRatio::Enum _ratio
-		, uint8_t _numMips
+		, bool _hasMips
+		, uint16_t _numLayers
 		, TextureFormat::Enum _format
 		, TextureFormat::Enum _format
 		, uint32_t _flags = BGFX_TEXTURE_NONE
 		, uint32_t _flags = BGFX_TEXTURE_NONE
 		);
 		);
@@ -1605,7 +1620,7 @@ namespace bgfx
 	/// @param[in] _width Width.
 	/// @param[in] _width Width.
 	/// @param[in] _height Height.
 	/// @param[in] _height Height.
 	/// @param[in] _depth Depth.
 	/// @param[in] _depth Depth.
-	/// @param[in] _numMips Number of mip-maps.
+	/// @param[in] _hasMips Indicates that texture contains full mip-map chain.
 	/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
 	/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
 	/// @param[in] _flags Default texture sampling mode is linear, and wrap mode
 	/// @param[in] _flags Default texture sampling mode is linear, and wrap mode
 	///   is repeat.
 	///   is repeat.
@@ -1622,7 +1637,7 @@ namespace bgfx
 		  uint16_t _width
 		  uint16_t _width
 		, uint16_t _height
 		, uint16_t _height
 		, uint16_t _depth
 		, uint16_t _depth
-		, uint8_t _numMips
+		, bool _hasMips
 		, TextureFormat::Enum _format
 		, TextureFormat::Enum _format
 		, uint32_t _flags = BGFX_TEXTURE_NONE
 		, uint32_t _flags = BGFX_TEXTURE_NONE
 		, const Memory* _mem = NULL
 		, const Memory* _mem = NULL
@@ -1631,7 +1646,9 @@ namespace bgfx
 	/// Create Cube texture.
 	/// Create Cube texture.
 	///
 	///
 	/// @param[in] _size Cube side size.
 	/// @param[in] _size Cube side size.
-	/// @param[in] _numMips Number of mip-maps.
+	/// @param[in] _hasMips Indicates that texture contains full mip-map chain.
+	/// @param[in] _numLayers Number of layers in texture array. Must be 1 if caps
+	///   `BGFX_CAPS_TEXTURE_CUBE_ARRAY` flag is not set.
 	/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
 	/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
 	/// @param[in] _flags Default texture sampling mode is linear, and wrap mode
 	/// @param[in] _flags Default texture sampling mode is linear, and wrap mode
 	///   is repeat.
 	///   is repeat.
@@ -1646,7 +1663,8 @@ namespace bgfx
 	///
 	///
 	TextureHandle createTextureCube(
 	TextureHandle createTextureCube(
 		  uint16_t _size
 		  uint16_t _size
-		, uint8_t _numMips
+		, bool _hasMips
+		, uint16_t _numLayers
 		, TextureFormat::Enum _format
 		, TextureFormat::Enum _format
 		, uint32_t _flags = BGFX_TEXTURE_NONE
 		, uint32_t _flags = BGFX_TEXTURE_NONE
 		, const Memory* _mem = NULL
 		, const Memory* _mem = NULL

+ 3 - 1
include/bgfx/bgfxdefines.h

@@ -6,7 +6,7 @@
 #ifndef BGFX_DEFINES_H_HEADER_GUARD
 #ifndef BGFX_DEFINES_H_HEADER_GUARD
 #define BGFX_DEFINES_H_HEADER_GUARD
 #define BGFX_DEFINES_H_HEADER_GUARD
 
 
-#define BGFX_API_VERSION UINT32_C(17)
+#define BGFX_API_VERSION UINT32_C(18)
 
 
 ///
 ///
 #define BGFX_STATE_RGB_WRITE               UINT64_C(0x0000000000000001) //!< Enable RGB write.
 #define BGFX_STATE_RGB_WRITE               UINT64_C(0x0000000000000001) //!< Enable RGB write.
@@ -386,6 +386,8 @@
 #define BGFX_CAPS_OCCLUSION_QUERY        UINT64_C(0x0000000000040000) //!< Occlusion query is supported.
 #define BGFX_CAPS_OCCLUSION_QUERY        UINT64_C(0x0000000000040000) //!< Occlusion query is supported.
 #define BGFX_CAPS_ALPHA_TO_COVERAGE      UINT64_C(0x0000000000080000) //!< Alpha to coverage is supported.
 #define BGFX_CAPS_ALPHA_TO_COVERAGE      UINT64_C(0x0000000000080000) //!< Alpha to coverage is supported.
 #define BGFX_CAPS_CONSERVATIVE_RASTER    UINT64_C(0x0000000000100000) //!< Conservative rasterization is supported.
 #define BGFX_CAPS_CONSERVATIVE_RASTER    UINT64_C(0x0000000000100000) //!< Conservative rasterization is supported.
+#define BGFX_CAPS_TEXTURE_2D_ARRAY       UINT64_C(0x0000000000200000) //!< 2D texture array is supported.
+#define BGFX_CAPS_TEXTURE_CUBE_ARRAY     UINT64_C(0x0000000000400000) //!< Cubemap texture array is supported.
 
 
 ///
 ///
 #define BGFX_CAPS_FORMAT_TEXTURE_NONE             UINT16_C(0x0000) //!< Texture format is not supported.
 #define BGFX_CAPS_FORMAT_TEXTURE_NONE             UINT16_C(0x0000) //!< Texture format is not supported.

+ 5 - 5
include/bgfx/c99/bgfx.h

@@ -653,22 +653,22 @@ BGFX_C_API bgfx_program_handle_t bgfx_create_compute_program(bgfx_shader_handle_
 BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle);
 BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle);
 
 
 /**/
 /**/
-BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, bgfx_texture_format_t _format);
+BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format);
 
 
 /**/
 /**/
 BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info);
 BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info);
 
 
 /**/
 /**/
-BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
+BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
 
 
 /**/
 /**/
-BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags);
+BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags);
 
 
 /**/
 /**/
-BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
+BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
 
 
 /**/
 /**/
-BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
+BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
 
 
 /**/
 /**/
 BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
 BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);

+ 5 - 5
include/bgfx/c99/bgfxplatform.h

@@ -127,12 +127,12 @@ typedef struct bgfx_interface_vtbl
     bgfx_program_handle_t (*create_program)(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders);
     bgfx_program_handle_t (*create_program)(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders);
     bgfx_program_handle_t (*create_compute_program)(bgfx_shader_handle_t _csh, bool _destroyShaders);
     bgfx_program_handle_t (*create_compute_program)(bgfx_shader_handle_t _csh, bool _destroyShaders);
     void (*destroy_program)(bgfx_program_handle_t _handle);
     void (*destroy_program)(bgfx_program_handle_t _handle);
-    void (*calc_texture_size)(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, bgfx_texture_format_t _format);
+    void (*calc_texture_size)(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format);
     bgfx_texture_handle_t (*create_texture)(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info);
     bgfx_texture_handle_t (*create_texture)(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info);
-    bgfx_texture_handle_t (*create_texture_2d)(uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
-    bgfx_texture_handle_t (*create_texture_2d_scaled)(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags);
-    bgfx_texture_handle_t (*create_texture_3d)(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
-    bgfx_texture_handle_t (*create_texture_cube)(uint16_t _size, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
+    bgfx_texture_handle_t (*create_texture_2d)(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
+    bgfx_texture_handle_t (*create_texture_2d_scaled)(bgfx_backbuffer_ratio_t _ratio, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags);
+    bgfx_texture_handle_t (*create_texture_3d)(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
+    bgfx_texture_handle_t (*create_texture_cube)(uint16_t _size, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
     void (*update_texture_2d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
     void (*update_texture_2d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
     void (*update_texture_3d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem);
     void (*update_texture_3d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem);
     void (*update_texture_cube)(bgfx_texture_handle_t _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
     void (*update_texture_cube)(bgfx_texture_handle_t _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);

+ 34 - 51
src/bgfx.cpp

@@ -472,7 +472,7 @@ namespace bgfx
 		uint8_t* rgba = mem->data;
 		uint8_t* rgba = mem->data;
 		charsetFillTexture(vga8x8, rgba, 8, pitch, bpp);
 		charsetFillTexture(vga8x8, rgba, 8, pitch, bpp);
 		charsetFillTexture(vga8x16, &rgba[8*pitch], 16, pitch, bpp);
 		charsetFillTexture(vga8x16, &rgba[8*pitch], 16, pitch, bpp);
-		m_texture = createTexture2D(width, height, 1, TextureFormat::R8
+		m_texture = createTexture2D(width, height, false, 1, TextureFormat::R8
 						, BGFX_TEXTURE_MIN_POINT
 						, BGFX_TEXTURE_MIN_POINT
 						| BGFX_TEXTURE_MAG_POINT
 						| BGFX_TEXTURE_MAG_POINT
 						| BGFX_TEXTURE_MIP_POINT
 						| BGFX_TEXTURE_MIP_POINT
@@ -2882,7 +2882,7 @@ error:
 		s_ctx->destroyProgram(_handle);
 		s_ctx->destroyProgram(_handle);
 	}
 	}
 
 
-	void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, TextureFormat::Enum _format)
+	void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format)
 	{
 	{
 		const ImageBlockInfo& blockInfo = getBlockInfo(_format);
 		const ImageBlockInfo& blockInfo = getBlockInfo(_format);
 		const uint8_t  bpp         = blockInfo.bitsPerPixel;
 		const uint8_t  bpp         = blockInfo.bitsPerPixel;
@@ -2894,32 +2894,15 @@ error:
 		_width   = bx::uint16_max(blockWidth  * minBlockX, ( (_width  + blockWidth  - 1) / blockWidth)*blockWidth);
 		_width   = bx::uint16_max(blockWidth  * minBlockX, ( (_width  + blockWidth  - 1) / blockWidth)*blockWidth);
 		_height  = bx::uint16_max(blockHeight * minBlockY, ( (_height + blockHeight - 1) / blockHeight)*blockHeight);
 		_height  = bx::uint16_max(blockHeight * minBlockY, ( (_height + blockHeight - 1) / blockHeight)*blockHeight);
 		_depth   = bx::uint16_max(1, _depth);
 		_depth   = bx::uint16_max(1, _depth);
-		_numMips = uint8_t(bx::uint16_max(1, _numMips) );
-
-		uint32_t width  = _width;
-		uint32_t height = _height;
-		uint32_t depth  = _depth;
-		uint32_t sides  = _cubeMap ? 6 : 1;
-		uint32_t size   = 0;
-
-		for (uint32_t lod = 0; lod < _numMips; ++lod)
-		{
-			width  = bx::uint32_max(blockWidth  * minBlockX, ( (width  + blockWidth  - 1) / blockWidth )*blockWidth);
-			height = bx::uint32_max(blockHeight * minBlockY, ( (height + blockHeight - 1) / blockHeight)*blockHeight);
-			depth  = bx::uint32_max(1, depth);
-
-			size += width*height*depth*bpp/8 * sides;
-
-			width  >>= 1;
-			height >>= 1;
-			depth  >>= 1;
-		}
+		const uint8_t  numMips = calcNumMips(_hasMips, _width, _height, _depth);
+		const uint32_t sides   = _cubeMap ? 6 : 1;
+		const uint32_t size    = _width*_height*_depth*numMips*bpp/8 * sides * _numLayers;
 
 
 		_info.format  = _format;
 		_info.format  = _format;
 		_info.width   = _width;
 		_info.width   = _width;
 		_info.height  = _height;
 		_info.height  = _height;
 		_info.depth   = _depth;
 		_info.depth   = _depth;
-		_info.numMips = _numMips;
+		_info.numMips = numMips;
 		_info.cubeMap = _cubeMap;
 		_info.cubeMap = _cubeMap;
 		_info.storageSize  = size;
 		_info.storageSize  = size;
 		_info.bitsPerPixel = bpp;
 		_info.bitsPerPixel = bpp;
@@ -2950,7 +2933,7 @@ error:
 		_height = bx::uint16_max(1, _height);
 		_height = bx::uint16_max(1, _height);
 	}
 	}
 
 
-	static TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
+	static TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
 	{
 	{
 		BGFX_CHECK_MAIN_THREAD();
 		BGFX_CHECK_MAIN_THREAD();
 
 
@@ -2969,13 +2952,13 @@ error:
 			getTextureSizeFromRatio(_ratio, _width, _height);
 			getTextureSizeFromRatio(_ratio, _width, _height);
 		}
 		}
 
 
-		_numMips = calcNumMips(_numMips, _width, _height);
+		const uint8_t numMips = calcNumMips(_hasMips, _width, _height);
 
 
 		if (BX_ENABLED(BGFX_CONFIG_DEBUG)
 		if (BX_ENABLED(BGFX_CONFIG_DEBUG)
 		&&  NULL != _mem)
 		&&  NULL != _mem)
 		{
 		{
 			TextureInfo ti;
 			TextureInfo ti;
-			calcTextureSize(ti, _width, _height, 1, false, _numMips, _format);
+			calcTextureSize(ti, _width, _height, 1, false, _hasMips, _numLayers, _format);
 			BX_CHECK(ti.storageSize == _mem->size
 			BX_CHECK(ti.storageSize == _mem->size
 				, "createTexture2D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)"
 				, "createTexture2D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)"
 				, ti.storageSize
 				, ti.storageSize
@@ -2995,7 +2978,7 @@ error:
 		tc.m_height  = _height;
 		tc.m_height  = _height;
 		tc.m_sides   = 0;
 		tc.m_sides   = 0;
 		tc.m_depth   = 0;
 		tc.m_depth   = 0;
-		tc.m_numMips = _numMips;
+		tc.m_numMips = numMips;
 		tc.m_format  = _format;
 		tc.m_format  = _format;
 		tc.m_cubeMap = false;
 		tc.m_cubeMap = false;
 		tc.m_mem     = _mem;
 		tc.m_mem     = _mem;
@@ -3004,19 +2987,19 @@ error:
 		return s_ctx->createTexture(mem, _flags, 0, NULL, _ratio);
 		return s_ctx->createTexture(mem, _flags, 0, NULL, _ratio);
 	}
 	}
 
 
-	TextureHandle createTexture2D(uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
+	TextureHandle createTexture2D(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
 	{
 	{
 		BX_CHECK(_width > 0 && _height > 0, "Invalid texture size (width %d, height %d).", _width, _height);
 		BX_CHECK(_width > 0 && _height > 0, "Invalid texture size (width %d, height %d).", _width, _height);
-		return createTexture2D(BackbufferRatio::Count, _width, _height, _numMips, _format, _flags, _mem);
+		return createTexture2D(BackbufferRatio::Count, _width, _height, _hasMips, _numLayers, _format, _flags, _mem);
 	}
 	}
 
 
-	TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags)
+	TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags)
 	{
 	{
 		BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio.");
 		BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio.");
-		return createTexture2D(_ratio, 0, 0, _numMips, _format, _flags, NULL);
+		return createTexture2D(_ratio, 0, 0, _hasMips, _numLayers, _format, _flags, NULL);
 	}
 	}
 
 
-	TextureHandle createTexture3D(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
+	TextureHandle createTexture3D(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
 	{
 	{
 		BGFX_CHECK_MAIN_THREAD();
 		BGFX_CHECK_MAIN_THREAD();
 		BGFX_CHECK_CAPS(BGFX_CAPS_TEXTURE_3D, "Texture3D is not supported!");
 		BGFX_CHECK_CAPS(BGFX_CAPS_TEXTURE_3D, "Texture3D is not supported!");
@@ -3025,13 +3008,13 @@ error:
 			, getName(_format)
 			, getName(_format)
 			);
 			);
 
 
-		_numMips = calcNumMips(_numMips, _width, _height, _depth);
+		const uint8_t numMips = calcNumMips(_hasMips, _width, _height, _depth);
 
 
 		if (BX_ENABLED(BGFX_CONFIG_DEBUG)
 		if (BX_ENABLED(BGFX_CONFIG_DEBUG)
 		&&  NULL != _mem)
 		&&  NULL != _mem)
 		{
 		{
 			TextureInfo ti;
 			TextureInfo ti;
-			calcTextureSize(ti, _width, _height, _depth, false, _numMips, _format);
+			calcTextureSize(ti, _width, _height, _depth, false, _hasMips, 1, _format);
 			BX_CHECK(ti.storageSize == _mem->size
 			BX_CHECK(ti.storageSize == _mem->size
 				, "createTexture3D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)"
 				, "createTexture3D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)"
 				, ti.storageSize
 				, ti.storageSize
@@ -3051,7 +3034,7 @@ error:
 		tc.m_height  = _height;
 		tc.m_height  = _height;
 		tc.m_sides   = 0;
 		tc.m_sides   = 0;
 		tc.m_depth   = _depth;
 		tc.m_depth   = _depth;
-		tc.m_numMips = _numMips;
+		tc.m_numMips = numMips;
 		tc.m_format  = _format;
 		tc.m_format  = _format;
 		tc.m_cubeMap = false;
 		tc.m_cubeMap = false;
 		tc.m_mem     = _mem;
 		tc.m_mem     = _mem;
@@ -3060,7 +3043,7 @@ error:
 		return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count);
 		return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count);
 	}
 	}
 
 
-	TextureHandle createTextureCube(uint16_t _size, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
+	TextureHandle createTextureCube(uint16_t _size, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
 	{
 	{
 		BGFX_CHECK_MAIN_THREAD();
 		BGFX_CHECK_MAIN_THREAD();
 		BX_CHECK(0 != (g_caps.formats[_format] & (BGFX_CAPS_FORMAT_TEXTURE_CUBE|BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED|BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB) )
 		BX_CHECK(0 != (g_caps.formats[_format] & (BGFX_CAPS_FORMAT_TEXTURE_CUBE|BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED|BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB) )
@@ -3068,13 +3051,13 @@ error:
 			, getName(_format)
 			, getName(_format)
 			);
 			);
 
 
-		_numMips = calcNumMips(_numMips, _size, _size);
+		const uint8_t numMips = calcNumMips(_hasMips, _size, _size);
 
 
 		if (BX_ENABLED(BGFX_CONFIG_DEBUG)
 		if (BX_ENABLED(BGFX_CONFIG_DEBUG)
 		&&  NULL != _mem)
 		&&  NULL != _mem)
 		{
 		{
 			TextureInfo ti;
 			TextureInfo ti;
-			calcTextureSize(ti, _size, _size, 1, true, _numMips, _format);
+			calcTextureSize(ti, _size, _size, 1, true, _hasMips, _numLayers, _format);
 			BX_CHECK(ti.storageSize == _mem->size
 			BX_CHECK(ti.storageSize == _mem->size
 				, "createTextureCube: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)"
 				, "createTextureCube: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)"
 				, ti.storageSize
 				, ti.storageSize
@@ -3094,7 +3077,7 @@ error:
 		tc.m_height  = _size;
 		tc.m_height  = _size;
 		tc.m_sides   = 6;
 		tc.m_sides   = 6;
 		tc.m_depth   = 0;
 		tc.m_depth   = 0;
-		tc.m_numMips = _numMips;
+		tc.m_numMips = numMips;
 		tc.m_format  = _format;
 		tc.m_format  = _format;
 		tc.m_cubeMap = true;
 		tc.m_cubeMap = true;
 		tc.m_mem     = _mem;
 		tc.m_mem     = _mem;
@@ -3177,7 +3160,7 @@ error:
 	FrameBufferHandle createFrameBuffer(uint16_t _width, uint16_t _height, TextureFormat::Enum _format, uint32_t _textureFlags)
 	FrameBufferHandle createFrameBuffer(uint16_t _width, uint16_t _height, TextureFormat::Enum _format, uint32_t _textureFlags)
 	{
 	{
 		_textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT;
 		_textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT;
-		TextureHandle th = createTexture2D(_width, _height, 1, _format, _textureFlags);
+		TextureHandle th = createTexture2D(_width, _height, false, 1, _format, _textureFlags);
 		return createFrameBuffer(1, &th, true);
 		return createFrameBuffer(1, &th, true);
 	}
 	}
 
 
@@ -3185,7 +3168,7 @@ error:
 	{
 	{
 		BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio.");
 		BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio.");
 		_textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT;
 		_textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT;
-		TextureHandle th = createTexture2D(_ratio, 1, _format, _textureFlags);
+		TextureHandle th = createTexture2D(_ratio, false, 1, _format, _textureFlags);
 		return createFrameBuffer(1, &th, true);
 		return createFrameBuffer(1, &th, true);
 	}
 	}
 
 
@@ -4156,10 +4139,10 @@ BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle)
 	bgfx::destroyProgram(handle.cpp);
 	bgfx::destroyProgram(handle.cpp);
 }
 }
 
 
-BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, bgfx_texture_format_t _format)
+BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format)
 {
 {
 	bgfx::TextureInfo& info = *(bgfx::TextureInfo*)_info;
 	bgfx::TextureInfo& info = *(bgfx::TextureInfo*)_info;
-	bgfx::calcTextureSize(info, _width, _height, _depth, _cubeMap, _numMips, bgfx::TextureFormat::Enum(_format) );
+	bgfx::calcTextureSize(info, _width, _height, _depth, _cubeMap, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format) );
 }
 }
 
 
 BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info)
 BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info)
@@ -4170,31 +4153,31 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem,
 	return handle.c;
 	return handle.c;
 }
 }
 
 
-BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem)
+BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem)
 {
 {
 	union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle;
 	union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle;
-	handle.cpp = bgfx::createTexture2D(_width, _height, _numMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem);
+	handle.cpp = bgfx::createTexture2D(_width, _height, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem);
 	return handle.c;
 	return handle.c;
 }
 }
 
 
-BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags)
+BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags)
 {
 {
 	union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle;
 	union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle;
-	handle.cpp = bgfx::createTexture2D(bgfx::BackbufferRatio::Enum(_ratio), _numMips, bgfx::TextureFormat::Enum(_format), _flags);
+	handle.cpp = bgfx::createTexture2D(bgfx::BackbufferRatio::Enum(_ratio), _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags);
 	return handle.c;
 	return handle.c;
 }
 }
 
 
-BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem)
+BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem)
 {
 {
 	union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle;
 	union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle;
-	handle.cpp = bgfx::createTexture3D(_width, _height, _depth, _numMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem);
+	handle.cpp = bgfx::createTexture3D(_width, _height, _depth, _hasMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem);
 	return handle.c;
 	return handle.c;
 }
 }
 
 
-BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem)
+BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem)
 {
 {
 	union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle;
 	union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle;
-	handle.cpp = bgfx::createTextureCube(_size, _numMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem);
+	handle.cpp = bgfx::createTextureCube(_size, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem);
 	return handle.c;
 	return handle.c;
 }
 }
 
 

+ 4 - 3
src/bgfx_p.h

@@ -364,9 +364,9 @@ namespace bgfx
 			;
 			;
 	}
 	}
 
 
-	inline uint8_t calcNumMips(uint8_t _numMips, uint16_t _width, uint16_t _height, uint16_t _depth = 1)
+	inline uint8_t calcNumMips(bool _hasMips, uint16_t _width, uint16_t _height, uint16_t _depth = 1)
 	{
 	{
-		if (1 < _numMips)
+		if (_hasMips)
 		{
 		{
 			const uint32_t max = bx::uint32_max(bx::uint32_max(_width, _height), _depth);
 			const uint32_t max = bx::uint32_max(bx::uint32_max(_width, _height), _depth);
 			const uint32_t num = 1 + uint32_t(bx::flog2(float(max) ) );
 			const uint32_t num = 1 + uint32_t(bx::flog2(float(max) ) );
@@ -3097,7 +3097,8 @@ namespace bgfx
 					, (uint16_t)imageContainer.m_height
 					, (uint16_t)imageContainer.m_height
 					, (uint16_t)imageContainer.m_depth
 					, (uint16_t)imageContainer.m_depth
 					, imageContainer.m_cubeMap
 					, imageContainer.m_cubeMap
-					, imageContainer.m_numMips
+					, imageContainer.m_numMips > 1
+					, 1
 					, TextureFormat::Enum(imageContainer.m_format)
 					, TextureFormat::Enum(imageContainer.m_format)
 					);
 					);
 			}
 			}