00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "scissorAttrib.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 ScissorAttrib::_type_handle;
00024 int ScissorAttrib::_attrib_slot;
00025 CPT(RenderAttrib) ScissorAttrib::_off;
00026
00027
00028
00029
00030
00031
00032
00033 ScissorAttrib::
00034 ScissorAttrib(const LVecBase4 &frame) :
00035 _frame(frame)
00036 {
00037
00038 _frame[0] = max(min(_frame[0], (PN_stdfloat)1.0), (PN_stdfloat)0.0);
00039 _frame[1] = max(min(_frame[1], (PN_stdfloat)1.0), _frame[0]);
00040 _frame[2] = max(min(_frame[2], (PN_stdfloat)1.0), (PN_stdfloat)0.0);
00041 _frame[3] = max(min(_frame[3], (PN_stdfloat)1.0), _frame[2]);
00042 }
00043
00044
00045
00046
00047
00048
00049
00050 CPT(RenderAttrib) ScissorAttrib::
00051 make_off() {
00052 if (_off != 0) {
00053 return _off;
00054 }
00055 ScissorAttrib *attrib = new ScissorAttrib(LVecBase4(0.0f, 1.0f, 0.0f, 1.0f));
00056 _off = return_new(attrib);
00057 return _off;
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 CPT(RenderAttrib) ScissorAttrib::
00069 make(const LVecBase4 &frame) {
00070 ScissorAttrib *attrib = new ScissorAttrib(frame);
00071 return return_new(attrib);
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081 CPT(RenderAttrib) ScissorAttrib::
00082 make_default() {
00083 return return_new(new ScissorAttrib(LVecBase4(0.0f, 1.0f, 0.0f, 1.0f)));
00084 }
00085
00086
00087
00088
00089
00090
00091 void ScissorAttrib::
00092 output(ostream &out) const {
00093 out << get_type() << ":[" << _frame << "]";
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 int ScissorAttrib::
00112 compare_to_impl(const RenderAttrib *other) const {
00113 const ScissorAttrib *ta;
00114 DCAST_INTO_R(ta, other, 0);
00115 return _frame.compare_to(ta->_frame);
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 size_t ScissorAttrib::
00129 get_hash_impl() const {
00130 size_t hash = 0;
00131 hash = _frame.add_hash(hash);
00132 return hash;
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 CPT(RenderAttrib) ScissorAttrib::
00153 compose_impl(const RenderAttrib *other) const {
00154 const ScissorAttrib *ta;
00155 DCAST_INTO_R(ta, other, 0);
00156
00157 LVecBase4 new_frame(max(ta->_frame[0], _frame[0]),
00158 min(ta->_frame[1], _frame[1]),
00159 max(ta->_frame[2], _frame[2]),
00160 min(ta->_frame[3], _frame[3]));
00161
00162 ScissorAttrib *attrib = new ScissorAttrib(new_frame);
00163 return return_new(attrib);
00164 }
00165
00166
00167
00168
00169
00170
00171
00172 void ScissorAttrib::
00173 register_with_read_factory() {
00174 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00175 }
00176
00177
00178
00179
00180
00181
00182
00183 void ScissorAttrib::
00184 write_datagram(BamWriter *manager, Datagram &dg) {
00185 RenderAttrib::write_datagram(manager, dg);
00186
00187 _frame.write_datagram(dg);
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 TypedWritable *ScissorAttrib::
00199 make_from_bam(const FactoryParams ¶ms) {
00200 ScissorAttrib *attrib = new ScissorAttrib(LVecBase4(0.0f, 1.0f, 0.0f, 1.0f));
00201 DatagramIterator scan;
00202 BamReader *manager;
00203
00204 parse_params(params, scan, manager);
00205 attrib->fillin(scan, manager);
00206
00207 return attrib;
00208 }
00209
00210
00211
00212
00213
00214
00215
00216
00217 void ScissorAttrib::
00218 fillin(DatagramIterator &scan, BamReader *manager) {
00219 RenderAttrib::fillin(scan, manager);
00220
00221 _frame.read_datagram(scan);
00222 }