| Index: ddraw/TextureManager.c |
| — | — | @@ -17,6 +17,7 @@ |
| 18 | 18 |
|
| 19 | 19 | #include "common.h"
|
| 20 | 20 | #include "TextureManager.h"
|
| | 21 | +#include <math.h>
|
| 21 | 22 |
|
| 22 | 23 | // Use EXACTLY one line per entry. Don't change layout of the list.
|
| 23 | 24 | static const int START_TEXFORMATS = __LINE__;
|
| — | — | @@ -54,6 +55,28 @@ |
| 55 | 56 | } while (1);
|
| 56 | 57 | }
|
| 57 | 58 |
|
| | 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 | +
|
| 58 | 81 | TextureManager *TextureManager_Create(glExtensions *glext)
|
| 59 | 82 | {
|
| 60 | 83 | TextureManager *newtex;
|
| — | — | @@ -119,6 +142,7 @@ |
| 120 | 143 | {
|
| 121 | 144 | int texformat = -1;
|
| 122 | 145 | int i;
|
| | 146 | + int x, y;
|
| 123 | 147 | GLenum error;
|
| 124 | 148 | texture->pixelformat.dwSize = sizeof(DDPIXELFORMAT);
|
| 125 | 149 | for(i = 0; i < numtexformats; i++)
|
| — | — | @@ -430,27 +454,33 @@ |
| 431 | 455 | texture->height = height;
|
| 432 | 456 | glGenTextures(1,&texture->id);
|
| 433 | 457 | 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++)
|
| 435 | 465 | {
|
| 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
|
| 440 | 467 | {
|
| 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)
|
| 442 | 473 | {
|
| 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;
|
| 445 | 481 | }
|
| 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 | + }
|
| 455 | 485 | }
|
| 456 | 486 |
|
| 457 | 487 | void TextureManager_DeleteTexture(TextureManager *This, TEXTURE *texture)
|
| Index: ddraw/TextureManager.h |
| — | — | @@ -74,6 +74,8 @@ |
| 75 | 75 | GLuint textures[16];
|
| 76 | 76 | } TextureManager;
|
| 77 | 77 |
|
| | 78 | +DWORD CalculateMipLevels(DWORD width, DWORD height);
|
| | 79 | +
|
| 78 | 80 | TextureManager *TextureManager_Create(glExtensions *glext);
|
| 79 | 81 | void TextureManager_InitSamplers(TextureManager *This);
|
| 80 | 82 | void TextureManager_DeleteSamplers(TextureManager *This);
|
| Index: ddraw/glDirectDraw.cpp |
| — | — | @@ -844,22 +844,33 @@ |
| 845 | 845 | HRESULT glDirectDraw7::CreateSurface2(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRECTDRAWSURFACE7 FAR *lplpDDSurface, IUnknown FAR *pUnkOuter, BOOL RecordSurface)
|
| 846 | 846 | {
|
| 847 | 847 | HRESULT error;
|
| | 848 | + int mipcount;
|
| 848 | 849 | 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))
|
| 853 | 854 | {
|
| 854 | | - if(primarylost)
|
| | 855 | + if (primarylost)
|
| 855 | 856 | {
|
| 856 | 857 | primary->Restore();
|
| 857 | 858 | *lplpDDSurface = primary;
|
| 858 | 859 | primarylost = false;
|
| 859 | | - TRACE_EXIT(23,DD_OK);
|
| | 860 | + TRACE_EXIT(23, DD_OK);
|
| 860 | 861 | return DD_OK;
|
| 861 | 862 | }
|
| 862 | | - else TRACE_RET(HRESULT,23,DDERR_PRIMARYSURFACEALREADYEXISTS);
|
| | 863 | + else TRACE_RET(HRESULT, 23, DDERR_PRIMARYSURFACEALREADYEXISTS);
|
| 863 | 864 | }
|
| | 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 | + }
|
| 864 | 875 | if (RecordSurface)
|
| 865 | 876 | {
|
| 866 | 877 | surfacecount++;
|
| — | — | @@ -872,7 +883,7 @@ |
| 873 | 884 | ZeroMemory(&surfaces[surfacecountmax], 1024 * sizeof(glDirectDrawSurface7 *));
|
| 874 | 885 | surfacecountmax += 1024;
|
| 875 | 886 | }
|
| 876 | | - surfaces[surfacecount - 1] = new glDirectDrawSurface7(this, lpDDSurfaceDesc2, &error, false, NULL);
|
| | 887 | + surfaces[surfacecount - 1] = new glDirectDrawSurface7(this, lpDDSurfaceDesc2, &error, NULL, NULL, 0);
|
| 877 | 888 | if (lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
| 878 | 889 | {
|
| 879 | 890 | primary = surfaces[surfacecount - 1];
|
| — | — | @@ -883,7 +894,7 @@ |
| 884 | 895 | else
|
| 885 | 896 | {
|
| 886 | 897 | 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);
|
| 888 | 899 | }
|
| 889 | 900 | TRACE_VAR("*lplpDDSurface",14,*lplpDDSurface);
|
| 890 | 901 | TRACE_EXIT(23,error);
|
| Index: ddraw/glDirectDrawSurface.cpp |
| — | — | @@ -36,9 +36,10 @@ |
| 37 | 37 |
|
| 38 | 38 |
|
| 39 | 39 | // 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)
|
| 41 | 42 | {
|
| 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);
|
| 43 | 44 | overlay = false;
|
| 44 | 45 | hasstencil = false;
|
| 45 | 46 | dirty = 2;
|
| — | — | @@ -67,23 +68,12 @@ |
| 68 | 69 | buffer = gdibuffer = NULL;
|
| 69 | 70 | bigbuffer = NULL;
|
| 70 | 71 | zbuffer = NULL;
|
| | 72 | + this->miplevel = miplevel;
|
| 71 | 73 | DWORD colormasks[3];
|
| 72 | 74 | 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;
|
| 88 | 78 | LONG sizes[6];
|
| 89 | 79 | ddInterface->GetSizes(sizes);
|
| 90 | 80 | if(ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
| — | — | @@ -209,7 +199,17 @@ |
| 210 | 200 | bitmapinfo->bmiHeader.biWidth = ddsd.dwWidth;
|
| 211 | 201 | bitmapinfo->bmiHeader.biHeight = -(signed)ddsd.dwHeight;
|
| 212 | 202 | 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;
|
| 214 | 214 | switch(surfacetype)
|
| 215 | 215 | {
|
| 216 | 216 | case 0:
|
| — | — | @@ -223,8 +223,8 @@ |
| 224 | 224 | buffer = NULL;
|
| 225 | 225 | break;
|
| 226 | 226 | case 2:
|
| | 227 | + buffer = NULL;
|
| 227 | 228 | maketex:
|
| 228 | | - buffer = NULL;
|
| 229 | 229 | if((dxglcfg.scalingfilter == 0) || (ddInterface->GetBPP() == 8)) magfilter = minfilter = GL_NEAREST;
|
| 230 | 230 | else magfilter = minfilter = GL_LINEAR;
|
| 231 | 231 | if(ddsd.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
|
| — | — | @@ -301,17 +301,32 @@ |
| 302 | 302 | }
|
| 303 | 303 | }
|
| 304 | 304 | 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))
|
| 309 | 306 | {
|
| 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);
|
| 312 | 319 | }
|
| 313 | | - texture->wraps = texture->wrapt = GL_CLAMP_TO_EDGE;
|
| 314 | | - glRenderer_MakeTexture(ddInterface->renderer,texture,fakex,fakey);
|
| 315 | 320 | }
|
| | 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 | + }
|
| 316 | 331 |
|
| 317 | 332 | if(ddsd.ddpfPixelFormat.dwRGBBitCount > 8)
|
| 318 | 333 | {
|
| — | — | @@ -337,7 +352,7 @@ |
| 338 | 353 | ddsdBack.dwBackBufferCount--;
|
| 339 | 354 | ddsdBack.ddsCaps.dwCaps |= DDSCAPS_BACKBUFFER;
|
| 340 | 355 | ddsdBack.ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER;
|
| 341 | | - backbuffer = new glDirectDrawSurface7(ddInterface,&ddsdBack,error,false,palette);
|
| | 356 | + backbuffer = new glDirectDrawSurface7(ddInterface,&ddsdBack,error,palette,parenttex,miplevel);
|
| 342 | 357 | }
|
| 343 | 358 | else if (ddsd.dwFlags & DDSD_BACKBUFFERCOUNT){}
|
| 344 | 359 | else *error = DDERR_INVALIDPARAMS;
|
| — | — | @@ -625,7 +640,7 @@ |
| 626 | 641 | glRenderer_UploadTexture(ddInterface->renderer, pattern->buffer, pattern->bigbuffer, pattern->texture,
|
| 627 | 642 | pattern->ddsd.dwWidth, pattern->ddsd.dwHeight, pattern->fakex, pattern->fakey, pattern->ddsd.lPitch,
|
| 628 | 643 | (NextMultipleOf4((ddInterface->GetBPPMultipleOf8() / 8)*pattern->fakex)),
|
| 629 | | - pattern->ddsd.ddpfPixelFormat.dwRGBBitCount);
|
| | 644 | + pattern->ddsd.ddpfPixelFormat.dwRGBBitCount,pattern->miplevel);
|
| 630 | 645 | }
|
| 631 | 646 | }
|
| 632 | 647 | if (dwFlags & DDBLT_KEYSRC)
|
| — | — | @@ -639,7 +654,7 @@ |
| 640 | 655 | {
|
| 641 | 656 | glRenderer_UploadTexture(ddInterface->renderer,buffer,bigbuffer,texture,ddsd.dwWidth,ddsd.dwHeight,
|
| 642 | 657 | fakex,fakey,ddsd.lPitch,(NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*fakex)),
|
| 643 | | - ddsd.ddpfPixelFormat.dwRGBBitCount);
|
| | 658 | + ddsd.ddpfPixelFormat.dwRGBBitCount,miplevel);
|
| 644 | 659 | dirty &= ~1;
|
| 645 | 660 | }
|
| 646 | 661 | if(src && (src->dirty & 1))
|
| — | — | @@ -647,7 +662,7 @@ |
| 648 | 663 | glRenderer_UploadTexture(ddInterface->renderer,src->buffer,src->bigbuffer,src->texture,src->ddsd.dwWidth,src->ddsd.dwHeight,
|
| 649 | 664 | src->fakex,src->fakey,src->ddsd.lPitch,
|
| 650 | 665 | (NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*src->fakex)),
|
| 651 | | - src->ddsd.ddpfPixelFormat.dwRGBBitCount);
|
| | 666 | + src->ddsd.ddpfPixelFormat.dwRGBBitCount,src->miplevel);
|
| 652 | 667 | src->dirty &= ~1;
|
| 653 | 668 | }
|
| 654 | 669 | if (clipper)
|
| — | — | @@ -822,7 +837,7 @@ |
| 823 | 838 | {
|
| 824 | 839 | glRenderer_UploadTexture(ddInterface->renderer,buffer,bigbuffer,texture,ddsd.dwWidth,ddsd.dwHeight,
|
| 825 | 840 | fakex,fakey,ddsd.lPitch,(NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*fakex)),
|
| 826 | | - ddsd.ddpfPixelFormat.dwRGBBitCount);
|
| | 841 | + ddsd.ddpfPixelFormat.dwRGBBitCount,miplevel);
|
| 827 | 842 | dirty &= ~1;
|
| 828 | 843 | }
|
| 829 | 844 | this->dirty |= 2;
|
| — | — | @@ -833,7 +848,7 @@ |
| 834 | 849 | {
|
| 835 | 850 | glRenderer_UploadTexture(ddInterface->renderer,tmp->buffer,tmp->bigbuffer,tmp->texture,tmp->ddsd.dwWidth,tmp->ddsd.dwHeight,
|
| 836 | 851 | tmp->fakex,tmp->fakey,tmp->ddsd.lPitch,(NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*tmp->fakex)),
|
| 837 | | - tmp->ddsd.ddpfPixelFormat.dwRGBBitCount);
|
| | 852 | + tmp->ddsd.ddpfPixelFormat.dwRGBBitCount,miplevel);
|
| 838 | 853 | tmp->dirty &= ~1;
|
| 839 | 854 | }
|
| 840 | 855 | tmp->dirty |= 2;
|
| — | — | @@ -1086,7 +1101,7 @@ |
| 1087 | 1102 | case 0:
|
| 1088 | 1103 | if(dirty & 2)
|
| 1089 | 1104 | 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);
|
| 1091 | 1106 | ddsd.lpSurface = buffer;
|
| 1092 | 1107 | dirty &= ~2;
|
| 1093 | 1108 | break;
|
| — | — | @@ -1101,7 +1116,7 @@ |
| 1102 | 1117 | bigbuffer = (char *)malloc((ddsd.ddpfPixelFormat.dwRGBBitCount * NextMultipleOfWord(fakex) * fakey)/8);
|
| 1103 | 1118 | else bigbuffer = NULL;
|
| 1104 | 1119 | 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);
|
| 1106 | 1121 | dirty &= ~2;
|
| 1107 | 1122 | surfacetype = 0;
|
| 1108 | 1123 | goto retry;
|
| — | — | @@ -1313,7 +1328,14 @@ |
| 1314 | 1329 | }
|
| 1315 | 1330 | else RenderScreen(texture,this,0);
|
| 1316 | 1331 | }
|
| 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);
|
| 1318 | 1340 | return DD_OK;
|
| 1319 | 1341 | }
|
| 1320 | 1342 | HRESULT WINAPI glDirectDrawSurface7::UpdateOverlay(LPRECT lpSrcRect, LPDIRECTDRAWSURFACE7 lpDDDestSurface, LPRECT lpDestRect, DWORD dwFlags, LPDDOVERLAYFX lpDDOverlayFx)
|
| Index: ddraw/glDirectDrawSurface.h |
| — | — | @@ -39,7 +39,7 @@ |
| 40 | 40 | class glDirectDrawSurface7 : public IDirectDrawSurface7
|
| 41 | 41 | {
|
| 42 | 42 | 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);
|
| 44 | 44 | virtual ~glDirectDrawSurface7();
|
| 45 | 45 | // ddraw 1+ api
|
| 46 | 46 | HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
|
| — | — | @@ -127,6 +127,8 @@ |
| 128 | 128 | TEXTURE *paltex;
|
| 129 | 129 | TEXTURE *stencil;
|
| 130 | 130 | bool hasstencil;
|
| | 131 | + DWORD miplevel;
|
| | 132 | + glDirectDrawSurface7 *miptexture;
|
| 131 | 133 | char *buffer;
|
| 132 | 134 | char *bigbuffer;
|
| 133 | 135 | char *gdibuffer;
|
| Index: ddraw/glRenderer.cpp |
| — | — | @@ -98,14 +98,16 @@ |
| 99 | 99 | * Pitch of the scaled surface buffer
|
| 100 | 100 | * @param bpp
|
| 101 | 101 | * Number of bits per surface pixel
|
| | 102 | + * @param miplevel
|
| | 103 | + * Mipmap level of texture to write
|
| 102 | 104 | */
|
| 103 | 105 | 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)
|
| 105 | 107 | {
|
| 106 | 108 | if(bpp == 15) bpp = 16;
|
| 107 | 109 | if((x == bigx && y == bigy) || !bigbuffer)
|
| 108 | 110 | {
|
| 109 | | - TextureManager__UploadTexture(This->texman, texture, 0, buffer, x, y, FALSE);
|
| | 111 | + TextureManager__UploadTexture(This->texman, texture, miplevel, buffer, x, y, FALSE);
|
| 110 | 112 | }
|
| 111 | 113 | else
|
| 112 | 114 | {
|
| — | — | @@ -125,7 +127,7 @@ |
| 126 | 128 | break;
|
| 127 | 129 | break;
|
| 128 | 130 | }
|
| 129 | | - TextureManager__UploadTexture(This->texman, texture, 0, bigbuffer, bigx, bigy, FALSE);
|
| | 131 | + TextureManager__UploadTexture(This->texman, texture, miplevel, bigbuffer, bigx, bigy, FALSE);
|
| 130 | 132 | }
|
| 131 | 133 | }
|
| 132 | 134 |
|
| — | — | @@ -150,17 +152,19 @@ |
| 151 | 153 | * Pitch of the scaled surface buffer
|
| 152 | 154 | * @param bpp
|
| 153 | 155 | * Number of bits per surface pixel
|
| | 156 | + * @param miplevel
|
| | 157 | + * Mipmap level of texture to read
|
| 154 | 158 | */
|
| 155 | 159 | 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)
|
| 157 | 161 | {
|
| 158 | 162 | if((bigx == x && bigy == y) || !bigbuffer)
|
| 159 | 163 | {
|
| 160 | | - TextureManager__DownloadTexture(This->texman,texture,0,buffer);
|
| | 164 | + TextureManager__DownloadTexture(This->texman,texture,miplevel,buffer);
|
| 161 | 165 | }
|
| 162 | 166 | else
|
| 163 | 167 | {
|
| 164 | | - TextureManager__DownloadTexture(This->texman,texture,0,bigbuffer);
|
| | 168 | + TextureManager__DownloadTexture(This->texman,texture,miplevel,bigbuffer);
|
| 165 | 169 | switch(bpp)
|
| 166 | 170 | {
|
| 167 | 171 | case 8:
|
| — | — | @@ -320,9 +324,11 @@ |
| 321 | 325 | * Pitch of the scaled surface buffer
|
| 322 | 326 | * @param bpp
|
| 323 | 327 | * Number of bits per surface pixel
|
| | 328 | + * @param miplevel
|
| | 329 | + * Mipmap level of texture to write
|
| 324 | 330 | */
|
| 325 | 331 | 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)
|
| 327 | 333 | {
|
| 328 | 334 | EnterCriticalSection(&This->cs);
|
| 329 | 335 | This->inputs[0] = buffer;
|
| — | — | @@ -335,6 +341,7 @@ |
| 336 | 342 | This->inputs[7] = (void*)pitch;
|
| 337 | 343 | This->inputs[8] = (void*)bigpitch;
|
| 338 | 344 | This->inputs[9] = (void*)bpp;
|
| | 345 | + This->inputs[10] = (void*)miplevel;
|
| 339 | 346 | This->opcode = OP_UPLOAD;
|
| 340 | 347 | SetEvent(This->start);
|
| 341 | 348 | WaitForSingleObject(This->busy,INFINITE);
|
| — | — | @@ -362,9 +369,11 @@ |
| 363 | 370 | * Pitch of the scaled surface buffer
|
| 364 | 371 | * @param bpp
|
| 365 | 372 | * Number of bits per surface pixel
|
| | 373 | + * @param miplevel
|
| | 374 | + * Mipmap level of texture to read
|
| 366 | 375 | */
|
| 367 | 376 | 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)
|
| 369 | 378 | {
|
| 370 | 379 | EnterCriticalSection(&This->cs);
|
| 371 | 380 | This->inputs[0] = buffer;
|
| — | — | @@ -377,6 +386,7 @@ |
| 378 | 387 | This->inputs[7] = (void*)pitch;
|
| 379 | 388 | This->inputs[8] = (void*)bigpitch;
|
| 380 | 389 | This->inputs[9] = (void*)bpp;
|
| | 390 | + This->inputs[10] = (void*)miplevel;
|
| 381 | 391 | This->opcode = OP_DOWNLOAD;
|
| 382 | 392 | SetEvent(This->start);
|
| 383 | 393 | WaitForSingleObject(This->busy,INFINITE);
|
| — | — | @@ -749,13 +759,13 @@ |
| 750 | 760 | case OP_UPLOAD:
|
| 751 | 761 | glRenderer__UploadTexture(This,(char*)This->inputs[0],(char*)This->inputs[1],(TEXTURE*)This->inputs[2],
|
| 752 | 762 | (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]);
|
| 754 | 764 | SetEvent(This->busy);
|
| 755 | 765 | break;
|
| 756 | 766 | case OP_DOWNLOAD:
|
| 757 | 767 | glRenderer__DownloadTexture(This,(char*)This->inputs[0],(char*)This->inputs[1],(TEXTURE*)This->inputs[2],
|
| 758 | 768 | (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]);
|
| 760 | 770 | SetEvent(This->busy);
|
| 761 | 771 | break;
|
| 762 | 772 | case OP_DELETETEX:
|
| — | — | @@ -1450,7 +1460,7 @@ |
| 1451 | 1461 | glRenderer__UploadTexture(This,src->buffer,src->bigbuffer,texture,src->ddsd.dwWidth,src->ddsd.dwHeight,
|
| 1452 | 1462 | src->fakex,src->fakey,src->ddsd.lPitch,
|
| 1453 | 1463 | (NextMultipleOf4((This->ddInterface->GetBPPMultipleOf8()/8)*src->fakex)),
|
| 1454 | | - src->ddsd.ddpfPixelFormat.dwRGBBitCount);
|
| | 1464 | + src->ddsd.ddpfPixelFormat.dwRGBBitCount,src->miplevel);
|
| 1455 | 1465 | src->dirty &= ~1;
|
| 1456 | 1466 | }
|
| 1457 | 1467 | if(dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
| — | — | @@ -1963,7 +1973,7 @@ |
| 1964 | 1974 | device->texstages[i].texture->ddsd.dwHeight,device->texstages[i].texture->fakex,
|
| 1965 | 1975 | device->texstages[i].texture->fakey,device->texstages[i].texture->ddsd.lPitch,
|
| 1966 | 1976 | (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);
|
| 1968 | 1978 | device->texstages[i].texture->dirty &= ~1;
|
| 1969 | 1979 | }
|
| 1970 | 1980 | if(device->texstages[i].texture)
|
| Index: ddraw/glRenderer.h |
| — | — | @@ -121,8 +121,8 @@ |
| 122 | 122 | void glRenderer_Init(glRenderer *This, int width, int height, int bpp, bool fullscreen, unsigned int frequency, HWND hwnd, glDirectDraw7 *glDD7, BOOL devwnd);
|
| 123 | 123 | void glRenderer_Delete(glRenderer *This);
|
| 124 | 124 | 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);
|
| 127 | 127 | HRESULT glRenderer_Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
| 128 | 128 | glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
|
| 129 | 129 | void glRenderer_MakeTexture(glRenderer *This, TEXTURE *texture, DWORD width, DWORD height);
|
| — | — | @@ -140,8 +140,8 @@ |
| 141 | 141 | // In-thread APIs
|
| 142 | 142 | DWORD glRenderer__Entry(glRenderer *This);
|
| 143 | 143 | 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);
|
| 146 | 146 | void glRenderer__Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
| 147 | 147 | glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
|
| 148 | 148 | void glRenderer__MakeTexture(glRenderer *This, TEXTURE *texture, DWORD width, DWORD height);
|