forked from wetadigital/USDPluginExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderBuffer.cpp
131 lines (109 loc) · 2.33 KB
/
renderBuffer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// Copyright © 2023 Weta Digital Limited
//
// SPDX-License-Identifier: Apache-2.0
//
#include "renderBuffer.h"
#include "debugCodes.h"
PXR_NAMESPACE_OPEN_SCOPE
HdTriRenderBuffer::HdTriRenderBuffer(const SdfPath& bprimId)
: HdRenderBuffer(bprimId)
{
}
bool
HdTriRenderBuffer::Allocate(const GfVec3i& dimensions,
HdFormat format,
bool multiSampled)
{
TF_DEBUG(HDTRI_GENERAL)
.Msg("[%s] Allocate render buffer id=%s, dimensions=(%i, %i, %i), "
"format=%i\n",
TF_FUNC_NAME().c_str(),
GetId().GetText(),
dimensions[0],
dimensions[1],
dimensions[2],
format);
_Deallocate();
// 2D buffer for now!
TF_VERIFY(dimensions[2] == 1);
_dimensions = dimensions;
_format = format;
_buffer.resize(_dimensions[0] * _dimensions[1] * _dimensions[2] *
HdDataSizeOfFormat(format));
TF_DEBUG(HDTRI_GENERAL)
.Msg("[%s] Render buffer id=%s, size=%lu\n",
TF_FUNC_NAME().c_str(),
GetId().GetText(),
_buffer.size());
return true;
}
unsigned int
HdTriRenderBuffer::GetWidth() const
{
return _dimensions[0];
}
unsigned int
HdTriRenderBuffer::GetHeight() const
{
return _dimensions[1];
}
unsigned int
HdTriRenderBuffer::GetDepth() const
{
return _dimensions[2];
}
HdFormat
HdTriRenderBuffer::GetFormat() const
{
return _format;
}
bool
HdTriRenderBuffer::IsMultiSampled() const
{
return false;
}
void*
HdTriRenderBuffer::Map()
{
_mappers.fetch_add(1);
return static_cast<void*>(_buffer.data());
}
void
HdTriRenderBuffer::Unmap()
{
_mappers.fetch_sub(1);
}
bool
HdTriRenderBuffer::IsMapped() const
{
return _mappers.load() > 0;
}
bool
HdTriRenderBuffer::IsConverged() const
{
return _converged.load();
}
void
HdTriRenderBuffer::SetConverged(bool converged)
{
_converged.store(converged);
}
void
HdTriRenderBuffer::Resolve()
{
// Nothing to do, there is only a single internal buffer for read/write.
return;
}
void
HdTriRenderBuffer::_Deallocate()
{
TF_VERIFY(!IsMapped());
// Reset to default/empty values.
_dimensions = GfVec3i(0, 0, 0);
_format = HdFormatInvalid;
_buffer.resize(0);
_mappers.store(0);
_converged.store(false);
}
PXR_NAMESPACE_CLOSE_SCOPE