Ticket #8197: sdl_gl.cpp.patch

File sdl_gl.cpp.patch, 11.5 KB (added by SF/luke_br, 22 years ago)

SDL/GL with SDL scalers

Line 
119c19
2< * $Header: /cvsroot/scummvm/scummvm/backends/sdl/sdl_gl.cpp,v 1.23 2003/04/15 01:32:16 kirben Exp $
3---
4> * $Header: /cvsroot/scummvm/scummvm/backends/sdl/sdl_gl.cpp,v 1.22 2003/03/06 21:45:14 aquadran Exp $
537,41c37
6< OSystem_SDL_OpenGL() {
7< _glScreenStart = 0;
8< _glBilinearFilter = true;
9< _glBottomOfTexture = 256; // height is always 256
10< }
11---
12> OSystem_SDL_OpenGL();
1351a48,51
14> // Get the next event.
15> // Returns true if an event was retrieved.
16> // bool poll_event(Event *event);
17>
1856a57
19> bool _usingOpenGL;
2058c59,60
21< SDL_Rect tmpBlackRect; // Black rectangle at end of the GL screen
22---
23> SDL_Rect tmpBlackRect; // Black rectangle at end of the GL screen
24> SDL_Rect _glWindow; // Only uses w and h (for window resizing)
2559a62,65
26>
27> SDL_Surface *_hwscreen; // hardware screen (=> _usingOpenGL == false)
28>
29> ScalerProc *_scaler_proc;
3069a76,87
31> OSystem_SDL_OpenGL::OSystem_SDL_OpenGL()
32> : _hwscreen(0), _scaler_proc(0)
33> {
34> _glScreenStart = 0;
35> _glBilinearFilter = true;
36> _usingOpenGL = true; // false => Switch to filters used in the sdl.cpp version
37> _glBottomOfTexture = 256; // height is always 256
38> // 640x480 resolution
39> _glWindow.w = 640;
40> _glWindow.h = 480;
41> }
42>
4396c114
44<
45---
46>
4799d116
48< _scaleFactor = 2;
49102a120,158
50>
51> switch(_mode) {
52> case GFX_2XSAI:
53> _scaleFactor = 2;
54> _scaler_proc = _2xSaI;
55> break;
56> case GFX_SUPER2XSAI:
57> _scaleFactor = 2;
58> _scaler_proc = Super2xSaI;
59> break;
60> case GFX_SUPEREAGLE:
61> _scaleFactor = 2;
62> _scaler_proc = SuperEagle;
63> break;
64> case GFX_ADVMAME2X:
65> _scaleFactor = 2;
66> _scaler_proc = AdvMame2x;
67> break;
68> case GFX_TV2X:
69> _scaleFactor = 2;
70> _scaler_proc = TV2x;
71> break;
72> case GFX_DOTMATRIX:
73> _scaleFactor = 2;
74> _scaler_proc = DotMatrix;
75> break;
76> case GFX_NORMAL:
77> _scaleFactor = 1;
78> _scaler_proc = Normal1x;
79> break;
80> default:
81> // error("unknown gfx mode");
82> _mode = GFX_NORMAL;
83> _scaleFactor = 1;
84> _scaler_proc = Normal1x;
85> }
86>
87> if (_mode != GFX_NORMAL)
88> _usingOpenGL = false;
89111d166
90<
91115,119c170,194
92<
93< _glFlags = FB2GL_320 | FB2GL_RGBA | FB2GL_16BIT;
94< if (_full_screen) {
95< _glFlags |= (FB2GL_FS);
96< _glScreenStart = 0;
97---
98> if (_usingOpenGL) {
99>
100> _glFlags = FB2GL_320 | FB2GL_RGBA | FB2GL_16BIT;
101> if (_full_screen) {
102> _glFlags |= (FB2GL_FS);
103> _glScreenStart = 0;
104> }
105> // _glWindow defines the resolution
106> fb2gl.init(_glWindow.w, _glWindow.h, 0, _glScreenStart? 15: 70,
107> _glFlags);
108>
109> }
110> else { // SDL backend
111>
112> _hwscreen = SDL_SetVideoMode(_screenWidth * _scaleFactor, _screenHeight * _scaleFactor, 16,
113> _full_screen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
114> );
115> if (_hwscreen == NULL)
116> error("_hwscreen failed");
117>
118> // Distinguish 555 and 565 mode
119> if (_hwscreen->format->Rmask == 0x7C00)
120> Init_2xSaI(555);
121> else
122> Init_2xSaI(565);
123121,122d195
124< // 640x480 screen resolution
125< fb2gl.init(640, 480, 0,_glScreenStart? 15: 70,_glFlags);
126125d197
127<
128133,134c205,211
129< _tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen,
130< _tmpScreenWidth, _screenHeight + 3, 16, _tmpScreenWidth * 2,
131---
132>
133> if (_usingOpenGL) {
134> _tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen,
135> _tmpScreenWidth,
136> _screenHeight + 3,
137> 16,
138> _tmpScreenWidth * 2,
139138a216,227
140> }
141> else { // SDL backend
142> _tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen,
143> _tmpScreenWidth,
144> _screenHeight + 3,
145> 16,
146> _tmpScreenWidth * 2,
147> _hwscreen->format->Rmask,
148> _hwscreen->format->Gmask,
149> _hwscreen->format->Bmask,
150> _hwscreen->format->Amask);
151> }
152164a254
153>
154165a256
155>
156170c261,264
157<
158---
159> if (_hwscreen) {
160> SDL_FreeSurface(_hwscreen);
161> _hwscreen = NULL;
162> }
163188,189c282,289
164< SDL_FreeSurface(fb2gl.getScreen());
165< fb2gl.setScreen(NULL);
166---
167> if (fb2gl.getScreen()) { // _usingOpenGL was true
168> SDL_FreeSurface(fb2gl.getScreen());
169> fb2gl.setScreen(NULL);
170> }
171> if (_hwscreen) {
172> SDL_FreeSurface(_hwscreen);
173> _hwscreen = NULL;
174> }
175213c313,319
176< SDL_Rect blackrect = {0, _glScreenStart, _screenWidth, _newShakePos+_glScreenStart};
177---
178> if (_usingOpenGL) {
179> SDL_Rect blackrect = {
180> 0,
181> _glScreenStart,
182> _screenWidth,
183> _newShakePos + _glScreenStart
184> };
185215,216c321,327
186< SDL_FillRect(tmpSurface, &blackrect, 0);
187< fb2gl.blit16(tmpSurface, 1, &blackrect, 0, 0);
188---
189> SDL_FillRect(tmpSurface, &blackrect, 0);
190> fb2gl.blit16(tmpSurface, 1, &blackrect, 0, 0);
191> }
192> else { // SDL backend
193> SDL_Rect blackrect = {0, 0, _screenWidth * _scaleFactor, _newShakePos * _scaleFactor};
194> SDL_FillRect(_hwscreen, &blackrect, 0);
195> }
196251a363
197> uint32 srcPitch, dstPitch;
198253c365
199<
200---
201>
202254a367
203> SDL_Rect dst;
204256d368
205< SDL_Rect dst;
206259,261c371,391
207< // dst.x++; // Shift rect by one since 2xSai needs to acces the data around
208< // dst.y++; // any pixel to scale it, and we want to avoid mem access crashes.
209< if (SDL_BlitSurface(_screen, r, _tmpscreen, &dst) != 0)
210---
211> dst.x++; // Shift rect by one since 2xSai needs to acces the data around
212> dst.y++; // any pixel to scale it, and we want to avoid mem access crashes.
213> if (_scaler_proc == Normal1x) {
214> if (_usingOpenGL) {
215> if (SDL_BlitSurface(_screen, r, _tmpscreen, &dst) != 0)
216> error("SDL_BlitSurface failed: %s", SDL_GetError());
217> }
218> else { // SDL backend
219> if (SDL_BlitSurface(_screen, r, _hwscreen, &dst) != 0)
220> error("SDL_BlitSurface failed: %s", SDL_GetError());
221> }
222> } else { // _scaler_proc != Normal1x
223> if (SDL_BlitSurface(_screen, r, _tmpscreen, &dst) != 0)
224> error("SDL_BlitSurface failed: %s", SDL_GetError());
225> }
226> }
227> } else {
228> if (!_usingOpenGL) {
229> for(r = _dirty_rect_list; r != last_rect; ++r) {
230> dst = *r;
231> if (SDL_BlitSurface(_tmpscreen, r, _hwscreen, &dst) != 0)
232263a394
233> }
234266,272d396
235< // Almost the same thing as SDL_UpdateRects
236< fb2gl.blit16(_tmpscreen, _num_dirty_rects, _dirty_rect_list, 0,
237< _currentShakePos+_glScreenStart);
238<
239< int _glBottomOfGameScreen = _screenHeight + _glScreenStart + _currentShakePos;
240< // Bottom black border height
241< tmpBlackRect.h = _glBottomOfTexture - _glBottomOfGameScreen;
242274,277c398,419
243< if (!(_full_screen) && (tmpBlackRect.h > 0)) {
244< SDL_FillRect(tmpSurface, &tmpBlackRect, 0);
245< fb2gl.blit16(tmpSurface, 1, &tmpBlackRect, 0,
246< _glBottomOfGameScreen);
247---
248> if (_usingOpenGL) {
249> // Almost the same thing as SDL_UpdateRects
250> fb2gl.blit16(
251> _tmpscreen,
252> _num_dirty_rects,
253> _dirty_rect_list,
254> 0,
255> _currentShakePos + _glScreenStart
256> );
257>
258> int _glBottomOfGameScreen = _screenHeight +
259> _glScreenStart + _currentShakePos;
260>
261> // Bottom black border height
262> tmpBlackRect.h = _glBottomOfTexture - _glBottomOfGameScreen;
263> if (!(_full_screen) && (tmpBlackRect.h > 0)) {
264> SDL_FillRect(tmpSurface, &tmpBlackRect, 0);
265> fb2gl.blit16(tmpSurface, 1, &tmpBlackRect, 0,
266> _glBottomOfGameScreen);
267> }
268>
269> fb2gl.display();
270278a421,425
271> else { // SDL backend
272>
273> if (_scaler_proc != Normal1x) {
274> SDL_LockSurface(_tmpscreen);
275> SDL_LockSurface(_hwscreen);
276280,281c427,464
277< fb2gl.display();
278< }
279---
280> srcPitch = _tmpscreen->pitch;
281> dstPitch = _hwscreen->pitch;
282>
283> for(r = _dirty_rect_list; r != last_rect; ++r) {
284> register int dst_y = r->y + _currentShakePos;
285> register int dst_h = 0;
286> if (dst_y < _screenHeight) {
287> dst_h = r->h;
288> if (dst_h > _screenHeight - dst_y)
289> dst_h = _screenHeight - dst_y;
290>
291> dst_y *= _scaleFactor;
292>
293> _scaler_proc((byte *)_tmpscreen->pixels + (r->x * 2 + 2) + (r->y + 1) * srcPitch, srcPitch, NULL,
294> (byte *)_hwscreen->pixels + r->x * 2 * _scaleFactor + dst_y * dstPitch, dstPitch, r->w, dst_h);
295> }
296>
297> r->x *= _scaleFactor;
298> r->y = dst_y;
299> r->w *= _scaleFactor;
300> r->h = dst_h * _scaleFactor;
301> }
302>
303> SDL_UnlockSurface(_tmpscreen);
304> SDL_UnlockSurface(_hwscreen);
305> }
306>
307> // Readjust the dirty rect list in case we are doing a full update.
308> // This is necessary if shaking is active.
309> if (_forceFull) {
310> _dirty_rect_list[0].y = 0;
311> _dirty_rect_list[0].h = _screenHeight * _scaleFactor;
312> }
313>
314> // Finally, blit all our changes to the screen
315> SDL_UpdateRects(_hwscreen, _num_dirty_rects, _dirty_rect_list);
316> } // END OF "SDL backend"
317> } // if (num_dirty_rects > 0) ...
318286a470,491
319> /*
320> bool OSystem_SDL_OpenGL::poll_event(Event *event) {
321> SDL_Event ev;
322> ev.type = 0;
323>
324> SDL_PeepEvents(&ev, 1, SDL_GETEVENT, SDL_VIDEORESIZEMASK);
325>
326> if (ev.type == SDL_VIDEORESIZE) {
327> int w = ev.resize.w;
328> int h = ev.resize.h;
329> glViewport(0, 0, (GLsizei)w, (GLsizei)h);
330> glMatrixMode(GL_PROJECTION);
331> glLoadIdentity();
332> glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
333> _glWindow.w = w;
334> _glWindow.h = h;
335> }
336>
337> return OSystem_SDL_Common::poll_event(event);
338> }
339> */
340>
341290a496,497
342> if (!_usingOpenGL)
343> assert(_hwscreen != 0);
344298c505,513
345< if (!SDL_WM_ToggleFullScreen(fb2gl.getScreen())) {
346---
347> SDL_Surface *_tmpScreen;
348> if (_usingOpenGL) {
349> _tmpScreen = fb2gl.getScreen();
350> }
351> else { // SDL backend
352> _tmpScreen = _hwscreen;
353> }
354>
355> if (!SDL_WM_ToggleFullScreen(_tmpScreen)) {
356308d522
357< glPopMatrix();
358309a524,531
359> if (value->gfx_mode < 3) { // OpenGL modes
360> if (!_usingOpenGL) {
361> _usingOpenGL = true;
362> _mode = GFX_NORMAL;
363> hotswap_gfx_mode();
364> }
365> }
366>
367316,317c538,547
368< glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
369< glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
370---
371> glTexParameteri(
372> GL_TEXTURE_2D,
373> GL_TEXTURE_MAG_FILTER,
374> GL_LINEAR
375> );
376> glTexParameteri(
377> GL_TEXTURE_2D,
378> GL_TEXTURE_MIN_FILTER,
379> GL_LINEAR
380> );
381319,320c549,558
382< glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
383< glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
384---
385> glTexParameteri(
386> GL_TEXTURE_2D,
387> GL_TEXTURE_MAG_FILTER,
388> GL_NEAREST
389> );
390> glTexParameteri(
391> GL_TEXTURE_2D,
392> GL_TEXTURE_MIN_FILTER,
393> GL_NEAREST
394> );
395324c562
396< case 1: // Don't use the whole screen
397---
398> case 1: // Don't use the whole screen (black borders)
399334,346c572,581
400< default: // Zooming
401< glPushMatrix();
402< /* SDL_FillRect(tmpSurface, &full, 0);
403< fb2gl.blit16(tmpSurface, 1, &full,0, _glScreenStart);
404< fb2gl.display();
405< double x = (double)((_mouseCurState.x)
406< - (_screenWidth / 2)) / (_screenWidth / 2);
407< double y = (double)((_mouseCurState.y)
408< - (_screenHeight / 2)) / (_screenHeight / 2);
409< glTranslatef(-x, y, 0);
410< */
411< glScalef(1.0 + (double)(value->gfx_mode - 1) / 10,
412< 1.0 + (double)(value->gfx_mode - 1) / 10, 0);
413---
414> default: // SDL backend
415> if (value->gfx_mode >= 9)
416> return 0;
417>
418> _mode = value->gfx_mode;
419>
420> if (_usingOpenGL)
421> _usingOpenGL = false;
422>
423> hotswap_gfx_mode();
424348,349c583,587
425< fb2gl.blit16(_tmpscreen, 1, &full, 0, _glScreenStart);
426< fb2gl.display();
427---
428>
429> if (_usingOpenGL) {
430> fb2gl.blit16(_tmpscreen, 1, &full, 0, _glScreenStart);
431> fb2gl.display();
432> }
433355a594
434>