Advertisement
JoshDreamland

shader-whatever.cpp

Aug 26th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. /** Copyright (C) 2013 Robert B. Colton, Josh Ventura
  2. ***
  3. *** This file is a part of the ENIGMA Development Environment.
  4. ***
  5. *** ENIGMA is free software: you can redistribute it and/or modify it under the
  6. *** terms of the GNU General Public License as published by the Free Software
  7. *** Foundation, version 3 of the license or any later version.
  8. ***
  9. *** This application and its source code is distributed AS-IS, WITHOUT ANY
  10. *** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. *** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  12. *** details.
  13. ***
  14. *** You should have received a copy of the GNU General Public License along
  15. *** with this code. If not, see <http://www.gnu.org/licenses/>
  16. **/
  17.  
  18. #include <stdio.h>
  19. #include <iostream>
  20. #include <fstream>
  21.  
  22. using namespace std;
  23.  
  24. #include "syntax/syncheck.h"
  25. #include "parser/parser.h"
  26.  
  27. #include "backend/EnigmaStruct.h" //LateralGM interface structures
  28. #include "parser/object_storage.h"
  29. #include "compiler/compile_common.h"
  30.  
  31. #include <math.h> //log2 to calculate passes.
  32.  
  33. #define flushl '\n' << flush
  34. #define flushs flush
  35.  
  36. #include "languages/lang_CPP.h"
  37.  
  38. #define SHADERSTRUCT "struct ShaderStruct { \
  39.     string fragment; \
  40.     string vertex; \
  41.     string type; \
  42.     bool precompile; \
  43.   }; "
  44.  
  45. static string esc(string str) {
  46.   string res;
  47.   res.reserve(str.length);
  48.   for (size_t i = 0; i < str.length(); ++i) {
  49.     char c = str[i];
  50.     if (c == '\n') { res += "\\n"; continue; }
  51.     if (c == '\r') { res += "\\r"; continue; }
  52.     if (c == '\\') { res += "\\\\"; continue; }
  53.     res.append(c);
  54.   }
  55.   return res;
  56. }
  57.  
  58. int lang_CPP::compile_writeShaderData(EnigmaStruct* es, parsed_object *EGMglobal)
  59. {
  60.   ofstream wto("ENIGMAsystem/SHELL/Preprocessor_Environment_Editable/IDE_EDIT_shaderarrays.h",ios_base::out);
  61.  
  62.   wto << license << "namespace enigma {\n"
  63.   wto << "  ShaderStruct shaderstructarray[] = {
  64.  
  65.  int idmax = 0;
  66.  for (int i = 0; i < es->shaderCount; i++)
  67.  {
  68.    while (idmax < es->shaders[i].id)
  69.      ++idmax, wto << "ShaderStruct(),\n";
  70.    wto << "    { "
  71.        << '"' << esc(es->shaders[i].vertex)   << "\", "
  72.        << '"' << esc(es->shaders[i].fragment) << "\", "
  73.         << '"' << es->shaders[i].type << "\", "
  74.         << (es->shaders[i].precompile? "true" : "false")
  75.         << " },\n";
  76.   }
  77.  
  78.   wto << "  };\n";
  79.   wto << "} // Namespace enigma\n";
  80.   wto.close();
  81.  
  82.   return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement