DXGL r498 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r497‎ | r498 | r499 >
Date:21:25, 24 August 2014
Author:admin
Status:new
Tags:
Comment:
Partial mipmap inplememtation.
Modified paths:
  • /ddraw/TextureManager.c (modified) (history)
  • /ddraw/TextureManager.h (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)

Diff [purge]

Index: ddraw/TextureManager.c
@@ -17,6 +17,7 @@
1818
1919 #include "common.h"
2020 #include "TextureManager.h"
 21+#include <math.h>
2122
2223 // Use EXACTLY one line per entry. Don't change layout of the list.
2324 static const int START_TEXFORMATS = __LINE__;
@@ -54,6 +55,28 @@
5556 } while (1);
5657 }
5758
 59+DWORD CalculateMipLevels(DWORD width, DWORD height)
 60+{
 61+ DWORD x, y;
 62+ DWORD levels = 1;
 63+ if ((!width) || (!height)) return 0;
 64+ if ((width == 1) || (height == 1)) return 1;
 65+ x = width;
 66+ y = height;
 67+miploop:
 68+ x = max(1,(DWORD)floorf((float)x / 2.0f));
 69+ y = max(1,(DWORD)floorf((float)y / 2.0f));
 70+ levels++;
 71+ if ((x == 1) || (y == 1)) return levels;
 72+ else goto miploop;
 73+}
 74+
 75+void ShrinkMip(DWORD *x, DWORD *y)
 76+{
 77+ *x = max(1, (DWORD)floorf((float)*x / 2.0f));
 78+ *y = max(1, (DWORD)floorf((float)*y / 2.0f));
 79+}
 80+
5881 TextureManager *TextureManager_Create(glExtensions *glext)
5982 {
6083 TextureManager *newtex;
@@ -119,6 +142,7 @@
120143 {
121144 int texformat = -1;
122145 int i;
 146+ int x, y;
123147 GLenum error;
124148 texture->pixelformat.dwSize = sizeof(DDPIXELFORMAT);
125149 for(i = 0; i < numtexformats; i++)
@@ -430,27 +454,33 @@
431455 texture->height = height;
432456 glGenTextures(1,&texture->id);
433457 TextureManager_SetTexture(This,0,texture);
434 - do
 458+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->minfilter);
 459+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->magfilter);
 460+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texture->wraps);
 461+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texture->wrapt);
 462+ x = texture->width;
 463+ y = texture->height;
 464+ for (i = 0; i < texture->miplevel; i++)
435465 {
436 - ClearError();
437 - glTexImage2D(GL_TEXTURE_2D, 0, texture->internalformats[0], texture->width, texture->height, 0, texture->format, texture->type, NULL);
438 - error = glGetError();
439 - if (error != GL_NO_ERROR)
 466+ do
440467 {
441 - if (texture->internalformats[1] == 0)
 468+ ClearError();
 469+ glTexImage2D(GL_TEXTURE_2D, i, texture->internalformats[0], x, y, 0, texture->format, texture->type, NULL);
 470+ ShrinkMip(&x, &y);
 471+ error = glGetError();
 472+ if (error != GL_NO_ERROR)
442473 {
443 - FIXME("Failed to create texture, cannot find internal format");
444 - break;
 474+ if (texture->internalformats[1] == 0)
 475+ {
 476+ FIXME("Failed to create texture, cannot find internal format");
 477+ break;
 478+ }
 479+ memmove(&texture->internalformats[0], &texture->internalformats[1], 7 * sizeof(GLint));
 480+ texture->internalformats[7] = 0;
445481 }
446 - memmove(&texture->internalformats[0], &texture->internalformats[1], 7 * sizeof(GLint));
447 - texture->internalformats[7] = 0;
448 - }
449 - else break;
450 - } while (1);
451 - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,texture->minfilter);
452 - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,texture->magfilter);
453 - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,texture->wraps);
454 - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,texture->wrapt);
 482+ else break;
 483+ } while (1);
 484+ }
455485 }
456486
457487 void TextureManager_DeleteTexture(TextureManager *This, TEXTURE *texture)
Index: ddraw/TextureManager.h
@@ -74,6 +74,8 @@
7575 GLuint textures[16];
7676 } TextureManager;
7777
 78+DWORD CalculateMipLevels(DWORD width, DWORD height);
 79+
7880 TextureManager *TextureManager_Create(glExtensions *glext);
7981 void TextureManager_InitSamplers(TextureManager *This);
8082 void TextureManager_DeleteSamplers(TextureManager *This);
Index: ddraw/glDirectDraw.cpp
@@ -844,22 +844,33 @@
845845 HRESULT glDirectDraw7::CreateSurface2(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRECTDRAWSURFACE7 FAR *lplpDDSurface, IUnknown FAR *pUnkOuter, BOOL RecordSurface)
846846 {
847847 HRESULT error;
 848+ int mipcount;
848849 TRACE_ENTER(5, 14, this, 14, lpDDSurfaceDesc2, 14, lplpDDSurface, 14, pUnkOuter, 22, RecordSurface);
849 - if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
850 - if(!lpDDSurfaceDesc2) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
851 - if(pUnkOuter) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
852 - if(primary && (lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) && (renderer->hRC == primary->hRC) )
 850+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 851+ if (!lpDDSurfaceDesc2) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 852+ if (pUnkOuter) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 853+ if (primary && (lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) && (renderer->hRC == primary->hRC))
853854 {
854 - if(primarylost)
 855+ if (primarylost)
855856 {
856857 primary->Restore();
857858 *lplpDDSurface = primary;
858859 primarylost = false;
859 - TRACE_EXIT(23,DD_OK);
 860+ TRACE_EXIT(23, DD_OK);
860861 return DD_OK;
861862 }
862 - else TRACE_RET(HRESULT,23,DDERR_PRIMARYSURFACEALREADYEXISTS);
 863+ else TRACE_RET(HRESULT, 23, DDERR_PRIMARYSURFACEALREADYEXISTS);
863864 }
 865+ if ((lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_MIPMAP) &&
 866+ (!(lpDDSurfaceDesc2->dwFlags & DDSD_WIDTH) || !(lpDDSurfaceDesc2->dwFlags & DDSD_HEIGHT)))
 867+ TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 868+ if (lpDDSurfaceDesc2->dwFlags & DDSD_MIPMAPCOUNT)
 869+ {
 870+ if (!(lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_MIPMAP))
 871+ TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 872+ mipcount = CalculateMipLevels(lpDDSurfaceDesc2->dwWidth, lpDDSurfaceDesc2->dwHeight);
 873+ if (mipcount < lpDDSurfaceDesc2->dwMipMapCount) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 874+ }
864875 if (RecordSurface)
865876 {
866877 surfacecount++;
@@ -872,7 +883,7 @@
873884 ZeroMemory(&surfaces[surfacecountmax], 1024 * sizeof(glDirectDrawSurface7 *));
874885 surfacecountmax += 1024;
875886 }
876 - surfaces[surfacecount - 1] = new glDirectDrawSurface7(this, lpDDSurfaceDesc2, &error, false, NULL);
 887+ surfaces[surfacecount - 1] = new glDirectDrawSurface7(this, lpDDSurfaceDesc2, &error, NULL, NULL, 0);
877888 if (lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
878889 {
879890 primary = surfaces[surfacecount - 1];
@@ -883,7 +894,7 @@
884895 else
885896 {
886897 if (lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
887 - *lplpDDSurface = new glDirectDrawSurface7(this, lpDDSurfaceDesc2, &error, false, NULL);
 898+ *lplpDDSurface = new glDirectDrawSurface7(this, lpDDSurfaceDesc2, &error, NULL, NULL, 0);
888899 }
889900 TRACE_VAR("*lplpDDSurface",14,*lplpDDSurface);
890901 TRACE_EXIT(23,error);
Index: ddraw/glDirectDrawSurface.cpp
@@ -36,9 +36,10 @@
3737
3838
3939 // DDRAW7 routines
40 -glDirectDrawSurface7::glDirectDrawSurface7(LPDIRECTDRAW7 lpDD7, LPDDSURFACEDESC2 lpDDSurfaceDesc2, HRESULT *error, bool copysurface, glDirectDrawPalette *palettein)
 40+glDirectDrawSurface7::glDirectDrawSurface7(LPDIRECTDRAW7 lpDD7, LPDDSURFACEDESC2 lpDDSurfaceDesc2, HRESULT *error,
 41+ glDirectDrawPalette *palettein, TEXTURE *parenttex, DWORD miplevel)
4142 {
42 - TRACE_ENTER(6,14,this,14,lpDD7,14,lpDDSurfaceDesc2,14,error,21,copysurface,14,palettein);
 43+ TRACE_ENTER(5,14,this,14,lpDD7,14,lpDDSurfaceDesc2,14,error,14,palettein);
4344 overlay = false;
4445 hasstencil = false;
4546 dirty = 2;
@@ -67,23 +68,12 @@
6869 buffer = gdibuffer = NULL;
6970 bigbuffer = NULL;
7071 zbuffer = NULL;
 72+ this->miplevel = miplevel;
7173 DWORD colormasks[3];
7274 magfilter = minfilter = GL_NEAREST;
73 - if(copysurface)
74 - {
75 - FIXME("glDirectDrawSurface7::glDirectDrawSurface7: copy surface stub\n");
76 - *error = DDERR_GENERIC;
77 - TRACE_VAR("*error",23,DDERR_GENERIC);
78 - TRACE_EXIT(-1,0);
79 - return;
80 - }
81 - else
82 - {
83 - ddInterface = (glDirectDraw7 *)lpDD7;
84 - hRC = ddInterface->renderer->hRC;
85 - ddsd = *lpDDSurfaceDesc2;
86 - }
87 - if(!(ddsd.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)) ddsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
 75+ ddInterface = (glDirectDraw7 *)lpDD7;
 76+ hRC = ddInterface->renderer->hRC;
 77+ ddsd = *lpDDSurfaceDesc2;
8878 LONG sizes[6];
8979 ddInterface->GetSizes(sizes);
9080 if(ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
@@ -209,7 +199,17 @@
210200 bitmapinfo->bmiHeader.biWidth = ddsd.dwWidth;
211201 bitmapinfo->bmiHeader.biHeight = -(signed)ddsd.dwHeight;
212202 bitmapinfo->bmiHeader.biPlanes = 1;
213 - texture = new TEXTURE;
 203+ backbuffer = NULL;
 204+ if ((ddsd.ddsCaps.dwCaps & DDSCAPS_MIPMAP) && !(ddsd.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL))
 205+ {
 206+ if (!(ddsd.dwFlags & DDSD_MIPMAPCOUNT))
 207+ {
 208+ ddsd.dwFlags |= DDSD_MIPMAPCOUNT;
 209+ ddsd.dwMipMapCount = CalculateMipLevels(ddsd.dwWidth, ddsd.dwHeight);
 210+ }
 211+ }
 212+ if (ddsd.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL) texture = parenttex;
 213+ else texture = new TEXTURE;
214214 switch(surfacetype)
215215 {
216216 case 0:
@@ -223,8 +223,8 @@
224224 buffer = NULL;
225225 break;
226226 case 2:
 227+ buffer = NULL;
227228 maketex:
228 - buffer = NULL;
229229 if((dxglcfg.scalingfilter == 0) || (ddInterface->GetBPP() == 8)) magfilter = minfilter = GL_NEAREST;
230230 else magfilter = minfilter = GL_LINEAR;
231231 if(ddsd.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
@@ -301,17 +301,32 @@
302302 }
303303 }
304304 else ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*(ddsd.ddpfPixelFormat.dwRGBBitCount / 8));
305 - texture->pixelformat = ddsd.ddpfPixelFormat;
306 - if((ddsd.dwFlags & DDSD_CAPS) && (ddsd.ddsCaps.dwCaps & DDSCAPS_TEXTURE))
307 - texture->minfilter = texture->magfilter = GL_NEAREST;
308 - else
 305+ if (!(ddsd.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL))
309306 {
310 - if(dxglcfg.scalingfilter && (ddInterface->GetBPP() > 8)) texture->minfilter = texture->magfilter = GL_LINEAR;
311 - else texture->minfilter = texture->magfilter = GL_NEAREST;
 307+ texture->pixelformat = ddsd.ddpfPixelFormat;
 308+ if ((ddsd.dwFlags & DDSD_CAPS) && (ddsd.ddsCaps.dwCaps & DDSCAPS_TEXTURE))
 309+ texture->minfilter = texture->magfilter = GL_NEAREST;
 310+ else
 311+ {
 312+ if (dxglcfg.scalingfilter && (ddInterface->GetBPP() > 8)) texture->minfilter = texture->magfilter = GL_LINEAR;
 313+ else texture->minfilter = texture->magfilter = GL_NEAREST;
 314+ }
 315+ texture->wraps = texture->wrapt = GL_CLAMP_TO_EDGE;
 316+ if (ddsd.ddsCaps.dwCaps & DDSCAPS_MIPMAP) texture->miplevel = ddsd.dwMipMapCount;
 317+ else texture->miplevel = 1;
 318+ glRenderer_MakeTexture(ddInterface->renderer, texture, fakex, fakey);
312319 }
313 - texture->wraps = texture->wrapt = GL_CLAMP_TO_EDGE;
314 - glRenderer_MakeTexture(ddInterface->renderer,texture,fakex,fakey);
315320 }
 321+ if ((ddsd.ddsCaps.dwCaps & DDSCAPS_MIPMAP) && ddsd.dwMipMapCount)
 322+ {
 323+ DDSURFACEDESC2 newdesc = ddsd;
 324+ newdesc.dwWidth = max(1, (DWORD)floorf((float)ddsd.dwWidth / 2.0f));
 325+ newdesc.dwHeight = max(1, (DWORD)floorf((float)ddsd.dwHeight / 2.0f));
 326+ newdesc.ddsCaps.dwCaps2 |= DDSCAPS2_MIPMAPSUBLEVEL;
 327+ newdesc.dwMipMapCount = ddsd.dwMipMapCount - 1;
 328+ HRESULT miperror;
 329+ if(newdesc.dwMipMapCount) miptexture = new glDirectDrawSurface7(lpDD7, &newdesc, &miperror, palette, texture, miplevel + 1);
 330+ }
316331
317332 if(ddsd.ddpfPixelFormat.dwRGBBitCount > 8)
318333 {
@@ -337,7 +352,7 @@
338353 ddsdBack.dwBackBufferCount--;
339354 ddsdBack.ddsCaps.dwCaps |= DDSCAPS_BACKBUFFER;
340355 ddsdBack.ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER;
341 - backbuffer = new glDirectDrawSurface7(ddInterface,&ddsdBack,error,false,palette);
 356+ backbuffer = new glDirectDrawSurface7(ddInterface,&ddsdBack,error,palette,parenttex,miplevel);
342357 }
343358 else if (ddsd.dwFlags & DDSD_BACKBUFFERCOUNT){}
344359 else *error = DDERR_INVALIDPARAMS;
@@ -625,7 +640,7 @@
626641 glRenderer_UploadTexture(ddInterface->renderer, pattern->buffer, pattern->bigbuffer, pattern->texture,
627642 pattern->ddsd.dwWidth, pattern->ddsd.dwHeight, pattern->fakex, pattern->fakey, pattern->ddsd.lPitch,
628643 (NextMultipleOf4((ddInterface->GetBPPMultipleOf8() / 8)*pattern->fakex)),
629 - pattern->ddsd.ddpfPixelFormat.dwRGBBitCount);
 644+ pattern->ddsd.ddpfPixelFormat.dwRGBBitCount,pattern->miplevel);
630645 }
631646 }
632647 if (dwFlags & DDBLT_KEYSRC)
@@ -639,7 +654,7 @@
640655 {
641656 glRenderer_UploadTexture(ddInterface->renderer,buffer,bigbuffer,texture,ddsd.dwWidth,ddsd.dwHeight,
642657 fakex,fakey,ddsd.lPitch,(NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*fakex)),
643 - ddsd.ddpfPixelFormat.dwRGBBitCount);
 658+ ddsd.ddpfPixelFormat.dwRGBBitCount,miplevel);
644659 dirty &= ~1;
645660 }
646661 if(src && (src->dirty & 1))
@@ -647,7 +662,7 @@
648663 glRenderer_UploadTexture(ddInterface->renderer,src->buffer,src->bigbuffer,src->texture,src->ddsd.dwWidth,src->ddsd.dwHeight,
649664 src->fakex,src->fakey,src->ddsd.lPitch,
650665 (NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*src->fakex)),
651 - src->ddsd.ddpfPixelFormat.dwRGBBitCount);
 666+ src->ddsd.ddpfPixelFormat.dwRGBBitCount,src->miplevel);
652667 src->dirty &= ~1;
653668 }
654669 if (clipper)
@@ -822,7 +837,7 @@
823838 {
824839 glRenderer_UploadTexture(ddInterface->renderer,buffer,bigbuffer,texture,ddsd.dwWidth,ddsd.dwHeight,
825840 fakex,fakey,ddsd.lPitch,(NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*fakex)),
826 - ddsd.ddpfPixelFormat.dwRGBBitCount);
 841+ ddsd.ddpfPixelFormat.dwRGBBitCount,miplevel);
827842 dirty &= ~1;
828843 }
829844 this->dirty |= 2;
@@ -833,7 +848,7 @@
834849 {
835850 glRenderer_UploadTexture(ddInterface->renderer,tmp->buffer,tmp->bigbuffer,tmp->texture,tmp->ddsd.dwWidth,tmp->ddsd.dwHeight,
836851 tmp->fakex,tmp->fakey,tmp->ddsd.lPitch,(NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*tmp->fakex)),
837 - tmp->ddsd.ddpfPixelFormat.dwRGBBitCount);
 852+ tmp->ddsd.ddpfPixelFormat.dwRGBBitCount,miplevel);
838853 tmp->dirty &= ~1;
839854 }
840855 tmp->dirty |= 2;
@@ -1086,7 +1101,7 @@
10871102 case 0:
10881103 if(dirty & 2)
10891104 glRenderer_DownloadTexture(ddInterface->renderer,buffer,bigbuffer,texture,ddsd.dwWidth,ddsd.dwHeight,fakex,fakey,ddsd.lPitch,
1090 - (ddInterface->GetBPPMultipleOf8()/8)*fakex,ddsd.ddpfPixelFormat.dwRGBBitCount);
 1105+ (ddInterface->GetBPPMultipleOf8()/8)*fakex,ddsd.ddpfPixelFormat.dwRGBBitCount,miplevel);
10911106 ddsd.lpSurface = buffer;
10921107 dirty &= ~2;
10931108 break;
@@ -1101,7 +1116,7 @@
11021117 bigbuffer = (char *)malloc((ddsd.ddpfPixelFormat.dwRGBBitCount * NextMultipleOfWord(fakex) * fakey)/8);
11031118 else bigbuffer = NULL;
11041119 glRenderer_DownloadTexture(ddInterface->renderer,buffer,bigbuffer,texture,ddsd.dwWidth,ddsd.dwHeight,fakex,fakey,ddsd.lPitch,
1105 - (ddInterface->GetBPPMultipleOf8()/8)*fakex,ddsd.ddpfPixelFormat.dwRGBBitCount);
 1120+ (ddInterface->GetBPPMultipleOf8()/8)*fakex,ddsd.ddpfPixelFormat.dwRGBBitCount,miplevel);
11061121 dirty &= ~2;
11071122 surfacetype = 0;
11081123 goto retry;
@@ -1313,7 +1328,14 @@
13141329 }
13151330 else RenderScreen(texture,this,0);
13161331 }
1317 - TRACE_EXIT(23,DD_OK);
 1332+ if (ddsd.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
 1333+ {
 1334+ glRenderer_UploadTexture(ddInterface->renderer, buffer, bigbuffer, texture, ddsd.dwWidth, ddsd.dwHeight,
 1335+ fakex, fakey, ddsd.lPitch, (NextMultipleOf4((ddInterface->GetBPPMultipleOf8() / 8)*fakex)),
 1336+ ddsd.ddpfPixelFormat.dwRGBBitCount, miplevel);
 1337+ dirty &= ~1;
 1338+ }
 1339+ TRACE_EXIT(23, DD_OK);
13181340 return DD_OK;
13191341 }
13201342 HRESULT WINAPI glDirectDrawSurface7::UpdateOverlay(LPRECT lpSrcRect, LPDIRECTDRAWSURFACE7 lpDDDestSurface, LPRECT lpDestRect, DWORD dwFlags, LPDDOVERLAYFX lpDDOverlayFx)
Index: ddraw/glDirectDrawSurface.h
@@ -39,7 +39,7 @@
4040 class glDirectDrawSurface7 : public IDirectDrawSurface7
4141 {
4242 public:
43 - glDirectDrawSurface7(LPDIRECTDRAW7 lpDD7, LPDDSURFACEDESC2 lpDDSurfaceDesc2, HRESULT *error, bool copysurface, glDirectDrawPalette *palettein);
 43+ glDirectDrawSurface7(LPDIRECTDRAW7 lpDD7, LPDDSURFACEDESC2 lpDDSurfaceDesc2, HRESULT *error, glDirectDrawPalette *palettein, TEXTURE *parenttex, DWORD miplevel);
4444 virtual ~glDirectDrawSurface7();
4545 // ddraw 1+ api
4646 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
@@ -127,6 +127,8 @@
128128 TEXTURE *paltex;
129129 TEXTURE *stencil;
130130 bool hasstencil;
 131+ DWORD miplevel;
 132+ glDirectDrawSurface7 *miptexture;
131133 char *buffer;
132134 char *bigbuffer;
133135 char *gdibuffer;
Index: ddraw/glRenderer.cpp
@@ -98,14 +98,16 @@
9999 * Pitch of the scaled surface buffer
100100 * @param bpp
101101 * Number of bits per surface pixel
 102+ * @param miplevel
 103+ * Mipmap level of texture to write
102104 */
103105 void glRenderer__UploadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y,
104 - int bigx, int bigy, int pitch, int bigpitch, int bpp)
 106+ int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel)
105107 {
106108 if(bpp == 15) bpp = 16;
107109 if((x == bigx && y == bigy) || !bigbuffer)
108110 {
109 - TextureManager__UploadTexture(This->texman, texture, 0, buffer, x, y, FALSE);
 111+ TextureManager__UploadTexture(This->texman, texture, miplevel, buffer, x, y, FALSE);
110112 }
111113 else
112114 {
@@ -125,7 +127,7 @@
126128 break;
127129 break;
128130 }
129 - TextureManager__UploadTexture(This->texman, texture, 0, bigbuffer, bigx, bigy, FALSE);
 131+ TextureManager__UploadTexture(This->texman, texture, miplevel, bigbuffer, bigx, bigy, FALSE);
130132 }
131133 }
132134
@@ -150,17 +152,19 @@
151153 * Pitch of the scaled surface buffer
152154 * @param bpp
153155 * Number of bits per surface pixel
 156+ * @param miplevel
 157+ * Mipmap level of texture to read
154158 */
155159 void glRenderer__DownloadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y,
156 - int bigx, int bigy, int pitch, int bigpitch, int bpp)
 160+ int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel)
157161 {
158162 if((bigx == x && bigy == y) || !bigbuffer)
159163 {
160 - TextureManager__DownloadTexture(This->texman,texture,0,buffer);
 164+ TextureManager__DownloadTexture(This->texman,texture,miplevel,buffer);
161165 }
162166 else
163167 {
164 - TextureManager__DownloadTexture(This->texman,texture,0,bigbuffer);
 168+ TextureManager__DownloadTexture(This->texman,texture,miplevel,bigbuffer);
165169 switch(bpp)
166170 {
167171 case 8:
@@ -320,9 +324,11 @@
321325 * Pitch of the scaled surface buffer
322326 * @param bpp
323327 * Number of bits per surface pixel
 328+ * @param miplevel
 329+ * Mipmap level of texture to write
324330 */
325331 void glRenderer_UploadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y,
326 - int bigx, int bigy, int pitch, int bigpitch, int bpp)
 332+ int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel)
327333 {
328334 EnterCriticalSection(&This->cs);
329335 This->inputs[0] = buffer;
@@ -335,6 +341,7 @@
336342 This->inputs[7] = (void*)pitch;
337343 This->inputs[8] = (void*)bigpitch;
338344 This->inputs[9] = (void*)bpp;
 345+ This->inputs[10] = (void*)miplevel;
339346 This->opcode = OP_UPLOAD;
340347 SetEvent(This->start);
341348 WaitForSingleObject(This->busy,INFINITE);
@@ -362,9 +369,11 @@
363370 * Pitch of the scaled surface buffer
364371 * @param bpp
365372 * Number of bits per surface pixel
 373+ * @param miplevel
 374+ * Mipmap level of texture to read
366375 */
367376 void glRenderer_DownloadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y,
368 - int bigx, int bigy, int pitch, int bigpitch, int bpp)
 377+ int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel)
369378 {
370379 EnterCriticalSection(&This->cs);
371380 This->inputs[0] = buffer;
@@ -377,6 +386,7 @@
378387 This->inputs[7] = (void*)pitch;
379388 This->inputs[8] = (void*)bigpitch;
380389 This->inputs[9] = (void*)bpp;
 390+ This->inputs[10] = (void*)miplevel;
381391 This->opcode = OP_DOWNLOAD;
382392 SetEvent(This->start);
383393 WaitForSingleObject(This->busy,INFINITE);
@@ -749,13 +759,13 @@
750760 case OP_UPLOAD:
751761 glRenderer__UploadTexture(This,(char*)This->inputs[0],(char*)This->inputs[1],(TEXTURE*)This->inputs[2],
752762 (int)This->inputs[3],(int)This->inputs[4],(int)This->inputs[5],(int)This->inputs[6],
753 - (int)This->inputs[7],(int)This->inputs[8],(int)This->inputs[9]);
 763+ (int)This->inputs[7],(int)This->inputs[8],(int)This->inputs[9],(int)This->inputs[10]);
754764 SetEvent(This->busy);
755765 break;
756766 case OP_DOWNLOAD:
757767 glRenderer__DownloadTexture(This,(char*)This->inputs[0],(char*)This->inputs[1],(TEXTURE*)This->inputs[2],
758768 (int)This->inputs[3],(int)This->inputs[4],(int)This->inputs[5],(int)This->inputs[6],
759 - (int)This->inputs[7],(int)This->inputs[8],(int)This->inputs[9]);
 769+ (int)This->inputs[7],(int)This->inputs[8],(int)This->inputs[9],(int)This->inputs[10]);
760770 SetEvent(This->busy);
761771 break;
762772 case OP_DELETETEX:
@@ -1450,7 +1460,7 @@
14511461 glRenderer__UploadTexture(This,src->buffer,src->bigbuffer,texture,src->ddsd.dwWidth,src->ddsd.dwHeight,
14521462 src->fakex,src->fakey,src->ddsd.lPitch,
14531463 (NextMultipleOf4((This->ddInterface->GetBPPMultipleOf8()/8)*src->fakex)),
1454 - src->ddsd.ddpfPixelFormat.dwRGBBitCount);
 1464+ src->ddsd.ddpfPixelFormat.dwRGBBitCount,src->miplevel);
14551465 src->dirty &= ~1;
14561466 }
14571467 if(dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
@@ -1963,7 +1973,7 @@
19641974 device->texstages[i].texture->ddsd.dwHeight,device->texstages[i].texture->fakex,
19651975 device->texstages[i].texture->fakey,device->texstages[i].texture->ddsd.lPitch,
19661976 (device->texstages[i].texture->ddsd.ddpfPixelFormat.dwRGBBitCount/8*device->texstages[i].texture->fakex),
1967 - device->texstages[i].texture->ddsd.ddpfPixelFormat.dwRGBBitCount);
 1977+ device->texstages[i].texture->ddsd.ddpfPixelFormat.dwRGBBitCount, device->texstages[i].texture->miplevel);
19681978 device->texstages[i].texture->dirty &= ~1;
19691979 }
19701980 if(device->texstages[i].texture)
Index: ddraw/glRenderer.h
@@ -121,8 +121,8 @@
122122 void glRenderer_Init(glRenderer *This, int width, int height, int bpp, bool fullscreen, unsigned int frequency, HWND hwnd, glDirectDraw7 *glDD7, BOOL devwnd);
123123 void glRenderer_Delete(glRenderer *This);
124124 static DWORD WINAPI glRenderer_ThreadEntry(void *entry);
125 -void glRenderer_UploadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp);
126 -void glRenderer_DownloadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp);
 125+void glRenderer_UploadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel);
 126+void glRenderer_DownloadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel);
127127 HRESULT glRenderer_Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
128128 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
129129 void glRenderer_MakeTexture(glRenderer *This, TEXTURE *texture, DWORD width, DWORD height);
@@ -140,8 +140,8 @@
141141 // In-thread APIs
142142 DWORD glRenderer__Entry(glRenderer *This);
143143 BOOL glRenderer__InitGL(glRenderer *This, int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND hWnd, glDirectDraw7 *glDD7);
144 -void glRenderer__UploadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp);
145 -void glRenderer__DownloadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp);
 144+void glRenderer__UploadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel);
 145+void glRenderer__DownloadTexture(glRenderer *This, char *buffer, char *bigbuffer, TEXTURE *texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int miplevel);
146146 void glRenderer__Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
147147 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
148148 void glRenderer__MakeTexture(glRenderer *This, TEXTURE *texture, DWORD width, DWORD height);