[Bf-blender-cvs] [3451769219b] temp-udim-images: Move GPUTexture to per-tile struct
Lukas Stockner
noreply at git.blender.org
Tue Jun 12 18:56:19 CEST 2018
Commit: 3451769219b5e1474689e388970950f107494d60
Author: Lukas Stockner
Date: Tue Jun 12 18:10:42 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rB3451769219b5e1474689e388970950f107494d60
Move GPUTexture to per-tile struct
===================================================================
M source/blender/blenkernel/intern/image.c
M source/blender/blenloader/intern/readfile.c
M source/blender/makesdna/DNA_image_types.h
M source/blender/makesrna/intern/rna_image_api.c
===================================================================
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index bbec4ec527a..7569e3fb9a6 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -452,12 +452,6 @@ 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);
-}
-
/**
* 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.
@@ -483,7 +477,11 @@ void BKE_image_copy_data(Main *UNUSED(bmain), Image *ima_dst, const Image *ima_s
}
BLI_listbase_clear(&ima_dst->anims);
- ima_dst->gputexture = NULL;
+ for (int i = 0; i < ima_dst->num_tiles; i++) {
+ for (int j = 0; j < TEXTARGET_COUNT; j++) {
+ ima_dst->tiles[i].gputexture[j] = NULL;
+ }
+ }
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
BKE_previewimg_id_copy(&ima_dst->id, &ima_src->id);
@@ -548,9 +546,11 @@ bool BKE_image_scale(Image *image, int width, int height)
bool BKE_image_has_opengl_texture(Image *ima)
{
- for (int i = 0; i < max_ii(1, ima->num_tiles)*TEXTARGET_COUNT; i++) {
- if (ima->gputexture[i]) {
- return true;
+ for (int i = 0; i < ima->num_tiles; i++) {
+ for (int j = 0; j < TEXTARGET_COUNT; j++) {
+ if (ima->tiles[i].gputexture[j]) {
+ return true;
+ }
}
}
return false;
@@ -2978,31 +2978,6 @@ int BKE_image_get_tile_index(struct Image *ima, struct ImageUser *iuser)
return iuser->tile;
}
-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);
-}
-
bool BKE_image_make_tiled(struct Image *ima, int num_tiles)
{
if (ima->source != IMA_SRC_FILE) {
@@ -3020,6 +2995,20 @@ bool BKE_image_make_tiled(struct Image *ima, int num_tiles)
return true;
}
+struct GPUTexture *BKE_image_get_gpu_texture(struct Image *ima, int tile, int type)
+{
+ BLI_assert(tile < ima->num_tiles);
+
+ return ima->tiles[tile].gputexture[type];
+}
+
+void BKE_image_set_gpu_texture(struct Image *ima, int tile, int type, struct GPUTexture *tex)
+{
+ BLI_assert(tile < ima->num_tiles);
+
+ ima->tiles[tile].gputexture[type] = tex;
+}
+
/* 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 ec236d9ff15..7fd91bffab1 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1634,7 +1634,7 @@ void blo_make_image_pointer_map(FileData *fd, Main *oldmain)
{
Image *ima = oldmain->image.first;
Scene *sce = oldmain->scene.first;
- int a;
+ int a, b;
fd->imamap = oldnewmap_new();
@@ -1646,11 +1646,10 @@ void blo_make_image_pointer_map(FileData *fd, Main *oldmain)
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->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 (a = 0; a < ima->num_tiles; a++) {
+ for (b = 0; b < TEXTARGET_COUNT; b++) {
+ if (ima->tiles[a].gputexture[b]) {
+ oldnewmap_insert(fd->imamap, ima->tiles[a].gputexture[b], ima->tiles[a].gputexture[b], 0);
}
}
}
@@ -1686,15 +1685,17 @@ void blo_end_image_pointer_map(FileData *fd, Main *oldmain)
if (ima->cache == NULL) {
ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
ima->rr = NULL;
- MEM_SAFE_FREE(ima->gputexture);
+ for (i = 0; i < ima->num_tiles; i++) {
+ for (int j = 0; j < TEXTARGET_COUNT; j++) {
+ ima->tiles[i].gputexture[j] = NULL;
+ }
+ }
}
for (i = 0; i < IMA_MAX_RENDER_SLOT; i++)
ima->renders[i] = newimaadr(fd, ima->renders[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]);
+ for (i = 0; i < ima->num_tiles; i++) {
+ for (int j = 0; j < TEXTARGET_COUNT; j++) {
+ ima->tiles[i].gputexture[j] = newimaadr(fd, ima->tiles[i].gputexture[j]);
}
}
@@ -3925,10 +3926,16 @@ 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;
- ima->gputexture = NULL;
+ if (ima->tiles) {
+ for (a = 0; a < ima->num_tiles; a++) {
+ for (int i = 0; i < TEXTARGET_COUNT; i++) {
+ ima->tiles[a].gputexture[i] = NULL;
+ }
+ }
+ }
ima->rr = NULL;
}
-
+
/* undo system, try to restore render buffers */
if (fd->imamap) {
for (a = 0; a < IMA_MAX_RENDER_SLOT; a++)
diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h
index 775285a976a..45abfd276c0 100644
--- a/source/blender/makesdna/DNA_image_types.h
+++ b/source/blender/makesdna/DNA_image_types.h
@@ -86,7 +86,14 @@ typedef struct RenderSlot {
char name[64]; /* 64 = MAX_NAME */
} RenderSlot;
+enum {
+ TEXTARGET_TEXTURE_2D = 0,
+ TEXTARGET_TEXTURE_CUBE_MAP = 1,
+ TEXTARGET_COUNT = 2
+};
+
typedef struct ImageTile {
+ struct GPUTexture *gputexture[2]; /* TEXTARGET_COUNT */
char ok;
char pad[7];
} ImageTile;
@@ -98,11 +105,6 @@ typedef struct ImageTile {
#define IMA_NEED_FRAME_RECALC 8
#define IMA_SHOW_STEREO 16
-enum {
- TEXTARGET_TEXTURE_2D = 0,
- TEXTARGET_TEXTURE_CUBE_MAP = 1,
- TEXTARGET_COUNT = 2
-};
typedef struct Image {
ID id;
@@ -110,7 +112,6 @@ typedef struct Image {
char name[1024]; /* file path, 1024 = FILE_MAX */
struct MovieCache *cache; /* not written in file */
- struct GPUTexture **gputexture; /* not written in file 2 = TEXTARGET_COUNT */
/* sources from: */
ListBase anims;
diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c
index d6fd83b0b41..4ce6dac0a8d 100644
--- a/source/blender/makesrna/intern/rna_image_api.c
+++ b/source/blender/makesrna/intern/rna_image_api.c
@@ -218,9 +218,9 @@ static void rna_Image_scale(Image *image, ReportList *reports, int width, int he
}
}
-static int rna_Image_gl_load(Image *image, ReportList *reports, int frame, int filter, int mag)
+static int rna_Image_gl_load(Image *image, ReportList *reports, int frame, int tile, int filter, int mag)
{
- GPUTexture *tex = image->gputexture[TEXTARGET_TEXTURE_2D];
+ GPUTexture *tex = BKE_image_get_gpu_texture(image, tile, TEXTARGET_TEXTURE_2D);
int error = GL_NO_ERROR;
if (tex)
@@ -229,6 +229,7 @@ static int rna_Image_gl_load(Image *image, ReportList *reports, int frame, int f
ImageUser iuser = {NULL};
iuser.framenr = frame;
iuser.ok = true;
+ iuser.tile = tile;
void *lock;
ImBuf *ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock);
@@ -257,7 +258,7 @@ static int rna_Image_gl_load(Image *image, ReportList *reports, int frame, int f
glDeleteTextures(1, (GLuint *)&bindcode);
}
else {
- image->gputexture[TEXTARGET_TEXTURE_2D] = GPU_texture_from_bindcode(GL_TEXTURE_2D, bindcode);
+ BKE_image_set_gpu_texture(image, tile, TEXTARGET_TEXTURE_2D, GPU_texture_from_bindcode(GL_TEXTURE_2D, bindcode));
}
BKE_image_release_ibuf(image, ibuf, lock);
@@ -265,14 +266,14 @@ static int rna_Image_gl_load(Image *image, ReportList *reports, int frame, int f
return error;
}
-static int rna_Image_gl_touch(Image *image, ReportList *reports, int frame, int filter, int mag)
+static int rna_Image_gl_touch(Image *image, ReportList *reports, int frame, int tile, int filter, int mag)
{
int error = GL_NO_ERROR;
BKE_image_tag_time(image);
- if (image->gputexture[TEXTARGET_TEXTURE_2D] == NULL)
- error = rna_Image_gl_load(image, reports, frame, filter, mag);
+ if (BKE_image_get_gpu_texture(image, tile, TEXTARGET_TEXTURE_2D) == NULL)
+ error = rna_Image_gl_load(image, reports, frame, tile, filter, mag);
return error;
}
@@ -357,6 +358,8 @@ void RNA_api_image(StructRNA *srna)
RNA_def_function_flag(func, FUNC_USE_REPORTS);
RNA_def_int(func, "frame", 0, 0, INT_MAX, "Frame",
"Frame of image sequence or movie", 0, INT_MAX);
+ RNA_def_int(func, "tile", 0, 0, INT_MAX, "Tile",
+ "Tile of a tiled image", 0, INT_MAX);
RNA_def_int(func, "filter", GL_LINEAR_MIPMAP_NEAREST, -INT_MAX, INT_MAX, "Filter",
"The texture minifying function to use if the image wasn't loaded", -INT_MAX, INT_MAX);
RNA_def_int(func, "mag", GL_LINEAR, -INT_MAX, INT_MAX, "Magnification",
@@ -370,6 +373,8 @@ void RNA_api_image(StructRNA *srna)
RNA_def_function_flag(func, FUNC_USE_REPORTS);
RNA_def_int(func, "frame", 0, 0, INT_MAX, "Frame",
"Frame of image sequence or movie", 0, INT_MAX);
+ RNA_def_int(func, "tile", 0, 0, INT_MAX, "Tile",
+ "Tile of a tiled image", 0, INT_MAX);
RNA_def_int(func, "filter", GL_LINEAR_MIPMAP_NEAREST, -INT_MAX, INT_MAX, "Filter",
"The texture minifying function", -INT_MAX, INT_MAX);
RNA_def_int(func, "mag", GL_LINEAR, -INT_MAX, INT_MAX, "Magnification",
More information about the Bf-blender-cvs
mailing list