把這個功能讓時間的雙重使用clock_gettime:着色時間統一 - clock_gettime被截斷
// return current time in milliseconds
static double time_get_ms(void)
{
struct timespec res;
#ifdef ANDROID
clock_gettime(CLOCK_REALTIME_HR, &res);
#else
clock_gettime(CLOCK_REALTIME, &res);
#endif
return (double)(1000.0*res.tv_sec + res.tv_nsec/1e6);
}
其發送到着色器需要轉換爲浮動。尾數正在溢出,並在到着色器的路上被截斷。
實施例:
作爲雙= 1330579093642.441895
作爲浮子= 1330579111936.000000
的浮點值被卡住在用於長時間的單個數字,由於截斷。
它似乎甚至res.tv_sec秒的值是一個大的浮點數,它也被截斷到GPU的路上。
嘗試測量應用程序啓動以來的時間,並且我很快遇到了同樣的問題。
那麼,什麼是獲得運行時間值到着色器的最佳方式?在Linux世界中有一些跨平臺的東西(如IOS,Android,Linux)。