diff options
author | James Brown | 2002-10-23 08:52:20 +0000 |
---|---|---|
committer | James Brown | 2002-10-23 08:52:20 +0000 |
commit | 134468fd619d36f2dca47a724c4e1cf01a930ee8 (patch) | |
tree | a5fea080b304643f56203369feb7dcaab61d6848 /backends | |
parent | f46346c2aaa4d63b8c7da1d359f41c8951909806 (diff) | |
download | scummvm-rg350-134468fd619d36f2dca47a724c4e1cf01a930ee8.tar.gz scummvm-rg350-134468fd619d36f2dca47a724c4e1cf01a930ee8.tar.bz2 scummvm-rg350-134468fd619d36f2dca47a724c4e1cf01a930ee8.zip |
Patch 627178: OpenGL updates
svn-id: r5279
Diffstat (limited to 'backends')
-rw-r--r-- | backends/sdl/fb2opengl.h | 103 | ||||
-rw-r--r-- | backends/sdl/sdl_gl.cpp | 29 |
2 files changed, 89 insertions, 43 deletions
diff --git a/backends/sdl/fb2opengl.h b/backends/sdl/fb2opengl.h index 285b12d6ef..0dfb1e74ac 100644 --- a/backends/sdl/fb2opengl.h +++ b/backends/sdl/fb2opengl.h @@ -22,7 +22,8 @@ // Andre Souza <asouza@olinux.com.br> #include <SDL.h> -#include <SDL_opengl.h> +//#include <SDL_opengl.h> +#include <GL/gl.h> #include <stdlib.h> #include <string.h> @@ -47,6 +48,9 @@ class FB2GL { // Framebuffer for RGBA */ unsigned char ogl_fb1[256][256][4]; unsigned char ogl_fb2[256][64][4]; + // Framebuffer for the blit function (SDL Blitting) + unsigned char fb1[256*256*4]; // Enough room for RGBA + unsigned char fb2[64*256*4]; // Enough room for RGBA // Texture(s) GLuint texture; GLuint textureb; @@ -69,7 +73,7 @@ class FB2GL { void update(void *fb, int width, int height, int pitch, int xskip, int yskip); void palette(int index, int r, int g, int b); void setPalette(int first, int ncolors); - void update_scummvm_screen(void *fb, int width, int height, int pitch, int x, int y); + void blit16(SDL_Surface *fb, int num_rect, SDL_Rect *rectlist, int xskip, int yskip); void display(); }; @@ -317,45 +321,72 @@ void FB2GL::update(void *fb, int w, int h, int pitch, int xskip, int yskip) { } -void FB2GL::update_scummvm_screen(void *fb, int w, int h, int pitch, int xpos, int ypos) { - uint16 *fb1 = (uint16 *)(((SDL_Surface *)fb)->pixels); - int x, y; - unsigned char r, g, b, a; +void FB2GL::blit16(SDL_Surface *fb, int num_rect, SDL_Rect *rect, int xskip, int yskip) { + int x, y, i; + int rx, ry, rw, rh; + int xend=0, yend=0; + int pitch = fb->pitch/2; // 16 bit pointer access (not char *) + int tex1_w = 0, tex2_w = 0, tex2_x = 0; + + for (i=0; i<num_rect; i++) { + tex1_w = tex2_w = tex2_x = 0; + rx = rect[i].x; + ry = rect[i].y; + rw = rect[i].w; + rh = rect[i].h; + xend = rx + rw; + yend = ry + rh; + if (xend > fb->w) continue; + if (yend > fb->h) continue; + + if (rx < 256) { // Begins before the end of the 1st texture + if (xend >= 256) { // Ends after the first texture + tex2_w = xend-256; // For the 2nd texture + tex1_w = rw - tex2_w; // For the 1st texture + } + else tex1_w = rw; + } + else { + tex2_w = rw; + tex2_x = rx - 256; + } - for (y=0; y<h; y++) { - for (x=0; x<w; x++) { - - SDL_GetRGBA(fb1[x],((SDL_Surface *)fb)->format,&r,&g,&b,&a); + for (y = ry; y < yend; y++) { + for (x = rx; x < xend; x++) { - if (x<256) { - ogl_fb1[y][x][0] = r; - ogl_fb1[y][x][1] = g; - ogl_fb1[y][x][2] = b; - ogl_fb1[y][x][3] = a; // Alpha - } - else { - ogl_fb2[y][x-256][0] = r; - ogl_fb2[y][x-256][1] = g; - ogl_fb2[y][x-256][2] = b; - ogl_fb2[y][x-256][3] = a; // Alpha + if (x < 256 && tex1_w) { + int pos = (x-rx+(y-ry)*tex1_w)*4; // RGBA + SDL_GetRGB(((Uint16 *)fb->pixels)[x+y*(pitch)],fb->format, + &fb1[pos], + &fb1[pos+1], + &fb1[pos+2]); + } + else if (x >= 256 && tex2_w) { + int rx2 = rx < 256? 256: rx; + int pos = (x-rx2+(y-ry)*tex2_w)*4; // RGBA + SDL_GetRGB(((Uint16 *)fb->pixels)[x+y*(pitch)],fb->format, + &fb2[pos], + &fb2[pos+1], + &fb2[pos+2]); + } } } - fb1 += pitch; - } - // Update 256x256 texture - glBindTexture(GL_TEXTURE_2D,texture); - glFlush(); - glTexSubImage2D(GL_TEXTURE_2D,0,xpos,ypos,256-xpos,256-ypos,GL_RGBA, - GL_UNSIGNED_BYTE,ogl_fb1); - - // Update 64x256 texture - glBindTexture(GL_TEXTURE_2D,textureb); - glFlush(); - glTexSubImage2D(GL_TEXTURE_2D,0,xpos,ypos,64-xpos,256-ypos,GL_RGBA, - GL_UNSIGNED_BYTE,ogl_fb2); - - display(); + if (tex1_w > 0) { + // Update 256x256 texture + glBindTexture(GL_TEXTURE_2D,texture); + glFlush(); + glTexSubImage2D(GL_TEXTURE_2D,0,rx+xskip,ry+yskip,tex1_w,rh,GL_RGBA, + GL_UNSIGNED_BYTE,fb1); + } + if (tex2_w > 0) { // What was left for this texture + // Update 64x256 texture + glBindTexture(GL_TEXTURE_2D,textureb); + glFlush(); + glTexSubImage2D(GL_TEXTURE_2D,0,tex2_x+xskip,ry+yskip,tex2_w,rh,GL_RGBA, + GL_UNSIGNED_BYTE,fb2); + } + } } void FB2GL::palette(int i, int r, int g, int b) { diff --git a/backends/sdl/sdl_gl.cpp b/backends/sdl/sdl_gl.cpp index ba1e785008..f44f8e503b 100644 --- a/backends/sdl/sdl_gl.cpp +++ b/backends/sdl/sdl_gl.cpp @@ -31,6 +31,7 @@ int glGetColorTable(int, int, int, void *) { return 0; } #endif #include "fb2opengl.h" +int _screenStart = 30; class OSystem_SDL_Normal : public OSystem_SDL_Common { public: @@ -211,6 +212,7 @@ void OSystem_SDL_Normal::load_gfx_mode() { sdl_tmpscreen = NULL; TMP_SCREEN_WIDTH = (_screenWidth + 3); +// TMP_SCREEN_WIDTH = (_screenWidth); // // Create the surface that contains the 8 bit game data @@ -224,9 +226,18 @@ void OSystem_SDL_Normal::load_gfx_mode() { // Create the surface that contains the scaled graphics in 16 bit mode // - int gl_flags = FB2GL_320 | FB2GL_PITCH | FB2GL_RGBA | FB2GL_EXPAND; +// SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); +// if (fb2gl.screen->format->Rmask == 0x7C00) +// SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); +// else +// SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 ); +// SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); +// SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); + + int gl_flags = FB2GL_320 | FB2GL_RGBA | FB2GL_EXPAND; if (_full_screen) gl_flags |= (FB2GL_FS); - fb2gl.init(640,480,0,70,gl_flags); // 640x480 screen resolution + // 640x480 screen resolution + fb2gl.init(640,480,0,_screenStart? 0: 70,gl_flags); SDL_SetGamma(1.25,1.25,1.25); @@ -278,8 +289,10 @@ void OSystem_SDL_Normal::update_screen() { // If the shake position changed, fill the dirty area with blackness if (_currentShakePos != _newShakePos) { -// SDL_Rect blackrect = {0, 0, _screenWidth*_scaleFactor, _newShakePos*_scaleFactor}; -// SDL_FillRect(sdl_hwscreen, &blackrect, 0); + SDL_Rect blackrect = {0, _screenStart, _screenWidth, _newShakePos+_screenStart}; + SDL_FillRect(sdl_tmpscreen, &blackrect, 0); + + fb2gl.blit16(sdl_tmpscreen,1,&blackrect,0,0); _currentShakePos = _newShakePos; @@ -328,9 +341,11 @@ void OSystem_SDL_Normal::update_screen() { error("SDL_BlitSurface failed: %s", SDL_GetError()); } } - - fb2gl.update_scummvm_screen((void *)sdl_tmpscreen,TMP_SCREEN_WIDTH,_screenHeight,TMP_SCREEN_WIDTH,0,_currentShakePos); - + + // Almost the same thing as SDL_UpdateRects + fb2gl.blit16(sdl_tmpscreen,_num_dirty_rects,_dirty_rect_list,0, + _currentShakePos+_screenStart); + fb2gl.display(); } _num_dirty_rects = 0; |