-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59ea4ff
commit 69d9c94
Showing
50 changed files
with
888 additions
and
453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
{ | ||
"FolderOrderSettings": [ | ||
{"name":"ShaderOverride","order":1,"path":"folders/Examples/ShaderOverride.yy",}, | ||
{"name":"InstancedRendering","order":1,"path":"folders/Examples/InstancedRendering.yy",}, | ||
], | ||
"ResourceOrderSettings": [ | ||
{"name":"RmShaderOverride","order":1,"path":"rooms/RmShaderOverride/RmShaderOverride.yy",}, | ||
{"name":"RmInstancedRendering","order":1,"path":"rooms/RmInstancedRendering/RmInstancedRendering.yy",}, | ||
{"name":"RmVTF","order":1,"path":"rooms/RmVTF/RmVTF.yy",}, | ||
{"name":"__d3d11_shader","order":2,"path":"scripts/__d3d11_shader/__d3d11_shader.yy",}, | ||
{"name":"SprRubberDuck","order":2,"path":"sprites/SprRubberDuck/SprRubberDuck.yy",}, | ||
{"name":"__d3d11_cbuffer","order":1,"path":"scripts/__d3d11_cbuffer/__d3d11_cbuffer.yy",}, | ||
{"name":"SprVTF","order":3,"path":"sprites/SprVTF/SprVTF.yy",}, | ||
{"name":"yamc","order":1,"path":"scripts/yamc/yamc.yy",}, | ||
{"name":"ShVTF","order":2,"path":"shaders/ShVTF/ShVTF.yy",}, | ||
], | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include <element.hpp> | ||
|
||
#include <cstdint> | ||
#include <d3d11.h> | ||
#include <unordered_map> | ||
|
||
extern std::unordered_map<size_t, class CBuffer*> gCBuffers; | ||
|
||
class CBuffer | ||
{ | ||
public: | ||
~CBuffer() | ||
{ | ||
if (Buffer) | ||
{ | ||
Buffer->Release(); | ||
} | ||
} | ||
|
||
bool AddElement(ElementType type, uint32_t count) | ||
{ | ||
if (count < 1) | ||
{ | ||
return false; | ||
} | ||
Size += GetElementSize(type) * count; | ||
return true; | ||
} | ||
|
||
size_t GetSize() const | ||
{ | ||
return Size; | ||
} | ||
|
||
ID3D11Buffer* Buffer = nullptr; | ||
|
||
private: | ||
size_t Size = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <Shader.hpp> | ||
|
||
class PShader : public Shader | ||
{ | ||
public: | ||
PShader(ID3DBlob* blob, ID3D11PixelShader* shader) | ||
: Raw(shader) | ||
, Shader(blob) | ||
{ | ||
} | ||
|
||
~PShader() | ||
{ | ||
if (Raw) | ||
{ | ||
Raw->Release(); | ||
} | ||
} | ||
|
||
ID3D11PixelShader* GetShader() const | ||
{ | ||
return Raw; | ||
} | ||
|
||
private: | ||
ID3D11PixelShader* Raw = nullptr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include <d3d11.h> | ||
#include <unordered_map> | ||
|
||
extern std::unordered_map<size_t, class Shader*> gShaders; | ||
|
||
class Shader | ||
{ | ||
public: | ||
Shader(ID3DBlob* blob) | ||
: Blob(blob) | ||
{ | ||
} | ||
|
||
virtual ~Shader() | ||
{ | ||
if (Blob) | ||
{ | ||
Blob->Release(); | ||
} | ||
} | ||
|
||
ID3DBlob* GetBlob() const | ||
{ | ||
return Blob; | ||
} | ||
|
||
private: | ||
ID3DBlob* Blob = nullptr; | ||
}; | ||
|
||
// Source: https://learn.microsoft.com/en-us/windows/win32/direct3d11/how-to--compile-a-shader | ||
HRESULT CompileShader(_In_ LPCWSTR srcFile, _In_ LPCSTR entryPoint, _In_ LPCSTR profile, _Outptr_ ID3DBlob** blob); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <Shader.hpp> | ||
|
||
class VShader : public Shader | ||
{ | ||
public: | ||
VShader(ID3DBlob* blob, ID3D11VertexShader* shader) | ||
: Raw(shader) | ||
, Shader(blob) | ||
{ | ||
} | ||
|
||
~VShader() | ||
{ | ||
if (Raw) | ||
{ | ||
Raw->Release(); | ||
} | ||
} | ||
|
||
ID3D11VertexShader* GetShader() const | ||
{ | ||
return Raw; | ||
} | ||
|
||
private: | ||
ID3D11VertexShader* Raw = nullptr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
enum class ElementType | ||
{ | ||
Bool, | ||
Int, | ||
Uint, | ||
Float | ||
}; | ||
|
||
size_t GetElementSize(ElementType type); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
|
||
// Source: https://stackoverflow.com/a/19717944 | ||
wchar_t* ConvertCharArrayToLPCWSTR(const char* charArray); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <PShader.hpp> | ||
|
||
#include <exports.hpp> | ||
#include <Shader.hpp> | ||
#include <utils.hpp> | ||
|
||
#include <iostream> | ||
|
||
extern ID3D11Device* gDevice; | ||
|
||
extern ID3D11DeviceContext* gContext; | ||
|
||
extern char* gErrorString; | ||
|
||
extern size_t gShaderID; | ||
|
||
ID3D11PixelShader* gOverridePS = nullptr; | ||
|
||
static PShader* CompilePS(char* file, char* entryPoint, char* profile) | ||
{ | ||
ID3DBlob* blob = nullptr; | ||
LPCWSTR path = ConvertCharArrayToLPCWSTR(file); | ||
HRESULT hr = CompileShader(path, (LPCSTR)entryPoint, (LPCSTR)profile, &blob); | ||
delete path; | ||
|
||
if (FAILED(hr)) | ||
{ | ||
std::cout << "Failed compiling PS " << file << "!" << std::endl; | ||
return nullptr; | ||
} | ||
|
||
ID3D11PixelShader* ps = nullptr; | ||
hr = gDevice->CreatePixelShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, &ps); | ||
|
||
if (FAILED(hr)) | ||
{ | ||
std::cout << "Failed creating PS " << file << "!" << std::endl; | ||
return nullptr; | ||
} | ||
|
||
std::cout << "Compiled PS " << file << std::endl; | ||
|
||
return new PShader(blob, ps); | ||
} | ||
|
||
GM_EXPORT double d3d11_shader_compile_ps(char* file, char* entryPoint, char* profile) | ||
{ | ||
PShader* shader = CompilePS(file, entryPoint, profile); | ||
if (!shader) | ||
{ | ||
return -1.0; | ||
} | ||
size_t index = gShaderID++; | ||
gShaders[index] = shader; | ||
return (double)index; | ||
} | ||
|
||
GM_EXPORT double d3d11_shader_override_ps(double ps) | ||
{ | ||
gOverridePS = (ps >= 0.0) ? ((PShader*)gShaders[(size_t)ps])->GetShader() : nullptr; | ||
return GM_TRUE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <VShader.hpp> | ||
|
||
#include <exports.hpp> | ||
#include <Shader.hpp> | ||
#include <utils.hpp> | ||
|
||
#include <iostream> | ||
|
||
extern ID3D11Device* gDevice; | ||
|
||
extern ID3D11DeviceContext* gContext; | ||
|
||
extern char* gErrorString; | ||
|
||
extern size_t gShaderID; | ||
|
||
ID3D11VertexShader* gOverrideVS = nullptr; | ||
|
||
static VShader* CompileVS(char* file, char* entryPoint, char* profile) | ||
{ | ||
ID3DBlob* blob = nullptr; | ||
LPCWSTR path = ConvertCharArrayToLPCWSTR(file); | ||
HRESULT hr = CompileShader(path, (LPCSTR)entryPoint, (LPCSTR)profile, &blob); | ||
delete path; | ||
|
||
if (FAILED(hr)) | ||
{ | ||
std::cout << "Failed compiling VS " << file << "!" << std::endl; | ||
return nullptr; | ||
} | ||
|
||
ID3D11VertexShader* vs = nullptr; | ||
hr = gDevice->CreateVertexShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, &vs); | ||
|
||
if (FAILED(hr)) | ||
{ | ||
std::cout << "Failed creating VS " << file << "!" << std::endl; | ||
return nullptr; | ||
} | ||
|
||
std::cout << "Compiled VS " << file << std::endl; | ||
|
||
return new VShader(blob, vs); | ||
} | ||
|
||
GM_EXPORT double d3d11_shader_compile_vs(char* file, char* entryPoint, char* profile) | ||
{ | ||
VShader* shader = CompileVS(file, entryPoint, profile); | ||
if (!shader) | ||
{ | ||
return -1.0; | ||
} | ||
size_t index = gShaderID++; | ||
gShaders[index] = shader; | ||
return (double)index; | ||
} | ||
|
||
GM_EXPORT double d3d11_shader_override_vs(double vs) | ||
{ | ||
gOverrideVS = (vs >= 0.0) ? ((VShader*)gShaders[(size_t)vs])->GetShader() : nullptr; | ||
return GM_TRUE; | ||
} |
Oops, something went wrong.