Removed unnecessary code in Graphics.cpp

Replaced the D3DFMT_A8 texture format with D3DFMT_L8.
Minor edits to documents.
This commit is contained in:
NovaRain
2020-12-09 10:49:02 +08:00
parent 4f7937314f
commit e0d5f6a568
4 changed files with 58 additions and 89 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ WindowData=0
TextureFilter=1
;Set to 1 to do the palette conversion on the GPU
;Set to 2 to do the palette conversion on the CPU
;Set to 2 to do the palette conversion on the CPU (used for compatibility with old video cards)
;Set to 0 to pick automatically
;GPU is faster, but requires v2.0 pixel shader support
GPUBlt=0
@@ -1,5 +1,4 @@
[Highlighting]
; DX scancode of a key to press to highlight items on the ground
; 42 - SHIFT key
Key=42
@@ -21,6 +20,7 @@ CheckLOS=0
; 16 - bright yellow
; 32 - dark yellow
; 64 - purple
; You can set a custom color from the game palette by multiplying the color index value by 256 (available since sfall 4.2.7)
OutlineColor=16
; Motion Scanner mode:
+2 -1
View File
@@ -439,7 +439,8 @@ What you can do:
- add AP costs for all inventory movement including reloading
- apply or remove some special scripted effects depending on PC's armor
int arg0 - Target slot (0 - main backpack, 1 - left hand, 2 - right hand, 3 - armor slot, 4 - weapon, when reloading it by dropping ammo, 5 - container, like bag/backpack, 6 - dropping on the ground, 7 - picking up item, 8 - dropping item on the character portrait)
int arg0 - Target slot (0 - main backpack, 1 - left hand, 2 - right hand, 3 - armor slot, 4 - weapon, when reloading it by dropping ammo, 5 - container, like bag/backpack, 6 - dropping on the ground,
7 - picking up item, 8 - dropping item on the character portrait)
Item arg1 - Item being moved
Item arg2 - Item being replaced, weapon being reloaded, or container being filled (can be 0)
+51 -83
View File
@@ -87,19 +87,19 @@ IDirect3DDevice9* d3d9Device = 0;
static IDirect3DTexture9* mainTex = 0;
static IDirect3DTexture9* sTex1 = 0;
static IDirect3DTexture9* sTex2 = 0;
static IDirect3DTexture9* movieTex;
static IDirect3DSurface9* sSurf1 = 0;
static IDirect3DSurface9* sSurf2 = 0;
static IDirect3DSurface9* backBuffer = 0;
static IDirect3DVertexBuffer9* vBuffer;
static IDirect3DVertexBuffer9* vBuffer2;
static IDirect3DVertexBuffer9* movieBuffer;
static IDirect3DVertexBuffer9* vertexOrigRes;
static IDirect3DVertexBuffer9* vertexSfallRes;
static IDirect3DVertexBuffer9* vertexMovie;
static IDirect3DTexture9* gpuPalette;
static IDirect3DTexture9* movieTex;
static ID3DXEffect* gpuBltEffect;
static const char* gpuEffect =
"texture image;"
"texture palette;"
@@ -112,25 +112,24 @@ static const char* gpuEffect =
// shader for displaying head textures
"float4 P1( in float2 Tex : TEXCOORD0 ) : COLOR0 {"
"float backdrop = tex2D(s0, Tex).a;"
"float backdrop = tex2D(s0, Tex).r;"
"float3 result;"
"if (abs(backdrop - 1.0) < 0.001) {" // (48.0 / 255.0) // 48 - key index color
"result = tex2D(s2, saturate((Tex - corner) / size));"
"} else {"
"result = tex1D(s1, backdrop);"
"result = float3(result.b, result.g, result.r);"
"result = tex1D(s1, backdrop).bgr;" // get color in palette and swap R <> B
"}"
"return float4(result.r, result.g, result.b, 1);"
"return float4(result, 1);"
"}"
"technique T1"
"{"
"pass p1 { PixelShader = compile ps_2_0 P1(); }"
"}"
// main shader
"float4 P0( in float2 Tex : TEXCOORD0 ) : COLOR0 {"
"float3 result = tex1D(s1, tex2D(s0, Tex).a);" // get color in palette
"return float4(result.b, result.g, result.r, 1);" // swap R <> B
"float3 result = tex1D(s1, tex2D(s0, Tex).r);" // get color in palette
"return float4(result.bgr, 1);" // swap R <> B
"}"
"technique T0"
@@ -395,10 +394,10 @@ static void ResetDevice(bool createNew) {
mainTexLock = false;
}
if (d3d9Device->CreateTexture(ResWidth, ResHeight, 1, D3DUSAGE_DYNAMIC, GPUBlt ? D3DFMT_A8 : D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &mainTex, 0) != D3D_OK) {
if (d3d9Device->CreateTexture(ResWidth, ResHeight, 1, D3DUSAGE_DYNAMIC, GPUBlt ? D3DFMT_L8 : D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &mainTex, 0) != D3D_OK) { // D3DFMT_A8 - not supported on some older video cards
d3d9Device->CreateTexture(ResWidth, ResHeight, 1, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &mainTex, 0);
GPUBlt = 0;
MessageBoxA(window, "GPU does not support the D3DFMT_A8 texture format.\nNow CPU is used to convert the palette.",
MessageBoxA(window, "GPU does not support the D3DFMT_L8 texture format.\nNow CPU is used to convert the palette.",
"Texture format error", MB_TASKMODAL | MB_ICONWARNING);
}
@@ -420,11 +419,11 @@ static void ResetDevice(bool createNew) {
ShaderVertices[3].y = ResHeight - 0.5f;
ShaderVertices[3].x = ResWidth - 0.5f;
d3d9Device->CreateVertexBuffer(4 * sizeof(VertexFormat), D3DUSAGE_WRITEONLY | (software ? D3DUSAGE_SOFTWAREPROCESSING : 0), _VERTEXFORMAT, D3DPOOL_DEFAULT, &vBuffer, 0);
d3d9Device->CreateVertexBuffer(4 * sizeof(VertexFormat), D3DUSAGE_WRITEONLY | (software ? D3DUSAGE_SOFTWAREPROCESSING : 0), _VERTEXFORMAT, D3DPOOL_DEFAULT, &vertexOrigRes, 0);
void* vertexPointer;
vBuffer->Lock(0, 0, &vertexPointer, 0);
vertexOrigRes->Lock(0, 0, &vertexPointer, 0);
CopyMemory(vertexPointer, ShaderVertices, sizeof(ShaderVertices));
vBuffer->Unlock();
vertexOrigRes->Unlock();
VertexFormat shaderVertices[4] = {
ShaderVertices[0],
@@ -438,16 +437,16 @@ static void ResetDevice(bool createNew) {
shaderVertices[3].y = (float)gHeight - 0.5f;
shaderVertices[3].x = (float)gWidth - 0.5f;
d3d9Device->CreateVertexBuffer(4 * sizeof(VertexFormat), D3DUSAGE_WRITEONLY | (software ? D3DUSAGE_SOFTWAREPROCESSING : 0), _VERTEXFORMAT, D3DPOOL_DEFAULT, &vBuffer2, 0);
vBuffer2->Lock(0, 0, &vertexPointer, 0);
d3d9Device->CreateVertexBuffer(4 * sizeof(VertexFormat), D3DUSAGE_WRITEONLY | (software ? D3DUSAGE_SOFTWAREPROCESSING : 0), _VERTEXFORMAT, D3DPOOL_DEFAULT, &vertexSfallRes, 0);
vertexSfallRes->Lock(0, 0, &vertexPointer, 0);
CopyMemory(vertexPointer, shaderVertices, sizeof(shaderVertices));
vBuffer2->Unlock();
vertexSfallRes->Unlock();
d3d9Device->CreateVertexBuffer(4 * sizeof(VertexFormat), D3DUSAGE_WRITEONLY | (software ? D3DUSAGE_SOFTWAREPROCESSING : 0), _VERTEXFORMAT, D3DPOOL_DEFAULT, &movieBuffer, 0);
d3d9Device->CreateVertexBuffer(4 * sizeof(VertexFormat), D3DUSAGE_WRITEONLY | (software ? D3DUSAGE_SOFTWAREPROCESSING : 0), _VERTEXFORMAT, D3DPOOL_DEFAULT, &vertexMovie, 0);
d3d9Device->SetFVF(_VERTEXFORMAT);
d3d9Device->SetTexture(0, mainTex);
d3d9Device->SetStreamSource(0, vBuffer, 0, sizeof(VertexFormat));
d3d9Device->SetStreamSource(0, vertexOrigRes, 0, sizeof(VertexFormat));
//d3d9Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false); // default false
//d3d9Device->SetRenderState(D3DRS_ALPHATESTENABLE, false); // default false
@@ -519,9 +518,9 @@ static void Present() {
SAFERELEASE(sSurf2);
SAFERELEASE(sTex1);
SAFERELEASE(sTex2);
SAFERELEASE(vBuffer);
SAFERELEASE(vBuffer2);
SAFERELEASE(movieBuffer);
SAFERELEASE(vertexOrigRes);
SAFERELEASE(vertexSfallRes);
SAFERELEASE(vertexMovie);
SAFERELEASE(gpuPalette);
Gfx_ReleaseMovieTexture();
if (gpuBltEffect) gpuBltEffect->OnLostDevice();
@@ -535,21 +534,25 @@ static void Refresh() {
if (DeviceLost) return;
d3d9Device->BeginScene();
d3d9Device->SetStreamSource(0, vBuffer, 0, sizeof(VertexFormat));
d3d9Device->SetStreamSource(0, vertexOrigRes, 0, sizeof(VertexFormat));
d3d9Device->SetRenderTarget(0, sSurf1);
d3d9Device->SetTexture(0, mainTex);
UINT passes;
if ((textureFilter || shadersSize) && GPUBlt) {
if (GPUBlt) {
// converts the palette in mainTex to RGB colors on the target surface (sSurf1/sTex1)
gpuBltEffect->Begin(&passes, 0);
gpuBltEffect->BeginPass(0);
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
gpuBltEffect->EndPass();
gpuBltEffect->End();
if (shadersSize) {
d3d9Device->StretchRect(sSurf1, 0, sSurf2, 0, D3DTEXF_NONE); // copy sSurf1 to sSurf2
d3d9Device->SetTexture(0, sTex2);
} else {
d3d9Device->SetTexture(0, mainTex);
d3d9Device->SetTexture(0, sTex1);
}
}
for (int i = shadersSize - 1; i >= 0; i--) {
if (!shaders[i].Effect || !shaders[i].Active) continue;
@@ -572,19 +575,10 @@ static void Refresh() {
d3d9Device->SetTexture(0, sTex2);
}
d3d9Device->SetStreamSource(0, vBuffer2, 0, sizeof(VertexFormat));
d3d9Device->SetStreamSource(0, vertexSfallRes, 0, sizeof(VertexFormat));
d3d9Device->SetRenderTarget(0, backBuffer);
if (!textureFilter && !shadersSize && GPUBlt) {
gpuBltEffect->Begin(&passes, 0);
gpuBltEffect->BeginPass(0);
}
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
if (!textureFilter && !shadersSize && GPUBlt) {
gpuBltEffect->EndPass();
gpuBltEffect->End();
}
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); // render square with a texture image (mainTex/sTex1/sTex2) to the backBuffer
d3d9Device->EndScene();
Present();
}
@@ -667,9 +661,9 @@ void Gfx_SetMovieTexture(bool state) {
}
void* vertexPointer;
movieBuffer->Lock(0, 0, &vertexPointer, 0);
vertexMovie->Lock(0, 0, &vertexPointer, 0);
CopyMemory(vertexPointer, shaderVertices, sizeof(shaderVertices));
movieBuffer->Unlock();
vertexMovie->Unlock();
Gfx_PlayAviMovie = true;
}
@@ -687,7 +681,7 @@ void Gfx_ShowMovieFrame(IDirect3DTexture9* tex) {
} else {
d3d9Device->SetTexture(0, mainTex);
}
d3d9Device->SetStreamSource(0, vBuffer2, 0, sizeof(VertexFormat));
d3d9Device->SetStreamSource(0, vertexSfallRes, 0, sizeof(VertexFormat));
// for showing subtitles
if (GPUBlt) {
@@ -703,7 +697,7 @@ void Gfx_ShowMovieFrame(IDirect3DTexture9* tex) {
}
// for avi movie
d3d9Device->SetTexture(0, movieTex);
d3d9Device->SetStreamSource(0, movieBuffer, 0, sizeof(VertexFormat));
d3d9Device->SetStreamSource(0, vertexMovie, 0, sizeof(VertexFormat));
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
d3d9Device->EndScene();
@@ -814,38 +808,7 @@ public:
//mainTexLock = false;
//if (Gfx_PlayAviMovie) return DD_OK; // Blt method is not executed during avi playback because the sfShowFrame_ function is blocked
if (!DeviceLost) {
d3d9Device->SetTexture(0, mainTex);
d3d9Device->BeginScene();
UINT passes;
if (textureFilter && GPUBlt) { // fixes color palette distortion of movie images when texture filtering and GPUBlt are enabled
d3d9Device->SetStreamSource(0, vBuffer, 0, sizeof(VertexFormat));
d3d9Device->SetRenderTarget(0, sSurf1);
gpuBltEffect->Begin(&passes, 0);
gpuBltEffect->BeginPass(0);
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
gpuBltEffect->EndPass();
gpuBltEffect->End();
d3d9Device->SetTexture(0, sTex1);
d3d9Device->SetRenderTarget(0, backBuffer);
}
d3d9Device->SetStreamSource(0, vBuffer2, 0, sizeof(VertexFormat));
if (!textureFilter && GPUBlt) {
gpuBltEffect->Begin(&passes, 0);
gpuBltEffect->BeginPass(0);
}
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
if (!textureFilter && GPUBlt) {
gpuBltEffect->EndPass();
gpuBltEffect->End();
}
d3d9Device->EndScene();
Present();
}
Refresh();
return DD_OK;
}
@@ -923,12 +886,12 @@ public:
mainTexLock = true;
D3DLOCKED_RECT dRect;
mainTex->LockRect(0, &dRect, 0, 0);
mainTex->LockRect(0, &dRect, 0, D3DLOCK_DISCARD);
DWORD* pBits = (DWORD*)dRect.pBits;
int pitch = (dRect.Pitch / 4) - ResWidth;
BYTE* target = lockTarget;
int height = ResHeight;
while (height--) {
int width = ResWidth;
@@ -939,6 +902,7 @@ public:
}
pBits += pitch;
}
mainTex->UnlockRect(0);
mainTexLock = false;
return DD_OK;
@@ -960,7 +924,7 @@ public:
mainTexLock = true;
D3DLOCKED_RECT dRect;
mainTex->LockRect(0, &dRect, lockRect, 0);
mainTex->LockRect(0, &dRect, lockRect, (lockRect) ? 0 : D3DLOCK_DISCARD);
DWORD* pBits = (DWORD*)dRect.pBits;
int pitch = dRect.Pitch / 4;
@@ -969,16 +933,20 @@ public:
BYTE* target = (BYTE*)lockSurface;
int width = (lockRect->right - lockRect->left);
int height = (lockRect->bottom - lockRect->top);
while (height--) {
int w = width;
while (w--) pBits[w] = palette[target[w]].xRGB;
pBits += pitch;
target += ResWidth;
}
lockRect = 0;
} else {
pitch -= ResWidth;
BYTE* target = lockTarget;
int height = ResHeight;
// slow copy method
while (height--) {
int width = ResWidth;
@@ -1047,7 +1015,7 @@ public:
if (GPUBlt) {
D3DLOCKED_RECT rect;
if (gpuPalette && !FAILED(gpuPalette->LockRect(0, &rect, 0, D3DLOCK_DISCARD))) {
if (!FAILED(gpuPalette->LockRect(0, &rect, 0, D3DLOCK_DISCARD))) {
CopyMemory(rect.pBits, palette, 256 * 4);
gpuPalette->UnlockRect(0);
}
@@ -1058,7 +1026,7 @@ public:
palette[i].B = palette[i].R;
palette[i].R = clr;
}
primaryDDSurface->SetPalette(0); // update
primaryDDSurface->SetPalette(0); // update texture
if (FakeDirectDrawSurface::IsPlayMovie) return DD_OK; // prevents flickering at the beginning of playback (w/o HRP & GPUBlt=2)
}
if (!Gfx_PlayAviMovie) {
@@ -1096,13 +1064,13 @@ public:
SAFERELEASE(mainTex);
SAFERELEASE(sTex1);
SAFERELEASE(sTex2);
SAFERELEASE(vBuffer);
SAFERELEASE(vBuffer2);
SAFERELEASE(vertexOrigRes);
SAFERELEASE(vertexSfallRes);
SAFERELEASE(d3d9Device);
SAFERELEASE(d3d9);
SAFERELEASE(gpuPalette);
SAFERELEASE(gpuBltEffect);
SAFERELEASE(movieBuffer);
SAFERELEASE(vertexMovie);
delete this;
return 0;