8#ifndef META_OCEAN_RENDERING_GLES_VERTEX_SET_H 
    9#define META_OCEAN_RENDERING_GLES_VERTEX_SET_H 
   26namespace GLESceneGraph
 
   55                virtual void bind(
const GLuint programId) 
const = 0;
 
 
   93                void setData(
const T* elements, 
const size_t numberElements, 
const GLenum usage = GL_STATIC_DRAW);
 
  100                void bind(
const GLuint programId, 
const char* attributeName) 
const;
 
  106                void bind(
const GLuint programId) 
const override;
 
  136                unsigned int numberElements_ = 0u;
 
  148        template <
typename T>
 
  149        static constexpr size_t numberComponents();
 
  156        template <
typename T>
 
  157        static constexpr GLenum componentType();
 
  164        template <
typename T>
 
  165        static constexpr bool isFloatComponent();
 
  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);
 
  351        GLuint vertexArray_ = 0u;
 
  380    attributeName_(std::move(attributeName))
 
 
  387    attributeName_(std::move(vertexBufferObject.attributeName_)),
 
  388    buffer_(vertexBufferObject.buffer_),
 
  389    numberElements_(vertexBufferObject.numberElements_)
 
  391    vertexBufferObject.buffer_ = 0u;
 
  392    vertexBufferObject.numberElements_ = 0u;
 
 
  398    ocean_assert(elements != 
nullptr);
 
  399    ocean_assert(numberElements != 0);
 
  403        glGenBuffers(1, &buffer_);
 
  404        ocean_assert(GL_NO_ERROR == glGetError());
 
  405        ocean_assert(buffer_ != 0u);
 
  408    glBindBuffer(GL_ARRAY_BUFFER, buffer_);
 
  409    ocean_assert(GL_NO_ERROR == glGetError());
 
  411    setBufferData(GL_ARRAY_BUFFER, elements, numberElements, usage);
 
  412    numberElements_ = (
unsigned int)(numberElements);
 
  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());
 
  439            constexpr GLint size = GLint(numberComponents<T>());
 
  440            constexpr GLenum 
type = componentType<T>();
 
  442            if (isFloatComponent<T>())
 
  444                glVertexAttribPointer(location, size, 
type, GL_FALSE, 0, 
nullptr);
 
  448                glVertexAttribIPointer(location, size, 
type, 0, 
nullptr);
 
  451            ocean_assert(GL_NO_ERROR == glGetError());
 
 
  459    bind(programId, attributeName_.c_str());
 
 
  465    return numberElements_;
 
 
  473        glDeleteBuffers(1, &buffer_);
 
  474        ocean_assert(GL_NO_ERROR == glGetError());
 
  477        numberElements_ = 0u;
 
 
 
  482constexpr size_t GLESVertexSet::numberComponents<uint8_t>()
 
 
  488constexpr size_t GLESVertexSet::numberComponents<uint16_t>()
 
 
  494constexpr size_t GLESVertexSet::numberComponents<uint32_t>()
 
 
  500constexpr size_t GLESVertexSet::numberComponents<float>()
 
 
  506constexpr size_t GLESVertexSet::numberComponents<double>()
 
 
  512constexpr size_t GLESVertexSet::numberComponents<RGBAColor>()
 
 
  518constexpr size_t GLESVertexSet::numberComponents<VectorF2>()
 
 
  524constexpr size_t GLESVertexSet::numberComponents<VectorD2>()
 
 
  530constexpr size_t GLESVertexSet::numberComponents<VectorF3>()
 
 
  536constexpr size_t GLESVertexSet::numberComponents<VectorD3>()
 
 
  542constexpr size_t GLESVertexSet::numberComponents<VectorF4>()
 
 
  548constexpr size_t GLESVertexSet::numberComponents<VectorD4>()
 
 
  554constexpr size_t GLESVertexSet::numberComponents<VectorT4<uint16_t>>()
 
 
  560constexpr size_t GLESVertexSet::numberComponents<VectorT4<uint32_t>>()
 
 
  568    ocean_assert(
false && 
"Missing implementation!");
 
 
  573constexpr GLenum GLESVertexSet::componentType<uint8_t>()
 
  575    return  GL_UNSIGNED_BYTE;
 
 
  579constexpr GLenum GLESVertexSet::componentType<uint16_t>()
 
  581    return  GL_UNSIGNED_SHORT;
 
 
  585constexpr GLenum GLESVertexSet::componentType<uint32_t>()
 
  587    return  GL_UNSIGNED_INT;
 
 
  591constexpr GLenum GLESVertexSet::componentType<float>()
 
 
  597constexpr GLenum GLESVertexSet::componentType<double>()
 
 
  603constexpr GLenum GLESVertexSet::componentType<RGBAColor>()
 
 
  609constexpr GLenum GLESVertexSet::componentType<VectorF2>()
 
 
  615constexpr GLenum GLESVertexSet::componentType<VectorD2>()
 
 
  621constexpr GLenum GLESVertexSet::componentType<VectorF3>()
 
 
  627constexpr GLenum GLESVertexSet::componentType<VectorD3>()
 
 
  633constexpr GLenum GLESVertexSet::componentType<VectorF4>()
 
 
  639constexpr GLenum GLESVertexSet::componentType<VectorD4>()
 
 
  645constexpr GLenum GLESVertexSet::componentType<VectorT4<uint16_t>>()
 
  647    return GL_UNSIGNED_SHORT;
 
 
  651constexpr GLenum GLESVertexSet::componentType<VectorT4<uint32_t>>()
 
  653    return GL_UNSIGNED_INT;
 
 
  659    ocean_assert(
false && 
"Missing implementation!");
 
 
  664constexpr bool GLESVertexSet::isFloatComponent<uint8_t>()
 
 
  670constexpr bool GLESVertexSet::isFloatComponent<uint16_t>()
 
 
  676constexpr bool GLESVertexSet::isFloatComponent<uint32_t>()
 
 
  682constexpr bool GLESVertexSet::isFloatComponent<VectorT4<uint16_t>>()
 
 
  688constexpr bool GLESVertexSet::isFloatComponent<VectorT4<uint32_t>>()
 
 
  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
 
This class is the base class for all GLESceneGraph objects.
Definition GLESObject.h:57
 
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
 
void bind(const GLuint programId) const override
Binds a vertex buffer object to a given program.
Definition GLESVertexSet.h:457
 
VertexBufferObjectT(VertexBufferObjectT< T > &&vertexBufferObject)
Move constructor.
Definition GLESVertexSet.h:386
 
unsigned int numberElements() const
Returns the number of elements the object holds.
Definition GLESVertexSet.h:463
 
void bind(const GLuint programId, const char *attributeName) const
Binds this vertex buffer to a specified program.
Definition GLESVertexSet.h:423
 
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
 
This class implements a GLESceneGraph vertex set object.
Definition GLESVertexSet.h:36
 
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.
 
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
 
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.
 
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.
 
std::unordered_map< std::string, std::shared_ptr< VertexBufferObject > > VertexBufferObjectMap
Definition GLESVertexSet.h:141
 
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.
 
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
 
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.
 
This class is the base class for all rendering vertex sets.
Definition VertexSet.h:47
 
ObjectType type() const override
Returns the type of this object.
 
This class implements a vector with two elements.
Definition Vector2.h:96
 
This class implements a vector with four elements.
Definition Vector4.h:97
 
std::vector< RGBAColor > RGBAColors
Definition of a vector holding rgba color objects.
Definition RGBAColor.h:27
 
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
 
std::vector< Normal > Normals
Definition of a vector holding normals.
Definition rendering/Rendering.h:107
 
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< Vertex > Vertices
Definition of a vector holding vertices.
Definition rendering/Rendering.h:119
 
std::vector< TriangleFace > TriangleFaces
Definition of a vector holding triangle faces.
Definition TriangleFace.h:30
 
std::vector< VertexIndices > VertexIndexGroups
Definition of a vector holding vertex indices.
Definition rendering/Rendering.h:125
 
The namespace covering the entire Ocean framework.
Definition Accessor.h:15