Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 878 vs 879 for /trunk/Source Code/Platform/Video/OpenGL/Shaders/glShader.cpp

Diff revisions: vs.
  @@ -16,6 +16,23 @@
16 16 stringImpl glShader::shaderAtomLocationPrefix[to_base(ShaderType::COUNT) + 1];
17 17
18 18 IMPLEMENT_CUSTOM_ALLOCATOR(glShader, 0, 0);
19 +
20 + void glShader::initStaticData() {
21 + stringImpl locPrefix(Paths::g_assetsLocation + Paths::g_shadersLocation + Paths::Shaders::GLSL::g_parentShaderLoc);
22 +
23 + shaderAtomLocationPrefix[to_base(ShaderType::FRAGMENT)] = locPrefix + Paths::Shaders::GLSL::g_fragAtomLoc;
24 + shaderAtomLocationPrefix[to_base(ShaderType::VERTEX)] = locPrefix + Paths::Shaders::GLSL::g_vertAtomLoc;
25 + shaderAtomLocationPrefix[to_base(ShaderType::GEOMETRY)] = locPrefix + Paths::Shaders::GLSL::g_geomAtomLoc;
26 + shaderAtomLocationPrefix[to_base(ShaderType::TESSELATION_CTRL)] = locPrefix + Paths::Shaders::GLSL::g_tescAtomLoc;
27 + shaderAtomLocationPrefix[to_base(ShaderType::TESSELATION_EVAL)] = locPrefix + Paths::Shaders::GLSL::g_teseAtomLoc;
28 + shaderAtomLocationPrefix[to_base(ShaderType::COMPUTE)] = locPrefix + Paths::Shaders::GLSL::g_compAtomLoc;
29 + shaderAtomLocationPrefix[to_base(ShaderType::COUNT)] = locPrefix + Paths::Shaders::GLSL::g_comnAtomLoc;
30 + }
31 +
32 + void glShader::destroyStaticData() {
33 +
34 + }
35 +
19 36 glShader::glShader(GFXDevice& context,
20 37 const stringImpl& name,
21 38 const ShaderType& type,
  @@ -52,18 +69,6 @@
52 69 _shader = glCreateShader(GL_COMPUTE_SHADER);
53 70 break;
54 71 };
55 -
56 - if (shaderAtomLocationPrefix[to_base(ShaderType::VERTEX)].empty()) {
57 - stringImpl locPrefix(Paths::g_assetsLocation + Paths::g_shadersLocation + Paths::Shaders::GLSL::g_parentShaderLoc);
58 -
59 - shaderAtomLocationPrefix[to_base(ShaderType::FRAGMENT)] = locPrefix + Paths::Shaders::GLSL::g_fragAtomLoc;
60 - shaderAtomLocationPrefix[to_base(ShaderType::VERTEX)] = locPrefix + Paths::Shaders::GLSL::g_vertAtomLoc;
61 - shaderAtomLocationPrefix[to_base(ShaderType::GEOMETRY)] = locPrefix + Paths::Shaders::GLSL::g_geomAtomLoc;
62 - shaderAtomLocationPrefix[to_base(ShaderType::TESSELATION_CTRL)] = locPrefix + Paths::Shaders::GLSL::g_tescAtomLoc;
63 - shaderAtomLocationPrefix[to_base(ShaderType::TESSELATION_EVAL)] = locPrefix + Paths::Shaders::GLSL::g_teseAtomLoc;
64 - shaderAtomLocationPrefix[to_base(ShaderType::COMPUTE)] = locPrefix + Paths::Shaders::GLSL::g_compAtomLoc;
65 - shaderAtomLocationPrefix[to_base(ShaderType::COUNT)] = locPrefix + Paths::Shaders::GLSL::g_comnAtomLoc;
66 - }
67 72 }
68 73
69 74 glShader::~glShader() {
  @@ -71,7 +76,7 @@
71 76 glDeleteShader(_shader);
72 77 }
73 78
74 - bool glShader::load(const stringImpl& source) {
79 + bool glShader::load(const stringImpl& source, U32 lineOffset) {
75 80 if (source.empty()) {
76 81 Console::errorfn(Locale::get(_ID("ERROR_GLSL_NOT_FOUND")), getName().c_str());
77 82 return false;
  @@ -79,7 +84,10 @@
79 84
80 85 _usedAtoms.clear();
81 86 stringImpl parsedSource = _skipIncludes ? source
82 - : preprocessIncludes(source, 0);
87 + : preprocessIncludes(getName(), source, 0, _usedAtoms);
88 +
89 + Util::ReplaceStringInPlace(parsedSource, "//__LINE_OFFSET_",
90 + Util::StringFormat("#line %d", lineOffset));
83 91
84 92 const char* src = parsedSource.c_str();
85 93
  @@ -131,7 +139,10 @@
131 139 return true;
132 140 }
133 141
134 - stringImpl glShader::preprocessIncludes(const stringImpl& source, I32 level /*= 0 */) {
142 + stringImpl glShader::preprocessIncludes(const stringImpl& name,
143 + const stringImpl& source,
144 + I32 level,
145 + vectorImpl<stringImpl>& foundAtoms) {
135 146 if (level > 32) {
136 147 Console::errorfn(Locale::get(_ID("ERROR_GLSL_INCLUD_LIMIT")));
137 148 }
  @@ -147,7 +158,7 @@
147 158 while (std::getline(input, line)) {
148 159 if (std::regex_search(line, matches, Paths::g_includePattern)) {
149 160 include_file = Util::Trim(matches[1].str().c_str());
150 - _usedAtoms.push_back(include_file);
161 + foundAtoms.push_back(include_file);
151 162
152 163 ShaderType typeIndex = ShaderType::COUNT;
153 164 // switch will throw warnings due to promotion to int
  @@ -171,14 +182,14 @@
171 182 }
172 183
173 184 include_string = ShaderProgram::shaderFileRead(include_file, shaderAtomLocationPrefix[to_U32(typeIndex)]);
174 -
175 185 if (include_string.empty()) {
176 186 Console::errorfn(Locale::get(_ID("ERROR_GLSL_NO_INCLUDE_FILE")),
177 - getName().c_str(),
187 + name.c_str(),
178 188 line_number,
179 189 include_file.c_str());
180 190 }
181 - output.append(preprocessIncludes(include_string, level + 1));
191 +
192 + output.append(preprocessIncludes(name, include_string, level + 1, foundAtoms));
182 193 } else {
183 194 output.append(line);
184 195 }
  @@ -226,7 +237,8 @@
226 237 const stringImpl& name,
227 238 const stringImpl& source,
228 239 const ShaderType& type,
229 - const bool parseCode) {
240 + const bool parseCode,
241 + U32 lineOffset) {
230 242 // See if we have the shader already loaded
231 243 glShader* shader = getShader(name);
232 244
  @@ -240,7 +252,7 @@
240 252
241 253 shader->skipIncludes(!parseCode);
242 254 // At this stage, we have a valid Shader object, so load the source code
243 - if (!shader->load(source)) {
255 + if (!shader->load(source, lineOffset)) {
244 256 // If loading the source code failed, delete it
245 257 if (newShader) {
246 258 MemoryManager::DELETE(shader);