HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
graphicsCmds.h
Go to the documentation of this file.
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 PXR_IMAGING_HGI_GRAPHICS_CMDS_H
25 #define PXR_IMAGING_HGI_GRAPHICS_CMDS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/gf/vec4i.h"
29 #include "pxr/imaging/hgi/api.h"
33 #include "pxr/imaging/hgi/cmds.h"
34 #include <memory>
35 
37 
38 using HgiGraphicsCmdsUniquePtr = std::unique_ptr<class HgiGraphicsCmds>;
39 
40 
41 /// \class HgiGraphicsCmds
42 ///
43 /// A graphics API independent abstraction of graphics commands.
44 /// HgiGraphicsCmds is a lightweight object that cannot be re-used after it has
45 /// been submitted. A new cmds object should be acquired for each frame.
46 ///
47 class HgiGraphicsCmds : public HgiCmds
48 {
49 public:
50  HGI_API
51  ~HgiGraphicsCmds() override;
52 
53  /// Push a debug marker.
54  HGI_API
55  virtual void PushDebugGroup(const char* label) = 0;
56 
57  /// Pop the last debug marker.
58  HGI_API
59  virtual void PopDebugGroup() = 0;
60 
61  /// Set viewport [left, BOTTOM, width, height] - OpenGL coords
62  HGI_API
63  virtual void SetViewport(GfVec4i const& vp) = 0;
64 
65  /// Only pixels that lie within the scissor box are modified by
66  /// drawing commands.
67  HGI_API
68  virtual void SetScissor(GfVec4i const& sc) = 0;
69 
70  /// Bind a pipeline state object. Usually you call this right after calling
71  /// CreateGraphicsCmds to set the graphics pipeline state.
72  /// The resource bindings used when creating the pipeline must be compatible
73  /// with the resources bound via BindResources().
74  HGI_API
75  virtual void BindPipeline(HgiGraphicsPipelineHandle pipeline) = 0;
76 
77  /// Bind resources such as textures and uniform buffers.
78  /// Usually you call this right after BindPipeline() and the resources bound
79  /// must be compatible with the bound pipeline.
80  HGI_API
81  virtual void BindResources(HgiResourceBindingsHandle resources) = 0;
82 
83  /// Set Push / Function constants.
84  /// `pipeline` is the pipeline that you are binding before the draw call. It
85  /// contains the program used for the uniform buffer
86  /// `stages` describes for what shader stage you are setting the push
87  /// constant values for. Each stage can have its own (or none) binding
88  /// and they must match what is described in the shader functions.
89  /// `byteSize` is the size of the data you are updating.
90  /// `data` is the data you are copying into the push constants block.
91  HGI_API
92  virtual void SetConstantValues(
95  uint32_t bindIndex,
96  uint32_t byteSize,
97  const void* data) = 0;
98 
99  /// Binds the vertex buffer(s) that describe the vertex attributes.
100  /// `firstBinding` the first index to which buffers are bound (usually 0).
101  /// `byteOffsets` offset to where the data of each buffer starts, in bytes.
102  /// `strides` the size of a vertex in each of the buffers.
103  HGI_API
104  virtual void BindVertexBuffers(
105  uint32_t firstBinding,
107  std::vector<uint32_t> const& byteOffsets) = 0;
108 
109  /// Records a draw command that renders one or more instances of primitives
110  /// using an indexBuffer starting from the base vertex of the base instance.
111  /// `indexCount` is the number of vertices.
112  /// `indexBufferByteOffset`: Byte offset within indexBuffer to start reading
113  /// indices from.
114  /// `vertexOffset`: the value added to the vertex index before indexing into
115  /// the vertex buffer (baseVertex).
116  /// `instanceCount`: number of instances (min 1) of the primitves to render.
117  HGI_API
118  virtual void DrawIndexed(
119  HgiBufferHandle const& indexBuffer,
120  uint32_t indexCount,
121  uint32_t indexBufferByteOffset,
122  uint32_t firstIndex,
123  uint32_t vertexOffset,
124  uint32_t instanceCount) = 0;
125 
126 protected:
127  HGI_API
128  HgiGraphicsCmds();
129 
130 private:
131  HgiGraphicsCmds & operator=(const HgiGraphicsCmds&) = delete;
132  HgiGraphicsCmds(const HgiGraphicsCmds&) = delete;
133 };
134 
135 
136 
138 
139 #endif
Definition: vec4i.h:61
virtual HGI_API void SetScissor(GfVec4i const &sc)=0
virtual HGI_API void BindResources(HgiResourceBindingsHandle resources)=0
virtual HGI_API void PopDebugGroup()=0
Pop the last debug marker.
virtual HGI_API void BindVertexBuffers(uint32_t firstBinding, HgiBufferHandleVector const &buffers, std::vector< uint32_t > const &byteOffsets)=0
virtual HGI_API void PushDebugGroup(const char *label)=0
Push a debug marker.
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
const GLuint * buffers
Definition: glew.h:1683
std::vector< HgiBufferHandle > HgiBufferHandleVector
Definition: buffer.h:142
GLuint GLsizei GLsizei GLchar * label
Definition: glew.h:8986
virtual HGI_API void DrawIndexed(HgiBufferHandle const &indexBuffer, uint32_t indexCount, uint32_t indexBufferByteOffset, uint32_t firstIndex, uint32_t vertexOffset, uint32_t instanceCount)=0
HGI_API HgiGraphicsCmds()
#define HGI_API
Definition: api.h:40
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HgiBits HgiShaderStage
Definition: enums.h:278
std::unique_ptr< class HgiGraphicsCmds > HgiGraphicsCmdsUniquePtr
Definition: graphicsCmds.h:38
virtual HGI_API void SetConstantValues(HgiGraphicsPipelineHandle pipeline, HgiShaderStage stages, uint32_t bindIndex, uint32_t byteSize, const void *data)=0
virtual HGI_API void BindPipeline(HgiGraphicsPipelineHandle pipeline)=0
Definition: cmds.h:43
HGI_API ~HgiGraphicsCmds() override
GLbitfield stages
Definition: glew.h:5939
virtual HGI_API void SetViewport(GfVec4i const &vp)=0
Set viewport [left, BOTTOM, width, height] - OpenGL coords.