c++ - Is it possible to execute a for loop inside a display list in openGL? -
i trying create pattern using multiples calls ellipse function, draws feature this:
glbegin(gl_line_loop); for(int i=0; < 360; i++) { //convert degrees radians float deginrad = i*deg2rad; glvertex2f(cos(deginrad)*xradius,sin(deginrad)*yradius); } glend(); to accelerate rendering decided put on display list , created following function called main() :
void features::drawellipse(float xradius, float yradius, gluint index) { glnewlist(index, gl_compile); glbegin(gl_line_loop); for(int i=0; < 360; i++) { //convert degrees radians float deginrad = i*deg2rad; glvertex2f(cos(deginrad)*xradius,sin(deginrad)*yradius); } glend(); glendlist(); } but there no evidence of better performance when call on main
static gluint ellipselist; ... drawellipse(0.2,0.3,ellipselist); what doing wrong or loop not allowed inside display lists?
opengl display lists don't care loops or other programming constructs. they're recording of every opengl function called, in sequence, happen between glnewlist , glendlist. it's kind of if surrounded every function beginning gl… (and those) print statement prints kind of file. when calling display list, contents "played back". loops used when building display lists effective putting loop around calls printf – same effect.
as why don't see performance difference? because modern gpus driver has compile calls glvertex , friends (the immediate mode drawing calls) command buffer gets submitted gpu anyway. , command buffer not different what's in display list itself. if amount of calls glvertex goes up, you'll see effect of function call , memory allocation overhead, though. try replacing 360 large number, 1000000.
Comments
Post a Comment