1

I'm developing an Android application.

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.

4

1 回答 1

1

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.

于 2010-12-01T19:22:47.507 回答