Fix T81206: Do not limit gl texture size in image editor
This patch will show textures in the image editor with the maximum available resolution determined by the GPU Hardware/Driver. Currently the size is limited by the user preference texture size limit. An image user can set the `IMA_SHOW_MAX_RESOLUTION` flag to request gpu textures in the max supported resolution. When this flag isn't set the gpu texture is limited by the user preference setting. When the gl resolution limit is disabled the GPU texture is always created for the max supported resolution. Reviewed By: Clément Foucault Maniphest Tasks: T81206 Differential Revision: https://developer.blender.org/D9160
This commit is contained in:
@@ -86,15 +86,15 @@ bool BKE_image_has_gpu_texture_premultiplied_alpha(Image *image, ImBuf *ibuf)
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name UDIM gpu texture
|
||||
* \{ */
|
||||
|
||||
static bool is_over_resolution_limit(int w, int h)
|
||||
static bool is_over_resolution_limit(int w, int h, bool limit_gl_texture_size)
|
||||
{
|
||||
return (w > GPU_texture_size_with_limit(w) || h > GPU_texture_size_with_limit(h));
|
||||
return (w > GPU_texture_size_with_limit(w, limit_gl_texture_size) ||
|
||||
h > GPU_texture_size_with_limit(h, limit_gl_texture_size));
|
||||
}
|
||||
|
||||
static int smaller_power_of_2_limit(int num)
|
||||
static int smaller_power_of_2_limit(int num, bool limit_gl_texture_size)
|
||||
{
|
||||
return power_of_2_min_i(GPU_texture_size_with_limit(num));
|
||||
return power_of_2_min_i(GPU_texture_size_with_limit(num, limit_gl_texture_size));
|
||||
}
|
||||
|
||||
static GPUTexture *gpu_texture_create_tile_mapping(Image *ima, const int multiview_eye)
|
||||
@@ -153,6 +153,7 @@ static int compare_packtile(const void *a, const void *b)
|
||||
|
||||
static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
|
||||
{
|
||||
const bool limit_gl_texture_size = (ima->gpuflag & IMA_GPU_MAX_RESOLUTION) == 0;
|
||||
int arraywidth = 0, arrayheight = 0;
|
||||
ListBase boxes = {NULL};
|
||||
|
||||
@@ -168,9 +169,10 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
|
||||
packtile->boxpack.w = ibuf->x;
|
||||
packtile->boxpack.h = ibuf->y;
|
||||
|
||||
if (is_over_resolution_limit(packtile->boxpack.w, packtile->boxpack.h)) {
|
||||
packtile->boxpack.w = smaller_power_of_2_limit(packtile->boxpack.w);
|
||||
packtile->boxpack.h = smaller_power_of_2_limit(packtile->boxpack.h);
|
||||
if (is_over_resolution_limit(
|
||||
packtile->boxpack.w, packtile->boxpack.h, limit_gl_texture_size)) {
|
||||
packtile->boxpack.w = smaller_power_of_2_limit(packtile->boxpack.w, limit_gl_texture_size);
|
||||
packtile->boxpack.h = smaller_power_of_2_limit(packtile->boxpack.h, limit_gl_texture_size);
|
||||
}
|
||||
arraywidth = max_ii(arraywidth, packtile->boxpack.w);
|
||||
arrayheight = max_ii(arrayheight, packtile->boxpack.h);
|
||||
@@ -312,18 +314,26 @@ static GPUTexture *image_get_gpu_texture(Image *ima,
|
||||
short requested_pass = iuser ? iuser->pass : 0;
|
||||
short requested_layer = iuser ? iuser->layer : 0;
|
||||
short requested_view = iuser ? iuser->multi_index : 0;
|
||||
const bool limit_resolution = U.glreslimit != 0 &&
|
||||
((iuser && (iuser->flag & IMA_SHOW_MAX_RESOLUTION) == 0) ||
|
||||
(iuser == NULL));
|
||||
short requested_gpu_flags = limit_resolution ? 0 : IMA_GPU_MAX_RESOLUTION;
|
||||
#define GPU_FLAGS_TO_CHECK (IMA_GPU_MAX_RESOLUTION)
|
||||
/* There is room for 2 multiview textures. When a higher number is requested we should always
|
||||
* target the first view slot. This is fine as multi view images aren't used together. */
|
||||
if (requested_view < 2) {
|
||||
requested_view = 0;
|
||||
}
|
||||
if (ima->gpu_pass != requested_pass || ima->gpu_layer != requested_layer ||
|
||||
ima->gpu_view != requested_view) {
|
||||
ima->gpu_view != requested_view ||
|
||||
((ima->gpuflag & GPU_FLAGS_TO_CHECK) != requested_gpu_flags)) {
|
||||
ima->gpu_pass = requested_pass;
|
||||
ima->gpu_layer = requested_layer;
|
||||
ima->gpu_view = requested_view;
|
||||
ima->gpuflag |= IMA_GPU_REFRESH;
|
||||
ima->gpuflag &= ~GPU_FLAGS_TO_CHECK;
|
||||
ima->gpuflag |= requested_gpu_flags | IMA_GPU_REFRESH;
|
||||
}
|
||||
#undef GPU_FLAGS_TO_CHECK
|
||||
|
||||
/* Check if image has been updated and tagged to be updated (full or partial). */
|
||||
ImageTile *tile = BKE_image_get_tile(ima, 0);
|
||||
@@ -390,9 +400,13 @@ static GPUTexture *image_get_gpu_texture(Image *ima,
|
||||
const bool use_high_bitdepth = (ima->flag & IMA_HIGH_BITDEPTH);
|
||||
const bool store_premultiplied = BKE_image_has_gpu_texture_premultiplied_alpha(ima,
|
||||
ibuf_intern);
|
||||
const bool limit_gl_texture_size = (ima->gpuflag & IMA_GPU_MAX_RESOLUTION) == 0;
|
||||
|
||||
*tex = IMB_create_gpu_texture(
|
||||
ima->id.name + 2, ibuf_intern, use_high_bitdepth, store_premultiplied);
|
||||
*tex = IMB_create_gpu_texture(ima->id.name + 2,
|
||||
ibuf_intern,
|
||||
use_high_bitdepth,
|
||||
store_premultiplied,
|
||||
limit_gl_texture_size);
|
||||
|
||||
GPU_texture_wrap_mode(*tex, true, false);
|
||||
|
||||
|
||||
@@ -2114,7 +2114,8 @@ GPUTexture *BKE_movieclip_get_gpu_texture(MovieClip *clip, MovieClipUser *cuser)
|
||||
/* This only means RGBA16F instead of RGBA32F. */
|
||||
const bool high_bitdepth = false;
|
||||
const bool store_premultiplied = ibuf->rect_float ? false : true;
|
||||
*tex = IMB_create_gpu_texture(clip->id.name + 2, ibuf, high_bitdepth, store_premultiplied);
|
||||
*tex = IMB_create_gpu_texture(
|
||||
clip->id.name + 2, ibuf, high_bitdepth, store_premultiplied, false);
|
||||
|
||||
/* Do not generate mips for movieclips... too slow. */
|
||||
GPU_texture_mipmap_mode(*tex, false, true);
|
||||
|
||||
@@ -1671,5 +1671,19 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
|
||||
*/
|
||||
{
|
||||
/* Keep this block, even when empty. */
|
||||
|
||||
/* UV/Image Max resolution images in image editor. */
|
||||
if (!DNA_struct_find(fd->filesdna, "SpaceImageOverlay")) {
|
||||
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
|
||||
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
||||
LISTBASE_FOREACH (SpaceLink *, space, &area->spacedata) {
|
||||
if (space->spacetype == SPACE_IMAGE) {
|
||||
SpaceImage *sima = (SpaceImage *)space;
|
||||
sima->iuser.flag |= IMA_SHOW_MAX_RESOLUTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ static SpaceLink *image_create(const ScrArea *UNUSED(area), const Scene *UNUSED(
|
||||
simage->overlay.flag = SI_OVERLAY_SHOW_OVERLAYS;
|
||||
|
||||
BKE_imageuser_default(&simage->iuser);
|
||||
simage->iuser.flag = IMA_SHOW_STEREO | IMA_ANIM_ALWAYS;
|
||||
simage->iuser.flag = IMA_SHOW_STEREO | IMA_ANIM_ALWAYS | IMA_SHOW_MAX_RESOLUTION;
|
||||
|
||||
BKE_scopes_new(&simage->scopes);
|
||||
simage->sample_line_hist.height = 100;
|
||||
|
||||
@@ -38,7 +38,7 @@ int GPU_max_textures_vert(void);
|
||||
int GPU_max_textures_geom(void);
|
||||
int GPU_max_textures_frag(void);
|
||||
|
||||
int GPU_texture_size_with_limit(int res);
|
||||
int GPU_texture_size_with_limit(int res, bool limit_gl_texture_size);
|
||||
|
||||
bool GPU_mip_render_workaround(void);
|
||||
bool GPU_depth_blitting_workaround(void);
|
||||
|
||||
@@ -49,10 +49,11 @@ int GPU_max_texture_size(void)
|
||||
return GCaps.max_texture_size;
|
||||
}
|
||||
|
||||
int GPU_texture_size_with_limit(int res)
|
||||
int GPU_texture_size_with_limit(int res, bool limit_gl_texture_size)
|
||||
{
|
||||
int size = GPU_max_texture_size();
|
||||
int reslimit = (U.glreslimit != 0) ? min_ii(U.glreslimit, size) : size;
|
||||
int reslimit = (limit_gl_texture_size && (U.glreslimit != 0)) ? min_ii(U.glreslimit, size) :
|
||||
size;
|
||||
return min_ii(reslimit, res);
|
||||
}
|
||||
|
||||
|
||||
@@ -745,7 +745,8 @@ const char *IMB_ffmpeg_last_error(void);
|
||||
struct GPUTexture *IMB_create_gpu_texture(const char *name,
|
||||
struct ImBuf *ibuf,
|
||||
bool use_high_bitdepth,
|
||||
bool use_premult);
|
||||
bool use_premult,
|
||||
bool limit_gl_texture_size);
|
||||
struct GPUTexture *IMB_touch_gpu_texture(
|
||||
const char *name, struct ImBuf *ibuf, int w, int h, int layers, bool use_high_bitdepth);
|
||||
void IMB_update_gpu_texture_sub(struct GPUTexture *tex,
|
||||
|
||||
@@ -219,10 +219,12 @@ void IMB_update_gpu_texture_sub(GPUTexture *tex,
|
||||
GPUTexture *IMB_create_gpu_texture(const char *name,
|
||||
ImBuf *ibuf,
|
||||
bool use_high_bitdepth,
|
||||
bool use_premult)
|
||||
bool use_premult,
|
||||
bool limit_gl_texture_size)
|
||||
{
|
||||
GPUTexture *tex = NULL;
|
||||
int size[2] = {GPU_texture_size_with_limit(ibuf->x), GPU_texture_size_with_limit(ibuf->y)};
|
||||
int size[2] = {GPU_texture_size_with_limit(ibuf->x, limit_gl_texture_size),
|
||||
GPU_texture_size_with_limit(ibuf->y, limit_gl_texture_size)};
|
||||
bool do_rescale = (ibuf->x != size[0]) || (ibuf->y != size[1]);
|
||||
|
||||
#ifdef WITH_DDS
|
||||
|
||||
@@ -119,6 +119,10 @@ typedef struct ImageTile {
|
||||
/* #define IMA_UNUSED_2 (1 << 2) */
|
||||
#define IMA_NEED_FRAME_RECALC (1 << 3)
|
||||
#define IMA_SHOW_STEREO (1 << 4)
|
||||
/* Do not limit the resolution by the limit texture size option in the user preferences.
|
||||
* Images in the image editor or used as a backdrop are always shown using the maximum
|
||||
* possible resolution. */
|
||||
#define IMA_SHOW_MAX_RESOLUTION (1 << 5)
|
||||
|
||||
/* Used to get the correct gpu texture from an Image datablock. */
|
||||
typedef enum eGPUTextureTarget {
|
||||
@@ -229,6 +233,8 @@ enum {
|
||||
IMA_GPU_PARTIAL_REFRESH = (1 << 1),
|
||||
/** All mipmap levels in OpenGL texture set? */
|
||||
IMA_GPU_MIPMAP_COMPLETE = (1 << 2),
|
||||
/** Current texture resolution won't be limited by the GL Texture Limit user preference. */
|
||||
IMA_GPU_MAX_RESOLUTION = (1 << 3),
|
||||
};
|
||||
|
||||
/* Image.source, where the image comes from */
|
||||
|
||||
Reference in New Issue
Block a user