From 854502d2e3dc5d0c08721bc3a6a4e08be6189fda Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Mon, 11 Jun 2012 16:23:10 +0000 Subject: Add user preference "GPU Mipmap Generation" under the System/OpenGL subpanel to calculate image mipmapping on the GPU, saving upload and calculation time. Default is off just in case. --- source/blender/gpu/GPU_draw.h | 3 +++ source/blender/gpu/intern/gpu_draw.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'source/blender/gpu') diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index 89976699114..438cfd6b741 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -112,6 +112,9 @@ void GPU_paint_set_mipmap(int mipmap); void GPU_set_anisotropic(float value); float GPU_get_anisotropic(void); +/* enable gpu mipmapping */ +void GPU_set_gpu_mipmapping(int gpu_mipmap); + /* Image updates and free * - these deal with images bound as opengl textures */ diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 3e53f2f3836..a1bd8dcb3a3 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -234,11 +234,23 @@ static struct GPUTextureState { int alphablend; float anisotropic; + int gpu_mipmap; MTFace *lasttface; -} GTS = {0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, 1, 0, 0, -1, 1.f, NULL}; +} GTS = {0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, 1, 0, 0, -1, 1.f, 0, NULL}; /* Mipmap settings */ +void GPU_set_gpu_mipmapping(int gpu_mipmap){ + int old_value = GTS.gpu_mipmap; + + /* only actually enable if it's supported */ + GTS.gpu_mipmap = gpu_mipmap && GLEW_EXT_framebuffer_object; + + if(old_value != GTS.gpu_mipmap) { + GPU_free_images(); + } +} + void GPU_set_mipmap(int mipmap) { if (GTS.domipmap != (mipmap != 0)) { @@ -632,10 +644,19 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1)); } else { - if (use_high_bit_depth) - gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA16, rectw, recth, GL_RGBA, GL_FLOAT, frect); - else - gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, rectw, recth, GL_RGBA, GL_UNSIGNED_BYTE, rect); + if(GTS.gpu_mipmap) { + if (use_high_bit_depth) + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect); + else + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect); + + glGenerateMipmapEXT(GL_TEXTURE_2D); + } else { + if (use_high_bit_depth) + gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA16, rectw, recth, GL_RGBA, GL_FLOAT, frect); + else + gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, rectw, recth, GL_RGBA, GL_UNSIGNED_BYTE, rect); + } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1)); -- cgit v1.2.3