Browse Source

Display render infos

Godzil 3 years ago
parent
commit
7ad63967b5
1 changed files with 25 additions and 6 deletions
  1. 25 6
      source/main.c

+ 25 - 6
source/main.c

@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <libc.h>
 
 #include <SDL.h>
 
@@ -37,7 +38,7 @@ bool doNotCull = false;
 enum displayMode_t currentDisplayMode = DISPLAY_MODE_SOLID;
 matrix4_t projectionMatrix;
 light_t globalLight;
-
+double updateTime, renderTime, waitTime;
 
 vec3_t cameraPosition =
 {
@@ -132,18 +133,30 @@ void processInput()
 
 }
 
+uint32_t getMicroSecTime()
+{
+    struct timeval curTime;
+    gettimeofday(&curTime, NULL);
+    return ((curTime.tv_sec) * 1000 * 1000) + (curTime.tv_usec);
+}
+
 void update()
 {
     uint32_t i, j;
     uint32_t faceCount;
     uint32_t timeToWait = FRAME_TARGET_TIME - (SDL_GetTicks() - previousFrameTime);
     matrix4_t worldMatrix;
+    uint32_t ticks = getMicroSecTime();
+
     if (timeToWait <= FRAME_TARGET_TIME)
     {
         SDL_Delay(timeToWait);
     }
     previousFrameTime = SDL_GetTicks();
 
+    waitTime = (waitTime + (getMicroSecTime() - ticks) / 1000.) / 2.0;
+    ticks = getMicroSecTime();
+
     mesh.rotation.x += 0.001;
     mesh.translation.z = 5;
 
@@ -231,15 +244,18 @@ void update()
           arrayGetSize(projectedTriangles),
           sizeof(triangle_t),
           compareTrianglesZOrder);
+
+    updateTime = (updateTime + (getMicroSecTime() - ticks) / 1000.) / 2.0;
 }
 
 void render()
 {
     int i;
+    uint32_t ticks = getMicroSecTime();
+
     SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
     SDL_RenderClear(renderer);
 
-#if 1
     int triangleCount = arrayGetSize(projectedTriangles);
 
     for(i = 0; i < triangleCount; i++)
@@ -285,13 +301,16 @@ void render()
         }
 
     }
-#else
-    drawTriangle(300, 100, 50, 400, 500, 700, 0xFF00FF00);
-    drawFilledTriangle(300, 100, 50, 400, 500, 700, 0xFFFF0000);
-#endif
+
     renderFrameBuffer();
     clearFrameBuffer(0xFF000000);
 
+    renderTime = (renderTime + (getMicroSecTime() - ticks) / 1000.) / 2.0;
+
+    drawText(5, 5, 0x11FF22, "Wait time: %02.2f ms", waitTime);
+    drawText(5, 17, 0x11FF22, "Update time: %02.2f ms", updateTime);
+    drawText(5, 29, 0x11FF22, "Render time: %02.2f ms", renderTime);
+    drawText(5, 41, 0x11FF22, "FPS: %.2f", 1000 / (waitTime + updateTime + renderTime));
     SDL_RenderPresent(renderer);
 }