Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/shader/outlineShader.cxx

Go to the documentation of this file.
00001 // Filename: outlineShader.cxx
00002 // Created by:  mike (09Jan97)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 #include "outlineShader.h"
00019 #include <lightTransition.h>
00020 #include <dftraverser.h>
00021 #include <depthTestTransition.h>
00022 #include <graphicsStateGuardian.h>
00023 #include <attribTraverser.h>
00024 #include <renderModeTransition.h>
00025 #include <cullFaceTransition.h>
00026 #include <colorTransition.h>
00027 #include <linesmoothTransition.h>
00028 #include <directRenderTraverser.h>
00029 #include <renderRelation.h>
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 // Static variables
00033 ////////////////////////////////////////////////////////////////////
00034 TypeHandle OutlineShader::_type_handle;
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //     Function: OutlineShader::constructor
00038 //       Access:
00039 //  Description:
00040 ////////////////////////////////////////////////////////////////////
00041 OutlineShader::OutlineShader(void) : Shader() {
00042   set_color(Colorf(0, 0, 0, 1));
00043 }
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //     Function: OutlineShader::constructor
00047 //       Access:
00048 //  Description:
00049 ////////////////////////////////////////////////////////////////////
00050 OutlineShader::OutlineShader(const Colorf &color) : Shader() {
00051   set_color(color);
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: OutlineShader::config
00056 //       Access:
00057 //  Description:
00058 ////////////////////////////////////////////////////////////////////
00059 void OutlineShader::config(void) {
00060   Configurable::config();
00061 }
00062 
00063 ////////////////////////////////////////////////////////////////////
00064 //     Function: OutlineShader::apply
00065 //       Access:
00066 //  Description:
00067 ////////////////////////////////////////////////////////////////////
00068 void OutlineShader::
00069 apply(Node *node, const AllAttributesWrapper &init_state,
00070       const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg) {
00071   Shader::apply(node, init_state, net_trans, gsg);
00072   DirectRenderTraverser drt(gsg, RenderRelation::get_class_type());
00073 
00074   // If the node is un-textured, we need to render it once first (since
00075   // the shader transition won't have drawn it unless it is textured
00076   if (!is_textured(node, init_state)) {
00077     gsg->render_subgraph(&drt, node, init_state, net_trans);
00078   }
00079 
00080   // Copy the transition wrapper so we can modify it freely.
00081   AllTransitionsWrapper trans(net_trans);
00082 
00083   // Turn lighting off
00084   trans.set_transition(new LightTransition(LightTransition::all_off()));
00085 
00086   // Enable line drawing
00087   RenderModeTransition *rm =
00088     new RenderModeTransition(RenderModeProperty::M_wireframe, 2.0);
00089   trans.set_transition(rm);
00090 
00091   // Enable line smooth
00092   //  LinesmoothTransition *lsm = new LinesmoothTransition;
00093   //  trans.set_transition(lsm);
00094 
00095   // Draw shared edges
00096   DepthTestTransition *dta =
00097     new DepthTestTransition(DepthTestProperty::M_less_equal);
00098   trans.set_transition(dta);
00099 
00100   // Draw back facing edges only
00101   CullFaceTransition *cf =
00102     new CullFaceTransition(CullFaceProperty::M_cull_counter_clockwise);
00103   trans.set_transition(cf);
00104 
00105   // Set the outline color
00106   ColorTransition *c = new ColorTransition(_color);
00107   trans.set_transition(c);
00108 
00109   gsg->render_subgraph(&drt, node, init_state, trans);
00110 }

Generated on Fri May 2 00:43:58 2003 for Panda by doxygen1.3