00001 /* 00002 Copyright (c) 2010, The Barbarian Group 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that 00006 the following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, this list of conditions and 00009 the following disclaimer. 00010 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 00011 the following disclaimer in the documentation and/or other materials provided with the distribution. 00012 00013 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 00014 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00015 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00016 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00017 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00018 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00019 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00020 POSSIBILITY OF SUCH DAMAGE. 00021 */ 00022 00023 #pragma once 00024 00025 #include "cinder/Cinder.h" 00026 #include "cinder/gl/gl.h" // necessary to give GLee the jump on Cocoa.h 00027 #include "cinder/Surface.h" 00028 #include "cinder/Display.h" 00029 00030 #if defined( CINDER_MAC ) 00031 #if defined __OBJC__ 00032 @class AppImplCocoaRendererQuartz; 00033 @class AppImplCocoaRendererGl; 00034 @class NSView; 00035 #else 00036 class AppImplCocoaRendererQuartz; 00037 class AppImplCocoaRendererGl; 00038 class NSView; 00039 #endif 00040 #elif defined( CINDER_COCOA_TOUCH ) 00041 #if defined __OBJC__ 00042 typedef struct CGContext * CGContextRef; 00043 @class AppImplCocoaTouchRendererGl; 00044 @class AppImplCocoaTouchRendererQuartz; 00045 @class UIView; 00046 #else 00047 typedef struct CGContext * CGContextRef; 00048 class AppImplCocoaTouchRendererGl; 00049 class AppImplCocoaTouchRendererQuartz; 00050 class UIView; 00051 #endif 00052 #endif 00053 00054 00055 namespace cinder { namespace app { 00056 00057 class App; 00058 00059 class Renderer { 00060 public: 00061 virtual ~Renderer() {}; 00062 #if defined( CINDER_COCOA ) 00063 #if defined( CINDER_MAC ) 00064 virtual void setup( App *aApp, CGRect frame, NSView *cinderView ) = 0; 00065 virtual CGContextRef getCgContext() { throw; } // the default behavior is failure 00066 virtual CGLContextObj getCglContext() { throw; } // the default behavior is failure 00067 virtual CGLPixelFormatObj getCglPixelFormat() { throw; } // the default behavior is failure 00068 #elif defined( CINDER_COCOA_TOUCH ) 00069 virtual void setup( App *aApp, const Area &frame, UIView *cinderView ) = 0; 00070 virtual bool isEaglLayer() const { return false; } 00071 #endif 00072 00073 virtual void setFrameSize( int width, int height ) {} 00074 00075 virtual void makeCurrentContext() = 0; 00076 #elif defined( CINDER_MSW ) 00077 virtual void setup( App *aApp, HWND wnd, HDC dc ) = 0; 00078 00079 virtual void prepareToggleFullScreen() {} 00080 virtual void finishToggleFullScreen() {} 00081 virtual void kill() {} 00082 00083 virtual HWND getHwnd() = 0; 00084 virtual HDC getDc() { throw; } // the default behavior is failure 00085 #endif 00086 00087 virtual Surface copyWindowSurface( const Area &area ) = 0; 00088 00089 virtual void startDraw() {} 00090 virtual void finishDraw() {} 00091 virtual void defaultResize() {} 00092 00093 protected: 00094 App *mApp; 00095 }; 00096 00097 class RendererGl : public Renderer { 00098 public: 00099 RendererGl(); 00100 RendererGl( int aAntiAliasing ); 00101 ~RendererGl(); 00102 00103 #if defined( CINDER_COCOA ) 00104 #if defined( CINDER_MAC ) 00105 virtual void setup( App *aApp, CGRect frame, NSView *cinderView ); 00106 virtual CGLContextObj getCglContext(); 00107 virtual CGLPixelFormatObj getCglPixelFormat(); 00108 #elif defined( CINDER_COCOA_TOUCH ) 00109 virtual void setup( App *aApp, const Area &frame, UIView *cinderView ); 00110 virtual bool isEaglLayer() const { return true; } 00111 #endif 00112 virtual void setFrameSize( int width, int height ); 00113 virtual void makeCurrentContext(); 00114 #elif defined( CINDER_MSW ) 00115 virtual void setup( App *aApp, HWND wnd, HDC dc ); 00116 virtual void kill(); 00117 virtual HWND getHwnd() { return mWnd; } 00118 virtual void prepareToggleFullScreen(); 00119 virtual void finishToggleFullScreen(); 00120 #endif 00121 00122 enum { AA_NONE = 0, AA_MSAA_2, AA_MSAA_4, AA_MSAA_6, AA_MSAA_8, AA_MSAA_16, AA_MSAA_32 }; 00123 static const int sAntiAliasingSamples[]; 00124 void setAntiAliasing( int aAntiAliasing ); 00125 int getAntiAliasing() const { return mAntiAliasing; } 00126 00127 virtual void startDraw(); 00128 virtual void finishDraw(); 00129 virtual void defaultResize(); 00130 virtual Surface copyWindowSurface( const Area &area ); 00131 00132 protected: 00133 int mAntiAliasing; 00134 #if defined( CINDER_MAC ) 00135 AppImplCocoaRendererGl *mImpl; 00136 #elif defined( CINDER_COCOA_TOUCH ) 00137 AppImplCocoaTouchRendererGl *mImpl; 00138 #elif defined( CINDER_MSW ) 00139 class AppImplMswRendererGl *mImpl; 00140 HWND mWnd; 00141 #endif 00142 }; 00143 00144 #if defined( CINDER_COCOA ) 00145 class Renderer2d : public Renderer { 00146 public: 00147 #if defined( CINDER_COCOA_TOUCH ) 00148 virtual void setup( App *aApp, const Area &frame, UIView *cinderView ); 00149 #else 00150 ~Renderer2d(); 00151 virtual void setup( App *aApp, CGRect frame, NSView *cinderView ); 00152 #endif 00153 00154 virtual CGContextRef getCgContext(); 00155 00156 virtual void startDraw(); 00157 virtual void finishDraw(); 00158 virtual void setFrameSize( int width, int height ); 00159 virtual void defaultResize(); 00160 virtual void makeCurrentContext(); 00161 virtual Surface copyWindowSurface( const Area &area ); 00162 protected: 00163 #if defined( CINDER_MAC ) 00164 AppImplCocoaRendererQuartz *mImpl; 00165 #else 00166 AppImplCocoaTouchRendererQuartz *mImpl; 00167 #endif 00168 CGContextRef mCGContext; 00169 }; 00170 00171 #elif defined( CINDER_MSW ) 00172 00173 class Renderer2d : public Renderer { 00174 public: 00175 Renderer2d( bool doubleBuffer = true ); 00176 00177 virtual void setup( App *aApp, HWND wnd, HDC dc ); 00178 virtual void kill(); 00179 00180 virtual HWND getHwnd() { return mWnd; } 00181 virtual HDC getDc(); 00182 00183 virtual void prepareToggleFullScreen(); 00184 virtual void finishToggleFullScreen(); 00185 00186 virtual void startDraw(); 00187 virtual void finishDraw(); 00188 virtual void defaultResize(); 00189 virtual Surface copyWindowSurface( const Area &area ); 00190 00191 protected: 00192 class AppImplMswRendererGdi *mImpl; 00193 00194 bool mDoubleBuffer; 00195 HWND mWnd; 00196 HDC mDC; 00197 }; 00198 00199 #endif 00200 00201 } } // namespace cinder::app