UNPKG

@lightningjs/renderer

Version:
51 lines 1.95 kB
/* * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: * * Copyright 2023 Comcast Cable Communications Management, LLC. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ //#endregion Types export function createShader(glw, type, source) { const shader = glw.createShader(type); if (!shader) { const glError = glw.getError(); throw new Error(`Unable to create the shader: ${type === glw.VERTEX_SHADER ? 'VERTEX_SHADER' : 'FRAGMENT_SHADER'}.${glError ? ` WebGlContext Error: ${glError}` : ''}`); } glw.shaderSource(shader, source); glw.compileShader(shader); const success = !!glw.getShaderParameter(shader, glw.COMPILE_STATUS); if (success) { return shader; } console.error(glw.getShaderInfoLog(shader)); glw.deleteShader(shader); } export function createProgram(glw, vertexShader, fragmentShader) { const program = glw.createProgram(); if (!program) { throw new Error('Unable to create program'); } glw.attachShader(program, vertexShader); glw.attachShader(program, fragmentShader); glw.linkProgram(program); const success = !!glw.getProgramParameter(program, glw.LINK_STATUS); if (success) { return program; } console.warn(glw.getProgramInfoLog(program)); glw.deleteProgram(program); return undefined; } //# sourceMappingURL=ShaderUtils.js.map