From 1ece5e87a29361c607d374d02edc4d4758294d37 Mon Sep 17 00:00:00 2001 From: Beat Reichenbach <44111292+beatreichenbach@users.noreply.github.com> Date: Sat, 14 Jun 2025 10:27:35 -0700 Subject: [PATCH] Add Python GPUProcessor example Signed-off-by: Beat Reichenbach <44111292+beatreichenbach@users.noreply.github.com> --- docs/guides/developing/usage_examples.rst | 35 ++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/docs/guides/developing/usage_examples.rst b/docs/guides/developing/usage_examples.rst index e6ef8f5061..e62b80f868 100644 --- a/docs/guides/developing/usage_examples.rst +++ b/docs/guides/developing/usage_examples.rst @@ -367,7 +367,7 @@ and an example helper class is provided for use with OpenGL. C++ +++ -This example is available as a working app in the OCIO source: src/apps/ociodisplay. +This example is available as a working app in the OCIO source: ``src/apps/ociodisplay``. .. code-block:: cpp @@ -402,3 +402,36 @@ This example is available as a working app in the OCIO source: src/apps/ociodisp oglApp->setShader(shaderDesc); oglApp->redisplay(); + +Python +++++++ + +A full example of a GPUProcessor can be found in the OCIO source: ``src/apps/pyociodisplay``. + +.. code-block:: python + + import PyOpenColorIO as OCIO + + # Step 1: Get the config + config = OCIO.GetCurrentConfig() + + # Step 2: Lookup the display ColorSpace + display = config.getDefaultDisplay() + view = config.getDefaultView(display) + + # Step 3: Create a DisplayViewTransform, and set the input, display, and view + # (This example assumes the input is a role. Adapt as needed.) + transform = OCIO.DisplayViewTransform() + transform.setSrc(OCIO.ROLE_SCENE_LINEAR) + transform.setDisplay(display) + transform.setView(view) + + # Step 4: Create the processor + processor = config.getProcessor(transform) + gpu = processor.getDefaultGPUProcessor() + + # Step 5: Extract the GLSL ShaderText to be used in an OpenGL app. + shader_desc = OCIO.GpuShaderDesc.CreateShaderDesc(language=OCIO.GPU_LANGUAGE_GLSL_4_0) + gpu.extractGpuShaderInfo(shader_desc) + source = shader_desc.getShaderText() + print(source)