protected override Task LoadContent() #endif { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here var assembly = GetType().Assembly; _font = StaticSpriteFont.FromBMFont(assembly.ReadResourceAsString("FontStashSharp.Samples.StaticSpriteFont.Fonts.Arial.fnt"), fileName => assembly.OpenResourceStream("FontStashSharp.Samples.StaticSpriteFont.Fonts." + fileName), GraphicsDevice); #if MONOGAME || FNA _white = new Texture2D(GraphicsDevice, 1, 1); _white.SetData(new[] { Color.White }); #elif STRIDE _white = Texture2D.New2D(GraphicsDevice, 1, 1, false, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.ShaderResource); _white.SetData(GraphicsContext.CommandList, new[] { Color.White }); #endif GC.Collect(); #if STRIDE return(base.LoadContent()); #endif }
public static Texture2D CreateTexture2D(int width, int height) { #if !STRIDE return new Texture2D(MyraEnvironment.GraphicsDevice, width, height, false, SurfaceFormat.Color); #else return Texture2D.New2D(MyraEnvironment.GraphicsDevice, width, height, false, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.ShaderResource); #endif }
public static Texture2D CreateTexture(GraphicsDevice device, int width, int height) { #if MONOGAME || FNA var texture2d = new Texture2D(device, width, height); #elif STRIDE var texture2d = Texture2D.New2D(device, width, height, false, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.ShaderResource); #endif return(texture2d); }
public ITexture2D Create(int width, int height) { #if MONOGAME || FNA var texture2d = new Texture2D(_device, width, height); #elif STRIDE var texture2d = Texture2D.New2D(_device, width, height, false, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource); #endif return(new Texture2DWrapper(texture2d)); }
private static Texture CreateWhiteTexture(GraphicsDevice device) { const int Size = 2; var whiteData = new Color[Size * Size]; for (int i = 0; i < Size * Size; i++) { whiteData[i] = Color.White; } return(Texture.New2D(device, Size, Size, PixelFormat.R8G8B8A8_UNorm, whiteData)); }
protected override Task LoadContent() #endif { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here var fontSystems = new List <FontSystem>(); // Simple var fontSystem = new FontSystem(); LoadFontSystem(fontSystem); fontSystems.Add(fontSystem); // Blurry var settings = new FontSystemSettings { Effect = FontSystemEffect.Blurry, EffectAmount = EffectAmount, }; var blurryFontSystem = new FontSystem(settings); LoadFontSystem(blurryFontSystem); fontSystems.Add(blurryFontSystem); // Stroked settings.Effect = FontSystemEffect.Stroked; var strokedFontSystem = new FontSystem(settings); LoadFontSystem(strokedFontSystem); fontSystems.Add(strokedFontSystem); _fontSystems = fontSystems.ToArray(); _currentFontSystem = _fontSystems[0]; #if MONOGAME || FNA _white = new Texture2D(GraphicsDevice, 1, 1); _white.SetData(new[] { Color.White }); #elif STRIDE _white = Texture2D.New2D(GraphicsDevice, 1, 1, false, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.ShaderResource); _white.SetData(GraphicsContext.CommandList, new[] { Color.White }); #endif GC.Collect(); #if STRIDE return(base.LoadContent()); #endif }
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { device.InitDefaultRenderTarget(presentationParameters); backBuffer = Texture.New2D(device, Description.BackBufferWidth, Description.BackBufferHeight, presentationParameters.BackBufferFormat, TextureFlags.RenderTarget | TextureFlags.ShaderResource); }
/// <summary> /// Initializes the specified device. /// </summary> /// <param name="graphicsProfiles">The graphics profiles.</param> /// <param name="deviceCreationFlags">The device creation flags.</param> /// <param name="windowHandle">The window handle.</param> private unsafe void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles, DeviceCreationFlags deviceCreationFlags, object windowHandle) { if (nativeDevice != VkDevice.Null) { // Destroy previous device ReleaseDevice(); } rendererName = Adapter.Description; vkGetPhysicalDeviceProperties(NativePhysicalDevice, out var physicalDeviceProperties); ConstantBufferDataPlacementAlignment = (int)physicalDeviceProperties.limits.minUniformBufferOffsetAlignment; TimestampFrequency = (long)(1.0e9 / physicalDeviceProperties.limits.timestampPeriod); // Resolution in nanoseconds RequestedProfile = graphicsProfiles.First(); var queueProperties = vkGetPhysicalDeviceQueueFamilyProperties(NativePhysicalDevice); //IsProfilingSupported = queueProperties[0].TimestampValidBits > 0; // Command lists are thread-safe and execute deferred IsDeferred = true; // TODO VULKAN // Create Vulkan device based on profile float queuePriorities = 0; var queueCreateInfo = new VkDeviceQueueCreateInfo { sType = VkStructureType.DeviceQueueCreateInfo, queueFamilyIndex = 0, queueCount = 1, pQueuePriorities = &queuePriorities, }; var enabledFeature = new VkPhysicalDeviceFeatures { fillModeNonSolid = true, shaderClipDistance = true, shaderCullDistance = true, samplerAnisotropy = true, depthClamp = true, }; var extensionProperties = vkEnumerateDeviceExtensionProperties(NativePhysicalDevice); var availableExtensionNames = new List <string>(); var desiredExtensionNames = new List <string>(); for (int index = 0; index < extensionProperties.Length; index++) { fixed(VkExtensionProperties *extensionPropertiesPtr = extensionProperties) { var namePointer = new IntPtr(extensionPropertiesPtr[index].extensionName); var name = Marshal.PtrToStringAnsi(namePointer); availableExtensionNames.Add(name); } } desiredExtensionNames.Add(KHRSwapchainExtensionName); if (!availableExtensionNames.Contains(KHRSwapchainExtensionName)) { throw new InvalidOperationException(); } if (availableExtensionNames.Contains(EXTDebugMarkerExtensionName) && IsDebugMode) { desiredExtensionNames.Add(EXTDebugMarkerExtensionName); IsProfilingSupported = true; } var enabledExtensionNames = desiredExtensionNames.Select(Marshal.StringToHGlobalAnsi).ToArray(); try { var deviceCreateInfo = new VkDeviceCreateInfo { sType = VkStructureType.DeviceCreateInfo, queueCreateInfoCount = 1, pQueueCreateInfos = &queueCreateInfo, enabledExtensionCount = (uint)enabledExtensionNames.Length, ppEnabledExtensionNames = enabledExtensionNames.Length > 0 ? (byte **)Core.Interop.Fixed(enabledExtensionNames) : null, pEnabledFeatures = &enabledFeature, }; vkCreateDevice(NativePhysicalDevice, &deviceCreateInfo, null, out nativeDevice); } finally { foreach (var enabledExtensionName in enabledExtensionNames) { Marshal.FreeHGlobal(enabledExtensionName); } } vkGetDeviceQueue(nativeDevice, 0, 0, out NativeCommandQueue); NativeCopyCommandPools = new ThreadLocal <VkCommandPool>(() => { //// Prepare copy command list (start it closed, so that every new use start with a Reset) var commandPoolCreateInfo = new VkCommandPoolCreateInfo { sType = VkStructureType.CommandPoolCreateInfo, queueFamilyIndex = 0, //device.NativeCommandQueue.FamilyIndex flags = VkCommandPoolCreateFlags.ResetCommandBuffer }; vkCreateCommandPool(NativeDevice, &commandPoolCreateInfo, null, out var result); return(result); }, true); DescriptorPools = new HeapPool(this); nativeResourceCollector = new NativeResourceCollector(this); graphicsResourceLinkCollector = new GraphicsResourceLinkCollector(this); EmptyTexelBufferInt = Buffer.Typed.New(this, 1, PixelFormat.R32G32B32A32_UInt); EmptyTexelBufferFloat = Buffer.Typed.New(this, 1, PixelFormat.R32G32B32A32_Float); EmptyTexture = Texture.New2D(this, 1, 1, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.ShaderResource); }
/// <summary> /// Initializes the specified device. /// </summary> /// <param name="graphicsProfiles">The graphics profiles.</param> /// <param name="deviceCreationFlags">The device creation flags.</param> /// <param name="windowHandle">The window handle.</param> private unsafe void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles, DeviceCreationFlags deviceCreationFlags, object windowHandle) { if (nativeDevice != Device.Null) { // Destroy previous device ReleaseDevice(); } rendererName = Adapter.Description; PhysicalDeviceProperties physicalDeviceProperties; NativePhysicalDevice.GetProperties(out physicalDeviceProperties); ConstantBufferDataPlacementAlignment = (int)physicalDeviceProperties.Limits.MinUniformBufferOffsetAlignment; TimestampFrequency = (long)(1.0e9 / physicalDeviceProperties.Limits.TimestampPeriod); // Resolution in nanoseconds RequestedProfile = graphicsProfiles.Last(); var queueProperties = NativePhysicalDevice.QueueFamilyProperties; //IsProfilingSupported = queueProperties[0].TimestampValidBits > 0; // Command lists are thread-safe and execute deferred IsDeferred = true; // TODO VULKAN // Create Vulkan device based on profile uint queuePriorities = 0; var queueCreateInfo = new DeviceQueueCreateInfo { StructureType = StructureType.DeviceQueueCreateInfo, QueueFamilyIndex = 0, QueueCount = 1, QueuePriorities = new IntPtr(&queuePriorities) }; var enabledFeature = new PhysicalDeviceFeatures { FillModeNonSolid = true, ShaderClipDistance = true, ShaderCullDistance = true, SamplerAnisotropy = true, DepthClamp = true, }; var extensionProperties = NativePhysicalDevice.GetDeviceExtensionProperties(); var availableExtensionNames = new List <string>(); var desiredExtensionNames = new List <string>(); for (int index = 0; index < extensionProperties.Length; index++) { var namePointer = new IntPtr(Interop.Fixed(ref extensionProperties[index].ExtensionName)); var name = Marshal.PtrToStringAnsi(namePointer); availableExtensionNames.Add(name); } desiredExtensionNames.Add("VK_KHR_swapchain"); if (!availableExtensionNames.Contains("VK_KHR_swapchain")) { throw new InvalidOperationException(); } if (availableExtensionNames.Contains("VK_EXT_debug_marker") && IsDebugMode) { desiredExtensionNames.Add("VK_EXT_debug_marker"); IsProfilingSupported = true; } var enabledExtensionNames = desiredExtensionNames.Select(Marshal.StringToHGlobalAnsi).ToArray(); try { var deviceCreateInfo = new DeviceCreateInfo { StructureType = StructureType.DeviceCreateInfo, QueueCreateInfoCount = 1, QueueCreateInfos = new IntPtr(&queueCreateInfo), EnabledExtensionCount = (uint)enabledExtensionNames.Length, EnabledExtensionNames = enabledExtensionNames.Length > 0 ? new IntPtr(Interop.Fixed(enabledExtensionNames)) : IntPtr.Zero, EnabledFeatures = new IntPtr(&enabledFeature) }; nativeDevice = NativePhysicalDevice.CreateDevice(ref deviceCreateInfo); } finally { foreach (var enabledExtensionName in enabledExtensionNames) { Marshal.FreeHGlobal(enabledExtensionName); } } NativeCommandQueue = nativeDevice.GetQueue(0, 0); //// Prepare copy command list (start it closed, so that every new use start with a Reset) var commandPoolCreateInfo = new CommandPoolCreateInfo { StructureType = StructureType.CommandPoolCreateInfo, QueueFamilyIndex = 0, //device.NativeCommandQueue.FamilyIndex Flags = CommandPoolCreateFlags.ResetCommandBuffer }; NativeCopyCommandPool = NativeDevice.CreateCommandPool(ref commandPoolCreateInfo); var commandBufferAllocationInfo = new CommandBufferAllocateInfo { StructureType = StructureType.CommandBufferAllocateInfo, Level = CommandBufferLevel.Primary, CommandPool = NativeCopyCommandPool, CommandBufferCount = 1 }; CommandBuffer nativeCommandBuffer; NativeDevice.AllocateCommandBuffers(ref commandBufferAllocationInfo, &nativeCommandBuffer); NativeCopyCommandBuffer = nativeCommandBuffer; DescriptorPools = new HeapPool(this); nativeResourceCollector = new NativeResourceCollector(this); graphicsResourceLinkCollector = new GraphicsResourceLinkCollector(this); EmptyTexelBufferInt = Buffer.Typed.New(this, 1, PixelFormat.R32G32B32A32_UInt); EmptyTexelBufferFloat = Buffer.Typed.New(this, 1, PixelFormat.R32G32B32A32_Float); EmptyTexture = Texture.New2D(this, 1, 1, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.ShaderResource); }