コード例 #1
0
ファイル: Devices.cs プロジェクト: Kharzette/GrogLibsCore
 public Devices(DrunkSpock spock)
 {
     ExaminePhysicalDevices(spock.GetInstance(), spock.GetSurface());
 }
コード例 #2
0
ファイル: GameWindow.cs プロジェクト: Kharzette/GrogLibsCore
        public GameWindow(DrunkSpock ds, bool bResizable, string title,
                          int width, int height, int monitorIndex, bool bCenter)
        {
            //set GLFW_NO_API
            Glfw.WindowHint(Hint.ClientApi, 0);
            Glfw.WindowHint(Hint.Resizable, bResizable);

            if (monitorIndex < 0 || monitorIndex >= Glfw.Monitors.Length)
            {
                monitorIndex = 0;
            }

            //my linux implementation has no monitor work area function
            List <int> xCoords = new List <int>();
            List <int> yCoords = new List <int>();

            for (int i = 0; i < Glfw.Monitors.Length; i++)
            {
                int mx, my;
                Glfw.GetMonitorPosition(Glfw.Monitors[i], out mx, out my);

                xCoords.Add(mx);
                yCoords.Add(my);
            }

            mWnd = Glfw.CreateWindow(width, height, title,
                                     Monitor.None, Window.None);

            int x, y;

            Glfw.GetWindowPosition(mWnd, out x, out y);

            //figure out which monitor the window is on
            int bestMonitorIndex = -1;
            int bestDist         = Int32.MaxValue;

            for (int i = 0; i < Glfw.Monitors.Length; i++)
            {
                if (x > xCoords[i])
                {
                    int dist = x - xCoords[i];
                    if (dist < bestDist)
                    {
                        bestMonitorIndex = i;
                    }
                }
            }

            //get current vidmode of monitors
            List <VideoMode> modes = new List <VideoMode>();

            for (int i = 0; i < Glfw.Monitors.Length; i++)
            {
                modes.Add(Glfw.GetVideoMode(Glfw.Monitors[i]));
            }

            if (bCenter)
            {
                //center of desired monitor
                x = modes[monitorIndex].Width / 2;
                y = modes[monitorIndex].Height / 2;

                //adjust back by half window size
                x -= width / 2;
                y -= height / 2;
            }
            else
            {
                //adjust to local coordiates
                x -= xCoords[bestMonitorIndex];
                y -= yCoords[bestMonitorIndex];
            }

            //add desired monitor xy
            x += xCoords[monitorIndex];
            y += yCoords[monitorIndex];

            Console.WriteLine(Glfw.VersionString);

            Glfw.SetWindowPosition(mWnd, x, y);

            ds.CreateWindowSurface(mWnd);

            Glfw.SetWindowSizeCallback(mWnd, OnReSize);

            mLastFrame = Stopwatch.GetTimestamp();
        }
コード例 #3
0
ファイル: Devices.cs プロジェクト: Kharzette/GrogLibsCore
        public bool CreateSwapChain(DrunkSpock spock,
                                    int extentX, int extentY)
        {
            PhysicalDevice phys = mLogical.Parent;
            SurfaceKhr     surf = spock.GetSurface();

            SurfaceCapabilitiesKhr surfCaps = phys.GetSurfaceCapabilitiesKhr(surf);

            SurfaceFormatKhr                [] surfFormats = phys.GetSurfaceFormatsKhr(surf);
            PresentModeKhr                  [] presModes   = phys.GetSurfacePresentModesKhr(surf);

            if (surfFormats.Length <= 0 || presModes.Length <= 0)
            {
                Misc.SafeInvoke(eErrorSpam, "Bad formats or pres modes...");
                return(false);
            }

            mSwapExtent = new Extent2D(extentX, extentY);

            int imageCount = surfCaps.MinImageCount + 1;

            if (surfCaps.MaxImageCount > 0 && imageCount > surfCaps.MaxImageCount)
            {
                imageCount = surfCaps.MaxImageCount;
            }

            SwapchainCreateInfoKhr scci = new SwapchainCreateInfoKhr(
                surf, Format.B8G8R8A8UNorm, mSwapExtent,
                imageCount, ColorSpaceKhr.SRgbNonlinear, 1,
                ImageUsages.ColorAttachment);

            scci.ImageSharingMode = SharingMode.Exclusive;

            if (presModes.Contains(PresentModeKhr.Mailbox))
            {
                scci.PresentMode = PresentModeKhr.Mailbox;
            }

            mSwapChain = mLogical.CreateSwapchainKhr(scci);
            if (mSwapChain == null)
            {
                Misc.SafeInvoke(eErrorSpam, "Create swap chain failed...");
                return(false);
            }

            VulkanCore.Image        [] chainImages = mSwapChain.GetImages();

            mChainImageViews = new ImageView[chainImages.Length];

            for (int i = 0; i < chainImages.Length; i++)
            {
                ImageSubresourceRange isr = new ImageSubresourceRange(
                    ImageAspects.Color, 0, 1, 0, 1);

                ImageViewCreateInfo ivci = new ImageViewCreateInfo(
                    mSwapChain.Format, isr);

                mChainImageViews[i] = chainImages[i].CreateView(ivci);
            }

            //descriptor pool stuff
            DescriptorPoolSize dps = new DescriptorPoolSize(
                DescriptorType.UniformBuffer, chainImages.Length);

            DescriptorPoolCreateInfo dpci = new DescriptorPoolCreateInfo();

            dpci.PoolSizes = new DescriptorPoolSize[] { dps };
            dpci.MaxSets   = chainImages.Length;

            mDPool = mLogical.CreateDescriptorPool(dpci);

            return(true);
        }