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?
相关问题
- OpenGL Shaders. Pass array of float
- Difference from eglCreatePbufferSurface and eglCre
- Render 3d Objects into Cameraview
- Reading a openGL ES texture to a raw array
- OpenGL ES:Purpose of calling glClear on every fram
相关文章
- Why is glClear blocking in OpenGLES?
- Writing to then reading from an offscreen FBO on i
- How to get OpenGL version using Javascript?
- Issue in passing Egl configured surface to native
- Draw a line over UIViewController
- OpenGL ES3 Shadow map problems
- OpenGL ES 2.0 Shader - 2D Radial Gradient in Polyg
- Cocos2d - apply GLImageProcessing effect to CCSpri
That's because this information doesn't live in the shader.
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 theseglVertexAttribPointer
definitions with avec4
attribute type: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.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.
The GLSL type you use for attributes only changes if you use
glVertexAttribIPointer
orglVertexAttribLPointer
, neither of which is available in OpenGL ES 2.0.In short: you should always use float GLSL types for attributes. OpenGL will do the conversion for you.