We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Vector versions of glVertex and glColor
Page Index Toggle Pages: 1
Vector versions of glVertex and glColor (Read 2875 times)
Vector versions of glVertex and glColor
Jun 15th, 2009, 5:38pm
 
I'm trying to use the vector versions of these (glVertex3fv() instead of glVertex3f()) for possible performance improvements.  However, I'm having an issue creating the array.

Code:

 int[][] edgepointer = new int[count][3];
for loop...
edgepointer[count][0] = x;
edgepointer[count][1] = y;
edgepointer[count][2] = z;
count++;
end loop...

for loop...
gl.glVertex3iv(edgepointer[i]);
gl.glVertex3iv(edgepointer[i]);
end loop...


It gives an error: The method glVertex3iv(int[], int) in the type GL is not applicable for the arguments (int[]).

I'm trying to find the fastest way to draw a large number of lines very fast.  Please let me know of any better ways.
Re: Vector versions of glVertex and glColor
Reply #1 - Jun 16th, 2009, 4:29am
 
look into vertex arrays or vertex-buffer objects if you have a list of data to render that will help you out..

as for your error if you look into jogl documentation that function needs one other parameter which is an integer. u can use value 0 as it is an offset parameter

http://download.java.net/media/jogl/builds/nightly/javadoc_public/javax/media/opengl/GL.html
Re: Vector versions of glVertex and glColor
Reply #2 - Jun 16th, 2009, 5:54am
 
Ahh, I was reading it backward... I thought it kept telling me I had an extra int.  Can't believe I didn't try that.  Must be a java thing as all the OpenGL stuff online didn't have that extra int.  

Thanks!
I tested it out and it didn't help the performance though.  I thought it might based on reading.. but no luck.  I appreciate the help though.  I've been trying to do vbo but it's a bit complex for me.  I'll give it another go.
Re: Vector versions of glVertex and glColor
Reply #3 - Jun 16th, 2009, 6:26am
 
jogl functions usual have this extra parameter, the C documentation doesn't.

give it a go on vertex arrays first. might look simpler to start with

create array of floats for vertices and pass it on to the functions

example:

init()
 FloatBuffer _grassSegPos;
   _grassSegPos = BufferUtil.newFloatBuffer( numOfElements * 6 );
   _grassSegPos.rewind();

// fill the buffer with data in a loop. pass each vertex component
// line point A
       _grassSegPos.put( index+0, pos.x );
       _grassSegPos.put( index+1, pos.y );
       _grassSegPos.put( index+2, pos.z );
// line point B
       _grassSegPos.put( index+3, pos2.x );
       _grassSegPos.put( index+4, pos2.y );
       _grassSegPos.put( index+5, pos2.z );


render()
   _grassSegPos.rewind();
   vgl.gl().glEnableClientState( GL.GL_VERTEX_ARRAY );
   vgl.gl().glVertexPointer( 3, GL.GL_FLOAT, 0, _grassSegPos );
   vgl.gl().glDrawArrays( GL.GL_TRIANGLES, 0, numOfElements*6 );
   vgl.gl().glDisableClientState( GL.GL_VERTEX_ARRAY );


that should get u rendering some lines on screen
Re: Vector versions of glVertex and glColor
Reply #4 - Jun 16th, 2009, 9:12am
 
Well, I got the VA and VBO working and didn't gain any performance improvements over my Display List.   EmbarrassedBelow is my VBO test Code:

float[] xyz;
float[] rgb;
FloatBuffer f;
FloatBuffer c;

void initEdges(){

 int count = 0;
 xyz=new float[2*3*Edges.length];
 rgb=new float[2*4*Edges.length];
 Edge e1;
 Node n1, n2;
 float z1,z2;
 
 for (int i = 0; i < Edges.length; i++) {
   e1 = Edges[i];
   n1 = e1.n1;
   n2 = e1.n2;
   xyz[count*3]=n1.x;
   xyz[count*3+1]=n1.y;
   xyz[count*3+2]=n1.z;
   rgb[count*4]=e1.c.c1;
   rgb[count*4+1]=e1.c.c2;
   rgb[count*4+2]=e1.c.c3;
   rgb[count*4+3]=linealpha;
   count++;
   xyz[count*3]=n2.x;
   xyz[count*3+1]=n2.y;
   xyz[count*3+2]=n2.z;
   rgb[count*4]=e1.c.c1;
   rgb[count*4+1]=e1.c.c2;
   rgb[count*4+2]=e1.c.c3;
   rgb[count*4+3]=linealpha;
   count++;
 }
 f = ByteBuffer.allocateDirect(8 * xyz.length).order(ByteOrder.nativeOrder()).asFloatBuffer();
 f.put(xyz);
 f.rewind();
 c = ByteBuffer.allocateDirect(4 * rgb.length).order(ByteOrder.nativeOrder()).asFloatBuffer();
 c.put(rgb);
 c.rewind();
}


Code:

 gl.glLineWidth(2.0);
 gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
 gl.glEnableClientState(GL.GL_COLOR_ARRAY);
 gl.glVertexPointer(3,GL.GL_FLOAT,0,f);
 gl.glColorPointer(4,GL.GL_FLOAT,0,c);
 gl.glDrawArrays(GL.GL_LINES,0,f.capacity()/6);  
 gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
 gl.glDisableClientState(GL.GL_COLOR_ARRAY);


Here is my VA Code:

FloatBuffer vbuffer;
FloatBuffer cbuffer;
int edgeList;
void initEdges(){

 int count = 0;
 for (int i = 0; i < Edges.length; i++) {
   if (Edges[i].enablecat == true) {
count++;
   }
 }
 edgepointer = new int[count*2][3];
 Edge e1;
 Node n1, n2;
 int z1,z2;
 count = 0;
 vbuffer = BufferUtil.newFloatBuffer(Edges.length * 8);
 cbuffer = BufferUtil.newFloatBuffer(Edges.length * 4);
 for (int i = 0; i < Edges.length; i++) {
   e1 = Edges[i];
   n1 = e1.n1;
   n2 = e1.n2;
   vbuffer.put(n1.x);
   vbuffer.put(n1.y);
   vbuffer.put(n1.z);
   vbuffer.put(n2.x);
   vbuffer.put(n2.y);
   vbuffer.put(n2.z);

   cbuffer.put(e1.c.c1);
   cbuffer.put(e1.c.c2);
   cbuffer.put(e1.c.c3);
   cbuffer.put(linealpha);
 }

 vbuffer.rewind();
 cbuffer.rewind();

gl.glLineWidth(2);
 gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
 gl.glVertexPointer(3, GL.GL_FLOAT, 0, vbuffer);

 gl.glEnableClientState(GL.GL_COLOR_ARRAY);
 gl.glColorPointer(4, GL.GL_FLOAT, 0, cbuffer);
}

Code:

gl.glDrawArrays(GL.GL_LINES, 0, Edges.length);
Re: Vector versions of glVertex and glColor
Reply #5 - Jun 16th, 2009, 9:18am
 
fbo are a special display list which are able to be updatedvertex arrays has that, display lists dont.

in the end vbo were create to get the best of the two, DL & VA.

u wont get relevant performance hits by changing from DL to any of the others.. depends on other things..

how many lines are u drawing ? i assume u arent changing them since u were using a display list.

what computer specs are u working on ?

Re: Vector versions of glVertex and glColor
Reply #6 - Jun 16th, 2009, 9:24am
 
At the moment, I'm only drawing about 7000 lines (not changing them), but would like to draw much more (maybe 250,000).  I'm working on a MacBook Pro, which this performs fine on.  I'm trying to increase performance for some of our older Windows boxes where it chokes (1.6Ghz Core 2 Duo, with 512mb) - drops down to 3fps.  My FPS without the lines runs around 300, and at about 85 with the lines on my MacBook.  I attempting to get this to perform as well as possible so that more equipment can run it.  Doesn't do a lot of good if I've got the only hardware that can run it.  Smiley
Re: Vector versions of glVertex and glColor
Reply #7 - Jun 16th, 2009, 12:53pm
 
7000 lines sounds very much possible to me.. even on a low end machine.

you better think about using a way to reject anything not on screen.
250.000 visible lines is overkill. you wont seen most of it anyway.


u also have to think about the GPU u're using, since u are using VA/DL. that will upload your data to the gpu, so it turns things much faster than the traditional way.. so if ur vcard is not up to it, 3fps sounds just fine.

another thing is the videocard fillrate. drawing things that occupy 20% of the screen and drawing sumtin that takes up to 90% of the screen is different.. lots of things to think and handle if u wanna have a 250K line scene


edit:
i took ur code and ran 100K lines with VA in a p4 3ghz, 1.5gb ram and an ati 9800 pro. 15fps.  
6,7fps when the lines take all the screen


drawing half of it (50K) takes the app up to 19. only 4fps more.

as u see its not only about the number of things u render that will make framerate double
Re: Vector versions of glVertex and glColor
Reply #8 - Jun 16th, 2009, 7:49pm
 
Could a glsl shader be used to improve performance on my lines?
Re: Vector versions of glVertex and glColor
Reply #9 - Jun 17th, 2009, 1:43am
 
not as you need
maybe if you explain more about what u're after i can help with it
Re: Vector versions of glVertex and glColor
Reply #10 - Jun 17th, 2009, 7:34am
 
I'm trying to create an interactive 3d graph visualizer.  Something in functionality to Skyrails, but that can scale to several hundred thousand nodes/edges.  I don't seem to have an issue with my nodes, which have multiple textures applied (I can add and remove them without much change in fps).  But the edges (lines) do drop it by several hundred.  Since I'm going for scalability, I just want to make sure I'm doing things as efficient as possible.  Cytoscape has a project to tie their product into Processing, so I want to leverage that if I can.  Here is a pic of one of it's graphs.
Re: Vector versions of glVertex and glColor
Reply #11 - Jun 17th, 2009, 5:23pm
 
hmm skyrails looks very good. still i dont think he renders 10K visible lines, even if it does its a waste.
but i think they may be using a system that hides and shows geometry based on where u go and how you "zoom" in and out. it also works with 3d models and information around the scenery.. still no need for all the 100k visible lines.

about the other picture. there are lots of lines but 10K can make that image.

what im trying to say is that you need to set your target machine and find your limits. whats the minimum requirements and work your application based on that. you wont be able to do alot with few.

following skyrails. he hides nodes based on distance from camera. it fades out, it sure would hide anything outside the camera frustum, if it doesnt it should. one looking at it it doesnt seem too complicated in geometry. you might have a graph of enough nodes to get 250k connections (lines) but honestly how many will you be seeing at one time.. even if you zoom out to get the big view of everything, most of the lines wont be visible. you need to think about all that and see how to build your application to get the best of it with low end machines.

im not sure i have helped you, hopefully you will think your project now from another point of view.. or not.

send some shots from your project, let me see something and maybe i can get some ideas on how to make it look the same with less.
Re: Vector versions of glVertex and glColor
Reply #12 - Jun 18th, 2009, 6:44pm
 
Thanks, I'll certainly think about those design elements.  I'll try to post something soon. Smiley
Page Index Toggle Pages: 1