Pablo Walters
Posts: 20
Joined: Sun Nov 27, 2016 6:21 am

Is there a way to use gl_InstanceID in shaders?

Sun May 12, 2019 1:46 am

I'd like to do instanced drawing like I do on iOS and OSX.

But neither

gl_InstanceID

nor

gl_InstanceIDEXT

are defined when compiling OpenGL ES shaders.

Is there a way to make this work on PI?

User avatar
Paeryn
Posts: 2516
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Is there a way to use gl_InstanceID in shaders?

Sun May 12, 2019 10:01 am

Pablo Walters wrote:
Sun May 12, 2019 1:46 am
I'd like to do instanced drawing like I do on iOS and OSX.

But neither

gl_InstanceID

nor

gl_InstanceIDEXT

are defined when compiling OpenGL ES shaders.

Is there a way to make this work on PI?
The RPi has native GL|ES 2 which uses GLSL version 100, gl_InstanceID comes from GLSL version 300 which typically means you need GL|ES 3 or above which the VC4 doesn't support natively.
She who travels light — forgot something.

Pablo Walters
Posts: 20
Joined: Sun Nov 27, 2016 6:21 am

Re: Is there a way to use gl_InstanceID in shaders?

Mon May 13, 2019 6:20 pm

I got it working by adding this to the shaders!

#extension GL_ARB_draw_instanced : enable
#define gl_InstanceID gl_InstanceIDEXT

User avatar
Paeryn
Posts: 2516
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Is there a way to use gl_InstanceID in shaders?

Tue May 14, 2019 3:35 am

Good find, I assumed it wasn't supported as GL_EXT_draw_instanced isn't reported as an extension. Having looked at when instancing was added, my copy of the GLSL spec is from before then.

Strange you say it is GL_ARB_ and not GL_EXT_, the Khronos registry for extensions say that GL_ARB_draw_instanced is for OpenGL (not ES) and that GL_EXT_draw_instanced is for both OpenGL & OpenGL ES.

Code: Select all

Name Strings
    GL_ARB_draw_instanced

Number
    ARB Extension #44

Dependencies
    OpenGL 2.0 is required.

Code: Select all

Name Strings
    GL_EXT_draw_instanced

Number
    OpenGL Extension #327
    OpenGL ES Extension #157

Dependencies
    OpenGL 2.0 or OpenGL ES 2.0 is required.
She who travels light — forgot something.

Return to “OpenGLES”