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