Lost 20 FPS when drawing 4 big QUAD shapes
in
Programming Questions
•
2 years ago
Hi everyone,
First of all I apologize for every english mistakes I made : my english is not fluent!
My problem is the following : I'm developing a P3D video-game with a GTA 1 (or 2) like graphics, recently I tried to add some Trees in my map using 3 or 4 QUAD shaped layers in different z pos. These shapes has differents texture and they are just simple "big" squares=> 500*500.
My app size is 800*600 and my camera's z position is 1500.
Before these trees my FPS was up to 60 at all times, and now when there is 2 trees on my screen (so max. 8 layers of 500*500 textured QUAD shapes) my FPS goes down to like 40 and when I use a less powerfull computer it goes down to 20 FPS~~.
I just don't understand because it's just 8 textured squares, and in my map there is like 20 houses which are for some 750*500*750 3d CUBES! More than 5 cubes can be drawn on the scene without a little FPS loss...
Maybe I'm doing something wrong when drawing those shapes ?! :
The thing is when I set the camera's z position to 3000 or 4000 (two times higher) there is no more FPS loss, we can see the whole map with all trees w/o any loss....
I really don't understand why there is this loss... It's just 4 damn 2D squares !
I also trid to change the texture to something with the exact size of the squares (500*500) so the app won't resize it, but no changes (I even tried to change the texture to something simply black, because my original textures are PNG with a lot of transparency, no changes)
Thank you for your help!
First of all I apologize for every english mistakes I made : my english is not fluent!
My problem is the following : I'm developing a P3D video-game with a GTA 1 (or 2) like graphics, recently I tried to add some Trees in my map using 3 or 4 QUAD shaped layers in different z pos. These shapes has differents texture and they are just simple "big" squares=> 500*500.
My app size is 800*600 and my camera's z position is 1500.
Before these trees my FPS was up to 60 at all times, and now when there is 2 trees on my screen (so max. 8 layers of 500*500 textured QUAD shapes) my FPS goes down to like 40 and when I use a less powerfull computer it goes down to 20 FPS~~.
I just don't understand because it's just 8 textured squares, and in my map there is like 20 houses which are for some 750*500*750 3d CUBES! More than 5 cubes can be drawn on the scene without a little FPS loss...
Maybe I'm doing something wrong when drawing those shapes ?! :
class tree implements mapObject
{
float x,y;
int type = 1;
float h;
int mySize = 50;
PImage tex1;
PImage tex2;
PImage tex3;
PImage tex4;
tree(float _x, float _y, float _h, int _type, int _size)
{
x=_x;
y=_y;
h=_h;
type=_type;
mySize = _size;
setText();
}
// There is 4 different type of Trees (with differents textures) so we change the textures depending on the type
void setText()
{
if (type == 1)
{
tex1=treeTex.get(0);
tex2=treeTex.get(2);
tex3=treeTex.get(3);
tex4=treeTex.get(1);
}
else if (type == 2)
{
tex1=treeTex.get(4);
tex2=treeTex.get(5);
tex3=treeTex.get(6);
}
else if (type == 3)
{
tex3=treeTex.get(7);
tex1=treeTex.get(8);
tex4=treeTex.get(9);
}
else if (type == 4)
{
tex1=treeTex.get(10);
tex4=treeTex.get(11);
tex3=treeTex.get(12);
}
else
{
tex1=treeTex.get(0);
tex2=treeTex.get(2);
tex3=treeTex.get(3);
tex4=treeTex.get(1);
}
}
void draw()
{
// when not on the screen, Tree are not draw
if(screenX(x,y,0)>-3 && screenX(x,y,0)<width+3 && screenY(x,y,0)>-3 && screenY(x,y,0)<height+3);
else if(screenX(x+mySize,y,0)>-3 && screenX(x+mySize,y,0)<width+3 && screenY(x+mySize,y,0)>-3 && screenY(x+mySize,y,0)<height+3);
else if(screenX(x,y+mySize,0)>-3 && screenX(x,y+mySize,0)<width+3 && screenY(x,y+mySize,0)>-3 && screenY(x,y+mySize,0)<height+3);
else if(screenX(x+mySize,y+mySize,0)>-3 && screenX(x+mySize,y+mySize,0)<width+3 && screenY(x+mySize,y+mySize,0)>-3 && screenY(x+mySize,y+mySize,0)<height+3);
else
{
return;
}
noStroke();
noFill();
// Tree's trunk (2 quads)
beginShape(QUADS);
{
vertex(x-10,y,0);
vertex(x+10,y,0);
vertex(x+10,y,h);
vertex(x-10,y,h);
vertex(x,y-10,0);
vertex(x,y+10,0);
vertex(x,y+10,h);
vertex(x,y-10,h);
}
endShape();
// First layer
if (tex1 != null)
{
beginShape(QUADS);
{
texture(tex1);
vertex(x-mySize,y-mySize,h,0,0);
vertex(x+mySize,y-mySize,h,tex1.width,0);
vertex(x+mySize,y+mySize,h,tex1.width,tex1.height);
vertex(x-mySize,y+mySize,h,0,tex1.height);
}
endShape();
}
// Second layer
if (tex2 != null)
{
beginShape(QUADS);
{
texture(tex2);
vertex(x-mySize,y-mySize,h-60,0,0);
vertex(x+mySize,y-mySize,h-60,tex2.width,0);
vertex(x+mySize,y+mySize,h-60,tex2.width,tex2.height);
vertex(x-mySize,y+mySize,h-60,0,tex2.height);
}
endShape();
}
// Third layer
if (tex3 != null)
{
beginShape(QUADS);
{
texture(tex3);
vertex(x-mySize,y-mySize,h+10,0,0);
vertex(x+mySize,y-mySize,h+10,tex3.width,0);
vertex(x+mySize,y+mySize,h+10,tex3.width,tex3.height);
vertex(x-mySize,y+mySize,h+10,0,tex3.height);
}
endShape();
}
// Fourth layer
if (tex4 != null)
{
beginShape(QUADS);
{
texture(tex4);
vertex(x-mySize,y-mySize,h-30,0,0);
vertex(x+mySize,y-mySize,h-30,tex4.width,0);
vertex(x+mySize,y+mySize,h-30,tex4.width,tex4.height);
vertex(x-mySize,y+mySize,h-30,0,tex4.height);
}
endShape();
}
}
}
tree(315,2870,250,2,250);
tree(840,3185,210,3,200);
The thing is when I set the camera's z position to 3000 or 4000 (two times higher) there is no more FPS loss, we can see the whole map with all trees w/o any loss....
I really don't understand why there is this loss... It's just 4 damn 2D squares !
I also trid to change the texture to something with the exact size of the squares (500*500) so the app won't resize it, but no changes (I even tried to change the texture to something simply black, because my original textures are PNG with a lot of transparency, no changes)
Thank you for your help!
1