Class GeometryStep

java.lang.Object
icyllis.arc3d.granite.GeometryStep
Direct Known Subclasses:
AnalyticArcStep, AnalyticSimpleBoxStep, CircleProcessor, DefaultGeoProc, RasterTextStep, SDFRectGeoProc, VerticesStep

@Immutable public abstract class GeometryStep extends Object
The GeometryProcessor represents some kind of geometric primitive. This includes the shape of the primitive and the inherent color of the primitive. The GeometryProcessor is responsible for providing a color and coverage input into the rendering pipeline. Through optimization, Engine may decide a different color, no color, and / or no coverage are required from the GeometryProcessor, so the GeometryProcessor must be able to support this functionality.

There are two feedback loops between the FragmentProcessors, the XferProcessor, and the GeometryProcessor. These loops run on the CPU and to determine known properties of the final color and coverage inputs to the XferProcessor in order to perform optimizations that preserve correctness. The DrawOp seeds these loops with initial color and coverage, in its getProcessorAnalysisInputs implementation. These seed values are processed by the subsequent stages of the rendering pipeline and the output is then fed back into the DrawOp in the applyPipelineOptimizations call, where the op can use the information to inform decisions about GeometryProcessor creation.

Note that all derived classes should hide their constructors and provide a Make factory function that takes an arena (except for Tesselation-specific classes). This is because geometry processors can be created in either the record-time or flush-time arenas which define their lifetimes (i.e., a DDLs life time in the first case and a single flush in the second case).

  • Field Details

  • Constructor Details

  • Method Details

    • makeColorAttribute

      @Nonnull protected static VertexInputLayout.Attribute makeColorAttribute(String name, boolean wideColor)
      GPs that need to use either float or ubyte colors can just call this to get a correctly configured Attribute struct
    • name

      @Nonnull public final String name()
      Human-meaningful string to identify this processor; may be embedded in generated shader code and must be a legal AkSL identifier prefix.
    • uniqueID

      public final int uniqueID()
      Returns:
      unique ID that identifies this processor class.
    • primitiveType

      public final byte primitiveType()
      Returns a primitive topology for render passes. If the return values of different instances are different, they must be reflected in the key, see appendToKey(KeyBuilder).
      See Also:
    • numTextureSamplers

      public int numTextureSamplers()
      Currently, GP is limited to one texture sampler at most.
    • textureSamplerState

      public int textureSamplerState(int i)
      Used to capture the properties of the TextureProxies required/expected by a GeometryProcessor along with an associated SamplerState. The actual proxies used are stored in either the fixed or dynamic state arrays. TextureSamplers don't perform any coord manipulation to account for texture origin.
      See Also:
    • textureSamplerSwizzle

      public short textureSamplerSwizzle(int i)
      See Also:
    • getInputLayout

      public VertexInputLayout getInputLayout()
    • hasVertexAttributes

      public final boolean hasVertexAttributes()
      Returns true if numVertexAttributes() will return non-zero.
      Returns:
      true if there are per-vertex attributes
    • vertexBinding

      public final int vertexBinding()
    • numVertexAttributes

      public final int numVertexAttributes()
      Returns the number of used per-vertex attributes (input variables). Note: attribute of a matrix type counts as just one.
      See Also:
    • numVertexLocations

      public final int numVertexLocations()
      Returns the number of used per-vertex attribute locations (slots). An attribute (variable) may take up multiple consecutive locations.
      See Also:
    • vertexAttributes

      @Nonnull public final Iterator<VertexInputLayout.Attribute> vertexAttributes()
      Returns an iterable of used per-vertex attributes. It's safe to call even if there's no attribute. The iterator handles hides two pieces of complexity:
      1. It skips unused attributes (see mask in
        invalid reference
        #setVertexAttributes(int)
        ).
      2. It always returns an attribute with a known offset.
    • vertexStride

      public final int vertexStride()
      Returns the number of bytes from one vertex to the next vertex, including paddings. A common practice is to populate the vertex's memory using an implicit array of structs. In this case, it is best to assert that: stride == sizeof(struct).
    • hasInstanceAttributes

      public final boolean hasInstanceAttributes()
      Returns true if numInstanceAttributes() will return non-zero.
      Returns:
      true if there are per-instance attributes
    • instanceBinding

      public final int instanceBinding()
    • numInstanceAttributes

      public final int numInstanceAttributes()
      Returns the number of used per-instance attributes (input variables). Note: attribute of a matrix type counts as just one.
      See Also:
    • numInstanceLocations

      public final int numInstanceLocations()
      Returns the number of used per-instance attribute locations. (slots). An attribute (variable) may take up multiple consecutive locations.
      See Also:
    • instanceAttributes

      @Nonnull public final Iterator<VertexInputLayout.Attribute> instanceAttributes()
      Returns an iterable of used per-instance attributes. It's safe to call even if there's no attribute. The iterator handles hides two pieces of complexity:
      1. It skips unused attributes (see mask in
        invalid reference
        #setInstanceAttributes(int)
        ).
      2. It always returns an attribute with a known offset.
    • instanceStride

      public final int instanceStride()
      Returns the number of bytes from one instance to the next instance, including paddings. A common practice is to populate the instance's memory using an implicit array of structs. In this case, it is best to assert that: stride == sizeof(struct).
    • performsShading

      public final boolean performsShading()
    • emitsCoverage

      public final boolean emitsCoverage()
    • handlesSolidColor

      public final boolean handlesSolidColor()
    • emitsPrimitiveColor

      public final boolean emitsPrimitiveColor()
    • depthStencilSettings

      public final DepthStencilSettings depthStencilSettings()
    • depthStencilFlags

      public final int depthStencilFlags()
    • appendToKey

      public abstract void appendToKey(@Nonnull KeyBuilder b)
      Appends a key on the KeyBuilder that reflects any variety in the code that the geometry processor subclass can emit.
      See Also:
    • appendAttributesToKey

      public final void appendAttributesToKey(@Nonnull KeyBuilder b)
    • makeProgramImpl

      @Nonnull public abstract GeometryStep.ProgramImpl makeProgramImpl(ShaderCaps caps)
      Returns a new instance of the appropriate implementation class for the given GeometryProcessor. This method is called only when the specified key does not exist in the program cache.
      See Also:
    • emitVaryings

      public void emitVaryings(VaryingHandler varyingHandler, boolean usesFastSolidColor)
    • emitUniforms

      public void emitUniforms(UniformHandler uniformHandler, boolean mayRequireLocalCoords)
    • emitSamplers

      public void emitSamplers(UniformHandler uniformHandler)
    • emitVertexGeomCode

      public void emitVertexGeomCode(Formatter vs, @Nonnull String worldPosVar, @Nullable String localPosVar, boolean usesFastSolidColor)
      Emits the geometry code into the vertex shader. Implementation must define "vec4 worldPosVar" with the given name and setup it. If localPosVar is not null, then it must write geometry's local pos to it.
    • emitFragmentColorCode

      public void emitFragmentColorCode(Formatter fs, String outputColor)
      Emits the fragment color code into the fragment shader. This is either paint's solid color or per-vertex primitive color. See FLAG_HANDLE_SOLID_COLOR and FLAG_EMIT_PRIMITIVE_COLOR.
    • emitFragmentCoverageCode

      public void emitFragmentCoverageCode(Formatter fs, String outputCoverage)
      Emits the fragment coverage code into the fragment shader.

      If emitsCoverage() is false, this method is called for hard-edge coverage, discard the fragment if coverage is 0. Otherwise outputCoverage is non-null, and coverage will involve in blending operations.

    • writeMesh

      public void writeMesh(MeshDrawWriter writer, Draw draw, @Nullable float[] solidColor, boolean mayRequireLocalCoords)
    • writeUniformsAndTextures

      public void writeUniformsAndTextures(RecordingContext context, Draw draw, UniformDataGatherer uniformDataGatherer, TextureDataGatherer textureDataGatherer, boolean mayRequireLocalCoords)