ソースを参照

Fixed immutable texture array.

Branimir Karadžić 9 年 前
コミット
15da3a3d5a
3 ファイル変更101 行追加77 行削除
  1. 1 1
      src/image.cpp
  2. 3 3
      src/renderer_d3d11.cpp
  3. 97 73
      src/renderer_gl.cpp

+ 1 - 1
src/image.cpp

@@ -3805,7 +3805,7 @@ namespace bgfx
 
 			for (uint8_t lod = 0, num = _imageContainer.m_numMips; lod < num; ++lod)
 			{
-				uint32_t imageSize = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE);
+				uint32_t imageSize = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE) / _imageContainer.m_numLayers;
 				offset += sizeof(uint32_t);
 
 				width  = bx::uint32_max(blockWidth  * minBlockX, ( (width  + blockWidth  - 1) / blockWidth )*blockWidth);

+ 3 - 3
src/renderer_d3d11.cpp

@@ -4294,10 +4294,11 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 			const bool compressed = isCompressed(TextureFormat::Enum(m_textureFormat) );
 			const bool swizzle    = TextureFormat::BGRA8 == m_textureFormat && 0 != (m_flags&BGFX_TEXTURE_COMPUTE_WRITE);
 
-			BX_TRACE("Texture %3d: %s (requested: %s), %dx%d%s%s%s."
+			BX_TRACE("Texture %3d: %s (requested: %s), layers %d, %dx%d%s%s%s."
 				, getHandle()
 				, getName( (TextureFormat::Enum)m_textureFormat)
 				, getName( (TextureFormat::Enum)m_requestedFormat)
+				, numLayers
 				, textureWidth
 				, textureHeight
 				, imageContainer.m_cubeMap ? "x6" : ""
@@ -4407,6 +4408,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 					desc.Width  = textureWidth;
 					desc.Height = textureHeight;
 					desc.MipLevels  = numMips;
+					desc.ArraySize  = numSides;
 					desc.Format     = format;
 					desc.SampleDesc = msaa;
 					desc.Usage      = kk == 0 || blit ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE;
@@ -4443,7 +4445,6 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 
 					if (imageContainer.m_cubeMap)
 					{
-						desc.ArraySize = 6 * numLayers;
 						desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
 						if (1 < numLayers)
 						{
@@ -4459,7 +4460,6 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 					}
 					else
 					{
-						desc.ArraySize = numLayers;
 						if (msaaSample)
 						{
 							if (1 < numLayers)

+ 97 - 73
src/renderer_gl.cpp

@@ -4260,6 +4260,58 @@ namespace bgfx { namespace gl
 		m_vcref.invalidate(s_renderGL->m_vaoStateCache);
 	}
 
+	static void texSubImage(
+		  GLenum _target
+		, GLint _level
+		, GLint _xoffset
+		, GLint _yoffset
+		, GLint _zoffset
+		, GLsizei _width
+		, GLsizei _height
+		, GLsizei _depth
+		, GLenum _format
+		, GLenum _type
+		, const GLvoid* _data
+	)
+	{
+		if (_target == GL_TEXTURE_3D
+		||  _target == GL_TEXTURE_2D_ARRAY
+		||  _target == GL_TEXTURE_CUBE_MAP_ARRAY)
+		{
+			GL_CHECK(glTexSubImage3D(
+				  _target
+				, _level
+				, _xoffset
+				, _yoffset
+				, _zoffset
+				, _width
+				, _height
+				, _depth
+				, _format
+				, _type
+				, _data
+				) );
+		}
+		else if (_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
+		{
+		}
+		else
+		{
+			BX_UNUSED(_zoffset, _depth);
+			GL_CHECK(glTexSubImage2D(
+				  _target
+				, _level
+				, _xoffset
+				, _yoffset
+				, _width
+				, _height
+				, _format
+				, _type
+				, _data
+				) );
+		}
+	}
+
 	static void texImage(
 		  GLenum _target
 		, uint32_t _msaaQuality
@@ -4274,9 +4326,7 @@ namespace bgfx { namespace gl
 		, const GLvoid* _data
 	)
 	{
-		if (_target == GL_TEXTURE_3D
-		||  _target == GL_TEXTURE_2D_ARRAY
-		||  _target == GL_TEXTURE_CUBE_MAP_ARRAY)
+		if (_target == GL_TEXTURE_3D)
 		{
 			GL_CHECK(glTexImage3D(
 				  _target
@@ -4291,6 +4341,11 @@ namespace bgfx { namespace gl
 				, _data
 				) );
 		}
+		else if (_target == GL_TEXTURE_2D_ARRAY
+			 ||  _target == GL_TEXTURE_CUBE_MAP_ARRAY)
+		{
+			texSubImage(_target, _level, 0, 0, _depth, _width, _height, 1, _format, _type, _data);
+		}
 		else if (_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
 		{
 		}
@@ -4323,7 +4378,7 @@ namespace bgfx { namespace gl
 		BX_UNUSED(_msaaQuality, _depth, _border, _data);
 	}
 
-	static void texSubImage(
+	static void compressedTexSubImage(
 		  GLenum _target
 		, GLint _level
 		, GLint _xoffset
@@ -4333,17 +4388,13 @@ namespace bgfx { namespace gl
 		, GLsizei _height
 		, GLsizei _depth
 		, GLenum _format
-		, GLenum _type
+		, GLsizei _imageSize
 		, const GLvoid* _data
 	)
 	{
-		if (_target == GL_TEXTURE_3D
-		||  _target == GL_TEXTURE_2D_ARRAY
-		||  _target == GL_TEXTURE_CUBE_MAP_ARRAY)
+		if (_target == GL_TEXTURE_3D)
 		{
-BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
-
-			GL_CHECK(glTexSubImage3D(
+			GL_CHECK(glCompressedTexSubImage3D(
 				  _target
 				, _level
 				, _xoffset
@@ -4353,17 +4404,14 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 				, _height
 				, _depth
 				, _format
-				, _type
+				, _imageSize
 				, _data
 				) );
 		}
-		else if (_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
-		{
-		}
 		else
 		{
 			BX_UNUSED(_zoffset, _depth);
-			GL_CHECK(glTexSubImage2D(
+			GL_CHECK(glCompressedTexSubImage2D(
 				  _target
 				, _level
 				, _xoffset
@@ -4371,7 +4419,7 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 				, _width
 				, _height
 				, _format
-				, _type
+				, _imageSize
 				, _data
 				) );
 		}
@@ -4389,9 +4437,7 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 		, const GLvoid* _data
 	)
 	{
-		if (_target == GL_TEXTURE_3D
-		||  _target == GL_TEXTURE_2D_ARRAY
-		||  _target == GL_TEXTURE_CUBE_MAP_ARRAY)
+		if (_target == GL_TEXTURE_3D)
 		{
 			GL_CHECK(glCompressedTexImage3D(
 				  _target
@@ -4405,6 +4451,11 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 				, _data
 				) );
 		}
+		else if (_target == GL_TEXTURE_2D_ARRAY
+			 ||  _target == GL_TEXTURE_CUBE_MAP_ARRAY)
+		{
+			compressedTexSubImage(_target, _level, 0, 0, _depth, _width, _height, 1, _internalformat, _imageSize, _data);
+		}
 		else if (_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
 		{
 		}
@@ -4424,53 +4475,6 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 		}
 	}
 
-	static void compressedTexSubImage(
-		  GLenum _target
-		, GLint _level
-		, GLint _xoffset
-		, GLint _yoffset
-		, GLint _zoffset
-		, GLsizei _width
-		, GLsizei _height
-		, GLsizei _depth
-		, GLenum _format
-		, GLsizei _imageSize
-		, const GLvoid* _data
-	)
-	{
-		if (_target == GL_TEXTURE_3D)
-		{
-			GL_CHECK(glCompressedTexSubImage3D(
-				  _target
-				, _level
-				, _xoffset
-				, _yoffset
-				, _zoffset
-				, _width
-				, _height
-				, _depth
-				, _format
-				, _imageSize
-				, _data
-				) );
-		}
-		else
-		{
-			BX_UNUSED(_zoffset, _depth);
-			GL_CHECK(glCompressedTexSubImage2D(
-				  _target
-				, _level
-				, _xoffset
-				, _yoffset
-				, _width
-				, _height
-				, _format
-				, _imageSize
-				, _data
-				) );
-		}
-	}
-
 	bool TextureGL::init(GLenum _target, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips, uint32_t _flags)
 	{
 		m_target  = _target;
@@ -4483,6 +4487,10 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 
 		const bool writeOnly    = 0 != (m_flags&BGFX_TEXTURE_RT_WRITE_ONLY);
 		const bool computeWrite = 0 != (m_flags&BGFX_TEXTURE_COMPUTE_WRITE );
+		const bool textureArray = false
+			|| _target == GL_TEXTURE_2D_ARRAY
+			|| _target == GL_TEXTURE_CUBE_MAP_ARRAY
+			;
 
 		if (!writeOnly)
 		{
@@ -4512,6 +4520,17 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 				m_type = tfiRgba8.m_type;
 			}
 
+			if (textureArray)
+			{
+				GL_CHECK(glTexStorage3D(_target
+					, _numMips
+					, s_textureFormat[m_textureFormat].m_internalFmt
+					, m_width
+					, m_height
+					, _depth
+					) );
+			}
+
 			if (computeWrite)
 			{
 				if (_target == GL_TEXTURE_3D)
@@ -4638,7 +4657,8 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 				target = GL_TEXTURE_3D;
 			}
 
-			if (1 < numLayers)
+			const bool textureArray = 1 < numLayers;
+			if (textureArray)
 			{
 				switch (target)
 				{
@@ -4713,6 +4733,10 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 				uint32_t width  = textureWidth;
 				uint32_t height = textureHeight;
 				uint32_t depth  = imageContainer.m_depth;
+				GLenum imageTarget = imageContainer.m_cubeMap && !textureArray
+					? target+side
+					: target
+					;
 
 				for (uint8_t lod = 0, num = numMips; lod < num; ++lod)
 				{
@@ -4720,7 +4744,7 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 					height = bx::uint32_max(1, height);
 					depth  = 1 < imageContainer.m_depth
 						? bx::uint32_max(1, depth)
-						: imageContainer.m_numLayers
+						: side
 						;
 
 					ImageMip mip;
@@ -4729,7 +4753,7 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 						if (compressed
 						&& !convert)
 						{
-							compressedTexImage(target+side
+							compressedTexImage(imageTarget
 								, lod
 								, internalFmt
 								, width
@@ -4756,7 +4780,7 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 								data = temp;
 							}
 
-							texImage(target+side
+							texImage(imageTarget
 								, msaaQuality
 								, lod
 								, internalFmt
@@ -4779,7 +4803,7 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 										  * 4*4*getBitsPerPixel(TextureFormat::Enum(m_textureFormat) )/8
 										  ;
 
-							compressedTexImage(target+side
+							compressedTexImage(imageTarget
 								, lod
 								, internalFmt
 								, width
@@ -4792,7 +4816,7 @@ BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
 						}
 						else
 						{
-							texImage(target+side
+							texImage(imageTarget
 								, msaaQuality
 								, lod
 								, internalFmt