Parcourir la source

Added support for shader-related TextureStage::Mode values

Josh Yelon il y a 18 ans
Parent
commit
6f81e4850c

+ 2 - 2
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx

@@ -2607,7 +2607,7 @@ void DXGraphicsStateGuardian8::
 do_issue_texture() {
 do_issue_texture() {
   DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1));
   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 &&
   nassertv(num_stages <= _max_texture_stages &&
            _num_active_texture_stages <= _max_texture_stages);
            _num_active_texture_stages <= _max_texture_stages);
 
 
@@ -2623,7 +2623,7 @@ do_issue_texture() {
 
 
   int i;
   int i;
   for (i = 0; i < num_stages; 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);
     Texture *texture = _effective_texture->get_on_texture(stage);
     nassertv(texture != (Texture *)NULL);
     nassertv(texture != (Texture *)NULL);
 
 

+ 3 - 3
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -3856,10 +3856,10 @@ void DXGraphicsStateGuardian9::
 update_standard_texture_bindings() {
 update_standard_texture_bindings() {
   DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1));
   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;
   int num_old_stages = _max_texture_stages;
   if (_state._texture != (TextureAttrib *)NULL) {
   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 &&
   nassertv(num_stages <= _max_texture_stages &&
@@ -3877,7 +3877,7 @@ update_standard_texture_bindings() {
 
 
   int i;
   int i;
   for (i = 0; i < num_stages; 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);
     Texture *texture = _effective_texture->get_on_texture(stage);
     nassertv(texture != (Texture *)NULL);
     nassertv(texture != (Texture *)NULL);
 
 

+ 32 - 0
panda/src/egg/eggTexture.cxx

@@ -563,6 +563,14 @@ affects_polygon_alpha() const {
   case ET_blend_color_scale:
   case ET_blend_color_scale:
     return false;
     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:
   case ET_unspecified:
     break;
     break;
   }
   }
@@ -872,6 +880,18 @@ string_env_type(const string &string) {
   } else if (cmp_nocase_uh(string, "blend_color_scale") == 0) {
   } else if (cmp_nocase_uh(string, "blend_color_scale") == 0) {
     return ET_blend_color_scale;
     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 {
   } else {
     return ET_unspecified;
     return ET_unspecified;
   }
   }
@@ -1270,6 +1290,18 @@ ostream &operator << (ostream &out, EggTexture::EnvType type) {
 
 
   case EggTexture::ET_blend_color_scale:
   case EggTexture::ET_blend_color_scale:
     return out << "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);
   nassertr(false, out);

+ 4 - 0
panda/src/egg/eggTexture.h

@@ -102,6 +102,10 @@ PUBLISHED:
     ET_replace,
     ET_replace,
     ET_add,
     ET_add,
     ET_blend_color_scale,
     ET_blend_color_scale,
+    ET_normal_map,
+    ET_gloss_map,
+    ET_normal_gloss_map,
+    ET_selector_map,
   };
   };
   enum CombineMode {
   enum CombineMode {
     CM_unspecified,
     CM_unspecified,

+ 16 - 0
panda/src/egg2pg/eggLoader.cxx

@@ -1379,6 +1379,22 @@ make_texture_stage(const EggTexture *egg_tex) {
     stage->set_mode(TextureStage::M_blend_color_scale);
     stage->set_mode(TextureStage::M_blend_color_scale);
     break;
     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:
   case EggTexture::ET_unspecified:
     break;
     break;
   }
   }

+ 6 - 6
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
     // least those for which we're not generating texture coordinates
     // automatically.
     // automatically.
     const Geom::ActiveTextureStages &active_stages =
     const Geom::ActiveTextureStages &active_stages =
-      _effective_texture->get_on_stages();
+      _effective_texture->get_on_ff_stages();
     const Geom::NoTexCoordStages &no_texcoords =
     const Geom::NoTexCoordStages &no_texcoords =
       _effective_tex_gen->get_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
     // least those for which we're not generating texture coordinates
     // automatically.
     // automatically.
     const Geom::ActiveTextureStages &active_stages =
     const Geom::ActiveTextureStages &active_stages =
-      _effective_texture->get_on_stages();
+      _effective_texture->get_on_ff_stages();
     const Geom::NoTexCoordStages &no_texcoords =
     const Geom::NoTexCoordStages &no_texcoords =
       _effective_tex_gen->get_no_texcoords();
       _effective_tex_gen->get_no_texcoords();
     
     
@@ -6092,7 +6092,7 @@ do_issue_texture() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void CLP(GraphicsStateGuardian)::
 void CLP(GraphicsStateGuardian)::
 update_standard_texture_bindings() {
 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 &&
   nassertv(num_stages <= _max_texture_stages &&
            _num_active_texture_stages <= _max_texture_stages);
            _num_active_texture_stages <= _max_texture_stages);
@@ -6103,7 +6103,7 @@ update_standard_texture_bindings() {
   int last_stage = -1;
   int last_stage = -1;
   int i;
   int i;
   for (i = 0; i < num_stages; 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);
     Texture *texture = _effective_texture->get_on_texture(stage);
     nassertv(texture != (Texture *)NULL);
     nassertv(texture != (Texture *)NULL);
 
 
@@ -6313,7 +6313,7 @@ do_issue_tex_matrix() {
   nassertv(_num_active_texture_stages <= _max_texture_stages);
   nassertv(_num_active_texture_stages <= _max_texture_stages);
 
 
   for (int i = 0; i < _num_active_texture_stages; i++) {
   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);
     _glActiveTexture(GL_TEXTURE0 + i);
 
 
     GLP(MatrixMode)(GL_TEXTURE);
     GLP(MatrixMode)(GL_TEXTURE);
@@ -6360,7 +6360,7 @@ do_issue_tex_gen() {
   bool got_point_sprites = false;
   bool got_point_sprites = false;
 
 
   for (int i = 0; i < _num_active_texture_stages; i++) {
   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);
     _glActiveTexture(GL_TEXTURE0 + i);
     GLP(Disable)(GL_TEXTURE_GEN_S);
     GLP(Disable)(GL_TEXTURE_GEN_S);
     GLP(Disable)(GL_TEXTURE_GEN_T);
     GLP(Disable)(GL_TEXTURE_GEN_T);

+ 12 - 0
panda/src/gobj/textureStage.I

@@ -188,6 +188,18 @@ get_mode() const {
   return _mode;
   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
 //     Function: TextureStage::set_color
 //       Access: Published
 //       Access: Published

+ 14 - 3
panda/src/gobj/textureStage.h

@@ -48,6 +48,8 @@ PUBLISHED:
   virtual ~TextureStage();
   virtual ~TextureStage();
 
 
   enum Mode {
   enum Mode {
+    // Modes that pertain to the fixed-function pipeline.
+    
     M_modulate,
     M_modulate,
     M_decal,
     M_decal,
     M_blend,
     M_blend,
@@ -55,8 +57,15 @@ PUBLISHED:
     M_add,
     M_add,
     M_combine,
     M_combine,
     M_blend_color_scale,
     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 {
   enum CombineMode {
     CM_undefined,
     CM_undefined,
     CM_replace,
     CM_replace,
@@ -104,10 +113,12 @@ PUBLISHED:
   INLINE void set_texcoord_name(InternalName *name);
   INLINE void set_texcoord_name(InternalName *name);
   INLINE void set_texcoord_name(const string &texcoord_name);
   INLINE void set_texcoord_name(const string &texcoord_name);
   INLINE InternalName *get_texcoord_name() const;
   INLINE InternalName *get_texcoord_name() const;
-
+  
   INLINE void set_mode(Mode mode);
   INLINE void set_mode(Mode mode);
   INLINE Mode get_mode() const;
   INLINE Mode get_mode() const;
-
+  
+  INLINE bool is_fixed_function() const;
+  
   INLINE void set_color(const Colorf &color);
   INLINE void set_color(const Colorf &color);
   INLINE Colorf get_color() const;
   INLINE Colorf get_color() const;
 
 

+ 41 - 0
panda/src/pgraph/textureAttrib.I

@@ -104,6 +104,33 @@ get_on_stage(int n) const {
   return _on_stages[n];
   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
 //     Function: TextureAttrib::has_on_stage
 //       Access: Published
 //       Access: Published
@@ -200,6 +227,20 @@ get_on_stages() const {
   return _on_stages;
   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
 //     Function: TextureAttrib::check_sorted
 //       Access: Private
 //       Access: Private

+ 10 - 1
panda/src/pgraph/textureAttrib.cxx

@@ -836,7 +836,8 @@ fillin(DatagramIterator &scan, BamReader *manager) {
 //     Function: TextureAttrib::sort_on_stages
 //     Function: TextureAttrib::sort_on_stages
 //       Access: Private
 //       Access: Private
 //  Description: Sorts the list of stages so that they are listed in
 //  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::
 void TextureAttrib::
 sort_on_stages() {
 sort_on_stages() {
@@ -844,6 +845,14 @@ sort_on_stages() {
 
 
   _sort_seq = TextureStage::get_sort_seq();
   _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
   // Also clear the _filtered map, so we'll have to recompute those
   // (in case the priority orders have changed as well).
   // (in case the priority orders have changed as well).
   _filtered.clear();
   _filtered.clear();

+ 5 - 1
panda/src/pgraph/textureAttrib.h

@@ -58,6 +58,8 @@ PUBLISHED:
 
 
   INLINE int get_num_on_stages() const;
   INLINE int get_num_on_stages() const;
   INLINE TextureStage *get_on_stage(int n) 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 bool has_on_stage(TextureStage *stage) const;
   INLINE Texture *get_on_texture(TextureStage *stage) const;
   INLINE Texture *get_on_texture(TextureStage *stage) const;
 
 
@@ -78,6 +80,7 @@ PUBLISHED:
 
 
 public:
 public:
   INLINE const Geom::ActiveTextureStages &get_on_stages() const;
   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;
   CPT(TextureAttrib) filter_to_max(int max_texture_stages) const;
 
 
   virtual void output(ostream &out) const;
   virtual void output(ostream &out) const;
@@ -99,7 +102,8 @@ private:
 private:
 private:
   typedef Geom::ActiveTextureStages OnStages;
   typedef Geom::ActiveTextureStages OnStages;
   OnStages _on_stages;
   OnStages _on_stages;
-
+  OnStages _on_ff_stages;
+  
   typedef ov_set<TextureStage *> OffStages;
   typedef ov_set<TextureStage *> OffStages;
   OffStages _off_stages;
   OffStages _off_stages;
   bool _off_all_stages;
   bool _off_all_stages;