GteDX11InputLayout.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 
13 {
15 }
16 
17 DX11InputLayout::DX11InputLayout(ID3D11Device* device,
18  VertexBuffer const* vbuffer, Shader const* vshader)
19  :
20  mLayout(nullptr),
21  mNumElements(0)
22 {
23  memset(&mElements[0], 0, VA_MAX_ATTRIBUTES*sizeof(mElements[0]));
24  if (vbuffer && vshader)
25  {
26  VertexFormat const& format = vbuffer->GetFormat();
27  mNumElements = format.GetNumAttributes();
28  for (int i = 0; i < mNumElements; ++i)
29  {
30  VASemantic semantic;
31  DFType type;
32  unsigned int unit, offset;
33  format.GetAttribute(i, semantic, type, unit, offset);
34 
35  D3D11_INPUT_ELEMENT_DESC& element = mElements[i];
36  element.SemanticName = msSemantic[semantic];
37  element.SemanticIndex = unit;
38  element.Format = static_cast<DXGI_FORMAT>(type);
39  element.InputSlot = 0; // TODO: Streams not yet supported.
40  element.AlignedByteOffset = offset;
41  element.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
42  element.InstanceDataStepRate = 0;
43  }
44 
45  std::vector<unsigned char> const& compiledCode =
46  vshader->GetCompiledCode();
47  HRESULT hr = device->CreateInputLayout(mElements, (UINT)mNumElements,
48  &compiledCode[0], compiledCode.size(), &mLayout);
49  CHECK_HR_RETURN_NONE("Failed to create input layout");
50  }
51  else
52  {
53  LogError("Invalid inputs to DX11InputLayout constructor.");
54  }
55 }
56 
57 void DX11InputLayout::Enable(ID3D11DeviceContext* context)
58 {
59  if (mLayout)
60  {
61  context->IASetInputLayout(mLayout);
62  }
63 }
64 
65 void DX11InputLayout::Disable(ID3D11DeviceContext* context)
66 {
67  if (mLayout)
68  {
69  // TODO: Verify that mLayout is the active input layout.
70  context->IASetInputLayout(nullptr);
71  }
72 }
73 
75 {
76  mName = name;
77  return SetPrivateName(mLayout, mName);
78 }
79 
80 
81 char const* DX11InputLayout::msSemantic[VA_NUM_SEMANTICS] =
82 {
83  "",
84  "POSITION",
85  "BLENDWEIGHT",
86  "BLENDINDICES",
87  "NORMAL",
88  "PSIZE",
89  "TEXCOORD",
90  "TANGENT",
91  "BINORMAL",
92  "TESSFACTOR",
93  "POSITIONT",
94  "COLOR",
95  "FOG",
96  "DEPTH",
97  "SAMPLE"
98 };
ID3D11InputLayout * mLayout
void Enable(ID3D11DeviceContext *context)
VA_MAX_ATTRIBUTES
static char const * msSemantic[VA_NUM_SEMANTICS]
#define CHECK_HR_RETURN_NONE(msg)
HRESULT SetPrivateName(ID3D11DeviceChild *object, std::string const &name)
bool GetAttribute(int i, VASemantic &semantic, DFType &type, unsigned int &unit, unsigned int &offset) const
GLuint const GLchar * name
Definition: glcorearb.h:781
ULONG FinalRelease(T *&object)
HRESULT SetName(std::string const &name)
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
#define LogError(message)
Definition: GteLogger.h:92
VertexFormat const & GetFormat() const
DX11InputLayout(ID3D11Device *device, VertexBuffer const *vbuffer, Shader const *vshader)
void Disable(ID3D11DeviceContext *context)
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:103
D3D11_INPUT_ELEMENT_DESC mElements[VA_MAX_ATTRIBUTES]
int GetNumAttributes() const
typedef UINT(WINAPI *PFNWGLGETGPUIDSAMDPROC)(UINT maxCount
GLintptr offset
Definition: glcorearb.h:660
std::vector< unsigned char > const & GetCompiledCode() const
Definition: GteShader.h:388
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:103


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