15 #include "standardMunger.h" 16 #include "renderState.h" 17 #include "graphicsStateGuardian.h" 19 #include "config_gobj.h" 20 #include "displayRegion.h" 35 StandardMunger::NumericType numeric_type,
36 StandardMunger::Contents contents) :
38 _num_components(num_components),
39 _numeric_type(numeric_type),
42 _munge_color_scale(false),
45 _render_mode = DCAST(
RenderModeAttrib, state->get_attrib(RenderModeAttrib::get_class_slot()));
50 state->get_attrib(ColorAttrib::get_class_slot());
52 state->get_attrib(ColorScaleAttrib::get_class_slot());
65 _color.set(_color[0] * cs[0],
75 _color_scale = color_scale_attrib->
get_scale();
78 state->get_attrib(TextureAttrib::get_class_slot());
84 _munge_color_scale =
true;
96 state->get_attrib_def(ShaderAttrib::get_class_slot());
100 if (shader_attrib->get_flag(ShaderAttrib::F_hardware_skinning)) {
103 _num_components |= 0x10000;
127 new_data = new_data->set_color(_color, _num_components & 0xffff,
128 _numeric_type, _contents);
129 }
else if (_munge_color_scale) {
130 new_data = new_data->scale_color(_color_scale, _num_components & 0xffff,
131 _numeric_type, _contents);
135 if (_num_components & 0x10000) {
138 }
else if (hardware_animated_vertices &&
140 new_data->get_slider_table() == (
SliderTable *)NULL) {
147 if (matrix_palette &&
172 CPT(GeomVertexFormat) orig_format = new_data->get_format();
173 CPT(GeomVertexFormat) new_format = munge_format(orig_format, animation);
175 if (new_format == orig_format) {
180 return new_data->convert_to(new_format);
188 void StandardMunger::
194 if (unsupported_bits != 0) {
200 if ((unsupported_bits & Geom::GR_composite_bits) != 0 ||
201 (unsupported_bits & Geom::GR_strip_cut_index) != 0) {
210 geom = geom->decompose();
216 if ((unsupported_bits & Geom::GR_shade_model_bits) != 0) {
220 geom = geom->rotate();
222 if ((unsupported_bits & Geom::GR_indexed_bits) != 0) {
226 new_geom->make_nonindexed(
false);
228 vertex_data = new_geom->get_vertex_data();
238 void StandardMunger::
243 if (unsupported_bits != 0) {
249 if ((unsupported_bits & Geom::GR_composite_bits) != 0 ||
250 (unsupported_bits & Geom::GR_strip_cut_index) != 0) {
259 geom = geom->decompose();
265 if ((unsupported_bits & Geom::GR_shade_model_bits) != 0) {
269 geom = geom->rotate();
271 if ((unsupported_bits & Geom::GR_indexed_bits) != 0) {
275 new_geom->make_nonindexed(
false);
277 vertex_data = new_geom->get_vertex_data();
291 compare_to_impl(
const GeomMunger *other)
const {
294 if (_render_mode != om->_render_mode) {
295 return _render_mode < om->_render_mode ? -1 : 1;
298 if (_munge_color != om->_munge_color) {
299 return (
int)_munge_color - (int)om->_munge_color;
301 if (_munge_color_scale != om->_munge_color_scale) {
302 return (
int)_munge_color_scale - (int)om->_munge_color_scale;
310 if (_munge_color_scale) {
311 int compare = _color_scale.
compare_to(om->_color_scale);
316 bool shader_skinning = ((_num_components & 0x10000) != 0);
317 bool om_shader_skinning = ((om->_num_components & 0x10000) != 0);
318 if (shader_skinning != om_shader_skinning) {
319 return (
int)shader_skinning - (int)om_shader_skinning;
321 if (_auto_shader != om->_auto_shader) {
322 return (
int)_auto_shader - (int)om->_auto_shader;
325 return StateMunger::compare_to_impl(other);
339 geom_compare_to_impl(
const GeomMunger *other)
const {
341 if (_munge_color != om->_munge_color) {
342 return (
int)_munge_color - (int)om->_munge_color;
344 if (_munge_color_scale != om->_munge_color_scale) {
345 return (
int)_munge_color_scale - (int)om->_munge_color_scale;
353 if (_munge_color_scale) {
354 int compare = _color_scale.
compare_to(om->_color_scale);
359 bool shader_skinning = ((_num_components & 0x10000) != 0);
360 bool om_shader_skinning = ((om->_num_components & 0x10000) != 0);
361 if (shader_skinning != om_shader_skinning) {
362 return (
int)shader_skinning - (int)om_shader_skinning;
365 return StateMunger::geom_compare_to_impl(other);
378 munged_state = munged_state->remove_attrib(ColorAttrib::get_class_slot());
379 munged_state = munged_state->remove_attrib(ColorScaleAttrib::get_class_slot());
380 }
else if (_munge_color_scale) {
381 munged_state = munged_state->remove_attrib(ColorScaleAttrib::get_class_slot());
385 CPT(
RenderState) shader_state = munged_state->get_auto_shader_state();
387 if (shader_generator == NULL) {
389 <<
"auto_shader enabled, but GSG has no shader generator assigned!\n";
392 if (shader_state->_generated_shader == NULL) {
394 shader_state->_generated_shader = shader_generator->synthesize_shader(shader_state);
396 munged_state = munged_state->set_attrib(shader_state->_generated_shader);
This is just a simple derivative of GeomMunger that adds the ability to munge states.
bool has_scale() const
Returns true if the ColorScaleAttrib has a non-identity scale, false otherwise (in which case it migh...
bool get_runtime_color_scale() const
Returns true if this particular GSG can implement (or would prefer to implement) set color and/or col...
bool auto_shader() const
If true, then this ShaderAttrib does not contain an explicit shader - instead, it requests the automa...
bool has_alpha_scale() const
Returns true if the ColorScaleAttrib has a non-identity scale in the alpha component (ignoring RGB)...
const LColor & get_color() const
If the type is T_flat or T_off, this returns the color that will be applied to geometry.
bool get_color_scale_via_lighting() const
Returns true if this particular GSG can implement (or would prefer to implement) set color and/or col...
This object describes how the vertex animation, if any, represented in a GeomVertexData is encoded...
const LVecBase4 & get_scale() const
Returns the scale to be applied to colors.
StandardMunger(GraphicsStateGuardianBase *gsg, const RenderState *state, int num_components, NumericType numeric_type, Contents contents)
The StandardMunger constructor accepts additional parameters that specify the GSG's preferred color f...
Objects of this class are used to convert vertex data from a Geom into a format suitable for passing ...
GraphicsStateGuardian * get_gsg() const
Returns a pointer to the GSG that created this munger.
ShaderGenerator * get_shader_generator() const
Returns the ShaderGenerator object that will be used by this GSG to generate shaders when necessary...
Performs some generic munging that is appropriate for all GSG types; for instance, applies ColorAttrib and ColorScaleAttrib to the vertices, and checks for hardware-accelerated animation capabilities.
void set_hardware(int num_transforms, bool indexed_transforms)
Specifies that vertex animation is to be performed by the graphics hardware (or at least by the graph...
Type get_color_type() const
Returns the type of color specified by this ColorAttrib.
bool get_alpha_scale_via_texture() const
Returns true if this particular GSG can implement (or would prefer to implement) an alpha scale via a...
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
int get_max_vertex_transforms() const
Returns the maximum number of transform matrices that may be simultaneously used to transform any one...
Stores the total set of VertexSliders that the vertices in a particular GeomVertexData object might d...
virtual Geom * make_copy() const
Returns a newly-allocated Geom that is a shallow copy of this one.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
int compare_to(const LVecBase4f &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
The ShaderGenerator is a device that effectively replaces the classic fixed function pipeline with a ...
A container for geometry primitives.
bool has_rgb_scale() const
Returns true if the ColorScaleAttrib has a non-identity scale in the RGB components (ignoring alpha)...
int get_geom_rendering() const
Returns the set of GeomRendering bits that represent the rendering properties required to properly re...
AnimationType get_animation_type() const
Returns the type of animation represented by this spec.
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...
This is the base class for all three-component vectors and points.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
void set_vertex_data(const GeomVertexData *data)
Replaces the Geom's underlying vertex data table with a completely new table.
A thread; that is, a lightweight process.
Specifies how polygons are to be drawn.
Indicates what color should be applied to renderable geometry.
virtual int get_supported_geom_rendering() const
Returns the union of Geom::GeomRendering values that this particular GSG can support directly...
int get_max_vertex_transform_indices() const
Returns the maximum number of transforms there may be in a single TransformTable for this graphics ha...
TypeHandle is the identifier used to differentiate C++ class types.