Commit: ce6418fc16172b91e705121ad4430f862f9a9936
Author: Clément Foucault
Date:   Wed Jun 20 18:31:46 2018 +0200
Branches: temp-eeveelightcache
https://developer.blender.org/rBce6418fc16172b91e705121ad4430f862f9a9936

GPUTexture: Add GPU_texture_read

This is to get the texture content from the GPU memory.

===================================================================

M       source/blender/gpu/GPU_texture.h
M       source/blender/gpu/intern/gpu_texture.c

===================================================================

diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index efe720d5d55..3c93d275892 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -168,6 +168,8 @@ GPUTexture *GPU_texture_from_preview(struct PreviewImage 
*prv, int mipmap);
 
 void GPU_texture_update(GPUTexture *tex, const float *pixels);
 
+void *GPU_texture_read(GPUTexture *tex, int miplvl);
+
 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 cebfe7920bc..dfa9e2365ec 100644
--- a/source/blender/gpu/intern/gpu_texture.c
+++ b/source/blender/gpu/intern/gpu_texture.c
@@ -913,6 +913,26 @@ void GPU_texture_update(GPUTexture *tex, const float 
*pixels)
        glBindTexture(tex->target, 0);
 }
 
+void *GPU_texture_read(GPUTexture *tex, int miplvl)
+{
+       glBindTexture(tex->target, tex->bindcode);
+
+       size_t buf_size = gpu_texture_memory_footprint_compute(tex);
+       /* We want floats (or ints) */
+       buf_size = tex->components * sizeof(float) * (buf_size / tex->bytesize);
+       void *buf = MEM_mallocN(buf_size, "GPU_texture_read");
+
+       GLenum format, data_format;
+       gpu_texture_get_format(tex->components, tex->format, &format, 
&data_format,
+                              &tex->format_flag, &tex->bytesize);
+
+       glGetTexImage(tex->target, miplvl, format, data_format, buf);
+
+       glBindTexture(tex->target, 0);
+
+       return buf;
+}
+
 void GPU_invalid_tex_init(void)
 {
        memory_usage = 0;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to