GL_SHORT 作为纹理坐标
Instruments 鼓励我使用 GL_SHORTs 作为纹理坐标。我对只需要值 0 和 1 的四边形执行此操作。
如果短路的精度足够,我还可以在需要 0 到 1 之间的值的其他情况下使用 GL_SHORT 吗?如果是这样怎么办?
Instruments encourages me to use GL_SHORTs for texture coordinates. I do that for quads where I only need values 0 and 1.
Can I also use GL_SHORT for other cases where I need values between 0 and 1 if the precision of a short is enough? If so how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要获得最大精度,您可以使用值 0..32767 将纹理坐标指定为 GL_SHORT,以指定从 0.0f 到 1.0f 的值。然后你将得到精度 1/32767,大约为 0.00003。对你来说够了吗? - 这取决于您和您的应用程序。很可能这对你来说就足够了。
要指定 0 到 1 之间的某个值,则可以使用具有缩放功能的纹理矩阵(如果您使用的是 GLES1),或者只需将纹理坐标与片段着色器中适当的缩放均匀性相乘(如果您使用的是 GLES2)。
这是 GLES1 的一个简单示例 - 假设您的纹理为 100x200,并且您不需要指定精度低于 1 纹素的纹理坐标。然后,您可以将纹理矩阵设置为以下因子的缩放 - 1/100 和 1/200:
之后在顶点数组/缓冲区中,您可以使用:
To get max precision, you can use values 0..32767 for specifying texture coordinates as GL_SHORT to specify values from 0.0f to 1.0f. Then you will get precision 1/32767, which approximately is 0.00003. Is it enough for you? - that is up to you and your application. Most likely it will be enough for you.
To specify some value between 0 and 1, then either use texture matrix with scaling (if you are on GLES1) or just multiply texture coordinate with proper scaling uniform in your fragment shader (if you are on GLES2).
Here's a simple example for GLES1 - lets say your texture ir 100x200 and you don't need to specify texture coordinates with less precision that 1 texel. Then you can set your texture matrix to scale for following factors - 1/100 and 1/200:
After that in your vertex array/buffer you can use: