18 #include "pandabase.h" 19 #include "config_gobj.h" 20 #include "typedWritableReferenceCount.h" 22 #include "graphicsStateGuardianBase.h" 23 #include "internalName.h" 25 #include "pta_float.h" 26 #include "pta_double.h" 27 #include "pta_stdfloat.h" 28 #include "pta_LMatrix4.h" 29 #include "pta_LMatrix3.h" 30 #include "pta_LVecBase4.h" 31 #include "pta_LVecBase3.h" 32 #include "pta_LVecBase2.h" 38 typedef struct _CGcontext *CGcontext;
39 typedef struct _CGprogram *CGprogram;
40 typedef struct _CGparameter *CGparameter;
69 enum AutoShaderSwitch {
78 bit_AutoShaderNormal = 0,
79 bit_AutoShaderGlow = 1,
80 bit_AutoShaderGloss = 2,
81 bit_AutoShaderRamp = 3,
82 bit_AutoShaderShadow = 4,
85 static PT(
Shader) load(
const Filename &file, ShaderLanguage lang = SL_none);
86 static PT(
Shader) make(
const string &body, ShaderLanguage lang = SL_none);
87 static PT(
Shader) load(ShaderLanguage lang,
91 const Filename &tess_evaluation =
"");
92 static PT(
Shader) load_compute(ShaderLanguage lang,
const Filename &fn);
93 static PT(
Shader) make(ShaderLanguage lang,
94 const string &vertex,
const string &fragment,
95 const string &geometry =
"",
96 const string &tess_control =
"",
97 const string &tess_evaluation =
"");
98 static PT(
Shader) make_compute(ShaderLanguage lang,
const string &body);
100 INLINE
Filename get_filename(
const ShaderType &type = ST_none)
const;
101 INLINE
const string &get_text(
const ShaderType &type = ST_none)
const;
102 INLINE
bool get_error_flag()
const;
103 INLINE ShaderLanguage get_language()
const;
105 INLINE
static ShaderUtilization get_shader_utilization();
106 INLINE
static void set_shader_utilization(ShaderUtilization utl);
107 INLINE
static bool have_shader_utilization();
118 enum ShaderMatInput {
160 SMO_apiview_x_to_view,
161 SMO_view_to_apiview_x,
166 SMO_apiclip_x_to_view,
167 SMO_view_to_apiclip_x,
176 SMO_mat_constant_x_attrib,
177 SMO_vec_constant_x_attrib,
180 SMO_light_source_i_attrib,
182 SMO_light_product_i_ambient,
183 SMO_light_product_i_diffuse,
184 SMO_light_product_i_specular,
187 SMO_apiview_clipplane_i,
189 SMO_model_to_apiview,
190 SMO_apiview_to_model,
191 SMO_apiview_to_apiclip,
192 SMO_apiclip_to_apiview,
197 enum ShaderArgClass {
243 enum ShaderMatPiece {
262 enum ShaderStateDep {
265 SSD_transform = 0x002,
267 SSD_colorscale = 0x008,
268 SSD_material = 0x010,
269 SSD_shaderinputs = 0x020,
272 SSD_clip_planes = 0x100,
276 SBUG_ati_draw_buffers,
281 SMF_transform_dlight,
282 SMF_transform_plight,
283 SMF_transform_slight,
295 ShaderArgClass _class;
296 ShaderArgClass _subclass;
298 ShaderArgDir _direction;
323 INLINE ShaderPtrData(
const PTA_float &ptr);
324 INLINE ShaderPtrData(
const PTA_LVecBase4f &ptr);
325 INLINE ShaderPtrData(
const PTA_LVecBase3f &ptr);
326 INLINE ShaderPtrData(
const PTA_LVecBase2f &ptr);
327 INLINE ShaderPtrData(
const PTA_LMatrix4f &mat);
328 INLINE ShaderPtrData(
const PTA_LMatrix3f &mat);
332 INLINE ShaderPtrData(
const LMatrix4f &mat);
333 INLINE ShaderPtrData(
const LMatrix3f &mat);
335 INLINE ShaderPtrData(
const PTA_double &ptr);
336 INLINE ShaderPtrData(
const PTA_LVecBase4d &ptr);
337 INLINE ShaderPtrData(
const PTA_LVecBase3d &ptr);
338 INLINE ShaderPtrData(
const PTA_LVecBase2d &ptr);
339 INLINE ShaderPtrData(
const PTA_LMatrix4d &mat);
340 INLINE ShaderPtrData(
const PTA_LMatrix3d &mat);
344 INLINE ShaderPtrData(
const LMatrix4d &mat);
345 INLINE ShaderPtrData(
const LMatrix3d &mat);
347 INLINE ShaderPtrData(
const PTA_int &ptr);
348 INLINE ShaderPtrData(
const PTA_LVecBase4i &ptr);
349 INLINE ShaderPtrData(
const PTA_LVecBase3i &ptr);
350 INLINE ShaderPtrData(
const PTA_LVecBase2i &ptr);
355 INLINE
void write_datagram(
Datagram &dg)
const;
364 ShaderMatInput _part[2];
365 PT(InternalName) _arg[2];
368 ShaderMatPiece _piece;
373 PT(InternalName) _name;
376 PT(InternalName) _suffix;
381 PT(InternalName) _name;
391 PT(InternalName) _arg;
399 INLINE
bool operator == (
const ShaderCaps &other)
const;
406 int _active_vprofile;
407 int _active_fprofile;
408 int _active_gprofile;
409 int _active_tprofile;
411 int _ultimate_vprofile;
412 int _ultimate_fprofile;
413 int _ultimate_gprofile;
414 int _ultimate_tprofile;
424 INLINE ShaderFile(
const string &vertex,
425 const string &fragment,
426 const string &geometry,
427 const string &tess_control,
428 const string &tess_evaluation);
430 INLINE
void write_datagram(
Datagram &dg)
const;
433 INLINE
bool operator < (
const ShaderFile &other)
const;
441 string _tess_control;
442 string _tess_evaluation;
451 void parse_line(
string &result,
bool rt,
bool lt);
452 void parse_upto(
string &result,
string pattern,
bool include);
453 void parse_rest(
string &result);
462 bool cp_errchk_parameter_float(
ShaderArgInfo &arg,
int lo,
int hi);
465 vector_string &pieces,
int &next);
467 vector_string &pieces,
int &next);
468 string cp_parse_non_delimiter(vector_string &pieces,
int &next);
470 vector_string &pieces,
int &next,
472 int cp_dependency(ShaderMatInput inp);
476 void cg_recurse_parameters(CGparameter parameter,
477 const ShaderType &type,
482 const ShaderArgClass &arg_class,
483 const ShaderArgClass &arg_subclass,
484 const ShaderArgType &arg_type,
485 const ShaderArgDir &arg_direction,
490 void clear_parameters();
494 ShaderArgClass cg_parameter_class(CGparameter p);
495 ShaderArgType cg_parameter_type(CGparameter p);
496 ShaderArgDir cg_parameter_dir(CGparameter p);
498 CGprogram cg_compile_entry_point(
const char *entry,
const ShaderCaps &caps,
499 CGcontext context, ShaderType type);
501 bool cg_analyze_entry_point(CGprogram prog, ShaderType type);
503 bool cg_analyze_shader(
const ShaderCaps &caps);
504 bool cg_compile_shader(
const ShaderCaps &caps, CGcontext context);
505 void cg_release_resources();
506 void cg_report_errors();
510 void cg_get_profile_from_header(
ShaderCaps &caps);
513 static CGcontext _cg_context;
514 CGprogram _cg_vprogram;
515 CGprogram _cg_fprogram;
516 CGprogram _cg_gprogram;
522 CGprogram cg_program_from_shadertype(ShaderType type);
525 bool cg_compile_for(
const ShaderCaps &caps, CGcontext context,
532 epvector <ShaderMatSpec> _mat_spec;
543 ShaderLanguage _language;
549 time_t _last_modified;
552 static ShaderUtilization _shader_utilization;
553 static int _shaders_generated;
557 static ShaderTable _load_table;
558 static ShaderTable _make_table;
569 Shader(ShaderLanguage lang);
572 bool do_read_source(
string &into,
const Filename &fn);
573 bool r_preprocess_source(ostream &out,
const Filename &fn,
575 set<Filename> &open_files,
int depth = 0);
577 bool check_modified()
const;
582 INLINE
Filename get_filename_from_index(
int index, ShaderType type)
const;
585 static void register_with_read_factory();
596 static void init_type() {
597 TypedWritableReferenceCount::init_type();
598 register_type(_type_handle,
"Shader",
599 TypedWritableReferenceCount::get_class_type());
602 return get_class_type();
604 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
This is the base class for all three-component vectors and points.
This is our own Panda specialization on the default STL map.
This is a 4-by-4 transform matrix.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
This is the base class for all two-component vectors and points.
Base class for objects that can be written to and read from Bam files.
This is the base class for all two-component vectors and points.
This is the base class for all three-component vectors and points.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
A table of objects that are saved within the graphics context for reference by handle later...
This is the base class for all three-component vectors and points.
The ShaderContext is meant to contain the compiled version of a shader string.
A particular category of error messages.
This is our own Panda specialization on the default STL vector.
This is a 3-by-3 transform matrix.
The name of a file, such as a texture file or an Egg file.
This is a 4-by-4 transform matrix.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
This is the base class for all two-component vectors and points.
This is the base class for all three-component vectors and points.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
This is the base class for all three-component vectors and points.
This is the base class for all three-component vectors and points.
A base class for all things that want to be reference-counted.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
This is our own Panda specialization on the default STL set.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
This is a 3-by-3 transform matrix.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...