浏览代码

publish Textures::up/down_to_power_2()

David Rose 17 年之前
父节点
当前提交
86409f66e4
共有 2 个文件被更改,包括 33 次插入33 次删除
  1. 30 30
      panda/src/gobj/texture.cxx
  2. 3 3
      panda/src/gobj/texture.h

+ 30 - 30
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

+ 3 - 3
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);