AaronCameron.net
I care not for your petty politics.
Not a Member? - Login or Create an Account
Wednesday the 23rd of May 2012 @ 08:47am
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cFramebufferDisplay.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library
00003 Copyright (C) 2003  Aaron Cameron
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 
00019 A copy of the GNU Lesser General Public License has been provided with
00020 this library in the file 'COPYING'.
00021 
00022 Contact information for the author of this library has been provided
00023 with this library in the file 'AUTHOR'.
00024 ************************************************************************/
00025 #include "cFramebufferDisplay.h"
00026 #include "SDL.h"
00027 
00028 namespace n2l
00029 {
00030 
00031     /* ********************************************************************** */
00032     cFramebufferDisplay::cFramebufferDisplay(
00033                                 const tUint iWidth,
00034                                 const tUint iHeight,
00035                                 const tUbyte iBpp,
00036                                 const tBool iDoubleBuffered,
00037                                 const tBool iResizeable,
00038                                 const tBool iFullScreen  )
00039     {
00040         if (displayExists())
00041             throw cException(   "cFramebufferDisplay::cFramebufferDisplay",
00042                                 "Only one surface at a time is supported "
00043                                 "destory any existing displays before "
00044                                 "proceeding." );
00045     
00046 
00047         // Bits per pixel
00048         cPixelFormat::tBitCount bpp = iBpp;
00049         // If not set, use the current system display value
00050         if (0==bpp)
00051             bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
00052 
00053         // Build surface properties
00054         cSurfaceProperties newProperties;
00055 
00056         newProperties.setFlags( cSurfaceProperties::SurfaceFlag_SoftwareSurface );
00057         
00058         if (iDoubleBuffered)
00059             newProperties.addFlags( cSurfaceProperties::SurfaceFlag_DoubleBuffered );
00060                     
00061         if (iResizeable)
00062             newProperties.addFlags( cSurfaceProperties::SurfaceFlag_Resizable );
00063 
00064         if (iFullScreen)
00065             newProperties.addFlags( cSurfaceProperties::SurfaceFlag_FullScreen );
00066 
00067         newProperties.setSize( cSurfaceProperties::tSize(iWidth,iHeight) );
00068 
00069 
00070 //      if (!surfaceIsSupported(newFormat,newProperties))
00071 //          throw cException(   "cFramebufferDisplay::cFramebufferDisplay",
00072 //                              "Provided information is not supported" );
00073 
00074         SDL_Surface * newSurface = SDL_SetVideoMode(
00075                                             newProperties.size().getX(),
00076                                             newProperties.size().getY(),
00077                                             bpp,
00078                                             newProperties.flags() );
00079         if (0==newSurface)
00080             throw cSDLException(    "cFramebufferDisplay::cFramebufferDisplay",
00081                                     "Failed to create the requested surface" );
00082 
00083         registerDisplayCreated();
00084 
00085         setRawSurface( newSurface,false );  // false, take no ownership
00086         setFormat( *(rawSurface()->format) );
00087         setProperties( *rawSurface() );
00088     }
00089 
00090 
00091     /* ********************************************************************** */
00092     cFramebufferDisplay::cFramebufferDisplay(
00093                                     const cPixelFormat & iFormat,
00094                                     const cSurfaceProperties & iProperties )
00095     {
00096         if (!surfaceIsSupported(iFormat,iProperties))
00097             throw cException(   "cFramebufferDisplay::cFramebufferDisplay",
00098                                 "Provided format/properties are not supported" );
00099 
00100         SDL_Surface * newSurface = SDL_SetVideoMode(
00101                                             iProperties.size().getX(),
00102                                             iProperties.size().getY(),
00103                                             iFormat.bitsPerPixel(),
00104                                             iProperties.flags() );
00105         if (0==newSurface)
00106             throw cSDLException(    "cFramebufferDisplay::cFramebufferDisplay",
00107                                     "Failed to create the requested surface" );
00108 
00109         // Take the properties of the surface now, and make sure we
00110         // match them internally
00111         setRawSurface( newSurface,false );  // false, take no ownership
00112         setFormat( *(rawSurface()->format) );
00113         setProperties( *rawSurface() );
00114     }
00115 
00116     /* ************************************************************ */
00117     cFramebufferDisplay::~cFramebufferDisplay()
00118     {
00119     }
00120 
00121 
00122     /* ************************************************************ */
00123     void cFramebufferDisplay::resizeTo( const tVector2u & iNewSize )
00124     {
00125         SDL_Surface * newSurface = SDL_SetVideoMode(
00126                                             iNewSize.x(),
00127                                             iNewSize.y(),
00128                                             format().bitsPerPixel(),
00129                                             properties().flags() ); 
00130         if (0==newSurface)
00131             throw cSDLException(    "cFramebufferDisplay::resizeTo",
00132                                     "Failed to resize to requested dimensions" );
00133         setRawSurface( newSurface,false );  // false, take no ownership
00134         setFormat( *(rawSurface()->format) );
00135         setProperties( *rawSurface() );
00136         registerDisplayCreated();
00137     }
00138 
00139 
00140     /* ************************************************************ */
00141     const tBool cFramebufferDisplay::supportsRWBuffer() const
00142     {
00143         // For now.
00144         return false;
00145     }
00146 
00147 
00148     /* ************************************************************ */
00149     void * const cFramebufferDisplay::aquireRWBuffer()
00150     {
00151         // For now
00152         throw cUnsupportedMethodException(
00153                                 "cFramebufferDisplay::aquireRWBuffer",
00154                                 "RW Buffers not supported" );
00155     }
00156 
00157 
00158     /* ************************************************************ */
00159     void cFramebufferDisplay::releaseRWBuffer() const
00160     {
00161         // For now
00162         throw cUnsupportedMethodException(
00163                                 "cFramebufferDisplay::releaseRWBuffer",
00164                                 "RW Buffers not supported" );
00165     }
00166 
00167 
00168     /* ************************************************************ */
00169     void cFramebufferDisplay::flip() const
00170     {
00171         SDL_Flip(rawSurface());
00172     }
00173 
00174 } // namespace
©2012 Aaron Cameron