Browse Source

api-level antialias control

David Rose 21 years ago
parent
commit
f939c61b1a

+ 75 - 2
panda/src/glstuff/glGraphicsStateGuardian_src.I

@@ -110,7 +110,6 @@ enable_line_smooth(bool val) {
     _line_smooth_enabled = val;
     if (val) {
       GLP(Enable)(GL_LINE_SMOOTH);
-      GLP(Hint)(GL_LINE_SMOOTH_HINT, GL_NICEST);
     } else {
       GLP(Disable)(GL_LINE_SMOOTH);
     }
@@ -128,13 +127,87 @@ enable_point_smooth(bool val) {
     _point_smooth_enabled = val;
     if (val) {
       GLP(Enable)(GL_POINT_SMOOTH);
-      GLP(Hint)(GL_POINT_SMOOTH_HINT, GL_NICEST);
     } else {
       GLP(Disable)(GL_POINT_SMOOTH);
     }
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CLP(GraphicsStateGuardian)::enable_polygon_smooth
+//       Access:
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE void CLP(GraphicsStateGuardian)::
+enable_polygon_smooth(bool val) {
+  if (_polygon_smooth_enabled != val) {
+    _polygon_smooth_enabled = val;
+    if (val) {
+      GLP(Enable)(GL_POLYGON_SMOOTH);
+    } else {
+      GLP(Disable)(GL_POLYGON_SMOOTH);
+    }
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CLP(GraphicsStateGuardian)::setup_antialias_line
+//       Access: Protected
+//  Description: Sets the appropriate antialiasing modes to render a
+//               series of line primitives, according to
+//               _antialias_mode.
+////////////////////////////////////////////////////////////////////
+INLINE void CLP(GraphicsStateGuardian)::
+setup_antialias_line() {
+  if (_antialias_mode == (unsigned short)AntialiasAttrib::M_best) {
+    // Lines supposedly look better using line smoothing, even if we
+    // have multisample available.
+    enable_multisample(false);
+    enable_line_smooth(true);
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CLP(GraphicsStateGuardian)::setup_antialias_point
+//       Access: Protected
+//  Description: Sets the appropriate antialiasing modes to render a
+//               series of point primitives, according to
+//               _antialias_mode.
+////////////////////////////////////////////////////////////////////
+INLINE void CLP(GraphicsStateGuardian)::
+setup_antialias_point() {
+  if (_antialias_mode == (unsigned short)AntialiasAttrib::M_best) {
+    // Points supposedly look better using point smoothing, even if we
+    // have multisample available.
+    enable_multisample(false);
+    enable_point_smooth(true);
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CLP(GraphicsStateGuardian)::setup_antialias_polygon
+//       Access: Protected
+//  Description: Sets the appropriate antialiasing modes to render a
+//               series of point primitives, according to
+//               _antialias_mode.
+////////////////////////////////////////////////////////////////////
+INLINE void CLP(GraphicsStateGuardian)::
+setup_antialias_polygon() {
+  if (_antialias_mode == (unsigned short)AntialiasAttrib::M_best) {
+    if (_render_mode == RenderModeAttrib::M_wireframe) {
+      // In wireframe mode, we're really drawing lines.
+      enable_multisample(false);
+      enable_line_smooth(true);
+
+    } else {
+      // For polygons, multisample is best if it's available, otherwise
+      // polygon smoothing will do.
+      enable_multisample(true);
+      enable_polygon_smooth(true);
+    }
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CLP(GraphicsStateGuardian)::enable_stencil_test
 //       Access:

+ 54 - 24
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -38,9 +38,6 @@
 #include "colorWriteAttrib.h"
 #include "texMatrixAttrib.h"
 #include "texGenAttrib.h"
-#ifdef HAVE_CGGL
-#include "cgShaderAttrib.h"
-#endif
 #include "materialAttrib.h"
 #include "renderModeAttrib.h"
 #include "rescaleNormalAttrib.h"
@@ -57,6 +54,9 @@
 #ifdef DO_PSTATS
 #include "pStatTimer.h"
 #endif
+#ifdef HAVE_CGGL
+#include "cgShaderAttrib.h"
+#endif
 
 #include <algorithm>
 
@@ -438,19 +438,6 @@ reset() {
     _buffer_mask &= ~RenderBuffer::T_back;
   }
 
-#if 0
-  //Note 8/01: This is incorrect for mono displays, if stereo is not in use, we need
-  //           to use the GL_BACK constants and not the GL_BACK_LEFT ones, which
-  //           under the RenderBuffer flag schemes require both left and right flags set.
-
-  // Check to see if we have stereo (and therefore a right buffer).
-  GLboolean has_stereo;
-  GLP(GetBooleanv)(GL_STEREO, &has_stereo);
-  if (!has_stereo) {
-    _buffer_mask &= ~RenderBuffer::T_right;
-  }
-#endif
-
   // Set up the specific state values to GL's known initial values.
   GLP(FrontFace)(GL_CCW);
 
@@ -459,6 +446,7 @@ reset() {
   _multisample_enabled = false;
   _line_smooth_enabled = false;
   _point_smooth_enabled = false;
+  _polygon_smooth_enabled = false;
   _scissor_enabled = false;
   _stencil_test_enabled = false;
   _multisample_alpha_one_enabled = false;
@@ -476,11 +464,6 @@ reset() {
 
   _texgen_forced_normal = false;
 
-  // Antialiasing.
-  enable_line_smooth(false);
-  enable_point_smooth(false);
-  enable_multisample(true);
-
 #ifdef HAVE_CGGL
   _cg_shader = (CgShader *)NULL;
 #endif
@@ -508,6 +491,8 @@ reset() {
   _needs_tex_mat = false;
   _current_tex_gen = DCAST(TexGenAttrib, TexGenAttrib::make());
   _needs_tex_gen = false;
+  _antialias_mode = AntialiasAttrib::M_none;
+  _render_mode = RenderModeAttrib::M_filled;
 
   report_my_gl_errors();
 
@@ -770,6 +755,8 @@ draw_point(GeomPoint *geom, GeomContext *gc) {
   GLCAT.spam() << "draw_point()" << endl;
 #endif
 
+  setup_antialias_point();
+
   if (draw_display_list(gc)) {
     return;
   }
@@ -840,6 +827,8 @@ draw_line(GeomLine *geom, GeomContext *gc) {
   GLCAT.spam() << "draw_line()" << endl;
 #endif
 
+  setup_antialias_line();
+
   if (draw_display_list(gc)) {
     return;
   }
@@ -920,6 +909,8 @@ draw_linestrip(GeomLinestrip *geom, GeomContext *gc) {
   GLCAT.spam() << "draw_linestrip()" << endl;
 #endif
 
+  setup_antialias_line();
+
   if (draw_display_list(gc)) {
     return;
   }
@@ -1058,6 +1049,8 @@ draw_sprite(GeomSprite *geom, GeomContext *) {
   GLCAT.spam() << "draw_sprite()" << endl;
 #endif
 
+  setup_antialias_polygon();
+
   // get the array traversal set up.
   int nprims = geom->get_num_prims();
   if (nprims==0) {
@@ -1299,6 +1292,8 @@ draw_polygon(GeomPolygon *geom, GeomContext *gc) {
   GLCAT.spam() << "draw_polygon()" << endl;
 #endif
 
+  setup_antialias_polygon();
+
   if (draw_display_list(gc)) {
     return;
   }
@@ -1386,6 +1381,8 @@ draw_tri(GeomTri *geom, GeomContext *gc) {
   GLCAT.spam() << "draw_tri()" << endl;
 #endif
 
+  setup_antialias_polygon();
+
   if (draw_display_list(gc)) {
     return;
   }
@@ -1470,6 +1467,8 @@ draw_quad(GeomQuad *geom, GeomContext *gc) {
   GLCAT.spam() << "draw_quad()" << endl;
 #endif
 
+  setup_antialias_polygon();
+
   if (draw_display_list(gc)) {
     return;
   }
@@ -1553,6 +1552,8 @@ draw_tristrip(GeomTristrip *geom, GeomContext *gc) {
   GLCAT.spam() << "draw_tristrip()" << endl;
 #endif
 
+  setup_antialias_polygon();
+
   if (draw_display_list(gc)) {
     return;
   }
@@ -1663,6 +1664,8 @@ draw_trifan(GeomTrifan *geom, GeomContext *gc) {
   GLCAT.spam() << "draw_trifan()" << endl;
 #endif
 
+  setup_antialias_polygon();
+
   if (draw_display_list(gc)) {
     return;
   }
@@ -1768,6 +1771,8 @@ draw_sphere(GeomSphere *geom, GeomContext *gc) {
   GLCAT.spam() << "draw_sphere()" << endl;
 #endif
 
+  setup_antialias_polygon();
+
   if (draw_display_list(gc)) {
     return;
   }
@@ -2527,9 +2532,9 @@ issue_material(const MaterialAttrib *attrib) {
 ////////////////////////////////////////////////////////////////////
 void CLP(GraphicsStateGuardian)::
 issue_render_mode(const RenderModeAttrib *attrib) {
-  RenderModeAttrib::Mode mode = attrib->get_mode();
+  _render_mode = attrib->get_mode();
 
-  switch (mode) {
+  switch (_render_mode) {
   case RenderModeAttrib::M_filled:
     GLP(PolygonMode)(GL_FRONT_AND_BACK, GL_FILL);
     break;
@@ -2541,7 +2546,32 @@ issue_render_mode(const RenderModeAttrib *attrib) {
 
   default:
     GLCAT.error()
-      << "Unknown render mode " << (int)mode << endl;
+      << "Unknown render mode " << (int)_render_mode << endl;
+  }
+  report_my_gl_errors();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CLP(GraphicsStateGuardian)::issue_antialias
+//       Access: Public, Virtual
+//  Description:
+////////////////////////////////////////////////////////////////////
+void CLP(GraphicsStateGuardian)::
+issue_antialias(const AntialiasAttrib *attrib) {
+  _antialias_mode = attrib->get_mode();
+
+  if (_antialias_mode == AntialiasAttrib::M_best) {
+    // In this special mode, we must enable antialiasing on a
+    // case-by-case basis, because we enable it differently for
+    // polygons and for points and lines.
+
+  } else {
+    // Otherwise, explicitly enable or disable according to the bits
+    // that are set.
+    enable_line_smooth((_antialias_mode & AntialiasAttrib::M_line) != 0);
+    enable_point_smooth((_antialias_mode & AntialiasAttrib::M_point) != 0);
+    enable_polygon_smooth((_antialias_mode & AntialiasAttrib::M_polygon) != 0);
+    enable_multisample((_antialias_mode & AntialiasAttrib::M_multisample) != 0);
   }
   report_my_gl_errors();
 }

+ 12 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.h

@@ -30,6 +30,8 @@
 #include "texGenAttrib.h"
 #include "textureStage.h"
 #include "textureApplyAttrib.h"
+#include "antialiasAttrib.h"
+#include "renderModeAttrib.h"
 #include "pointerToArray.h"
 #include "fog.h"
 #include "graphicsWindow.h"
@@ -38,6 +40,7 @@
 #ifdef HAVE_CGGL
 #include "cgShader.h"
 #endif
+
 class PlaneNode;
 class Light;
 
@@ -112,6 +115,7 @@ public:
   virtual void issue_texture(const TextureAttrib *attrib);
   virtual void issue_material(const MaterialAttrib *attrib);
   virtual void issue_render_mode(const RenderModeAttrib *attrib);
+  virtual void issue_antialias(const AntialiasAttrib *);
   virtual void issue_rescale_normal(const RescaleNormalAttrib *attrib);
   virtual void issue_texture_apply(const TextureApplyAttrib *attrib);
   virtual void issue_color_write(const ColorWriteAttrib *attrib);
@@ -188,6 +192,11 @@ protected:
   INLINE void enable_multisample(bool val);
   INLINE void enable_line_smooth(bool val);
   INLINE void enable_point_smooth(bool val);
+  INLINE void enable_polygon_smooth(bool val);
+  INLINE void setup_antialias_line();
+  INLINE void setup_antialias_point();
+  INLINE void setup_antialias_polygon();
+
   INLINE void enable_scissor(bool val);
   INLINE void enable_stencil_test(bool val);
   INLINE void enable_multisample_alpha_one(bool val);
@@ -243,6 +252,7 @@ protected:
   bool _multisample_enabled;
   bool _line_smooth_enabled;
   bool _point_smooth_enabled;
+  bool _polygon_smooth_enabled;
   bool _scissor_enabled;
   bool _stencil_test_enabled;
   bool _multisample_alpha_one_enabled;
@@ -268,6 +278,8 @@ protected:
   bool _needs_tex_mat;
   CPT(TexGenAttrib) _current_tex_gen;
   bool _needs_tex_gen;
+  unsigned short _antialias_mode;
+  RenderModeAttrib::Mode _render_mode;
 
   CPT(DisplayRegion) _actual_display_region;
 #ifdef HAVE_CGGL

+ 2 - 0
panda/src/gsgbase/graphicsStateGuardianBase.h

@@ -60,6 +60,7 @@ class TextureAttrib;
 class LightAttrib;
 class MaterialAttrib;
 class RenderModeAttrib;
+class AntialiasAttrib;
 class RescaleNormalAttrib;
 class ColorBlendAttrib;
 class TextureApplyAttrib;
@@ -187,6 +188,7 @@ public:
   virtual void issue_light(const LightAttrib *) { }
   virtual void issue_material(const MaterialAttrib *) { }
   virtual void issue_render_mode(const RenderModeAttrib *) { }
+  virtual void issue_antialias(const AntialiasAttrib *) { }
   virtual void issue_rescale_normal(const RescaleNormalAttrib *) { }
   virtual void issue_texture_apply(const TextureApplyAttrib *) { }
   virtual void issue_color_write(const ColorWriteAttrib *) { }

+ 3 - 0
panda/src/pgraph/Sources.pp

@@ -12,6 +12,7 @@
     accumulatedAttribs.I accumulatedAttribs.h \
     alphaTestAttrib.I alphaTestAttrib.h \  
     ambientLight.I ambientLight.h \
+    antialiasAttrib.I antialiasAttrib.h \
     auxSceneData.I auxSceneData.h \
     bamFile.I bamFile.h \
     billboardEffect.I billboardEffect.h \
@@ -106,6 +107,7 @@
     accumulatedAttribs.cxx \
     alphaTestAttrib.cxx \  
     ambientLight.cxx \
+    antialiasAttrib.cxx \
     auxSceneData.cxx \
     bamFile.cxx \
     billboardEffect.cxx \
@@ -198,6 +200,7 @@
     accumulatedAttribs.I accumulatedAttribs.h \
     alphaTestAttrib.I alphaTestAttrib.h \  
     ambientLight.I ambientLight.h \
+    antialiasAttrib.I antialiasAttrib.h \
     auxSceneData.I auxSceneData.h \
     bamFile.I bamFile.h \
     billboardEffect.I billboardEffect.h \

+ 40 - 0
panda/src/pgraph/antialiasAttrib.I

@@ -0,0 +1,40 @@
+// Filename: antialiasAttrib.I
+// Created by:  drose (26Jan05)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: AntialiasAttrib::Constructor
+//       Access: Private
+//  Description: Use AntialiasAttrib::make() to construct a new
+//               AntialiasAttrib object.
+////////////////////////////////////////////////////////////////////
+INLINE AntialiasAttrib::
+AntialiasAttrib(unsigned short mode) :
+  _mode(mode)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AntialiasAttrib::get_mode
+//       Access: Published
+//  Description: Returns the render mode.
+////////////////////////////////////////////////////////////////////
+INLINE unsigned short AntialiasAttrib::
+get_mode() const {
+  return _mode;
+}

+ 235 - 0
panda/src/pgraph/antialiasAttrib.cxx

@@ -0,0 +1,235 @@
+// Filename: antialiasAttrib.cxx
+// Created by:  drose (26Jan05)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "antialiasAttrib.h"
+#include "graphicsStateGuardianBase.h"
+#include "dcast.h"
+#include "bamReader.h"
+#include "bamWriter.h"
+#include "datagram.h"
+#include "datagramIterator.h"
+
+TypeHandle AntialiasAttrib::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: AntialiasAttrib::make
+//       Access: Published, Static
+//  Description: Constructs a new AntialiasAttrib object.
+//
+//               The mode should be either M_none, M_best, or a union
+//               of any or all of M_point, M_line, M_polygon, and
+//               M_multisample.
+//
+//               If M_none is specified, no antialiasing is performed.  
+//
+//               If M_best is specified, M_multisample is selected if
+//               it is available, otherwise M_polygon is selected,
+//               unless drawing lines or points, in which case M_line
+//               or M_point is selected (these two generally produce
+//               better results than M_multisample)
+//
+//               In the explicit form, it enables all of the specified
+//               multisample modes.
+////////////////////////////////////////////////////////////////////
+CPT(RenderAttrib) AntialiasAttrib::
+make(unsigned short mode) {
+  AntialiasAttrib *attrib = new AntialiasAttrib(mode);
+  return return_new(attrib);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AntialiasAttrib::issue
+//       Access: Public, Virtual
+//  Description: Calls the appropriate method on the indicated GSG
+//               to issue the graphics commands appropriate to the
+//               given attribute.  This is normally called
+//               (indirectly) only from
+//               GraphicsStateGuardian::set_state() or modify_state().
+////////////////////////////////////////////////////////////////////
+void AntialiasAttrib::
+issue(GraphicsStateGuardianBase *gsg) const {
+  gsg->issue_antialias(this);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AntialiasAttrib::output
+//       Access: Public, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void AntialiasAttrib::
+output(ostream &out) const {
+  out << get_type() << ":";
+  if (_mode == M_none) {
+    out << " none";
+
+  } else if (_mode == M_best) {
+    out << " best";
+
+  } else {
+    char sep = ' ';
+    if ((_mode & M_point) != 0) {
+      out << sep << "point";
+      sep = '|';
+    }
+    if ((_mode & M_line) != 0) {
+      out << sep << "line";
+      sep = '|';
+    }
+    if ((_mode & M_polygon) != 0) {
+      out << sep << "polygon";
+      sep = '|';
+    }
+    if ((_mode & M_best) != 0) {
+      out << sep << "best";
+      sep = '|';
+    }
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AntialiasAttrib::compare_to_impl
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by derived AntialiasAttrib
+//               types to return a unique number indicating whether
+//               this AntialiasAttrib is equivalent to the other one.
+//
+//               This should return 0 if the two AntialiasAttrib objects
+//               are equivalent, a number less than zero if this one
+//               should be sorted before the other one, and a number
+//               greater than zero otherwise.
+//
+//               This will only be called with two AntialiasAttrib
+//               objects whose get_type() functions return the same.
+////////////////////////////////////////////////////////////////////
+int AntialiasAttrib::
+compare_to_impl(const RenderAttrib *other) const {
+  const AntialiasAttrib *ta;
+  DCAST_INTO_R(ta, other, 0);
+  if (_mode != ta->_mode) {
+    return (int)_mode - (int)ta->_mode;
+  }
+  return 0;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AntialiasAttrib::compose_impl
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by derived RenderAttrib
+//               types to specify how two consecutive RenderAttrib
+//               objects of the same type interact.
+//
+//               This should return the result of applying the other
+//               RenderAttrib to a node in the scene graph below this
+//               RenderAttrib, which was already applied.  In most
+//               cases, the result is the same as the other
+//               RenderAttrib (that is, a subsequent RenderAttrib
+//               completely replaces the preceding one).  On the other
+//               hand, some kinds of RenderAttrib (for instance,
+//               ColorTransformAttrib) might combine in meaningful
+//               ways.
+////////////////////////////////////////////////////////////////////
+CPT(RenderAttrib) AntialiasAttrib::
+compose_impl(const RenderAttrib *other) const {
+  const AntialiasAttrib *ta;
+  DCAST_INTO_R(ta, other, 0);
+  if (ta->get_mode() == M_none || ta->get_mode() == M_best ||
+      get_mode() == M_none || get_mode() == M_best) {
+    // These two special modes don't combine: if one of these modes is
+    // involved, the lower attrib wins.
+    return ta;
+  }
+
+  // Otherwise, both attribs reflect an explicit setting.  In that
+  // case, these modes combine in the sensible way, as a union of
+  // bits.
+  return make(get_mode() | ta->get_mode());
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AntialiasAttrib::make_default_impl
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by derived AntialiasAttrib
+//               types to specify what the default property for a
+//               AntialiasAttrib of this type should be.
+//
+//               This should return a newly-allocated AntialiasAttrib of
+//               the same type that corresponds to whatever the
+//               standard default for this kind of AntialiasAttrib is.
+////////////////////////////////////////////////////////////////////
+RenderAttrib *AntialiasAttrib::
+make_default_impl() const {
+  return new AntialiasAttrib(M_none);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AntialiasAttrib::register_with_read_factory
+//       Access: Public, Static
+//  Description: Tells the BamReader how to create objects of type
+//               AntialiasAttrib.
+////////////////////////////////////////////////////////////////////
+void AntialiasAttrib::
+register_with_read_factory() {
+  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AntialiasAttrib::write_datagram
+//       Access: Public, Virtual
+//  Description: Writes the contents of this object to the datagram
+//               for shipping out to a Bam file.
+////////////////////////////////////////////////////////////////////
+void AntialiasAttrib::
+write_datagram(BamWriter *manager, Datagram &dg) {
+  RenderAttrib::write_datagram(manager, dg);
+
+  dg.add_uint16(_mode);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AntialiasAttrib::make_from_bam
+//       Access: Protected, Static
+//  Description: This function is called by the BamReader's factory
+//               when a new object of type AntialiasAttrib is encountered
+//               in the Bam file.  It should create the AntialiasAttrib
+//               and extract its information from the file.
+////////////////////////////////////////////////////////////////////
+TypedWritable *AntialiasAttrib::
+make_from_bam(const FactoryParams &params) {
+  AntialiasAttrib *attrib = new AntialiasAttrib(M_none);
+  DatagramIterator scan;
+  BamReader *manager;
+
+  parse_params(params, scan, manager);
+  attrib->fillin(scan, manager);
+
+  return attrib;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AntialiasAttrib::fillin
+//       Access: Protected
+//  Description: This internal function is called by make_from_bam to
+//               read in all of the relevant data from the BamFile for
+//               the new AntialiasAttrib.
+////////////////////////////////////////////////////////////////////
+void AntialiasAttrib::
+fillin(DatagramIterator &scan, BamReader *manager) {
+  RenderAttrib::fillin(scan, manager);
+
+  _mode = scan.get_uint16();
+}

+ 93 - 0
panda/src/pgraph/antialiasAttrib.h

@@ -0,0 +1,93 @@
+// Filename: antialiasAttrib.h
+// Created by:  drose (26Jan05)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef ANTIALIASATTRIB_H
+#define ANTIALIASATTRIB_H
+
+#include "pandabase.h"
+
+#include "renderAttrib.h"
+
+class FactoryParams;
+
+////////////////////////////////////////////////////////////////////
+//       Class : AntialiasAttrib
+// Description : Specifies whether or how to enable antialiasing, if
+//               supported by the backend renderer.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA AntialiasAttrib : public RenderAttrib {
+PUBLISHED:
+  enum Mode {
+    M_none        = 0x0000,
+    M_point       = 0x0001,
+    M_line        = 0x0002,
+    M_polygon     = 0x0004,
+    M_multisample = 0x0008,
+    M_best        = 0x001f,
+  };
+
+private:
+  INLINE AntialiasAttrib(unsigned short mode);
+
+PUBLISHED:
+  static CPT(RenderAttrib) make(unsigned short mode);
+
+  INLINE unsigned short get_mode() const;
+
+public:
+  virtual void issue(GraphicsStateGuardianBase *gsg) const;
+  virtual void output(ostream &out) const;
+
+protected:
+  virtual int compare_to_impl(const RenderAttrib *other) const;
+  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
+  virtual RenderAttrib *make_default_impl() const;
+
+private:
+  unsigned short _mode;
+
+public:
+  static void register_with_read_factory();
+  virtual void write_datagram(BamWriter *manager, Datagram &dg);
+
+protected:
+  static TypedWritable *make_from_bam(const FactoryParams &params);
+  void fillin(DatagramIterator &scan, BamReader *manager);
+  
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    RenderAttrib::init_type();
+    register_type(_type_handle, "AntialiasAttrib",
+                  RenderAttrib::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "antialiasAttrib.I"
+
+#endif
+

+ 3 - 0
panda/src/pgraph/config_pgraph.cxx

@@ -20,6 +20,7 @@
 
 #include "alphaTestAttrib.h"
 #include "ambientLight.h"
+#include "antialiasAttrib.h"
 #include "auxSceneData.h"
 #include "billboardEffect.h"
 #include "camera.h"
@@ -218,6 +219,7 @@ init_libpgraph() {
 
   AlphaTestAttrib::init_type();
   AmbientLight::init_type();
+  AntialiasAttrib::init_type();
   AuxSceneData::init_type();
   BillboardEffect::init_type();
   Camera::init_type();
@@ -296,6 +298,7 @@ init_libpgraph() {
 
   AlphaTestAttrib::register_with_read_factory();
   AmbientLight::register_with_read_factory();
+  AntialiasAttrib::register_with_read_factory();
   BillboardEffect::register_with_read_factory();
   Camera::register_with_read_factory();
   ClipPlaneAttrib::register_with_read_factory();

+ 68 - 12
panda/src/pgraph/nodePath.cxx

@@ -39,6 +39,7 @@
 #include "compassEffect.h"
 #include "showBoundsEffect.h"
 #include "transparencyAttrib.h"
+#include "antialiasAttrib.h"
 #include "texProjectorEffect.h"
 #include "lensNode.h"
 #include "materialPool.h"
@@ -4178,14 +4179,9 @@ has_compass() const {
 //               for alpha color to be rendered partially transparent.
 ////////////////////////////////////////////////////////////////////
 void NodePath::
-set_transparency(bool transparency, int priority) {
+set_transparency(TransparencyAttrib::Mode mode, int priority) {
   nassertv_always(!is_empty());
 
-  TransparencyAttrib::Mode mode =
-    transparency ?
-    TransparencyAttrib::M_alpha :
-    TransparencyAttrib::M_none;
-
   node()->set_attrib(TransparencyAttrib::make(mode), priority);
 }
 
@@ -4224,25 +4220,85 @@ has_transparency() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: NodePath::get_transparency
 //       Access: Published
-//  Description: Returns true if transparent rendering has been
+//  Description: Returns the transparent rendering that has been
 //               specifically set on this node via set_transparency(), or
-//               false if nontransparent rendering has been specifically
+//               M_none if nontransparent rendering has been specifically
 //               set, or if nothing has been specifically set.  See
 //               also has_transparency().  This does not necessarily
 //               imply that the geometry will or will not be rendered
 //               transparent, as there may be other nodes that override.
 ////////////////////////////////////////////////////////////////////
-bool NodePath::
+TransparencyAttrib::Mode NodePath::
 get_transparency() const {
-  nassertr_always(!is_empty(), false);
+  nassertr_always(!is_empty(), TransparencyAttrib::M_none);
   const RenderAttrib *attrib =
     node()->get_attrib(TransparencyAttrib::get_class_type());
   if (attrib != (const RenderAttrib *)NULL) {
     const TransparencyAttrib *ta = DCAST(TransparencyAttrib, attrib);
-    return (ta->get_mode() != TransparencyAttrib::M_none);
+    return ta->get_mode();
   }
 
-  return false;
+  return TransparencyAttrib::M_none;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::set_antialias
+//       Access: Published
+//  Description: Specifies the antialiasing type that should be
+//               applied at this node and below.  See AntialiasAttrib.
+////////////////////////////////////////////////////////////////////
+void NodePath::
+set_antialias(unsigned short mode, int priority) {
+  nassertv_always(!is_empty());
+
+  node()->set_attrib(AntialiasAttrib::make(mode), priority);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::clear_antialias
+//       Access: Published
+//  Description: Completely removes any antialias setting that
+//               may have been set on this node via set_antialias().
+////////////////////////////////////////////////////////////////////
+void NodePath::
+clear_antialias() {
+  nassertv_always(!is_empty());
+  node()->clear_attrib(AntialiasAttrib::get_class_type());
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::has_antialias
+//       Access: Published
+//  Description: Returns true if an antialias setting has been
+//               explicitly mode on this particular node via
+//               set_antialias().  If this returns true, then
+//               get_antialias() may be called to determine what the
+//               setting was.
+////////////////////////////////////////////////////////////////////
+bool NodePath::
+has_antialias() const {
+  nassertr_always(!is_empty(), false);
+  return node()->has_attrib(AntialiasAttrib::get_class_type());
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::get_antialias
+//       Access: Published
+//  Description: Returns the antialias setting that has been
+//               specifically set on this node via set_antialias(), or
+//               M_none if no setting has been made.
+////////////////////////////////////////////////////////////////////
+unsigned short NodePath::
+get_antialias() const {
+  nassertr_always(!is_empty(), AntialiasAttrib::M_none);
+  const RenderAttrib *attrib =
+    node()->get_attrib(AntialiasAttrib::get_class_type());
+  if (attrib != (const RenderAttrib *)NULL) {
+    const AntialiasAttrib *ta = DCAST(AntialiasAttrib, attrib);
+    return ta->get_mode();
+  }
+
+  return AntialiasAttrib::M_none;
 }
 
 

+ 8 - 2
panda/src/pgraph/nodePath.h

@@ -25,6 +25,7 @@
 #include "renderState.h"
 #include "transformState.h"
 #include "texGenAttrib.h"
+#include "transparencyAttrib.h"
 #include "nodePathComponent.h"
 
 #include "pointerTo.h"
@@ -636,10 +637,15 @@ PUBLISHED:
   void clear_compass();
   bool has_compass() const;
 
-  void set_transparency(bool transparency, int priority = 0);
+  void set_transparency(TransparencyAttrib::Mode mode, int priority = 0);
   void clear_transparency();
   bool has_transparency() const;
-  bool get_transparency() const;
+  TransparencyAttrib::Mode get_transparency() const;
+
+  void set_antialias(unsigned short mode, int priority = 0);
+  void clear_antialias();
+  bool has_antialias() const;
+  unsigned short get_antialias() const;
 
   INLINE void adjust_all_priorities(int adjustment);
 

+ 1 - 0
panda/src/pgraph/pgraph_composite1.cxx

@@ -1,5 +1,6 @@
 #include "accumulatedAttribs.cxx"
 #include "ambientLight.cxx"
+#include "antialiasAttrib.cxx"
 #include "auxSceneData.cxx"
 #include "bamFile.cxx"
 #include "billboardEffect.cxx"

+ 5 - 2
panda/src/pgraph/transparencyAttrib.h

@@ -40,8 +40,11 @@ class FactoryParams;
 class EXPCL_PANDA TransparencyAttrib : public RenderAttrib {
 PUBLISHED:
   enum Mode {
-    M_none,             // No transparency.
-    M_alpha,            // Normal transparency, panda will sort back-to-front.
+    // The first two should be specifically 0 and 1, for historical
+    // reasons (NodePath::set_transparency() used to accept a boolean
+    // value, which corresponded to M_none or M_alpha).
+    M_none = 0,         // No transparency.
+    M_alpha = 1,        // Normal transparency, panda will sort back-to-front.
     M_notused,          // Unused placeholder.  Do not use this.
     M_multisample,      // Uses ms buffer, alpha values modified to 1.0.
     M_multisample_mask, // Uses ms buffer, alpha values not modified.