ShaderGL_Multi.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 #if ( defined DC_BACKENDS_SHADERGL_X11 || defined DC_BACKENDS_SHADERGL_WIN32 )
34 
35 
36 #ifndef GLINTERFACE_H_INCLUDED
37 #define GLINTERFACE_H_INCLUDED
38 
39 
40 
41 #include <Dynacoe/Backends/Renderer/Renderer.h>
42 #ifndef GLEW_STATIC
43 #define GLEW_STATIC
44 #endif
45 #ifdef DC_BACKENDS_SHADERGL_X11
46  #include <GL/glew.h>
47 #else
48  #ifdef _MBCS
49  #include <GL/glew.h>
50  #else
51  #include <glew.h>
52  #endif
53 #endif
54 #include <Dynacoe/Backends/Renderer/ShaderGL/TextureManager.h>
55 #include <Dynacoe/Backends/Renderer/ShaderGL/Renderer2D.h>
56 #include <vector>
57 #include <stack>
58 
59 
60 
61 namespace Dynacoe {
62 
63 class RenderBuffer;
64 class StaticProgram;
65 class StaticState;
66 class DynamicProgram;
67 struct ShaderGLRenderer : public Dynacoe::Renderer {
68  public:
69  ShaderGLRenderer();
70 
71  std::string Name();
72  std::string Version();
73  bool Valid();
74 
75 
76  void Queue2DVertices(
77  const uint32_t * indices,
78  uint32_t count
79  );
80 
81  uint32_t Add2DObject();
82  void Remove2DObject(uint32_t);
83  uint32_t Add2DVertex();
84  void Remove2DVertex(uint32_t object);
85  void Set2DVertex(uint32_t vertex, Vertex2D);
86  Vertex2D Get2DVertex(uint32_t vertex);
87  void Set2DObjectParameters(uint32_t object, Render2DObjectParameters);
88  void Render2DVertices(const Render2DStaticParameters &);
89  void Clear2DQueue();
90 
91  void RenderStatic(StaticState *);
92  void ClearRenderedData();
93  RenderBufferID GetStaticViewingMatrixID();
94  RenderBufferID GetStaticProjectionMatrixID();
95 
96  int AddTexture(int, int, const uint8_t *);
97  void UpdateTexture(int, const uint8_t *);
98  void RemoveTexture(int tex);
99  void GetTexture(int, uint8_t*);
100  void SetTextureFilter(TexFilter);
101  TexFilter GetTextureFilter();
102  int GetTextureWidth(int);
103  int GetTextureHeight(int);
104  int MaxSimultaneousTextures();
105 
106  RenderBufferID AddBuffer(float *, int);
107  void UpdateBuffer(RenderBufferID, float *, int, int);
108  void ReadBuffer(RenderBufferID, float *, int, int);
109  int BufferSize(RenderBufferID);
110  void RemoveBuffer(RenderBufferID);
111 
112 
113  LightID AddLight(LightType);
114  void UpdateLightAttributes(LightID, float *);
115  void EnableLight(LightID, bool doIt);
116  void RemoveLight(LightID);
117  int MaxEnabledLights();
118  int NumLights();
119 
120  std::string ProgramGetLanguage();
121  ProgramID ProgramGetBuiltIn(BuiltInShaderMode);
122  ProgramID ProgramAdd(const std::string&, const std::string &, std::string &);
123 
124 
125  bool IsSupported(Capability);
126  void SetDrawingMode(Polygon, Dimension, AlphaRule);
127  void GetDrawingMode(Polygon *, Dimension *, AlphaRule *);
128  void AttachTarget(Dynacoe::Framebuffer *);
129  Dynacoe::Framebuffer * GetTarget();
130  std::vector<Dynacoe::Framebuffer::Type> SupportedFramebuffers();
131  TextureManager * GetTextureManager() { return texture; }
132 
133 
134  double diagnostic_dynamic_vtex_per_render_accumulated_avg;
135  uint32_t diagnostic_dynamic_vtex_per_render_accumulated_avg_ct;
136  uint32_t diagnostic_dynamic_vtex_per_render_avg;
137  uint32_t diagnostic_dynamic_vtex_per_render_min;
138  uint32_t diagnostic_dynamic_vtex_per_render_max;
139  uint32_t diagnostic_dynamic_vtex_render_per_frame;
140  uint32_t diagnostic_dynamic_vtex_render_last;
141  time_t diagnostic_dynamic_vtex_render_frame_time;
142  uint32_t diagnostic_static_object_count_per_second;
143  time_t diagnostic_static_object_count_time;
144  uint32_t diagnostic_static_object_count_per_second_last;
145  double diagnostic_static_object_avg_indices_acc;
146  uint32_t diagnostic_static_object_avg_indices_ct;
147  uint32_t diagnostic_static_object_avg_indices;
148 
149  private:
150  void gl3warning(const char *);
151  void gl3fatal(const char *);
152 
153 
154  // list of reserved active textures
155  void resolveDisplayMode(Renderer::Polygon, Renderer::Dimension, Renderer::AlphaRule);
156  void resolveDisplayMode();
157  void onFirstAttach();
158  void initGL();
159  void initGLBuffers();
160 
161  Display * attachedDisplay;
162  GLuint * texImageBounds;
163 
164  TextureManager * texture;
165  Renderer2D * renderer2D;
166 
167 
168 
169 
170  GLenum drawMode;
171 
172  Framebuffer * framebuffer;
173 
174  void prepareTextures(StaticState*);
175  void framebufferCheck();
176 
177  RenderBufferID mainProjectionUniform;
178  RenderBufferID mainViewUniform;
179  RenderBufferID mainTextureUniform;
180  RenderBufferID mainTextureUniform2;
181  RenderBufferID mainLightUniform;
182  RenderBufferID mainLightUniform2;
183 
185  Dynacoe::Table<StaticProgram*> shaderPrograms;
186 
187  Dynacoe::LookupID basicProgramID;
188  Dynacoe::LookupID lightProgramID;
189 
190 
191 
192 
193  bool checkSupported();
194  bool createContext();
195 
196  bool samplebufferSet;
197  GLuint lastSamplebuffer;
198 
199  GLuint framebufferHandle;
200  GLuint framebufferW;
201  GLuint framebufferH;
202  GLuint framebufferTex;
203 
204  bool valid;
205 
206  Polygon curPolygon;
207  AlphaRule curAlphaRule;
208  Dimension curDimension;
209 
210 
211 
212 
213  bool lightsDirty;
214  float * lightDataSrc;
215  float * lightDataSrc2;
216  void SyncLightBuffer();
217 
218 
219 
220 };
221 }
222 
223 #endif
224 #endif
225 
Contains a visual state.
Definition: Framebuffer.h:49
Definition: AssetID.h:37
An associative container that issues each member an ID guaranteed to be unique for the duration of th...
Definition: Table.h:58