more egg texture options; add gl-support-clamp-to-border

This commit is contained in:
David Rose 2005-12-22 18:32:33 +00:00
parent 9e82e17ae7
commit ef0f485932
16 changed files with 178 additions and 79 deletions

View File

@ -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
<Scalar> borderr { red-value }
<Scalar> borderg { green-value }
<Scalar> borderb { blue-value }
<Scalar> 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.
<Scalar> type { texture-type }
This may be one of the following attributes:

View File

@ -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

View File

@ -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 &copy) {
_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 {
<< "<Scalar> blenda { " << _color[3] << " }\n";
}
if (has_border_color()) {
indent(out, indent_level + 2)
<< "<Scalar> borderr { " << _border_color[0] << " }\n";
indent(out, indent_level + 2)
<< "<Scalar> borderg { " << _border_color[1] << " }\n";
indent(out, indent_level + 2)
<< "<Scalar> borderb { " << _border_color[2] << " }\n";
indent(out, indent_level + 2)
<< "<Scalar> bordera { " << _border_color[3] << " }\n";
}
if (has_uv_name()) {
indent(out, indent_level + 2)
<< "<Scalar> 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);

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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 "

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -34,8 +34,8 @@
////////////////////////////////////////////////////////////////////
BamWriter::
BamWriter(DatagramSink *sink, const Filename &name) :
_target(sink),
_filename(name)
_filename(name),
_target(sink)
{
}