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: 2952
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: 2952
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.

Brian Beuken
Posts: 221
Joined: Fri Jan 29, 2016 12:51 pm

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

Thu Jun 27, 2019 11:14 am

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
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

Return to “OpenGLES”