Advertisement
mattparks5855

Theta OpenGL generator IDEA.

Apr 10th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. import Theta::IO.*;
  2. import Theta::Web.*;
  3.  
  4. module Theta::Program;
  5.  
  6. // @summary A class capable of generation OpenGL for Theta.
  7. public prototype Generator {
  8. fields
  9. {
  10. // @summary The main workspace that holds the project.
  11. public static String GLWorkspaceName = "Khronos.TEA";
  12.  
  13. // @summary The project where files will be placed.
  14. public static String GLTargetProjectName = "OpenGL.TEA";
  15.  
  16. // @summary The gl target path.
  17. public static mut String GLTargetPath;
  18.  
  19. // @summary The project to generate code in.
  20. public static mut String GLTargetSourcesPath;
  21.  
  22. // @summary The path to where to download / get OpenGL specs.
  23. public static mut String GLTargetSpecs;
  24. }
  25.  
  26. structures
  27. {
  28. private type SpecURL<String> =
  29. {
  30. EGL("https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/egl.xml"),
  31. GL("https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/gl.xml"),
  32. GLX("https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/glx.xml"),
  33. WGL("https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/wgl.xml"),
  34. README("https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/readme.pdf"),
  35. }
  36. }
  37.  
  38. methods
  39. {
  40. def UpdateDirPaths<private, static, void>()
  41. {
  42. IO::DirectoryInfo directoryRoot = new IO::DirectoryInfo(IO::Directory.GetCurrentDirectory());
  43.  
  44. // Walk up to the solution file so we can then go into the project and write to the C# files directly.
  45. while (directoryRoot != null && !IO::File.Exists(IO::Path.Combine(directoryRoot.FullName, glWorkspaceName + ".sln")))
  46. {
  47. directoryRoot = directoryRoot.Parent;
  48. }
  49.  
  50. // If the solution wasn't found (maybe its not not running from the bin directory), just write out to the current directory.
  51. if (directoryRoot == null)
  52. {
  53. directoryRoot = new IO::DirectoryInfo(IO::Directory.GetCurrentDirectory());
  54. }
  55.  
  56. // Sets the specified gl paths.
  57. GLTargetPath = IO::Path.Combine(directoryRoot.FullName, glTargetProjectName);
  58. GLTargetSourcesPath = glTargetPath + "/" + "Sources";
  59. GLTargetSpecs = glTargetPath + "/" + "GLSpecs";
  60. }
  61.  
  62. def DownloadSpecs<private, static, void>()
  63. {
  64. // Creates the specs path directory if it does not exist!
  65. if (!IO::Directory.Exists(glTargetSpecs))
  66. {
  67. IO::Directory.CreateDirectory(glTargetSpecs);
  68. }
  69.  
  70. // Downloads the specs files.
  71. foreach (SpecURL url : SpecURL.ToList)
  72. {
  73. String[] spilit = url.Value.Split('/');
  74. String p = "";
  75.  
  76. if (!IO::File.Exists((p = IO::Path.Combine(glTargetSpecs, spilit[spilit.Length - 1]))))
  77. {
  78. if (Web::HasInternet)
  79. {
  80. IO::StdOut.PrintLn("Downloading the required {0} document!", spilit[spilit.Length - 1]);
  81. Web::WebClient glClient = new Web::WebClient();
  82. glClient.DownloadFile(url.Value, p);
  83. }
  84. else
  85. {
  86. IO::StdOut.PrintLn("Could not download {0}, no internet connection!", url.Name);
  87. }
  88. }
  89. }
  90. }
  91.  
  92. def Generate<private, static void>Generate(String xmlName, String dllPath)
  93. {
  94. // TODO: Generate to files!
  95. }
  96.  
  97. // @summary Entry point to the program, can be in any prototype.
  98. // @params args: Arguements provided to the program.
  99. // @returns int: Status code of the program.
  100. def Main<entry, Int>(String[] args)
  101. {
  102. // Sets up the console.
  103. IO::StdOut.Title = "TEA OpenGL";
  104. IO::StdOut.BackgroundColor = IO::ConsoleColour.Black;
  105. IO::StdOut.ForegroundColor = IO::ConsoleColour.Green;
  106.  
  107. // Initalize files and paths.
  108. UpdateDirPaths();
  109. DownloadSpecs();
  110.  
  111. // Generate files! TODO: OpenAL, OpenCL & GLFS
  112. Generate("glfw", "");
  113. Generate("gl", "");
  114. // Generate("wgl", "");
  115. // Generate("glx", "");
  116. // Generate("egl", "");
  117.  
  118. // Wait for the user to end the program.
  119. IO::StdOut.PrintLn("Press any key to exit...");
  120. IO::StdOut.Pause();
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement