Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

renderer.plugins: WebGLPrepare, CanvasPrepare, BasePrepare, WebGLExtract #132

Merged
merged 2 commits into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions src/pixi/core/renderers/BasePrepare.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package pixi.core.renderers;
import haxe.Constraints.Function;
import pixi.core.display.Container;
import pixi.core.display.DisplayObject;
import pixi.core.graphics.Graphics;
import pixi.core.renderers.SystemRenderer;
import pixi.core.text.Text;
import pixi.core.textures.BaseTexture;
import pixi.core.textures.Texture;
import haxe.extern.EitherType;

typedef Uplodable =
EitherType<Text,
EitherType<Graphics,
EitherType<Texture,
EitherType<BaseTexture,
EitherType<Container,
DisplayObject
>>>>>;

/**
* The prepare manager provides functionality to upload content to the GPU.
* BasePrepare handles basic queuing functionality and is extended by PIXI.prepare.WebGLPrepare and PIXI.prepare.CanvasPrepare
* to provide preparation capabilities specific to their respective renderers.
*/
@:native("PIXI.prepare.BasePrepare")
extern class BasePrepare
{
/**
* Creates BasePrepare
* @param {PIXI.SystemRenderer} renderer - A reference to the current renderer
*/
public function new(renderer:SystemRenderer);


/**
* Manually add an item to the uploading queue.
* @param { PIXI.DisplayObject | PIXI.Container | PIXI.BaseTexture | PIXI.Texture | PIXI.Graphics | PIXI.Text } item Object to add to the queue
* @return {PIXI.CanvasPrepare | PIXI.WebGLPrepare} Instance of plugin for chaining.
*/
public function add(item:Uplodable):BasePrepare;

/**
* @deprecated since 4.4.2
*
* Register hooks
* @param { function } addHook - Function call that takes two parameters: item:*, queue:Array function must return true if it was able to add item to the queue.
* @param { function } uploadHook - Function call that takes two parameters: prepare:CanvasPrepare, item:* and function must return true if it was able to handle upload of item.
* @return {PIXI.CanvasPrepare | PIXI.WebGLPrepare} Instance of plugin for chaining.
*/
public function register(?addHoook:Function, ?uploadHook:Function):BasePrepare;


/**
* Register find hook
* @param { function } addHook - Function call that takes two parameters: item:*, queue:Array function must return true if it was able to add item to the queue.
* @return {PIXI.CanvasPrepare | PIXI.WebGLPrepare} Instance of plugin for chaining.
*/
public function registerFindHook(addHook:Function):BasePrepare;


/**
* Register upload hook
* @param { function } uploadHook - Function call that takes two parameters: prepare:CanvasPrepare, item:* and function must return true if it was able to handle upload of item.
* @return {PIXI.CanvasPrepare | PIXI.WebGLPrepare} Instance of plugin for chaining.
*/
public function registerUploadHook(uploadHook:Function):BasePrepare;

/**
* Upload all the textures and graphics to the GPU.
* @param { PIXI.DisplayObject | PIXI.Container | PIXI.BaseTexture | PIXI.Texture | PIXI.Graphics | PIXI.Text | * } Either the container or display object to search for items to upload, the items to upload themselves, or the callback function, if items have been added using prepare.add
* @param { function } done Optional callback when all queued uploads have completed
* @return {PIXI.CanvasPrepare | PIXI.WebGLPrepare} Instance of plugin for chaining.
*/
public function upload(?item:Uplodable, ?done:Void->Void):BasePrepare;



/**
* Destroys the plugin, don't use after this.
*/
public function destroy():Void;
}
32 changes: 32 additions & 0 deletions src/pixi/core/renderers/RendererPlugins.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package pixi.core.renderers;
import pixi.accessibility.AccessibilityManager;
import pixi.core.renderers.webgl.extract.WebGLExtract;
import pixi.interaction.InteractionManager;

/**
* Collection of installed plugins.
* These are included by default in PIXI, but can be excluded by creating a custom build.
* Consult the README for more information about creating custom builds and excluding plugins.
*/
extern class RendererPlugins implements Dynamic
{
/**
* Support tabbing interactive elements.
*/
public var accessibility:AccessibilityManager;

/**
* Extract image data from renderer.
*/
public var extract:WebGLExtract;

/**
* Handles mouse, touch and pointer events.
*/
public var interaction:InteractionManager;

/**
* Pre-render display objects.
*/
public var prepare:BasePrepare;
}
2 changes: 1 addition & 1 deletion src/pixi/core/renderers/SystemRenderer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ extern class SystemRenderer extends EventEmitter {
/**
* Plugins object
*/
var plugins:Dynamic;
var plugins:RendererPlugins;

/**
* Resizes the canvas view to the specified width and height
Expand Down
13 changes: 13 additions & 0 deletions src/pixi/core/renderers/canvas/utils/CanvasPrepare.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pixi.core.renderers.canvas.utils;
import pixi.core.renderers.canvas.CanvasRenderer;

/**
* The prepare manager provides functionality to upload content to the GPU.
* An instance of this class is automatically created by default, and can be found at renderer.plugins.prepare
*/
@:native("PIXI.prepare.CanvasPrepare")
extern class CanvasPrepare extends BasePrepare
{

}

64 changes: 64 additions & 0 deletions src/pixi/core/renderers/webgl/extract/WebGLExtract.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package pixi.core.renderers.webgl.extract;
import js.html.CanvasElement;
import js.html.ImageElement;
import js.html.Uint8ClampedArray;
import pixi.core.display.DisplayObject;
import pixi.core.renderers.webgl.WebGLRenderer;
import pixi.core.textures.RenderTexture;
import haxe.extern.EitherType;

/**
* The extract manager provides functionality to export content from the renderers.
*
* An instance of this class is automatically created by default, and can be found at renderer.plugins.extract
*/
@:native("PIXI.extract.WebGLExtract")
extern class WebGLExtract
{

/**
* Creates WebGLExtract
*
* @param {PIXI.WebGLRenderer} renderer - A reference to the current renderer
*/
public function new(renderer:WebGLRenderer);

/**
* Will return a a base64 encoded string of this target. It works by calling WebGLExtract.getCanvas and then running toDataURL on that.
*
* @param {PIXI.DisplayObject | PIXI.RenderTexture} target - A displayObject or renderTexture to convert. If left empty will use the main renderer
* @return {String} A base64 encoded string of the texture.
*/
public function base64(?target:EitherType<DisplayObject, RenderTexture>):String;

/**
* Creates a Canvas element, renders this target to it and then returns it.
*
* @param {PIXI.DisplayObject | PIXI.RenderTexture} target - A displayObject or renderTexture to convert. If left empty will use the main renderer
* @return {HTMLCanvasElement} A Canvas element with the texture rendered on.
*/
public function canvas(?target:EitherType<DisplayObject, RenderTexture>):CanvasElement;

/**
* Will return a HTML Image of the target
*
* @param {PIXI.DisplayObject | PIXI.RenderTexture} target - A displayObject or renderTexture to convert. If left empty will use the main renderer
* @return {HTMLImageElement} HTML Image of the target
*/
public function image(?target:EitherType<DisplayObject, RenderTexture>):ImageElement;

/**
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA order, with integer values between 0 and 255 (included).
*
* @param {PIXI.DisplayObject | PIXI.RenderTexture} target - A displayObject or renderTexture to convert. If left empty will use the main renderer
* @return {Uint8ClampedArray} One-dimensional array containing the pixel data of the entire texture
*/
public function pixels(?target:EitherType<DisplayObject, RenderTexture>):Uint8ClampedArray;

/**
* Destroys the extract
*/
public function destroy():Void;


}
14 changes: 14 additions & 0 deletions src/pixi/core/renderers/webgl/utils/WebGLPrepare.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package pixi.core.renderers.webgl.utils;
import pixi.core.renderers.BasePrepare;
import pixi.core.renderers.webgl.WebGLRenderer;

/**
* The prepare manager provides functionality to upload content to the GPU.
* An instance of this class is automatically created by default, and can be found at renderer.plugins.prepare
*/
@:native("PIXI.prepare.WebGLPrepare")
extern class WebGLPrepare extends BasePrepare
{

}