Page MenuHome
Paste P1007

T65812 possible fix (store original size in the Image ~ DNA)
ArchivedPublic

Authored by Campbell Barton (campbellbarton) on Jun 21 2019, 9:38 AM.
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index e8c600ee545..1ee23c95d38 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -979,8 +979,9 @@ static void DRW_shgroup_empty_image(OBJECT_Shaders *sh_data,
if (ima != NULL) {
tex = GPU_texture_from_blender(ima, ob->iuser, GL_TEXTURE_2D);
if (tex) {
- size[0] = GPU_texture_width(tex);
- size[1] = GPU_texture_height(tex);
+ const int *gpu_size = ima->gputexture_orig_size[TEXTARGET_TEXTURE_2D];
+ size[0] = gpu_size[0];
+ size[1] = gpu_size[1];
}
}
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 7813ae68371..8a7f9ade969 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -196,16 +196,15 @@ float GPU_get_anisotropic(void)
/* Set OpenGL state for an MTFace */
-static GPUTexture **gpu_get_image_gputexture(Image *ima, GLenum textarget)
+static int gpu_get_index_from_textarget(GLenum textarget)
{
if (textarget == GL_TEXTURE_2D) {
- return &ima->gputexture[TEXTARGET_TEXTURE_2D];
+ return TEXTARGET_TEXTURE_2D;
}
else if (textarget == GL_TEXTURE_CUBE_MAP) {
- return &ima->gputexture[TEXTARGET_TEXTURE_CUBE_MAP];
+ return TEXTARGET_TEXTURE_CUBE_MAP;
}
-
- return NULL;
+ return -1;
}
static uint gpu_texture_create_from_ibuf(Image *ima, ImBuf *ibuf, int textarget)
@@ -443,12 +442,23 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int textarget
ima->gpuflag &= ~IMA_GPU_REFRESH;
}
+ const int tex_index = gpu_get_index_from_textarget(textarget);
+ if (tex_index == -1) {
+ BLI_assert(0);
+ return NULL;
+ }
+
/* Test if we already have a texture. */
- GPUTexture **tex = gpu_get_image_gputexture(ima, textarget);
+ GPUTexture **tex = &(ima->gputexture[tex_index]);
if (*tex) {
return *tex;
}
+ int *gputexture_orig_size = ima->gputexture_orig_size[tex_index];
+
+ gputexture_orig_size[0] = 0;
+ gputexture_orig_size[1] = 0;
+
/* Check if we have a valid image. If not, we return a dummy
* texture with zero bindcode so we don't keep trying. */
uint bindcode = 0;
@@ -469,6 +479,10 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int textarget
BKE_image_release_ibuf(ima, ibuf, NULL);
*tex = GPU_texture_from_bindcode(textarget, bindcode);
+
+ gputexture_orig_size[0] = ibuf->x;
+ gputexture_orig_size[1] = ibuf->y;
+
return *tex;
}
diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h
index 5e4ed16d28e..6b4bcec6057 100644
--- a/source/blender/makesdna/DNA_image_types.h
+++ b/source/blender/makesdna/DNA_image_types.h
@@ -112,6 +112,9 @@ typedef struct Image {
/** Not written in file 2 = TEXTARGET_COUNT. */
struct GPUTexture *gputexture[2];
+ /** 2 = TEXTARGET_COUNT. */
+ int gputexture_orig_size[2][2];
+
/* sources from: */
ListBase anims;
struct RenderResult *rr;

Event Timeline

Campbell Barton (campbellbarton) changed the title of this paste from T65812 possible fix #2 to T65812 possible fix (store original size in the Image ~ DNA).Jun 21 2019, 9:40 AM