Loading...
Searching...
No Matches
fullscreenShader.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 PXR_IMAGING_HDX_FULLSCREENSHADER_H
25#define PXR_IMAGING_HDX_FULLSCREENSHADER_H
26
27#include "pxr/pxr.h"
28
29#include "pxr/imaging/hdx/api.h"
30#include "pxr/imaging/hdx/effectsShader.h"
31
32#include "pxr/imaging/hgi/buffer.h"
33#include "pxr/imaging/hgi/graphicsPipeline.h"
34#include "pxr/imaging/hgi/shaderProgram.h"
35#include "pxr/imaging/hgi/texture.h"
36
37#include "pxr/base/gf/vec4i.h"
38
39#include "pxr/base/tf/token.h"
40
41#include <map>
42#include <vector>
43
44PXR_NAMESPACE_OPEN_SCOPE
45
46class Hgi;
47class HioGlslfx;
48
56{
57public:
61 HDX_API
62 HdxFullscreenShader(Hgi* hgi, const std::string& debugName);
63
65 HDX_API
67
79 HDX_API
81 const TfToken& glslfxPath,
82 const TfToken& shaderName,
83 HgiShaderFunctionDesc& fragDesc);
84
88 HDX_API
90 const HgiShaderFunctionDesc& fragDesc);
91
99 HDX_API
100 void BindBuffers(HgiBufferHandleVector const& buffers);
101
108 HDX_API
110 HgiTextureHandleVector const& textures);
111
115 HDX_API
117
120 HDX_API
122 bool enableBlending,
123 HgiBlendFactor srcColorBlendFactor,
124 HgiBlendFactor dstColorBlendFactor,
125 HgiBlendOp colorBlendOp,
126 HgiBlendFactor srcAlphaBlendFactor,
127 HgiBlendFactor dstAlphaBlendFactor,
128 HgiBlendOp alphaBlendOp);
129
132 HDX_API
134 HgiAttachmentLoadOp attachmentLoadOp,
135 HgiAttachmentStoreOp attachmentStoreOp);
136
140 HDX_API
142 uint32_t byteSize,
143 const void* data);
144
147 HDX_API
148 void Draw(HgiTextureHandle const& colorDst,
149 HgiTextureHandle const& depthDst);
150
151 HDX_API
152 void Draw(HgiTextureHandle const& colorDst,
153 HgiTextureHandle const& colorResolveDst,
154 HgiTextureHandle const& depthDst,
155 HgiTextureHandle const& depthResolveDst,
156 GfVec4i const& viewport);
157
158private:
159 HdxFullscreenShader() = delete;
161 HdxFullscreenShader& operator=(const HdxFullscreenShader&) = delete;
162
163 // Utility function to create buffer resources.
164 void _CreateBufferResources();
165
166 // Utility to set resource bindings.
167 void _SetResourceBindings();
168
169 // Utility to create default vertex buffer descriptor.
170 void _SetVertexBufferDescriptor();
171
172 // Utility to create a texture sampler.
173 bool _CreateSampler();
174
175 // Utility to set the default program.
176 void _SetDefaultProgram(bool writeDepth);
177
178 // Internal draw method
179 void _Draw(
180 HgiTextureHandle const& colorDst,
181 HgiTextureHandle const& colorResolveDst,
182 HgiTextureHandle const& depthDst,
183 HgiTextureHandle const& depthResolveDst,
184 GfVec4i const &viewport);
185
186 void _RecordDrawCmds() override;
187
188 // Print shader compile errors.
189 void _PrintCompileErrors();
190
191 HgiTextureHandleVector _textures;
192 HgiBufferHandleVector _buffers;
193
194 TfToken _glslfxPath;
195 TfToken _shaderName;
196
197 HgiBufferHandle _indexBuffer;
198 HgiBufferHandle _vertexBuffer;
199 HgiShaderProgramHandle _shaderProgram;
200 HgiSamplerHandle _sampler;
201
202 HgiDepthStencilState _depthStencilState;
203
204 HgiAttachmentDesc _colorAttachment;
205 HgiAttachmentDesc _depthAttachment;
206};
207
208PXR_NAMESPACE_CLOSE_SCOPE
209
210#endif // PXR_IMAGING_HDX_FULLSCREENSHADER_H
Basic type for a vector of 4 int components.
Definition: vec4i.h:61
This class provides functionality to create and manage a single HgiGraphicsPipeline instance and to i...
Definition: effectsShader.h:62
This class is a utility for rendering deep raytracer or aov output (color/depth) to a hgi texture.
HDX_API void BindTextures(HgiTextureHandleVector const &textures)
Bind (externally managed) textures to the shader program.
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 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:111
A class representing the config and shader source of a glslfx file.
Definition: glslfx.h:151
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
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...