aglet/drawparams

Draw parameters, used for draw() in the target module.

Types

BlendEquation = enum
  beAdd,                      ## src * srcFactor + dest * destFactor
  beSubtract,                 ## src * srcFactor - dest * destFactor
  beReverseSubtract,          ## dest * destFactor - src * srcFactor
  beMin,                      ## min(src, dest)
  beMax                       ## max(src, dest)
Base blend equation to be used in blending.   Source Edit
BlendFactor = enum
  bfZero,                     ## (0, 0, 0)              | 0
  bfOne,                      ## (1, 1, 1)              | 1
  bfSrcColor,                 ## src.rgb                | src.a
  bfOneMinusSrcColor,         ## (1, 1, 1) - src.rgb    | 1 - src.a
  bfDestColor,                ## dest.rgb               | dest.a
  bfOneMinusDestColor,        ## (1, 1, 1) - dest.rgb   | 1 - dest.a
  bfSrcAlpha,                 ## src.a                  | src.a
  bfSrcAlphaSaturate,         ## min(src.a, 1 - dest.a) | 1
  bfOneMinusSrcAlpha,         ## 1 - src.a              | 1 - src.a
  bfDestAlpha,                ## dest.a                 | dest.a
  bfOneMinusDestAlpha,        ## 1 - dest.a             | 1 - dest.a
  bfConstColor,               ## constant.rgb           | constant.a
  bfOneMinusConstColor,       ## 1 - constant.rgb       | 1 - constant.a
  bfConstAlpha,               ## const.a                | constant.a
  bfOneMinusConstAlpha        ## 1 - const.a            | 1 - constant.a
Factors used in blend equations (suffixed with Factor). First column is color, second column is alpha.   Source Edit
BlendFunc = object
  case equation: BlendEquation
  of beAdd, beSubtract, beReverseSubtract:
      src, dest: BlendFactor

  of beMin, beMax:
    nil
  
A blending function.   Source Edit
BlendMode = object
  color, alpha: BlendFunc
  constant: Vec4f
Blending mode. For each fragment that is rendered, if enabled, blending is performed using the specified blend functions separately for the color and alpha components.   Source Edit
ColorLogic = enum
  clClear,                    ## 0
  clSet,                      ## 1
  clCopy,                     ## s
  clCopyInverted,             ## not s
  clNoop,                     ## d
  clInvert,                   ## not d
  clAnd,                      ## s and d
  clNand,                     ## not (s and d)
  clOr,                       ## s or d
  clNor,                      ## not (s or d)
  clXor,                      ## s xor d
  clEquiv,                    ## not (s xor d)
  clAndReverse,               ## s and not d
  clAndInverted,              ## not s and d
  clOrReverse,                ## s or not d
  clOrInverted                ## not s or d
Logic operation to apply to color buffers. This does not work for float framebuffers. s = source, d = destination. Nim operators are used.   Source Edit
CompareFunc = enum
  cfNever,                    ## false
  cfLess,                     ## (reference and mask) <  (stencil and mask)
  cfLessEqual,                ## (reference and mask) <= (stencil and mask)
  cfGreater,                  ## (reference and mask) >  (stencil and mask)
  cfGreaterEqual,             ## (reference and mask) >= (stencil and mask)
  cfEqual,                    ## (reference and mask) == (stencil and mask)
  cfNotEqual,                 ## (reference and mask) != (stencil and mask)
  cfAlways                    ## true
Equation for checking if the stencil test passes. Nim operators are used.   Source Edit
StencilFunc = object
  equation: CompareFunc        ## the equation to apply
  reference: int32             ## reference value
  mask: uint32                 ## bitmask with which ``reference`` and ``stencil`` are ANDed when testing
  
Function for stencil testing. Refer to StencilEquation for details on how each individual equation value works.   Source Edit
StencilAction = enum
  saKeep,                     ## keep value in stencil buffer
  saZero,                     ## set the value to 0
  saReplace,                  ## replace the value with ``reference`` value from ``StencilFunc``
  saInc,                      ## increment value with clamping on overflow
  saIncWrap,                  ## increment value with wrapping on overflow
  saDec,                      ## decrement value with clamping on underflow
  saDecWrap,                  ## decrement value with wrapping on underflow
  saInvert                    ## bitwise invert the value
Action to take on a given stencil condition (pass, depth fail, depth pass).   Source Edit
StencilOp = object
  stencilFail: StencilAction   ## action to take when stencil test fails
  stencilPassDepthFail: StencilAction ## action to take when stencil test passes but depth test fails
  stencilPassDepthPass: StencilAction ## action to take when stencil test passes and depth test passes
  
Set of stencil operations for cases when the stencil test fails or passes and the depth test fails or passes.   Source Edit
StencilMode = object
  funcs: array[Facing, StencilFunc] ## functions for individual facings
  ops: array[Facing, StencilOp] ## operations for individual facings
  masks: array[Facing, uint32]  ## bitmasks for write operations
  
Stencil buffer operation mode.   Source Edit
PolygonMode = enum
  pmPoint,                    ## draw individual vertices
  pmLine,                     ## draw vertices connected with lines
  pmFill                      ## draw filled shape
Mode used for polygon rendering.   Source Edit
ColorMask = tuple[red, green, blue, alpha: bool]
Mask specifying which color channels are to be written to when rendering.   Source Edit
DrawParams = object
  hash: Hash                   ## hash of ``val`` used for optimization purposes
  val: DrawParamsVal           ## actual draw parameters
  
A set of draw parameters. These are used to specify how a mesh is drawn, what features to enable, etc.   Source Edit

Consts

blendMin = (equation: beMin, src: bfZero, dest: bfZero)
beMin blend equation. This is a constant because the equation requires no parameters.   Source Edit
blendMax = (equation: beMax, src: bfZero, dest: bfZero)
beMax blend equation.   Source Edit

Procs

proc blendMode(color: BlendFunc; alpha = color; constant = vec4f(0.0)): BlendMode {...}{.
    inline, raises: [], tags: [].}
Construct a blend mode.   Source Edit
proc blendAdd(src, dest: BlendFactor): BlendFunc {...}{.inline, raises: [], tags: [].}
Construct an addition blend function. Check BlendFunc for reference.   Source Edit
proc blendSub(src, dest: BlendFactor): BlendFunc {...}{.inline, raises: [], tags: [].}
Construct a subtraction blend function.   Source Edit
proc blendRevSub(src, dest: BlendFactor): BlendFunc {...}{.inline, raises: [], tags: [].}
Construct a reverse subtraction blend function.   Source Edit
proc stencilMode(funcs: array[Facing, StencilFunc]; ops: array[Facing, StencilOp];
                masks: array[Facing, uint32] = [high(uint32), high(uint32)]): StencilMode {...}{.
    inline, raises: [], tags: [].}
Constructs a stencil mode using the provided stencil functions and operations.   Source Edit
proc stencilMode(funcBoth: StencilFunc; opBoth: StencilOp; maskBoth = high(uint32)): StencilMode {...}{.
    inline, raises: [], tags: [].}
Constructs a stencil mode. funcBoth and opBoth are used both for front and back faces.   Source Edit
proc stencilFunc(equation: CompareFunc; reference: int32; mask = high(uint32)): StencilFunc {...}{.
    inline, raises: [], tags: [].}
Constructs a stencil test function using the given equation, reference value, and optional bitmask.   Source Edit
proc stencilOp(stencilFail, stencilPassDepthFail, stencilPassDepthPass: StencilAction): StencilOp {...}{.
    inline, raises: [], tags: [].}
Constructs a stencil operation from the given parameters.   Source Edit
proc blend(params; mode: BlendMode) {...}{.inline, raises: [], tags: [].}

Enables blending. If enabled, each fragment to be drawn (source) is blended with fragments already in the framebuffer (destination). Refer to BlendMode for more details.

Default: disabled

  Source Edit
proc noBlend(params) {...}{.inline, raises: [], tags: [].}

Disables blending.

Default: disabled

  Source Edit
proc noColorLogicOp(params) {...}{.inline, raises: [], tags: [].}

Disables color logic operations.

Default: disabled

  Source Edit
proc colorLogicOp(params; op: ColorLogic) {...}{.inline, raises: [], tags: [].}

Enables color logic operations.

Default: disabled

  Source Edit
proc colorMask(params; red, green, blue, alpha: bool) {...}{.inline, raises: [], tags: [].}

Sets the color mask.

Default: (on, on, on, on)

  Source Edit
proc depthMask(params; enabled: bool) {...}{.inline, raises: [], tags: [].}

Enables or disables writing to the depth buffer. Depth testing is still performed if enabled == false, but new depth fragments are not written.

Default: on

  Source Edit
proc depthTest(params; function = cfLess) {...}{.inline, raises: [], tags: [].}

Enables depth testing.

Default: disabled

  Source Edit
proc noDepthTest(params) {...}{.inline, raises: [], tags: [].}

Enables depth testing.

Default: disabled

  Source Edit
proc dither(params; enabled: bool) {...}{.inline, raises: [], tags: [].}

Enables or disables dithering.

Default: on

  Source Edit
proc faceCulling(params; facings: set[Facing]) {...}{.inline, raises: [], tags: [].}

Enables or disables face culling.

Default: disabled

  Source Edit
proc frontFace(params; winding: Winding) {...}{.raises: [], tags: [].}

Sets the front face winding direction.

Default: windingCounterclockwise

  Source Edit
proc hint(params; hint: Hint; value: HintValue) {...}{.inline, raises: [], tags: [].}

Sets an implementation-defined hint.

Defaults:

  • hintFragmentShaderDerivative: hvDontCare
  • hintLineSmooth: hvDontCare
  • hintPolygonSmooth: hvDontCare
  Source Edit
proc lineSmooth(params; enabled: bool) {...}{.inline, raises: [], tags: [].}

Enables or disables line antialiasing. This feature can be used without multisampling.

Default: off

  Source Edit
proc lineWidth(params; width: float32) {...}{.inline, raises: [], tags: [].}

Sets the line width. The allowed range of values is implementation-defined, and the only width guaranteed to be supported is 1.

Default: 1

  Source Edit
proc multisample(params; enabled: bool) {...}{.inline, raises: [], tags: [].}

Enables or disables multisample anti-aliasing (MSAA). Keep in mind that the target must have a multisample capable framebuffer. This can be enabled for the default framebuffer when creating the window, or when creating a 2D framebuffer texture. Keep in mind that the default framebuffer is not guaranteed to support multisampling, so it's always safer to use a texture when you depend on MSAA, but multisampling is available on pretty much all modern hardware no matter the framebuffer.

Default: off

  Source Edit
proc pointSize(params; size: float32) {...}{.inline, raises: [], tags: [].}

Specifies the radius of rasterized points.

Default: 1

  Source Edit
proc programPointSize(params; enabled: bool) {...}{.inline, raises: [], tags: [].}
Enables or disables setting the point size via shader programs. Enabling this will make rasterization respect the gl_PointSize variable from vertex and geometry shaders.   Source Edit
proc polygonMode(params; facings: set[Facing]; mode: PolygonMode) {...}{.inline, raises: [],
    tags: [].}

Sets the polygon rasterization mode.

Defaults:

  • facingFront: pmFill
  • facingBack: pmFill
  Source Edit
proc polygonSmooth(params; enabled: bool) {...}{.inline, raises: [], tags: [].}

Enables or disables polygon antialiasing. This feature can be used without multisampling. Alpha blending must be enabled and polygons must be sorted from front to back to produce correct results.

Default: off

  Source Edit
proc primitiveRestartIndex(params; index: uint32) {...}{.inline, raises: [], tags: [].}

Enables the primitive restart index. The usage of this index in any mesh will cause the current primitive to be restarted. This is useful for line strips, line loops, triangle fans, and triangle strips.

Default: disabled

  Source Edit
proc noPrimitiveRestartIndex(params) {...}{.inline, raises: [], tags: [].}

Disables the primitive restart index.

Default: disabled

  Source Edit
proc scissor(params; rect: Recti) {...}{.inline, raises: [], tags: [].}

Enables scissor testing. If enabled, the scissor test discards all fragments outside of the provided rect.

Default: disabled

  Source Edit
proc noScissor(params) {...}{.inline, raises: [], tags: [].}

Disables scissor testing.

Default: disabled

  Source Edit
proc stencil(params; mode: StencilMode) {...}{.inline, raises: [], tags: [].}

Enables stencil testing. If enabled, a per-fragment stencil test is performed. Fragments that don't pass the test are discarded. Refer to StencilMode's documentation for details.

Default: disabled

  Source Edit
proc noStencil(params) {...}{.inline, raises: [], tags: [].}

Disables stencil testing.

Default: disabled

  Source Edit
proc seamlessCubeMapSampling(params; enabled: bool) {...}{.inline, raises: [], tags: [].}

Enables or disables seamless cubemap sampling. This parameter enables blending of cubemap edges, making the cubemap seamless.

Default: disabled

  Source Edit
proc finish(params) {...}{.inline, raises: [], tags: [].}
Finalizes construction of draw parameters by re-hashing them. This step is very important. aglet keeps a hash of the draw parameters for optimization purposes (so that the parameters don't have to be re-written every single time draw() is called, and comparisons between previously used draw parameters and the current ones are fast). If this procedure is not called, things will most likely break when using multiple sets of draw parameters. You don't need to call this procedure if you're using the derive macro (which you should).   Source Edit
proc `==`(a, b: DrawParams): bool {...}{.inline, raises: [], tags: [].}
Compares two sets of draw parameters by their hash.   Source Edit
proc defaultDrawParams(): DrawParams {...}{.raises: [], tags: [].}
Returns a set of draw parameters matching that described in procedure descriptions. These parameters also match the default settings of OpenGL, as specified in the official documentation.   Source Edit
proc IMPL_apply(params: DrawParams; gl: OpenGl) {...}{.raises: [Exception, UnpackError],
    tags: [RootEffect].}
Apply the given draw parameters to the GL context. Implementation detail, do not use.   Source Edit

Macros

macro derive(params: DrawParams; body: untyped): untyped
A macro for making param deriving nice. Creates a block with a temporary variable params, and prepends it to the arguments of every single call in the block. Finally, adds a call to finish(params).

Examples:

let
  cool = defaultDrawParams().derive:
    multisample on
    depthTest
  lame = block:
    var p = defaultDrawParams()
    p.multisample on
    p.depthTest
    p.finish
    p
assert cool == lame
  Source Edit