Add more improvements
This commit is contained in:
parent
e1c74a8054
commit
bc16bdd62e
4 changed files with 286 additions and 158 deletions
|
|
@ -3,7 +3,7 @@ import { checkShader } from './check-shader';
|
|||
export const checkProgram = (gl: WebGL2RenderingContext, program: WebGLProgram) => {
|
||||
const success = gl.getProgramParameter(program, gl.LINK_STATUS);
|
||||
|
||||
if (!success) {
|
||||
if (!success && !gl.isContextLost()) {
|
||||
gl.getAttachedShaders(program)?.forEach((s) => {
|
||||
checkShader(gl, s);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
export const checkShader = (gl: WebGL2RenderingContext, shader: WebGLShader) => {
|
||||
const success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
||||
|
||||
if (!success) {
|
||||
if (!success && !gl.isContextLost()) {
|
||||
throw new Error(gl.getShaderInfoLog(shader)!);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,11 +7,8 @@ export const createProgram = (
|
|||
fragmentShaderSource: string,
|
||||
substitutions: { [name: string]: string }
|
||||
): WebGLProgram => {
|
||||
const program = gl.createProgram();
|
||||
|
||||
if (!program) {
|
||||
throw new Error('Could not create program');
|
||||
}
|
||||
// can only return null on lost context
|
||||
const program = gl.createProgram()!;
|
||||
|
||||
// const extension = tryEnableExtension(gl, 'KHR_parallel_shader_compile');
|
||||
|
||||
|
|
@ -43,5 +40,8 @@ export const createProgram = (
|
|||
|
||||
checkProgram(gl, program);
|
||||
|
||||
gl.deleteShader(vertexShader);
|
||||
gl.deleteShader(fragmentShader);
|
||||
|
||||
return program;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,11 +9,8 @@ export const createShader = (
|
|||
return Number.isInteger(value) ? `${value}.0` : value;
|
||||
});
|
||||
|
||||
const shader = gl.createShader(type);
|
||||
|
||||
if (!shader) {
|
||||
throw new Error('Could not create shader');
|
||||
}
|
||||
// can only return null on lost context
|
||||
const shader = gl.createShader(type)!;
|
||||
|
||||
gl.shaderSource(shader, source);
|
||||
gl.compileShader(shader);
|
||||
|
|
|
|||
Loading…
Reference in a new issue