DI-Guy SDK Documentation  13.1
diguyGraphicsShaderTechnique.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  ** Copyright (c) 1992-2015 VT MAK
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(0),
56  m_custom_shader_program(0),
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 /****************************************************************************/
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 /*****************************************************************************/
236  /*l
237  *b Description:
238  **
239  ** This function allows you create a new shader that uses the same
240  ** vertex and pixel files as the one passed in. The user is then able
241  ** modify the subclassed shader before calling load().
242  ** This function should allow end users to create an arbitrary number of
243  ** shader permutations and then return them via overriding pick_shader_program().
244  ** See diguyOglGraphicsShaderTechnique::build() for an example of it's usage.
245  ** Override pick_shader_program() to return a procedurally created shader.
246  */
247  diguyGraphicsShaderProgram * find_or_create_shader_variation(diguyGraphicsShaderProgram * program, const char * new_name);
248 
249  /*l
250  *b Description:
251  **
252  ** Adds an additional shader program to the technique these will get
253  ** automatically updated if any of the shader uniform functions are used.
254  ** These are mostly for convenience. Users will probably want their own
255  ** data structures to store shader lookup tables.
256  **/
257  void add_additional_shader(diguyGraphicsShaderProgram* program);
258 
259  /*l
260  *b Returns:
261  ** The number of shaders that have been procedurally added to the technique.
262  */
263  int get_num_additional_shaders();
264 
265  /*l
266  *b Returns:
267  ** A pointer to the procedural shaders that has been procedurally added to
268  ** the technique.
269  */
270  diguyGraphicsShaderProgram* get_additional_shader_at_index(int index);
271 
272 /*****************************************************************************/
276  /*l
277  *b Description:
278  **
279  ** Convenience functions. Loops through all shaders in this technique
280  ** and sets uniform variables if they exist.
281  **
282  *b Callable From:
283  **
284  *- - C++
285  *- - Script
286  */
287  int set_variable_float(const char* name, float value, int set_current = 1, int set_initial = 0);
288  int set_variable_vec2(const char* name, float x, float y, int set_current = 1, int set_initial = 0);
289  int set_variable_vec3(const char* name, float x, float y, float z, int set_current = 1, int set_initial = 0);
290  int set_variable_vec4(const char* name, float x, float y, float z, float w, int set_current = 1, int set_initial = 0);
291  int set_variable_int(const char* name, int value, int set_current = 1, int set_initial = 0);
292 
293 /*****************************************************************************/
305  /*l
306  *b Description:
307  **
308  ** Allows users to use a subclass to override the default shader LOD system
309  ** see diguyOglGraphicsShaderTechnique::pick_shader_program() for an example
310  ** of it's usage.
311  **/
312  virtual diguyGraphicsShaderProgram * pick_shader_program(const diguyShaderPickDescription & desc);
313 
314 
315  /*l
316  *b Description:
317  **
318  ** Allows users to do their own post shader load behavior.
319  **/
320  virtual void build();
321 
327 #ifdef CPLUSPLUS_ONLY
328 
329  bdiShaderTechnique* get_internal_data() {return m_internal_data;}
330 
331 protected:
332 
333  /*l
334  ** A protected constructor. Constructors are called automatically
335  ** by DI-Guy.
336  */
337  diguyGraphicsShaderTechnique(void* internal_data);
338 
339  /*l
340  ** A protected destructor. Destructors are called automatically
341  ** by DI-Guy.
342  */
343  virtual ~diguyGraphicsShaderTechnique();
344 
345 private:
346 
347  /*l
348  ** A pointer to internal data.
349  */
350  bdiShaderTechnique* m_internal_data;
351 
352  friend class bdiShaderTechnique;
353  friend class bdiGeometryFactory;
354 #endif
355 };
358 #endif /* __diguyGraphicsShaderTechnique_H */
359 
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::aet_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: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:107
void * m_post_draw_user_data
Definition: diguyGraphicsShaderTechnique.h:78