整型
错误提示:
“ERROR: 0:3: int can’t be an in in the vertex shader\n”
OpenGL shader 2.0顶点着色器 不支持int作为输入。
输入类型
a、顶点 着色器中定义输入:
- attribute highp vec3 inVertex
- attribute highp float inNormal
b、代码数值传入调用接口:
void glVertexAttribPointer( GLuint index,
GLint size,
GLenum type,
GLboolean normalized,
GLsizei stride,
const GLvoid * pointer);
其中我们探讨的是type:(参考表说明如下)
type
Specifies the data type of each component in the array. Symbolic constants:GL_BYTE, GL_SHORT,GL_UNSIGNED_SHORT, GL_FIXED, or GL_FLOAT are accepted. The initial value is GL_FLOAT.
前提:shader中定义的输入为float型时
当如果代码输入类型设定为GL_FLOAT时,gpu会直接做数据拷贝进行处理。
当如果代码输入类型设定为非GL_FLOAT,也就是GL_BYTE, GL_SHORT,GL_UNSIGNED_SHORT或者 GL_FIXED时候,gpu会进行转换处理,将相关类型数据转为GL_FLOAT。
当然一切都会正常运行,但是问题是:
在iphone5这样的GPU处理能力较差的设备上就会出现费时的情况。因为GPU的数据类型转换消耗了大部分时间。当然这个问题在iphone5s这样的设备上消耗就不会明显。