DI-Guy SDK Documentation  13.5
diguyGraphicsShaderTechnique.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  ** Copyright (c) 1992-2020 MAK Technologies, Inc.
4  ** All rights reserved.
5  *********************************************************************/
6 
7 /*********************************************************************/
14 #ifndef __diguyGraphicsShaderTechnique_H
15 #define __diguyGraphicsShaderTechnique_H
16 
17 
18 #ifdef SWIG
20 #else
21 #define CPLUSPLUS_ONLY
22 #endif
23 
24 #ifdef CPLUSPLUS_ONLY
25 
26 #include <diguy_constants.h>
27 #include <declspec_diguy.h>
28 
29 class diguyGraphicsLink;
32 class bdiShaderTechnique;
33 
34 #endif
35 
36 /****************************************************************************/
42 typedef void diguyDrawFunc();
43 
44 typedef enum
45 {
47  DIGUY_DRAW_OPAQUE = 0x1,
50 
51 struct BDI_DECLSPEC_diguy diguyDrawPass
52 {
53  diguyDrawPass() :
54  m_render_pass(DIGUY_DRAW_NONE),
55  m_render_mode(NULL),
56  m_custom_shader_program(NULL),
57  m_pre_draw(0),
58  m_pre_draw_user_data(0),
59  m_post_draw(0),
60  m_post_draw_user_data(0)
61  {}
62 
63  bool operator==(const diguyDrawPass& rhs) const
64  {
65  return (m_render_pass == rhs.m_render_pass &&
66  m_pre_draw == rhs.m_pre_draw &&
67  m_pre_draw_user_data == rhs.m_pre_draw_user_data &&
68  m_post_draw == rhs.m_post_draw &&
69  m_post_draw_user_data == rhs.m_post_draw_user_data);
70  }
71 
72  int m_render_pass;
73  const char* m_render_mode;
74  const char* m_custom_shader_program;
75 
76  diguyDrawFunc* m_pre_draw;
77  void* m_pre_draw_user_data;
78 
79  diguyDrawFunc* m_post_draw;
80  void* m_post_draw_user_data;
81 };
82 
83 
84 /****************************************************************************/
90 {
92  m_shader_instance(NULL),
95  m_shader_lod(-1),
99  m_use_instancing(false),
101  {
102  ;
103  }
108 
111 
115 
118 
120  float m_shader_lod_bias;
121 
126 
129 
131 
133  bool m_use_instancing;
138 };
139 
140 /****************************************************************************/
155 class BDI_DECLSPEC_diguy diguyGraphicsShaderTechnique
156 {
157 
158 public:
159 
160 /*****************************************************************************/
173  /*l
174  *b Returns:
175  **
176  ** the name of the shader technique. This pointer will
177  ** never be NULL.
178  */
179  const char* get_name();
180 
181  /*l
182  *b Description:
183  **
184  ** Returns the number of lod shaders the technique has.
185  */
186  int get_num_shader_lod_programs(bool instanced = false);
187 
188  /*l
189  *b Description:
190  **
191  ** Returns the shader program at a lod index.
192  */
193  diguyGraphicsShaderProgram* get_shader_lod_program_at_index(int index, bool instanced = false);
194 
195  /*l
196  *b Description:
197  **
198  ** Returns the distance that a shader lod switches out at.
199  */
200  float get_shader_lod_range_at_index(int index);
201 
202  /*l
203  *b Description:
204  **
205  ** Returns a shader based on the rendering distance.
206  */
207  diguyGraphicsShaderProgram * get_shader_by_distance(float distance, int max_quality_level, bool instanced = false);
208 
209  /*l
210  *b Description:
211  **
212  ** Returns the shader index based on the rendering distance.
213  */
214  int get_program_index_by_distance(float distance, int max_quality_level);
215 
216  /*l
217  *b Description:
218  **
219  ** Returns the shader specified for intersections.
220  */
221  diguyGraphicsShaderProgram* get_intersection_shader();
222 
223  /*l
224  *b Description:
225  **
226  ** Returns the shader specified for shadow map generation.
227  */
228  diguyGraphicsShaderProgram* get_shadow_pass_shader();
229 
230  /*l
231  *b Description:
232  **
233  ** Returns the shader specified for shadow map generation for instanced objects
234  */
235  diguyGraphicsShaderProgram * get_instanced_shadow_pass_shader();
236 
237 /*****************************************************************************/
242  /*l
243  *b Description:
244  **
245  ** This function allows you create a new shader that uses the same
246  ** vertex and pixel files as the one passed in. The user is then able
247  ** modify the subclassed shader before calling load().
248  ** This function should allow end users to create an arbitrary number of
249  ** shader permutations and then return them via overriding pick_shader_program().
250  ** See diguyOglGraphicsShaderTechnique::build() for an example of it's usage.
251  ** Override pick_shader_program() to return a procedurally created shader.
252  */
253  diguyGraphicsShaderProgram * find_or_create_shader_variation(diguyGraphicsShaderProgram * program, const char * new_name);
254 
255  /*l
256  *b Description:
257  **
258  ** Adds an additional shader program to the technique these will get
259  ** automatically updated if any of the shader uniform functions are used.
260  ** These are mostly for convenience. Users will probably want their own
261  ** data structures to store shader lookup tables.
262  **/
263  void add_additional_shader(diguyGraphicsShaderProgram* program);
264 
265  /*l
266  *b Returns:
267  ** The number of shaders that have been procedurally added to the technique.
268  */
269  int get_num_additional_shaders();
270 
271  /*l
272  *b Returns:
273  ** A pointer to the procedural shaders that has been procedurally added to
274  ** the technique.
275  */
276  diguyGraphicsShaderProgram* get_additional_shader_at_index(int index);
277 
278 /*****************************************************************************/
282  /*l
283  *b Description:
284  **
285  ** Convenience functions. Loops through all shaders in this technique
286  ** and sets uniform variables if they exist.
287  **
288  *b Callable From:
289  **
290  *- - C++
291  *- - Script
292  */
293  int set_variable_float(const char* name, float value, int set_current = 1, int set_initial = 0);
294  int set_variable_vec2(const char* name, float x, float y, int set_current = 1, int set_initial = 0);
295  int set_variable_vec3(const char* name, float x, float y, float z, int set_current = 1, int set_initial = 0);
296  int set_variable_vec4(const char* name, float x, float y, float z, float w, int set_current = 1, int set_initial = 0);
297  int set_variable_int(const char* name, int value, int set_current = 1, int set_initial = 0);
298 
299 /*****************************************************************************/
311  /*l
312  *b Description:
313  **
314  ** Allows users to use a subclass to override the default shader LOD system
315  ** see diguyOglGraphicsShaderTechnique::pick_shader_program() for an example
316  ** of it's usage.
317  **/
318  virtual diguyGraphicsShaderProgram * pick_shader_program(const diguyShaderPickDescription & desc);
319 
320 
321  /*l
322  *b Description:
323  **
324  ** Allows users to do their own post shader load behavior.
325  **/
326  virtual void build();
327 
333 #ifdef CPLUSPLUS_ONLY
334 
335  bdiShaderTechnique* get_internal_data() {return m_internal_data;}
336 
337 protected:
338 
339  /*l
340  ** A protected constructor. Constructors are called automatically
341  ** by DI-Guy.
342  */
343  diguyGraphicsShaderTechnique(void* internal_data);
344 
345  /*l
346  ** A protected destructor. Destructors are called automatically
347  ** by DI-Guy.
348  */
349  virtual ~diguyGraphicsShaderTechnique();
350 
351 private:
352 
353  /*l
354  ** A pointer to internal data.
355  */
356  bdiShaderTechnique* m_internal_data;
357 
358  friend class bdiShaderTechnique;
359  friend class bdiGeometryFactory;
360 #endif
361 };
362 
363 
364 #endif /* __diguyGraphicsShaderTechnique_H */
365 
A class that represents the unique per-character shader object.
Definition: diguyGraphicsShaderInstance.h:55
const char * m_custom_shader_program
Definition: diguyGraphicsShaderTechnique.h:127
Definition: diguyGraphicsShaderTechnique.h:45
diguyGraphicsShaderInstance * m_shader_instance
The pointer to the current shader instance, allows access to the currently draw character object...
Definition: diguyGraphicsShaderTechnique.h:134
This struct is passed into diguyGraphicsShaderTechnique::pick_shader_program() to provide the end use...
Definition: diguyGraphicsShaderTechnique.h:86
float m_shader_lod_bias
a multiplier to use on the distance to camera
Definition: diguyGraphicsShaderTechnique.h:117
diguyShaderPickDescription()
Definition: diguyGraphicsShaderTechnique.h:88
int m_render_pass
Definition: diguyGraphicsShaderTechnique.h:70
void * m_pre_draw_user_data
Definition: diguyGraphicsShaderTechnique.h:75
void diguyDrawFunc()
This struct is populated by the user and passed into diguyApp::add_draw_pass(diguyDrawPass drawPass)...
Definition: diguyGraphicsShaderTechnique.h:40
Definition: diguyGraphicsShaderTechnique.h:49
diguyDrawFunc * m_pre_draw
Definition: diguyGraphicsShaderTechnique.h:74
int m_max_quality_level
typically this will either be DIGUY_GRAPHICS_SHADER_QUALITY_PER_PIXEL or DIGUY_GRAPHICS_SHADER_QUALIT...
Definition: diguyGraphicsShaderTechnique.h:122
float m_render_distance
the distance from the object to the camera
Definition: diguyGraphicsShaderTechnique.h:114
int m_shader_lod
the current specified shader level of detail, -1 indicates to use m_render_distance for picking...
Definition: diguyGraphicsShaderTechnique.h:111
diguyDrawFunc * m_post_draw
Definition: diguyGraphicsShaderTechnique.h:77
Definition: diguyGraphicsShaderTechnique.h:44
int m_num_active_point_lights
Number of additional point lights. Set by diguyScenario::set_num_active_point_lights().
Definition: diguyGraphicsShaderTechnique.h:125
bool m_use_instancing
Use a shader that supports instancing.
Definition: diguyGraphicsShaderTechnique.h:130
diguyRenderPass
Definition: diguyGraphicsShaderTechnique.h:42
int m_current_render_pass
which pass is currently being rendered opaque objects == 0 objects with transparency == 1 ...
Definition: diguyGraphicsShaderTechnique.h:104
Definition: diguyGraphicsShaderTechnique.h:46
This class implements shader lod system for use with DI-Guy character graphics.
Definition: diguyGraphicsShaderTechnique.h:152
This class implements shader programs for use with DI-Guy character graphics.
Definition: diguyGraphicsShaderProgram.h:96
int m_current_render_flags
a list of diguyRenderPassFlags ored together
Definition: diguyGraphicsShaderTechnique.h:107
void * m_post_draw_user_data
Definition: diguyGraphicsShaderTechnique.h:78