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