84 const bool a_useTexCoordData,
85 const bool a_useColorData,
86 const bool a_useTangentData,
87 const bool a_useBitangentData,
88 const bool a_useUserData)
159 m_flagPositionData =
false;
160 m_flagNormalData =
false;
161 m_flagTexCoordData =
false;
162 m_flagColorData =
false;
163 m_flagTangentData =
false;
164 m_flagBitangentData =
false;
165 m_flagUserData =
false;
166 m_flagBufferResize =
true;
167 m_positionBuffer = (GLuint)(-1);
168 m_normalBuffer = (GLuint)(-1);
169 m_texCoordBuffer = (GLuint)(-1);
170 m_colorBuffer = (GLuint)(-1);
171 m_tangentBuffer = (GLuint)(-1);
172 m_bitangentBuffer = (GLuint)(-1);
198 static cVertexArrayPtr
create(
const bool a_useNormalData,
199 const bool a_useTexCoordData,
200 const bool a_useColorData,
201 const bool a_useTangentData,
202 const bool a_useBitangentData,
203 const bool a_useUserData)
212 return (std::make_shared<cVertexArray>(options));
236 m_flagBufferResize =
true;
255 vertexArray->m_localPos = m_localPos;
256 vertexArray->m_globalPos = m_globalPos;
257 vertexArray->m_normal = m_normal;
258 vertexArray->m_texCoord = m_texCoord;
259 vertexArray->m_color = m_color;
260 vertexArray->m_tangent = m_tangent;
261 vertexArray->m_bitangent = m_bitangent;
262 vertexArray->m_userData = m_userData;
271 vertexArray->m_numVertices = m_numVertices;
274 return (vertexArray);
287 return (newVertices(1));
303 if (a_numberOfVertices == 0) {
return (-1); }
306 int index = m_numVertices;
331 m_localPos[a_vertexIndex].set(a_x, a_y, a_z);
332 m_flagPositionData =
true;
347 m_localPos[a_vertexIndex] = a_pos;
348 m_flagPositionData =
true;
364 m_localPos[a_vertexIndex].add(a_translation);
365 m_flagPositionData =
true;
379 return (m_localPos[a_vertexIndex]);
395 return (m_globalPos[a_vertexIndex]);
412 m_normal[a_vertexIndex] = a_normal;
413 m_flagNormalData =
true;
435 m_normal[a_vertexIndex].set(a_x, a_y, a_z);
436 m_flagNormalData =
true;
451 return (m_normal[a_vertexIndex]);
468 m_texCoord[a_vertexIndex] = a_texCoord;
469 m_flagTexCoordData =
true;
487 const double& a_ty = 0.0,
488 const double& a_tz = 0.0)
492 m_texCoord[a_vertexIndex].set(a_tx, a_ty,a_tz);
493 m_flagTexCoordData =
true;
508 return (m_texCoord[a_vertexIndex]);
520 inline void setColor(
const unsigned int a_vertexIndex,
525 m_color[a_vertexIndex] = a_color;
526 m_flagColorData =
true;
543 inline void setColor(
const unsigned int a_vertexIndex,
545 const float& a_green,
547 const float& a_alpha = 1.0 )
551 m_color[a_vertexIndex].set(a_red, a_green, a_blue, a_alpha);
552 m_flagColorData =
true;
565 inline void setColor(
const unsigned int a_vertexIndex,
570 m_color[a_vertexIndex] = a_color.
getColorf();
571 m_flagColorData =
true;
586 return (m_color[a_vertexIndex]);
603 m_tangent[a_vertexIndex] = a_tangent;
604 m_flagTangentData =
true;
626 m_tangent[a_vertexIndex].set(a_x, a_y, a_z);
627 m_flagTangentData =
true;
642 return (m_tangent[a_vertexIndex]);
659 m_bitangent[a_vertexIndex] = a_bitangent;
660 m_flagBitangentData =
true;
682 m_bitangent[a_vertexIndex].set(a_x, a_y, a_z);
683 m_flagBitangentData =
true;
698 return (m_bitangent[a_vertexIndex]);
711 const int a_userData)
715 m_userData[a_vertexIndex] = a_userData;
716 m_flagUserData =
true;
731 return (m_userData[a_vertexIndex]);
749 a_globalRot.
mulr(m_localPos[a_vertexIndex], m_globalPos[a_vertexIndex]);
750 m_globalPos[a_vertexIndex].add(a_globalPos);
763 return (m_numVertices);
860 if (m_positionBuffer == (GLuint)(-1))
862 glGenBuffers(1, &m_positionBuffer);
867 glGenBuffers(1, &m_normalBuffer);
872 glGenBuffers(1, &m_texCoordBuffer);
877 glGenBuffers(1, &m_colorBuffer);
882 glGenBuffers(1, &m_tangentBuffer);
887 glGenBuffers(1, &m_bitangentBuffer);
891 if (m_flagBufferResize)
895 glBindBuffer(GL_ARRAY_BUFFER, m_positionBuffer);
896 glBufferData(GL_ARRAY_BUFFER, m_numVertices *
sizeof(
cVector3d), &(m_localPos[0]), GL_STATIC_DRAW);
901 glBindBuffer(GL_ARRAY_BUFFER, m_normalBuffer);
902 glBufferData(GL_ARRAY_BUFFER, m_numVertices *
sizeof(
cVector3d), &(m_normal[0]), GL_STATIC_DRAW);
907 glBindBuffer(GL_ARRAY_BUFFER, m_texCoordBuffer);
908 glBufferData(GL_ARRAY_BUFFER, m_numVertices *
sizeof(
cVector3d), &(m_texCoord[0]), GL_STATIC_DRAW);
913 glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer);
914 glBufferData(GL_ARRAY_BUFFER, m_numVertices *
sizeof(
cColorf), &(m_color[0]), GL_STATIC_DRAW);
919 glBindBuffer(GL_ARRAY_BUFFER, m_tangentBuffer);
920 glBufferData(GL_ARRAY_BUFFER, m_numVertices *
sizeof(
cVector3d), &(m_tangent[0]), GL_STATIC_DRAW);
925 glBindBuffer(GL_ARRAY_BUFFER, m_bitangentBuffer);
926 glBufferData(GL_ARRAY_BUFFER, m_numVertices *
sizeof(
cVector3d), &(m_bitangent[0]), GL_STATIC_DRAW);
929 m_flagBufferResize =
false;
933 if (m_flagPositionData)
935 glBindBuffer(GL_ARRAY_BUFFER, m_positionBuffer);
936 glBufferSubData(GL_ARRAY_BUFFER, 0, m_numVertices *
sizeof(
cVector3d), &(m_localPos[0]));
937 m_flagPositionData =
false;
939 if (m_flagNormalData)
941 glBindBuffer(GL_ARRAY_BUFFER, m_normalBuffer);
942 glBufferSubData(GL_ARRAY_BUFFER, 0, m_numVertices *
sizeof(
cVector3d), &(m_normal[0]));
943 m_flagNormalData =
false;
945 if (m_flagTexCoordData)
947 glBindBuffer(GL_ARRAY_BUFFER, m_texCoordBuffer);
948 glBufferSubData(GL_ARRAY_BUFFER, 0, m_numVertices *
sizeof(
cVector3d), &(m_texCoord[0]));
949 m_flagTexCoordData =
false;
953 glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer);
954 glBufferSubData(GL_ARRAY_BUFFER, 0, m_numVertices *
sizeof(
cColorf), &(m_color[0]));
955 m_flagColorData =
false;
957 if (m_flagTangentData)
959 glBindBuffer(GL_ARRAY_BUFFER, m_tangentBuffer);
960 glBufferSubData(GL_ARRAY_BUFFER, 0, m_numVertices *
sizeof(
cVector3d), &(m_tangent[0]));
961 m_flagTangentData =
false;
963 if (m_flagBitangentData)
965 glBindBuffer(GL_ARRAY_BUFFER, m_bitangentBuffer);
966 glBufferSubData(GL_ARRAY_BUFFER, 0, m_numVertices *
sizeof(
cVector3d), &(m_bitangent[0]));
967 m_flagBitangentData =
false;
972 glBindBuffer(GL_ARRAY_BUFFER, m_positionBuffer);
974 glVertexAttribPointer(
C_VB_POSITION, 3, GL_DOUBLE, GL_FALSE, 0, 0);
975 glVertexPointer(3, GL_DOUBLE, 0, 0);
980 glBindBuffer(GL_ARRAY_BUFFER, m_normalBuffer);
982 glVertexAttribPointer(
C_VB_NORMAL, 3, GL_DOUBLE, GL_FALSE, 0, 0);
991 glBindBuffer(GL_ARRAY_BUFFER, m_texCoordBuffer);
993 glVertexAttribPointer(
C_VB_TEXCOORD, 3, GL_DOUBLE, GL_FALSE, 0, 0);
1002 glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer);
1013 glBindBuffer(GL_ARRAY_BUFFER, m_tangentBuffer);
1015 glVertexAttribPointer(
C_VB_TANGENT, 3, GL_DOUBLE, GL_FALSE, 0, 0);
1024 glBindBuffer(GL_ARRAY_BUFFER, m_bitangentBuffer);
1026 glVertexAttribPointer(
C_VB_BITANGENT, 3, GL_DOUBLE, GL_FALSE, 0, 0);
1033 glBindBuffer(GL_ARRAY_BUFFER, 0);
1070 const bool a_useNormalData,
1071 const bool a_useTexCoordData,
1072 const bool a_useColorData,
1073 const bool a_useTangentData,
1074 const bool a_useBitangentData,
1075 const bool a_useUserData)
1078 m_numVertices = m_numVertices + a_numberOfVertices;
1082 m_localPos.resize(m_numVertices, pos);
1083 m_globalPos.resize(m_numVertices, pos);
1090 if ((a_numberOfVertices > 1) || (a_numberOfVertices == 0))
1092 m_normal.resize(m_numVertices, normal);
1096 m_normal.push_back(normal);
1098 m_flagNormalData =
true;
1110 if ((a_numberOfVertices > 1) || (a_numberOfVertices == 0))
1112 m_texCoord.resize(m_numVertices, texCoord);
1116 m_texCoord.push_back(texCoord);
1118 m_flagTexCoordData =
true;
1129 cColorf color(0.0, 0.0, 0.0, 1.0);
1130 if ((a_numberOfVertices > 1) || (a_numberOfVertices == 0))
1132 m_color.resize(m_numVertices, color);
1136 m_color.push_back(color);
1138 m_flagColorData =
true;
1150 if ((a_numberOfVertices > 1) || (a_numberOfVertices == 0))
1152 m_tangent.resize(m_numVertices, tangent);
1156 m_tangent.push_back(tangent);
1158 m_flagTangentData =
true;
1170 if ((a_numberOfVertices > 1) || (a_numberOfVertices == 0))
1172 m_bitangent.resize(m_numVertices, bitangent);
1176 m_bitangent.push_back(bitangent);
1178 m_flagBitangentData =
true;
1182 m_bitangent.clear();
1190 if ((a_numberOfVertices > 1) || (a_numberOfVertices == 0))
1192 m_userData.resize(m_numVertices, data);
1196 m_userData.push_back(data);
1198 m_flagUserData =
true;
1206 m_flagBufferResize =
true;
This class implements a 3D vector.
Definition: CVector3d.h:88
int newVertex()
Definition: CVertexArray.h:285
Implements an OpenGL shader primitive.
bool m_useBitangentData
If true then surface bitangent data will be allocated for each new vertex.
Definition: CVertexArray.h:1263
std::vector< int > m_userData
User data of vertices.
Definition: CVertexArray.h:1238
void mulr(const cMatrix3d &a_matrix, cMatrix3d &a_result) const
This function computes the multiplication of this matrix with another.
Definition: CMatrix3d.h:922
#define C_VB_BITANGENT
Definition: CShader.h:78
std::vector< cVector3d > m_bitangent
Surface bitangent of vertices.
Definition: CVertexArray.h:1235
void setTangent(const unsigned int a_vertexIndex, const cVector3d &a_tangent)
Definition: CVertexArray.h:598
cColorf getColor(const unsigned int a_vertexIndex) const
Definition: CVertexArray.h:584
bool m_useTexCoordData
Definition: CVertexArray.h:99
bool m_useTexCoordData
If true then texture coordinate data will be allocated for each new vertex.
Definition: CVertexArray.h:1254
bool m_useUserData
Definition: CVertexArray.h:103
cVector3d getTexCoord(const unsigned int a_vertexIndex) const
Definition: CVertexArray.h:506
std::vector< cColorf > m_color
Color of vertices.
Definition: CVertexArray.h:1229
This class implements array of 3D vertices.
Definition: CVertexArray.h:133
std::vector< cVector3d > m_tangent
Surface tangent of vertices.
Definition: CVertexArray.h:1232
bool m_flagBufferResize
If true, then data buffer need to be updated in size.
Definition: CVertexArray.h:1297
void allocateData(const int a_numberOfVertices, const bool a_useNormalData, const bool a_useTexCoordData, const bool a_useColorData, const bool a_useTangentData, const bool a_useBitangentData, const bool a_useUserData)
Definition: CVertexArray.h:1069
void setNormal(const unsigned int a_vertexIndex, const double &a_x, const double &a_y, const double &a_z)
Definition: CVertexArray.h:428
int getUserData(const unsigned int a_vertexIndex) const
Definition: CVertexArray.h:729
GLuint m_bitangentBuffer
OpenGL Buffer for storing triangle indices.
Definition: CVertexArray.h:1322
bool m_useBitangentData
Definition: CVertexArray.h:102
void renderFinalize()
Definition: CVertexArray.h:1043
bool m_flagColorData
If true then vertex color data has been modified.
Definition: CVertexArray.h:1285
static cVertexArrayPtr create(const bool a_useNormalData, const bool a_useTexCoordData, const bool a_useColorData, const bool a_useTangentData, const bool a_useBitangentData, const bool a_useUserData)
Definition: CVertexArray.h:198
bool m_flagTangentData
If true then surface tangent data has been modified.
Definition: CVertexArray.h:1288
void setTexCoord(const unsigned int a_vertexIndex, const cVector3d &a_texCoord)
Definition: CVertexArray.h:463
std::vector< cVector3d > m_normal
Surface normal of vertices.
Definition: CVertexArray.h:1223
This structure manages user options when creating vertex arrays.
Definition: CVertexArray.h:78
bool m_flagNormalData
If true then normal data has been modified.
Definition: CVertexArray.h:1279
bool m_useColorData
If true then vertex color data will be allocated for each new vertex.
Definition: CVertexArray.h:1257
void setColor(const unsigned int a_vertexIndex, const cColorf &a_color)
Definition: CVertexArray.h:520
bool m_flagUserData
If true then user data has been modified.
Definition: CVertexArray.h:1294
This class implements a 3D matrix.
Definition: CMatrix3d.h:97
#define C_VB_COLOR
Definition: CShader.h:76
GLuint m_tangentBuffer
OpenGL Buffer for storing triangle indices.
Definition: CVertexArray.h:1319
cVertexArrayPtr copy()
Definition: CVertexArray.h:245
cVector3d getBitangent(const unsigned int a_vertexIndex) const
Definition: CVertexArray.h:696
This class defines a color using a GLubyte representation for each component.
Definition: CColor.h:1184
~cVertexArray()
Definition: CVertexArray.h:181
bool getUseTangentData() const
Definition: CVertexArray.h:817
GLuint m_texCoordBuffer
OpenGL Buffer for storing triangle indices.
Definition: CVertexArray.h:1313
unsigned int getNumElements() const
Definition: CVertexArray.h:761
bool m_useColorData
Definition: CVertexArray.h:100
void setLocalPos(const unsigned int a_vertexIndex, const double &a_x, const double &a_y, const double &a_z)
Definition: CVertexArray.h:326
cVertexArrayOptions(const bool a_useNormalData, const bool a_useTexCoordData, const bool a_useColorData, const bool a_useTangentData, const bool a_useBitangentData, const bool a_useUserData)
Definition: CVertexArray.h:83
#define C_VB_POSITION
Definition: CShader.h:73
std::vector< cVector3d > m_globalPos
Global position of vertices in world coordinates.
Definition: CVertexArray.h:1220
std::vector< cVector3d > m_localPos
Local position of vertices.
Definition: CVertexArray.h:1217
#define C_VB_TANGENT
Definition: CShader.h:77
GLuint m_positionBuffer
OpenGL Buffer for storing triangle indices.
Definition: CVertexArray.h:1307
cVector3d getLocalPos(const unsigned int a_vertexIndex) const
Definition: CVertexArray.h:377
void setColor(const unsigned int a_vertexIndex, const cColorb &a_color)
Definition: CVertexArray.h:565
bool getUseBitangentData() const
Definition: CVertexArray.h:831
void setBitangent(const unsigned int a_vertexIndex, const double &a_x, const double &a_y, const double &a_z)
Definition: CVertexArray.h:675
std::shared_ptr< cVertexArray > cVertexArrayPtr
Definition: CVertexArray.h:107
bool m_useTangentData
If true then surface tangent data will be allocated for each new vertex.
Definition: CVertexArray.h:1260
This class defines a color using a GLfloat representation for each component.
Definition: CColor.h:138
Implements color properties.
bool getUseColorData() const
Definition: CVertexArray.h:803
void setUserData(const unsigned int a_vertexIndex, const int a_userData)
Definition: CVertexArray.h:710
cVertexArray(const cVertexArrayOptions &a_options)
Definition: CVertexArray.h:150
void setTexCoord(const unsigned int a_vertexIndex, const double &a_tx, const double &a_ty=0.0, const double &a_tz=0.0)
Definition: CVertexArray.h:485
#define C_VB_INDEX_BUFFER
Definition: CShader.h:72
bool getUseUserData() const
Definition: CVertexArray.h:845
bool getUseTexCoordData() const
Definition: CVertexArray.h:789
bool m_flagPositionData
If true then position data has been modified.
Definition: CVertexArray.h:1276
bool m_flagTexCoordData
If true then texture coordinate data has been modified.
Definition: CVertexArray.h:1282
bool m_useNormalData
If true then normal data will be allocated for each new vertex.
Definition: CVertexArray.h:1251
#define C_VB_TEXCOORD
Definition: CShader.h:75
void setNormal(const unsigned int a_vertexIndex, const cVector3d &a_normal)
Definition: CVertexArray.h:407
void setTangent(const unsigned int a_vertexIndex, const double &a_x, const double &a_y, const double &a_z)
Definition: CVertexArray.h:619
bool m_flagBitangentData
If true then surface bitangent data has been modified.
Definition: CVertexArray.h:1291
bool m_useNormalData
Definition: CVertexArray.h:98
void clear()
Definition: CVertexArray.h:225
std::vector< cVector3d > m_texCoord
Texture coordinate (U,V,W) of vertices.
Definition: CVertexArray.h:1226
Definition: CAudioBuffer.cpp:56
GLuint m_colorBuffer
OpenGL Buffer for storing triangle indices.
Definition: CVertexArray.h:1316
GLuint m_normalBuffer
OpenGL Buffer for storing triangle indices.
Definition: CVertexArray.h:1310
#define C_VB_NORMAL
Definition: CShader.h:74
bool m_useTangentData
Definition: CVertexArray.h:101
cVector3d getGlobalPos(const unsigned int a_vertexIndex) const
Definition: CVertexArray.h:393
void renderInitialize()
Definition: CVertexArray.h:856
unsigned int m_numVertices
Number of vertices.
Definition: CVertexArray.h:1248
void setColor(const unsigned int a_vertexIndex, const float &a_red, const float &a_green, const float &a_blue, const float &a_alpha=1.0)
Definition: CVertexArray.h:543
int newVertices(unsigned int a_numberOfVertices)
Definition: CVertexArray.h:300
void computeGlobalPosition(const unsigned int a_vertexIndex, const cVector3d &a_globalPos, const cMatrix3d &a_globalRot)
Definition: CVertexArray.h:745
void translate(const unsigned int a_vertexIndex, const cVector3d &a_translation)
Definition: CVertexArray.h:361
void setLocalPos(const unsigned int a_vertexIndex, const cVector3d &a_pos)
Definition: CVertexArray.h:344
cColorf getColorf() const
This method returns this color converted into cColorf format.
Definition: CColor.cpp:76
void setBitangent(const unsigned int a_vertexIndex, const cVector3d &a_bitangent)
Definition: CVertexArray.h:654
bool getUseNormalData() const
Definition: CVertexArray.h:775
bool m_useUserData
If true then surface bitangent data will be allocated for each new vertex.
Definition: CVertexArray.h:1266
cVector3d getNormal(const unsigned int a_vertexIndex) const
Definition: CVertexArray.h:449
cVector3d getTangent(const unsigned int a_vertexIndex) const
Definition: CVertexArray.h:640