Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-12-16 13:25:07 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-12-16 13:25:07 +0400
commit2253b63c979fbfbbb6f06c93ede85d9b9b6caddf (patch)
tree6fe58202f96a7edd8448d7fbf17a14df6098d0f7 /source/blender/gpu
parent91f14ddf3da140156c722e347b6f188210903629 (diff)
static functions for getting power of 2 values were being copied about too much, add to the BLI_math api.
- is_power_of_2_i - power_of_2_min_i - power_of_2_max_i
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/intern/gpu_draw.c20
-rw-r--r--source/blender/gpu/intern/gpu_extensions.c27
2 files changed, 9 insertions, 38 deletions
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 4af0cceb4e0..2dcce996065 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -189,20 +189,6 @@ void GPU_render_text(MTFace *tface, int mode,
/* Checking powers of two for images since opengl 1.x requires it */
-static int is_pow2(int num)
-{
- /* (n&(n-1)) zeros the least significant bit of n */
- return ((num)&(num-1))==0;
-}
-
-static int smaller_pow2(int num)
-{
- while (!is_pow2(num))
- num= num&(num-1);
-
- return num;
-}
-
static int is_pow2_limit(int num)
{
/* take texture clamping into account */
@@ -214,7 +200,7 @@ static int is_pow2_limit(int num)
if (U.glreslimit != 0 && num > U.glreslimit)
return 0;
- return ((num)&(num-1))==0;
+ return is_power_of_2_i(num);
}
static int smaller_pow2_limit(int num)
@@ -227,7 +213,7 @@ static int smaller_pow2_limit(int num)
if (U.glreslimit != 0 && num > U.glreslimit)
return U.glreslimit;
- return smaller_pow2(num);
+ return power_of_2_min_i(num);
}
/* Current OpenGL state caching for GPU_set_tpage */
@@ -692,7 +678,7 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h, int mipmap)
ibuf = BKE_image_get_ibuf(ima, NULL);
if (ima->repbind || (gpu_get_mipmap() && mipmap) || !ima->bindcode || !ibuf ||
- (!is_pow2(ibuf->x) || !is_pow2(ibuf->y)) ||
+ (!is_power_of_2_i(ibuf->x) || !is_power_of_2_i(ibuf->y)) ||
(w == 0) || (h == 0)) {
/* these cases require full reload still */
GPU_free_image(ima);
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index 79db125c21f..4c0a3d6c5e4 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -41,6 +41,7 @@
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
+#include "BLI_math_base.h"
#include "GPU_draw.h"
#include "GPU_extensions.h"
@@ -292,22 +293,6 @@ static unsigned char *GPU_texture_convert_pixels(int length, float *fpixels)
return pixels;
}
-static int is_pow2(int n)
-{
- return ((n)&(n-1))==0;
-}
-
-static int larger_pow2(int n)
-{
- if (is_pow2(n))
- return n;
-
- while(!is_pow2(n))
- n= n&(n-1);
-
- return n*2;
-}
-
static void GPU_glTexSubImageEmpty(GLenum target, GLenum format, int x, int y, int w, int h)
{
void *pixels = MEM_callocN(sizeof(char)*4*w*h, "GPUTextureEmptyPixels");
@@ -353,8 +338,8 @@ static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, in
}
if (!GPU_non_power_of_two_support()) {
- tex->w = larger_pow2(tex->w);
- tex->h = larger_pow2(tex->h);
+ tex->w = power_of_2_max_i(tex->w);
+ tex->h = power_of_2_max_i(tex->h);
}
tex->number = 0;
@@ -462,9 +447,9 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels)
}
if (!GPU_non_power_of_two_support()) {
- tex->w = larger_pow2(tex->w);
- tex->h = larger_pow2(tex->h);
- tex->depth = larger_pow2(tex->depth);
+ tex->w = power_of_2_max_i(tex->w);
+ tex->h = power_of_2_max_i(tex->h);
+ tex->depth = power_of_2_max_i(tex->depth);
}
tex->number = 0;