8#ifndef META_OCEAN_RENDERING_GLES_VERTEX_SET_H
9#define META_OCEAN_RENDERING_GLES_VERTEX_SET_H
55 virtual void bind(
const GLuint programId)
const = 0;
100 void bind(
const GLuint programId,
const char* attributeName)
const;
106 void bind(
const GLuint programId)
const override;
148 template <
typename T>
156 template <
typename T>
164 template <
typename T>
294 template <
typename T>
295 void setAttribute(
const std::string& attributeName,
const T* elements,
const size_t numberElements);
338 template <
typename T>
339 static void setBufferData(
const GLenum target,
const T* values,
const size_t size,
const GLenum usage);
391 vertexBufferObject.buffer_ = 0u;
392 vertexBufferObject.numberElements_ = 0u;
398 ocean_assert(elements !=
nullptr);
404 ocean_assert(GL_NO_ERROR == glGetError());
408 glBindBuffer(GL_ARRAY_BUFFER,
buffer_);
409 ocean_assert(GL_NO_ERROR == glGetError());
414 if (glGetError() == GL_OUT_OF_MEMORY)
418 ocean_assert(
false &&
"Out of memory!");
427 glBindBuffer(GL_ARRAY_BUFFER,
buffer_);
428 ocean_assert(GL_NO_ERROR == glGetError());
430 ocean_assert(glIsProgram(programId));
431 const GLint location = glGetAttribLocation(programId, attributeName !=
nullptr ? attributeName :
attributeName_.c_str());
432 ocean_assert(GL_NO_ERROR == glGetError());
436 glEnableVertexAttribArray(location);
437 ocean_assert(GL_NO_ERROR == glGetError());
444 glVertexAttribPointer(location, size,
type, GL_FALSE, 0,
nullptr);
448 glVertexAttribIPointer(location, size,
type, 0,
nullptr);
451 ocean_assert(GL_NO_ERROR == glGetError());
474 ocean_assert(GL_NO_ERROR == glGetError());
568 ocean_assert(
false &&
"Missing implementation!");
575 return GL_UNSIGNED_BYTE;
581 return GL_UNSIGNED_SHORT;
587 return GL_UNSIGNED_INT;
647 return GL_UNSIGNED_SHORT;
653 return GL_UNSIGNED_INT;
659 ocean_assert(
false &&
"Missing implementation!");
715 ocean_assert(GL_NO_ERROR == glGetError());
717 static_assert(
sizeof(GLbyte) ==
sizeof(uint8_t),
"Invalid data type!");
719 glBufferData(target, GLsizeiptr(size *
sizeof(GLbyte)), values, usage);
720 ocean_assert(GL_NO_ERROR == glGetError());
726 ocean_assert(GL_NO_ERROR == glGetError());
728 static_assert(
sizeof(GLshort) ==
sizeof(uint16_t),
"Invalid data type!");
730 glBufferData(target, GLsizeiptr(size *
sizeof(GLshort)), values, usage);
731 ocean_assert(GL_NO_ERROR == glGetError());
737 ocean_assert(GL_NO_ERROR == glGetError());
739 static_assert(
sizeof(GLint) ==
sizeof(uint32_t),
"Invalid data type!");
741 glBufferData(target, GLsizeiptr(size *
sizeof(GLint)), values, usage);
742 ocean_assert(GL_NO_ERROR == glGetError());
748 ocean_assert(GL_NO_ERROR == glGetError());
750 static_assert(
sizeof(GLfloat) ==
sizeof(float),
"Invalid data type!");
752 glBufferData(target, GLsizeiptr(size *
sizeof(GLfloat)), values, usage);
753 ocean_assert(GL_NO_ERROR == glGetError());
759 ocean_assert(GL_NO_ERROR == glGetError());
761 std::vector<float> floatValues(size);
763 for (
size_t n = 0; n < size; n++)
765 floatValues[n] = float(values[n]);
768 static_assert(
sizeof(GLfloat) ==
sizeof(float),
"Invalid data type!");
770 glBufferData(target, GLsizeiptr(size *
sizeof(GLfloat)), floatValues.data(), usage);
771 ocean_assert(GL_NO_ERROR == glGetError());
777 ocean_assert(GL_NO_ERROR == glGetError());
779 static_assert(
sizeof(GLfloat) * 4 ==
sizeof(
RGBAColor),
"Invalid data type!");
781 glBufferData(target, GLsizeiptr(size *
sizeof(GLfloat) * 4), values, usage);
782 ocean_assert(GL_NO_ERROR == glGetError());
788 ocean_assert(GL_NO_ERROR == glGetError());
790 static_assert(
sizeof(GLfloat) * 2 ==
sizeof(
VectorF2),
"Invalid data type!");
792 glBufferData(target, GLsizeiptr(size *
sizeof(GLfloat) * 2), values, usage);
793 ocean_assert(GL_NO_ERROR == glGetError());
799 ocean_assert(GL_NO_ERROR == glGetError());
801 std::vector<float> floatValues(size * 2);
803 for (
size_t n = 0; n < size; n++)
805 floatValues[2 * n + 0] = float(values[n][0]);
806 floatValues[2 * n + 1] = float(values[n][1]);
809 static_assert(
sizeof(GLfloat) * 2 ==
sizeof(
VectorF2),
"Invalid data type!");
811 glBufferData(target, GLsizeiptr(size *
sizeof(GLfloat) * 2), floatValues.data(), usage);
812 ocean_assert(GL_NO_ERROR == glGetError());
818 ocean_assert(GL_NO_ERROR == glGetError());
820 static_assert(
sizeof(GLfloat) * 3 ==
sizeof(
VectorF3),
"Invalid data type!");
822 glBufferData(target, GLsizeiptr(size *
sizeof(GLfloat) * 3), values, usage);
823 ocean_assert(GL_NO_ERROR == glGetError());
829 ocean_assert(GL_NO_ERROR == glGetError());
831 std::vector<float> floatValues(size * 3);
833 for (
size_t n = 0; n < size; n++)
835 floatValues[3 * n + 0] = float(values[n][0]);
836 floatValues[3 * n + 1] = float(values[n][1]);
837 floatValues[3 * n + 2] = float(values[n][2]);
840 static_assert(
sizeof(GLfloat) * 3 ==
sizeof(
VectorF3),
"Invalid data type!");
842 glBufferData(target, GLsizeiptr(size *
sizeof(GLfloat) * 3), floatValues.data(), usage);
843 ocean_assert(GL_NO_ERROR == glGetError());
849 ocean_assert(GL_NO_ERROR == glGetError());
851 static_assert(
sizeof(GLfloat) * 4 ==
sizeof(
VectorF4),
"Invalid data type!");
853 glBufferData(target, GLsizeiptr(size *
sizeof(GLfloat) * 4), values, usage);
854 ocean_assert(GL_NO_ERROR == glGetError());
860 ocean_assert(GL_NO_ERROR == glGetError());
862 std::vector<float> floatValues(size * 4);
864 for (
size_t n = 0; n < size; n++)
866 floatValues[4 * n + 0] = float(values[n][0]);
867 floatValues[4 * n + 1] = float(values[n][1]);
868 floatValues[4 * n + 2] = float(values[n][2]);
869 floatValues[4 * n + 3] = float(values[n][3]);
872 static_assert(
sizeof(GLfloat) * 4 ==
sizeof(
VectorF4),
"Invalid data type!");
874 glBufferData(target, GLsizeiptr(size *
sizeof(GLfloat) * 4), floatValues.data(), usage);
875 ocean_assert(GL_NO_ERROR == glGetError());
881 ocean_assert(GL_NO_ERROR == glGetError());
883 static_assert(
sizeof(GLushort) * 4 ==
sizeof(
VectorT4<uint16_t>),
"Invalid data type!");
885 glBufferData(target, GLsizeiptr(size *
sizeof(GLushort) * 4), values, usage);
886 ocean_assert(GL_NO_ERROR == glGetError());
892 ocean_assert(GL_NO_ERROR == glGetError());
894 static_assert(
sizeof(GLuint) * 4 ==
sizeof(
VectorT4<uint32_t>),
"Invalid data type!");
896 glBufferData(target, GLsizeiptr(size *
sizeof(GLuint) * 4), values, usage);
897 ocean_assert(GL_NO_ERROR == glGetError());
903 ocean_assert(
false &&
"Missing implementation!");
This class implements a 3D bounding box.
Definition BoundingBox.h:23
This class implements a color defined by red, green, blue and alpha parameters.
Definition RGBAColor.h:41
GLESObject()
Creates a new GLESceneGraph object.
This class is the base class for all VertexBufferObjects.
Definition GLESVertexSet.h:43
virtual void bind(const GLuint programId) const =0
Binds a vertex buffer object to a given program.
virtual ~VertexBufferObject()=default
Destructs a vertex buffer object and releases all resources.
This class implements the wrapper around a vertex buffer object.
Definition GLESVertexSet.h:64
VertexBufferObjectT(const VertexBufferObjectT &vertexBufferObject)=delete
Disabled copy constructor.
VertexBufferObjectT(std::string attributeName)
Creates a new vertex buffer object.
Definition GLESVertexSet.h:379
~VertexBufferObjectT() override
Destructs the object and releases all resources.
Definition GLESVertexSet.h:82
void setData(const T *elements, const size_t numberElements, const GLenum usage=GL_STATIC_DRAW)
Sets the data of this buffer.
Definition GLESVertexSet.h:396
unsigned int numberElements() const
Definition GLESVertexSet.h:463
unsigned int numberElements_
The number of elements stored in the buffer object.
Definition GLESVertexSet.h:136
void bind(const GLuint programId, const char *attributeName) const
Binds this vertex buffer to a specified program.
Definition GLESVertexSet.h:423
GLuint buffer_
The buffer object.
Definition GLESVertexSet.h:133
std::string attributeName_
The attribute name associated with this buffer object.
Definition GLESVertexSet.h:130
void release()
Explicitly releases the vertex buffer object and all resources.
Definition GLESVertexSet.h:469
std::string phantomTextureReferenceCoordinateSystem_
Explicit reference coordinate system for phantom texture coordinates.
Definition GLESVertexSet.h:372
TextureCoordinates textureCoordinates(const unsigned int layerIndex) const override
Returns the texture coordinates of this set.
void setNormals(const Vector3 *normals, const size_t size) override
Sets the normals for this set.
BoundingBox boundingBox(const VertexIndices &vertexIndices) const
Determines the bounding box of this vertex set.
BoundingBox boundingBox(const unsigned int numberVertices) const
Determines the bounding box of this vertex set.
std::string phantomTextureCoordinateSystem() const override
Returns the explicit reference coordinate system of the phantom object, if any.
Vectors3 vertices_
The vertices stored in this vertex set.
Definition GLESVertexSet.h:375
void setPhantomTextureCoordinateSystem(const std::string &reference) override
Sets the explicit reference coordinate system of the phantom objects.
void setVertices(const Vertices &vertices) override
Sets the vertices for this set.
VertexBufferObjectT< Vector3 > bufferVertices_
The buffer object for the vertices.
Definition GLESVertexSet.h:354
void setAttribute(const std::string &attributeName, const T *elements, const size_t numberElements)
Sets a custom VertexSet attribute in addition to the standard attributes like e.g....
Definition GLESVertexSet.h:700
Vertices vertices() const override
Returns the vertices of this set.
unsigned int numberColors() const override
Returns the number of colors of this set.
void release()
Releases all internal OpenGL ES vertex buffer objects.
VertexBufferObjectMap customVertexBufferObjectMap_
The custom buffer objects.
Definition GLESVertexSet.h:369
VertexBufferObjectT< RGBAColor > bufferColors_
The buffer object for the colors.
Definition GLESVertexSet.h:366
void set(const Vertices &vertices, const Normals &normals, const TextureCoordinates &textureCoordinates, const RGBAColors &colors) override
Sets several attributes concurrently.
Normals normals() const override
Returns the normals of this set.
VertexBufferObjectT< Vector2 > bufferTextureCoordinates2D_
The buffer object for the 2D texture coordinates.
Definition GLESVertexSet.h:360
static constexpr bool isFloatComponent()
Returns whether the component is float component.
Definition GLESVertexSet.h:694
static constexpr GLenum componentType()
Returns the type of the components of a data type.
Definition GLESVertexSet.h:657
void setPhantomTextureCoordinates(const Vertices &textureCoordinates, const unsigned int layerIndex) override
Sets 3D texels for this set used for phantom objects.
BoundingBox boundingBox(const VertexIndexGroups &strips) const
Determines the bounding box of this vertex set.
unsigned int numberVertices() const override
Returns the number of vertices of this set.
VertexBufferObjectT< Vector3 > bufferNormals_
The buffer object for the normals.
Definition GLESVertexSet.h:357
GLuint vertexArray_
The vertex array for this VertexSet.
Definition GLESVertexSet.h:351
BoundingBox boundingBox(const TriangleFaces &triangleFaces) const
Determines the bounding box of this vertex set.
void bindVertexSet(const GLuint programId)
Binds the vertex set to a program.
RGBAColors colors() const override
Returns the colors of this set.
VertexBufferObjectT< Vector3 > bufferTextureCoordinates3D_
The buffer object for the 3D textures coordinates (for phantom objects).
Definition GLESVertexSet.h:363
void setTextureCoordinates(const TextureCoordinates &textureCoordinates, const unsigned int layerIndex) override
Sets the texels for this set.
static void setBufferData(const GLenum target, const T *values, const size_t size, const GLenum usage)
Creates and initializes a buffer object's data store.
Definition GLESVertexSet.h:901
std::unordered_map< std::string, std::shared_ptr< VertexBufferObject > > VertexBufferObjectMap
Definition GLESVertexSet.h:141
static constexpr size_t numberComponents()
Returns the number of components a data type has.
Definition GLESVertexSet.h:566
unsigned int numberNormals() const override
Returns the number of normals of this set.
~GLESVertexSet() override
Destructs a GLESceneGraph vertex set object.
void setNormals(const Normals &normals) override
Sets the normals for this set.
GLESVertexSet()
Creates a new GLESceneGraph vertex set object.
unsigned int numberTextureCoordinates(const unsigned int layerIndex) const override
Returns the number of texture coordinates of this set.
void setVertices(const Vector3 *vertices, const size_t size) override
Sets the vertices for this set.
void setColors(const RGBAColors &colors) override
Sets the colors for this set.
VertexSet()
Creates a new vertex set object.
ObjectType type() const override
Returns the type of this object.
This class implements a vector with four elements.
Definition Vector4.h:97
VectorT3< float > VectorF3
Definition of a 3D vector with float values.
Definition Vector3.h:43
VectorT2< float > VectorF2
Definition of a 2D vector with float values.
Definition Vector2.h:42
VectorT4< double > VectorD4
Definition of a 4D vector with double values.
Definition Vector4.h:36
VectorT2< double > VectorD2
Definition of a 2D vector with double values.
Definition Vector2.h:35
std::vector< RGBAColor > RGBAColors
Definition of a vector holding rgba color objects.
Definition RGBAColor.h:27
VectorT3< Scalar > Vector3
Definition of a 3D vector.
Definition Vector3.h:29
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
VectorT4< float > VectorF4
Definition of a 4D vector with float values.
Definition Vector4.h:43
VectorT3< double > VectorD3
Definition of a 3D vector with double values.
Definition Vector3.h:36
std::vector< VertexIndex > VertexIndices
Definition of a vector holding vertex indices.
Definition rendering/Rendering.h:101
std::vector< TextureCoordinate > TextureCoordinates
Definition of a vector holding texture coordinates.
Definition rendering/Rendering.h:113
std::vector< Normal > Normals
Definition of a vector holding normals.
Definition rendering/Rendering.h:107
std::vector< Vertex > Vertices
Definition of a vector holding vertices.
Definition rendering/Rendering.h:119
std::vector< VertexIndices > VertexIndexGroups
Definition of a vector holding vertex indices.
Definition rendering/Rendering.h:125
std::vector< TriangleFace > TriangleFaces
Definition of a vector holding triangle faces.
Definition TriangleFace.h:30
Namespace of the Rendering GLESceneGraph library.
Definition rendering/glescenegraph/android/Android.h:20
Namespace of the Rendering library.
Definition AbsoluteTransform.h:18
The namespace covering the entire Ocean framework.
Definition Accessor.h:15