Cleaning up Some..

This commit is contained in:
Roger Hughston 2006-03-11 01:54:02 +00:00
parent 5a52512d8e
commit 325e42d530
10 changed files with 568 additions and 530 deletions

View File

@ -1,10 +1,7 @@
// Filename: config_glxdisplay.cxx
// Created by: cary (07Oct99)
//
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// //
// PANDA 3D SOFTWARE // PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved // Copyright (c) 2001 - 2006, Disney Enterprises, Inc. All rights reserved
// //
// All use of this software is subject to the terms of the Panda 3d // All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license // Software license. You should have received a copy of this license
@ -55,8 +52,6 @@ init_libosxdisplay() {
} }
initialized = true; initialized = true;
printf("****** In libosx init \n");
osxGraphicsStateGuardian::init_type(); osxGraphicsStateGuardian::init_type();
osxGraphicsPipe::init_type(); osxGraphicsPipe::init_type();
osxGraphicsWindow::init_type(); osxGraphicsWindow::init_type();
@ -69,8 +64,4 @@ init_libosxdisplay() {
PandaSystem *ps = PandaSystem::get_global_ptr(); PandaSystem *ps = PandaSystem::get_global_ptr();
ps->set_system_tag("OpenGL", "window_system", "OSX"); ps->set_system_tag("OpenGL", "window_system", "OSX");
printf("****** out libosx init \n");
} }

View File

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// //
// PANDA 3D SOFTWARE // PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved // Copyright (c) 2001 - 2006, Disney Enterprises, Inc. All rights reserved
// //
// All use of this software is subject to the terms of the Panda 3d // All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license // Software license. You should have received a copy of this license
@ -26,6 +26,5 @@ NotifyCategoryDecl( osxdisplay , EXPCL_PANDAGL, EXPTP_PANDAGL);
extern EXPCL_PANDAGL void init_libosxdisplay(); extern EXPCL_PANDAGL void init_libosxdisplay();
extern ConfigVariableString display_cfg; extern ConfigVariableString display_cfg;
extern ConfigVariableBool osx_error_abort;
#endif /* __CONFIG_OSXDISPLAY_H__ */ #endif /* __CONFIG_OSXDISPLAY_H__ */

View File

@ -38,8 +38,6 @@ osxGraphicsBuffer(GraphicsPipe *pipe, GraphicsStateGuardian *gsg,
osxGraphicsPipe *osx_pipe; osxGraphicsPipe *osx_pipe;
DCAST_INTO_V(osx_pipe, _pipe); DCAST_INTO_V(osx_pipe, _pipe);
// Since the pbuffer never gets flipped, we get screenshots from the
// same buffer we draw into.
_screenshot_buffer_type = _draw_buffer_type; _screenshot_buffer_type = _draw_buffer_type;
} }
@ -74,13 +72,10 @@ begin_frame(FrameMode mode) {
DCAST_INTO_R(osxgsg, _gsg, false); DCAST_INTO_R(osxgsg, _gsg, false);
// osxMakeCurrent(_display, _pbuffer, osxgsg->_context); // osxMakeCurrent(_display, _pbuffer, osxgsg->_context);
// Now that we have made the context current to a window, we can
// reset the GSG state if this is the first time it has been used.
// (We can't just call reset() when we construct the GSG, because
// reset() requires having a current context.)
osxgsg->reset_if_new(); osxgsg->reset_if_new();
if (mode == FM_render) { if (mode == FM_render)
{
// begin_render_texture(); // begin_render_texture();
clear_cube_map_selection(); clear_cube_map_selection();
} }
@ -99,7 +94,8 @@ end_frame(FrameMode mode) {
end_frame_spam(); end_frame_spam();
nassertv(_gsg != (GraphicsStateGuardian *)NULL); nassertv(_gsg != (GraphicsStateGuardian *)NULL);
if (mode == FM_render) { if (mode == FM_render)
{
// end_render_texture(); // end_render_texture();
copy_to_textures(); copy_to_textures();
} }
@ -138,7 +134,7 @@ release_gsg() {
void osxGraphicsBuffer:: void osxGraphicsBuffer::
close_buffer() { close_buffer() {
// _is_valid = false; _is_valid = false;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -26,14 +26,11 @@
#include "graphicsBuffer.h" #include "graphicsBuffer.h"
#include "glgsg.h" #include "glgsg.h"
// This must be included after we have included glgsg.h (which
// includes gl.h).
//#include "wglext.h"
//#include <windows.h>
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : OSXGraphicsBuffer // Class : OSXGraphicsBuffer
// rhh mar-2006
// Sorry ... this is not functional at all... I have no need for it yet ?
//
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class EXPCL_PANDAGL osxGraphicsBuffer : public GraphicsBuffer { class EXPCL_PANDAGL osxGraphicsBuffer : public GraphicsBuffer {
public: public:
@ -42,20 +39,16 @@ public:
int x_size, int y_size); int x_size, int y_size);
virtual ~osxGraphicsBuffer(); virtual ~osxGraphicsBuffer();
virtual bool begin_frame(FrameMode mode); virtual bool begin_frame(FrameMode mode);
virtual void end_frame(FrameMode mode); virtual void end_frame(FrameMode mode);
virtual void release_gsg(); virtual void release_gsg();
// virtual void begin_render_texture();
// virtual void end_render_texture();
protected: protected:
virtual void close_buffer(); virtual void close_buffer();
virtual bool open_buffer(); virtual bool open_buffer();
private:
public: public:
static TypeHandle get_class_type() { static TypeHandle get_class_type() {

View File

@ -19,7 +19,6 @@
#include "osxGraphicsBuffer.h" #include "osxGraphicsBuffer.h"
#include "osxGraphicsStateGuardian.h" #include "osxGraphicsStateGuardian.h"
//typedef enum {Software, MCD, ICD} OGLDriverType;
TypeHandle osxGraphicsPipe::_type_handle; TypeHandle osxGraphicsPipe::_type_handle;

View File

@ -64,6 +64,4 @@ private:
friend class osxGraphicsBuffer; friend class osxGraphicsBuffer;
}; };
//#include "osxGraphicsPipe.I"
#endif #endif

View File

@ -60,7 +60,6 @@ osxGraphicsStateGuardian(const FrameBufferProperties &properties,
_aglPixFmt(NULL), _aglPixFmt(NULL),
_aglcontext(NULL) _aglcontext(NULL)
{ {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -102,7 +101,8 @@ void osxGraphicsStateGuardian::reset()
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: osxGraphicsStateGuardian::buildGL // Function: osxGraphicsStateGuardian::buildGL
// Access: Public, Virtual // Access: Public, Virtual
// Description: // Description: This function will build up a context for a gsg..
// rhh.. This does not respect the flags passed into it for context type ?? hmmm things to do things to do..
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
OSStatus osxGraphicsStateGuardian::buildGL (osxGraphicsWindow &window) OSStatus osxGraphicsStateGuardian::buildGL (osxGraphicsWindow &window)

View File

@ -40,18 +40,14 @@ public:
osxGraphicsStateGuardian *share_with, osxGraphicsStateGuardian *share_with,
int pfnum); int pfnum);
virtual ~osxGraphicsStateGuardian(); virtual ~osxGraphicsStateGuardian();
virtual void reset(); virtual void reset();
AGLContext get_context(void) { return _aglcontext; };
OSStatus buildGL (osxGraphicsWindow &window);
protected: protected:
virtual void *get_extension_func(const char *prefix, const char *name); virtual void *get_extension_func(const char *prefix, const char *name);
private: private:
OSStatus buildGL (osxGraphicsWindow &window);
AGLContext get_context(void) { return _aglcontext; };
// We have to save a pointer to the GSG we intend to share texture // We have to save a pointer to the GSG we intend to share texture
// context with, since we don't create our own context in the // context with, since we don't create our own context in the

View File

@ -27,20 +27,18 @@
#include <AGL/agl.h> #include <AGL/agl.h>
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
////////////////////////// Global Objects .....
TypeHandle osxGraphicsWindow::_type_handle; TypeHandle osxGraphicsWindow::_type_handle;
osxGraphicsWindow * osxGraphicsWindow::FullScreenWindow = NULL;
ButtonHandle OSX_TranslateKey( UInt32 key, EventRef event );
EventHandlerUPP gEvtHandler; // main event handler ////////////////////////////////////////////////////////////////////
EventHandlerUPP gWinEvtHandler; // window event handler // Function: GetCurrentOSxWindow
//AbsoluteTime gStartTime; // Access: Static,
// Description: How to find the active window for events on osx..
char gErrorMessage[256] = ""; // buffer for error message output //
float gErrorTime = 0.0; ////////////////////////////////////////////////////////////////////
osxGraphicsWindow * osxGraphicsWindow::GetCurrentOSxWindow (WindowRef window)
static osxGraphicsWindow * FullScreenWindow = NULL;
osxGraphicsWindow * GetCurrentOSxWindow (WindowRef window)
{ {
if(FullScreenWindow != NULL) if(FullScreenWindow != NULL)
return FullScreenWindow; return FullScreenWindow;
@ -53,8 +51,12 @@ osxGraphicsWindow * GetCurrentOSxWindow (WindowRef window)
return NULL; return NULL;
} }
////////////////////////////////////////////////////////////////////
// Function: aglReportError
// Access: public
// Description: Helper function for AGL error message and Grabing error code if any
//
////////////////////////////////////////////////////////////////////
OSStatus aglReportError (void) OSStatus aglReportError (void)
{ {
GLenum err = aglGetError(); GLenum err = aglGetError();
@ -66,8 +68,13 @@ OSStatus aglReportError (void)
else else
return (OSStatus) err; return (OSStatus) err;
} }
////////////////////////////////////////////////////////////////////
void InvertGLImage( char *imageData, size_t imageSize, size_t rowBytes ) // Function: InvertGLImage
// Access: file scopre, static
// Description: Helper function invertiung a gl image
//
////////////////////////////////////////////////////////////////////
static void InvertGLImage( char *imageData, size_t imageSize, size_t rowBytes )
{ {
size_t i, j; size_t i, j;
char *tBuffer = (char*) malloc (rowBytes); char *tBuffer = (char*) malloc (rowBytes);
@ -82,8 +89,13 @@ void InvertGLImage( char *imageData, size_t imageSize, size_t rowBytes )
free(tBuffer); free(tBuffer);
} }
////////////////////////////////////////////////////////////////////
void CompositeGLBufferIntoWindow (AGLContext ctx, Rect *bufferRect, GrafPtr out_port) // Function: CompositeGLBufferIntoWindow
// Access: file scopre, static
// Description: Drop a Gl overlay onto a carbon window..
//
////////////////////////////////////////////////////////////////////
static void CompositeGLBufferIntoWindow (AGLContext ctx, Rect *bufferRect, GrafPtr out_port)
{ {
GWorldPtr pGWorld; GWorldPtr pGWorld;
QDErr err; QDErr err;
@ -93,7 +105,6 @@ void CompositeGLBufferIntoWindow (AGLContext ctx, Rect *bufferRect, GrafPtr out_
long height = (bufferRect->bottom - bufferRect->top); long height = (bufferRect->bottom - bufferRect->top);
Rect src_rect = {0, 0, height, width}; Rect src_rect = {0, 0, height, width};
Rect ddrc_rect = {0, 0, height, width}; Rect ddrc_rect = {0, 0, height, width};
long rowBytes = width * 4; long rowBytes = width * 4;
@ -104,8 +115,6 @@ void CompositeGLBufferIntoWindow (AGLContext ctx, Rect *bufferRect, GrafPtr out_
return; // no harm in continuing return; // no harm in continuing
} }
// printf(" Reading aa Conte Data %d %d\n",height,width);
// pull GL content down to our image buffer // pull GL content down to our image buffer
aglSetCurrentContext( ctx ); aglSetCurrentContext( ctx );
glReadPixels (0, 0, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image); glReadPixels (0, 0, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image);
@ -131,16 +140,26 @@ void CompositeGLBufferIntoWindow (AGLContext ctx, Rect *bufferRect, GrafPtr out_
DisposeGWorld( pGWorld ); DisposeGWorld( pGWorld );
DisposePtr ( image ); DisposePtr ( image );
} }
////////////////////////////////////////////////////////////////////
// Function: osxGraphicsWindow::SystemCloseWindow
// Access: private
// Description: The Windows is closed by a OS resource not by a internal request
//
////////////////////////////////////////////////////////////////////
void osxGraphicsWindow::SystemCloseWindow() void osxGraphicsWindow::SystemCloseWindow()
{ {
osxdisplay_cat.debug() << "System Closing Window \n"; osxdisplay_cat.debug() << "System Closing Window \n";
ReleaseSystemResources(); ReleaseSystemResources();
}; };
////////////////////////////////////////////////////////////////////
// window event handler // Function: windowEvtHndlr
// Access: file scope static
// Description: The C callback for Window Events ..
//
// We only hook this up for none fullscreen window... so we only handle system window events..
//
////////////////////////////////////////////////////////////////////
static pascal OSStatus windowEvtHndlr (EventHandlerCallRef myHandler, EventRef event, void* userData) static pascal OSStatus windowEvtHndlr (EventHandlerCallRef myHandler, EventRef event, void* userData)
{ {
#pragma unused (userData) #pragma unused (userData)
@ -187,9 +206,17 @@ static pascal OSStatus windowEvtHndlr (EventHandlerCallRef myHandler, EventRef e
} }
return result; return result;
} }
///////////////////////////////////////////////////////////////////
// Function: osxGraphicsWindow::DoResize
// Access:
// Description: The C callback for Window Events ..
//
// We only hook this up for none fullscreen window... so we only handle system window events..
//
////////////////////////////////////////////////////////////////////
void osxGraphicsWindow::DoResize(void) void osxGraphicsWindow::DoResize(void)
{ {
// only in window mode .. not full screen
if(_osx_window != NULL) if(_osx_window != NULL)
{ {
Rect rectPort = {0,0,0,0}; Rect rectPort = {0,0,0,0};
@ -198,22 +225,27 @@ void osxGraphicsWindow::DoResize(void)
GetWindowPortBounds (_osx_window, &rectPort); GetWindowPortBounds (_osx_window, &rectPort);
viewRect.size.width = (float) (rectPort.right - rectPort.left); viewRect.size.width = (float) (rectPort.right - rectPort.left);
viewRect.size.height = (float) (rectPort.bottom - rectPort.top); viewRect.size.height = (float) (rectPort.bottom - rectPort.top);
// tell panda
WindowProperties properties; WindowProperties properties;
properties.set_size((int)viewRect.size.width,(int)viewRect.size.height); properties.set_size((int)viewRect.size.width,(int)viewRect.size.height);
properties.set_origin((int) rectPort.left,(int)rectPort.top); properties.set_origin((int) rectPort.left,(int)rectPort.top);
system_changed_properties(properties); system_changed_properties(properties);
osxdisplay_cat.debug() << " Resizing Window " << viewRect.size.width << " " << viewRect.size.height << "\n"; osxdisplay_cat.debug() << " Resizing Window " << viewRect.size.width << " " << viewRect.size.height << "\n";
// ping gl
aglUpdateContext (aglGetCurrentContext()); aglUpdateContext (aglGetCurrentContext());
aglReportError(); aglReportError();
} }
//printf(" Setting Window Size to %d %d \n",(int)viewRect.size.width,(int)viewRect.size.height);
}; };
// application level event handler ///////////////////////////////////////////////////////////////////
// Function: appEvtHndlr
// Access:
// Description: The C callback for APlication Events..
//
// Hooked once for application
//
////////////////////////////////////////////////////////////////////
static pascal OSStatus appEvtHndlr (EventHandlerCallRef myHandler, EventRef event, void* userData) static pascal OSStatus appEvtHndlr (EventHandlerCallRef myHandler, EventRef event, void* userData)
{ {
#pragma unused (myHandler) #pragma unused (myHandler)
@ -269,7 +301,13 @@ static pascal OSStatus appEvtHndlr (EventHandlerCallRef myHandler, EventRef even
return result; return result;
} }
///////////////////////////////////////////////////////////////////
// Function: osxGraphicsWindow::handleTextInput
// Access:
// Description: Trap Unicode Input.
//
//
////////////////////////////////////////////////////////////////////
OSStatus osxGraphicsWindow::handleTextInput (EventHandlerCallRef myHandler, EventRef theTextEvent) OSStatus osxGraphicsWindow::handleTextInput (EventHandlerCallRef myHandler, EventRef theTextEvent)
{ {
UniChar *text = NULL; UniChar *text = NULL;
@ -288,17 +326,19 @@ OSStatus osxGraphicsWindow::handleTextInput (EventHandlerCallRef myHandler, Even
return ret; return ret;
for(unsigned int x = 0; x < actualSize/sizeof(UniChar); ++x) for(unsigned int x = 0; x < actualSize/sizeof(UniChar); ++x)
{
printf(" Push KetStroke %x\n",(int)text[x]);
_input_devices[0].keystroke(text[x]); _input_devices[0].keystroke(text[x]);
}
DisposePtr((char *)text); DisposePtr((char *)text);
} }
return ret; return ret;
} }
///////////////////////////////////////////////////////////////////
// Function: osxGraphicsWindow::handleTextInput
// Access: private..
// Description: Clean up the OS level messes..
////////////////////////////////////////////////////////////////////
void osxGraphicsWindow::ReleaseSystemResources() void osxGraphicsWindow::ReleaseSystemResources()
{ {
@ -391,11 +431,11 @@ osxGraphicsWindow::~osxGraphicsWindow()
cerr << " osxGraphicsWindow::~osxGraphicsWindow() \n"; cerr << " osxGraphicsWindow::~osxGraphicsWindow() \n";
} }
void osxGraphicsWindow::make_current() ///////////////////////////////////////////////////////////////////
{ // Function: osxGraphicsWindow::get_context
// Access: private..
} // Description: Helper to Decide whitch context to use if any
////////////////////////////////////////////////////////////////////
AGLContext osxGraphicsWindow::get_context(void) AGLContext osxGraphicsWindow::get_context(void)
{ {
if(_aglcontext != NULL) if(_aglcontext != NULL)
@ -403,6 +443,11 @@ AGLContext osxGraphicsWindow::get_context(void)
return get_ggs_context(); return get_ggs_context();
} }
///////////////////////////////////////////////////////////////////
// Function: osxGraphicsWindow::get_ggs_context
// Access: private..
// Description:
////////////////////////////////////////////////////////////////////
AGLContext osxGraphicsWindow::get_ggs_context(void) AGLContext osxGraphicsWindow::get_ggs_context(void)
{ {
@ -415,7 +460,11 @@ AGLContext osxGraphicsWindow::get_ggs_context(void)
return NULL; return NULL;
} }
///////////////////////////////////////////////////////////////////
// Function: osxGraphicsWindow::buildGL
// Access: private..
// Description: Code of the class.. used to control the GL context Allocation ..
////////////////////////////////////////////////////////////////////
OSStatus osxGraphicsWindow::buildGL (void) OSStatus osxGraphicsWindow::buildGL (void)
{ {
// make sure the ggs is up and runnig.. // make sure the ggs is up and runnig..
@ -479,20 +528,21 @@ bool osxGraphicsWindow::begin_frame(FrameMode mode) {
begin_frame_spam(); begin_frame_spam();
if (_gsg == (GraphicsStateGuardian *)NULL || (_osx_window == NULL && _is_fullsreen != true)) if (_gsg == (GraphicsStateGuardian *)NULL || (_osx_window == NULL && _is_fullsreen != true))
{ {
// not powered up .. just abort..
return false; return false;
} }
if(_is_fullsreen) if(_is_fullsreen)
{ {
if (!aglSetCurrentContext(get_context())) if (!aglSetCurrentContext(get_context()))
aglReportError (); aglReportError ();
// printf(" In Full Screen begin_frame\n");
} }
else else
{ {
#ifndef HACK_SCREEN_HASH_CONTEXT
// if we do not have local contexts we need to do some wor
GrafPtr OtherWin = (GrafPtr)aglGetDrawable(get_context()); GrafPtr OtherWin = (GrafPtr)aglGetDrawable(get_context());
aglReportError(); aglReportError();
WindowPtr other = GetWindowFromPort(OtherWin); WindowPtr other = GetWindowFromPort(OtherWin);
@ -505,6 +555,8 @@ bool osxGraphicsWindow::begin_frame(FrameMode mode) {
CompositeGLBufferIntoWindow(get_context(),& r,OtherWin); CompositeGLBufferIntoWindow(get_context(),& r,OtherWin);
} }
// uggly uggly uggly on a mac ... not a good thing..
aglSetDrawable (get_context(),GetWindowPort (_osx_window)); aglSetDrawable (get_context(),GetWindowPort (_osx_window));
aglReportError(); aglReportError();
@ -513,6 +565,13 @@ bool osxGraphicsWindow::begin_frame(FrameMode mode) {
aglReportError (); aglReportError ();
} }
#else
if (!aglSetCurrentContext(get_context()))
aglReportError ();
#endif
@ -611,10 +670,9 @@ extern OSErr CPSSetFrontProcess( struct CPSProcessSerNum *psn);
// thread. Returns true if the window is successfully // thread. Returns true if the window is successfully
// opened, or false if there was a problem. // opened, or false if there was a problem.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool osxGraphicsWindow::open_window() { bool osxGraphicsWindow::open_window()
OSErr err; {
printf(" In Open Window \n"); OSErr err;
static bool GlobalInits = false; static bool GlobalInits = false;
if(GlobalInits != true) if(GlobalInits != true)
@ -633,6 +691,7 @@ OSErr err;
{ kEventClassKeyboard, kEventRawKeyModifiersChanged } , { kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
{kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}, {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent},
}; };
EventHandlerUPP gEvtHandler; // main event handler
gEvtHandler = NewEventHandlerUPP(appEvtHndlr); gEvtHandler = NewEventHandlerUPP(appEvtHndlr);
@ -695,8 +754,8 @@ OSErr err;
r.bottom = r.top + 512; r.bottom = r.top + 512;
} }
if(_properties.has_fullscreen() && _properties.get_fullscreen() == true) if(_properties.has_fullscreen() && _properties.get_fullscreen() == true)
{ {
// capture the main display // capture the main display
CGDisplayCapture( kCGDirectMainDisplay ); CGDisplayCapture( kCGDirectMainDisplay );
// if sized try and switch it.. // if sized try and switch it..
@ -718,23 +777,16 @@ if(_properties.has_fullscreen() && _properties.get_fullscreen() == true)
if (!aglSetInteger (get_context(), AGL_SWAP_INTERVAL, &swap)) if (!aglSetInteger (get_context(), AGL_SWAP_INTERVAL, &swap))
aglReportError (); aglReportError ();
// CreateNewWindow(//
// kOverlayWindowClass,
// kWindowStandardHandlerAttribute,
// &r, &_osx_window);
_is_fullsreen =true; _is_fullsreen =true;
FullScreenWindow = this; FullScreenWindow = this;
} }
else else
{ {
CreateNewWindow(// CreateNewWindow(//
// kUtilityWindowClass, // kUtilityWindowClass,
kDocumentWindowClass, kDocumentWindowClass,
// kWindowLiveResizeAttribute | // kWindowLiveResizeAttribute |
kWindowStandardDocumentAttributes | kWindowStandardDocumentAttributes |
kWindowStandardHandlerAttribute, kWindowStandardHandlerAttribute,
&r, &_osx_window); &r, &_osx_window);
@ -742,6 +794,18 @@ else
if (_osx_window) if (_osx_window)
{ {
EventHandlerUPP gWinEvtHandler; // window event handler
EventHandlerRef ref;
EventTypeSpec list[] = { { kEventClassWindow, kEventWindowCollapsing },
{ kEventClassWindow, kEventWindowShown },
{ kEventClassWindow, kEventWindowActivated },
{ kEventClassWindow, kEventWindowClose },
{ kEventClassWindow, kEventWindowBoundsChanged },
{ kEventClassWindow, kEventWindowZoomed },
// { kEventClassKeyboard, kEventRawKeyDown },
// { kEventClassKeyboard, kEventRawKeyUp } ,
// { kEventClassKeyboard, kEventRawKeyModifiersChanged }
};
SetWRefCon (_osx_window, (long) this); // point to the window record in the ref con of the window SetWRefCon (_osx_window, (long) this); // point to the window record in the ref con of the window
gWinEvtHandler = NewEventHandlerUPP(windowEvtHndlr); gWinEvtHandler = NewEventHandlerUPP(windowEvtHndlr);
@ -767,9 +831,11 @@ else
SetPort (portSave); SetPort (portSave);
} }
} }
//RunApplicationEventLoop();
//
// pull the size from the real window .. do not trust the requested values?
WindowProperties properties; WindowProperties properties;
_properties.set_foreground(true); _properties.set_foreground(true);
@ -781,7 +847,7 @@ else
CGDirectDisplayID display = CGMainDisplayID (); CGDirectDisplayID display = CGMainDisplayID ();
osxdisplay_cat.debug() << "Full Screen Size ["<< CGDisplayPixelsWide (display) <<","<< CGDisplayPixelsHigh (display) << "\n"; osxdisplay_cat.debug() << "Full Screen Size ["<< CGDisplayPixelsWide (display) <<","<< CGDisplayPixelsHigh (display) << "\n";
// _properties.set_size((int)800,(int) 600); // _properties.set_size((int)800,(int) 600);
_properties.set_size((int)CGDisplayPixelsWide (display),(int) CGDisplayPixelsHigh (display)); _properties.set_size((int)CGDisplayPixelsWide (display),(int) CGDisplayPixelsHigh (display));
_properties.set_origin((int) 0,(int)0); _properties.set_origin((int) 0,(int)0);
} }
@ -794,7 +860,13 @@ else
} }
return true; return true;
} }
////////////////////////////////////////////////////////////////////
// Function: osxGraphicsWindow::process_events()
// Access: virtual, protected
// Description: Required Event upcall . Used to dispatch Window and Aplication Events
// back into panda
//
////////////////////////////////////////////////////////////////////
void osxGraphicsWindow::process_events() void osxGraphicsWindow::process_events()
{ {
GraphicsWindow::process_events(); GraphicsWindow::process_events();
@ -802,7 +874,7 @@ void osxGraphicsWindow::process_events()
EventTargetRef theTarget; EventTargetRef theTarget;
theTarget = GetEventDispatcherTarget(); theTarget = GetEventDispatcherTarget();
// while (ReceiveNextEvent(0, NULL,kEventDurationForever,true, &theEvent)== noErr) // while (ReceiveNextEvent(0, NULL,kEventDurationForever,true, &theEvent)== noErr)
while (ReceiveNextEvent(0, NULL,kEventDurationNoWait,true, &theEvent)== noErr) while (ReceiveNextEvent(0, NULL,kEventDurationNoWait,true, &theEvent)== noErr)
{ {
SendEventToEventTarget (theEvent, theTarget); SendEventToEventTarget (theEvent, theTarget);
@ -833,24 +905,13 @@ void handleWindowDMEvent (void *userData, short theMessage, void *notifyData)
} }
} }
} }
/* ////////////////////////////////////////////////////////////////////
// Function: osxGraphicsWindow::process_events()
// Access: virtual, protected
EventRef theTextEvent; // Description: Required Event upcall . Used to dispatch Window and Aplication Events
UniChar *text; // back into panda
UInt32 actualSize; //
////////////////////////////////////////////////////////////////////
GetEventParameter (theTextEvent, kEventParamTextInputSendText,
typeUnicodeText, NULL, 0, &actualSize, NULL);
text = (UniChar*) NewPtr(actualSize);
GetEventParameter (theTextEvent, kEventParamTextInputSendText,
typeUnicodeText, NULL, actualSize, NULL, text);
*/
// key input handler // key input handler
OSStatus osxGraphicsWindow::handleKeyInput (EventHandlerCallRef myHandler, EventRef event, Boolean keyDown) OSStatus osxGraphicsWindow::handleKeyInput (EventHandlerCallRef myHandler, EventRef event, Boolean keyDown)
{ {
@ -879,14 +940,22 @@ OSStatus osxGraphicsWindow::handleKeyInput (EventHandlerCallRef myHandler, Event
return result; return result;
} }
////////////////////////////////////////////////////////////////////
// Function:
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void osxGraphicsWindow::SystemSetWindowForground(bool forground) void osxGraphicsWindow::SystemSetWindowForground(bool forground)
{ {
WindowProperties properties; WindowProperties properties;
properties.set_foreground(forground); properties.set_foreground(forground);
system_changed_properties(properties); system_changed_properties(properties);
}; };
////////////////////////////////////////////////////////////////////
// Function:
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void osxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint) void osxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint)
{ {
@ -897,15 +966,18 @@ void osxGraphicsWindow::SystemSetWindowForground(bool forground)
SetPort( savePort ); SetPort( savePort );
}; };
////////////////////////////////////////////////////////////////////
// Function:
// Access:
// Description:
////////////////////////////////////////////////////////////////////
OSStatus osxGraphicsWindow::handleWindowMouseEvents (EventHandlerCallRef myHandler, EventRef event) OSStatus osxGraphicsWindow::handleWindowMouseEvents (EventHandlerCallRef myHandler, EventRef event)
{ {
WindowRef window = NULL; WindowRef window = NULL;
// pRecContext pContextInfo = NULL;
OSStatus result = eventNotHandledErr; OSStatus result = eventNotHandledErr;
UInt32 kind = GetEventKind (event); UInt32 kind = GetEventKind (event);
EventMouseButton button = 0; EventMouseButton button = 0;
// HIPoint location = {0.0f, 0.0f};
Point qdGlobalPoint = {0, 0}; Point qdGlobalPoint = {0, 0};
UInt32 modifiers = 0; UInt32 modifiers = 0;
long wheelDelta = 0; long wheelDelta = 0;
@ -914,14 +986,8 @@ OSStatus osxGraphicsWindow::handleWindowMouseEvents (EventHandlerCallRef myHandl
// Mac OS X v10.1 and later // Mac OS X v10.1 and later
// should this be front window??? // should this be front window???
GetEventParameter(event, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); GetEventParameter(event, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
// if (window)
// pContextInfo = GetCurrentContextInfo (window);
// if (!pContextInfo)
// return result; // not an application GLWindow so do not process (there is an exception)
GetWindowPortBounds (window, &rectPort); GetWindowPortBounds (window, &rectPort);
//printf(" Got Mouse Event \n");
result = CallNextEventHandler(myHandler, event); result = CallNextEventHandler(myHandler, event);
if (eventNotHandledErr == result) if (eventNotHandledErr == result)
{ // only handle events not already handled (prevents wierd resize interaction) { // only handle events not already handled (prevents wierd resize interaction)
@ -930,7 +996,6 @@ OSStatus osxGraphicsWindow::handleWindowMouseEvents (EventHandlerCallRef myHandl
case kEventMouseDown: case kEventMouseDown:
{ {
GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(EventMouseButton), NULL, &button); GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(EventMouseButton), NULL, &button);
// GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &location); // Mac OS X v10.1 and later
GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
GetEventParameter(event, kEventParamMouseLocation,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint); GetEventParameter(event, kEventParamMouseLocation,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint);
SystemPointToLocalPoint(qdGlobalPoint); SystemPointToLocalPoint(qdGlobalPoint);
@ -940,11 +1005,6 @@ OSStatus osxGraphicsWindow::handleWindowMouseEvents (EventHandlerCallRef myHandl
button_h = MouseButton::two(); button_h = MouseButton::two();
if(kEventMouseButtonTertiary == button) if(kEventMouseButtonTertiary == button)
button_h = MouseButton::three(); button_h = MouseButton::three();
// cerr << " Mouse Down " << location.x << " " << location.y << " "<< button_h << "\n" ;
// cerr << " Mouse Down " << qdGlobalPoint.h << " " << qdGlobalPoint.v << " "<< button_h << "\n" ;
// cerr << " Window Port " << rectPort.top << " " << rectPort.bottom ;
// _input_devices[0].set_pointer_in_window((int)location.x, (int)location.y);
_input_devices[0].set_pointer_in_window((int)qdGlobalPoint.h, (int)qdGlobalPoint.v); _input_devices[0].set_pointer_in_window((int)qdGlobalPoint.h, (int)qdGlobalPoint.v);
_input_devices[0].button_down(button_h); _input_devices[0].button_down(button_h);
} }
@ -953,7 +1013,7 @@ OSStatus osxGraphicsWindow::handleWindowMouseEvents (EventHandlerCallRef myHandl
case kEventMouseUp: case kEventMouseUp:
{ {
GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(EventMouseButton), NULL, &button); GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(EventMouseButton), NULL, &button);
// GetEventParameter(event, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &location); // Mac OS X v10.1 and later // GetEventParameter(event, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &location); // Mac OS X v10.1 and later
GetEventParameter(event, kEventParamMouseLocation,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint); GetEventParameter(event, kEventParamMouseLocation,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint);
SystemPointToLocalPoint(qdGlobalPoint); SystemPointToLocalPoint(qdGlobalPoint);
@ -962,20 +1022,12 @@ OSStatus osxGraphicsWindow::handleWindowMouseEvents (EventHandlerCallRef myHandl
button_h = MouseButton::two(); button_h = MouseButton::two();
if(kEventMouseButtonTertiary == button) if(kEventMouseButtonTertiary == button)
button_h = MouseButton::three(); button_h = MouseButton::three();
// cerr << " Mouse Up " << location.x << " " << location.y << " "<< button_h << "\n";
// cerr << " Mouse up " << qdGlobalPoint.h << " " << qdGlobalPoint.v << " "<< button_h << "\n" ;
_input_devices[0].set_pointer_in_window((int)qdGlobalPoint.h, (int)qdGlobalPoint.v); _input_devices[0].set_pointer_in_window((int)qdGlobalPoint.h, (int)qdGlobalPoint.v);
_input_devices[0].button_up(button_h); _input_devices[0].button_up(button_h);
} }
break; break;
case kEventMouseMoved: case kEventMouseMoved:
case kEventMouseDragged: case kEventMouseDragged:
// GetEventParameter(event, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &location); // Mac OS X v10.1 and later
// GetEventParameter(event, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &location); // Mac OS X v10.1 and later
// _input_devices[0].set_pointer_in_window((int)location.x, (int)location.y);
// _input_devices[0].set_pointer_in_window(event.xmotion.x, event.xmotion.y);
GetEventParameter(event, kEventParamMouseLocation,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint); GetEventParameter(event, kEventParamMouseLocation,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint);
SystemPointToLocalPoint(qdGlobalPoint); SystemPointToLocalPoint(qdGlobalPoint);
@ -989,11 +1041,15 @@ OSStatus osxGraphicsWindow::handleWindowMouseEvents (EventHandlerCallRef myHandl
result = noErr; result = noErr;
} }
return result; return result;
} }
////////////////////////////////////////////////////////////////////
ButtonHandle OSX_TranslateKey( UInt32 key, EventRef event) // Function: osxGraphicsWindow::OSX_TranslateKey
{ // Access: Private
// Description: MAC Key Codes to Panda Key Codes
////////////////////////////////////////////////////////////////////
ButtonHandle osxGraphicsWindow::OSX_TranslateKey( UInt32 key, EventRef event)
{
ButtonHandle nk = ButtonHandle::none(); ButtonHandle nk = ButtonHandle::none();
@ -1051,7 +1107,7 @@ ButtonHandle OSX_TranslateKey( UInt32 key, EventRef event)
case 92: nk = KeyboardButton::ascii_key('9'); break; case 92: nk = KeyboardButton::ascii_key('9'); break;
// case 36: nk = KeyboardButton::ret(); break; // no return in panda ??? // case 36: nk = KeyboardButton::ret(); break; // no return in panda ???
case 49: nk = KeyboardButton::space(); break; case 49: nk = KeyboardButton::space(); break;
case 51: nk = KeyboardButton::backspace(); break; case 51: nk = KeyboardButton::backspace(); break;
case 48: nk = KeyboardButton::tab(); break; case 48: nk = KeyboardButton::tab(); break;
@ -1067,10 +1123,10 @@ ButtonHandle OSX_TranslateKey( UInt32 key, EventRef event)
case 121: nk = KeyboardButton::page_down(); break; case 121: nk = KeyboardButton::page_down(); break;
case 115: nk = KeyboardButton::home(); break; case 115: nk = KeyboardButton::home(); break;
case 119: nk = KeyboardButton::end(); break; case 119: nk = KeyboardButton::end(); break;
// case : nk = KeyboardButton::insert(); break; // case : nk = KeyboardButton::insert(); break;
case 117: nk = KeyboardButton::del(); break; case 117: nk = KeyboardButton::del(); break;
// case 71: nk = KeyboardButton::num_lock() break; // case 71: nk = KeyboardButton::num_lock() break;
case 122: nk = KeyboardButton::f1(); break; case 122: nk = KeyboardButton::f1(); break;
case 120: nk = KeyboardButton::f2(); break; case 120: nk = KeyboardButton::f2(); break;
@ -1080,11 +1136,11 @@ ButtonHandle OSX_TranslateKey( UInt32 key, EventRef event)
case 97: nk = KeyboardButton::f6(); break; case 97: nk = KeyboardButton::f6(); break;
case 98: nk = KeyboardButton::f7(); break; case 98: nk = KeyboardButton::f7(); break;
case 100: nk = KeyboardButton::f8(); break; case 100: nk = KeyboardButton::f8(); break;
// case : nk = KeyboardButton::f9(); break; // seem to be used by the systems.. // case : nk = KeyboardButton::f9(); break; // seem to be used by the systems..
// case : nk = KeyboardButton::f10(); break; // case : nk = KeyboardButton::f10(); break;
// case : nk = KeyboardButton::f11(); break; // case : nk = KeyboardButton::f11(); break;
// case : nk = KeyboardButton::f12(); break; // case : nk = KeyboardButton::f12(); break;
// case 105: nk = KeyboardButton::f13(); break; // panda does not have a 13 // case 105: nk = KeyboardButton::f13(); break; // panda does not have a 13
// shiftable chartablet // shiftable chartablet
case 50: nk = KeyboardButton::ascii_key('`'); break; case 50: nk = KeyboardButton::ascii_key('`'); break;
@ -1100,7 +1156,7 @@ ButtonHandle OSX_TranslateKey( UInt32 key, EventRef event)
case 44: nk = KeyboardButton::ascii_key('/'); break; case 44: nk = KeyboardButton::ascii_key('/'); break;
default: default:
// printf (" Untranslated KeyCode: %lu (0x%lX)\n", key, key); // printf (" Untranslated KeyCode: %lu (0x%lX)\n", key, key);
// not sure this is right .. but no mapping for keypad and such // not sure this is right .. but no mapping for keypad and such
// this at least does a best gess.. // this at least does a best gess..
@ -1109,9 +1165,12 @@ ButtonHandle OSX_TranslateKey( UInt32 key, EventRef event)
nk = KeyboardButton::ascii_key(charCode); nk = KeyboardButton::ascii_key(charCode);
} }
return nk; return nk;
} }
////////////////////////////////////////////////////////////////////
// Function: osxGraphicsWindow::HandleModifireDeleta
// Access: Private
// Description: Used to emulate key events for the MAC key Modifiers..
////////////////////////////////////////////////////////////////////
void osxGraphicsWindow::HandleModifireDeleta(UInt32 newModifiers) void osxGraphicsWindow::HandleModifireDeleta(UInt32 newModifiers)
{ {
UInt32 changed = _last_key_modifiers ^ newModifiers; UInt32 changed = _last_key_modifiers ^ newModifiers;

View File

@ -43,20 +43,19 @@ public:
const string &name); const string &name);
virtual ~osxGraphicsWindow(); virtual ~osxGraphicsWindow();
// virtual bool move_pointer(int device, int x, int y); virtual bool move_pointer(int device, int x, int y);
//virtual bool make_context();
virtual void make_current(); virtual void make_current();
virtual void release_gsg(); virtual void release_gsg();
virtual bool begin_frame(FrameMode mode); virtual bool begin_frame(FrameMode mode);
virtual void end_frame(FrameMode mode); virtual void end_frame(FrameMode mode);
virtual void begin_flip(); virtual void begin_flip();
virtual void process_events(); virtual void process_events();
private:
void ReleaseSystemResources(); void ReleaseSystemResources();
@ -65,11 +64,19 @@ protected:
virtual bool open_window(); virtual bool open_window();
private: private:
//
// a singleton .. for the events to find the right pipe to push the event into
//
static osxGraphicsWindow * FullScreenWindow;
static osxGraphicsWindow * GetCurrentOSxWindow (WindowRef hint);
public: // do not call direct .. public: // do not call direct ..
OSStatus handleKeyInput (EventHandlerCallRef myHandler, EventRef event, Boolean keyDown); OSStatus handleKeyInput (EventHandlerCallRef myHandler, EventRef event, Boolean keyDown);
OSStatus handleTextInput (EventHandlerCallRef myHandler, EventRef event); OSStatus handleTextInput (EventHandlerCallRef myHandler, EventRef event);
OSStatus handleWindowMouseEvents (EventHandlerCallRef myHandler, EventRef event); OSStatus handleWindowMouseEvents (EventHandlerCallRef myHandler, EventRef event);
ButtonHandle OSX_TranslateKey( UInt32 key, EventRef event );
void HandleModifireDeleta(UInt32 modifiers); void HandleModifireDeleta(UInt32 modifiers);
void DoResize(void); void DoResize(void);
@ -92,10 +99,10 @@ public: // do not call direct ..
} }
inline bool IsAlive(void) // inline bool IsAlive(void)
{ // {
return (_is_fullsreen || _osx_window != NULL); // return (_is_fullsreen || _osx_window != NULL);
} // }
WindowProperties & properties() { return _properties; }; WindowProperties & properties() { return _properties; };
private: private: