diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index ccbedf7141..eea6a760f3 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -2607,7 +2607,7 @@ void DXGraphicsStateGuardian8:: do_issue_texture() { DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1)); - int num_stages = _effective_texture->get_num_on_stages(); + int num_stages = _effective_texture->get_num_on_ff_stages(); nassertv(num_stages <= _max_texture_stages && _num_active_texture_stages <= _max_texture_stages); @@ -2623,7 +2623,7 @@ do_issue_texture() { int i; for (i = 0; i < num_stages; i++) { - TextureStage *stage = _effective_texture->get_on_stage(i); + TextureStage *stage = _effective_texture->get_on_ff_stage(i); Texture *texture = _effective_texture->get_on_texture(stage); nassertv(texture != (Texture *)NULL); diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 1faf934246..529fc9dba6 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -3856,10 +3856,10 @@ void DXGraphicsStateGuardian9:: update_standard_texture_bindings() { DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1)); - int num_stages = _effective_texture->get_num_on_stages(); + int num_stages = _effective_texture->get_num_on_ff_stages(); int num_old_stages = _max_texture_stages; if (_state._texture != (TextureAttrib *)NULL) { - num_old_stages = _state._texture->get_num_on_stages(); + num_old_stages = _state._texture->get_num_on_ff_stages(); } nassertv(num_stages <= _max_texture_stages && @@ -3877,7 +3877,7 @@ update_standard_texture_bindings() { int i; for (i = 0; i < num_stages; i++) { - TextureStage *stage = _effective_texture->get_on_stage(i); + TextureStage *stage = _effective_texture->get_on_ff_stage(i); Texture *texture = _effective_texture->get_on_texture(stage); nassertv(texture != (Texture *)NULL); diff --git a/panda/src/egg/eggTexture.cxx b/panda/src/egg/eggTexture.cxx index d744221662..dee7db13b5 100644 --- a/panda/src/egg/eggTexture.cxx +++ b/panda/src/egg/eggTexture.cxx @@ -563,6 +563,14 @@ affects_polygon_alpha() const { case ET_blend_color_scale: return false; + case ET_normal_map: + case ET_gloss_map: + case ET_normal_gloss_map: + return false; + + case ET_selector_map: + return true; + case ET_unspecified: break; } @@ -872,6 +880,18 @@ string_env_type(const string &string) { } else if (cmp_nocase_uh(string, "blend_color_scale") == 0) { return ET_blend_color_scale; + } else if (cmp_nocase_uh(string, "normal_map") == 0) { + return ET_normal_map; + + } else if (cmp_nocase_uh(string, "gloss_map") == 0) { + return ET_gloss_map; + + } else if (cmp_nocase_uh(string, "normal_gloss_map") == 0) { + return ET_normal_gloss_map; + + } else if (cmp_nocase_uh(string, "selector_map") == 0) { + return ET_selector_map; + } else { return ET_unspecified; } @@ -1270,6 +1290,18 @@ ostream &operator << (ostream &out, EggTexture::EnvType type) { case EggTexture::ET_blend_color_scale: return out << "blend_color_scale"; + + case EggTexture::ET_normal_map: + return out << "normal_map"; + + case EggTexture::ET_gloss_map: + return out << "gloss_map"; + + case EggTexture::ET_normal_gloss_map: + return out << "normal_gloss_map"; + + case EggTexture::ET_selector_map: + return out << "selector_map"; } nassertr(false, out); diff --git a/panda/src/egg/eggTexture.h b/panda/src/egg/eggTexture.h index 2111c73917..688031e66a 100644 --- a/panda/src/egg/eggTexture.h +++ b/panda/src/egg/eggTexture.h @@ -102,6 +102,10 @@ PUBLISHED: ET_replace, ET_add, ET_blend_color_scale, + ET_normal_map, + ET_gloss_map, + ET_normal_gloss_map, + ET_selector_map, }; enum CombineMode { CM_unspecified, diff --git a/panda/src/egg2pg/eggLoader.cxx b/panda/src/egg2pg/eggLoader.cxx index 328fc6970d..9abf348e0a 100644 --- a/panda/src/egg2pg/eggLoader.cxx +++ b/panda/src/egg2pg/eggLoader.cxx @@ -1379,6 +1379,22 @@ make_texture_stage(const EggTexture *egg_tex) { stage->set_mode(TextureStage::M_blend_color_scale); break; + case EggTexture::ET_normal_map: + stage->set_mode(TextureStage::M_normal_map); + break; + + case EggTexture::ET_gloss_map: + stage->set_mode(TextureStage::M_gloss_map); + break; + + case EggTexture::ET_normal_gloss_map: + stage->set_mode(TextureStage::M_normal_gloss_map); + break; + + case EggTexture::ET_selector_map: + stage->set_mode(TextureStage::M_selector_map); + break; + case EggTexture::ET_unspecified: break; } diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index f91dee5598..143a230520 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -1785,7 +1785,7 @@ update_standard_vertex_arrays(bool force) { // least those for which we're not generating texture coordinates // automatically. const Geom::ActiveTextureStages &active_stages = - _effective_texture->get_on_stages(); + _effective_texture->get_on_ff_stages(); const Geom::NoTexCoordStages &no_texcoords = _effective_tex_gen->get_no_texcoords(); @@ -1886,7 +1886,7 @@ update_standard_vertex_arrays(bool force) { // least those for which we're not generating texture coordinates // automatically. const Geom::ActiveTextureStages &active_stages = - _effective_texture->get_on_stages(); + _effective_texture->get_on_ff_stages(); const Geom::NoTexCoordStages &no_texcoords = _effective_tex_gen->get_no_texcoords(); @@ -6092,7 +6092,7 @@ do_issue_texture() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: update_standard_texture_bindings() { - int num_stages = _effective_texture->get_num_on_stages(); + int num_stages = _effective_texture->get_num_on_ff_stages(); nassertv(num_stages <= _max_texture_stages && _num_active_texture_stages <= _max_texture_stages); @@ -6103,7 +6103,7 @@ update_standard_texture_bindings() { int last_stage = -1; int i; for (i = 0; i < num_stages; i++) { - TextureStage *stage = _effective_texture->get_on_stage(i); + TextureStage *stage = _effective_texture->get_on_ff_stage(i); Texture *texture = _effective_texture->get_on_texture(stage); nassertv(texture != (Texture *)NULL); @@ -6313,7 +6313,7 @@ do_issue_tex_matrix() { nassertv(_num_active_texture_stages <= _max_texture_stages); for (int i = 0; i < _num_active_texture_stages; i++) { - TextureStage *stage = _effective_texture->get_on_stage(i); + TextureStage *stage = _effective_texture->get_on_ff_stage(i); _glActiveTexture(GL_TEXTURE0 + i); GLP(MatrixMode)(GL_TEXTURE); @@ -6360,7 +6360,7 @@ do_issue_tex_gen() { bool got_point_sprites = false; for (int i = 0; i < _num_active_texture_stages; i++) { - TextureStage *stage = _effective_texture->get_on_stage(i); + TextureStage *stage = _effective_texture->get_on_ff_stage(i); _glActiveTexture(GL_TEXTURE0 + i); GLP(Disable)(GL_TEXTURE_GEN_S); GLP(Disable)(GL_TEXTURE_GEN_T); diff --git a/panda/src/gobj/textureStage.I b/panda/src/gobj/textureStage.I index be1c7e0478..5eefa32aeb 100755 --- a/panda/src/gobj/textureStage.I +++ b/panda/src/gobj/textureStage.I @@ -188,6 +188,18 @@ get_mode() const { return _mode; } +//////////////////////////////////////////////////////////////////// +// Function: TextureStage::is_fixed_function +// Access: Published +// Description: Returns true if the TextureStage is relevant to +// the classic fixed function pipeline. This excludes +// texture stages such as normal mapping and the like. +//////////////////////////////////////////////////////////////////// +INLINE bool TextureStage:: +is_fixed_function() const { + return (_mode < M_normal_map); +} + //////////////////////////////////////////////////////////////////// // Function: TextureStage::set_color // Access: Published diff --git a/panda/src/gobj/textureStage.h b/panda/src/gobj/textureStage.h index 5006cdea0a..20f89540cb 100644 --- a/panda/src/gobj/textureStage.h +++ b/panda/src/gobj/textureStage.h @@ -48,6 +48,8 @@ PUBLISHED: virtual ~TextureStage(); enum Mode { + // Modes that pertain to the fixed-function pipeline. + M_modulate, M_decal, M_blend, @@ -55,8 +57,15 @@ PUBLISHED: M_add, M_combine, M_blend_color_scale, + + // Modes that are only relevant to shader-based rendering. + + M_normal_map, + M_gloss_map, + M_normal_gloss_map, + M_selector_map, }; - + enum CombineMode { CM_undefined, CM_replace, @@ -104,10 +113,12 @@ PUBLISHED: INLINE void set_texcoord_name(InternalName *name); INLINE void set_texcoord_name(const string &texcoord_name); INLINE InternalName *get_texcoord_name() const; - + INLINE void set_mode(Mode mode); INLINE Mode get_mode() const; - + + INLINE bool is_fixed_function() const; + INLINE void set_color(const Colorf &color); INLINE Colorf get_color() const; diff --git a/panda/src/pgraph/textureAttrib.I b/panda/src/pgraph/textureAttrib.I index f3dc2e9847..d7f6266515 100644 --- a/panda/src/pgraph/textureAttrib.I +++ b/panda/src/pgraph/textureAttrib.I @@ -104,6 +104,33 @@ get_on_stage(int n) const { return _on_stages[n]; } +//////////////////////////////////////////////////////////////////// +// Function: TextureAttrib::get_num_on_ff_stages +// Access: Published +// Description: Returns the number of on-stages that are relevant +// to the classic fixed function pipeline. This excludes +// texture stages such as normal maps. +//////////////////////////////////////////////////////////////////// +INLINE int TextureAttrib:: +get_num_on_ff_stages() const { + check_sorted(); + return _on_ff_stages.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: TextureAttrib::get_on_ff_stage +// Access: Published +// Description: Returns the nth stage turned on by the attribute, +// sorted in render order, including only those relevant +// to the classic fixed function pipeline. This excludes +// texture stages such as normal maps. +//////////////////////////////////////////////////////////////////// +INLINE TextureStage *TextureAttrib:: +get_on_ff_stage(int n) const { + nassertr(n >= 0 && n < (int)_on_ff_stages.size(), (TextureStage *)NULL); + return _on_ff_stages[n]; +} + //////////////////////////////////////////////////////////////////// // Function: TextureAttrib::has_on_stage // Access: Published @@ -200,6 +227,20 @@ get_on_stages() const { return _on_stages; } +//////////////////////////////////////////////////////////////////// +// Function: TextureAttrib::get_on_ff_stages +// Access: Public +// Description: Returns the complete list of stages defined within +// this TextureAttrib, including only those which are +// relevant to the classic fixed-function pipeline. +// The result is suitable for passing to +// Geom::setup_multitexcoord_iterator(). +//////////////////////////////////////////////////////////////////// +INLINE const Geom::ActiveTextureStages &TextureAttrib:: +get_on_ff_stages() const { + return _on_ff_stages; +} + //////////////////////////////////////////////////////////////////// // Function: TextureAttrib::check_sorted // Access: Private diff --git a/panda/src/pgraph/textureAttrib.cxx b/panda/src/pgraph/textureAttrib.cxx index b26821425a..5628f1c8ec 100644 --- a/panda/src/pgraph/textureAttrib.cxx +++ b/panda/src/pgraph/textureAttrib.cxx @@ -836,7 +836,8 @@ fillin(DatagramIterator &scan, BamReader *manager) { // Function: TextureAttrib::sort_on_stages // Access: Private // Description: Sorts the list of stages so that they are listed in -// render order. Also clears the _filtered map. +// render order. Also clears the _filtered map and +// recalculates the list of fixed-function stages. //////////////////////////////////////////////////////////////////// void TextureAttrib:: sort_on_stages() { @@ -844,6 +845,14 @@ sort_on_stages() { _sort_seq = TextureStage::get_sort_seq(); + _on_ff_stages.clear(); + OnStages::const_iterator osi; + for (osi = _on_stages.begin(); osi != _on_stages.end(); ++osi) { + if ((*osi)->is_fixed_function()) { + _on_ff_stages.push_back(*osi); + } + } + // Also clear the _filtered map, so we'll have to recompute those // (in case the priority orders have changed as well). _filtered.clear(); diff --git a/panda/src/pgraph/textureAttrib.h b/panda/src/pgraph/textureAttrib.h index 01fb9c31af..1363f87c5d 100644 --- a/panda/src/pgraph/textureAttrib.h +++ b/panda/src/pgraph/textureAttrib.h @@ -58,6 +58,8 @@ PUBLISHED: INLINE int get_num_on_stages() const; INLINE TextureStage *get_on_stage(int n) const; + INLINE int get_num_on_ff_stages() const; + INLINE TextureStage *get_on_ff_stage(int n) const; INLINE bool has_on_stage(TextureStage *stage) const; INLINE Texture *get_on_texture(TextureStage *stage) const; @@ -78,6 +80,7 @@ PUBLISHED: public: INLINE const Geom::ActiveTextureStages &get_on_stages() const; + INLINE const Geom::ActiveTextureStages &get_on_ff_stages() const; CPT(TextureAttrib) filter_to_max(int max_texture_stages) const; virtual void output(ostream &out) const; @@ -99,7 +102,8 @@ private: private: typedef Geom::ActiveTextureStages OnStages; OnStages _on_stages; - + OnStages _on_ff_stages; + typedef ov_set OffStages; OffStages _off_stages; bool _off_all_stages;