DXGL r141 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r140‎ | r141 | r142 >
Date:22:14, 16 April 2012
Author:admin
Status:new
Tags:
Comment:
Add texture filtering.
Modified paths:
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DDevice.cpp
@@ -145,8 +145,10 @@
146146 0,
147147 D3DTTFF_DISABLE,
148148 NULL,
 149+ false,
149150 0,
150 - 0
 151+ GL_NEAREST,
 152+ GL_NEAREST
151153 };
152154 const TEXTURESTAGE texstagedefault1 =
153155 {
@@ -995,16 +997,101 @@
996998 if(!dwValue || (dwValue > 5)) return DDERR_INVALIDPARAMS;
997999 texstages[dwStage].magfilter = (D3DTEXTUREMAGFILTER)dwValue;
9981000 texstages[dwStage].dirty = true;
 1001+ switch(texstages[dwStage].magfilter)
 1002+ {
 1003+ case 1:
 1004+ default:
 1005+ texstages[dwStage].glmagfilter = GL_NEAREST;
 1006+ break;
 1007+ case 2:
 1008+ case 3:
 1009+ case 4:
 1010+ case 5:
 1011+ texstages[dwStage].glmagfilter = GL_LINEAR;
 1012+ break;
 1013+ }
9991014 return D3D_OK;
10001015 case D3DTSS_MINFILTER:
10011016 if(!dwValue || (dwValue > 3)) return DDERR_INVALIDPARAMS;
10021017 texstages[dwStage].minfilter = (D3DTEXTUREMINFILTER)dwValue;
10031018 texstages[dwStage].dirty = true;
 1019+ switch(texstages[dwStage].minfilter)
 1020+ {
 1021+ case 1:
 1022+ default:
 1023+ switch(texstages[dwStage].mipfilter)
 1024+ {
 1025+ case 1:
 1026+ default:
 1027+ texstages[dwStage].glminfilter = GL_NEAREST;
 1028+ break;
 1029+ case 2:
 1030+ texstages[dwStage].glminfilter = GL_NEAREST_MIPMAP_NEAREST;
 1031+ break;
 1032+ case 3:
 1033+ texstages[dwStage].glminfilter = GL_NEAREST_MIPMAP_LINEAR;
 1034+ break;
 1035+ }
 1036+ break;
 1037+ case 2:
 1038+ case 3:
 1039+ switch(texstages[dwStage].mipfilter)
 1040+ {
 1041+ case 1:
 1042+ default:
 1043+ texstages[dwStage].glminfilter = GL_LINEAR;
 1044+ break;
 1045+ case 2:
 1046+ texstages[dwStage].glminfilter = GL_LINEAR_MIPMAP_NEAREST;
 1047+ break;
 1048+ case 3:
 1049+ texstages[dwStage].glminfilter = GL_LINEAR_MIPMAP_LINEAR;
 1050+ break;
 1051+ }
 1052+ break;
 1053+ }
10041054 return D3D_OK;
10051055 case D3DTSS_MIPFILTER:
10061056 if(!dwValue || (dwValue > 3)) return DDERR_INVALIDPARAMS;
10071057 texstages[dwStage].mipfilter = (D3DTEXTUREMIPFILTER)dwValue;
10081058 texstages[dwStage].dirty = true;
 1059+ switch(texstages[dwStage].mipfilter)
 1060+ {
 1061+ case 1:
 1062+ default:
 1063+ switch(texstages[dwStage].minfilter)
 1064+ {
 1065+ case 1:
 1066+ default:
 1067+ texstages[dwStage].glminfilter = GL_NEAREST;
 1068+ case 2:
 1069+ case 3:
 1070+ texstages[dwStage].glminfilter = GL_LINEAR;
 1071+ }
 1072+ break;
 1073+ case 2:
 1074+ switch(texstages[dwStage].minfilter)
 1075+ {
 1076+ case 1:
 1077+ default:
 1078+ texstages[dwStage].glminfilter = GL_NEAREST_MIPMAP_NEAREST;
 1079+ case 2:
 1080+ case 3:
 1081+ texstages[dwStage].glminfilter = GL_LINEAR_MIPMAP_NEAREST;
 1082+ }
 1083+ break;
 1084+ case 3:
 1085+ switch(texstages[dwStage].minfilter)
 1086+ {
 1087+ case 1:
 1088+ default:
 1089+ texstages[dwStage].glminfilter = GL_NEAREST_MIPMAP_LINEAR;
 1090+ case 2:
 1091+ case 3:
 1092+ texstages[dwStage].glminfilter = GL_LINEAR_MIPMAP_LINEAR;
 1093+ }
 1094+ break;
 1095+ }
10091096 return D3D_OK;
10101097 case D3DTSS_MIPMAPLODBIAS:
10111098 memcpy(&texstages[dwStage].lodbias,&dwValue,sizeof(D3DVALUE));
Index: ddraw/glDirect3DDevice.h
@@ -50,6 +50,8 @@
5151 glDirectDrawSurface7 *texture;
5252 bool dirty;
5353 __int64 shaderid;
 54+ GLint glmagfilter;
 55+ GLint glminfilter;
5456 };
5557
5658 class glDirect3DLight;
Index: ddraw/glDirectDrawSurface.cpp
@@ -56,7 +56,7 @@
5757 bigbuffer = NULL;
5858 zbuffer = NULL;
5959 DWORD colormasks[3];
60 - filter = GL_NEAREST;
 60+ magfilter = minfilter = GL_NEAREST;
6161 if(copysurface)
6262 {
6363 FIXME("glDirectDrawSurface7::glDirectDrawSurface7: copy surface stub\n");
@@ -197,8 +197,8 @@
198198 case 2:
199199 maketex:
200200 buffer = NULL;
201 - if((dxglcfg.scalingfilter == 0) || (ddInterface->GetBPP() == 8)) filter = GL_NEAREST;
202 - else filter = GL_LINEAR;
 201+ if((dxglcfg.scalingfilter == 0) || (ddInterface->GetBPP() == 8)) magfilter = minfilter = GL_NEAREST;
 202+ else magfilter = minfilter = GL_LINEAR;
203203 if(ddsd.dwFlags & DDSD_PIXELFORMAT)
204204 {
205205 if(ddsd.ddpfPixelFormat.dwFlags & DDPF_RGB)
@@ -388,7 +388,7 @@
389389 return;
390390 }
391391 }
392 - texture = renderer->MakeTexture(filter,filter,GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE,fakex,fakey,texformat,texformat2,texformat3);
 392+ texture = renderer->MakeTexture(minfilter,magfilter,GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE,fakex,fakey,texformat,texformat2,texformat3);
393393 }
394394
395395 if(ddsd.ddpfPixelFormat.dwRGBBitCount > 8)
@@ -973,7 +973,7 @@
974974 if(backbuffer) backbuffer->Restore2();
975975 if(zbuffer) zbuffer->Restore2();
976976 if(paltex) paltex = renderer->MakeTexture(GL_NEAREST,GL_NEAREST,GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE,256,1,GL_RGBA,GL_UNSIGNED_BYTE,GL_RGB);
977 - texture = renderer->MakeTexture(filter,filter,GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE,fakex,fakey,texformat,texformat2,texformat3);
 977+ texture = renderer->MakeTexture(minfilter,magfilter,GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE,fakex,fakey,texformat,texformat2,texformat3);
978978 }
979979 }
980980 HRESULT WINAPI glDirectDrawSurface7::Restore()
@@ -1017,7 +1017,7 @@
10181018 if(zbuffer) zbuffer->Restore();
10191019 }
10201020 if(paltex) paltex = renderer->MakeTexture(GL_NEAREST,GL_NEAREST,GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE,256,1,GL_RGBA,GL_UNSIGNED_BYTE,GL_RGB);
1021 - texture = renderer->MakeTexture(filter,filter,GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE,fakex,fakey,texformat,texformat2,texformat3);
 1021+ texture = renderer->MakeTexture(minfilter,magfilter,GL_CLAMP_TO_EDGE,GL_CLAMP_TO_EDGE,fakex,fakey,texformat,texformat2,texformat3);
10221022 return DD_OK;
10231023 }
10241024 else return DD_OK;
@@ -1190,6 +1190,47 @@
11911191 if(!this) return DDERR_INVALIDPARAMS;
11921192 return Unlock((LPRECT)lpSurfaceData);
11931193 }
 1194+void glDirectDrawSurface7::SetFilter(int level, GLint mag, GLint min)
 1195+{
 1196+ switch(dxglcfg.texfilter)
 1197+ {
 1198+ default:
 1199+ break;
 1200+ case 1:
 1201+ mag = min = GL_NEAREST;
 1202+ break;
 1203+ case 2:
 1204+ mag = min = GL_LINEAR;
 1205+ break;
 1206+ case 3:
 1207+ mag = GL_NEAREST;
 1208+ min = GL_NEAREST_MIPMAP_NEAREST;
 1209+ break;
 1210+ case 4:
 1211+ mag = GL_NEAREST;
 1212+ min = GL_NEAREST_MIPMAP_LINEAR;
 1213+ break;
 1214+ case 5:
 1215+ mag = GL_LINEAR;
 1216+ min = GL_LINEAR_MIPMAP_NEAREST;
 1217+ break;
 1218+ case 6:
 1219+ mag = GL_LINEAR;
 1220+ min = GL_LINEAR_MIPMAP_LINEAR;
 1221+ break;
 1222+ }
 1223+ if((magfilter != mag) || (minfilter != min)) ::SetTexture(level,texture);
 1224+ if(magfilter != mag)
 1225+ {
 1226+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,mag);
 1227+ magfilter = mag;
 1228+ }
 1229+ if(minfilter != min)
 1230+ {
 1231+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,min);
 1232+ minfilter = min;
 1233+ }
 1234+}
11941235
11951236 // DDRAW1 wrapper
11961237 glDirectDrawSurface1::glDirectDrawSurface1(glDirectDrawSurface7 *gl_DDS7)
Index: ddraw/glDirectDrawSurface.h
@@ -92,6 +92,7 @@
9393 HRESULT WINAPI GetPriority(LPDWORD lpdwPriority);
9494 HRESULT WINAPI SetLOD(DWORD dwMaxLOD);
9595 HRESULT WINAPI GetLOD(LPDWORD lpdwMaxLOD);
 96+ void SetFilter(int level, GLint mag, GLint min);
9697 // internal functions
9798 GLuint GetTexture(){
9899 return texture;
@@ -140,7 +141,7 @@
141142 glDirectDrawSurface7 *backbuffer;
142143 glDirectDrawClipper *clipper;
143144 int pagelocked;
144 - GLint filter;
 145+ GLint magfilter,minfilter;
145146 };
146147
147148 // Legacy DDRAW Interfaces
Index: ddraw/glRenderer.cpp
@@ -1053,7 +1053,6 @@
10541054 }
10551055 for(i = 0; i < 2; i++)
10561056 {
1057 - GLint colorloc;
10581057 if(vertices[i+8].data)
10591058 {
10601059 if(prog.attribs[8+i] != -1)
@@ -1159,6 +1158,8 @@
11601159 device->texstages[i].texture->texformat2,device->texstages[i].texture->texformat3);
11611160 device->texstages[i].texture->dirty &= ~1;
11621161 }
 1162+ if(device->texstages[i].texture)
 1163+ device->texstages[i].texture->SetFilter(i,device->texstages[i].glmagfilter,device->texstages[i].glminfilter);
11631164 SetTexture(i,device->texstages[i].texture->texture);
11641165 }
11651166 else SetTexture(i,0);