From fc5863ac467db0ae6a743e34c9f8363a344be591 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Mon, 17 Jan 2022 12:12:08 +0800 Subject: [PATCH] Added a new warning message on shader effects to Graphics.cpp --- sfall/Modules/Graphics.cpp | 51 ++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/sfall/Modules/Graphics.cpp b/sfall/Modules/Graphics.cpp index 8ecdde17..78d2e02b 100644 --- a/sfall/Modules/Graphics.cpp +++ b/sfall/Modules/Graphics.cpp @@ -179,12 +179,10 @@ static void ResetDevice(bool create) { static D3DFORMAT textureFormat = D3DFMT_X8R8G8B8; if (create) { - bool A8_IsSupport = false; - dlog("Creating D3D9 Device...", DL_MAIN); if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_PUREDEVICE | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE, ¶ms, &d3d9Device))) { MessageBoxA(window, "Failed to create hardware vertex processing device.\nUsing software vertex processing instead.", - "D3D9 Device", MB_TASKMODAL | MB_ICONWARNING); + "sfall DX9", MB_TASKMODAL | MB_ICONWARNING); software = true; d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE, ¶ms, &d3d9Device); } @@ -196,33 +194,42 @@ static void ResetDevice(bool create) { // Use: 0 - only CPU, 1 - force GPU, 2 - Auto Mode (GPU or switch to CPU) if (Graphics::GPUBlt == 2 && ShaderVersion < 20) Graphics::GPUBlt = 0; + bool A8IsSupported = (d3d9Device->CreateTexture(ResWidth, ResHeight, 1, 0, D3DFMT_A8, D3DPOOL_SYSTEMMEM, &mainTex, 0) == D3D_OK); + if (Graphics::GPUBlt) { - d3d9Device->CreateTexture(256, 1, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &paletteTex, 0); + const char* shader = (A8IsSupported) ? gpuEffectA8 : gpuEffectL8; + if (D3DXCreateEffect(d3d9Device, shader, strlen(shader), 0, 0, 0, 0, &gpuBltEffect, 0) == D3D_OK) { + gpuBltMainTex = gpuBltEffect->GetParameterByName(0, "image"); + gpuBltPalette = gpuBltEffect->GetParameterByName(0, "palette"); + // for head textures + gpuBltHead = gpuBltEffect->GetParameterByName(0, "head"); + gpuBltHeadSize = gpuBltEffect->GetParameterByName(0, "size"); + gpuBltHeadCorner = gpuBltEffect->GetParameterByName(0, "corner"); + gpuBltHighlight = gpuBltEffect->GetParameterByName(0, "highlight"); + gpuBltHighlightSize = gpuBltEffect->GetParameterByName(0, "sizehl"); + gpuBltHighlightCorner = gpuBltEffect->GetParameterByName(0, "cornerhl"); + gpuBltShowHighlight = gpuBltEffect->GetParameterByName(0, "showhl"); - A8_IsSupport = (d3d9Device->CreateTexture(ResWidth, ResHeight, 1, 0, D3DFMT_A8, D3DPOOL_SYSTEMMEM, &mainTex, 0) == D3D_OK); - textureFormat = (A8_IsSupport) ? D3DFMT_A8 : D3DFMT_L8; // D3DFMT_A8 - not supported on some older video cards + Graphics::SetDefaultTechnique(); - const char* shader = (A8_IsSupport) ? gpuEffectA8 : gpuEffectL8; - D3DXCreateEffect(d3d9Device, shader, strlen(shader), 0, 0, 0, 0, &gpuBltEffect, 0); - gpuBltMainTex = gpuBltEffect->GetParameterByName(0, "image"); - gpuBltPalette = gpuBltEffect->GetParameterByName(0, "palette"); - // for head textures - gpuBltHead = gpuBltEffect->GetParameterByName(0, "head"); - gpuBltHeadSize = gpuBltEffect->GetParameterByName(0, "size"); - gpuBltHeadCorner = gpuBltEffect->GetParameterByName(0, "corner"); - gpuBltHighlight = gpuBltEffect->GetParameterByName(0, "highlight"); - gpuBltHighlightSize = gpuBltEffect->GetParameterByName(0, "sizehl"); - gpuBltHighlightCorner = gpuBltEffect->GetParameterByName(0, "cornerhl"); - gpuBltShowHighlight = gpuBltEffect->GetParameterByName(0, "showhl"); + d3d9Device->CreateTexture(256, 1, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &paletteTex, 0); - Graphics::SetDefaultTechnique(); + textureFormat = (A8IsSupported) ? D3DFMT_A8 : D3DFMT_L8; // D3DFMT_A8 - not supported on some older video cards + } else { + MessageBoxA(window, "Failed to create shader effects.\nSwitching to CPU for the palette conversion.", + "sfall DX9", MB_TASKMODAL | MB_ICONWARNING); + if (mainTex) SAFERELEASE(mainTex); // release D3DFMT_A8 format texture + Graphics::GPUBlt = 0; + A8IsSupported = false; + } } - if (!A8_IsSupport && d3d9Device->CreateTexture(ResWidth, ResHeight, 1, 0, textureFormat, D3DPOOL_SYSTEMMEM, &mainTex, 0) != D3D_OK) { + if (!A8IsSupported && d3d9Device->CreateTexture(ResWidth, ResHeight, 1, 0, textureFormat, D3DPOOL_SYSTEMMEM, &mainTex, 0) != D3D_OK) { textureFormat = D3DFMT_X8R8G8B8; d3d9Device->CreateTexture(ResWidth, ResHeight, 1, 0, textureFormat, D3DPOOL_SYSTEMMEM, &mainTex, 0); - 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); + MessageBoxA(window, "Texture format error.\nGPU does not support the D3DFMT_L8 texture format.\nNow CPU is used to convert the palette.\n" + "Set 'GPUBlt' option to CPU to bypass this warning message.", + "sfall DX9", MB_TASKMODAL | MB_ICONWARNING); Graphics::GPUBlt = 0; } if (Graphics::GPUBlt == 0) palette = new DirectDraw::PALCOLOR[256];