diff options
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_materials.c | 11 | ||||
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 1 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 5 | ||||
-rw-r--r-- | source/blender/gpu/GPU_texture.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture.c | 32 |
5 files changed, 47 insertions, 4 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index a26c2a4478f..a9425139ebf 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -413,9 +413,6 @@ static void create_default_shader(int options) void EEVEE_update_util_texture(float offset) { - if (e_data.util_tex != NULL) { - DRW_TEXTURE_FREE_SAFE(e_data.util_tex); - } /* TODO: split this into 2 functions : one for init, * and the other one that updates the noise with the offset. */ @@ -462,7 +459,13 @@ void EEVEE_update_util_texture(float offset) texels_layer += 64 * 64; } - e_data.util_tex = DRW_texture_create_2D_array(64, 64, layers, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_WRAP, (float *)texels); + if (e_data.util_tex == NULL) { + e_data.util_tex = DRW_texture_create_2D_array(64, 64, layers, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_WRAP, (float *)texels); + } + else { + DRW_texture_update(e_data.util_tex, (float *)texels); + } + MEM_freeN(texels); } diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 853f2d123eb..00f822d6877 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -165,6 +165,7 @@ struct GPUTexture *DRW_texture_create_2D_array( struct GPUTexture *DRW_texture_create_cube( int w, DRWTextureFormat format, DRWTextureFlag flags, const float *fpixels); void DRW_texture_generate_mipmaps(struct GPUTexture *tex); +void DRW_texture_update(struct GPUTexture *tex, const float *pixels); void DRW_texture_free(struct GPUTexture *tex); #define DRW_TEXTURE_FREE_SAFE(tex) do { \ if (tex != NULL) { \ diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 889fb3ce810..d5b2944990b 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -515,6 +515,11 @@ void DRW_texture_generate_mipmaps(GPUTexture *tex) GPU_texture_unbind(tex); } +void DRW_texture_update(GPUTexture *tex, const float *pixels) +{ + GPU_texture_update(tex, pixels); +} + void DRW_texture_free(GPUTexture *tex) { GPU_texture_free(tex); diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h index 83872ccdf80..fa8ed992c72 100644 --- a/source/blender/gpu/GPU_texture.h +++ b/source/blender/gpu/GPU_texture.h @@ -167,6 +167,8 @@ GPUTexture *GPU_texture_from_blender( struct Image *ima, struct ImageUser *iuser, int textarget, bool is_data, double time, int mipmap); GPUTexture *GPU_texture_from_preview(struct PreviewImage *prv, int mipmap); +void GPU_texture_update(GPUTexture *tex, const float *pixels); + void GPU_invalid_tex_init(void); void GPU_invalid_tex_bind(int mode); void GPU_invalid_tex_free(void); diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c index 959fc7e8794..e8d488afbdd 100644 --- a/source/blender/gpu/intern/gpu_texture.c +++ b/source/blender/gpu/intern/gpu_texture.c @@ -66,6 +66,7 @@ struct GPUTexture { unsigned int bytesize; /* number of byte for one pixel */ int format; /* GPUTextureFormat */ + int components; /* number of color/alpha channels */ }; /* ------ Memory Management ------- */ @@ -326,6 +327,7 @@ static GPUTexture *GPU_texture_create_nD( tex->refcount = 1; tex->fb_attachment = -1; tex->format = data_type; + tex->components = components; if (n == 2) { if (d == 0) @@ -468,6 +470,7 @@ static GPUTexture *GPU_texture_cube_create( tex->refcount = 1; tex->fb_attachment = -1; tex->format = data_type; + tex->components = components; if (d == 0) { tex->target_base = tex->target = GL_TEXTURE_CUBE_MAP; @@ -555,6 +558,7 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int textarget tex->target_base = textarget; tex->fromblender = 1; tex->format = -1; + tex->components = -1; ima->gputexture[gputt] = tex; @@ -608,6 +612,7 @@ GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap) tex->target = GL_TEXTURE_2D; tex->target_base = GL_TEXTURE_2D; tex->format = -1; + tex->components = -1; prv->gputexture[0] = tex; @@ -706,6 +711,33 @@ GPUTexture *GPU_texture_create_depth_multisample(int w, int h, int samples, char return GPU_texture_create_nD(w, h, 0, 2, NULL, GPU_DEPTH_COMPONENT24, 1, samples, false, err_out); } +void GPU_texture_update(GPUTexture *tex, const float *pixels) +{ + BLI_assert(tex->format > -1); + BLI_assert(tex->components > -1); + + GLenum format, internalformat, data_format; + internalformat = gpu_texture_get_format(tex->components, tex->format, + &format, &data_format, &tex->depth, &tex->stencil, &tex->bytesize); + + glBindTexture(tex->target, tex->bindcode); + + if (tex->target == GL_TEXTURE_2D || + tex->target == GL_TEXTURE_2D_MULTISAMPLE || + tex->target == GL_TEXTURE_1D_ARRAY) + { + glTexSubImage2D(tex->target, 0, 0, 0, tex->w, tex->h, format, data_format, pixels); + } + else if (tex->target == GL_TEXTURE_1D) { + glTexSubImage1D(tex->target, 0, 0, tex->w, format, data_format, pixels); + } + else { /* GL_TEXTURE_3D */ + glTexSubImage3D(tex->target, 0, 0, 0, 0, tex->w, tex->h, tex->d, format, data_format, pixels); + } + + glBindTexture(tex->target, 0); +} + void GPU_invalid_tex_init(void) { memory_usage = 0; |