GteGL4InputLayout.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>
9 #include <LowLevel/GteLogger.h>
11 #include <cstring>
12 using namespace gte;
13 
15 {
17 }
18 
19 GL4InputLayout::GL4InputLayout(GLuint programHandle, GLuint vbufferHandle,
20  VertexBuffer const* vbuffer)
21  :
22  mProgramHandle(programHandle),
23  mVBufferHandle(vbufferHandle),
25 {
28 
29  memset(&mAttributes[0], 0, VA_MAX_ATTRIBUTES*sizeof(mAttributes[0]));
30  if (vbuffer)
31  {
32  VertexFormat const& format = vbuffer->GetFormat();
34  for (int i = 0; i < mNumAttributes; ++i)
35  {
36  Attribute& attribute = mAttributes[i];
37 
38  DFType type;
39  unsigned int unit, offset;
40  format.GetAttribute(i, attribute.semantic, type, unit, offset);
41 
42  attribute.numChannels = static_cast<GLint>(
44  attribute.channelType =
46  attribute.normalize = static_cast<GLboolean>(
47  DataFormat::ConvertChannel(type) ? 1 : 0);
48  attribute.location = i; // layouts must be zero-based sequential
49  attribute.offset = static_cast<GLintptr>(offset);
50  attribute.stride = static_cast<GLsizei>(format.GetVertexSize());
51 
54  attribute.stride);
55  glVertexAttribFormat(attribute.location, attribute.numChannels,
56  attribute.channelType, attribute.normalize, 0);
57  glVertexAttribBinding(attribute.location, i);
58  }
59  }
60  else
61  {
62  LogError("Invalid inputs to GL4InputLayout constructor.");
63  }
64 
66 }
67 
69 {
71 }
72 
74 {
76 }
77 
78 
80 {
81  GL_ZERO, // DF_UNSUPPORTED
82  GL_BYTE, // DF_BYTE
83  GL_UNSIGNED_BYTE, // DF_UBYTE
84  GL_SHORT, // DF_SHORT
85  GL_UNSIGNED_SHORT, // DF_USHORT
86  GL_INT, // DF_INT
87  GL_UNSIGNED_INT, // DF_UINT
88  GL_HALF_FLOAT, // DF_HALF_FLOAT
89  GL_FLOAT, // DF_FLOAT
90  GL_DOUBLE, // DF_DOUBLE
91  GL_INT_2_10_10_10_REV, // DF_INT_10_10_2
92  GL_UNSIGNED_INT_2_10_10_10_REV, // DF_UINT_10_10_2
93  GL_UNSIGNED_INT_10F_11F_11F_REV // DF_FLOAT_11_11_10
94 };
void APIENTRY glDeleteVertexArrays(GLsizei n, const GLuint *arrays)
Definition: GteOpenGL.cpp:4396
int GLint
Definition: glcorearb.h:85
unsigned int GLuint
Definition: glcorearb.h:89
#define GL_SHORT
Definition: glcorearb.h:325
static unsigned int GetNumChannels(DFType type)
void APIENTRY glEnableVertexAttribArray(GLuint index)
Definition: GteOpenGL.cpp:1996
unsigned int GetVertexSize() const
#define GL_ZERO
Definition: glcorearb.h:217
void APIENTRY glBindVertexBuffer(GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride)
Definition: GteOpenGL.cpp:8103
VA_MAX_ATTRIBUTES
#define GL_UNSIGNED_INT_2_10_10_10_REV
Definition: glcorearb.h:455
unsigned char GLboolean
Definition: glcorearb.h:90
void APIENTRY glBindVertexArray(GLuint array)
Definition: GteOpenGL.cpp:4383
bool GetAttribute(int i, VASemantic &semantic, DFType &type, unsigned int &unit, unsigned int &offset) const
#define GL_FLOAT
Definition: glcorearb.h:329
#define GL_DOUBLE
Definition: glcorearb.h:330
static bool ConvertChannel(DFType type)
int GLsizei
Definition: glcorearb.h:86
static DFChannelType GetChannelType(DFType type)
unsigned int GLenum
Definition: glcorearb.h:83
GL4InputLayout(GLuint programHandle, GLuint vbufferHandle, VertexBuffer const *vbuffer)
#define LogError(message)
Definition: GteLogger.h:92
VertexFormat const & GetFormat() const
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:103
#define GL_UNSIGNED_BYTE
Definition: glcorearb.h:324
void APIENTRY glVertexAttribBinding(GLuint attribindex, GLuint bindingindex)
Definition: GteOpenGL.cpp:8155
#define GL_UNSIGNED_INT
Definition: glcorearb.h:328
#define GL_INT_2_10_10_10_REV
Definition: glcorearb.h:1645
#define GL_BYTE
Definition: glcorearb.h:323
void APIENTRY glVertexAttribFormat(GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset)
Definition: GteOpenGL.cpp:8116
#define GL_UNSIGNED_INT_10F_11F_11F_REV
Definition: glcorearb.h:1037
static GLenum const msChannelType[]
#define GL_UNSIGNED_SHORT
Definition: glcorearb.h:326
int GetNumAttributes() const
GLintptr offset
Definition: glcorearb.h:660
void APIENTRY glGenVertexArrays(GLsizei n, GLuint *arrays)
Definition: GteOpenGL.cpp:4409
#define GL_HALF_FLOAT
Definition: glcorearb.h:1183
Attribute mAttributes[VA_MAX_ATTRIBUTES]
ptrdiff_t GLintptr
Definition: glcorearb.h:618
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:103
#define GL_INT
Definition: glcorearb.h:327


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