UNPKG

ts-game-engine

Version:

Simple WebGL game/render engine written in TypeScript

39 lines (38 loc) 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const BaseSystem_1 = require("../BaseSystem"); const PipelineState_1 = require("./PipelineState"); class GraphicsSystem extends BaseSystem_1.BaseSystem { constructor(canvas) { super(); this.canvas = canvas; // Get the context let context = this.canvas.getContext("webgl2", { antialias: true }); if (context === null) throw new Error("WebGL context not supported."); this.context = context; this.pipelineState = new PipelineState_1.PipelineState(this.context); this.width = this.canvas.clientWidth; this.height = this.canvas.clientHeight; this.aspectRatio = this.width / this.height; } get Canvas() { return this.canvas; } get Context() { return this.context; } get PipelineState() { return this.pipelineState; } get Width() { return this.width; } get Height() { return this.height; } get AspectRatio() { return this.aspectRatio; } Resize(width, height) { this.width = width; this.height = height; this.aspectRatio = width / height; const widthWithPixelRation = width * window.devicePixelRatio; const heightWithPixelRation = height * window.devicePixelRatio; this.canvas.width = widthWithPixelRation; this.canvas.height = heightWithPixelRation; this.context.viewport(0, 0, widthWithPixelRation, heightWithPixelRation); } Dispose() { } } exports.GraphicsSystem = GraphicsSystem;