xoreos  0.0.5
renderqueue.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef GRAPHICS_RENDER_RENDERQUEUE_H
26 #define GRAPHICS_RENDER_RENDERQUEUE_H
27 
28 #include "glm/vec3.hpp"
29 #include "glm/mat4x4.hpp"
30 
31 #include "src/graphics/graphics.h"
33 
34 #include <vector>
35 
36 namespace Graphics {
37 
38 namespace Render {
39 
40 class RenderQueue {
41 public:
42  struct RenderQueueNode {
47  const glm::mat4 *transform;
48  float reference;
49  float alpha;
50 
51  RenderQueueNode() : program(0), surface(0), material(0), mesh(0), transform(0), reference(0.0f), alpha(1.0f) {}
53  RenderQueueNode(Shader::ShaderProgram *prog, Shader::ShaderSurface *sur, Shader::ShaderMaterial *mat, Mesh::Mesh *mes, const glm::mat4 *t, float a = 1.0f, float ref = 0.0f) : program(prog), surface(sur), material(mat), mesh(mes), transform(t), reference(ref), alpha(a) {}
54 
55  inline const RenderQueueNode &operator=(const RenderQueueNode &src) { program = src.program; material = src.material; surface = src.surface; mesh = src.mesh; transform = src.transform; reference = src.reference; alpha = src.alpha; return *this; }
56  };
57 
58  RenderQueue(uint32 precache = 1000);
59  ~RenderQueue();
60 
61  void setCameraReference(const glm::vec3 &reference);
62 
63  void queueItem(Shader::ShaderProgram *program, Shader::ShaderSurface *surface, Shader::ShaderMaterial *material, Mesh::Mesh *mesh, const glm::mat4 *transform, float alpha);
64  void queueItem(Shader::ShaderRenderable *renderable, const glm::mat4 *transform, float alpha);
65 
66  void sortShader();
67  void sortDepth();
68 
69  void render();
70 
71  void clear();
72 
73 private:
74 
75  std::vector<RenderQueueNode>_nodeArray;
76  glm::vec3 _cameraReference;
77 };
78 
79 } // namespace Render
80 
81 } // namespace Graphics
82 
83 #endif // GRAPHICS_RENDER_RENDERQUEUE
The global graphics manager.
Shader renderable, a class for easier managing of a collection of items (surface, material...
void clear()
Clear the queue of all items.
float reference
Reference point to the camera location, primarily used for depth sorting.
Definition: renderqueue.h:48
const RenderQueueNode & operator=(const RenderQueueNode &src)
Definition: renderqueue.h:55
void sortShader()
Sort queue elements by shader program.
Definition: renderqueue.cpp:92
RenderQueue(uint32 precache=1000)
Definition: renderqueue.cpp:58
void queueItem(Shader::ShaderProgram *program, Shader::ShaderSurface *surface, Shader::ShaderMaterial *material, Mesh::Mesh *mesh, const glm::mat4 *transform, float alpha)
Definition: renderqueue.cpp:71
RenderQueueNode(Shader::ShaderProgram *prog, Shader::ShaderSurface *sur, Shader::ShaderMaterial *mat, Mesh::Mesh *mes, const glm::mat4 *t, float a=1.0f, float ref=0.0f)
Definition: renderqueue.h:53
void sortDepth()
Sort queue elements by depth.
Definition: renderqueue.cpp:98
uint32_t uint32
Definition: types.h:204
std::vector< RenderQueueNode > _nodeArray
Definition: renderqueue.h:75
float alpha
Custom alpha value applied per-object.
Definition: renderqueue.h:49
RenderQueueNode(const RenderQueueNode &src)
Definition: renderqueue.h:52
void render()
Render all queued items.
void setCameraReference(const glm::vec3 &reference)
Definition: renderqueue.cpp:67