Browse Source

use 2-d texture coordinates when possible

David Rose 20 years ago
parent
commit
85ff01dba5
3 changed files with 48 additions and 17 deletions
  1. 21 0
      panda/src/grutil/cardMaker.I
  2. 25 16
      panda/src/grutil/cardMaker.cxx
  3. 2 1
      panda/src/grutil/cardMaker.h

+ 21 - 0
panda/src/grutil/cardMaker.I

@@ -47,6 +47,19 @@ set_has_uvs(bool flag) {
   _has_uvs = flag;
   _has_uvs = flag;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: CardMaker::set_has_3d_uvs
+//       Access: Public
+//  Description: Sets the flag indicating whether vertices will be
+//               generated with 3-component UVW's (true) or
+//               2-component UV's (the default, false).  Normally,
+//               this will be implicitly set by setting the uv_range.
+////////////////////////////////////////////////////////////////////
+INLINE void CardMaker::
+set_has_3d_uvs(bool flag) {
+  _has_3d_uvs = flag;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: CardMaker::set_uv_range
 //     Function: CardMaker::set_uv_range
 //       Access: Public
 //       Access: Public
@@ -62,6 +75,8 @@ set_uv_range(const TexCoord3f &ll, const TexCoord3f &lr, const TexCoord3f &ur, c
   _lr_tex = lr;
   _lr_tex = lr;
   _ur_tex = ur;
   _ur_tex = ur;
   _ul_tex = ul;
   _ul_tex = ul;
+  _has_uvs = true;
+  _has_3d_uvs = true;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -79,6 +94,8 @@ set_uv_range(const TexCoordf &ll, const TexCoordf &lr, const TexCoordf &ur, cons
   _lr_tex.set(lr[0], lr[1], 0.0f);
   _lr_tex.set(lr[0], lr[1], 0.0f);
   _ur_tex.set(ur[0], ur[1], 0.0f);
   _ur_tex.set(ur[0], ur[1], 0.0f);
   _ul_tex.set(ul[0], ul[1], 0.0f);
   _ul_tex.set(ul[0], ul[1], 0.0f);
+  _has_uvs = true;
+  _has_3d_uvs = false;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -96,6 +113,8 @@ set_uv_range(const TexCoordf &ll, const TexCoordf &ur) {
   _lr_tex.set(ur[0], ll[1], 0.0f);
   _lr_tex.set(ur[0], ll[1], 0.0f);
   _ur_tex.set(ur[0], ur[1], 0.0f);
   _ur_tex.set(ur[0], ur[1], 0.0f);
   _ul_tex.set(ll[0], ur[1], 0.0f);
   _ul_tex.set(ll[0], ur[1], 0.0f);
+  _has_uvs = true;
+  _has_3d_uvs = false;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -113,6 +132,8 @@ set_uv_range(const LVector4f &x, const LVector4f &y, const LVector4f &z) {
   _lr_tex.set(x[1], y[1], z[1]);
   _lr_tex.set(x[1], y[1], z[1]);
   _ur_tex.set(x[2], y[2], z[2]);
   _ur_tex.set(x[2], y[2], z[2]);
   _ul_tex.set(x[3], y[3], z[3]);
   _ul_tex.set(x[3], y[3], z[3]);
+  _has_uvs = true;
+  _has_3d_uvs = true;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 25 - 16
panda/src/grutil/cardMaker.cxx

@@ -34,6 +34,7 @@
 void CardMaker::
 void CardMaker::
 reset() {
 reset() {
   _has_uvs = true;
   _has_uvs = true;
+  _has_3d_uvs = false;
 
 
   _ll_pos.set(0.0f, 0.0f, 0.0f);
   _ll_pos.set(0.0f, 0.0f, 0.0f);
   _lr_pos.set(1.0f, 0.0f, 0.0f);
   _lr_pos.set(1.0f, 0.0f, 0.0f);
@@ -71,27 +72,35 @@ generate() {
   CPT(GeomVertexFormat) format;
   CPT(GeomVertexFormat) format;
   if (_has_normals) {
   if (_has_normals) {
     if (_has_uvs) {
     if (_has_uvs) {
-      format = GeomVertexFormat::register_format(new GeomVertexArrayFormat
-                                                 (InternalName::get_vertex(), 3,
-                                                  GeomEnums::NT_float32, GeomEnums::C_point,
-                                                  InternalName::get_normal(), 3,
-                                                  GeomEnums::NT_float32, GeomEnums::C_vector,
-                                                  InternalName::get_color(), 1,
-                                                  GeomEnums::NT_packed_dabc, GeomEnums::C_color,
-                                                  InternalName::get_texcoord(), 3,
-                                                  GeomEnums::NT_float32, GeomEnums::C_texcoord));
+      if (_has_3d_uvs) {
+	format = GeomVertexFormat::register_format(new GeomVertexArrayFormat
+						   (InternalName::get_vertex(), 3,
+						    GeomEnums::NT_float32, GeomEnums::C_point,
+						    InternalName::get_normal(), 3,
+						    GeomEnums::NT_float32, GeomEnums::C_vector,
+						    InternalName::get_color(), 1,
+						    GeomEnums::NT_packed_dabc, GeomEnums::C_color,
+						    InternalName::get_texcoord(), 3,
+						    GeomEnums::NT_float32, GeomEnums::C_texcoord));
+      } else {
+	format = GeomVertexFormat::get_v3n3cpt2();
+      }
     } else {
     } else {
       format = GeomVertexFormat::get_v3n3cp();
       format = GeomVertexFormat::get_v3n3cp();
     }
     }
   } else {
   } else {
     if (_has_uvs) {
     if (_has_uvs) {
-      format = GeomVertexFormat::register_format(new GeomVertexArrayFormat
-                                                 (InternalName::get_vertex(), 3,
-                                                  GeomEnums::NT_float32, GeomEnums::C_point,
-                                                  InternalName::get_color(), 1,
-                                                  GeomEnums::NT_packed_dabc, GeomEnums::C_color,
-                                                  InternalName::get_texcoord(), 3,
-                                                  GeomEnums::NT_float32, GeomEnums::C_texcoord));
+      if (_has_3d_uvs) {
+	format = GeomVertexFormat::register_format(new GeomVertexArrayFormat
+						   (InternalName::get_vertex(), 3,
+						    GeomEnums::NT_float32, GeomEnums::C_point,
+						    InternalName::get_color(), 1,
+						    GeomEnums::NT_packed_dabc, GeomEnums::C_color,
+						    InternalName::get_texcoord(), 3,
+						    GeomEnums::NT_float32, GeomEnums::C_texcoord));
+      } else {
+	format = GeomVertexFormat::get_v3cpt2();
+      }
     } else {
     } else {
       format = GeomVertexFormat::get_v3cp();
       format = GeomVertexFormat::get_v3cp();
     }
     }

+ 2 - 1
panda/src/grutil/cardMaker.h

@@ -43,6 +43,7 @@ PUBLISHED:
   INLINE void set_uv_range(const TexCoord3f &ll, const TexCoord3f &lr, const TexCoord3f &ur, const TexCoord3f &ul);
   INLINE void set_uv_range(const TexCoord3f &ll, const TexCoord3f &lr, const TexCoord3f &ur, const TexCoord3f &ul);
   INLINE void set_uv_range(const LVector4f &x, const LVector4f &y, const LVector4f &z);
   INLINE void set_uv_range(const LVector4f &x, const LVector4f &y, const LVector4f &z);
   INLINE void set_has_uvs(bool flag);
   INLINE void set_has_uvs(bool flag);
+  INLINE void set_has_3d_uvs(bool flag);
   INLINE void set_uv_range_cube(int face);
   INLINE void set_uv_range_cube(int face);
 
 
   INLINE void set_frame(float left, float right, float bottom, float top);
   INLINE void set_frame(float left, float right, float bottom, float top);
@@ -62,7 +63,7 @@ PUBLISHED:
 private:
 private:
   PT(PandaNode) rescale_source_geometry();
   PT(PandaNode) rescale_source_geometry();
 
 
-  bool _has_uvs;
+  bool _has_uvs, _has_3d_uvs;
   Vertexf    _ul_tex, _ll_tex, _lr_tex, _ur_tex;
   Vertexf    _ul_tex, _ll_tex, _lr_tex, _ur_tex;
   TexCoord3f _ul_pos, _ll_pos, _lr_pos, _ur_pos;
   TexCoord3f _ul_pos, _ll_pos, _lr_pos, _ur_pos;