24 int ColorScaleAttrib::_attrib_slot;
31 ColorScaleAttrib(
bool off,
const LVecBase4 &scale) :
36 _has_scale = !_scale.almost_equal(LVecBase4(1.0f, 1.0f, 1.0f, 1.0f));
37 _has_rgb_scale = !LVecBase3(_scale[0], _scale[1], _scale[2]).almost_equal(LVecBase3(1.0f, 1.0f, 1.0f));
38 _has_alpha_scale = !IS_NEARLY_EQUAL(_scale[3], 1.0f);
48 if (_identity_attrib ==
nullptr) {
50 _identity_attrib = return_new(attrib);
53 return _identity_attrib;
61 make(
const LVecBase4 &scale) {
63 return return_new(attrib);
75 return return_new(attrib);
84 return return_new(
new ColorScaleAttrib(
false, LVecBase4(1.0f, 1.0f, 1.0f, 1.0f)));
92 set_scale(
const LVecBase4 &scale)
const {
94 attrib->_scale = scale;
95 attrib->quantize_scale();
96 attrib->_has_scale = !scale.almost_equal(LVecBase4(1.0f, 1.0f, 1.0f, 1.0f));
97 attrib->_has_rgb_scale = !LVecBase3(scale[0], scale[1], scale[2]).almost_equal(LVecBase3(1.0f, 1.0f, 1.0f));
98 attrib->_has_alpha_scale = !IS_NEARLY_EQUAL(scale[3], 1.0f);
99 return return_new(attrib);
131 void ColorScaleAttrib::
132 output(std::ostream &out)
const {
133 out << get_type() <<
":";
157 int ColorScaleAttrib::
165 return _scale.compare_to(ta->_scale);
174 size_t ColorScaleAttrib::
175 get_hash_impl()
const {
178 hash = _scale.add_hash(hash);
201 LVecBase4 new_scale(ta->_scale[0] * _scale[0],
202 ta->_scale[1] * _scale[1],
203 ta->_scale[2] * _scale[2],
204 ta->_scale[3] * _scale[3]);
207 return return_new(attrib);
223 LVecBase4 new_scale(_scale[0] == 0.0f ? 1.0f : ta->_scale[0] / _scale[0],
224 _scale[1] == 0.0f ? 1.0f : ta->_scale[1] / _scale[1],
225 _scale[2] == 0.0f ? 1.0f : ta->_scale[2] / _scale[2],
226 _scale[3] == 0.0f ? 1.0f : ta->_scale[3] / _scale[3]);
229 return return_new(attrib);
236 void ColorScaleAttrib::
238 _scale[0] = cfloor(_scale[0] * 1024.0f + 0.5f) / 1024.0f;
239 _scale[1] = cfloor(_scale[1] * 1024.0f + 0.5f) / 1024.0f;
240 _scale[2] = cfloor(_scale[2] * 1024.0f + 0.5f) / 1024.0f;
241 _scale[3] = cfloor(_scale[3] * 1024.0f + 0.5f) / 1024.0f;
264 _scale.write_datagram(dg);
279 attrib->fillin(scan, manager);
288 void ColorScaleAttrib::
290 RenderAttrib::fillin(scan, manager);
293 _scale.read_datagram(scan);
295 _has_scale = !_scale.almost_equal(LVecBase4(1.0f, 1.0f, 1.0f, 1.0f));
296 _has_rgb_scale = !LVecBase3(_scale[0], _scale[1], _scale[2]).almost_equal(LVecBase3(1.0f, 1.0f, 1.0f));
297 _has_alpha_scale = !IS_NEARLY_EQUAL(_scale[3], 1.0f);
has_scale
Returns true if the ColorScaleAttrib has a non-identity scale, false otherwise (in which case it migh...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
get_scale
Returns the scale to be applied to colors.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
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.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
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,...
static void register_with_read_factory()
Tells the BamReader how to create objects of type ColorScaleAttrib.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Applies a scale to colors in the scene graph and on vertices.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
CPT(RenderAttrib) ColorScaleAttrib
Constructs an identity scale attrib.
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 ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.