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.
Page Index Toggle Pages: 1
JOGL performance (Read 946 times)
JOGL performance
Dec 17th, 2009, 4:27pm
 
Kind of scratching my head over this. Doing some benchmarking with JOGL implemented in Processing compared to in straight Java. The test code draws/rotates 50k rectangles. I did 2 versions in Java with/without display lists.
Running on MacBook Pro, 10.6.2, newest build version of JOGL

Results so far, better performance in Processing.

I've been messing with anti-aliasing, lighting, etc, but P5 JOGL still out performs Java/JOGL.



Re: JOGL performance
Reply #1 - Dec 21st, 2009, 7:47am
 
Here's a test that I had done previously, maybe not exactly the same as what you're testing, but might perhaps help track down what/where your performance problem is (?)

Quote:
/**
* P5GL.pde (davebollinger-a_t-gmail_d-o-t_com)
* (old undated code, but rechecked vs 1.0.9 on 12/21/2009)
* to compare performance between having processing "wrap"
* all the OpenGL calls, versus doing them directly.  intent
* is to mimic as closely as possible same code conventions
* between either method (that is, with no "fancy" tricks,
* like vertex buffers, etc)
*/
import processing.opengl.*;
import javax.media.opengl.GL;
PGraphicsOpenGL pgl;
GL gl;

final int NOP = 0;
final int PGL = 1;
final int OGL = 2;
int drawmode = PGL;

// with 10k tris, direct opengl is about 10X faster on my pc
// but.. with 100k tris, opengl is only about 2X faster
// so watch out for "performance thresholds" while testing
int ntris = 10000;
RandomTriangle [] tris;

float rotx_rad, roty_rad; // in radians, for p5
float rotx_deg, roty_deg; // in degrees, for gl

void setup() {
 size(500,500,OPENGL);  
 pgl = (PGraphicsOpenGL)g;
 tris = new RandomTriangle[ntris];
 for (int i=0; i<ntris; i++)
   tris[i] = new RandomTriangle();
}

void animate() {
 // two copies of the rotation values so that the
 // rad2deg conversion occurs outside the timing loop
 rotx_rad += 0.012;
 roty_rad += 0.023;
 rotx_deg = degrees(rotx_rad);
 roty_deg = degrees(roty_rad);
}

void draw() {
 animate();
 long startTime = System.nanoTime();
 switch(drawmode) {
   case NOP : drawNOP(); break;
   case PGL : drawPGL(); break;
   case OGL : drawOGL(); break;
 }
 long elapsedTime = System.nanoTime() - startTime;
 println("elasepd = " + elapsedTime);
}

void drawNOP() {
 // the point here is to time just the invariant stuff:
 // looping, array indexing, method calling
 // (it should be trivial, but.. just to be thorough..)
 for (int i=0; i<ntris; i++)
   tris[i].renderNOP();
}

void drawPGL() {
 // clear
 background(0);
 // transform
 translate(width/2f,height/2f,0f);
 rotateX(rotx_rad);
 rotateY(roty_rad);
 // lights
 lights();
 // render the tris
 fill(255);
 noStroke();
 beginShape(TRIANGLES);
 for (int i=0; i<ntris; i++)
   tris[i].renderPGL();
 endShape();
 // done
}

void drawOGL() {
 gl = pgl.beginGL();
 // clear
 gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
 // transform
 gl.glTranslatef(width/2f, height/2f, 0f); // note: beginDraw() has already flipped y
 gl.glRotatef(rotx_deg, 1.0, 0.0, 0.0);
 gl.glRotatef(roty_deg, 0.0, 1.0, 0.0);
 // lights
 // does NOT exactly mimic p5's lights(),
 // but DOES turn one (default) light on
 // (to represent equiv effort as p5's lights())
 // beginDraw() may have already done some of this for us, oh well
 gl.glShadeModel(GL.GL_SMOOTH);
 gl.glEnable(GL.GL_LIGHT0);
 gl.glEnable(GL.GL_LIGHTING);
 gl.glEnable(GL.GL_COLOR_MATERIAL);
 gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, 1);
 // turn on some things to mimic what p5 is doing
 // behind the scenes as far as normal generation
 // (GL_NORMALIZE may be unfair/unnecessary, but assume worst case for testing)
 gl.glEnable(GL.GL_NORMALIZE);
 gl.glEnable(GL.GL_AUTO_NORMAL);
 // render the tris
 gl.glColor4f(1f,1f,1f,1f);
 gl.glBegin(GL.GL_TRIANGLES);
 for (int i=0; i<ntris; i++)
   tris[i].renderOGL();
 gl.glEnd();
 // done
 pgl.endGL();
}

void keyPressed() {
 switch(key) {
   case ' ' :
     drawmode = (drawmode+1)%3;
     println("drawmode = " + drawmode);
     break;
 }
}

class RandomTriangle {
 PVector [] verts;
 RandomTriangle() {
   verts = new PVector[3];
   float XYZ = 150f;
   float x = random(-XYZ,XYZ);
   float y = random(-XYZ,XYZ);
   float z = random(-XYZ,XYZ);
   float WHD = 30f;
   for (int i=0; i<3; i++)
     verts[i] = new PVector(x+random(-WHD,WHD),y+random(-WHD,WHD),z+random(-WHD,WHD));
 }
 void renderNOP() {
 }
 void renderPGL() {
   // begin/end are handled OUTSIDE loop
   //beginShape(TRIANGLES);
   PVector v;
   v = verts[0]; vertex(v.x, v.y, v.z);
   v = verts[1]; vertex(v.x, v.y, v.z);
   v = verts[2]; vertex(v.x, v.y, v.z);
   //endShape();
 }
 void renderOGL() {
   // begin/end are handled OUTSIDE loop
   //gl.glBegin(GL.GL_TRIANGLES);
   PVector v;
   v = verts[0]; gl.glVertex3f(v.x, v.y, v.z);
   v = verts[1]; gl.glVertex3f(v.x, v.y, v.z);
   v = verts[2]; gl.glVertex3f(v.x, v.y, v.z);
   //gl.glEnd();
 }
}

Page Index Toggle Pages: 1