PShape/VBO + Textures = slowness
in
Programming Questions
•
9 months ago
Hi all,
I'm trying to optimize my game using retained mode, i.e.drawing a lot of my geometry using PShapes, which I understand are implemented as VBOs in Processing 2.x. Before this I was drawing a quad-based heightmap terrain in immediate mode, within which some of the quads (tiles) are differently textured. I found that it was really slow when it had to switch between textures from tile to tile, so I thought maybe moving to using blocks of PShapes to draw the terrain would be faster. Unfortunately using textures with the PShape is a lot slower. Here's the code that generates a block of textured terrain:
void createGroundVBOModel()
{
terrainModel = createShape(GROUP);
for(int i =0; i < numGroundQuads-2; i++)
for(int j =0; j < numGroundQuads-2; j++)
if(true) //ignore this, it will be used for checking frustum culling later
{
PShape thisShape = createShape();
Quad quad = terrainQuads.get(i + j*(numGroundQuads-1));
//if it's bitgrass, get the right tile
PImage bitGrassTex;
bitGrassTex = getShoreQuadTexFromTileset(i, j, bitGrass);
//bitGrassTex = blackWater;
thisShape.texture(bitGrassTex);
//if all four verts of this quad are at sea level then texture this is sea
if(quad.isWater)
{
thisShape.texture(blackWater);
}
thisShape.noFill();
thisShape.noStroke();
thisShape.vertex(quad.tvert1.x,quad.tvert1.y, quad.tvert1.z, 0, 0);
thisShape.vertex(quad.tvert2.x, quad.tvert2.y, quad.tvert2.z, 64, 0);
thisShape.vertex(quad.tvert3.x, quad.tvert3.y, quad.tvert3.z, 64, 64);
thisShape.vertex(quad.tvert4.x, quad.tvert4.y, quad.tvert4.z, 0, 64);
thisShape.end();
terrainModel.addChild(thisShape);
}
// terrainModel.end();
}
I then simply call shape(terrainModel); in my draw function (amongst a lot of other things related to the camera movement).
Any idea why this would happen?
Thanks a lot!
I'm trying to optimize my game using retained mode, i.e.drawing a lot of my geometry using PShapes, which I understand are implemented as VBOs in Processing 2.x. Before this I was drawing a quad-based heightmap terrain in immediate mode, within which some of the quads (tiles) are differently textured. I found that it was really slow when it had to switch between textures from tile to tile, so I thought maybe moving to using blocks of PShapes to draw the terrain would be faster. Unfortunately using textures with the PShape is a lot slower. Here's the code that generates a block of textured terrain:
void createGroundVBOModel()
{
terrainModel = createShape(GROUP);
for(int i =0; i < numGroundQuads-2; i++)
for(int j =0; j < numGroundQuads-2; j++)
if(true) //ignore this, it will be used for checking frustum culling later
{
PShape thisShape = createShape();
Quad quad = terrainQuads.get(i + j*(numGroundQuads-1));
//if it's bitgrass, get the right tile
PImage bitGrassTex;
bitGrassTex = getShoreQuadTexFromTileset(i, j, bitGrass);
//bitGrassTex = blackWater;
thisShape.texture(bitGrassTex);
//if all four verts of this quad are at sea level then texture this is sea
if(quad.isWater)
{
thisShape.texture(blackWater);
}
thisShape.noFill();
thisShape.noStroke();
thisShape.vertex(quad.tvert1.x,quad.tvert1.y, quad.tvert1.z, 0, 0);
thisShape.vertex(quad.tvert2.x, quad.tvert2.y, quad.tvert2.z, 64, 0);
thisShape.vertex(quad.tvert3.x, quad.tvert3.y, quad.tvert3.z, 64, 64);
thisShape.vertex(quad.tvert4.x, quad.tvert4.y, quad.tvert4.z, 0, 64);
thisShape.end();
terrainModel.addChild(thisShape);
}
// terrainModel.end();
}
I then simply call shape(terrainModel); in my draw function (amongst a lot of other things related to the camera movement).
Any idea why this would happen?
Thanks a lot!
1