Skip to content

Commit

Permalink
fix(webgl): update extension handling in shader(), add ExtensionInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 17, 2019
1 parent 2071133 commit 12abaa0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
32 changes: 20 additions & 12 deletions packages/webgl/src/api/ext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const GL_EXT_INFO = {
import { IObjectOf } from "@thi.ng/api";

export const GL_EXT_INFO: IObjectOf<ExtensionInfo> = {
WEBGL_draw_buffers: {
gl: true,
alias: "GL_EXT_draw_buffers"
Expand All @@ -9,30 +11,36 @@ export const GL_EXT_INFO = {
}
};

export interface ExtensionInfo {
gl?: boolean;
gl2?: boolean;
alias: string;
}

export interface WebGLExtensionMap {
ANGLE_instanced_arrays: ANGLE_instanced_arrays;
EXT_blend_minmax: EXT_blend_minmax;
EXT_color_buffer_float: WEBGL_color_buffer_float;
EXT_texture_filter_anisotropic: EXT_texture_filter_anisotropic;
EXT_frag_depth: EXT_frag_depth;
EXT_shader_texture_lod: EXT_shader_texture_lod;
EXT_sRGB: EXT_sRGB;
EXT_texture_filter_anisotropic: EXT_texture_filter_anisotropic;
OES_element_index_uint: OES_element_index_uint;
OES_standard_derivatives: OES_standard_derivatives;
OES_texture_float_linear: OES_texture_float_linear;
OES_texture_float: OES_texture_float;
OES_texture_half_float_linear: OES_texture_half_float_linear;
OES_texture_half_float: OES_texture_half_float;
OES_vertex_array_object: OES_vertex_array_object;
WEBGL_color_buffer_float: WEBGL_color_buffer_float;
WEBGL_compressed_texture_astc: WEBGL_compressed_texture_astc;
WEBGL_compressed_texture_s3tc_srgb: WEBGL_compressed_texture_s3tc_srgb;
WEBGL_compressed_texture_s3tc: WEBGL_compressed_texture_s3tc;
WEBGL_debug_renderer_info: WEBGL_debug_renderer_info;
WEBGL_debug_shaders: WEBGL_debug_shaders;
WEBGL_depth_texture: WEBGL_depth_texture;
WEBGL_draw_buffers: WEBGL_draw_buffers;
WEBGL_lose_context: WEBGL_lose_context;
WEBGL_depth_texture: WEBGL_depth_texture;
WEBGL_debug_renderer_info: WEBGL_debug_renderer_info;
WEBGL_compressed_texture_s3tc: WEBGL_compressed_texture_s3tc;
OES_texture_half_float_linear: OES_texture_half_float_linear;
OES_texture_half_float: OES_texture_half_float;
OES_texture_float_linear: OES_texture_float_linear;
OES_texture_float: OES_texture_float;
OES_standard_derivatives: OES_standard_derivatives;
OES_element_index_uint: OES_element_index_uint;
ANGLE_instanced_arrays: ANGLE_instanced_arrays;
}

export type ExtensionName = keyof WebGLExtensionMap;
Expand Down
6 changes: 3 additions & 3 deletions packages/webgl/src/shader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ const compileExtensionPragma = (
behavior: ExtensionBehavior,
version: GLSLVersion
) => {
const ext = (<any>GL_EXT_INFO)[id];
const ext = GL_EXT_INFO[id];
const gl2 = version === GLSLVersion.GLES_300;
return !ext || (!gl2 && ext.gl) || (gl2 && ext.gl2)
? `#extension ${ext.alias || id} : ${
return ext && ((!gl2 && ext.gl) || (gl2 && ext.gl2))
? `#extension ${(ext && ext.alias) || id} : ${
isBoolean(behavior) ? (behavior ? "enable" : "disable") : behavior
}\n`
: "";
Expand Down

0 comments on commit 12abaa0

Please sign in to comment.