srp
software rendering pipeline
Loading...
Searching...
No Matches
Primitive assembly

Functions related to primitive assembly. More...

Collaboration diagram for Primitive assembly:

Files

file  primitive_assembly.c
 
file  primitive_assembly.h
 
file  topology.c
 
file  topology.h
 
static void warnOnExcessVertexCount (const SRPIndexBuffer *ib, const SRPVertexBuffer *vb, SRPPrimitive prim, size_t startIndex, size_t vertexCount)
 
static void resolvePolygonModeOutput (size_t *nOutPrimitivesPerClippedTriangle, size_t *sizeOutPrimitive)
 
bool assembleLines (const SRPIndexBuffer *ib, const SRPVertexBuffer *vb, const SRPFramebuffer *fb, const SRPShaderProgram *sp, SRPPrimitive prim, size_t startIndex, size_t vertexCount, size_t *outLineCount, SRPLine **outLines)
 
bool assemblePoints (const SRPIndexBuffer *ib, const SRPVertexBuffer *vb, const SRPFramebuffer *fb, const SRPShaderProgram *sp, size_t startIndex, size_t count, size_t *outPointCount, SRPPoint **outPoints)
 
bool assembleTrianglesGeneric (const SRPIndexBuffer *ib, const SRPVertexBuffer *vb, const SRPFramebuffer *fb, const SRPShaderProgram *sp, SRPPrimitive prim, size_t startIndex, size_t vertexCount, size_t *outCount, void **outPrimitives)
 
size_t computeTriangleCount (size_t vertexCount, SRPPrimitive prim)
 
void resolveTriangleTopology (size_t base, size_t rawTriIdx, SRPPrimitive prim, size_t *out)
 
size_t computeLineCount (size_t vertexCount, SRPPrimitive prim)
 
void resolveLineTopology (size_t base, size_t rawLineIdx, SRPPrimitive prim, size_t vertexCount, size_t *out)
 

Detailed Description

Functions related to primitive assembly.

Function Documentation

◆ assembleLines()

bool assembleLines ( const SRPIndexBuffer ib,
const SRPVertexBuffer vb,
const SRPFramebuffer fb,
const SRPShaderProgram sp,
SRPPrimitive  primitive,
size_t  startIndex,
size_t  count,
size_t *  outLineCount,
SRPLine **  outLines 
)

Call the vertex shader and assemble lines from vertex or index buffer. If ib == NULL, assembles from vertex buffer, else from index buffer. Uses memory from SRPArena, so the returned points are valid until the next call to arenaReset().

Parameters
[in]ibPointer to index buffer, or NULL if assembling from vertex buffer
[in]vbPointer to vertex buffer
[in]fbPointer to the framebuffer to draw to (needed for NDC to screen-space conversion)
[in]spPointer to the shader program to use
[in]primitivePrimitive type (one of SRP_PRIM_LINES, SRP_PRIM_LINE_STRIP or SRP_PRIM_LINE_LOOP)
[in]startIndexFirst stream index to assemble
[in]countNumber of stream indices to assemble
[out]outLineCountAmount of assembled lines
[out]outLinesPointer to the array of count assembled lines
Returns
true if successful, false otherwise. If false if returned, *outLineCount and *outLines are undefined

◆ assemblePoints()

bool assemblePoints ( const SRPIndexBuffer ib,
const SRPVertexBuffer vb,
const SRPFramebuffer fb,
const SRPShaderProgram sp,
size_t  startIndex,
size_t  count,
size_t *  outPointCount,
SRPPoint **  outPoints 
)

Call the vertex shader and assemble points from vertex or index buffer. If ib == NULL, assembles from vertex buffer, else from index buffer. Uses memory from SRPArena, so the returned points are valid until the next call to arenaReset().

Parameters
[in]ibPointer to index buffer, or NULL if assembling from vertex buffer
[in]vbPointer to vertex buffer
[in]fbPointer to the framebuffer to draw to (needed for NDC to screen-space conversion)
[in]spPointer to the shader program to use
[in]startIndexFirst stream index to assemble
[in]countNumber of stream indices to assemble
[out]outPointCountAmount of assembled points
[out]outPointsPointer to the array of count assembled points
Returns
true if successful, false otherwise. If false if returned, *outPointCount and *outPoints are undefined

◆ assembleTrianglesGeneric()

bool assembleTrianglesGeneric ( const SRPIndexBuffer ib,
const SRPVertexBuffer vb,
const SRPFramebuffer fb,
const SRPShaderProgram sp,
SRPPrimitive  prim,
size_t  startIndex,
size_t  vertexCount,
size_t *  outCount,
void **  outPrimitives 
)

Call the vertex shader and assemble triangles from vertex or index buffer, possibly converting them to lines or points according to the set polygon mode. If ib == NULL, assembles from vertex buffer, else from index buffer. Uses memory from SRPArena, so the returned triangles are valid until the next call to arenaReset().

Parameters
[in]ibPointer to index buffer, or NULL if assembling from vertex buffer
[in]vbPointer to vertex buffer
[in]fbPointer to the framebuffer to draw to (needed for NDC to screen-space conversion)
[in]spPointer to the shader program to use
[in]primPrimitive type (one of SRP_PRIM_TRIANGLES, SRP_PRIM_TRIANGLE_STRIP or SRP_PRIM_TRIANGLE_FAN)
[in]startIndexFirst stream index to assemble
[in]vertexCountNumber of stream indices to assemble
[out]outCountAmount of assembled primitives
[out]outPrimitivesPointer to the array of assembled primitives
Returns
true if successful, false otherwise. If false is returned, *outCount and *outPrimitives are 0 and NULL

◆ computeLineCount()

size_t computeLineCount ( size_t  vertexCount,
SRPPrimitive  prim 
)

Deduce the number of lines to assemble based on the number of vertices and primitive type

Parameters
[in]vertexCountNumber of vertices
[in]primPrimitive type
Returns
Number of lines that should be assembled

◆ computeTriangleCount()

size_t computeTriangleCount ( size_t  vertexCount,
SRPPrimitive  prim 
)

Deduce the number of triangles to assemble based on the number of vertices and primitive type

Parameters
[in]vertexCountNumber of vertices
[in]primPrimitive type
Returns
Number of triangles that should be assembled

◆ resolveLineTopology()

void resolveLineTopology ( size_t  base,
size_t  rawLineIdx,
SRPPrimitive  prim,
size_t  vertexCount,
size_t *  out 
)

Determine the stream indices for a line based on its type

Parameters
[in]baseBase stream index
[in]rawLineIdxIndex of the primitive to assemble, starting from 0, including culled/skipped lines
[in]primPrimitive type
[in]vertexCountThe total amount of stream vertices for this draw call
[out]outArray of size 2 to store the resulting stream indices

◆ resolvePolygonModeOutput()

static void resolvePolygonModeOutput ( size_t *  nOutPrimitivesPerClippedTriangle,
size_t *  sizeOutPrimitive 
)
static

Calculate constants for triangle assembly

Parameters
[out]nOutPrimitivesPerClippedTriangleHow many primitives end up from a clipped triangle
[out]sizeOutPrimitiveThe size of an output primitive (in bytes)

◆ resolveTriangleTopology()

void resolveTriangleTopology ( size_t  base,
size_t  rawTriIdx,
SRPPrimitive  prim,
size_t *  out 
)

Determine the stream indices for a triangle based on its type

Parameters
[in]baseBase stream index
[in]rawTriIdxIndex of the primitive to assemble, starting from 0, including culled triangles
[in]primPrimitive type
[out]outArray of size 3 to store the resulting stream indices

◆ warnOnExcessVertexCount()

static void warnOnExcessVertexCount ( const SRPIndexBuffer ib,
const SRPVertexBuffer vb,
SRPPrimitive  prim,
size_t  startIndex,
size_t  vertexCount 
)
static

Check if there are excess vertices when drawing some kind of primitive, send a warning if so

See also
assembleTriangles() for parameter documentation