Coder Social home page Coder Social logo

sharpvk-samples's People

Contributors

facticiusvir avatar kaktusbot avatar realvictorprm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sharpvk-samples's Issues

Linux

I've tested SharpVK on linux, to have it working (debian 10):

  1. change 'glfw3' to 'glfw' for library name, under debian, lib has the version suffixes out of the scope of dll import.
  2. use 'Path.Combine' to build shader pathes (directory backslash is for win only).

After these two simple steps, HelloTriangle works.

Switch samples to use GLFW

Current sample projects use WinForms as the Surface host, which makes them dependent on Windows; GLFW is a cross-platform window library with explicit support for Vulkan Surfaces.

Running om macosx

Hello I am quite inexperienced at this. Any chance anyone has gotten this to work on macosx? I get the following error when building, after adding sharpvk.glfw och sharpvk.shanq via nuget. Anyone have a workaround?

screen shot 2019-03-01 at 09 42 57

CreateDebugReportCallback leads to a System.ArgumentNullException

Hello,
When attempting to run CreateDebugReportCallback, I encounter a System.ArgumentNullException.

Here is the stack trace:

Value cannot be null. (Parameter 'ptr')
Stack trace:    at System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(IntPtr ptr, Type t)
   at System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer[TDelegate](IntPtr ptr)
   at SharpVk.CommandCache.GetCommandDelegate[T](String name, String type)
   at SharpVk.Multivendor.InstanceExtensions.CreateDebugReportCallback(Instance extendedHandle, DebugReportCallbackDelegate callback, Nullable`1 flags, Nullable`1 userData, Nullable`1 allocator)
   at DNA.Application..ctor(Int32 windowWidth, Int32 windowHeight) in C:\Users\Woodensponge\Documents\GitHub\Dust-and-Ashes\Dust and Ashes\Application.cs:line 83
   at Program.Run(String[] args) in C:\Users\Woodensponge\Documents\GitHub\Dust-and-Ashes\Dust and Ashes\Program.cs:line 36
   at Program.Main(String[] args) in C:\Users\Woodensponge\Documents\GitHub\Dust-and-Ashes\Dust and Ashes\Program.cs:line 12

Here is my code involving the whole process of creation.

Application.cs

using System;
using SharpVk.Glfw;
using SharpVk;
using System.Collections.Generic;
using System.Linq;

using DNA.Game;
using DNA.Game.StateTypes;
using DNA.Rendering;
using DNA.Utility;
using SharpVk.Multivendor;

namespace DNA
{
    [Flags]
    enum AppFlags
    {
        Running = 1 << 0,
        Minimized = 1 << 1
    }

    class Application : Singleton<Application>, IDisposable
    {
        public Application()
            : this(640, 480)
        {
            //TODO: Add configuration functionality, utilizing both the registry AND a config file.
        }

        public Application(int windowWidth, int windowHeight)
        {
            Debug.Log("Initiating Application...");

            WindowWidth = windowWidth;
            WindowHeight = windowHeight;
            
            //Glfw stuff

            Glfw3.Init();
            Glfw3.SetErrorCallback(_glfwErrorDelegate);
            
            Window = Glfw3.CreateWindow(windowWidth, windowHeight, "Dust and Ashes", IntPtr.Zero, IntPtr.Zero);

            int screenWidth, screenHeight;
            Glfw3.GetMonitorPhysicalSize(Glfw3.GetPrimaryMonitor(), out screenWidth, out screenHeight);
            int windowX = (screenWidth - windowWidth) / 2;
            int windowY = (screenHeight - windowHeight) / 2;
            

            if (Window.RawHandle == IntPtr.Zero)
            {
                Debug.LogError("Glfw could not instance a window. Aborting program.");
            }

            //Vulkan Stuff
            Vulkan.Instance.GetRequiredExtensions();
            
            Vulkan.Instance.AddValidationLayer("VK_LAYER_LUNARG_standard_validation");
            Vulkan.Instance.AddExtension(ExtExtensions.DebugReport);

            Vulkan.Instance.CreateVulkanInstance(appInfo: new ApplicationInfo()
            {
                ApiVersion = new SharpVk.Version(1, 0, 0),
                ApplicationVersion = new SharpVk.Version(1, 0, 0),
                ApplicationName = "Dust and Ashes",
                EngineName = "Dust and Ashes Engine",
                EngineVersion = new SharpVk.Version(1, 0, 0)
            });

            /*
             Value cannot be null. (Parameter 'ptr')
                Stack trace:    at System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(IntPtr ptr, Type t)
                at System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer[TDelegate](IntPtr ptr)
                at SharpVk.CommandCache.GetCommandDelegate[T](String name, String type)
                at SharpVk.Multivendor.InstanceExtensions.CreateDebugReportCallback(Instance extendedHandle, DebugReportCallbackDelegate callback, Nullable`1 flags, Nullable`1 userData, Nullable`1 allocator)
                at DNA.Application..ctor(Int32 windowWidth, Int32 windowHeight) in C:\Users\Woodensponge\Documents\GitHub\Dust-and-Ashes\Dust and Ashes\Application.cs:line 74
                at Program.Run(String[] args) in C:\Users\Woodensponge\Documents\GitHub\Dust-and-Ashes\Dust and Ashes\Program.cs:line 36
                at Program.Main(String[] args) in C:\Users\Woodensponge\Documents\GitHub\Dust-and-Ashes\Dust and Ashes\Program.cs:line 12
             */
#if !DEBUG
            Vulkan.Instance.VkInstance.CreateDebugReportCallback(_debugReportVulkan, DebugReportFlags.Error | DebugReportFlags.Warning);
#elif DEBUG
            Vulkan.Instance.VkInstance.CreateDebugReportCallback
                (
                _debugReportVulkan,
                DebugReportFlags.Error |
                DebugReportFlags.Warning |
                DebugReportFlags.PerformanceWarning |
                DebugReportFlags.Information |
                DebugReportFlags.Debug
                );
#endif
            Flags |= AppFlags.Running;

            CurrentState = new GameState();
        }

        public void Dispose()
        {
            CurrentState.Dispose();

            Glfw3.Terminate();
        }

        public void Render()
        {
            CurrentState.Render();
        }

        public void Update()
        {
            PollEvents();
            
            CurrentState.Update();

            //State switching
            if (CurrentState.StateToBeSwitched != null)
            {
                State newState = CurrentState.StateToBeSwitched;
                
                Debug.Log($"Switching state from {CurrentState.GetType().Name} to {newState.GetType().Name}.");
                CurrentState.Dispose();
                CurrentState = newState;
                
                Debug.Log("SWITCHED STATES!");
            }

            Render();
        }

        static void GlfwErrorLog(int error, string description)
        {
            Debug.Log($"GLFW ERROR | CODE:{error} | Message: {description}");
        }

        static void GlfwWindowSize(WindowHandle window, int width, int height)
        {
            Instance.WindowWidth = width;
            Instance.WindowHeight = height;
            Debug.Log($"Width: {width} Height: {height}");
        }

        static Bool32 DebugLogVulkan(DebugReportFlags flags, DebugReportObjectType objectType, ulong @object, HostSize location, int messageCode, string pLayerPrefix, string pMessage, IntPtr pUserData)
        {
            Debug.Log($"VULKAN | Report type: {flags} | CODE: {messageCode} | Message: {pMessage}");
            return new Bool32(true);
        }
        void FixedUpdate()
        {
            //TODO: Add timestep (also actual functionality.)
            CurrentState.FixedUpdate();
        }

        void PollEvents()
        {
            Glfw3.PollEvents();
            if (Glfw3.WindowShouldClose(Window))
            {
                Flags &= ~AppFlags.Running;
            }
        }

        public int WindowWidth;
        public int WindowHeight;

        public State CurrentState;

        public WindowHandle Window
        {
            get
            {
                return _window;
            }
            private set
            {
                _window = value;
            }
        }
        public AppFlags Flags;
        WindowHandle _window;

        static readonly ErrorDelegate _glfwErrorDelegate = GlfwErrorLog;
        static readonly WindowSizeDelegate _glfwWindowSizeDelegate = GlfwWindowSize;
        static readonly DebugReportCallbackDelegate _debugReportVulkan = DebugLogVulkan;
    }
}

Vulkan.cs

using System.Collections.Generic;
using System.Linq;
using SharpVk.Glfw;

using DNA.Utility;
using SharpVk.Multivendor;
using System;

namespace DNA.Rendering
{
    class Vulkan : Singleton<Vulkan>
    {
        public List<string> AddExtension(string extension)
        {
            extensions.Append(extension);
            return extensions;
        }

        /// <summary>
        /// Adds validation layers before the instance is created.
        /// </summary>
        /// <param name="layerName"></param>
        /// <returns>The enabled layers list on success. Null on error.</returns>
        public List<string> AddValidationLayer(string layerName)
        {
            if (SharpVk.Instance.EnumerateLayerProperties().Any(x => x.LayerName == layerName))
            {
                enabledLayers.Add(layerName);
            }
            else if (SharpVk.Instance.EnumerateLayerProperties().Any(x => x.LayerName != layerName))
            {
                return null;
            }
            return enabledLayers;
        }

        public SharpVk.Instance CreateVulkanInstance(SharpVk.ApplicationInfo appInfo)
        {
            VkInstance = SharpVk.Instance.Create(enabledLayers.ToArray(), extensions.ToArray(), SharpVk.InstanceCreateFlags.None, appInfo);

            return VkInstance;
        }

        /// <summary>
        /// Gets the required extensions needed to properly run vulkan. Must be run before instance creation.
        /// </summary>
        /// <returns>The extention list on success. Null on error.</returns>
        public List<string> GetRequiredExtensions()
        {
            extensions = Glfw3.GetRequiredInstanceExtensions().ToList();

            Debug.Log($"Loaded required Vulkan extensions: {extensions.Count}");
            foreach (string extension in extensions)
            {
                Debug.Log($"   {extension}");
            }

            return extensions;
        }

        public SharpVk.Instance VkInstance;
        public List<string> extensions = new List<string>();
        public List<string> enabledLayers = new List<string>();
    }
}

Help would be greatly appreciated.

EDIT: Not only is this the wrong repository, but I've already found what was causing the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.