简体   繁体   English

openGLES 2-有没有一种方法可以在不扩展为无符号字节的情况下,每1位加载一个带有alpha元素的纹理?

[英]openGLES 2 - Is there a way to load a texture with one alpha element per 1-bit, without expanding to an unsigned byte?

I have a bitmask that I would like to set as a texture to play with (eg sample from it setting alpha to either 0 or 1, or use it as stencil test). 我有一个要设置为要使用的纹理的位掩码(例如,从其中设置为0或1的alpha样本,或将其用作模板测试)。

Do I need to make each bit in this existing mask into a byte and use GL_UNSIGNED_BYTE or is there a more clever way to use this mask? 我是否需要将现有掩码中的每一位都变成一个字节并使用GL_UNSIGNED_BYTE还是有使用该掩码的更聪明的方法?

OpenGLES 2 has only one texture format with single bit alpha: GL_UNSIGNED_SHORT_5_5_5_1 , a 16-bit RGBA texture. OpenGLES 2仅具有一种具有单个Alpha位的纹理格式: GL_UNSIGNED_SHORT_5_5_5_1 (16位RGBA纹理)。 If you have any use of the 15-bits of RGB, I'd say it is your best shot. 如果您对RGB的15位有任何使用,那是您的最佳选择。 Using compressed texture may or may not work better. 使用压缩纹理可能会更好,也可能不会更好。

For single bit stencil there is the GL_OES_STENCIL1 extension, however it is really simple using a single bit plane in an 8-bit stencil (in fact very few use more than a single bit plane at a time). 对于单个位模板,有GL_OES_STENCIL1扩展名,但是在8位模板中使用单个位平面确实很简单(实际上很少有一次使用一个以上的位平面)。

Using stencil requries you to create, render and project into a RenderBuffer, and then render that RenderBuffer onto the next target (eg default framebuffer). 使用模具要求您创建,渲染和投影到RenderBuffer中,然后将该RenderBuffer渲染到下一个目标(例如默认帧缓冲区)上。

Not sure about your use case, but I cannot think of any where this would be worth the effort compared to just roll with 8-bit alpha set to [0.0,1.0] through and through. 不确定您的用例,但是与仅将8位alpha设置为[0.0,1.0]进行滚动相比,我想不出什么值得付出的努力。 If you are after performance, stick to mainstream solutions and let the driver work its magic. 如果您追求性能,请坚持使用主流解决方案,并让驱动程序发挥其魔力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM