forked from Hal47/dsfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GAUSS.cpp
59 lines (55 loc) · 2.39 KB
/
GAUSS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "GAUSS.h"
#include "util.h"
#include <array>
#include <string>
#include <wrl/client.h>
using namespace Microsoft;
extern HMODULE g_hDll;
GAUSS::GAUSS(IDirect3DDevice9* device, int width, int height) noexcept
: Effect(device), width(width), height(height) {
try {
spdlog::info("Gauss construct");
// Setup pixel size macro
std::string pixelSize = fmt::format("float2(1.0 / {}, 1.0 / {})", width, height);
// Setup the defines for compiling the effect
std::array<D3DXMACRO, 2> defines = {{{"PIXEL_SIZE", pixelSize.c_str()}, {nullptr, nullptr}}};
// Load effect from file
spdlog::info("Gauss load");
WRL::ComPtr<ID3DXBuffer> errors;
ThrowIfFailed(::D3DXCreateEffectFromResourceW(device, g_hDll, L"GAUSS.fx", &defines.front(),
nullptr, D3DXFX_NOT_CLONEABLE, nullptr, &effect,
&errors));
// Create buffers
ThrowIfFailed(device->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT, &buffer1Tex, nullptr));
ThrowIfFailed(buffer1Tex->GetSurfaceLevel(0, &buffer1Surf));
// get handles
frameTexHandle = effect->GetParameterByName(nullptr, "frameTex2D");
} catch (const std::system_error& err) {
spdlog::error(L"GAUSS::GAUSS: error: {}", DXGetErrorString9W(err.code().value()));
}
}
void GAUSS::go(IDirect3DTexture9* input, IDirect3DSurface9* dst) noexcept {
try {
ThrowIfFailed(device->SetVertexDeclaration(vertexDeclaration.Get()));
UINT passes;
// Horizontal blur
ThrowIfFailed(device->SetRenderTarget(0, buffer1Surf.Get()));
ThrowIfFailed(effect->SetTexture(frameTexHandle, input));
ThrowIfFailed(effect->Begin(&passes, 0));
ThrowIfFailed(effect->BeginPass(0));
quad(width, height);
ThrowIfFailed(effect->EndPass());
ThrowIfFailed(effect->End());
// Vertical blur
ThrowIfFailed(device->SetRenderTarget(0, dst));
ThrowIfFailed(effect->SetTexture(frameTexHandle, buffer1Tex.Get()));
ThrowIfFailed(effect->Begin(&passes, 0));
ThrowIfFailed(effect->BeginPass(1));
quad(width, height);
ThrowIfFailed(effect->EndPass());
ThrowIfFailed(effect->End());
} catch (const std::system_error& err) {
spdlog::error(L"{}", DXGetErrorString9W(err.code().value()));
}
}