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),
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;
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) {
146 get_gsg()->get_max_vertex_transforms()) {
147 if (matrix_palette &&
164 get_gsg()->get_max_vertex_transforms()) {
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) {
224 PT(
Geom) new_geom = geom->make_copy();
225 new_geom->set_vertex_data(vertex_data);
226 new_geom->make_nonindexed(false);
228 vertex_data = new_geom->get_vertex_data();
242 int unsupported_bits = geom->get_geom_rendering() & ~supported_geom_rendering;
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();
263 unsupported_bits = geom->get_geom_rendering() & ~supported_geom_rendering;
265 if ((unsupported_bits & Geom::GR_shade_model_bits) != 0) {
269 geom = geom->rotate();
271 if ((unsupported_bits & Geom::GR_indexed_bits) != 0) {
273 PT(
Geom) new_geom = geom->make_copy();
274 new_geom->set_vertex_data(vertex_data);
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);
int compare_to(const LVecBase4f &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
This is just a simple derivative of GeomMunger that adds the ability to munge states.
const RenderAttrib * get_attrib_def(int slot) const
Returns the RenderAttrib with the indicated slot index, or the default attrib for that slot if there ...
This object describes how the vertex animation, if any, represented in a GeomVertexData is encoded...
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...
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...
Objects of this class are used to convert vertex data from a Geom into a format suitable for passing ...
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.
bool has_scale() const
Returns true if the ColorScaleAttrib has a non-identity scale, false otherwise (in which case it migh...
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.
virtual int get_supported_geom_rendering() const
Returns the union of Geom::GeomRendering values that this particular GSG can support directly...
bool auto_shader() const
If true, then this ShaderAttrib does not contain an explicit shader - instead, it requests the automa...
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
AnimationType get_animation_type() const
Returns the type of animation represented by this spec.
Stores the total set of VertexSliders that the vertices in a particular GeomVertexData object might d...
const LColor & get_color() const
If the type is T_flat or T_off, this returns the color that will be applied to geometry.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
const LVecBase4 & get_scale() const
Returns the scale to be applied to colors.
The ShaderGenerator is a device that effectively replaces the classic fixed function pipeline with a ...
A container for geometry primitives.
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...
bool get_runtime_color_scale() const
Returns true if this particular GSG can implement (or would prefer to implement) set color and/or col...
const RenderAttrib * get_attrib(TypeHandle type) const
Looks for a RenderAttrib of the indicated type in the state, and returns it if it is found...
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.
bool has_alpha_scale() const
Returns true if the ColorScaleAttrib has a non-identity scale in the alpha component (ignoring RGB)...
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A thread; that is, a lightweight process.
Specifies how polygons are to be drawn.
Indicates what color should be applied to renderable geometry.
TypeHandle is the identifier used to differentiate C++ class types.
int get_geom_rendering() const
Returns the set of GeomRendering bits that represent the rendering properties required to properly re...
bool has_rgb_scale() const
Returns true if the ColorScaleAttrib has a non-identity scale in the RGB components (ignoring alpha)...
GraphicsStateGuardian * get_gsg() const
Returns a pointer to the GSG that created this munger.