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

panda/src/shader/spheretexShader.cxx

Go to the documentation of this file.
00001 // Filename: spheretexShader.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 "spheretexShader.h"
00019 #include "config_shader.h"
00020 
00021 #include <lightTransition.h>
00022 #include <textureTransition.h>
00023 #include <textureTransition.h>
00024 #include <texMatrixTransition.h>
00025 #include <depthTestTransition.h>
00026 #include <texGenTransition.h>
00027 #include <textureApplyTransition.h>
00028 #include <colorBlendTransition.h>
00029 #include <get_rel_pos.h>
00030 #include <dftraverser.h>
00031 #include <graphicsStateGuardian.h>
00032 #include <colorBlendTransition.h>
00033 #include <attribTraverser.h>
00034 #include <directRenderTraverser.h>
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 // Static variables
00038 ////////////////////////////////////////////////////////////////////
00039 TypeHandle SpheretexShader::_type_handle;
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: SpheretexShader::constructor
00043 //       Access:
00044 //  Description:
00045 ////////////////////////////////////////////////////////////////////
00046 SpheretexShader::SpheretexShader(Texture* texture) : Shader()
00047 {
00048   set_texture(texture);
00049   _blend_mode = ColorBlendProperty::M_multiply_add;
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: SpheretexShader::config
00054 //       Access:
00055 //  Description:
00056 ////////////////////////////////////////////////////////////////////
00057 void SpheretexShader::config(void)
00058 {
00059   Configurable::config();
00060 
00061   nassertv(_texture != (Texture *)NULL);
00062   _texture->set_minfilter(Texture::FT_linear);
00063   _texture->set_magfilter(Texture::FT_linear);
00064   _texture->set_wrapu(Texture::WM_clamp);
00065   _texture->set_wrapv(Texture::WM_clamp);
00066 }
00067 
00068 ////////////////////////////////////////////////////////////////////
00069 //     Function: SpheretexShader::apply
00070 //       Access:
00071 //  Description:
00072 ////////////////////////////////////////////////////////////////////
00073 void SpheretexShader::
00074 apply(Node *node, const AllAttributesWrapper &init_state,
00075       const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg) {
00076 
00077   Shader::apply(node, init_state, net_trans, gsg);
00078 
00079   // Copy the transition wrapper so we can modify it freely.
00080   AllTransitionsWrapper trans(net_trans);
00081 
00082   // Create the texture generation transition
00083   TexGenTransition *tg = new TexGenTransition;
00084   tg->set_sphere_map();
00085   trans.set_transition(tg);
00086 
00087   // Create the texture transition
00088   nassertv(_texture != (Texture *)NULL);
00089   TextureTransition *t = new TextureTransition;
00090   t->set_on(_texture);
00091   t->set_priority(_priority);
00092   trans.set_transition(t);
00093 
00094   if (_viz != (Shader::Visualize*)0L)
00095     _viz->DisplayTexture(_texture, this);
00096 
00097   // Clear the texture matrix transition
00098   trans.set_transition(new TexMatrixTransition(LMatrix4f::ident_mat()));
00099 
00100   // Turn lighting off - we still want to issue normals, though
00101   trans.set_transition(new LightTransition(LightTransition::all_off()));
00102   gsg->enable_normals(true);
00103 
00104   // Do some extra work if we're doing the 2-pass version (e.g. the
00105   // object we are shading is textured)
00106   if (_multipass_on) {
00107     // Set a color blend mode that assumes this is a second pass over
00108     // textured geometry
00109     ColorBlendTransition *cb =
00110       new ColorBlendTransition(_blend_mode);
00111     trans.set_transition(cb);
00112 
00113     TextureApplyTransition *ta =
00114       new TextureApplyTransition(TextureApplyProperty::M_decal);
00115     trans.set_transition(ta);
00116 
00117     // Set the depth test to M_equal (? Or should this be M_none?)
00118     DepthTestTransition *dta =
00119       new DepthTestTransition(DepthTestProperty::M_equal);
00120     trans.set_transition(dta);
00121   }
00122 
00123   // Render the node with the new transitions.
00124   DirectRenderTraverser drt(gsg, RenderRelation::get_class_type());
00125   gsg->render_subgraph(&drt, node, init_state, trans);
00126 
00127   gsg->enable_normals(false);
00128 }
00129 
00130 
00131 

Generated on Fri May 2 00:44:05 2003 for Panda by doxygen1.3