30
// //-----------------------------------------------------------------------------
31
// void AddShaderDefinition(std::vector<ShaderDefinition>& Definitions,const TCHAR* Name,const TCHAR* Format,...)
33
// TCHAR DefinitionText[1024];
34
// GET_VARARGS(DefinitionText, NUX_ARRAY_COUNT(DefinitionText), NUX_ARRAY_COUNT(DefinitionText)-1,Format);
36
// ShaderDefinition Definition;
37
// Definition.Name = Name;
38
// Definition.Value = DefinitionText;
39
// Definitions.push_back(Definition);
42
// //-----------------------------------------------------------------------------
43
// bool ExtractShaderString3(const NString &ShaderToken, const NString &ShaderSource, NString &RetSource, NString& ShaderPreprocessorDefines)
45
// unsigned int lineStart = 0;
46
// unsigned int lineCount = 1;
47
// bool startTokenFound = false;
48
// int shaderStringStart =0;
49
// int shaderStartLine =1;
52
// //Loop for all characters in the string
53
// if(ShaderToken != TEXT(""))
56
// for(i = 0; i< ShaderSource.Length(); i++)
58
// //Check if the starting character '[' (open bracket) is found at the beginning of the line
59
// // i counts the characters in the file. lineStart is equal to i at the beginning of the line.
60
// if((TCharStringNCompare(&ShaderSource[i],TEXT("["), 1) == 0) && (lineStart == i))
62
// if(!startTokenFound)
64
// //Test for the start token
65
// if(ShaderSource.FindFirstOccurence(ShaderToken) == i)
67
// // Found the shader token
68
// shaderStringStart = i + ShaderToken.Length();
69
// startTokenFound = true;
71
// //Set what line the shader was found on
72
// shaderStartLine = lineCount;
77
// //Break where the end token was found
82
// //If the character is equal to the new line character,
83
// // The next character must be on the new line
84
// if((TCharStringNCompare(&ShaderSource[i], TEXT("\r"), 1) == 0) || (TCharStringNCompare(&ShaderSource[i], TEXT("\n"), 1) == 0))
89
// //Count the new lines
90
// if(TCharStringNCompare(&ShaderSource[i], TEXT("\n"), 1) == 0)
96
// //If the string was not found, return false
97
// if(!startTokenFound || shaderStringStart >= i)
102
// //Assign the return string
103
// RetSource = ShaderSource.GetSubString(shaderStringStart, i - shaderStringStart);
105
// //Add the line directive to the shader source. See the documentation for GLSL #line directive.
106
// // GLSL spec: The #version directive must occur in a shader before anything else, except for comments and white space.
107
// int Pos = RetSource.FindFirstOccurence(TEXT("#version"));
108
// while(RetSource[Pos] != TEXT('\n'))
110
// if(RetSource[Pos] == 0)
114
// if(RetSource[Pos] != 0)
117
// int EndOfLinePosition = 0;
118
// unsigned int LinePosition = 0;
119
// while((EndOfLinePosition = RetSource.FindNextOccurence(TEXT('\n'), EndOfLinePosition)) < Pos-1)
121
// ++EndOfLinePosition;
125
// RetSource.Insert(Pos, NString::Printf(TEXT("#line %u\n"), LinePosition + shaderStartLine));
127
// // Insert the preprocessor definitions before the #line directive
128
// if(ShaderPreprocessorDefines.Length())
129
// RetSource.Insert(Pos, ShaderPreprocessorDefines + NString(TEXT('\n')));
135
// // We are not searching for a start token. Return the whole source.
136
// RetSource = ShaderSource;
141
// void InsertPreProcessorDefinitions(const NString &ShaderSource, NString &RetSource, NString& ShaderPreprocessorDefines)
143
// RetSource = ShaderSource;
145
// if(ShaderPreprocessorDefines.Length() == 0)
148
// // GLSL spec: The #version directive must occur in a shader before anything else, except for comments and white space.
149
// int Pos = RetSource.FindFirstOccurence(TEXT("#version"));
152
// Pos = RetSource.FindNextOccurence(TEXT('\n'), Pos);
155
// // this is most likely an incorrect shader
156
// Pos = RetSource.Size();
157
// RetSource.Insert(Pos, NString(TEXT('\n')));
158
// Pos = RetSource.Size();
162
// // Skip character \n
171
// if(ShaderPreprocessorDefines.Length())
172
// RetSource.Insert(Pos, ShaderPreprocessorDefines + NString(TEXT('\n')));