GteDX11RasterizerState.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 DX11RasterizerState::DX11RasterizerState(ID3D11Device* device, RasterizerState const* rasterizerState)
13  :
14  DX11DrawingState(rasterizerState)
15 {
16  // Specify the rasterizer state description.
17  D3D11_RASTERIZER_DESC desc;
18  desc.FillMode = msFillMode[rasterizerState->fillMode];
19  desc.CullMode = msCullMode[rasterizerState->cullMode];
20  desc.FrontCounterClockwise = (rasterizerState->frontCCW ? TRUE : FALSE);
21  desc.DepthBias = rasterizerState->depthBias;
22  desc.DepthBiasClamp = rasterizerState->depthBiasClamp;
23  desc.SlopeScaledDepthBias = rasterizerState->slopeScaledDepthBias;
24  desc.DepthClipEnable = (rasterizerState->enableDepthClip ? TRUE : FALSE);
25  desc.ScissorEnable = (rasterizerState->enableScissor ? TRUE : FALSE);
26  desc.MultisampleEnable = (rasterizerState->enableMultisample ? TRUE : FALSE);
27  desc.AntialiasedLineEnable = (rasterizerState->enableAntialiasedLine ? TRUE : FALSE);
28 
29  // Create the rasterizer state.
30  ID3D11RasterizerState* state = nullptr;
31  HRESULT hr = device->CreateRasterizerState(&desc, &state);
32  CHECK_HR_RETURN_NONE("Failed to create rasterizer state");
33  mDXObject = state;
34 }
35 
36 std::shared_ptr<GEObject> DX11RasterizerState::Create(void* device, GraphicsObject const* object)
37 {
38  if (object->GetType() == GT_RASTERIZER_STATE)
39  {
40  return std::make_shared<DX11RasterizerState>(
41  reinterpret_cast<ID3D11Device*>(device),
42  static_cast<RasterizerState const*>(object));
43  }
44 
45  LogError("Invalid object type.");
46  return nullptr;
47 }
48 
49 void DX11RasterizerState::Enable(ID3D11DeviceContext* context)
50 {
51  context->RSSetState(GetDXRasterizerState());
52 }
53 
54 
55 D3D11_FILL_MODE const DX11RasterizerState::msFillMode[] =
56 {
57  D3D11_FILL_SOLID,
58  D3D11_FILL_WIREFRAME
59 };
60 
61 D3D11_CULL_MODE const DX11RasterizerState::msCullMode[] =
62 {
63  D3D11_CULL_NONE,
64  D3D11_CULL_FRONT,
65  D3D11_CULL_BACK
66 };
static D3D11_FILL_MODE const msFillMode[]
DX11RasterizerState(ID3D11Device *device, RasterizerState const *rasterizerState)
#define CHECK_HR_RETURN_NONE(msg)
GraphicsObjectType GetType() const
GT_RASTERIZER_STATE
#define LogError(message)
Definition: GteLogger.h:92
ID3D11DeviceChild * mDXObject
ID3D11RasterizerState * GetDXRasterizerState()
void Enable(ID3D11DeviceContext *context)
static std::shared_ptr< GEObject > Create(void *device, GraphicsObject const *object)
static D3D11_CULL_MODE const msCullMode[]


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