Renderable
public protocol Renderable: NodeGeometry, Tree
The Renderable
protocol is required by an object that wishes to be rendered. Applying this protocol to an object should be sufficient for creating a custom pipeline.
The following base classes conform to this protocol: - ShapeNode - SpriteNode - TextNode
discussion: Currently, this doesn’t need to be public as there’s no way to add a custom Pipeline
to the Renderer
at some point I will expose that.
I’m just not entirely sure how I want to do it yet.
Seealso
NodeGeometry
and Tree
-
Holds the vertex data for an object. Currently, perhaps forever, the only way to update the vertices of an object after creating is by updating their size using the default implementation of updateSize in
NodeGeometry
.Note
All the default renderable objects only have 4 vertices in a rectangular shape.
Warning
For the default renderable objects, the size of this is buffer is the exact size required and therefore should not be updated after this object has been added to the draw loop. Currently, it’s not a big deal I don’t think, but that may change at some point.
Seealso
func updateSize()
Declaration
Swift
var vertexBuffer: MTLBuffer { get }
-
Holds the indices for each vertex of an object.
Note
By default, this buffer holds [0, 1, 2, 2, 3, 0] where 0, 1, 2 is the upper left triangle, 0 being the lower left vertex.
Seealso
Quad
for an example.Declaration
Swift
var indexBuffer: MTLBuffer { get }
-
A texture to be applied in the fragment shader.
Declaration
Swift
var texture: Texture? { get set }
-
A color to be applied during the fragment shader. By default, this is blended with the texture.
Declaration
Swift
var color: Color { get set }
-
decompose(_:)
Default implementationThis is used in order to properly update a model matrix of an object based on the parent’s model matrix. This, in general, should be used as the model matrix for the uniform buffer and not the default model matrix of the
Renderable
object.Note
By default, the
parentMatrix
is the direct parent of aRenderable
object. I think that’s sufficient?Default Implementation
Undocumented
Declaration
Swift
func decompose(parentMatrix: Mat4) -> Mat4
Parameters
parentMatrix
The
Renderable
’s parent model matrix.Return Value
A new model matrix to be used as this
Renderable
’s model matrix. -
This is used by the various
Pipeline
s to encode the objects to theMTLCommandBuffer
to be drawn by the GPU.Note
The commandBuffer in general is not actually required at this point. It’s only being used to signal to the
uniformBufferQueue
that the commandBuffer is done and we can update the uniform buffers again.Declaration
Swift
func draw(commandBuffer: MTLCommandBuffer, renderEncoder: MTLRenderCommandEncoder, sampler: MTLSamplerState?)
Parameters
commandBuffer
The buffer to encode the commands for drawing the
Renderable
.renderEncoder
The command encoder to use for encoding the commands for drawing the
Renderale
to the command buffer.sampler
The sampler to use to encode how the shader should sample the texture being applied.