Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2019-04-23 14:56:30 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-13 16:56:10 +0300
commit7ad802cf3ae500bc72863b6dba0f28a488fce3d1 (patch)
treea1dd8b96c21a8ba51434933163b5792564006d55 /source/blender/makesrna/intern/rna_image_api.c
parente9d2ec46c413718cd058abba84e2badd48542781 (diff)
Cycles/Eevee: unified and improved texture image color space handling
Cycles now uses the color space on the image datablock, and uses OpenColorIO to convert to scene linear as needed. Byte images do not take extra memory, they are compressed in scene linear + sRGB transfer function which in common cases is a no-op. Eevee and workbench were changed to work similar. Float images are stored as scene linear. Byte images are compressed as scene linear + sRGB and stored in a GL_SRGB8_ALPHA8 texture. From the GLSL shader side this means they are read as scene linear, simplifying the code and taking advantage of hardware support. Further, OpenGL image textures are now all stored with premultiplied alpha. Eevee texture sampling looks a little different now because interpolation happens premultiplied and in scene linear space. Overlays and grease pencil work in sRGB space so those now have an extra conversion to sRGB after reading from image textures. This is not particularly elegant but as long as engines use different conventions, one or the other needs to do conversion. This change breaks compatibility for cases where multiple image texture nodes were using the same image with different color space node settings. However it gives more predictable behavior for baking and texture painting if save, load and image editing operations have a single color space to handle. Differential Revision: https://developer.blender.org/D4807
Diffstat (limited to 'source/blender/makesrna/intern/rna_image_api.c')
-rw-r--r--source/blender/makesrna/intern/rna_image_api.c95
1 files changed, 12 insertions, 83 deletions
diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c
index ca75f862b11..553dbeeb97b 100644
--- a/source/blender/makesrna/intern/rna_image_api.c
+++ b/source/blender/makesrna/intern/rna_image_api.c
@@ -211,69 +211,30 @@ 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)
{
- GPUTexture *tex = image->gputexture[TEXTARGET_TEXTURE_2D];
- int error = GL_NO_ERROR;
-
- if (tex)
- return error;
-
ImageUser iuser = {NULL};
iuser.framenr = frame;
iuser.ok = true;
- void *lock;
- ImBuf *ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock);
-
- /* clean glError buffer */
- while (glGetError() != GL_NO_ERROR) {
- }
+ GPUTexture *tex = GPU_texture_from_blender(image, &iuser, GL_TEXTURE_2D);
- if (ibuf == NULL || ibuf->rect == NULL) {
- BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
- BKE_image_release_ibuf(image, ibuf, lock);
+ if (tex == NULL) {
+ BKE_reportf(reports, RPT_ERROR, "Failed to load image texture '%s'", image->id.name + 2);
return (int)GL_INVALID_OPERATION;
}
- unsigned int bindcode = 0;
- GPU_create_gl_tex(&bindcode,
- ibuf->rect,
- ibuf->rect_float,
- ibuf->x,
- ibuf->y,
- GL_TEXTURE_2D,
- (filter != GL_NEAREST && filter != GL_LINEAR),
- false,
- image);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (GLint)filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (GLint)mag);
-
- /* TODO(merwin): validate input (dimensions, filter, mag) before calling OpenGL
- * instead of trusting input & testing for error after */
- error = glGetError();
-
- if (error) {
- glDeleteTextures(1, (GLuint *)&bindcode);
- }
- else {
- image->gputexture[TEXTARGET_TEXTURE_2D] = GPU_texture_from_bindcode(GL_TEXTURE_2D, bindcode);
- }
-
- BKE_image_release_ibuf(image, ibuf, lock);
-
- return error;
+ return GL_NO_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 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);
+ error = rna_Image_gl_load(image, reports, frame);
return error;
}
@@ -367,52 +328,20 @@ 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,
- "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",
- "The texture magnification function to use if the image wasn't loaded",
- -INT_MAX,
- INT_MAX);
/* return value */
parm = RNA_def_int(
func, "error", 0, -INT_MAX, INT_MAX, "Error", "OpenGL error value", -INT_MAX, INT_MAX);
RNA_def_function_return(func, parm);
func = RNA_def_function(srna, "gl_load", "rna_Image_gl_load");
- RNA_def_function_ui_description(func, "Load the image into OpenGL graphics memory");
+ RNA_def_function_ui_description(
+ func,
+ "Load the image into an OpenGL texture. On success, image.bindcode will contain the "
+ "OpenGL texture bindcode. Colors read from the texture will be in scene linear color space "
+ "and have premultiplied alpha.");
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,
- "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",
- "The texture magnification function",
- -INT_MAX,
- INT_MAX);
/* return value */
parm = RNA_def_int(
func, "error", 0, -INT_MAX, INT_MAX, "Error", "OpenGL error value", -INT_MAX, INT_MAX);