Panda3D
baseParticleRenderer.cxx
1 // Filename: baseParticleRenderer.cxx
2 // Created by: charles (20Jun00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "pandabase.h"
16 
17 #include "baseParticleRenderer.h"
18 #include "transparencyAttrib.h"
19 #include "colorAttrib.h"
20 #include "compassEffect.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function : BaseParticleRender::BaseParticleRenderer
24 // Access : Published
25 // Description : Default Constructor
26 ////////////////////////////////////////////////////////////////////
27 BaseParticleRenderer::
28 BaseParticleRenderer(ParticleRendererAlphaMode alpha_mode) :
29  _alpha_mode(PR_NOT_INITIALIZED_YET) {
30  _render_node = new GeomNode("BaseParticleRenderer render node");
31  _render_node_path = NodePath(_render_node);
32 
33  _user_alpha = 1.0f;
34  _ignore_scale = false;
35 
36  update_alpha_mode(alpha_mode);
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function : BaseParticleRender::BaseParticleRenderer
41 // Access : Published
42 // Description : Copy Constructor
43 ////////////////////////////////////////////////////////////////////
44 BaseParticleRenderer::
45 BaseParticleRenderer(const BaseParticleRenderer& copy) :
46  _alpha_mode(PR_ALPHA_NONE) {
47  _render_node = new GeomNode("BaseParticleRenderer render node");
48  _render_node_path = NodePath(_render_node);
49 
50  _user_alpha = copy._user_alpha;
51  set_ignore_scale(copy._ignore_scale);
52 
53  update_alpha_mode(copy._alpha_mode);
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function : BaseParticleRender::~BaseParticleRenderer
58 // Access : Published
59 // Description : Destructor
60 ////////////////////////////////////////////////////////////////////
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function : BaseParticleRender::set_ignore_scale
67 // Access : Published
68 // Description : Sets the "ignore scale" flag. When this is true,
69 // particles will be drawn as if they had no scale,
70 // regardless of whatever scale might be inherited from
71 // above the render node in the scene graph.
72 //
73 // This flag is mainly useful to support legacy code
74 // that was written for a very early version of Panda,
75 // whose sprite particle renderer had a bug that
76 // incorrectly ignored the inherited scale.
77 ////////////////////////////////////////////////////////////////////
79 set_ignore_scale(bool ignore_scale) {
80  _ignore_scale = ignore_scale;
81 
82  if (_ignore_scale) {
83  _render_node->set_effect(CompassEffect::make(NodePath(), CompassEffect::P_scale));
84  } else {
85  _render_node->clear_effect(CompassEffect::get_class_type());
86  }
87 }
88 
89 ////////////////////////////////////////////////////////////////////
90 // Function : BaseParticleRender::output
91 // Access : Published
92 // Description : Write a string representation of this instance to
93 // <out>.
94 ////////////////////////////////////////////////////////////////////
96 output(ostream &out) const {
97  #ifndef NDEBUG //[
98  out<<"BaseParticleRenderer";
99  #endif //] NDEBUG
100 }
101 
102 ////////////////////////////////////////////////////////////////////
103 // Function : BaseParticleRender::write
104 // Access : Published
105 // Description : Write a string representation of this instance to
106 // <out>.
107 ////////////////////////////////////////////////////////////////////
109 write(ostream &out, int indent) const {
110  #ifndef NDEBUG //[
111  out.width(indent); out<<""; out<<"BaseParticleRenderer:\n";
112  out.width(indent+2); out<<""; out<<"_render_node "<<_render_node_path<<"\n";
113  out.width(indent+2); out<<""; out<<"_user_alpha "<<_user_alpha<<"\n";
114  //ReferenceCount::write(out, indent+2);
115  #endif //] NDEBUG
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function : BaseParticleRender::update_alpha_state
120 // Access : Private
121 // Description : handles the base class part of alpha updating.
122 ////////////////////////////////////////////////////////////////////
123 void BaseParticleRenderer::
124 update_alpha_mode(ParticleRendererAlphaMode am) {
125  if (_alpha_mode == am)
126  return;
127 
128  if ((am == PR_ALPHA_NONE) && (_alpha_mode != PR_ALPHA_NONE))
129  disable_alpha();
130  else if ((am != PR_ALPHA_NONE) && (_alpha_mode == PR_ALPHA_NONE))
131  enable_alpha();
132 
133  _alpha_mode = am;
134 }
135 
136 ////////////////////////////////////////////////////////////////////
137 // Function : BaseParticleRender::enable_alpha
138 // Access : Private
139 // Description : Builds an intermediate node and transition that
140 // enables alpha channeling.
141 ////////////////////////////////////////////////////////////////////
142 void BaseParticleRenderer::
143 enable_alpha() {
144  _render_state = RenderState::make(TransparencyAttrib::make(TransparencyAttrib::M_alpha),
145  ColorAttrib::make_vertex());
146 }
147 
148 ////////////////////////////////////////////////////////////////////
149 // Function : BaseParticleRender::disable_alpha
150 // Access : Private
151 // Description : kills the intermediate alpha node/arc
152 ////////////////////////////////////////////////////////////////////
153 void BaseParticleRenderer::
154 disable_alpha() {
155  _render_state = RenderState::make(TransparencyAttrib::make(TransparencyAttrib::M_none),
156  ColorAttrib::make_vertex());
157 }
virtual ~BaseParticleRenderer()
Destructor.
Pure virtual particle renderer base class.
void set_ignore_scale(bool ignore_scale)
Sets the "ignore scale" flag.
virtual void output(ostream &out) const
Write a string representation of this instance to <out>.
virtual void write(ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37