Commit: 94d0cbf12782f232eebd9fe54788150421391f37
Author: Lukas Stockner
Date:   Mon Jun 11 19:51:38 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rB94d0cbf12782f232eebd9fe54788150421391f37

Support tiled textures in the viewport and in Eevee

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

M       source/blender/blenkernel/BKE_image.h
M       source/blender/blenkernel/intern/image.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/draw/intern/draw_manager_data.c
M       source/blender/editors/space_image/image_ops.c
M       source/blender/gpu/GPU_material.h
M       source/blender/gpu/intern/gpu_codegen.c
M       source/blender/gpu/intern/gpu_codegen.h
M       source/blender/gpu/intern/gpu_draw.c
M       source/blender/gpu/intern/gpu_texture.c
M       source/blender/gpu/shaders/gpu_shader_material.glsl
M       source/blender/makesdna/DNA_image_types.h
M       source/blender/nodes/shader/nodes/node_shader_tex_environment.c
M       source/blender/nodes/shader/nodes/node_shader_tex_image.c
M       source/blender/nodes/shader/nodes/node_shader_texture.c
M       source/tools

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

diff --git a/source/blender/blenkernel/BKE_image.h 
b/source/blender/blenkernel/BKE_image.h
index 86d3922ca38..2d913da38c5 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -274,6 +274,17 @@ bool BKE_image_has_alpha(struct Image *image);
 /* check if texture has gpu texture code */
 bool BKE_image_has_bindcode(struct Image *ima);
 
+/* get tile index for tiled images */
+int BKE_image_get_tile_index(struct Image *ima, struct ImageUser *iuser);
+
+unsigned int BKE_image_get_bindcode(struct Image *ima, int tile, int type);
+void BKE_image_set_bindcode(struct Image *ima, int tile, int type, unsigned 
int bindcode);
+
+struct GPUTexture *BKE_image_get_gpu_texture(struct Image *ima, int tile, int 
type);
+void BKE_image_set_gpu_texture(struct Image *ima, int tile, int type, struct 
GPUTexture *tex);
+
+void BKE_image_set_num_tiles(struct Image *ima, int num_tiles);
+
 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]);
 void BKE_image_get_aspect(struct Image *image, float *aspx, float *aspy);
diff --git a/source/blender/blenkernel/intern/image.c 
b/source/blender/blenkernel/intern/image.c
index aa05116f052..accbf052de4 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -446,6 +446,13 @@ static void copy_image_packedfiles(ListBase *lb_dst, const 
ListBase *lb_src)
        }
 }
 
+static void image_alloc_gputexture(Image *ima)
+{
+       int len = TEXTARGET_COUNT * max_ii(1, ima->num_tiles);
+       ima->gputexture = MEM_recallocN(ima->gputexture, sizeof(struct 
GPUTexture*) * len);
+       ima->bindcode = MEM_recallocN(ima->bindcode, sizeof(unsigned int) * 
len);
+}
+
 /**
  * Only copy internal data of Image ID from source to already 
allocated/initialized destination.
  * You probably nerver want to use that directly, use id_copy or 
BKE_id_copy_ex for typical needs.
@@ -472,10 +479,9 @@ 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;
-       }
+       ima_dst->gputexture = NULL;
+       ima_dst->bindcode = NULL;
+       image_alloc_gputexture(ima_dst);
 
        if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
                BKE_previewimg_id_copy(&ima_dst->id, &ima_src->id);
@@ -2946,6 +2952,60 @@ void BKE_image_multiview_index(Image *ima, ImageUser 
*iuser)
        }
 }
 
+int BKE_image_get_tile_index(struct Image *ima, struct ImageUser *iuser)
+{
+       if ((ima->source != IMA_SRC_TILED) || !iuser) {
+               return 0;
+       }
+
+       BLI_assert(iuser->tile < ima->num_tiles);
+
+       return iuser->tile;
+}
+
+unsigned int BKE_image_get_bindcode(struct Image *ima, int tile, int type)
+{
+       if (!ima->bindcode) {
+               image_alloc_gputexture(ima);
+       }
+
+       return ima->bindcode[tile*TEXTARGET_COUNT + type];
+}
+
+void BKE_image_set_bindcode(struct Image *ima, int tile, int type, unsigned 
int bindcode)
+{
+       if (!ima->bindcode) {
+               image_alloc_gputexture(ima);
+       }
+
+       ima->bindcode[tile*TEXTARGET_COUNT + type] = bindcode;
+}
+
+struct GPUTexture *BKE_image_get_gpu_texture(struct Image *ima, int tile, int 
type)
+{
+       if (!ima->gputexture) {
+               image_alloc_gputexture(ima);
+       }
+
+       return ima->gputexture[tile*TEXTARGET_COUNT + type];
+}
+
+void BKE_image_set_gpu_texture(struct Image *ima, int tile, int type, struct 
GPUTexture *tex)
+{
+       if (!ima->gputexture) {
+               image_alloc_gputexture(ima);
+       }
+
+       ima->gputexture[tile*TEXTARGET_COUNT + type] = tex;
+}
+
+void BKE_image_set_num_tiles(struct Image *ima, int num_tiles)
+{
+       BLI_assert(ima->source == IMA_SRC_TILED);
+       ima->num_tiles = num_tiles;
+       image_alloc_gputexture(ima);
+}
+
 /* if layer or pass changes, we need an index for the imbufs list */
 /* note it is called for rendered results, but it doesnt use the index! */
 /* and because rendered results use fake layer/passes, don't correct for wrong 
indices here */
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index a9f93dff9e6..8618bd76ec6 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1641,14 +1641,22 @@ void blo_make_image_pointer_map(FileData *fd, Main 
*oldmain)
        for (; ima; ima = ima->id.next) {
                if (ima->cache)
                        oldnewmap_insert(fd->imamap, ima->cache, ima->cache, 0);
-               for (a = 0; a < TEXTARGET_COUNT; a++)
-                       if (ima->gputexture[a])
-                               oldnewmap_insert(fd->imamap, 
ima->gputexture[a], ima->gputexture[a], 0);
                if (ima->rr)
                        oldnewmap_insert(fd->imamap, ima->rr, ima->rr, 0);
                for (a=0; a < IMA_MAX_RENDER_SLOT; a++)
                        if (ima->renders[a])
                                oldnewmap_insert(fd->imamap, ima->renders[a], 
ima->renders[a], 0);
+               if (ima->bindcode) {
+                       oldnewmap_insert(fd->imamap, ima->bindcode, 
ima->bindcode, 0);
+               }
+               if (ima->gputexture) {
+                       oldnewmap_insert(fd->imamap, ima->gputexture, 
ima->gputexture, 0);
+                       for (a = 0; a < max_ii(1, 
ima->num_tiles)*TEXTARGET_COUNT; a++) {
+                               if (ima->gputexture[a]) {
+                                       oldnewmap_insert(fd->imamap, 
ima->gputexture[a], ima->gputexture[a], 0);
+                               }
+                       }
+               }
        }
        for (; sce; sce = sce->id.next) {
                if (sce->nodetree && sce->nodetree->previews) {
@@ -1680,17 +1688,21 @@ void blo_end_image_pointer_map(FileData *fd, Main 
*oldmain)
                ima->cache = newimaadr(fd, ima->cache);
                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;
+                       MEM_SAFE_FREE(ima->gputexture);
+                       MEM_SAFE_FREE(ima->bindcode);
                }
                for (i = 0; i < IMA_MAX_RENDER_SLOT; i++)
                        ima->renders[i] = newimaadr(fd, ima->renders[i]);
                
-               for (i = 0; i < TEXTARGET_COUNT; i++)
-                       ima->gputexture[i] = newimaadr(fd, ima->gputexture[i]);
+               ima->bindcode = newimaadr(fd, ima->bindcode);
+               ima->gputexture = newimaadr(fd, ima->gputexture);
+               if (ima->gputexture) {
+                       for (i = 0; i < max_ii(1, 
ima->num_tiles)*TEXTARGET_COUNT; i++) {
+                               ima->gputexture[i] = newimaadr(fd, 
ima->gputexture[i]);
+                       }
+               }
+
                ima->rr = newimaadr(fd, ima->rr);
        }
        for (; sce; sce = sce->id.next) {
@@ -3915,10 +3927,9 @@ static void direct_link_image(FileData *fd, Image *ima)
        /* if not restored, we keep the binded opengl index */
        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->gputexture = NULL;
+               ima->bindcode = NULL;
                ima->rr = NULL;
        }
        
diff --git a/source/blender/draw/intern/draw_manager_data.c 
b/source/blender/draw/intern/draw_manager_data.c
index b49af47223f..805d71eb393 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -766,9 +766,18 @@ static DRWShadingGroup 
*drw_shgroup_material_inputs(DRWShadingGroup *grp, struct
        for (GPUInput *input = inputs->first; input; input = input->next) {
                /* Textures */
                if (input->ima) {
+                       ImageUser *tex_iuser = input->iuser;
+
+                       /* If there's no specified iuser but we need a 
different tile, create a temporary one. */
+                       ImageUser iuser = {NULL};
+                       iuser.ok = true;
+                       iuser.tile = input->image_tile;
+                       if (!tex_iuser && iuser.tile != 0)
+                               tex_iuser = &iuser;
+
                        double time = 0.0; /* TODO make time variable */
                        GPUTexture *tex = GPU_texture_from_blender(
-                               input->ima, input->iuser, input->textarget, 
input->image_isdata, time, 1);
+                               input->ima, tex_iuser, input->textarget, 
input->image_isdata, time, 1);
 
                        if (input->bindtex) {
                                DRW_shgroup_uniform_texture(grp, 
input->shadername, tex);
diff --git a/source/blender/editors/space_image/image_ops.c 
b/source/blender/editors/space_image/image_ops.c
index 1fc09fb5e86..a3eafc05df1 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -1271,7 +1271,7 @@ static Image *image_open_single(
                if ((frame_seq_len > 1) && (ima->source == IMA_SRC_FILE)) {
                        if (frame_seq_ofs == 1001) {
                                ima->source = IMA_SRC_TILED;
-                               ima->num_tiles = frame_seq_len;
+                               BKE_image_set_num_tiles(ima, frame_seq_len);
                        }
                        else {
                                ima->source = IMA_SRC_SEQUENCE;
diff --git a/source/blender/gpu/GPU_material.h 
b/source/blender/gpu/GPU_material.h
index 0805cc25d04..eb4eaea8c3e 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -220,7 +220,7 @@ GPUNodeLink *GPU_attribute(CustomDataType type, const char 
*name);
 GPUNodeLink *GPU_uniform(float *num);
 GPUNodeLink *GPU_dynamic_uniform(float *num, GPUDynamicType dynamictype, void 
*data);
 GPUNodeLink *GPU_uniform_buffer(float *num, GPUType gputype);
-GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, bool 
is_data);
+GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, bool 
is_data, int tile);
 GPUNodeLink *GPU_cube_map(struct Image *ima, struct ImageUser *iuser, bool 
is_data);
 GPUNodeLink *GPU_image_preview(struct PreviewImage *prv);
 GPUNodeLink *GPU_texture(int size, float *pixels);
diff --git a/source/blender/gpu/intern/gpu_codegen.c 
b/source/blender/gpu/intern/gpu_codegen.c
index 0dd9d1f0908..07c4eb5ce3a 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -498,17 +498,19 @@ const char *GPU_builtin_name(GPUBuiltin builtin)
 }
 
 /* assign only one texid per buffer to avoid sampling the same texture twice */
-static void codegen_set_texid(GHash *bindhash, GPUInput *input, int *texid, 
void *key)
+static void codegen_set_texid(GHash *bindhash, GPUInput *input, int *texid, 
void *key1, int key2)
 {
-       if (BLI_ghash_haskey(bindhash, key)) {
+       GHashPair pair = {key1, SET_INT_IN_POINTER(key2 << 16)};
+       if (BLI_ghash_haskey(bindhash, &pair)) {
                /* Reuse existing texid */
-               input->texid = GET_INT_FROM_POINTER(BLI_ghash_lookup(bindhash, 
key));
+               input->texid = GET_INT_FROM_POINTER(BLI_ghash_lookup(bindhash, 
&pair));
        }
        else {
                /* Allocate new texid */
                input->texid = *texid;
                (*texid)++;
                input->bindtex = true;
+               void *key = BLI_ghashutil_pairallo

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