HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
glUtils.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_HD_ST_GL_UTILS_H
25 #define PXR_IMAGING_HD_ST_GL_UTILS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hd/types.h"
30 #include "pxr/imaging/hgi/buffer.h"
31 
32 #include "pxr/base/vt/value.h"
33 
35 
36 class HdStGLUtils {
37 public:
38 
39  /// Reads the content of VBO back to VtArray.
40  /// The \p vboOffset is expressed in bytes.
41  HDST_API
42  static VtValue ReadBuffer(uint64_t vbo,
43  HdTupleType tupleType,
44  int vboOffset,
45  int stride,
46  int numElements);
47 };
48 
49 /// \class HdStBufferRelocator
50 ///
51 /// A utility class to perform batched buffer copy.
52 ///
54 public:
56  HgiBufferHandle const& srcBuffer, HgiBufferHandle const& dstBuffer) :
57  _srcBuffer(srcBuffer), _dstBuffer(dstBuffer) {}
58 
59  /// Schedule the range to be copied. The consecutive ranges could be
60  /// aggregated into a single copy where possible.
61  HDST_API
62  void AddRange(ptrdiff_t readOffset,
63  ptrdiff_t writeOffset,
64  ptrdiff_t copySize);
65 
66  /// Execute Hgi buffer copy command to flush all scheduled range copies.
67  HDST_API
68  void Commit(class HgiBlitCmds* blitCmds);
69 
70 private:
71  struct _CopyUnit {
72  _CopyUnit(ptrdiff_t read, ptrdiff_t write, ptrdiff_t size)
73  : readOffset(read), writeOffset(write), copySize(size) {}
74 
75  bool Concat(_CopyUnit const &next) {
76  if (readOffset + copySize == next.readOffset &&
77  writeOffset + copySize == next.writeOffset) {
78  copySize += next.copySize;
79  return true;
80  }
81  return false;
82  }
83 
84  ptrdiff_t readOffset;
85  ptrdiff_t writeOffset;
86  ptrdiff_t copySize;
87  };
88 
89  std::vector<_CopyUnit> _queue;
90  HgiBufferHandle _srcBuffer;
91  HgiBufferHandle _dstBuffer;
92 };
93 
94 
96 
97 #endif // PXR_IMAGING_HD_ST_GL_UTILS_H
HDST_API void AddRange(ptrdiff_t readOffset, ptrdiff_t writeOffset, ptrdiff_t copySize)
void read(T &in, bool &v)
Definition: ImfXdr.h:611
GLenum GLintptr readOffset
Definition: glcorearb.h:1460
GLsizeiptr size
Definition: glcorearb.h:663
HDST_API void Commit(class HgiBlitCmds *blitCmds)
Execute Hgi buffer copy command to flush all scheduled range copies.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
#define HDST_API
Definition: api.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
static HDST_API VtValue ReadBuffer(uint64_t vbo, HdTupleType tupleType, int vboOffset, int stride, int numElements)
GLenum GLintptr GLintptr writeOffset
Definition: glcorearb.h:1460
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:871
void write(T &out, bool v)
Definition: ImfXdr.h:332
Definition: value.h:168
HdStBufferRelocator(HgiBufferHandle const &srcBuffer, HgiBufferHandle const &dstBuffer)
Definition: glUtils.h:55