2002-09-26 18:11:06 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-11-01 18:59:18 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <afxwin.h>
|
|
|
|
DWORD WINAPI win_graphics_event_loop( LPVOID duff );
|
2002-11-14 00:49:24 +00:00
|
|
|
HANDLE graphics_threadh=NULL;
|
2002-11-01 18:59:18 +00:00
|
|
|
#endif
|
|
|
|
|
2002-10-31 00:13:50 +00:00
|
|
|
#ifdef BOINC_APP_GRAPHICS
|
|
|
|
#ifdef __APPLE_CC__
|
|
|
|
#include <OpenGL/gl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <gl\gl.h> // Header File For The OpenGL32 Library
|
|
|
|
#include <gl\glu.h> // Header File For The GLu32 Library
|
|
|
|
#include <gl\glaux.h> // Header File For The Glaux Library
|
|
|
|
#endif
|
2002-11-12 20:59:00 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_GL_LIB
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#include "x_opengl.h"
|
|
|
|
#endif
|
2002-10-31 00:13:50 +00:00
|
|
|
#endif
|
|
|
|
|
2002-08-09 21:43:59 +00:00
|
|
|
#include "graphics_api.h"
|
2002-09-17 21:54:59 +00:00
|
|
|
#include "error_numbers.h"
|
2002-08-09 21:43:59 +00:00
|
|
|
|
|
|
|
#include "parse.h"
|
|
|
|
|
2002-11-12 20:59:00 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2002-09-18 21:15:23 +00:00
|
|
|
#ifdef __APPLE_CC__
|
2002-10-29 18:51:45 +00:00
|
|
|
#include "mac_app_opengl.h"
|
2002-09-18 21:15:23 +00:00
|
|
|
#endif
|
|
|
|
|
2002-11-12 20:59:00 +00:00
|
|
|
#ifdef HAVE_PTHREAD
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
|
2002-09-18 21:15:23 +00:00
|
|
|
extern GRAPHICS_INFO gi;
|
|
|
|
|
|
|
|
int boinc_init_opengl() {
|
|
|
|
#ifdef BOINC_APP_GRAPHICS
|
2002-09-18 22:15:49 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
DWORD threadId;
|
|
|
|
|
|
|
|
// Create the graphics thread, passing it the graphics info
|
2002-11-12 20:59:00 +00:00
|
|
|
// TODO: is it better to use _beginthreadex here?
|
2002-11-14 00:49:24 +00:00
|
|
|
graphics_threadh = CreateThread(
|
2002-10-06 00:43:55 +00:00
|
|
|
NULL, 0, win_graphics_event_loop, &gi, CREATE_SUSPENDED, &threadId
|
|
|
|
);
|
2002-09-18 22:15:49 +00:00
|
|
|
|
|
|
|
// Set it to idle priority
|
2002-11-14 00:49:24 +00:00
|
|
|
SetThreadPriority(graphics_threadh, THREAD_PRIORITY_HIGHEST);
|
2002-09-18 22:15:49 +00:00
|
|
|
|
|
|
|
// Start the graphics thread
|
2002-11-14 00:49:24 +00:00
|
|
|
ResumeThread(graphics_threadh);
|
2002-09-18 22:15:49 +00:00
|
|
|
#endif
|
|
|
|
|
2002-09-18 21:15:23 +00:00
|
|
|
#ifdef __APPLE_CC__
|
|
|
|
OSErr theErr = noErr;
|
|
|
|
ThreadID graphicsThreadID = 0;
|
|
|
|
ThreadEntryUPP entry_proc;
|
|
|
|
|
|
|
|
entry_proc = NewThreadEntryUPP( mac_graphics_event_loop );
|
|
|
|
|
|
|
|
// Create the thread in a suspended state
|
2002-10-29 18:51:45 +00:00
|
|
|
theErr = NewThread ( kCooperativeThread, entry_proc,
|
|
|
|
(void *)(&gi), 0, kNewSuspend | kCreateIfNeeded, NULL, &graphicsThreadID );
|
2002-09-18 21:15:23 +00:00
|
|
|
if (theErr != noErr) return ERR_THREAD;
|
|
|
|
|
|
|
|
// In theory we could do customized scheduling or install thread disposal routines here
|
|
|
|
|
|
|
|
// Put the graphics event loop into the ready state
|
2002-10-06 00:43:55 +00:00
|
|
|
SetThreadState(graphicsThreadID, kReadyThreadState, kNoThreadID);
|
2002-09-18 21:15:23 +00:00
|
|
|
|
|
|
|
YieldToAnyThread();
|
|
|
|
#endif
|
2002-11-12 20:59:00 +00:00
|
|
|
|
|
|
|
#ifdef _PTHREAD_H
|
|
|
|
pthread_t graphics_thread;
|
|
|
|
pthread_attr_t graphics_thread_attr;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
pthread_attr_init( &graphics_thread_attr );
|
|
|
|
retval = pthread_create( &graphics_thread, &graphics_thread_attr, p_graphics_loop, &gi );
|
|
|
|
if (retval) return ERR_THREAD;
|
|
|
|
pthread_attr_destroy( &graphics_thread_attr );
|
|
|
|
#endif
|
|
|
|
|
2002-09-18 21:15:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int boinc_finish_opengl() {
|
2002-09-18 22:15:49 +00:00
|
|
|
return 0;
|
2002-09-18 21:15:23 +00:00
|
|
|
}
|
|
|
|
|
2002-09-17 21:54:59 +00:00
|
|
|
int write_graphics_file(FILE* f, GRAPHICS_INFO* gi) {
|
2002-08-05 00:29:34 +00:00
|
|
|
fprintf(f,
|
2002-09-17 21:54:59 +00:00
|
|
|
"<graphics_info>\n"
|
2002-09-11 21:41:42 +00:00
|
|
|
" <graphics_xsize>%d</graphics_xsize>\n"
|
|
|
|
" <graphics_ysize>%d</graphics_ysize>\n"
|
|
|
|
" <graphics_mode>%d</graphics_mode>\n"
|
|
|
|
" <graphics_refresh_period>%f</graphics_refresh_period>\n"
|
2002-09-17 21:54:59 +00:00
|
|
|
"</graphics_info>\n",
|
|
|
|
gi->xsize,
|
|
|
|
gi->ysize,
|
|
|
|
gi->graphics_mode,
|
|
|
|
gi->refresh_period
|
2002-08-05 00:29:34 +00:00
|
|
|
);
|
2002-09-11 21:41:42 +00:00
|
|
|
|
2002-10-30 04:30:28 +00:00
|
|
|
return 0;
|
2002-08-05 00:29:34 +00:00
|
|
|
}
|
|
|
|
|
2002-09-17 21:54:59 +00:00
|
|
|
int parse_graphics_file(FILE* f, GRAPHICS_INFO* gi) {
|
2002-08-05 00:29:34 +00:00
|
|
|
char buf[256];
|
|
|
|
while (fgets(buf, 256, f)) {
|
2002-10-06 00:43:55 +00:00
|
|
|
if (match_tag(buf, "<graphics_info>")) continue;
|
2002-09-11 21:41:42 +00:00
|
|
|
if (match_tag(buf, "</graphics_info>")) return 0;
|
2002-09-17 21:54:59 +00:00
|
|
|
else if (parse_int(buf, "<graphics_xsize>", gi->xsize)) continue;
|
|
|
|
else if (parse_int(buf, "<graphics_ysize>", gi->ysize)) continue;
|
|
|
|
else if (parse_int(buf, "<graphics_mode>", gi->graphics_mode)) continue;
|
|
|
|
else if (parse_double(buf, "<graphics_refresh_period>", gi->refresh_period)) continue;
|
2002-10-06 00:43:55 +00:00
|
|
|
else fprintf(stderr, "parse_graphics_file: unrecognized %s", buf);
|
2002-08-05 00:29:34 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2002-10-31 00:13:50 +00:00
|
|
|
|
|
|
|
#ifdef BOINC_APP_GRAPHICS
|
|
|
|
|
|
|
|
GLvoid glPrint(GLuint font, const char *fmt, ...) // Custom GL "Print" Routine
|
|
|
|
{
|
|
|
|
char text[256]; // Holds Our String
|
|
|
|
va_list ap; // Pointer To List Of Arguments
|
|
|
|
|
|
|
|
if (fmt == NULL) // If There's No Text
|
|
|
|
return; // Do Nothing
|
|
|
|
|
|
|
|
va_start(ap, fmt); // Parses The String For Variables
|
|
|
|
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
|
|
|
|
va_end(ap); // Results Are Stored In Text
|
|
|
|
|
|
|
|
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
|
|
|
|
glListBase(font); // Sets The Base Character
|
|
|
|
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
|
|
|
|
glPopAttrib(); // Pops The Display List Bits
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|