15 #include "lightRampAttrib.h"
16 #include "graphicsStateGuardianBase.h"
18 #include "bamReader.h"
19 #include "bamWriter.h"
21 #include "datagramIterator.h"
24 int LightRampAttrib::_attrib_slot;
38 _default = return_new(attrib);
53 attrib->_mode = LRT_identity;
54 return return_new(attrib);
72 make_single_threshold(PN_stdfloat thresh0, PN_stdfloat val0) {
74 attrib->_mode = LRT_single_threshold;
75 attrib->_threshold[0] = thresh0;
76 attrib->_level[0] = val0;
77 return return_new(attrib);
97 make_double_threshold(PN_stdfloat thresh0, PN_stdfloat val0, PN_stdfloat thresh1, PN_stdfloat val1) {
99 attrib->_mode = LRT_double_threshold;
100 attrib->_threshold[0] = thresh0;
101 attrib->_level[0] = val0;
102 attrib->_threshold[1] = thresh1;
103 attrib->_level[1] = val1;
104 return return_new(attrib);
132 attrib->_mode = LRT_hdr0;
133 return return_new(attrib);
161 attrib->_mode = LRT_hdr1;
162 return return_new(attrib);
190 attrib->_mode = LRT_hdr2;
191 return return_new(attrib);
199 void LightRampAttrib::
200 output(ostream &out)
const {
201 out << get_type() <<
":";
209 case LRT_single_threshold:
210 out <<
"single_threshold(" << _level[0] <<
"," << _level[1] <<
"," << _threshold[0] <<
")";
212 case LRT_double_threshold:
213 out <<
"double_threshold(" << _level[0] <<
"," << _level[1] <<
"," << _threshold[0] <<
"," << _threshold[1] <<
")";
242 int LightRampAttrib::
245 DCAST_INTO_R(ta, other, 0);
246 int compare_result = ((int)_mode - (
int)ta->_mode) ;
247 if (compare_result != 0) {
248 return compare_result;
250 for (
int i = 0; i < 2; i++) {
251 if (_level[i] != ta->_level[i]) {
252 return (_level[i] < ta->_level[i]) ? -1 : 1;
255 for (
int i = 0; i < 2; i++) {
256 if (_threshold[i] != ta->_threshold[i]) {
257 return (_threshold[i] < ta->_threshold[i]) ? -1 : 1;
273 size_t LightRampAttrib::
274 get_hash_impl()
const {
278 for (
int i = 0; i < 2; i++) {
279 hash = fh.
add_hash(hash, _level[i]);
280 hash = fh.
add_hash(hash, _threshold[i]);
291 get_auto_shader_attrib_impl(const
RenderState *state)
const {
301 void LightRampAttrib::
302 register_with_read_factory() {
317 for (
int i=0; i<2; i++) {
320 for (
int i=0; i<2; i++) {
339 parse_params(params, scan, manager);
340 attrib->fillin(scan, manager);
352 void LightRampAttrib::
354 RenderAttrib::fillin(scan, manager);
356 _mode = (LightRampMode)scan.
get_int8();
357 for (
int i=0; i<2; i++) {
360 for (
int i=0; i<2; i++) {
PN_int8 get_int8()
Extracts a signed 8-bit integer.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
This is the base class for a number of render attributes (other than transform) that may be set on sc...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
void add_int8(PN_int8 value)
Adds a signed 8-bit integer to the datagram.
Base class for objects that can be written to and read from Bam files.
A Light Ramp is any unary operator that takes a rendered pixel as input, and adjusts the brightness o...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
This hash_compare class hashes a float or a double.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
size_t add_hash(size_t start, const Key &key) const
Adds the indicated key into a running hash.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
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 class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...