From 86409f66e47bc5891c8ca9c10054fdeda46ba25d Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 4 Feb 2009 14:23:17 +0000 Subject: [PATCH] publish Textures::up/down_to_power_2() --- panda/src/gobj/texture.cxx | 60 +++++++++++++++++++------------------- panda/src/gobj/texture.h | 6 ++-- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 63989bb349..fd2da54fd3 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -1530,6 +1530,36 @@ prepare_now(PreparedGraphicsObjects *prepared_objects, return tc; } +//////////////////////////////////////////////////////////////////// +// Function: Texture::up_to_power_2 +// Access: Published, Static +// Description: Returns the smallest power of 2 greater than or equal +// to value. +//////////////////////////////////////////////////////////////////// +int Texture:: +up_to_power_2(int value) { + if (value <= 1) { + return 1; + } + int bit = get_next_higher_bit(((unsigned int)value) - 1); + return (1 << bit); +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::down_to_power_2 +// Access: Published, Static +// Description: Returns the largest power of 2 less than or equal +// to value. +//////////////////////////////////////////////////////////////////// +int Texture:: +down_to_power_2(int value) { + if (value <= 1) { + return 1; + } + int bit = get_next_higher_bit(((unsigned int)value) >> 1); + return (1 << bit); +} + //////////////////////////////////////////////////////////////////// // Function: Texture::texture_uploaded @@ -1660,36 +1690,6 @@ make_texture() { return new Texture; } -//////////////////////////////////////////////////////////////////// -// Function: Texture::up_to_power_2 -// Access: Public, Static -// Description: Returns the smallest power of 2 greater than or equal -// to value. -//////////////////////////////////////////////////////////////////// -int Texture:: -up_to_power_2(int value) { - int x = 1; - while (x < value) { - x = (x << 1); - } - return x; -} - -//////////////////////////////////////////////////////////////////// -// Function: Texture::down_to_power_2 -// Access: Public, Static -// Description: Returns the largest power of 2 less than or equal -// to value. -//////////////////////////////////////////////////////////////////// -int Texture:: -down_to_power_2(int value) { - int x = 1; - while ((x << 1) <= value) { - x = (x << 1); - } - return x; -} - //////////////////////////////////////////////////////////////////// // Function: Texture::is_specific // Access: Public, Static diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index a026d6fd63..359634b91c 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -424,6 +424,9 @@ PUBLISHED: TextureContext *prepare_now(PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg); + static int up_to_power_2(int value); + static int down_to_power_2(int value); + public: void texture_uploaded(GraphicsStateGuardianBase *gsg); @@ -436,9 +439,6 @@ public: static PT(Texture) make_texture(); public: - static int up_to_power_2(int value); - static int down_to_power_2(int value); - static bool is_specific(CompressionMode compression); static bool has_alpha(Format format); static bool has_binary_alpha(Format format);