vrj::GlWindowOSX Class Reference

An OpenGL-specific glWindow for OS X. More...

#include <vrj/Draw/OGL/GlWindowOSX.h>

Inheritance diagram for vrj::GlWindowOSX:

Inheritance graph
[legend]
Collaboration diagram for vrj::GlWindowOSX:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 GlWindowOSX ()
virtual ~GlWindowOSX ()
virtual void swapBuffers ()
 Performs an OpenGL swap buffers command.
virtual bool open ()
 Opens the OpenGL window.
virtual bool close ()
 Closes the OpenGL window.
bool makeCurrent ()
 Sets the current OpenGL context to this window.
void configWindow (Display *_display)
 Configures the window.
Pure virtuals required by gadget::Input.
bool startSampling ()
 Override the version from gadget::EventWindowOSX so we can do our own thing here.

Protected Member Functions

OSStatus BuildGLFromWindow (WindowPtr pWindow, AGLContext *paglContext, structGLWindowInfo *pcontextInfo)
OSStatus BuildGLonWindow (WindowPtr pWindow, AGLContext *paglContext, structGLWindowInfo *pcontextInfo)
OSStatus DestroyGLFromWindow (AGLContext *paglContext, structGLWindowInfo *pcontextInfo)
short FindGDHandleFromWindow (WindowPtr pWindow, GDHandle *phgdOnThisDevice)
Boolean CheckRenderer (GDHandle hGD, long *VRAM, long *textureRAM, GLint *, Boolean fAccelMust)
Boolean CheckAllDeviceRenderers (long *pVRAM, long *pTextureRAM, GLint *pDepthSizeSupport, Boolean fAccelMust)
void ReportError (const char *strError)
GLenum aglReportError (void)

Detailed Description

An OpenGL-specific glWindow for OS X.

Has all information specific to dealing with a GL window in OpenGL.

Definition at line 93 of file GlWindowOSX.h.


Constructor & Destructor Documentation

vrj::GlWindowOSX::GlWindowOSX (  ) 

Definition at line 52 of file GlWindowOSX.cpp.

00053    : GlWindow()
00054    , gadget::EventWindowOSX()
00055 {
00056 }

vrj::GlWindowOSX::~GlWindowOSX (  )  [virtual]

Definition at line 58 of file GlWindowOSX.cpp.

References close().

00058                           {
00059     close();
00060 }


Member Function Documentation

void vrj::GlWindowOSX::swapBuffers (  )  [virtual]

Performs an OpenGL swap buffers command.

Postcondition:
A glFlush must be called explicitly by the implementation or explicitly by the functions used in the implementation.

Reimplemented from vrj::GlWindow.

Definition at line 62 of file GlWindowOSX.cpp.

References vrj::GlWindow::swapBuffers(), and vrjDBG_DRAW_MGR().

00063 {
00064    GlWindow::swapBuffers();
00065 
00066    vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HEX_LVL)
00067       << "vrj::GlWindowOSX::swapBuffers()" << std::endl << vprDEBUG_FLUSH;
00068 
00069     if(aglContext)
00070     {
00071         aglSwapBuffers (aglContext);
00072 
00073         /* This code is supposed to change the size of the window
00074         ** it works but it is a waste to check to see if the size of the window is a
00075         ** different every frame.  If we want to implement this feature
00076         ** we should capture the window resize event and change based on that
00077         Rect rectPort;
00078         if(gpWindow)
00079         {
00080             //If the window changed size
00081             GetWindowPortBounds (gpWindow, &rectPort);
00082             int newWidth = rectPort.right - rectPort.left;
00083             int newHeight = rectPort.bottom - rectPort.top;
00084             if( newWidth != mWindowWidth || newHeight != mWindowHeight)
00085             {
00086                 // Refresh the window with black...
00087                 aglUpdateContext (aglContext);
00088                 glViewport (0, 0, rectPort.right - rectPort.left, rectPort.bottom - rectPort.top);
00089                 mWindowWidth = newWidth; mWindowHeight = newHeight;
00090                 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
00091                 glClear (GL_COLOR_BUFFER_BIT);
00092                 aglSwapBuffers (aglContext);
00093 
00094                 glViewport (0, 0, rectPort.right - rectPort.left, rectPort.bottom - rectPort.top);
00095             }
00096         }
00097         */
00098     }
00099 
00100 }

bool vrj::GlWindowOSX::open (  )  [virtual]

Opens the OpenGL window.

Precondition:
this has been configured.

Reimplemented from vrj::GlWindow.

Definition at line 102 of file GlWindowOSX.cpp.

References structGLWindowInfo::aglAttributes, BuildGLFromWindow(), DestroyGLFromWindow(), structGLWindowInfo::fAcceleratedMust, structGLWindowInfo::fDraggable, structGLWindowInfo::fmt, vrj::GlWindow::mIsEventSource, vrj::GlWindow::mOriginX, vrj::GlWindow::mOriginY, vrj::GlWindow::mWindowHeight, vrj::GlWindow::mWindowIsOpen, vrj::GlWindow::mWindowWidth, startSampling(), structGLWindowInfo::textureRAM, structGLWindowInfo::VRAM, and vrjDBG_DRAW_MGR().

00102                        {
00103    vpr::DebugOutputGuard(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL,
00104                          "vrj::GlWindowOSX::open()\n",
00105                          "vrj::GlWindowOSX::open() done.\n");
00106 
00107     //Get the size of the screen from core graphics
00108     //I'll need to check to see how this works with multiple monitors
00109     CGRect bounds;
00110     bounds = CGDisplayBounds(kCGDirectMainDisplay);
00111 
00112     // If the size of the window and the size of the screen are the same
00113     // switch to fullscreen mode
00114     // Note: this is not true fullscreen the menu bar and dock are just hiden
00115     // this will not give you the speed increases you could get if you gave GL
00116     // full control of the screen
00117     if( bounds.size.height == mWindowHeight &&
00118         bounds.size.width == mWindowWidth)
00119     {
00120         vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL)
00121            << "FULLSCREEN Mode enabled" << std::endl << vprDEBUG_FLUSH;
00122         HideMenuBar ();
00123     }
00124 
00125 
00126     //set the window size and location with the height adjusted
00127     SetRect(&rectWin, mOriginX , bounds.size.height - mOriginY - mWindowHeight,
00128             mOriginX + mWindowWidth, bounds.size.height - mOriginY);
00129                             /* left, top, right, bottom */
00130     /*
00131     rectWin.top = mOriginY;
00132     rectWin.left = mOriginX;
00133     rectWin.bottom = mOriginY + mWindowHeight;
00134     rectWin.right = mOriginX + mWindowWidth;
00135     */
00136     if (noErr != CreateNewWindow (kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowNoShadowAttribute | kWindowLiveResizeAttribute, &rectWin, &gpWindow))
00137     {
00138         vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CRITICAL_LVL)
00139            << "[vrj::GlWindowOSX::open()] Window failed to open!" << std::endl
00140            << vprDEBUG_FLUSH;
00141         return false;
00142     }
00143     SetWindowTitleWithCFString(gpWindow,window_title);
00144     InstallStandardEventHandler(GetWindowEventTarget(gpWindow));
00145     ChangeWindowAttributes(gpWindow, NULL, kWindowCloseBoxAttribute );
00146 
00147     //This is the an event source window.
00148     if (mIsEventSource == true)
00149     {
00150         vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL)
00151            << "vrj::GlWindowOSX::config(): We will be an event source\n"
00152            << vprDEBUG_FLUSH;
00153 
00154         gadget::EventWindowOSX::mWindow = gpWindow;
00155         gadget::Input* dev_ptr = dynamic_cast<gadget::Input*>(this);
00156         vrj::Kernel::instance()->getInputManager()->addDevice(dev_ptr);
00157 
00158         startSampling();
00159     }
00160 
00161 
00162     ShowWindow (gpWindow);
00163     SetPort ( (GrafPtr) GetWindowPort(gpWindow) );
00164     glInfo.fAcceleratedMust = false;    // must renderer be accelerated?
00165     glInfo.VRAM = 0 * 1048576;          // minimum VRAM (if not zero this is always required)
00166     glInfo.textureRAM = 0 * 1048576;    // minimum texture RAM (if not zero this is always required)
00167     glInfo.fDraggable = false;      // desired vertical refresh frequency in Hz (0 = any)
00168     glInfo.fmt = 0;                 // output pixel format
00169 
00170     int i = 0;
00171     glInfo.aglAttributes [i++] = AGL_RGBA;
00172     glInfo.aglAttributes [i++] = AGL_DOUBLEBUFFER;
00173     glInfo.aglAttributes [i++] = AGL_DEPTH_SIZE;
00174     glInfo.aglAttributes [i++] = 32;
00175     glInfo.aglAttributes [i++] = AGL_NONE;
00176 
00177     BuildGLFromWindow (gpWindow, &aglContext, &glInfo);
00178     if (!aglContext)
00179     {
00180         DestroyGLFromWindow (&aglContext, &glInfo);
00181         vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CRITICAL_LVL)
00182            << "[vrj::GlWindowOSX::open()] Window could not create GL Context!"
00183            << std::endl << vprDEBUG_FLUSH;
00184         return false;
00185     }
00186     Rect rectPort;
00187     GetWindowPortBounds (gpWindow, &rectPort);
00188     aglUpdateContext (aglContext);
00189     glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
00190     glClear (GL_COLOR_BUFFER_BIT);
00191     aglSwapBuffers (aglContext);
00192     glViewport(0, 0, rectPort.right - rectPort.left,
00193                rectPort.bottom - rectPort.top);
00194 
00195     mWindowIsOpen = true;
00196     return true;
00197 }

bool vrj::GlWindowOSX::close (  )  [virtual]

Closes the OpenGL window.

Reimplemented from vrj::GlWindow.

Definition at line 199 of file GlWindowOSX.cpp.

References DestroyGLFromWindow(), and vrjDBG_DRAW_MGR().

Referenced by ~GlWindowOSX().

00199                         {
00200     vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL)
00201        << "vrj::GlWindowOSX::close()" << std::endl << vprDEBUG_FLUSH;
00202     if(!gpWindow) return false;
00203 
00204     DestroyGLFromWindow (&aglContext, &glInfo);
00205     DisposeWindow (gpWindow);
00206 
00207     gpWindow = NULL;
00208     gFrameWindow = 0;
00209     gTimeWindow.hi = 0;
00210     gTimeWindow.lo = 0;
00211     gRotation = 0.0;
00212     return true;
00213 }

bool vrj::GlWindowOSX::makeCurrent (  )  [virtual]

Sets the current OpenGL context to this window.

Postcondition:
this.context is active context.

Reimplemented from vrj::GlWindow.

Definition at line 215 of file GlWindowOSX.cpp.

References vrjDBG_DRAW_MGR().

00215                               {
00216     vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HEX_LVL)
00217       << "vrj::GlWindowOSX::makeCurrent()" << std::endl << vprDEBUG_FLUSH;
00218     if(!aglContext) return false;
00219     aglSetCurrentContext (aglContext);
00220     return true;
00221 }

bool vrj::GlWindowOSX::startSampling (  ) 

Override the version from gadget::EventWindowOSX so we can do our own thing here.

Definition at line 702 of file GlWindowOSX.cpp.

References vrjDBG_DRAW_MGR().

Referenced by open().

00703 {
00704     if(mAmSampling == true)
00705     {
00706         vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
00707             << clrOutNORM(clrRED,"ERROR:")
00708             << "vrj::GlWindowOSX: startSampling called, when already sampling.\n"
00709             << vprDEBUG_FLUSH;
00710         vprASSERT(false);
00711         return false;
00712     }
00713 
00714     //openTheWindow();
00715 
00716     vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL)
00717        << "vrj::GlWindowOSX::startSampling() starting to sample\n"
00718        << vprDEBUG_FLUSH;
00719 
00720     attachEvents(mWindow);
00721 
00722     mAmSampling = true;
00723 
00724     return true;
00725 }

void vrj::GlWindowOSX::configWindow ( Display _display  )  [virtual]

Configures the window.

Postcondition:
this is configured based on the data in display.

Reimplemented from vrj::GlWindow.

Definition at line 223 of file GlWindowOSX.cpp.

References vrj::GlWindow::configWindow(), vrj::Display::getConfigElement(), vrj::Display::getName(), vrj::Display::getPipe(), vrj::GlWindow::mIsEventSource, and vrjDBG_DRAW_MGR().

00224 {
00225    vpr::DebugOutputGuard(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL,
00226                          "vrj::GlWindowOSX::configWindow()\n",
00227                          "vrj::GlWindowOSX::configWindow() done.\n");
00228 
00229    GlWindow::configWindow(_display);
00230 
00231     // Get the vector of display elements.
00232    jccl::ConfigElementPtr disp_sys_elt = DisplayManager::instance()->getDisplaySystemElement();
00233    jccl::ConfigElementPtr display_elt = _display->getConfigElement();
00234 
00235    mPipe = _display->getPipe();
00236    vprASSERT(mPipe >= 0);
00237 
00238    window_title = CFStringCreateWithCString(NULL, _display->getName().c_str(), kCFStringEncodingMacRoman);
00239 
00240    mIsEventSource = display_elt->getProperty<bool>("act_as_event_source");
00241    // if should act as an event source
00242    if ( true == mIsEventSource )
00243    {
00244       vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00245          << "vrj::GlWindowOSX::config(): We will be an event source\n"
00246          << vprDEBUG_FLUSH;
00247 
00248       // Configure keyboard device portion
00249       jccl::ConfigElementPtr event_win_element =
00250          display_elt->getProperty<jccl::ConfigElementPtr>("event_window_device");
00251 
00252       // Set the name of the element to the same as the parent element (so we
00253       // can point at it).
00254       //event_win_element->setProperty("name", display_elt->getName();
00255 
00256       bool test = gadget::EventWindowOSX::config(event_win_element);
00257 
00258       if (test == false)
00259       {
00260          vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CRITICAL_LVL)
00261             << "vrj::GlWindowOSX::config(): Failed to configure gadget::EventWindowOSX\n"
00262             << vprDEBUG_FLUSH;
00263       }
00264 
00265       // Custom configuration These proably do not matter
00266       //gadget::EventWindowOSX::m_width = GlWindowXWin::mWindowWidth;
00267       //gadget::EventWindowOSX::m_height = GlWindowXWin::mWindowHeight;
00268 
00269       //mWeOwnTheWindow = false;      // Event window device does not own window
00270    }
00271 
00272 
00273 }

OSStatus vrj::GlWindowOSX::BuildGLFromWindow ( WindowPtr  pWindow,
AGLContext *  paglContext,
structGLWindowInfo pcontextInfo 
) [protected]

Definition at line 296 of file GlWindowOSX.cpp.

References BuildGLonWindow().

Referenced by open().

00299 {
00300    if (!pWindow)
00301       return paramErr;
00302    return BuildGLonWindow(pWindow, paglContext, pcontextInfo);
00303 }

OSStatus vrj::GlWindowOSX::BuildGLonWindow ( WindowPtr  pWindow,
AGLContext *  paglContext,
structGLWindowInfo pcontextInfo 
) [protected]

Definition at line 305 of file GlWindowOSX.cpp.

References structGLWindowInfo::aglAttributes, aglReportError(), CheckAllDeviceRenderers(), CheckRenderer(), structGLWindowInfo::fAcceleratedMust, structGLWindowInfo::fDraggable, FindGDHandleFromWindow(), structGLWindowInfo::fmt, ReportError(), structGLWindowInfo::textureRAM, and structGLWindowInfo::VRAM.

Referenced by BuildGLFromWindow().

00308 {
00309    GDHandle hGD = NULL;
00310    short numDevices;
00311    GLint depthSizeSupport;
00312    OSStatus err = noErr;
00313 
00314    if (!pWindow || !pcontextInfo)
00315    {
00316       ReportError ("NULL parameter passed to BuildGLonDrawable.");
00317       return paramErr;
00318    }
00319 
00320    // check renderere VRAM and acceleration
00321    numDevices = FindGDHandleFromWindow (pWindow, &hGD);
00322    // so what do we do here?
00323    if (!pcontextInfo->fDraggable)    // if numDevices > 1 then we will only be using the software renderer otherwise check only window device
00324    {
00325       if ((numDevices > 1) || (numDevices == 0)) // this window spans mulitple devices thus will be software only
00326       {
00327          // software renderer
00328          // infinite VRAM, infinite textureRAM, not accelerated
00329          if (pcontextInfo->fAcceleratedMust)
00330          {
00331             ReportError ("Unable to accelerate window that spans multiple devices");
00332             return err;
00333          }
00334       }
00335       else // not draggable on single device
00336       {
00337          if (!CheckRenderer (hGD, &(pcontextInfo->VRAM), &(pcontextInfo->textureRAM), &depthSizeSupport, pcontextInfo->fAcceleratedMust))
00338          {
00339             ReportError ("Renderer check failed");
00340             return err;
00341          }
00342       }
00343    }
00344    // else draggable so must check all for support (each device should have at least one renderer that meets the requirements)
00345    else if (!CheckAllDeviceRenderers (&(pcontextInfo->VRAM), &(pcontextInfo->textureRAM), &depthSizeSupport, pcontextInfo->fAcceleratedMust))
00346    {
00347       ReportError ("Renderer check failed");
00348       return err;
00349    }
00350 
00351    // do agl
00352    if ((Ptr) kUnresolvedCFragSymbolAddress == (Ptr) aglChoosePixelFormat) // check for existance of OpenGL
00353    {
00354       ReportError ("OpenGL not installed");
00355       return NULL;
00356    }
00357    // we successfully passed the renderer check
00358 
00359    if ((!pcontextInfo->fDraggable && (numDevices == 1)))  // not draggable on a single device
00360       pcontextInfo->fmt = aglChoosePixelFormat (&hGD, 1, pcontextInfo->aglAttributes); // get an appropriate pixel format
00361    else
00362       pcontextInfo->fmt = aglChoosePixelFormat (NULL, 0, pcontextInfo->aglAttributes); // get an appropriate pixel format
00363 
00364    aglReportError();
00365 
00366    if (NULL == pcontextInfo->fmt)
00367    {
00368       ReportError("Could not find valid pixel format");
00369       return NULL;
00370    }
00371 
00372    // using a default method of sharing all the contexts enables texture sharing across these contexts by default
00373    *paglContext = aglCreateContext (pcontextInfo->fmt, aglShareContext);            // Create an AGL context
00374    aglReportError ();
00375    if (NULL == *paglContext)
00376    {
00377       ReportError ("Could not create context");
00378       return NULL;
00379    }
00380    if (aglShareContext == NULL)
00381       aglShareContext = *paglContext;
00382 
00383    if (!aglSetDrawable (*paglContext, GetWindowPort (pWindow))) // attach the CGrafPtr to the context
00384       return aglReportError ();
00385 
00386    if(!aglSetCurrentContext (*paglContext)) // make the context the current context
00387       return aglReportError ();
00388 
00389    return err;
00390 }

OSStatus vrj::GlWindowOSX::DestroyGLFromWindow ( AGLContext *  paglContext,
structGLWindowInfo pcontextInfo 
) [protected]

Definition at line 398 of file GlWindowOSX.cpp.

References aglReportError(), and structGLWindowInfo::fmt.

Referenced by close(), and open().

00400 {
00401     OSStatus err;
00402 
00403     if ((!paglContext) || (!*paglContext))
00404         return paramErr; // not a valid context
00405     glFinish ();
00406     aglSetCurrentContext (NULL);
00407     err = aglReportError ();
00408     aglSetDrawable (*paglContext, NULL);
00409     err = aglReportError ();
00410     aglDestroyContext (*paglContext);
00411     err = aglReportError ();
00412     *paglContext = NULL;
00413 
00414     if (pcontextInfo->fmt)
00415     {
00416         aglDestroyPixelFormat (pcontextInfo->fmt); // pixel format is no longer valid
00417         err = aglReportError ();
00418     }
00419     pcontextInfo->fmt = 0;
00420 
00421     return err;
00422 }

short vrj::GlWindowOSX::FindGDHandleFromWindow ( WindowPtr  pWindow,
GDHandle *  phgdOnThisDevice 
) [protected]

Definition at line 424 of file GlWindowOSX.cpp.

Referenced by BuildGLonWindow().

00426 {
00427    GrafPtr pgpSave;
00428    Rect rectWind, rectSect;
00429    long greatestArea, sectArea;
00430    short numDevices = 0;
00431    GDHandle hgdNthDevice;
00432 
00433    if (!pWindow || !phgdOnThisDevice)
00434       return NULL;
00435 
00436    *phgdOnThisDevice = NULL;
00437 
00438    GetPort (&pgpSave);
00439    SetPortWindowPort (pWindow);
00440 
00441 #if TARGET_API_MAC_CARBON
00442    GetWindowPortBounds (pWindow, &rectWind);
00443 #else
00444    rectWind = pWindow->portRect;
00445 #endif // TARGET_API_MAC_CARBON
00446    LocalToGlobal ((Point*)& rectWind.top);   // convert to global coordinates
00447    LocalToGlobal ((Point*)& rectWind.bottom);
00448    hgdNthDevice = GetDeviceList ();
00449    greatestArea = 0;
00450    // check window against all gdRects in gDevice list and remember
00451    //  which gdRect contains largest area of window}
00452    while (hgdNthDevice)
00453    {
00454       if (TestDeviceAttribute (hgdNthDevice, screenDevice))
00455          if (TestDeviceAttribute (hgdNthDevice, screenActive))
00456          {
00457             // The SectRect routine calculates the intersection
00458             //  of the window rectangle and this gDevice
00459             //  rectangle and returns TRUE if the rectangles intersect,
00460             //  FALSE if they don't.
00461             SectRect (&rectWind, &(**hgdNthDevice).gdRect, &rectSect);
00462             // determine which screen holds greatest window area
00463             //  first, calculate area of rectangle on current device
00464             sectArea = (long) (rectSect.right - rectSect.left) * (rectSect.bottom - rectSect.top);
00465             if (sectArea > 0)
00466                numDevices++;
00467             if (sectArea > greatestArea)
00468             {
00469                greatestArea = sectArea; // set greatest area so far
00470                *phgdOnThisDevice = hgdNthDevice; // set zoom device
00471             }
00472             hgdNthDevice = GetNextDevice(hgdNthDevice);
00473          }
00474    }
00475 
00476    SetPort (pgpSave);
00477    return numDevices;
00478 }

Boolean vrj::GlWindowOSX::CheckRenderer ( GDHandle  hGD,
long *  VRAM,
long *  textureRAM,
GLint *  ,
Boolean  fAccelMust 
) [protected]

Definition at line 496 of file GlWindowOSX.cpp.

References aglReportError(), and ReportError().

Referenced by BuildGLonWindow().

00500 {
00501    AGLRendererInfo info, head_info;
00502    GLint inum;
00503    GLint dAccel = 0;
00504    GLint dVRAM = 0, dMaxVRAM = 0;
00505    Boolean canAccel = false, found = false;
00506    head_info = aglQueryRendererInfo(&hGD, 1);
00507    aglReportError ();
00508    if(!head_info)
00509    {
00510       ReportError ("aglQueryRendererInfo error");
00511       return false;
00512    }
00513    else
00514    {
00515       info = head_info;
00516       inum = 0;
00517       // see if we have an accelerated renderer, if so ignore non-accelerated ones
00518       // this prevents returning info on software renderer when actually we'll get the hardware one
00519       while (info)
00520       {
00521          aglDescribeRenderer(info, AGL_ACCELERATED, &dAccel);
00522          aglReportError ();
00523          if (dAccel)
00524             canAccel = true;
00525          info = aglNextRendererInfo(info);
00526          aglReportError ();
00527          inum++;
00528       }
00529 
00530       info = head_info;
00531       inum = 0;
00532       while (info)
00533       {
00534          aglDescribeRenderer (info, AGL_ACCELERATED, &dAccel);
00535          aglReportError ();
00536          // if we can accel then we will choose the accelerated renderer
00537          // how about compliant renderers???
00538          if ((canAccel && dAccel) || (!canAccel && (!fAccelMust || dAccel)))
00539          {
00540             aglDescribeRenderer (info, AGL_VIDEO_MEMORY, &dVRAM);   // we assume that VRAM returned is total thus add texture and VRAM required
00541             aglReportError ();
00542             if (dVRAM >= (*pVRAM + *pTextureRAM))
00543             {
00544                if (dVRAM >= dMaxVRAM) // find card with max VRAM
00545                {
00546                   aglDescribeRenderer (info, AGL_DEPTH_MODES, pDepthSizeSupport);   // which depth buffer modes are supported
00547                   aglReportError ();
00548                   dMaxVRAM = dVRAM; // store max
00549                   found = true;
00550                }
00551             }
00552          }
00553          info = aglNextRendererInfo(info);
00554          aglReportError ();
00555          inum++;
00556       }
00557    }
00558    aglDestroyRendererInfo(head_info);
00559    if (found) // if we found a card that has enough VRAM and meets the accel criteria
00560    {
00561       *pVRAM = dMaxVRAM; // return VRAM
00562       return true;
00563    }
00564    // VRAM will remain to same as it did when sent in
00565    return false;
00566 }

Boolean vrj::GlWindowOSX::CheckAllDeviceRenderers ( long *  pVRAM,
long *  pTextureRAM,
GLint *  pDepthSizeSupport,
Boolean  fAccelMust 
) [protected]

Definition at line 585 of file GlWindowOSX.cpp.

References aglReportError(), and ReportError().

Referenced by BuildGLonWindow().

00588 {
00589    AGLRendererInfo info, head_info;
00590    GLint inum;
00591    GLint dAccel = 0;
00592    GLint dVRAM = 0, dMaxVRAM = 0;
00593    Boolean canAccel = false, found = false, goodCheck = true; // can the renderer accelerate, did we find a valid renderer for the device, are we still successfully on all the devices looked at
00594    long MinVRAM = 0x8FFFFFFF; // max long
00595    GDHandle hGD;
00596 
00597    hGD = GetDeviceList (); // get the first screen
00598    while (hGD && goodCheck)
00599    {
00600       head_info = aglQueryRendererInfo(&hGD, 1);
00601       aglReportError ();
00602       if(!head_info)
00603       {
00604          ReportError ("aglQueryRendererInfo error");
00605          return false;
00606       }
00607       else
00608       {
00609          info = head_info;
00610          inum = 0;
00611          // see if we have an accelerated renderer, if so ignore non-accelerated ones
00612          // this prevents returning info on software renderer when actually we'll get the hardware one
00613          while (info)
00614          {
00615                 aglDescribeRenderer(info, AGL_ACCELERATED, &dAccel);
00616             aglReportError ();
00617             if (dAccel)
00618                canAccel = true;
00619             info = aglNextRendererInfo(info);
00620             aglReportError ();
00621             inum++;
00622          }
00623 
00624          info = head_info;
00625          inum = 0;
00626          while (info)
00627          {
00628             aglDescribeRenderer(info, AGL_ACCELERATED, &dAccel);
00629             aglReportError ();
00630             // if we can accel then we will choose the accelerated renderer
00631             // how about compliant renderers???
00632             if ((canAccel && dAccel) || (!canAccel && (!fAccelMust || dAccel)))
00633             {
00634                     aglDescribeRenderer(info, AGL_VIDEO_MEMORY, &dVRAM);   // we assume that VRAM returned is total thus add texture and VRAM required
00635                aglReportError ();
00636                if (dVRAM >= (*pVRAM + *pTextureRAM))
00637                {
00638                   if (dVRAM >= dMaxVRAM) // find card with max VRAM
00639                   {
00640                      aglDescribeRenderer(info, AGL_DEPTH_MODES, pDepthSizeSupport);   // which depth buffer modes are supported
00641                      aglReportError ();
00642                      dMaxVRAM = dVRAM; // store max
00643                      found = true;
00644                   }
00645                }
00646             }
00647             info = aglNextRendererInfo(info);
00648             aglReportError ();
00649             inum++;
00650          }
00651       }
00652       aglDestroyRendererInfo(head_info);
00653       if (found) // if we found a card that has enough VRAM and meets the accel criteria
00654       {
00655          if (MinVRAM > dMaxVRAM)
00656             MinVRAM = dMaxVRAM; // return VRAM
00657 
00658       }
00659       else
00660          goodCheck = false; // one device failed thus entire requirement fails
00661       hGD = GetNextDevice (hGD); // get next device
00662    } // while
00663    if (goodCheck) // we check all devices and each was good
00664    {
00665       *pVRAM = MinVRAM; // return VRAM
00666       return true;
00667    }
00668    return false; //at least one device failed to have mins
00669 }

void vrj::GlWindowOSX::ReportError ( const char *  strError  )  [protected]

Definition at line 671 of file GlWindowOSX.cpp.

Referenced by aglReportError(), BuildGLonWindow(), CheckAllDeviceRenderers(), and CheckRenderer().

00672 {
00673    char errMsgCStr [256];
00674    Str255 strErr = "\0";
00675 
00676    sprintf (errMsgCStr, "%s", strError);
00677 
00678    // out as debug string
00679 #ifdef kVerboseErrors
00680 #ifdef kQuake3
00681       ri.Printf( PRINT_ALL, errMsgCStr);
00682 #else
00683       // ensure we are faded in
00684       if (gDSpStarted)
00685          DSpContext_CustomFadeGammaIn (NULL, NULL, 0);
00686       CStrToPStr (strErr, errMsgCStr);
00687       DebugStr (strErr);
00688 #endif //  kQuake3
00689 #endif // kVerboseErrors
00690 }

GLenum vrj::GlWindowOSX::aglReportError ( void   )  [protected]

Definition at line 692 of file GlWindowOSX.cpp.

References ReportError().

Referenced by BuildGLonWindow(), CheckAllDeviceRenderers(), CheckRenderer(), and DestroyGLFromWindow().

00692                                     {
00693    GLenum err = aglGetError();
00694    if (AGL_NO_ERROR != err)
00695       ReportError ((char *)aglErrorString(err));
00696 
00697    return err;
00698 }


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:58:21 2007 for VR Juggler by  doxygen 1.5.1