GteDX11PixelShader.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
10 using namespace gte;
11 
12 DX11PixelShader::DX11PixelShader(ID3D11Device* device, Shader const* shader)
13  :
14  DX11Shader(shader)
15 {
16  std::vector<unsigned char> const& code = shader->GetCompiledCode();
17 
18  ID3D11ClassLinkage* linkage = nullptr;
19  ID3D11PixelShader* dxShader = nullptr;
20  HRESULT hr = device->CreatePixelShader(&code[0], code.size(), linkage, &dxShader);
21  CHECK_HR_RETURN_NONE("Failed to create pixel shader");
22 
23  mDXObject = dxShader;
24 }
25 
26 std::shared_ptr<GEObject> DX11PixelShader::Create(void* device, GraphicsObject const* object)
27 {
28  if (object->GetType() == GT_PIXEL_SHADER)
29  {
30  return std::make_shared<DX11PixelShader>(
31  reinterpret_cast<ID3D11Device*>(device),
32  static_cast<Shader const*>(object));
33  }
34 
35  LogError("Invalid object type.");
36  return nullptr;
37 }
38 
39 void DX11PixelShader::Enable(ID3D11DeviceContext* context)
40 {
41  if (mDXObject)
42  {
43  ID3D11ClassInstance* instances[1] = { nullptr };
44  UINT numInstances = 0;
45  ID3D11PixelShader* dxShader = static_cast<ID3D11PixelShader*>(mDXObject);
46  context->PSSetShader(dxShader, instances, numInstances);
47  }
48 }
49 
50 void DX11PixelShader::Disable(ID3D11DeviceContext* context)
51 {
52  if (mDXObject)
53  {
54  ID3D11ClassInstance* instances[1] = { nullptr };
55  UINT numInstances = 0;
56  ID3D11PixelShader* dxShader = nullptr;
57  context->PSSetShader(dxShader, instances, numInstances);
58  }
59 }
60 
61 void DX11PixelShader::EnableCBuffer(ID3D11DeviceContext* context,
62  unsigned int bindPoint, ID3D11Buffer* buffer)
63 {
64  if (mDXObject)
65  {
66  ID3D11Buffer* buffers[1] = { buffer };
67  context->PSSetConstantBuffers(bindPoint, 1, buffers);
68  }
69 }
70 
71 void DX11PixelShader::DisableCBuffer(ID3D11DeviceContext* context,
72  unsigned int bindPoint)
73 {
74  if (mDXObject)
75  {
76  ID3D11Buffer* buffers[1] = { nullptr };
77  context->PSSetConstantBuffers(bindPoint, 1, buffers);
78  }
79 }
80 
81 void DX11PixelShader::EnableSRView(ID3D11DeviceContext* context,
82  unsigned int bindPoint, ID3D11ShaderResourceView* srView)
83 {
84  if (mDXObject)
85  {
86  ID3D11ShaderResourceView* views[1] = { srView };
87  context->PSSetShaderResources(bindPoint, 1, views);
88  }
89 }
90 
91 void DX11PixelShader::DisableSRView(ID3D11DeviceContext* context,
92  unsigned int bindPoint)
93 {
94  if (mDXObject)
95  {
96  ID3D11ShaderResourceView* views[1] = { nullptr };
97  context->PSSetShaderResources(bindPoint, 1, views);
98  }
99 }
100 
101 void DX11PixelShader::EnableUAView(ID3D11DeviceContext* context,
102  unsigned int bindPoint, ID3D11UnorderedAccessView* uaView,
103  unsigned int initialCount)
104 {
105  if (mDXObject)
106  {
107  ID3D11UnorderedAccessView* uaViews[1] = { uaView };
108  unsigned int initialCounts[1] = { initialCount };
109  context->OMSetRenderTargetsAndUnorderedAccessViews(
110  D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr,
111  bindPoint, 1, uaViews, initialCounts);
112  }
113 }
114 
115 void DX11PixelShader::DisableUAView(ID3D11DeviceContext* context,
116  unsigned int bindPoint)
117 {
118  if (mDXObject)
119  {
120  ID3D11UnorderedAccessView* uaViews[1] = { nullptr };
121  unsigned int initialCounts[1] = { 0xFFFFFFFFu };
122  context->OMSetRenderTargetsAndUnorderedAccessViews(
123  D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr,
124  bindPoint, 1, uaViews, initialCounts);
125  }
126 }
127 
128 void DX11PixelShader::EnableSampler(ID3D11DeviceContext* context,
129  unsigned int bindPoint, ID3D11SamplerState* state)
130 {
131  if (mDXObject)
132  {
133  ID3D11SamplerState* states[1] = { state };
134  context->PSSetSamplers(bindPoint, 1, states);
135  }
136 }
137 
138 void DX11PixelShader::DisableSampler(ID3D11DeviceContext* context,
139  unsigned int bindPoint)
140 {
141  if (mDXObject)
142  {
143  ID3D11SamplerState* states[1] = { nullptr };
144  context->PSSetSamplers(bindPoint, 1, states);
145  }
146 }
#define CHECK_HR_RETURN_NONE(msg)
virtual void DisableSampler(ID3D11DeviceContext *context, unsigned int bindPoint) override
virtual void Enable(ID3D11DeviceContext *context) override
const GLuint * buffers
Definition: glcorearb.h:656
GraphicsObjectType GetType() const
virtual void DisableCBuffer(ID3D11DeviceContext *context, unsigned int bindPoint) override
DX11PixelShader(ID3D11Device *device, Shader const *shader)
#define LogError(message)
Definition: GteLogger.h:92
ID3D11DeviceChild * mDXObject
virtual void EnableSampler(ID3D11DeviceContext *context, unsigned int bindPoint, ID3D11SamplerState *state) override
GT_PIXEL_SHADER
GLuint shader
Definition: glcorearb.h:780
virtual void DisableUAView(ID3D11DeviceContext *context, unsigned int bindPoint) override
virtual void EnableSRView(ID3D11DeviceContext *context, unsigned int bindPoint, ID3D11ShaderResourceView *srView) override
virtual void DisableSRView(ID3D11DeviceContext *context, unsigned int bindPoint) override
static std::shared_ptr< GEObject > Create(void *device, GraphicsObject const *object)
typedef UINT(WINAPI *PFNWGLGETGPUIDSAMDPROC)(UINT maxCount
GLuint buffer
Definition: glcorearb.h:655
virtual void EnableCBuffer(ID3D11DeviceContext *context, unsigned int bindPoint, ID3D11Buffer *buffer) override
virtual void Disable(ID3D11DeviceContext *context) override
virtual void EnableUAView(ID3D11DeviceContext *context, unsigned int bindPoint, ID3D11UnorderedAccessView *uaView, unsigned int initialCount) override
std::vector< unsigned char > const & GetCompiledCode() const
Definition: GteShader.h:388


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59