From ef0f4859329cdd34ff3d3a673b47abc488ff05cf Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 22 Dec 2005 18:32:33 +0000 Subject: [PATCH] more egg texture options; add gl-support-clamp-to-border --- panda/src/doc/eggSyntax.txt | 18 +++ panda/src/egg/eggTexture.I | 44 +++++++ panda/src/egg/eggTexture.cxx | 25 ++++ panda/src/egg/eggTexture.h | 10 +- panda/src/egg/parser.yxx | 20 ++++ panda/src/egg2pg/config_egg2pg.cxx | 2 - panda/src/egg2pg/eggLoader.cxx | 108 +++++++----------- panda/src/egg2pg/eggLoader.h | 1 + .../glstuff/glGraphicsStateGuardian_src.cxx | 5 +- panda/src/glstuff/glShaderContext_src.cxx | 2 +- panda/src/glstuff/glmisc_src.cxx | 7 ++ panda/src/glstuff/glmisc_src.h | 1 + panda/src/gobj/texture.cxx | 5 + .../osMesaGraphicsStateGuardian.cxx | 2 +- panda/src/putil/bam.h | 3 +- panda/src/putil/bamWriter.cxx | 4 +- 16 files changed, 178 insertions(+), 79 deletions(-) diff --git a/panda/src/doc/eggSyntax.txt b/panda/src/doc/eggSyntax.txt index b88694cdde..1b5eea5695 100644 --- a/panda/src/doc/eggSyntax.txt +++ b/panda/src/doc/eggSyntax.txt @@ -182,6 +182,24 @@ appear before they are referenced. Although less often used, for 3-d textures wrapw may also be specified, and it behaves similarly to wrapu and wrapv. + There are other legal values in addtional to REPEAT and CLAMP. + The full list is: + + CLAMP + REPEAT + MIRROR + MIRROR_ONCE + BORDER_COLOR + + borderr { red-value } + borderg { green-value } + borderb { blue-value } + bordera { alpha-value } + + These define the "border color" of the texture, which is + particularly important when one of the wrap modes, above, is + BORDER_COLOR. + type { texture-type } This may be one of the following attributes: diff --git a/panda/src/egg/eggTexture.I b/panda/src/egg/eggTexture.I index 94d0177d3e..435545d60c 100644 --- a/panda/src/egg/eggTexture.I +++ b/panda/src/egg/eggTexture.I @@ -569,6 +569,50 @@ get_color() const { return _color; } +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::set_border_color +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void EggTexture:: +set_border_color(const Colorf &border_color) { + _border_color = border_color; + _flags |= F_has_border_color; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::clear_border_color +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void EggTexture:: +clear_border_color() { + _border_color.set(0.0f, 0.0f, 0.0f, 1.0f); + _flags &= ~F_has_border_color; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::has_border_color +// Access: Published +// Description: Returns true if a border color has been +// specified for the texture. +//////////////////////////////////////////////////////////////////// +INLINE bool EggTexture:: +has_border_color() const { + return (_flags & F_has_border_color) != 0; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::get_border_color +// Access: Published +// Description: Returns the border color if one has been +// specified, or (0, 0, 0, 1) otherwise. +//////////////////////////////////////////////////////////////////// +INLINE const Colorf &EggTexture:: +get_border_color() const { + return _border_color; +} + //////////////////////////////////////////////////////////////////// // Function: EggTexture::set_uv_name // Access: Published diff --git a/panda/src/egg/eggTexture.cxx b/panda/src/egg/eggTexture.cxx index 6f8871a658..0fc0dab69f 100644 --- a/panda/src/egg/eggTexture.cxx +++ b/panda/src/egg/eggTexture.cxx @@ -49,6 +49,7 @@ EggTexture(const string &tref_name, const string &filename) _tex_gen = TG_unspecified; _priority = 0; _color.set(0.0f, 0.0f, 0.0f, 1.0f); + _border_color.set(0.0f, 0.0f, 0.0f, 1.0f); _flags = 0; _alpha_file_channel = 0; _multitexture_sort = 0; @@ -92,6 +93,7 @@ operator = (const EggTexture ©) { _stage_name = copy._stage_name; _priority = copy._priority; _color = copy._color; + _border_color = copy._border_color; _uv_name = copy._uv_name; _rgb_scale = 1; _alpha_scale = 1; @@ -242,6 +244,17 @@ write(ostream &out, int indent_level) const { << " blenda { " << _color[3] << " }\n"; } + if (has_border_color()) { + indent(out, indent_level + 2) + << " borderr { " << _border_color[0] << " }\n"; + indent(out, indent_level + 2) + << " borderg { " << _border_color[1] << " }\n"; + indent(out, indent_level + 2) + << " borderb { " << _border_color[2] << " }\n"; + indent(out, indent_level + 2) + << " bordera { " << _border_color[3] << " }\n"; + } + if (has_uv_name()) { indent(out, indent_level + 2) << " uv-name { " << get_uv_name() << " }\n"; @@ -680,6 +693,12 @@ string_wrap_mode(const string &string) { return WM_repeat; } else if (cmp_nocase_uh(string, "clamp") == 0) { return WM_clamp; + } else if (cmp_nocase_uh(string, "mirror") == 0) { + return WM_clamp; + } else if (cmp_nocase_uh(string, "mirror_once") == 0) { + return WM_clamp; + } else if (cmp_nocase_uh(string, "border_color") == 0) { + return WM_border_color; } else { return WM_unspecified; } @@ -1060,6 +1079,12 @@ ostream &operator << (ostream &out, EggTexture::WrapMode mode) { return out << "repeat"; case EggTexture::WM_clamp: return out << "clamp"; + case EggTexture::WM_mirror: + return out << "mirror"; + case EggTexture::WM_mirror_once: + return out << "mirror_once"; + case EggTexture::WM_border_color: + return out << "border_color"; } nassertr(false, out); diff --git a/panda/src/egg/eggTexture.h b/panda/src/egg/eggTexture.h index ee6a9c9464..83769085ac 100644 --- a/panda/src/egg/eggTexture.h +++ b/panda/src/egg/eggTexture.h @@ -70,7 +70,8 @@ PUBLISHED: F_luminance_alpha, F_luminance_alphamask }; enum WrapMode { - WM_unspecified, WM_repeat, WM_clamp + WM_unspecified, WM_clamp, WM_repeat, + WM_mirror, WM_mirror_once, WM_border_color }; enum FilterType { // Note that these type values match up, name-for-name, with a @@ -213,6 +214,11 @@ PUBLISHED: INLINE bool has_color() const; INLINE const Colorf &get_color() const; + INLINE void set_border_color(const Colorf &border_color); + INLINE void clear_border_color(); + INLINE bool has_border_color() const; + INLINE const Colorf &get_border_color() const; + INLINE void set_uv_name(const string &uv_name); INLINE void clear_uv_name(); INLINE bool has_uv_name() const; @@ -275,6 +281,7 @@ private: F_has_color = 0x0080, F_has_rgb_scale = 0x0100, F_has_alpha_scale = 0x0200, + F_has_border_color = 0x0400, }; TextureType _texture_type; @@ -288,6 +295,7 @@ private: string _stage_name; int _priority; Colorf _color; + Colorf _border_color; string _uv_name; int _rgb_scale; int _alpha_scale; diff --git a/panda/src/egg/parser.yxx b/panda/src/egg/parser.yxx index 382395de25..2c1219dc46 100644 --- a/panda/src/egg/parser.yxx +++ b/panda/src/egg/parser.yxx @@ -560,6 +560,26 @@ texture_body: color[3] = value; texture->set_color(color); + } else if (cmp_nocase_uh(name, "borderr") == 0) { + Colorf border_color = texture->get_border_color(); + border_color[0] = value; + texture->set_border_color(border_color); + + } else if (cmp_nocase_uh(name, "borderg") == 0) { + Colorf border_color = texture->get_border_color(); + border_color[1] = value; + texture->set_border_color(border_color); + + } else if (cmp_nocase_uh(name, "borderb") == 0) { + Colorf border_color = texture->get_border_color(); + border_color[2] = value; + texture->set_border_color(border_color); + + } else if (cmp_nocase_uh(name, "bordera") == 0) { + Colorf border_color = texture->get_border_color(); + border_color[3] = value; + texture->set_border_color(border_color); + } else if (cmp_nocase_uh(name, "uv_name") == 0) { texture->set_uv_name(strval); diff --git a/panda/src/egg2pg/config_egg2pg.cxx b/panda/src/egg2pg/config_egg2pg.cxx index 310d25edda..051a6aba96 100644 --- a/panda/src/egg2pg/config_egg2pg.cxx +++ b/panda/src/egg2pg/config_egg2pg.cxx @@ -40,8 +40,6 @@ ConfigVariableBool egg_ignore_mipmaps ("egg-ignore-mipmaps", false); ConfigVariableBool egg_ignore_filters ("egg-ignore-filters", false); -ConfigVariableBool egg_ignore_clamp -("egg-ignore-clamp", false); ConfigVariableBool egg_ignore_decals ("egg-ignore-decals", false); ConfigVariableBool egg_flatten diff --git a/panda/src/egg2pg/eggLoader.cxx b/panda/src/egg2pg/eggLoader.cxx index f6db77b446..6149b5e5db 100644 --- a/panda/src/egg2pg/eggLoader.cxx +++ b/panda/src/egg2pg/eggLoader.cxx @@ -927,76 +927,12 @@ load_texture(TextureDef &def, const EggTexture *egg_tex) { //////////////////////////////////////////////////////////////////// void EggLoader:: apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) { - switch (egg_tex->determine_wrap_u()) { - case EggTexture::WM_repeat: - tex->set_wrap_u(Texture::WM_repeat); - break; + tex->set_wrap_u(convert_wrap_mode(egg_tex->determine_wrap_u())); + tex->set_wrap_v(convert_wrap_mode(egg_tex->determine_wrap_v())); + tex->set_wrap_w(convert_wrap_mode(egg_tex->determine_wrap_w())); - case EggTexture::WM_clamp: - if (egg_ignore_clamp) { - egg2pg_cat.warning() - << "Ignoring clamp request\n"; - tex->set_wrap_u(Texture::WM_repeat); - } else { - tex->set_wrap_u(Texture::WM_clamp); - } - break; - - case EggTexture::WM_unspecified: - break; - - default: - egg2pg_cat.warning() - << "Unexpected texture wrap flag: " - << (int)egg_tex->determine_wrap_u() << "\n"; - } - - switch (egg_tex->determine_wrap_v()) { - case EggTexture::WM_repeat: - tex->set_wrap_v(Texture::WM_repeat); - break; - - case EggTexture::WM_clamp: - if (egg_ignore_clamp) { - egg2pg_cat.warning() - << "Ignoring clamp request\n"; - tex->set_wrap_v(Texture::WM_repeat); - } else { - tex->set_wrap_v(Texture::WM_clamp); - } - break; - - case EggTexture::WM_unspecified: - break; - - default: - egg2pg_cat.warning() - << "Unexpected texture wrap flag: " - << (int)egg_tex->determine_wrap_v() << "\n"; - } - - switch (egg_tex->determine_wrap_w()) { - case EggTexture::WM_repeat: - tex->set_wrap_w(Texture::WM_repeat); - break; - - case EggTexture::WM_clamp: - if (egg_ignore_clamp) { - egg2pg_cat.warning() - << "Ignoring clamp request\n"; - tex->set_wrap_w(Texture::WM_repeat); - } else { - tex->set_wrap_w(Texture::WM_clamp); - } - break; - - case EggTexture::WM_unspecified: - break; - - default: - egg2pg_cat.warning() - << "Unexpected texture wrap flag: " - << (int)egg_tex->determine_wrap_w() << "\n"; + if (egg_tex->has_border_color()) { + tex->set_border_color(egg_tex->get_border_color()); } switch (egg_tex->get_minfilter()) { @@ -1234,6 +1170,40 @@ apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) { } } +//////////////////////////////////////////////////////////////////// +// Function: EggLoader::convert_wrap_mode +// Access: Private +// Description: Returns the Texture::WrapMode enum corresponding to +// the EggTexture::WrapMode. Returns WM_repeat if the +// wrap mode is unspecified. +//////////////////////////////////////////////////////////////////// +Texture::WrapMode EggLoader:: +convert_wrap_mode(EggTexture::WrapMode wrap_mode) const { + switch (wrap_mode) { + case EggTexture::WM_clamp: + return Texture::WM_clamp; + + case EggTexture::WM_repeat: + return Texture::WM_repeat; + + case EggTexture::WM_mirror: + return Texture::WM_mirror; + + case EggTexture::WM_mirror_once: + return Texture::WM_mirror_once; + + case EggTexture::WM_border_color: + return Texture::WM_border_color; + + case EggTexture::WM_unspecified: + return Texture::WM_repeat; + } + + egg2pg_cat.warning() + << "Unexpected texture wrap flag: " << (int)wrap_mode << "\n"; + return Texture::WM_repeat; +} + //////////////////////////////////////////////////////////////////// // Function: EggLoader::make_texture_stage // Access: Private diff --git a/panda/src/egg2pg/eggLoader.h b/panda/src/egg2pg/eggLoader.h index ceeac507ef..fb36bc38a1 100644 --- a/panda/src/egg2pg/eggLoader.h +++ b/panda/src/egg2pg/eggLoader.h @@ -122,6 +122,7 @@ private: void load_textures(); bool load_texture(TextureDef &def, const EggTexture *egg_tex); void apply_texture_attributes(Texture *tex, const EggTexture *egg_tex); + Texture::WrapMode convert_wrap_mode(EggTexture::WrapMode wrap_mode) const; PT(TextureStage) make_texture_stage(const EggTexture *egg_tex); void separate_switches(EggNode *egg_node); diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index ba86662ead..59be836e06 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -673,8 +673,9 @@ reset() { } _border_clamp = GL_CLAMP; - if (has_extension("GL_ARB_texture_border_clamp") || - is_at_least_version(1, 3)) { + if (CLP(support_clamp_to_border) && + (has_extension("GL_ARB_texture_border_clamp") || + is_at_least_version(1, 3))) { _border_clamp = GL_CLAMP_TO_BORDER; } diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index eb592574cb..e82c44119d 100755 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -146,7 +146,7 @@ parse_cg_profile(const string &id, bool vertex) } return CG_PROFILE_UNKNOWN; } -#endif HAVE_CGGL +#endif // HAVE_CGGL //////////////////////////////////////////////////////////////////// // Function: GLShaderContext::try_cg_compile diff --git a/panda/src/glstuff/glmisc_src.cxx b/panda/src/glstuff/glmisc_src.cxx index 87478d7caa..ea6eb03584 100644 --- a/panda/src/glstuff/glmisc_src.cxx +++ b/panda/src/glstuff/glmisc_src.cxx @@ -28,6 +28,13 @@ ConfigVariableBool CLP(ignore_clamp) PRC_DESC("Configure this true to disable texture clamp mode (all textures " "repeat, a little cheaper for software renderers).")); +ConfigVariableBool CLP(support_clamp_to_border) + ("gl-support-clamp-to-border", true, + PRC_DESC("Configure this true to enable the use of the clamp_to_border " + "if the GL claims to support it, or false not to use it even " + "if it appears to be available. (On some OpenGL drivers, " + "enabling this mode can force software rendering.)")); + ConfigVariableBool CLP(ignore_filters) ("gl-ignore-filters", false, PRC_DESC("Configure this true to disable any texture filters at all (forcing " diff --git a/panda/src/glstuff/glmisc_src.h b/panda/src/glstuff/glmisc_src.h index c94833f900..6b14c79b83 100644 --- a/panda/src/glstuff/glmisc_src.h +++ b/panda/src/glstuff/glmisc_src.h @@ -23,6 +23,7 @@ extern ConfigVariableBool CLP(cheap_textures); extern ConfigVariableBool CLP(ignore_clamp); +extern ConfigVariableBool CLP(support_clamp_to_border); extern ConfigVariableBool CLP(ignore_filters); extern ConfigVariableBool CLP(ignore_mipmaps); extern ConfigVariableBool CLP(force_mipmaps); diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index f6e65c7656..5a7d676d69 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -1828,6 +1828,10 @@ fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata) { _magfilter = (FilterType)scan.get_uint8(); _anisotropic_degree = scan.get_int16(); + if (manager->get_file_minor_ver() >= 5) { + _border_color.read_datagram(scan); + } + Format format = (Format)scan.get_uint8(); int num_components = scan.get_uint8(); @@ -1945,6 +1949,7 @@ write_datagram(BamWriter *manager, Datagram &me) { me.add_uint8(_minfilter); me.add_uint8(_magfilter); me.add_int16(_anisotropic_degree); + _border_color.write_datagram(me); me.add_uint8(_format); me.add_uint8(_num_components); diff --git a/panda/src/mesadisplay/osMesaGraphicsStateGuardian.cxx b/panda/src/mesadisplay/osMesaGraphicsStateGuardian.cxx index 70faf7547c..8c4636107d 100644 --- a/panda/src/mesadisplay/osMesaGraphicsStateGuardian.cxx +++ b/panda/src/mesadisplay/osMesaGraphicsStateGuardian.cxx @@ -73,7 +73,7 @@ get_extension_func(const char *, const char *name) { // Mesa functions to "mgl", they're still stored as "gl" in the // OSMesaGetProcAddress() lookup table. string fullname = string("gl") + string(name); - return OSMesaGetProcAddress(fullname.c_str()); + return (void *)OSMesaGetProcAddress(fullname.c_str()); #else // Otherwise, too bad. No extension functions for you. We could diff --git a/panda/src/putil/bam.h b/panda/src/putil/bam.h index 426b886599..c579376edf 100644 --- a/panda/src/putil/bam.h +++ b/panda/src/putil/bam.h @@ -35,11 +35,12 @@ static const unsigned short _bam_major_ver = 5; // Bumped to major version 4 on 4/10/02 to store new scene graph. // Bumped to major version 5 on 5/6/05 for new Geom implementation. -static const unsigned short _bam_minor_ver = 4; +static const unsigned short _bam_minor_ver = 5; // Bumped to minor version 1 on 7/14/05 to add TextureStage::_saved_result. // Bumped to minor version 2 on 7/21/05 to add TransformState::is_2d. // Bumped to minor version 3 on 8/25/05 to add ModelNode::_preserve_attributes. // Bumped to minor version 4 on 9/27/05 to make SequenceNode inherit from AnimInterface. +// Bumped to minor version 5 on 12/22/05 to add Texture::_border_color. #endif diff --git a/panda/src/putil/bamWriter.cxx b/panda/src/putil/bamWriter.cxx index e9883790e4..58982afe24 100644 --- a/panda/src/putil/bamWriter.cxx +++ b/panda/src/putil/bamWriter.cxx @@ -34,8 +34,8 @@ //////////////////////////////////////////////////////////////////// BamWriter:: BamWriter(DatagramSink *sink, const Filename &name) : - _target(sink), - _filename(name) + _filename(name), + _target(sink) { }