Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
TVertexArray.h
Go to the documentation of this file.
1#pragma once
2#include "Matrix.h"
3
4#include <QOpenGLBuffer>
5#include <QOpenGLTexture>
6#include <misc/gen/TVector.h>
7#include <xgl/ShaderProgram.h>
8#include <xgl/Types.h>
10
11namespace sf::xgl
12{
13
18template<VertexArrayBase::VertexMember VertexMembers>
20{
21 public:
27
31 ~TVertexArray() override;
32
38
43 void draw() final;
44
49 void paint() final;
50
54 bool hasColor() const final;
55
59 bool hasTexture() const final;
60
65 void setTexture(QOpenGLTexture* texture);
66
71
75 void clearData() override;
76
77 protected:
81 bool setup() override;
82
87
95 template<typename VertexType, typename FieldType>
96 void setAttribPointer(ShaderProgram::Attribute sa, size_t offset);
97
101 typedef struct
102 {
104 } VT_Position;
108 typedef struct
109 {
111 Color color{0.7, 0.7, 0.7, 0.3};
112 } VT_PositionColor;
132 typedef struct
133 {
137 } VT_PositionNormalColor;
161 using Vertex = std::conditional_t<
162 VertexMembers == vmPosition, VT_Position,
163 std::conditional_t<
164 VertexMembers == (vmPosition | vmColor), VT_PositionColor,
165 std::conditional_t<
166 VertexMembers == (vmPosition | vmNormal), VT_PositionNormal,
167 std::conditional_t<
168 VertexMembers == (vmPosition | vmNormal | vmColor), VT_PositionNormalColor,
169 std::conditional_t<
170 VertexMembers == (vmPosition | vmTexCoord), VT_PositionTexture,
171 std::conditional_t<
173 std::conditional_t<
175 // Ought not to happen but a type is required.
176 void>>>>>>>;
185 {
189 GLenum mode;
193 size_t stop;
197 size_t start{std::numeric_limits<size_t>::max()};
202 Color color{0.0f, 0.0f, 0.0f, 0.0f};
211 };
212
217
222
227
235 void callModifyContext(const ModeRange& mr, bool before, bool draw, size_t mode_index);
236
241 bool checkData() const;
242
243 private:
247 ShaderProgram* _shaderProgram;
251 struct
252 {
256 QOpenGLBuffer vbo{QOpenGLBuffer::VertexBuffer};
260 QOpenGLBuffer ebo{QOpenGLBuffer::IndexBuffer};
261 } _buffers;
265 QOpenGLTexture* _texture{nullptr};
266};
267
268}// namespace sf::xgl
269
270// Include all inlined functions and template implementations.
271#include <xgl/TVertexArray.hpp>
Counted vector having additional methods and operators for ease of usage.
Definition TVector.h:25
Color class used in vertex arrays and has layout of 4 x GLfloat.
Definition Color.h:15
A 4x4 matrix class used in arrays and has layout of 16x GLfloat.
Definition Matrix.h:15
Shader program having a default vertex and fragment shader.
Definition ShaderProgram.h:13
OpenGL base class and wrapper template for vertex arrays. Automates most of the things needed for pri...
Definition TVertexArray.h:20
TVector< Vertex > _vertices
Holds the data of the vertices before being copied to OpenGL memory.
Definition TVertexArray.h:180
bool setup() override
Sets up the vertex array for the OpenGL context.
void setupLayout()
Sets up the layout of the Vertex structure for OpenGL.
void paint() final
Overridden from base class VertexArrayBase. Uses old style OpenGL without a shader program.
~TVertexArray() override
Virtual destructor.
void draw() final
Overridden from base class VertexArrayBase. Uses new style OpenGL with a shader program.
TVertexArray(ShaderProgram *sp)
Constructor.
ShaderProgram * shaderProgram()
Gets the associated shader program.
void callModifyContext(const ModeRange &mr, bool before, bool draw, size_t mode_index)
Calls the function modifyContext when overridden.
void clearData() override
Clears the data to generate array buffers.
QOpenGLBuffer vbo
Holds the vertex buffer object.
Definition TVertexArray.h:256
void setTexture(QOpenGLTexture *texture)
Assigns the texture.
bool hasTexture() const final
Overridden from base class VertexArrayBase.
std::conditional_t< VertexMembers==vmPosition, VT_Position, std::conditional_t< VertexMembers==(vmPosition|vmColor), VT_PositionColor, std::conditional_t< VertexMembers==(vmPosition|vmNormal), VT_PositionNormal, std::conditional_t< VertexMembers==(vmPosition|vmNormal|vmColor), VT_PositionNormalColor, std::conditional_t< VertexMembers==(vmPosition|vmTexCoord), VT_PositionTexture, std::conditional_t< VertexMembers==(vmPosition|vmNormal|vmTexCoord), VT_PositionNormalTexture, std::conditional_t< VertexMembers==(vmPosition|vmNormal|vmColor|vmTexCoord), VT_PositionNormalColorTexture, void > > > > > > > Vertex
Conditional vertex structure type. Used for memory locations.
Definition TVertexArray.h:176
TVector< GLuint > IndexVectorType
Type definition for storing indices.
Definition TVertexArray.h:216
bool checkData() const
Check the data integrity of indices to vertices,.
bool hasColor() const final
Overridden from base class VertexArrayBase.
IndexVectorType _indices
Holds the data of the indices for solid and wire drawing.
Definition TVertexArray.h:221
TVector< ModeRange > _modes
Modes to call glDrawArrays() or glDrawElements() depending on the _indices member not being empty.
Definition TVertexArray.h:226
void setAttribPointer(ShaderProgram::Attribute sa, size_t offset)
Makes a call to setVertexAttribPointer().
NormalsDataType getNormalsData() const override
Overridden from base class.
QOpenGLBuffer ebo
Holds the index buffer object for solid drawing.
Definition TVertexArray.h:260
Base class for Vertex array derived classes.
Definition VertexArrayBase.h:14
@ vmTexCoord
Definition VertexArrayBase.h:36
@ vmColor
Definition VertexArrayBase.h:34
@ vmPosition
Definition VertexArrayBase.h:30
@ vmNormal
Definition VertexArrayBase.h:32
static const Color & getDefaultColor()
Gets the default color used by the vertex structures when not set by the derived class....
Definition DemoRenderer.h:6
QFlags< ECullingFlag > CullingState
Type to contain bitmapped culling settings.
Definition Types.h:61
@ cfBackside
Definition Types.h:54
@ cfDisabled
Definition Types.h:46
@ cfCCW
Definition Types.h:50
std::array< GLfloat, 2 > vector2f
Type which correspond with a GLSL type and used to implement Vertex structures.
Definition Types.h:17
std::array< GLfloat, 3 > vector3f
Type which correspond with a GLSL type and used to implement Vertex structures.
Definition Types.h:21
Modes to be called on the available indices.
Definition TVertexArray.h:185
Matrix matrix
Matrix set before rendering.
Definition TVertexArray.h:206
size_t stop
Stop index of the indices that belong to this mode.
Definition TVertexArray.h:193
GLenum mode
Mode to call glDrawArrays() with to get a wire model.
Definition TVertexArray.h:189
Color color
Color set before rendering. Only set when not (0,0,0,0).
Definition TVertexArray.h:202
size_t start
Start index of the indices that belong to this mode.
Definition TVertexArray.h:197
CullingState culling
Required culling state.
Definition TVertexArray.h:210
Available structure for a typical selection of members.
Definition TVertexArray.h:109
vector3f position
Definition TVertexArray.h:110
Available structure for a typical selection of members.
Definition TVertexArray.h:151
vector3f normal
Definition TVertexArray.h:153
vector2f texture
Definition TVertexArray.h:155
vector3f position
Definition TVertexArray.h:152
Available structure for a typical selection of members.
Definition TVertexArray.h:133
vector3f normal
Definition TVertexArray.h:135
vector3f position
Definition TVertexArray.h:134
Available structure for a typical selection of members.
Definition TVertexArray.h:142
vector2f texture
Definition TVertexArray.h:145
vector3f normal
Definition TVertexArray.h:144
vector3f position
Definition TVertexArray.h:143
Available structure for a typical selection of members.
Definition TVertexArray.h:117
vector3f position
Definition TVertexArray.h:118
vector3f normal
Definition TVertexArray.h:119
Available structure for a typical selection of members.
Definition TVertexArray.h:125
vector3f position
Definition TVertexArray.h:126
vector2f texture
Definition TVertexArray.h:127
Available structure for a typical selection of members.
Definition TVertexArray.h:102
vector3f position
Definition TVertexArray.h:103