comparison engine/core/video/sdl/renderbackendsdl.cpp @ 654:5d6b1820b953

* Added the ability to change screen modes on the fly. This works both in OpenGL and SDL modes. * Added IEngineChangeListener so the client can update the cameras viewport if the screen mode has been changed. I chose to do it this way because the engine has no way to know which camera it should update. It will be up to the client to do it. * The cursor surface is now correctly freed when exiting. * Added DeviceCaps::getNearestScreenMode() for the client to request a supported screen mode. closes[t:315]
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 21 Oct 2010 18:50:50 +0000
parents 01acc9fc35ea
children e3140f01749d
comparison
equal deleted inserted replaced
653:01acc9fc35ea 654:5d6b1820b953
78 SDL_SetClipRect(m_screen->getSurface(), &rect); 78 SDL_SetClipRect(m_screen->getSurface(), &rect);
79 SDL_FillRect(m_screen->getSurface(), 0, 0x00); 79 SDL_FillRect(m_screen->getSurface(), 0, 0x00);
80 } 80 }
81 81
82 Image* RenderBackendSDL::createMainScreen(const ScreenMode& mode, const std::string& title, const std::string& icon){ 82 Image* RenderBackendSDL::createMainScreen(const ScreenMode& mode, const std::string& title, const std::string& icon){
83 m_screenMode = mode;
84 unsigned int width = mode.getWidth();
85 unsigned int height = mode.getHeight();
86 unsigned char bitsPerPixel = mode.getBPP();
87 bool fs = mode.isFullScreen();
88 Uint32 flags = mode.getSDLFlags();
89
90 if(icon != "") { 83 if(icon != "") {
91 SDL_Surface *img = IMG_Load(icon.c_str()); 84 SDL_Surface *img = IMG_Load(icon.c_str());
92 if(img != NULL) { 85 if(img != NULL) {
93 SDL_WM_SetIcon(img, 0); 86 SDL_WM_SetIcon(img, 0);
94 } 87 }
95 } 88 }
96 89
90 Image *image = setScreenMode(mode);
91
92 SDL_WM_SetCaption(title.c_str(), 0);
93
94 return image;
95 }
96
97 Image* RenderBackendSDL::setScreenMode(const ScreenMode& mode) {
98 uint16_t width = mode.getWidth();
99 uint16_t height = mode.getHeight();
100 uint16_t bitsPerPixel = mode.getBPP();
101 bool fs = mode.isFullScreen();
102 uint32_t flags = mode.getSDLFlags();
103
97 SDL_Surface* screen = NULL; 104 SDL_Surface* screen = NULL;
98 105
99 if( 0 == bitsPerPixel ) { 106 if (bitsPerPixel != 0) {
100 /// autodetect best mode 107 uint16_t bpp = SDL_VideoModeOK(width, height, bitsPerPixel, flags);
101 unsigned char possibleBitsPerPixel[] = {16, 24, 32, 0}; 108 if (!bpp){
102 int i = 0; 109 throw SDLException("Selected video mode not supported!");
103 while( true ) {
104 bitsPerPixel = possibleBitsPerPixel[i];
105 if( !bitsPerPixel ) {
106 // Last try, sometimes VideoModeOK seems to lie.
107 // Try bpp=0
108 screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
109 if( !screen ) {
110 throw SDLException("Videomode not available");
111 }
112 break;
113 }
114 bitsPerPixel = SDL_VideoModeOK(width, height, bitsPerPixel, flags);
115 if ( bitsPerPixel ) {
116 screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
117 if( screen ) {
118 break;
119 }
120 }
121 ++i;
122 } 110 }
123 } else {
124 if ( !SDL_VideoModeOK(width, height, bitsPerPixel, flags) ) {
125 throw SDLException("Videomode not available");
126 }
127 screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
128 } 111 }
112
113 screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
114 if( !screen ) {
115 throw SDLException("Unable to set video mode selected!");
116 }
117
129 FL_LOG(_log, LMsg("RenderBackendSDL") 118 FL_LOG(_log, LMsg("RenderBackendSDL")
130 << "Videomode " << width << "x" << height 119 << "Videomode " << width << "x" << height
131 << " at " << int(screen->format->BitsPerPixel) << " bpp"); 120 << " at " << int(screen->format->BitsPerPixel) << " bpp");
132 121
133 //update the screen mode with the actual flags used 122 //update the screen mode with the actual flags used
134 123 m_screenMode = ScreenMode(width,
135 m_screenMode = ScreenMode(m_screenMode.getWidth(), 124 height,
136 m_screenMode.getHeight(), 125 bitsPerPixel,
137 m_screenMode.getBPP(),
138 screen->flags); 126 screen->flags);
139
140 SDL_WM_SetCaption(title.c_str(), NULL);
141 127
142 if (!screen) { 128 if (!screen) {
143 throw SDLException(SDL_GetError()); 129 throw SDLException(SDL_GetError());
144 } 130 }
145 131
132 delete m_screen;
146 m_screen = new SDLImage(screen); 133 m_screen = new SDLImage(screen);
147 return m_screen; 134 return m_screen;
148 } 135 }
149 136
150 void RenderBackendSDL::startFrame() { 137 void RenderBackendSDL::startFrame() {