-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUsdFrame.cpp
92 lines (78 loc) · 2.01 KB
/
UsdFrame.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
// Copyright 2020 The Khronos Group
// SPDX-License-Identifier: Apache-2.0
#include "UsdFrame.h"
#include "UsdBridge/UsdBridge.h"
#include "UsdAnari.h"
#include "UsdDevice.h"
#include "anari/frontend/type_utility.h"
DEFINE_PARAMETER_MAP(UsdFrame,
REGISTER_PARAMETER_MACRO("size", ANARI_UINT32_VEC2, size)
REGISTER_PARAMETER_MACRO("channel.color", ANARI_DATA_TYPE, color)
REGISTER_PARAMETER_MACRO("channel.depth", ANARI_DATA_TYPE, depth)
)
UsdFrame::UsdFrame(UsdBridge* bridge)
: UsdParameterizedBaseObject<UsdFrame, UsdFrameData>(ANARI_FRAME)
{
}
UsdFrame::~UsdFrame()
{
delete[] mappedColorMem;
delete[] mappedDepthMem;
}
bool UsdFrame::deferCommit(UsdDevice* device)
{
return false;
}
bool UsdFrame::doCommitData(UsdDevice* device)
{
return false;
}
const void* UsdFrame::mapBuffer(const char *channel,
uint32_t *width,
uint32_t *height,
ANARIDataType *pixelType)
{
const UsdFrameData& paramData = getReadParams();
*width = paramData.size.Data[0];
*height = paramData.size.Data[1];
*pixelType = ANARI_UNKNOWN;
if (strEquals(channel, "channel.color"))
{
mappedColorMem = ReserveBuffer(paramData.color);
*pixelType = paramData.color;
return mappedColorMem;
}
else if (strEquals(channel, "channel.depth"))
{
mappedDepthMem = ReserveBuffer(paramData.depth);
*pixelType = paramData.depth;
return mappedDepthMem;
}
*width = 0;
*height = 0;
return nullptr;
}
void UsdFrame::unmapBuffer(const char *channel)
{
if (strEquals(channel, "channel.color"))
{
delete[] mappedColorMem;
mappedColorMem = nullptr;
}
else if (strEquals(channel, "channel.depth"))
{
delete[] mappedDepthMem;
mappedDepthMem = nullptr;
}
}
char* UsdFrame::ReserveBuffer(ANARIDataType format)
{
const UsdFrameData& paramData = getReadParams();
size_t formatSize = anari::sizeOf(format);
size_t memSize = formatSize * paramData.size.Data[0] * paramData.size.Data[1];
return new char[memSize];
}
void UsdFrame::saveUsd(UsdDevice* device)
{
device->getUsdBridge()->SaveScene();
}