RenderSurface.cpp

Go to the documentation of this file.
00001 /*
00002 RenderSurface.cpp : RenderSurface Interface source file
00003 
00004 Copyright (C) 2002, 2003 The Pentagram Team
00005 
00006 This program is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU General Public License
00008 as published by the Free Software Foundation; either version 2
00009 of the License, or (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 */
00020 
00021 #include "pent_include.h"
00022 #include "RenderSurface.h"
00023 #include "SoftRenderSurface.h"
00024 #include <SDL.h>
00025 #include <cmath>
00026 
00027 #if defined(WIN32) && defined(I_AM_COLOURLESS_EXPERIMENTING_WITH_D3D)
00028 #include "D3D9SoftRenderSurface.h"
00029 #endif
00030 
00031 RenderSurface::Format   RenderSurface::format = {
00032         0,      0,
00033         0,      0,      0,      0,
00034         0,      0,      0,      0,
00035         0,      0,      0,      0,
00036         0,      0,      0,      0
00037 };
00038 
00039 uint8 RenderSurface::Gamma10toGamma22[256];
00040 uint8 RenderSurface::Gamma22toGamma10[256];
00041 
00042 //
00043 // RenderSurface::SetVideoMode()
00044 //
00045 // Desc: Create a standard RenderSurface
00046 // Returns: Created RenderSurface or 0
00047 //
00048 
00049 RenderSurface *RenderSurface::SetVideoMode(uint32 width,                // Width of desired mode
00050                                                                         uint32 height,          // Height of desired mode
00051                                                                         uint32 bpp,                     // Bits Per Pixel of desired mode
00052                                                                         bool fullscreen,        // Fullscreen if true, Windowed if false
00053                                                                         bool use_opengl)        // Use OpenGL if true, Software if false
00054 {
00055         // TODO: Add in OpenGL
00056         if (use_opengl)
00057         {
00058                 pout << "OpenGL Mode not enabled" << std::endl;
00059                 // TODO: Set Error Code
00060                 return 0;
00061         }
00062 
00063         // check to make sure a 16 bit or 32 bit Mode has been requested
00064         if (bpp != 16 && bpp != 32)
00065         {
00066                 pout << "Only 16 bit and 32 bit video modes supported" << std::endl;
00067                 // TODO: Set Error Code
00068                 return 0;
00069         }
00070 
00071         // SDL Flags to set
00072         uint32 flags = 0;
00073 
00074         // Get Current Video Mode details
00075         const SDL_VideoInfo *vinfo = SDL_GetVideoInfo();
00076 
00077         if (!vinfo)
00078         {
00079                 pout << "SDL_GetVideoInfo() failed: " << SDL_GetError() << std::endl;
00080                 return 0;
00081         }
00082 
00083         // Specific Windowed code
00084         if (!fullscreen) 
00085         {
00086                 // Use the BPP of the desktop
00087                 //bpp = vinfo->vfmt->BitsPerPixel;
00088 
00089                 // check to make sure we are in 16 bit or 32 bit
00090                 if (bpp != 16 && bpp != 32)
00091                 {
00092                         pout << bpp << " bit windowed mode unsupported" << std::endl;
00093                         // TODO: Set Error Code
00094                         return 0;
00095                 }
00096         }
00097         // Fullscreen Specific 
00098         else
00099         {
00100                 // Enable Fullscreen
00101                 flags |= SDL_FULLSCREEN;
00102         }
00103 
00104         // Double buffered (sdl will emulate if we don't have)
00105         // Um, no, it's been decided that this is a very bad idea
00106         // Transparency is very very slow with hardware
00107         //flags |= SDL_HWSURFACE|SDL_DOUBLEBUF;
00108         flags |= SDL_SWSURFACE;
00109 
00110         SDL_Surface *sdl_surf = SDL_SetVideoMode(width, height, bpp, flags);
00111         
00112         if (!sdl_surf)
00113         {
00114                 // TODO: Set Error Code
00115                 return 0;
00116         }
00117 
00118         // Now create the SoftRenderSurface
00119         RenderSurface *surf;
00120 
00121         // TODO: Change this
00122 #if defined(WIN32) && defined(I_AM_COLOURLESS_EXPERIMENTING_WITH_D3D)
00123         if (bpp == 32) surf = new D3D9SoftRenderSurface<uint32>(width,height,fullscreen);
00124         else surf = new D3D9SoftRenderSurface<uint16>(width,height,fullscreen);
00125 #else
00126         if (bpp == 32) surf = new SoftRenderSurface<uint32>(sdl_surf);
00127         else surf = new SoftRenderSurface<uint16>(sdl_surf);
00128 #endif
00129 
00130         // Initialize gamma correction tables
00131         for (int i = 0; i < 256; i++)
00132         {
00133                 Gamma22toGamma10[i] = static_cast<uint8>(0.5 + (std::pow (i/255.0, 2.2/1.0) * 255.0));
00134                 Gamma10toGamma22[i] = static_cast<uint8>(0.5 + (std::pow (i/255.0, 1.0/2.2) * 255.0));
00135         }
00136 
00137         return surf;
00138 }
00139 
00140 // Create a SecondaryRenderSurface with an associated Texture object
00141 RenderSurface *RenderSurface::CreateSecondaryRenderSurface(uint32 width, uint32 height)
00142 {
00143         // Now create the SoftRenderSurface
00144         RenderSurface *surf;
00145 
00146         // TODO: Change this
00147         if (format.s_bpp == 32) surf = new SoftRenderSurface<uint32>(width,height);
00148         else surf = new SoftRenderSurface<uint16>(width,height);
00149         return surf;
00150 }
00151 
00152 RenderSurface::~RenderSurface()
00153 {
00154 }

Generated on Fri Jul 27 22:27:31 2007 for pentagram by  doxygen 1.4.7