mirror of https://github.com/BOINC/boinc.git
parent
fa8713feb4
commit
6fab589545
|
@ -18,6 +18,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
// Code that's in the BOINC app library (but NOT in the core client)
|
// Code that's in the BOINC app library (but NOT in the core client)
|
||||||
|
// graphics-related code goes in graphics_api.C, not here
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -44,17 +45,6 @@ MMRESULT timer_id;
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#ifdef BOINC_APP_GRAPHICS
|
|
||||||
#ifdef _WIN32
|
|
||||||
HANDLE hQuitEvent;
|
|
||||||
extern HANDLE graphics_threadh;
|
|
||||||
extern BOOL win_loop_done;
|
|
||||||
#endif
|
|
||||||
#ifdef __APPLE_CC__
|
|
||||||
#include <Carbon/Carbon.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
#include "shmem.h"
|
#include "shmem.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -72,7 +62,6 @@ extern void boinc_quit(int sig);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static APP_INIT_DATA aid;
|
static APP_INIT_DATA aid;
|
||||||
GRAPHICS_INFO gi;
|
|
||||||
static double timer_period = 1.0/50.0; // 50 Hz timer
|
static double timer_period = 1.0/50.0; // 50 Hz timer
|
||||||
static double time_until_checkpoint;
|
static double time_until_checkpoint;
|
||||||
static double time_until_fraction_done_update;
|
static double time_until_fraction_done_update;
|
||||||
|
@ -131,22 +120,6 @@ int boinc_init(bool standalone_ /* = false */) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f = fopen(GRAPHICS_DATA_FILE, "r");
|
|
||||||
if (!f) {
|
|
||||||
fprintf(stderr, "boinc_init(): can't open graphics data file\n");
|
|
||||||
fprintf(stderr, "Using default graphics settings.\n");
|
|
||||||
gi.refresh_period = 0.1; // 1/10th of a second
|
|
||||||
gi.xsize = 640;
|
|
||||||
gi.ysize = 480;
|
|
||||||
} else {
|
|
||||||
retval = parse_graphics_file(f, &gi);
|
|
||||||
if (retval) {
|
|
||||||
fprintf(stderr, "boinc_init(): can't parse graphics data file\n");
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
f = fopen(FD_INIT_FILE, "r");
|
f = fopen(FD_INIT_FILE, "r");
|
||||||
if (f) {
|
if (f) {
|
||||||
parse_fd_init_file(f);
|
parse_fd_init_file(f);
|
||||||
|
@ -269,15 +242,7 @@ int boinc_finish(int status) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// Stop the timer
|
// Stop the timer
|
||||||
timeKillEvent(timer_id);
|
timeKillEvent(timer_id);
|
||||||
#ifdef BOINC_APP_GRAPHICS
|
boinc_finish_opengl();
|
||||||
if (using_opengl) {
|
|
||||||
// If the graphics thread is running, tell it to quit and wait for it
|
|
||||||
win_loop_done = TRUE;
|
|
||||||
if (hQuitEvent != NULL) {
|
|
||||||
WaitForSingleObject(hQuitEvent, 1000); // Wait up to 1000 ms
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
cleanup_shared_mem();
|
cleanup_shared_mem();
|
||||||
exit(status);
|
exit(status);
|
||||||
|
@ -447,10 +412,13 @@ void on_timer(int a) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// ???? shouldn't have graphics-related stuff here
|
||||||
#if defined __APPLE_CC__ && defined BOINC_APP_GRAPHICS
|
#if defined __APPLE_CC__ && defined BOINC_APP_GRAPHICS
|
||||||
// Yield to the graphics thread to let it draw if needed
|
// Yield to the graphics thread to let it draw if needed
|
||||||
YieldToAnyThread();
|
YieldToAnyThread();
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -470,16 +438,6 @@ int set_timer(double period) {
|
||||||
);
|
);
|
||||||
sprintf(buf, "%s%s", QUIT_PREFIX, aid.comm_obj_name);
|
sprintf(buf, "%s%s", QUIT_PREFIX, aid.comm_obj_name);
|
||||||
hQuitRequest = OpenEvent(EVENT_ALL_ACCESS, FALSE, buf);
|
hQuitRequest = OpenEvent(EVENT_ALL_ACCESS, FALSE, buf);
|
||||||
#ifdef BOINC_APP_GRAPHICS
|
|
||||||
// Create the event object used to signal between the
|
|
||||||
// worker and event threads
|
|
||||||
|
|
||||||
hQuitEvent = CreateEvent(
|
|
||||||
NULL, // no security attributes
|
|
||||||
TRUE, // manual reset event
|
|
||||||
TRUE, // initial state is signaled
|
|
||||||
NULL); // object not named
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_SIGNAL_H
|
#if HAVE_SIGNAL_H
|
||||||
|
|
|
@ -22,32 +22,65 @@
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <afxwin.h>
|
#include <afxwin.h>
|
||||||
DWORD WINAPI win_graphics_event_loop( LPVOID duff );
|
extern DWORD WINAPI win_graphics_event_loop( LPVOID duff );
|
||||||
HANDLE graphics_threadh=NULL;
|
HANDLE graphics_threadh=NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "graphics_api.h"
|
|
||||||
#include "error_numbers.h"
|
|
||||||
|
|
||||||
#include "parse.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#ifdef __APPLE_CC__
|
|
||||||
#include "mac_app_opengl.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_PTHREAD
|
#ifdef HAVE_PTHREAD
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern GRAPHICS_INFO gi;
|
#define HAVE_GL_LIB 1
|
||||||
|
|
||||||
|
#include "parse.h"
|
||||||
|
#include "app_ipc.h"
|
||||||
|
#include "graphics_api.h"
|
||||||
|
#include "error_numbers.h"
|
||||||
|
|
||||||
|
#ifdef __APPLE_CC__
|
||||||
|
#include "mac_app_opengl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GRAPHICS_INFO gi;
|
||||||
|
bool graphics_inited = false;
|
||||||
|
|
||||||
int boinc_init_opengl() {
|
int boinc_init_opengl() {
|
||||||
#ifdef BOINC_APP_GRAPHICS
|
FILE* f;
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
f = fopen(GRAPHICS_DATA_FILE, "r");
|
||||||
|
if (!f) {
|
||||||
|
fprintf(stderr, "boinc_init(): can't open graphics data file\n");
|
||||||
|
fprintf(stderr, "Using default graphics settings.\n");
|
||||||
|
gi.refresh_period = 0.1; // 1/10th of a second
|
||||||
|
gi.xsize = 640;
|
||||||
|
gi.ysize = 480;
|
||||||
|
} else {
|
||||||
|
retval = parse_graphics_file(f, &gi);
|
||||||
|
if (retval) {
|
||||||
|
fprintf(stderr, "boinc_init(): can't parse graphics data file\n");
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
// Create the event object used to signal between the
|
||||||
|
// worker and event threads
|
||||||
|
|
||||||
|
hQuitEvent = CreateEvent(
|
||||||
|
NULL, // no security attributes
|
||||||
|
TRUE, // manual reset event
|
||||||
|
TRUE, // initial state is signaled
|
||||||
|
NULL // object not named
|
||||||
|
);
|
||||||
|
|
||||||
DWORD threadId;
|
DWORD threadId;
|
||||||
|
|
||||||
// Create the graphics thread, passing it the graphics info
|
// Create the graphics thread, passing it the graphics info
|
||||||
|
@ -94,7 +127,6 @@ int boinc_init_opengl() {
|
||||||
#ifdef _PTHREAD_H
|
#ifdef _PTHREAD_H
|
||||||
pthread_t graphics_thread;
|
pthread_t graphics_thread;
|
||||||
pthread_attr_t graphics_thread_attr;
|
pthread_attr_t graphics_thread_attr;
|
||||||
int retval;
|
|
||||||
|
|
||||||
pthread_attr_init( &graphics_thread_attr );
|
pthread_attr_init( &graphics_thread_attr );
|
||||||
retval = pthread_create( &graphics_thread, &graphics_thread_attr, p_graphics_loop, &gi );
|
retval = pthread_create( &graphics_thread, &graphics_thread_attr, p_graphics_loop, &gi );
|
||||||
|
@ -102,18 +134,23 @@ int boinc_init_opengl() {
|
||||||
pthread_attr_destroy( &graphics_thread_attr );
|
pthread_attr_destroy( &graphics_thread_attr );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
graphics_inited = true;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int boinc_finish_opengl() {
|
int boinc_finish_opengl() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (graphics_inited) {
|
||||||
|
win_loop_done = TRUE;
|
||||||
|
if (hQuitEvent != NULL) {
|
||||||
|
WaitForSingleObject(hQuitEvent, 1000); // Wait up to 1000 ms
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BOINC_APP_GRAPHICS
|
|
||||||
|
|
||||||
GLvoid glPrint(GLuint font, const char *fmt, ...) // Custom GL "Print" Routine
|
GLvoid glPrint(GLuint font, const char *fmt, ...) // Custom GL "Print" Routine
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -138,43 +175,52 @@ GLenum InitGL(GLvoid) { // All Setup For OpenGL Goes Here
|
||||||
GLenum err;
|
GLenum err;
|
||||||
|
|
||||||
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
|
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
|
||||||
if (err=glGetError()) return err;
|
err = glGetError();
|
||||||
|
if (err) return err;
|
||||||
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
|
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
|
||||||
if (err=glGetError()) return err;
|
err = glGetError();
|
||||||
|
if (err) return err;
|
||||||
|
|
||||||
glClearDepth(1.0f); // Depth Buffer Setup
|
glClearDepth(1.0f); // Depth Buffer Setup
|
||||||
if (err=glGetError()) return err;
|
err = glGetError();
|
||||||
|
if (err) return err;
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
|
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
|
||||||
if (err=glGetError()) return err;
|
err = glGetError();
|
||||||
|
if (err) return err;
|
||||||
|
|
||||||
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
|
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
|
||||||
if (err=glGetError()) return err;
|
err = glGetError();
|
||||||
|
if (err) return err;
|
||||||
|
|
||||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
|
||||||
if (err=glGetError()) return err;
|
err = glGetError();
|
||||||
|
if (err) return err;
|
||||||
|
|
||||||
|
|
||||||
return GL_NO_ERROR; // Initialization Went OK
|
return GL_NO_ERROR; // Initialization Went OK
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum ReSizeGLScene(GLsizei width, GLsizei height) { // Resize And Initialize The GL Window
|
// Resize And Initialize The GL Window
|
||||||
|
// TODO: why is 4/3 hardwired here?
|
||||||
|
GLenum ReSizeGLScene(GLsizei width, GLsizei height) {
|
||||||
GLenum err;
|
GLenum err;
|
||||||
double aspect_ratio = 4.0/3.0;
|
double aspect_ratio = 4.0/3.0;
|
||||||
|
|
||||||
if (height<=0) height=1; // Prevent A Divide By Zero By Making Height Equal One
|
if (height<=0) height=1;
|
||||||
if (width<=0) width=1;
|
if (width<=0) width=1;
|
||||||
|
|
||||||
if (height*aspect_ratio > width)
|
if (height*aspect_ratio > width) {
|
||||||
glViewport(0,0,(int)width,(int)(width/aspect_ratio)); // Reset The Current Viewport
|
glViewport(0,0,(int)width,(int)(width/aspect_ratio));
|
||||||
else
|
} else {
|
||||||
glViewport(0,0,(int)(height*aspect_ratio),(height)); // Reset The Current Viewport
|
glViewport(0,0,(int)(height*aspect_ratio),(height));
|
||||||
|
}
|
||||||
|
|
||||||
if (err=glGetError()) return err;
|
err = glGetError();
|
||||||
|
if (err) return err;
|
||||||
|
|
||||||
app_resize(width,height);
|
app_resize(width,height);
|
||||||
|
|
||||||
return GL_NO_ERROR;
|
return GL_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#ifndef BOINC_GRAPHICS_API_H
|
#ifndef BOINC_GRAPHICS_API_H
|
||||||
#define BOINC_GRAPHICS_API_H
|
#define BOINC_GRAPHICS_API_H
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#ifdef BOINC_APP_GRAPHICS
|
|
||||||
#ifdef __APPLE_CC__
|
#ifdef __APPLE_CC__
|
||||||
#include <OpenGL/gl.h>
|
#include <OpenGL/gl.h>
|
||||||
|
#include <Carbon/Carbon.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -19,23 +17,21 @@
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include "x_opengl.h"
|
#include "x_opengl.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
extern HANDLE hQuitEvent;
|
||||||
|
extern HANDLE graphics_threadh;
|
||||||
|
extern BOOL win_loop_done;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "app_ipc.h"
|
extern int boinc_init_opengl();
|
||||||
|
extern int boinc_finish_opengl();
|
||||||
|
|
||||||
struct APP_OUT_GRAPHICS {
|
extern GLvoid glPrint(GLuint font, const char *fmt, ...);
|
||||||
};
|
extern GLenum InitGL(GLvoid);
|
||||||
|
extern GLenum ReSizeGLScene(GLsizei width, GLsizei height);
|
||||||
int boinc_init_opengl();
|
|
||||||
int boinc_finish_opengl();
|
|
||||||
|
|
||||||
#ifdef BOINC_APP_GRAPHICS
|
|
||||||
GLvoid glPrint(GLuint font, const char *fmt, ...);
|
|
||||||
GLenum InitGL(GLvoid);
|
|
||||||
GLenum ReSizeGLScene(GLsizei width, GLsizei height);
|
|
||||||
extern bool app_render(int xs, int ys, double time_of_day);
|
extern bool app_render(int xs, int ys, double time_of_day);
|
||||||
extern void app_init_gl(void);
|
extern void app_init_gl(void);
|
||||||
extern void app_resize(int width, int height);
|
extern void app_resize(int width, int height);
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
// Event loop and support functions for BOINC applications w/ graphics.
|
||||||
|
// Is any of this related to or dependent on OpenGL??
|
||||||
|
//
|
||||||
|
|
||||||
/* This Code Was Created By Jeff Molofee 2000
|
/* This Code Was Created By Jeff Molofee 2000
|
||||||
* A HUGE Thanks To Fredric Echols For Cleaning Up
|
* A HUGE Thanks To Fredric Echols For Cleaning Up
|
||||||
|
@ -57,7 +60,6 @@ double starttime;
|
||||||
double fps=60.;
|
double fps=60.;
|
||||||
|
|
||||||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
|
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
|
||||||
DWORD WINAPI win_graphics_event_loop( LPVOID duff );
|
|
||||||
BOOL reg_win_class();
|
BOOL reg_win_class();
|
||||||
BOOL unreg_win_class();
|
BOOL unreg_win_class();
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
void *p_graphics_loop( void * );
|
extern void *p_graphics_loop( void * );
|
||||||
|
|
||||||
|
|
|
@ -53,12 +53,12 @@
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "graphics_api.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "filesys.h"
|
#include "filesys.h"
|
||||||
#include "boinc_api.h"
|
#include "boinc_api.h"
|
||||||
#include "graphics_api.h"
|
|
||||||
|
|
||||||
#define CHECKPOINT_FILE "upper_case_state"
|
#define CHECKPOINT_FILE "upper_case_state"
|
||||||
|
|
||||||
|
|
|
@ -6427,3 +6427,16 @@ David Sept 30 2003
|
||||||
pers_file_xfer.C
|
pers_file_xfer.C
|
||||||
lib/
|
lib/
|
||||||
error_numbers.h
|
error_numbers.h
|
||||||
|
|
||||||
|
|
||||||
|
David Sept 30 2003
|
||||||
|
- Move graphics-related code from boinc_api.C to graphics_api.C
|
||||||
|
- Don't use the preprocessor symbol BOINC_APP_GRAPHICS in api/
|
||||||
|
|
||||||
|
api/
|
||||||
|
boinc_api.C
|
||||||
|
graphics_api.C,h
|
||||||
|
windows_opengl.C
|
||||||
|
x_opengl.h
|
||||||
|
apps/
|
||||||
|
upper_case.C
|
||||||
|
|
Loading…
Reference in New Issue