import { ShaderVersion } from '../types/type'; /** * This class converts the code property of a shaderity object to the specified format. */ export default class ShaderTransformer { /** * @private * Translate a GLSL ES3 shader code to a GLSL ES1 shader code */ static _transformToGLSLES1(splittedShaderCode: string[], isFragmentShader: boolean, embedErrorsInOutput: boolean): string[]; /** * @private * Translate a GLSL ES1 shader code to a GLSL ES3 shader code */ static _transformToGLSLES3(splittedShaderCode: string[], isFragmentShader: boolean): string[]; /** * @private * Translate a GLSL shader code to a shader code of specified GLSL version */ static _transformTo(version: ShaderVersion, splittedShaderCode: string[], isFragmentShader: boolean, embedErrorsInOutput: boolean): string[]; /** * @private * If the first line contains version information, overwrite the first line with '#version 100'. * If not, add '#version 100' to the first line. * * Note: If the first line is commented out and the version information is written in the second or later line, * the appropriate version information will be added to the first line and the user-defined version information * in the second or later line will be removed. */ private static __convertOrInsertVersionGLSLES1; /** * @private * If the first line contains version information, overwrite the first line with '#version 300 es'. * If not, add '#version 300 es' to the first line. * In both cases, '#define GLSL_ES3' will be inserted in the second line. * Use the '#define GLSL_ES3' directive if you want to write a shader code that will only run in the case of webgl2. * * Note: If the first line is commented out and the version information is written in the second or later line, * the appropriate version information will be added to the first line and the user-defined version information * in the second or later line will be removed. */ private static __convertOrInsertVersionGLSLES3; /** * @private * Find the 'in' qualifier in the shader code and replace it with the GLSL ES1 qualifier('attribute' or 'varying') * This method directly replace the elements of the splittedShaderCode variable. */ private static __convertIn; /** * @private * Find the "out" qualifier in the shader code and modify the shader code. * If the shader stage is vertex, the "out" qualifiers will be replaced by "varying" qualifier. * If the shader stage is fragment and the shader has "out" qualifiers, the "out" qualifiers will * be deleted and the variable is used to assign a value to gl_FragColor. * This method directly replace the elements of the splittedShaderCode variable. */ private static __convertOut; /** * @private * This method is a part of __convertOut method. * This method deletes the "out" qualifiers and adds the line for assigning to gl_FragColor. * If the shader does not have the "out" qualifiers, this method does nothing. */ private static __removeOutQualifier; private static __addGLFragColor; /** * @private * Find the qualifier for es3 only in the shader code and remove it * This method directly replace the elements of the splittedShaderCode variable. */ private static __removeES3Qualifier; /** * @private * Find the "flat" and "smooth" qualifier in the shader code and remove it */ private static __removeVaryingQualifier; /** * @private * Find the "layout" qualifier in the shader code and remove it */ private static __removeLayout; /** * @private * Find the "precision" qualifier in the shader code and remove it if the "precision" qualifier is valid for only GLSL ES3 * This method directly replace the elements of the splittedShaderCode variable. */ private static __removePrecisionForES3; /** * @private * Find the "texture" and "textureProj" method in the shader code and * replace it with the GLSL ES1 method('texture2D', 'texture2D', and so on) * This method directly replace the elements of the splittedShaderCode variable. */ private static __convertTextureFunctionToES1; /** * @private * This method finds uniform declarations of sampler types in the shader and * creates a map with variable names as keys and types as values. */ private static __createUniformSamplerMap; /** * @private * This method finds sampler types from the function arguments and * creates a map with variable names as keys and types as values. */ private static __createArgumentSamplerMap; /** * @private * This method returns the part enclosed in brackets(= '()'). * For example, you can get lines that contain function arguments, conditional expressions for if statements, etc. */ private static __getBracketSection; /** * @private * Find the 'attribute' qualifier in the vertex shader code and replace it with the GLSL ES3 qualifier('in') * This method directly replace the elements of the splittedShaderCode variable. */ private static __convertAttribute; /** * @private * Find the 'varying' qualifier in the shader code and replace it with the GLSL ES3 qualifier('in' or 'out') * This method directly replace the elements of the splittedShaderCode variable. */ private static __convertVarying; /** * @private * Find the 'textureCube' method in the shader code and replace it with the GLSL ES3 method('texture') * This method directly replace the elements of the splittedShaderCode variable. */ private static __convertTextureCube; /** * @private * Find the 'texture2D' method in the shader code and replace it with the GLSL ES3 method('texture') * This method directly replace the elements of the splittedShaderCode variable. */ private static __convertTexture2D; /** * @private * Find the 'texture2DProj' method in the shader code and replace it with the GLSL ES3 method('textureProj') * This method directly replace the elements of the splittedShaderCode variable. */ private static __convertTexture2DProd; /** * @private * Find the 'texture3D' method in the shader code and replace it with the GLSL ES3 method('texture') * This method directly replace the elements of the splittedShaderCode variable. */ private static __convertTexture3D; /** * @private * Find the 'texture3DProj' method in the shader code and replace it with the GLSL ES3 method('textureProj') * This method directly replace the elements of the splittedShaderCode variable. */ private static __convertTexture3DProd; private static __regSymbols; private static __replaceLine; private static __removeFirstMatchingLine; private static __outError; }