graphics fixes

svn path=/trunk/boinc/; revision=784
This commit is contained in:
Eric Heien 2002-12-20 20:20:56 +00:00
parent 8a0feee2fc
commit 843aa91865
4 changed files with 51 additions and 20 deletions

View File

@ -55,7 +55,7 @@ MMRESULT timer_id;
#include <gl\gl.h> // Header File For The OpenGL32 Library #include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library #include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The Glaux Library #include <gl\glaux.h> // Header File For The Glaux Library
HANDLE hGlobalDrawEvent,hQuitEvent; HANDLE hDoneDrawingEvent,hQuitEvent, hGraphicsDrawEvent;
extern HANDLE graphics_threadh; extern HANDLE graphics_threadh;
extern BOOL win_loop_done; extern BOOL win_loop_done;
#endif #endif
@ -311,11 +311,14 @@ bool boinc_time_to_checkpoint() {
ok_to_draw = 1; ok_to_draw = 1;
// And wait for the graphics thread to notify us that it's done drawing // And wait for the graphics thread to notify us that it's done drawing
#ifdef _WIN32 #ifdef _WIN32
ResetEvent(hGlobalDrawEvent); // Notify the graphics thread
SetEvent(hGraphicsDrawEvent);
// Reset the draw done event
ResetEvent(hDoneDrawingEvent);
while (ok_to_draw) { while (ok_to_draw) {
// Wait for drawing to finish. We don't do an infinite wait here to avoid the // Wait for drawing to finish. We don't do an infinite wait here to avoid the
// possibility of deadlock (which was happening with an infinite wait value) // possibility of deadlock (which was happening with an infinite wait value)
WaitForSingleObject( hGlobalDrawEvent, 10 ); WaitForSingleObject( hDoneDrawingEvent, 10 );
} }
#endif _WIN32 #endif _WIN32
#ifdef __APPLE_CC__ #ifdef __APPLE_CC__
@ -516,7 +519,13 @@ int set_timer(double period) {
#ifdef BOINC_APP_GRAPHICS #ifdef BOINC_APP_GRAPHICS
// Create the event object used to signal between the // Create the event object used to signal between the
// worker and event threads // worker and event threads
hGlobalDrawEvent = CreateEvent( hDoneDrawingEvent = CreateEvent(
NULL, // no security attributes
TRUE, // manual reset event
TRUE, // initial state is signaled
NULL); // object not named
hGraphicsDrawEvent = CreateEvent(
NULL, // no security attributes NULL, // no security attributes
TRUE, // manual reset event TRUE, // manual reset event
TRUE, // initial state is signaled TRUE, // initial state is signaled

View File

@ -53,7 +53,7 @@ bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
BOOL win_loop_done=FALSE; // Bool Variable To Exit Loop BOOL win_loop_done=FALSE; // Bool Variable To Exit Loop
int counter,old_left,old_top,old_right,old_bottom,cur_gfx_mode,old_gfx_mode; int counter,old_left,old_top,old_right,old_bottom,cur_gfx_mode,old_gfx_mode;
extern HANDLE hGlobalDrawEvent,hQuitEvent; extern HANDLE hGraphicsDrawEvent,hQuitEvent,hDoneDrawingEvent;
int DrawGLScene(GLvoid); int DrawGLScene(GLvoid);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
@ -164,6 +164,11 @@ void ChangeMode( int mode ) {
switch (mode) { switch (mode) {
case MODE_NO_GRAPHICS: case MODE_NO_GRAPHICS:
if (fullscreen) while(ShowCursor(true) < 0); // Show Mouse Pointer if (fullscreen) while(ShowCursor(true) < 0); // Show Mouse Pointer
GetWindowRect( hWnd, &WindowRect );
old_left = WindowRect.left;
old_top = WindowRect.top;
old_right = WindowRect.right;
old_bottom = WindowRect.bottom;
fullscreen = false; fullscreen = false;
break; break;
case MODE_WINDOW: case MODE_WINDOW:
@ -420,6 +425,21 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height
return 0; // Jump Back return 0; // Jump Back
} }
// If we get a redraw request outside of our normal
// redraw framework, just fill the window with black
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc;
RECT winRect;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &winRect);
FillRect(hdc, &winRect, (HBRUSH) GetStockObject(BLACK_BRUSH));
EndPaint(hWnd, &ps);
return 0;
}
} }
// Pass All Unhandled Messages To DefWindowProc // Pass All Unhandled Messages To DefWindowProc
@ -428,6 +448,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
DWORD WINAPI win_graphics_event_loop( LPVOID gi ) { DWORD WINAPI win_graphics_event_loop( LPVOID gi ) {
MSG msg; // Windows Message Structure MSG msg; // Windows Message Structure
HANDLE objs[1];
fullscreen=FALSE; // Windowed Mode fullscreen=FALSE; // Windowed Mode
@ -461,21 +482,23 @@ DWORD WINAPI win_graphics_event_loop( LPVOID gi ) {
TranslateMessage(&msg); // Translate The Message TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message DispatchMessage(&msg); // Dispatch The Message
} }
} else {
objs[0] = hGraphicsDrawEvent;
MsgWaitForMultipleObjects( 1, objs, FALSE, 1000, QS_ALLEVENTS|QS_POSTMESSAGE );
} }
else // If There Are No Messages if (ok_to_draw) { // Window Active?
{ if (active) { // Time To Update Screen
if (ok_to_draw) { // Window Active? // Draw The Scene
if (active) { // Not Time To Quit, Update Screen DrawGLScene();
// Draw The Scene // Swap Buffers (Double Buffering). This seems to take lots of CPU time
DrawGLScene(); SwapBuffers(hDC);
// Swap Buffers (Double Buffering). This seems to take lots of CPU time
SwapBuffers(hDC);
}
// TODO: Do we need a mutex for ok_to_draw?
ok_to_draw = 0;
// Signal the worker thread that we're done drawing
SetEvent(hGlobalDrawEvent);
} }
// TODO: Do we need a mutex for ok_to_draw?
ok_to_draw = 0;
// Signal the worker thread that we're done drawing
SetEvent(hDoneDrawingEvent);
// Put hGraphicsDrawEvent in unsignaled state so we don't immediately wake up
ResetEvent(hGraphicsDrawEvent);
} }
} }

View File

@ -151,7 +151,7 @@ int read_file_malloc(char* pathname, char*& str) {
// replace XML element contents. not currently used // replace XML element contents. not currently used
// //
void replace_element(char* buf, char* start, char* end, char* replacement) { void replace_element(char* buf, char* start, char* end, char* replacement) {
char temp[MAX_BLOB_SIZE], *p, *q; char temp[4096], *p, *q;
p = strstr(buf, start); p = strstr(buf, start);
p += strlen(start); p += strlen(start);

View File

@ -18,7 +18,6 @@
// //
#include <stdio.h> #include <stdio.h>
#include <db.h>
extern bool parse(char*, char*); extern bool parse(char*, char*);
extern bool parse_int(char*, char*, int&); extern bool parse_int(char*, char*, int&);