[D3D] Code factorization...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Now that the texture code is refactored, use it for the Unlock case.

Changelog:
 - added RECT support to the texture upload code
 - use the common code for the FB Unlock code

-- 
		 Lionel Ulmer - http://www.bbrox.org/
--- dlls/ddraw_CVS/d3ddevice/mesa.c	2003-05-30 11:48:55.000000000 +0200
+++ dlls/ddraw/d3ddevice/mesa.c	2003-05-30 15:04:05.000000000 +0200
@@ -357,6 +357,9 @@
 	HeapFree(GetProcessHeap(), 0, This->view_mat);
 	HeapFree(GetProcessHeap(), 0, This->proj_mat);
 
+	if (glThis->surface_ptr)
+	    HeapFree(GetProcessHeap(), 0, glThis->surface_ptr);
+
 	DeleteCriticalSection(&(This->crit));
 	
 	ENTER_GL();
@@ -2911,13 +2914,13 @@
 #define UNLOCK_TEX_SIZE 256
 
 static void d3ddevice_flush_to_frame_buffer(IDirect3DDeviceImpl *d3d_dev, LPCRECT pRect, IDirectDrawSurfaceImpl *surf) {
-    GLenum buffer_type, buffer_color;
     RECT loc_rect;
     IDirect3DDeviceGLImpl* gl_d3d_dev = (IDirect3DDeviceGLImpl*) d3d_dev;
-    GLint depth_test, alpha_test, cull_face, lighting, min_tex, max_tex, tex_env, blend, stencil_test, fog;
+    GLint depth_test, alpha_test, cull_face, lighting, tex_env, blend, stencil_test, fog;
     GLuint initial_texture;
     GLint tex_state;
     int x, y;
+    BOOLEAN initial = FALSE;
 
     /* Note : no need here to lock the 'device critical section' as we are already protected by
        the GL critical section. */
@@ -2928,6 +2931,24 @@
     loc_rect.right = surf->surface_desc.dwWidth;
 
     TRACE(" flushing memory back to the frame-buffer (%ld,%ld) x (%ld,%ld).\n", loc_rect.top, loc_rect.left, loc_rect.right, loc_rect.bottom);
+
+    glGetIntegerv(GL_TEXTURE_BINDING_2D, &initial_texture);
+    if (gl_d3d_dev->unlock_tex == 0) {
+        glGenTextures(1, &gl_d3d_dev->unlock_tex);
+	glBindTexture(GL_TEXTURE_2D, gl_d3d_dev->unlock_tex);
+	initial = TRUE;
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+    } else {
+        glBindTexture(GL_TEXTURE_2D, gl_d3d_dev->unlock_tex);
+    }
+    
+    if (upload_surface_to_tex_memory_init(surf, 0, &gl_d3d_dev->current_internal_format,
+					  initial, FALSE, UNLOCK_TEX_SIZE, UNLOCK_TEX_SIZE) != D3D_OK) {
+        ERR(" unsupported pixel format at frame buffer flush.\n");
+	glBindTexture(GL_TEXTURE_2D, initial_texture);
+	return;
+    }
 	
     glGetIntegerv(GL_DEPTH_TEST, &depth_test);
     glGetIntegerv(GL_ALPHA_TEST, &alpha_test);
@@ -2935,36 +2956,13 @@
     glGetIntegerv(GL_CULL_FACE, &cull_face);
     glGetIntegerv(GL_LIGHTING, &lighting);
     glGetIntegerv(GL_BLEND, &blend);
-    glGetIntegerv(GL_TEXTURE_BINDING_2D, &initial_texture);
     glGetIntegerv(GL_TEXTURE_2D, &tex_state);
     glGetIntegerv(GL_FOG, &fog);
-    glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &max_tex);
-    glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &min_tex);
     glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &tex_env);
     glMatrixMode(GL_TEXTURE);
     glLoadIdentity();
     /* TODO: scissor test if ever we use it ! */
     
-    if ((surf->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount == 16) &&
-	(surf->surface_desc.u4.ddpfPixelFormat.u2.dwRBitMask ==        0xF800) &&
-	(surf->surface_desc.u4.ddpfPixelFormat.u3.dwGBitMask ==        0x07E0) &&
-	(surf->surface_desc.u4.ddpfPixelFormat.u4.dwBBitMask ==        0x001F) &&
-	(surf->surface_desc.u4.ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x0000)) {
-        buffer_type = GL_UNSIGNED_SHORT_5_6_5;
-	buffer_color = GL_RGB;
-    } else if ((surf->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount == 32) &&
-	       (surf->surface_desc.u4.ddpfPixelFormat.u2.dwRBitMask ==        0x00FF0000) &&
-	       (surf->surface_desc.u4.ddpfPixelFormat.u3.dwGBitMask ==        0x0000FF00) &&
-	       (surf->surface_desc.u4.ddpfPixelFormat.u4.dwBBitMask ==        0x000000FF) &&
-	       (surf->surface_desc.u4.ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000000)) {
-        buffer_type = GL_UNSIGNED_BYTE;
-	buffer_color = GL_BGRA;
-	glPixelStorei(GL_UNPACK_SWAP_BYTES, TRUE);
-    } else {
-        ERR(" unsupported pixel format at frame buffer flush.\n");
-	return;
-    }
-
     gl_d3d_dev->transform_state = GL_TRANSFORM_ORTHO;
     d3ddevice_set_ortho(d3d_dev);
     
@@ -2975,40 +2973,26 @@
     glViewport(0, 0, d3d_dev->surface->surface_desc.dwWidth, d3d_dev->surface->surface_desc.dwHeight);
     glScissor(loc_rect.left, surf->surface_desc.dwHeight - loc_rect.bottom,
 	      loc_rect.right - loc_rect.left, loc_rect.bottom - loc_rect.top);
-    
-    if (gl_d3d_dev->unlock_tex == 0) {
-        glGenTextures(1, &gl_d3d_dev->unlock_tex);
-	glBindTexture(GL_TEXTURE_2D, gl_d3d_dev->unlock_tex);
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
-		     UNLOCK_TEX_SIZE, UNLOCK_TEX_SIZE, 0,
-		     GL_RGB, buffer_type, NULL);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    } else {
-        glBindTexture(GL_TEXTURE_2D, gl_d3d_dev->unlock_tex);
-    }
-    glPixelStorei(GL_UNPACK_ROW_LENGTH, surf->surface_desc.dwWidth);
-    
-    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     glDisable(GL_LIGHTING);
     glDisable(GL_CULL_FACE);
     glDisable(GL_ALPHA_TEST);
     glDisable(GL_STENCIL_TEST);
     glDisable(GL_BLEND);
     glDisable(GL_FOG);
-
+    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+    
     for (x = loc_rect.left; x < loc_rect.right; x += UNLOCK_TEX_SIZE) {
         for (y = loc_rect.top; y < loc_rect.bottom; y += UNLOCK_TEX_SIZE) {
 	    /* First, upload the texture... */
-	    int w = (x + UNLOCK_TEX_SIZE > surf->surface_desc.dwWidth)  ? (surf->surface_desc.dwWidth - x)  : UNLOCK_TEX_SIZE;
-	    int h = (y + UNLOCK_TEX_SIZE > surf->surface_desc.dwHeight) ? (surf->surface_desc.dwHeight - y) : UNLOCK_TEX_SIZE;
-	    glTexSubImage2D(GL_TEXTURE_2D,
-			    0,
-			    0, 0,
-			    w, h,
-			    buffer_color,
-			    buffer_type,
-			    ((char *) surf->surface_desc.lpSurface) + (x * GET_BPP(surf->surface_desc)) + (y * surf->surface_desc.u1.lPitch));
+	    RECT flush_rect;
+
+	    flush_rect.left = x;
+	    flush_rect.top = y;
+	    flush_rect.right  = (x + UNLOCK_TEX_SIZE > surf->surface_desc.dwWidth)  ? surf->surface_desc.dwWidth  : (x + UNLOCK_TEX_SIZE);
+	    flush_rect.bottom = (y + UNLOCK_TEX_SIZE > surf->surface_desc.dwHeight) ? surf->surface_desc.dwHeight : (y + UNLOCK_TEX_SIZE);
+
+	    upload_surface_to_tex_memory(&flush_rect, 0, 0, &(gl_d3d_dev->surface_ptr));
+
 	    glBegin(GL_QUADS);
 	    glColor3ub(0xFF, 0xFF, 0xFF);
 	    glTexCoord2f(0.0, 0.0);
@@ -3023,6 +3007,7 @@
 	}
     }
     
+    upload_surface_to_tex_memory_release();
     
     /* And restore all the various states modified by this code */
     if (depth_test != 0) glEnable(GL_DEPTH_TEST);
--- dlls/ddraw_CVS/d3dtexture.c	2003-05-30 11:48:55.000000000 +0200
+++ dlls/ddraw/d3dtexture.c	2003-05-30 15:03:13.000000000 +0200
@@ -121,7 +121,7 @@
 
 	    if (upload_surface_to_tex_memory_init(surf_ptr, surf_ptr->mipmap_level, &(gl_surf_ptr->current_internal_format),
 						  gl_surf_ptr->initial_upload_done == FALSE, TRUE, 0, 0) == D3D_OK) {
-	        upload_surface_to_tex_memory(NULL, &(gl_surf_ptr->surface_ptr));
+	        upload_surface_to_tex_memory(NULL, 0, 0, &(gl_surf_ptr->surface_ptr));
 		upload_surface_to_tex_memory_release();
 		gl_surf_ptr->dirty_flag = SURFACE_MEMORY;
 	    }
@@ -232,7 +232,7 @@
 		/* If not 'full size' and the surface is dirty, first flush it to GL before doing the copy. */
 	        if (upload_surface_to_tex_memory_init(surf_ptr, surf_ptr->mipmap_level, &(gl_surf_ptr->current_internal_format),
 						      gl_surf_ptr->initial_upload_done == FALSE, TRUE, 0, 0) != D3D_OK) {
-		    upload_surface_to_tex_memory(NULL, &(gl_surf_ptr->surface_ptr));
+		    upload_surface_to_tex_memory(NULL, 0, 0, &(gl_surf_ptr->surface_ptr));
 		    upload_surface_to_tex_memory_release();
 		    gl_surf_ptr->dirty_flag = SURFACE_MEMORY;
 		} else {
@@ -245,7 +245,7 @@
 		gl_surf_ptr->dirty_flag = SURFACE_MEMORY_DIRTY;
 		if (upload_surface_to_tex_memory_init(surf_ptr, surf_ptr->mipmap_level, &(gl_surf_ptr->current_internal_format),
 						       gl_surf_ptr->initial_upload_done == FALSE, TRUE, 0, 0) != D3D_OK) {
-		    upload_surface_to_tex_memory(NULL, &(gl_surf_ptr->surface_ptr));
+		    upload_surface_to_tex_memory(NULL, 0, 0, &(gl_surf_ptr->surface_ptr));
 		    upload_surface_to_tex_memory_release();
 		    gl_surf_ptr->dirty_flag = SURFACE_MEMORY;
 		} else {
--- dlls/ddraw_CVS/mesa.c	2003-05-30 11:48:55.000000000 +0200
+++ dlls/ddraw/mesa.c	2003-05-30 15:11:28.000000000 +0200
@@ -586,6 +586,8 @@
 static CONVERT_TYPES convert_type;
 static IDirectDrawSurfaceImpl *current_surface;
 static GLuint current_level;
+static DWORD current_tex_width;
+static DWORD current_tex_height;
 
 HRESULT upload_surface_to_tex_memory_init(IDirectDrawSurfaceImpl *surf_ptr, GLuint level, GLenum *current_internal_format,
 					  BOOLEAN need_to_alloc, BOOLEAN need_alpha_ck, DWORD tex_width, DWORD tex_height)
@@ -617,6 +619,9 @@
 	tex_height = surf_ptr->surface_desc.dwHeight;
     }
 
+    current_tex_width = tex_width;
+    current_tex_height = tex_height;
+
     if (src_pf->dwFlags & DDPF_PALETTEINDEXED8) {
 	/* ****************
 	   Paletted Texture
@@ -820,18 +825,32 @@
     return DD_OK;
 }
 
-HRESULT upload_surface_to_tex_memory(RECT *rect, void **temp_buffer)
+HRESULT upload_surface_to_tex_memory(RECT *rect, DWORD xoffset, DWORD yoffset, void **temp_buffer)
 {
     const DDSURFACEDESC * const src_d = (DDSURFACEDESC *)&(current_surface->surface_desc);
     void *surf_buffer = NULL;
+    RECT lrect;
+    DWORD width, height;
+    BYTE bpp = GET_BPP(current_surface->surface_desc);
+
+    if (rect == NULL) {
+	lrect.top = 0;
+	lrect.left = 0;
+	lrect.bottom = current_tex_height;
+	lrect.right = current_tex_width;
+	rect = &lrect;
+    }
+
+    width = rect->right - rect->left;
+    height = rect->bottom - rect->top;
 
     switch (convert_type) {
         case CONVERT_PALETTED: {
 	    IDirectDrawPaletteImpl* pal = current_surface->palette;
 	    BYTE table[256][4];
 	    int i;
-	    BYTE *src = (BYTE *) src_d->lpSurface, *dst;
-	    	    
+	    BYTE *src = (BYTE *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
+	    
 	    if (pal == NULL) {
 		/* Upload a black texture. The real one will be uploaded on palette change */
 		WARN("Palettized texture Loading with a NULL palette !\n");
@@ -856,10 +875,10 @@
 	    
 	    if (*temp_buffer == NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 
-					 src_d->dwWidth * src_d->dwHeight * sizeof(DWORD));
+					 current_tex_width * current_tex_height * sizeof(DWORD));
 	    dst = (BYTE *) *temp_buffer;
 	    
-	    for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+	    for (i = 0; i < height * width; i++) {
 		BYTE color = *src++;
 		*dst++ = table[color][0];
 		*dst++ = table[color][1];
@@ -880,14 +899,14 @@
 	              color-space or not ?
 	    */
 	    DWORD i;
-	    WORD *src = (WORD *) src_d->lpSurface, *dst;
+	    WORD *src = (WORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
 	    if (*temp_buffer != NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-					 src_d->dwWidth * src_d->dwHeight * sizeof(WORD));
+					 current_tex_width * current_tex_height * sizeof(WORD));
 	    dst = (WORD *) *temp_buffer;
 	    
-	    for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+	    for (i = 0; i < height * width; i++) {
 		WORD color = *src++;
 		*dst = ((color & 0xFFC0) | ((color & 0x1F) << 1));
 		if ((color < src_d->ddckCKSrcBlt.dwColorSpaceLowValue) ||
@@ -900,14 +919,14 @@
         case CONVERT_CK_5551: {
 	    /* Change the alpha value of the color-keyed pixels to emulate color-keying. */
 	    DWORD i;
-	    WORD *src = (WORD *) src_d->lpSurface, *dst;
+	    WORD *src = (WORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
 	    if (*temp_buffer != NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-					 src_d->dwWidth * src_d->dwHeight * sizeof(WORD));
+					 current_tex_width * current_tex_height * sizeof(WORD));
 	    dst = (WORD *) *temp_buffer;
 	    
-	    for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+	    for (i = 0; i < height * width; i++) {
 		WORD color = *src++;
 		*dst = color & 0xFFFE;
 		if ((color < src_d->ddckCKSrcBlt.dwColorSpaceLowValue) ||
@@ -920,14 +939,14 @@
         case CONVERT_CK_4444: {
 	    /* Change the alpha value of the color-keyed pixels to emulate color-keying. */
 	    DWORD i;
-	    WORD *src = (WORD *) src_d->lpSurface, *dst;
+	    WORD *src = (WORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
 	    if (*temp_buffer != NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-					 src_d->dwWidth * src_d->dwHeight * sizeof(WORD));
+					 current_tex_width * current_tex_height * sizeof(WORD));
 	    dst = (WORD *) *temp_buffer;
 	    
-	    for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+	    for (i = 0; i < height * width; i++) {
 		WORD color = *src++;
 		*dst = color & 0xFFF0;
 		if ((color < src_d->ddckCKSrcBlt.dwColorSpaceLowValue) ||
@@ -940,14 +959,14 @@
         case CONVERT_CK_4444_ARGB: {
 	    /* Move the four Alpha bits... */
 	    DWORD i;
-	    WORD *src = (WORD *) src_d->lpSurface, *dst;
+	    WORD *src = (WORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
 	    if (*temp_buffer != NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-					 src_d->dwWidth * src_d->dwHeight * sizeof(WORD));
+					 current_tex_width * current_tex_height * sizeof(WORD));
 	    dst = (WORD *) *temp_buffer;
 	    
-	    for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+	    for (i = 0; i < height * width; i++) {
 		WORD color = *src++;
 		*dst = (color & 0x0FFF) << 4;
 		if ((color < src_d->ddckCKSrcBlt.dwColorSpaceLowValue) ||
@@ -959,14 +978,14 @@
 	
         case CONVERT_CK_1555: {
 	    DWORD i;
-	    WORD *src = (WORD *) src_d->lpSurface, *dst;
+	    WORD *src = (WORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
 	    if (*temp_buffer != NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-					 src_d->dwWidth * src_d->dwHeight * sizeof(WORD));
+					 current_tex_width * current_tex_height * sizeof(WORD));
 	    dst = (WORD *) *temp_buffer;
 	    
-	    for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+	    for (i = 0; i < height * width; i++) {
 		WORD color = *src++;
 		*dst = (color & 0x7FFF) << 1;
 		if ((color < src_d->ddckCKSrcBlt.dwColorSpaceLowValue) ||
@@ -979,15 +998,15 @@
         case CONVERT_555: {
 	    /* Converting the 0555 format in 5551 packed */
 	    DWORD i;
-	    WORD *src = (WORD *) src_d->lpSurface, *dst;
+	    WORD *src = (WORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
 	    if (*temp_buffer != NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-					 src_d->dwWidth * src_d->dwHeight * sizeof(WORD));
+					 current_tex_width * current_tex_height * sizeof(WORD));
 	    dst = (WORD *) *temp_buffer;
 	    
 	    if (src_d->dwFlags & DDSD_CKSRCBLT) {
-		for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+		for (i = 0; i < height * width; i++) {
 		    WORD color = *src++;
 		    *dst = (color & 0x7FFF) << 1;
 		    if ((color < src_d->ddckCKSrcBlt.dwColorSpaceLowValue) ||
@@ -996,7 +1015,7 @@
 		    dst++;
 		}
 	    } else {
-		for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+		for (i = 0; i < height * width; i++) {
 		    WORD color = *src++;
 		    *dst++ = ((color & 0x7FFF) << 1) | 0x0001;
 		}
@@ -1007,15 +1026,15 @@
         case CONVERT_CK_RGB24: {
 	    /* This is a pain :-) */
 	    DWORD i;
-	    BYTE *src = (BYTE *) src_d->lpSurface;
+	    BYTE *src = (BYTE *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top));
 	    DWORD *dst;
 	    
 	    if (*temp_buffer != NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-					 src_d->dwWidth * src_d->dwHeight * sizeof(DWORD));
+					 current_tex_width * current_tex_height * sizeof(DWORD));
 	    dst = (DWORD *) *temp_buffer;
 
-	    for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+	    for (i = 0; i < height * width; i++) {
 		DWORD color = *((DWORD *) src) & 0x00FFFFFF;
 		src += 3;
 		*dst = *src++ << 8;
@@ -1029,14 +1048,14 @@
         case CONVERT_CK_8888: {
 	    /* Just use the alpha component to handle color-keying... */
 	    DWORD i;
-	    DWORD *src = (DWORD *) src_d->lpSurface, *dst;
+	    DWORD *src = (DWORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
 	    if (*temp_buffer != NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-					 src_d->dwWidth * src_d->dwHeight * sizeof(DWORD));	    
+					 current_tex_width * current_tex_height * sizeof(DWORD));	    
 	    dst = (DWORD *) *temp_buffer;
 	    
-	    for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+	    for (i = 0; i < height * width; i++) {
 		DWORD color = *src++;
 		*dst = color & 0xFFFFFF00;
 		if ((color < src_d->ddckCKSrcBlt.dwColorSpaceLowValue) ||
@@ -1048,14 +1067,14 @@
 	
         case CONVERT_CK_8888_ARGB: {
 	    DWORD i;
-	    DWORD *src = (DWORD *) src_d->lpSurface, *dst;
+	    DWORD *src = (DWORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
 	    if (*temp_buffer != NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-					 src_d->dwWidth * src_d->dwHeight * sizeof(DWORD));	    
+					 current_tex_width * current_tex_height * sizeof(DWORD));	    
 	    dst = (DWORD *) *temp_buffer;
 	    
-	    for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+	    for (i = 0; i < height * width; i++) {
 		DWORD color = *src++;
 		*dst = (color & 0x00FFFFFF) << 8;
 		if ((color < src_d->ddckCKSrcBlt.dwColorSpaceLowValue) ||
@@ -1068,15 +1087,15 @@
         case CONVERT_RGB32_888: {
 	    /* Just add an alpha component and handle color-keying... */
 	    DWORD i;
-	    DWORD *src = (DWORD *) src_d->lpSurface, *dst;
+	    DWORD *src = (DWORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
 	    if (*temp_buffer != NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-					 src_d->dwWidth * src_d->dwHeight * sizeof(DWORD));	    
+					 current_tex_width * current_tex_height * sizeof(DWORD));	    
 	    dst = (DWORD *) *temp_buffer;
 	    
 	    if (src_d->dwFlags & DDSD_CKSRCBLT) {
-		for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+		for (i = 0; i < height * width; i++) {
 		    DWORD color = *src++;
 		    *dst = color << 8;
 		    if ((color < src_d->ddckCKSrcBlt.dwColorSpaceLowValue) ||
@@ -1085,7 +1104,7 @@
 		    dst++;
 		}
 	    } else {
-		for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
+		for (i = 0; i < height * width; i++) {
 		    *dst++ = (*src++ << 8) | 0xFF;
 		}
 	    }
@@ -1093,7 +1112,7 @@
 
         case NO_CONVERSION:
 	    /* Nothing to do here as the name suggests... This just prevents a compiler warning */
-	    surf_buffer = src_d->lpSurface;
+	    surf_buffer = (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top));
 	    break;
     }
 
@@ -1103,8 +1122,8 @@
     
     glTexSubImage2D(GL_TEXTURE_2D,
 		    current_level,
-		    0, 0,
-		    src_d->dwWidth, src_d->dwHeight,
+		    xoffset, yoffset,
+		    width, height,
 		    current_format,
 		    current_pixel_format,
 		    surf_buffer);
--- dlls/ddraw_CVS/mesa_private.h	2003-05-30 11:48:55.000000000 +0200
+++ dlls/ddraw/mesa_private.h	2003-05-30 15:02:43.000000000 +0200
@@ -105,7 +105,11 @@
     Display  *display;
     Drawable drawable;
 
+    /* Variables used for the flush to frame-buffer code using the texturing code */
     GLuint unlock_tex;
+    void *surface_ptr;
+    GLenum current_internal_format;
+    
     SURFACE_STATE state, front_state;
     IDirectDrawSurfaceImpl *lock_surf, *front_lock_surf;
 } IDirect3DDeviceGLImpl;
@@ -149,7 +153,7 @@
 /* Memory to texture conversion code. Split in three functions to do some optimizations. */
 extern HRESULT upload_surface_to_tex_memory_init(IDirectDrawSurfaceImpl *surface, GLuint level, GLenum *prev_internal_format,
 						 BOOLEAN need_to_alloc, BOOLEAN need_alpha_ck, DWORD tex_width, DWORD tex_height);
-extern HRESULT upload_surface_to_tex_memory(RECT *rect, void **temp_buffer);
+extern HRESULT upload_surface_to_tex_memory(RECT *rect, DWORD xoffset, DWORD yoffset, void **temp_buffer);
 extern HRESULT upload_surface_to_tex_memory_release(void);
 
 #endif /* HAVE_OPENGL */

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux