mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-12 11:15:29 +00:00
* CppSpecWriter.cs: Defined Init() methods, declared all OpenGL
functions and fixed the formatting of the header.
This commit is contained in:
parent
6b95ee466a
commit
99e9531b1e
|
@ -42,6 +42,7 @@ namespace Bind
|
||||||
sealed class CppSpecWriter : ISpecWriter
|
sealed class CppSpecWriter : ISpecWriter
|
||||||
{
|
{
|
||||||
readonly char[] numbers = "0123456789".ToCharArray();
|
readonly char[] numbers = "0123456789".ToCharArray();
|
||||||
|
const string AllowDeprecated = "ALLOW_DEPRECATED_GL";
|
||||||
|
|
||||||
#region WriteBindings
|
#region WriteBindings
|
||||||
|
|
||||||
|
@ -107,19 +108,62 @@ namespace Bind
|
||||||
void WriteLoader(BindStreamWriter sw, FunctionCollection wrappers,
|
void WriteLoader(BindStreamWriter sw, FunctionCollection wrappers,
|
||||||
Dictionary<string, string> CSTypes)
|
Dictionary<string, string> CSTypes)
|
||||||
{
|
{
|
||||||
|
// Used to avoid multiple declarations of the same function
|
||||||
|
Delegate last_delegate = null;
|
||||||
|
|
||||||
|
// Declare all functions
|
||||||
|
foreach (var ext in wrappers.Keys)
|
||||||
|
{
|
||||||
|
var forward_compatible = wrappers[ext].Where(f => !f.Deprecated);
|
||||||
|
var deprecated = wrappers[ext].Where(f => f.Deprecated);
|
||||||
|
|
||||||
|
last_delegate = null;
|
||||||
|
for (var current = forward_compatible; current != deprecated; current = deprecated)
|
||||||
|
{
|
||||||
|
foreach (var function in current)
|
||||||
|
{
|
||||||
|
if (function.WrappedDelegate == last_delegate)
|
||||||
|
continue;
|
||||||
|
last_delegate = function.WrappedDelegate;
|
||||||
|
|
||||||
|
if (ext == "Core")
|
||||||
|
sw.WriteLine("{0}::{1} = 0;", Settings.GLClass, function.TrimmedName);
|
||||||
|
else
|
||||||
|
sw.WriteLine("{0}::{1}::{2} = 0;", Settings.GLClass, function.Extension, function.TrimmedName);
|
||||||
|
}
|
||||||
|
sw.WriteLine("#ifdef {0}", AllowDeprecated);
|
||||||
|
}
|
||||||
|
sw.WriteLine("#endif");
|
||||||
|
}
|
||||||
|
sw.WriteLine();
|
||||||
|
|
||||||
|
// Add Init() methods
|
||||||
foreach (var ext in wrappers.Keys)
|
foreach (var ext in wrappers.Keys)
|
||||||
{
|
{
|
||||||
if (ext == "Core")
|
if (ext == "Core")
|
||||||
sw.WriteLine("{0}::{0}()", Settings.GLClass);
|
sw.WriteLine("{0}::Init()", Settings.GLClass);
|
||||||
else
|
else
|
||||||
sw.WriteLine("{0}::{1}::{1}()", Settings.GLClass, ext);
|
sw.WriteLine("{0}::{1}::Init()", Settings.GLClass, ext);
|
||||||
sw.WriteLine("{");
|
sw.WriteLine("{");
|
||||||
sw.Indent();
|
sw.Indent();
|
||||||
|
|
||||||
foreach (var function in wrappers[ext])
|
var forward_compatible = wrappers[ext].Where(f => !f.Deprecated);
|
||||||
|
var deprecated = wrappers[ext].Where(f => f.Deprecated);
|
||||||
|
|
||||||
|
for (var current = forward_compatible; current != deprecated; current = deprecated)
|
||||||
{
|
{
|
||||||
sw.WriteLine("{0} = GetAddress(\"{1}\");", function.TrimmedName, function.Name);
|
last_delegate = null;
|
||||||
|
foreach (var function in wrappers[ext])
|
||||||
|
{
|
||||||
|
if (function.WrappedDelegate == last_delegate)
|
||||||
|
continue;
|
||||||
|
last_delegate = function.WrappedDelegate;
|
||||||
|
|
||||||
|
sw.WriteLine("{0} = (p{0})GetAddress(\"{1}\");", function.TrimmedName, function.Name);
|
||||||
|
}
|
||||||
|
sw.WriteLine("#ifdef {0}", AllowDeprecated);
|
||||||
}
|
}
|
||||||
|
sw.WriteLine("#endif");
|
||||||
|
|
||||||
sw.Unindent();
|
sw.Unindent();
|
||||||
sw.WriteLine("}");
|
sw.WriteLine("}");
|
||||||
|
@ -148,7 +192,8 @@ namespace Bind
|
||||||
|
|
||||||
#region WriteWrappers
|
#region WriteWrappers
|
||||||
|
|
||||||
public void WriteWrappers(BindStreamWriter sw, FunctionCollection wrappers, Dictionary<string, string> CSTypes)
|
public void WriteWrappers(BindStreamWriter sw, FunctionCollection wrappers,
|
||||||
|
Dictionary<string, string> CSTypes)
|
||||||
{
|
{
|
||||||
sw.WriteLine("struct {0}", Settings.GLClass);
|
sw.WriteLine("struct {0}", Settings.GLClass);
|
||||||
sw.WriteLine("{");
|
sw.WriteLine("{");
|
||||||
|
@ -163,19 +208,21 @@ namespace Bind
|
||||||
sw.Indent();
|
sw.Indent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sw.WriteLine("static void Init();");
|
||||||
|
|
||||||
// Avoid multiple definitions of the same function
|
// Avoid multiple definitions of the same function
|
||||||
Delegate last_delegate = null;
|
Delegate last_delegate = null;
|
||||||
|
|
||||||
// Write forward-compatible functions
|
// Write forward-compatible functions
|
||||||
foreach (Function f in wrappers[extension].Where(f => !f.Deprecated).Select(f => f))
|
foreach (Function f in wrappers[extension].Where(f => !f.Deprecated))
|
||||||
{
|
{
|
||||||
WriteDelegate(sw, f, ref last_delegate);
|
WriteDelegate(sw, f, ref last_delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write deprecated functions
|
// Write deprecated functions
|
||||||
sw.WriteLine("#ifdef ALLOW_DEPRECATED_GL");
|
sw.WriteLine("#ifdef {0}", AllowDeprecated);
|
||||||
sw.Indent();
|
sw.Indent();
|
||||||
foreach (Function f in wrappers[extension].Where(f => !f.Deprecated).Select(f => f))
|
foreach (Function f in wrappers[extension].Where(f => !f.Deprecated))
|
||||||
{
|
{
|
||||||
WriteDelegate(sw, f, ref last_delegate);
|
WriteDelegate(sw, f, ref last_delegate);
|
||||||
}
|
}
|
||||||
|
@ -200,7 +247,7 @@ namespace Bind
|
||||||
if (d != last_delegate)
|
if (d != last_delegate)
|
||||||
{
|
{
|
||||||
last_delegate = d;
|
last_delegate = d;
|
||||||
sw.WriteLine("static {0} (*p{1})({2});", d.ReturnType, f.TrimmedName, d.Parameters);
|
sw.WriteLine("static {0} (*p{1}){2};", d.ReturnType, f.TrimmedName, d.Parameters);
|
||||||
sw.WriteLine("extern p{0} {0};", f.TrimmedName);
|
sw.WriteLine("extern p{0} {0};", f.TrimmedName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,20 +336,15 @@ namespace Bind
|
||||||
{
|
{
|
||||||
foreach (Enum @enum in enums.Values)
|
foreach (Enum @enum in enums.Values)
|
||||||
{
|
{
|
||||||
sw.Write("struct ");
|
sw.WriteLine("struct {0} : Enumeration<{0}>", @enum.Name);
|
||||||
sw.Write(@enum.Name);
|
|
||||||
sw.Write(" : Enumeration<");
|
|
||||||
sw.Write(@enum.Name);
|
|
||||||
sw.WriteLine(">");
|
|
||||||
sw.WriteLine("{");
|
sw.WriteLine("{");
|
||||||
sw.Indent();
|
sw.Indent();
|
||||||
sw.WriteLine("enum ");
|
sw.WriteLine("enum");
|
||||||
sw.WriteLine("{");
|
sw.WriteLine("{");
|
||||||
sw.Indent();
|
sw.Indent();
|
||||||
foreach (var c in @enum.ConstantCollection.Values)
|
foreach (var c in @enum.ConstantCollection.Values)
|
||||||
{
|
{
|
||||||
sw.Write(c);
|
sw.WriteLine("{0},", c);
|
||||||
sw.WriteLine(",");
|
|
||||||
}
|
}
|
||||||
sw.Unindent();
|
sw.Unindent();
|
||||||
sw.WriteLine("};");
|
sw.WriteLine("};");
|
||||||
|
|
Loading…
Reference in a new issue