-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor WebGLExtensions to class
- Loading branch information
Showing
3 changed files
with
45 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,58 @@ | ||
function WebGLExtensions(gl) { | ||
const extensions = {}; | ||
class WebGLExtensions { | ||
/** !param { WebGL2RenderingContext} gl */ | ||
constructor(gl) { | ||
this.gl = gl; | ||
this.extensions = []; | ||
|
||
function getExtension(name) { | ||
if (extensions[name] !== undefined) { | ||
return extensions[name]; | ||
// debug: gl.getSupportedExtensions(); | ||
} | ||
|
||
_getExtension(name) { | ||
if (this.extensions[name] !== undefined) { | ||
return this.extensions[name]; | ||
} | ||
|
||
let extension; | ||
|
||
switch (name) { | ||
case 'WEBGL_compressed_texture_pvrtc': | ||
extension = | ||
gl.getExtension('WEBGL_compressed_texture_pvrtc') || | ||
gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc'); | ||
this.gl.getExtension('WEBGL_compressed_texture_pvrtc') || | ||
this.gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc'); | ||
break; | ||
|
||
default: | ||
extension = gl.getExtension(name); | ||
extension = this.gl.getExtension(name); | ||
} | ||
|
||
extensions[name] = extension; | ||
this.extensions[name] = extension; | ||
|
||
return extension; | ||
} | ||
|
||
return { | ||
has(name) { | ||
return getExtension(name) !== null; | ||
}, | ||
// | ||
|
||
init(capabilities) { | ||
// EP: some extensions need to be initialised by a query to function | ||
// Browser support percentages sourced from https://web3dsurvey.com/webgl2 | ||
getExtension('EXT_color_buffer_float'); // 99.8% | ||
getExtension('OES_texture_float_linear'); // 86.31% | ||
getExtension('EXT_color_buffer_half_float'); // 92.2% | ||
}, | ||
has(name) { | ||
return this._getExtension(name) !== null; | ||
} | ||
|
||
get(name) { | ||
const extension = getExtension(name); | ||
init(capabilities) { | ||
// EP: some extensions need to be initialised by a query to function | ||
// Browser support percentages sourced from https://web3dsurvey.com/webgl2 | ||
this._getExtension('EXT_color_buffer_float'); // 99.8% | ||
this._getExtension('OES_texture_float_linear'); // 86.31% | ||
this._getExtension('EXT_color_buffer_half_float'); // 92.2% | ||
} | ||
|
||
if (extension === null) { | ||
console.warn(`WebGLRenderer: ${name} extension not supported.`); | ||
} | ||
get(name) { | ||
const extension = this._getExtension(name); | ||
|
||
return extension; | ||
if (extension === null) { | ||
console.warn(`WebGLRenderer: ${name} extension not supported.`); | ||
} | ||
}; | ||
|
||
return extension; | ||
} | ||
} | ||
|
||
export { WebGLExtensions }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters