I'm trying to display multiple sprites on the screen, between 200 and 400 per frame, I am using the PVR API, I think it is able to do that, but I am getting some serious slowdown, here is how works my game.
Code: Select all
int main()
{
initMyGame();
while(1)
{
UpdateMyGame();
ScreenFlip();
}
}
Code: Select all
void PVR_VblankStart()
{
pvr_wait_ready();
pvr_scene_begin();
pvr_list_begin(PVR_LIST_TR_POLY);
}
void PVR_VblankEnd()
{
pvr_list_finish();
pvr_scene_finish();
}
void ScreenFlip()
{
PVR_VblankStart();
for(std::size_t i=0; i < spritesPVR_counter; ++i) //here spritesPVR_counter is between 200 and 400
{
pvr_poly_hdr_t hdr;
pvr_poly_cxt_t cxt;
pvr_vertex_t vert;
if(spritesPVR[i].tex == 255) //for Rectangle, Line
{
pvr_poly_cxt_col(&cxt, PVR_LIST_TR_POLY);
if(spritesPVR[i].isAddBlend)
{
cxt.blend.src = PVR_BLEND_ONE;
cxt.blend.dst = PVR_BLEND_ONE;
}
pvr_poly_compile(&hdr, &cxt);
}
else //for texture
{
pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444 | PVR_TXRFMT_TWIDDLED | PVR_TXRFMT_VQ_ENABLE, 1024, 1024, myTexture[spritesPVR[i].tex], PVR_FILTER_BILINEAR);
if(spritesPVR[i].isAddBlend)
{
cxt.blend.src = PVR_BLEND_ONE;
cxt.blend.dst = PVR_BLEND_ONE;
}
pvr_poly_compile(&hdr, &cxt);
}
pvr_prim(&hdr, sizeof(hdr));
vert.argb = PVR_PACK_COLOR(spritesPVR[i].argb.alpha, spritesPVR[i].argb.red, spritesPVR[i].argb.green, spritesPVR[i].argb.blue);
vert.oargb = 0;
vert.flags = PVR_CMD_VERTEX;
vert.x = spritesPVR[i].topleft.x;
vert.y = spritesPVR[i].topleft.y;
vert.z = spritesPVR[i].z;
vert.u = spritesPVR[i].uvtopleft.u;
vert.v = spritesPVR[i].uvtopleft.v;
pvr_prim(&vert, sizeof(vert));
vert.x = spritesPVR[i].topright.x;
vert.y = spritesPVR[i].topright.y;
vert.z = spritesPVR[i].z;
vert.u = spritesPVR[i].uvtopright.u;
vert.v = spritesPVR[i].uvtopright.v;
pvr_prim(&vert, sizeof(vert));
vert.x = spritesPVR[i].bottomleft.x;
vert.y = spritesPVR[i].bottomleft.y;
vert.z = spritesPVR[i].z;
vert.u = spritesPVR[i].uvbottomleft.u;
vert.v = spritesPVR[i].uvbottomleft.v;
pvr_prim(&vert, sizeof(vert));
vert.x = spritesPVR[i].bottomright.x;
vert.y = spritesPVR[i].bottomright.y;
vert.z = spritesPVR[i].z;
vert.u = spritesPVR[i].uvbottomright.u;
vert.v = spritesPVR[i].uvbottomright.v;
vert.flags = PVR_CMD_VERTEX_EOL;
pvr_prim(&vert, sizeof(vert));
}
for(std::size_t j = 0; j < stringPVR.size(); ++j)
{
fontPos.z = stringPVR[j].z;
fontPos.x = (float)stringPVR[j].x;
fontPos.y = (float)stringPVR[j].y;
plx_fcxt_begin(fontCxtAX);
plx_fcxt_setsize(fontCxtAX, (float)stringPVR[j].fontSize);
plx_fcxt_setcolor4f(fontCxtAX, 1.0f, ((float)stringPVR[j].color.r)/255.0f, ((float)stringPVR[j].color.g)/255.0f, ((float)stringPVR[j].color.b)/255.0f);
plx_fcxt_setpos_pnt(fontCxtAX, &fontPos);
plx_fcxt_draw(fontCxtAX, stringPVR[j].strblit.c_str());
plx_fcxt_end(fontCxtAX);
}
PVR_VblankEnd();
}
Code: Select all
pvr_init_params_t init = {{ PVR_BINSIZE_0, PVR_BINSIZE_0, PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_0},512*1024, 0, 0};
pvr_init(&init);
The update of my game is in time, maximum 4ms
On the other hand my Screenflip goes above 17ms often
(I specify that I am looking at milliseconds with NullDC, because I don't have a coder cable )
I'm sure I'm missing something in ScreenFlip, too many poly_compile calls?
Too much data transfer?
Too many sprites?
I tested various things already like for exemple reducing poly_compile and poly_cxt_txr
but that doesn't seem to change much
Anyone have an idea of a mistake I made? Or is the dreamcast not powerful enough?
Thank you in advance for your help!