Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
skgpu::tess::FixedCountCurves Class Reference

#include <FixedCountBufferUtils.h>

Static Public Member Functions

static constexpr int PreallocCount (int totalCombinedPathVerbCnt)
 
static int VertexCount (const LinearTolerances &tolerances)
 
static constexpr size_t VertexBufferSize ()
 
static constexpr size_t IndexBufferSize ()
 
static void WriteVertexBuffer (VertexWriter, size_t bufferSize)
 
static void WriteIndexBuffer (VertexWriter, size_t bufferSize)
 

Detailed Description

Fixed-count tessellation operates in three modes, two for filling paths, and one for stroking. These modes may have additional sub-variations, but in terms of vertex buffer management, these three categories are sufficient:

The three types defined below for these three modes provide utility functions for heuristics to choose pre-allocation size when accumulating instance attributes with a PatchWriter, and functions for creating static/GPU-private vertex and index buffers that are used as the template for instanced rendering.

Definition at line 39 of file FixedCountBufferUtils.h.

Member Function Documentation

◆ IndexBufferSize()

static constexpr size_t skgpu::tess::FixedCountCurves::IndexBufferSize ( )
inlinestaticconstexpr

Definition at line 66 of file FixedCountBufferUtils.h.

66 {
67 return NumCurveTrianglesAtResolveLevel(kMaxResolveLevel) * 3 * sizeof(uint16_t);
68 }
static constexpr int NumCurveTrianglesAtResolveLevel(int resolveLevel)
static constexpr int kMaxResolveLevel

◆ PreallocCount()

static constexpr int skgpu::tess::FixedCountCurves::PreallocCount ( int  totalCombinedPathVerbCnt)
inlinestaticconstexpr

Definition at line 43 of file FixedCountBufferUtils.h.

43 {
44 // Over-allocate enough curves for 1 in 4 to chop. Every chop introduces 2 new patches:
45 // another curve patch and a triangle patch that glues the two chops together,
46 // i.e. + 2 * ((count + 3) / 4) == (count + 3) / 2
47 return totalCombinedPathVerbCnt + (totalCombinedPathVerbCnt + 3) / 2;
48 }

◆ VertexBufferSize()

static constexpr size_t skgpu::tess::FixedCountCurves::VertexBufferSize ( )
inlinestaticconstexpr

Definition at line 61 of file FixedCountBufferUtils.h.

61 {
62 return (kMaxParametricSegments + 1) * (2 * sizeof(float));
63 }
static constexpr int kMaxParametricSegments

◆ VertexCount()

static int skgpu::tess::FixedCountCurves::VertexCount ( const LinearTolerances tolerances)
inlinestatic

Definition at line 52 of file FixedCountBufferUtils.h.

52 {
53 // We should already chopped curves to make sure none needed a higher resolveLevel than
54 // kMaxResolveLevel.
55 int resolveLevel = std::min(tolerances.requiredResolveLevel(), kMaxResolveLevel);
56 return NumCurveTrianglesAtResolveLevel(resolveLevel) * 3;
57 }

◆ WriteIndexBuffer()

void skgpu::tess::FixedCountCurves::WriteIndexBuffer ( VertexWriter  vertexWriter,
size_t  bufferSize 
)
static

Definition at line 103 of file FixedCountBufferUtils.cpp.

103 {
104 write_curve_index_buffer_base_index(std::move(vertexWriter), bufferSize, /*baseIndex=*/0);
105}

◆ WriteVertexBuffer()

void skgpu::tess::FixedCountCurves::WriteVertexBuffer ( VertexWriter  vertexWriter,
size_t  bufferSize 
)
static

Definition at line 70 of file FixedCountBufferUtils.cpp.

70 {
71 SkASSERT(bufferSize >= sizeof(SkPoint) * 2);
72 int vertexCount = bufferSize / sizeof(SkPoint);
73 SkASSERT(vertexCount > 3);
74 SkDEBUGCODE(auto end = vertexWriter.mark(vertexCount * sizeof(SkPoint));)
75
76 // Lay out the vertices in "middle-out" order:
77 //
78 // T= 0/1, 1/1, ; resolveLevel=0
79 // 1/2, ; resolveLevel=1 (0/2 and 2/2 are already in resolveLevel 0)
80 // 1/4, 3/4, ; resolveLevel=2 (2/4 is already in resolveLevel 1)
81 // 1/8, 3/8, 5/8, 7/8, ; resolveLevel=3 (2/8 and 6/8 are already in resolveLevel 2)
82 // ... ; resolveLevel=...
83 //
84 // Resolve level 0 is just the beginning and ending vertices.
85 vertexWriter << (float)0/*resolveLevel*/ << (float)0/*idx*/;
86 vertexWriter << (float)0/*resolveLevel*/ << (float)1/*idx*/;
87
88 // Resolve levels 1..kMaxResolveLevel.
89 int maxResolveLevel = SkPrevLog2(vertexCount - 1);
90 SkASSERT((1 << maxResolveLevel) + 1 == vertexCount);
91 for (int resolveLevel = 1; resolveLevel <= maxResolveLevel; ++resolveLevel) {
92 int numSegmentsInResolveLevel = 1 << resolveLevel;
93 // Write out the odd vertices in this resolveLevel. The even vertices were already written
94 // out in previous resolveLevels and will be indexed from there.
95 for (int i = 1; i < numSegmentsInResolveLevel; i += 2) {
96 vertexWriter << (float)resolveLevel << (float)i;
97 }
98 }
99
100 SkASSERT(vertexWriter.mark() == end);
101}
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
static int SkPrevLog2(uint32_t value)
Definition SkMathPriv.h:257
glong glong end

The documentation for this class was generated from the following files: