Eevee: Fix T52486

For that introduce an update function for textures.
This commit is contained in:
2017-08-22 10:22:11 +02:00
parent 7e87849257
commit 417581636f
5 changed files with 47 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -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) { \

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;