A 2D scene renderer.
Passed during Object.sync
and Object.drawRec
and can be accessed directly via Scene.renderer
.
Constructor
Variables
read onlycurrentCamera:Null<Camera> = null
The camera instance that is currently being rendered, if present, null
otherwise.
defaultSmooth:Bool = false
Determines texture filtering method (Linear or Nearest).
Not recommended to use - assign Scene.defaultSmooth
instead.
globalAlpha:Float = 1.
Current transparency value used for rendering objects.
Automatically managed by Object
.
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
.
Methods
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
Should be called before performing a new draw call in order to sync shader data and other parameters.
beginDrawBatchState(obj:Drawable):Bool
Prepares rendering with BatchState.
Each state draw should be preceded with swapTexture
call.
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
)
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.
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
.
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
Restores previous viewport state prior to camera rendering, removing it from the camera stack.
popFilter():Void
Finalizes Filter rendering and removes top-most Object from filter stack.
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.
pushCamera(cam:Camera):Void
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
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.
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 |
---|---|
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 |
height | Height of the clipping area on the Texture. If equals to |
setFilterScale(scaleX:Float, scaleY:Float):Void
Sets the current filter texture resolution scale factor.