Skip to content

Commit ef0f485

Browse files
committed
more egg texture options; add gl-support-clamp-to-border
1 parent 9e82e17 commit ef0f485

File tree

16 files changed

+178
-79
lines changed

16 files changed

+178
-79
lines changed

panda/src/doc/eggSyntax.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,24 @@ appear before they are referenced.
182182
Although less often used, for 3-d textures wrapw may also be
183183
specified, and it behaves similarly to wrapu and wrapv.
184184

185+
There are other legal values in addtional to REPEAT and CLAMP.
186+
The full list is:
187+
188+
CLAMP
189+
REPEAT
190+
MIRROR
191+
MIRROR_ONCE
192+
BORDER_COLOR
193+
194+
<Scalar> borderr { red-value }
195+
<Scalar> borderg { green-value }
196+
<Scalar> borderb { blue-value }
197+
<Scalar> bordera { alpha-value }
198+
199+
These define the "border color" of the texture, which is
200+
particularly important when one of the wrap modes, above, is
201+
BORDER_COLOR.
202+
185203
<Scalar> type { texture-type }
186204

187205
This may be one of the following attributes:

panda/src/egg/eggTexture.I

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,50 @@ get_color() const {
569569
return _color;
570570
}
571571

572+
////////////////////////////////////////////////////////////////////
573+
// Function: EggTexture::set_border_color
574+
// Access: Published
575+
// Description:
576+
////////////////////////////////////////////////////////////////////
577+
INLINE void EggTexture::
578+
set_border_color(const Colorf &border_color) {
579+
_border_color = border_color;
580+
_flags |= F_has_border_color;
581+
}
582+
583+
////////////////////////////////////////////////////////////////////
584+
// Function: EggTexture::clear_border_color
585+
// Access: Published
586+
// Description:
587+
////////////////////////////////////////////////////////////////////
588+
INLINE void EggTexture::
589+
clear_border_color() {
590+
_border_color.set(0.0f, 0.0f, 0.0f, 1.0f);
591+
_flags &= ~F_has_border_color;
592+
}
593+
594+
////////////////////////////////////////////////////////////////////
595+
// Function: EggTexture::has_border_color
596+
// Access: Published
597+
// Description: Returns true if a border color has been
598+
// specified for the texture.
599+
////////////////////////////////////////////////////////////////////
600+
INLINE bool EggTexture::
601+
has_border_color() const {
602+
return (_flags & F_has_border_color) != 0;
603+
}
604+
605+
////////////////////////////////////////////////////////////////////
606+
// Function: EggTexture::get_border_color
607+
// Access: Published
608+
// Description: Returns the border color if one has been
609+
// specified, or (0, 0, 0, 1) otherwise.
610+
////////////////////////////////////////////////////////////////////
611+
INLINE const Colorf &EggTexture::
612+
get_border_color() const {
613+
return _border_color;
614+
}
615+
572616
////////////////////////////////////////////////////////////////////
573617
// Function: EggTexture::set_uv_name
574618
// Access: Published

panda/src/egg/eggTexture.cxx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ EggTexture(const string &tref_name, const string &filename)
4949
_tex_gen = TG_unspecified;
5050
_priority = 0;
5151
_color.set(0.0f, 0.0f, 0.0f, 1.0f);
52+
_border_color.set(0.0f, 0.0f, 0.0f, 1.0f);
5253
_flags = 0;
5354
_alpha_file_channel = 0;
5455
_multitexture_sort = 0;
@@ -92,6 +93,7 @@ operator = (const EggTexture &copy) {
9293
_stage_name = copy._stage_name;
9394
_priority = copy._priority;
9495
_color = copy._color;
96+
_border_color = copy._border_color;
9597
_uv_name = copy._uv_name;
9698
_rgb_scale = 1;
9799
_alpha_scale = 1;
@@ -242,6 +244,17 @@ write(ostream &out, int indent_level) const {
242244
<< "<Scalar> blenda { " << _color[3] << " }\n";
243245
}
244246

247+
if (has_border_color()) {
248+
indent(out, indent_level + 2)
249+
<< "<Scalar> borderr { " << _border_color[0] << " }\n";
250+
indent(out, indent_level + 2)
251+
<< "<Scalar> borderg { " << _border_color[1] << " }\n";
252+
indent(out, indent_level + 2)
253+
<< "<Scalar> borderb { " << _border_color[2] << " }\n";
254+
indent(out, indent_level + 2)
255+
<< "<Scalar> bordera { " << _border_color[3] << " }\n";
256+
}
257+
245258
if (has_uv_name()) {
246259
indent(out, indent_level + 2)
247260
<< "<Scalar> uv-name { " << get_uv_name() << " }\n";
@@ -680,6 +693,12 @@ string_wrap_mode(const string &string) {
680693
return WM_repeat;
681694
} else if (cmp_nocase_uh(string, "clamp") == 0) {
682695
return WM_clamp;
696+
} else if (cmp_nocase_uh(string, "mirror") == 0) {
697+
return WM_clamp;
698+
} else if (cmp_nocase_uh(string, "mirror_once") == 0) {
699+
return WM_clamp;
700+
} else if (cmp_nocase_uh(string, "border_color") == 0) {
701+
return WM_border_color;
683702
} else {
684703
return WM_unspecified;
685704
}
@@ -1060,6 +1079,12 @@ ostream &operator << (ostream &out, EggTexture::WrapMode mode) {
10601079
return out << "repeat";
10611080
case EggTexture::WM_clamp:
10621081
return out << "clamp";
1082+
case EggTexture::WM_mirror:
1083+
return out << "mirror";
1084+
case EggTexture::WM_mirror_once:
1085+
return out << "mirror_once";
1086+
case EggTexture::WM_border_color:
1087+
return out << "border_color";
10631088
}
10641089

10651090
nassertr(false, out);

panda/src/egg/eggTexture.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class EXPCL_PANDAEGG EggTexture : public EggFilenameNode, public EggRenderMode,
7070
F_luminance_alpha, F_luminance_alphamask
7171
};
7272
enum WrapMode {
73-
WM_unspecified, WM_repeat, WM_clamp
73+
WM_unspecified, WM_clamp, WM_repeat,
74+
WM_mirror, WM_mirror_once, WM_border_color
7475
};
7576
enum FilterType {
7677
// Note that these type values match up, name-for-name, with a
@@ -213,6 +214,11 @@ class EXPCL_PANDAEGG EggTexture : public EggFilenameNode, public EggRenderMode,
213214
INLINE bool has_color() const;
214215
INLINE const Colorf &get_color() const;
215216

217+
INLINE void set_border_color(const Colorf &border_color);
218+
INLINE void clear_border_color();
219+
INLINE bool has_border_color() const;
220+
INLINE const Colorf &get_border_color() const;
221+
216222
INLINE void set_uv_name(const string &uv_name);
217223
INLINE void clear_uv_name();
218224
INLINE bool has_uv_name() const;
@@ -275,6 +281,7 @@ class EXPCL_PANDAEGG EggTexture : public EggFilenameNode, public EggRenderMode,
275281
F_has_color = 0x0080,
276282
F_has_rgb_scale = 0x0100,
277283
F_has_alpha_scale = 0x0200,
284+
F_has_border_color = 0x0400,
278285
};
279286

280287
TextureType _texture_type;
@@ -288,6 +295,7 @@ class EXPCL_PANDAEGG EggTexture : public EggFilenameNode, public EggRenderMode,
288295
string _stage_name;
289296
int _priority;
290297
Colorf _color;
298+
Colorf _border_color;
291299
string _uv_name;
292300
int _rgb_scale;
293301
int _alpha_scale;

panda/src/egg/parser.yxx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,26 @@ texture_body:
560560
color[3] = value;
561561
texture->set_color(color);
562562

563+
} else if (cmp_nocase_uh(name, "borderr") == 0) {
564+
Colorf border_color = texture->get_border_color();
565+
border_color[0] = value;
566+
texture->set_border_color(border_color);
567+
568+
} else if (cmp_nocase_uh(name, "borderg") == 0) {
569+
Colorf border_color = texture->get_border_color();
570+
border_color[1] = value;
571+
texture->set_border_color(border_color);
572+
573+
} else if (cmp_nocase_uh(name, "borderb") == 0) {
574+
Colorf border_color = texture->get_border_color();
575+
border_color[2] = value;
576+
texture->set_border_color(border_color);
577+
578+
} else if (cmp_nocase_uh(name, "bordera") == 0) {
579+
Colorf border_color = texture->get_border_color();
580+
border_color[3] = value;
581+
texture->set_border_color(border_color);
582+
563583
} else if (cmp_nocase_uh(name, "uv_name") == 0) {
564584
texture->set_uv_name(strval);
565585

panda/src/egg2pg/config_egg2pg.cxx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ ConfigVariableBool egg_ignore_mipmaps
4040
("egg-ignore-mipmaps", false);
4141
ConfigVariableBool egg_ignore_filters
4242
("egg-ignore-filters", false);
43-
ConfigVariableBool egg_ignore_clamp
44-
("egg-ignore-clamp", false);
4543
ConfigVariableBool egg_ignore_decals
4644
("egg-ignore-decals", false);
4745
ConfigVariableBool egg_flatten

panda/src/egg2pg/eggLoader.cxx

Lines changed: 39 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -927,76 +927,12 @@ load_texture(TextureDef &def, const EggTexture *egg_tex) {
927927
////////////////////////////////////////////////////////////////////
928928
void EggLoader::
929929
apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) {
930-
switch (egg_tex->determine_wrap_u()) {
931-
case EggTexture::WM_repeat:
932-
tex->set_wrap_u(Texture::WM_repeat);
933-
break;
934-
935-
case EggTexture::WM_clamp:
936-
if (egg_ignore_clamp) {
937-
egg2pg_cat.warning()
938-
<< "Ignoring clamp request\n";
939-
tex->set_wrap_u(Texture::WM_repeat);
940-
} else {
941-
tex->set_wrap_u(Texture::WM_clamp);
942-
}
943-
break;
944-
945-
case EggTexture::WM_unspecified:
946-
break;
947-
948-
default:
949-
egg2pg_cat.warning()
950-
<< "Unexpected texture wrap flag: "
951-
<< (int)egg_tex->determine_wrap_u() << "\n";
952-
}
953-
954-
switch (egg_tex->determine_wrap_v()) {
955-
case EggTexture::WM_repeat:
956-
tex->set_wrap_v(Texture::WM_repeat);
957-
break;
958-
959-
case EggTexture::WM_clamp:
960-
if (egg_ignore_clamp) {
961-
egg2pg_cat.warning()
962-
<< "Ignoring clamp request\n";
963-
tex->set_wrap_v(Texture::WM_repeat);
964-
} else {
965-
tex->set_wrap_v(Texture::WM_clamp);
966-
}
967-
break;
968-
969-
case EggTexture::WM_unspecified:
970-
break;
971-
972-
default:
973-
egg2pg_cat.warning()
974-
<< "Unexpected texture wrap flag: "
975-
<< (int)egg_tex->determine_wrap_v() << "\n";
976-
}
977-
978-
switch (egg_tex->determine_wrap_w()) {
979-
case EggTexture::WM_repeat:
980-
tex->set_wrap_w(Texture::WM_repeat);
981-
break;
930+
tex->set_wrap_u(convert_wrap_mode(egg_tex->determine_wrap_u()));
931+
tex->set_wrap_v(convert_wrap_mode(egg_tex->determine_wrap_v()));
932+
tex->set_wrap_w(convert_wrap_mode(egg_tex->determine_wrap_w()));
982933

983-
case EggTexture::WM_clamp:
984-
if (egg_ignore_clamp) {
985-
egg2pg_cat.warning()
986-
<< "Ignoring clamp request\n";
987-
tex->set_wrap_w(Texture::WM_repeat);
988-
} else {
989-
tex->set_wrap_w(Texture::WM_clamp);
990-
}
991-
break;
992-
993-
case EggTexture::WM_unspecified:
994-
break;
995-
996-
default:
997-
egg2pg_cat.warning()
998-
<< "Unexpected texture wrap flag: "
999-
<< (int)egg_tex->determine_wrap_w() << "\n";
934+
if (egg_tex->has_border_color()) {
935+
tex->set_border_color(egg_tex->get_border_color());
1000936
}
1001937

1002938
switch (egg_tex->get_minfilter()) {
@@ -1234,6 +1170,40 @@ apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) {
12341170
}
12351171
}
12361172

1173+
////////////////////////////////////////////////////////////////////
1174+
// Function: EggLoader::convert_wrap_mode
1175+
// Access: Private
1176+
// Description: Returns the Texture::WrapMode enum corresponding to
1177+
// the EggTexture::WrapMode. Returns WM_repeat if the
1178+
// wrap mode is unspecified.
1179+
////////////////////////////////////////////////////////////////////
1180+
Texture::WrapMode EggLoader::
1181+
convert_wrap_mode(EggTexture::WrapMode wrap_mode) const {
1182+
switch (wrap_mode) {
1183+
case EggTexture::WM_clamp:
1184+
return Texture::WM_clamp;
1185+
1186+
case EggTexture::WM_repeat:
1187+
return Texture::WM_repeat;
1188+
1189+
case EggTexture::WM_mirror:
1190+
return Texture::WM_mirror;
1191+
1192+
case EggTexture::WM_mirror_once:
1193+
return Texture::WM_mirror_once;
1194+
1195+
case EggTexture::WM_border_color:
1196+
return Texture::WM_border_color;
1197+
1198+
case EggTexture::WM_unspecified:
1199+
return Texture::WM_repeat;
1200+
}
1201+
1202+
egg2pg_cat.warning()
1203+
<< "Unexpected texture wrap flag: " << (int)wrap_mode << "\n";
1204+
return Texture::WM_repeat;
1205+
}
1206+
12371207
////////////////////////////////////////////////////////////////////
12381208
// Function: EggLoader::make_texture_stage
12391209
// Access: Private

panda/src/egg2pg/eggLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class EggLoader {
122122
void load_textures();
123123
bool load_texture(TextureDef &def, const EggTexture *egg_tex);
124124
void apply_texture_attributes(Texture *tex, const EggTexture *egg_tex);
125+
Texture::WrapMode convert_wrap_mode(EggTexture::WrapMode wrap_mode) const;
125126
PT(TextureStage) make_texture_stage(const EggTexture *egg_tex);
126127

127128
void separate_switches(EggNode *egg_node);

panda/src/glstuff/glGraphicsStateGuardian_src.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,9 @@ reset() {
673673
}
674674

675675
_border_clamp = GL_CLAMP;
676-
if (has_extension("GL_ARB_texture_border_clamp") ||
677-
is_at_least_version(1, 3)) {
676+
if (CLP(support_clamp_to_border) &&
677+
(has_extension("GL_ARB_texture_border_clamp") ||
678+
is_at_least_version(1, 3))) {
678679
_border_clamp = GL_CLAMP_TO_BORDER;
679680
}
680681

panda/src/glstuff/glShaderContext_src.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ parse_cg_profile(const string &id, bool vertex)
146146
}
147147
return CG_PROFILE_UNKNOWN;
148148
}
149-
#endif HAVE_CGGL
149+
#endif // HAVE_CGGL
150150

151151
////////////////////////////////////////////////////////////////////
152152
// Function: GLShaderContext::try_cg_compile

0 commit comments

Comments
 (0)