GteDX11SamplerState.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 DX11SamplerState::DX11SamplerState(ID3D11Device* device, SamplerState const* samplerState)
13  :
14  DX11DrawingState(samplerState)
15 {
16  // Specify the sampler state description.
17  D3D11_SAMPLER_DESC desc;
18  desc.Filter = msFilter[samplerState->filter];
19  desc.AddressU = msMode[samplerState->mode[0]];
20  desc.AddressV = msMode[samplerState->mode[1]];
21  desc.AddressW = msMode[samplerState->mode[2]];
22  desc.MipLODBias = samplerState->mipLODBias;
23  desc.MaxAnisotropy = samplerState->maxAnisotropy;
24  desc.ComparisonFunc = msComparison[samplerState->comparison];
25  desc.BorderColor[0] = samplerState->borderColor[0];
26  desc.BorderColor[1] = samplerState->borderColor[1];
27  desc.BorderColor[2] = samplerState->borderColor[2];
28  desc.BorderColor[3] = samplerState->borderColor[3];
29  desc.MinLOD = samplerState->minLOD;
30  desc.MaxLOD = samplerState->maxLOD;
31 
32  // Create the sampler state.
33  ID3D11SamplerState* state = nullptr;
34  HRESULT hr = device->CreateSamplerState(&desc, &state);
35  CHECK_HR_RETURN_NONE("Failed to create sampler state");
36  mDXObject = state;
37 }
38 
39 std::shared_ptr<GEObject> DX11SamplerState::Create(void* device, GraphicsObject const* object)
40 {
41  if (object->GetType() == GT_SAMPLER_STATE)
42  {
43  return std::make_shared<DX11SamplerState>(
44  reinterpret_cast<ID3D11Device*>(device),
45  static_cast<SamplerState const*>(object));
46  }
47 
48  LogError("Invalid object type.");
49  return nullptr;
50 }
51 
52 
53 D3D11_FILTER const DX11SamplerState::msFilter[] =
54 {
55  D3D11_FILTER_MIN_MAG_MIP_POINT,
56  D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR,
57  D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT,
58  D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR,
59  D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT,
60  D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
61  D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT,
62  D3D11_FILTER_MIN_MAG_MIP_LINEAR,
63  D3D11_FILTER_ANISOTROPIC,
64  D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT,
65  D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR,
66  D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
67  D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR,
68  D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT,
69  D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
70  D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT,
71  D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR,
72  D3D11_FILTER_COMPARISON_ANISOTROPIC
73 };
74 
75 D3D11_TEXTURE_ADDRESS_MODE const DX11SamplerState::msMode[] =
76 {
77  D3D11_TEXTURE_ADDRESS_WRAP,
78  D3D11_TEXTURE_ADDRESS_MIRROR,
79  D3D11_TEXTURE_ADDRESS_CLAMP,
80  D3D11_TEXTURE_ADDRESS_BORDER,
81  D3D11_TEXTURE_ADDRESS_MIRROR_ONCE
82 };
83 
84 D3D11_COMPARISON_FUNC const DX11SamplerState::msComparison[] =
85 {
86  D3D11_COMPARISON_NEVER,
87  D3D11_COMPARISON_LESS,
88  D3D11_COMPARISON_EQUAL,
89  D3D11_COMPARISON_LESS_EQUAL,
90  D3D11_COMPARISON_GREATER,
91  D3D11_COMPARISON_NOT_EQUAL,
92  D3D11_COMPARISON_GREATER_EQUAL,
93  D3D11_COMPARISON_ALWAYS
94 };
unsigned int maxAnisotropy
#define CHECK_HR_RETURN_NONE(msg)
GT_SAMPLER_STATE
GraphicsObjectType GetType() const
static D3D11_COMPARISON_FUNC const msComparison[]
static D3D11_FILTER const msFilter[]
#define LogError(message)
Definition: GteLogger.h:92
Vector4< float > borderColor
ID3D11DeviceChild * mDXObject
static std::shared_ptr< GEObject > Create(void *device, GraphicsObject const *object)
Comparison comparison
DX11SamplerState(ID3D11Device *device, SamplerState const *samplerState)
static D3D11_TEXTURE_ADDRESS_MODE const msMode[]


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