20using namespace OCIO_NAMESPACE;
22static ConstProcessorRcPtr create_to_scene_linear_processor(
26 ocio_config, display_shader.from_colorspace.c_str(), ROLE_SCENE_LINEAR);
29static ConstProcessorRcPtr create_to_display_processor(
34 display_parameters.view = display_shader.view;
35 display_parameters.display = display_shader.display;
36 display_parameters.look = display_shader.look;
37 display_parameters.use_hdr_buffer = display_shader.use_hdr_buffer;
38 display_parameters.use_display_emulation = display_shader.use_display_emulation;
39 display_parameters.use_scope_space = display_shader.use_scope_space;
44 const GpuShaderDescRcPtr &shader_desc,
49 if (
uniform.data.m_type == UNIFORM_UNKNOWN) {
53 textures.uniforms.append(
uniform);
58 const GpuShaderDescRcPtr &shader_desc,
61 const char *texture_name =
nullptr;
62 const char *sampler_name =
nullptr;
66 GpuShaderCreator::TextureType channel = GpuShaderCreator::TEXTURE_RGB_CHANNEL;
70 static_assert(OCIO_VERSION_HEX >= 0x02030000);
71 GpuShaderDesc::TextureDimensions dimensions = GpuShaderDesc::TEXTURE_2D;
72 shader_desc->getTexture(
73 index, texture_name, sampler_name, width, height, channel, dimensions, interpolation);
76 shader_desc->getTextureValues(index, values);
77 if (texture_name ==
nullptr || sampler_name ==
nullptr || width == 0 || height == 0 ||
84 gpu::TextureFormat::SFLOAT_16_16_16 :
92 std::string sampler1D_name = std::string(
"sampler1D ") + sampler_name;
93 if (strstr(shader_desc->getShaderText(), sampler1D_name.c_str()) !=
nullptr) {
101 if (lut.texture ==
nullptr) {
108 lut.sampler_name = sampler_name;
110 textures.luts.append(lut);
116 const GpuShaderDescRcPtr &shader_desc,
119 const char *texture_name =
nullptr;
120 const char *sampler_name =
nullptr;
123 shader_desc->get3DTexture(index, texture_name, sampler_name, edgelen, interpolation);
126 shader_desc->get3DTextureValues(index, values);
127 if (texture_name ==
nullptr || sampler_name ==
nullptr || edgelen == 0 || values ==
nullptr) {
137 gpu::TextureFormat::SFLOAT_16_16_16,
140 if (lut.texture ==
nullptr) {
147 lut.sampler_name = sampler_name;
149 textures.luts.append(lut);
154 const GpuShaderDescRcPtr &shader_desc)
156 for (
int index = 0;
index < shader_desc->getNumUniforms();
index++) {
157 if (!add_gpu_uniform(textures, shader_desc, index)) {
161 for (
int index = 0;
index < shader_desc->getNumTextures();
index++) {
162 if (!add_gpu_lut_1D2D(textures, shader_desc, index)) {
166 for (
int index = 0;
index < shader_desc->getNum3DTextures();
index++) {
167 if (!add_gpu_lut_3D(textures, shader_desc, index)) {
177void LibOCIOGPUShaderBinder::construct_shader_for_processors(
179 const ConstProcessorRcPtr &processor_to_scene_linear,
180 const ConstProcessorRcPtr &processor_to_display,
181 const Span<std::array<StringRefNull, 2>> additional_defines)
const
183 std::string fragment_source;
185 GpuShaderDescRcPtr shaderdesc_to_scene_linear;
186 if (processor_to_scene_linear) {
187 shaderdesc_to_scene_linear = GpuShaderDesc::CreateShaderDesc();
188 shaderdesc_to_scene_linear->setLanguage(GPU_LANGUAGE_GLSL_1_3);
189 shaderdesc_to_scene_linear->setFunctionName(
"OCIO_to_scene_linear");
190 shaderdesc_to_scene_linear->setResourcePrefix(
"to_scene");
191 processor_to_scene_linear->getDefaultGPUProcessor()->extractGpuShaderInfo(
192 shaderdesc_to_scene_linear);
193 shaderdesc_to_scene_linear->finalize();
195 if (!create_gpu_textures(display_shader.textures, shaderdesc_to_scene_linear)) {
196 display_shader.is_valid =
false;
200 fragment_source += shaderdesc_to_scene_linear->getShaderText();
201 fragment_source +=
"\n";
204 GpuShaderDescRcPtr shaderdesc_to_display;
205 if (processor_to_display) {
206 shaderdesc_to_display = GpuShaderDesc::CreateShaderDesc();
207 shaderdesc_to_display->setLanguage(GPU_LANGUAGE_GLSL_1_3);
208 shaderdesc_to_display->setFunctionName(
"OCIO_to_display");
209 shaderdesc_to_display->setResourcePrefix(
"to_display");
210 processor_to_display->getDefaultGPUProcessor()->extractGpuShaderInfo(shaderdesc_to_display);
211 shaderdesc_to_display->finalize();
213 if (!create_gpu_textures(display_shader.textures, shaderdesc_to_display)) {
214 display_shader.is_valid =
false;
218 fragment_source += shaderdesc_to_display->getShaderText();
219 fragment_source +=
"\n";
223 display_shader.is_valid =
false;
227 display_shader.is_valid =
true;
234 const OCIO_NAMESPACE::ConstConfigRcPtr &ocio_config = config.
get_ocio_config();
236 ConstProcessorRcPtr processor_to_scene_linear = create_to_scene_linear_processor(ocio_config,
238 ConstProcessorRcPtr processor_to_display = create_to_display_processor(config, display_shader);
240 if (!processor_to_scene_linear || !processor_to_display) {
245 construct_shader_for_processors(
246 display_shader, processor_to_scene_linear, processor_to_display, {});
253 const OCIO_NAMESPACE::ConstConfigRcPtr &ocio_config = config.
get_ocio_config();
255 ConstProcessorRcPtr processor_to_scene_linear = create_to_scene_linear_processor(ocio_config,
257 if (!processor_to_scene_linear) {
262 construct_shader_for_processors(
264 processor_to_scene_linear,
266 {{
"USE_TO_SCENE_LINEAR_ONLY",
""}, {
"OUTPUT_PREMULTIPLIED",
""}});
static bool create_gpu_shader(internal::GPUDisplayShader &display_shader, StringRefNull fragment_source, Span< std::array< StringRefNull, 2 > > additional_defines)
const OCIO_NAMESPACE::ConstConfigRcPtr & get_ocio_config() const
void construct_scene_linear_shader(internal::GPUDisplayShader &display_shader) const override
void construct_display_shader(internal::GPUDisplayShader &display_shader) const override
OCIO_NAMESPACE::ConstProcessorRcPtr create_ocio_display_processor(const LibOCIOConfig &config, const DisplayParameters &display_parameters)
OCIO_NAMESPACE::ConstProcessorRcPtr create_ocio_processor(const OCIO_NAMESPACE::ConstConfigRcPtr &ocio_config, const StringRefNull from_colorspace, const StringRefNull to_colorspace)
gpu::Texture * GPU_texture_create_1d(const char *name, int width, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
@ GPU_TEXTURE_USAGE_SHADER_READ
void GPU_texture_filter_mode(gpu::Texture *texture, bool use_filter)
gpu::Texture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
void GPU_texture_extend_mode(gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
std::string format(const std::string &fmt, Args &&...args)
StringRefNull from_colorspace