Page 1 of 1

Is there a way to use gl_InstanceID in shaders?

Posted: Sun May 12, 2019 1:46 am
by Pablo Walters
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?

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

Posted: Sun May 12, 2019 10:01 am
by Paeryn
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.

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

Posted: Mon May 13, 2019 6:20 pm
by Pablo Walters
I got it working by adding this to the shaders!

#extension GL_ARB_draw_instanced : enable
#define gl_InstanceID gl_InstanceIDEXT

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

Posted: Tue May 14, 2019 3:35 am
by Paeryn
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.

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

Posted: Thu Jun 27, 2019 11:14 am
by Brian Beuken
hmmm how could that work? All you did was define a couple of labels..if they are not supported in the GPU (and they are not) they will take a value from the shader compiler

I suspect there's no increment on the ID value and it stays at null each shader call.

But, if it does acutally work...thats very curious