Loading...
Searching...
No Matches
fullscreenShader.h
1//
2// Copyright 2018 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HDX_FULLSCREENSHADER_H
8#define PXR_IMAGING_HDX_FULLSCREENSHADER_H
9
10#include "pxr/pxr.h"
11
12#include "pxr/imaging/hdx/api.h"
13#include "pxr/imaging/hdx/effectsShader.h"
14
15#include "pxr/imaging/hgi/buffer.h"
16#include "pxr/imaging/hgi/graphicsPipeline.h"
17#include "pxr/imaging/hgi/shaderProgram.h"
18#include "pxr/imaging/hgi/texture.h"
19
20#include "pxr/base/gf/vec4i.h"
21
22#include "pxr/base/tf/token.h"
23
24#include <map>
25#include <vector>
26
27PXR_NAMESPACE_OPEN_SCOPE
28
29class Hgi;
30class HioGlslfx;
31
39{
40public:
44 HDX_API
45 HdxFullscreenShader(Hgi* hgi, const std::string& debugName);
46
48 HDX_API
50
62 HDX_API
64 const TfToken& glslfxPath,
65 const TfToken& shaderName,
66 HgiShaderFunctionDesc& fragDesc);
67
71 HDX_API
73 const HgiShaderFunctionDesc& fragDesc);
74
82 HDX_API
83 void BindBuffers(HgiBufferHandleVector const& buffers);
84
94 HDX_API
96 HgiTextureHandleVector const& textures,
97 HgiSamplerHandleVector const& samplers = HgiSamplerHandleVector());
98
104 HDX_API
106
110 HDX_API
112 bool enableBlending,
113 HgiBlendFactor srcColorBlendFactor,
114 HgiBlendFactor dstColorBlendFactor,
115 HgiBlendOp colorBlendOp,
116 HgiBlendFactor srcAlphaBlendFactor,
117 HgiBlendFactor dstAlphaBlendFactor,
118 HgiBlendOp alphaBlendOp);
119
124 HDX_API
126 GfVec4f clearColor,
127 GfVec4f clearDepth);
128
132 HDX_API
134 uint32_t byteSize,
135 const void* data);
136
139 HDX_API
140 void Draw(HgiTextureHandle const& colorDst,
141 HgiTextureHandle const& depthDst);
142
143 HDX_API
144 void Draw(HgiTextureHandle const& colorDst,
145 HgiTextureHandle const& colorResolveDst,
146 HgiTextureHandle const& depthDst,
147 HgiTextureHandle const& depthResolveDst,
148 GfVec4i const& viewport);
149
150private:
151 HdxFullscreenShader() = delete;
153 HdxFullscreenShader& operator=(const HdxFullscreenShader&) = delete;
154
155 // Utility function to create buffer resources.
156 void _CreateBufferResources();
157
158 // Utility to set resource bindings.
159 void _SetResourceBindings();
160
161 // Utility to create default vertex buffer descriptor.
162 void _SetVertexBufferDescriptor();
163
164 // Utility to create and get the default texture sampler.
165 HgiSamplerHandle _GetDefaultSampler();
166
167 // Utility to set the default program.
168 void _SetDefaultProgram(bool writeDepth);
169
170 // Internal draw method
171 void _Draw(
172 HgiTextureHandle const& colorDst,
173 HgiTextureHandle const& colorResolveDst,
174 HgiTextureHandle const& depthDst,
175 HgiTextureHandle const& depthResolveDst,
176 GfVec4i const &viewport);
177
178 void _RecordDrawCmds() override;
179
180 // Print shader compile errors.
181 void _PrintCompileErrors();
182
183 HgiTextureHandleVector _textures;
184 HgiSamplerHandleVector _samplers;
185 HgiBufferHandleVector _buffers;
186
187 TfToken _glslfxPath;
188 TfToken _shaderName;
189
190 HgiBufferHandle _indexBuffer;
191 HgiBufferHandle _vertexBuffer;
192 HgiShaderProgramHandle _shaderProgram;
193 HgiSamplerHandle _defaultSampler;
194
195 HgiDepthStencilState _depthStencilState;
196
197 HgiAttachmentDesc _colorAttachment;
198 HgiAttachmentDesc _depthAttachment;
199};
200
201PXR_NAMESPACE_CLOSE_SCOPE
202
203#endif // PXR_IMAGING_HDX_FULLSCREENSHADER_H
Basic type for a vector of 4 float components.
Definition: vec4f.h:46
Basic type for a vector of 4 int components.
Definition: vec4i.h:44
This class provides functionality to create and manage a single HgiGraphicsPipeline instance and to i...
Definition: effectsShader.h:45
This class is a utility for rendering deep raytracer or aov output (color/depth) to a hgi texture.
HDX_API void SetBlendState(bool enableBlending, HgiBlendFactor srcColorBlendFactor, HgiBlendFactor dstColorBlendFactor, HgiBlendOp colorBlendOp, HgiBlendFactor srcAlphaBlendFactor, HgiBlendFactor dstAlphaBlendFactor, HgiBlendOp alphaBlendOp)
By default HdxFullscreenShader uses no blending (opaque).
HDX_API void SetProgram(const TfToken &glslfxPath, const TfToken &shaderName, HgiShaderFunctionDesc &fragDesc)
Set the program for the class to use for its fragment shader.
HDX_API void BindTextures(HgiTextureHandleVector const &textures, HgiSamplerHandleVector const &samplers=HgiSamplerHandleVector())
Bind (externally managed) textures to the shader program and use the optionally provided samplers for...
HDX_API void SetDepthState(HgiDepthStencilState const &state)
By default HdxFullscreenShader creates a pipeline object that enables depth testing and enables depth...
HDX_API void SetShaderConstants(uint32_t byteSize, const void *data)
Provide the shader constant values (uniforms).
HDX_API HdxFullscreenShader(Hgi *hgi, const std::string &debugName)
Create a new fullscreen shader object.
HDX_API ~HdxFullscreenShader() override
Destroy the fullscreen shader object, releasing GPU resources.
HDX_API void BindBuffers(HgiBufferHandleVector const &buffers)
Bind (externally managed) buffers to the shader program.
HDX_API void SetProgram(const HgiShaderFunctionDesc &fragDesc)
Bypasses any cache checking or HioGlslfx processing and just re-creates the shader program using the ...
HDX_API void Draw(HgiTextureHandle const &colorDst, HgiTextureHandle const &depthDst)
Draw the internal textures to the provided destination textures.
HDX_API void SetClearState(GfVec4f clearColor, GfVec4f clearDepth)
Ask HdxFullscreenShader to do a color/depth clear.
Hydra Graphics Interface.
Definition: hgi.h:95
A class representing the config and shader source of a glslfx file.
Definition: glslfx.h:134
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Describes the properties of a framebuffer attachment.
Properties to configure depth and stencil test.
Describes the properties needed to create a GPU shader function.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...