Просмотр исходного кода

Use TextureInfo for caclTextureSize.

bkaradzic 13 лет назад
Родитель
Сommit
96199abe81
3 измененных файлов с 23 добавлено и 15 удалено
  1. 4 4
      include/bgfx.h
  2. 9 7
      src/bgfx.cpp
  3. 10 4
      src/bgfx_p.h

+ 4 - 4
include/bgfx.h

@@ -428,9 +428,12 @@ namespace bgfx
 	struct TextureInfo
 	{
 		TextureFormat::Enum format;
+		uint32_t storageSize;
 		uint16_t width;
 		uint16_t height;
 		uint16_t depth;
+		uint8_t numMips;
+		uint8_t bitsPerPixel;
 	};
 
 	/// Vertex declaration.
@@ -605,11 +608,8 @@ namespace bgfx
 	/// Destroy program.
 	void destroyProgram(ProgramHandle _handle);
 
-	/// Returns number of bits per pixel.
-	uint32_t getBitsPerPixel(TextureFormat::Enum _format);
-
 	/// Calculate amount of memory required for texture.
-	uint32_t calcTextureSize(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format);
+	void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format);
 
 	/// Create texture from memory buffer.
 	TextureHandle createTexture(const Memory* _mem, uint32_t _flags = BGFX_TEXTURE_NONE, TextureInfo* _info = NULL);

+ 9 - 7
src/bgfx.cpp

@@ -909,16 +909,12 @@ namespace bgfx
 		32, // RGB10A2
 	};
 
-	uint32_t getBitsPerPixel(TextureFormat::Enum _format)
-	{
-		return s_bitsPerPixel[_format];
-	}
-
-	uint32_t calcTextureSize(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format)
+	void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format)
 	{
 		uint32_t width = _width;
 		uint32_t height = _height;
 		uint32_t depth = _depth;
+
 		uint32_t bpp = s_bitsPerPixel[_format];
 		uint32_t size = 0;
 
@@ -935,7 +931,13 @@ namespace bgfx
 			depth >>= 1;
 		}
 
-		return size;
+		_info.format = _format;
+		_info.storageSize = size;
+		_info.width = _width;
+		_info.height = _height;
+		_info.depth = _depth;
+		_info.numMips = _numMips;
+		_info.bitsPerPixel = bpp;
 	}
 
 	TextureHandle createTexture(const Memory* _mem, uint32_t _flags, TextureInfo* _info)

+ 10 - 4
src/bgfx_p.h

@@ -1950,17 +1950,23 @@ namespace bgfx
 				Dds dds;
 				if (parseDds(dds, _mem) )
 				{
-					_info->format = dds.m_type;
-					_info->width = (uint16_t)dds.m_width;
-					_info->height = (uint16_t)dds.m_height;
-					_info->depth = (uint16_t)dds.m_depth;
+					calcTextureSize(*_info
+						, (uint16_t)dds.m_width
+						, (uint16_t)dds.m_height
+						, (uint16_t)dds.m_depth
+						, dds.m_numMips
+						, dds.m_type
+						);
 				}
 				else
 				{
 					_info->format = TextureFormat::Unknown;
+					_info->storageSize = 0;
 					_info->width = 0;
 					_info->height = 0;
 					_info->depth = 0;
+					_info->numMips = 0;
+					_info->bitsPerPixel = 0;
 				}
 			}