-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhowTo07_UseIncludeExclude.cpp
More file actions
169 lines (122 loc) · 5.42 KB
/
Copy pathhowTo07_UseIncludeExclude.cpp
File metadata and controls
169 lines (122 loc) · 5.42 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright 2025 Autodesk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifdef __APPLE__
#include "TargetConditionals.h"
#endif
#include <pxr/pxr.h>
PXR_NAMESPACE_USING_DIRECTIVE
#include <RenderingFramework/TestContextCreator.h>
#include <hvt/engine/viewportEngine.h>
#include <gtest/gtest.h>
#include <RenderingFramework/TestFlags.h>
//
// Include or exclude geometry prims on the fly?
//
namespace
{
// The default path for the grid.
const SdfPath gridPath("/gizmos/grid");
} // anonymous namespace.
// The method creates a single frame pass and executes it.
void CreateTest(const std::shared_ptr<TestHelpers::TestContext>& context,
TestHelpers::TestStage& stage, const HdRprimCollection& collection)
{
hvt::RenderIndexProxyPtr renderIndex;
hvt::FramePassPtr sceneFramePass;
// Defines the main frame pass i.e., the one containing the scene to display.
{
// Creates the render index by providing the hgi driver and the requested renderer name.
hvt::RendererDescriptor renderDesc;
renderDesc.hgiDriver = &context->_backend->hgiDriver();
renderDesc.rendererName = "HdStormRendererPlugin";
hvt::ViewportEngine::CreateRenderer(renderIndex, renderDesc);
// Adds another model to the current stage.
hvt::ViewportEngine::CreateGrid(stage.stage(), gridPath, GfVec3d(0.0, 0.0, 0.0), true);
// Creates the scene index containing the model.
HdSceneIndexBaseRefPtr sceneIndex = hvt::ViewportEngine::CreateUSDSceneIndex(stage.stage());
renderIndex->RenderIndex()->InsertSceneIndex(sceneIndex, SdfPath::AbsoluteRootPath());
// Creates the frame pass instance.
hvt::FramePassDescriptor passDesc;
passDesc.renderIndex = renderIndex->RenderIndex();
passDesc.uid = SdfPath("/sceneFramePass");
sceneFramePass = hvt::ViewportEngine::CreateFramePass(passDesc);
}
// Renders 10 times (i.e., arbitrary number to guarantee best result).
int frameCount = 10;
auto render = [&]() {
// Updates the main frame pass.
auto& params = sceneFramePass->params();
params.renderBufferSize = GfVec2i(context->width(), context->height());
params.viewInfo.framing =
hvt::ViewParams::GetDefaultFraming(context->width(), context->height());
params.viewInfo.viewMatrix = stage.viewMatrix();
params.viewInfo.projectionMatrix = stage.projectionMatrix();
params.viewInfo.lights = stage.defaultLights();
params.viewInfo.material = stage.defaultMaterial();
params.viewInfo.ambient = stage.defaultAmbient();
params.colorspace = HdxColorCorrectionTokens->sRGB;
params.backgroundColor = TestHelpers::ColorDarkGrey;
params.selectionColor = TestHelpers::ColorYellow;
params.enablePresentation = context->presentationEnabled();
// Selects what prims to render.
params.collection = collection;
// Renders.
sceneFramePass->Render();
return --frameCount > 0;
};
// Runs the render loop (i.e., that's backend specific).
context->run(render, sceneFramePass.get());
}
// FIXME: It's sometime failed to render on iOS.Refer to OGSMOD-6933.
// Need to investigate if Android has similar issue too
#if defined(__ANDROID__) || (TARGET_OS_IPHONE == 1)
HVT_TEST(howTo, DISABLED_useCollectionToExclude)
#else
HVT_TEST(howTo, useCollectionToExclude)
#endif
{
// Helper to create the Hgi implementation.
auto context = TestHelpers::CreateTestContext();
TestHelpers::TestStage stage(context->_backend);
ASSERT_TRUE(stage.open(context->_sceneFilepath));
// Executes the test.
// Only excludes geometry prims from the grid i.e., selects everything else.
HdRprimCollection collection { hvt::FramePassParams().collection };
collection.SetExcludePaths({ gridPath });
// Creates and runs the test.
CreateTest(context, stage, collection);
// Validates the rendering result.
ASSERT_TRUE(context->validateImages(computedImageName, imageFile));
}
// FIXME: It's sometime failed to render on iOS.Refer to OGSMOD-6933.
// Need to investigate if Android has similar issue too
#if defined(__ANDROID__) || (TARGET_OS_IPHONE == 1)
HVT_TEST(howTo, DISABLED_useCollectionToInclude)
#else
HVT_TEST(howTo, useCollectionToInclude)
#endif
{
// Helper to create the Hgi implementation.
auto context = TestHelpers::CreateTestContext();
TestHelpers::TestStage stage(context->_backend);
ASSERT_TRUE(stage.open(context->_sceneFilepath));
// Executes the test.
// Only includes the geometry prims from the grid i.e., nothing else.
HdRprimCollection collection { hvt::FramePassParams().collection };
collection.SetRootPath(gridPath);
// Creates and runs the test.
CreateTest(context, stage, collection);
// Validates the rendering result.
ASSERT_TRUE(context->validateImages(computedImageName, imageFile));
}