DI-Guy SDK Documentation  13.6
diguyGraphicsShaderTechnique.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  ** Copyright (c) 1992-2022 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 typedef void diguyDrawFunc();
37 
38 typedef enum
39 {
41  DIGUY_DRAW_OPAQUE = 0x1,
44 
45 /****************************************************************************/
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 /****************************************************************************/
92 {
94  m_shader_instance(NULL),
97  m_shader_lod(-1),
101  m_use_instancing(false),
103  {
104  ;
105  }
110 
113 
117 
120 
122  float m_shader_lod_bias;
123 
128 
131 
133 
135  bool m_use_instancing;
140 };
141 
142 /****************************************************************************/
157 class BDI_DECLSPEC_diguy diguyGraphicsShaderTechnique
158 {
159 
160 public:
161 
162 /*****************************************************************************/
175  /*l
176  *b Returns:
177  **
178  ** the name of the shader technique. This pointer will
179  ** never be NULL.
180  */
181  const char* get_name();
182 
183  /*l
184  *b Description:
185  **
186  ** Returns the number of lod shaders the technique has.
187  */
188  int get_num_shader_lod_programs(bool instanced = false);
189 
190  /*l
191  *b Description:
192  **
193  ** Returns the shader program at a lod index.
194  */
195  diguyGraphicsShaderProgram* get_shader_lod_program_at_index(int index, bool instanced = false);
196 
197  /*l
198  *b Description:
199  **
200  ** Returns the distance that a shader lod switches out at.
201  */
202  float get_shader_lod_range_at_index(int index);
203 
204  /*l
205  *b Description:
206  **
207  ** Returns a shader based on the rendering distance.
208  */
209  diguyGraphicsShaderProgram * get_shader_by_distance(float distance, int max_quality_level, bool instanced = false);
210 
211  /*l
212  *b Description:
213  **
214  ** Returns the shader index based on the rendering distance.
215  */
216  int get_program_index_by_distance(float distance, int max_quality_level);
217 
218  /*l
219  *b Description:
220  **
221  ** Returns the shader specified for intersections.
222  */
223  diguyGraphicsShaderProgram* get_intersection_shader();
224 
225  /*l
226  *b Description:
227  **
228  ** Returns the shader specified for shadow map generation.
229  */
230  diguyGraphicsShaderProgram* get_shadow_pass_shader();
231 
232  /*l
233  *b Description:
234  **
235  ** Returns the shader specified for shadow map generation for instanced objects
236  */
237  diguyGraphicsShaderProgram * get_instanced_shadow_pass_shader();
238 
239 /*****************************************************************************/
244  /*l
245  *b Description:
246  **
247  ** This function allows you create a new shader that uses the same
248  ** vertex and pixel files as the one passed in. The user is then able
249  ** modify the subclassed shader before calling load().
250  ** This function should allow end users to create an arbitrary number of
251  ** shader permutations and then return them via overriding pick_shader_program().
252  ** See diguyOglGraphicsShaderTechnique::build() for an example of it's usage.
253  ** Override pick_shader_program() to return a procedurally created shader.
254  */
255  diguyGraphicsShaderProgram * find_or_create_shader_variation(diguyGraphicsShaderProgram * program, const char * new_name);
256 
257  /*l
258  *b Description:
259  **
260  ** Adds an additional shader program to the technique these will get
261  ** automatically updated if any of the shader uniform functions are used.
262  ** These are mostly for convenience. Users will probably want their own
263  ** data structures to store shader lookup tables.
264  **/
265  void add_additional_shader(diguyGraphicsShaderProgram* program);
266 
267  /*l
268  *b Returns:
269  ** The number of shaders that have been procedurally added to the technique.
270  */
271  int get_num_additional_shaders();
272 
273  /*l
274  *b Returns:
275  ** A pointer to the procedural shaders that has been procedurally added to
276  ** the technique.
277  */
278  diguyGraphicsShaderProgram* get_additional_shader_at_index(int index);
279 
280 /*****************************************************************************/
284  /*l
285  *b Description:
286  **
287  ** Convenience functions. Loops through all shaders in this technique
288  ** and sets uniform variables if they exist.
289  **
290  *b Callable From:
291  **
292  *- - C++
293  *- - Script
294  */
295  int set_variable_float(const char* name, float value, int set_current = 1, int set_initial = 0);
296  int set_variable_vec2(const char* name, float x, float y, int set_current = 1, int set_initial = 0);
297  int set_variable_vec3(const char* name, float x, float y, float z, int set_current = 1, int set_initial = 0);
298  int set_variable_vec4(const char* name, float x, float y, float z, float w, int set_current = 1, int set_initial = 0);
299  int set_variable_int(const char* name, int value, int set_current = 1, int set_initial = 0);
300 
301 /*****************************************************************************/
313  /*l
314  *b Description:
315  **
316  ** Allows users to use a subclass to override the default shader LOD system
317  ** see diguyOglGraphicsShaderTechnique::pick_shader_program() for an example
318  ** of it's usage.
319  **/
320  virtual diguyGraphicsShaderProgram * pick_shader_program(const diguyShaderPickDescription & desc);
321 
322 
323  /*l
324  *b Description:
325  **
326  ** Allows users to do their own post shader load behavior.
327  **/
328  virtual void build();
329 
335 #ifdef CPLUSPLUS_ONLY
336 
337  bdiShaderTechnique* get_internal_data() {return m_internal_data;}
338 
339 protected:
340 
341  /*l
342  ** A protected constructor. Constructors are called automatically
343  ** by DI-Guy.
344  */
345  diguyGraphicsShaderTechnique(void* internal_data);
346 
347  /*l
348  ** A protected destructor. Destructors are called automatically
349  ** by DI-Guy.
350  */
351  virtual ~diguyGraphicsShaderTechnique();
352 
353 private:
354 
355  /*l
356  ** A pointer to internal data.
357  */
358  bdiShaderTechnique* m_internal_data;
359 
360  friend class bdiShaderTechnique;
361  friend class bdiGeometryFactory;
362 #endif
363 };
364 
365 
366 #endif /* __diguyGraphicsShaderTechnique_H */
367 
A class that represents the unique per-character shader object.
Definition: diguyGraphicsShaderInstance.h:55
const char * m_custom_shader_program
Definition: diguyGraphicsShaderTechnique.h:129
Definition: diguyGraphicsShaderTechnique.h:39
diguyGraphicsShaderInstance * m_shader_instance
The pointer to the current shader instance, allows access to the currently draw character object...
Definition: diguyGraphicsShaderTechnique.h:136
This struct is passed into diguyGraphicsShaderTechnique::pick_shader_program() to provide the end use...
Definition: diguyGraphicsShaderTechnique.h:88
float m_shader_lod_bias
a multiplier to use on the distance to camera
Definition: diguyGraphicsShaderTechnique.h:119
diguyShaderPickDescription()
Definition: diguyGraphicsShaderTechnique.h:90
int m_render_pass
Definition: diguyGraphicsShaderTechnique.h:70
void * m_pre_draw_user_data
Definition: diguyGraphicsShaderTechnique.h:75
void diguyDrawFunc()
Definition: diguyGraphicsShaderTechnique.h:34
This struct is populated by the user and passed into diguyApp::add_draw_pass(diguyDrawPass drawPass)...
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:124
float m_render_distance
the distance from the object to the camera
Definition: diguyGraphicsShaderTechnique.h:116
int m_shader_lod
the current specified shader level of detail, -1 indicates to use m_render_distance for picking...
Definition: diguyGraphicsShaderTechnique.h:113
diguyDrawFunc * m_post_draw
Definition: diguyGraphicsShaderTechnique.h:77
Definition: diguyGraphicsShaderTechnique.h:38
int m_num_active_point_lights
Number of additional point lights. Set by diguyScenario::set_num_active_point_lights().
Definition: diguyGraphicsShaderTechnique.h:127
bool m_use_instancing
Use a shader that supports instancing.
Definition: diguyGraphicsShaderTechnique.h:132
diguyRenderPass
Definition: diguyGraphicsShaderTechnique.h:36
int m_current_render_pass
which pass is currently being rendered opaque objects == 0 objects with transparency == 1 ...
Definition: diguyGraphicsShaderTechnique.h:106
Definition: diguyGraphicsShaderTechnique.h:40
This class implements shader lod system for use with DI-Guy character graphics.
Definition: diguyGraphicsShaderTechnique.h:154
This class implements shader programs for use with DI-Guy character graphics.
Definition: diguyGraphicsShaderProgram.h:94
int m_current_render_flags
a list of diguyRenderPassFlags ored together
Definition: diguyGraphicsShaderTechnique.h:109
void * m_post_draw_user_data
Definition: diguyGraphicsShaderTechnique.h:78