BytePtr
April 14th, 2009, 01:05 PM
Im creating map editor for one game, so far OK. But i found one bottleneck from my algorithm.
At the moment this is the case.
I have 3 for loops (x,y), 0-35,0-7, in this for loop i check for block sides (CheckSides) and also at the same time im drawing the block (DrawIt(x)).
procedure Render;
for x:= 0 to 35 do
for y:= 0 to 35 do
begin
glPushMatrix();
glTranslatef( 1.0 * y, 0.0, 1.0 * x );
// For all blocks in column..
for z:= 0 to 7 do
begin
glPushMatrix();
CheckSides( z, x, y );
DrawIt( 0 );
glPopMatrix();
glTranslatef( 0.0, 1.0, 0.0 );
end;
glPopMatrix;
end; }
DrawIt() procedure is something like this (basically it contains all glVertex3f calls.
if WireFrame = True then glBegin( GL_LINE_STRIP ) else glBegin( GL_QUADS );
glColor3f(1,1,1);
for i:=0 to 3 do
begin
glTexCoord2f(SLOPE_RAW_DATA[Which,0,i,0],
SLOPE_raw_DATA[Which,0,i,2]);
glvertex3f(SLOPE_RAW_DATA[Which,3,i,0],
SLOPE_RAW_DATA[Which,3,i,1],
SLOPE_RAW_DATA[Which,3,i,2]);
end;
glVertex3f(SLOPE_RAW_DATA[Which,3,0,0],
SLOPE_RAW_DATA[Which,3,0,1],
SLOPE_RAW_DATA[Which,3,0,2]);
glEnd;
end;
Yes, it's Pascal, but code is simple.
So Render procedure basically checks and draws everything.
So as you see: for loops are in MAIN rendering procedure. This is bad.
Eats alot of CPU, when running i get 70-80 CPU usage.
If i remove for loops from main rendering procedure then CPU usage goes down to 03%.
How could i rewrite my algorithm, so i can remove for loops from rendering routine?
Read and check the data somewhere else and store also somewhere, but how can i read them?
Im lost totally.
Any ideas, hints or suggestions?
At the moment this is the case.
I have 3 for loops (x,y), 0-35,0-7, in this for loop i check for block sides (CheckSides) and also at the same time im drawing the block (DrawIt(x)).
procedure Render;
for x:= 0 to 35 do
for y:= 0 to 35 do
begin
glPushMatrix();
glTranslatef( 1.0 * y, 0.0, 1.0 * x );
// For all blocks in column..
for z:= 0 to 7 do
begin
glPushMatrix();
CheckSides( z, x, y );
DrawIt( 0 );
glPopMatrix();
glTranslatef( 0.0, 1.0, 0.0 );
end;
glPopMatrix;
end; }
DrawIt() procedure is something like this (basically it contains all glVertex3f calls.
if WireFrame = True then glBegin( GL_LINE_STRIP ) else glBegin( GL_QUADS );
glColor3f(1,1,1);
for i:=0 to 3 do
begin
glTexCoord2f(SLOPE_RAW_DATA[Which,0,i,0],
SLOPE_raw_DATA[Which,0,i,2]);
glvertex3f(SLOPE_RAW_DATA[Which,3,i,0],
SLOPE_RAW_DATA[Which,3,i,1],
SLOPE_RAW_DATA[Which,3,i,2]);
end;
glVertex3f(SLOPE_RAW_DATA[Which,3,0,0],
SLOPE_RAW_DATA[Which,3,0,1],
SLOPE_RAW_DATA[Which,3,0,2]);
glEnd;
end;
Yes, it's Pascal, but code is simple.
So Render procedure basically checks and draws everything.
So as you see: for loops are in MAIN rendering procedure. This is bad.
Eats alot of CPU, when running i get 70-80 CPU usage.
If i remove for loops from main rendering procedure then CPU usage goes down to 03%.
How could i rewrite my algorithm, so i can remove for loops from rendering routine?
Read and check the data somewhere else and store also somewhere, but how can i read them?
Im lost totally.
Any ideas, hints or suggestions?