博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Unity中如何计算带minimap的贴图资源的大小
阅读量:4337 次
发布时间:2019-06-07

本文共 6029 字,大约阅读时间需要 20 分钟。

///     /// 计算贴图大小,包含mipmap内存的叠加    ///     ///     /// 
public static int CalculateTextureSizeBytes(Texture tTexture) { int tWidth = tTexture.width; int tHeight = tTexture.height; if (tTexture is Texture2D) { Texture2D tTex2D = tTexture as Texture2D; int bitsPerPixel = GetBitsPerPixel(tTex2D.format); int mipMapCount = tTex2D.mipmapCount; int mipLevel = 1; int tSize = 0; while (mipLevel <= mipMapCount) { tSize += tWidth * tHeight * bitsPerPixel / 8; tWidth = tWidth / 2; tHeight = tHeight / 2; mipLevel++; } return tSize; } return 0; } /// /// 计算贴图大小,包含mipmap内存的叠加,指定贴图格式 /// /// ///
public static int CalculateTextureSizeBytesByFormat(Texture tTexture, TextureImporterFormat format) { int tWidth = tTexture.width; int tHeight = tTexture.height; if (tTexture is Texture2D) { Texture2D tTex2D = tTexture as Texture2D; if (TextureImporterFormat.Automatic == format) { Debug.LogError("------------------>有贴图格式未设置: 贴图名称:" + tTexture.name); } int bitsPerPixel = GetBitsPerPixelForImportFormat(format); int mipMapCount = tTex2D.mipmapCount; int mipLevel = 1; int tSize = 0; while (mipLevel <= mipMapCount) { tSize += tWidth * tHeight * bitsPerPixel / 8; tWidth = tWidth / 2; tHeight = tHeight / 2; mipLevel++; } return tSize; } return 0; } /// /// 获取对应个是贴图的位大小 /// /// ///
public static int GetBitsPerPixel(TextureFormat format) { switch (format) { case TextureFormat.Alpha8: // Alpha-only texture format. return 8; case TextureFormat.ARGB4444: // A 16 bits/pixel texture format. Texture stores color with an alpha channel. return 16; case TextureFormat.RGBA4444: // A 16 bits/pixel texture format. return 16; case TextureFormat.RGB24: // A color texture format. return 24; case TextureFormat.RGBA32: //Color with an alpha channel texture format. return 32; case TextureFormat.ARGB32: //Color with an alpha channel texture format. return 32; case TextureFormat.RGB565: // A 16 bit color texture format. return 16; case TextureFormat.DXT1: // Compressed color texture format. return 4; case TextureFormat.DXT5: // Compressed color with alpha channel texture format. return 8; case TextureFormat.PVRTC_RGB2:// PowerVR (iOS) 2 bits/pixel compressed color texture format. return 2; case TextureFormat.PVRTC_RGBA2:// PowerVR (iOS) 2 bits/pixel compressed with alpha channel texture format return 2; case TextureFormat.PVRTC_RGB4:// PowerVR (iOS) 4 bits/pixel compressed color texture format. return 4; case TextureFormat.PVRTC_RGBA4:// PowerVR (iOS) 4 bits/pixel compressed with alpha channel texture format return 4; case TextureFormat.ETC_RGB4:// ETC (GLES2.0) 4 bits/pixel compressed RGB texture format. return 4; case TextureFormat.ETC2_RGBA8:// ATC (ATITC) 8 bits/pixel compressed RGB texture format. return 8; case TextureFormat.BGRA32:// Format returned by iPhone camera return 32; } return 0; } public static int GetBitsPerPixelForImportFormat(TextureImporterFormat format) { switch (format) { case TextureImporterFormat.Alpha8: // Alpha-only texture format. return 8; case TextureImporterFormat.RGB24: // A color texture format. return 24; case TextureImporterFormat.RGBA32: //Color with an alpha channel texture format. return 32; case TextureImporterFormat.ARGB32: //Color with an alpha channel texture format. return 32; case TextureImporterFormat.RGBA16: // A 16 bit color texture format. return 16; case TextureImporterFormat.RGB16: // A 16 bit color texture format. return 16; case TextureImporterFormat.DXT1: // Compressed color texture format. return 4; case TextureImporterFormat.DXT5: // Compressed color with alpha channel texture format. return 8; case TextureImporterFormat.PVRTC_RGB2:// PowerVR (iOS) 2 bits/pixel compressed color texture format. return 2; case TextureImporterFormat.PVRTC_RGBA2:// PowerVR (iOS) 2 bits/pixel compressed with alpha channel texture format return 2; case TextureImporterFormat.PVRTC_RGB4:// PowerVR (iOS) 4 bits/pixel compressed color texture format. return 4; case TextureImporterFormat.PVRTC_RGBA4:// PowerVR (iOS) 4 bits/pixel compressed with alpha channel texture format return 4; case TextureImporterFormat.ETC_RGB4:// ETC (GLES2.0) 4 bits/pixel compressed RGB texture format. return 4; case TextureImporterFormat.ETC2_RGB4:// ETC (GLES3.0) 4 bits/pixel compressed RGB texture format. return 4; case TextureImporterFormat.ETC2_RGBA8:// ETC (GLES3.0) 8 bits/pixel compressed RGBA texture format. return 8; case TextureImporterFormat.Automatic:// 没有设置贴图格式,默认给4bit. return 4; } return 0; }

 

转载于:https://www.cnblogs.com/hengsoft/p/10289647.html

你可能感兴趣的文章
Django 之Form
查看>>
开发ProxyServer的时候如何在一台PC上调试
查看>>
C#用于对用户输入数据进行校验的类
查看>>
低速前碰开发
查看>>
python-9-IO编程
查看>>
【GoLang】转载:我为什么放弃Go语言,哈哈
查看>>
【MySQL】MySQL 如何实现 唯一随机数ID
查看>>
【Redis】Redis分布式集群几点说道
查看>>
HDU2819(KB10-E 二分图最大匹配)
查看>>
mysql主从复制、redis基础、持久化和主从复制
查看>>
文档工具GitBook使用
查看>>
两个链表的第一个公共节点
查看>>
知道这20个正则表达式,能让你少写1,000行代码
查看>>
Digit Sum II( ABC044&ARC060)
查看>>
MariaDB 主从同步与热备(14)
查看>>
推荐的 CSS 书写顺序
查看>>
NIO:与 Buffer 一起使用 Channel
查看>>
Android帧缓冲区(Frame Buffer)硬件抽象层(HAL)模块Gralloc的实现原理分析
查看>>
Android - 广播机制和Service
查看>>
MFC接收ShellExecute多个参数
查看>>