From ffdbf61985855d4ac855eee214392d49f0f3a77f Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 25 Feb 2005 18:25:00 +0000 Subject: [PATCH] TextureStage::M_blend_color_scale, TextureStage::rgb_scale, ColorBlendAttrib::O_color_scale, better handling of state changes in GL --- panda/src/display/graphicsStateGuardian.cxx | 61 ++- panda/src/display/graphicsStateGuardian.h | 15 +- panda/src/doc/eggSyntax.txt | 14 +- panda/src/doc/howto.use_multitexture.txt | 5 + panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx | 30 +- panda/src/dxgsg8/dxGraphicsStateGuardian8.I | 8 +- panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx | 4 +- panda/src/dxgsg9/dxGraphicsStateGuardian9.I | 8 +- panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 4 +- panda/src/egg/eggTexture.I | 101 +++++ panda/src/egg/eggTexture.cxx | 24 ++ panda/src/egg/eggTexture.h | 16 + panda/src/egg/parser.cxx.prebuilt | 402 +++++++++--------- panda/src/egg/parser.yxx | 16 + panda/src/egg2pg/eggLoader.cxx | 15 + .../src/glstuff/glGraphicsStateGuardian_src.I | 21 +- .../glstuff/glGraphicsStateGuardian_src.cxx | 364 +++++++++------- .../src/glstuff/glGraphicsStateGuardian_src.h | 10 +- panda/src/gobj/textureStage.I | 134 ++++-- panda/src/gobj/textureStage.cxx | 79 ++-- panda/src/gobj/textureStage.h | 20 +- panda/src/grutil/multitexReducer.cxx | 8 + panda/src/pgraph/colorBlendAttrib.I | 52 ++- panda/src/pgraph/colorBlendAttrib.cxx | 18 +- panda/src/pgraph/colorBlendAttrib.h | 17 + panda/src/pgui/pgSliderBar.cxx | 4 +- panda/src/putil/bam.h | 3 +- panda/src/tform/mouseWatcher.cxx | 4 + 28 files changed, 988 insertions(+), 469 deletions(-) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index ddf33c69db..c9b6d6d0cd 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -150,23 +150,28 @@ reset() { _accum_clear_value.set(0.0f, 0.0f, 0.0f, 0.0f); _force_normals = 0; - //Color and alpha transform variables - _color_transform_enabled = 0; - _current_color_offset.set(0.0f, 0.0f, 0.0f, 0.0f); - _current_color_scale.set(1.0f, 1.0f, 1.0f, 1.0f); - - _color_write_mode = ColorWriteAttrib::M_on; - _color_blend_mode = ColorBlendAttrib::M_none; - _transparency_mode = TransparencyAttrib::M_none; - _has_scene_graph_color = false; _scene_graph_color_stale = false; + _color_blend_involves_color_scale = false; + _texture_involves_color_scale = false; _vertex_colors_enabled = true; _lighting_enabled = false; _lighting_enabled_this_frame = false; _clip_planes_enabled = false; _clip_planes_enabled_this_frame = false; + + _color_scale_enabled = false; + _current_color_scale.set(1.0f, 1.0f, 1.0f, 1.0f); + + _color_write_mode = ColorWriteAttrib::M_on; + _color_blend_mode = ColorBlendAttrib::M_none; + _transparency_mode = TransparencyAttrib::M_none; + + _color_blend = NULL; + _blend_mode_stale = false; + _pending_texture = NULL; + _texture_stale = false; } //////////////////////////////////////////////////////////////////// @@ -625,15 +630,17 @@ issue_transform(const TransformState *) { //////////////////////////////////////////////////////////////////// void GraphicsStateGuardian:: issue_color_scale(const ColorScaleAttrib *attrib) { + _color_scale_enabled = attrib->has_scale(); _current_color_scale = attrib->get_scale(); - if (attrib->has_scale()) { - _color_transform_enabled |= CT_scale; - } else { - _color_transform_enabled &= ~CT_scale; - } - _scene_graph_color_stale = _has_scene_graph_color; + + if (_color_blend_involves_color_scale) { + _blend_mode_stale = true; + } + if (_texture_involves_color_scale) { + _texture_stale = true; + } } //////////////////////////////////////////////////////////////////// @@ -834,7 +841,7 @@ issue_light(const LightAttrib *attrib) { void GraphicsStateGuardian:: issue_color_write(const ColorWriteAttrib *attrib) { _color_write_mode = attrib->get_mode(); - set_blend_mode(); + _blend_mode_stale = true; } //////////////////////////////////////////////////////////////////// @@ -845,7 +852,7 @@ issue_color_write(const ColorWriteAttrib *attrib) { void GraphicsStateGuardian:: issue_transparency(const TransparencyAttrib *attrib) { _transparency_mode = attrib->get_mode(); - set_blend_mode(); + _blend_mode_stale = true; } //////////////////////////////////////////////////////////////////// @@ -857,7 +864,21 @@ void GraphicsStateGuardian:: issue_color_blend(const ColorBlendAttrib *attrib) { _color_blend = attrib; _color_blend_mode = attrib->get_mode(); - set_blend_mode(); + _color_blend_involves_color_scale = attrib->involves_color_scale(); + _blend_mode_stale = true; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::issue_texture +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +void GraphicsStateGuardian:: +issue_texture(const TextureAttrib *attrib) { + // By default, we don't apply the texture attrib right away, since + // it might have a dependency on the current ColorScaleAttrib. + _pending_texture = attrib; + _texture_stale = true; } //////////////////////////////////////////////////////////////////// @@ -1203,6 +1224,10 @@ set_blend_mode() { //////////////////////////////////////////////////////////////////// void GraphicsStateGuardian:: finish_modify_state() { + if (_blend_mode_stale) { + _blend_mode_stale = false; + set_blend_mode(); + } } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index 0fb5cd9b61..dcb93fc690 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -42,6 +42,7 @@ #include "planeNode.h" #include "colorWriteAttrib.h" #include "colorBlendAttrib.h" +#include "textureAttrib.h" #include "transparencyAttrib.h" #include "config_display.h" @@ -165,6 +166,7 @@ public: virtual void issue_color_write(const ColorWriteAttrib *attrib); virtual void issue_transparency(const TransparencyAttrib *attrib); virtual void issue_color_blend(const ColorBlendAttrib *attrib); + virtual void issue_texture(const TextureAttrib *attrib); virtual void issue_clip_plane(const ClipPlaneAttrib *attrib); virtual void bind_light(PointLight *light_obj, const NodePath &light, @@ -256,22 +258,23 @@ protected: Colorf _scene_graph_color; bool _has_scene_graph_color; bool _scene_graph_color_stale; + bool _color_blend_involves_color_scale; + bool _texture_involves_color_scale; bool _vertex_colors_enabled; bool _lighting_enabled; bool _clip_planes_enabled; - enum ColorTransform { - CT_offset = 0x01, - CT_scale = 0x02, - }; - int _color_transform_enabled; // Zero or more of ColorTransform bits, above. - LVecBase4f _current_color_offset; + bool _color_scale_enabled; LVecBase4f _current_color_scale; ColorWriteAttrib::Mode _color_write_mode; ColorBlendAttrib::Mode _color_blend_mode; TransparencyAttrib::Mode _transparency_mode; CPT(ColorBlendAttrib) _color_blend; + bool _blend_mode_stale; + + CPT(TextureAttrib) _pending_texture; + bool _texture_stale; bool _needs_reset; bool _closing_gsg; diff --git a/panda/src/doc/eggSyntax.txt b/panda/src/doc/eggSyntax.txt index d14072f1b6..7f5fa15724 100644 --- a/panda/src/doc/eggSyntax.txt +++ b/panda/src/doc/eggSyntax.txt @@ -200,12 +200,13 @@ appear before they are referenced. BLEND REPLACE ADD + BLEND_COLOR_SCALE The default environment type is MODULATE, which means the texture color is multiplied with the base polygon (or vertex) color. This is the most common texture environment by far. Other environment types are more esoteric and are especially useful in the presence - of multitexture. + of multitexture. See howto.use_multitexture.txt for more on these. combine-rgb { combine-mode } combine-alpha { combine-mode } @@ -246,6 +247,7 @@ appear before they are referenced. CONSTANT PRIMARY-COLOR PREVIOUS + CONSTANT_COLOR_SCALE combine-operand may be one of: @@ -313,6 +315,14 @@ appear before they are referenced. associated with this texture. If this is omitted, the default texture coordinates are used. + rgb-scale { scale } + alpha-scale { scale } + + Specifies an additional scale factor that will scale the r, g, b + (or a) components after the texture has been applied. This is + only used when a combine mode is in effect. The only legal values + are 1, 2, or 4. + alpha { alpha-type } This specifies whether and what type of transparency will be @@ -326,7 +336,7 @@ appear before they are referenced. MS_MASK If alpha-type is OFF, it means not to enable transparency, even if - the image contains an alpha channel or the format is RGBA12. If + the image contains an alpha channel or the format is RGBA. If alpha-type is ON, it means to enable the default transparency, even if the image filename does not contain an alpha channel. If alpha-type is any of the other options, it specifies the type of diff --git a/panda/src/doc/howto.use_multitexture.txt b/panda/src/doc/howto.use_multitexture.txt index 73dd59d873..18243021c0 100644 --- a/panda/src/doc/howto.use_multitexture.txt +++ b/panda/src/doc/howto.use_multitexture.txt @@ -93,6 +93,11 @@ texture_stage.set_mode(). The mode may be one of: used to paint arbitrary color stripes or a similar effect over an existing texture. + TextureStage::M_blend_color_scale + This is identical to M_blend, except that the blend color, + specified by texture_stage.set_color(), is also modified by the + color scale applied to the scene graph. + TextureStage::M_replace Completely replaces the incoming color with the texture color; probably not terribly useful in a multitexture environment, diff --git a/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx b/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx index 812d383dc1..99ef9f04bf 100644 --- a/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx +++ b/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx @@ -1068,10 +1068,10 @@ typedef enum { INLINE void DXGraphicsStateGuardian7:: transform_color(Colorf &InColor,D3DCOLOR &OutRGBAColor) { Colorf transformed - ((InColor[0] * _current_color_scale[0]) + _current_color_offset[0], - (InColor[1] * _current_color_scale[1]) + _current_color_offset[1], - (InColor[2] * _current_color_scale[2]) + _current_color_offset[2], - (InColor[3] * _current_color_scale[3]) + _current_color_offset[3]); + (InColor[0] * _current_color_scale[0], + InColor[1] * _current_color_scale[1], + InColor[2] * _current_color_scale[2], + InColor[3] * _current_color_scale[3]); OutRGBAColor = Colorf_to_D3DCOLOR(transformed); } @@ -1097,7 +1097,7 @@ draw_prim_setup(const Geom *geom) { #define GET_NEXT_TEXCOORD() { p_texcoord = geom->get_next_texcoord(ti); } #define GET_NEXT_COLOR() { \ Colorf tempcolor = geom->get_next_color(ci); \ - if(_color_transform_enabled == 0) { \ + if(!_color_scale_enabled) { \ _curD3Dcolor = Colorf_to_D3DCOLOR(tempcolor); \ } else { \ transform_color(tempcolor,_curD3Dcolor); \ @@ -1134,7 +1134,7 @@ draw_prim_setup(const Geom *geom) { if (_has_scene_graph_color) { if (_scene_graph_color_stale) { // Compute the D3DCOLOR for the scene graph override color. - if(_color_transform_enabled == 0) { + if(!_color_scale_enabled) { _scene_graph_color_D3DCOLOR = Colorf_to_D3DCOLOR(_scene_graph_color); } else { transform_color(_scene_graph_color, _scene_graph_color_D3DCOLOR); @@ -1433,7 +1433,7 @@ draw_point(GeomPoint *geom, GeomContext *gc) { // BUGBUG: eventually this hack every-frame all-colors conversion needs // to be done only once as part of a vertex buffer - if(_color_transform_enabled == 0) { + if(!_color_scale_enabled) { for (int i=0;iget_next_color(ci); \ - if(_color_transform_enabled == 0) { \ + if(!_color_scale_enabled) { \ _curD3Dcolor = Colorf_to_D3DCOLOR(tempcolor); \ } else { \ transform_color(tempcolor,_curD3Dcolor); \ @@ -994,7 +994,7 @@ draw_prim_setup(const Geom *geom) { if (_has_scene_graph_color) { if (_scene_graph_color_stale) { // Compute the D3DCOLOR for the scene graph override color. - if(_color_transform_enabled == 0) { + if(!_color_scale_enabled) { _scene_graph_color_D3DCOLOR = Colorf_to_D3DCOLOR(_scene_graph_color); } else { transform_color(_scene_graph_color, _scene_graph_color_D3DCOLOR); diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.I b/panda/src/dxgsg9/dxGraphicsStateGuardian9.I index 786731c36a..518bea83d4 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.I +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.I @@ -435,10 +435,10 @@ add_to_FVFBuf(void *data, size_t bytes) { INLINE void DXGraphicsStateGuardian9:: transform_color(Colorf &InColor,D3DCOLOR &OutRGBAColor) { Colorf transformed - ((InColor[0] * _current_color_scale[0]) + _current_color_offset[0], - (InColor[1] * _current_color_scale[1]) + _current_color_offset[1], - (InColor[2] * _current_color_scale[2]) + _current_color_offset[2], - (InColor[3] * _current_color_scale[3]) + _current_color_offset[3]); + (InColor[0] * _current_color_scale[0], + InColor[1] * _current_color_scale[1], + InColor[2] * _current_color_scale[2], + InColor[3] * _current_color_scale[3]); OutRGBAColor = Colorf_to_D3DCOLOR(transformed); } diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 55f2f057ca..f94a03170f 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -942,7 +942,7 @@ draw_prim_setup(const Geom *geom) { #define GET_NEXT_COLOR() { \ Colorf tempcolor = geom->get_next_color(ci); \ - if(_color_transform_enabled == 0) { \ + if(!_color_scale_enabled) { \ _curD3Dcolor = Colorf_to_D3DCOLOR(tempcolor); \ } else { \ transform_color(tempcolor,_curD3Dcolor); \ @@ -979,7 +979,7 @@ draw_prim_setup(const Geom *geom) { if (_has_scene_graph_color) { if (_scene_graph_color_stale) { // Compute the D3DCOLOR for the scene graph override color. - if(_color_transform_enabled == 0) { + if(!_color_scale_enabled) { _scene_graph_color_D3DCOLOR = Colorf_to_D3DCOLOR(_scene_graph_color); } else { transform_color(_scene_graph_color, _scene_graph_color_D3DCOLOR); diff --git a/panda/src/egg/eggTexture.I b/panda/src/egg/eggTexture.I index 96c9346b24..fc09afbfed 100644 --- a/panda/src/egg/eggTexture.I +++ b/panda/src/egg/eggTexture.I @@ -527,6 +527,107 @@ get_uv_name() const { return _uv_name; } +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::set_rgb_scale +// Access: Published +// Description: Sets an additional factor that will scale all three +// r, g, b components after the texture has been +// applied. This is used only when a combine mode is in +// effect. +// +// The only legal values are 1, 2, or 4. +//////////////////////////////////////////////////////////////////// +INLINE void EggTexture:: +set_rgb_scale(int rgb_scale) { + _rgb_scale = rgb_scale; + _flags |= F_has_rgb_scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::clear_rgb_scale +// Access: Published +// Description: Removes the rgb_scale from the texture and restores +// it to the default value of 1. +//////////////////////////////////////////////////////////////////// +INLINE void EggTexture:: +clear_rgb_scale() { + _rgb_scale = 1; + _flags &= ~F_has_rgb_scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::has_rgb_scale +// Access: Published +// Description: Returns true if an rgb_scale has been specified for +// the texture, false otherwise. +//////////////////////////////////////////////////////////////////// +INLINE bool EggTexture:: +has_rgb_scale() const { + return (_flags & F_has_rgb_scale) != 0; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::get_rgb_scale +// Access: Published +// Description: Returns the rgb_scale value that has been +// specified for the texture, or 1 if no rgb_scale value +// has been specified. +//////////////////////////////////////////////////////////////////// +INLINE int EggTexture:: +get_rgb_scale() const { + return _rgb_scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::set_alpha_scale +// Access: Published +// Description: Sets an additional factor that will scale the +// alpha component after the texture has been applied. +// This is used only when a combine mode is in effect. +// +// The only legal values are 1, 2, or 4. +//////////////////////////////////////////////////////////////////// +INLINE void EggTexture:: +set_alpha_scale(int alpha_scale) { + _alpha_scale = alpha_scale; + _flags |= F_has_alpha_scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::clear_alpha_scale +// Access: Published +// Description: Removes the alpha_scale from the texture and restores +// it to the default value of 1. +//////////////////////////////////////////////////////////////////// +INLINE void EggTexture:: +clear_alpha_scale() { + _alpha_scale = 1; + _flags &= ~F_has_alpha_scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::has_alpha_scale +// Access: Published +// Description: Returns true if an alpha_scale has been specified for +// the texture, false otherwise. +//////////////////////////////////////////////////////////////////// +INLINE bool EggTexture:: +has_alpha_scale() const { + return (_flags & F_has_alpha_scale) != 0; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::get_alpha_scale +// Access: Published +// Description: Returns the alpha_scale value that has been +// specified for the texture, or 1 if no alpha_scale +// value has been specified. +//////////////////////////////////////////////////////////////////// +INLINE int EggTexture:: +get_alpha_scale() const { + return _alpha_scale; +} + //////////////////////////////////////////////////////////////////// // Function: EggTexture::set_transform // Access: Published diff --git a/panda/src/egg/eggTexture.cxx b/panda/src/egg/eggTexture.cxx index af706c3128..03e2f953d5 100644 --- a/panda/src/egg/eggTexture.cxx +++ b/panda/src/egg/eggTexture.cxx @@ -87,6 +87,8 @@ operator = (const EggTexture ©) { _priority = copy._priority; _color = copy._color; _uv_name = copy._uv_name; + _rgb_scale = 1; + _alpha_scale = 1; _flags = copy._flags; _transform = copy._transform; _alpha_filename = copy._alpha_filename; @@ -225,6 +227,16 @@ write(ostream &out, int indent_level) const { << " uv-name { " << get_uv_name() << " }\n"; } + if (has_rgb_scale()) { + indent(out, indent_level + 2) + << " rgb-scale { " << get_rgb_scale() << " }\n"; + } + + if (has_alpha_scale()) { + indent(out, indent_level + 2) + << " alpha-scale { " << get_alpha_scale() << " }\n"; + } + EggRenderMode::write(out, indent_level + 2); if (has_transform()) { @@ -676,6 +688,9 @@ string_env_type(const string &string) { } else if (cmp_nocase_uh(string, "add") == 0) { return ET_add; + } else if (cmp_nocase_uh(string, "blend_color_scale") == 0) { + return ET_blend_color_scale; + } else { return ET_unspecified; } @@ -740,6 +755,9 @@ string_combine_source(const string &string) { } else if (cmp_nocase_uh(string, "previous") == 0) { return CS_previous; + } else if (cmp_nocase_uh(string, "constant_color_scale") == 0) { + return CS_constant_color_scale; + } else { return CS_unspecified; } @@ -979,6 +997,9 @@ ostream &operator << (ostream &out, EggTexture::EnvType type) { case EggTexture::ET_add: return out << "add"; + + case EggTexture::ET_blend_color_scale: + return out << "blend_color_scale"; } nassertr(false, out); @@ -1054,6 +1075,9 @@ operator << (ostream &out, EggTexture::CombineSource cs) { case EggTexture::CS_previous: return out << "previous"; + + case EggTexture::CS_constant_color_scale: + return out << "constant_color_scale"; } return out << "**invalid CombineSource(" << (int)cs << ")**"; diff --git a/panda/src/egg/eggTexture.h b/panda/src/egg/eggTexture.h index 1d64c403b4..92dfa4c67e 100644 --- a/panda/src/egg/eggTexture.h +++ b/panda/src/egg/eggTexture.h @@ -91,6 +91,7 @@ PUBLISHED: ET_blend, ET_replace, ET_add, + ET_blend_color_scale, }; enum CombineMode { CM_unspecified, @@ -117,6 +118,7 @@ PUBLISHED: CS_constant, CS_primary_color, CS_previous, + CS_constant_color_scale, }; enum CombineOperand { CO_unspecified, @@ -192,6 +194,16 @@ PUBLISHED: INLINE bool has_uv_name() const; INLINE const string &get_uv_name() const; + INLINE void set_rgb_scale(int rgb_scale); + INLINE void clear_rgb_scale(); + INLINE bool has_rgb_scale() const; + INLINE int get_rgb_scale() const; + + INLINE void set_alpha_scale(int alpha_scale); + INLINE void clear_alpha_scale(); + INLINE bool has_alpha_scale() const; + INLINE int get_alpha_scale() const; + INLINE void set_transform(const LMatrix3d &transform); INLINE void clear_transform(); INLINE bool has_transform() const; @@ -240,6 +252,8 @@ private: F_has_uv_name = 0x0020, F_has_priority = 0x0040, F_has_color = 0x0080, + F_has_rgb_scale = 0x0100, + F_has_alpha_scale = 0x0200, }; Format _format; @@ -252,6 +266,8 @@ private: int _priority; Colorf _color; string _uv_name; + int _rgb_scale; + int _alpha_scale; int _flags; LMatrix3d _transform; Filename _alpha_filename; diff --git a/panda/src/egg/parser.cxx.prebuilt b/panda/src/egg/parser.cxx.prebuilt index 89e0adac7d..15a1a424a7 100644 --- a/panda/src/egg/parser.cxx.prebuilt +++ b/panda/src/egg/parser.cxx.prebuilt @@ -428,29 +428,29 @@ static const short yyrline[] = { 0, 209, 211, 212, 213, 223, 225, 239, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 264, 287, 301, 301, 329, 331, 597, 607, - 607, 634, 636, 730, 738, 757, 757, 793, 795, 805, - 805, 817, 817, 862, 867, 871, 875, 879, 879, 894, - 895, 896, 904, 922, 927, 935, 952, 957, 965, 982, - 987, 995, 1012, 1012, 1032, 1032, 1053, 1053, 1074, 1076, - 1146, 1158, 1163, 1170, 1176, 1189, 1196, 1209, 1215, 1221, - 1227, 1232, 1238, 1239, 1240, 1241, 1254, 1284, 1286, 1307, - 1307, 1323, 1325, 1326, 1327, 1328, 1329, 1330, 1331, 1334, - 1340, 1346, 1352, 1358, 1364, 1368, 1374, 1378, 1380, 1401, - 1401, 1420, 1422, 1423, 1424, 1425, 1428, 1434, 1440, 1446, - 1449, 1451, 1469, 1502, 1507, 1531, 1543, 1549, 1565, 1565, - 1584, 1584, 1603, 1603, 1622, 1622, 1641, 1641, 1661, 1663, - 1664, 1665, 1666, 1667, 1668, 1669, 1670, 1728, 1730, 1731, - 1732, 1733, 1734, 1735, 1736, 1737, 1738, 1739, 1740, 1746, - 1747, 1810, 1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, - 1820, 1821, 1889, 1906, 1946, 1963, 1968, 1976, 1993, 1998, - 2006, 2023, 2039, 2070, 2088, 2108, 2128, 2134, 2144, 2151, - 2169, 2185, 2206, 2206, 2228, 2228, 2250, 2252, 2256, 2260, - 2264, 2268, 2282, 2282, 2303, 2305, 2317, 2330, 2330, 2351, - 2353, 2370, 2383, 2383, 2404, 2406, 2421, 2435, 2440, 2453, - 2458, 2471, 2492, 2513, 2537, 2543, 2554, 2566, 2572, 2582, - 2587, 2600, 2605, 2609, 2621, 2626, 2641, 2646, 2659, 2661, - 2675, 2682, 2688, 2704, 2713, 2719 + 253, 254, 264, 287, 301, 301, 329, 331, 613, 623, + 623, 650, 652, 746, 754, 773, 773, 809, 811, 821, + 821, 833, 833, 878, 883, 887, 891, 895, 895, 910, + 911, 912, 920, 938, 943, 951, 968, 973, 981, 998, + 1003, 1011, 1028, 1028, 1048, 1048, 1069, 1069, 1090, 1092, + 1162, 1174, 1179, 1186, 1192, 1205, 1212, 1225, 1231, 1237, + 1243, 1248, 1254, 1255, 1256, 1257, 1270, 1300, 1302, 1323, + 1323, 1339, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1350, + 1356, 1362, 1368, 1374, 1380, 1384, 1390, 1394, 1396, 1417, + 1417, 1436, 1438, 1439, 1440, 1441, 1444, 1450, 1456, 1462, + 1465, 1467, 1485, 1518, 1523, 1547, 1559, 1565, 1581, 1581, + 1600, 1600, 1619, 1619, 1638, 1638, 1657, 1657, 1677, 1679, + 1680, 1681, 1682, 1683, 1684, 1685, 1686, 1744, 1746, 1747, + 1748, 1749, 1750, 1751, 1752, 1753, 1754, 1755, 1756, 1762, + 1763, 1826, 1828, 1829, 1830, 1831, 1832, 1833, 1834, 1835, + 1836, 1837, 1905, 1922, 1962, 1979, 1984, 1992, 2009, 2014, + 2022, 2039, 2055, 2086, 2104, 2124, 2144, 2150, 2160, 2167, + 2185, 2201, 2222, 2222, 2244, 2244, 2266, 2268, 2272, 2276, + 2280, 2284, 2298, 2298, 2319, 2321, 2333, 2346, 2346, 2367, + 2369, 2386, 2399, 2399, 2420, 2422, 2437, 2451, 2456, 2469, + 2474, 2487, 2508, 2529, 2553, 2559, 2570, 2582, 2588, 2598, + 2603, 2616, 2621, 2625, 2637, 2642, 2657, 2662, 2675, 2677, + 2691, 2698, 2704, 2720, 2729, 2735 }; #endif @@ -1983,6 +1983,22 @@ case 27: } else if (cmp_nocase_uh(name, "uv_name") == 0) { texture->set_uv_name(strval); + } else if (cmp_nocase_uh(name, "rgb_scale") == 0) { + int int_value = (int)value; + if (int_value != 1 && int_value != 2 && int_value != 4) { + eggyyerror("Invalid rgb-scale value " + strval); + } else { + texture->set_rgb_scale(int_value); + } + + } else if (cmp_nocase_uh(name, "alpha_scale") == 0) { + int int_value = (int)value; + if (int_value != 1 && int_value != 2 && int_value != 4) { + eggyyerror("Invalid alpha-scale value " + strval); + } else { + texture->set_alpha_scale(int_value); + } + } else if (cmp_nocase_uh(name, "alpha") == 0) { EggRenderMode::AlphaMode a = EggRenderMode::string_alpha_mode(strval); if (a == EggRenderMode::AM_unspecified) { @@ -2036,7 +2052,7 @@ case 27: } break; case 29: -#line 609 "parser.yxx" +#line 625 "parser.yxx" { string mref_name = yyvsp[-1]._string; EggMaterial *material = new EggMaterial(mref_name); @@ -2050,14 +2066,14 @@ case 29: } break; case 30: -#line 621 "parser.yxx" +#line 637 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 32: -#line 637 "parser.yxx" +#line 653 "parser.yxx" { EggMaterial *material = DCAST(EggMaterial, egg_stack.back()); string name = yyvsp[-3]._string; @@ -2143,7 +2159,7 @@ case 32: } break; case 33: -#line 732 "parser.yxx" +#line 748 "parser.yxx" { string node_name = yyvsp[-3]._string; Filename filename = yyvsp[-1]._string; @@ -2152,7 +2168,7 @@ case 33: } break; case 34: -#line 739 "parser.yxx" +#line 755 "parser.yxx" { if (cmp_nocase_uh(yyvsp[-5]._string, "group") != 0) { eggyyerror("keyword 'group' expected"); @@ -2164,7 +2180,7 @@ case 34: } break; case 35: -#line 759 "parser.yxx" +#line 775 "parser.yxx" { string name = yyvsp[0]._string; EggVertexPool *pool = NULL; @@ -2186,20 +2202,20 @@ case 35: } break; case 36: -#line 779 "parser.yxx" +#line 795 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 39: -#line 807 "parser.yxx" +#line 823 "parser.yxx" { egg_stack.push_back(new EggVertex); } break; case 40: -#line 811 "parser.yxx" +#line 827 "parser.yxx" { PT(EggVertex) vtx = DCAST(EggVertex, egg_stack.back()); egg_stack.pop_back(); @@ -2208,7 +2224,7 @@ case 40: } break; case 41: -#line 818 "parser.yxx" +#line 834 "parser.yxx" { vertex_index = (int)yyvsp[0]._number; EggVertexPool *pool = DCAST(EggVertexPool, egg_stack.back()); @@ -2235,7 +2251,7 @@ case 41: } break; case 42: -#line 843 "parser.yxx" +#line 859 "parser.yxx" { PT(EggVertex) vtx = DCAST(EggVertex, egg_stack.back()); egg_stack.pop_back(); @@ -2247,31 +2263,31 @@ case 42: } break; case 43: -#line 864 "parser.yxx" +#line 880 "parser.yxx" { DCAST(EggVertex, egg_stack.back())->set_pos(yyvsp[0]._number); } break; case 44: -#line 868 "parser.yxx" +#line 884 "parser.yxx" { DCAST(EggVertex, egg_stack.back())->set_pos(LPoint2d(yyvsp[-1]._number, yyvsp[0]._number)); } break; case 45: -#line 872 "parser.yxx" +#line 888 "parser.yxx" { DCAST(EggVertex, egg_stack.back())->set_pos(LPoint3d(yyvsp[-2]._number, yyvsp[-1]._number, yyvsp[0]._number)); } break; case 46: -#line 876 "parser.yxx" +#line 892 "parser.yxx" { DCAST(EggVertex, egg_stack.back())->set_pos(LPoint4d(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number, yyvsp[0]._number)); } break; case 47: -#line 880 "parser.yxx" +#line 896 "parser.yxx" { EggVertex *vertex = DCAST(EggVertex, egg_stack.back()); EggVertexUV *uv = new EggVertexUV(yyvsp[-1]._string, TexCoordd::zero()); @@ -2284,13 +2300,13 @@ case 47: } break; case 48: -#line 891 "parser.yxx" +#line 907 "parser.yxx" { egg_stack.pop_back(); } break; case 51: -#line 897 "parser.yxx" +#line 913 "parser.yxx" { bool inserted = DCAST(EggVertex, egg_stack.back())->_dxyzs. insert(EggMorphVertex(yyvsp[-5]._string, LVector3d(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number))).second; @@ -2300,7 +2316,7 @@ case 51: } break; case 52: -#line 905 "parser.yxx" +#line 921 "parser.yxx" { bool inserted = DCAST(EggVertex, egg_stack.back())->_dxyzs. insert(EggMorphVertex(yyvsp[-4]._string, LVector3d(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number))).second; @@ -2310,13 +2326,13 @@ case 52: } break; case 53: -#line 924 "parser.yxx" +#line 940 "parser.yxx" { DCAST(EggVertexUV, egg_stack.back())->set_uv(TexCoordd(yyvsp[-1]._number, yyvsp[0]._number)); } break; case 54: -#line 928 "parser.yxx" +#line 944 "parser.yxx" { bool inserted = DCAST(EggVertexUV, egg_stack.back())->_duvs. insert(EggMorphTexCoord(yyvsp[-4]._string, LVector2d(yyvsp[-2]._number, yyvsp[-1]._number))).second; @@ -2326,7 +2342,7 @@ case 54: } break; case 55: -#line 936 "parser.yxx" +#line 952 "parser.yxx" { bool inserted = DCAST(EggVertexUV, egg_stack.back())->_duvs. insert(EggMorphTexCoord(yyvsp[-3]._string, LVector2d(yyvsp[-2]._number, yyvsp[-1]._number))).second; @@ -2336,13 +2352,13 @@ case 55: } break; case 56: -#line 954 "parser.yxx" +#line 970 "parser.yxx" { DCAST(EggVertex, egg_stack.back())->set_normal(Normald(yyvsp[-2]._number, yyvsp[-1]._number, yyvsp[0]._number)); } break; case 57: -#line 958 "parser.yxx" +#line 974 "parser.yxx" { bool inserted = DCAST(EggVertex, egg_stack.back())->_dnormals. insert(EggMorphNormal(yyvsp[-5]._string, LVector3d(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number))).second; @@ -2352,7 +2368,7 @@ case 57: } break; case 58: -#line 966 "parser.yxx" +#line 982 "parser.yxx" { bool inserted = DCAST(EggVertex, egg_stack.back())->_dnormals. insert(EggMorphNormal(yyvsp[-4]._string, LVector3d(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number))).second; @@ -2362,13 +2378,13 @@ case 58: } break; case 59: -#line 984 "parser.yxx" +#line 1000 "parser.yxx" { DCAST(EggVertex, egg_stack.back())->set_color(Colorf(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number, yyvsp[0]._number)); } break; case 60: -#line 988 "parser.yxx" +#line 1004 "parser.yxx" { bool inserted = DCAST(EggVertex, egg_stack.back())->_drgbas. insert(EggMorphColor(yyvsp[-6]._string, LVector4f(yyvsp[-4]._number, yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number))).second; @@ -2378,7 +2394,7 @@ case 60: } break; case 61: -#line 996 "parser.yxx" +#line 1012 "parser.yxx" { bool inserted = DCAST(EggVertex, egg_stack.back())->_drgbas. insert(EggMorphColor(yyvsp[-5]._string, LVector4f(yyvsp[-4]._number, yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number))).second; @@ -2388,21 +2404,21 @@ case 61: } break; case 62: -#line 1014 "parser.yxx" +#line 1030 "parser.yxx" { EggGroup *group = new EggGroup(yyvsp[0]._string); egg_stack.push_back(group); } break; case 63: -#line 1019 "parser.yxx" +#line 1035 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 64: -#line 1034 "parser.yxx" +#line 1050 "parser.yxx" { EggGroup *group = new EggGroup(yyvsp[0]._string); group->set_group_type(EggGroup::GT_joint); @@ -2410,14 +2426,14 @@ case 64: } break; case 65: -#line 1040 "parser.yxx" +#line 1056 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 66: -#line 1055 "parser.yxx" +#line 1071 "parser.yxx" { EggGroup *group = new EggGroup(yyvsp[0]._string); group->set_group_type(EggGroup::GT_instance); @@ -2425,14 +2441,14 @@ case 66: } break; case 67: -#line 1061 "parser.yxx" +#line 1077 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 69: -#line 1077 "parser.yxx" +#line 1093 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); string name = yyvsp[-3]._string; @@ -2504,7 +2520,7 @@ case 69: } break; case 70: -#line 1147 "parser.yxx" +#line 1163 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); string strval = yyvsp[-1]._string; @@ -2518,14 +2534,14 @@ case 70: } break; case 71: -#line 1159 "parser.yxx" +#line 1175 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); group->set_billboard_center(LPoint3d(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number)); } break; case 72: -#line 1164 "parser.yxx" +#line 1180 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); string name = yyvsp[-4]._string; @@ -2534,7 +2550,7 @@ case 72: } break; case 73: -#line 1171 "parser.yxx" +#line 1187 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); int value = (int)yyvsp[-1]._number; @@ -2542,7 +2558,7 @@ case 73: } break; case 74: -#line 1177 "parser.yxx" +#line 1193 "parser.yxx" { // The special flavor of DCS, with { sync } or { nosync }. EggGroup *group = DCAST(EggGroup, egg_stack.back()); @@ -2557,7 +2573,7 @@ case 74: } break; case 75: -#line 1190 "parser.yxx" +#line 1206 "parser.yxx" { // The traditional flavor of DART, with { 0 } or { 1 }. EggGroup *group = DCAST(EggGroup, egg_stack.back()); @@ -2566,7 +2582,7 @@ case 75: } break; case 76: -#line 1197 "parser.yxx" +#line 1213 "parser.yxx" { // The special flavor of DART, with { sync } or { nosync }. EggGroup *group = DCAST(EggGroup, egg_stack.back()); @@ -2581,7 +2597,7 @@ case 76: } break; case 77: -#line 1210 "parser.yxx" +#line 1226 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); int value = (int)yyvsp[-1]._number; @@ -2589,7 +2605,7 @@ case 77: } break; case 78: -#line 1216 "parser.yxx" +#line 1232 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); string type = yyvsp[-1]._string; @@ -2597,7 +2613,7 @@ case 78: } break; case 79: -#line 1222 "parser.yxx" +#line 1238 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); int value = (int)yyvsp[-1]._number; @@ -2605,14 +2621,14 @@ case 79: } break; case 80: -#line 1228 "parser.yxx" +#line 1244 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); group->set_tag(yyvsp[-3]._string, yyvsp[-1]._string); } break; case 81: -#line 1233 "parser.yxx" +#line 1249 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); int value = (int)yyvsp[-1]._number; @@ -2620,13 +2636,13 @@ case 81: } break; case 85: -#line 1242 "parser.yxx" +#line 1258 "parser.yxx" { DCAST(EggGroup, egg_stack.back())->add_child(DCAST(EggNode, yyvsp[0]._egg)); } break; case 86: -#line 1256 "parser.yxx" +#line 1272 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); string strval = yyvsp[0]._string; @@ -2648,7 +2664,7 @@ case 86: } break; case 88: -#line 1287 "parser.yxx" +#line 1303 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); string strval = yyvsp[0]._string; @@ -2662,55 +2678,55 @@ case 88: } break; case 89: -#line 1309 "parser.yxx" +#line 1325 "parser.yxx" { DCAST(EggGroup, egg_stack.back())->clear_transform(); } break; case 99: -#line 1335 "parser.yxx" +#line 1351 "parser.yxx" { DCAST(EggGroup, egg_stack.back())->add_translate(LVector3d(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number)); } break; case 100: -#line 1341 "parser.yxx" +#line 1357 "parser.yxx" { DCAST(EggGroup, egg_stack.back())->add_rotx(yyvsp[-1]._number); } break; case 101: -#line 1347 "parser.yxx" +#line 1363 "parser.yxx" { DCAST(EggGroup, egg_stack.back())->add_roty(yyvsp[-1]._number); } break; case 102: -#line 1353 "parser.yxx" +#line 1369 "parser.yxx" { DCAST(EggGroup, egg_stack.back())->add_rotz(yyvsp[-1]._number); } break; case 103: -#line 1359 "parser.yxx" +#line 1375 "parser.yxx" { DCAST(EggGroup, egg_stack.back())->add_rotate(yyvsp[-4]._number, LVector3d(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number)); } break; case 104: -#line 1365 "parser.yxx" +#line 1381 "parser.yxx" { DCAST(EggGroup, egg_stack.back())->add_scale(LVecBase3d(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number)); } break; case 105: -#line 1369 "parser.yxx" +#line 1385 "parser.yxx" { DCAST(EggGroup, egg_stack.back())->add_uniform_scale(yyvsp[-1]._number); } break; case 108: -#line 1384 "parser.yxx" +#line 1400 "parser.yxx" { DCAST(EggGroup, egg_stack.back())->add_matrix (LMatrix4d(yyvsp[-15]._number, yyvsp[-14]._number, yyvsp[-13]._number, yyvsp[-12]._number, @@ -2720,37 +2736,37 @@ case 108: } break; case 109: -#line 1403 "parser.yxx" +#line 1419 "parser.yxx" { matrix_2d = LMatrix3d::ident_mat(); } break; case 110: -#line 1407 "parser.yxx" +#line 1423 "parser.yxx" { DCAST(EggTexture, egg_stack.back())->set_transform(matrix_2d); } break; case 116: -#line 1429 "parser.yxx" +#line 1445 "parser.yxx" { matrix_2d *= LMatrix3d::translate_mat(yyvsp[-2]._number, yyvsp[-1]._number); } break; case 117: -#line 1435 "parser.yxx" +#line 1451 "parser.yxx" { matrix_2d *= LMatrix3d::rotate_mat(yyvsp[-1]._number); } break; case 118: -#line 1441 "parser.yxx" +#line 1457 "parser.yxx" { matrix_2d *= LMatrix3d::scale_mat(yyvsp[-2]._number, yyvsp[-1]._number); } break; case 121: -#line 1454 "parser.yxx" +#line 1470 "parser.yxx" { matrix_2d *= LMatrix3d(yyvsp[-8]._number, yyvsp[-7]._number, yyvsp[-6]._number, yyvsp[-5]._number, yyvsp[-4]._number, yyvsp[-3]._number, @@ -2758,7 +2774,7 @@ case 121: } break; case 122: -#line 1471 "parser.yxx" +#line 1487 "parser.yxx" { if (yyvsp[-2]._egg != (EggVertexPool *)NULL) { EggVertexPool *pool = DCAST(EggVertexPool, yyvsp[-2]._egg); @@ -2782,13 +2798,13 @@ case 122: } break; case 123: -#line 1504 "parser.yxx" +#line 1520 "parser.yxx" { yyval._number = 1.0; } break; case 124: -#line 1508 "parser.yxx" +#line 1524 "parser.yxx" { string name = yyvsp[-3]._string; double value = yyvsp[-1]._number; @@ -2804,86 +2820,86 @@ case 124: } break; case 126: -#line 1545 "parser.yxx" +#line 1561 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); group->set_lod(EggSwitchConditionDistance(yyvsp[-8]._number, yyvsp[-7]._number, LPoint3d(yyvsp[-4]._number, yyvsp[-3]._number, yyvsp[-2]._number))); } break; case 127: -#line 1550 "parser.yxx" +#line 1566 "parser.yxx" { EggGroup *group = DCAST(EggGroup, egg_stack.back()); group->set_lod(EggSwitchConditionDistance(yyvsp[-9]._number, yyvsp[-8]._number, LPoint3d(yyvsp[-4]._number, yyvsp[-3]._number, yyvsp[-2]._number), yyvsp[-7]._number)); } break; case 128: -#line 1567 "parser.yxx" +#line 1583 "parser.yxx" { egg_stack.push_back(new EggPolygon(yyvsp[0]._string)); } break; case 129: -#line 1571 "parser.yxx" +#line 1587 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 130: -#line 1586 "parser.yxx" +#line 1602 "parser.yxx" { egg_stack.push_back(new EggPoint(yyvsp[0]._string)); } break; case 131: -#line 1590 "parser.yxx" +#line 1606 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 132: -#line 1605 "parser.yxx" +#line 1621 "parser.yxx" { egg_stack.push_back(new EggLine(yyvsp[0]._string)); } break; case 133: -#line 1609 "parser.yxx" +#line 1625 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 134: -#line 1624 "parser.yxx" +#line 1640 "parser.yxx" { egg_stack.push_back(new EggNurbsSurface(yyvsp[0]._string)); } break; case 135: -#line 1628 "parser.yxx" +#line 1644 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 136: -#line 1643 "parser.yxx" +#line 1659 "parser.yxx" { egg_stack.push_back(new EggNurbsCurve(yyvsp[0]._string)); } break; case 137: -#line 1647 "parser.yxx" +#line 1663 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 146: -#line 1671 "parser.yxx" +#line 1687 "parser.yxx" { EggPrimitive *primitive = DCAST(EggPrimitive, egg_stack.back()); string name = yyvsp[-3]._string; @@ -2934,7 +2950,7 @@ case 146: } break; case 158: -#line 1741 "parser.yxx" +#line 1757 "parser.yxx" { EggNurbsCurve *curve = DCAST(EggNurbsCurve, yyvsp[0]._egg); EggNurbsSurface *nurbs = DCAST(EggNurbsSurface, egg_stack.back()); @@ -2942,7 +2958,7 @@ case 158: } break; case 160: -#line 1748 "parser.yxx" +#line 1764 "parser.yxx" { EggNurbsSurface *primitive = DCAST(EggNurbsSurface, egg_stack.back()); string name = yyvsp[-3]._string; @@ -2997,7 +3013,7 @@ case 160: } break; case 171: -#line 1822 "parser.yxx" +#line 1838 "parser.yxx" { EggNurbsCurve *primitive = DCAST(EggNurbsCurve, egg_stack.back()); string name = yyvsp[-3]._string; @@ -3058,7 +3074,7 @@ case 171: } break; case 172: -#line 1891 "parser.yxx" +#line 1907 "parser.yxx" { if (yyvsp[0]._egg != (EggTexture *)NULL) { EggTexture *texture = DCAST(EggTexture, yyvsp[0]._egg); @@ -3067,7 +3083,7 @@ case 172: } break; case 173: -#line 1908 "parser.yxx" +#line 1924 "parser.yxx" { EggTexture *texture = NULL; @@ -3099,7 +3115,7 @@ case 173: } break; case 174: -#line 1948 "parser.yxx" +#line 1964 "parser.yxx" { if (yyvsp[0]._egg != (EggMaterial *)NULL) { EggMaterial *material = DCAST(EggMaterial, yyvsp[0]._egg); @@ -3108,13 +3124,13 @@ case 174: } break; case 175: -#line 1965 "parser.yxx" +#line 1981 "parser.yxx" { DCAST(EggPrimitive, egg_stack.back())->set_normal(Normald(yyvsp[-2]._number, yyvsp[-1]._number, yyvsp[0]._number)); } break; case 176: -#line 1969 "parser.yxx" +#line 1985 "parser.yxx" { bool inserted = DCAST(EggPrimitive, egg_stack.back())->_dnormals. insert(EggMorphNormal(yyvsp[-5]._string, LVector3d(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number))).second; @@ -3124,7 +3140,7 @@ case 176: } break; case 177: -#line 1977 "parser.yxx" +#line 1993 "parser.yxx" { bool inserted = DCAST(EggPrimitive, egg_stack.back())->_dnormals. insert(EggMorphNormal(yyvsp[-4]._string, LVector3d(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number))).second; @@ -3134,13 +3150,13 @@ case 177: } break; case 178: -#line 1995 "parser.yxx" +#line 2011 "parser.yxx" { DCAST(EggPrimitive, egg_stack.back())->set_color(Colorf(yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number, yyvsp[0]._number)); } break; case 179: -#line 1999 "parser.yxx" +#line 2015 "parser.yxx" { bool inserted = DCAST(EggPrimitive, egg_stack.back())->_drgbas. insert(EggMorphColor(yyvsp[-6]._string, LVector4f(yyvsp[-4]._number, yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number))).second; @@ -3150,7 +3166,7 @@ case 179: } break; case 180: -#line 2007 "parser.yxx" +#line 2023 "parser.yxx" { bool inserted = DCAST(EggPrimitive, egg_stack.back())->_drgbas. insert(EggMorphColor(yyvsp[-5]._string, LVector4f(yyvsp[-4]._number, yyvsp[-3]._number, yyvsp[-2]._number, yyvsp[-1]._number))).second; @@ -3160,7 +3176,7 @@ case 180: } break; case 181: -#line 2025 "parser.yxx" +#line 2041 "parser.yxx" { EggPrimitive *primitive = DCAST(EggPrimitive, egg_stack.back()); int value = (int)yyvsp[0]._number; @@ -3168,7 +3184,7 @@ case 181: } break; case 182: -#line 2041 "parser.yxx" +#line 2057 "parser.yxx" { if (yyvsp[-2]._egg != (EggVertexPool *)NULL) { EggVertexPool *pool = DCAST(EggVertexPool, yyvsp[-2]._egg); @@ -3191,7 +3207,7 @@ case 182: } break; case 183: -#line 2072 "parser.yxx" +#line 2088 "parser.yxx" { EggNurbsSurface *nurbs = DCAST(EggNurbsSurface, egg_stack.back()); int u_order = (int)yyvsp[-1]._number; @@ -3201,7 +3217,7 @@ case 183: } break; case 184: -#line 2090 "parser.yxx" +#line 2106 "parser.yxx" { EggNurbsSurface *nurbs = DCAST(EggNurbsSurface, egg_stack.back()); PTA_double nums = yyvsp[0]._number_list; @@ -3213,7 +3229,7 @@ case 184: } break; case 185: -#line 2110 "parser.yxx" +#line 2126 "parser.yxx" { EggNurbsSurface *nurbs = DCAST(EggNurbsSurface, egg_stack.back()); PTA_double nums = yyvsp[0]._number_list; @@ -3225,14 +3241,14 @@ case 185: } break; case 186: -#line 2130 "parser.yxx" +#line 2146 "parser.yxx" { EggNurbsSurface *nurbs = DCAST(EggNurbsSurface, egg_stack.back()); nurbs->_trims.push_back(EggNurbsSurface::Trim()); } break; case 188: -#line 2146 "parser.yxx" +#line 2162 "parser.yxx" { EggNurbsSurface *nurbs = DCAST(EggNurbsSurface, egg_stack.back()); nassertr(!nurbs->_trims.empty(), 0); @@ -3240,7 +3256,7 @@ case 188: } break; case 189: -#line 2152 "parser.yxx" +#line 2168 "parser.yxx" { EggNurbsSurface *nurbs = DCAST(EggNurbsSurface, egg_stack.back()); nassertr(!nurbs->_trims.empty(), 0); @@ -3250,7 +3266,7 @@ case 189: } break; case 190: -#line 2171 "parser.yxx" +#line 2187 "parser.yxx" { EggNurbsCurve *nurbs = DCAST(EggNurbsCurve, egg_stack.back()); int order = (int)yyvsp[0]._number; @@ -3258,7 +3274,7 @@ case 190: } break; case 191: -#line 2187 "parser.yxx" +#line 2203 "parser.yxx" { EggNurbsCurve *nurbs = DCAST(EggNurbsCurve, egg_stack.back()); PTA_double nums = yyvsp[0]._number_list; @@ -3270,7 +3286,7 @@ case 191: } break; case 192: -#line 2208 "parser.yxx" +#line 2224 "parser.yxx" { EggTable *table = new EggTable(yyvsp[0]._string); table->set_table_type(EggTable::TT_table); @@ -3278,14 +3294,14 @@ case 192: } break; case 193: -#line 2214 "parser.yxx" +#line 2230 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 194: -#line 2230 "parser.yxx" +#line 2246 "parser.yxx" { EggTable *table = new EggTable(yyvsp[0]._string); table->set_table_type(EggTable::TT_bundle); @@ -3293,58 +3309,58 @@ case 194: } break; case 195: -#line 2236 "parser.yxx" +#line 2252 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 197: -#line 2253 "parser.yxx" -{ - DCAST(EggTable, egg_stack.back())->add_child(DCAST(EggNode, yyvsp[0]._egg)); -} - break; -case 198: -#line 2257 "parser.yxx" -{ - DCAST(EggTable, egg_stack.back())->add_child(DCAST(EggNode, yyvsp[0]._egg)); -} - break; -case 199: -#line 2261 "parser.yxx" -{ - DCAST(EggTable, egg_stack.back())->add_child(DCAST(EggNode, yyvsp[0]._egg)); -} - break; -case 200: -#line 2265 "parser.yxx" -{ - DCAST(EggTable, egg_stack.back())->add_child(DCAST(EggNode, yyvsp[0]._egg)); -} - break; -case 201: #line 2269 "parser.yxx" +{ + DCAST(EggTable, egg_stack.back())->add_child(DCAST(EggNode, yyvsp[0]._egg)); +} + break; +case 198: +#line 2273 "parser.yxx" +{ + DCAST(EggTable, egg_stack.back())->add_child(DCAST(EggNode, yyvsp[0]._egg)); +} + break; +case 199: +#line 2277 "parser.yxx" +{ + DCAST(EggTable, egg_stack.back())->add_child(DCAST(EggNode, yyvsp[0]._egg)); +} + break; +case 200: +#line 2281 "parser.yxx" +{ + DCAST(EggTable, egg_stack.back())->add_child(DCAST(EggNode, yyvsp[0]._egg)); +} + break; +case 201: +#line 2285 "parser.yxx" { DCAST(EggTable, egg_stack.back())->add_child(DCAST(EggNode, yyvsp[0]._egg)); } break; case 202: -#line 2284 "parser.yxx" +#line 2300 "parser.yxx" { EggSAnimData *anim_data = new EggSAnimData(yyvsp[0]._string); egg_stack.push_back(anim_data); } break; case 203: -#line 2289 "parser.yxx" +#line 2305 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 205: -#line 2306 "parser.yxx" +#line 2322 "parser.yxx" { EggSAnimData *anim_data = DCAST(EggSAnimData, egg_stack.back()); string name = yyvsp[-3]._string; @@ -3358,27 +3374,27 @@ case 205: } break; case 206: -#line 2318 "parser.yxx" +#line 2334 "parser.yxx" { DCAST(EggSAnimData, egg_stack.back())->set_data(yyvsp[-1]._number_list); } break; case 207: -#line 2332 "parser.yxx" +#line 2348 "parser.yxx" { EggXfmAnimData *anim_data = new EggXfmAnimData(yyvsp[0]._string); egg_stack.push_back(anim_data); } break; case 208: -#line 2337 "parser.yxx" +#line 2353 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 210: -#line 2354 "parser.yxx" +#line 2370 "parser.yxx" { EggXfmAnimData *anim_data = DCAST(EggXfmAnimData, egg_stack.back()); string name = yyvsp[-3]._string; @@ -3397,27 +3413,27 @@ case 210: } break; case 211: -#line 2371 "parser.yxx" +#line 2387 "parser.yxx" { DCAST(EggXfmAnimData, egg_stack.back())->set_data(yyvsp[-1]._number_list); } break; case 212: -#line 2385 "parser.yxx" +#line 2401 "parser.yxx" { EggXfmSAnim *anim_group = new EggXfmSAnim(yyvsp[0]._string); egg_stack.push_back(anim_group); } break; case 213: -#line 2390 "parser.yxx" +#line 2406 "parser.yxx" { yyval._egg = egg_stack.back(); egg_stack.pop_back(); } break; case 215: -#line 2407 "parser.yxx" +#line 2423 "parser.yxx" { EggXfmSAnim *anim_group = DCAST(EggXfmSAnim, egg_stack.back()); string name = yyvsp[-3]._string; @@ -3434,37 +3450,37 @@ case 215: } break; case 216: -#line 2422 "parser.yxx" +#line 2438 "parser.yxx" { DCAST(EggXfmSAnim, egg_stack.back())->add_child(DCAST(EggNode, yyvsp[0]._egg)); } break; case 217: -#line 2437 "parser.yxx" +#line 2453 "parser.yxx" { yyval._number_list = PTA_double::empty_array(0); } break; case 218: -#line 2441 "parser.yxx" +#line 2457 "parser.yxx" { yyval._number_list.push_back((double)yyvsp[0]._number); } break; case 219: -#line 2455 "parser.yxx" +#line 2471 "parser.yxx" { yyval._number_list = PTA_double::empty_array(0); } break; case 220: -#line 2459 "parser.yxx" +#line 2475 "parser.yxx" { yyval._number_list.push_back(yyvsp[0]._number); } break; case 221: -#line 2473 "parser.yxx" +#line 2489 "parser.yxx" { string name = yyvsp[0]._string; Textures::iterator vpi = textures.find(name); @@ -3477,7 +3493,7 @@ case 221: } break; case 222: -#line 2494 "parser.yxx" +#line 2510 "parser.yxx" { string name = yyvsp[0]._string; Materials::iterator vpi = materials.find(name); @@ -3490,7 +3506,7 @@ case 222: } break; case 223: -#line 2515 "parser.yxx" +#line 2531 "parser.yxx" { string name = yyvsp[0]._string; VertexPools::iterator vpi = vertex_pools.find(name); @@ -3505,69 +3521,69 @@ case 223: } break; case 224: -#line 2539 "parser.yxx" +#line 2555 "parser.yxx" { eggyyerror("Name required."); yyval._string = ""; } break; case 227: -#line 2568 "parser.yxx" +#line 2584 "parser.yxx" { eggyyerror("String required."); yyval._string = ""; } break; case 229: -#line 2584 "parser.yxx" +#line 2600 "parser.yxx" { yyval._string = ""; } break; case 231: -#line 2602 "parser.yxx" +#line 2618 "parser.yxx" { yyval._string = yyvsp[0]._string; } break; case 232: -#line 2606 "parser.yxx" +#line 2622 "parser.yxx" { yyval._string = yyvsp[0]._string; } break; case 234: -#line 2623 "parser.yxx" +#line 2639 "parser.yxx" { yyval._string = ""; } break; case 235: -#line 2627 "parser.yxx" -{ - yyval._string = yyvsp[0]._string; -} - break; -case 236: #line 2643 "parser.yxx" +{ + yyval._string = yyvsp[0]._string; +} + break; +case 236: +#line 2659 "parser.yxx" { yyval._string = yyvsp[0]._string; } break; case 237: -#line 2647 "parser.yxx" +#line 2663 "parser.yxx" { yyval._string = yyvsp[-1]._string + "\n" + yyvsp[0]._string; } break; case 239: -#line 2662 "parser.yxx" +#line 2678 "parser.yxx" { yyval._number = yyvsp[0]._ulong; } break; case 240: -#line 2677 "parser.yxx" +#line 2693 "parser.yxx" { yyval._number = yyvsp[0]._number; yyval._ulong = (unsigned long)yyvsp[0]._number; @@ -3575,7 +3591,7 @@ case 240: } break; case 241: -#line 2683 "parser.yxx" +#line 2699 "parser.yxx" { yyval._number = yyvsp[0]._ulong; yyval._ulong = yyvsp[0]._ulong; @@ -3583,7 +3599,7 @@ case 241: } break; case 242: -#line 2689 "parser.yxx" +#line 2705 "parser.yxx" { yyval._number = 0.0; yyval._ulong = 0; @@ -3591,7 +3607,7 @@ case 242: } break; case 243: -#line 2706 "parser.yxx" +#line 2722 "parser.yxx" { int i = (int)yyvsp[0]._number; if ((double)i != yyvsp[0]._number) { @@ -3601,7 +3617,7 @@ case 243: } break; case 244: -#line 2714 "parser.yxx" +#line 2730 "parser.yxx" { yyval._number = yyvsp[0]._ulong; } @@ -3839,4 +3855,4 @@ yyreturn: #endif return yyresult; } -#line 2721 "parser.yxx" +#line 2737 "parser.yxx" diff --git a/panda/src/egg/parser.yxx b/panda/src/egg/parser.yxx index ace7868243..26bc9bb5a3 100644 --- a/panda/src/egg/parser.yxx +++ b/panda/src/egg/parser.yxx @@ -543,6 +543,22 @@ texture_body: } else if (cmp_nocase_uh(name, "uv_name") == 0) { texture->set_uv_name(strval); + } else if (cmp_nocase_uh(name, "rgb_scale") == 0) { + int int_value = (int)value; + if (int_value != 1 && int_value != 2 && int_value != 4) { + eggyyerror("Invalid rgb-scale value " + strval); + } else { + texture->set_rgb_scale(int_value); + } + + } else if (cmp_nocase_uh(name, "alpha_scale") == 0) { + int int_value = (int)value; + if (int_value != 1 && int_value != 2 && int_value != 4) { + eggyyerror("Invalid alpha-scale value " + strval); + } else { + texture->set_alpha_scale(int_value); + } + } else if (cmp_nocase_uh(name, "alpha") == 0) { EggRenderMode::AlphaMode a = EggRenderMode::string_alpha_mode(strval); if (a == EggRenderMode::AM_unspecified) { diff --git a/panda/src/egg2pg/eggLoader.cxx b/panda/src/egg2pg/eggLoader.cxx index 968babc853..18dd1b582a 100644 --- a/panda/src/egg2pg/eggLoader.cxx +++ b/panda/src/egg2pg/eggLoader.cxx @@ -1188,6 +1188,10 @@ make_texture_stage(const EggTexture *egg_tex) { case EggTexture::ET_add: stage->set_mode(TextureStage::M_add); break; + + case EggTexture::ET_blend_color_scale: + stage->set_mode(TextureStage::M_blend_color_scale); + break; case EggTexture::ET_unspecified: break; @@ -1268,6 +1272,14 @@ make_texture_stage(const EggTexture *egg_tex) { stage->set_texcoord_name(name); } + if (egg_tex->has_rgb_scale()) { + stage->set_rgb_scale(egg_tex->get_rgb_scale()); + } + + if (egg_tex->has_alpha_scale()) { + stage->set_alpha_scale(egg_tex->get_alpha_scale()); + } + stage->set_sort(egg_tex->get_multitexture_sort() * 10); if (egg_tex->has_priority()) { @@ -3047,6 +3059,9 @@ get_combine_source(const EggTexture *egg_tex, case EggTexture::CS_previous: return TextureStage::CS_previous; + + case EggTexture::CS_constant_color_scale: + return TextureStage::CS_constant_color_scale; }; return TextureStage::CS_undefined; diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.I b/panda/src/glstuff/glGraphicsStateGuardian_src.I index 517c962e82..4f03f3f06f 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.I +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.I @@ -171,6 +171,7 @@ enable_multisample_alpha_mask(bool val) { INLINE void CLP(GraphicsStateGuardian):: enable_line_smooth(bool val) { if (_line_smooth_enabled != val) { + _blend_mode_stale = true; _line_smooth_enabled = val; if (val) { GLP(Enable)(GL_LINE_SMOOTH); @@ -188,6 +189,7 @@ enable_line_smooth(bool val) { INLINE void CLP(GraphicsStateGuardian):: enable_point_smooth(bool val) { if (_point_smooth_enabled != val) { + _blend_mode_stale = true; _point_smooth_enabled = val; if (val) { GLP(Enable)(GL_POINT_SMOOTH); @@ -228,7 +230,10 @@ setup_antialias_line() { // have multisample available. enable_multisample_antialias(false); enable_line_smooth(true); - set_blend_mode(); + + if (_blend_mode_stale) { + set_blend_mode(); + } } } @@ -246,7 +251,10 @@ setup_antialias_point() { // have multisample available. enable_multisample_antialias(false); enable_point_smooth(true); - set_blend_mode(); + + if (_blend_mode_stale) { + set_blend_mode(); + } } } @@ -276,13 +284,18 @@ setup_antialias_polygon() { default: // For polygons, multisample is best if it's available, otherwise // polygon smoothing will do. + enable_line_smooth(false); + enable_point_smooth(false); if (_supports_multisample) { enable_multisample_antialias(true); } else { enable_polygon_smooth(true); } } - set_blend_mode(); + + if (_blend_mode_stale) { + set_blend_mode(); + } } } @@ -483,7 +496,7 @@ get_clip_plane_id(int index) const { INLINE void CLP(GraphicsStateGuardian):: issue_scene_graph_color() { if (_scene_graph_color_stale) { - issue_transformed_color(_scene_graph_color); + issue_scaled_color(_scene_graph_color); _scene_graph_color_stale = false; } } diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index ea90e632f2..135b876bd1 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -114,11 +114,11 @@ issue_color_gl(const Geom *geom, Geom::ColorIterator &citerator, } static void -issue_transformed_color_gl(const Geom *geom, Geom::ColorIterator &citerator, +issue_scaled_color_gl(const Geom *geom, Geom::ColorIterator &citerator, GraphicsStateGuardianBase *gsg) { const CLP(GraphicsStateGuardian) *glgsg = DCAST(CLP(GraphicsStateGuardian), gsg); const Colorf &color = geom->get_next_color(citerator); - glgsg->issue_transformed_color(color); + glgsg->issue_scaled_color(color); } // The following noop functions are assigned to the corresponding @@ -784,10 +784,10 @@ draw_point(GeomPoint *geom, GeomContext *gc) { GeomIssuer::IssueColor *issue_color; - if (_color_transform_enabled == 0) { + if (_color_blend_involves_color_scale || !_color_scale_enabled) { issue_color = issue_color_gl; } else { - issue_color = issue_transformed_color_gl; + issue_color = issue_scaled_color_gl; } GeomIssuer issuer(geom, this, @@ -854,10 +854,10 @@ draw_line(GeomLine *geom, GeomContext *gc) { GeomIssuer::IssueColor *issue_color; - if (_color_transform_enabled == 0) { + if (_color_blend_involves_color_scale || !_color_scale_enabled) { issue_color = issue_color_gl; } else { - issue_color = issue_transformed_color_gl; + issue_color = issue_scaled_color_gl; } GeomIssuer issuer(geom, this, @@ -938,10 +938,10 @@ draw_linestrip(GeomLinestrip *geom, GeomContext *gc) { GeomIssuer::IssueColor *issue_color; - if (_color_transform_enabled == 0) { + if (_color_blend_involves_color_scale || !_color_scale_enabled) { issue_color = issue_color_gl; } else { - issue_color = issue_transformed_color_gl; + issue_color = issue_scaled_color_gl; } GeomIssuer issuer(geom, this, @@ -1320,10 +1320,10 @@ draw_polygon(GeomPolygon *geom, GeomContext *gc) { GeomIssuer::IssueColor *issue_color; - if (_color_transform_enabled == 0) { + if (_color_blend_involves_color_scale || !_color_scale_enabled) { issue_color = issue_color_gl; } else { - issue_color = issue_transformed_color_gl; + issue_color = issue_scaled_color_gl; } GeomIssuer issuer(geom, this, @@ -1408,10 +1408,10 @@ draw_tri(GeomTri *geom, GeomContext *gc) { GeomIssuer::IssueColor *issue_color; - if (_color_transform_enabled == 0) { + if (_color_blend_involves_color_scale || !_color_scale_enabled) { issue_color = issue_color_gl; } else { - issue_color = issue_transformed_color_gl; + issue_color = issue_scaled_color_gl; } GeomIssuer issuer(geom, this, @@ -1494,10 +1494,10 @@ draw_quad(GeomQuad *geom, GeomContext *gc) { GeomIssuer::IssueColor *issue_color; - if (_color_transform_enabled == 0) { + if (_color_blend_involves_color_scale || !_color_scale_enabled) { issue_color = issue_color_gl; } else { - issue_color = issue_transformed_color_gl; + issue_color = issue_scaled_color_gl; } GeomIssuer issuer(geom, this, @@ -1584,10 +1584,10 @@ draw_tristrip(GeomTristrip *geom, GeomContext *gc) { GeomIssuer::IssueColor *issue_color; - if (_color_transform_enabled == 0) { + if (_color_blend_involves_color_scale || !_color_scale_enabled) { issue_color = issue_color_gl; } else { - issue_color = issue_transformed_color_gl; + issue_color = issue_scaled_color_gl; } GeomIssuer issuer(geom, this, @@ -1692,10 +1692,10 @@ draw_trifan(GeomTrifan *geom, GeomContext *gc) { GeomIssuer::IssueColor *issue_color; - if (_color_transform_enabled == 0) { + if (_color_blend_involves_color_scale || !_color_scale_enabled) { issue_color = issue_color_gl; } else { - issue_color = issue_transformed_color_gl; + issue_color = issue_scaled_color_gl; } GeomIssuer issuer(geom, this, @@ -1797,10 +1797,10 @@ draw_sphere(GeomSphere *geom, GeomContext *gc) { GeomIssuer::IssueColor *issue_color; - if (_color_transform_enabled == 0) { + if (_color_blend_involves_color_scale || !_color_scale_enabled) { issue_color = issue_color_gl; } else { - issue_color = issue_transformed_color_gl; + issue_color = issue_scaled_color_gl; } GeomIssuer issuer(geom, this, @@ -2387,128 +2387,6 @@ issue_tex_gen(const TexGenAttrib *attrib) { _needs_tex_gen = true; } -//////////////////////////////////////////////////////////////////// -// Function: CLP(GraphicsStateGuardian)::issue_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CLP(GraphicsStateGuardian):: -issue_texture(const TextureAttrib *attrib) { - DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1)); - - CPT(TextureAttrib) new_texture = attrib->filter_to_max(_max_texture_stages); - - int num_stages = new_texture->get_num_on_stages(); - int num_old_stages = _current_texture->get_num_on_stages(); - - nassertv(num_stages <= _max_texture_stages && - num_old_stages <= _max_texture_stages); - - int i; - for (i = 0; i < num_stages; i++) { - TextureStage *stage = new_texture->get_on_stage(i); - Texture *texture = new_texture->get_on_texture(stage); - nassertv(texture != (Texture *)NULL); - - if (i >= num_old_stages || - stage != _current_texture->get_on_stage(i) || - texture != _current_texture->get_on_texture(stage)) { - // Stage i has changed. Issue the texture on this stage. - _glActiveTexture(GL_TEXTURE0 + i); - - GLP(Enable)(GL_TEXTURE_2D); - - TextureContext *tc = texture->prepare_now(_prepared_objects, this); - apply_texture(tc); - - GLint glmode = get_texture_apply_mode_type(stage->get_mode()); - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, glmode); - GLP(TexEnvfv)(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, stage->get_color().get_data()); - - if (stage->get_mode() == TextureStage::M_combine) { - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_COMBINE_RGB, - get_texture_combine_type(stage->get_combine_rgb_mode())); - - switch (stage->get_num_combine_rgb_operands()) { - case 3: - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC2_RGB, - get_texture_src_type(stage->get_combine_rgb_source2())); - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND2_RGB, - get_texture_operand_type(stage->get_combine_rgb_operand2())); - // fall through - - case 2: - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC1_RGB, - get_texture_src_type(stage->get_combine_rgb_source1())); - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND1_RGB, - get_texture_operand_type(stage->get_combine_rgb_operand1())); - // fall through - - case 1: - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC0_RGB, - get_texture_src_type(stage->get_combine_rgb_source0())); - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND0_RGB, - get_texture_operand_type(stage->get_combine_rgb_operand0())); - // fall through - - default: - break; - } - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, - get_texture_combine_type(stage->get_combine_alpha_mode())); - - switch (stage->get_num_combine_alpha_operands()) { - case 3: - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC2_ALPHA, - get_texture_src_type(stage->get_combine_alpha_source2())); - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, - get_texture_operand_type(stage->get_combine_alpha_operand2())); - // fall through - - case 2: - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC1_ALPHA, - get_texture_src_type(stage->get_combine_alpha_source1())); - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, - get_texture_operand_type(stage->get_combine_alpha_operand1())); - // fall through - - case 1: - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC0_ALPHA, - get_texture_src_type(stage->get_combine_alpha_source0())); - GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, - get_texture_operand_type(stage->get_combine_alpha_operand0())); - // fall through - - default: - break; - } - } - - GLP(MatrixMode)(GL_TEXTURE); - if (_current_tex_mat->has_stage(stage)) { - GLP(LoadMatrixf)(_current_tex_mat->get_mat(stage).get_data()); - } else { - GLP(LoadIdentity)(); - } - } - } - - // Disable the texture stages that are no longer used. - for (i = num_stages; i < num_old_stages; i++) { - _glActiveTexture(GL_TEXTURE0 + i); - GLP(Disable)(GL_TEXTURE_2D); - } - - _current_texture = new_texture; - - // Changing the set of texture stages will require us to reissue the - // texgen and texmat attribs. - _needs_tex_gen = true; - _needs_tex_mat = true; - - report_my_gl_errors(); -} - //////////////////////////////////////////////////////////////////// // Function: CLP(GraphicsStateGuardian)::issue_material // Access: Public, Virtual @@ -3976,6 +3854,7 @@ get_texture_apply_mode_type(TextureStage::Mode am) { case TextureStage::M_replace: return GL_REPLACE; case TextureStage::M_add: return GL_ADD; case TextureStage::M_combine: return GL_COMBINE; + case TextureStage::M_blend_color_scale: return GL_BLEND; } GLCAT.error() @@ -4021,6 +3900,7 @@ get_texture_src_type(TextureStage::CombineSource cs) { case TextureStage::CS_constant: return GL_CONSTANT; case TextureStage::CS_primary_color: return GL_PRIMARY_COLOR; case TextureStage::CS_previous: return GL_PREVIOUS; + case TextureStage::CS_constant_color_scale: return GL_CONSTANT; } GLCAT.error() @@ -4141,15 +4021,19 @@ get_blend_func(ColorBlendAttrib::Operand operand) { return GL_ONE_MINUS_DST_ALPHA; case ColorBlendAttrib::O_constant_color: + case ColorBlendAttrib::O_color_scale: return GL_CONSTANT_COLOR; case ColorBlendAttrib::O_one_minus_constant_color: + case ColorBlendAttrib::O_one_minus_color_scale: return GL_ONE_MINUS_CONSTANT_COLOR; case ColorBlendAttrib::O_constant_alpha: + case ColorBlendAttrib::O_alpha_scale: return GL_CONSTANT_ALPHA; case ColorBlendAttrib::O_one_minus_constant_alpha: + case ColorBlendAttrib::O_one_minus_alpha_scale: return GL_ONE_MINUS_CONSTANT_ALPHA; case ColorBlendAttrib::O_incoming_color_saturate: @@ -4211,18 +4095,18 @@ print_gfx_visual() { } //////////////////////////////////////////////////////////////////// -// Function: CLP(GraphicsStateGuardian)::issue_transformed_color +// Function: CLP(GraphicsStateGuardian)::issue_scaled_color // Access: Public // Description: Transform the color by the current color matrix, and // calls the appropriate glColor function. //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: -issue_transformed_color(const Colorf &color) const { +issue_scaled_color(const Colorf &color) const { Colorf transformed - ((color[0] * _current_color_scale[0]) + _current_color_offset[0], - (color[1] * _current_color_scale[1]) + _current_color_offset[1], - (color[2] * _current_color_scale[2]) + _current_color_offset[2], - (color[3] * _current_color_scale[3]) + _current_color_offset[3]); + (color[0] * _current_color_scale[0], + color[1] * _current_color_scale[1], + color[2] * _current_color_scale[2], + color[3] * _current_color_scale[3]); GLP(Color4fv)(transformed.get_data()); } @@ -4462,8 +4346,16 @@ set_blend_mode() { _glBlendEquation(get_blend_equation_type(_color_blend_mode)); GLP(BlendFunc)(get_blend_func(_color_blend->get_operand_a()), get_blend_func(_color_blend->get_operand_b())); - Colorf c = _color_blend->get_color(); - _glBlendColor(c[0], c[1], c[2], c[3]); + + if (_color_blend_involves_color_scale) { + // Apply the current color scale to the blend mode. + _glBlendColor(_current_color_scale[0], _current_color_scale[1], + _current_color_scale[2], _current_color_scale[3]); + + } else { + Colorf c = _color_blend->get_color(); + _glBlendColor(c[0], c[1], c[2], c[3]); + } return; } @@ -4538,6 +4430,14 @@ set_blend_mode() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: finish_modify_state() { + GraphicsStateGuardian::finish_modify_state(); + + // Apply the texture, if it needs to be reapplied. + if (_texture_stale) { + _texture_stale = false; + do_issue_texture(); + } + // Apply the texture matrix, if needed. if (_needs_tex_mat) { _needs_tex_mat = false; @@ -4810,6 +4710,170 @@ do_auto_rescale_normal() { } } +//////////////////////////////////////////////////////////////////// +// Function: CLP(GraphicsStateGuardian)::do_issue_texture +// Access: Protected +// Description: This is called by finish_modify_state() when the +// texture state has changed. +//////////////////////////////////////////////////////////////////// +void CLP(GraphicsStateGuardian):: +do_issue_texture() { + DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1)); + + CPT(TextureAttrib) new_texture = _pending_texture->filter_to_max(_max_texture_stages); + + int num_stages = new_texture->get_num_on_stages(); + int num_old_stages = _current_texture->get_num_on_stages(); + + nassertv(num_stages <= _max_texture_stages && + num_old_stages <= _max_texture_stages); + + _texture_involves_color_scale = false; + + int i; + for (i = 0; i < num_stages; i++) { + TextureStage *stage = new_texture->get_on_stage(i); + Texture *texture = new_texture->get_on_texture(stage); + nassertv(texture != (Texture *)NULL); + + if (i >= num_old_stages || + stage != _current_texture->get_on_stage(i) || + texture != _current_texture->get_on_texture(stage) || + stage->involves_color_scale()) { + // Stage i has changed. Issue the texture on this stage. + _glActiveTexture(GL_TEXTURE0 + i); + + GLP(Enable)(GL_TEXTURE_2D); + + TextureContext *tc = texture->prepare_now(_prepared_objects, this); + apply_texture(tc); + + if (stage->involves_color_scale() && _color_scale_enabled) { + Colorf color = stage->get_color(); + color.set(color[0] * _current_color_scale[0], + color[1] * _current_color_scale[1], + color[2] * _current_color_scale[2], + color[3] * _current_color_scale[3]); + _texture_involves_color_scale = true; + GLP(TexEnvfv)(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color.get_data()); + } else { + GLP(TexEnvfv)(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, stage->get_color().get_data()); + } + + if (stage->get_mode() == TextureStage::M_decal) { + if (texture->_pbuffer != (PixelBuffer *)NULL && + texture->_pbuffer->get_num_components() < 3) { + // Make a special case for 1- and 2-channel decal textures. + // OpenGL does not define their use with GL_DECAL for some + // reason, so implement them using the combiner instead. + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_RGB_SCALE, 1); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_TEXTURE); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA); + + } else { + // Normal 3- and 4-channel decal textures. + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + } + + } else if (stage->get_mode() == TextureStage::M_combine) { + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_RGB_SCALE, stage->get_rgb_scale()); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_ALPHA_SCALE, stage->get_alpha_scale()); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_COMBINE_RGB, + get_texture_combine_type(stage->get_combine_rgb_mode())); + + switch (stage->get_num_combine_rgb_operands()) { + case 3: + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC2_RGB, + get_texture_src_type(stage->get_combine_rgb_source2())); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND2_RGB, + get_texture_operand_type(stage->get_combine_rgb_operand2())); + // fall through + + case 2: + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC1_RGB, + get_texture_src_type(stage->get_combine_rgb_source1())); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND1_RGB, + get_texture_operand_type(stage->get_combine_rgb_operand1())); + // fall through + + case 1: + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC0_RGB, + get_texture_src_type(stage->get_combine_rgb_source0())); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND0_RGB, + get_texture_operand_type(stage->get_combine_rgb_operand0())); + // fall through + + default: + break; + } + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, + get_texture_combine_type(stage->get_combine_alpha_mode())); + + switch (stage->get_num_combine_alpha_operands()) { + case 3: + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC2_ALPHA, + get_texture_src_type(stage->get_combine_alpha_source2())); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, + get_texture_operand_type(stage->get_combine_alpha_operand2())); + // fall through + + case 2: + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC1_ALPHA, + get_texture_src_type(stage->get_combine_alpha_source1())); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, + get_texture_operand_type(stage->get_combine_alpha_operand1())); + // fall through + + case 1: + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_SRC0_ALPHA, + get_texture_src_type(stage->get_combine_alpha_source0())); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, + get_texture_operand_type(stage->get_combine_alpha_operand0())); + // fall through + + default: + break; + } + + } else { + GLint glmode = get_texture_apply_mode_type(stage->get_mode()); + GLP(TexEnvi)(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, glmode); + } + + GLP(MatrixMode)(GL_TEXTURE); + if (_current_tex_mat->has_stage(stage)) { + GLP(LoadMatrixf)(_current_tex_mat->get_mat(stage).get_data()); + } else { + GLP(LoadIdentity)(); + } + } + } + + // Disable the texture stages that are no longer used. + for (i = num_stages; i < num_old_stages; i++) { + _glActiveTexture(GL_TEXTURE0 + i); + GLP(Disable)(GL_TEXTURE_2D); + } + + _current_texture = new_texture; + + // Changing the set of texture stages will require us to reissue the + // texgen and texmat attribs. + _needs_tex_gen = true; + _needs_tex_mat = true; + + report_my_gl_errors(); +} + #ifndef NDEBUG //////////////////////////////////////////////////////////////////// // Function: CLP(GraphicsStateGuardian)::build_phony_mipmaps diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index 026eea5866..c3220d8f5e 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -112,7 +112,6 @@ public: virtual void issue_transform(const TransformState *transform); virtual void issue_tex_matrix(const TexMatrixAttrib *attrib); - virtual void issue_texture(const TextureAttrib *attrib); virtual void issue_material(const MaterialAttrib *attrib); virtual void issue_render_mode(const RenderModeAttrib *attrib); virtual void issue_antialias(const AntialiasAttrib *); @@ -148,7 +147,7 @@ public: //enabled/disable GL State compared to what GL says it is void dump_state(void); - void issue_transformed_color(const Colorf &color) const; + void issue_scaled_color(const Colorf &color) const; INLINE static bool report_errors(int line, const char *source_file); INLINE void report_my_errors(int line, const char *source_file); @@ -240,6 +239,7 @@ protected: static CPT(RenderState) get_untextured_state(); void do_auto_rescale_normal(); + void do_issue_texture(); #ifndef NDEBUG void build_phony_mipmaps(Texture *tex); @@ -247,6 +247,12 @@ protected: void save_mipmap_images(Texture *tex); #endif + enum AutoAntialiasMode { + AA_poly, + AA_line, + AA_point, + }; + enum MultisampleMode { MM_antialias = 0x0001, MM_alpha_one = 0x0002, diff --git a/panda/src/gobj/textureStage.I b/panda/src/gobj/textureStage.I index 8507c7e72e..84e63227eb 100755 --- a/panda/src/gobj/textureStage.I +++ b/panda/src/gobj/textureStage.I @@ -17,6 +17,16 @@ //////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +// Function: TextureStage::Copy Constructor +// Access: Published +// Description: Initialize the texture stage from other +//////////////////////////////////////////////////////////////////// +INLINE TextureStage:: +TextureStage(TextureStage ©) { + (*this) = copy; +} + //////////////////////////////////////////////////////////////////// // Function: TextureStage::get_name // Access: Published @@ -118,37 +128,6 @@ operator < (const TextureStage &other) const { return (_sort < other._sort); } -//////////////////////////////////////////////////////////////////// -// Function: TextureStage::opertor = -// Access: Published -// Description: just copy the members of other to this -//////////////////////////////////////////////////////////////////// -INLINE TextureStage &TextureStage:: -operator = (const TextureStage &other) { - _name = other._name; - _sort = other._sort; - _priority = other._priority; - _texcoord_name = other._texcoord_name; - _mode = other._mode; - _color = other._color; - _combine_rgb_mode = other._combine_rgb_mode; - _combine_rgb_source0 = other._combine_rgb_source0; - _combine_rgb_operand0 = other._combine_rgb_operand0; - _combine_rgb_source1 = other._combine_rgb_source1; - _combine_rgb_operand1 = other._combine_rgb_operand1; - _combine_rgb_source2 = other._combine_rgb_source2; - _combine_rgb_operand2 = other._combine_rgb_operand2; - _combine_alpha_mode = other._combine_alpha_mode; - _combine_alpha_source0 = other._combine_alpha_source0; - _combine_alpha_operand0 = _combine_alpha_operand0; - _combine_alpha_source1 = other._combine_alpha_source1; - _combine_alpha_operand1 = other._combine_alpha_operand1; - _combine_alpha_source2 = other._combine_alpha_source2; - _combine_alpha_operand2 = other._combine_alpha_operand2; - - return *this; -} - //////////////////////////////////////////////////////////////////// // Function: TextureStage::set_texcoord_name // Access: Published @@ -196,6 +175,7 @@ set_mode(TextureStage::Mode mode) { _num_combine_rgb_operands = 0; _num_combine_alpha_operands = 0; } + set_involves_color_scale(); } //////////////////////////////////////////////////////////////////// @@ -228,6 +208,57 @@ get_color() const { return _color; } +//////////////////////////////////////////////////////////////////// +// Function: TextureStage::set_rgb_scale +// Access: Published +// Description: Sets an additional factor that will scale all three +// r, g, b components after the texture has been +// applied. This is used only when the mode is +// CM_combine. +// +// The only legal values are 1, 2, or 4. +//////////////////////////////////////////////////////////////////// +INLINE void TextureStage:: +set_rgb_scale(int rgb_scale) { + nassertv(rgb_scale == 1 || rgb_scale == 2 || rgb_scale == 4); + _rgb_scale = rgb_scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: TextureStage::get_rgb_scale +// Access: Published +// Description: See set_rgb_scale(). +//////////////////////////////////////////////////////////////////// +INLINE int TextureStage:: +get_rgb_scale() const { + return _rgb_scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: TextureStage::set_alpha_scale +// Access: Published +// Description: Sets an additional factor that will scale the +// alpha component after the texture has been applied. +// This is used only when the mode is CM_combine. +// +// The only legal values are 1, 2, or 4. +//////////////////////////////////////////////////////////////////// +INLINE void TextureStage:: +set_alpha_scale(int alpha_scale) { + nassertv(alpha_scale == 1 || alpha_scale == 2 || alpha_scale == 4); + _alpha_scale = alpha_scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: TextureStage::get_alpha_scale +// Access: Published +// Description: See set_alpha_scale(). +//////////////////////////////////////////////////////////////////// +INLINE int TextureStage:: +get_alpha_scale() const { + return _alpha_scale; +} + //////////////////////////////////////////////////////////////////// // Function: TextureStage::set_combine_rgb // Access: Published @@ -249,6 +280,8 @@ set_combine_rgb(CombineMode mode, _combine_rgb_operand1 = CO_undefined; _combine_rgb_source2 = CS_undefined; _combine_rgb_operand2 = CO_undefined; + + set_involves_color_scale(); } //////////////////////////////////////////////////////////////////// @@ -275,6 +308,8 @@ set_combine_rgb(CombineMode mode, _combine_rgb_operand1 = operand1; _combine_rgb_source2 = CS_undefined; _combine_rgb_operand2 = CO_undefined; + + set_involves_color_scale(); } //////////////////////////////////////////////////////////////////// @@ -302,6 +337,8 @@ set_combine_rgb(CombineMode mode, _combine_rgb_operand1 = operand1; _combine_rgb_source2 = source2; _combine_rgb_operand2 = operand2; + + set_involves_color_scale(); } //////////////////////////////////////////////////////////////////// @@ -407,6 +444,8 @@ set_combine_alpha(CombineMode mode, _combine_alpha_operand1 = CO_undefined; _combine_alpha_source2 = CS_undefined; _combine_alpha_operand2 = CO_undefined; + + set_involves_color_scale(); } //////////////////////////////////////////////////////////////////// @@ -433,6 +472,8 @@ set_combine_alpha(CombineMode mode, _combine_alpha_operand1 = operand1; _combine_alpha_source2 = CS_undefined; _combine_alpha_operand2 = CO_undefined; + + set_involves_color_scale(); } //////////////////////////////////////////////////////////////////// @@ -460,6 +501,8 @@ set_combine_alpha(CombineMode mode, _combine_alpha_operand1 = operand1; _combine_alpha_source2 = source2; _combine_alpha_operand2 = operand2; + + set_involves_color_scale(); } //////////////////////////////////////////////////////////////////// @@ -544,6 +587,18 @@ get_combine_alpha_operand2() const { return _combine_alpha_operand2; } +//////////////////////////////////////////////////////////////////// +// Function: TextureStage::involves_color_scale +// Access: Published +// Description: Returns true if the TextureStage is affected by the +// setting of the current ColorScaleAttrib, false +// otherwise. +//////////////////////////////////////////////////////////////////// +INLINE bool TextureStage:: +involves_color_scale() const { + return _involves_color_scale; +} + //////////////////////////////////////////////////////////////////// // Function: TextureStage::get_default // Access: Published, Static @@ -574,6 +629,23 @@ get_sort_seq() { return _sort_seq; } +//////////////////////////////////////////////////////////////////// +// Function: TextureStage::set_involves_color_scale +// Access: Private +// Description: Updates _involves_color_scale appropriately. +//////////////////////////////////////////////////////////////////// +INLINE void TextureStage:: +set_involves_color_scale() { + _involves_color_scale = (_mode == M_blend_color_scale || + (_mode == M_combine && + (_combine_rgb_source0 == CS_constant_color_scale || + _combine_rgb_source1 == CS_constant_color_scale || + _combine_rgb_source2 == CS_constant_color_scale || + _combine_alpha_source0 == CS_constant_color_scale || + _combine_alpha_source1 == CS_constant_color_scale || + _combine_alpha_source2 == CS_constant_color_scale))); +} + INLINE ostream & operator << (ostream &out, const TextureStage &ts) { ts.output(out); diff --git a/panda/src/gobj/textureStage.cxx b/panda/src/gobj/textureStage.cxx index 367b8def1b..54239e9f29 100755 --- a/panda/src/gobj/textureStage.cxx +++ b/panda/src/gobj/textureStage.cxx @@ -37,6 +37,8 @@ TextureStage(const string &name) { _texcoord_name = TexCoordName::get_default(); _mode = M_modulate; _color.set(0.0f, 0.0f, 0.0f, 1.0f); + _rgb_scale = 1; + _alpha_scale = 1; _combine_rgb_mode = CM_undefined; _num_combine_rgb_operands = 0; _combine_rgb_source0 = CS_undefined; @@ -53,36 +55,42 @@ TextureStage(const string &name) { _combine_alpha_operand1 = CO_undefined; _combine_alpha_source2 = CS_undefined; _combine_alpha_operand2 = CO_undefined; + + _involves_color_scale = false; } //////////////////////////////////////////////////////////////////// -// Function: TextureStage::Constructor +// Function: TextureStage::operator = // Access: Published -// Description: Initialize the texture stage from other +// Description: just copy the members of other to this //////////////////////////////////////////////////////////////////// -TextureStage:: -TextureStage(TextureStage *copy) { - _name = copy->_name; - _sort = copy->_sort; - _priority = copy->_priority; - _texcoord_name = copy->_texcoord_name; - _mode = copy->_mode; - _color = copy->_color; - _combine_rgb_mode = copy->_combine_rgb_mode; - _combine_rgb_source0 = copy->_combine_rgb_source0; - _combine_rgb_operand0 = copy->_combine_rgb_operand0; - _combine_rgb_source1 = copy->_combine_rgb_source1; - _combine_rgb_operand1 = copy->_combine_rgb_operand1; - _combine_rgb_source2 = copy->_combine_rgb_source2; - _combine_rgb_operand2 = copy->_combine_rgb_operand2; - _combine_alpha_mode = copy->_combine_alpha_mode; - _combine_alpha_source0 = copy->_combine_alpha_source0; - _combine_alpha_operand0 = _combine_alpha_operand0; - _combine_alpha_source1 = copy->_combine_alpha_source1; - _combine_alpha_operand1 = copy->_combine_alpha_operand1; - _combine_alpha_source2 = copy->_combine_alpha_source2; - _combine_alpha_operand2 = copy->_combine_alpha_operand2; +void TextureStage:: +operator = (const TextureStage &other) { + _name = other._name; + _sort = other._sort; + _priority = other._priority; + _texcoord_name = other._texcoord_name; + _mode = other._mode; + _color = other._color; + _rgb_scale = other._rgb_scale; + _alpha_scale = other._alpha_scale; + _combine_rgb_mode = other._combine_rgb_mode; + _combine_rgb_source0 = other._combine_rgb_source0; + _combine_rgb_operand0 = other._combine_rgb_operand0; + _combine_rgb_source1 = other._combine_rgb_source1; + _combine_rgb_operand1 = other._combine_rgb_operand1; + _combine_rgb_source2 = other._combine_rgb_source2; + _combine_rgb_operand2 = other._combine_rgb_operand2; + _combine_alpha_mode = other._combine_alpha_mode; + _combine_alpha_source0 = other._combine_alpha_source0; + _combine_alpha_operand0 = _combine_alpha_operand0; + _combine_alpha_source1 = other._combine_alpha_source1; + _combine_alpha_operand1 = other._combine_alpha_operand1; + _combine_alpha_source2 = other._combine_alpha_source2; + _combine_alpha_operand2 = other._combine_alpha_operand2; + + _involves_color_scale = other._involves_color_scale; } //////////////////////////////////////////////////////////////////// @@ -103,7 +111,8 @@ void TextureStage:: write(ostream &out) const { out << "TextureStage " << get_name() << ", sort = " << get_sort() << ", priority = " << get_priority() << "\n" << " texcoords = " << get_texcoord_name()->get_name() - << ", mode = " << get_mode() << ", color = " << get_color() << "\n"; + << ", mode = " << get_mode() << ", color = " << get_color() + << ", scale = " << get_rgb_scale() << ", " << get_alpha_scale() << "\n"; if (get_mode() == M_combine) { out << " RGB combine mode = " << get_combine_rgb_mode() << "\n"; @@ -269,6 +278,14 @@ fillin(DatagramIterator &scan, BamReader *manager) { _mode = (TextureStage::Mode) scan.get_uint8(); _color.read_datagram(scan); + + if (manager->get_file_minor_ver() >= 16) { + _rgb_scale = scan.get_uint8(); + _alpha_scale = scan.get_uint8(); + } else { + _rgb_scale = 1; + _alpha_scale = 1; + } _combine_rgb_mode = (TextureStage::CombineMode) scan.get_uint8(); _num_combine_rgb_operands = scan.get_uint8(); @@ -287,6 +304,8 @@ fillin(DatagramIterator &scan, BamReader *manager) { _combine_alpha_operand1 = (TextureStage::CombineOperand) scan.get_uint8(); _combine_alpha_source2 = (TextureStage::CombineSource) scan.get_uint8(); _combine_alpha_operand2 = (TextureStage::CombineOperand) scan.get_uint8(); + + set_involves_color_scale(); } //////////////////////////////////////////////////////////////////// @@ -322,10 +341,12 @@ write_datagram(BamWriter *manager, Datagram &me) { me.add_int32(_sort); me.add_int32(_priority); - manager->write_pointer(me,_texcoord_name); + manager->write_pointer(me, _texcoord_name); me.add_uint8(_mode); _color.write_datagram(me); + me.add_uint8(_rgb_scale); + me.add_uint8(_alpha_scale); me.add_uint8(_combine_rgb_mode); me.add_uint8(_num_combine_rgb_operands); @@ -367,6 +388,9 @@ operator << (ostream &out, TextureStage::Mode mode) { case TextureStage::M_combine: return out << "combine"; + + case TextureStage::M_blend_color_scale: + return out << "blend_color_scale"; } return out << "**invalid Mode(" << (int)mode << ")**"; @@ -423,6 +447,9 @@ operator << (ostream &out, TextureStage::CombineSource cs) { case TextureStage::CS_previous: return out << "previous"; + + case TextureStage::CS_constant_color_scale: + return out << "constant_color_scale"; } return out << "**invalid CombineSource(" << (int)cs << ")**"; diff --git a/panda/src/gobj/textureStage.h b/panda/src/gobj/textureStage.h index 983fdef974..04520131c7 100644 --- a/panda/src/gobj/textureStage.h +++ b/panda/src/gobj/textureStage.h @@ -42,7 +42,9 @@ class FactoryParams; class EXPCL_PANDA TextureStage : public TypedWritableReferenceCount { PUBLISHED: TextureStage(const string &name); - TextureStage(TextureStage *copy); + INLINE TextureStage(TextureStage ©); + void operator = (const TextureStage ©); + virtual ~TextureStage(); enum Mode { @@ -52,6 +54,7 @@ PUBLISHED: M_replace, M_add, M_combine, + M_blend_color_scale, }; enum CombineMode { @@ -75,6 +78,7 @@ PUBLISHED: CS_constant, CS_primary_color, CS_previous, + CS_constant_color_scale, }; enum CombineOperand { @@ -95,7 +99,6 @@ PUBLISHED: INLINE int get_priority() const; INLINE bool operator < (const TextureStage &other) const; - INLINE TextureStage &operator = (const TextureStage ©); INLINE void set_texcoord_name(const TexCoordName *name); INLINE void set_texcoord_name(const string &texcoord_name); @@ -107,6 +110,12 @@ PUBLISHED: INLINE void set_color(const Colorf &color); INLINE Colorf get_color() const; + INLINE void set_rgb_scale(int rgb_scale); + INLINE int get_rgb_scale() const; + + INLINE void set_alpha_scale(int alpha_scale); + INLINE int get_alpha_scale() const; + INLINE void set_combine_rgb(CombineMode mode, CombineSource source0, CombineOperand operand0); INLINE void set_combine_rgb(CombineMode mode, @@ -143,6 +152,8 @@ PUBLISHED: INLINE CombineSource get_combine_alpha_source2() const; INLINE CombineOperand get_combine_alpha_operand2() const; + INLINE bool involves_color_scale() const; + void write(ostream &out) const; void output(ostream &out) const; @@ -150,6 +161,8 @@ PUBLISHED: INLINE static UpdateSeq get_sort_seq(); private: + INLINE void set_involves_color_scale(); + static int get_expected_num_combine_operands(CombineMode cm); static bool operand_valid_for_rgb(CombineOperand co); static bool operand_valid_for_alpha(CombineOperand co); @@ -160,6 +173,9 @@ private: CPT(TexCoordName) _texcoord_name; Mode _mode; Colorf _color; + int _rgb_scale; + int _alpha_scale; + bool _involves_color_scale; CombineMode _combine_rgb_mode; int _num_combine_rgb_operands; diff --git a/panda/src/grutil/multitexReducer.cxx b/panda/src/grutil/multitexReducer.cxx index 46da30e823..4bf9c5fd3e 100644 --- a/panda/src/grutil/multitexReducer.cxx +++ b/panda/src/grutil/multitexReducer.cxx @@ -741,6 +741,14 @@ make_texture_layer(const NodePath &render, (ColorBlendAttrib::M_add, ColorBlendAttrib::O_fbuffer_color, ColorBlendAttrib::O_zero); break; + + case TextureStage::M_blend_color_scale: + // TODO: make a distinction between this and M_blend. + cba = ColorBlendAttrib::make + (ColorBlendAttrib::M_add, ColorBlendAttrib::O_constant_color, + ColorBlendAttrib::O_one_minus_incoming_color, + stage_info._stage->get_color()); + break; } NodePath geom; diff --git a/panda/src/pgraph/colorBlendAttrib.I b/panda/src/pgraph/colorBlendAttrib.I index fe12a71140..460946d720 100644 --- a/panda/src/pgraph/colorBlendAttrib.I +++ b/panda/src/pgraph/colorBlendAttrib.I @@ -28,7 +28,9 @@ ColorBlendAttrib() : _mode(M_none), _a(O_one), _b(O_one), - _color(Colorf::zero()) + _color(Colorf::zero()), + _involves_constant_color(false), + _involves_color_scale(false) { } @@ -45,7 +47,9 @@ ColorBlendAttrib(ColorBlendAttrib::Mode mode, _mode(mode), _a(a), _b(b), - _color(color) + _color(color), + _involves_constant_color(involves_constant_color(a) || involves_constant_color(b)), + _involves_color_scale(involves_color_scale(a) || involves_color_scale(b)) { } @@ -89,6 +93,28 @@ get_color() const { return _color; } +//////////////////////////////////////////////////////////////////// +// Function: ColorBlendAttrib::involves_constant_color +// Access: Published +// Description: Returns true if the this attrib uses the +// constant color, false otherwise. +//////////////////////////////////////////////////////////////////// +INLINE bool ColorBlendAttrib:: +involves_constant_color() const { + return _involves_constant_color; +} + +//////////////////////////////////////////////////////////////////// +// Function: ColorBlendAttrib::involves_color_scale +// Access: Published +// Description: Returns true if the this attrib uses the +// color scale attrib, false otherwise. +//////////////////////////////////////////////////////////////////// +INLINE bool ColorBlendAttrib:: +involves_color_scale() const { + return _involves_color_scale; +} + //////////////////////////////////////////////////////////////////// // Function: ColorBlendAttrib::involves_constant_color // Access: Published, Static @@ -96,7 +122,7 @@ get_color() const { // constant color, false otherwise. //////////////////////////////////////////////////////////////////// INLINE bool ColorBlendAttrib:: -involves_constant_color(Operand operand) { +involves_constant_color(ColorBlendAttrib::Operand operand) { switch (operand) { case O_constant_color: case O_one_minus_constant_color: @@ -108,3 +134,23 @@ involves_constant_color(Operand operand) { return false; } } + +//////////////////////////////////////////////////////////////////// +// Function: ColorBlendAttrib::involves_color_scale +// Access: Published, Static +// Description: Returns true if the indicated operand uses the +// color scale attrib, false otherwise. +//////////////////////////////////////////////////////////////////// +INLINE bool ColorBlendAttrib:: +involves_color_scale(ColorBlendAttrib::Operand operand) { + switch (operand) { + case O_color_scale: + case O_one_minus_color_scale: + case O_alpha_scale: + case O_one_minus_alpha_scale: + return true; + + default: + return false; + } +} diff --git a/panda/src/pgraph/colorBlendAttrib.cxx b/panda/src/pgraph/colorBlendAttrib.cxx index 969f091296..3914884263 100644 --- a/panda/src/pgraph/colorBlendAttrib.cxx +++ b/panda/src/pgraph/colorBlendAttrib.cxx @@ -94,8 +94,7 @@ output(ostream &out) const { if (get_mode() != M_none) { out << "(" << get_operand_a() << "," << get_operand_b(); - if (involves_constant_color(get_operand_a()) || - involves_constant_color(get_operand_b())) { + if (involves_constant_color()) { out << "," << get_color(); } out << ")"; @@ -215,6 +214,9 @@ fillin(DatagramIterator &scan, BamReader *manager) { _a = (Operand)scan.get_uint8(); _b = (Operand)scan.get_uint8(); _color.read_datagram(scan); + + _involves_constant_color = involves_constant_color(_a) || involves_constant_color(_b); + _involves_color_scale = involves_color_scale(_a) || involves_color_scale(_b); } //////////////////////////////////////////////////////////////////// @@ -297,6 +299,18 @@ operator << (ostream &out, ColorBlendAttrib::Operand operand) { case ColorBlendAttrib::O_incoming_color_saturate: return out << "ics"; + + case ColorBlendAttrib::O_color_scale: + return out << "cs"; + + case ColorBlendAttrib::O_one_minus_color_scale: + return out << "1-cs"; + + case ColorBlendAttrib::O_alpha_scale: + return out << "as"; + + case ColorBlendAttrib::O_one_minus_alpha_scale: + return out << "1-as"; } return out << "**invalid ColorBlendAttrib::Operand(" << (int)operand << ")**"; diff --git a/panda/src/pgraph/colorBlendAttrib.h b/panda/src/pgraph/colorBlendAttrib.h index 3d11e26a46..3a29c0157b 100644 --- a/panda/src/pgraph/colorBlendAttrib.h +++ b/panda/src/pgraph/colorBlendAttrib.h @@ -58,6 +58,17 @@ PUBLISHED: O_constant_alpha, O_one_minus_constant_alpha, O_incoming_color_saturate, // valid only for operand a + + // If you set either of the operands to any of the below, the + // blend color is taken from the current ColorScaleAttrib. This + // also inhibits the normal behavior of the ColorScaleAttrib; it + // no longer directly scales the vertex colors, on the assumption + // that you will instead take care of the scale here, in the blend + // mode. + O_color_scale, + O_one_minus_color_scale, + O_alpha_scale, + O_one_minus_alpha_scale, }; private: @@ -76,7 +87,11 @@ PUBLISHED: INLINE Operand get_operand_b() const; INLINE Colorf get_color() const; + INLINE bool involves_constant_color() const; + INLINE bool involves_color_scale() const; + INLINE static bool involves_constant_color(Operand operand); + INLINE static bool involves_color_scale(Operand operand); public: virtual void issue(GraphicsStateGuardianBase *gsg) const; @@ -90,6 +105,8 @@ private: Mode _mode; Operand _a, _b; Colorf _color; + bool _involves_constant_color; + bool _involves_color_scale; public: static void register_with_read_factory(); diff --git a/panda/src/pgui/pgSliderBar.cxx b/panda/src/pgui/pgSliderBar.cxx index 9c84e2817b..d82277d6b7 100755 --- a/panda/src/pgui/pgSliderBar.cxx +++ b/panda/src/pgui/pgSliderBar.cxx @@ -68,8 +68,8 @@ PGSliderBar:: PGSliderBar:: PGSliderBar(const PGSliderBar ©) : PGItem(copy), - _range(copy._range), _value(copy._value), + _range(copy._range), // _slider(copy._slider), _left(copy._left), _right(copy._right) @@ -238,7 +238,7 @@ drag(const MouseWatcherParameter ¶m) { //////////////////////////////////////////////////////////////////// void PGSliderBar:: update() { - int state = get_state(); + // int state = get_state(); // need left and right button input if they exist if (!_slider_only) { diff --git a/panda/src/putil/bam.h b/panda/src/putil/bam.h index 5f9ad8facb..39e5993974 100644 --- a/panda/src/putil/bam.h +++ b/panda/src/putil/bam.h @@ -34,7 +34,7 @@ static const unsigned short _bam_major_ver = 4; // Bumped to major version 3 on 12/8/00 to change float64's to float32's. // Bumped to major version 4 on 4/10/02 to store new scene graph. -static const unsigned short _bam_minor_ver = 15; +static const unsigned short _bam_minor_ver = 16; // Bumped to minor version 1 on 4/10/03 to add CullFaceAttrib::reverse. // Bumped to minor version 1 on 4/10/03 to add CullFaceAttrib::reverse. // Bumped to minor version 2 on 4/12/03 to add num_components to texture. @@ -51,6 +51,7 @@ static const unsigned short _bam_minor_ver = 15; // Bumped to minor version 13 on 09/24/04 to store actual LODNode switch distances instead of squares. // Bumped to minor version 14 on 11/18/04 to differentiate old_hpr from new_hpr in compressed anim channels. // Bumped to minor version 15 on 1/16/05 to remove width from GeomLine, etc. +// Bumped to minor version 16 on 2/24/05 to add TextureStage::rgb_scale, etc. #endif diff --git a/panda/src/tform/mouseWatcher.cxx b/panda/src/tform/mouseWatcher.cxx index 7f83fc3315..079d850e71 100644 --- a/panda/src/tform/mouseWatcher.cxx +++ b/panda/src/tform/mouseWatcher.cxx @@ -1046,6 +1046,10 @@ do_transmit_data(const DataNodeTransmit &input, DataNodeTransmit &output) { case ButtonEvent::T_resume_down: // Ignore this, since the button wasn't pressed just now. break; + + case ButtonEvent::T_move: + // This is handled below. + break; } } }