Hello Johannes,

On Mon, Mar 3, 2014 at 12:58 PM, Johannes <jbru...@datasolid.de> wrote:
> To be more explicit about what I have in mind...
> 2. Details
> ==========
> i) class UniformBufferObjectChunk:
> ----------------------------------
> This class should abstract the memory block (buffer) and must know the
> binding point (bind_pnt) and the update hint (hint) for the buffer. It
> is a state chunk and should bind the buffer to the GL_UNIFORM_BUFFER
> target at activation time. It is independent of any shader program.
>
> a) initialization time
>      glGenBuffers(1, &_ubo_id);
>      glBindBuffer(GL_UNIFORM_BUFFER, _ubo_id);
>      glBufferData(GL_UNIFORM_BUFFER, buffer.size(), &buffer[0], hint);
>
>      glBindBufferBase(GL_UNIFORM_BUFFER, bind_pnt, _ubo_id);
>      glBindBuffer(GL_UNIFORM_BUFFER, 0);
>
> The buffer is provided from outside. The binding point must according to
> the hardware caps be valid. The hint come from the following set
> {GL_STATIC_DRAW, GL_DYNAMIC_DRAW,...).

hmm, what do you mean by "the buffer is provided from outside"? I
would have thought UniformBufferObjectChunk contains an MFUChar8 that
is used as an array of bytes as the OpenSG side copy of the buffer?

> b) update time
>      glBindBuffer(GL_UNIFORM_BUFFER, _ubo_id);
>      GLubyte* pBuffer = static_cast<GLubyte*>(
>          glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY));
>
>      // overwrite pBuffer by buffer content with memcpy...
>
>      glUnmapBuffer(GL_UNIFORM_BUFFER);
>      glBindBuffer(GL_UNIFORM_BUFFER, 0);

ok, just to be sure: this is meant to happen when OpenSG detects that
it needs to update the contents of the UBO? Since OpenSG in general
assumes that there is no OpenGL context active in an application
thread there is a mechanism for this kind of update of a GL object -
you could take a look at what happens for textures, since the case
here seems quite analogous: some application memory (image/buffer
content) changes and needs to be transferred to GL.

> d) deinitialization
>      glDeleteBuffers(1, &_ubo_id);
>
> ii) class UniformBlocks:
> ------------------------
> The responsibility of this class is to bind the shader uniform blocks to
> the binding points (bind_pnt). It should have a map of block names to
> UniformBufferObjectChunk objects providing the appropriate binding
> points. An instance of this class can be added to a ShaderProgramChunk
> object. On usage of such a program the uniform block binding must be
> established:
>
>      GLuint index = glGetUniformBlockIndex(
>                          _shader.GetProgram(), block_name);
>      glUniformBlockBinding(_shader.GetProgram(), index, bind_pnt);
>
>
> iii) the host application:
> --------------------------
> The host application can easily setup the memory buffer according to
> std140 with the help of the following helper function:
>
> static int align_offset(int base_alignment, int base_offset)
> {
>      if (base_offset == 0) return 0;
>
>      int n = 1;
>      while (n * base_alignment < base_offset) ++n;
>      return n * base_alignment;
> }
>
> At the end (*) you can find some examples for usage...
>
> iv) implementation
> ------------------
> Ok, at this point I need help because I'm still not familiar enough with
> the OpenSG nuts and bolts to implement this idea properly.
>
> Could you please review this proposal and check if it
>
> a) is sound and feasible
> b) has limitations

I always find it difficult to predict all kinds of eventualities in
advance, but it does sound like a good plan.

> c) is desirable

Sure, after all there is at least your use case, so that seems like
something useful to have ;)

> And if so, I would appreciate some mentoring for implementing this in
> OpenSG.

Ok. It would be easiest to have an idea what your concrete questions
are, because without digging through a lot of code I could not come up
with a list of places to modify for example. As a starting point I
would add the UBOChunk and model its create/update/destroy behavior on
what is done for textures - I believe TextureObjChunk is the one that
does the actual data transfers to a texture object. These classes
generally have a function called handleGL (or similar) that is called
when a GL object needs to be modified. If the OpenSG side buffer (or
image) is changed this is usually just noted and the update delayed
until the GL object is used the next time (at which point we can also
be sure that a GL context is available).
Hope this helps, thanks for your interest in adding UBO support!

Cheers,
Carsten

------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to