/// <summary> /// Initializes a new instance of the <see cref="UserInterfaceRenderer10"/> class. /// </summary> /// <param name="device">The device.</param> /// <param name="width">The width of the renderable area.</param> /// <param name="height">The height of the renderable area.</param> public UserInterfaceRenderer10(D3D.Device device, int width, int height) { if (device == null) throw new ArgumentNullException("device"); if (width < 0) throw new ArgumentException("Value must be positive.", "width"); if (height < 0) throw new ArgumentException("Value must be positive.", "height"); this.device = device; halfWidth = width / 2; halfHeight = height / 2; font = new D3D.Font(device, 18, 0, D3D.FontWeight.Bold, 0, false, D3D.FontCharacterSet.Default, D3D.FontPrecision.Default, D3D.FontQuality.Antialiased, D3D.FontPitchAndFamily.Default, "Arial"); sprite = new SlimDX.Direct3D10.Sprite(device, 0); lineBuffer = new DynamicPrimitiveBuffer10<ColoredVertex>(device); Assembly assembly = Assembly.GetExecutingAssembly(); using (Stream stream = assembly.GetManifestResourceStream("SampleFramework.Resources.UserInterface10.fx")) using (StreamReader reader = new StreamReader(stream)) { effect = D3D.Effect.FromString(device, reader.ReadToEnd(), "fx_4_0"); } technique = effect.GetTechniqueByIndex(0); pass = technique.GetPassByIndex(0); ShaderSignature signature = pass.Description.Signature; inputLayout = new D3D.InputLayout(device, signature, new[] { new D3D.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0), new D3D.InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, D3D.InputElement.AppendAligned, 0 ) }); }
int mipbias = 4; // 3 is sufficient, but at 4 it loads #endregion Fields #region Constructors public VirtualTexture( D3D10.Device device, VirtualTextureInfo info, int atlassize, int uploadsperframe, string filename ) { this.device = device; this.info = info; this.atlascount = atlassize / info.PageSize; this.uploadsperframe = uploadsperframe; indexer = new PageIndexer( info ); toload = new List<PageCount>( indexer.Count ); Console.Write( "Creating PageAtlas..."); atlas = new TextureAtlas( device, info, atlascount, uploadsperframe ); Console.WriteLine("done."); Console.Write( "Creating PageLoader..." ); loader = new PageLoader( filename + ".cache", indexer, info ); Console.WriteLine("done."); cache = new PageCache( info, atlas, loader, indexer, atlascount ); Console.Write( "Creating PageTable..."); pagetable = new PageTable( device, cache, info, indexer ); Console.WriteLine("done."); }
public Texture( D3D10.Device device, int width, int height, DXGI.Format format, D3D10.ResourceUsage usage, int miplevels ) { D3D10.Texture2DDescription desc = new D3D10.Texture2DDescription(); desc.Width = width; desc.Height = height; D3D10.BindFlags bindflags = D3D10.BindFlags.ShaderResource; D3D10.ResourceOptionFlags optionflags = D3D10.ResourceOptionFlags.None; if( miplevels != 1 ) { bindflags |= D3D10.BindFlags.RenderTarget; optionflags |= D3D10.ResourceOptionFlags.GenerateMipMaps; } desc.ArraySize = 1; desc.BindFlags = bindflags; desc.CpuAccessFlags = D3D10.CpuAccessFlags.None; desc.Format = format; desc.MipLevels = miplevels; desc.OptionFlags = optionflags; desc.SampleDescription = new SlimDX.DXGI.SampleDescription( 1, 0 ); desc.Usage = usage; Create( device, desc ); }
public void BindToEffect( D3D10.Effect effect ) { texture.BindToEffect( effect, "PageTable" ); D3D10.EffectScalarVariable fxpagetablesize = effect.GetVariableByName( "PageTableSize" ).AsScalar(); fxpagetablesize.Set( (float)info.PageTableSize ); }
public TextureAtlas( D3D10.Device device, VirtualTextureInfo info, int count, int uploadsperframe ) { this.device = device; this.info = info; int pagesize = info.PageSize; resource = new Direct3D.Texture( device, count * pagesize, count * pagesize, DXGI.Format.R8G8B8A8_UNorm, D3D10.ResourceUsage.Default, 1 ); staging = new Direct3D.StagingTexturePool( device, pagesize, pagesize, DXGI.Format.R8G8B8A8_UNorm, uploadsperframe, D3D10.CpuAccessFlags.Write ); }
/// <summary> /// Draws the console /// </summary> /// <param name="sprite">Sprite for better performance</param> public override void Draw(D3D10.Sprite sprite) { if (isOn&&font!=null) { //old ones for (int i = 0; i < 10; i++) { font.Draw(sprite, lines[(i + counter) % 10], new Rectangle(140, i * 10, 600, 20), SlimDX.Direct3D10.FontDrawFlags.Left, (uint)Color.AliceBlue.ToArgb()); } //and the current one font.Draw(sprite, ">" + currentLine, new Rectangle(140, 105, 600, 20), SlimDX.Direct3D10.FontDrawFlags.Left, (uint)Color.AliceBlue.ToArgb()); } }
public PageTable( D3D10.Device device, PageCache cache, VirtualTextureInfo info, PageIndexer indexer ) { this.info = info; this.device = device; this.indexer = indexer; quadtree = new Quadtree(new Rectangle(0, 0, info.PageTableSize, info.PageTableSize), MathExtensions.Log2(info.PageTableSize)); int size = info.PageTableSize; texture = new Direct3D.Texture( device, size, size, DXGI.Format.R8G8B8A8_UNorm, D3D10.ResourceUsage.Default, 0 ); staging = new Direct3D.WriteTexture( device, size, size, DXGI.Format.R8G8B8A8_UNorm ); cache.Added += ( Page page, Point pt ) => quadtree.Add( page, pt ); cache.Removed += ( Page page, Point pt ) => quadtree.Remove( page ); SetupDataAndInfo(); }
public WriteTexture( D3D10.Device device, int width, int height, DXGI.Format format ) { D3D10.Texture2DDescription desc = new D3D10.Texture2DDescription(); desc.Width = width; desc.Height = height; desc.ArraySize = 1; desc.BindFlags = D3D10.BindFlags.None; desc.CpuAccessFlags = D3D10.CpuAccessFlags.Write; desc.Format = format; desc.MipLevels = 1; desc.OptionFlags = D3D10.ResourceOptionFlags.None; desc.SampleDescription = new SlimDX.DXGI.SampleDescription( 1, 0 ); desc.Usage = D3D10.ResourceUsage.Staging; Resource = new D3D10.Texture2D( device, desc ); }
public StagingTexturePool( D3D10.Device device, int width, int height, DXGI.Format format, int count, D3D10.CpuAccessFlags cpuaccess ) { D3D10.Texture2DDescription desc = new D3D10.Texture2DDescription(); desc.Width = width; desc.Height = height; desc.ArraySize = 1; desc.BindFlags = D3D10.BindFlags.None; desc.CpuAccessFlags = cpuaccess; desc.Format = format; desc.MipLevels = 1; desc.OptionFlags = D3D10.ResourceOptionFlags.None; desc.SampleDescription = new SlimDX.DXGI.SampleDescription( 1, 0 ); desc.Usage = D3D10.ResourceUsage.Staging; resources = new D3D10.Texture2D[count]; for( int i = 0; i < count; ++i ) resources[i] = new D3D10.Texture2D( device, desc ); }
public DepthBuffer( D3D10.Device device, int width, int height, DXGI.Format format ) { this.device = device; D3D10.Texture2DDescription desc = new D3D10.Texture2DDescription(); desc.Width = width; desc.Height = height; desc.ArraySize = 1; desc.BindFlags = D3D10.BindFlags.DepthStencil; desc.CpuAccessFlags = D3D10.CpuAccessFlags.None; desc.Format = format; desc.MipLevels = 1; desc.OptionFlags = D3D10.ResourceOptionFlags.None; desc.SampleDescription = new SlimDX.DXGI.SampleDescription( 1, 0 ); desc.Usage = D3D10.ResourceUsage.Default; Resource = new D3D10.Texture2D( device, desc ); View = new D3D10.DepthStencilView( device, Resource ); }
public D3D10.Texture2D AddToTexture2D(String name, D3D10.Texture2D file, int nr ,int maxTextures) { D3D10.Texture2D temp; if (textures.ContainsKey(name)) temp = textures[name]; else { D3D10.Texture2DDescription desc = new SlimDX.Direct3D10.Texture2DDescription(); desc.ArraySize = maxTextures; desc.BindFlags = D3D10.BindFlags.ShaderResource; desc.CpuAccessFlags = D3D10.CpuAccessFlags.None; desc.Format = file.Description.Format; desc.Height = file.Description.Height; desc.Width = file.Description.Width; desc.MipLevels = file.Description.MipLevels; desc.OptionFlags = D3D10.ResourceOptionFlags.None; SlimDX.DXGI.SampleDescription sampleDesc = new SlimDX.DXGI.SampleDescription(); sampleDesc.Count = 1; sampleDesc.Quality = 0; desc.SampleDescription = sampleDesc; desc.Usage = D3D10.ResourceUsage.Default; temp = new SlimDX.Direct3D10.Texture2D(Game.gameClass.GetDevice(), desc); textures.Add(name, temp); } D3D10.ResourceRegion region = new SlimDX.Direct3D10.ResourceRegion(); region.Back = 1; region.Front = 0; region.Left = region.Top = 0; region.Right = file.Description.Width; region.Bottom = file.Description.Height; for (int i = 0, q = 1; i < file.Description.MipLevels; i++, q *= 2) { region.Right /= q; region.Bottom /= q; Game.gameClass.GetDevice().CopySubresourceRegion(file, i, region, temp, i + (nr * file.Description.MipLevels), 0, 0, 0); } return temp; }
public void BindToEffect( D3D10.Effect effect, string name ) { D3D10.EffectResourceVariable fxvar = effect.GetVariableByName( name ).AsResource(); fxvar.SetResource( View ); }
public void BindToEffect( D3D10.Effect effect ) { D3D10.EffectResourceVariable fxpagetabletex2 = effect.GetVariableByName( "TextureAtlas" ).AsResource(); fxpagetabletex2.SetResource( resource.View ); }
public Texture( D3D10.Device device, string filename ) { Resource = D3D10.Texture2D.FromFile( device, filename ); View = new D3D10.ShaderResourceView( device, Resource ); }
void Create( D3D10.Device device, D3D10.Texture2DDescription desc ) { Resource = new D3D10.Texture2D( device, desc ); View = new D3D10.ShaderResourceView( device, Resource ); }
public D3D10.Font LoadFont(String name, D3D10.FontDescription desc) { if (fonts.ContainsKey(name)) return fonts[name]; D3D10.Font temp = new SlimDX.Direct3D10.Font(Game.gameClass.GetDevice(), desc); fonts.Add(name,temp); return temp; }
/// <summary> /// Loads effect /// </summary> /// <param name="name">Effect name</param> /// <param name="pool">If effect is to be a 'child effect' then recived 'pool' variable /// will be used as a parent. In other case type 'null'</param> /// <returns>Desired effect</returns> public D3D10.Effect LoadEffect(String name, D3D10.EffectPool pool) { if (effects.ContainsKey(name)) return effects[name]; string error=""; D3D10.Effect temp; if(pool==null) temp = D3D10.Effect.FromFile(Game.gameClass.GetDevice(), name, "fx_4_0", SlimDX.Direct3D10.ShaderFlags.Debug, SlimDX.Direct3D10.EffectFlags.None, null, null, out error); else temp = D3D10.Effect.FromFile(Game.gameClass.GetDevice(), name, "fx_4_0", SlimDX.Direct3D10.ShaderFlags.Debug, SlimDX.Direct3D10.EffectFlags.ChildEffect, pool, null, out error); effects.Add(name, temp); return temp; }
/// <summary> /// Draws the panel /// </summary> /// <param name="sprite">Sprite for better performance</param> public override void Draw(D3D10.Sprite sprite) { if (isOn&&font!=null) font.Draw(sprite, info, new Rectangle(0, 0, 130,300), SlimDX.Direct3D10.FontDrawFlags.Left, (uint)Color.AliceBlue.ToArgb()); }
protected bool isOn; //each module can be turned on/off #endregion Fields #region Methods public virtual void Draw(D3D10.Sprite sprite) { }
public void BindToEffect( D3D10.Effect effect ) { atlas.BindToEffect( effect ); pagetable.BindToEffect( effect ); int pagesize = info.PageSize; effect.GetVariableByName( "VirtualTextureSize" ).AsScalar().Set( (float)info.VirtualTextureSize ); effect.GetVariableByName( "AtlasScale" ).AsScalar().Set( 1.0f/atlascount ); effect.GetVariableByName( "BorderScale" ).AsScalar().Set( (pagesize-2.0f*info.BorderSize)/pagesize ); effect.GetVariableByName( "BorderOffset" ).AsScalar().Set( info.BorderSize/(float)pagesize ); fxmipbias = effect.GetVariableByName( "MipBias" ).AsScalar(); fxmipbias.Set( (float)mipbias ); }