载入中...
搜索中...
未找到
GraphicsPrimitives.cpp
浏览该文件的文档.
6
7namespace eve::graphics::vulkan {
8
10 ASSERT(initialized);
11 if (!initialized) throw Exception("drawPrimitiveScene: graphics not initialized");
12 const bool offscreen = offscreen3DPassOpen;
13 if (!offscreen && gpuDrivenScenePassPending_) gpuDrivenOpenScenePass();
14 if (!offscreen && !swapchainPassOpen) throw Exception("drawPrimitiveScene: call begin3DFrame first");
15
17 if (resolved.vertices.empty()) return;
18
19 struct DrawGroup {
21 std::size_t sequence = 0;
22 float averageDepth = 0.f;
23 std::size_t firstVertex = 0;
24 std::size_t vertexCount = 0;
25 };
26 std::vector<DrawGroup> groups;
27 groups.reserve(resolved.batches3D.size());
28 for (const ResolvedPrimitiveBatch3D &batch : resolved.batches3D) {
29 DrawGroup group;
30 group.paint = batch.paint;
31 group.sequence = batch.sequence;
32 group.averageDepth = batch.averageDepth;
33 group.firstVertex = batch.firstVertex;
34 group.vertexCount = batch.vertexCount;
35 groups.push_back(std::move(group));
36 }
37 std::stable_sort(groups.begin(), groups.end(), [&](const DrawGroup &a, const DrawGroup &b) {
38 const ScenePrimitivePaint &paintA = a.paint;
39 const ScenePrimitivePaint &paintB = b.paint;
40 const bool ignoreA = paintA.depth == PrimitiveDepthMode::Ignore;
41 const bool ignoreB = paintB.depth == PrimitiveDepthMode::Ignore;
42 if (ignoreA != ignoreB) return !ignoreA;
43 if (paintA.layer != paintB.layer) return paintA.layer < paintB.layer;
44 const bool transparentA = paintA.blend != BlendMode::Opaque || paintA.color.a < 1.f;
45 const bool transparentB = paintB.blend != BlendMode::Opaque || paintB.color.a < 1.f;
46 if (transparentA != transparentB) return !transparentA;
47 if (transparentA && a.averageDepth != b.averageDepth) return a.averageDepth > b.averageDepth;
48 return a.sequence < b.sequence;
49 });
50
51 auto &buffers = offscreen ? offscreenPrimitive3DBufs : currentFrame2DBuffers().primitive3DBufs;
52 auto &drawIndex = offscreen ? offscreenPrimitive3DDrawIndex : currentFrame2DBuffers().primitive3DDrawIndex;
53 if (drawIndex == buffers.size()) buffers.emplace_back();
54 // Earlier submissions still reference their buffers until this frame's fence.
55 auto &buffer = buffers[drawIndex++];
56 const vk::CommandBuffer cb = offscreen ? offscreen3DCB : currentPresentCb();
57 const uint32_t targetWidth =
58 offscreen ? static_cast<uint32_t>(offscreen3DCanvas->getWidth()) : swapchain.extent.width;
59 const uint32_t targetHeight =
60 offscreen ? static_cast<uint32_t>(offscreen3DCanvas->getHeight()) : swapchain.extent.height;
61 auto &pipelines = offscreen
62 ? (offscreen3DHDRActive ? hdrOffscreenPrimitive3DPipelines : offscreenPrimitive3DPipelines)
63 : primitive3DPipelines;
64 setViewportAndScissor(cb, targetWidth, targetHeight);
65 std::vector<Primitive3DVertex> vertices;
66 vertices.reserve(resolved.vertices.size());
67 for (const DrawGroup &group : groups) {
68 for (std::size_t vertex = group.firstVertex; vertex < group.firstVertex + group.vertexCount; ++vertex)
69 vertices.push_back({resolved.vertices[vertex].clipPosition, resolved.vertices[vertex].color});
70 }
71 buffer.allocate<Primitive3DVertex>(frameToken(), device, vertices);
72 const vk::DeviceSize offset = 0;
73 cb.bindVertexBuffers(0, 1, buffer, &offset);
74 std::uint32_t firstVertex = 0;
75 for (std::size_t groupIndex = 0; groupIndex < groups.size(); ++groupIndex) {
76 const DrawGroup &group = groups[groupIndex];
77 const ScenePrimitivePaint &paint = group.paint;
78 const std::size_t pipelineIndex = primitive3DPipelineIndex(paint.depth, paint.blend, paint.cull);
79 const vk::Pipeline primitivePipeline = pipelines[pipelineIndex];
80 if (!primitivePipeline) throw Exception("drawPrimitiveScene: primitive pipeline unavailable");
81 cb.bindPipeline(vk::PipelineBindPoint::eGraphics, primitivePipeline);
82 cb.draw(static_cast<uint32_t>(group.vertexCount), 1, firstVertex, 0);
83 firstVertex += static_cast<std::uint32_t>(group.vertexCount);
84 }
85}
86
87} // namespace eve::graphics::vulkan
building::EdgeCurveGroup group
std::uint32_t vertexCount
vkb::Device & device
std::uint32_t firstVertex
size_t offset
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
uint32_t groups
Definition OnnxGpgpu.cpp:39
std::unique_ptr< gpgpu::GpuBuffer > buffer
Definition OnnxGpgpu.cpp:26
std::unique_ptr< gpgpu::Sequence > sequence
Definition OnnxGpgpu.cpp:43
std::vector< Point > vertices
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Frame-local scene recorder for 3D line primitives.
void drawPrimitiveScene(const PrimitiveSceneCanvas3D &canvas) override
Draws primitive scene.
void gpuDrivenOpenScenePass()
Gpu driven open scene pass.
int getHeight() const override
Returns the height.
Definition Canvas.h:25
int getWidth() const override
Returns the width.
Definition Canvas.h:23
ResolvedPrimitiveTriangles resolvePrimitiveStrokes3D(const PrimitiveSceneCanvas3D &canvas)
Resolves 3D stroke segment bodies with near-plane clipping.
One contiguous 3D pipeline/sort batch in the resolved vertex stream.
Owning backend-neutral triangle stream for one primitive pass.
std::vector< PrimitiveTriangleVertex > vertices
std::vector< ResolvedPrimitiveBatch3D > batches3D
Additional scene-pass state carried by every 3D command.
Clip-space vertex emitted by the backend-neutral primitive tessellator.
Definition Graphics.h:82