GteVertexBuffer.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/11/28)
7 
8 #include <GTEnginePCH.h>
11 using namespace gte;
12 
14  unsigned int numVertices, bool createStorage)
15  :
16  Buffer(numVertices, vformat.GetVertexSize(), createStorage),
17  mVFormat(vformat)
18 {
20 }
21 
23  std::shared_ptr<StructuredBuffer> const& sbuffer)
24  :
25  Buffer(sbuffer->GetNumElements(), vformat.GetVertexSize(), false),
26  mVFormat(vformat),
27  mSBuffer(sbuffer)
28 {
30  SetNumActiveElements(sbuffer->GetNumElements());
31 }
32 
33 VertexBuffer::VertexBuffer(unsigned int numVertices)
34  :
35  Buffer(numVertices, 0, false)
36 {
38 }
39 
40 char* VertexBuffer::GetChannel(VASemantic semantic, unsigned int unit,
41  std::set<DFType> const& requiredTypes)
42 {
43  char* data = (mSBuffer == nullptr ? mData : mSBuffer->GetData());
44  if (!data)
45  {
46  // The system memory copy does not exist. You need to recreate it
47  // before populating it.
48  return nullptr;
49  }
50 
51  int index = mVFormat.GetIndex(semantic, unit);
52  if (index < 0)
53  {
54  // The buffer does not have the specified semantic that uses the
55  // specified unit.
56  return nullptr;
57  }
58 
59  DFType type = mVFormat.GetType(index);
60  if (requiredTypes.size() > 0)
61  {
62  if (requiredTypes.find(type) == requiredTypes.end())
63  {
64  // The type of the semantic is not in the set of required types.
65  return nullptr;
66  }
67  }
68 
69  return data + mVFormat.GetOffset(index);
70 }
std::shared_ptr< StructuredBuffer > mSBuffer
unsigned int GetNumElements() const
Definition: GteResource.h:106
GT_VERTEX_BUFFER
GraphicsObjectType mType
int GetIndex(VASemantic semantic, unsigned int unit) const
GLboolean * data
Definition: glcorearb.h:126
VertexBuffer(VertexFormat const &vformat, unsigned int numVertices, bool createStorage=true)
unsigned int GetOffset(int i) const
VertexFormat mVFormat
GLuint index
Definition: glcorearb.h:781
void SetNumActiveElements(unsigned int numActiveElements)
DFType GetType(int i) const
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:103
char * GetChannel(VASemantic semantic, unsigned int unit, std::set< DFType > const &requiredTypes)


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:02