00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00044
00045
00046
00047
00048
00049 RenderSurface *RenderSurface::SetVideoMode(uint32 width,
00050 uint32 height,
00051 uint32 bpp,
00052 bool fullscreen,
00053 bool use_opengl)
00054 {
00055
00056 if (use_opengl)
00057 {
00058 pout << "OpenGL Mode not enabled" << std::endl;
00059
00060 return 0;
00061 }
00062
00063
00064 if (bpp != 16 && bpp != 32)
00065 {
00066 pout << "Only 16 bit and 32 bit video modes supported" << std::endl;
00067
00068 return 0;
00069 }
00070
00071
00072 uint32 flags = 0;
00073
00074
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
00084 if (!fullscreen)
00085 {
00086
00087
00088
00089
00090 if (bpp != 16 && bpp != 32)
00091 {
00092 pout << bpp << " bit windowed mode unsupported" << std::endl;
00093
00094 return 0;
00095 }
00096 }
00097
00098 else
00099 {
00100
00101 flags |= SDL_FULLSCREEN;
00102 }
00103
00104
00105
00106
00107
00108 flags |= SDL_SWSURFACE;
00109
00110 SDL_Surface *sdl_surf = SDL_SetVideoMode(width, height, bpp, flags);
00111
00112 if (!sdl_surf)
00113 {
00114
00115 return 0;
00116 }
00117
00118
00119 RenderSurface *surf;
00120
00121
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
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
00141 RenderSurface *RenderSurface::CreateSecondaryRenderSurface(uint32 width, uint32 height)
00142 {
00143
00144 RenderSurface *surf;
00145
00146
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 }