00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "stencilAttrib.h"
00016 #include "graphicsStateGuardianBase.h"
00017 #include "dcast.h"
00018 #include "bamReader.h"
00019 #include "bamWriter.h"
00020 #include "datagram.h"
00021 #include "datagramIterator.h"
00022
00023 TypeHandle StencilAttrib::_type_handle;
00024 int StencilAttrib::_attrib_slot;
00025
00026 const char *StencilAttrib::
00027 stencil_render_state_name_array [StencilAttrib::SRS_total] =
00028 {
00029 "SRS_front_enable",
00030 "SRS_back_enable",
00031
00032 "SRS_front_comparison_function",
00033 "SRS_front_stencil_fail_operation",
00034 "SRS_front_stencil_pass_z_fail_operation",
00035 "SRS_front_stencil_pass_z_pass_operation",
00036
00037 "SRS_reference",
00038 "SRS_read_mask",
00039 "SRS_write_mask",
00040
00041 "SRS_back_comparison_function",
00042 "SRS_back_stencil_fail_operation",
00043 "SRS_back_stencil_pass_z_fail_operation",
00044 "SRS_back_stencil_pass_z_pass_operation",
00045
00046 "SRS_clear",
00047 "SRS_clear_value",
00048 };
00049
00050
00051
00052
00053
00054
00055
00056 StencilAttrib::
00057 StencilAttrib() {
00058
00059 _stencil_render_states [SRS_front_enable] = 0;
00060 _stencil_render_states [SRS_back_enable] = 0;
00061
00062 _stencil_render_states [SRS_front_comparison_function] = SCF_always;
00063 _stencil_render_states [SRS_front_stencil_fail_operation] = SO_keep;
00064 _stencil_render_states [SRS_front_stencil_pass_z_fail_operation] = SO_keep;
00065 _stencil_render_states [SRS_front_stencil_pass_z_pass_operation] = SO_keep;
00066
00067 _stencil_render_states [SRS_reference] = 0;
00068 _stencil_render_states [SRS_read_mask] = ~0;
00069 _stencil_render_states [SRS_write_mask] = ~0;
00070
00071 _stencil_render_states [SRS_back_comparison_function] = SCF_always;
00072 _stencil_render_states [SRS_back_stencil_fail_operation] = SO_keep;
00073 _stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = SO_keep;
00074 _stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = SO_keep;
00075
00076 _stencil_render_states [SRS_clear] = 0;
00077 _stencil_render_states [SRS_clear_value] = 0;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 CPT(RenderAttrib) StencilAttrib::
00087 make_off()
00088 {
00089 StencilAttrib *attrib = new StencilAttrib;
00090
00091 return return_new(attrib);
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101 CPT(RenderAttrib) StencilAttrib::
00102 make_default() {
00103 return return_new(new StencilAttrib);
00104 }
00105
00106
00107
00108
00109
00110
00111 CPT(RenderAttrib) StencilAttrib::
00112 make(
00113 unsigned int front_enable,
00114 unsigned int front_comparison_function,
00115 unsigned int stencil_fail_operation,
00116 unsigned int stencil_pass_z_fail_operation,
00117 unsigned int front_stencil_pass_z_pass_operation,
00118 unsigned int reference,
00119 unsigned int read_mask,
00120 unsigned int write_mask)
00121 {
00122 StencilAttrib *attrib = new StencilAttrib;
00123
00124 attrib->_stencil_render_states [SRS_front_enable] = front_enable;
00125 attrib->_stencil_render_states [SRS_back_enable] = 0;
00126
00127 attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function;
00128 attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation;
00129 attrib->_stencil_render_states [SRS_front_stencil_pass_z_fail_operation] = stencil_pass_z_fail_operation;
00130 attrib->_stencil_render_states [SRS_front_stencil_pass_z_pass_operation] = front_stencil_pass_z_pass_operation;
00131
00132 attrib->_stencil_render_states [SRS_reference] = reference;
00133 attrib->_stencil_render_states [SRS_read_mask] = read_mask;
00134 attrib->_stencil_render_states [SRS_write_mask] = write_mask;
00135
00136 attrib->_stencil_render_states [SRS_back_comparison_function] = SCF_always;
00137 attrib->_stencil_render_states [SRS_back_stencil_fail_operation] = SO_keep;
00138 attrib->_stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = SO_keep;
00139 attrib->_stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = SO_keep;
00140
00141 return return_new(attrib);
00142 }
00143
00144
00145
00146
00147
00148
00149 CPT(RenderAttrib) StencilAttrib::
00150 make_2_sided(
00151 unsigned int front_enable,
00152 unsigned int back_enable,
00153 unsigned int front_comparison_function,
00154 unsigned int stencil_fail_operation,
00155 unsigned int stencil_pass_z_fail_operation,
00156 unsigned int front_stencil_pass_z_pass_operation,
00157 unsigned int reference,
00158 unsigned int read_mask,
00159 unsigned int write_mask,
00160 unsigned int back_comparison_function,
00161 unsigned int back_stencil_fail_operation,
00162 unsigned int back_stencil_pass_z_fail_operation,
00163 unsigned int back_stencil_pass_z_pass_operation)
00164 {
00165 StencilAttrib *attrib = new StencilAttrib;
00166
00167 attrib->_stencil_render_states [SRS_front_enable] = front_enable;
00168 attrib->_stencil_render_states [SRS_back_enable] = back_enable;
00169
00170 attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function;
00171 attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation;
00172 attrib->_stencil_render_states [SRS_front_stencil_pass_z_fail_operation] = stencil_pass_z_fail_operation;
00173 attrib->_stencil_render_states [SRS_front_stencil_pass_z_pass_operation] = front_stencil_pass_z_pass_operation;
00174
00175 attrib->_stencil_render_states [SRS_reference] = reference;
00176 attrib->_stencil_render_states [SRS_read_mask] = read_mask;
00177 attrib->_stencil_render_states [SRS_write_mask] = write_mask;
00178
00179 attrib->_stencil_render_states [SRS_back_comparison_function] = back_comparison_function;
00180 attrib->_stencil_render_states [SRS_back_stencil_fail_operation] = back_stencil_fail_operation;
00181 attrib->_stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = back_stencil_pass_z_fail_operation;
00182 attrib->_stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = back_stencil_pass_z_pass_operation;
00183
00184 return return_new(attrib);
00185 }
00186
00187
00188
00189
00190
00191
00192 CPT(RenderAttrib) StencilAttrib::
00193 make_with_clear(
00194 unsigned int front_enable,
00195 unsigned int front_comparison_function,
00196 unsigned int stencil_fail_operation,
00197 unsigned int stencil_pass_z_fail_operation,
00198 unsigned int front_stencil_pass_z_pass_operation,
00199 unsigned int reference,
00200 unsigned int read_mask,
00201 unsigned int write_mask,
00202 unsigned int clear,
00203 unsigned int clear_value)
00204 {
00205 StencilAttrib *attrib = new StencilAttrib;
00206
00207 attrib->_stencil_render_states [SRS_front_enable] = front_enable;
00208 attrib->_stencil_render_states [SRS_back_enable] = 0;
00209
00210 attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function;
00211 attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation;
00212 attrib->_stencil_render_states [SRS_front_stencil_pass_z_fail_operation] = stencil_pass_z_fail_operation;
00213 attrib->_stencil_render_states [SRS_front_stencil_pass_z_pass_operation] = front_stencil_pass_z_pass_operation;
00214
00215 attrib->_stencil_render_states [SRS_reference] = reference;
00216 attrib->_stencil_render_states [SRS_read_mask] = read_mask;
00217 attrib->_stencil_render_states [SRS_write_mask] = write_mask;
00218
00219 attrib->_stencil_render_states [SRS_back_comparison_function] = SCF_always;
00220 attrib->_stencil_render_states [SRS_back_stencil_fail_operation] = SO_keep;
00221 attrib->_stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = SO_keep;
00222 attrib->_stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = SO_keep;
00223
00224 attrib->_stencil_render_states [SRS_clear] = clear;
00225 attrib->_stencil_render_states [SRS_clear_value] = clear_value;
00226
00227 return return_new(attrib);
00228 }
00229
00230
00231
00232
00233
00234
00235 CPT(RenderAttrib) StencilAttrib::
00236 make_2_sided_with_clear(
00237 unsigned int front_enable,
00238 unsigned int back_enable,
00239 unsigned int front_comparison_function,
00240 unsigned int stencil_fail_operation,
00241 unsigned int stencil_pass_z_fail_operation,
00242 unsigned int front_stencil_pass_z_pass_operation,
00243 unsigned int reference,
00244 unsigned int read_mask,
00245 unsigned int write_mask,
00246 unsigned int back_comparison_function,
00247 unsigned int back_stencil_fail_operation,
00248 unsigned int back_stencil_pass_z_fail_operation,
00249 unsigned int back_stencil_pass_z_pass_operation,
00250 unsigned int clear,
00251 unsigned int clear_value)
00252 {
00253 StencilAttrib *attrib = new StencilAttrib;
00254
00255 attrib->_stencil_render_states [SRS_front_enable] = front_enable;
00256 attrib->_stencil_render_states [SRS_back_enable] = back_enable;
00257
00258 attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function;
00259 attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation;
00260 attrib->_stencil_render_states [SRS_front_stencil_pass_z_fail_operation] = stencil_pass_z_fail_operation;
00261 attrib->_stencil_render_states [SRS_front_stencil_pass_z_pass_operation] = front_stencil_pass_z_pass_operation;
00262
00263 attrib->_stencil_render_states [SRS_reference] = reference;
00264 attrib->_stencil_render_states [SRS_read_mask] = read_mask;
00265 attrib->_stencil_render_states [SRS_write_mask] = write_mask;
00266
00267 attrib->_stencil_render_states [SRS_back_comparison_function] = back_comparison_function;
00268 attrib->_stencil_render_states [SRS_back_stencil_fail_operation] = back_stencil_fail_operation;
00269 attrib->_stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = back_stencil_pass_z_fail_operation;
00270 attrib->_stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = back_stencil_pass_z_pass_operation;
00271
00272 attrib->_stencil_render_states [SRS_clear] = clear;
00273 attrib->_stencil_render_states [SRS_clear_value] = clear_value;
00274
00275 return return_new(attrib);
00276 }
00277
00278
00279
00280
00281
00282
00283 void StencilAttrib::
00284 output(ostream &out) const {
00285
00286 int index;
00287 for (index = 0; index < SRS_total; index++) {
00288 out
00289 << "(" << stencil_render_state_name_array [index]
00290 << ", " << _stencil_render_states [index] << ")";
00291 }
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 int StencilAttrib::
00310 compare_to_impl(const RenderAttrib *other) const {
00311 const StencilAttrib *sa;
00312 DCAST_INTO_R(sa, other, 0);
00313
00314 int a;
00315 int b;
00316 int index;
00317 int compare_result = 0;
00318
00319 for (index = 0; index < SRS_total; index++) {
00320 a = (int) sa -> _stencil_render_states [index];
00321 b = (int) _stencil_render_states [index];
00322 compare_result = (a - b);
00323 if (compare_result) {
00324 break;
00325 }
00326 }
00327
00328 return compare_result;
00329 }
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341 size_t StencilAttrib::
00342 get_hash_impl() const {
00343 size_t hash = 0;
00344 for (int index = 0; index < SRS_total; index++) {
00345 hash = int_hash::add_hash(hash, (int)_stencil_render_states[index]);
00346 }
00347 return hash;
00348 }
00349
00350
00351
00352
00353
00354
00355
00356 void StencilAttrib::
00357 register_with_read_factory() {
00358 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00359 }
00360
00361
00362
00363
00364
00365
00366
00367 void StencilAttrib::
00368 write_datagram(BamWriter *manager, Datagram &dg) {
00369 RenderAttrib::write_datagram(manager, dg);
00370
00371 int index;
00372 for (index = 0; index < SRS_total; index++) {
00373 dg.add_int32(_stencil_render_states [index]);
00374 }
00375 }
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 TypedWritable *StencilAttrib::
00386 make_from_bam(const FactoryParams ¶ms) {
00387 StencilAttrib *attrib = new StencilAttrib;
00388 DatagramIterator scan;
00389 BamReader *manager;
00390
00391 parse_params(params, scan, manager);
00392 attrib->fillin(scan, manager);
00393
00394 return attrib;
00395 }
00396
00397
00398
00399
00400
00401
00402
00403
00404 void StencilAttrib::
00405 fillin(DatagramIterator &scan, BamReader *manager) {
00406 RenderAttrib::fillin(scan, manager);
00407
00408 int index;
00409 for (index = 0; index < SRS_total; index++) {
00410 _stencil_render_states [index] = scan.get_int32();
00411 }
00412 }