File: GLVertexFormat.h

package info (click to toggle)
jazz2-native 3.5.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 16,912 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (125 lines) | stat: -rw-r--r-- 2,878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once

#ifndef DOXYGEN_GENERATING_OUTPUT
#define NCINE_INCLUDE_OPENGL
#include "../../CommonHeaders.h"
#endif

#include <Containers/SmallVector.h>

using namespace Death::Containers;

namespace nCine
{
	class GLBufferObject;

	/// Collects all the state that specifies the format of a vertex
	class GLVertexFormat
	{
	public:
		/// The minimum value for `GL_MAX_VERTEX_ATTRIBS`
		static constexpr std::uint32_t MaxAttributes = 16;

		/// Vertex format attribute
		class Attribute
		{
			friend class GLVertexFormat;

		public:
			Attribute();

			void Init(std::uint32_t index, GLint size, GLenum type);
			bool operator==(const Attribute& other) const;
			bool operator!=(const Attribute& other) const;

			inline bool IsEnabled() const {
				return enabled_;
			}
			inline const GLBufferObject* GetVbo() const {
				return vbo_;
			}
			inline std::uint32_t GetIndex() const {
				return index_;
			}
			inline GLint GetSize() const {
				return size_;
			}
			inline GLenum GetType() const {
				return type_;
			}
			inline bool IsNormalized() const {
				return normalized_ == GL_TRUE;
			}
			inline GLsizei GetStride() const {
				return stride_;
			}
			inline const GLvoid* GetPointer() const {
				return pointer_;
			}
			inline std::uint32_t GetBaseOffset() const {
				return baseOffset_;
			}

			void SetVboParameters(GLsizei stride, const GLvoid* pointer);
			inline void setVbo(const GLBufferObject* vbo) {
				vbo_ = vbo;
			}
			inline void SetBaseOffset(std::uint32_t baseOffset) {
				baseOffset_ = baseOffset;
			}

			inline void SetSize(GLint size) {
				size_ = size;
			}
			inline void SetType(GLenum type) {
				type_ = type;
			}
			inline void SetNormalized(bool normalized) {
				normalized_ = normalized;
			}

		private:
			bool enabled_;
			const GLBufferObject* vbo_;
			std::uint32_t index_;
			GLint size_;
			GLenum type_;
			GLboolean normalized_;
			GLsizei stride_;
			const GLvoid* pointer_;
			/// Used to simulate missing `glDrawElementsBaseVertex()` on OpenGL ES 3.0
			std::uint32_t baseOffset_;
		};

		GLVertexFormat();
		GLVertexFormat(const GLVertexFormat& other) = default;
		GLVertexFormat& operator=(const nCine::GLVertexFormat& other) = default;

		inline std::uint32_t GetAttributeCount() const {
			return std::uint32_t(attributes_.size());
		}

		inline const GLBufferObject* GetIbo() const {
			return ibo_;
		}
		inline void SetIbo(const GLBufferObject* ibo) {
			ibo_ = ibo;
		}
		void Define();
		void Reset();

		inline Attribute& operator[](std::uint32_t index) {
			return attributes_[index];
		}
		inline const Attribute& operator[](std::uint32_t index) const {
			return attributes_[index];
		}

		bool operator==(const GLVertexFormat& other) const;
		bool operator!=(const GLVertexFormat& other) const;

	private:
		SmallVector<Attribute, MaxAttributes> attributes_;
		const GLBufferObject* ibo_;
	};
}