setScissor method

void setScissor(
  1. int x,
  2. int y,
  3. int width,
  4. int height,
)

Enables and defines a scissor rectangle for clipping rendering.

When scissor testing is enabled, rendering is confined to the specified rectangular area of the canvas.

  • x: The x-coordinate of the lower-left corner of the scissor box.
  • y: The y-coordinate of the lower-left corner of the scissor box (origin at top-left of canvas).
  • width: The width of the scissor box.
  • height: The height of the scissor box.

Implementation

void setScissor(int x, int y, int width, int height) {
  flush();

  if (!_renderState.isScissorEnabled) {
    gl.enable(GL.SCISSOR_TEST);
    _renderState.isScissorEnabled = true;
  }

  final glY = _canvas.height - (y + height);
  gl.scissor(x, glY, width, height);
  _renderState.scissor.set(x, glY, width, height);
}