ofMesh draw() slow vs ofGetGLRenderer()->draw(ofMesh)

Basically its this; I am drawing ~1000 ofTextures on screen, and that’s pretty fast.

My project requires the textures to be drawn in a parallelogram shape, so I built an ofMesh for each texture, updating it when required, and then drawing the mesh binding the appropriate texture before.

tex->bind();
mesh.draw();
tex->unbind();

But this really dropped my framerate. Looking into how ofTexture.draw() works, I saw a custom ofMesh is built in place for every draw() call, so I thought I should get a similar performance… So digging around, I ended up trying what happens inside ofTexture:

tex->bind();
ofGetGLRenderer()->draw(mesh, false, true, false);
tex->unbind();

And it blows away mesh.draw() in terms of performance. How come? It’s not really a bug, but something is clearly off. Anyone getting this? This is in 0.8.4 release on OSX 10.9.

are you using 0.8.4 or current master? in any case ofMesh::draw is making an extra call to ofMesh::draw(polyMode) and then it checks that the mesh is not empty before calling renderer->draw so that might make things slightly slower. also what’s the difference between the 2 methods?

Hey Arturo!

Testing on a frankenstein OSX mashup branch bc I need 64 bit (https://github.com/local-projects/openFrameworks/tree/project/PG).

I just put a breakpoint on ofMesh(draw) and I see that in my ofMesh useColors and useNormals are true when they shouldn’t (I don’t add any colors or normals to the mesh); Its the only difference I can see?

void ofMesh::draw(ofPolyRenderMode renderType) const{
	if(getNumVertices()==0) return;
	ofGetCurrentRenderer()->draw(*this,renderType,useColors,useTextures,useNormals);
}

So I just tried hardcoding ofMesh::draw() to not use normals or colors as a quick test

void ofMesh::draw(ofPolyRenderMode renderType) const{
	if(getNumVertices()==0) return;
	ofGetCurrentRenderer()->draw(*this,renderType,false,useTextures,false);
}

And I also get a low frame rate. I’m quite puzzled too.

see for yourself: http://cl.ly/0F361q3g3p05

Got it! if I drop the renderType from the ofMesh draw() call, then its back to speed

void ofMesh::draw(ofPolyRenderMode renderType) const{
	if(getNumVertices()==0) return;
	ofGetCurrentRenderer()->draw(*this, /*renderType,*/ useColors,useTextures,useNormals);
}

So I’m guessing the

	glPushAttrib(GL_POLYGON_BIT);
	glPolygonMode(GL_FRONT_AND_BACK, ofGetGLPolyMode(renderType));
	draw(vertexData,useColors,useTextures,useNormals);
	glPopAttrib(); //TODO: GLES doesnt support polygon mode, add renderType to gl renderer?

that happen across 1000 calls per frame really slow it down. I wonder if those can be skipped in ofMesh.draw()

Do you want this as a github issue?

the programmable renderer already doesn’t use push / pop attributes and instead just sets back the polygon mode according to the current fill style so we probably should just do that in the fixed pipeline renderer too.

but yes if you can open an issue?