diff --git a/panda/src/text/dynamicTextFont.I b/panda/src/text/dynamicTextFont.I index ea8d8fad3c..0e2cfa8617 100644 --- a/panda/src/text/dynamicTextFont.I +++ b/panda/src/text/dynamicTextFont.I @@ -230,6 +230,77 @@ get_page_y_size() const { return _page_y_size; } +//////////////////////////////////////////////////////////////////// +// Function: DynamicTextFont::set_minfilter +// Access: Published +// Description: Sets the filter type used when minimizing the +// textures created for this font. +//////////////////////////////////////////////////////////////////// +INLINE void DynamicTextFont:: +set_minfilter(Texture::FilterType filter) { + _minfilter = filter; + update_filters(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DynamicTextFont::get_minfilter +// Access: Published +// Description: Returns the filter type used when minimizing the +// textures created for this font. +//////////////////////////////////////////////////////////////////// +INLINE Texture::FilterType DynamicTextFont:: +get_minfilter() const { + return _minfilter; +} + +//////////////////////////////////////////////////////////////////// +// Function: DynamicTextFont::set_magfilter +// Access: Published +// Description: Sets the filter type used when enlarging the +// textures created for this font. +//////////////////////////////////////////////////////////////////// +INLINE void DynamicTextFont:: +set_magfilter(Texture::FilterType filter) { + _magfilter = filter; + update_filters(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DynamicTextFont::get_magfilter +// Access: Published +// Description: Returns the filter type used when enlarging the +// textures created for this font. +//////////////////////////////////////////////////////////////////// +INLINE Texture::FilterType DynamicTextFont:: +get_magfilter() const { + return _magfilter; +} + +//////////////////////////////////////////////////////////////////// +// Function: DynamicTextFont::set_anisotropic_degree +// Access: Published +// Description: Enables or disables anisotropic filtering on the +// textures created for this font. The default value is +// usually 1, or off. See +// Texture::set_anisotropic_degree(). +//////////////////////////////////////////////////////////////////// +INLINE void DynamicTextFont:: +set_anisotropic_degree(int anisotropic_degree) { + _anisotropic_degree = anisotropic_degree; + update_filters(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DynamicTextFont::get_anisotropic_degree +// Access: Published +// Description: Returns the current anisotropic degree for textures +// created for this font. See set_anisotropic_degree(). +//////////////////////////////////////////////////////////////////// +INLINE int DynamicTextFont:: +get_anisotropic_degree() const { + return _anisotropic_degree; +} + //////////////////////////////////////////////////////////////////// // Function: DynamicTextFont::set_update_cleared_glyphs // Access: Published, Static diff --git a/panda/src/text/dynamicTextFont.cxx b/panda/src/text/dynamicTextFont.cxx index 0d61c569b1..de767ab45a 100644 --- a/panda/src/text/dynamicTextFont.cxx +++ b/panda/src/text/dynamicTextFont.cxx @@ -60,6 +60,18 @@ DynamicTextFont(const Filename &font_filename, int face_index) { _small_caps = text_small_caps; _small_caps_scale = text_small_caps_scale; + // We don't necessarily want to use mipmaps, since we don't want to + // regenerate those every time the texture changes, but we probably + // do want at least linear filtering. Use whatever the Configrc + // file suggests. + _minfilter = text_minfilter; + _magfilter = text_magfilter; + + // Anisotropic filtering can help the look of the text, and doesn't + // require generating mipmaps, but does require hardware support. + _anisotropic_degree = text_anisotropic_degree; + + _preferred_page = 0; if (!_ft_initialized) { @@ -291,6 +303,24 @@ get_glyph(int character, const TextGlyph *&glyph, float &glyph_scale) { return (glyph_index != 0 && glyph != (DynamicTextGlyph *)NULL); } + +//////////////////////////////////////////////////////////////////// +// Function: DynamicTextFont::update_filters +// Access: Private +// Description: Reapplies all current filter settings to all of the +// pages. This is normally called whenever the filter +// settings change. +//////////////////////////////////////////////////////////////////// +void DynamicTextFont:: +update_filters() { + Pages::iterator pi; + for (pi = _pages.begin(); pi != _pages.end(); ++pi) { + DynamicTextPage *page = (*pi); + page->set_minfilter(_minfilter); + page->set_magfilter(_magfilter); + page->set_anisotropic_degree(_anisotropic_degree); + } +} //////////////////////////////////////////////////////////////////// // Function: DynamicTextFont::reset_scale diff --git a/panda/src/text/dynamicTextFont.h b/panda/src/text/dynamicTextFont.h index a9e1cce245..d57c04ba52 100644 --- a/panda/src/text/dynamicTextFont.h +++ b/panda/src/text/dynamicTextFont.h @@ -66,6 +66,13 @@ PUBLISHED: INLINE int get_page_x_size() const; INLINE int get_page_y_size() const; + INLINE void set_minfilter(Texture::FilterType filter); + INLINE Texture::FilterType get_minfilter() const; + INLINE void set_magfilter(Texture::FilterType filter); + INLINE Texture::FilterType get_magfilter() const; + INLINE void set_anisotropic_degree(int anisotropic_degree); + INLINE int get_anisotropic_degree() const; + INLINE static void set_update_cleared_glyphs(bool update_cleared_glyphs); INLINE static bool get_update_cleared_glyphs(); @@ -83,6 +90,7 @@ public: float &glyph_scale); private: + void update_filters(); bool reset_scale(); DynamicTextGlyph *make_glyph(int glyph_index); DynamicTextGlyph *slot_glyph(int x_size, int y_size); @@ -98,6 +106,10 @@ private: int _page_x_size, _page_y_size; static bool _update_cleared_glyphs; + Texture::FilterType _minfilter; + Texture::FilterType _magfilter; + int _anisotropic_degree; + typedef pvector< PT(DynamicTextPage) > Pages; Pages _pages; int _preferred_page; diff --git a/panda/src/text/dynamicTextPage.cxx b/panda/src/text/dynamicTextPage.cxx index b27b00b946..44a500b041 100644 --- a/panda/src/text/dynamicTextPage.cxx +++ b/panda/src/text/dynamicTextPage.cxx @@ -46,16 +46,10 @@ DynamicTextPage(DynamicTextFont *font) : // We'd better never free this image. set_keep_ram_image(true); - // We don't necessarily want to use mipmaps, since we don't want to - // regenerate those every time the texture changes, but we probably - // do want at least linear filtering. Use whatever the Configrc - // file suggests. - set_minfilter(text_minfilter); - set_magfilter(text_magfilter); + set_minfilter(_font->get_minfilter()); + set_magfilter(_font->get_magfilter()); - // Anisotropic filtering can help the look of the text, and doesn't - // require generating mipmaps, but does require hardware support. - set_anisotropic_degree(text_anisotropic_degree); + set_anisotropic_degree(_font->get_anisotropic_degree()); // It's slightly better to let the texture clamp, rather than // wrapping, so we're less likely to get bleeding at the edges.