7#if defined(WITH_OPENCOLORIO)
22using namespace OCIO_NAMESPACE;
24static ConstProcessorRcPtr create_to_scene_linear_processor(
27 return create_ocio_processor(
28 ocio_config, display_shader.from_colorspace.c_str(), ROLE_SCENE_LINEAR);
31static ConstProcessorRcPtr create_to_display_processor(
36 display_parameters.view = display_shader.view;
37 display_parameters.display = display_shader.display;
38 display_parameters.look = display_shader.look;
39 return create_ocio_display_processor(config, display_parameters);
43 const GpuShaderDescRcPtr &shader_desc,
47 uniform.
name = shader_desc->getUniform(index, uniform.data);
48 if (uniform.data.m_type == UNIFORM_UNKNOWN) {
52 textures.uniforms.append(uniform);
57 const GpuShaderDescRcPtr &shader_desc,
60 const char *texture_name =
nullptr;
61 const char *sampler_name =
nullptr;
65 GpuShaderCreator::TextureType channel = GpuShaderCreator::TEXTURE_RGB_CHANNEL;
69 static_assert(OCIO_VERSION_HEX >= 0x02030000);
70 GpuShaderDesc::TextureDimensions dimensions = GpuShaderDesc::TEXTURE_2D;
71 shader_desc->getTexture(
72 index, texture_name, sampler_name, width, height, channel, dimensions, interpolation);
75 shader_desc->getTextureValues(index, values);
76 if (texture_name ==
nullptr || sampler_name ==
nullptr || width == 0 || height == 0 ||
90 std::string sampler1D_name = std::string(
"sampler1D ") + sampler_name;
91 if (strstr(shader_desc->getShaderText(), sampler1D_name.c_str()) !=
nullptr) {
99 if (lut.texture ==
nullptr) {
106 lut.sampler_name = sampler_name;
108 textures.luts.append(lut);
114 const GpuShaderDescRcPtr &shader_desc,
117 const char *texture_name =
nullptr;
118 const char *sampler_name =
nullptr;
121 shader_desc->get3DTexture(index, texture_name, sampler_name, edgelen, interpolation);
124 shader_desc->get3DTextureValues(index, values);
125 if (texture_name ==
nullptr || sampler_name ==
nullptr || edgelen == 0 || values ==
nullptr) {
138 if (lut.texture ==
nullptr) {
145 lut.sampler_name = sampler_name;
147 textures.luts.append(lut);
152 const GpuShaderDescRcPtr &shader_desc)
154 for (
int index = 0; index < shader_desc->getNumUniforms(); index++) {
155 if (!add_gpu_uniform(textures, shader_desc, index)) {
159 for (
int index = 0; index < shader_desc->getNumTextures(); index++) {
160 if (!add_gpu_lut_1D2D(textures, shader_desc, index)) {
164 for (
int index = 0; index < shader_desc->getNum3DTextures(); index++) {
165 if (!add_gpu_lut_3D(textures, shader_desc, index)) {
175void LibOCIOGPUShaderBinder::construct_shader_for_processors(
177 const ConstProcessorRcPtr &processor_to_scene_linear,
178 const ConstProcessorRcPtr &processor_to_display,
179 const Span<std::array<StringRefNull, 2>> additional_defines)
const
181 std::string fragment_source;
183 GpuShaderDescRcPtr shaderdesc_to_scene_linear;
184 if (processor_to_scene_linear) {
185 shaderdesc_to_scene_linear = GpuShaderDesc::CreateShaderDesc();
186 shaderdesc_to_scene_linear->setLanguage(GPU_LANGUAGE_GLSL_1_3);
187 shaderdesc_to_scene_linear->setFunctionName(
"OCIO_to_scene_linear");
188 shaderdesc_to_scene_linear->setResourcePrefix(
"to_scene");
189 processor_to_scene_linear->getDefaultGPUProcessor()->extractGpuShaderInfo(
190 shaderdesc_to_scene_linear);
191 shaderdesc_to_scene_linear->finalize();
193 if (!create_gpu_textures(display_shader.textures, shaderdesc_to_scene_linear)) {
194 display_shader.is_valid =
false;
198 fragment_source += shaderdesc_to_scene_linear->getShaderText();
199 fragment_source +=
"\n";
202 GpuShaderDescRcPtr shaderdesc_to_display;
203 if (processor_to_display) {
204 shaderdesc_to_display = GpuShaderDesc::CreateShaderDesc();
205 shaderdesc_to_display->setLanguage(GPU_LANGUAGE_GLSL_1_3);
206 shaderdesc_to_display->setFunctionName(
"OCIO_to_display");
207 shaderdesc_to_display->setResourcePrefix(
"to_display");
208 processor_to_display->getDefaultGPUProcessor()->extractGpuShaderInfo(shaderdesc_to_display);
209 shaderdesc_to_display->finalize();
211 if (!create_gpu_textures(display_shader.textures, shaderdesc_to_display)) {
212 display_shader.is_valid =
false;
216 fragment_source += shaderdesc_to_display->getShaderText();
217 fragment_source +=
"\n";
220 if (!create_gpu_shader(display_shader, fragment_source, additional_defines)) {
221 display_shader.is_valid =
false;
225 display_shader.is_valid =
true;
228void LibOCIOGPUShaderBinder::construct_display_shader(
231 const LibOCIOConfig &config =
static_cast<const LibOCIOConfig &
>(config_);
232 const OCIO_NAMESPACE::ConstConfigRcPtr &ocio_config = config.get_ocio_config();
234 ConstProcessorRcPtr processor_to_scene_linear = create_to_scene_linear_processor(ocio_config,
236 ConstProcessorRcPtr processor_to_display = create_to_display_processor(config, display_shader);
238 if (!processor_to_scene_linear || !processor_to_display) {
239 display_shader.is_valid =
false;
243 construct_shader_for_processors(
244 display_shader, processor_to_scene_linear, processor_to_display, {});
247void LibOCIOGPUShaderBinder::construct_scene_linear_shader(
250 const LibOCIOConfig &config =
static_cast<const LibOCIOConfig &
>(config_);
251 const OCIO_NAMESPACE::ConstConfigRcPtr &ocio_config = config.get_ocio_config();
253 ConstProcessorRcPtr processor_to_scene_linear = create_to_scene_linear_processor(ocio_config,
255 if (!processor_to_scene_linear) {
256 display_shader.is_valid =
false;
260 construct_shader_for_processors(
261 display_shader, processor_to_scene_linear,
nullptr, {{
"USE_TO_SCENE_LINEAR_ONLY",
""}});
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
GPUTexture * GPU_texture_create_1d(const char *name, int width, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
GPUTexture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const void *data)
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
StringRefNull from_colorspace