/*
Copyright 2005-2011 Intel Corporation. All Rights Reserved.
This file is part of Threading Building Blocks.
Threading Building Blocks is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
Threading Building Blocks is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Threading Building Blocks; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
As a special exception, you may use this file as part of a free software
library without restriction. Specifically, if other files instantiate
templates or use macros or inline functions from this file, or you compile
this file and link it with other files to produce an executable, this
file does not by itself cause the resulting executable to be covered by
the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.
*/
/*
* Based on "OpenGL Image" example from http://developer.apple.com/samplecode/OpenGL_Image/
*/
#include "video.h"
#include <sched.h>
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <AvailabilityMacros.h>
#undef DEPRECATED_ATTRIBUTE
#define DEPRECATED_ATTRIBUTE
#include <Carbon/Carbon.h>
#include <AGL/agl.h>
#include <OpenGL/gl.h> // for OpenGL API
#include <OpenGL/glext.h> // for OpenGL extension support
unsigned int * g_pImg = 0;
int g_sizex, g_sizey;
WindowRef g_window = 0;
static video * g_video = 0;
static int g_fps = 0;
struct timeval g_time;
static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
static OSStatus AppEventHandler( EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon );
WindowRef HandleNew();
static OSStatus WindowEventHandler( EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon );
static IBNibRef sNibRef;
//--------------------------------------------------------------------------------------------
// structure for creating a fullscreen context
struct structGLInfo // storage for setup info
{
SInt16 width; // input: width of drawable (screen width in full screen mode), return: actual width allocated
SInt16 height; // input: height of drawable (screen height in full screen mode), return: actual height allocated
UInt32 pixelDepth; // input: requested pixel depth
Boolean fDepthMust; // input: pixel depth must be set (if false then current depth will be used if able)
Boolean fAcceleratedMust; // input: must renderer be accelerated?
GLint aglAttributes[64]; // input: pixel format attributes always required (reset to what was actually allocated)
SInt32 VRAM; // input: minimum VRAM; output: actual (if successful otherwise input)
SInt32 textureRAM; // input: amount of texture RAM required on card; output: same (used in allcoation to ensure enough texture
AGLPixelFormat fmt; // input: none; output pixel format...
};
typedef struct structGLInfo structGLInfo;
typedef struct structGLInfo * pstructGLInfo;
// structure for creating a context from a window
struct structGLWindowInfo // storage for setup info
{
Boolean fAcceleratedMust; // input: must renderer be accelerated?
GLint aglAttributes[64]; // input: pixel format attributes always required (reset to what was actually allocated)
SInt32 VRAM; // input: minimum VRAM; output: actual (if successful otherwise input)
SInt32 textureRAM; // input: amount of texture RAM required on card; output: same (used in allcoation to ensure enough texture
AGLPixelFormat fmt; // input: none; output pixel format...
Boolean fDraggable; // input: is window going to be draggable,
// if so renderer check (accel, VRAM, textureRAM) will look at all renderers vice just the current one
// if window is not draggable renderer check will either check the single device or short
// circuit to software if window spans multiple devices
// software renderer is consider to have unlimited VRAM, unlimited textureRAM and to not be accelerated
};
typedef struct structGLWindowInfo structGLWindowInfo;
typedef struct structGLWindowInfo * pstructGLWindowInfo;
//--------------------------------------------------------------------------------------------
struct recGLCap // structure to store minimum OpenGL capabilites across all displays and GPUs
{
Boolean f_ext_texture_rectangle; // is texture rectangle extension supported
Boolean f_ext_client_storage; // is client storage extension supported
Boolean f_ext_packed_pixel; // is packed pixel extension supported
Boolean f_ext_texture_edge_clamp; // is SGI texture edge clamp extension supported
Boolean f_gl_texture_edge_clamp; // is OpenGL texture edge clamp support (1.2+)
unsigned long edgeClampParam; // the param that is passed to the texturing parmeteres
long maxTextureSize; // the minimum max texture size across all GPUs
long maxNOPTDTextureSize; // the minimum max texture size across all GPUs that support non-power of two texture dimensions
};
typedef struct recGLCap recGLCap;
typedef recGLCap * pRecGLCap;
struct recImage // OpenGL and image information associated with each window
{
// genric OpenGL stuff
structGLWindowInfo glInfo; // gl info used with SetupGL to build context
AGLContext aglContext; // the OpenGL context (read: state)
GLuint fontList; // the display list storing the bitmap font created for the context to display info
Boolean fAGPTexturing; // 10.1+ only: texture from AGP memory without loading to GPU
// texture display stuff
Boolean fNPOTTextures; // are we using Non-Power Of Two (NPOT) textures?
Boolean fTileTextures; // are multiple tiled textures used to display image?
Boolean fOverlapTextures; // do tiled textures overlapped to create correct filtering between tiles? (only applies if using tiled textures)
Boolean fClientTextures; // 10.1+ only: texture from client memory
unsigned char * pImageBuffer; // image buffer that contains data for image (disposed after loading into texture if not using client textures)
long imageWidth; // height of orginal image
long imageHeight; // width of orginal image
float imageAspect; // width / height or aspect ratio of orginal image
long imageDepth; // depth of image (after loading into gworld, will be either 32 or 16 bits)
long textureX; // number of horizontal textures
long textureY; // number of vertical textures
long maxTextureSize; // max texture size for image
GLuint * pTextureName; // array for texture names (# = textureX * textureY)
long textureWidth; // total width of texels with cover image (including any border on image, but not internal texture overlaps)
long textureHeight; // total height of texels with cover image (including any border on image, but not internal texture overlaps)
float zoomX; // zoom from on texel = one pixel is 1.0
float zoomY; // zoom from on texel = one pixel is 1.0
};
typedef struct recImage recImage; // typedef for easy declaration
typedef recImage * pRecImage; // pointer type
// ==================================
// public function declarations -------------------------------------
// Destro