Shadowrun: Awakened 29 September 2011 - Build 871
Classes | Defines | Typedefs | Functions | Variables
macvideo.cpp File Reference
#include "video.h"
#include <sched.h>
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <AvailabilityMacros.h>
#include <Carbon/Carbon.h>
#include <AGL/agl.h>
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
Include dependency graph for macvideo.cpp:

Go to the source code of this file.

Classes

struct  recGLCap
struct  recImage
struct  structGLInfo
struct  structGLWindowInfo

Defines

#define DEPRECATED_ATTRIBUTE

Typedefs

typedef recGLCappRecGLCap
typedef recImagepRecImage
typedef struct structGLInfopstructGLInfo
typedef struct structGLWindowInfopstructGLWindowInfo
typedef struct recGLCap recGLCap
typedef struct recImage recImage
typedef struct structGLInfo structGLInfo
typedef struct structGLWindowInfo structGLWindowInfo

Functions

OSStatus aglReportError (void)
static OSStatus AppEventHandler (EventHandlerCallRef inCaller, EventRef inEvent, void *inRefcon)
OSStatus BuildGLForWindow (WindowRef window)
static OSStatus BuildGLonWindow (WindowPtr pWindow, AGLContext *paglContext, pstructGLWindowInfo pcontextInfo, AGLContext aglShareContext)
static Boolean CheckAllDeviceRenderers (long *pVRAM, long *pTextureRAM, GLint *pDepthSizeSupport, Boolean fAccelMust)
static Boolean CheckRenderer (GDHandle hGD, long *VRAM, long *textureRAM, GLint *, Boolean fAccelMust)
OSStatus DestroyGLFromWindow (AGLContext *paglContext, pstructGLWindowInfo pcontextInfo)
OSStatus DisposeGLForWindow (WindowRef window)
void DrawGL (WindowRef window)
static void DumpCurrent (AGLDrawable *paglDraw, AGLContext *paglContext, pstructGLInfo pcontextInfo)
short FindGDHandleFromWindow (WindowPtr pWindow, GDHandle *phgdOnThisDevice)
static void FindMinimumOpenGLCapabilities (pRecGLCap pOpenGLCaps)
static long GetNextTextureSize (long textureDimension, long maxTextureSize, Boolean textureRectangle)
static long GetTextureNumFromTextureDim (long textureDimension, long maxTextureSize, Boolean texturesOverlap, Boolean textureRectangle)
OSStatus glReportError (void)
WindowRef HandleNew ()
void ReportError (char *strError)
void ReportErrorNum (char *strError, long numError)
OSStatus ResizeMoveGLWindow (WindowRef window)
static OSStatus WindowEventHandler (EventHandlerCallRef inCaller, EventRef inEvent, void *inRefcon)

Variables

static int g_fps = 0
static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER
unsigned int * g_pImg = 0
int g_sizex
int g_sizey
struct timeval g_time
static videog_video = 0
WindowRef g_window = 0
pRecGLCap gpOpenGLCaps
static IBNibRef sNibRef

Define Documentation

Definition at line 42 of file macvideo.cpp.


Typedef Documentation

typedef recGLCap* pRecGLCap

Definition at line 112 of file macvideo.cpp.

typedef recImage* pRecImage

Definition at line 144 of file macvideo.cpp.

typedef struct structGLInfo* pstructGLInfo

Definition at line 79 of file macvideo.cpp.

Definition at line 96 of file macvideo.cpp.

typedef struct recGLCap recGLCap

Definition at line 111 of file macvideo.cpp.

typedef struct recImage recImage

Definition at line 143 of file macvideo.cpp.

typedef struct structGLInfo structGLInfo

Definition at line 78 of file macvideo.cpp.

Definition at line 95 of file macvideo.cpp.


Function Documentation

OSStatus aglReportError ( void  )

Definition at line 218 of file macvideo.cpp.

References ReportError().

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

{
    GLenum err = aglGetError();
    if (AGL_NO_ERROR != err)
        ReportError ((char *)aglErrorString(err));
    // ensure we are returning an OSStatus noErr if no error condition
    if (err == AGL_NO_ERROR)
        return noErr;
    else
        return (OSStatus) err;
}
static OSStatus AppEventHandler ( EventHandlerCallRef  inCaller,
EventRef  inEvent,
void *  inRefcon 
) [static]

Definition at line 1344 of file macvideo.cpp.

{
    OSStatus    result = eventNotHandledErr;

    return result;
}
OSStatus BuildGLForWindow ( WindowRef  window)
static OSStatus BuildGLonWindow ( WindowPtr  pWindow,
AGLContext *  paglContext,
pstructGLWindowInfo  pcontextInfo,
AGLContext  aglShareContext 
) [static]

Definition at line 484 of file macvideo.cpp.

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

Referenced by BuildGLForWindow().

{
    GDHandle hGD = NULL;
    GrafPtr cgrafSave = NULL;
    short numDevices;
    GLint depthSizeSupport;
    OSStatus err = noErr;
    
    if (!pWindow || !pcontextInfo)
    {
        ReportError ("NULL parameter passed to BuildGLonWindow.");
        return paramErr;
    }
    
    GetPort (&cgrafSave);
    SetPortWindowPort(pWindow);

    // check renderere VRAM and acceleration
    numDevices = FindGDHandleFromWindow (pWindow, &hGD);
    if (!pcontextInfo->fDraggable)     // if numDevices > 1 then we will only be using the software renderer otherwise check only window device
    {
        if ((numDevices > 1) || (numDevices == 0)) // this window spans mulitple devices thus will be software only
        {
            // software renderer
            // infinite VRAM, infinite textureRAM, not accelerated
            if (pcontextInfo->fAcceleratedMust)
            {
                ReportError ("Unable to accelerate window that spans multiple devices");
                return err;
            }
        }
        else // not draggable on single device
        {
            if (!CheckRenderer (hGD, &(pcontextInfo->VRAM), &(pcontextInfo->textureRAM), &depthSizeSupport, pcontextInfo->fAcceleratedMust))
            {
                ReportError ("Renderer check failed");
                return err;
            }
        }
    }
    // else draggable so must check all for support (each device should have at least one renderer that meets the requirements)
    else if (!CheckAllDeviceRenderers (&(pcontextInfo->VRAM), &(pcontextInfo->textureRAM), &depthSizeSupport, pcontextInfo->fAcceleratedMust))
    {
        ReportError ("Renderer check failed");
        return err;
    }
    
    // do agl
    if ((Ptr) kUnresolvedCFragSymbolAddress == (Ptr) aglChoosePixelFormat) // check for existance of OpenGL
    {
        ReportError ("OpenGL not installed");
        return noErr;
    }    
    // we successfully passed the renderer check

    if ((!pcontextInfo->fDraggable && (numDevices == 1)))  // not draggable on a single device
        pcontextInfo->fmt = aglChoosePixelFormat (&hGD, 1, pcontextInfo->aglAttributes); // get an appropriate pixel format
    else
        pcontextInfo->fmt = aglChoosePixelFormat (NULL, 0, pcontextInfo->aglAttributes); // get an appropriate pixel format
    aglReportError ();
    if (NULL == pcontextInfo->fmt) 
    {
        ReportError("Could not find valid pixel format");
        return noErr;
    }

    *paglContext = aglCreateContext (pcontextInfo->fmt, aglShareContext); // Create an AGL context
    if (AGL_BAD_MATCH == aglGetError())
        *paglContext = aglCreateContext (pcontextInfo->fmt, 0); // unable to sahre context, create without sharing
    aglReportError ();
    if (NULL == *paglContext) 
    {
        ReportError ("Could not create context");
        return noErr;
    }
    
    if (!aglSetDrawable (*paglContext, GetWindowPort (pWindow))) // attach the CGrafPtr to the context
        return aglReportError ();
    
    if(!aglSetCurrentContext (*paglContext)) // make the context the current context
        return aglReportError ();

    SetPort (cgrafSave);

    return err;
}
static Boolean CheckAllDeviceRenderers ( long *  pVRAM,
long *  pTextureRAM,
GLint *  pDepthSizeSupport,
Boolean  fAccelMust 
) [static]

Definition at line 363 of file macvideo.cpp.

References aglReportError(), and ReportError().

Referenced by BuildGLonWindow().

{
    AGLRendererInfo info, head_info;
    GLint inum;
    GLint dAccel = 0;
    GLint dVRAM = 0, dMaxVRAM = 0;
    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
    long MinVRAM = 0x8FFFFFFF; // max long
    GDHandle hGD = GetDeviceList (); // get the first screen
    while (hGD && goodCheck)
    {
        head_info = aglQueryRendererInfo(&hGD, 1);
        aglReportError ();
        if(!head_info)
        {
            ReportError ("aglQueryRendererInfo error");
            return false;
        }
        else
        {
            info = head_info;
            inum = 0;
            // see if we have an accelerated renderer, if so ignore non-accelerated ones
            // this prevents returning info on software renderer when actually we'll get the hardware one
            while (info)
            {
                aglDescribeRenderer(info, AGL_ACCELERATED, &dAccel);
                aglReportError ();
                if (dAccel)
                    canAccel = true;
                info = aglNextRendererInfo(info);
                aglReportError ();
                inum++;
            }
                
            info = head_info;
            inum = 0;
            while (info)
            {    
                aglDescribeRenderer(info, AGL_ACCELERATED, &dAccel);
                aglReportError ();
                // if we can accel then we will choose the accelerated renderer 
                // how about compliant renderers???
                if ((canAccel && dAccel) || (!canAccel && (!fAccelMust || dAccel)))
                {
                    aglDescribeRenderer(info, AGL_VIDEO_MEMORY, &dVRAM);    // we assume that VRAM returned is total thus add texture and VRAM required
                    aglReportError ();
                    if (dVRAM >= (*pVRAM + *pTextureRAM))
                    {
                        if (dVRAM >= dMaxVRAM) // find card with max VRAM
                        {
                            aglDescribeRenderer(info, AGL_DEPTH_MODES, pDepthSizeSupport);    // which depth buffer modes are supported
                            aglReportError ();
                            dMaxVRAM = dVRAM; // store max
                            found = true;
                        }
                    }
                }
                info = aglNextRendererInfo(info);
                aglReportError ();
                inum++;
            }
        }
        aglDestroyRendererInfo(head_info);
        if (found) // if we found a card that has enough VRAM and meets the accel criteria
        {
            if (MinVRAM > dMaxVRAM)
                MinVRAM = dMaxVRAM; // return VRAM
            
        }
        else
            goodCheck = false; // one device failed thus entire requirement fails
        hGD = GetNextDevice (hGD); // get next device
    } // while
    if (goodCheck) // we check all devices and each was good
    {
        *pVRAM = MinVRAM; // return VRAM
        return true;
    }
    return false; //at least one device failed to have mins
}
static Boolean CheckRenderer ( GDHandle  hGD,
long *  VRAM,
long *  textureRAM,
GLint *  pDepthSizeSupport,
Boolean  fAccelMust 
) [static]

Definition at line 282 of file macvideo.cpp.

References aglReportError(), and ReportError().

Referenced by BuildGLonWindow().

{
    AGLRendererInfo info, head_info;
    GLint inum;
    GLint dAccel = 0;
    GLint dVRAM = 0, dMaxVRAM = 0;
    Boolean canAccel = false, found = false;
    head_info = aglQueryRendererInfo(&hGD, 1);
    aglReportError ();
    if(!head_info)
    {
        ReportError ("aglQueryRendererInfo error");
        return false;
    }
    else
    {
        info = head_info;
        inum = 0;
        // see if we have an accelerated renderer, if so ignore non-accelerated ones
        // this prevents returning info on software renderer when actually we'll get the hardware one
        while (info)
        {    
            aglDescribeRenderer(info, AGL_ACCELERATED, &dAccel);
            aglReportError ();
            if (dAccel)
                canAccel = true;
            info = aglNextRendererInfo(info);
            aglReportError ();
            inum++;
        }
            
        info = head_info;
        inum = 0;
        while (info)
        {
            aglDescribeRenderer (info, AGL_ACCELERATED, &dAccel);
            aglReportError ();
            // if we can accel then we will choose the accelerated renderer 
            // how about compliant renderers???
            if ((canAccel && dAccel) || (!canAccel && (!fAccelMust || dAccel)))
            {
                aglDescribeRenderer (info, AGL_VIDEO_MEMORY, &dVRAM);    // we assume that VRAM returned is total thus add texture and VRAM required
                aglReportError ();
                if (dVRAM >= (*pVRAM + *pTextureRAM))
                {
                    if (dVRAM >= dMaxVRAM) // find card with max VRAM
                    {
                        aglDescribeRenderer (info, AGL_DEPTH_MODES, pDepthSizeSupport);    // which depth buffer modes are supported
                        aglReportError ();
                        dMaxVRAM = dVRAM; // store max
                        found = true;
                    }
                }
            }
            info = aglNextRendererInfo(info);
            aglReportError ();
            inum++;
        }
    }
    aglDestroyRendererInfo(head_info);
    if (found) // if we found a card that has enough VRAM and meets the accel criteria
    {
        *pVRAM = dMaxVRAM; // return VRAM
        return true;
    }
    // VRAM will remain to same as it did when sent in
    return false;
}
OSStatus DestroyGLFromWindow ( AGLContext *  paglContext,
pstructGLWindowInfo  pcontextInfo 
)
OSStatus DisposeGLForWindow ( WindowRef  window)

Referenced by HandleNew().

void DrawGL ( WindowRef  window)
void DumpCurrent ( AGLDrawable *  paglDraw,
AGLContext *  paglContext,
pstructGLInfo  pcontextInfo 
) [static]

Definition at line 454 of file macvideo.cpp.

References aglReportError(), and structGLInfo::fmt.

{
    if (*paglContext)
    {
        aglSetCurrentContext (NULL);
        aglReportError ();
        aglSetDrawable (*paglContext, NULL);
        aglReportError ();
        aglDestroyContext (*paglContext);
        aglReportError ();
        *paglContext = NULL;
    }
    
    if (pcontextInfo->fmt)
    {
        aglDestroyPixelFormat (pcontextInfo->fmt); // pixel format is no longer needed
        aglReportError ();
    }
    pcontextInfo->fmt = 0;

    if (*paglDraw) // do not destory a window on DSp since there is no window built in X
        DisposeWindow (GetWindowFromPort (*paglDraw));
    *paglDraw = NULL;
}
short FindGDHandleFromWindow ( WindowPtr  pWindow,
GDHandle *  phgdOnThisDevice 
)

Referenced by BuildGLonWindow().

static void FindMinimumOpenGLCapabilities ( pRecGLCap  pOpenGLCaps) [static]

Definition at line 1090 of file macvideo.cpp.

References recGLCap::edgeClampParam, recGLCap::f_ext_client_storage, recGLCap::f_ext_packed_pixel, recGLCap::f_ext_texture_edge_clamp, recGLCap::f_ext_texture_rectangle, recGLCap::f_gl_texture_edge_clamp, L, recGLCap::maxNOPTDTextureSize, recImage::maxTextureSize, and recGLCap::maxTextureSize.

Referenced by HandleNew().

{
    WindowPtr pWin = NULL; 
    Rect rectWin = {0, 0, 10, 10};
    GLint attrib[] = { AGL_RGBA, AGL_NONE };
    AGLPixelFormat fmt = NULL;
    AGLContext ctx = NULL;
    GLint deviceMaxTextureSize = 0, NPOTDMaxTextureSize = 0;
    
    if (NULL != gpOpenGLCaps)
    {
        // init desired caps to max values
        pOpenGLCaps->f_ext_texture_rectangle = true;
        pOpenGLCaps->f_ext_client_storage = true;
        pOpenGLCaps->f_ext_packed_pixel = true;
        pOpenGLCaps->f_ext_texture_edge_clamp = true;
        pOpenGLCaps->f_gl_texture_edge_clamp = true;
        pOpenGLCaps->maxTextureSize = 0x7FFFFFFF;
        pOpenGLCaps->maxNOPTDTextureSize = 0x7FFFFFFF;

        // build window
        pWin = NewCWindow (0L, &rectWin, NULL, false,
                plainDBox, (WindowPtr) -1L, true, 0L);
                
        // build context
        fmt = aglChoosePixelFormat(NULL, 0, attrib);
        if (fmt)
            ctx = aglCreateContext(fmt, NULL);
        if (ctx)
        {
            GDHandle hgdNthDevice;
            
            aglSetDrawable(ctx, GetWindowPort (pWin));
            aglSetCurrentContext(ctx);
            
            // for each display
            hgdNthDevice = GetDeviceList ();
            while (hgdNthDevice)
            {
                if (TestDeviceAttribute (hgdNthDevice, screenDevice))
                    if (TestDeviceAttribute (hgdNthDevice, screenActive))
                    {
                        // move window to display
                        MoveWindow (pWin, (**hgdNthDevice).gdRect.left + 5, (**hgdNthDevice).gdRect.top + 5, false);
                        aglUpdateContext(ctx);
                        
                        // for each cap (this can obviously be expanded)
                        // if this driver/GPU/display is less capable
                            // save this minimum capability
                        {
                            // get strings
                            enum { kShortVersionLength = 32 };
                            const GLubyte * strVersion = glGetString (GL_VERSION); // get version string
                            const GLubyte * strExtension = glGetString (GL_EXTENSIONS);    // get extension string
                            
                            // get just the non-vendor specific part of version string
                            GLubyte strShortVersion [kShortVersionLength];
                            short i = 0;
                            while ((((strVersion[i] <= '9') && (strVersion[i] >= '0')) || (strVersion[i] == '.')) && (i < kShortVersionLength)) // get only basic version info (until first space)
                                strShortVersion [i] = strVersion[i++];
                            strShortVersion [i] = 0; //truncate string
                            
                            // compare capabilities based on extension string and GL version
                            pOpenGLCaps->f_ext_texture_rectangle = 
                                pOpenGLCaps->f_ext_texture_rectangle && (NULL != strstr ((const char *) strExtension, "GL_EXT_texture_rectangle"));
                            pOpenGLCaps->f_ext_client_storage = 
                                pOpenGLCaps->f_ext_client_storage && (NULL != strstr ((const char *) strExtension, "GL_APPLE_client_storage"));
                            pOpenGLCaps->f_ext_packed_pixel = 
                                pOpenGLCaps->f_ext_packed_pixel && (NULL != strstr ((const char *) strExtension, "GL_APPLE_packed_pixel"));
                            pOpenGLCaps->f_ext_texture_edge_clamp = 
                                pOpenGLCaps->f_ext_texture_edge_clamp && (NULL != strstr ((const char *) strExtension, "GL_SGIS_texture_edge_clamp"));
                            pOpenGLCaps->f_gl_texture_edge_clamp = 
                                pOpenGLCaps->f_gl_texture_edge_clamp && (!strstr ((const char *) strShortVersion, "1.0") && !strstr ((const char *) strShortVersion, "1.1")); // if not 1.0 and not 1.1 must be 1.2 or greater
                            
                            // get device max texture size
                            glGetIntegerv (GL_MAX_TEXTURE_SIZE, &deviceMaxTextureSize);
                            if (deviceMaxTextureSize < pOpenGLCaps->maxTextureSize)
                                pOpenGLCaps->maxTextureSize = deviceMaxTextureSize;
                            // get max size of non-power of two texture on devices which support
                            if (NULL != strstr ((const char *) strExtension, "GL_EXT_texture_rectangle"))
                            {
                            #ifdef GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT
                                glGetIntegerv (GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT, &NPOTDMaxTextureSize);
                                if (NPOTDMaxTextureSize < pOpenGLCaps->maxNOPTDTextureSize)
                                    pOpenGLCaps->maxNOPTDTextureSize = NPOTDMaxTextureSize;
                            #endif
                            }
                        }
                        // next display
                        hgdNthDevice = GetNextDevice(hgdNthDevice);
                    }
            }
            aglDestroyContext( ctx );
        }
        else
        { // could not build context set caps to min
            pOpenGLCaps->f_ext_texture_rectangle = false;
            pOpenGLCaps->f_ext_client_storage = false;
            pOpenGLCaps->f_ext_packed_pixel = false;
            pOpenGLCaps->f_ext_texture_edge_clamp = false;
            pOpenGLCaps->f_gl_texture_edge_clamp = false;
            pOpenGLCaps->maxTextureSize = 0;
        }
        
        // set clamp param based on retrieved capabilities
        if (pOpenGLCaps->f_gl_texture_edge_clamp) // if OpenGL 1.2 or later and texture edge clamp is supported natively
                    pOpenGLCaps->edgeClampParam = GL_CLAMP_TO_EDGE;  // use 1.2+ constant to clamp texture coords so as to not sample the border color
        else if (pOpenGLCaps->f_ext_texture_edge_clamp) // if GL_SGIS_texture_edge_clamp extension supported
            pOpenGLCaps->edgeClampParam = GL_CLAMP_TO_EDGE_SGIS; // use extension to clamp texture coords so as to not sample the border color
        else
            pOpenGLCaps->edgeClampParam = GL_CLAMP; // clamp texture coords to [0, 1]

        aglDestroyPixelFormat( fmt );
        DisposeWindow( pWin );
    }
}
static long GetNextTextureSize ( long  textureDimension,
long  maxTextureSize,
Boolean  textureRectangle 
) [static]

Definition at line 673 of file macvideo.cpp.

References recImage::maxTextureSize.

Referenced by BuildGLForWindow(), and DrawGL().

{
    long targetTextureSize = maxTextureSize; // start at max texture size
    if (textureRectangle)
    {
        if (textureDimension >= targetTextureSize) // the texture dimension is greater than the target texture size (i.e., it fits)
            return targetTextureSize; // return corresponding texture size
        else
            return textureDimension; // jusr return the dimension
    }
    else
    {
        do // while we have txture sizes check for texture value being equal or greater
        {  
            if (textureDimension >= targetTextureSize) // the texture dimension is greater than the target texture size (i.e., it fits)
                return targetTextureSize; // return corresponding texture size
        }
        while (targetTextureSize >>= 1); // step down to next texture size smaller
    }
    return 0; // no textures fit so return zero
}
static long GetTextureNumFromTextureDim ( long  textureDimension,
long  maxTextureSize,
Boolean  texturesOverlap,
Boolean  textureRectangle 
) [static]

Definition at line 701 of file macvideo.cpp.

References recImage::maxTextureSize, and ReportErrorNum().

Referenced by BuildGLForWindow().

{
    // start at max texture size 
    // loop through each texture size, removing textures in turn which are less than the remaining texture dimension
    // each texture has 2 pixels of overlap (one on each side) thus effective texture removed is 2 less than texture size
    
    long i = 0; // initially no textures
    long bitValue = maxTextureSize; // start at max texture size
    long texOverlapx2 = texturesOverlap ? 2 : 0;
    textureDimension -= texOverlapx2; // ignore texture border since we are using effective texure size (by subtracting 2 from the initial size)
    if (textureRectangle)
    {
        // count number of full textures
        while (textureDimension > (bitValue - texOverlapx2)) // while our texture dimension is greater than effective texture size (i.e., minus the border)
        {
            i++; // count a texture
            textureDimension -= bitValue - texOverlapx2; // remove effective texture size
        }
        // add one partial texture
        i++; 
    }
    else
    {
        do
        {
            while (textureDimension >= (bitValue - texOverlapx2)) // while our texture dimension is greater than effective texture size (i.e., minus the border)
            {
                i++; // count a texture
                textureDimension -= bitValue - texOverlapx2; // remove effective texture size
            }
        }
        while ((bitValue >>= 1) > texOverlapx2); // step down to next texture while we are greater than two (less than 4 can't be used due to 2 pixel overlap)
    if (textureDimension > 0x0) // if any textureDimension is left there is an error, because we can't texture these small segments and in anycase should not have image pixels left
        ReportErrorNum ("GetTextureNumFromTextureDim error: Texture to small to draw, should not ever get here, texture size remaining:", textureDimension);
    }
    return i; // return textures counted
} 
OSStatus glReportError ( void  )

Definition at line 234 of file macvideo.cpp.

References ReportError().

Referenced by BuildGLForWindow(), and DrawGL().

{
    GLenum err = glGetError();
    switch (err)
    {
        case GL_NO_ERROR:
            break;
        case GL_INVALID_ENUM:
            ReportError ("GL Error: Invalid enumeration");
            break;
        case GL_INVALID_VALUE:
            ReportError ("GL Error: Invalid value");
            break;
        case GL_INVALID_OPERATION:
            ReportError ("GL Error: Invalid operation");
            break;
        case GL_STACK_OVERFLOW:
            ReportError ("GL Error: Stack overflow");
            break;
        case GL_STACK_UNDERFLOW:
            ReportError ("GL Error: Stack underflow");
            break;
        case GL_OUT_OF_MEMORY:
            ReportError ("GL Error: Out of memory");
            break;
    }
    // ensure we are returning an OSStatus noErr if no error condition
    if (err == GL_NO_ERROR)
        return noErr;
    else
        return (OSStatus) err;
}
WindowRef HandleNew ( )
void ReportError ( char *  strError)

Definition at line 204 of file macvideo.cpp.

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

{
    char errMsgPStr [257];
    
    errMsgPStr[0] = (char)snprintf (errMsgPStr+1, 255, "%s\n", strError); 

    // ensure we are faded in
    DebugStr ( (ConstStr255Param) errMsgPStr );
}
void ReportErrorNum ( char *  strError,
long  numError 
)

Definition at line 192 of file macvideo.cpp.

Referenced by GetTextureNumFromTextureDim(), and ResizeMoveGLWindow().

{
    char errMsgPStr [257];
    
    errMsgPStr[0] = (char)snprintf (errMsgPStr+1, 255, "%s %ld (0x%lx)\n", strError, numError, numError); 

    // ensure we are faded in
    DebugStr ( (ConstStr255Param) errMsgPStr );
}
OSStatus ResizeMoveGLWindow ( WindowRef  window)

Referenced by WindowEventHandler().

static OSStatus WindowEventHandler ( EventHandlerCallRef  inCaller,
EventRef  inEvent,
void *  inRefcon 
) [static]

Definition at line 1210 of file macvideo.cpp.

References BuildGLForWindow(), recImage::imageHeight, recImage::imageWidth, video::on_key(), video::on_mouse(), ResizeMoveGLWindow(), video::running, recImage::zoomX, and recImage::zoomY.

{
    OSStatus    err = eventNotHandledErr;
    WindowRef    window = (WindowRef) inRefcon;

    if( GetEventClass(inEvent) == kEventClassMouse )
    {
        Point mousePoint; // UInt32 modifiers;
        verify_noerr( GetEventParameter(inEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mousePoint) );
        pRecImage pWindowInfo = (pRecImage) GetWRefCon (window); // get the gl info for the window
        if(pWindowInfo) {
            SetPortWindowPort(window);
            GlobalToLocal (&mousePoint); //convert mouse coordinates to local coordintes prior to recording
            mousePoint.h /= pWindowInfo->zoomX; mousePoint.v /= pWindowInfo->zoomY;
            if(mousePoint.h >= 0 && mousePoint.h < pWindowInfo->imageWidth && mousePoint.v >= 0 && mousePoint.v < pWindowInfo->imageHeight)
                g_video->on_mouse(mousePoint.h, mousePoint.v, GetEventKind(inEvent) == kEventMouseUp?-1:1), err = noErr;
        }
    }
    else if( GetEventClass(inEvent) == kEventClassKeyboard )
    {
        char ch;
        verify_noerr( GetEventParameter( inEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof( ch ), NULL, &ch ) );
        if(g_video)
            g_video->on_key(ch);
    }
    else //if( GetEventClass(inEvent) == kEventClassWindow )
    {
        if (GetEventKind(inEvent) == kEventWindowDrawContent)
        {
            //DrawGL(window);
            err = noErr;
        }
        else if (GetEventKind(inEvent) == kEventWindowClose)
        {
            if (window)
            {
                g_video->running = false;
            }
            err = noErr;
        }
        else if (GetEventKind(inEvent) == kEventWindowShowing)
        {
            err = BuildGLForWindow (window);
        }
        else if ((GetEventKind(inEvent) == kEventWindowResizeCompleted) || (GetEventKind(inEvent) == kEventWindowDragCompleted))
        {
            err = ResizeMoveGLWindow (window);
        }
        else if (GetEventKind(inEvent) == kEventWindowZoomed)
        {
            err = ResizeMoveGLWindow (window);
        }
    }
    
    return err;
}

Variable Documentation

int g_fps = 0 [static]

Definition at line 52 of file macvideo.cpp.

pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER [static]

Definition at line 54 of file macvideo.cpp.

unsigned int* g_pImg = 0

Definition at line 48 of file macvideo.cpp.

int g_sizex

Definition at line 49 of file macvideo.cpp.

int g_sizey

Definition at line 49 of file macvideo.cpp.

struct timeval g_time

Definition at line 53 of file macvideo.cpp.

video* g_video = 0 [static]

Definition at line 51 of file macvideo.cpp.

WindowRef g_window = 0

Definition at line 50 of file macvideo.cpp.

Definition at line 171 of file macvideo.cpp.

IBNibRef sNibRef [static]

Definition at line 61 of file macvideo.cpp.

Referenced by HandleNew().


Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net