private TextBox CreateTextBox <TValue>(FormatProperties formatProperties, Func <string, IFormatProvider, TValue> parse, Func <TValue, string, IFormatProvider, string> toString, string format) { TextBox textBox = new TextBox(); Func <string, TValue> parse2; Func <TValue, string> toString2; if (formatProperties != null) { parse2 = (s) => parse(s, formatProperties.FormatProvider); toString2 = (v) => toString(v, formatProperties.Format ?? format, formatProperties.FormatProvider); } else { parse2 = (s) => parse(s, null); toString2 = (v) => toString(v, format, null); } //TextProperties textProperties = properties.OfType<TextProperties>().FirstOrDefault(); ControlExchange.Set(textBox, new DelegateFormattableTextBoxExchange <TValue>(parse2, toString2)); return(textBox); }
internal void GenerateDepthStencilFormat() { Format[] validFormats = { Format.D32SFloatS8UInt, Format.D32SFloat, Format.D24UNormS8UInt, Format.D16UNormS8UInt, Format.D16UNorm }; Format?potentialFormat = validFormats.FirstOrDefault( validFormat => { FormatProperties formatProps = PhysicalDevice.GetFormatProperties(validFormat); return((formatProps.OptimalTilingFeatures & FormatFeatures.DepthStencilAttachment) > 0); }); if (!potentialFormat.HasValue) { throw new InvalidOperationException("Required depth stencil format not supported."); } DepthStencilFormat = potentialFormat.Value; }
void AppDevDumpFormatProps(AppDev dev, Format fmt, StreamWriter output) { FormatProperties props = dev.FormatProbs[(int)fmt]; Feature[] features = new Feature[3]; features[0].Name = "linearTiling FormatFeatureFlags"; features[0].Flags = (FormatFeatureFlags)props.LinearTilingFeatures; features[1].Name = "optimalTiling FormatFeatureFlags"; features[1].Flags = (FormatFeatureFlags)props.OptimalTilingFeatures; features[2].Name = "bufferFeatures FormatFeatureFlags"; features[2].Flags = (FormatFeatureFlags)props.BufferFeatures; output.Write("\nFORMAT_{0}:", GetVkName(fmt.ToString())); foreach (Feature feature in features) { output.Write("\n\t{0}:", feature.Name); if (feature.Flags == 0) { output.Write("\n\t\tNone"); } else { foreach (FormatFeatureFlags flag in Enum.GetValues(typeof(FormatFeatureFlags))) { if ((feature.Flags & flag) == flag) { string name = GetVkName(flag.ToString(), "VK_FORMAT_FEATURE_", "_BIT"); output.Write("\n\t\t{0}", name); } } } } output.WriteLine(); }
private void Register <TValue>(Func <string, IFormatProvider, TValue> parse, Func <TValue, string, IFormatProvider, string> toString, string format) { this.dictionary.Add( typeof(TValue), (type, properties, serviceProvider) => { FormatProperties formatProperties = properties.OfType <FormatProperties>().FirstOrDefault(); return(this.CreateTextBox(formatProperties, parse, toString, format)); }); }
private ComboBox CreateList(Type valueType, IRefList refList, ViewProperties[] properties, IServiceProvider serviceProvider) { ComboBox combo = new ComboBox(); combo.CausesValidation = true; combo.Sorted = false; combo.FormattingEnabled = true; combo.DropDownStyle = ComboBoxStyle.DropDownList; FormatProperties formatProperties = properties.OfType <FormatProperties>().FirstOrDefault(); string format = formatProperties.With(x => x.Format); IFormatProvider formatProvider = formatProperties.With(x => x.FormatProvider); ICustomFormatter customFormatter = formatProperties.With(x => x.CustomFormatter); combo.Format += (sender, args) => { if (!object.Equals(args.DesiredType, typeof(string))) { Log <DefaultEditorFactory> .Error("Se intenta convertir a un valor diferente de String."); args.Value = null; return; } // Se formatea. try { object item = args.ListItem; if (item is IFormattable) { args.Value = ((IFormattable)item).ToString(format, formatProvider); } else if (customFormatter != null) { args.Value = customFormatter.Format(format, item, formatProvider); } else { args.Value = item.ToString(); } } catch (Exception e) { Log <DefaultEditorFactory> .Error("Excepcion al formatear.", e); args.Value = null; } }; ControlExchange.Set(combo, TypeUtils.NewGeneric <ControlExchange>(typeof(ComboBoxExchange <>), valueType)); return(combo); }
private Format GetBestDepthBufferFormat() { foreach (var A in depthFormats) { FormatProperties myProperties = GetFormatProperties(A); if ((myProperties.OptimalTilingFeatures & FormatFeatureFlags.DepthStencilAttachment) == FormatFeatureFlags.DepthStencilAttachment) { return(A); } } throw new Exception("Could not find appropriate depth buffer!"); }
public static VulkanImage DepthStencil(VulkanContext device, int width, int height) { Format[] validFormats = { Format.D32SFloatS8UInt, Format.D32SFloat, Format.D24UNormS8UInt, Format.D16UNormS8UInt, Format.D16UNorm }; Format?potentialFormat = validFormats.FirstOrDefault( validFormat => { FormatProperties formatProps = device.PhysicalDevice.GetFormatProperties(validFormat); return((formatProps.OptimalTilingFeatures & FormatFeatures.DepthStencilAttachment) > 0); }); if (!potentialFormat.HasValue) { throw new InvalidOperationException("Required depth stencil format not supported."); } Format format = potentialFormat.Value; Image image = device.Device.CreateImage(new ImageCreateInfo { ImageType = ImageType.Image2D, Format = format, Extent = new Extent3D(width, height, 1), MipLevels = 1, ArrayLayers = 1, Samples = SampleCounts.Count1, Tiling = ImageTiling.Optimal, Usage = ImageUsages.DepthStencilAttachment | ImageUsages.TransferSrc }); MemoryRequirements memReq = image.GetMemoryRequirements(); int heapIndex = device.MemoryProperties.MemoryTypes.IndexOf( memReq.MemoryTypeBits, MemoryProperties.DeviceLocal); DeviceMemory memory = device.Device.AllocateMemory(new MemoryAllocateInfo(memReq.Size, heapIndex)); image.BindMemory(memory); ImageView view = image.CreateView(new ImageViewCreateInfo(format, new ImageSubresourceRange(ImageAspects.Depth | ImageAspects.Stencil, 0, 1, 0, 1))); return(new VulkanImage(image, memory, view, format)); }
/// <summary> /// Get best depth and stencil supported for given internalFormat /// </summary> /// <param name="format"></param> /// <param name="depthFormat"></param> /// <param name="stencilFormat"></param> public void GetBestDepthStencil(PixelFormat format, out int depthFormat, out int stencilFormat) { FormatProperties props = this._props[(int)format]; /// Decide what stencil and depth formats to use /// [best supported for internal format] int bestmode = 0; int bestscore = -1; for (int mode = 0; mode < props.Modes.Count; mode++) { int desirability = 0; /// Find most desirable mode /// desirability == 0 if no depth, no stencil /// desirability == 1000...2000 if no depth, stencil /// desirability == 2000...3000 if depth, no stencil /// desirability == 3000+ if depth and stencil /// beyond this, the total numer of bits (stencil+depth) is maximised if (props.Modes[mode].Stencil != 0) { desirability += 1000; } if (props.Modes[mode].Depth != 0) { desirability += 2000; } if (this._depthBits[props.Modes[mode].Depth] == 24) // Prefer 24 bit for now { desirability += 500; } if (this._depthFormats[props.Modes[mode].Depth] == GL_DEPTH24_STENCIL8_EXT) // Prefer 24/8 packed { desirability += 5000; } desirability += this._stencilBits[props.Modes[mode].Stencil] + this._depthBits[props.Modes[mode].Depth]; if (desirability > bestscore) { bestscore = desirability; bestmode = mode; } } depthFormat = this._depthFormats[props.Modes[bestmode].Depth]; stencilFormat = this._stencilFormats[props.Modes[bestmode].Stencil]; }
/// <summary> /// Get best depth and stencil supported for given internalFormat /// </summary> /// <param name="internalFormat"> </param> /// <param name="depthFormat"> </param> /// <param name="stencilFormat"> </param> public override void GetBestDepthStencil(All internalFormat, out All depthFormat, out All stencilFormat) { FormatProperties props = this._props[(int)internalFormat]; /// Decide what stencil and depth formats to use /// [best supported for internal format] int bestmode = 0; int bestscore = 1; for (int mode = 0; mode < props.Modes.Count; mode++) { int desirability = 0; /// Find most desirable mode /// desirability == 0 if no depth, no stencil /// desirability == 1000...2000 if no depth, stencil /// desirability == 2000...3000 if depth, no stencil /// desirability == 3000+ if depth and stencil /// beyond this, the total numer of bits (stencil+depth) is maximised if (props.Modes[mode].Stencil != 0) { desirability += 1000; } if (props.Modes[mode].Depth != 0) { desirability += 2000; } if (DepthBits[props.Modes[mode].Depth] == 24) // Prefer 24 bit for now { desirability += 500; } if (DepthFormats[props.Modes[mode].Depth] == All.Depth24Stencil8Oes) // Prefer 24/8 packed { desirability += 5000; } desirability += StencilBits[props.Modes[mode].Stencil] + DepthBits[props.Modes[mode].Depth]; if (desirability > bestscore) { bestscore = desirability; bestmode = mode; } } //end for mode depthFormat = DepthFormats[props.Modes[bestmode].Depth]; stencilFormat = StencilFormats[props.Modes[bestmode].Stencil]; }
void AppDevInitFormats(AppDev dev) { int formatCount = 0; foreach (Format f in Enum.GetValues(typeof(Format))) { int fi = (int)f; formatCount = formatCount < fi ? fi : formatCount; } FormatProperties[] formatList = new FormatProperties[formatCount + 1]; foreach (Format f in Enum.GetValues(typeof(Format))) { int index = (int)f; formatList[index] = (dev.Gpu.Obj.GetFormatProperties(f)); } dev.FormatProbs = formatList; }
private void UpdateControl() { try { string format = ""; IFormatProvider formatProvider = null; if (this.context.PropertiesProvider != null) { FormatProperties props = this.context.PropertiesProvider.FindProperties <FormatProperties>(this.Item) ?? FormatProperties.Empty; format = props.Format; formatProvider = props.FormatProvider; } this.TSItem.Value = this.Item.ToString(format, formatProvider); } catch (Exception e) { Log <TSIRenderProperty> .Warn(e); } }
public override void GetBestDepthStencil(GLenum internalColorFormat, ref OpenTK.Graphics.ES20.All depthFormat, ref OpenTK.Graphics.ES20.All stencilFormat) { FormatProperties prop = this.props[(int)internalColorFormat]; int bestmode = 0; int bestscore = -1; for (int mode = 0; mode < prop.Modes.Count; mode++) { int desirability = 0; /// Find most desirable mode /// desirability == 0 if no depth, no stencil /// desirability == 1000...2000 if no depth, stencil /// desirability == 2000...3000 if depth, no stencil /// desirability == 3000+ if depth and stencil /// beyond this, the total numer of bits (stencil+depth) is maximised if (prop.Modes[mode].Stencil > 0) { desirability += 1000; } if (prop.Modes[mode].Depth > 0) { desirability += 2000; } if (depthBits[prop.Modes[mode].Depth] == 24) //Prefer 24 bit for now { desirability += 500; } if (depthFormats[prop.Modes[mode].Depth] == GLenum.Depth24Stencil8Oes) //Prefer 24/8 packed { desirability += 5000; } desirability += stencilBits[prop.Modes[mode].Stencil] + depthBits[prop.Modes[mode].Depth]; if (desirability > bestscore) { bestscore = desirability; bestmode = mode; } } depthFormat = depthFormats[prop.Modes[bestmode].Depth]; stencilFormat = stencilFormats[prop.Modes[bestmode].Stencil]; }
internal GLFBORTTManager( BaseGLSupport glSupport, bool atiMode ) : base( glSupport ) { for ( int x = 0; x < _props.GetLength( 0 ); x++ ) { _props[ x ] = new FormatProperties(); } _atiMode = atiMode; _detectFBOFormats(); Gl.glGenFramebuffersEXT( 1, out _tempFBO ); }
/// <summary> /// Detect which internal formats are allowed as RTT /// Also detect what combinations of stencil and depth are allowed with this internal /// format. /// </summary> private void DetectFBOFormats() { // Try all formats, and report which ones work as target int fb = 0, tid = 0; All target = All.Texture2D; for ( int x = 0; x < (int)Media.PixelFormat.Count; x++ ) { _props[ x ] = new FormatProperties(); _props[ x ].IsValid = false; _props[ x ].Modes = new List<FormatProperties.Mode>(); // Fetch GL format token All fmt = GLESPixelUtil.GetClosestGLInternalFormat( (Media.PixelFormat)x ); if ( fmt == 0 && x != 0 ) continue; // No test for compressed formats if ( PixelUtil.IsCompressed( (Media.PixelFormat)x ) ) continue; // Create and attach framebuffer OpenGLOES.GenRenderbuffers( 1, ref fb ); GLESConfig.GlCheckError( this ); OpenGLOES.BindFramebuffer( All.FramebufferOes, fb ); GLESConfig.GlCheckError( this ); if ( fmt != 0 ) { // Create and attach texture OpenGL.GenTextures( 1, ref tid ); GLESConfig.GlCheckError( this ); OpenGL.BindTexture( target, tid ); GLESConfig.GlCheckError( this ); // Set some default parameters OpenGL.TexParameterx( target, All.TextureMinFilter, (int)All.LinearMipmapNearest ); GLESConfig.GlCheckError( this ); OpenGL.TexParameterx( target, All.TextureMagFilter, (int)All.Nearest ); GLESConfig.GlCheckError( this ); OpenGL.TexParameterx( target, All.TextureWrapS, (int)All.ClampToEdge ); GLESConfig.GlCheckError( this ); OpenGL.TexParameterx( target, All.TextureWrapT, (int)All.ClampToEdge ); GLESConfig.GlCheckError( this ); OpenGL.TexImage2D( target, 0, (int)fmt, ProbeSize, ProbeSize, 0, fmt, All.UnsignedByte, IntPtr.Zero ); GLESConfig.GlCheckError( this ); OpenGLOES.FramebufferTexture2D( All.FramebufferOes, All.ColorAttachment0Oes, target, tid, 0 ); GLESConfig.GlCheckError( this ); } // Check status All status = OpenGLOES.CheckFramebufferStatus( All.FramebufferOes ); GLESConfig.GlCheckError( this ); // Ignore status in case of fmt==GL_NONE, because no implementation will accept // a buffer without *any* attachment. Buffers with only stencil and depth attachment // might still be supported, so we must continue probing. if ( fmt == 0 || status == All.FramebufferCompleteOes ) { _props[ x ].IsValid = true; StringBuilder str = new StringBuilder(); str.Append( "FBO " + PixelUtil.GetFormatName( (Media.PixelFormat)x ) + " depth/stencil support: " ); // For each depth/stencil formats for ( int depth = 0; depth < DepthFormatCount; ++depth ) { if ( DepthFormats[ depth ] != All.Depth24Stencil8Oes ) { // General depth/stencil combination for ( int stencil = 0; stencil < StencilFormatCount; ++stencil ) { if ( TryFormat( DepthFormats[ depth ], StencilFormats[ stencil ] ) ) { /// Add mode to allowed modes str.Append( "D" + DepthBits[ depth ] + "S" + StencilBits[ stencil ] + " " ); FormatProperties.Mode mode = new FormatProperties.Mode(); mode.Depth = depth; mode.Stencil = stencil; _props[ x ].Modes.Add( mode ); } }//end for stencil }//end if else { // Packed depth/stencil format if ( TryPacketFormat( DepthFormats[ depth ] ) ) { /// Add mode to allowed modes str.Append( "Packed-D" + DepthBits[ depth ] + "S8" + " " ); FormatProperties.Mode mode = new FormatProperties.Mode(); mode.Depth = depth; mode.Stencil = 0;//unused _props[ x ].Modes.Add( mode ); } } }//end for depth LogManager.Instance.Write( str.ToString() ); }//end if // Delete texture and framebuffer #if AXIOM_PLATFORM_IPHONE // The screen buffer is 1 on iPhone OpenGLOES.BindFramebuffer(All.FramebufferOes, 1); #else OpenGLOES.BindFramebuffer( All.FramebufferOes, 0 ); #endif GLESConfig.GlCheckError( this ); OpenGLOES.DeleteFramebuffers( 1, ref fb ); GLESConfig.GlCheckError( this ); if ( fmt != 0 ) OpenGL.DeleteTextures( 1, ref tid ); }//end for pixelformat count string fmtstring = string.Empty; for ( int x = 0; x < (int)Media.PixelFormat.Count; x++ ) { if ( _props[ x ].IsValid ) { fmtstring += PixelUtil.GetFormatName( (Media.PixelFormat)x ); } } LogManager.Instance.Write("[GL] : Valid FBO targets " + fmtstring); }
public unsafe void GetFormatProperties(Format format, out FormatProperties formatProperties) { fixed (FormatProperties* __formatProperties__ = &formatProperties) { vkGetPhysicalDeviceFormatProperties(this, format, __formatProperties__); } }
/// <summary> /// Detect which internal formats are allowed as RTT /// Also detect what combinations of stencil and depth are allowed with this internal /// format. /// </summary> private void DetectFBOFormats() { // Try all formats, and report which ones work as target int fb = 0, tid = 0; All target = All.Texture2D; for (int x = 0; x < (int)Media.PixelFormat.Count; x++) { _props[x] = new FormatProperties(); _props[x].IsValid = false; _props[x].Modes = new List <FormatProperties.Mode>(); // Fetch GL format token All fmt = GLESPixelUtil.GetClosestGLInternalFormat((Media.PixelFormat)x); if (fmt == 0 && x != 0) { continue; } // No test for compressed formats if (PixelUtil.IsCompressed((Media.PixelFormat)x)) { continue; } // Create and attach framebuffer OpenGLOES.GenRenderbuffers(1, ref fb); GLESConfig.GlCheckError(this); OpenGLOES.BindFramebuffer(All.FramebufferOes, fb); GLESConfig.GlCheckError(this); if (fmt != 0) { // Create and attach texture OpenGL.GenTextures(1, ref tid); GLESConfig.GlCheckError(this); OpenGL.BindTexture(target, tid); GLESConfig.GlCheckError(this); // Set some default parameters OpenGL.TexParameterx(target, All.TextureMinFilter, (int)All.LinearMipmapNearest); GLESConfig.GlCheckError(this); OpenGL.TexParameterx(target, All.TextureMagFilter, (int)All.Nearest); GLESConfig.GlCheckError(this); OpenGL.TexParameterx(target, All.TextureWrapS, (int)All.ClampToEdge); GLESConfig.GlCheckError(this); OpenGL.TexParameterx(target, All.TextureWrapT, (int)All.ClampToEdge); GLESConfig.GlCheckError(this); OpenGL.TexImage2D(target, 0, (int)fmt, ProbeSize, ProbeSize, 0, fmt, All.UnsignedByte, IntPtr.Zero); GLESConfig.GlCheckError(this); OpenGLOES.FramebufferTexture2D(All.FramebufferOes, All.ColorAttachment0Oes, target, tid, 0); GLESConfig.GlCheckError(this); } // Check status All status = OpenGLOES.CheckFramebufferStatus(All.FramebufferOes); GLESConfig.GlCheckError(this); // Ignore status in case of fmt==GL_NONE, because no implementation will accept // a buffer without *any* attachment. Buffers with only stencil and depth attachment // might still be supported, so we must continue probing. if (fmt == 0 || status == All.FramebufferCompleteOes) { _props[x].IsValid = true; StringBuilder str = new StringBuilder(); str.Append("FBO " + PixelUtil.GetFormatName((Media.PixelFormat)x) + " depth/stencil support: "); // For each depth/stencil formats for (int depth = 0; depth < DepthFormatCount; ++depth) { if (DepthFormats[depth] != All.Depth24Stencil8Oes) { // General depth/stencil combination for (int stencil = 0; stencil < StencilFormatCount; ++stencil) { if (TryFormat(DepthFormats[depth], StencilFormats[stencil])) { /// Add mode to allowed modes str.Append("D" + DepthBits[depth] + "S" + StencilBits[stencil] + " "); FormatProperties.Mode mode = new FormatProperties.Mode(); mode.Depth = depth; mode.Stencil = stencil; _props[x].Modes.Add(mode); } } //end for stencil } //end if else { // Packed depth/stencil format if (TryPacketFormat(DepthFormats[depth])) { /// Add mode to allowed modes str.Append("Packed-D" + DepthBits[depth] + "S8" + " "); FormatProperties.Mode mode = new FormatProperties.Mode(); mode.Depth = depth; mode.Stencil = 0; //unused _props[x].Modes.Add(mode); } } } //end for depth LogManager.Instance.Write(str.ToString()); } //end if // Delete texture and framebuffer #if AXIOM_PLATFORM_IPHONE // The screen buffer is 1 on iPhone OpenGLOES.BindFramebuffer(All.FramebufferOes, 1); #else OpenGLOES.BindFramebuffer(All.FramebufferOes, 0); #endif GLESConfig.GlCheckError(this); OpenGLOES.DeleteFramebuffers(1, ref fb); GLESConfig.GlCheckError(this); if (fmt != 0) { OpenGL.DeleteTextures(1, ref tid); } } //end for pixelformat count string fmtstring = string.Empty; for (int x = 0; x < (int)Media.PixelFormat.Count; x++) { if (_props[x].IsValid) { fmtstring += PixelUtil.GetFormatName((Media.PixelFormat)x); } } LogManager.Instance.Write("[GL] : Valid FBO targets " + fmtstring); }
internal static unsafe extern void vkGetPhysicalDeviceFormatProperties(PhysicalDevice physicalDevice, Format format, FormatProperties* formatProperties);