mirror of https://github.com/BOINC/boinc.git
frame rate throttling
svn path=/trunk/boinc/; revision=2392
This commit is contained in:
parent
be95b0e165
commit
938a303ef8
|
@ -28,6 +28,9 @@ extern DWORD WINAPI win_graphics_event_loop( LPVOID duff );
|
||||||
HANDLE graphics_threadh=NULL;
|
HANDLE graphics_threadh=NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE_CC__
|
||||||
|
#include "mac_app_opengl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
@ -37,13 +40,12 @@ HANDLE graphics_threadh=NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
|
#include "util.h"
|
||||||
#include "app_ipc.h"
|
#include "app_ipc.h"
|
||||||
#include "graphics_api.h"
|
|
||||||
#include "error_numbers.h"
|
#include "error_numbers.h"
|
||||||
|
#include "boinc_api.h"
|
||||||
|
#include "graphics_api.h"
|
||||||
|
|
||||||
#ifdef __APPLE_CC__
|
|
||||||
#include "mac_app_opengl.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HANDLE hQuitEvent;
|
HANDLE hQuitEvent;
|
||||||
|
@ -158,6 +160,61 @@ int boinc_finish_opengl() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void throttled_app_render(int x, int y, double t) {
|
||||||
|
static double total_render_time = 0;
|
||||||
|
static double time_until_render = 0;
|
||||||
|
static double last_now = 0;
|
||||||
|
static double elapsed_time = 0;
|
||||||
|
double now, t0, t1, diff, frac, m;
|
||||||
|
bool ok_to_render;
|
||||||
|
|
||||||
|
// the following should be passed in via prefs
|
||||||
|
double max_fps = 1;
|
||||||
|
double max_gfx_cpu_frac = 0.2;
|
||||||
|
|
||||||
|
ok_to_render = true;
|
||||||
|
now = dtime();
|
||||||
|
diff = now - last_now;
|
||||||
|
last_now = now;
|
||||||
|
if (diff > 1) diff = 0; // handle initial case
|
||||||
|
|
||||||
|
// enforce frames/sec restriction
|
||||||
|
//
|
||||||
|
if (max_fps) {
|
||||||
|
time_until_render -= diff;
|
||||||
|
if (time_until_render < 0) {
|
||||||
|
time_until_render += 1./max_fps;
|
||||||
|
} else {
|
||||||
|
ok_to_render = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// enforce max CPU time restriction
|
||||||
|
//
|
||||||
|
if (max_gfx_cpu_frac) {
|
||||||
|
elapsed_time += diff;
|
||||||
|
if (elapsed_time) {
|
||||||
|
frac = total_render_time/elapsed_time;
|
||||||
|
if (frac > max_gfx_cpu_frac) {
|
||||||
|
ok_to_render = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// render if allowed
|
||||||
|
//
|
||||||
|
if (ok_to_render) {
|
||||||
|
if (max_gfx_cpu_frac) {
|
||||||
|
boinc_cpu_time(t0, m);
|
||||||
|
}
|
||||||
|
app_render(x, y, t);
|
||||||
|
if (max_gfx_cpu_frac) {
|
||||||
|
boinc_cpu_time(t1, m);
|
||||||
|
total_render_time += t1 - t0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_GL_LIB
|
#ifdef HAVE_GL_LIB
|
||||||
// Custom GL "Print" Routine
|
// Custom GL "Print" Routine
|
||||||
GLvoid glPrint(GLuint font, const char *fmt, ...) {
|
GLvoid glPrint(GLuint font, const char *fmt, ...) {
|
||||||
|
|
|
@ -8,9 +8,11 @@
|
||||||
#ifndef HAVE_OPENGL_GL_H
|
#ifndef HAVE_OPENGL_GL_H
|
||||||
#define HAVE_OPENGL_GL_H
|
#define HAVE_OPENGL_GL_H
|
||||||
#endif
|
#endif
|
||||||
|
#include <Carbon/Carbon.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
#ifndef HAVE_GL_LIB
|
#ifndef HAVE_GL_LIB
|
||||||
#define HAVE_GL_LIB 1
|
#define HAVE_GL_LIB 1
|
||||||
#endif
|
#endif
|
||||||
|
@ -68,15 +70,10 @@
|
||||||
#include "x_opengl.h"
|
#include "x_opengl.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __APPLE_CC__
|
|
||||||
#include <Carbon/Carbon.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// The API (functions called by the app)
|
// The API (functions called by the app)
|
||||||
extern int boinc_init_opengl();
|
extern int boinc_init_opengl();
|
||||||
extern int boinc_finish_opengl();
|
extern int boinc_finish_opengl();
|
||||||
extern GLvoid glPrint(GLuint font, const char *fmt, ...);
|
extern GLvoid glPrint(GLuint font, const char *fmt, ...);
|
||||||
extern GLenum ReSizeGLScene(GLsizei width, GLsizei height);
|
|
||||||
|
|
||||||
// Functions that must be supplied by the app
|
// Functions that must be supplied by the app
|
||||||
//
|
//
|
||||||
|
@ -88,6 +85,7 @@ extern void app_resize(int width, int height);
|
||||||
//
|
//
|
||||||
extern GLenum InitGL(GLvoid);
|
extern GLenum InitGL(GLvoid);
|
||||||
extern GLenum ReSizeGLScene(GLsizei width, GLsizei height);
|
extern GLenum ReSizeGLScene(GLsizei width, GLsizei height);
|
||||||
|
extern void throttled_app_render(int, int, double);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
extern HANDLE hQuitEvent;
|
extern HANDLE hQuitEvent;
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
// Event loop and support functions for BOINC applications w/ graphics.
|
// Event loop and support functions for Windows versions
|
||||||
// Is any of this related to or dependent on OpenGL??
|
// of BOINC applications w/ graphics.
|
||||||
|
// Platform-independent code should NOT be here.
|
||||||
|
//
|
||||||
|
// TODO: Is any of this related to or dependent on OpenGL??
|
||||||
|
// Why not make it independent of OpenGL?
|
||||||
//
|
//
|
||||||
|
|
||||||
/* This Code Was Created By Jeff Molofee 2000
|
/* This Code Was Created By Jeff Molofee 2000
|
||||||
|
@ -137,9 +141,8 @@ void SetMode(int mode) {
|
||||||
hWnd = CreateWindowEx(dwExStyle, "BOINC_OpenGL", aid.app_name,
|
hWnd = CreateWindowEx(dwExStyle, "BOINC_OpenGL", aid.app_name,
|
||||||
dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, WindowRect.left, WindowRect.top,
|
dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, WindowRect.left, WindowRect.top,
|
||||||
WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top,
|
WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top,
|
||||||
NULL, NULL, hInstance, NULL);
|
NULL, NULL, hInstance, NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
SetForegroundWindow(hWnd);
|
SetForegroundWindow(hWnd);
|
||||||
|
|
||||||
|
@ -241,8 +244,8 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
|
||||||
}
|
}
|
||||||
if (current_graphics_mode == MODE_HIDE_GRAPHICS) return 0;
|
if (current_graphics_mode == MODE_HIDE_GRAPHICS) return 0;
|
||||||
|
|
||||||
if(dtime()-starttime>1./fps)
|
// TODO: remove width, height from API
|
||||||
{
|
//
|
||||||
GetClientRect(hWnd, &rt);
|
GetClientRect(hWnd, &rt);
|
||||||
width = rt.right-rt.left;
|
width = rt.right-rt.left;
|
||||||
height = rt.bottom-rt.top;
|
height = rt.bottom-rt.top;
|
||||||
|
@ -257,11 +260,10 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
|
||||||
}
|
}
|
||||||
vis_render(width,height,dtime(),data,data_size);
|
vis_render(width,height,dtime(),data,data_size);
|
||||||
#else
|
#else
|
||||||
app_render(width, height, dtime());
|
throttled_app_render(width, height, dtime());
|
||||||
#endif
|
#endif
|
||||||
starttime=dtime();
|
starttime=dtime();
|
||||||
SwapBuffers(hDC);
|
SwapBuffers(hDC);
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue