@luma.gl/shadertools
Advanced tools
@@ -10,3 +10,3 @@ export function getShaderInfo(source, defaultName) { | ||
let defaultName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'unnamed'; | ||
const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/; | ||
const SHADER_NAME_REGEXP = /#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/; | ||
const match = SHADER_NAME_REGEXP.exec(shader); | ||
@@ -13,0 +13,0 @@ return match ? match[1] : defaultName; |
import { WgslReflect } from '../../libs/wgsl-reflect/wgsl_reflect.module.js'; | ||
export function getShaderLayoutFromWGSL(source) { | ||
const reflect = new WgslReflect(source); | ||
const shaderLayout = { | ||
@@ -8,3 +7,4 @@ attributes: [], | ||
}; | ||
for (const uniform of reflect.uniforms) { | ||
const parsedWGSL = parseWGSL(source); | ||
for (const uniform of parsedWGSL.uniforms) { | ||
const members = []; | ||
@@ -25,3 +25,3 @@ for (const member of uniform.type.members) { | ||
} | ||
const vertex = reflect.entry.vertex[0]; | ||
const vertex = parsedWGSL.entry.vertex[0]; | ||
const attributeCount = vertex.inputs.length; | ||
@@ -44,2 +44,21 @@ for (let i = 0; i < attributeCount; i++) { | ||
} | ||
function parseWGSL(source) { | ||
try { | ||
return new WgslReflect(source); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
throw error; | ||
} | ||
let message = 'WGSL parse error'; | ||
if (typeof error === 'object' && error !== null && error !== void 0 && error.message) { | ||
message += `: ${error.message} `; | ||
} | ||
if (typeof error === 'object' && error !== null && error !== void 0 && error.token) { | ||
message += error.token.line || ''; | ||
} | ||
throw new Error(message, { | ||
cause: error | ||
}); | ||
} | ||
} | ||
//# sourceMappingURL=get-shader-layout-wgsl.js.map |
{ | ||
"name": "@luma.gl/shadertools", | ||
"version": "9.0.0-alpha.54", | ||
"version": "9.0.0-beta.1", | ||
"description": "Shader module system for luma.gl", | ||
@@ -31,5 +31,5 @@ "type": "module", | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs", | ||
"types": "./dist/index.d.ts" | ||
"require": "./dist/index.cjs" | ||
} | ||
@@ -50,7 +50,7 @@ }, | ||
"@babel/runtime": "^7.0.0", | ||
"@luma.gl/core": "9.0.0-alpha.54", | ||
"@luma.gl/core": "9.0.0-beta.1", | ||
"@math.gl/core": "^4.0.0", | ||
"@math.gl/types": "^4.0.0" | ||
}, | ||
"gitHead": "6028eb651303eadbc8f25e86d135d28f118fa3cf" | ||
"gitHead": "5fb42f651e80825336a372ca5a66de7d55611ddf" | ||
} |
@@ -22,3 +22,3 @@ // luma.gl, MIT license | ||
function getShaderName(shader: string, defaultName: string = 'unnamed'): string { | ||
const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/; | ||
const SHADER_NAME_REGEXP = /#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/; | ||
const match = SHADER_NAME_REGEXP.exec(shader); | ||
@@ -25,0 +25,0 @@ return match ? match[1] : defaultName; |
@@ -13,7 +13,8 @@ // luma.gl, MIT license | ||
export function getShaderLayoutFromWGSL(source: string): ShaderLayout { | ||
const reflect = new WgslReflect(source); | ||
const shaderLayout: ShaderLayout = {attributes: [], bindings: []}; | ||
for (const uniform of reflect.uniforms) { | ||
const parsedWGSL = parseWGSL(source); | ||
for (const uniform of parsedWGSL.uniforms) { | ||
const members = []; | ||
@@ -37,3 +38,3 @@ for (const member of uniform.type.members) { | ||
const vertex = reflect.entry.vertex[0]; // "main" | ||
const vertex = parsedWGSL.entry.vertex[0]; // "main" | ||
@@ -63,1 +64,19 @@ // Vertex shader inputs | ||
} | ||
function parseWGSL(source: string): WgslReflect { | ||
try { | ||
return new WgslReflect(source); | ||
} catch (error: any) { | ||
if (error instanceof Error) { | ||
throw error; | ||
} | ||
let message = 'WGSL parse error'; | ||
if (typeof error === 'object' && error?.message) { | ||
message += `: ${error.message} `; | ||
} | ||
if (typeof error === 'object' && error?.token) { | ||
message += error.token.line || ''; | ||
} | ||
throw new Error(message, {cause: error}); | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2407482
0.15%45999
0.16%