[Scummvm-cvs-logs] CVS: scummvm/backends/sdl fb2opengl.h,1.2,1.3 sdl_gl.cpp,1.8,1.9

James Brown ender at users.sourceforge.net
Wed Oct 23 01:53:03 CEST 2002


Update of /cvsroot/scummvm/scummvm/backends/sdl
In directory usw-pr-cvs1:/tmp/cvs-serv26611

Modified Files:
	fb2opengl.h sdl_gl.cpp 
Log Message:
Patch 627178: OpenGL updates


Index: fb2opengl.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/fb2opengl.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- fb2opengl.h	22 Oct 2002 00:58:48 -0000	1.2
+++ fb2opengl.h	23 Oct 2002 08:52:20 -0000	1.3
@@ -22,7 +22,8 @@
 // Andre Souza <asouza at 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 @@
     // 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 @@
     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_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 (y=0; y<h; y++) {
-    for (x=0; x<w; x++) {
-      
-      SDL_GetRGBA(fb1[x],((SDL_Surface *)fb)->format,&r,&g,&b,&a);
-      
-      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
+  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;
     }
-    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);
+    for (y = ry; y < yend; y++) {
+      for (x = rx; x < xend; x++) {
+      
+        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]);
+	}
+      }
+    }
 
-  // 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) {

Index: sdl_gl.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/sdl_gl.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- sdl_gl.cpp	22 Oct 2002 00:58:48 -0000	1.8
+++ sdl_gl.cpp	23 Oct 2002 08:52:20 -0000	1.9
@@ -31,6 +31,7 @@
 #endif
 
 #include "fb2opengl.h"
+int _screenStart = 30;
 
 class OSystem_SDL_Normal : public OSystem_SDL_Common {
 public:
@@ -211,6 +212,7 @@
 
 	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 @@
 	// 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 @@
 	
 	// 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 @@
 					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;





More information about the Scummvm-git-logs mailing list