From d6e30256ad7e2660db796b41cf8a7bf073aa6d09 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 4 May 2016 12:36:51 -0300 Subject: ability to shrink all images x2 on load this is for extreme cases when running on devices with very low video memory, so you can still retain compatibility. --- drivers/gles2/rasterizer_gles2.cpp | 19 ++++++++++++++++++- drivers/gles2/rasterizer_gles2.h | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 4b976c5b0..2d1bda005 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -921,6 +921,11 @@ void RasterizerGLES2::texture_allocate(RID p_texture,int p_width, int p_height,I texture->alloc_height = texture->height; }; + if (shrink_textures_x2) { + texture->alloc_height = MAX(1,texture->alloc_height/2); + texture->alloc_width = MAX(1,texture->alloc_width/2); + } + texture->gl_components_cache=components; texture->gl_format_cache=format; @@ -970,8 +975,15 @@ void RasterizerGLES2::texture_set_data(RID p_texture,const Image& p_image,VS::Cu if (texture->alloc_width != img.get_width() || texture->alloc_height != img.get_height()) { - if (img.get_format() <= Image::FORMAT_INDEXED_ALPHA) + + if (texture->alloc_width == img.get_width()/2 && texture->alloc_height == img.get_height()/2) { + + img.shrink_x2(); + } else if (img.get_format() <= Image::FORMAT_INDEXED_ALPHA) { + img.resize(texture->alloc_width, texture->alloc_height, Image::INTERPOLATE_BILINEAR); + + } }; @@ -1452,6 +1464,11 @@ void RasterizerGLES2::texture_debug_usage(List *r_info){ } +void RasterizerGLES2::texture_set_shrink_all_x2_on_set_data(bool p_enable) { + + shrink_textures_x2=p_enable; +} + /* SHADER API */ RID RasterizerGLES2::shader_create(VS::ShaderMode p_mode) { diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h index 0f70ceaa9..d74daf37d 100644 --- a/drivers/gles2/rasterizer_gles2.h +++ b/drivers/gles2/rasterizer_gles2.h @@ -108,6 +108,8 @@ class RasterizerGLES2 : public Rasterizer { bool use_half_float; bool low_memory_2d; + bool shrink_textures_x2; + Vector skel_default; Image _get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags,GLenum& r_gl_format,GLenum& r_gl_internal_format,int &r_gl_components,bool &r_has_alpha_cache,bool &r_compressed); @@ -1334,6 +1336,8 @@ public: virtual String texture_get_path(RID p_texture) const; virtual void texture_debug_usage(List *r_info); + virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable); + GLuint _texture_get_name(RID p_tex); /* SHADER API */ -- cgit v1.3.1