mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-10 00:28:20 +00:00
[client] opengl: show actual FPS seperate from updates per second (UPS)
This commit is contained in:
parent
7d307c0a9c
commit
8b25f8a344
@ -90,6 +90,7 @@ struct LGR_OpenGLBasic
|
||||
uint64_t lastFrameTime;
|
||||
uint64_t renderTime;
|
||||
uint64_t frameCount;
|
||||
uint64_t renderCount;
|
||||
SDL_Rect fpsRect;
|
||||
|
||||
bool mouseUpdate;
|
||||
@ -506,8 +507,9 @@ bool lgr_opengl_basic_on_frame_event(void * opaque, const uint8_t * data)
|
||||
if (this->params.showFPS && this->renderTime > 1e9)
|
||||
{
|
||||
char str[128];
|
||||
const float avgFPS = 1000.0f / (((float)this->renderTime / this->frameCount) / 1e6f);
|
||||
snprintf(str, sizeof(str), "FPS: %8.4f", avgFPS);
|
||||
const float avgFPS = 1000.0f / (((float)this->renderTime / this->frameCount ) / 1e6f);
|
||||
const float renderFPS = 1000.0f / (((float)this->renderTime / this->renderCount) / 1e6f);
|
||||
snprintf(str, sizeof(str), "UPS: %8.4f, FPS: %8.4f", avgFPS, renderFPS);
|
||||
SDL_Color color = {0xff, 0xff, 0xff};
|
||||
SDL_Surface *textSurface = NULL;
|
||||
if (!(textSurface = TTF_RenderText_Blended(this->params.font, str, color)))
|
||||
@ -545,9 +547,10 @@ bool lgr_opengl_basic_on_frame_event(void * opaque, const uint8_t * data)
|
||||
|
||||
SDL_FreeSurface(textSurface);
|
||||
|
||||
this->renderTime = 0;
|
||||
this->frameCount = 0;
|
||||
this->fpsTexture = true;
|
||||
this->renderTime = 0;
|
||||
this->frameCount = 0;
|
||||
this->renderCount = 0;
|
||||
this->fpsTexture = true;
|
||||
|
||||
glNewList(this->fpsList, GL_COMPILE);
|
||||
glEnable(GL_BLEND);
|
||||
@ -613,6 +616,7 @@ bool lgr_opengl_basic_on_frame_event(void * opaque, const uint8_t * data)
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
++this->frameCount;
|
||||
this->frameUpdate = true;
|
||||
return true;
|
||||
}
|
||||
@ -716,10 +720,10 @@ bool lgr_opengl_basic_render(void * opaque)
|
||||
else
|
||||
SDL_GL_SwapWindow(this->sdlWindow);
|
||||
|
||||
++this->frameCount;
|
||||
const uint64_t t = nanotime();
|
||||
this->renderTime += t - this->lastFrameTime;
|
||||
this->lastFrameTime = t;
|
||||
++this->renderCount;
|
||||
|
||||
this->frameUpdate = false;
|
||||
this->mouseUpdate = false;
|
||||
|
@ -96,6 +96,7 @@ struct LGR_OpenGL
|
||||
uint64_t lastFrameTime;
|
||||
uint64_t renderTime;
|
||||
uint64_t frameCount;
|
||||
uint64_t renderCount;
|
||||
SDL_Rect fpsRect;
|
||||
|
||||
bool mouseUpdate;
|
||||
@ -559,8 +560,9 @@ bool lgr_opengl_on_frame_event(void * opaque, const uint8_t * data)
|
||||
if (this->params.showFPS && this->renderTime > 1e9)
|
||||
{
|
||||
char str[128];
|
||||
const float avgFPS = 1000.0f / (((float)this->renderTime / this->frameCount) / 1e6f);
|
||||
snprintf(str, sizeof(str), "FPS: %8.4f", avgFPS);
|
||||
const float avgFPS = 1000.0f / (((float)this->renderTime / this->frameCount ) / 1e6f);
|
||||
const float renderFPS = 1000.0f / (((float)this->renderTime / this->renderCount) / 1e6f);
|
||||
snprintf(str, sizeof(str), "UPS: %8.4f, FPS: %8.4f", avgFPS, renderFPS);
|
||||
SDL_Color color = {0xff, 0xff, 0xff};
|
||||
SDL_Surface *textSurface = NULL;
|
||||
if (!(textSurface = TTF_RenderText_Blended(this->params.font, str, color)))
|
||||
@ -598,9 +600,10 @@ bool lgr_opengl_on_frame_event(void * opaque, const uint8_t * data)
|
||||
|
||||
SDL_FreeSurface(textSurface);
|
||||
|
||||
this->renderTime = 0;
|
||||
this->frameCount = 0;
|
||||
this->fpsTexture = true;
|
||||
this->renderTime = 0;
|
||||
this->frameCount = 0;
|
||||
this->renderCount = 0;
|
||||
this->fpsTexture = true;
|
||||
|
||||
glNewList(this->fpsList, GL_COMPILE);
|
||||
glEnable(GL_BLEND);
|
||||
@ -678,6 +681,7 @@ bool lgr_opengl_on_frame_event(void * opaque, const uint8_t * data)
|
||||
if (++this->texIndex == BUFFER_COUNT)
|
||||
this->texIndex = 0;
|
||||
|
||||
++this->frameCount;
|
||||
this->frameUpdate = true;
|
||||
return true;
|
||||
}
|
||||
@ -780,10 +784,10 @@ bool lgr_opengl_render(void * opaque)
|
||||
else
|
||||
SDL_GL_SwapWindow(this->sdlWindow);
|
||||
|
||||
++this->frameCount;
|
||||
const uint64_t t = nanotime();
|
||||
this->renderTime += t - this->lastFrameTime;
|
||||
this->lastFrameTime = t;
|
||||
++this->renderCount;
|
||||
|
||||
this->frameUpdate = false;
|
||||
this->mouseUpdate = false;
|
||||
|
Loading…
Reference in New Issue
Block a user