载入中...
搜索中...
未找到
GraphicsPrimitives.cpp
浏览该文件的文档.
1#include "common/Assert.h"
7
8namespace eve::graphics::vulkan {
9
11 ASSERT(initialized);
12 if (!initialized) throw Exception("drawPrimitiveScene: graphics not initialized");
13 const bool offscreen = offscreen3DPassOpen;
14 if (!offscreen && gpuDrivenScenePassPending_) gpuDrivenOpenScenePass();
15 if (!offscreen && !swapchainPassOpen) throw Exception("drawPrimitiveScene: call begin3DFrame first");
16
18 if (resolved.vertices.empty()) return;
19
20 struct DrawGroup {
22 std::size_t sequence = 0;
23 float averageDepth = 0.f;
24 std::size_t firstVertex = 0;
25 std::size_t vertexCount = 0;
26 };
27 std::vector<DrawGroup> groups;
28 groups.reserve(resolved.batches3D.size());
29 for (const ResolvedPrimitiveBatch3D &batch : resolved.batches3D) {
30 DrawGroup group;
31 group.paint = batch.paint;
32 group.sequence = batch.sequence;
33 group.averageDepth = batch.averageDepth;
34 group.firstVertex = batch.firstVertex;
35 group.vertexCount = batch.vertexCount;
36 groups.push_back(std::move(group));
37 }
38 std::stable_sort(groups.begin(), groups.end(), [&](const DrawGroup &a, const DrawGroup &b) {
39 const ScenePrimitivePaint &paintA = a.paint;
40 const ScenePrimitivePaint &paintB = b.paint;
41 const bool ignoreA = paintA.depth == PrimitiveDepthMode::Ignore;
42 const bool ignoreB = paintB.depth == PrimitiveDepthMode::Ignore;
43 if (ignoreA != ignoreB) return !ignoreA;
44 if (paintA.layer != paintB.layer) return paintA.layer < paintB.layer;
45 const bool transparentA = paintA.blend != BlendMode::Opaque || paintA.color.a < 1.f;
46 const bool transparentB = paintB.blend != BlendMode::Opaque || paintB.color.a < 1.f;
47 if (transparentA != transparentB) return !transparentA;
48 if (transparentA && a.averageDepth != b.averageDepth) return a.averageDepth > b.averageDepth;
49 return a.sequence < b.sequence;
50 });
51
52 auto &buffers = offscreen ? offscreenPrimitive3DBufs : currentFrame2DBuffers().primitive3DBufs;
53 auto &drawIndex = offscreen ? offscreenPrimitive3DDrawIndex : currentFrame2DBuffers().primitive3DDrawIndex;
54 if (drawIndex == buffers.size()) buffers.emplace_back();
55 // Earlier submissions still reference their buffers until this frame's fence.
56 auto &buffer = buffers[drawIndex++];
57 const vk::CommandBuffer cb = offscreen ? offscreen3DCB : currentPresentCb();
58 const uint32_t targetWidth =
59 offscreen ? static_cast<uint32_t>(offscreen3DCanvas->getWidth()) : swapchain.extent.width;
60 const uint32_t targetHeight =
61 offscreen ? static_cast<uint32_t>(offscreen3DCanvas->getHeight()) : swapchain.extent.height;
62 auto &pipelines = offscreen
63 ? (offscreen3DHDRActive ? hdrOffscreenPrimitive3DPipelines : offscreenPrimitive3DPipelines)
64 : primitive3DPipelines;
65 setViewportAndScissor(cb, targetWidth, targetHeight);
66 std::vector<Primitive3DVertex> vertices;
67 vertices.reserve(resolved.vertices.size());
68 for (const DrawGroup &group : groups) {
69 for (std::size_t vertex = group.firstVertex; vertex < group.firstVertex + group.vertexCount; ++vertex)
70 vertices.push_back({resolved.vertices[vertex].clipPosition, resolved.vertices[vertex].color});
71 }
72 buffer.allocate<Primitive3DVertex>(frameToken(), device, vertices);
73 const vk::DeviceSize offset = 0;
74 cb.bindVertexBuffers(0, 1, buffer, &offset);
75 std::uint32_t firstVertex = 0;
76 for (std::size_t groupIndex = 0; groupIndex < groups.size(); ++groupIndex) {
77 const DrawGroup &group = groups[groupIndex];
78 const ScenePrimitivePaint &paint = group.paint;
79 const std::size_t pipelineIndex = primitive3DPipelineIndex(paint.depth, paint.blend, paint.cull);
80 const vk::Pipeline primitivePipeline = pipelines[pipelineIndex];
81 if (!primitivePipeline) throw Exception("drawPrimitiveScene: primitive pipeline unavailable");
82 cb.bindPipeline(vk::PipelineBindPoint::eGraphics, primitivePipeline);
83 cb.draw(static_cast<uint32_t>(group.vertexCount), 1, firstVertex, 0);
84 firstVertex += static_cast<std::uint32_t>(group.vertexCount);
85 }
86}
87
88} // namespace eve::graphics::vulkan
EVEngine assertion entry point, backed by zeroerr.
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
RoadNetwork resolved
AbilityActivationGroup group
std::array< double, 2 > vertices[3]
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.
Additional scene-pass state carried by every 3D command.
Clip-space vertex emitted by the backend-neutral primitive tessellator.
Definition Graphics.h:89