VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
DebugRenderer.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef DEBUGRENDERER_H
18 #define DEBUGRENDERER_H
19 
20 #include "RendererCommon.h"
21 #include <vector>
22 
37 public:
41  DebugRenderer();
42  ~DebugRenderer();
43 
48  const Matrix4& getProjectionMatrix() const { return mProjectionMatrix; }
58  void setProjectionMatrix(const Matrix4& matrix);
59 
66  void queueLine(const Vector2& pos1, const Vector2& pos2, unsigned int colorRgba);
73  void queuePolygon(const Vector2* points, int count, unsigned int colorRgba);
81  void queueFilledPolygon(const Vector2* points, int count, unsigned int colorRgba);
89  void queueCircle(const Vector2& center, float radius, int segments, unsigned int colorRgba);
97  void queueFilledCircle(const Vector2& center, float radius, int segments,
98  unsigned int colorRgba);
99 
106  void flush();
121  void render();
122 private:
123  struct DebugVertex {
124  Vector2 position = Vector2(0.0f, 0.0f);
125  unsigned int color = 0x00000000;
126  };
127  struct DebugDraw {
128  int count = 0;
129  GLuint mode = GL_LINES;
130  };
131 
132  DebugVertex* allocateVertices(int count, GLuint mode);
133  void flushCurrentDraw();
134  void createShader();
135  Vector2 transformVertex(const Vector2& point);
136 
137  Matrix4 mProjectionMatrix = {
138  1.0f, 0.0f, 0.0f, 0.0f,
139  0.0f, 1.0f, 0.0f, 0.0f,
140  0.0f, 0.0f, 1.0f, 0.0f,
141  0.0f, 0.0f, 0.0f, 1.0f };
142  bool mHasCurrentDraw = false;
143  DebugDraw mCurrentDraw;
144  std::vector<DebugVertex> mVertexBuffer;
145  std::vector<DebugDraw> mDrawList;
146  std::vector<DebugVertex> mRenderVertexBuffer;
147  std::vector<DebugDraw> mRenderDrawList;
148  MeshPtr mRenderMesh;
149  MeshInstancePtr mRenderMeshInstance;
150 };
151 
152 #endif // DEBUGRENDERER_H
Header declaring and including types common to renderer classes such as Vector2. Also includes GL hea...
A class with helper methods for rendering primitives like lines, for debug visualization.
Definition: DebugRenderer.h:36
float Matrix4[16]
4x4 float matrix, whose layout is compatible with GL.
Definition: RendererCommon.h:46
const Matrix4 & getProjectionMatrix() const
Gets the current projection matrix.
Definition: DebugRenderer.h:48
void flush()
Flushes the current shape being queued, preventing additional vertices from getting added to that dra...
void queueCircle(const Vector2 &center, float radius, int segments, unsigned int colorRgba)
Queues a circle centered about a point.
void queuePolygon(const Vector2 *points, int count, unsigned int colorRgba)
Queue a colored polygon line.
void queueLine(const Vector2 &pos1, const Vector2 &pos2, unsigned int colorRgba)
Queue a colored line segment.
void synchronizeForRendering()
Flips double buffered data, and clears the current queue.
b2Vec2 Vector2
2D float vector, whose layout is compatible with GL.
Definition: RendererCommon.h:50
void render()
Renders draw calls in the render queue.
void setProjectionMatrix(const Matrix4 &matrix)
Sets the current projection matrix.
DebugRenderer()
Constructs a DebugRenderer.
std::shared_ptr< MeshInstance > MeshInstancePtr
Shared pointer typedef for MeshInstance.
Definition: PointerDeclarations.h:113
std::shared_ptr< Mesh > MeshPtr
Shared pointer typedef for Mesh.
Definition: PointerDeclarations.h:103
void queueFilledCircle(const Vector2 &center, float radius, int segments, unsigned int colorRgba)
Queues a filled circle centered about a point.
void queueFilledPolygon(const Vector2 *points, int count, unsigned int colorRgba)
Queue a filled convex polygon shape.