I've been trying to measure the time I take to render each frame on KOS, but sometimes I get odd results such as the start time being bigger than the end time, when using the timer_ms_gettime(); function.
My render look is written as follows :
Code: Select all
void new_draw(pDemoAssetList a)
{
// measures the time it took to render in order to keep the animation time dependent instead of frame rate dependent.
// the scene descriptor WILL get modified during the demo execution
// delete ?
struct timespec start;
struct timespec end;
struct timespec elapsed;
struct timeval start_val;
struct timeval end_val;
//
//double elapsed_val;
uint32 elapsed_time;
uint32 ms_start;
uint32 ms_end;
uint32 ms_elapsed ;
uint32 s_start;
uint32 s_end;
uint32 s_elapsed ;
timer_ms_gettime(&s_start, &ms_start);
// clock_gettime(CLOCK_REALTIME, &start);
//gettimeofday(&start_val, NULL);
//clock_t start = clock();
unsigned long total_render_time_ms ;
pDemoAssetList iter ;
p3DModelList m;
pTextureList t;
pSceneDescription d;
pCameraList c ;
pmesh curr_model ;
int curr_texture ;
int curr_texture_pos ;
iter = a ;
m = iter->m ; // model list
t = iter->t ; // texture list
d = iter->d ; // scene descriptor
c = iter->c ; // camera descriptor
float curr_transf = 0.0 ;
while(isCameraInTime(c, iter->milisec_elapsed) == 0)
{
c = c->next ; // seeks the camera in the current time frame
}
gluLookAt( c->start_pos.x,
c->start_pos.y,
c->start_pos.z,
c->start_looking_direction.x,
c->start_looking_direction.y,
c->start_looking_direction.z,
0.0,
1.0,
0.0 );
while (d != NULL) // goes trough all the meshes on the asset list
{
glPushMatrix();
glKosBeginFrame();
if(d->render_effects & DRAW_WIREFRAME)
{
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
if(d->render_effects & DRAW_FLAT)
{
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
glRotatef(d->angle, d->rotation.x, d->rotation.y, d->rotation.z );
glTranslatef(d->pos.x, d->pos.y, d->pos.z);
glScalef(d->scale.x, d->scale.y , d->scale.z );
//glRotatef(d->angle, d->rotation.x, d->rotation.y, d->rotation.z );
curr_texture_pos = getTexturePos(t, d->texture_name);
printf("texture_pos : %d \ntexture name : %s" , curr_texture_pos, d->texture_name);
curr_texture = retrieveTextureHandle(t, curr_texture_pos);
//printf("texture handle %d\n", curr_texture);
glBindTexture(GL_TEXTURE_2D, curr_texture);
curr_model = retrieveMesh (m, getMeshPos(m, d->mesh_name));
printf("mesh name \t %s\n" , d->mesh_name);
draw_p(curr_model) ;
//glKosFinishList();
glPopMatrix();
d = d -> next ; // goes to the next element
}
//printf("all meshes drawn\n");
glKosFinishFrame();
//clock_gettime(CLOCK_REALTIME, &end);
timer_ms_gettime(&s_end, &ms_end);
elapsed_time = diff_msec(ms_start, ms_end);
//printf("elapsed_t : %d ns \n", iter->milisec_elapsed);
iter->milisec_elapsed += elapsed_time;
printf("elapsed : %u ms \nstart : %u\nend : %u\n", elapsed_time, ms_start, ms_end );
printf("elapsed TOTAL: %u ms \n", iter->milisec_elapsed );
CameraListPosUpdate(iter->c, (iter->milisec_elapsed));
}
void demo_render(pDemoAssetList a)
{
while(1)
{
new_draw(a);
}
}
Code: Select all
inline unsigned long diff_msec(uint32 start,uint32 end)
{
if(end > start)
{
return (end - start);
}
else
{
return (start - end);
}
}