Hello, sorry for such a newby question but i have no clue how to map and bind a java object to a uniform buffer object.
For example: JAVA: public void GlobalGameInfo extends UniformBufferObject{ long timeGlobal; float timePerFrame; } with the use of reflection i then get: GLSL: uniform GlobalGameInfo{ long timeGlobal; float timePerFrame; }inGlobalGameInfo; This all works fine. However, i don't know how to pass the data from the java object to the UBO creted with: gl.getGL3().glGenBuffers(1, uniformBuffer, 0); uniformObject.nativeId=uniformBuffer[0]; gl.getGL3().glBindBuffer(GL3.GL_UNIFORM_BUFFER, uniformObject.nativeId); gl.getGL3().glBufferData(uniformObject.nativeId,?????, ??????, ?????); |
A simple workaround for me was to not use structs in the shader but use simple types, being a newbie I didn't want to tangle with using buffers for the uniforms.
like shader: uniform float time ; and then: gl.glUniform1f(uniformId, time); But I'd be interested to learn how to do that struct/buffer thingy :-) |
Administrator
|
On 06/13/2013 07:56 PM, jmaasing [via jogamp] wrote:
> A simple workaround for me was to not use structs in the shader but use simple > types, being a newbie I didn't want to tangle with using buffers for the > uniforms. > > like shader: uniform float time ; > and then: gl.glUniform1f(uniformId, time); > > But I'd be interested to learn how to do that struct/buffer thingy :-) Discrete r/w access is possible via: http://jogamp.org/git/?p=jogl.git;a=blob;f=src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_lightdef.glsl;hb=HEAD http://jogamp.org/git/?p=jogl.git;a=blob;f=src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java;hb=HEAD#l445 However, that is ofc not optimal to burst a bunch of data. For the latter I usually use arrays. Maybe there is said 'buffer' solution available as well, but above example is restricted to ES2. ~Sven signature.asc (911 bytes) Download Attachment |
@jmaasing
Yeah, i know, 'normal' uniforms work nicely. But since this is more a personal experiment i want to try this UBO thing. From what i get it would allow me to update uniforms trough different shaders with one update call. If possible i want to make the nicest implementation and for that structs seem to me the better choice. @Sven ES2 probably does not yet support UBO's. I think support comes with GLES3 |
Administrator
|
On 06/13/2013 08:19 PM, zzuegg [via jogamp] wrote:
> @jmaasing > Yeah, i know, 'normal' uniforms work nicely. But since this is more a personal > experiment i want to try this UBO thing. From what i get it would allow me to > update uniforms trough different shaders with one update call. If possible i > want to make the nicest implementation and for that structs seem to me the > better choice. > > @Sven > ES2 probably does not yet support UBO's. I think support comes with GLES3 I guess we shall work on supporting it (-> bugreport.enhancement)! This requires to map a native structure to java, but I have to read about UBO .. best while adding ES3 support :) Ofc .. code snippets - maybe a unit tests which fails right now, but uses UBO - or shows/documents how it is desired would be a good idea. Pls send a pull request in this regard .. and add it's reference to the bugreport. Thank you! ~Sven signature.asc (911 bytes) Download Attachment |
From the OpenGL side (Not ES) everything needed for UBO is already here. The question was how do i actually pass the values to the GPU, probably trough a bytebuffer. Well i am implementing it and hopefully the mapping (from bytebuffer to glsl struct) get's done automatically.
|
I remember reading about the UBO layout, I found it in Section 2.11.4 of the OpenGL 3.2 core specification (I'm on a Mac so 3.2 is all I got). But I haven't tried it, so it's just theory to me.
|
No tessellation on mac?
|
Sadly Apple is not advancing the OpenGL cause much :/ OpenGL3.2 is what they support.
https://developer.apple.com/graphicsimaging/opengl/capabilities/index.html Edit: Although they just announced that OSX 10.9 will support OGL 4.1 so, yay tessellation will come :-) |
Administrator
|
In reply to this post by zzuegg
On 06/13/2013 09:23 PM, zzuegg [via jogamp] wrote:
> From the OpenGL side (Not ES) everything needed for UBO is already here. The > question was how do i actually pass the values to the GPU, probably trough a > bytebuffer. Well i am implementing it and hopefully the mapping (from > bytebuffer to glsl struct) get's done automatically. yes .. that is the point. I.e. in the native code world, I assume you simply pass the pointer to a c-structure and push the sizeof(struct) down to the GPU while adjusting alignment - right .. <https://www.opengl.org/wiki/Uniform_Buffer_Object> <https://www.opengl.org/wiki/Buffer_Object#Binding_indexed_targets> Hence you might want to use GlueGen's StructAccessor to map a c-struct to java. The Platform's MachineDescriptor will give you information about the alignment. Usually you would do that in a tedious way, i.e. configure gluegen for your few c-structs, etc. To ease this process, I have [finally] merged and enhanced the Annotated Processor (APT) once written by Michael Bien into gluegen.jar. <http://jogamp.org/git/?p=gluegen.git;a=commit;h=a7802a2ab90a68ecbba962149a335f975fce24e7> Within this commit, you can see how the new unit test is being processed, i.e. added ant recipe for APT .. should work seamless. -> TestStructGen01.java, TestStruct01.h Having this tool, you should be able to write your uniform structure in a little c-struct file and map it automatic to java. Now .. your task would be to use the GL3 spec properly and add a unit test in our JOGL package: com.jogamp.opengl.test.junit.jogl.demos.gl3 would be _very_ much appreciated! Cheers, Sven signature.asc (911 bytes) Download Attachment |
Administrator
|
In reply to this post by zzuegg
On 06/14/2013 04:53 AM, Sven Gothel wrote:
> On 06/13/2013 09:23 PM, zzuegg [via jogamp] wrote: >> From the OpenGL side (Not ES) everything needed for UBO is already here. The >> question was how do i actually pass the values to the GPU, probably trough a >> bytebuffer. Well i am implementing it and hopefully the mapping (from >> bytebuffer to glsl struct) get's done automatically. > > yes .. that is the point. > > I.e. in the native code world, I assume you simply pass > the pointer to a c-structure and push the sizeof(struct) > down to the GPU while adjusting alignment - right .. > > <https://www.opengl.org/wiki/Uniform_Buffer_Object> > <https://www.opengl.org/wiki/Buffer_Object#Binding_indexed_targets> > > Hence you might want to use GlueGen's StructAccessor > to map a c-struct to java. > The Platform's MachineDescriptor will give you information > about the alignment. > > Usually you would do that in a tedious way, i.e. > configure gluegen for your few c-structs, etc. > > To ease this process, I have [finally] merged and enhanced > the Annotated Processor (APT) once written by Michael Bien > into gluegen.jar. > > <http://jogamp.org/git/?p=gluegen.git;a=commit;h=a7802a2ab90a68ecbba962149a335f975fce24e7> > > Within this commit, you can see how the new unit test is being processed, > i.e. added ant recipe for APT .. should work seamless. > -> TestStructGen01.java, TestStruct01.h > > Having this tool, you should be able to write your uniform structure > in a little c-struct file and map it automatic to java. > > Now .. your task would be to use the GL3 spec properly > and add a unit test in our JOGL package: > > com.jogamp.opengl.test.junit.jogl.demos.gl3 > > would be _very_ much appreciated! > <http://www.packtpub.com/article/opengl-glsl-4-using-uniform-blocks-buffer-objects> it seems that the ideal way would be to have all alignments and offset being fetched from the GPU and used to configure the generated struct's offset/alignment table ? Just a little brainstorming .. haven't read this in detail yet. But probably better than forcing the GPU to adapt to the CPU's alignment/offset .. if that is even possible. ~Sven signature.asc (911 bytes) Download Attachment |
As far as I can tell that's what std140 layout sort of does. It mandates to the GPU how to layout the alignments and offsets so you can know before hand. But then again, querying should be a one time operation as long as the struct doesn't change - I hope at least. Either way should be possibly if you like @zzuegg generate the shader code based on reflection. I can see how this would be a really good utility to have, I hope @zzuegg will share the findings :-) |
@jmaasing: sure once i got the thing running i will post my findings/utilityclasses
@sven: thanks for the links and work on reading. I will see if i get some test to run and report back. Lots of reading now |
Free forum by Nabble | Edit this page |