GteConstantBuffer.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.1 (2016/08/29)
7 
8 #include <GTEnginePCH.h>
10 #include <algorithm>
11 #include <cstring>
12 using namespace gte;
13 
14 ConstantBuffer::ConstantBuffer(size_t numBytes, bool allowDynamicUpdate)
15  :
16  Buffer(1, GetRoundedNumBytes(numBytes), true)
17 {
19  mUsage = (allowDynamicUpdate ? DYNAMIC_UPDATE : IMMUTABLE);
20  memset(mData, 0, mNumBytes);
21 }
22 
24 {
25  auto iter = std::find_if(mLayout.begin(), mLayout.end(),
26  [&name](MemberLayout const& item){ return name == item.name; });
27  return iter != mLayout.end();
28 }
29 
30 size_t ConstantBuffer::GetRoundedNumBytes(size_t numBytes)
31 {
32 #if defined(GTE_USE_DX12)
33  size_t const multiple = 256;
34 #else
35  size_t const multiple = 16;
36 #endif
37  if (numBytes > 0)
38  {
39  size_t remainder = numBytes % multiple;
40  if (remainder == 0)
41  {
42  // The number is already the correct multiple.
43  return numBytes;
44  }
45  else
46  {
47  // Round up to the nearest multiple.
48  return numBytes + multiple - remainder;
49  }
50  }
51  else
52  {
53  // At least one register must be allocated.
54  return multiple;
55  }
56 }
DYNAMIC_UPDATE
Definition: GteResource.h:42
INT64 INT64 INT64 remainder
Definition: wglext.h:822
IMMUTABLE
Definition: GteResource.h:42
GraphicsObjectType mType
unsigned int mNumBytes
Definition: GteResource.h:96
GLuint const GLchar * name
Definition: glcorearb.h:781
bool HasMember(std::string const &name) const
static size_t GetRoundedNumBytes(size_t numBytes)
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
GT_CONSTANT_BUFFER
ConstantBuffer(size_t numBytes, bool allowDynamicUpdate)
std::vector< MemberLayout > mLayout


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