Skip to content

Commit

Permalink
Fixes some WebGL types (#4197)
Browse files Browse the repository at this point in the history
* WebGLUniformLocation and others

* WebglShader#_processError: Untyped array -> typed tuple

* `WebglGraphicsDevice#setFramebuffer()` can be called with null

* Remove `@ts-ignore`
  • Loading branch information
kungfooman committed Jun 21, 2022
1 parent 307d8fc commit e0d6dc4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/graphics/shader-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ShaderInput {
* @param {GraphicsDevice} graphicsDevice - The graphics device used to manage this shader input.
* @param {string} name - The name of the shader input.
* @param {number} type - The type of the shader input.
* @param {number} locationId - The location id of the shader input.
* @param {number | WebGLUniformLocation} locationId - The location id of the shader input.
*/
constructor(graphicsDevice, name, type, locationId) {
// Set the shader attribute location
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/webgl/webgl-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ class WebglGraphicsDevice extends GraphicsDevice {
/**
* Binds the specified framebuffer object.
*
* @param {WebGLFramebuffer} fb - The framebuffer to bind.
* @param {WebGLFramebuffer | null} fb - The framebuffer to bind.
* @ignore
*/
setFramebuffer(fb) {
Expand Down
13 changes: 7 additions & 6 deletions src/graphics/webgl/webgl-shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Preprocessor } from '../../core/preprocessor.js';
import { ShaderInput } from '../shader-input.js';
import { SHADERTAG_MATERIAL, semanticToLocation } from '../constants.js';

/** @typedef {import('../graphics-device.js').GraphicsDevice} GraphicsDevice */
/** @typedef {import('./webgl-graphics-device.js').WebglGraphicsDevice} WebglGraphicsDevice */
/** @typedef {import('../shader.js').Shader} Shader */

/**
Expand Down Expand Up @@ -34,6 +34,7 @@ class WebglShader {
* @param {Shader} shader - The shader to free.
*/
destroy(shader) {
/** @type {WebglGraphicsDevice} */
const device = shader.device;
const idx = device.shaders.indexOf(shader);
if (idx !== -1) {
Expand All @@ -50,7 +51,7 @@ class WebglShader {
/**
* Restore shader after the context has been obtained.
*
* @param {GraphicsDevice} device - The graphics device.
* @param {WebglGraphicsDevice} device - The graphics device.
* @param {Shader} shader - The shader to restore.
*/
restoreContext(device, shader) {
Expand All @@ -60,7 +61,7 @@ class WebglShader {
/**
* Compile and link a shader program.
*
* @param {GraphicsDevice} device - The graphics device.
* @param {WebglGraphicsDevice} device - The graphics device.
* @param {Shader} shader - The shader to compile.
*/
compileAndLink(device, shader) {
Expand Down Expand Up @@ -173,7 +174,7 @@ class WebglShader {
/**
* Extract attribute and uniform information from a successfully linked shader.
*
* @param {GraphicsDevice} device - The graphics device.
* @param {WebglGraphicsDevice} device - The graphics device.
* @param {Shader} shader - The shader to query.
* @returns {boolean} True if the shader was successfully queried and false otherwise.
*/
Expand Down Expand Up @@ -265,7 +266,7 @@ class WebglShader {
/**
* Check the compilation status of a shader.
*
* @param {GraphicsDevice} device - The graphics device.
* @param {WebglGraphicsDevice} device - The graphics device.
* @param {Shader} shader - The shader to query.
* @param {WebGLShader} glShader - The WebGL shader.
* @param {string} source - The shader source code.
Expand Down Expand Up @@ -297,7 +298,7 @@ class WebglShader {
*
* @param {string} src - The shader source code.
* @param {string} infoLog - The info log returned from WebGL on a failed shader compilation.
* @returns {Array} An array where the first element is the 10 lines of code around the first
* @returns {[string, {message?: string, line?: number, source?: string}]} A tuple where the first element is the 10 lines of code around the first
* detected error, and the second element an object storing the error messsage, line number and
* complete shader source.
* @private
Expand Down

0 comments on commit e0d6dc4

Please sign in to comment.