android - GLSL ERROR: No vertex attrib is enabled in a draw call -


i writing app android in opengl es 2.0 , have problem shader code. here is:

attribute vec4 vposition; vec4 tempposition;  void main() {     tempposition = vposition;     tempposition.x = 2 - tempposition.x;     gl_position = tempposition.yxzw; } 

the line causes error one:

tempposition.x = 2 - tempposition.x; 

i enabling , disabling vertex atrrib arrays each time want draw something. before draw call this: gles20.glenablevertexattribarray(sposition); , after drew call gles20.gldisablevertexattribarray(sposition);

what doing wrong? how substract x 2?

edit:

if change line causes error this:

tempposition.xz = vec2(2,0) - tempposition.xz; 

than works, why cant substract single number?

in glsl version used es 2.0 (which mysteriously version 1.00), there no implicit type conversions. can't add value of type int value of type float, or vector of floats.

this specified in introduction of chapter 4 "variables , types" of spec:

the opengl es shading language type safe. there no implicit conversions between types.

and in more detail case in section 5.9 "expressions", + operator defined:

the 2 operands must same type, or 1 can scalar float , other float vector or matrix, or 1 can scalar integer , other integer vector.

therefore, need use float constants when operating floats:

tempposition.x = 2.0 - tempposition.x; 

the more interesting case why second attempt worked, since you're mixing different types:

tempposition.xz = vec2(2,0) - tempposition.xz; 

this legal because constructors can used convert types, , primary mechanism so. example, have written original expression as:

tempposition.x = float(2) - tempposition.x; 

this looks awkward constant value, make more sense if integer value in variable:

int foo = ...; tempposition.x = float(foo) - tempposition.x; 

back vector case, section 5.4.2 "vector , matrix constructors" specifies:

if basic type (bool, int, or float) of parameter constructor not match basic type of object being constructed, scalar construction rules (above) used convert parameters.

this means can use int value argument constructor of vec2, though contains float values. in case, value automatically converted. in other words, second statement equivalent to:

tempposition.xz = vec2(float(2), float(0)) - tempposition.xz; 

imho, it's still cleaner not rely on implicit conversions, , write:

tempposition.xz = vec2(2.0, 0.0) - tempposition.xz; 

note full opengl different opengl es in respect. in full glsl, there implicit type conversions. find unfortunate, because believe type safety useful principle.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -