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
102 HDX_API
104
107 HDX_API
109 bool enableBlending,
110 HgiBlendFactor srcColorBlendFactor,
111 HgiBlendFactor dstColorBlendFactor,
112 HgiBlendOp colorBlendOp,
113 HgiBlendFactor srcAlphaBlendFactor,
114 HgiBlendFactor dstAlphaBlendFactor,
115 HgiBlendOp alphaBlendOp);
116
119 HDX_API
121 HgiAttachmentLoadOp attachmentLoadOp,
122 HgiAttachmentStoreOp attachmentStoreOp);
123
127 HDX_API
129 uint32_t byteSize,
130 const void* data);
131
134 HDX_API
135 void Draw(HgiTextureHandle const& colorDst,
136 HgiTextureHandle const& depthDst);
137
138 HDX_API
139 void Draw(HgiTextureHandle const& colorDst,
140 HgiTextureHandle const& colorResolveDst,
141 HgiTextureHandle const& depthDst,
142 HgiTextureHandle const& depthResolveDst,
143 GfVec4i const& viewport);
144
145private:
146 HdxFullscreenShader() = delete;
148 HdxFullscreenShader& operator=(const HdxFullscreenShader&) = delete;
149
150 // Utility function to create buffer resources.
151 void _CreateBufferResources();
152
153 // Utility to set resource bindings.
154 void _SetResourceBindings();
155
156 // Utility to create default vertex buffer descriptor.
157 void _SetVertexBufferDescriptor();
158
159 // Utility to create and get the default texture sampler.
160 HgiSamplerHandle _GetDefaultSampler();
161
162 // Utility to set the default program.
163 void _SetDefaultProgram(bool writeDepth);
164
165 // Internal draw method
166 void _Draw(
167 HgiTextureHandle const& colorDst,
168 HgiTextureHandle const& colorResolveDst,
169 HgiTextureHandle const& depthDst,
170 HgiTextureHandle const& depthResolveDst,
171 GfVec4i const &viewport);
172
173 void _RecordDrawCmds() override;
174
175 // Print shader compile errors.
176 void _PrintCompileErrors();
177
178 HgiTextureHandleVector _textures;
179 HgiSamplerHandleVector _samplers;
180 HgiBufferHandleVector _buffers;
181
182 TfToken _glslfxPath;
183 TfToken _shaderName;
184
185 HgiBufferHandle _indexBuffer;
186 HgiBufferHandle _vertexBuffer;
187 HgiShaderProgramHandle _shaderProgram;
188 HgiSamplerHandle _defaultSampler;
189
190 HgiDepthStencilState _depthStencilState;
191
192 HgiAttachmentDesc _colorAttachment;
193 HgiAttachmentDesc _depthAttachment;
194};
195
196PXR_NAMESPACE_CLOSE_SCOPE
197
198#endif // PXR_IMAGING_HDX_FULLSCREENSHADER_H
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 SetAttachmentLoadStoreOp(HgiAttachmentLoadOp attachmentLoadOp, HgiAttachmentStoreOp attachmentStoreOp)
By default HdxFullscreenShader uses LoadOpDontCare and StoreOpStore.
Hydra Graphics Interface.
Definition: hgi.h:94
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...