Stellarium  0.90.0
StelOpenGLArray.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2016 Florian Schaukowitsch
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELOPENGLARRAY_HPP_
21 #define _STELOPENGLARRAY_HPP_
22 
23 #include "VecMath.hpp"
24 
25 #include <QLoggingCategory>
26 #include <QOpenGLBuffer>
27 #include <QOpenGLFunctions>
28 #include <QOpenGLVertexArrayObject>
29 #include <QVector>
30 
31 class StelOBJ;
32 class QOpenGLFunctions;
33 
34 Q_DECLARE_LOGGING_CATEGORY(stelOpenGLArray)
35 
36 class StelOpenGLArray
41 {
42 public:
47  {
60  ATTLOC_SIZE
61  };
62 
65  StelOpenGLArray();
67  ~StelOpenGLArray();
68 
70  void clear();
71 
82  bool load(const StelOBJ* obj, bool useTangents = true);
83 
86  void bind();
89  void release();
90 
93  inline void draw() const
94  {
95  draw(0,m_indexCount);
96  }
99  inline void draw(int offset, int count) const
100  {
101  gl->glDrawElements(GL_TRIANGLES, count, m_indexBufferType, reinterpret_cast<const GLvoid*>(offset * m_indexBufferTypeSize));
102  }
103 
105  const QOpenGLBuffer& getVertexBuffer() const { return m_vertexBuffer; }
107  const QOpenGLBuffer& getIndexBuffer() const { return m_indexBuffer; }
109  const QOpenGLVertexArrayObject& getVAO() const { return m_vao; }
110 
114  GLenum getIndexBufferType() const { return m_indexBufferType; }
116  size_t getIndexBufferTypeSize() const { return m_indexBufferTypeSize; }
118  int getIndexCount() const { return m_indexCount; }
119 
121  static void initGL();
127  static bool supportsVertexArrayObject() { return s_vaosSupported; }
130  static bool supportsIntegerElementIndex() { return s_intElementBuffersSupported; }
131 private:
132  QOpenGLBuffer m_vertexBuffer;
133  QOpenGLBuffer m_indexBuffer;
134  QOpenGLVertexArrayObject m_vao;
135  GLenum m_indexBufferType;
136  size_t m_indexBufferTypeSize;
137  int m_indexCount;
138  size_t m_memoryUsage;
139 
140  quintptr m_offsets[ATTLOC_SIZE];
141  GLint m_sizes[ATTLOC_SIZE];
142  GLenum m_types[ATTLOC_SIZE];
143  GLsizei m_strides[ATTLOC_SIZE];
144 
145  void bindBuffers();
146  void releaseBuffers();
147 
148  static QOpenGLFunctions* gl;
149  static bool s_vaosSupported;
150  static bool s_intElementBuffersSupported;
151 };
152 
153 #endif // _STELOPENGLARRAY_HPP_
const QOpenGLBuffer & getVertexBuffer() const
Returns the buffer used for the vertex data.
void draw(int offset, int count) const
Issues a glDrawElements call for the count indices starting at offset Does not bind the array first...
This is the OpenGL attribute location where 3D vertex normals are mapped to.
Encapsulates vertex data stored in the OpenGL server memory, which can be used for fast drawing comma...
This is the OpenGL attribute location where vertex tangents are mapped to.
size_t getIndexBufferTypeSize() const
Returns the size in bytes for the type from getIndexBufferType()
const QOpenGLVertexArrayObject & getVAO() const
Returns the VAO which is used, when possible.
int getIndexCount() const
Returns the number of indices stored in this array.
This is the OpenGL attribute location where 2D vertex texture coordinates are mapped to...
This is the OpenGL attribute location where vertex bitangents are mapped to.
AttributeLocation
Specifies the attribute location used for the glVertexAttribPointer calls.
static bool supportsVertexArrayObject()
Returns true if the hardware supports use of vertex array objects.
Representation of a custom subset of a Wavefront .obj file, including only triangle data and material...
Definition: StelOBJ.hpp:37
GLenum getIndexBufferType() const
Returns the type used for element index data in this instance.
This is the OpenGL attribute location where 3D vertex positions are mapped to.
const QOpenGLBuffer & getIndexBuffer() const
Returns the buffer used for the element index data.
void draw() const
Issues a glDrawElements call for all indices stored in this array.
static bool supportsIntegerElementIndex()
Returns true if the hardware supports use of (unsigned) integer element indices, instead of just byte...