UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

71 lines (70 loc) 2.63 kB
/** * An object that renders a quad using a {@link Shader}. * * Note: QuadRender does not modify render states. Before calling {@link QuadRender#render}, * you should set up the required states using {@link GraphicsDevice#setDrawStates}, or the * individual setters ({@link GraphicsDevice#setBlendState}, {@link GraphicsDevice#setCullMode}, * {@link GraphicsDevice#setFrontFace}, {@link GraphicsDevice#setDepthState}, * {@link GraphicsDevice#setStencilState}). Otherwise previously set states will be used. * * Example: * * ```javascript * const shader = pc.ShaderUtils.createShader(app.graphicsDevice, { * uniqueName: 'MyShader', * attributes: { aPosition: SEMANTIC_POSITION }, * vertexGLSL: '// vertex shader code', * fragmentGLSL: '// fragment shader code' * }); * const quad = new QuadRender(shader); * * // Set up render states before rendering (defaults are suitable for full-screen quads) * app.graphicsDevice.setDrawStates(); * * quad.render(); * quad.destroy(); * ``` * * @category Graphics */ export class QuadRender { /** * Create a new QuadRender instance. * * @param {Shader} shader - The shader to be used to render the quad. */ constructor(shader: Shader); /** * @type {UniformBuffer} * @ignore */ uniformBuffer: UniformBuffer; /** * @type {BindGroup} * @ignore */ bindGroup: BindGroup; shader: Shader; /** * Destroys the resources associated with this instance. */ destroy(): void; /** * Renders the quad. If the viewport is provided, the original viewport and scissor is restored * after the rendering. * * @param {Vec4} [viewport] - The viewport rectangle of the quad, in pixels. The viewport is * not changed if not provided. * @param {Vec4} [scissor] - The scissor rectangle of the quad, in pixels. Used only if the * viewport is provided. * @param {number} [numInstances] - Number of instances to draw. When provided, renders * multiple quads using instanced drawing. Each instance can use the instance index * (`gl_InstanceID` in GLSL, `pcInstanceIndex` in WGSL) to fetch per-quad data from * a texture or buffer, allowing each quad to be parameterized independently. */ render(viewport?: Vec4, scissor?: Vec4, numInstances?: number): void; } import { UniformBuffer } from '../../platform/graphics/uniform-buffer.js'; import { BindGroup } from '../../platform/graphics/bind-group.js'; import type { Shader } from '../../platform/graphics/shader.js'; import { Vec4 } from '../../core/math/vec4.js';