[Bf-blender-cvs] [799303dd871] temp-udim-images: Merge remote-tracking branch 'origin/blender2.8' into udim
Lukas Stockner
noreply at git.blender.org
Tue Jun 12 15:13:51 CEST 2018
Commit: 799303dd871862a6c1baa38c481242b9b35f6657
Author: Lukas Stockner
Date: Tue Jun 12 15:13:24 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rB799303dd871862a6c1baa38c481242b9b35f6657
Merge remote-tracking branch 'origin/blender2.8' into udim
===================================================================
===================================================================
diff --cc source/blender/blenkernel/BKE_image.h
index f795b53e818,546204b5eef..3cd83926379
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@@ -272,21 -271,8 +272,18 @@@ bool BKE_image_scale(struct Image *imag
bool BKE_image_has_alpha(struct Image *image);
/* check if texture has gpu texture code */
- bool BKE_image_has_bindcode(struct Image *ima);
+ bool BKE_image_has_opengl_texture(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);
+
+int BKE_image_get_tile_from_pos(struct Image *ima, float uv[2], float new_uv[2], float ofs[2]);
+
+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 --cc source/blender/blenkernel/intern/image.c
index 4edf89fc036,b6b3dd31096..b5a1728d6f9
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@@ -380,6 -380,6 +380,8 @@@ static void image_init(Image *ima, shor
if (source == IMA_SRC_VIEWER)
ima->flag |= IMA_VIEW_AS_RENDER;
++ ima->num_tiles = 1;
++
BKE_color_managed_colorspace_settings_init(&ima->colorspace_settings);
ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo Format");
}
@@@ -446,13 -446,6 +448,12 @@@ static void copy_image_packedfiles(List
}
}
+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.
@@@ -478,10 -471,10 +479,7 @@@ void BKE_image_copy_data(Main *UNUSED(b
}
BLI_listbase_clear(&ima_dst->anims);
--
- for (int i = 0; i < TEXTARGET_COUNT; i++) {
- 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);
@@@ -544,41 -537,16 +542,39 @@@ bool BKE_image_scale(Image *image, int
return (ibuf != NULL);
}
- bool BKE_image_has_bindcode(Image *ima)
+ bool BKE_image_has_opengl_texture(Image *ima)
{
- bool has_bindcode = false;
-- for (int i = 0; i < TEXTARGET_COUNT; i++) {
- if (ima->bindcode[i]) {
- has_bindcode = true;
- break;
++ for (int i = 0; i < max_ii(1, ima->num_tiles)*TEXTARGET_COUNT; i++) {
+ if (ima->gputexture[i]) {
+ return true;
}
}
- return has_bindcode;
+ return false;
}
+int BKE_image_get_tile_from_pos(struct Image *ima, float uv[2], float new_uv[2], float ofs[2])
+{
+ copy_v2_v2(new_uv, uv);
+ zero_v2(ofs);
+
+ if ((ima->source != IMA_SRC_TILED) || uv[0] < 0.0f || uv[1] < 0.0f || uv[0] >= 10.0f) {
+ return 0;
+ }
+
+ int ix = (int) uv[0];
+ int iy = (int) uv[1];
+ int tile = 10*iy + ix;
+
+ if (tile >= ima->num_tiles) {
+ return 0;
+ }
+
+ ofs[0] = ix;
+ ofs[1] = iy;
+ sub_v2_v2(new_uv, ofs);
+ return tile;
+}
+
static void image_init_color_management(Image *ima)
{
ImBuf *ibuf;
@@@ -2975,60 -2927,6 +2956,42 @@@ void BKE_image_multiview_index(Image *i
}
}
+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 --cc source/blender/blenloader/intern/readfile.c
index e91057c146b,8807cbc1d21..45b30e253cc
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@@ -1646,17 -1649,6 +1646,14 @@@ void blo_make_image_pointer_map(FileDat
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) {
@@@ -1688,21 -1680,16 +1685,19 @@@ void blo_end_image_pointer_map(FileDat
ima->cache = newimaadr(fd, ima->cache);
if (ima->cache == NULL) {
ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
- for (i = 0; i < TEXTARGET_COUNT; i++) {
- 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]);
- ima->bindcode = newimaadr(fd, ima->bindcode);
- for (i = 0; i < TEXTARGET_COUNT; i++)
- ima->gputexture[i] = newimaadr(fd, ima->gputexture[i]);
+ 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) {
@@@ -3927,9 -3914,9 +3922,7 @@@ static void direct_link_image(FileData
/* 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->gputexture[i] = NULL;
- }
+ ima->gputexture = NULL;
- ima->bindcode = NULL;
ima->rr = NULL;
}
diff --cc source/blender/gpu/intern/gpu_draw.c
index ad3ce9c0cb5,fdffe21b1e7..55fcb030252
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@@ -277,32 -284,46 +274,51 @@@ static void gpu_verify_high_bit_srgb_bu
}
}
- int GPU_verify_image(
- Image *ima, ImageUser *iuser,
- int textarget, bool compare, bool mipmap, bool is_data)
+ GPUTexture *GPU_texture_from_blender(Image *ima,
+ ImageUser *iuser,
+ int textarget,
+ bool is_data,
+ double UNUSED(time),
+ int mipmap)
{
- 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;
-
- GTS.ima = ima;
+ if (ima == NULL) {
+ return NULL;
+ }
++
++ int gputex_type = (textarget == GL_TEXTURE_CUBE_MAP)? TEXTARGET_TEXTURE_CUBE_MAP : TEXTARGET_TEXTURE_2D;
++ int tile = BKE_image_get_tile_index(ima, iuser);
+
+ /* Test if we already have a texture. */
- GPUTexture **tex = gpu_get_image_gputexture(ima, textarget);
- if (*tex) {
- return *tex;
++ GPUTexture *tex = BKE_image_get_gpu_texture(ima, tile, gputex_type);
++ if (tex) {
++ return tex;
+ }
- if (compare && ima == GTS.curima) {
- return (ima != NULL);
+ /* Check if we have a valid image. If not, we return a dummy
+ * texture with zero bindcode so we don't keep trying. */
+ unsigned int bindcode = 0;
+ if (ima->ok == 0) {
- *tex = GPU_texture_from_bindcode(textarget, bindcode);
- return *tex;
++ tex = GPU_texture_from_bindcode(textarget, bindcode);
++ BKE_image_set_gpu_texture(ima, tile, gputex_type, tex);
++ return tex;
}
- /* check if we have a valid image */
- if (ima == NULL || ima->ok == 0)
- return 0;
+ /* currently, tpage refresh is used by ima sequences */
+ if (ima->tpageflag & IMA_TPAGE_REFRESH) {
+ GPU_free_image(ima);
+ ima->tpageflag &= ~IMA_TPAGE_REFRESH;
+ }
/* check if we have a valid image buffer */
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
+ if (ibuf == NULL) {
- *tex = GPU_texture_from_bindcode(textarget, bindcode);
- return *tex;
++ tex = GPU_texture_from_bindcode(textarget, bindcode);
++ BKE_image_
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list