UNPKG

5.37 kBTypeScriptView Raw
1import { Matrix } from '@pixi/math';
2import type { ExtensionMetadata } from '@pixi/extensions';
3import type { Rectangle } from '@pixi/math';
4import type { Renderer } from '../Renderer';
5import type { ISystem } from '../system/ISystem';
6/**
7 * System plugin to the renderer to manage the projection matrix.
8 *
9 * The `projectionMatrix` is a global uniform provided to all shaders. It is used to transform points in world space to
10 * normalized device coordinates.
11 * @memberof PIXI
12 */
13export declare class ProjectionSystem implements ISystem {
14 /** @ignore */
15 static extension: ExtensionMetadata;
16 /**
17 * The destination frame used to calculate the current projection matrix.
18 *
19 * The destination frame is the rectangle in the render-target into which contents are rendered. If rendering
20 * to the screen, the origin is on the top-left. If rendering to a framebuffer, the origin is on the
21 * bottom-left. This "flipping" phenomenon is because of WebGL convention for (shader) texture coordinates, where
22 * the bottom-left corner is (0,0). It allows display-objects to map their (0,0) position in local-space (top-left)
23 * to (0,0) in texture space (bottom-left). In other words, a sprite's top-left corner actually renders the
24 * texture's bottom-left corner. You will also notice this when using a tool like SpectorJS to view your textures
25 * at runtime.
26 *
27 * The destination frame's dimensions (width,height) should be equal to the source frame. This is because,
28 * otherwise, the contents will be scaled to fill the destination frame. Similarly, the destination frame's (x,y)
29 * coordinates are (0,0) unless you know what you're doing.
30 * @readonly
31 */
32 destinationFrame: Rectangle;
33 /**
34 * The source frame used to calculate the current projection matrix.
35 *
36 * The source frame is the rectangle in world space containing the contents to be rendered.
37 * @readonly
38 */
39 sourceFrame: Rectangle;
40 /**
41 * Default destination frame
42 *
43 * This is not used internally. It is not advised to use this feature specifically unless you know what
44 * you're doing. The `update` method will default to this frame if you do not pass the destination frame.
45 * @readonly
46 */
47 defaultFrame: Rectangle;
48 /**
49 * Projection matrix
50 *
51 * This matrix can be used to transform points from world space to normalized device coordinates, and is calculated
52 * from the sourceFrame → destinationFrame mapping provided.
53 *
54 * The renderer's `globalUniforms` keeps a reference to this, and so it is available for all shaders to use as a
55 * uniform.
56 * @readonly
57 */
58 projectionMatrix: Matrix;
59 /**
60 * A transform to be appended to the projection matrix.
61 *
62 * This can be used to transform points in world-space one last time before they are outputted by the shader. You can
63 * use to rotate the whole scene, for example. Remember to clear it once you've rendered everything.
64 * @member {PIXI.Matrix}
65 */
66 transform: Matrix;
67 private renderer;
68 /** @param renderer - The renderer this System works for. */
69 constructor(renderer: Renderer);
70 /**
71 * Updates the projection-matrix based on the sourceFrame → destinationFrame mapping provided.
72 *
73 * NOTE: It is expected you call `renderer.framebuffer.setViewport(destinationFrame)` after this. This is because
74 * the framebuffer viewport converts shader vertex output in normalized device coordinates to window coordinates.
75 *
76 * NOTE-2: {@link PIXI.RenderTextureSystem#bind} updates the projection-matrix when you bind a render-texture.
77 * It is expected
78 * that you dirty the current bindings when calling this manually.
79 * @param destinationFrame - The rectangle in the render-target to render the contents into. If rendering to the canvas,
80 * the origin is on the top-left; if rendering to a render-texture, the origin is on the bottom-left.
81 * @param sourceFrame - The rectangle in world space that contains the contents being rendered.
82 * @param resolution - The resolution of the render-target, which is the ratio of
83 * world-space (or CSS) pixels to physical pixels.
84 * @param root - Whether the render-target is the screen. This is required because rendering to textures
85 * is y-flipped (i.e. upside down relative to the screen).
86 */
87 update(destinationFrame: Rectangle, sourceFrame: Rectangle, resolution: number, root: boolean): void;
88 /**
89 * Calculates the `projectionMatrix` to map points inside `sourceFrame` to inside `destinationFrame`.
90 * @param _destinationFrame - The destination frame in the render-target.
91 * @param sourceFrame - The source frame in world space.
92 * @param _resolution - The render-target's resolution, i.e. ratio of CSS to physical pixels.
93 * @param root - Whether rendering into the screen. Otherwise, if rendering to a framebuffer, the projection
94 * is y-flipped.
95 */
96 calculateProjection(_destinationFrame: Rectangle, sourceFrame: Rectangle, _resolution: number, root: boolean): void;
97 /**
98 * Sets the transform of the active render target to the given matrix.
99 * @param _matrix - The transformation matrix
100 */
101 setTransform(_matrix: Matrix): void;
102 destroy(): void;
103}