Commit: 1d111cd046b051efe71c6863b1c4a65233c45ac9
Author: Brecht Van Lommel
Date:   Mon Jun 11 22:34:35 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB1d111cd046b051efe71c6863b1c4a65233c45ac9

Revert "Cleanup: remove image->bindcode, always wrap in GPUTexture."

This reverts commit 8242a5bc853a74da1273fc7ad4b959ac716c563c. This isn't
quite ready to use yet.

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

M       source/blender/blenkernel/BKE_image.h
M       source/blender/blenkernel/intern/image.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/gpu/GPU_texture.h
M       source/blender/gpu/intern/gpu_draw.c
M       source/blender/gpu/intern/gpu_texture.c
M       source/blender/makesdna/DNA_image_types.h
M       source/blender/makesrna/intern/rna_image.c
M       source/blender/makesrna/intern/rna_image_api.c

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

diff --git a/source/blender/blenkernel/BKE_image.h 
b/source/blender/blenkernel/BKE_image.h
index 546204b5eef..fc018dbfe81 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -271,7 +271,7 @@ bool BKE_image_scale(struct Image *image, int width, int 
height);
 bool BKE_image_has_alpha(struct Image *image);
 
 /* check if texture has gpu texture code */
-bool BKE_image_has_opengl_texture(struct Image *ima);
+bool BKE_image_has_bindcode(struct Image *ima);
 
 void BKE_image_get_size(struct Image *image, struct ImageUser *iuser, int 
*width, int *height);
 void BKE_image_get_size_fl(struct Image *image, struct ImageUser *iuser, float 
size[2]);
diff --git a/source/blender/blenkernel/intern/image.c 
b/source/blender/blenkernel/intern/image.c
index b6b3dd31096..c1ecabcfb5a 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -473,6 +473,7 @@ void BKE_image_copy_data(Main *UNUSED(bmain), Image 
*ima_dst, const Image *ima_s
        BLI_listbase_clear(&ima_dst->anims);
 
        for (int i = 0; i < TEXTARGET_COUNT; i++) {
+               ima_dst->bindcode[i] = 0;
                ima_dst->gputexture[i] = NULL;
        }
 
@@ -537,14 +538,16 @@ bool BKE_image_scale(Image *image, int width, int height)
        return (ibuf != NULL);
 }
 
-bool BKE_image_has_opengl_texture(Image *ima)
+bool BKE_image_has_bindcode(Image *ima)
 {
+       bool has_bindcode = false;
        for (int i = 0; i < TEXTARGET_COUNT; i++) {
-               if (ima->gputexture[i]) {
-                       return true;
+               if (ima->bindcode[i]) {
+                       has_bindcode = true;
+                       break;
                }
        }
-       return false;
+       return has_bindcode;
 }
 
 static void image_init_color_management(Image *ima)
@@ -927,6 +930,21 @@ void BKE_image_tag_time(Image *ima)
        ima->lastused = PIL_check_seconds_timer_i();
 }
 
+#if 0
+static void tag_all_images_time(Main *bmain)
+{
+       Image *ima;
+       int ctime = PIL_check_seconds_timer_i();
+
+       ima = bmain->image.first;
+       while (ima) {
+               if (ima->bindcode || ima->repbind || ima->ibufs.first) {
+                       ima->lastused = ctime;
+               }
+       }
+}
+#endif
+
 static uintptr_t image_mem_size(Image *image)
 {
        uintptr_t size = 0;
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 8807cbc1d21..039af3cfa61 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1681,6 +1681,7 @@ void blo_end_image_pointer_map(FileData *fd, Main 
*oldmain)
                if (ima->cache == NULL) {
                        ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
                        for (i = 0; i < TEXTARGET_COUNT; i++) {
+                               ima->bindcode[i] = 0;
                                ima->gputexture[i] = NULL;
                        }
                        ima->rr = NULL;
@@ -3915,6 +3916,7 @@ static void direct_link_image(FileData *fd, Image *ima)
        if (!ima->cache) {
                ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
                for (int i = 0; i < TEXTARGET_COUNT; i++) {
+                       ima->bindcode[i] = 0;
                        ima->gputexture[i] = NULL;
                }
                ima->rr = NULL;
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index e58d5d92831..09b351a544a 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -161,7 +161,6 @@ GPUTexture *GPU_texture_create_from_vertbuf(
 GPUTexture *GPU_texture_create_buffer(
         GPUTextureFormat data_type, const uint buffer);
 
-GPUTexture *GPU_texture_from_bindcode(int textarget, int bindcode);
 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);
diff --git a/source/blender/gpu/intern/gpu_draw.c 
b/source/blender/gpu/intern/gpu_draw.c
index 0c9832f20b3..7bfebb702a1 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -127,6 +127,8 @@ static int smaller_power_of_2_limit(int num)
 /* Current OpenGL state caching for GPU_set_tpage */
 
 static struct GPUTextureState {
+       Image *ima, *curima;
+
        /* also controls min/mag filtering */
        bool domipmap;
        /* only use when 'domipmap' is set */
@@ -134,9 +136,10 @@ static struct GPUTextureState {
        /* store this so that new images created while texture painting won't 
be set to mipmapped */
        bool texpaint;
 
+       int alphablend;
        float anisotropic;
        int gpu_mipmap;
-} GTS = {1, 0, 0, 1.0f, 0};
+} GTS = {NULL, NULL, 1, 0, 0, -1, 1.0f, 0};
 
 /* Mipmap settings */
 
@@ -224,14 +227,16 @@ float GPU_get_anisotropic(void)
 
 /* Set OpenGL state for an MTFace */
 
-static GPUTexture **gpu_get_image_gputexture(Image *ima, GLenum textarget)
+static unsigned int *gpu_get_image_bindcode(Image *ima, GLenum textarget)
 {
+       unsigned int *bind = 0;
+
        if (textarget == GL_TEXTURE_2D)
-               return &ima->gputexture[TEXTARGET_TEXTURE_2D];
+               bind = &ima->bindcode[TEXTARGET_TEXTURE_2D];
        else if (textarget == GL_TEXTURE_CUBE_MAP)
-               return &ima->gputexture[TEXTARGET_TEXTURE_CUBE_MAP];
+               bind = &ima->bindcode[TEXTARGET_TEXTURE_CUBE_MAP];
 
-       return NULL;
+       return bind;
 }
 
 typedef struct VerifyThreadData {
@@ -284,38 +289,33 @@ static void gpu_verify_high_bit_srgb_buffer(float 
*srgb_frect,
        }
 }
 
-GPUTexture *GPU_texture_from_blender(Image *ima,
-                                     ImageUser *iuser,
-                                     int textarget,
-                                     bool is_data,
-                                     double UNUSED(time),
-                                     int mipmap)
+int GPU_verify_image(
+        Image *ima, ImageUser *iuser,
+        int textarget, bool compare, bool mipmap, bool is_data)
 {
-       /* check if we have a valid image */
-       if (ima == NULL || ima->ok == 0) {
-               return NULL;
-       }
+       unsigned int *bind = NULL;
+       int tpx = 0, tpy = 0;
+       unsigned int *rect = NULL;
+       float *frect = NULL;
+       float *srgb_frect = NULL;
+       /* flag to determine whether deep format is used */
+       bool use_high_bit_depth = false, do_color_management = false;
 
-       /* currently, tpage refresh is used by ima sequences */
-       if (ima->tpageflag & IMA_TPAGE_REFRESH) {
-               GPU_free_image(ima);
-               ima->tpageflag &= ~IMA_TPAGE_REFRESH;
-       }
+       GTS.ima = ima;
 
-       /* Test if we already have a texture. */
-       GPUTexture **tex = gpu_get_image_gputexture(ima, textarget);
-       if (*tex) {
-               return *tex;
+       if (compare && ima == GTS.curima) {
+               return (ima != NULL);
        }
 
+       /* check if we have a valid image */
+       if (ima == NULL || ima->ok == 0)
+               return 0;
+
        /* check if we have a valid image buffer */
        ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
-       if (ibuf == NULL) {
-               return NULL;
-       }
 
-       /* flag to determine whether deep format is used */
-       bool use_high_bit_depth = false, do_color_management = false;
+       if (ibuf == NULL)
+               return 0;
 
        if (ibuf->rect_float) {
                if (U.use_16bit_textures) {
@@ -337,38 +337,54 @@ GPUTexture *GPU_texture_from_blender(Image *ima,
                }
        }
 
-       const int rectw = ibuf->x;
-       const int recth = ibuf->y;
-       unsigned int *rect = ibuf->rect;
-       float *frect = NULL;
-       float *srgb_frect = NULL;
+       /* currently, tpage refresh is used by ima sequences */
+       if (ima->tpageflag & IMA_TPAGE_REFRESH) {
+               GPU_free_image(ima);
+               ima->tpageflag &= ~IMA_TPAGE_REFRESH;
+       }
 
-       if (use_high_bit_depth) {
-               if (do_color_management) {
-                       frect = srgb_frect = MEM_mallocN(ibuf->x * ibuf->y * 
sizeof(*srgb_frect) * 4, "floar_buf_col_cor");
-                       gpu_verify_high_bit_srgb_buffer(srgb_frect, ibuf);
-               }
-               else {
-                       frect = ibuf->rect_float;
+       {
+               /* regular image mode */
+               bind = gpu_get_image_bindcode(ima, textarget);
+
+               if (*bind == 0) {
+                       tpx = ibuf->x;
+                       tpy = ibuf->y;
+                       rect = ibuf->rect;
+                       if (use_high_bit_depth) {
+                               if (do_color_management) {
+                                       frect = srgb_frect = 
MEM_mallocN(ibuf->x * ibuf->y * sizeof(*srgb_frect) * 4, "floar_buf_col_cor");
+                                       
gpu_verify_high_bit_srgb_buffer(srgb_frect, ibuf);
+                               }
+                               else
+                                       frect = ibuf->rect_float;
+                       }
                }
        }
 
-       unsigned int bindcode = 0;
+       if (*bind != 0) {
+               /* enable opengl drawing with textures */
+               glBindTexture(textarget, *bind);
+               BKE_image_release_ibuf(ima, ibuf, NULL);
+               return *bind;
+       }
+
+       const int rectw = tpx;
+       const int recth = tpy;
+
 #ifdef WITH_DDS
        if (ibuf->ftype == IMB_FTYPE_DDS)
-               GPU_create_gl_tex_compressed(&bindcode, rect, rectw, recth, 
textarget, mipmap, ima, ibuf);
+               GPU_create_gl_tex_compressed(bind, rect, rectw, recth, 
textarget, mipmap, ima, ibuf);
        else
 #endif
-               GPU_create_gl_tex(&bindcode, rect, frect, rectw, recth, 
textarget, mipmap, use_high_bit_depth, ima);
+               GPU_create_gl_tex(bind, rect, frect, rectw, recth, textarget, 
mipmap, use_high_bit_depth, ima);
 
        /* mark as non-color data texture */
-       if (bindcode) {
+       if (*bind) {
                if (is_data)
                        ima->tpageflag |= IMA_GLBIND_IS_DATA;
                else
                        ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
-
-               *tex = GPU_texture_from_bindcode(textarget, bindcode);
        }
 
        /* clean up */
@@ -377,7 +393,7 @@ GPUTexture *GPU_texture_from_blender(Image *ima,
 
        BKE_image_release_ibuf(ima, ibuf, NULL);
 
-       return *tex;
+       return *bind;
 }
 
 static void **gpu_gen_cube_map(unsigned int *rect, float *frect, int rectw, 
int recth, bool use_high_bit_depth)
@@ -578,8 +594,6 @@ void GPU_create_gl_tex(
        if (GLEW_EXT_texture_filter_anisotropic)
                glTexParameterf(textarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, 
GPU_get_anisotropic());
 
-       glBindTexture(textarget, 0);
-
        if (ibuf)
                IMB_freeImBuf(ibuf);
 }
@@ -666,8 +680,6 @@ void GPU_create_gl_tex_compressed(
                glDeleteTextures(1, (GLuint *)bind);
                GPU_create_gl_tex(bind, pix, NULL, x, y, textarget, mipmap, 0, 
ima);
        }
-
-       glBindTexture(textarget, 0);
 #endif
 }
 
@@ -684,13 +696,17 @@ void GPU_paint_set_mipmap(bool mipmap)
 
        if (mipmap) {
                for (Image *ima = G.main->image.first; ima; ima = ima->id.next) 
{
-                       if (BKE_image_has_opengl_texture(ima)) {
+                       if (BKE_image_has_bindcode(ima)) {
                                if (ima->tpageflag & IMA_MIPMAP_COMPLETE) {
-                                       if 
(ima->gputexture[TEXTARGET_TEXTURE_2D]) {
-                                               
GPU_texture_bind(ima->gputexture[TEXTARGET_TEXTURE_2D], 0);
+                                       if 
(ima->bindcode[TEXTARGET_TEXTURE_2D]) {
+                                               glBindTexture(GL_TEXTURE_2D, 
ima->bindcode[TEXTARGET_TEXTURE_2D]);
                                                glTexParameteri(GL_TEXTURE_2D, 
GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
                                                glTexParameteri(GL_TEXTURE_2D, 
GL_TEXTURE_MAG_FILTER, gpu_

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to