Exemplo n.º 1
0
        public static RenderContext CreateRenderContext(ref RenderContextCreateInfo contextCI, Sdl2Window window)
        {
            GraphicsBackend?backend = contextCI.Backend;

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

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

            case GraphicsBackend.OpenGLES:
                return(CreateDefaultOpenGLESRenderContext(ref contextCI, window));

            case GraphicsBackend.Vulkan:
                return(CreateVulkanRenderContext(ref contextCI, window));

            default:
                throw new VeldridException("Invalid GraphicsBackend: " + contextCI.Backend);
            }
        }
Exemplo n.º 2
0
 public static void CreateWindowAndRenderContext(
     ref WindowCreateInfo windowCI,
     ref RenderContextCreateInfo contextCI,
     out Sdl2Window window,
     out RenderContext rc)
 {
     window = CreateWindow(ref windowCI);
     rc     = CreateRenderContext(ref contextCI, window);
 }
Exemplo n.º 3
0
        public static D3DRenderContext CreateDefaultD3DRenderContext(ref RenderContextCreateInfo contextCI, Sdl2Window window)
        {
            SharpDX.Direct3D11.DeviceCreationFlags flags = SharpDX.Direct3D11.DeviceCreationFlags.None;
            if (contextCI.DebugContext)
            {
                flags |= SharpDX.Direct3D11.DeviceCreationFlags.Debug;
            }

            return(new D3DRenderContext(window, flags));
        }
Exemplo n.º 4
0
        public static unsafe RenderContext CreateVulkanRenderContext(ref RenderContextCreateInfo contextCI, Sdl2Window window)
        {
            IntPtr        sdlHandle = window.SdlWindowHandle;
            SDL_SysWMinfo sysWmInfo;

            Sdl2Native.SDL_GetVersion(&sysWmInfo.version);
            Sdl2Native.SDL_GetWMWindowInfo(sdlHandle, &sysWmInfo);
            VkSurfaceSource surfaceSource = GetSurfaceSource(sysWmInfo);
            VkRenderContext rc            = new VkRenderContext(surfaceSource, window.Width, window.Height);

            if (contextCI.DebugContext)
            {
                rc.EnableDebugCallback();
            }

            return(rc);
        }
Exemplo n.º 5
0
        public static OpenGLRenderContext CreateDefaultOpenGLRenderContext(ref RenderContextCreateInfo contextCI, Sdl2Window window)
        {
            IntPtr sdlHandle = window.SdlWindowHandle;

            if (contextCI.DebugContext)
            {
                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 = Utilities.GetString(error);
                    throw new VeldridException("Unable to create GL Context: " + errorString);
                }
            }

            Sdl2Native.SDL_GL_MakeCurrent(sdlHandle, contextHandle);
            OpenGLPlatformContextInfo ci = new OpenGLPlatformContextInfo(
                contextHandle,
                Sdl2Native.SDL_GL_GetProcAddress,
                Sdl2Native.SDL_GL_GetCurrentContext,
                () => Sdl2Native.SDL_GL_SwapWindow(sdlHandle));
            OpenGLRenderContext rc = new OpenGLRenderContext(window, ci);

            if (contextCI.DebugContext)
            {
                // Slows things down significantly -- Only use when debugging something specific.
                rc.EnableDebugCallback(OpenTK.Graphics.OpenGL.DebugSeverity.DebugSeverityNotification);
            }
            return(rc);
        }