15 #include "colorScaleAttrib.h" 16 #include "graphicsStateGuardianBase.h" 18 #include "bamReader.h" 19 #include "bamWriter.h" 21 #include "datagramIterator.h" 22 #include "config_pgraph.h" 25 int ColorScaleAttrib::_attrib_slot;
35 ColorScaleAttrib(
bool off,
const LVecBase4 &scale) :
42 _has_alpha_scale = !IS_NEARLY_EQUAL(_scale[3], 1.0f);
56 _identity_attrib = return_new(attrib);
59 return _identity_attrib;
71 return return_new(attrib);
86 return return_new(attrib);
108 set_scale(
const LVecBase4 &scale)
const {
110 attrib->_scale = scale;
111 attrib->quantize_scale();
114 attrib->_has_alpha_scale = !IS_NEARLY_EQUAL(scale[3], 1.0f);
115 return return_new(attrib);
158 void ColorScaleAttrib::
159 output(ostream &out)
const {
160 out << get_type() <<
":";
187 int ColorScaleAttrib::
190 DCAST_INTO_R(ta, other, 0);
209 size_t ColorScaleAttrib::
210 get_hash_impl()
const {
237 DCAST_INTO_R(ta, other, 0);
243 LVecBase4 new_scale(ta->_scale[0] * _scale[0],
244 ta->_scale[1] * _scale[1],
245 ta->_scale[2] * _scale[2],
246 ta->_scale[3] * _scale[3]);
249 return return_new(attrib);
267 DCAST_INTO_R(ta, other, 0);
268 LVecBase4 new_scale(_scale[0] == 0.0f ? 1.0f : ta->_scale[0] / _scale[0],
269 _scale[1] == 0.0f ? 1.0f : ta->_scale[1] / _scale[1],
270 _scale[2] == 0.0f ? 1.0f : ta->_scale[2] / _scale[2],
271 _scale[3] == 0.0f ? 1.0f : ta->_scale[3] / _scale[3]);
274 return return_new(attrib);
283 get_auto_shader_attrib_impl(
const RenderState *state)
const {
298 void ColorScaleAttrib::
300 _scale[0] = cfloor(_scale[0] * 1000.0f + 0.5f) * 0.001f;
301 _scale[1] = cfloor(_scale[1] * 1000.0f + 0.5f) * 0.001f;
302 _scale[2] = cfloor(_scale[2] * 1000.0f + 0.5f) * 0.001f;
303 _scale[3] = cfloor(_scale[3] * 1000.0f + 0.5f) * 0.001f;
348 parse_params(params, scan, manager);
349 attrib->fillin(scan, manager);
361 void ColorScaleAttrib::
363 RenderAttrib::fillin(scan, manager);
370 _has_alpha_scale = !IS_NEARLY_EQUAL(_scale[3], 1.0f);
bool has_scale() const
Returns true if the ColorScaleAttrib has a non-identity scale, false otherwise (in which case it migh...
This is the base class for all three-component vectors and points.
bool get_bool()
Extracts a boolean value.
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...
const LVecBase4 & get_scale() const
Returns the scale to be applied to colors.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
size_t add_hash(size_t hash) const
Adds the vector into the running hash.
Base class for objects that can be written to and read from Bam files.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
bool almost_equal(const LVecBase3f &other, float threshold) const
Returns true if two vectors are memberwise equal within a specified tolerance.
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
void add_bool(bool value)
Adds a boolean value to the datagram.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
bool almost_equal(const LVecBase4f &other, float threshold) const
Returns true if two vectors are memberwise equal within a specified tolerance.
int compare_to(const LVecBase4f &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void read_datagram(DatagramIterator &source)
Reads the vector from the Datagram using get_stdfloat().
virtual bool lower_attrib_can_override() const
Intended to be overridden by derived RenderAttrib types to specify how two consecutive RenderAttrib o...
bool is_off() const
Returns true if the ColorScaleAttrib will ignore any color scales inherited from above, false otherwise.
static void register_with_read_factory()
Tells the BamReader how to create objects of type ColorScaleAttrib.
Applies a scale to colors in the scene graph and on vertices.
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.
This is the base class for all three-component vectors and points.
void write_datagram(Datagram &destination) const
Writes the vector to the Datagram using add_stdfloat().
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
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 ...