A 2D scene renderer.

Passed during Object.sync and Object.drawRec and can be accessed directly via Scene.renderer.

Constructor

new(scene:Scene)

Create a new RenderContext and attach it to specified Scene.

Parameters:

scene

The scene which RenderContext will render.

Variables

@:value(false)defaultSmooth:Bool = false

Internal usage

Determines texture filtering method (Linear or Nearest). Not recommended to use - assign Scene.defaultSmooth instead.

front2back:Bool

When enabled, causes Object to render its children in reverse order.

@:value(1.)globalAlpha:Float = 1.

Current transparency value used for rendering objects. Automatically managed by Object.

killAlpha:Bool

When enabled, pixels with alpha value below 0.001 will be discarded.

scene:Scene

The 2D scene attached to this RenderContext instance.

onBeginDraw:Drawable ‑> Bool

Sent before Drawable is rendered. Drawable won't be rendered if callback returns false.

onEnterFilter:Object ‑> Bool

Sent before filter begins rendering. Filter (and it's object tree) won't be rendered if callback returns false.

onLeaveFilter:Object ‑> Void

Send after filter has been rendered.

Methods

@:value({ filter : false })allocTarget(name:String, filter:Bool = false):Texture

Allocated a cached render target Texture with specified name, filter mode and current Scene.width and Scene.height.

Returns:

Either precached Texture under same name or newly allocated one.

beforeDraw():Void

Internal usage

Should be called before performing a new draw call in order to sync shader data and other parameters.

begin():Void

Internal usage

Prepares RenderContext to begin rendering a new frame.

@:access(h2d.Drawable)beginDrawBatchState(obj:Drawable):Bool

Prepares rendering with BatchState. Each state draw should be preceded with swapTexture call.

@:access(h2d.Drawable)beginDrawObject(obj:Drawable, texture:Texture):Bool

Prepares rendering of the Drawable object with specified texture.

Returns:

true if rendering is prepared, false otherwise (see RenderContext.onBeginDraw)

clear(color:Null<Int>):Void

Clears current render target with specified color.

clipRenderZone(x:Float, y:Float, w:Float, h:Float):Void

Pushes new render zone with respect to the old render zone settings by clipping new and old render zones, pushing the intersection area result. Used so that any call to the clipRenderZone respects the already set zone, and can't render outside of it.

drawScene():Void

Renders the assigned Scene. Same as s2d.drawRec(s2d.renderer).

@:access(h2d.Drawable)drawTile(obj:Drawable, tile:Tile):Bool

Renders a Tile with the transform of the given Drawable.

Returns:

true if tile was drawn, false otherwise. Tile is not drawn if it's either outside of the rendering area or was cancelled by RenderContext.onBeginDraw.

end():Void

Internal usage

Performers cleanup after frame is rendered.

getFilterScale(?into:Point):Null<Point>

Retrieves the current filter scale factor.

Parameters:

into

The 2D Point instance into which the scale is written. Creates a new Point if null.

Returns:

The current filter resolution scale or { 1, 1 } point.

popCamera():Void

Internal usage

Restores previous viewport state prior to camera rendering, removing it from the camera stack.

popFilter():Void

Internal usage

Finalizes Filter rendering and removes top-most Object from filter stack.

popRenderZone():Void

Restores previous render zone settings.

popTarget():Void

Pops current render target from the target stack. If last texture was removed from the stack, will restore the primary render buffer as a render target.

@:access(h2d.Camera)pushCamera(cam:Camera):Void

Internal usage

Applies Camera cam transform to current viewport and pushes it onto the camera stack. Should call RenderContext.popCamera when rendering is complete.

pushFilter(spr:Object):Bool

Internal usage

Prepares to render Filter and pushes provided Object onto filter stack.

Returns:

true if filter is allowed to render, false otherwise (see RenderContext.onEnterFilter)

pushRenderZone(x:Float, y:Float, w:Float, h:Float):Void

Sets rectangular render zone area, saving previous render zone settings. To respect previous render zone area, use RenderContext.clipRenderZone method.

RenderContext.popRenderZone should be called afterwards to clear render zone stack.

@:value({ height : -1, width : -1, startY : 0, startX : 0 })pushTarget(t:Texture, startX:Int = 0, startY:Int = 0, width:Int = -1, height:Int = -1):Void

Sets provided texture as a render target and pushes it onto target stack. If only part of the Texture should be rendered onto, method should be used with pushRenderZone() to avoid rendering outside specified texture area.

Parameters:

t

Texture to which RenderContext will render to. Texture should be allocated as a render target (have Target flag).

startX

X offset of rendering area on the Texture.

startY

Y offset of rendering area on the Texture.

width

Width of the clipping area on the Texture. If equals to -1, will use texture width.

height

Height of the clipping area on the Texture. If equals to -1 will use texture height.

pushTargets(texs:Array<Texture>):Void

Pushes an array of render targets onto target stack.

setFilterScale(scaleX:Float, scaleY:Float):Void

Internal usage

Sets the current filter texture resolution scale factor.

inlineswapTexture(texture:Texture):Void

Swap current active texture and prepares for next drawcall.

Inherited Variables

Inherited Methods

Defined by RenderContext

@:value({ opt : false })inlinegetParamValue(p:AllocParam, shaders:ShaderList, opt:Bool = false):Dynamic

setCurrent():Void