Experiencing slow frameRate with GLGraphics
in
Contributed Library Questions
•
1 years ago
The following sketch its running at an avg. of 17fps when I use GLGraphics and GLModel to draw bunch of simple square planes, so I wonder if I'm doing something wrong with my GLGraphics setup.
Here is the main blocks of my sketch, BoxFitter class is not included all it does is claculate the size and positions of each cell in setup()
Main:
- import javax.media.opengl.*;
- import java.util.ArrayList;
- import codeanticode.glgraphics.*;
- import processing.opengl.*;
- import toxi.geom.Vec3D;
- import remixlab.proscene.*;
- BoxFitter fitter;
- ArrayList<Cell> cells;
- int currentSeed = 0;
- int fitterWidth = 640;
- int fitterHeight = 480;
- boolean showWireframes = false;
- Scene scene;
- GLTexture textureSource;
- public void setup() {
- size( 640, 480, GLGraphics.GLGRAPHICS );
- // Setup scene
- scene = new Scene( this );
- scene.setRadius( 600 );
- scene.showAll();
- scene.setAxisIsDrawn( false );
- scene.setGridIsDrawn( false );
- // Initialize fitter
- fitter = new BoxFitter( fitterWidth, fitterHeight, 10, 10, 10 );
- fitter.make( ++currentSeed );
- // Initialize boxes
- cells = new ArrayList<Cell>();
- createBoxes();
- }
- public void draw() {
- GLGraphics renderer = (GLGraphics)g;
- background( 0 );
- for ( int i = 0; i < cells.size(); i++ ) {
- Cell cell = (Cell)cells.get( i );
- cell.position.z += -cell.position.z * (cell.sizeD * 0.01f);
- pushMatrix();
- translate( -fitterWidth / 2, -fitterHeight / 2, 0 );
- cell.showWires = showWireframes;
- cell.display();
- renderer.beginGL();
- renderer.model( cell.plane );
- renderer.endGL();
- popMatrix();
- }
- //println( frameRate );
- }
- private void createBoxes() {
- cells.clear();
- for ( int i = 0; i < fitter.getNumberOfCells(); i++ ) {
- int x = fitter.getCellsProperties()[i][0];
- int y = fitter.getCellsProperties()[i][1];
- int w = fitter.getCellsProperties()[i][2];
- int h = fitter.getCellsProperties()[i][3];
- int c = color( random( 82, 255 ), 30, random( 130, 255 ) );
- int m = fitter.maxSizer;
- Cell cell = new Cell( this, w, h, w, c, m );
- cell.position = new Vec3D( x, y, 600 );
- cells.add( cell );
- }
- }
Cell:
- public class Cell {
- PApplet parent;
- Vec3D position;
- int sizeW, sizeH, sizeD;
- int colorTint;
- int maxSize;
- boolean showWires;
- GLModel plane;
- int[] planeModelIndices = { 0, 1, 2, 0, 3, 2 };
- Cell( PApplet _parent, int _sizeW, int _sizeH, int _sizeD, int _colorTint, int _maxSize ) {
- parent = _parent;
- sizeW = _sizeW;
- sizeH = _sizeH;
- sizeD = _sizeD;
- colorTint = _colorTint;
- maxSize = _maxSize;
- showWires = false;
- // Setup plane
- plane = new GLModel( parent, 4, GLModel.TRIANGLES, GLModel.STATIC );
- plane.initIndices( 6 );
- plane.updateIndices( planeModelIndices );
- plane.beginUpdateVertices();
- plane.updateVertex( 0, -sizeW / 2, -sizeH / 2, 0 );
- plane.updateVertex( 1, sizeW / 2, -sizeH / 2, 0 );
- plane.updateVertex( 2, sizeW / 2, sizeH / 2, 0 );
- plane.updateVertex( 3, -sizeW / 2, sizeH / 2, 0 );
- plane.endUpdateVertices();
- plane.initColors();
- plane.beginUpdateColors();
- plane.updateColor( 0, red( colorTint ), green( colorTint ), blue( colorTint ), 255 );
- plane.updateColor( 1, red( colorTint ), green( colorTint ), blue( colorTint ), 255 );
- plane.updateColor( 2, red( colorTint ), green( colorTint ), blue( colorTint ), 255 );
- plane.updateColor( 3, red( colorTint ), green( colorTint ), blue( colorTint ), 255 );
- plane.endUpdateColors();
- }
- public void update() {
- }
- public void display() {
- //GLGraphics renderer = (GLGraphics)g;
- if ( showWires ) {
- stroke( color( colorTint ) );
- noFill();
- }
- else {
- noStroke();
- fill( color( colorTint ) );
- }
- pushMatrix();
- translate( position.x + (sizeW / 2), position.y + (sizeH / 2), position.z);
- //box( sizeW, sizeH, sizeW );
- //rect( -sizeW / 2, -sizeH / 2, sizeW, sizeH );
- //renderer.beginGL();
- //renderer.model( plane );
- //renderer.endGL();
- popMatrix();
- }
- }
I try calling the renderer begin/endGL inside the cell object thinking that may be the bottle neck so I move it to the main draw() but didn't make any difference.
Any help will be much appreciated
1