UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

46 lines (43 loc) 1.42 kB
import { platform } from '../../core/platform.js'; import { Preprocessor } from '../../core/preprocessor.js'; import { ShaderUtils } from './shader-utils.js'; var id = 0; class Shader { init() { this.ready = false; this.failed = false; } get label() { return "Shader Id " + this.id + " " + this.name; } destroy() { this.device.onDestroyShader(this); this.impl.destroy(this); } loseContext() { this.init(); this.impl.loseContext(); } restoreContext() { this.impl.restoreContext(this.device, this); } constructor(graphicsDevice, definition){ this.id = id++; this.device = graphicsDevice; this.definition = definition; this.name = definition.name || 'Untitled'; this.init(); if (definition.cshader) ; else { var _definition; definition.vshader = Preprocessor.run(definition.vshader, definition.vincludes); var _attributes; (_attributes = (_definition = definition).attributes) != null ? _attributes : _definition.attributes = ShaderUtils.collectAttributes(definition.vshader); var stripUnusedColorAttachments = graphicsDevice.isWebGL2 && (platform.name === 'osx' || platform.name === 'ios'); definition.fshader = Preprocessor.run(definition.fshader, definition.fincludes, { stripUnusedColorAttachments }); } this.impl = graphicsDevice.createShaderImpl(this); } } export { Shader };