From 18e10653c05b2feacfc80552d3ce2c9ec169f404 Mon Sep 17 00:00:00 2001 From: Amer Koleci Date: Thu, 1 Sep 2022 10:41:06 +0200 Subject: [PATCH] Initial setup --- .editorconfig | 194 +++++++++++++ .github/FUNDING.yml | 1 + .github/workflows/build.yml | 38 +++ .gitignore | 260 ++++++++++++++++++ Directory.Build.props | 42 +++ Directory.Build.targets | 15 + LICENSE | 21 ++ NuGet.config | 13 + README.md | 29 ++ Vortice.Win32.sln | 53 ++++ src/Generator/CodeWriter.cs | 164 +++++++++++ src/Generator/Generator.csproj | 19 ++ src/Generator/Program.cs | 28 ++ src/Vortice.Win32/Vortice.Win32.csproj | 22 ++ .../01-ClearScreen/01-ClearScreen.csproj | 13 + src/samples/01-ClearScreen/Program.cs | 14 + 16 files changed, 926 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/build.yml create mode 100644 .gitignore create mode 100644 Directory.Build.props create mode 100644 Directory.Build.targets create mode 100644 LICENSE create mode 100644 NuGet.config create mode 100644 README.md create mode 100644 Vortice.Win32.sln create mode 100644 src/Generator/CodeWriter.cs create mode 100644 src/Generator/Generator.csproj create mode 100644 src/Generator/Program.cs create mode 100644 src/Vortice.Win32/Vortice.Win32.csproj create mode 100644 src/samples/01-ClearScreen/01-ClearScreen.csproj create mode 100644 src/samples/01-ClearScreen/Program.cs diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..921c81f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,194 @@ +# editorconfig.org + +# top-most EditorConfig file +root = true + +# Default settings: +# A newline ending every file +# Use 4 spaces as indentation +[*] +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +# Generated code +[*{_AssemblyInfo.cs,.notsupported.cs,AsmOffsets.cs}] +generated_code = true + +[project.json] +indent_size = 2 + +# C# files +[*.cs] +# New line preferences +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_switch_labels = true +csharp_indent_labels = one_less_than_current + +# Modifier preferences +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion + +# avoid this. unless absolutely necessary +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_event = false:suggestion + +# Types: use keywords instead of BCL types, and permit var only when the type is clear +csharp_style_var_for_built_in_types = false:suggestion +csharp_style_var_when_type_is_apparent = false:none +csharp_style_var_elsewhere = false:suggestion +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion + +# name all constant fields using PascalCase +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.required_modifiers = const +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +# static fields should have s_ prefix +dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion +dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields +dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style +dotnet_naming_symbols.static_fields.applicable_kinds = field +dotnet_naming_symbols.static_fields.required_modifiers = static +dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected +dotnet_naming_style.static_prefix_style.required_prefix = s_ +dotnet_naming_style.static_prefix_style.capitalization = camel_case + +# internal and private fields should be _camelCase +dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion +dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +dotnet_naming_symbols.private_internal_fields.applicable_kinds = field +dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal +dotnet_naming_style.camel_case_underscore_style.required_prefix = _ +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case + +# Code style defaults +csharp_using_directive_placement = outside_namespace:error +dotnet_sort_system_directives_first = true +csharp_prefer_braces = true:silent +csharp_preserve_single_line_blocks = true:none +csharp_preserve_single_line_statements = false:none +csharp_prefer_static_local_function = true:suggestion +csharp_prefer_simple_using_statement = false:none +csharp_style_prefer_switch_expression = true:suggestion +dotnet_style_readonly_field = true:suggestion + +# Expression-level preferences +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +csharp_prefer_simple_default_expression = true:suggestion + +# Expression-bodied members +csharp_style_expression_bodied_methods = true:silent +csharp_style_expression_bodied_constructors = true:silent +csharp_style_expression_bodied_operators = true:silent +csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = true:silent + +# Pattern matching +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion + +# Null checking preferences +csharp_style_throw_expression = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion + +# Other features +csharp_style_prefer_index_operator = false:none +csharp_style_prefer_range_operator = false:none +csharp_style_pattern_local_over_anonymous_function = false:none + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = do_not_ignore +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +csharp_style_namespace_declarations=file_scoped:error + +# License header +file_header_template = Copyright © Amer Koleci and Contributors.\nLicensed under the MIT License (MIT). See LICENSE in the repository root for more information. + +# C++ Files +[*.{cpp,h,in}] +curly_bracket_next_line = true +indent_brace_style = Allman + +# Xml project files +[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] +indent_size = 2 + +[*.{csproj,vbproj,proj,nativeproj,locproj}] +charset = utf-8 + +# Xml build files +[*.builds] +indent_size = 2 + +# Xml files +[*.{xml,stylecop,resx,ruleset}] +indent_size = 2 + +# Xml config files +[*.{props,targets,config,nuspec}] +indent_size = 2 + +# YAML config files +[*.{yml,yaml}] +indent_size = 2 + +# Shell scripts +[*.sh] +end_of_line = lf +[*.{cmd,bat}] +end_of_line = crlf diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..ed89b3c --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [amerkoleci] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..2bf3fef --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,38 @@ +name: Build + +on: + push: + branches: + - 'main' + paths-ignore: + - '*.md' + - 'LICENSE' + pull_request: + paths-ignore: + - '*.md' + - 'LICENSE' + +env: + DOTNET_CLI_TELEMETRY_OPTOUT: false + +jobs: + build: + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup .NET 6.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 6.0.x + + - name: Pack + run: dotnet pack Vortice.Win32.sln --configuration Release --output build/packages + + - name: Publish to NuGet + if: github.event_name == 'push' + run: dotnet nuget push build/packages/**/*.nupkg -k ${{secrets.NUGET_TOKEN}} --skip-duplicate --source https://api.nuget.org/v3/index.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dae3b69 --- /dev/null +++ b/.gitignore @@ -0,0 +1,260 @@ +syntax: glob + +#NuGet things +project.lock.json + +### VisualStudio ### + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +msbuild.log + +# Visual Studio 2015 +.vs/ + +# Visual Studio 2015 Pre-CTP6 +*.sln.ide +*.ide/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +**/packages/* + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +*.metaproj +*.metaproj.tmp + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +### MonoDevelop ### + +*.pidb +*.userprefs + +### Windows ### + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +### Linux ### + +*~ + +# KDE directory preferences +.directory + +### OSX ### + +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# vim temporary files +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +*.un~ +Session.vim +.netrwhist +*~ + +*.ini +*.VC.db +*.nvact +*.opendb + +#VS Code stuff + +.vscode +launchSettings.json diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..4438b28 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,42 @@ + + + 10.0 + enable + enable + true + + true + CS1591;CS1701 + + + + https://github.com/amerkoleci/Vortice.Win32 + git + + https://github.com/amerkoleci/Vortice.Win32 + Amer Koleci + Amer Koleci + Amer Koleci + Copyright © 2022 Amer Koleci + MIT + true + win32 graphics gamedev core standard game vortice + + + + + true + true + false + snupkg + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + + + all + runtime; build; native; contentfiles; analyzers + + + + diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000..3b0b2cc --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,15 @@ + + + + + + true + + + + + true + true + + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..01d2d1c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2022 Amer Koleci + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/NuGet.config b/NuGet.config new file mode 100644 index 0000000..5e7f1cc --- /dev/null +++ b/NuGet.config @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..6ff1a95 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Vortice.Vulkan + +[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/amerkoleci/Vortice.Vulkan/blob/main/LICENSE) +[![Build status](https://github.com/amerkoleci/Vortice.Vulkan/workflows/Build/badge.svg)](https://github.com/amerkoleci/Vortice.Vulkan/actions) +[![Vulkan](https://img.shields.io/badge/vulkan-1.3.225-brightgreen.svg)](https://www.khronos.org/vulkan/) +[![NuGet](https://img.shields.io/nuget/v/Vortice.Vulkan.svg)](https://www.nuget.org/packages/Vortice.Vulkan) + +**Vortice.Vulkan** is a .NET Standard 2.0 and .NET 6.0 low-level bindings for [Vulkan](https://www.khronos.org/vulkan/), [VulkanMemoryAllocator](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator), [SPIRV-Cross](https://github.com/KhronosGroup/SPIRV-Cross) and [shaderc](https://github.com/google/shaderc). + +## Sponsors +To further help development of these bindings library or other projects, please consider [SPONSOR](https://github.com/sponsors/amerkoleci) my profile in order to allow faster issue triaging and new features to be implemented. + +## Credits + +Vortice.Vulkan development, contributions and bugfixes by: + +- Amer Koleci + +Ideas and generator part is based on [vk](https://github.com/mellinoe/vk) + +Other similar projects: + +- [vk](https://github.com/mellinoe/vk) +- [VulkanCore](https://github.com/discosultan/VulkanCore) +- [Silk.NET](https://github.com/dotnet/Silk.NET) + +Projects using Vortice.Vulkan: + +- [Stride Game Engine (formerly Xenko)](https://stride3d.net/) diff --git a/Vortice.Win32.sln b/Vortice.Win32.sln new file mode 100644 index 0000000..f865f2a --- /dev/null +++ b/Vortice.Win32.sln @@ -0,0 +1,53 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31808.319 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vortice.Win32", "src\Vortice.Win32\Vortice.Win32.csproj", "{428306C9-6B88-4296-AD5C-82778B3D675B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Generator", "src\Generator\Generator.csproj", "{41382FC3-7129-46CA-9D0F-52302C1ED692}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{08F6AF96-809B-45C5-BE6C-5BAB7D9AFB60}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "01-ClearScreen", "src\samples\01-ClearScreen\01-ClearScreen.csproj", "{5A10816D-90A4-4AEA-B06E-6A463DA4A891}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{065268A8-16E6-4CFF-8F67-3FD99155877F}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + .gitignore = .gitignore + Directory.Build.props = Directory.Build.props + Directory.Build.targets = Directory.Build.targets + LICENSE = LICENSE + NuGet.config = NuGet.config + README.md = README.md + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {428306C9-6B88-4296-AD5C-82778B3D675B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {428306C9-6B88-4296-AD5C-82778B3D675B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {428306C9-6B88-4296-AD5C-82778B3D675B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {428306C9-6B88-4296-AD5C-82778B3D675B}.Release|Any CPU.Build.0 = Release|Any CPU + {41382FC3-7129-46CA-9D0F-52302C1ED692}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {41382FC3-7129-46CA-9D0F-52302C1ED692}.Debug|Any CPU.Build.0 = Debug|Any CPU + {41382FC3-7129-46CA-9D0F-52302C1ED692}.Release|Any CPU.ActiveCfg = Release|Any CPU + {41382FC3-7129-46CA-9D0F-52302C1ED692}.Release|Any CPU.Build.0 = Release|Any CPU + {5A10816D-90A4-4AEA-B06E-6A463DA4A891}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5A10816D-90A4-4AEA-B06E-6A463DA4A891}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5A10816D-90A4-4AEA-B06E-6A463DA4A891}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5A10816D-90A4-4AEA-B06E-6A463DA4A891}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {5A10816D-90A4-4AEA-B06E-6A463DA4A891} = {08F6AF96-809B-45C5-BE6C-5BAB7D9AFB60} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DF0375B3-E304-4A53-8E5F-FC9D23743647} + EndGlobalSection +EndGlobal diff --git a/src/Generator/CodeWriter.cs b/src/Generator/CodeWriter.cs new file mode 100644 index 0000000..7ec0e05 --- /dev/null +++ b/src/Generator/CodeWriter.cs @@ -0,0 +1,164 @@ +// Copyright © Amer Koleci and Contributors. +// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. + +namespace Generator; + +public sealed class CodeWriter : IDisposable +{ + private bool _shouldIndent = true; + private readonly string[] _indentStrings; + private string _indentString = ""; + private readonly StreamWriter _writer; + + public int IndentLevel { get; private set; } + + public CodeWriter(string fileName, bool enableNullable, params string[] namespaces) + { + _indentStrings = new string[10]; + for (int i = 0; i < _indentStrings.Length; i++) + { + _indentStrings[i] = new string('\t', i); + } + + _writer = File.CreateText(fileName); + _writer.WriteLine("// ------------------------------------------------------------------------------"); + _writer.WriteLine("// "); + _writer.WriteLine("// This code was generated by a tool."); + _writer.WriteLine("//"); + _writer.WriteLine("// Changes to this file may cause incorrect behavior and will be lost if"); + _writer.WriteLine("// the code is regenerated."); + _writer.WriteLine("// "); + _writer.WriteLine("// ------------------------------------------------------------------------------"); + _writer.WriteLine(); + + if (enableNullable) + { + _writer.WriteLine($"#nullable enable"); + _writer.WriteLine(); + } + + foreach (string ns in namespaces) + { + _writer.WriteLine($"using {ns};"); + } + + if (namespaces.Length > 0) + { + _writer.WriteLine(); + } + + _writer.WriteLine("namespace Vortice.Vulkan;"); + _writer.WriteLine(); + } + + public void Dispose() + { + _writer.Dispose(); + } + + public void Write(char chr) + { + WriteIndented(chr); + } + + public void Write(string @string) + { + WriteIndented(@string); + } + + public void WriteLine() + { + _writer.WriteLine(); + _shouldIndent = true; + } + + public void WriteLine(string @string) + { + WriteIndented(@string); + _writer.WriteLine(); + _shouldIndent = true; + } + + public void BeginBlock(string content) + { + WriteLine(content); + WriteLine("{"); + Indent(1); + } + + public void EndBlock() + { + Dedent(1); + WriteLine("}"); + } + + public IDisposable PushBlock(string marker = "{") => new CodeBlock(this, marker); + + public void Indent(int count = 1) + { + IndentLevel += count; + + if (IndentLevel < _indentStrings.Length) + { + _indentString = _indentStrings[IndentLevel]; + } + else + { + _indentString = new string('\t', IndentLevel); + } + } + + public void Dedent(int count = 1) + { + if (count > IndentLevel) + throw new ArgumentException("count out of range.", nameof(count)); + + IndentLevel -= count; + if (IndentLevel < _indentStrings.Length) + { + _indentString = _indentStrings[IndentLevel]; + } + else + { + _indentString = new string('\t', IndentLevel); + } + } + + private void WriteIndented(char chr) + { + if (_shouldIndent) + { + _writer.Write(_indentString); + _shouldIndent = false; + } + + _writer.Write(chr); + } + + private void WriteIndented(string @string) + { + if (_shouldIndent) + { + _writer.Write(_indentString); + _shouldIndent = false; + } + + _writer.Write(@string); + } + + private class CodeBlock : IDisposable + { + private readonly CodeWriter _writer; + + public CodeBlock(CodeWriter writer, string content) + { + _writer = writer; + _writer.BeginBlock(content); + } + + public void Dispose() + { + _writer.EndBlock(); + } + } +} diff --git a/src/Generator/Generator.csproj b/src/Generator/Generator.csproj new file mode 100644 index 0000000..1d5d07e --- /dev/null +++ b/src/Generator/Generator.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + Exe + true + false + + + + + PreserveNewest + + + PreserveNewest + + + + diff --git a/src/Generator/Program.cs b/src/Generator/Program.cs new file mode 100644 index 0000000..d58bdef --- /dev/null +++ b/src/Generator/Program.cs @@ -0,0 +1,28 @@ +// Copyright © Amer Koleci and Contributors. +// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. + +namespace Generator; + +public static class Program +{ + public static int Main(string[] args) + { + string outputPath = AppContext.BaseDirectory; + if (args.Length > 0) + { + outputPath = args[0]; + } + + if (!Path.IsPathRooted(outputPath)) + { + outputPath = Path.Combine(AppContext.BaseDirectory, outputPath); + } + + if (!Directory.Exists(outputPath)) + { + Directory.CreateDirectory(outputPath); + } + + return 0; + } +} diff --git a/src/Vortice.Win32/Vortice.Win32.csproj b/src/Vortice.Win32/Vortice.Win32.csproj new file mode 100644 index 0000000..0ff8034 --- /dev/null +++ b/src/Vortice.Win32/Vortice.Win32.csproj @@ -0,0 +1,22 @@ + + + + netstandard2.0;net6.0; + Windows API low level bindings. + 1.0.0 + + + + + + + + + + + + + + + + diff --git a/src/samples/01-ClearScreen/01-ClearScreen.csproj b/src/samples/01-ClearScreen/01-ClearScreen.csproj new file mode 100644 index 0000000..06b3174 --- /dev/null +++ b/src/samples/01-ClearScreen/01-ClearScreen.csproj @@ -0,0 +1,13 @@ + + + Exe + net461;net6.0 + true + false + ClearScreen + x64 + + + + + diff --git a/src/samples/01-ClearScreen/Program.cs b/src/samples/01-ClearScreen/Program.cs new file mode 100644 index 0000000..a5f9600 --- /dev/null +++ b/src/samples/01-ClearScreen/Program.cs @@ -0,0 +1,14 @@ +// Copyright © Amer Koleci and Contributors. +// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. + +using System.Numerics; + +namespace ClearScreen; + +public static unsafe class Program +{ + public static void Main() + { + + } +}