-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPixelShader.cpp
More file actions
78 lines (66 loc) · 1.84 KB
/
PixelShader.cpp
File metadata and controls
78 lines (66 loc) · 1.84 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "PixelShader.h"
#include <d3dcompiler.h>
#include <filesystem>
PixelShader::PixelShader()
{
mPixelShader = nullptr;
}
PixelShader::~PixelShader()
{
RwD3D9DeletePixelShader(mPixelShader);
}
inline DWORD* fileread(const char* filename)
{
FILE* fp = nullptr;
long size;
fopen_s(&fp, filename, "rb");
fseek(fp, 0, SEEK_END);
size = ftell(fp);
fseek(fp, 0, SEEK_SET);
DWORD* dat = new DWORD[size];
fread_s(dat, size * sizeof(DWORD), size, 1, fp);
fclose(fp);
return dat;
}
void PixelShader::CreateFromBinary(string file)
{
string path = DEFERREDSHADERPATHBINARY + file + ".cso";
if(!std::filesystem::exists(path))
{
string message = "Failed to load shader: " + file;
MessageBox(0, &message[0], "Error", MB_OK);
}
unique_ptr<DWORD> bytes(fileread(path.c_str()));
mBinary = bytes.get();
RwD3D9CreatePixelShader((RwUInt32*)bytes.get(), &mPixelShader);
Initialize(bytes.get());
}
void PixelShader::CreateFromFile(string file, string profile)
{
string path = DEFERREDSHADERPATH + file + ".hlsl";
if(!std::filesystem::exists(path))
{
string message = "Failed to load shader: " + file;
MessageBox(0, &message[0], "Error", MB_OK);
}
ID3DBlob* vsCodeBlob;
ID3DBlob* vsErrorBlob;
std::filesystem::path parentPath = std::filesystem::canonical(path);
D3DCompileFromFile(parentPath.c_str(), NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, profile.c_str(), "ps_3_0", NULL, 0, &vsCodeBlob, &vsErrorBlob);
if(vsErrorBlob && vsErrorBlob->GetBufferPointer())
{
MessageBox(0, (char*)vsErrorBlob->GetBufferPointer(), "Error", MB_OK);
vsErrorBlob->Release();
}
RwD3D9CreatePixelShader((RwUInt32*)vsCodeBlob->GetBufferPointer(), &mPixelShader);
Initialize(vsCodeBlob->GetBufferPointer());
vsCodeBlob->Release();
}
void PixelShader::Apply()
{
_rwD3D9SetPixelShader(mPixelShader);
}
void* PixelShader::GetObject()
{
return mPixelShader;
}