对顶点使用GLshort而不是GLfloat [英] Using GLshort instead of GLfloat for vertices

查看:98
本文介绍了对顶点使用GLshort而不是GLfloat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的程序从GLfloat转换为GLshort的顶点位置,我不确定如何在着色器中表示它.我在着色器中使用了vec3数据类型,但是vec3表示3个浮点数.现在我需要代表3条短裤.据我所知,OpenGL没有短裤向量,那么在这种情况下我应该怎么做?

I'm attempting to convert my program from GLfloat to GLshort for vertex positions and I'm not sure how to represent this in the shader. I was using a vec3 datatype in the shader but vec3 represents 3 floats. Now I need to represent 3 shorts. As far as I can tell OpenGL doesn't have a vector for shorts so what am I supposed to do in this case?

推荐答案

我不确定如何在着色器中表示它.

I'm not sure how to represent this in the shader.

这是因为此信息不在着色器中.

That's because this information doesn't live in the shader.

glVertexAttribPointer提供的所有值都将转换为浮点GLSL值(如果它们尚未浮点).此转换基本上是免费的.因此,您可以将这些glVertexAttribPointer定义中的任何一个与vec4属性类型一起使用:

All values provided by glVertexAttribPointer will be converted to floating-point GLSL values (if they're not floats already). This conversion is essentially free. So you can use any of these glVertexAttribPointer definitions with a vec4 attribute type:

glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, ...);
glVertexAttribPointer(0, 4, GL_UNSIGNED_SHORT, GL_TRUE, ...);
glVertexAttribPointer(0, 4, GL_SHORT, GL_TRUE, ...);
glVertexAttribPointer(0, 4, GL_SHORT, GL_FALSE, ...);

所有这些都将自动转换为vec4 .您的着色器不必知道或不在乎它是不是短裤,字节,整数,浮点数等.

All of these will be converted into a vec4 automatically. Your shader doesn't have to know or care that it's being fed shorts, bytes, integers, floats, etc.

第一个将按原样使用.第二个将无符号的短范围[0,65535]转换为[0.0,1.0]浮点范围.第三个将有符号的短范围[-32768,32767]转换为[-1.0,1.0]范围(

The first one will be used as is. The second one will convert the unsigned short range [0, 65535] to the [0.0, 1.0] floating-point range. The third will convert the signed short range [-32768, 32767] to the [-1.0, 1.0] range (though the conversion is a bit odd and differs for certain OpenGL versions, so as to allow the integer 0 to map to the floating point 0.0). The fourth will convert [-32768, 32767] to [-32768.0, 32767.0], as a floating-point range.

仅当使用glVertexAttribIPointerglVertexAttribLPointer时,用于属性的GLSL类型才会更改,而OpenGL ES 2.0中都不可用.

The GLSL type you use for attributes only changes if you use glVertexAttribIPointer or glVertexAttribLPointer, neither of which is available in OpenGL ES 2.0.

简而言之:您应该始终对属性使用浮点GLSL类型. OpenGL将为您完成转换.

In short: you should always use float GLSL types for attributes. OpenGL will do the conversion for you.

这篇关于对顶点使用GLshort而不是GLfloat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆