All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
colorChannelTask.h
1 //
2 // Copyright 2019 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_COLORCHANNEL_TASK_H
25 #define HDX_COLORCHANNEL_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 
46 class HdxColorChannelTask : public HdTask
47 {
48 public:
49  HDX_API
50  HdxColorChannelTask(HdSceneDelegate* delegate, SdfPath const& id);
51 
52  HDX_API
53  virtual ~HdxColorChannelTask();
54 
56  HDX_API
57  virtual void Sync(HdSceneDelegate* delegate,
58  HdTaskContext* ctx,
59  HdDirtyBits* dirtyBits) override;
60 
62  HDX_API
63  virtual void Prepare(HdTaskContext* ctx,
64  HdRenderIndex* renderIndex) override;
65 
67  HDX_API
68  virtual void Execute(HdTaskContext* ctx) override;
69 
70 private:
71  HdxColorChannelTask() = delete;
72  HdxColorChannelTask(const HdxColorChannelTask &) = delete;
73  HdxColorChannelTask &operator =(const HdxColorChannelTask &) = delete;
74 
75  // Utility function to create the GL program for color channel
76  bool _CreateShaderResources();
77 
78  // Utility function to create buffer resources.
79  bool _CreateBufferResources();
80 
81  // Utility function to setup the copy-framebuffer
82  bool _CreateFramebufferResources();
83 
84  // Copies the client framebuffer texture into ours
85  void _CopyTexture();
86 
88  void _ApplyColorChannel();
89 
90  // Get an integer that represents the color channel. This can be used to
91  // pass the color channel option as a uniform uint argument of the glsl
92  // shader (see the `#define CHANNEL_*` lines in the shader).
93  // If _channel contains an invalid entry this will return 'color'.
94  GLint _GetChannelAsGLint();
95 
96  HdStGLSLProgramSharedPtr _shaderProgram;
97  GLuint _texture;
98  GfVec2i _textureSize;
99  GLint _locations[5];
100  GLuint _vertexBuffer;
101 
102  // XXX: Removed due to slowness in the IsCurrent() call when multiple
103  // gl contexts are registered in GlfGLContextRegistry.
104  // GlfGLContextSharedPtr _owningContext;
105 
106  GLuint _copyFramebuffer;
107  GfVec2i _framebufferSize;
108 
109  // The color channel to be rendered (see HdxColorChannelTokens for the
110  // possible values).
111  TfToken _channel;
112 };
113 
114 
120 {
122 
123  // Resolution of bound framebuffer we are color correcting.
124  // This must be set if the viewport and framebuffer do not match.
125  GfVec2i framebufferSize = GfVec2i(0);
126 
127  // Specifies which output color channel should be drawn. Defaults to 'color'
128  // (untouched RGBA).
129  TfToken channel = HdxColorChannelTokens->color;
130 };
131 
132 // VtValue requirements
133 HDX_API
134 std::ostream& operator<<(std::ostream& out, const HdxColorChannelTaskParams& pv);
135 HDX_API
136 bool operator==(const HdxColorChannelTaskParams& lhs,
137  const HdxColorChannelTaskParams& rhs);
138 HDX_API
139 bool operator!=(const HdxColorChannelTaskParams& lhs,
140  const HdxColorChannelTaskParams& rhs);
141 
142 
143 PXR_NAMESPACE_CLOSE_SCOPE
144 
145 #endif
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:117
ColorChannelTask parameters.
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
virtual HDX_API void Execute(HdTaskContext *ctx) override
Execute the color channel task.
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
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Adapter class providing data exchange with the client scene graph.
virtual HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
A task for choosing a color channel for display.
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.