android opengl es 1.1 即时纹理压缩

发布于 2024-12-02 03:37:26 字数 365 浏览 2 评论 0原文

我必须使用纹理压缩,因为我的应用程序当前使用多达 100MB 的 RAM 来存储纹理。

我正在从视图创建纹理,因此不可能以压缩格式创建它们。我如何使用 ETC1/ATC/PVRTC 动态压缩它们并将它们发送到 GPU?我尝试过:

GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, ETC1.ETC1_RGB8_OES, bitmap, 0);

我也尝试过我的手机支持的其他压缩格式,但纹理始终是白色的。输入位图是 RGB_565 并且 mip-maps 被禁用。

是否可以将位图作为纹理发送到 opengl es 1.1,以便它在 Android 上自动压缩,就像在 PC 上一样?

i have to use texture compression as my app is currently using up to 100MB of ram for textures.

i am creating textures from Views, so it is not possible for them to be created in a compressed format. how can i compress them with ETC1/ATC/PVRTC on the fly and send them to gpu? i tried:

GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, ETC1.ETC1_RGB8_OES, bitmap, 0);

i also tried other compression formats supported by my phone, but the texture is always white. the input bitmap is an RGB_565 and mip-maps are disabled.

is it possible to send a bitmap as a texture to opengl es 1.1 so it gets automatically compressed on android, like it is possible on a pc?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你的心境我的脸 2024-12-09 03:37:26

在 Arne Bergene Fossaa 的帮助下,我得到了这个解决方案:

int size = m_TexBitmap.getRowBytes() * m_TexBitmap.getHeight();
ByteBuffer bb = ByteBuffer.allocateDirect(size); // size is good
bb.order(ByteOrder.nativeOrder());
m_TexBitmap.copyPixelsToBuffer(bb);
bb.position(0);

ETC1Texture etc1tex;
// RGB_565 is 2 bytes per pixel
//ETC1Texture etc1tex = ETC1Util.compressTexture(bb, m_TexWidth, m_TexHeight, 2, 2*m_TexWidth);

final int encodedImageSize = ETC1.getEncodedDataSize(m_TexWidth, m_TexHeight);
ByteBuffer compressedImage = ByteBuffer.allocateDirect(encodedImageSize).order(ByteOrder.nativeOrder());
// RGB_565 is 2 bytes per pixel
ETC1.encodeImage(bb, m_TexWidth, m_TexHeight, 2, 2*m_TexWidth, compressedImage);
etc1tex = new ETC1Texture(m_TexWidth, m_TexHeight, compressedImage);

//ETC1Util.loadTexture(GL10.GL_TEXTURE_2D, 0, 0, GL10.GL_RGB, GL10.GL_UNSIGNED_SHORT_5_6_5, etc1tex);
gl.glCompressedTexImage2D(GL10.GL_TEXTURE_2D, 0, ETC1.ETC1_RGB8_OES, m_TexWidth, m_TexHeight, 0, etc1tex.getData().capacity(), etc1tex.getData());

bb = null;
compressedImage = null;
etc1tex = null;

我知道 ETC1Util.compressTextureETC1Util.loadTexture,但它们提供了损坏的纹理。好消息是,我的本机内存消耗从 100MB 减少到了 26MB。但这个解决方案非常慢。即使它是在具有最小优先级的单独线程上完成的,渲染线程也完全被阻塞。有更有效的方法吗?或者我是否必须在新设备上首次运行时创建这些 ETC1 纹理并将它们保存到 SD 卡以供以后重复使用?

with help from Arne Bergene Fossaa i get to this solution:

int size = m_TexBitmap.getRowBytes() * m_TexBitmap.getHeight();
ByteBuffer bb = ByteBuffer.allocateDirect(size); // size is good
bb.order(ByteOrder.nativeOrder());
m_TexBitmap.copyPixelsToBuffer(bb);
bb.position(0);

ETC1Texture etc1tex;
// RGB_565 is 2 bytes per pixel
//ETC1Texture etc1tex = ETC1Util.compressTexture(bb, m_TexWidth, m_TexHeight, 2, 2*m_TexWidth);

final int encodedImageSize = ETC1.getEncodedDataSize(m_TexWidth, m_TexHeight);
ByteBuffer compressedImage = ByteBuffer.allocateDirect(encodedImageSize).order(ByteOrder.nativeOrder());
// RGB_565 is 2 bytes per pixel
ETC1.encodeImage(bb, m_TexWidth, m_TexHeight, 2, 2*m_TexWidth, compressedImage);
etc1tex = new ETC1Texture(m_TexWidth, m_TexHeight, compressedImage);

//ETC1Util.loadTexture(GL10.GL_TEXTURE_2D, 0, 0, GL10.GL_RGB, GL10.GL_UNSIGNED_SHORT_5_6_5, etc1tex);
gl.glCompressedTexImage2D(GL10.GL_TEXTURE_2D, 0, ETC1.ETC1_RGB8_OES, m_TexWidth, m_TexHeight, 0, etc1tex.getData().capacity(), etc1tex.getData());

bb = null;
compressedImage = null;
etc1tex = null;

i know about the ETC1Util.compressTexture and ETC1Util.loadTexture, but they were giving corrupted textures. good thing is that i went from 100MB down to 26MB with native memory consumption. but this solution is slow as hell. and even though it is done on a separate thread with min priority, the rendering thread is totally blocked. is there a more efficent way? or do i have to create these ETC1 textures on the first run on a new device and save them to SD card for later reuse?

川水往事 2024-12-09 03:37:26

您无法通过 OpenGL ES 执行此操作 - 仅支持 ETC 解压缩。 ETC 压缩要做得又快又好并不是一件简单的事 - 您可以看看 http://devtools.ericsson.com /etc 并在您的程序中实现 etcpack。

You cannot do that through OpenGL ES - only ETC decompression is supported. ETC compression is not really trivial to do fast and good - you might have a look at http://devtools.ericsson.com/etc and implement etcpack in your program, though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文