how can i know how many triangles are being rendered on screen?

how can i know how many triangles are being rendered on screen? thanks

that’s a odd question…
since you’re drawing them you should know…

unless you’re using tesselators or evaluators…

the idea is to know HOW MANY ON SCREEN not in total because in total thats simple to keep track but how do you know how many are seen at that exact moment? :expressionless: not an odd question to me.

i believe you mean how many triangles are visible… look for a post i made some time ago about that, i got a very good answer

you mean how many are visible in the current viewport?

Easiest method I can think of is to use selection mode,
Just render the scene in the exact same way under selection mode, supplying a name for each triangle.

Seeing as you only want to know how many triangles are visible, you wouldn’t even need to read the hit buffer just take the hit count.

Here’s an example:

Adjust BUFSIZE depending how big a buffer you need,
the more triangles you draw the bigger buffer you’ll need.

#define BUFSIZE 512

GLuint buf[BUFSIZE];
GLint hits;

glSelectBuffer(BUFSIZE, buf);
glRenderMode(GL_SELECT);

glInitNames();
glPushName(0);

/* Here draw your triangles, calling glLoadName(<num>); before each /
/
You could even just call it with 0 each time, seeing as you only want the hit count */
for each triangle do {
glLoadName(0);
drawtriangle();
}

glFlush();

/* Hits will be the triangle count */
hits = glRenderMode(GL_RENDER);

thank you! im going to try it right now!

hi it works however my objects are not being rendered now! but when i debug and i move (i know where i move to a certain point some objects will be off-focus) the number of shown tris changes so i guess its working but they arent being rendered yes i change the render mode to gl_render … but it aint working!

okey looks like ill have to “render” everything twice in order to get this method to work, then its not good for me because if you want to debug how many triangles are on scene and check the current fps… then that fps will be worthless as it will be the count of rendering double data ? it goes too slow here with this method i mean i had to do a pass with the selection rendering mode and then the same pass but with normal render mode and its very laggy!! i get low amount of FPS and of course im rendering everything twice (at least on the loop im processing 2 times the same) how can i make it better? i mean its a waste of everything to do it like this!!

perhaps you should read redarrow’s first post again…you only asked for the count, not some sort of snazzy bench.

if you’re really benching your app, you should already have a good idea of how many triangles you’re pushing each frame. if not there’s something horribly wrong with your pipes. this kind of information is eminently knowable.

heck, if you don’t belive me, just ask jeeves.

sincerely,
bonehead

Originally posted by doodlemunch:
I mean its a waste of everything to do it like this!!
True, glad you’ve seen it by yourself :smiley:
Really, the number of triangles onscreen is not really useful to benchmark.
Basically each triangle must be transformed to know whether it is within the view fustrum.

However, the total number of pixel that have to be drawn on screen is important, especially in case of overdraw and blending, worst case is fullscreen puffs of semitransparent smoke, even if there are only a dozen it can be very slow.

Can you tell us more about what you really want to achieve ?

well in dx you can do this with out speed loss thats why i wanted to achive a CurrentTris() function but seems like opengl is not up to the task for this.

it is not a stupid idea to have such function, because its useful for level designers, you tell them “I want maximum 10.000 faces onscreen” so you give them a simple viewer where they can test the level and get the amount of tris being rendered, thats the main purpose of this. its not for benchmarking because I dont care about that…

doodlemunch…as you render your world simply count the triangles/batches you draw. i don’t see a strongly compelleing argument for having opengl do this. d3d does expose some stat stuff through its query mechanism, but for simple triangle counting this is not really necessary, is it?

maybe opengl will expose similar functionality in its query mechanism, as an extension. i never said the idea was stupid…and it’s not like this has never come up before (try a search if you have a free afternoon). for what it’s worth i’m not fundamentally opposed to the idea. but for now i think the only query available at the moment is occlusion.

best of wishes,
bonehead

pitty I just needed something like this but fast method