mirror of
https://github.com/amerkoleci/Vortice.Win32.git
synced 2026-01-14 16:16:04 +08:00
More generation (add initial functions generation) and D3D11 logic.
This commit is contained in:
@@ -60,6 +60,7 @@ public class ApiFunction
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public bool SetLastError { get; set; }
|
||||
public string DllImport { get; set; }
|
||||
public ApiDataType ReturnType { get; set; }
|
||||
public List<object> ReturnAttrs { get; set; }
|
||||
|
||||
|
||||
@@ -331,6 +331,7 @@ public static class Program
|
||||
|
||||
GenerateConstants(writer, api);
|
||||
GenerateTypes(writer, api);
|
||||
GenerateFunctions(writer, api);
|
||||
}
|
||||
|
||||
private static void GenerateConstants(CodeWriter writer, ApiData api)
|
||||
@@ -516,6 +517,105 @@ public static class Program
|
||||
writer.WriteLine($"#endregion Com Types");
|
||||
}
|
||||
|
||||
private static void GenerateFunctions(CodeWriter writer, ApiData api)
|
||||
{
|
||||
if (api.Functions.Length == 0)
|
||||
return;
|
||||
|
||||
writer.WriteLine($"#region Functions");
|
||||
using (writer.PushBlock($"public static unsafe partial class Apis"))
|
||||
{
|
||||
foreach (ApiFunction function in api.Functions)
|
||||
{
|
||||
if (function.Name.StartsWith("D3DX11") ||
|
||||
function.Name == "D3DDisassemble11Trace")
|
||||
continue;
|
||||
|
||||
WriteFunction(writer, api, function);
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
writer.WriteLine($"#endregion Functions");
|
||||
}
|
||||
|
||||
private static void WriteFunction(CodeWriter writer, ApiData api, ApiFunction function)
|
||||
{
|
||||
string returnType = GetTypeName(function.ReturnType);
|
||||
string functionSuffix = string.Empty;
|
||||
|
||||
if (string.IsNullOrEmpty(function.DllImport) == false)
|
||||
{
|
||||
functionSuffix = "static extern ";
|
||||
writer.WriteLine($"[DllImport(\"{function.DllImport}\", ExactSpelling = true)]");
|
||||
}
|
||||
|
||||
StringBuilder argumentBuilder = new();
|
||||
StringBuilder argumentsTypesBuilder = new();
|
||||
StringBuilder argumentsNameBuilder = new();
|
||||
int parameterIndex = 0;
|
||||
foreach (ApiParameter parameter in function.Params)
|
||||
{
|
||||
bool asPointer = false;
|
||||
string parameterType = default;
|
||||
if (parameter.Type.Kind == "ApiRef")
|
||||
{
|
||||
if (parameter.Type.TargetKind == "FunctionPointer")
|
||||
{
|
||||
var functionType = api.Types.First(item => item.Name == parameter.Type.Name && item.Kind == "FunctionPointer");
|
||||
parameterType = "delegate* unmanaged[Stdcall]<void*, void>";
|
||||
}
|
||||
else
|
||||
{
|
||||
string fullTypeName = $"{parameter.Type.Api}.{parameter.Type.Name}";
|
||||
if (!IsEnum(fullTypeName))
|
||||
{
|
||||
asPointer = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(parameterType))
|
||||
{
|
||||
parameterType = GetTypeName(parameter.Type, asPointer);
|
||||
}
|
||||
|
||||
parameterType = NormalizeTypeName(writer.Api, parameterType);
|
||||
string parameterName = parameter.Name;
|
||||
|
||||
bool isOptional = parameter.Attrs.Any(item => item is string str && str == "Optional");
|
||||
if (parameter.Attrs.Any(item => item is string str && str == "ComOutPtr"))
|
||||
{
|
||||
if (!IsPrimitive(parameter.Type))
|
||||
{
|
||||
parameterType += "*";
|
||||
}
|
||||
}
|
||||
|
||||
argumentBuilder.Append(parameterType).Append(' ').Append(parameterName);
|
||||
if (isOptional == true)
|
||||
{
|
||||
//argumentBuilder.Append(" = default");
|
||||
}
|
||||
|
||||
argumentsTypesBuilder.Append(parameterType);
|
||||
argumentsNameBuilder.Append(parameterName);
|
||||
|
||||
if (parameterIndex < function.Params.Count - 1)
|
||||
{
|
||||
argumentBuilder.Append(", ");
|
||||
argumentsTypesBuilder.Append(", ");
|
||||
argumentsNameBuilder.Append(", ");
|
||||
}
|
||||
|
||||
parameterIndex++;
|
||||
}
|
||||
|
||||
string argumentsString = argumentBuilder.ToString();
|
||||
writer.Write($"public {functionSuffix}{returnType} {function.Name}({argumentsString})");
|
||||
writer.WriteLine(";");
|
||||
}
|
||||
|
||||
private static void GenerateEnum(CodeWriter writer, ApiType enumType, bool autoGenerated)
|
||||
{
|
||||
string csTypeName = GetDataTypeName(enumType.Name, out string enumPrefix);
|
||||
|
||||
Reference in New Issue
Block a user