All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
colorCorrectionTask.h
1 //
2 // Copyright 2018 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef HDX_COLORCORRECTION_TASK_H
25 #define HDX_COLORCORRECTION_TASK_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/sdf/path.h"
29 #include "pxr/imaging/hdx/api.h"
30 #include "pxr/imaging/hd/task.h"
31 #include "pxr/imaging/hdx/tokens.h"
32 #include "pxr/imaging/garch/gl.h"
33 #include <string>
34 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
37 class HdStGLSLProgram;
38 typedef boost::shared_ptr<class HdStGLSLProgram> HdStGLSLProgramSharedPtr;
39 typedef boost::shared_ptr<class GlfGLContext> GlfGLContextSharedPtr;
40 
41 
47 class HdxColorCorrectionTask : public HdTask
48 {
49 public:
50  HDX_API
51  HdxColorCorrectionTask(HdSceneDelegate* delegate, SdfPath const& id);
52 
53  HDX_API
54  virtual ~HdxColorCorrectionTask();
55 
57  HDX_API
58  virtual void Sync(HdSceneDelegate* delegate,
59  HdTaskContext* ctx,
60  HdDirtyBits* dirtyBits) override;
61 
63  HDX_API
64  virtual void Prepare(HdTaskContext* ctx,
65  HdRenderIndex* renderIndex) override;
66 
68  HDX_API
69  virtual void Execute(HdTaskContext* ctx) override;
70 
71 private:
72  HdxColorCorrectionTask() = delete;
73  HdxColorCorrectionTask(const HdxColorCorrectionTask &) = delete;
74  HdxColorCorrectionTask &operator =(const HdxColorCorrectionTask &) = delete;
75 
76  // Utility to create OCIO resources and returns the OCIO shadercode
77  std::string _CreateOpenColorIOResources();
78 
79  // Utility function to create the GL program for color correction
80  bool _CreateShaderResources();
81 
82  // Utility function to create buffer resources.
83  bool _CreateBufferResources();
84 
85  // Utility function to setup the copy-framebuffer
86  bool _CreateFramebufferResources();
87 
88  // Copies the client framebuffer texture into ours
89  void _CopyTexture();
90 
91  // Extracts the HgiTexture from the AOV
92  class HgiGLTexture* _GetAovHgiGLTexture();
93 
95  void _ApplyColorCorrection();
96 
97  HdStGLSLProgramSharedPtr _shaderProgram;
98  GLuint _texture;
99  GLuint _texture3dLUT;
100  GfVec2i _textureSize;
101  GLint _locations[4];
102  GLuint _vertexBuffer;
103 
104  GlfGLContextSharedPtr _owningContext;
105  GLuint _copyFramebuffer;
106  GfVec2i _framebufferSize;
107 
108  TfToken _colorCorrectionMode;
109  std::string _displayOCIO;
110  std::string _viewOCIO;
111  std::string _colorspaceOCIO;
112  std::string _looksOCIO;
113  int _lut3dSizeOCIO;
114 
115  TfToken _aovName;
116  SdfPath _aovBufferPath;
117  HdRenderBuffer* _aovBuffer;
118  class HgiGLTexture* _aovTexture;
119  GLuint _aovFramebuffer;
120 };
121 
122 
128 {
130 
131  // Resolution of bound framebuffer we are color correcting.
132  // This must be set if the viewport and framebuffer do not match.
133  GfVec2i framebufferSize = GfVec2i(0);
134 
135  // Switch between HdColorCorrectionTokens.
136  // We default to 'disabled' to be backwards compatible with clients that are
137  // still running with sRGB buffers.
138  TfToken colorCorrectionMode = HdxColorCorrectionTokens->disabled;
139 
140  // 'display', 'view', 'colorspace' and 'look' are options the client may
141  // supply to configure OCIO. If one is not provided the default values
142  // is substituted. You can find the values for these strings inside the
143  // profile/config .ocio file. For example:
144  //
145  // displays:
146  // rec709g22:
147  // !<View> {name: studio, colorspace: linear, looks: studio_65_lg2}
148  //
149  std::string displayOCIO;
150  std::string viewOCIO;
151  std::string colorspaceOCIO;
152  std::string looksOCIO;
153 
154  // The width, height and depth used for the GPU LUT 3d texture
155  // 0-64 (65) is the current pxr default
156  int lut3dSizeOCIO = 65;
157 
158  // When no AOV is provided ColorCorrection will operate on the default FB
159  // color attachment.
160  TfToken aovName;
161  SdfPath aovBufferPath;
162 };
163 
164 // VtValue requirements
165 HDX_API
166 std::ostream& operator<<(std::ostream& out, const HdxColorCorrectionTaskParams& pv);
167 HDX_API
169  const HdxColorCorrectionTaskParams& rhs);
170 HDX_API
172  const HdxColorCorrectionTaskParams& rhs);
173 
174 
175 PXR_NAMESPACE_CLOSE_SCOPE
176 
177 #endif
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:119
A task for performing color correction (and optionally color grading) on a color buffer to transform ...
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
An instance of a glsl program.
Definition: glslProgram.h:44
virtual HDX_API void Execute(HdTaskContext *ctx) override
Execute the color correction task.
ColorCorrectionTask parameters.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
virtual HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.
Adapter class providing data exchange with the client scene graph.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
virtual HDX_API void Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.
Represents a OpenGL GPU texture resource.
Definition: texture.h:38
A render buffer is a handle to a data resource that can be rendered into, such as a 2d image for a dr...
Definition: renderBuffer.h:48