开发者

OpenGL ES 2.0: attribute not bound on vertex shader

开发者 https://www.devze.com 2023-01-28 15:04 出处:网络
I\'m developing an Android applica开发者_如何学Ction. I have the following vertex shader. \"attribute vec4 vertexPosition;

I'm developing an Android applica开发者_如何学Ction.

I have the following vertex shader.

"attribute vec4 vertexPosition; 
attribute vec4 vertexNormal; 
attribute vec2 vertexTexCoord; 

varying vec2 texCoord; 
varying vec4 normal; 

uniform mat4 modelViewProjectionMatrix; 

void main() 
{ 
   gl_Position = modelViewProjectionMatrix * vertexPosition; 
   normal = vertexNormal; 
   texCoord = vertexTexCoord; 
} 
";

And this is the fragment shader:

precision mediump float; 

varying vec2 texCoord; 
varying vec4 normal; 

uniform sampler2D texSampler2D;

void main()
{ 
   gl_FragColor = texture2D(texSampler2D, texCoord); 
} 
";

Is there any problem if I left vertexTexCoord unbound? I think I must use a different vertex and fragment shader if my model doesn't have a texture, isn't?

Thanks.


Yes you should have another shader for models without texture. Otherwise, I think you will experience implementation dependant behavior.

Related to that, OpenGL documentation says:

Active attributes that are not explicitly bound will be bound by the linker when glLinkProgram is called. The locations assigned can be queried by calling glGetAttribLocation.

So if vertex attributes are enabled it will try to get vertexTexCoord from one of the attributes. I'm not sure what will happen if no more than number of attributes needed for untextured model are enabled and you shouldn't rely on thing like that. Use another shader.

0

精彩评论

暂无评论...
验证码 换一张
取 消