C# Class ShaderInterpreter.Converter

显示文件 Open project: Patapom/GodComplex Class Usage Examples

Public Methods

Method Description
ConvertShader ( FileInfo _ShaderPath, string _ShaderSource, string _ClassName, string _EntryPointVS, string _EntryPointPS ) : string

Converts a source shader into a C#-runnable class

RemovePreprocessorDirectives ( string _Source ) : string

Removes all recognizable preprocessor directives like //#ifdef, //#define, //#ifndef, //#endif, etc.

ReplaceStaticConsts ( string _Source ) : string

Replaces "static consts" by simple "static"

Private Methods

Method Description
CommentLinesWith ( string _Source, string _Pattern ) : string

Comments any line containing the specified pattern

ConvertConstantBuffers ( string _Source ) : string

Converts all constant buffers syntax (cbuffer) into a struct with a cbuffer attribute Builds a dictionary of constant names so we can replace their simple use by a composition cbufferName.ConstantName instead

ConvertFloatToDouble ( string _Source ) : string

Converts the float type to double type

ConvertOutFunctions ( string _Source ) : string

Converts all functions with an "inout" syntax as "ref" and fix callers of such functions to issue either a "ref" or an "out" prefix

ConvertRegisters ( string _Source ) : string

Converts all registers syntax (: register(xx)) into an attribute inserted above the line with register

ConvertSemantics ( string _Source ) : string

Converts all semantics syntax (: NAME) into an attribute inserted above the line with semantic

ConvertVectorConstructors ( string _Source ) : string

Converts vector constructors (float2, float3, float4, uint2, uint3, uint4, etc.) by a function that calls actual C# constructors

EnsureAlphanumeric ( string _Name ) : bool

Ensures the provided name is alphanumeric

ErrorIfLinesWith ( string _Source, string _Pattern ) : void

Throws an exception if there is a line with the //#if syntax, which is not supported in C# (except very annoying //#define at the very beginning of the file)!

FindBOL ( string _Source, int _StartIndex ) : int

/// Inserts a snippet of text at a specific index in the source ///

Finds the index of the beginning of the current line

FindEOL ( string _Source, int _StartIndex ) : int

Finds teh index of the end of the current line

IndexOfBetween ( string _Source, string _Pattern, int _StartIndex, int _EndIndex ) : int

Same as IndexOf except it returns -1 if the match is outside of the specified [Start,End] range

IsCommentedLine ( string _Source, int _Index ) : bool

Checks if the current position is part of a comment (warning: only // coments are supported!)

MakeStructFieldsPublic ( string _Source ) : string

Makes all the fields in structs public

ResolveIncludes ( FileInfo _ShaderPath, string _ShaderSource ) : string

Resolves all include files an merge them into the shader source

Method Details

ConvertShader() public static method

Converts a source shader into a C#-runnable class
public static ConvertShader ( FileInfo _ShaderPath, string _ShaderSource, string _ClassName, string _EntryPointVS, string _EntryPointPS ) : string
_ShaderPath System.IO.FileInfo The path of the shader to convert (for includes resolution)
_ShaderSource string The shader code
_ClassName string
_EntryPointVS string The name of the Vertex Shader entry point function
_EntryPointPS string The name of the Vertex Shader entry point function
return string

RemovePreprocessorDirectives() public static method

Removes all recognizable preprocessor directives like //#ifdef, //#define, //#ifndef, //#endif, etc.
public static RemovePreprocessorDirectives ( string _Source ) : string
_Source string
return string

ReplaceStaticConsts() public static method

Replaces "static consts" by simple "static"
public static ReplaceStaticConsts ( string _Source ) : string
_Source string
return string