RenderContext

class RenderContext(val ag: AG, val bp: BoundsProvider = BoundsProvider.Base(), val deviceDimensionsProvider: DeviceDimensionsProvider = (bp as? DeviceDimensionsProvider?) ?: DeviceDimensionsProvider.DEFAULT, val stats: Stats = Stats(), val coroutineContext: CoroutineContext = EmptyCoroutineContext, val batchMaxQuads: Int = BatchBuilder2D.DEFAULT_BATCH_QUADS, val windowConfig: GameWindowConfig = GameWindowConfig.Impl()) : Extra, BoundsProvider, AGFeatures, DeviceDimensionsProvider, Closeable

A context that allows to render objects.

The RenderContext contains the ag (Accelerated Graphics), that allow to render triangles and other primitives to the current render buffer.

When doing 2D, you should usually use the batch to buffer vertices, so they can be rendered at once when flushing.

If you plan to do a custom drawing using ag directly, you should call flush, so all the pending vertices are rendered.

If you want to perform drawing using a context allowing non-precomputed transformations you can use ctx2d.

If you need to get textures from Bitmap that are allocated and deallocated as required preventing leaks, you should use getTex.

Constructors

Link copied to clipboard
constructor(ag: AG, bp: BoundsProvider = BoundsProvider.Base(), deviceDimensionsProvider: DeviceDimensionsProvider = (bp as? DeviceDimensionsProvider?) ?: DeviceDimensionsProvider.DEFAULT, stats: Stats = Stats(), coroutineContext: CoroutineContext = EmptyCoroutineContext, batchMaxQuads: Int = BatchBuilder2D.DEFAULT_BATCH_QUADS, windowConfig: GameWindowConfig = GameWindowConfig.Impl())

Types

Link copied to clipboard

Properties

Link copied to clipboard
open override val actualVirtualBottom: Double
Link copied to clipboard
open override var actualVirtualBounds: Rectangle
Link copied to clipboard
open override val actualVirtualHeight: Int
Link copied to clipboard
open override val actualVirtualLeft: Int
Link copied to clipboard
open override val actualVirtualRight: Double
Link copied to clipboard
open override val actualVirtualTop: Int
Link copied to clipboard
open override val actualVirtualWidth: Int
Link copied to clipboard
val ag: AG

The Accelerated Graphics object that allows direct rendering

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open val backHeight: Int
Link copied to clipboard
open val backWidth: Int
Link copied to clipboard

Allows to draw quads, sprites and nine patches using a precomputed global matrix or raw vertices

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val computedPixelRatio: Double
Link copied to clipboard
Link copied to clipboard

RenderContext2D similar to the one from JS, that keeps a matrix (affine transformation) and allows to draw shapes using the current matrix

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val devicePixelRatio: Double
Link copied to clipboard
open override var extra: ExtraType
Link copied to clipboard
Link copied to clipboard

Allows to register handlers when the flush method is called

Link copied to clipboard
Link copied to clipboard
open override var globalToWindowMatrix: Matrix
Link copied to clipboard
open override val globalToWindowScale: Scale
Link copied to clipboard
open override val globalToWindowScaleAvg: Double
Link copied to clipboard
open override val globalToWindowScaleX: Double
Link copied to clipboard
open override val globalToWindowScaleY: Double
Link copied to clipboard
Link copied to clipboard
open override val graphicExtensions: Set<String>
Link copied to clipboard
open override val isFloatTextureSupported: Boolean
Link copied to clipboard
open override val isInstancedSupported: Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val isVertexArraysSupported: Boolean
Link copied to clipboard
Link copied to clipboard

Allows to toggle whether stencil-based masks are enabled or not.

Link copied to clipboard
open override val parentFeatures: AGFeatures?
Link copied to clipboard
open override val pixelsPerCm: Double

Approximate on iOS

Link copied to clipboard
open override val pixelsPerInch: Double

Approximate on iOS

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Object storing all the rendering Stats like number of batches, number of vertices etc.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val views: Views?
Link copied to clipboard
open override val virtualBottom: Double
Link copied to clipboard
open override val virtualLeft: Double
Link copied to clipboard
open override val virtualRight: Double
Link copied to clipboard
open override val virtualTop: Double
Link copied to clipboard
Link copied to clipboard
open override var windowToGlobalMatrix: Matrix
Link copied to clipboard
open override val windowToGlobalScale: Scale
Link copied to clipboard
open override val windowToGlobalScaleAvg: Double
Link copied to clipboard
open override val windowToGlobalScaleX: Double
Link copied to clipboard
open override val windowToGlobalScaleY: Double
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
Link copied to clipboard
inline fun backupTexture(frameBuffer: AGFrameBuffer, tex: AGTexture?, callback: () -> Unit)
Link copied to clipboard
fun clear(color: RGBA = Colors.TRANSPARENT, depth: Float = 1.0f, stencil: Int = 0, clearColor: Boolean = true, clearDepth: Boolean = true, clearStencil: Boolean = true, scissor: AGScissor = AGScissor.NIL)
Link copied to clipboard
open override fun close()
Link copied to clipboard
Link copied to clipboard
inline fun doRender(frameBuffer: AGFrameBuffer = mainFrameBuffer, block: () -> Unit)
Link copied to clipboard
inline fun doRenderNew(frameBuffer: AGFrameBuffer = mainFrameBuffer, block: () -> Unit)
Link copied to clipboard
fun drawBitmap(frameBuffer: AGFrameBuffer, bmp: Bitmap, left: Float = -1f, top: Float = +1f, right: Float = +1f, bottom: Float = -1f)
Link copied to clipboard
fun drawBitmapXY(frameBuffer: AGFrameBuffer, bmp: Bitmap, x: Int, y: Int, scale: Float = 1.0f)
Link copied to clipboard
fun RenderContext.drawText(font: BitmapFont, textSize: Double, str: String, x: Int, y: Int, m: Matrix = Matrix.IDENTITY, colMul: RGBA = Colors.WHITE, blendMode: BlendMode = BlendMode.INHERIT, filtering: Boolean = true)
Link copied to clipboard
fun drawTexture(frameBuffer: AGFrameBuffer, tex: AGTexture, left: Float = -1f, top: Float = +1f, right: Float = +1f, bottom: Float = -1f)
Link copied to clipboard
fun finish()

Finishes the drawing and flips the screen. Called by the KorGe engine at the end of the frame.

Link copied to clipboard
fun flush(kind: RenderContext.FlushKind = FlushKind.FULL)

Flushes all the pending renderings. This is called automatically at the end of the frame. You should call this if you plan to render something else not managed via batch, so all the pending vertices are drawn.

Link copied to clipboard
operator fun <T : UniformBlock> get(uniformBlock: T): UniformBlockBuffer<T>
operator fun get(program: Program): AGProgramWithUniforms
Link copied to clipboard
Link copied to clipboard

Allocates a Texture.Base from a Bitmap. A Texture.Base doesn't have region information. It is just the whole texture/bitmap.

Temporarily allocates a Texture with its coords from a BmpSlice. Textures are managed (allocated and de-allocated) automatically by the engine as required. The texture coords matches the region in the BmpSlice.

Link copied to clipboard
open override fun globalToWindowBounds(bounds: Rectangle): Rectangle
Link copied to clipboard
open override fun globalToWindowCoords(pos: Point): Point
Link copied to clipboard
Link copied to clipboard
fun pushFrameBuffer(frameBuffer: AGFrameBuffer)
Link copied to clipboard
fun refGcCloseable(closeable: Closeable)

References a closeable for this frame that will be tracked in next frames. If after a period of time, this closeable has not been referenced in between frames, the Closeable.close method will be called so the object can be freed.

Link copied to clipboard
inline fun renderToBitmap(bmp: Bitmap32, hasDepth: Boolean = false, hasStencil: Boolean = false, msamples: Int = 1, useTexture: Boolean = true, callback: () -> Unit): Bitmap32

Sets the render buffer temporarily to bmp and calls the callback render method that should perform all the renderings inside.

inline fun renderToBitmap(width: Int, height: Int, hasDepth: Boolean = false, hasStencil: Boolean = false, msamples: Int = 1, callback: () -> Unit): Bitmap32
Link copied to clipboard
inline fun renderToFrameBuffer(frameBuffer: AGFrameBuffer, clear: Boolean = true, render: (AGFrameBuffer) -> Unit)
Link copied to clipboard
inline fun renderToTexture(width: Int, height: Int, render: (AGFrameBuffer) -> Unit = {}, hasDepth: Boolean = false, hasStencil: Boolean = true, msamples: Int = 1, use: (Texture) -> Unit)

Temporarily sets the render buffer to a temporal texture of the size width and height that can be used later in the use method. First the texture is created, then render method is called once the render buffer is set to the texture, and later the context is restored and the use method is called providing as first argument the rendered Texture. This method is useful for per-frame filters. If you plan to keep the texture data, consider using the renderToBitmap method.

Link copied to clipboard
inline fun renderToTextureInternal(width: Int, height: Int, render: (rb: AGFrameBuffer) -> Unit, hasDepth: Boolean = false, hasStencil: Boolean = false, msamples: Int = 1, use: (tex: AGTexture, texWidth: Int, texHeight: Int) -> Unit)
Link copied to clipboard
fun BoundsProvider.setBoundsInfo(reqVirtualSize: Size, actualSize: Size, scaleMode: ScaleMode = ScaleMode.FILL, anchor: Anchor = Anchor.CENTER, virtualSize: Ref<SizeInt> = Ref(), targetSize: Ref<SizeInt> = Ref())
Link copied to clipboard
Link copied to clipboard
inline fun setViewMatrixTemp(matrix: Matrix, crossinline callback: () -> Unit)

Executes callback while setting temporarily the view matrix to matrix

Link copied to clipboard
inline fun tempAllocateFrameBuffer(width: Int, height: Int, hasDepth: Boolean = false, hasStencil: Boolean = true, msamples: Int = 1, block: (rb: AGFrameBuffer) -> Unit)
Link copied to clipboard
inline fun tempAllocateFrameBuffers2(width: Int, height: Int, hasDepth: Boolean = false, hasStencil: Boolean = true, msamples: Int = 1, block: (rb0: AGFrameBuffer, rb1: AGFrameBuffer) -> Unit)
Link copied to clipboard
fun unsafeAllocateFrameBuffer(width: Int, height: Int, hasDepth: Boolean = false, hasStencil: Boolean = true, msamples: Int = 1, onlyThisFrame: Boolean = true): AGFrameBuffer
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
inline fun useBatcher(block: (BatchBuilder2D) -> Unit)
inline fun <T> useBatcher(batcher: T, block: (T) -> Unit)
Link copied to clipboard
inline fun useCtx2d(block: (RenderContext2D) -> Unit)
Link copied to clipboard
inline fun RenderContext.useLineBatcher(matrix: Matrix? = null, block: (LineRenderBatcher) -> Unit)
Link copied to clipboard
open override fun windowToGlobalCoords(pos: Point): Point