/// <summary> /// /// </summary> /// <param name="device"></param> internal protected ShaderResource( GraphicsDevice device, ShaderResourceView srv, int w, int h, int d ) : base(device) { this.SRV = srv; this.Width = w; this.Height = h; this.Depth = d; }
/// <summary> /// /// </summary> /// <param name="device"></param> /// <param name="size"></param> /// <param name="count"></param> /// <param name="format"></param> /// <param name="mips"></param> public TextureCubeArray ( GraphicsDevice device, int size, int count, ColorFormat format, bool mips ) : base(device) { if (count>2048/6) { throw new GraphicsException("Too much elements in texture array"); } this.Width = size; this.Depth = 1; this.Height = size; this.MipCount = mips ? ShaderResource.CalculateMipLevels(Width,Height) : 1; var texDesc = new Texture2DDescription(); texDesc.ArraySize = 6 * count; texDesc.BindFlags = BindFlags.ShaderResource; texDesc.CpuAccessFlags = CpuAccessFlags.None; texDesc.Format = MakeTypeless( Converter.Convert( format ) ); texDesc.Height = Height; texDesc.MipLevels = 0; texDesc.OptionFlags = ResourceOptionFlags.TextureCube; texDesc.SampleDescription.Count = 1; texDesc.SampleDescription.Quality = 0; texDesc.Usage = ResourceUsage.Default; texDesc.Width = Width; texCubeArray = new D3D.Texture2D( device.Device, texDesc ); SRV = new ShaderResourceView( device.Device, texCubeArray ); }
/// <summary> /// Creates texture /// </summary> /// <param name="device"></param> public VolumeRWTexture ( GraphicsDevice device, int width, int height, int depth, ColorFormat format, bool mips ) : base( device ) { this.Width = width; this.Height = height; this.Depth = depth; this.format = format; this.mipCount = mips ? ShaderResource.CalculateMipLevels(Width,Height,Depth) : 1; var texDesc = new Texture3DDescription(); texDesc.BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess; texDesc.CpuAccessFlags = CpuAccessFlags.None; texDesc.Format = Converter.Convert( format ); texDesc.Height = Height; texDesc.MipLevels = mipCount; texDesc.OptionFlags = ResourceOptionFlags.None; texDesc.Usage = ResourceUsage.Default; texDesc.Width = Width; texDesc.Depth = Depth; var uavDesc = new UnorderedAccessViewDescription(); uavDesc.Format = Converter.Convert( format ); uavDesc.Dimension = UnorderedAccessViewDimension.Texture3D; uavDesc.Texture3D.FirstWSlice = 0; uavDesc.Texture3D.MipSlice = 0; uavDesc.Texture3D.WSize = depth; tex3D = new D3D.Texture3D( device.Device, texDesc ); SRV = new D3D.ShaderResourceView( device.Device, tex3D ); uav = new UnorderedAccessView( device.Device, tex3D, uavDesc ); }
/// <summary> /// Constructor /// </summary> /// <param name="rs"></param> /// <param name="path"></param> /// <param name="combinerEnum"></param> public Ubershader ( GraphicsDevice device, Stream stream ) : base(device) { database.Clear(); using ( var br = new BinaryReader( stream ) ) { var foucCC = br.ReadFourCC(); if (foucCC!=UbershaderSignature) { throw new IOException("Bad ubershader signature"); } var count = br.ReadInt32(); for (int i=0; i<count; i++) { var defines = br.ReadString(); int length; br.ExpectFourCC("PSBC", "ubershader"); length = br.ReadInt32(); var ps = br.ReadBytes( length ); br.ExpectFourCC("VSBC", "ubershader"); length = br.ReadInt32(); var vs = br.ReadBytes( length ); br.ExpectFourCC("GSBC", "ubershader"); length = br.ReadInt32(); var gs = br.ReadBytes( length ); br.ExpectFourCC("HSBC", "ubershader"); length = br.ReadInt32(); var hs = br.ReadBytes( length ); br.ExpectFourCC("DSBC", "ubershader"); length = br.ReadInt32(); var ds = br.ReadBytes( length ); br.ExpectFourCC("CSBC", "ubershader"); length = br.ReadInt32(); var cs = br.ReadBytes( length ); //Log.Message("{0}", profile ); //PrintSignature( bytecode, "ISGN" ); //PrintSignature( bytecode, "OSGN" ); //PrintSignature( bytecode, "OSG5" ); if (database.ContainsKey(defines)) { Log.Warning("Duplicate definitions: {0}", defines ); continue; } database.Add( defines, new UsdbEntry( defines, ps, vs, gs, hs, ds, cs ) ); } } Log.Debug("Ubershader: {0} shaders", database.Count ); }
/// <summary> /// Creates an instance of this object. /// </summary> /// <param name="device"></param> /// <param name="capacity"></param> public IndexBuffer ( GraphicsDevice device, int capacity ) { //Log.Message("Creation: Index Buffer"); this.device = device; this.capacity = capacity; BufferDescription desc = new BufferDescription(); desc.BindFlags = BindFlags.IndexBuffer; desc.CpuAccessFlags = CpuAccessFlags.Write; desc.OptionFlags = ResourceOptionFlags.None; desc.SizeInBytes = capacity * sizeof(int); desc.StructureByteStride = 0; desc.Usage = ResourceUsage.Dynamic; lock (device.DeviceContext) { indexBuffer = new D3D11.Buffer( device.Device, desc ); } }
/// <summary> /// /// </summary> /// <param name="engine"></param> public RenderSystem ( Game Game ) : base(Game) { Counters = new RenderCounters(); Width = 1024; Height = 768; Fullscreen = false; StereoMode = StereoMode.Disabled; InterlacingMode = InterlacingMode.HorizontalLR; UseDebugDevice = false; VSyncInterval = 1; MsaaEnabled = false; UseFXAA = true; this.Device = Game.GraphicsDevice; viewLayers = new List<RenderLayer>(); spriteEngine = new SpriteEngine( this ); gis = new Gis(Game); filter = new Filter( Game ); ssaoFilter = new SsaoFilter( Game ); hdrFilter = new HdrFilter( Game ); dofFilter = new DofFilter( Game ); lightRenderer = new LightRenderer( Game ); sceneRenderer = new SceneRenderer( Game, this ); sky = new Sky( Game ); bitonicSort = new BitonicSort( Game ); Device.DisplayBoundsChanged += (s,e) => { var handler = DisplayBoundsChanged; if (handler!=null) { handler(s,e); } }; }
/// <summary> /// Creates instance of HbaoFilter /// </summary> /// <param name="Game"></param> public SsaoFilter( Game Game ) : base( Game ) { device = Game.GraphicsDevice; }
/// <summary> /// /// </summary> public PipelineState ( GraphicsDevice device ) : base(device) { BlendState = BlendState.Opaque; RasterizerState = RasterizerState.CullNone; DepthStencilState = DepthStencilState.Default; RasterizedStream = -1; Primitive = Primitive.TriangleList; isReady = false; }
/// <summary> /// Creates instance of sampler state collection. /// </summary> /// <param name="device"></param> internal SamplerStateCollection ( GraphicsDevice device, CommonShaderStage stage ) : base(device) { states = new SamplerState[ Count ]; this.stage = stage; deviceContext = device.DeviceContext; }
public BitonicSort( Game Game ) : base( Game ) { device = Game.GraphicsDevice; }
/// <summary> /// /// </summary> /// <param name="device"></param> public GraphicsResource ( GraphicsDevice device ) { this.device = device; }
/// <summary> /// Creates buffer from given indices /// </summary> /// <param name="device"></param> /// <param name="indices"></param> /// <returns></returns> public static IndexBuffer Create ( GraphicsDevice device, int[] indices ) { var ib = new IndexBuffer( device, indices.Length ); ib.SetData( indices ); return ib; }
/// <summary> /// /// </summary> /// <param name="device"></param> internal void Apply ( GraphicsDevice device ) { if ( state == null ) { var dss = new DepthStencilStateDescription(); dss.DepthComparison = Converter.Convert( this.depthComparison ); dss.DepthWriteMask = this.depthWriteEnabled ? DepthWriteMask.All : DepthWriteMask.Zero; dss.IsDepthEnabled = this.depthEnabled; dss.IsStencilEnabled = this.stencilEnabled; dss.StencilReadMask = this.stencilReadMask; dss.StencilWriteMask = this.stencilWriteMask; dss.BackFace.Comparison = Converter.Convert( this.backStencilComparison ); dss.BackFace.FailOperation = Converter.Convert( this.backFailOp ); dss.BackFace.DepthFailOperation = Converter.Convert( this.backDepthFailOp ); dss.BackFace.PassOperation = Converter.Convert( this.backPassOp ); dss.FrontFace.Comparison = Converter.Convert( this.backStencilComparison ); dss.FrontFace.FailOperation = Converter.Convert( this.backFailOp ); dss.FrontFace.DepthFailOperation = Converter.Convert( this.backDepthFailOp ); dss.FrontFace.PassOperation = Converter.Convert( this.backPassOp ); state = new D3DDepthStencilState( device.Device, dss ); } device.DeviceContext.OutputMerger.DepthStencilState = state; device.DeviceContext.OutputMerger.DepthStencilReference = stencilReference; }
/// <summary> /// /// </summary> /// <param name="singleShadowMapSize"></param> /// <param name="splitCount"></param> public CascadedShadowMap ( GraphicsDevice device, int cascadeSize, int cascadeCount ) { this.device = device; this.cascadeCount = cascadeCount; this.cascadeSize = cascadeSize; if (cascadeCount<1 || cascadeCount>MaxCascadeCount) { throw new ArgumentOutOfRangeException("cascadeCount must be within range 1.." + MaxCascadeCount.ToString()); } if (cascadeSize<64 || cascadeSize > MaxCascadeSize) { throw new ArgumentOutOfRangeException("cascadeSize must be within range 64.." + MaxCascadeSize.ToString()); } if (!MathUtil.IsPowerOfTwo( cascadeSize )) { Log.Warning("CascadedShadowMap : splitSize is not power of 2"); } csmColor = new RenderTarget2D( device, ColorFormat.R32F, cascadeSize * cascadeCount, cascadeSize ); csmDepth = new DepthStencil2D( device, DepthFormat.D24S8, cascadeSize * cascadeCount, cascadeSize ); prtShadow = new RenderTarget2D( device, ColorFormat.Rgba8_sRGB, cascadeSize * cascadeCount, cascadeSize ); }
/// <summary> /// Constructor /// </summary> /// <param name="rs"></param> public Sky ( Game game ) : base( game ) { rs = Game.GraphicsDevice; }
/// <summary> /// Creates render target /// </summary> /// <param name="rs"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> public RenderTargetCube ( GraphicsDevice device, ColorFormat format, int size, int samples, string debugName = "" ) : base ( device ) { Create( format, size, samples, false, debugName ); }
/// <summary> /// /// </summary> /// <param name="device"></param> protected ShaderResource( GraphicsDevice device ) : base(device) { }
/// <summary> /// /// </summary> /// <param name="device"></param> internal D3DSamplerState Apply ( GraphicsDevice device ) { if ( state == null ) { var ssd = new SamplerStateDescription(); ssd.ComparisonFunction = Converter.Convert( this.compareFunc ); ssd.AddressU = Converter.Convert( this.addressU ); ssd.AddressV = Converter.Convert( this.addressV ); ssd.AddressW = Converter.Convert( this.addressW ); ssd.BorderColor = SharpDXHelper.Convert( this.borderColor ); ssd.Filter = Converter.Convert( this.filter ); ssd.MaximumAnisotropy = this.maxAnisotropy; ssd.MaximumLod = this.maxMipLevel; ssd.MinimumLod = this.minMipLevel; ssd.MipLodBias = this.mipMapBias; state = new D3DSamplerState( device.Device, ssd ); } return state; }
/// <summary> /// Creates instance of sampler state collection. /// </summary> /// <param name="device"></param> internal ConstantBufferCollection ( GraphicsDevice device, CommonShaderStage stage ) : base(device) { buffers = new ConstantBuffer[ Count ]; this.stage = stage; deviceContext = device.DeviceContext; }
/// <summary> /// Constrcutor /// </summary> /// <param name="device"></param> /// <param name="fileName"></param> public SpriteFont ( GraphicsDevice rs, Stream stream ) { this.rs = rs; using (var br = new BinaryReader(stream)) { var xml = br.ReadString(); FontFile input = FontLoader.LoadFromString( xml ); int numGlyphs = input.Chars.Max( ch => ch.ID ); // create charInfo and kernings : fontInfo.kernings = new Dictionary<Tuple<char,char>, float>(); fontInfo.charInfo = new SpriteFontInfo.CharInfo[numGlyphs+1]; // check one-page bitmap fonts : if (input.Pages.Count!=1) { throw new GraphicsException("Only one page of font image is supported"); } // create path for font-image : string fontImagePath = input.Pages[0].File; // skip two bytes : var texData = stream.ReadAllBytes(); fontTexture = new UserTexture( rs.Game.RenderSystem, texData, false ); // Fill structure : fontInfo.fontFace = input.Info.Face; fontInfo.baseLine = input.Common.Base; fontInfo.lineHeight = input.Common.LineHeight; fontInfo.scaleWidth = input.Common.ScaleW; fontInfo.scaleHeight = input.Common.ScaleH; float scaleWidth = fontInfo.scaleWidth; float scaleHeight = fontInfo.scaleHeight; // process character info : for ( int i=0; i<input.Chars.Count; i++) { FontChar ch = input.Chars[i]; int id = ch.ID; if (id<0) continue; int x = ch.X; int y = ch.Y; int xoffs = ch.XOffset; int yoffs = ch.YOffset; int w = ch.Width; int h = ch.Height; fontInfo.charInfo[ ch.ID ].validChar = true; fontInfo.charInfo[ ch.ID ].xAdvance = ch.XAdvance; fontInfo.charInfo[ ch.ID ].srcRect = new RectangleF(x, y, w, h); fontInfo.charInfo[ ch.ID ].dstRect = new RectangleF(xoffs, yoffs, w, h); } var letterHeights = input.Chars .Where( ch1 => char.IsUpper( (char)(ch1.ID) ) ) .Select( ch2 => ch2.Height ) .OrderBy( h => h ) .ToList(); CapHeight = letterHeights[ letterHeights.Count/2 ]; // process kerning info : for ( int i=0; i<input.Kernings.Count; i++) { var pair = new Tuple<char,char>( (char)input.Kernings[i].First, (char)input.Kernings[i].Second); int kerning = input.Kernings[i].Amount; fontInfo.kernings.Add( pair, kerning ); } SpaceWidth = MeasureString(" ").Width; LineHeight = MeasureString(" ").Height; } }
/// <summary> /// Creates render target /// </summary> /// <param name="rs"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> public DepthStencilCube ( GraphicsDevice device, DepthFormat format, int size, int samples, string debugName = "" ) : base ( device ) { bool msaa = samples > 1; CheckSamplesCount( samples ); SampleCount = samples; Format = format; SampleCount = samples; Width = size; Height = size; Depth = 1; var texDesc = new Texture2DDescription(); texDesc.Width = Width; texDesc.Height = Height; texDesc.ArraySize = 6; texDesc.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource; texDesc.CpuAccessFlags = CpuAccessFlags.None; texDesc.Format = Converter.ConvertToTex( format ); texDesc.MipLevels = 1; texDesc.OptionFlags = ResourceOptionFlags.TextureCube; texDesc.SampleDescription = new DXGI.SampleDescription(samples, 0); texDesc.Usage = ResourceUsage.Default; texCube = new D3D.Texture2D( device.Device, texDesc ); var srvDesc = new ShaderResourceViewDescription(); srvDesc.Dimension = samples > 1 ? ShaderResourceViewDimension.Texture2DMultisampled : ShaderResourceViewDimension.Texture2D; srvDesc.Format = Converter.ConvertToSRV( format ); srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.MipLevels = 1; SRV = new ShaderResourceView( device.Device, texCube ); // // Create surfaces : // surfaces = new DepthStencilSurface[ 6 ]; for ( int face=0; face<6; face++) { var rtvDesc = new DepthStencilViewDescription(); rtvDesc.Texture2DArray.MipSlice = 0; rtvDesc.Texture2DArray.FirstArraySlice = face; rtvDesc.Texture2DArray.ArraySize = 1; rtvDesc.Dimension = msaa ? DepthStencilViewDimension.Texture2DMultisampledArray : DepthStencilViewDimension.Texture2DArray; rtvDesc.Format = Converter.ConvertToDSV( format ); var dsv = new DepthStencilView( device.Device, texCube, rtvDesc ); int subResId = Resource.CalculateSubResourceIndex( 0, face, 1 ); surfaces[face] = new DepthStencilSurface( dsv, format, Width, Height, SampleCount ); } }
/// <summary> /// Sets materials textures /// </summary> /// <param name="device"></param> internal void SetTextures ( GraphicsDevice device ) { for (int i=0; i<shaderResources.Length; i++) { device.PixelShaderResources[i] = shaderResources[i]; } }
/// <summary> /// /// </summary> /// <param name="device"></param> internal ShaderResourceCollection ( GraphicsDevice device, CommonShaderStage stage ) : base(device) { resources = new ShaderResource[ Count ]; this.stage = stage; deviceContext = device.DeviceContext; }
/// <summary> /// Creates render target /// </summary> /// <param name="rs"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> public RenderTargetCube ( GraphicsDevice device, ColorFormat format, int size, bool mips, string debugName = "" ) : base ( device ) { Create( format, size, 1, mips, debugName ); }
public Filter( Game Game ) : base( Game ) { rs = Game.GraphicsDevice; }
/// <summary> /// /// </summary> /// <param name="rs"></param> public SpriteEngine( RenderSystem rs ) : base(rs.Game) { this.device = rs.Device; }