41typedef struct _CGcontext *CGcontext;
42typedef struct _CGprogram *CGprogram;
43typedef struct _CGparameter *CGparameter;
49class EXPCL_PANDA_GOBJ Shader :
public TypedWritableReferenceCount {
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);
103 INLINE
const std::string &
get_text(ShaderType type = ST_none)
const;
113 PT(
AsyncFuture) prepare(PreparedGraphicsObjects *prepared_objects);
114 bool is_prepared(PreparedGraphicsObjects *prepared_objects)
const;
115 bool release(PreparedGraphicsObjects *prepared_objects);
118 ShaderContext *
prepare_now(PreparedGraphicsObjects *prepared_objects,
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;
373 struct ShaderPtrData {
375 PT(ReferenceCount) _pta;
384 INLINE ShaderPtrData();
385 INLINE ShaderPtrData(
const PTA_float &ptr);
386 INLINE ShaderPtrData(
const PTA_LVecBase4f &ptr);
387 INLINE ShaderPtrData(
const PTA_LVecBase3f &ptr);
388 INLINE ShaderPtrData(
const PTA_LVecBase2f &ptr);
389 INLINE ShaderPtrData(
const PTA_LMatrix4f &mat);
390 INLINE ShaderPtrData(
const PTA_LMatrix3f &mat);
391 INLINE ShaderPtrData(
const LVecBase4f &vec);
392 INLINE ShaderPtrData(
const LVecBase3f &vec);
393 INLINE ShaderPtrData(
const LVecBase2f &vec);
394 INLINE ShaderPtrData(
const LMatrix4f &mat);
395 INLINE ShaderPtrData(
const LMatrix3f &mat);
397 INLINE ShaderPtrData(
const PTA_double &ptr);
398 INLINE ShaderPtrData(
const PTA_LVecBase4d &ptr);
399 INLINE ShaderPtrData(
const PTA_LVecBase3d &ptr);
400 INLINE ShaderPtrData(
const PTA_LVecBase2d &ptr);
401 INLINE ShaderPtrData(
const PTA_LMatrix4d &mat);
402 INLINE ShaderPtrData(
const PTA_LMatrix3d &mat);
403 INLINE ShaderPtrData(
const LVecBase4d &vec);
404 INLINE ShaderPtrData(
const LVecBase3d &vec);
405 INLINE ShaderPtrData(
const LVecBase2d &vec);
406 INLINE ShaderPtrData(
const LMatrix4d &mat);
407 INLINE ShaderPtrData(
const LMatrix3d &mat);
409 INLINE ShaderPtrData(
const PTA_int &ptr);
410 INLINE ShaderPtrData(
const PTA_LVecBase4i &ptr);
411 INLINE ShaderPtrData(
const PTA_LVecBase3i &ptr);
412 INLINE ShaderPtrData(
const PTA_LVecBase2i &ptr);
413 INLINE ShaderPtrData(
const LVecBase4i &vec);
414 INLINE ShaderPtrData(
const LVecBase3i &vec);
415 INLINE ShaderPtrData(
const LVecBase2i &vec);
426 ShaderMatInput _part[2];
430 ShaderMatPiece _piece;
436 ShaderTexInput _part;
447 ShaderPtrType _numeric_type;
459 class EXPCL_PANDA_GOBJ ShaderCaps {
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;
483 class ShaderFile :
public ReferenceCount {
485 INLINE ShaderFile() {};
486 INLINE ShaderFile(std::string shared);
487 INLINE ShaderFile(std::string vertex, std::string fragment, std::string geometry,
488 std::string tess_control, std::string tess_evaluation);
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);
525 vector_string &pieces,
int &next);
527 vector_string &pieces,
int &next);
530 vector_string &pieces,
int &next,
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;
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,
585 CGprogram &combined_program, pvector<CGparameter> &
map);
590 pvector<ShaderPtrSpec> _ptr_spec;
591 epvector<ShaderMatSpec> _mat_spec;
592 pvector<ShaderTexSpec> _tex_spec;
593 pvector<ShaderVarSpec> _var_spec;
604 ShaderLanguage _language;
606 typedef pvector<Filename> Filenames;
607 Filenames _included_files;
611 Filenames _source_files;
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;
622 typedef pmap<
ShaderFile, PT(Shader)> ShaderTable;
624 static ShaderTable _load_table;
625 static ShaderTable _make_table;
627 friend class ShaderContext;
628 friend class PreparedGraphicsObjects;
630 typedef pmap <PreparedGraphicsObjects *, ShaderContext *> Contexts;
634 void clear_prepared(PreparedGraphicsObjects *prepared_objects);
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;
664 static TypedWritable *make_from_bam(
const FactoryParams ¶ms);
671 static void init_type() {
672 TypedWritableReferenceCount::init_type();
674 TypedWritableReferenceCount::get_class_type());
676 virtual TypeHandle get_type()
const {
677 return get_class_type();
679 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
682 static TypeHandle _type_handle;
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class represents a thread-safe handle to a promised future result of an asynchronous operation,...
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
The name of a file, such as a texture file or an Egg file.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Encodes a string name in a hash table, mapping it to a pointer.
A particular category of error messages.
void read_datagram(DatagramIterator &source)
Reads the object from a Datagram.
void write_datagram(Datagram &dg) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
bool cp_errchk_parameter_varying(ShaderArgInfo &arg)
Make sure the provided parameter has the correct variance.
bool cp_parse_eol(ShaderArgInfo &arg, vector_string &pieces, int &next)
Make sure the next thing on the word list is EOL.
bool get_error_flag() const
Returns true if the shader contains a compile-time error.
void cp_optimize_mat_spec(ShaderMatSpec &spec)
Analyzes a ShaderMatSpec and decides what it should use its cache for.
bool get_compiled(unsigned int &format, std::string &binary) const
Called by the back-end to retrieve compiled data.
bool cp_parse_delimiter(ShaderArgInfo &arg, vector_string &pieces, int &next)
Pop a delimiter ('to' or 'rel') from the word list.
bool has_fullpath() const
Returns true if the fullpath has been set and is available.
const std::string & get_text(ShaderType type=ST_none) const
Return the Shader's text for the given shader type.
void cp_report_error(ShaderArgInfo &arg, const std::string &msg)
Generate an error message including a description of the specified parameter.
void parse_init()
Set a 'parse pointer' to the beginning of the shader.
void set_compiled(unsigned int format, const char *data, size_t length)
Called by the back-end when the shader has compiled data available.
ShaderContext * prepare_now(PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg)
Creates a context for the shader on the particular GSG, if it does not already exist.
bool compile_parameter(ShaderArgInfo &p, int *arg_dim)
Analyzes a parameter and decides how to bind the parameter to some part of panda's internal state.
int release_all()
Frees the context allocated on all objects for which the texture has been declared.
void set_filename(ShaderType type, const Filename &filename)
Sets the Shader's filename for the given shader type.
bool cp_errchk_parameter_in(ShaderArgInfo &arg)
Make sure the provided parameter has the 'in' direction.
bool cp_errchk_parameter_uniform(ShaderArgInfo &arg)
Make sure the provided parameter has the correct variance.
bool cp_parse_coord_sys(ShaderArgInfo &arg, vector_string &pieces, int &next, ShaderMatSpec &spec, bool fromflag)
Convert a single-word coordinate system name into a PART/ARG of a ShaderMatSpec.
static void set_default_caps(const ShaderCaps &caps)
Called by the graphics back-end to specify the caps with which we will likely want to be compiling ou...
Filename get_filename_from_index(int index, ShaderType type) const
Returns the filename of the included shader with the given source file index (as recorded in the #lin...
std::string cp_parse_non_delimiter(vector_string &pieces, int &next)
Pop a non-delimiter word from the word list.
void parse_line(std::string &result, bool rt, bool lt)
Parse a line of text.
void set_cache_compiled_shader(bool flag)
Sets the cache_compiled_shader flag.
void parse_rest(std::string &result)
Returns the rest of the text from the current parse location.
bool is_prepared(PreparedGraphicsObjects *prepared_objects) const
Returns true if the shader has already been prepared or enqueued for preparation on the indicated GSG...
bool cp_errchk_parameter_float(ShaderArgInfo &arg, int lo, int hi)
Make sure the provided parameter has a floating point type.
void parse_upto(std::string &result, std::string pattern, bool include)
Parse lines until you read a line that matches the specified pattern.
bool get_cache_compiled_shader() const
Returns the setting of the cache_compiled_shader flag.
static void register_with_read_factory()
Tells the BamReader how to create objects of type Shader.
bool cp_errchk_parameter_words(ShaderArgInfo &arg, int len)
Make sure the provided parameter contains the specified number of words.
bool cp_errchk_parameter_sampler(ShaderArgInfo &arg)
Make sure the provided parameter has a texture type.
ShaderLanguage get_language() const
Returns the shader language in which this shader was written.
bool parse_eof()
Returns true if the parse pointer is at the end of the shader.
Filename get_filename(ShaderType type=ST_none) const
Return the Shader's filename for the given shader type.
const Filename & get_fullpath() const
Returns the fullpath that has been set.
int cp_dependency(ShaderMatInput inp)
Given ShaderMatInput, returns an indication of what part or parts of the state_and_transform the Shad...
bool release(PreparedGraphicsObjects *prepared_objects)
Frees the texture context only on the indicated object, if it exists there.
TypeHandle is the identifier used to differentiate C++ class types.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void write_datagram(Datagram &dg) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
void read_datagram(DatagramIterator &source)
Reads the object from a Datagram.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.