Panda3D
|
00001 // Filename: stencilAttrib.h 00002 // Created by: aignacio (18May06) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef STENCILATTRIB_H 00016 #define STENCILATTRIB_H 00017 00018 #include "pandabase.h" 00019 #include "renderAttrib.h" 00020 00021 class FactoryParams; 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Class : StencilAttrib 00025 // Description : A StencilAttrib is a collection of all stencil render 00026 // states. The render states in a StencilAttrib are 00027 // read-only. A StencilAttrib is created with make or 00028 // make_2_sided. To determine if two sided stencil is 00029 // supported, call the function GraphicsStateGuardian:: 00030 // get_supports_two_sided_stencil. 00031 //////////////////////////////////////////////////////////////////// 00032 class EXPCL_PANDA_PGRAPH StencilAttrib : public RenderAttrib { 00033 00034 private: 00035 StencilAttrib(); 00036 00037 PUBLISHED: 00038 00039 // enums are duplicated here from class StencilRenderStates for use in Python 00040 enum StencilRenderState 00041 { 00042 SRS_front_enable, 00043 SRS_back_enable, 00044 00045 SRS_front_comparison_function, 00046 SRS_front_stencil_fail_operation, 00047 SRS_front_stencil_pass_z_fail_operation, 00048 SRS_front_stencil_pass_z_pass_operation, 00049 00050 SRS_reference, 00051 SRS_read_mask, 00052 SRS_write_mask, 00053 00054 SRS_back_comparison_function, 00055 SRS_back_stencil_fail_operation, 00056 SRS_back_stencil_pass_z_fail_operation, 00057 SRS_back_stencil_pass_z_pass_operation, 00058 00059 SRS_clear, 00060 SRS_clear_value, 00061 00062 SRS_total, 00063 00064 SRS_first = 0, 00065 }; 00066 00067 enum StencilComparisonFunction 00068 { 00069 SCF_never, 00070 SCF_less_than, 00071 SCF_equal, 00072 SCF_less_than_or_equal, 00073 SCF_greater_than, 00074 SCF_not_equal, 00075 SCF_greater_than_or_equal, 00076 SCF_always, 00077 }; 00078 00079 enum StencilOperation 00080 { 00081 SO_keep, 00082 SO_zero, 00083 SO_replace, 00084 SO_increment, 00085 SO_decrement, 00086 SO_invert, 00087 SO_increment_saturate, 00088 SO_decrement_saturate, 00089 }; 00090 00091 enum StencilMask 00092 { 00093 SM_default = ~0, 00094 }; 00095 00096 static CPT(RenderAttrib) make_off(); 00097 static CPT(RenderAttrib) make_default(); 00098 00099 static CPT(RenderAttrib) make( 00100 unsigned int front_enable, 00101 unsigned int front_comparison_function, 00102 unsigned int stencil_fail_operation, 00103 unsigned int stencil_pass_z_fail_operation, 00104 unsigned int front_stencil_pass_z_pass_operation, 00105 unsigned int reference, 00106 unsigned int read_mask, 00107 unsigned int write_mask); 00108 00109 static CPT(RenderAttrib) make_2_sided( 00110 unsigned int front_enable, 00111 unsigned int back_enable, 00112 unsigned int front_comparison_function, 00113 unsigned int stencil_fail_operation, 00114 unsigned int stencil_pass_z_fail_operation, 00115 unsigned int front_stencil_pass_z_pass_operation, 00116 unsigned int reference, 00117 unsigned int read_mask, 00118 unsigned int write_mask, 00119 unsigned int back_comparison_function, 00120 unsigned int back_stencil_fail_operation, 00121 unsigned int back_stencil_pass_z_fail_operation, 00122 unsigned int back_stencil_pass_z_pass_operation); 00123 00124 static CPT(RenderAttrib) make_with_clear( 00125 unsigned int front_enable, 00126 unsigned int front_comparison_function, 00127 unsigned int stencil_fail_operation, 00128 unsigned int stencil_pass_z_fail_operation, 00129 unsigned int front_stencil_pass_z_pass_operation, 00130 unsigned int reference, 00131 unsigned int read_mask, 00132 unsigned int write_mask, 00133 unsigned int clear, 00134 unsigned int clear_value); 00135 00136 static CPT(RenderAttrib) make_2_sided_with_clear( 00137 unsigned int front_enable, 00138 unsigned int back_enable, 00139 unsigned int front_comparison_function, 00140 unsigned int stencil_fail_operation, 00141 unsigned int stencil_pass_z_fail_operation, 00142 unsigned int front_stencil_pass_z_pass_operation, 00143 unsigned int reference, 00144 unsigned int read_mask, 00145 unsigned int write_mask, 00146 unsigned int back_comparison_function, 00147 unsigned int back_stencil_fail_operation, 00148 unsigned int back_stencil_pass_z_fail_operation, 00149 unsigned int back_stencil_pass_z_pass_operation, 00150 unsigned int clear, 00151 unsigned int clear_value); 00152 00153 INLINE unsigned int get_render_state (unsigned int render_state_identifier) const; 00154 00155 public: 00156 static const char *stencil_render_state_name_array [SRS_total]; 00157 00158 virtual void output(ostream &out) const; 00159 00160 protected: 00161 virtual int compare_to_impl(const RenderAttrib *other) const; 00162 virtual size_t get_hash_impl() const; 00163 00164 private: 00165 unsigned int _stencil_render_states [SRS_total]; 00166 00167 PUBLISHED: 00168 static int get_class_slot() { 00169 return _attrib_slot; 00170 } 00171 virtual int get_slot() const { 00172 return get_class_slot(); 00173 } 00174 00175 public: 00176 static void register_with_read_factory(); 00177 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00178 00179 protected: 00180 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00181 void fillin(DatagramIterator &scan, BamReader *manager); 00182 00183 public: 00184 static TypeHandle get_class_type() { 00185 return _type_handle; 00186 } 00187 static void init_type() { 00188 RenderAttrib::init_type(); 00189 register_type(_type_handle, "StencilAttrib", 00190 RenderAttrib::get_class_type()); 00191 _attrib_slot = register_slot(_type_handle, 100, make_default); 00192 } 00193 virtual TypeHandle get_type() const { 00194 return get_class_type(); 00195 } 00196 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00197 00198 private: 00199 static TypeHandle _type_handle; 00200 static int _attrib_slot; 00201 }; 00202 00203 #include "stencilAttrib.I" 00204 00205 #endif 00206