Forums > Jitter

Optimise OpenGL on Jitter: 3D scene too slow (2)

March 22, 2010 | 12:42 pm

Hi,

just restarting the thread http://cycling74.com/forums/topic.php?id=25464 to add a more friendly compressed code of my patch.

– Pasted Max Patch, click to expand. –

March 22, 2010 | 6:25 pm

For this sort of thing, definitely, shapeslice 2 2 will be much faster (for cubes). And you might want to look at jit.gl.multiple instead of this approach.

Finally, rather than regenerating every command each time, you could just append new shapes when you change the dimensions rather than uzi from the beginning. This requires a little more state, and might suggest you work on building your commandlist in something like JS.

Otherwise, you are sending a *lot* of messages all at once, and also trying to render a potentially huge amount of geometry. So you’ll need to make some choices for what is acceptable to your application w/r/t complexity vs. performance.


March 23, 2010 | 5:17 pm

Thank you for your help. I have changed the shapeslice parameter to [2 2] for cubes and planes, and it improved the efficiency greatly.

I am using Java to control this, the patch I have submitted is a simplified version of it. I now improved it also by replacing commands using ‘cmd_replace’.

If ever that’s of use to anyone, I post below the method ‘setcell’ of my java external, which takes as parameters the 3D coordinates of an object and its color. I’m using a hashtable to locate the number of the command, which is all i need to replace the objects by new ones. The point of that function is to redraw an object in a 3D space in replacement of a similar object. This is useful only if you have a large number of elements and want to change some of them.


public void setcell(int x, int y, int z, float r,float g,float b, float alpha)
{
// mat is a Jitter Matrix
mat.setcell(new int[]{x,y,z},new float[]{r,g,b,alpha});
int[] dim = mat.getDim();

int cmd = 0;
try //get the command number from the hashtable
{
String s = "x"+x+"y"+y+"z"+z;
cmd = ((Integer)(hasht.get(s))).intValue();
}
catch (Exception e)
{

post("nexception caught "+e.getLocalizedMessage());
}
//Building a command seems to work only with arrays of Atom
Atom [] tmp = new Atom[6];
tmp[0] = Atom.newAtom(cmd);
tmp[1] = Atom.newAtom("glcolor");
tmp[2] = Atom.newAtom(r);
tmp[3] = Atom.newAtom(g);
tmp[4] = Atom.newAtom(b);
tmp[5] = Atom.newAtom(alpha);

sketch.send("cmd_replace",tmp); //set the color in jit.gl.sketch object

cmd++;

tmp = new Atom[5];
tmp[0] = Atom.newAtom(cmd);
tmp[1] = Atom.newAtom("moveto");
tmp[2]= Atom.newAtom((x-dim[0]/2.f)/(dim[0]/2.f));
tmp[3] = Atom.newAtom((y-dim[1]/2.f)/(dim[1]/2.f));
tmp[4] = Atom.newAtom((zspace*z-dim[2])/25.f);

sketch.send("cmd_replace",tmp); //move to the desired position

cmd++;

// We need different sizes for the array of Atoms according to the shape that we want to render
//In this last sequence, we render either a cube, a plane or a sphere into the sketch space in replacement of the previous command
if (shape.equals("cube"))
{
tmp[0] = Atom.newAtom(cmd);
tmp[1] = Atom.newAtom(shape);
tmp[2] = Atom.newAtom(csize*0.075f/10.f);
tmp[3] = Atom.newAtom(csize*0.075f/10.f);
tmp[4] = Atom.newAtom(0.01f);
sketch.send("cmd_replace",tmp);
}
else if (shape.equals("plane"))
{
tmp = new Atom[4];
tmp[0] = Atom.newAtom(cmd);
tmp[1] = Atom.newAtom(shape);
tmp[2] = Atom.newAtom(csize*0.075f/10.f);
tmp[3] = Atom.newAtom(csize*0.075f/10.f);
sketch.send("cmd_replace",tmp);

}
else if (shape.equals("sphere"))
{
tmp = new Atom[3];
tmp[0] = Atom.newAtom(cmd);
tmp[1] = Atom.newAtom(shape);
tmp[2] = Atom.newAtom(csize*0.075f/10.f);
sketch.send("cmd_replace",tmp);
}

}


Viewing 3 posts - 1 through 3 (of 3 total)