2013-11-29 10:25:27 +01:00
|
|
|
#include "GeneralLoader.h"
|
|
|
|
#include "..\Core\Dx11Includes.h"
|
|
|
|
#include "..\Core\Core.h"
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Graphics
|
|
|
|
{
|
|
|
|
namespace Loading
|
|
|
|
{
|
2014-01-31 16:29:50 +01:00
|
|
|
void* LoadShader(const wchar_t filename[], int type);
|
2013-12-05 14:56:34 +01:00
|
|
|
|
2013-11-29 10:25:27 +01:00
|
|
|
void UnloadShaderP(void* loadedData)
|
|
|
|
{
|
|
|
|
ID3D11PixelShader* ps = ((ID3D11PixelShader*)loadedData);
|
|
|
|
SAFE_RELEASE(ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnloadShaderG(void* loadedData)
|
|
|
|
{
|
|
|
|
ID3D11GeometryShader* gs = ((ID3D11GeometryShader*)loadedData);
|
|
|
|
SAFE_RELEASE(gs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnloadShaderC(void* loadedData)
|
|
|
|
{
|
|
|
|
ID3D11ComputeShader* ps = ((ID3D11ComputeShader*)loadedData);
|
|
|
|
SAFE_RELEASE(ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnloadShaderH(void* loadedData)
|
|
|
|
{
|
|
|
|
ID3D11HullShader* ps = ((ID3D11HullShader*)loadedData);
|
|
|
|
SAFE_RELEASE(ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnloadShaderD(void* loadedData)
|
|
|
|
{
|
|
|
|
ID3D11DomainShader* ps = ((ID3D11DomainShader*)loadedData);
|
|
|
|
SAFE_RELEASE(ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnloadShaderV(void* loadedData)
|
|
|
|
{
|
|
|
|
ID3D11VertexShader* ps = ((ID3D11VertexShader*)loadedData);
|
|
|
|
SAFE_RELEASE(ps);
|
|
|
|
}
|
|
|
|
|
2014-01-31 16:29:50 +01:00
|
|
|
void* LoadShaderP(const wchar_t filename[])
|
2013-11-29 10:25:27 +01:00
|
|
|
{
|
2014-01-31 16:29:50 +01:00
|
|
|
return LoadShader(filename,Core::PipelineManager::Pixel);
|
2013-11-29 10:25:27 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 16:29:50 +01:00
|
|
|
void* LoadShaderG(const wchar_t filename[])
|
2013-11-29 10:25:27 +01:00
|
|
|
{
|
|
|
|
|
2014-01-31 16:29:50 +01:00
|
|
|
return LoadShader(filename,Core::PipelineManager::Geometry);
|
2013-11-29 10:25:27 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 16:29:50 +01:00
|
|
|
void* LoadShaderC(const wchar_t filename[])
|
2013-11-29 10:25:27 +01:00
|
|
|
{
|
|
|
|
|
2014-01-31 16:29:50 +01:00
|
|
|
return LoadShader(filename,Core::PipelineManager::Compute);
|
2013-11-29 10:25:27 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 16:29:50 +01:00
|
|
|
void* LoadShaderH(const wchar_t filename[])
|
2013-11-29 10:25:27 +01:00
|
|
|
{
|
|
|
|
|
2014-01-31 16:29:50 +01:00
|
|
|
return LoadShader(filename,Core::PipelineManager::Hull);
|
2013-11-29 10:25:27 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 16:29:50 +01:00
|
|
|
void* LoadShaderD(const wchar_t filename[])
|
2013-11-29 10:25:27 +01:00
|
|
|
{
|
|
|
|
|
2014-01-31 16:29:50 +01:00
|
|
|
return LoadShader(filename,Core::PipelineManager::Domain);
|
2013-11-29 10:25:27 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 16:29:50 +01:00
|
|
|
void* LoadShaderV(const wchar_t filename[])
|
2013-11-29 10:25:27 +01:00
|
|
|
{
|
2014-01-31 16:29:50 +01:00
|
|
|
return LoadShader(filename,Core::PipelineManager::Vertex);
|
2013-11-29 10:25:27 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 16:29:50 +01:00
|
|
|
void* LoadShader(const wchar_t filename[], int type)
|
2013-11-29 10:25:27 +01:00
|
|
|
{
|
2013-12-18 20:28:06 +01:00
|
|
|
Core::PipelineManager::ShaderData data;
|
2013-11-29 10:25:27 +01:00
|
|
|
#ifdef _DEBUG
|
|
|
|
ID3DBlob *Shader=NULL, *Error=NULL;
|
|
|
|
HRESULT hr;
|
2013-12-18 20:28:06 +01:00
|
|
|
switch (Core::PipelineManager::ShaderType(type))
|
2013-11-29 10:25:27 +01:00
|
|
|
{
|
2013-12-18 20:28:06 +01:00
|
|
|
case Oyster::Graphics::Core::PipelineManager::Vertex:
|
2013-11-29 10:25:27 +01:00
|
|
|
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","vs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
|
|
|
break;
|
2013-12-18 20:28:06 +01:00
|
|
|
case Oyster::Graphics::Core::PipelineManager::Hull:
|
2013-11-29 10:25:27 +01:00
|
|
|
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","hs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
|
|
|
break;
|
2013-12-18 20:28:06 +01:00
|
|
|
case Oyster::Graphics::Core::PipelineManager::Domain:
|
2013-11-29 10:25:27 +01:00
|
|
|
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","ds_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
|
|
|
break;
|
2013-12-18 20:28:06 +01:00
|
|
|
case Oyster::Graphics::Core::PipelineManager::Geometry:
|
2013-11-29 10:25:27 +01:00
|
|
|
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","gs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
|
|
|
break;
|
2013-12-18 20:28:06 +01:00
|
|
|
case Oyster::Graphics::Core::PipelineManager::Pixel:
|
2013-11-29 10:25:27 +01:00
|
|
|
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","ps_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
|
|
|
break;
|
2013-12-18 20:28:06 +01:00
|
|
|
case Oyster::Graphics::Core::PipelineManager::Compute:
|
2013-11-29 10:25:27 +01:00
|
|
|
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","cs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
if(Error)
|
|
|
|
{
|
|
|
|
Error->Release();
|
|
|
|
}
|
|
|
|
if(Shader)
|
|
|
|
{
|
|
|
|
Shader->Release();
|
|
|
|
}
|
2014-01-31 16:29:50 +01:00
|
|
|
return NULL;
|
2013-11-29 10:25:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
data.size = Shader->GetBufferSize();
|
|
|
|
data.data = new char[data.size];
|
|
|
|
memcpy(data.data,Shader->GetBufferPointer(),data.size);
|
|
|
|
#else
|
2013-12-04 09:36:43 +01:00
|
|
|
std::ifstream stream;
|
|
|
|
|
2013-11-29 10:25:27 +01:00
|
|
|
stream.open(filename, std::ifstream::in | std::ifstream::binary);
|
|
|
|
if(stream.good())
|
|
|
|
{
|
|
|
|
stream.seekg(0, std::ios::end);
|
2013-12-04 09:36:43 +01:00
|
|
|
data.size = size_t(stream.tellg());
|
|
|
|
data.data = new char[data.size];
|
2013-11-29 10:25:27 +01:00
|
|
|
stream.seekg(0, std::ios::beg);
|
2013-12-04 09:36:43 +01:00
|
|
|
stream.read(&data.data[0], data.size);
|
2013-11-29 10:25:27 +01:00
|
|
|
stream.close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-04 14:59:51 +01:00
|
|
|
return NULL;
|
2013-11-29 10:25:27 +01:00
|
|
|
}
|
|
|
|
#endif
|
2014-01-31 16:29:50 +01:00
|
|
|
return Core::PipelineManager::CreateShader(data, Core::PipelineManager::ShaderType(type));
|
2013-11-29 10:25:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|