Ocean
Loading...
Searching...
No Matches
GLESVertexSet.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_RENDERING_GLES_VERTEX_SET_H
9#define META_OCEAN_RENDERING_GLES_VERTEX_SET_H
10
14
16
19
20namespace Ocean
21{
22
23namespace Rendering
24{
25
26namespace GLESceneGraph
27{
28
29/**
30 * This class implements a GLESceneGraph vertex set object.
31 * @ingroup renderinggles
32 */
33class OCEAN_RENDERING_GLES_EXPORT GLESVertexSet :
34 virtual public GLESObject,
35 virtual public VertexSet
36{
37 public:
38
39 /**
40 * This class is the base class for all VertexBufferObjects
41 */
43 {
44 public:
45
46 /**
47 * Destructs a vertex buffer object and releases all resources.
48 */
49 virtual ~VertexBufferObject() = default;
50
51 /**
52 * Binds a vertex buffer object to a given program.
53 * @param programId The id of the program to which this object will be bound.
54 */
55 virtual void bind(const GLuint programId) const = 0;
56 };
57
58 /**
59 * This class implements the wrapper around a vertex buffer object.
60 * @tparam T The data type of the elements the vertex buffer object is holding
61 */
62 template <typename T>
64 {
65 public:
66
67 /**
68 * Creates a new vertex buffer object.
69 * @param attributeName The attribute name to which this vertex buffer will be bound
70 */
71 explicit VertexBufferObjectT(std::string attributeName);
72
73 /**
74 * Move constructor.
75 * @param vertexBufferObject Vertex buffer object to be moved
76 */
78
79 /**
80 * Destructs the object and releases all resources.
81 */
82 ~VertexBufferObjectT() override // need to be defined here in the class as Clang will complain otherwise
83 {
84 release();
85 }
86
87 /**
88 * Sets the data of this buffer.
89 * @param elements The elements to be set, must be valid
90 * @param numberElements The number of elements to set, with range [1, infinity)
91 * @param usage Specifies the expected usage pattern of the data store
92 */
93 void setData(const T* elements, const size_t numberElements, const GLenum usage = GL_STATIC_DRAW);
94
95 /**
96 * Binds this vertex buffer to a specified program.
97 * @param programId The id of the program to which the buffer will be bound
98 * @param attributeName Optional explicit attribute name to be used instead of the object's attribute name; nullptr to use the object's attribute name
99 */
100 void bind(const GLuint programId, const char* attributeName) const;
101
102 /**
103 * Binds a vertex buffer object to a given program.
104 * @see VertexBufferObject::bind().
105 */
106 void bind(const GLuint programId) const override;
107
108 /**
109 * Returns the number of elements the object holds.
110 * @return The object's elements
111 */
112 inline unsigned int numberElements() const;
113
114 /**
115 * Explicitly releases the vertex buffer object and all resources.
116 */
117 void release();
118
119 protected:
120
121 /**
122 * Disabled copy constructor.
123 * @param vertexBufferObject The vertex buffer object which would be copied
124 */
125 VertexBufferObjectT(const VertexBufferObjectT& vertexBufferObject) = delete;
126
127 protected:
128
129 /// The attribute name associated with this buffer object.
130 std::string attributeName_;
131
132 /// The buffer object.
133 GLuint buffer_ = 0u;
134
135 /// The number of elements stored in the buffer object.
136 unsigned int numberElements_ = 0u;
137 };
138
139 protected:
140
141 using VertexBufferObjectMap = std::unordered_map<std::string, std::shared_ptr<VertexBufferObject>>;
142
143 /**
144 * Returns the number of components a data type has.
145 * @return The data type's number of components
146 * @tparam T The data type
147 */
148 template <typename T>
149 static constexpr size_t numberComponents();
150
151 /**
152 * Returns the type of the components of a data type.
153 * @return The data type's component type
154 * @tparam T The data type
155 */
156 template <typename T>
157 static constexpr GLenum componentType();
158
159 /**
160 * Returns whether the component is float component.
161 * @return True, if so; False, if the component is an integer component
162 * @tparam T The data type
163 */
164 template <typename T>
165 static constexpr bool isFloatComponent();
166
167 public:
168
169 /**
170 * Creates a new GLESceneGraph vertex set object.
171 */
173
174 /**
175 * Destructs a GLESceneGraph vertex set object.
176 */
177 ~GLESVertexSet() override;
178
179 /**
180 * Returns the normals of this set.
181 * @see VertexSet::normals().
182 */
183 Normals normals() const override;
184
185 /**
186 * Returns the texture coordinates of this set.
187 * @see VertexSet::textureCoordinates().
188 */
189 TextureCoordinates textureCoordinates(const unsigned int layerIndex) const override;
190
191 /**
192 * Returns the explicit reference coordinate system of the phantom object, if any.
193 * @return The name of the reference coordinate system
194 */
195 std::string phantomTextureCoordinateSystem() const override;
196
197 /**
198 * Returns the vertices of this set.
199 * @see VertexSet::vertices().
200 */
201 Vertices vertices() const override;
202
203 /**
204 * Returns the colors of this set.
205 * @see VertexSet::colors();
206 */
207 RGBAColors colors() const override;
208
209 /**
210 * Returns the number of normals of this set.
211 * @see VertexSet::numberNormals().
212 */
213 unsigned int numberNormals() const override;
214
215 /**
216 * Returns the number of texture coordinates of this set.
217 * @see VertexSet::numberTextureCoordinates().
218 */
219 unsigned int numberTextureCoordinates(const unsigned int layerIndex) const override;
220
221 /**
222 * Returns the number of vertices of this set.
223 * @see VertexSet::numberVertices().
224 */
225 unsigned int numberVertices() const override;
226
227 /**
228 * Returns the number of colors of this set.
229 * @see VertexSet::numberColors().
230 */
231 unsigned int numberColors() const override;
232
233 /**
234 * Sets the normals for this set.
235 * @see VertexSet::setNormals().
236 */
237 void setNormals(const Normals& normals) override;
238
239 /**
240 * Sets the normals for this set.
241 * @see VertexSet::setNormals().
242 */
243 void setNormals(const Vector3* normals, const size_t size) override;
244
245 /**
246 * Sets the texels for this set.
247 * @see VertexSet::setTextureCoordinates().
248 */
249 void setTextureCoordinates(const TextureCoordinates& textureCoordinates, const unsigned int layerIndex) override;
250
251 /**
252 * Sets 3D texels for this set used for phantom objects.
253 * @see VertexSet::setPhantomTextureCoordinates().
254 */
255 void setPhantomTextureCoordinates(const Vertices& textureCoordinates, const unsigned int layerIndex) override;
256
257 /**
258 * Sets the explicit reference coordinate system of the phantom objects.
259 * @see VertexSet::setPhantomTextureCoordinateSystem().
260 */
261 void setPhantomTextureCoordinateSystem(const std::string& reference) override;
262
263 /**
264 * Sets the vertices for this set.
265 * @see VertexSet::setVertices().
266 */
267 void setVertices(const Vertices& vertices) override;
268
269 /**
270 * Sets the vertices for this set.
271 * @see VertexSet::setVertices().
272 */
273 void setVertices(const Vector3* vertices, const size_t size) override;
274
275 /**
276 * Sets the colors for this set.
277 * @see VertexSet::setColors().
278 */
279 void setColors(const RGBAColors& colors) override;
280
281 /**
282 * Sets several attributes concurrently.
283 * @see VertexSet::set().
284 */
285 void set(const Vertices& vertices, const Normals& normals, const TextureCoordinates& textureCoordinates, const RGBAColors& colors) override;
286
287 /**
288 * Sets a custom VertexSet attribute in addition to the standard attributes like e.g., vertices, normals, textureCoordinates etc.
289 * @param attributeName The name of the attribute, must be valid
290 * @param elements The elements of the attribute to set, must be valid
291 * @param numberElements The number of elements to set, with range [1, infinity)
292 * @tparam T The data type of the elements of the attribute
293 */
294 template <typename T>
295 void setAttribute(const std::string& attributeName, const T* elements, const size_t numberElements);
296
297 /**
298 * Binds the vertex set to a program.
299 * @param programId The id of the program to which the buffer will be bound
300 */
301 void bindVertexSet(const GLuint programId);
302
303 /**
304 * Determines the bounding box of this vertex set.
305 * @param vertexIndices The indices of the vertices for which the bounding box will be determined, can be empty
306 * @return The resulting bounding box
307 */
308 BoundingBox boundingBox(const VertexIndices& vertexIndices) const;
309
310 /**
311 * Determines the bounding box of this vertex set.
312 * @param triangleFaces The triangle faces of the vertices for which the bounding box will be determined, can be empty
313 * @return The resulting bounding box
314 */
315 BoundingBox boundingBox(const TriangleFaces& triangleFaces) const;
316
317 /**
318 * Determines the bounding box of this vertex set.
319 * @param strips The triangle strips of the vertices for which the bounding box will be determined, can be empty
320 * @return The resulting bounding box
321 */
323
324 /**
325 * Determines the bounding box of this vertex set.
326 * @param numberVertices The number of vertices for which the bounding box will be determined, with range [0, infinity)
327 * @return The resulting bounding box
328 */
329 BoundingBox boundingBox(const unsigned int numberVertices) const;
330
331 /**
332 * Creates and initializes a buffer object's data store.
333 * @param target Specifies the target to which the buffer object is bound
334 * @param values The values to be set, must be valid
335 * @param size The number of values to be set, with range [1, infinity)
336 * @param usage Specifies the expected usage pattern of the data store
337 */
338 template <typename T>
339 static void setBufferData(const GLenum target, const T* values, const size_t size, const GLenum usage);
340
341 protected:
342
343 /**
344 * Releases all internal OpenGL ES vertex buffer objects.
345 */
346 void release();
347
348 protected:
349
350 /// The vertex array for this VertexSet.
351 GLuint vertexArray_ = 0u;
352
353 /// The buffer object for the vertices.
355
356 /// The buffer object for the normals.
358
359 /// The buffer object for the 2D texture coordinates.
360 VertexBufferObjectT<Vector2> bufferTextureCoordinates2D_ = VertexBufferObjectT<Vector2>("aTextureCoordinate");
361
362 /// The buffer object for the 3D textures coordinates (for phantom objects).
363 VertexBufferObjectT<Vector3> bufferTextureCoordinates3D_ = VertexBufferObjectT<Vector3>("aTextureCoordinate");
364
365 /// The buffer object for the colors.
367
368 /// The custom buffer objects.
370
371 /// Explicit reference coordinate system for phantom texture coordinates.
373
374 /// The vertices stored in this vertex set.
376};
377
378template <typename T>
380 attributeName_(std::move(attributeName))
381{
382 // nothing to do here
383}
384
385template <typename T>
387 attributeName_(std::move(vertexBufferObject.attributeName_)),
388 buffer_(vertexBufferObject.buffer_),
389 numberElements_(vertexBufferObject.numberElements_)
390{
391 vertexBufferObject.buffer_ = 0u;
392 vertexBufferObject.numberElements_ = 0u;
393}
394
395template <typename T>
396void GLESVertexSet::VertexBufferObjectT<T>::setData(const T* elements, const size_t numberElements, const GLenum usage)
397{
398 ocean_assert(elements != nullptr);
399 ocean_assert(numberElements != 0);
400
401 if (buffer_ == 0u)
402 {
403 glGenBuffers(1, &buffer_);
404 ocean_assert(GL_NO_ERROR == glGetError());
405 ocean_assert(buffer_ != 0u);
406 }
407
408 glBindBuffer(GL_ARRAY_BUFFER, buffer_);
409 ocean_assert(GL_NO_ERROR == glGetError());
410
411 setBufferData(GL_ARRAY_BUFFER, elements, numberElements, usage);
412 numberElements_ = (unsigned int)(numberElements);
413
414 if (glGetError() == GL_OUT_OF_MEMORY)
415 {
416 release();
417
418 ocean_assert(false && "Out of memory!");
419 }
420}
421
422template <typename T>
423void GLESVertexSet::VertexBufferObjectT<T>::bind(const GLuint programId, const char* attributeName) const
424{
425 if (buffer_ != 0u)
426 {
427 glBindBuffer(GL_ARRAY_BUFFER, buffer_);
428 ocean_assert(GL_NO_ERROR == glGetError());
429
430 ocean_assert(glIsProgram(programId));
431 const GLint location = glGetAttribLocation(programId, attributeName != nullptr ? attributeName : attributeName_.c_str());
432 ocean_assert(GL_NO_ERROR == glGetError());
433
434 if (location != -1)
435 {
436 glEnableVertexAttribArray(location);
437 ocean_assert(GL_NO_ERROR == glGetError());
438
439 constexpr GLint size = GLint(numberComponents<T>());
440 constexpr GLenum type = componentType<T>();
441
442 if (isFloatComponent<T>())
443 {
444 glVertexAttribPointer(location, size, type, GL_FALSE, 0, nullptr);
445 }
446 else
447 {
448 glVertexAttribIPointer(location, size, type, 0, nullptr);
449 }
450
451 ocean_assert(GL_NO_ERROR == glGetError());
452 }
453 }
454}
455
456template <typename T>
457void GLESVertexSet::VertexBufferObjectT<T>::bind(const GLuint programId) const
458{
459 bind(programId, attributeName_.c_str());
460}
461
462template <typename T>
464{
465 return numberElements_;
466}
467
468template <typename T>
470{
471 if (buffer_ != 0u)
472 {
473 glDeleteBuffers(1, &buffer_);
474 ocean_assert(GL_NO_ERROR == glGetError());
475
476 buffer_ = 0u;
477 numberElements_ = 0u;
478 }
479}
480
481template <>
482constexpr size_t GLESVertexSet::numberComponents<uint8_t>()
483{
484 return 1;
485}
486
487template <>
488constexpr size_t GLESVertexSet::numberComponents<uint16_t>()
489{
490 return 1;
491}
492
493template <>
494constexpr size_t GLESVertexSet::numberComponents<uint32_t>()
495{
496 return 1;
497}
498
499template <>
500constexpr size_t GLESVertexSet::numberComponents<float>()
501{
502 return 1;
503}
504
505template <>
506constexpr size_t GLESVertexSet::numberComponents<double>()
507{
508 return 1;
509}
510
511template <>
512constexpr size_t GLESVertexSet::numberComponents<RGBAColor>()
513{
514 return 4;
515}
516
517template <>
518constexpr size_t GLESVertexSet::numberComponents<VectorF2>()
519{
520 return 2;
521}
522
523template <>
524constexpr size_t GLESVertexSet::numberComponents<VectorD2>()
525{
526 return 2;
527}
528
529template <>
530constexpr size_t GLESVertexSet::numberComponents<VectorF3>()
531{
532 return 3;
533}
534
535template <>
536constexpr size_t GLESVertexSet::numberComponents<VectorD3>()
537{
538 return 3;
539}
540
541template <>
542constexpr size_t GLESVertexSet::numberComponents<VectorF4>()
543{
544 return 4;
545}
546
547template <>
548constexpr size_t GLESVertexSet::numberComponents<VectorD4>()
549{
550 return 4;
551}
552
553template <>
554constexpr size_t GLESVertexSet::numberComponents<VectorT4<uint16_t>>()
555{
556 return 4;
557}
558
559template <>
560constexpr size_t GLESVertexSet::numberComponents<VectorT4<uint32_t>>()
561{
562 return 4;
563}
564
565template <typename T>
567{
568 ocean_assert(false && "Missing implementation!");
569 return 0;
570}
571
572template <>
573constexpr GLenum GLESVertexSet::componentType<uint8_t>()
574{
575 return GL_UNSIGNED_BYTE;
576}
577
578template <>
579constexpr GLenum GLESVertexSet::componentType<uint16_t>()
580{
581 return GL_UNSIGNED_SHORT;
582}
583
584template <>
585constexpr GLenum GLESVertexSet::componentType<uint32_t>()
586{
587 return GL_UNSIGNED_INT;
588}
589
590template <>
591constexpr GLenum GLESVertexSet::componentType<float>()
592{
593 return GL_FLOAT;
594}
595
596template <>
597constexpr GLenum GLESVertexSet::componentType<double>()
598{
599 return GL_FLOAT; // float as we use float32 only
600}
601
602template <>
603constexpr GLenum GLESVertexSet::componentType<RGBAColor>()
604{
605 return GL_FLOAT;
606}
607
608template <>
609constexpr GLenum GLESVertexSet::componentType<VectorF2>()
610{
611 return GL_FLOAT;
612}
613
614template <>
615constexpr GLenum GLESVertexSet::componentType<VectorD2>()
616{
617 return GL_FLOAT;
618}
619
620template <>
621constexpr GLenum GLESVertexSet::componentType<VectorF3>()
622{
623 return GL_FLOAT;
624}
625
626template <>
627constexpr GLenum GLESVertexSet::componentType<VectorD3>()
628{
629 return GL_FLOAT;
630}
631
632template <>
633constexpr GLenum GLESVertexSet::componentType<VectorF4>()
634{
635 return GL_FLOAT;
636}
637
638template <>
639constexpr GLenum GLESVertexSet::componentType<VectorD4>()
640{
641 return GL_FLOAT;
642}
643
644template <>
645constexpr GLenum GLESVertexSet::componentType<VectorT4<uint16_t>>()
646{
647 return GL_UNSIGNED_SHORT;
648}
649
650template <>
651constexpr GLenum GLESVertexSet::componentType<VectorT4<uint32_t>>()
652{
653 return GL_UNSIGNED_INT;
654}
655
656template <typename T>
658{
659 ocean_assert(false && "Missing implementation!");
660 return 0;
661}
662
663template <>
664constexpr bool GLESVertexSet::isFloatComponent<uint8_t>()
665{
666 return false;
667}
668
669template <>
670constexpr bool GLESVertexSet::isFloatComponent<uint16_t>()
671{
672 return false;
673}
674
675template <>
676constexpr bool GLESVertexSet::isFloatComponent<uint32_t>()
677{
678 return false;
679}
680
681template <>
682constexpr bool GLESVertexSet::isFloatComponent<VectorT4<uint16_t>>()
683{
684 return false;
685}
686
687template <>
688constexpr bool GLESVertexSet::isFloatComponent<VectorT4<uint32_t>>()
689{
690 return false;
691}
692
693template <typename T>
695{
696 return true;
697}
698
699template <typename T>
700void GLESVertexSet::setAttribute(const std::string& attibuteName, const T* elements, const size_t numberElements)
701{
702 VertexBufferObjectMap::iterator iObject = customVertexBufferObjectMap_.find(attibuteName);
703
704 if (iObject == customVertexBufferObjectMap_.cend())
705 {
706 iObject = customVertexBufferObjectMap_.emplace(attibuteName, std::make_shared<VertexBufferObjectT<T>>(attibuteName)).first;
707 }
708
709 dynamic_cast<VertexBufferObjectT<T>*>(iObject->second.get())->setData(elements, numberElements);
710}
711
712template <>
713inline void GLESVertexSet::setBufferData(const GLenum target, const uint8_t* values, const size_t size, const GLenum usage)
714{
715 ocean_assert(GL_NO_ERROR == glGetError());
716
717 static_assert(sizeof(GLbyte) == sizeof(uint8_t), "Invalid data type!");
718
719 glBufferData(target, GLsizeiptr(size * sizeof(GLbyte)), values, usage);
720 ocean_assert(GL_NO_ERROR == glGetError());
721}
722
723template <>
724inline void GLESVertexSet::setBufferData(const GLenum target, const uint16_t* values, const size_t size, const GLenum usage)
725{
726 ocean_assert(GL_NO_ERROR == glGetError());
727
728 static_assert(sizeof(GLshort) == sizeof(uint16_t), "Invalid data type!");
729
730 glBufferData(target, GLsizeiptr(size * sizeof(GLshort)), values, usage);
731 ocean_assert(GL_NO_ERROR == glGetError());
732}
733
734template <>
735inline void GLESVertexSet::setBufferData(const GLenum target, const uint32_t* values, const size_t size, const GLenum usage)
736{
737 ocean_assert(GL_NO_ERROR == glGetError());
738
739 static_assert(sizeof(GLint) == sizeof(uint32_t), "Invalid data type!");
740
741 glBufferData(target, GLsizeiptr(size * sizeof(GLint)), values, usage);
742 ocean_assert(GL_NO_ERROR == glGetError());
743}
744
745template <>
746inline void GLESVertexSet::setBufferData(const GLenum target, const float* values, const size_t size, const GLenum usage)
747{
748 ocean_assert(GL_NO_ERROR == glGetError());
749
750 static_assert(sizeof(GLfloat) == sizeof(float), "Invalid data type!");
751
752 glBufferData(target, GLsizeiptr(size * sizeof(GLfloat)), values, usage);
753 ocean_assert(GL_NO_ERROR == glGetError());
754}
755
756template <>
757inline void GLESVertexSet::setBufferData(const GLenum target, const double* values, const size_t size, const GLenum usage)
758{
759 ocean_assert(GL_NO_ERROR == glGetError());
760
761 std::vector<float> floatValues(size);
762
763 for (size_t n = 0; n < size; n++)
764 {
765 floatValues[n] = float(values[n]);
766 }
767
768 static_assert(sizeof(GLfloat) == sizeof(float), "Invalid data type!");
769
770 glBufferData(target, GLsizeiptr(size * sizeof(GLfloat)), floatValues.data(), usage);
771 ocean_assert(GL_NO_ERROR == glGetError());
772}
773
774template <>
775inline void GLESVertexSet::setBufferData(const GLenum target, const RGBAColor* values, const size_t size, const GLenum usage)
776{
777 ocean_assert(GL_NO_ERROR == glGetError());
778
779 static_assert(sizeof(GLfloat) * 4 == sizeof(RGBAColor), "Invalid data type!");
780
781 glBufferData(target, GLsizeiptr(size * sizeof(GLfloat) * 4), values, usage);
782 ocean_assert(GL_NO_ERROR == glGetError());
783}
784
785template <>
786inline void GLESVertexSet::setBufferData(const GLenum target, const VectorF2* values, const size_t size, const GLenum usage)
787{
788 ocean_assert(GL_NO_ERROR == glGetError());
789
790 static_assert(sizeof(GLfloat) * 2 == sizeof(VectorF2), "Invalid data type!");
791
792 glBufferData(target, GLsizeiptr(size * sizeof(GLfloat) * 2), values, usage);
793 ocean_assert(GL_NO_ERROR == glGetError());
794}
795
796template <>
797inline void GLESVertexSet::setBufferData(const GLenum target, const VectorD2* values, const size_t size, const GLenum usage)
798{
799 ocean_assert(GL_NO_ERROR == glGetError());
800
801 std::vector<float> floatValues(size * 2);
802
803 for (size_t n = 0; n < size; n++)
804 {
805 floatValues[2 * n + 0] = float(values[n][0]);
806 floatValues[2 * n + 1] = float(values[n][1]);
807 }
808
809 static_assert(sizeof(GLfloat) * 2 == sizeof(VectorF2), "Invalid data type!");
810
811 glBufferData(target, GLsizeiptr(size * sizeof(GLfloat) * 2), floatValues.data(), usage);
812 ocean_assert(GL_NO_ERROR == glGetError());
813}
814
815template <>
816inline void GLESVertexSet::setBufferData(const GLenum target, const VectorF3* values, const size_t size, const GLenum usage)
817{
818 ocean_assert(GL_NO_ERROR == glGetError());
819
820 static_assert(sizeof(GLfloat) * 3 == sizeof(VectorF3), "Invalid data type!");
821
822 glBufferData(target, GLsizeiptr(size * sizeof(GLfloat) * 3), values, usage);
823 ocean_assert(GL_NO_ERROR == glGetError());
824}
825
826template <>
827inline void GLESVertexSet::setBufferData(const GLenum target, const VectorD3* values, const size_t size, const GLenum usage)
828{
829 ocean_assert(GL_NO_ERROR == glGetError());
830
831 std::vector<float> floatValues(size * 3);
832
833 for (size_t n = 0; n < size; n++)
834 {
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]);
838 }
839
840 static_assert(sizeof(GLfloat) * 3 == sizeof(VectorF3), "Invalid data type!");
841
842 glBufferData(target, GLsizeiptr(size * sizeof(GLfloat) * 3), floatValues.data(), usage);
843 ocean_assert(GL_NO_ERROR == glGetError());
844}
845
846template <>
847inline void GLESVertexSet::setBufferData(const GLenum target, const VectorF4* values, const size_t size, const GLenum usage)
848{
849 ocean_assert(GL_NO_ERROR == glGetError());
850
851 static_assert(sizeof(GLfloat) * 4 == sizeof(VectorF4), "Invalid data type!");
852
853 glBufferData(target, GLsizeiptr(size * sizeof(GLfloat) * 4), values, usage);
854 ocean_assert(GL_NO_ERROR == glGetError());
855}
856
857template <>
858inline void GLESVertexSet::setBufferData(const GLenum target, const VectorD4* values, const size_t size, const GLenum usage)
859{
860 ocean_assert(GL_NO_ERROR == glGetError());
861
862 std::vector<float> floatValues(size * 4);
863
864 for (size_t n = 0; n < size; n++)
865 {
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]);
870 }
871
872 static_assert(sizeof(GLfloat) * 4 == sizeof(VectorF4), "Invalid data type!");
873
874 glBufferData(target, GLsizeiptr(size * sizeof(GLfloat) * 4), floatValues.data(), usage);
875 ocean_assert(GL_NO_ERROR == glGetError());
876}
877
878template <>
879inline void GLESVertexSet::setBufferData(const GLenum target, const VectorT4<uint16_t>* values, const size_t size, const GLenum usage) // **TODO** use template parameters to remove functions above
880{
881 ocean_assert(GL_NO_ERROR == glGetError());
882
883 static_assert(sizeof(GLushort) * 4 == sizeof(VectorT4<uint16_t>), "Invalid data type!");
884
885 glBufferData(target, GLsizeiptr(size * sizeof(GLushort) * 4), values, usage);
886 ocean_assert(GL_NO_ERROR == glGetError());
887}
888
889template <>
890inline void GLESVertexSet::setBufferData(const GLenum target, const VectorT4<uint32_t>* values, const size_t size, const GLenum usage) // **TODO** use template parameters to remove functions above
891{
892 ocean_assert(GL_NO_ERROR == glGetError());
893
894 static_assert(sizeof(GLuint) * 4 == sizeof(VectorT4<uint32_t>), "Invalid data type!");
895
896 glBufferData(target, GLsizeiptr(size * sizeof(GLuint) * 4), values, usage);
897 ocean_assert(GL_NO_ERROR == glGetError());
898}
899
900template <typename T>
901void GLESVertexSet::setBufferData(const GLenum /*target*/, const T* /*values*/, const size_t /*size*/, const GLenum /*usage*/)
902{
903 ocean_assert(false && "Missing implementation!");
904}
905
906}
907
908}
909
910}
911
912#endif // META_OCEAN_RENDERING_GLES_VERTEX_SET_H
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