Cinder

  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

include/cinder/app/Renderer.h

Go to the documentation of this file.
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 Renderer {
00058  public:
00059     virtual ~Renderer() {};
00060 #if defined( CINDER_COCOA )
00061     #if defined( CINDER_MAC )
00062         virtual void    setup( class App *aApp, CGRect frame, NSView *cinderView ) = 0; 
00063         virtual CGContextRef            getCgContext() { throw; } // the default behavior is failure
00064         virtual CGLContextObj           getCglContext() { throw; } // the default behavior is failure
00065         virtual CGLPixelFormatObj       getCglPixelFormat() { throw; } // the default behavior is failure
00066     #elif defined( CINDER_COCOA_TOUCH )
00067         virtual void    setup( class App *aApp, const Area &frame, UIView *cinderView ) = 0;
00068         virtual bool    isEaglLayer() const { return false; }
00069     #endif
00070 
00071     virtual void    setFrameSize( int width, int height ) {}        
00072 
00073     virtual void                    makeCurrentContext() = 0;
00074 #elif defined( CINDER_MSW )
00075     virtual void setup( class App *aApp, HWND wnd, HDC dc ) = 0;
00076 
00077     virtual void prepareToggleFullScreen() {}
00078     virtual void finishToggleFullScreen() {}
00079     virtual void kill() {}
00080 
00081     virtual HWND                getHwnd() = 0;
00082     virtual HDC                 getDc() { throw; } // the default behavior is failure
00083 #endif
00084 
00085     virtual Surface copyWindowSurface( const Area &area ) = 0;
00086 
00087     virtual void startDraw() {}
00088     virtual void finishDraw() {}        
00089     virtual void defaultResize() {}
00090 
00091  protected:
00092     class App           *mApp;
00093 };
00094 
00095 class RendererGl : public Renderer {
00096  public:
00097     RendererGl();
00098     RendererGl( int aAntiAliasing );
00099     ~RendererGl();
00100  
00101 #if defined( CINDER_COCOA )
00102     #if defined( CINDER_MAC )
00103         virtual void setup( App *aApp, CGRect frame, NSView *cinderView );
00104         virtual CGLContextObj           getCglContext();
00105         virtual CGLPixelFormatObj       getCglPixelFormat();
00106     #elif defined( CINDER_COCOA_TOUCH )
00107         virtual void setup( App *aApp, const Area &frame, UIView *cinderView );
00108         virtual bool    isEaglLayer() const { return true; }
00109     #endif
00110     virtual void    setFrameSize( int width, int height );          
00111     virtual void    makeCurrentContext();
00112 #elif defined( CINDER_MSW )
00113     virtual void    setup( App *aApp, HWND wnd, HDC dc );
00114     virtual void    kill();
00115     virtual HWND    getHwnd() { return mWnd; }
00116     virtual void    prepareToggleFullScreen();
00117     virtual void    finishToggleFullScreen();
00118 #endif
00119 
00120     enum    { AA_NONE = 0, AA_MSAA_2, AA_MSAA_4, AA_MSAA_6, AA_MSAA_8, AA_MSAA_16, AA_MSAA_32 };
00121     static const int    sAntiAliasingSamples[];
00122     void                setAntiAliasing( int aAntiAliasing );
00123     int                 getAntiAliasing() const { return mAntiAliasing; }
00124 
00125     virtual void    startDraw();
00126     virtual void    finishDraw();
00127     virtual void    defaultResize();
00128     virtual Surface copyWindowSurface( const Area &area );
00129     
00130  protected:
00131     int         mAntiAliasing;
00132 #if defined( CINDER_MAC )
00133     AppImplCocoaRendererGl      *mImpl;
00134 #elif defined( CINDER_COCOA_TOUCH )
00135     AppImplCocoaTouchRendererGl     *mImpl;
00136 #elif defined( CINDER_MSW )
00137     class AppImplMswRendererGl  *mImpl;
00138     HWND                        mWnd;
00139 #endif
00140 };
00141 
00142 #if defined( CINDER_COCOA )
00143 class Renderer2d : public Renderer {
00144  public:
00145     #if defined( CINDER_COCOA_TOUCH )
00146         virtual void setup( App *aApp, const Area &frame, UIView *cinderView );
00147     #else
00148         ~Renderer2d();
00149         virtual void setup( App *aApp, CGRect frame, NSView *cinderView );
00150     #endif
00151 
00152     virtual CGContextRef            getCgContext();
00153 
00154     virtual void startDraw();
00155     virtual void finishDraw();
00156     virtual void setFrameSize( int width, int height );
00157     virtual void defaultResize();
00158     virtual void makeCurrentContext();
00159     virtual Surface copyWindowSurface( const Area &area );
00160  protected:
00161 #if defined( CINDER_MAC )
00162     AppImplCocoaRendererQuartz      *mImpl;
00163 #else
00164     AppImplCocoaTouchRendererQuartz     *mImpl;
00165 #endif
00166     CGContextRef                    mCGContext;
00167 };
00168 
00169 #elif defined( CINDER_MSW )
00170 
00171 class Renderer2d : public Renderer {
00172  public:
00173     Renderer2d( bool doubleBuffer = true );
00174     
00175     virtual void setup( App *aApp, HWND wnd, HDC dc );
00176     virtual void kill();
00177     
00178     virtual HWND    getHwnd() { return mWnd; }
00179     virtual HDC     getDc();
00180 
00181     virtual void    prepareToggleFullScreen();
00182     virtual void    finishToggleFullScreen();
00183 
00184     virtual void startDraw();
00185     virtual void finishDraw();
00186     virtual void defaultResize();
00187     virtual Surface copyWindowSurface( const Area &area );
00188     
00189  protected:
00190     class AppImplMswRendererGdi *mImpl;
00191 
00192     bool            mDoubleBuffer;
00193     HWND            mWnd;
00194     HDC             mDC;
00195 };
00196 
00197 #endif
00198 
00199 } } // namespace cinder::app