VBO for AudioArray is Buggy in ZGEViz - help needed

Discuss the ZGameEditor Visualizer plugin for FL-Studio.

Moderator: Moderators

Post Reply
StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

VBO for AudioArray is Buggy in ZGEViz - help needed

Post by StevenM » Sun Jan 24, 2016 2:56 pm

Im' new to working with the vbo, so I must be missing something - the code is only few lines. It simply is a dynamic array that is binded to the FLStudio builtin AudioArray - it is a gpu versiom of this :

Code: Select all

glLineWidth(1f);
glBegin(3);
for (int i = 0; i < AudioArray.SizeDim1-2; i+=2){
  glColor3f(0f,255f,0f);
  glVertex2f(AudioArray[i],AudioArray[i+1]);
}
glEnd();
The idea here is to split the interlaced audio AudioArray in to left right stereo fields by binding it to glVertex,xy- this creates a vectorscope.

The problem:

The script runs in fl studio if you load it by itself on a single layer, but things start acting weird when I try to various things . Scripts that use the audio array don't work if i add them to another layer, for example joy dividers. Applying an effect like feedback does not work. After things act up most effects stop working. Trying to export video renders black...there is more but overall it causes the visualizer to go haywire.

If anyone can see whats causing all this weird behavior, please let me know. It would be very useful to use a dynamic VBO in scripts for a lot of other applications, but right now I can't because the way I implement it is not stable -

Here is the current version:
SimpleVectorscopeGPU2.zgeproj
(1.83 KiB) Downloaded 141 times

User avatar
Kjell
Posts: 1699
Joined: Sat Feb 23, 2008 11:15 pm

Re: VBO for AudioArray is Buggy in ZGEViz - help needed

Post by Kjell » Sun Jan 24, 2016 3:19 pm

Hi StevenM,

Only glanced at the source of your .zgeproj .. but did notice a couple of things.

- You should bind your objects each time you want to access them .. other effects / components can & will override your bindings.
- You're using both modern OpenGL ( glVertexAttribPointer ) and legacy OpenGL ( gl_Vertex ). Go for one or the other, don't combine them.
- You don't have a OnGLContextChange function. If you're going to use OpenGL objects in FL Studio, you need to deal with reconstructing OpenGL objects yourself.
- I don't think you actually want / intended to use GL_DYNAMIC_DRAW.

+ Bit of a strange example for a VBO though .. updating all data of a VBO each frame kind of defeats the purpose.

K

StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Re: VBO for AudioArray is Buggy in ZGEViz - help needed

Post by StevenM » Mon Jan 25, 2016 7:03 am

You don't have a OnGLContextChange function. If you're going to use OpenGL objects in FL Studio, you need to deal with reconstructing OpenGL objects yourself.
I don't understand that -never knew about this. I seen that you do use this in the polar script, I'll take a closer look at that. It looks complicated though - exactly why is this nessesary?
+ Bit of a strange example for a VBO though .. updating all data of a VBO each frame kind of defeats the purpose.
Yes, actually the cpu version is fine.

The problem was just an effort to create a vector scope with a shader. I thought this would be the best approach - but is there a better way?

User avatar
VilleK
Site Admin
Posts: 1981
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: VBO for AudioArray is Buggy in ZGEViz - help needed

Post by VilleK » Mon Jan 25, 2016 9:58 am

Sometimes the visualizer needs to recreate the OpenGL-context and then any internal state (all textures, buffers etc) will be invalid. The ZGE components (RenderMesh, Bitmap etc) are written to be aware of this so there it is not a problem. However when you make direct OpenGL calls and maintain state between render calls (i.e. create GL-buffers) then you need to write a OnGLContextChange method to know when the buffers should be recreated.

Possibly I can make a better solution for it later but this is how it works at the moment.

User avatar
Kjell
Posts: 1699
Joined: Sat Feb 23, 2008 11:15 pm

Re: VBO for AudioArray is Buggy in ZGEViz - help needed

Post by Kjell » Mon Jan 25, 2016 11:43 am

Hi StevenM,
StevenM wrote:Yes, actually the cpu version is fine.
Just a semantics thing ( which is why i didn't mention it the first time ) .. but this has nothing to do with CPU / GPU version. The technique you used in your snippet is referred to as "immediate mode" ( whereas your VBO version is called "retained mode" ).
StevenM wrote:The problem was just an effort to create a vector scope with a shader. I thought this would be the best approach - but is there a better way?
There's nothing wrong with updating all data of a VBO each frame, but there's not much benefit over simply using the array directly. In fact, in that case you don't have to worry about OnGLContextChange since you don't have a OpenGL object either.

K

StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Re: VBO for AudioArray is Buggy in ZGEViz - help needed

Post by StevenM » Mon Jan 25, 2016 1:34 pm

There's nothing wrong with updating all data of a VBO each frame, but there's not much benefit over simply using the array directly. In fact, in that case you don't have to worry about OnGLContextChange since you don't have a OpenGL object either.
What I don't like about using the AudioArray as a uniform it that it's interlaced. There is probably a better way to split the AudioArray into Left and Right channels, but what I do is loop through the AudioArray and create two new arrays on every frame, which I use as uniform variables in the shader.

The VBO seems like it's a better fit for an interlaced array, but the OnGLContextChange is a problem that I was not aware of, and I really don't know how to handle that.

User avatar
VilleK
Site Admin
Posts: 1981
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: VBO for AudioArray is Buggy in ZGEViz - help needed

Post by VilleK » Mon Jan 25, 2016 1:49 pm

StevenM wrote:but the OnGLContextChange is a problem that I was not aware of, and I really don't know how to handle that.
Simply do the same initialization in OnGLContextChange as you do in OnLoaded (i.e. create your buffer). Put your init-code in a ZLibrary function and then you can just call it from both places.

User avatar
Kjell
Posts: 1699
Joined: Sat Feb 23, 2008 11:15 pm

Re: VBO for AudioArray is Buggy in ZGEViz - help needed

Post by Kjell » Mon Jan 25, 2016 2:05 pm

Hi StevenM,
StevenM wrote:What I don't like about using the AudioArray as a uniform it that it's interlaced.
Ehm .. that's not what i meant with "using the array directly". I was referring to doing this ..

Code: Select all

glVertexAttribPointer(0, 2, GL_FLOAT, 0, 0, myArray); // Use the array directly instead of using / binding a VBO
.. instead of ..

Code: Select all

glBindBuffer(GL_ARRAY_BUFFER, myBuffer);
glVertexAttribPointer(0, 2, GL_FLOAT, 0, 0, null);
Besides, interleaved data is usually desirable ( due to how caching works ). You can use the stride argument to set up various interleaved attributes from a single array.

K

StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Re: VBO for AudioArray is Buggy in ZGEViz - help needed

Post by StevenM » Mon Jan 25, 2016 2:54 pm

Simply do the same initialization in OnGLContextChange as you do in OnLoaded (i.e. create your buffer). Put your init-code in a ZLibrary function and then you can just call it from both places.
That worked :) thanks.

StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Re: VBO for AudioArray is Buggy in ZGEViz - help needed

Post by StevenM » Mon Jan 25, 2016 3:25 pm

Kjell wrote:Hi StevenM,
StevenM wrote:What I don't like about using the AudioArray as a uniform it that it's interlaced.
Ehm .. that's not what i meant with "using the array directly". I was referring to doing this ..

Code: Select all

glVertexAttribPointer(0, 2, GL_FLOAT, 0, 0, myArray); // Use the array directly instead of using / binding a VBO
.. instead of ..

Code: Select all

glBindBuffer(GL_ARRAY_BUFFER, myBuffer);
glVertexAttribPointer(0, 2, GL_FLOAT, 0, 0, null);
Besides, interleaved data is usually desirable ( due to how caching works ). You can use the stride argument to set up various interleaved attributes from a single array.

K
OK, I did think that you meant using AudioArray as a uniform variable. I'm binding with glVertexPointer now and with OnGLContextChange added, everything is working ok, but I'll look into this.

Post Reply