Panda3D
stencilAttrib.h
1 // Filename: stencilAttrib.h
2 // Created by: aignacio (18May06)
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 #ifndef STENCILATTRIB_H
16 #define STENCILATTRIB_H
17 
18 #include "pandabase.h"
19 #include "renderAttrib.h"
20 
21 class FactoryParams;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Class : StencilAttrib
25 // Description : A StencilAttrib is a collection of all stencil render
26 // states. The render states in a StencilAttrib are
27 // read-only. A StencilAttrib is created with make or
28 // make_2_sided. To determine if two sided stencil is
29 // supported, call the function GraphicsStateGuardian::
30 // get_supports_two_sided_stencil.
31 ////////////////////////////////////////////////////////////////////
32 class EXPCL_PANDA_PGRAPH StencilAttrib : public RenderAttrib {
33 
34 private:
35  StencilAttrib();
36 
37 PUBLISHED:
38  // enums are duplicated here from class StencilRenderStates for use in Python
39  enum StencilRenderState {
40  SRS_front_comparison_function,
41  SRS_front_stencil_fail_operation,
42  SRS_front_stencil_pass_z_fail_operation,
43  SRS_front_stencil_pass_z_pass_operation,
44 
45  SRS_reference,
46  SRS_read_mask,
47  SRS_write_mask,
48 
49  SRS_back_comparison_function,
50  SRS_back_stencil_fail_operation,
51  SRS_back_stencil_pass_z_fail_operation,
52  SRS_back_stencil_pass_z_pass_operation,
53 
54  SRS_clear,
55  SRS_clear_value,
56 
57  SRS_total,
58  };
59 
60  // Exists purely for backward compatibility.
61  enum StencilComparisonFunction {
62  SCF_never = M_never,
63  SCF_less_than = M_less,
64  SCF_equal = M_equal,
65  SCF_less_than_or_equal = M_less_equal,
66  SCF_greater_than = M_greater,
67  SCF_not_equal = M_not_equal,
68  SCF_greater_than_or_equal = M_greater_equal,
69  SCF_always = M_always,
70  };
71 
72  enum StencilOperation {
73  SO_keep,
74  SO_zero,
75  SO_replace,
76  SO_increment,
77  SO_decrement,
78  SO_invert,
79  SO_increment_saturate,
80  SO_decrement_saturate,
81  };
82 
83  static CPT(RenderAttrib) make_off();
84  static CPT(RenderAttrib) make_default();
85 
86  static CPT(RenderAttrib) make(
87  bool front_enable,
88  PandaCompareFunc front_comparison_function,
89  StencilOperation stencil_fail_operation,
90  StencilOperation stencil_pass_z_fail_operation,
91  StencilOperation front_stencil_pass_z_pass_operation,
92  unsigned int reference,
93  unsigned int read_mask,
94  unsigned int write_mask);
95 
96  static CPT(RenderAttrib) make_2_sided(
97  bool front_enable,
98  bool back_enable,
99  PandaCompareFunc front_comparison_function,
100  StencilOperation stencil_fail_operation,
101  StencilOperation stencil_pass_z_fail_operation,
102  StencilOperation front_stencil_pass_z_pass_operation,
103  unsigned int reference,
104  unsigned int read_mask,
105  unsigned int write_mask,
106  PandaCompareFunc back_comparison_function,
107  StencilOperation back_stencil_fail_operation,
108  StencilOperation back_stencil_pass_z_fail_operation,
109  StencilOperation back_stencil_pass_z_pass_operation);
110 
111  static CPT(RenderAttrib) make_with_clear(
112  bool front_enable,
113  PandaCompareFunc front_comparison_function,
114  StencilOperation stencil_fail_operation,
115  StencilOperation stencil_pass_z_fail_operation,
116  StencilOperation front_stencil_pass_z_pass_operation,
117  unsigned int reference,
118  unsigned int read_mask,
119  unsigned int write_mask,
120  bool clear,
121  unsigned int clear_value);
122 
123  static CPT(RenderAttrib) make_2_sided_with_clear(
124  bool front_enable,
125  bool back_enable,
126  PandaCompareFunc front_comparison_function,
127  StencilOperation stencil_fail_operation,
128  StencilOperation stencil_pass_z_fail_operation,
129  StencilOperation front_stencil_pass_z_pass_operation,
130  unsigned int reference,
131  unsigned int read_mask,
132  unsigned int write_mask,
133  PandaCompareFunc back_comparison_function,
134  StencilOperation back_stencil_fail_operation,
135  StencilOperation back_stencil_pass_z_fail_operation,
136  StencilOperation back_stencil_pass_z_pass_operation,
137  bool clear,
138  unsigned int clear_value);
139 
140  INLINE unsigned int get_render_state(StencilRenderState render_state_identifier) const;
141 
142 public:
143  static const char *stencil_render_state_name_array [SRS_total];
144 
145  virtual void output(ostream &out) const;
146 
147 protected:
148  virtual int compare_to_impl(const RenderAttrib *other) const;
149  virtual size_t get_hash_impl() const;
150 
151 private:
152  unsigned int _stencil_render_states [SRS_total];
153 
154 PUBLISHED:
155  static int get_class_slot() {
156  return _attrib_slot;
157  }
158  virtual int get_slot() const {
159  return get_class_slot();
160  }
161 
162 public:
163  static void register_with_read_factory();
164  virtual void write_datagram(BamWriter *manager, Datagram &dg);
165 
166 protected:
167  static TypedWritable *make_from_bam(const FactoryParams &params);
168  void fillin(DatagramIterator &scan, BamReader *manager);
169 
170 public:
171  static TypeHandle get_class_type() {
172  return _type_handle;
173  }
174  static void init_type() {
175  RenderAttrib::init_type();
176  register_type(_type_handle, "StencilAttrib",
177  RenderAttrib::get_class_type());
178  _attrib_slot = register_slot(_type_handle, 100, make_default);
179  }
180  virtual TypeHandle get_type() const {
181  return get_class_type();
182  }
183  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
184 
185 private:
186  static TypeHandle _type_handle;
187  static int _attrib_slot;
188 };
189 
190 #include "stencilAttrib.I"
191 
192 #endif
193 
static int register_slot(TypeHandle type_handle, int sort, RenderAttribRegistry::MakeDefaultFunc *make_default_func)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
Definition: renderAttrib.I:163
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:60
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
A StencilAttrib is a collection of all stencil render states.
Definition: stencilAttrib.h:32
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43