ofLine makes my framerate drop

Hi, on raspberry PI2 this function reduce the framerate from 60fps to 10fps…

ofColor(255, 255, 255, 255);
int col_step = width / 10;
int row_step = height / 10;

ofDisableSmoothing();
ofDisableAntiAliasing();
for (int i = 0; i < width; i += col_step) {
	ofLine(i, 0, i, height);
}
for (int i = 0; i < height; i += row_step) {
	ofLine(0, i, width, i);
}
ofEnableAntiAliasing();
ofEnableSmoothing();

Is there anything else I need to disable before using ofLine ? Without the ofDisableXX / ofEnable : same result

Hi,

Something like this will be faster, the GPU prefers it if you hand it a lot of vertices to draw at once, which you can do using an ofMesh.

ofColor(255, 255, 255, 255);
int col_step = width / 10;
int row_step = height / 10;

ofMesh mesh;
mesh.setMode( OF_PRIMITIVE_LINES );

ofDisableSmoothing();
ofDisableAntiAliasing();
for (int i = 0; i < width; i += col_step) {
	//ofLine(i, 0, i, height);
	mesh.addVertex( ofVec2f(i,0) );
	mesh.addVertex( ofVec2f(i,height) );
}
for (int i = 0; i < height; i += row_step) {
	//ofLine(0, i, width, i);
	mesh.addVertex( ofVec2f(0,1) );
	mesh.addVertex( ofVec2f(width,i) );
}
mesh.draw();
ofEnableAntiAliasing();
ofEnableSmoothing();

Then of course you can just make the mesh once in setup() and draw it every frame.

2 Likes

Thanks !!

Yes ! Pfeew… Why didn’t I thought about setting up the mesh and using it when needed ?

It’s a long way to the top if you wanna be a rock’n’roll star :slight_smile:

1 Like

That’s what we’re here for!

There is ofVboMesh as well which might let you squeeze a few more fps out of it, but definitely batching the vertices up is the lowest hanging fruit in the pursuit of ULTIMATE performance.

1 Like