Graphics.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 
34 #ifndef DC_GRAPHICS_INCLUDED
35 #define DC_GRAPHICS_INCLUDED
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 #include <Dynacoe/Util/Chain.h>
47 #include <Dynacoe/Color.h>
48 #include <Dynacoe/Image.h>
49 #include <Dynacoe/Particle.h>
50 
51 #include <Dynacoe/Modules/Assets.h>
52 #include <Dynacoe/Components/Render2D.h>
53 #include <Dynacoe/Components/RenderMesh.h>
54 #include <Dynacoe/Camera.h>
55 
56 #include <string>
57 #include <iostream>
58 #include <fstream>
59 #include <map>
60 
61 
62 
63 
64 
65 namespace Dynacoe {
66 class Assets;
67 class Renderer;
68 
69 
70 
71 
72 
73 
74 
75 
76 
86 class Graphics : public Module {
87  public:
88 
89 
90 
91  /* Drawing */
100 
101 
104  static void Draw(Render2D &);
105 
106 
107 
109 
110 
116 
119  static void Draw( RenderMesh &);
120 
122 
123 
124 
131 
135  static void Commit();
136 
137 
138 
141  static void DrawEachFrame(bool doIt);
142 
145  static bool DrawEachFrame();
147 
148 
149 
150 
151 
152 
153 
158  static Renderer * GetRenderer();
159 
165  static void SetRenderer(Renderer *);
166 
167 
168 
169 
170 
171 
172 
173 
174 
182 
184 
188  static void EnableFiltering(bool doIt);
189 
190 
191 
192 
193 
194 
198  static void SetCamera3D(Camera &);
199 
203  static void SetCamera2D(Camera &);
204 
208  static void SetRenderCamera(Camera &);
209 
213  static Camera & GetCamera3D();
214  static Camera & GetCamera2D();
215  static Camera & GetRenderCamera();
217 
218 
219  private:
220  friend class Assets;
221  friend class GraphicsResizeCallback;
222  friend class Image;
223 
224  static Renderer * drawBuffer;
225 
226 
227 
228  /* Drawing state and display management */
229  static void setDisplayMode(Renderer::Polygon p, Renderer::Dimension, Renderer::AlphaRule a);
230 
231  // draw immediates
232  static float * transformResult;
233  static float * transformResult2;
234  static float * quadVertices2D;
235 
236 
237 
238 
239 
240  //Identical to coebeefSys function of the same name.
241  //internal use onlyx
242 
243  static AssetID fontID;
244 
245 
246  // Initializes a new particle as a copy of a cached particle
247  static bool autoRefresh;
248 
249  static int filter;
250 
251  static AssetID lastDisplayID;
252 
253 
254  friend class Aspect3D;
255  friend class Material;
256 
257 
258  static void storeFont();
259 
260  static Image * errorImage;
261  static std::vector<int> consoleTextures;
262 
263 
264 
265  struct GraphicsState {
266  Renderer::Dimension dim;
267  Renderer::Polygon polygon;
268  Renderer::AlphaRule alpha;
269 
270 
271 
272  Entity::ID currentCamera3D;
273  Entity::ID currentCamera2D;
274  Entity::ID currentCameraTarget;
275  };
276 
277  struct FontSpec {
278  int height;
279  int width;
280  float fontGlyphScaleWidth;
281  };
282 
283  static GraphicsState state;
284  static FontSpec defaultFontSpec;
285  public:
286  static void storeSystemImages();
287 
288 
289  public:
290  std::string GetName() { return "Graphics"; }
291  void Init(); void InitAfter(); void RunBefore(); void RunAfter(); void DrawBefore(); void DrawAfter();
292  Backend * GetBackend();
293  static void Flush2D();
294  static void UpdateCameraTransforms(Camera * );
295 };
296 };
297 
298 
299 
300 #endif
Backend.
Definition: Backend.h:56
static void Commit()
Forces the rendered scene to be drawn on the screen. This is normally done for you.
Base component to render a 2D object.
Definition: Render2D.h:42
static void SetRenderer(Renderer *)
Sets the current Renderer instance.
static void SetCamera3D(Camera &)
Sets the current camera to view from for 3D renderings.
static void EnableFiltering(bool doIt)
Disables or enables bilinear filtering of Images during rendering. Bilinear filtering makes stratched...
Definition: AssetID.h:37
The viewport object.
Definition: Camera.h:56
Class for abstracting visual data blocks.
Definition: Image.h:62
Assets are referred to by an AssetID. The AssetID uniquely refers to an Asset stored within memory...
Definition: AssetID.h:42
static Renderer * GetRenderer()
Retrieve the Renderer instance.
static Camera & GetCamera3D()
Returns the current cameras.
Defines how an AspectMesh is visualized.
Definition: Material.h:44
static void Draw(Render2D &)
Draws an Aspect to the current display.
static void SetCamera2D(Camera &)
Sets the current camera to view from for 2D renderings.
static void SetRenderCamera(Camera &)
Sets the current camera that processes all visuals and hands them to the display i.e. the window.
Aspect representing a 3D object that reduces to a Mesh.
Definition: RenderMesh.h:50
The central class for rendering.
Definition: Graphics.h:86
static bool DrawEachFrame()
Returns whether each frame is being drawn, updated, and swapped automatically by Dynacoe or not...
Uniquely identifies an Entity.
Definition: Entity.h:67
Handles loading media.
Definition: Assets.h:97