twgl.js 4.23.0 → 4.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/4.x/twgl-full.d.ts +0 -14
- package/dist/4.x/twgl-full.js +114 -62
- package/dist/4.x/twgl-full.module.js +90 -48
- package/dist/4.x/twgl.d.ts +0 -14
- package/dist/4.x/twgl.js +114 -62
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @license twgl.js 4.
|
|
1
|
+
/* @license twgl.js 4.24.0 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
|
|
2
2
|
Available via the MIT license.
|
|
3
3
|
see: http://github.com/greggman/twgl.js for details */
|
|
4
4
|
/*
|
|
@@ -2431,6 +2431,9 @@ function getNumElementsFromNonIndexedArrays(arrays) {
|
|
|
2431
2431
|
}
|
|
2432
2432
|
const array = arrays[key];
|
|
2433
2433
|
const length = getArray(array).length;
|
|
2434
|
+
if (length === undefined) {
|
|
2435
|
+
return 1; // There's no arrays
|
|
2436
|
+
}
|
|
2434
2437
|
const numComponents = getNumComponents(array, key);
|
|
2435
2438
|
const numElements = length / numComponents;
|
|
2436
2439
|
if (length % numComponents > 0) {
|
|
@@ -2456,6 +2459,9 @@ function getNumElementsFromAttributes(gl, attribs) {
|
|
|
2456
2459
|
key = Object.keys(attribs)[0];
|
|
2457
2460
|
}
|
|
2458
2461
|
const attrib = attribs[key];
|
|
2462
|
+
if (!attrib.buffer) {
|
|
2463
|
+
return 1; // There's no buffer
|
|
2464
|
+
}
|
|
2459
2465
|
gl.bindBuffer(ARRAY_BUFFER, attrib.buffer);
|
|
2460
2466
|
const numBytes = gl.getBufferParameter(ARRAY_BUFFER, BUFFER_SIZE);
|
|
2461
2467
|
gl.bindBuffer(ARRAY_BUFFER, null);
|
|
@@ -6088,6 +6094,7 @@ function loadAndUseImage(obj, crossOrigin, callback) {
|
|
|
6088
6094
|
* @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
|
|
6089
6095
|
* This is often the same options you passed in when you created the texture.
|
|
6090
6096
|
* @memberOf module:twgl/textures
|
|
6097
|
+
* @private
|
|
6091
6098
|
*/
|
|
6092
6099
|
function setTextureTo1PixelColor(gl, tex, options) {
|
|
6093
6100
|
options = options || defaults$1.textureOptions;
|
|
@@ -6197,6 +6204,7 @@ function loadTextureFromUrl(gl, tex, options, callback) {
|
|
|
6197
6204
|
* @param {module:twgl.CubemapReadyCallback} [callback] A function to be called when all the images have finished loading. err will
|
|
6198
6205
|
* be non null if there was an error.
|
|
6199
6206
|
* @memberOf module:twgl/textures
|
|
6207
|
+
* @private
|
|
6200
6208
|
*/
|
|
6201
6209
|
function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
6202
6210
|
callback = callback || noop;
|
|
@@ -6280,6 +6288,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
|
6280
6288
|
* @param {module:twgl.ThreeDReadyCallback} [callback] A function to be called when all the images have finished loading. err will
|
|
6281
6289
|
* be non null if there was an error.
|
|
6282
6290
|
* @memberOf module:twgl/textures
|
|
6291
|
+
* @private
|
|
6283
6292
|
*/
|
|
6284
6293
|
function loadSlicesFromUrls(gl, tex, options, callback) {
|
|
6285
6294
|
callback = callback || noop;
|
|
@@ -6858,6 +6867,7 @@ const typeMap = {};
|
|
|
6858
6867
|
|
|
6859
6868
|
/**
|
|
6860
6869
|
* Returns the corresponding bind point for a given sampler type
|
|
6870
|
+
* @private
|
|
6861
6871
|
*/
|
|
6862
6872
|
function getBindPointForSamplerType(gl, type) {
|
|
6863
6873
|
return typeMap[type].bindPoint;
|
|
@@ -7276,6 +7286,7 @@ const spaceRE = /^[ \t]*\n/;
|
|
|
7276
7286
|
*
|
|
7277
7287
|
* @param {string} shaderSource The source of the shader
|
|
7278
7288
|
* @returns {{shaderSource: string, lineOffset: number}}
|
|
7289
|
+
* @private
|
|
7279
7290
|
*/
|
|
7280
7291
|
function prepShaderSource(shaderSource) {
|
|
7281
7292
|
let lineOffset = 0;
|
|
@@ -7286,15 +7297,32 @@ function prepShaderSource(shaderSource) {
|
|
|
7286
7297
|
return {lineOffset, shaderSource};
|
|
7287
7298
|
}
|
|
7288
7299
|
|
|
7300
|
+
/**
|
|
7301
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
7302
|
+
* @param {string} msg
|
|
7303
|
+
* @return null
|
|
7304
|
+
* @private
|
|
7305
|
+
*/
|
|
7306
|
+
function reportError(progOptions, msg) {
|
|
7307
|
+
progOptions.errorCallback(msg);
|
|
7308
|
+
if (progOptions.callback) {
|
|
7309
|
+
setTimeout(() => {
|
|
7310
|
+
progOptions.callback(`${msg}\n${progOptions.errors.join('\n')}`);
|
|
7311
|
+
});
|
|
7312
|
+
}
|
|
7313
|
+
return null;
|
|
7314
|
+
}
|
|
7315
|
+
|
|
7289
7316
|
/**
|
|
7290
7317
|
* Loads a shader.
|
|
7291
7318
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
7292
7319
|
* @param {string} shaderSource The shader source.
|
|
7293
7320
|
* @param {number} shaderType The type of shader.
|
|
7321
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
7294
7322
|
* @return {WebGLShader} The created shader.
|
|
7295
7323
|
* @private
|
|
7296
7324
|
*/
|
|
7297
|
-
function loadShader(gl, shaderSource, shaderType) {
|
|
7325
|
+
function loadShader(gl, shaderSource, shaderType, progOptions) {
|
|
7298
7326
|
// Create the shader object
|
|
7299
7327
|
const shader = gl.createShader(shaderType);
|
|
7300
7328
|
|
|
@@ -7304,15 +7332,22 @@ function loadShader(gl, shaderSource, shaderType) {
|
|
|
7304
7332
|
// Compile the shader
|
|
7305
7333
|
gl.compileShader(shader);
|
|
7306
7334
|
|
|
7335
|
+
if (!progOptions.callback && !checkShaderStatus(gl, shaderType, shader, progOptions.errorCallback)) {
|
|
7336
|
+
gl.deleteShader(shader);
|
|
7337
|
+
return null;
|
|
7338
|
+
}
|
|
7339
|
+
|
|
7307
7340
|
return shader;
|
|
7308
7341
|
}
|
|
7309
7342
|
|
|
7310
7343
|
/**
|
|
7311
7344
|
* Check Shader status
|
|
7312
7345
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
7346
|
+
* @param {number} shaderType The shader type
|
|
7313
7347
|
* @param {WebGLShader} shader The shader
|
|
7314
7348
|
* @param {ErrorCallback} [errFn] function to receive error message.
|
|
7315
|
-
* @
|
|
7349
|
+
* @return {bool} true if shader is ok.
|
|
7350
|
+
* @private
|
|
7316
7351
|
*/
|
|
7317
7352
|
function checkShaderStatus(gl, shaderType, shader, errFn) {
|
|
7318
7353
|
errFn = errFn || error$1;
|
|
@@ -7321,7 +7356,6 @@ function checkShaderStatus(gl, shaderType, shader, errFn) {
|
|
|
7321
7356
|
if (!compiled) {
|
|
7322
7357
|
// Something went wrong during compilation; get the error
|
|
7323
7358
|
const lastError = gl.getShaderInfoLog(shader);
|
|
7324
|
-
const shaderType = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
7325
7359
|
const {lineOffset, shaderSource} = prepShaderSource(gl.getShaderSource(shader));
|
|
7326
7360
|
errFn(`${addLineNumbersWithError(shaderSource, lastError, lineOffset)}\nError compiling ${glEnumToString(gl, shaderType)}: ${lastError}`);
|
|
7327
7361
|
}
|
|
@@ -7363,7 +7397,7 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
7363
7397
|
} else if (opt_attribs && !Array.isArray(opt_attribs)) {
|
|
7364
7398
|
// If we have an errorCallback we can just return this object
|
|
7365
7399
|
// Otherwise we need to construct one with default errorCallback
|
|
7366
|
-
if (opt_attribs.errorCallback) {
|
|
7400
|
+
if (opt_attribs.errorCallback && opt_attribs.errors) {
|
|
7367
7401
|
return opt_attribs;
|
|
7368
7402
|
}
|
|
7369
7403
|
const opt = opt_attribs;
|
|
@@ -7374,11 +7408,17 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
7374
7408
|
callback = opt.callback;
|
|
7375
7409
|
}
|
|
7376
7410
|
|
|
7411
|
+
const errorCallback = opt_errorCallback || error$1;
|
|
7412
|
+
const errors = [];
|
|
7377
7413
|
const options = {
|
|
7378
|
-
errorCallback
|
|
7414
|
+
errorCallback(msg, ...args) {
|
|
7415
|
+
errors.push(msg);
|
|
7416
|
+
errorCallback(msg, ...args);
|
|
7417
|
+
},
|
|
7379
7418
|
transformFeedbackVaryings,
|
|
7380
7419
|
transformFeedbackMode,
|
|
7381
7420
|
callback,
|
|
7421
|
+
errors,
|
|
7382
7422
|
};
|
|
7383
7423
|
|
|
7384
7424
|
if (opt_attribs) {
|
|
@@ -7420,7 +7460,7 @@ const wait = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));
|
|
|
7420
7460
|
|
|
7421
7461
|
/**
|
|
7422
7462
|
* Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
|
|
7423
|
-
* program
|
|
7463
|
+
* program.
|
|
7424
7464
|
*
|
|
7425
7465
|
* NOTE: There are 4 signatures for this function
|
|
7426
7466
|
*
|
|
@@ -7435,7 +7475,7 @@ const wait = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));
|
|
|
7435
7475
|
* @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
|
|
7436
7476
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
7437
7477
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
7438
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
7478
|
+
* @return {WebGLProgram?} the created program or null if error of a callback was provided.
|
|
7439
7479
|
* @memberOf module:twgl/programs
|
|
7440
7480
|
*/
|
|
7441
7481
|
function createProgram(
|
|
@@ -7454,11 +7494,7 @@ function createProgram(
|
|
|
7454
7494
|
if (elem && elem.type) {
|
|
7455
7495
|
type = getShaderTypeFromScriptType(gl, elem.type) || type;
|
|
7456
7496
|
}
|
|
7457
|
-
shader = loadShader(gl, src, type);
|
|
7458
|
-
if (!progOptions.callback && !checkShaderStatus(gl, shader, opt_errorCallback)) {
|
|
7459
|
-
gl.deleteShader(shader);
|
|
7460
|
-
shader = null;
|
|
7461
|
-
}
|
|
7497
|
+
shader = loadShader(gl, src, type, progOptions);
|
|
7462
7498
|
newShaders.push(shader);
|
|
7463
7499
|
}
|
|
7464
7500
|
if (isShader(gl, shader)) {
|
|
@@ -7467,9 +7503,8 @@ function createProgram(
|
|
|
7467
7503
|
}
|
|
7468
7504
|
|
|
7469
7505
|
if (realShaders.length !== shaders.length) {
|
|
7470
|
-
progOptions.errorCallback("not enough shaders for program");
|
|
7471
7506
|
deleteShaders(gl, newShaders);
|
|
7472
|
-
return
|
|
7507
|
+
return reportError(progOptions, "not enough shaders for program");
|
|
7473
7508
|
}
|
|
7474
7509
|
|
|
7475
7510
|
const program = gl.createProgram();
|
|
@@ -7535,7 +7570,7 @@ function createProgramAsync(gl, shaders, ...args) {
|
|
|
7535
7570
|
resolve(program);
|
|
7536
7571
|
}
|
|
7537
7572
|
};
|
|
7538
|
-
|
|
7573
|
+
createProgram(gl, shaders, programOptions);
|
|
7539
7574
|
});
|
|
7540
7575
|
}
|
|
7541
7576
|
|
|
@@ -7563,7 +7598,7 @@ function createProgramInfoAsync(gl, shaders, ...args) {
|
|
|
7563
7598
|
resolve(programInfo);
|
|
7564
7599
|
}
|
|
7565
7600
|
};
|
|
7566
|
-
|
|
7601
|
+
createProgramInfo(gl, shaders, programOptions);
|
|
7567
7602
|
});
|
|
7568
7603
|
}
|
|
7569
7604
|
|
|
@@ -7575,6 +7610,7 @@ function createProgramInfoAsync(gl, shaders, ...args) {
|
|
|
7575
7610
|
* @param {WebGLRenderingContext} gl The context
|
|
7576
7611
|
* @param {WebGLProgram} program The program
|
|
7577
7612
|
* @param {module:twgl.ProgramOptions} progOptions Options for the program or an array of attribs names or an error callback. Locations will be assigned by index if not passed in
|
|
7613
|
+
* @private
|
|
7578
7614
|
*/
|
|
7579
7615
|
async function checkForProgramLinkCompletionAsync(gl, program, progOptions) {
|
|
7580
7616
|
const ext = gl.getExtension('KHR_parallel_shader_compile');
|
|
@@ -7588,9 +7624,8 @@ async function checkForProgramLinkCompletionAsync(gl, program, progOptions) {
|
|
|
7588
7624
|
waitTime = 1000 / 60;
|
|
7589
7625
|
} while (!checkFn(gl, program));
|
|
7590
7626
|
|
|
7591
|
-
const
|
|
7592
|
-
const
|
|
7593
|
-
const err = success ? undefined : errMsgs.join('\n');
|
|
7627
|
+
const success = checkProgramStatus(gl, program, progOptions.errorCallback);
|
|
7628
|
+
const err = success ? undefined : progOptions.errors.join('\n');
|
|
7594
7629
|
if (!success) {
|
|
7595
7630
|
const errFn = progOptions.errorCallback || error$1;
|
|
7596
7631
|
errFn(err);
|
|
@@ -7608,6 +7643,7 @@ async function checkForProgramLinkCompletionAsync(gl, program, progOptions) {
|
|
|
7608
7643
|
* @param {WebGLProgram} program Program to check
|
|
7609
7644
|
* @param {ErrorCallback} [errFn] func for errors
|
|
7610
7645
|
* @return {bool} true if program is ok
|
|
7646
|
+
* @private
|
|
7611
7647
|
*/
|
|
7612
7648
|
function checkProgramStatus(gl, program, errFn) {
|
|
7613
7649
|
errFn = errFn || error$1;
|
|
@@ -7616,15 +7652,7 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
7616
7652
|
if (!linked) {
|
|
7617
7653
|
// something went wrong with the link
|
|
7618
7654
|
const lastError = gl.getProgramInfoLog(program);
|
|
7619
|
-
errFn(
|
|
7620
|
-
gl.getAttachedShaders(program).map(shader => {
|
|
7621
|
-
const {lineOffset, shaderSource} = prepShaderSource(gl.getShaderSource(shader));
|
|
7622
|
-
const shaderError = gl.getShaderInfoLog(shader);
|
|
7623
|
-
const src = addLineNumbersWithError(shaderSource, shaderError, lineOffset);
|
|
7624
|
-
const type = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
7625
|
-
return `${glEnumToString(gl, type)}\n${src}}`;
|
|
7626
|
-
}).join('\n')
|
|
7627
|
-
}\nError in program linking: ${lastError}`);
|
|
7655
|
+
errFn(`Error in program linking: ${lastError}`);
|
|
7628
7656
|
}
|
|
7629
7657
|
return linked;
|
|
7630
7658
|
}
|
|
@@ -7635,25 +7663,25 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
7635
7663
|
* @param {string} scriptId The id of the script tag.
|
|
7636
7664
|
* @param {number} [opt_shaderType] The type of shader. If not passed in it will
|
|
7637
7665
|
* be derived from the type of the script tag.
|
|
7638
|
-
* @param {module:twgl.
|
|
7666
|
+
* @param {module:twgl.ProgramOptions} [progOptions] callback for errors.
|
|
7639
7667
|
* @return {WebGLShader?} The created shader or null if error.
|
|
7640
7668
|
* @private
|
|
7641
7669
|
*/
|
|
7642
7670
|
function createShaderFromScript(
|
|
7643
|
-
gl, scriptId, opt_shaderType,
|
|
7671
|
+
gl, scriptId, opt_shaderType, progOptions) {
|
|
7644
7672
|
let shaderSource = "";
|
|
7645
7673
|
const shaderScript = getElementById(scriptId);
|
|
7646
7674
|
if (!shaderScript) {
|
|
7647
|
-
|
|
7675
|
+
return reportError(progOptions, `unknown script element: ${scriptId}`);
|
|
7648
7676
|
}
|
|
7649
7677
|
shaderSource = shaderScript.text;
|
|
7650
7678
|
|
|
7651
7679
|
const shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
|
|
7652
7680
|
if (!shaderType) {
|
|
7653
|
-
|
|
7681
|
+
return reportError(progOptions, 'unknown shader type');
|
|
7654
7682
|
}
|
|
7655
7683
|
|
|
7656
|
-
return loadShader(gl, shaderSource, shaderType);
|
|
7684
|
+
return loadShader(gl, shaderSource, shaderType, progOptions);
|
|
7657
7685
|
}
|
|
7658
7686
|
|
|
7659
7687
|
/**
|
|
@@ -7675,7 +7703,7 @@ function createShaderFromScript(
|
|
|
7675
7703
|
* @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
|
|
7676
7704
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
7677
7705
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
7678
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
7706
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
7679
7707
|
* @memberOf module:twgl/programs
|
|
7680
7708
|
*/
|
|
7681
7709
|
function createProgramFromScripts(
|
|
@@ -7684,7 +7712,7 @@ function createProgramFromScripts(
|
|
|
7684
7712
|
const shaders = [];
|
|
7685
7713
|
for (let ii = 0; ii < shaderScriptIds.length; ++ii) {
|
|
7686
7714
|
const shader = createShaderFromScript(
|
|
7687
|
-
gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions
|
|
7715
|
+
gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions);
|
|
7688
7716
|
if (!shader) {
|
|
7689
7717
|
return null;
|
|
7690
7718
|
}
|
|
@@ -7712,7 +7740,7 @@ function createProgramFromScripts(
|
|
|
7712
7740
|
* @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
|
|
7713
7741
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
7714
7742
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
7715
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
7743
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
7716
7744
|
* @memberOf module:twgl/programs
|
|
7717
7745
|
*/
|
|
7718
7746
|
function createProgramFromSources(
|
|
@@ -7720,9 +7748,8 @@ function createProgramFromSources(
|
|
|
7720
7748
|
const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
|
|
7721
7749
|
const shaders = [];
|
|
7722
7750
|
for (let ii = 0; ii < shaderSources.length; ++ii) {
|
|
7723
|
-
const shader = loadShader(
|
|
7724
|
-
|
|
7725
|
-
if (!shader) {
|
|
7751
|
+
const shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions);
|
|
7752
|
+
if (!progOptions.callback && !shader) {
|
|
7726
7753
|
return null;
|
|
7727
7754
|
}
|
|
7728
7755
|
shaders.push(shader);
|
|
@@ -8633,6 +8660,7 @@ function createAttributeSetters(gl, program) {
|
|
|
8633
8660
|
* @param {Object.<string, module:twgl.AttribInfo>} buffers AttribInfos mapped by attribute name.
|
|
8634
8661
|
* @memberOf module:twgl/programs
|
|
8635
8662
|
* @deprecated use {@link module:twgl.setBuffersAndAttributes}
|
|
8663
|
+
* @private
|
|
8636
8664
|
*/
|
|
8637
8665
|
function setAttributes(setters, buffers) {
|
|
8638
8666
|
for (const name in buffers) {
|
|
@@ -8786,10 +8814,7 @@ function createProgramInfo(
|
|
|
8786
8814
|
return source;
|
|
8787
8815
|
});
|
|
8788
8816
|
if (errors.length) {
|
|
8789
|
-
|
|
8790
|
-
progOptions.callback(errors.join('\n'));
|
|
8791
|
-
}
|
|
8792
|
-
return null;
|
|
8817
|
+
return reportError(progOptions, '');
|
|
8793
8818
|
}
|
|
8794
8819
|
const origCallback = progOptions.callback;
|
|
8795
8820
|
if (origCallback) {
|
|
@@ -8803,7 +8828,6 @@ function createProgramInfo(
|
|
|
8803
8828
|
}
|
|
8804
8829
|
const program = createProgramFromSources(gl, shaderSources, progOptions);
|
|
8805
8830
|
if (!program) {
|
|
8806
|
-
// we should never get if if we have a callback
|
|
8807
8831
|
return null;
|
|
8808
8832
|
}
|
|
8809
8833
|
return createProgramInfoFromProgram(gl, program);
|
|
@@ -9122,6 +9146,12 @@ function isRenderbufferFormat(format) {
|
|
|
9122
9146
|
return renderbufferFormats[format];
|
|
9123
9147
|
}
|
|
9124
9148
|
|
|
9149
|
+
const MAX_COLOR_ATTACHMENT_POINTS = 32; // even an 3090 only supports 8 but WebGL/OpenGL ES define constants for 32
|
|
9150
|
+
|
|
9151
|
+
function isColorAttachmentPoint(attachmentPoint) {
|
|
9152
|
+
return attachmentPoint >= COLOR_ATTACHMENT0 && attachmentPoint < COLOR_ATTACHMENT0 + MAX_COLOR_ATTACHMENT_POINTS;
|
|
9153
|
+
}
|
|
9154
|
+
|
|
9125
9155
|
/**
|
|
9126
9156
|
* @typedef {Object} FramebufferInfo
|
|
9127
9157
|
* @property {WebGLFramebuffer} framebuffer The WebGLFramebuffer for this framebufferInfo
|
|
@@ -9135,6 +9165,9 @@ function isRenderbufferFormat(format) {
|
|
|
9135
9165
|
* Creates a framebuffer and attachments.
|
|
9136
9166
|
*
|
|
9137
9167
|
* This returns a {@link module:twgl.FramebufferInfo} because it needs to return the attachments as well as the framebuffer.
|
|
9168
|
+
* It also leaves the framebuffer it just created as the currently bound `FRAMEBUFFER`.
|
|
9169
|
+
* Note: If this is WebGL2 or if you called {@link module:twgl.addExtensionsToContext} then it will set the drawBuffers
|
|
9170
|
+
* to `[COLOR_ATTACHMENT0, COLOR_ATTACHMENT1, ...]` for how ever many color attachments were created.
|
|
9138
9171
|
*
|
|
9139
9172
|
* The simplest usage
|
|
9140
9173
|
*
|
|
@@ -9174,20 +9207,24 @@ function createFramebufferInfo(gl, attachments, width, height) {
|
|
|
9174
9207
|
width = width || gl.drawingBufferWidth;
|
|
9175
9208
|
height = height || gl.drawingBufferHeight;
|
|
9176
9209
|
attachments = attachments || defaultAttachments;
|
|
9177
|
-
|
|
9210
|
+
const usedColorAttachmentsPoints = [];
|
|
9178
9211
|
const framebufferInfo = {
|
|
9179
9212
|
framebuffer: fb,
|
|
9180
9213
|
attachments: [],
|
|
9181
9214
|
width: width,
|
|
9182
9215
|
height: height,
|
|
9183
9216
|
};
|
|
9184
|
-
|
|
9217
|
+
|
|
9218
|
+
attachments.forEach(function(attachmentOptions, i) {
|
|
9185
9219
|
let attachment = attachmentOptions.attachment;
|
|
9186
9220
|
const samples = attachmentOptions.samples;
|
|
9187
9221
|
const format = attachmentOptions.format;
|
|
9188
9222
|
let attachmentPoint = attachmentOptions.attachmentPoint || getAttachmentPointForFormat(format, attachmentOptions.internalFormat);
|
|
9189
9223
|
if (!attachmentPoint) {
|
|
9190
|
-
attachmentPoint = COLOR_ATTACHMENT0 +
|
|
9224
|
+
attachmentPoint = COLOR_ATTACHMENT0 + i;
|
|
9225
|
+
}
|
|
9226
|
+
if (isColorAttachmentPoint(attachmentPoint)) {
|
|
9227
|
+
usedColorAttachmentsPoints.push(attachmentPoint);
|
|
9191
9228
|
}
|
|
9192
9229
|
if (!attachment) {
|
|
9193
9230
|
if (samples !== undefined || isRenderbufferFormat(format)) {
|
|
@@ -9235,6 +9272,9 @@ function createFramebufferInfo(gl, attachments, width, height) {
|
|
|
9235
9272
|
}
|
|
9236
9273
|
framebufferInfo.attachments.push(attachment);
|
|
9237
9274
|
});
|
|
9275
|
+
if (gl.drawBuffers) {
|
|
9276
|
+
gl.drawBuffers(usedColorAttachmentsPoints);
|
|
9277
|
+
}
|
|
9238
9278
|
return framebufferInfo;
|
|
9239
9279
|
}
|
|
9240
9280
|
|
|
@@ -9764,6 +9804,8 @@ function create3DContext(canvas, opt_attribs) {
|
|
|
9764
9804
|
* @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes
|
|
9765
9805
|
* @return {WebGLRenderingContext} The created context.
|
|
9766
9806
|
* @memberOf module:twgl
|
|
9807
|
+
* @deprecated
|
|
9808
|
+
* @private
|
|
9767
9809
|
*/
|
|
9768
9810
|
function getWebGLContext(canvas, opt_attribs) {
|
|
9769
9811
|
const gl = create3DContext(canvas, opt_attribs);
|
package/dist/4.x/twgl.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export type Defaults = {
|
|
|
7
7
|
};
|
|
8
8
|
export function setDefaults(newDefaults: Defaults): void;
|
|
9
9
|
export function addExtensionsToContext(gl: WebGLRenderingContext): void;
|
|
10
|
-
export function getWebGLContext(canvas: HTMLCanvasElement, opt_attribs?: WebGLContextAttributes): WebGLRenderingContext;
|
|
11
10
|
export function createContext(canvas: HTMLCanvasElement): WebGLRenderingContext;
|
|
12
11
|
export function getContext(canvas: HTMLCanvasElement, opt_attribs?: WebGLContextAttributes): WebGLRenderingContext;
|
|
13
12
|
export function resizeCanvasToDisplaySize(canvas: HTMLCanvasElement, multiplier?: number): boolean;
|
|
@@ -256,15 +255,10 @@ export function resizeFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo
|
|
|
256
255
|
export function bindFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo?: FramebufferInfo | null, target?: number): void;
|
|
257
256
|
|
|
258
257
|
|
|
259
|
-
export function getBindPointForSamplerType(): void;
|
|
260
258
|
export type ProgramCallback = (err?: string, result?: WebGLProgram | ProgramInfo) => void;
|
|
261
|
-
export function prepShaderSource(shaderSource: string): any;
|
|
262
|
-
export function checkShaderStatus(gl: WebGLRenderingContext, shader: WebGLShader, errFn?: ErrorCallback): boolean;
|
|
263
259
|
export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
|
|
264
260
|
export function createProgramAsync(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<WebGLProgram>;
|
|
265
261
|
export function createProgramInfoAsync(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<ProgramInfo>;
|
|
266
|
-
export function checkForProgramLinkCompletionAsync(gl: WebGLRenderingContext, program: WebGLProgram, progOptions: ProgramOptions): void;
|
|
267
|
-
export function checkProgramStatus(gl: WebGLRenderingContext, program: WebGLProgram, errFn?: ErrorCallback): boolean;
|
|
268
262
|
export function createProgramFromScripts(gl: WebGLRenderingContext, shaderScriptIds: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
|
|
269
263
|
export function createProgramFromSources(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
|
|
270
264
|
export function createUniformSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
|
|
@@ -291,11 +285,6 @@ export function setUniformsAndBindTextures(setters: ProgramInfo | {
|
|
|
291
285
|
export function createAttributeSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
|
|
292
286
|
[key: string]: (...params: any[]) => any;
|
|
293
287
|
};
|
|
294
|
-
export function setAttributes(setters: {
|
|
295
|
-
[key: string]: (...params: any[]) => any;
|
|
296
|
-
}, buffers: {
|
|
297
|
-
[key: string]: AttribInfo;
|
|
298
|
-
}): void;
|
|
299
288
|
export function setBuffersAndAttributes(gl: WebGLRenderingContext, setters: ProgramInfo | {
|
|
300
289
|
[key: string]: (...params: any[]) => any;
|
|
301
290
|
}, buffers: BufferInfo | VertexArrayInfo): void;
|
|
@@ -317,10 +306,7 @@ export function setTextureParameters(gl: WebGLRenderingContext, tex: WebGLTextur
|
|
|
317
306
|
export function setSamplerParameters(gl: WebGLRenderingContext, sampler: WebGLSampler, options: TextureOptions): void;
|
|
318
307
|
export function setTextureFilteringForSize(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, width?: number, height?: number, internalFormat?: number): void;
|
|
319
308
|
export function setTextureFromElement(gl: WebGLRenderingContext, tex: WebGLTexture, element: HTMLElement, options?: TextureOptions): void;
|
|
320
|
-
export function setTextureTo1PixelColor(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions): void;
|
|
321
309
|
export function loadTextureFromUrl(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, callback?: TextureReadyCallback): HTMLImageElement;
|
|
322
|
-
export function loadCubemapFromUrls(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, callback?: CubemapReadyCallback): void;
|
|
323
|
-
export function loadSlicesFromUrls(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, callback?: ThreeDReadyCallback): void;
|
|
324
310
|
export function setTextureFromArray(gl: WebGLRenderingContext, tex: WebGLTexture, src: number[] | ArrayBufferView, options?: TextureOptions): void;
|
|
325
311
|
export function setEmptyTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions): void;
|
|
326
312
|
export function createTexture(gl: WebGLRenderingContext, options?: TextureOptions, callback?: TextureReadyCallback): WebGLTexture;
|