コード例 #1
0
ファイル: VeldridStartup.cs プロジェクト: suprafun/veldrid
        public static GraphicsDevice CreateGraphicsDevice(ref GraphicsDeviceCreateInfo graphicsDeviceCI, Sdl2Window window)
        {
            GraphicsBackend?backend = graphicsDeviceCI.Backend;

            if (!backend.HasValue)
            {
                backend = GetPlatformDefaultBackend();
            }
            switch (backend)
            {
            case GraphicsBackend.Direct3D11:
                return(CreateDefaultD3D11GraphicsDevice(ref graphicsDeviceCI, window));

            case GraphicsBackend.Vulkan:
                return(CreateVulkanGraphicsDevice(ref graphicsDeviceCI, window));

            case GraphicsBackend.OpenGL:
                return(CreateDefaultOpenGLRenderContext(ref graphicsDeviceCI, window));

            //case GraphicsBackend.OpenGLES:
            //    return CreateDefaultOpenGLESRenderContext(ref contextCI, window);
            default:
                throw new VeldridException("Invalid GraphicsBackend: " + graphicsDeviceCI.Backend);
            }
        }
コード例 #2
0
ファイル: VeldridStartup.cs プロジェクト: suprafun/veldrid
 public static void CreateWindowAndGraphicsDevice(
     ref WindowCreateInfo windowCI,
     ref GraphicsDeviceCreateInfo graphicsDeviceCI,
     out Sdl2Window window,
     out GraphicsDevice gd)
 {
     window = CreateWindow(ref windowCI);
     gd     = CreateGraphicsDevice(ref graphicsDeviceCI, window);
 }
コード例 #3
0
ファイル: VeldridStartup.cs プロジェクト: suprafun/veldrid
        public static GraphicsDevice CreateDefaultD3D11GraphicsDevice(ref GraphicsDeviceCreateInfo deviceCI, Sdl2Window window)
        {
            SharpDX.Direct3D11.DeviceCreationFlags flags = SharpDX.Direct3D11.DeviceCreationFlags.None;
            if (deviceCI.DebugDevice)
            {
                flags |= SharpDX.Direct3D11.DeviceCreationFlags.Debug;
            }

            return(Hacks.CreateD3D11(window.Handle, window.Width, window.Height));
        }
コード例 #4
0
ファイル: VeldridStartup.cs プロジェクト: suprafun/veldrid
        public static unsafe GraphicsDevice CreateVulkanGraphicsDevice(ref GraphicsDeviceCreateInfo contextCI, Sdl2Window window)
        {
            IntPtr        sdlHandle = window.SdlWindowHandle;
            SDL_SysWMinfo sysWmInfo;

            Sdl2Native.SDL_GetVersion(&sysWmInfo.version);
            Sdl2Native.SDL_GetWMWindowInfo(sdlHandle, &sysWmInfo);
            VkSurfaceSource surfaceSource = GetSurfaceSource(sysWmInfo);
            GraphicsDevice  gd            = Hacks.CreateVulkan(surfaceSource, (uint)window.Width, (uint)window.Height, contextCI.DebugDevice);

            return(gd);
        }
コード例 #5
0
ファイル: VeldridStartup.cs プロジェクト: suprafun/veldrid
        //public static OpenGLESRenderContext CreateDefaultOpenGLESRenderContext(ref RenderContextCreateInfo contextCI, Sdl2Window window)
        //{
        //    if (contextCI.DebugContext)
        //    {
        //        Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextFlags, (int)SDL_GLContextFlag.Debug);
        //    }

        //    IntPtr sdlHandle = window.SdlWindowHandle;
        //    Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextProfileMask, (int)SDL_GLProfile.ES);
        //    Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextMajorVersion, 3);
        //    Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextMinorVersion, 0);
        //    IntPtr contextHandle = Sdl2Native.SDL_GL_CreateContext(sdlHandle);
        //    Sdl2Native.SDL_GL_MakeCurrent(sdlHandle, contextHandle);

        //    if (contextHandle == IntPtr.Zero)
        //    {
        //        unsafe
        //        {
        //            byte* error = Sdl2Native.SDL_GetError();
        //            string errorString = Utilities.GetString(error);
        //            throw new VeldridException("Unable to create GL Context: " + errorString);
        //        }
        //    }

        //    OpenGLPlatformContextInfo ci = new OpenGLPlatformContextInfo(
        //        contextHandle,
        //        Sdl2Native.SDL_GL_GetProcAddress,
        //        Sdl2Native.SDL_GL_GetCurrentContext,
        //        () => Sdl2Native.SDL_GL_SwapWindow(sdlHandle));
        //    OpenGLESRenderContext rc = new OpenGLESRenderContext(window, ci);
        //    if (contextCI.DebugContext)
        //    {
        //        rc.EnableDebugCallback(OpenTK.Graphics.ES30.DebugSeverity.DebugSeverityLow);
        //    }
        //    return rc;
        //}

        public static GraphicsDevice CreateDefaultOpenGLRenderContext(ref GraphicsDeviceCreateInfo gdCI, Sdl2Window window)
        {
            IntPtr sdlHandle = window.SdlWindowHandle;

            if (gdCI.DebugDevice)
            {
                Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextFlags, (int)SDL_GLContextFlag.Debug);
            }

            Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextProfileMask, (int)SDL_GLProfile.Core);
            Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextMajorVersion, 4);
            Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextMinorVersion, 0);

            IntPtr contextHandle = Sdl2Native.SDL_GL_CreateContext(sdlHandle);

            if (contextHandle == IntPtr.Zero)
            {
                unsafe
                {
                    byte * error       = Sdl2Native.SDL_GetError();
                    string errorString = GetString(error);
                    throw new VeldridException("Unable to create GL Context: " + errorString);
                }
            }

            int result = Sdl2Native.SDL_GL_SetSwapInterval(0);

            OpenGLPlatformInfo platformInfo = new OpenGLPlatformInfo(
                contextHandle,
                Sdl2Native.SDL_GL_GetProcAddress,
                context => Sdl2Native.SDL_GL_MakeCurrent(sdlHandle, context),
                Sdl2Native.SDL_GL_DeleteContext,
                () => Sdl2Native.SDL_GL_SwapWindow(sdlHandle));

            return(Hacks.CreateOpenGL(
                       platformInfo,
                       (uint)window.Width,
                       (uint)window.Height,
                       gdCI.DebugDevice));
        }