GlobeEngine
DrawableComponent.h
Go to the documentation of this file.
1 
8 #ifndef GlobeEngine_DrawableComponent_h
9 #define GlobeEngine_DrawableComponent_h
10 
11 #include "OpenGL_Includes.h"
12 #include "GlobeComponent.h"
13 #include "BoundingBox.h"
14 #include "BoundingSphere.h"
15 #include "Shader.h"
16 #include "Buffer.h"
17 #include "BufferArray.h"
18 #include "VertexArrayObject.h"
19 #include <vmmlib/vmmlib.hpp>
20 
21 class Camera;
22 
23 namespace ge {
24 
26  {
27  public:
29 
30  public:
33  DrawableComponent(const DrawableComponent& _in) = delete;
34  DrawableComponent& operator=(const DrawableComponent& _in) = delete;
35 
36  virtual void clear();
37  virtual void draw(std::shared_ptr<ge::Camera> _cam);
38  virtual void setPosition(vmml::Vector3d _position);
39  vmml::Vector3d getPosition() const;
40  virtual void setScale(vmml::Vector3d _scale);
41  vmml::Vector3d getScale() const;
42  virtual void setRotation(vmml::Vector3d _rotations);
43  vmml::Vector3d getRotation() const;
44 
45  void setBoundingSphere(BoundingSphere _boundingSphere);
46  void setBoundingBox(BoundingBox3d _boundingBox);
47  const BoundingSphere* getBoundingSphere() const;
48  const BoundingBox3d* getBoundingBox() const;
49  bool isVisible() const;
50  virtual void isVisible(bool _input);
51  bool isGeometryReady() const;
52  virtual void isGeometryReady(bool _input);
53 
54  virtual void setColor(vmml::Vector3f _color);
55  const vmml::Vector3f getColor() const;
56 
57  virtual void setColorPerVertex(unsigned int _in){
58  this->colorPerVertex = _in;
59  };
60  unsigned int getColorPerVertex() const {
61  return this->colorPerVertex;
62  }
63 
64  void setTextured(bool _in);
65  bool isTextured();
66  void setTextureHandle(GLuint _handle);
67  GLuint getTextureHandle() const;
68 
69  void setNormalTextureHandle(GLuint _handle);
70  GLuint getNormalTextureHandle() const;
71  void setNormalMapped(bool _in);
72  bool isNormalMapped();
73 
74  virtual void setShader(std::shared_ptr<ge::Shader> _shader);
75  void setStandardUniforms();
76  const std::shared_ptr<ge::Shader> getShader() const;
77  // only use this if you what you are doing. :)
78  void recompileShader();
79 
80  void setNormalMatrix();
81  void setModelMatrices();
82  vmml::Matrix4d getModelMatrix() const;
83  vmml::Matrix4d getInverseModelMatrix() const;
84  void setViewProjMatrices(const std::shared_ptr<ge::Camera> _cam);
85  void setMVPMatrix(const std::shared_ptr<ge::Camera> _cam);
86 
87  virtual void enableOcclusionQueries(bool _in);
88 #if defined(GENGINE_GL_ES)
89 #else
90  void beginOcclusionQuery(RENDERSTATE _state);
91  void endOcclusionQuery(RENDERSTATE _state);
92  GLuint getQueryResult();
93 
94  /* point sprites */
95  void enablePointSprites();
96  void disablePointSprites();
97 #endif
99 
103  void enableVertexAttributes(int vaaSize = 2);
104  void disableVertexAttributes(int vaaSize = 2);
105  void setNumberOfVertexAttributes(unsigned int _in);
106 
107  void generateVertexHandlesFromShader(int _bufferCount = 0);
108  void setVertexAttributePointer(GLuint _bufferID, GLuint _index, GLint _size, GLenum _type);
109  /* maps attribute values between 0.0 and 1.0 if values are not float */
110  void setVertexAttributePointerNormalized(GLuint _bufferID, GLuint _index, GLint _size, GLenum _type);
111  void setVertexLongAttributePointer(GLuint _bufferID, GLuint _index, GLint _size, GLenum _type);
112 
113  void unbindVertexBuffers();
114 
115  /* copy attribute data */
116  void setAttributeBuffer1i(int _bufferID, int _input);
117  void setAttributeBuffer1i(int _bufferID, std::vector<int> _input);
118  void setAttributeBuffer1f(int _bufferID, float _value);
119  void setAttributeBuffer1f(int _bufferID, std::vector<float> _input);
120  void addVertex3fAttribute(unsigned int _bufferPos, unsigned int _size, const vmml::Vector3d _value);
121  void addVertex3fAttribute(unsigned int _bufferPos, unsigned int _size, const vmml::Vector3d* _values);
122  void addCustomVertexAttributef(unsigned int _bufferPos, unsigned int _attributeCount, unsigned int _sizePerAttribute, float** _values);
123 
124  /* shadow map */
125  void setDepthMatrix(vmml::Matrix4d _mat);
126  void setDepthMatrixUniform();
127  void setDepthTextureHandle(GLuint _handle);
128  //void setDepthTextureHandleUniform();
129  void setDepthUniforms();
130  GLuint getDepthTextureHandle() const;
131 
132  /* set picking shader information */
133  void setPickingInformation();
134 
135  /* For multidraw components */
136  void createMultiDrawPointerList(GLuint _numberOfDrawObjects, GLsizei* _stripLenghts);
137  void createMultiDrawPointerList(GLuint _numberOfDrawObjects, GLsizei _stripLenghts);
138  void drawMultiElements(GLenum _mode, const GLsizei* _count, GLsizei _drawcount);
139 
140  void drawArrays(GLenum _mode, GLint _first, GLsizei _count);
141  void drawElements(GLenum _mode, GLsizei _count, const GLvoid * _indices);
142  void drawMultiArrays(GLenum _mode, const GLsizei* _count, GLsizei _drawcount);
143 
144  /* primitive restart */
145  void enablePrimitiveRestart();
147  void setPrimitiveRestartIndex(GLuint _in);
148 
149  unsigned int getVertexCount() const { return vertexCount; }
150 
151  void setVertexAttributePointerForBuffer(unsigned int _bufferID, unsigned int _size, GLenum _type);
152 
153  private:
154  void clearInitial();
155  void deleteMemory();
156 
157  private:
158  bool visible;
159  bool geometryready;
160 
161  protected:
162  std::shared_ptr<ge::Shader> shader;
163  vmml::Vector3d position;
164  vmml::Vector3d scale;
165  vmml::Vector3d rotations;
166  vmml::Vector3f color;
167  unsigned int colorPerVertex; //per object, per Vertex
168 
169  // texture stuff
170  bool textured;
174 
177 
178  // Matrix information
179  vmml::Matrix4d modelMatrix;
180  vmml::Matrix4d mvpMatrix;
181  vmml::Matrix3d normalMatrix;
182 
183  // Shadow
184  vmml::Matrix4d depthTextureMatrix;
186 
187  // Rendering structs
190  //GLuint* bufferHandles;
191 
192  // vertex information
193  GLuint vertexCount;
194 
195  // index structs
196  GLuint indexCount;
198 
200  const GLvoid** multiDrawPointerList;
202 
203  /* Hardware occlusion queries
204  * 0 = no query requested
205  * 1 = query requested
206  * 2 = glBeginQuery called
207  * 3 = wait for result
208  * 4 = result ready, query deleted
209  */
213 
214  // Uniform locations
219 
224  };
225 }
226 #endif
Definition: DrawableComponent.h:25
vmml::Matrix4d depthTextureMatrix
Definition: DrawableComponent.h:184
unsigned int getVertexCount() const
Definition: DrawableComponent.h:149
void addVertex3fAttribute(unsigned int _bufferPos, unsigned int _size, const vmml::Vector3d _value)
Definition: DrawableComponent.cpp:456
GLuint occlusionQueryID
Definition: DrawableComponent.h:211
GLint uniformColorPerVertexLocation
Definition: DrawableComponent.h:221
vmml::Matrix4d mvpMatrix
Definition: DrawableComponent.h:180
void setNumberOfVertexAttributes(unsigned int _in)
bool isNormalMapped()
Definition: DrawableComponent.cpp:677
Definition: BoundingBox.h:15
GLuint getNormalTextureHandle() const
Definition: DrawableComponent.cpp:669
void setBoundingSphere(BoundingSphere _boundingSphere)
void setStandardUniforms()
Definition: DrawableComponent.cpp:169
void createMultiDrawPointerList(GLuint _numberOfDrawObjects, GLsizei *_stripLenghts)
Definition: DrawableComponent.cpp:503
ge::IndexBuffer indexBuffer
Definition: DrawableComponent.h:197
void endOcclusionQuery(RENDERSTATE _state)
Definition: DrawableComponent.cpp:309
GLuint normalTexHandle
Definition: DrawableComponent.h:173
void setDepthMatrix(vmml::Matrix4d _mat)
Definition: DrawableComponent.cpp:613
void setNormalMatrix()
Definition: DrawableComponent.cpp:240
vmml::Matrix4d modelMatrix
Definition: DrawableComponent.h:179
~DrawableComponent()
Definition: DrawableComponent.cpp:18
void setVertexAttributePointerForBuffer(unsigned int _bufferID, unsigned int _size, GLenum _type)
Definition: DrawableComponent.cpp:373
DrawableComponent()
Definition: DrawableComponent.cpp:11
bool isVisible() const
Definition: DrawableComponent.cpp:143
unsigned int getColorPerVertex() const
Definition: DrawableComponent.h:60
const BoundingSphere * getBoundingSphere() const
Definition: DrawableComponent.cpp:123
const vmml::Vector3f getColor() const
Definition: DrawableComponent.cpp:158
GLint * multiDrawArraysList
Definition: DrawableComponent.h:201
void setNormalMapped(bool _in)
Definition: DrawableComponent.cpp:673
void recompileShader()
Definition: DrawableComponent.cpp:183
BoundingBox3d * boundingBox
Definition: DrawableComponent.h:176
bool normalMapped
Definition: DrawableComponent.h:172
GLuint vertexCount
Definition: DrawableComponent.h:193
void setVertexAttributePointer(GLuint _bufferID, GLuint _index, GLint _size, GLenum _type)
Definition: DrawableComponent.cpp:355
GLint uniformModelMatrixLocation
Definition: DrawableComponent.h:217
virtual void setColor(vmml::Vector3f _color)
Definition: DrawableComponent.cpp:153
Definition: DrawableComponent.h:28
void setPrimitiveRestartIndex(GLuint _in)
Definition: DrawableComponent.cpp:579
GLint uniformObjectGroupIDLocation
Definition: DrawableComponent.h:223
vmml::Vector3d position
Definition: DrawableComponent.h:163
virtual void draw(std::shared_ptr< ge::Camera > _cam)
Definition: DrawableComponent.cpp:76
vmml::Vector3d scale
Definition: DrawableComponent.h:164
virtual void clear()
Definition: DrawableComponent.cpp:23
bool textured
Definition: DrawableComponent.h:170
GLuint depthTextureHandle
Definition: DrawableComponent.h:185
void setAttributeBuffer1i(int _bufferID, int _input)
Definition: DrawableComponent.cpp:409
void disableVertexAttributes(int vaaSize=2)
Definition: DrawableComponent.cpp:279
Definition: DrawableComponent.h:28
Definition: DrawableComponent.h:28
GLint uniformViewMatrixLocation
Definition: DrawableComponent.h:215
void setTextured(bool _in)
Definition: DrawableComponent.cpp:654
Definition: DrawableComponent.h:28
RENDERSTATE
Definition: DrawableComponent.h:28
ge::VertexBufferArray attributes
Definition: DrawableComponent.h:189
std::shared_ptr< ge::Shader > shader
Definition: DrawableComponent.h:162
GLuint colorTexHandle
Definition: DrawableComponent.h:171
GLint uniformMVPMatrixLocation
Definition: DrawableComponent.h:218
void setMVPMatrix(const std::shared_ptr< ge::Camera > _cam)
Definition: DrawableComponent.cpp:219
Definition: DrawableComponent.h:28
GLuint getQueryResult()
Definition: DrawableComponent.cpp:314
const GLvoid ** multiDrawPointerList
Definition: DrawableComponent.h:200
void disablePointSprites()
Definition: DrawableComponent.cpp:604
void setVertexAttributePointerNormalized(GLuint _bufferID, GLuint _index, GLint _size, GLenum _type)
Definition: DrawableComponent.cpp:361
void setPickingInformation()
Definition: DrawableComponent.cpp:193
void drawMultiElements(GLenum _mode, const GLsizei *_count, GLsizei _drawcount)
Definition: DrawableComponent.cpp:528
void unbindVertexBuffers()
Definition: DrawableComponent.cpp:345
void drawArrays(GLenum _mode, GLint _first, GLsizei _count)
Definition: DrawableComponent.cpp:550
void disablePrimitiveRestart()
Definition: DrawableComponent.cpp:587
bool isGeometryReady() const
Definition: DrawableComponent.cpp:133
GLuint getTextureHandle() const
Definition: DrawableComponent.cpp:650
void drawMultiArrays(GLenum _mode, const GLsizei *_count, GLsizei _drawcount)
Definition: DrawableComponent.cpp:541
virtual void setScale(vmml::Vector3d _scale)
Definition: DrawableComponent.cpp:94
virtual void setColorPerVertex(unsigned int _in)
Definition: DrawableComponent.h:57
DrawableComponent & operator=(const DrawableComponent &_in)=delete
GLuint queryResultPixelCount
Definition: DrawableComponent.h:212
void setModelMatrices()
Definition: DrawableComponent.cpp:229
vmml::Vector3d getScale() const
Definition: DrawableComponent.cpp:102
Definition: GlobeComponent.h:15
bool isTextured()
Definition: DrawableComponent.cpp:658
virtual void setShader(std::shared_ptr< ge::Shader > _shader)
Definition: DrawableComponent.cpp:163
vmml::Matrix4d getModelMatrix() const
Definition: DrawableComponent.cpp:248
void beginOcclusionQuery(RENDERSTATE _state)
Definition: DrawableComponent.cpp:303
void enablePointSprites()
Definition: DrawableComponent.cpp:594
void setVertexLongAttributePointer(GLuint _bufferID, GLuint _index, GLint _size, GLenum _type)
Definition: DrawableComponent.cpp:367
void enablePrimitiveRestart()
Definition: DrawableComponent.cpp:583
virtual void setPosition(vmml::Vector3d _position)
Definition: DrawableComponent.cpp:81
vmml::Vector3d getRotation() const
Definition: DrawableComponent.cpp:118
unsigned int colorPerVertex
Definition: DrawableComponent.h:167
GLint uniformObjectIDLocation
Definition: DrawableComponent.h:222
Definition: AvalancheTrainingSimulationEngine.h:28
void drawElements(GLenum _mode, GLsizei _count, const GLvoid *_indices)
Definition: DrawableComponent.cpp:561
GLuint getDepthTextureHandle() const
Definition: DrawableComponent.cpp:629
GLint uniformObjectColorLocation
Definition: DrawableComponent.h:220
vmml::Vector3d getPosition() const
Definition: DrawableComponent.cpp:89
virtual void setRotation(vmml::Vector3d _rotations)
Definition: DrawableComponent.cpp:107
vmml::Vector3f color
Definition: DrawableComponent.h:166
vmml::Matrix4d getInverseModelMatrix() const
Definition: DrawableComponent.cpp:252
void setTextureHandle(GLuint _handle)
Definition: DrawableComponent.cpp:643
virtual void enableOcclusionQueries(bool _in)
Definition: DrawableComponent.cpp:291
void generateVertexHandlesFromShader(int _bufferCount=0)
Definition: DrawableComponent.cpp:331
GLuint indexCount
Definition: DrawableComponent.h:196
void setAttributeBuffer1f(int _bufferID, float _value)
Definition: DrawableComponent.cpp:428
const std::shared_ptr< ge::Shader > getShader() const
Definition: DrawableComponent.cpp:188
Definition: VertexArrayObject.h:17
const BoundingBox3d * getBoundingBox() const
Definition: DrawableComponent.cpp:128
void setDepthMatrixUniform()
Definition: DrawableComponent.cpp:617
vmml::Vector3d rotations
Definition: DrawableComponent.h:165
Definition: DrawableComponent.h:28
BoundingSphere * boundingSphere
Definition: DrawableComponent.h:175
GLuint multiDrawPointerListSize
Definition: DrawableComponent.h:199
void setDepthTextureHandle(GLuint _handle)
Definition: DrawableComponent.cpp:625
ge::VertexArrayObject vao
Definition: DrawableComponent.h:188
void addCustomVertexAttributef(unsigned int _bufferPos, unsigned int _attributeCount, unsigned int _sizePerAttribute, float **_values)
Definition: DrawableComponent.cpp:486
GLuint occlusionQueryState
Definition: DrawableComponent.h:210
void setViewProjMatrices(const std::shared_ptr< ge::Camera > _cam)
Definition: DrawableComponent.cpp:205
void setDepthUniforms()
Definition: DrawableComponent.cpp:637
void fillIndexBufferWithLinearValues()
Definition: DrawableComponent.cpp:391
void setBoundingBox(BoundingBox3d _boundingBox)
Definition: DrawableComponent.h:28
vmml::Matrix3d normalMatrix
Definition: DrawableComponent.h:181
void setNormalTextureHandle(GLuint _handle)
Definition: DrawableComponent.cpp:662
GLint uniformProjectionMatrixLocation
Definition: DrawableComponent.h:216
void enableVertexAttributes(int vaaSize=2)
Definition: DrawableComponent.cpp:263
Definition: DrawableComponent.h:28
Definition: BoundingSphere.h:19