GLES 2 and unsigned byte attribute (ivec4?)

I was trying to have a VBO with bone indices in my Android GLES2 3D game.

The issue is that most of the vertex buffer contains float while the indices only require unsigned bytes.

At first I was just using floats as indices for the bones but I wanted to do better. So I made a vertex buffer that have both floats and unsigned chars.

In order to tell GLES2.0 you want 4 indices of unsigned chars you need to call:


You will need to make sure you pass a ByteBuffer with the correct format to GLES2 with GLES20.glBufferData.

Lastly, and this is the tricky part and reason why I wrote this article. How to refer to unsigned bytes attributes inside the GLSL shader code?

Well it turns out GLES2.0 does not have ivec4 which is a vector of 4 ints. However, in GLES2.0 you can use “attribute vec4” for unsigned bytes even though the bytes are not 32 bit floats.

This will result in a float data type but you can convert it into int using int(YourVar).

One thought on “GLES 2 and unsigned byte attribute (ivec4?)

  1. This is just what I was looking for.. well, not precisely – but it pointed me in the right direction on how to pass ints through to GLES shaders, and in fewer bytes than before – so, win 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s