[Bf-blender-cvs] [fd8418385c2] master: Add layer and pass index parameters to rna_Image_gl_load

Paul Golter noreply at git.blender.org
Wed Dec 1 14:59:09 CET 2021


Commit: fd8418385c2e3b0cc9ff8a254c3f3e408d0565f9
Author: Paul Golter
Date:   Wed Dec 1 14:58:16 2021 +0100
Branches: master
https://developer.blender.org/rBfd8418385c2e3b0cc9ff8a254c3f3e408d0565f9

Add layer and pass index parameters to rna_Image_gl_load

This patch adds a layer_idx and pass_idx parameter to the rna_Image_gl_load function. It exposes both to the Python API as optional parameters.
This allows python scripters to specifiy which layer and pass they want to load in to an OpenGL texture. Right now image.gl_load() always takes the first layer and first pass.
This is limiting when working with multilayer openEXRs.

With this patch scripters can do something like this:

```
pass_idx = area.spaces.active.image_user.multilayer_pass
layer_idx = area.spaces.active.image_user.multilayer_layer
image.gl_load(frame=0, layer_idx=layer_idx, pass_idx=pass_idx)
```

As the parameters are optional and default to 0, it should not break existing code.

Reviewed By: campbellbarton

Differential Revision: https://developer.blender.org/D13435

===================================================================

M	source/blender/makesrna/intern/rna_image_api.c

===================================================================

diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c
index 4b52ceb6241..7d2697c8770 100644
--- a/source/blender/makesrna/intern/rna_image_api.c
+++ b/source/blender/makesrna/intern/rna_image_api.c
@@ -213,11 +213,17 @@ 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)
+static int rna_Image_gl_load(
+    Image *image, ReportList *reports, int frame, int layer_index, int pass_index)
 {
   ImageUser iuser;
   BKE_imageuser_default(&iuser);
   iuser.framenr = frame;
+  iuser.layer = layer_index;
+  iuser.pass = pass_index;
+  if (image->rr != NULL) {
+    BKE_image_multilayer_index(image->rr, &iuser);
+  }
 
   GPUTexture *tex = BKE_image_get_gpu_texture(image, &iuser, NULL);
 
@@ -230,14 +236,15 @@ static int rna_Image_gl_load(Image *image, ReportList *reports, int frame)
   return 0; /* GL_NO_ERROR */
 }
 
-static int rna_Image_gl_touch(Image *image, ReportList *reports, int frame)
+static int rna_Image_gl_touch(
+    Image *image, ReportList *reports, int frame, int layer_index, int pass_index)
 {
   int error = 0; /* GL_NO_ERROR */
 
   BKE_image_tag_time(image);
 
   if (image->gputexture[TEXTARGET_2D][0] == NULL) {
-    error = rna_Image_gl_load(image, reports, frame);
+    error = rna_Image_gl_load(image, reports, frame, layer_index, pass_index);
   }
 
   return error;
@@ -332,6 +339,24 @@ 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,
+              "layer_index",
+              0,
+              0,
+              INT_MAX,
+              "Layer",
+              "Index of layer that should be loaded",
+              0,
+              INT_MAX);
+  RNA_def_int(func,
+              "pass_index",
+              0,
+              0,
+              INT_MAX,
+              "Pass",
+              "Index of pass that should be loaded",
+              0,
+              INT_MAX);
   /* return value */
   parm = RNA_def_int(
       func, "error", 0, -INT_MAX, INT_MAX, "Error", "OpenGL error value", -INT_MAX, INT_MAX);
@@ -346,6 +371,24 @@ 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,
+              "layer_index",
+              0,
+              0,
+              INT_MAX,
+              "Layer",
+              "Index of layer that should be loaded",
+              0,
+              INT_MAX);
+  RNA_def_int(func,
+              "pass_index",
+              0,
+              0,
+              INT_MAX,
+              "Pass",
+              "Index of pass that should be loaded",
+              0,
+              INT_MAX);
   /* return value */
   parm = RNA_def_int(
       func, "error", 0, -INT_MAX, INT_MAX, "Error", "OpenGL error value", -INT_MAX, INT_MAX);



More information about the Bf-blender-cvs mailing list