70 enum AutoShaderSwitch {
79 bit_AutoShaderNormal = 0,
80 bit_AutoShaderGlow = 1,
81 bit_AutoShaderGloss = 2,
82 bit_AutoShaderRamp = 3,
83 bit_AutoShaderShadow = 4,
86 static PT(
Shader) load(
const Filename &file, ShaderLanguage lang = SL_none);
87 static PT(
Shader) make(std::string body, ShaderLanguage lang = SL_none);
88 static PT(
Shader) load(ShaderLanguage lang,
92 const Filename &tess_evaluation =
"");
93 static PT(
Shader) load_compute(ShaderLanguage lang,
const Filename &fn);
94 static PT(
Shader) make(ShaderLanguage lang,
95 std::string vertex, std::string fragment,
96 std::string geometry =
"",
97 std::string tess_control =
"",
98 std::string tess_evaluation =
"");
99 static PT(
Shader) make_compute(ShaderLanguage lang, std::string body);
101 INLINE
Filename get_filename(ShaderType type = ST_none)
const;
102 INLINE
void set_filename(ShaderType type,
const Filename &filename);
103 INLINE
const std::string &get_text(ShaderType type = ST_none)
const;
104 INLINE
bool get_error_flag()
const;
105 INLINE ShaderLanguage get_language()
const;
107 INLINE
bool has_fullpath()
const;
108 INLINE
const Filename &get_fullpath()
const;
110 INLINE
bool get_cache_compiled_shader()
const;
111 INLINE
void set_cache_compiled_shader(
bool flag);
122 enum ShaderMatInput {
164 SMO_apiview_x_to_view,
165 SMO_view_to_apiview_x,
170 SMO_apiclip_x_to_view,
171 SMO_view_to_apiclip_x,
180 SMO_mat_constant_x_attrib,
181 SMO_vec_constant_x_attrib,
184 SMO_light_source_i_attrib,
186 SMO_light_product_i_ambient,
187 SMO_light_product_i_diffuse,
188 SMO_light_product_i_specular,
191 SMO_apiview_clipplane_i,
193 SMO_model_to_apiview,
194 SMO_apiview_to_model,
195 SMO_apiview_to_apiclip,
196 SMO_apiclip_to_apiview,
209 SMO_light_source_i_packed,
221 SMO_attr_pointparams,
226 enum ShaderTexInput {
233 STO_light_i_shadow_map,
236 STO_stage_modulate_i,
240 STO_stage_selector_i,
242 STO_stage_emission_i,
245 enum ShaderArgClass {
282 SAT_sampler_cube_array,
294 enum ShaderMatPiece {
315 enum ShaderStateDep {
318 SSD_transform = 0x2002,
320 SSD_colorscale = 0x008,
321 SSD_material = 0x010,
322 SSD_shaderinputs = 0x020,
325 SSD_clip_planes = 0x100,
326 SSD_tex_matrix = 0x200,
328 SSD_projection = 0x800,
329 SSD_texture = 0x1000,
330 SSD_view_transform= 0x2000,
331 SSD_tex_gen = 0x4000,
332 SSD_render_mode = 0x8000,
336 SBUG_ati_draw_buffers,
341 SMF_transform_dlight,
342 SMF_transform_plight,
343 SMF_transform_slight,
363 ShaderArgClass _class;
364 ShaderArgClass _subclass;
366 ShaderArgDir _direction;
368 ShaderPtrType _numeric_type;
417 INLINE
void write_datagram(
Datagram &dg)
const;
426 ShaderMatInput _part[2];
430 ShaderMatPiece _piece;
436 ShaderTexInput _part;
447 ShaderPtrType _numeric_type;
462 INLINE
bool operator == (
const ShaderCaps &other)
const;
469 int _active_vprofile;
470 int _active_fprofile;
471 int _active_gprofile;
472 int _active_tprofile;
474 int _ultimate_vprofile;
475 int _ultimate_fprofile;
476 int _ultimate_gprofile;
477 int _ultimate_tprofile;
479 pset <ShaderBug> _bug_list;
487 INLINE
ShaderFile(std::string vertex, std::string fragment, std::string geometry,
488 std::string tess_control, std::string tess_evaluation);
490 INLINE
void write_datagram(
Datagram &dg)
const;
493 INLINE
bool operator < (
const ShaderFile &other)
const;
499 std::string _fragment;
500 std::string _geometry;
501 std::string _tess_control;
502 std::string _tess_evaluation;
503 std::string _compute;
511 void parse_line(std::string &result,
bool rt,
bool lt);
512 void parse_upto(std::string &result, std::string pattern,
bool include);
513 void parse_rest(std::string &result);
516 void cp_report_error(
ShaderArgInfo &arg,
const std::string &msg);
522 bool cp_errchk_parameter_float(
ShaderArgInfo &arg,
int lo,
int hi);
525 vector_string &pieces,
int &next);
527 vector_string &pieces,
int &next);
528 std::string cp_parse_non_delimiter(vector_string &pieces,
int &next);
530 vector_string &pieces,
int &next,
532 int cp_dependency(ShaderMatInput inp);
536 void cg_recurse_parameters(CGparameter parameter,
537 const ShaderType &type,
543 void clear_parameters();
545 void set_compiled(
unsigned int format,
const char *data,
size_t length);
546 bool get_compiled(
unsigned int &format, std::string &binary)
const;
548 static void set_default_caps(
const ShaderCaps &caps);
552 ShaderArgClass cg_parameter_class(CGparameter p);
553 ShaderArgType cg_parameter_type(CGparameter p);
554 ShaderArgDir cg_parameter_dir(CGparameter p);
556 CGprogram cg_compile_entry_point(
const char *entry,
const ShaderCaps &caps,
557 CGcontext context, ShaderType type);
559 bool cg_analyze_entry_point(CGprogram prog, ShaderType type);
561 bool cg_analyze_shader(
const ShaderCaps &caps);
562 bool cg_compile_shader(
const ShaderCaps &caps, CGcontext context);
563 void cg_release_resources();
564 void cg_report_errors();
569 void cg_get_profile_from_header(
ShaderCaps &caps);
572 static CGcontext _cg_context;
573 CGprogram _cg_vprogram;
574 CGprogram _cg_fprogram;
575 CGprogram _cg_gprogram;
581 CGprogram cg_program_from_shadertype(ShaderType type);
584 bool cg_compile_for(
const ShaderCaps &caps, CGcontext context,
591 epvector<ShaderMatSpec> _mat_spec;
604 ShaderLanguage _language;
612 time_t _last_modified;
615 bool _cache_compiled_shader;
616 unsigned int _compiled_format;
617 std::string _compiled_binary;
620 static int _shaders_generated;
630 typedef pmap <PreparedGraphicsObjects *, ShaderContext *>
Contexts;
636 Shader(ShaderLanguage lang);
641 bool do_load_source(std::string &into,
const std::string &source,
BamCacheRecord *record);
642 bool r_preprocess_include(std::ostream &out,
const Filename &fn,
644 std::set<Filename> &open_files,
646 bool r_preprocess_source(std::ostream &out, std::istream &in,
648 std::set<Filename> &open_files,
650 int fileno = 0,
int depth = 0);
652 bool check_modified()
const;
657 Filename get_filename_from_index(
int index, ShaderType type)
const;
660 static void register_with_read_factory();
671 static void init_type() {
672 TypedWritableReferenceCount::init_type();
674 TypedWritableReferenceCount::get_class_type());
677 return get_class_type();
679 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
The ShaderContext is meant to contain the compiled version of a shader string.