| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- #include "CmD3D11GpuProgram.h"
- #include "CmD3D11Device.h"
- #include "CmException.h"
- #include "CmDebug.h"
- namespace CamelotEngine
- {
- D3D11GpuProgram::D3D11GpuProgram(GpuProgramType type, GpuProgramProfile profile)
- : GpuProgram("", "", "", type, profile)
- {
- }
- void D3D11GpuProgram::loadImpl(void)
- {
- // Call polymorphic load
- loadFromSource();
- }
- void D3D11GpuProgram::loadFromSource(void)
- {
- CM_EXCEPT(RenderingAPIException, "DirectX 11 doesn't support assembly shaders.");
- }
- D3D11GpuVertexProgram::D3D11GpuVertexProgram(GpuProgramProfile profile)
- : D3D11GpuProgram(GPT_VERTEX_PROGRAM, profile)
- , mVertexShader(nullptr)
- { }
- D3D11GpuVertexProgram::~D3D11GpuVertexProgram()
- {
- // have to call this here reather than in Resource destructor
- // since calling virtual methods in base destructors causes crash
- unload();
- }
- void D3D11GpuVertexProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob * microcode)
- {
- if (isSupported())
- {
- // Create the shader
- HRESULT hr = device.getD3D11Device()->CreateVertexShader(
- static_cast<DWORD*>(microcode->GetBufferPointer()),
- microcode->GetBufferSize(),
- NULL,
- &mVertexShader);
- if (FAILED(hr) || device.hasError())
- {
- String errorDescription = device.getErrorDescription();
- CM_EXCEPT(RenderingAPIException,
- "Cannot create D3D11 vertex shader from microcode\nError Description:" + errorDescription);
- }
- }
- else
- {
- LOGWRN("Unsupported D3D11 vertex shader was not loaded.");
- }
- }
- void D3D11GpuVertexProgram::unloadImpl(void)
- {
- SAFE_RELEASE(mVertexShader);
- }
- ID3D11VertexShader * D3D11GpuVertexProgram::getVertexShader( void ) const
- {
- return mVertexShader;
- }
- D3D11GpuFragmentProgram::D3D11GpuFragmentProgram(GpuProgramProfile profile)
- : D3D11GpuProgram(GPT_FRAGMENT_PROGRAM, profile)
- , mPixelShader(nullptr)
- { }
- D3D11GpuFragmentProgram::~D3D11GpuFragmentProgram()
- {
- unload();
- }
- void D3D11GpuFragmentProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
- {
- if (isSupported())
- {
- // Create the shader
- HRESULT hr = device.getD3D11Device()->CreatePixelShader(
- static_cast<DWORD*>(microcode->GetBufferPointer()),
- microcode->GetBufferSize(),
- NULL,
- &mPixelShader);
- if (FAILED(hr) || device.hasError())
- {
- String errorDescription = device.getErrorDescription();
- CM_EXCEPT(RenderingAPIException,
- "Cannot create D3D11 pixel shader from microcode.\nError Description:" + errorDescription);
- }
- }
- else
- {
- LOGWRN("Unsupported D3D11 pixel shader was not loaded.");
- }
- }
- void D3D11GpuFragmentProgram::unloadImpl(void)
- {
- SAFE_RELEASE(mPixelShader);
- }
- ID3D11PixelShader * D3D11GpuFragmentProgram::getPixelShader( void ) const
- {
- return mPixelShader;
- }
- D3D11GpuGeometryProgram::D3D11GpuGeometryProgram(GpuProgramProfile profile)
- : D3D11GpuProgram(GPT_GEOMETRY_PROGRAM, profile)
- , mGeometryShader(nullptr)
- { }
- D3D11GpuGeometryProgram::~D3D11GpuGeometryProgram()
- {
- unload();
- }
- void D3D11GpuGeometryProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
- {
- if (isSupported())
- {
- // Create the shader
- HRESULT hr = device.getD3D11Device()->CreateGeometryShader(
- static_cast<DWORD*>(microcode->GetBufferPointer()),
- microcode->GetBufferSize(),
- NULL,
- &mGeometryShader);
- if (FAILED(hr) || device.hasError())
- {
- String errorDescription = device.getErrorDescription();
- CM_EXCEPT(RenderingAPIException,
- "Cannot create D3D11 geometry shader from microcode.\nError Description:" + errorDescription);
- }
- }
- else
- {
- LOGWRN("Unsupported D3D11 geometry shader was not loaded.");
- }
- }
- void D3D11GpuGeometryProgram::unloadImpl(void)
- {
- SAFE_RELEASE(mGeometryShader);
- }
- ID3D11GeometryShader * D3D11GpuGeometryProgram::getGeometryShader(void) const
- {
- return mGeometryShader;
- }
- D3D11GpuDomainProgram::D3D11GpuDomainProgram(GpuProgramProfile profile)
- : D3D11GpuProgram(GPT_DOMAIN_PROGRAM, profile)
- , mDomainShader(nullptr)
- { }
- D3D11GpuDomainProgram::~D3D11GpuDomainProgram()
- {
- unload();
- }
- void D3D11GpuDomainProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
- {
- if (isSupported())
- {
- // Create the shader
- HRESULT hr = device.getD3D11Device()->CreateDomainShader(
- static_cast<DWORD*>(microcode->GetBufferPointer()),
- microcode->GetBufferSize(),
- NULL,
- &mDomainShader);
- if (FAILED(hr) || device.hasError())
- {
- String errorDescription = device.getErrorDescription();
- CM_EXCEPT(RenderingAPIException,
- "Cannot create D3D11 domain shader from microcode.\nError Description:" + errorDescription);
- }
- }
- else
- {
- LOGWRN("Unsupported D3D11 domain shader was not loaded.");
- }
- }
- void D3D11GpuDomainProgram::unloadImpl(void)
- {
- SAFE_RELEASE(mDomainShader);
- }
- ID3D11DomainShader * D3D11GpuDomainProgram::getDomainShader(void) const
- {
- return mDomainShader;
- }
- D3D11GpuHullProgram::D3D11GpuHullProgram(GpuProgramProfile profile)
- : D3D11GpuProgram(GPT_HULL_PROGRAM, profile)
- , mHullShader(nullptr)
- { }
- D3D11GpuHullProgram::~D3D11GpuHullProgram()
- {
- unload();
- }
- void D3D11GpuHullProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
- {
- if (isSupported())
- {
- // Create the shader
- HRESULT hr = device.getD3D11Device()->CreateHullShader(
- static_cast<DWORD*>(microcode->GetBufferPointer()),
- microcode->GetBufferSize(),
- NULL,
- &mHullShader);
- if (FAILED(hr) || device.hasError())
- {
- String errorDescription = device.getErrorDescription();
- CM_EXCEPT(RenderingAPIException,
- "Cannot create D3D11 hull shader from microcode.\nError Description:" + errorDescription);
- }
- }
- else
- {
- LOGWRN("Unsupported D3D11 hull shader was not loaded.");
- }
- }
- void D3D11GpuHullProgram::unloadImpl(void)
- {
- SAFE_RELEASE(mHullShader);
- }
- ID3D11HullShader* D3D11GpuHullProgram::getHullShader(void) const
- {
- return mHullShader;
- }
- }
|