Example #1
0
		public RenderTarget2D (GraphicsDevice graphicsDevice, int width, int height, bool mipMap, 
			SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
			:base (graphicsDevice, width, height, mipMap, preferredFormat)
		{


#if IPHONE
			if(GraphicsDevice.OpenGLESVersion == MonoTouch.OpenGLES.EAGLRenderingAPI.OpenGLES2)

			{
				GL20.GenFramebuffers(1, ref frameBuffer);
			}
			else
			{
				RenderTargetUsage = usage;
				DepthStencilFormat = preferredDepthFormat;
			}
#elif ANDROID
            if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0)
            {
                GL20.GenFramebuffers(1, ref frameBuffer);
            }
            else
            {
                RenderTargetUsage = usage;
                DepthStencilFormat = preferredDepthFormat;
            }
#else
				RenderTargetUsage = usage;
				DepthStencilFormat = preferredDepthFormat;
#endif


        }
        public IntermediateRenderTarget GetIntermediateTexture(int width, int height, bool mipmap, SurfaceFormat SurfaceFormat, DepthFormat DepthFormat, int preferedMultisampleCount, RenderTargetUsage RenderTargetUsage)
        {
            // Look for a matching rendertarget in the cache
            for (int i = 0; i < intermediateTextures.Count; i++)
            {
                if (intermediateTextures[i].InUse == false
                    && height == intermediateTextures[i].RenderTarget.Height
                    && width == intermediateTextures[i].RenderTarget.Width
                    && preferedMultisampleCount == intermediateTextures[i].RenderTarget.MultiSampleCount
                    && SurfaceFormat == intermediateTextures[i].RenderTarget.Format
                    && DepthFormat == intermediateTextures[i].RenderTarget.DepthStencilFormat
                    && RenderTargetUsage == intermediateTextures[i].RenderTarget.RenderTargetUsage
                    && (mipmap == true && intermediateTextures[i].RenderTarget.LevelCount > 0 || mipmap == false && intermediateTextures[i].RenderTarget.LevelCount == 0)

                    )
                {
                    intermediateTextures[i].InUse = true;
                    return intermediateTextures[i];
                }
            }

            // We didn't find one, let's make one
            IntermediateRenderTarget newTexture = new IntermediateRenderTarget();
            newTexture.RenderTarget = new RenderTarget2D(device,width, height, mipmap, SurfaceFormat,DepthFormat, preferedMultisampleCount, RenderTargetUsage );
            intermediateTextures.Add(newTexture);
            newTexture.InUse = true;
            return newTexture;
        }
Example #3
0
        public BackBuffer(GraphicsDevice graphicsDevice, string name)
        {
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("graphicsDevice");
            }

            this.graphicsDevice = graphicsDevice;

            Name = name;

            var pp = graphicsDevice.PresentationParameters;
            width = pp.BackBufferWidth;
            height = pp.BackBufferHeight;
            mipMap = true;
            surfaceFormat = pp.BackBufferFormat;
            depthFormat = pp.DepthStencilFormat;
            multiSampleCount = pp.MultiSampleCount;
            renderTargetUsage = pp.RenderTargetUsage;

            renderTargetCount = 1;
            currentIndex = 0;

            activated = false;
            disposed = false;
        }
Example #4
0
 public PostProcesses(SurfaceFormat? surface = null, DepthFormat? depth = null, bool mipmap = false, RenderTargetUsage? usage = null)
 {
     FormatSurface = surface;
     FormatDepth   = depth;
     MipMap        = mipmap;
     Usage         = usage;
 }
Example #5
0
        public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, 
			SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
            : base(graphicsDevice, width, height, mipMap, preferredFormat)
        {
            RenderTargetUsage = usage;
            DepthStencilFormat = preferredDepthFormat;
        }
        public RenderTarget2D UpdateCustomRenderTarget(RenderTarget2D renderTarget, IGameContext gameContext, SurfaceFormat? surfaceFormat, DepthFormat? depthFormat, int? multiSampleCount)
        {
            if (IsCustomRenderTargetOutOfDate(renderTarget, gameContext, surfaceFormat, depthFormat, multiSampleCount))
            {
                if (renderTarget != null)
                {
                    renderTarget.Dispose();
                }

                if (gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth == 0 &&
                    gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight == 0)
                {
                    return null;
                }

                renderTarget = new RenderTarget2D(
                    gameContext.Graphics.GraphicsDevice,
                    gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,
                    gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight,
                    false,
                    surfaceFormat ?? gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferFormat,
                    depthFormat ?? gameContext.Graphics.GraphicsDevice.PresentationParameters.DepthStencilFormat,
                    multiSampleCount ?? gameContext.Graphics.GraphicsDevice.PresentationParameters.MultiSampleCount,
                    RenderTargetUsage.PreserveContents);
            }

            return renderTarget;
        }
Example #7
0
 public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
   : base(graphicsDevice, width, height, mipMap, preferredFormat, true)
 {
   RenderTarget2D renderTarget2D = this;
   this.DepthStencilFormat = preferredDepthFormat;
   this.MultiSampleCount = preferredMultiSampleCount;
   this.RenderTargetUsage = usage;
   if (preferredDepthFormat == DepthFormat.None)
     return;
   Threading.BlockOnUIThread((Action) (() =>
   {
     GL.GenRenderbuffers(1, out renderTarget2D.glDepthStencilBuffer);
     GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, renderTarget2D.glDepthStencilBuffer);
     RenderbufferStorage local_0 = RenderbufferStorage.DepthComponent16;
     switch (preferredDepthFormat)
     {
       case DepthFormat.Depth24Stencil8:
         local_0 = RenderbufferStorage.Depth24Stencil8;
         break;
       case DepthFormat.Depth24:
         local_0 = RenderbufferStorage.DepthComponent24;
         break;
       case DepthFormat.Depth16:
         local_0 = RenderbufferStorage.DepthComponent16;
         break;
     }
     if (renderTarget2D.MultiSampleCount == 0)
       GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, local_0, renderTarget2D.width, renderTarget2D.height);
     else
       GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, renderTarget2D.MultiSampleCount, local_0, renderTarget2D.width, renderTarget2D.height);
   }));
 }
Example #8
0
 public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, 
     SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
     : base(graphicsDevice, width, height, mipMap, preferredFormat)
 {
     RenderTargetUsage = usage;
     //allocateOpenGLTexture();
 }
        private void PlatformConstruct(GraphicsDevice graphicsDevice, int width, int height, bool mipMap,
            SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
        {
            // Setup the multisampling description.
            var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0);
            if (preferredMultiSampleCount > 1)
            {
                multisampleDesc.Count = preferredMultiSampleCount;
                multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern;
            }

            // Create a descriptor for the depth/stencil buffer.
            // Allocate a 2-D surface as the depth/stencil buffer.
            // Create a DepthStencil view on this surface to use on bind.
            using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription
            {
                Format = SharpDXHelper.ToFormat(preferredDepthFormat),
                ArraySize = 1,
                MipLevels = 1,
                Width = width,
                Height = height,
                SampleDescription = multisampleDesc,
                BindFlags = BindFlags.DepthStencil,
            }))
            {
                // Create the view for binding to the device.
                _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription()
                {
                    Format = SharpDXHelper.ToFormat(preferredDepthFormat),
                    Dimension = DepthStencilViewDimension.Texture2D
                });
            }
        }
Example #10
0
 internal DepthStencilBuffer(GraphicsDevice device, Texture2DDescription description2D, DepthFormat depthFormat)
     : base(device, description2D)
 {
     DepthFormat = depthFormat;
     DefaultViewFormat = ComputeViewFormat(DepthFormat, out HasStencil);
     Initialize(Resource);
     HasReadOnlyView = InitializeViewsDelayed(out ReadOnlyView);
 }
Example #11
0
 internal DepthStencilBuffer(GraphicsDevice device, Direct3D11.Texture2D texture, DepthFormat depthFormat)
     : base(device, texture)
 {
     DepthFormat = depthFormat;
     DefaultViewFormat = ComputeViewFormat(DepthFormat, out HasStencil);
     Initialize(Resource);
     HasReadOnlyView = InitializeViewsDelayed(out ReadOnlyView);
 }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="dsv"></param>
		internal DepthStencilSurface ( DepthStencilView dsv, DepthFormat format, int width, int height, int sampleCount )
		{
			Width			=	width;
			Height			=	height;
			Format			=	format;
			SampleCount		=	sampleCount;
			DSV				=	dsv;
		}
        public RenderTargetGraphicsPresenter(GraphicsDevice device, RenderTarget2D renderTarget, DepthFormat depthFormat = DepthFormat.None)
            : base(device, CreatePresentationParameters(renderTarget, depthFormat))
        {
            PresentInterval = Description.PresentationInterval;

            // Initialize the swap chain
            backBuffer = renderTarget;
        }
Example #14
0
 public RenderTargetCube(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
   : base(graphicsDevice, size, mipMap, preferredFormat, true)
 {
   this.DepthStencilFormat = preferredDepthFormat;
   this.MultiSampleCount = preferredMultiSampleCount;
   this.RenderTargetUsage = usage;
   throw new NotImplementedException();
 }
Example #15
0
        /// <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 );
            }
        }
Example #16
0
	    public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage, bool shared, int arraySize)
	        : base(graphicsDevice, width, height, mipMap, preferredFormat, SurfaceType.RenderTarget, shared, arraySize)
	    {
            DepthStencilFormat = preferredDepthFormat;
            MultiSampleCount = preferredMultiSampleCount;
            RenderTargetUsage = usage;

            PlatformConstruct(graphicsDevice, width, height, mipMap, preferredFormat, preferredDepthFormat, preferredMultiSampleCount, usage, shared);
	    }
Example #17
0
		public RenderTarget2D (GraphicsDevice graphicsDevice, int width, int height, bool mipMap,
         					   SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount,
		                       RenderTargetUsage usage)
			:base(graphicsDevice, width, height,0, TextureUsage.None, format)
		{				
			
			allocateOpenGLTexture();
			
		}
Example #18
0
 public RenderTargetInfo(int width, int height, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, bool mipMap, RenderTargetUsage usage)
 {
     Width = width;
     Height = height;
     SurfaceFormat = format;
     DepthFormat = depthFormat;
     MultiSampleCount = multiSampleCount;
     MipMap = mipMap;
     Usage = usage;
 }
Example #19
0
 private void PlatformConstruct(GraphicsDevice graphicsDevice, int width, int height, bool mipMap,
     SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage, bool shared)
 {
     Threading.BlockOnUIThread(() =>
     {
         graphicsDevice.PlatformCreateRenderTarget(this, width, height, mipMap, preferredFormat, preferredDepthFormat, preferredMultiSampleCount, usage);
     });
     
     
 }
        public RenderTargetGraphicsPresenter(GraphicsDevice device, RenderTarget2D backBuffer, DepthFormat depthFormat = DepthFormat.None, bool disposeRenderTarget = false, bool depthAsShaderResource = false)
            : base(device, CreatePresentationParameters(backBuffer, depthFormat, depthAsShaderResource))
        {
            PresentInterval = Description.PresentationInterval;

            this.backBuffer = backBuffer;

            if (disposeRenderTarget)
                ToDispose(this.backBuffer);
        }
Example #21
0
 protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage)
 {
     m_Width = (int)Math.Ceiling(w * CCMacros.CCContentScaleFactor());
     m_Height = (int)Math.Ceiling(h * CCMacros.CCContentScaleFactor());
     m_ColorFormat = colorFormat;
     m_DepthFormat = depthFormat;
     m_Usage = usage;
     MakeTexture();
     return true;
 }
Example #22
0
        /// <summary>
        /// Creates depth stencil texture, view and shader resource with format D24S8
        /// </summary>
        /// <param name="rs"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="format"></param>
        public DepthStencil2D( GraphicsDevice device, DepthFormat format, int width, int height, int samples = 1 )
            : base(device)
        {
            CheckSamplesCount( samples );

            Width		=	width;
            Height		=	height;
            Depth		=	1;
            Format		=	format;
            SampleCount	=	samples;

            var bindFlags	=	BindFlags.DepthStencil;

            if (device.GraphicsProfile==GraphicsProfile.HiDef) {
                bindFlags	|=	BindFlags.ShaderResource;

            } else if (device.GraphicsProfile==GraphicsProfile.Reach) {
                if (samples==1) {
                    bindFlags	|=	BindFlags.ShaderResource;
                }
            }

            var	texDesc	=	new Texture2DDescription();
                texDesc.Width				=	width;
                texDesc.Height				=	height;
                texDesc.ArraySize			=	1;
                texDesc.BindFlags			=	bindFlags;
                texDesc.CpuAccessFlags		=	CpuAccessFlags.None;
                texDesc.Format				=	Converter.ConvertToTex( format );
                texDesc.MipLevels			=	1;
                texDesc.OptionFlags			=	ResourceOptionFlags.None;
                texDesc.SampleDescription	=	new DXGI.SampleDescription(samples, 0);
                texDesc.Usage				=	ResourceUsage.Default;

            var dsvDesc	=	new DepthStencilViewDescription();
                dsvDesc.Dimension			=	samples > 1 ? DepthStencilViewDimension.Texture2DMultisampled : DepthStencilViewDimension.Texture2D;
                dsvDesc.Format				=	Converter.ConvertToDSV( format );
                dsvDesc.Flags				=	DepthStencilViewFlags.None;

            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;

            tex2D		=	new D3D.Texture2D		( device.Device, texDesc );

            var dsv		=	new DepthStencilView	( device.Device, tex2D,	dsvDesc );

            if (bindFlags.HasFlag( BindFlags.ShaderResource)) {
                SRV		=	new ShaderResourceView	( device.Device, tex2D,	srvDesc );
            }

            surface		=	new DepthStencilSurface	( dsv, format, width, height, samples );
        }
Example #23
0
 public OutputSettings(int adapter, bool windowed, DeviceType devType, Format devFormat,
                       MultiSampleType antiAliasing, DepthFormat depthFormat, CreateFlags createFlags)
 {
     this.adapter = adapter;
     this.windowed = windowed;
     this.devType = devType;
     this.devFormat = devFormat;
     this.antiAliasing = antiAliasing;
     this.depthFormat = depthFormat;
     this.createFlags = createFlags;
 }
 public OutputRequirements(MultiSampleType aa, DeviceType dType, Format format, bool windowed,
                             DepthFormat depthFormat, bool hardwareTnL, Version vs)
 {
     this.antiAliasing = aa;
     this.devType = dType;
     this.format = format;
     this.windowed = windowed;
     this.depthFormat = depthFormat;
     this.hardwareTnL = hardwareTnL;
     this.vs = vs;
 }
Example #25
0
 /// <summary>
 /// Create a ManagedDepthStencilBuffer.
 /// </summary>
 /// <param name="game">The game.</param>
 /// <param name="surfaceToScreenRatio">The surface to screen ratio.</param>
 /// <param name="format">The format of the stencil buffer.</param>
 /// <param name="msType">The multi-sampling type of the texture produced by the render target.</param>
 /// <param name="msQuality">The multi-sampling quality of the texture produced by the render target.</param>
 public ManagedDepthStencilBuffer(XiGame game, float surfaceToScreenRatio,
     DepthFormat format, MultiSampleType msType, int msQuality)
 {
     XiHelper.ArgumentNullCheck(game);
     this.game = game;
     this.format = format;
     this.msType = msType;
     this.msQuality = msQuality;
     game.GraphicsDevice.DeviceReset += device_DeviceReset;
     SurfaceToScreenRatio = surfaceToScreenRatio;
 }
 public GraphicsDeviceSettings(int adapter, bool windowed, DeviceType devType, Format devFormat,
                               MultiSampleType multisample, DepthFormat depthFormat, CreateFlags createFlags)
 {
     this.adapter = adapter;
     this.windowed = windowed;
     this.devType = devType;
     this.devFormat = devFormat;
     this.multisample = multisample;
     this.depthFormat = depthFormat;
     this.createFlags = createFlags;
 }
Example #27
0
 private void PlatformConstruct(
     GraphicsDevice graphicsDevice,
     int width,
     int height,
     bool mipMap,
     DepthFormat preferredDepthFormat,
     int preferredMultiSampleCount,
     RenderTargetUsage usage,
     bool shared)
 {
     throw new NotImplementedException();
 }
 public GraphicsDevice3DOutputDescription(int adapter, bool windowed, DeviceType type,
                                          Format format, MultiSampleType multiSample,
                                          DepthFormat depthFormat, CreateFlags createFlags)
 {
     this.adapter = adapter;
     this.windowed = windowed;
     this.type = type;
     this.format = format;
     this.multiSample = multiSample;
     this.depthFormat = depthFormat;
     this.createFlags = createFlags;
 }
 private void PlatformConstruct(
     GraphicsDevice graphicsDevice,
     int width,
     int height,
     bool mipMap,
     DepthFormat preferredDepthFormat,
     int preferredMultiSampleCount,
     RenderTargetUsage usage,
     bool shared)
 {
     graphicsDevice.PlatformCreateRenderTarget(this, width, height, mipMap, this.Format, preferredDepthFormat, preferredMultiSampleCount, usage);
 }
Example #30
0
        public IDictionary <TrackingMarker, Point3D> Convert2DTrackingPointsTo3DTrackingPoints(
            IDictionary <TrackingMarker, Point2D> trackingPoints2D,
            DepthFormat dFormat, ICollection <short> depthShorts, ColourFormat cFormat)
        {
            var kdFormat = FormatConvertor.ConvertToKinect(dFormat);
            var kcFormat = FormatConvertor.ConvertToKinect(cFormat);

            var dShorts = depthShorts.ToArray();

            // HACK!!!!!!!!!!!!!!!!
            return(_ConvertColourPointsToWorldPoints(trackingPoints2D, kdFormat, dShorts, kcFormat));
        }
Example #31
0
        private void PlatformConstruct(GraphicsDevice graphicsDevice, int width, int height, bool mipMap,
            SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage, bool shared)
        {
            _frameBuffer = new FrameBuffer();     
            _frameBuffer.SetColorTarget(_texture2D,0);

            // If we don't need a depth buffer then we're done.
            if (preferredDepthFormat == DepthFormat.None)
                return;

            throw new NotImplementedException();
        }
Example #32
0
            "GraphicsConfig.cfg");                                                  // File Name

        public Configuration LoadConfiguration()
        {
            Configuration config = new Configuration();

            if (!File.Exists(ConfigLocation))
            {
                return(config);
            }
            try
            {
                using (StreamReader sr = new StreamReader(new BufferedStream(File.Open(ConfigLocation, FileMode.Open))))
                {
                    sr.ReadLine(); // Skip warning line
                    string adapterDesc = sr.ReadLine();
                    string adapterName = sr.ReadLine();
                    if (String.IsNullOrEmpty(adapterName) || String.IsNullOrEmpty(adapterName))
                    {
                        return(config);
                    }

                    string[] resString = sr.ReadLine().Split('.');
                    config.Resolution = new Resolution()
                    {
                        Width  = int.Parse(resString[0]),
                        Height = int.Parse(resString[1]),
                    };
                    config.RefreshRate = new RefreshRate(int.Parse(resString[2]));

                    config.Antialiasing = int.Parse(sr.ReadLine()) > 0 ? OnOff.On : OnOff.Off;
                    config.VSync        = int.Parse(sr.ReadLine()) > 0 ? OnOff.On : OnOff.Off;

                    config.ShadowQuality     = int.Parse(sr.ReadLine()) > 0 ? HighLow.High : HighLow.Low;
                    config.ReflectionQuality = int.Parse(sr.ReadLine()) > 0 ? HighLow.High : HighLow.Low;

                    config.DisplayMode = int.Parse(sr.ReadLine()) > 0 ? DisplayMode.Letterbox : DisplayMode.Widescreen;

                    config.GraphicsAdapter = new GraphicsAdapter()
                    {
                        GUID        = sr.ReadLine(),
                        Name        = adapterName,
                        Description = adapterDesc,
                        MonitorID   = sr.ReadLine()
                    };

                    config.DepthFormat = DepthFormat.FromFourCC(int.Parse(sr.ReadLine()));
                    return(config);
                }
            }
            catch
            {
                return(new Configuration());
            }
        }
Example #33
0
        public static Format ConvertToSRV(DepthFormat format)
        {
            switch (format)
            {
            case DepthFormat.D24S8: return(Format.R24_UNorm_X8_Typeless);

            case DepthFormat.D16: return(Format.R16_UNorm);

            case DepthFormat.D32F: return(Format.R32_Float);
            }
            throw new ArgumentException("bad format");
        }
Example #34
0
        /// <summary>
        /// Creates a render target for render to textures. Use size type constructor for screen relative sizes.
        /// </summary>
        /// <param name="size">Render target size</param>
        /// <param name="_surfaceFormat">Surface format</param>
        /// <param name="_depthFormat">Depth Format</param>
        /// <param name="antialiasingType">Multi sampling type: System value or no antialiasing.</param>
        public RenderTargetCube(int size, SurfaceFormat _surfaceFormat, DepthFormat _depthFormat, RenderTarget.AntialiasingType antialiasingType = RenderTarget.AntialiasingType.NoAntialiasing, bool mipMap = false)
        {
            Name = "Render Target";
            Size = size;

            SurfaceFormat = _surfaceFormat;
            DepthFormat = _depthFormat;
            Antialiasing = antialiasingType;
            MipMap = mipMap;

            Create();
        } // RenderTarget
Example #35
0
 public GraphicsDevice3DOutputDescription(int adapter, bool windowed, DeviceType type,
                                          Format format, MultiSampleType multiSample,
                                          DepthFormat depthFormat, CreateFlags createFlags)
 {
     this.adapter     = adapter;
     this.windowed    = windowed;
     this.type        = type;
     this.format      = format;
     this.multiSample = multiSample;
     this.depthFormat = depthFormat;
     this.createFlags = createFlags;
 }
Example #36
0
        public RenderTargetBinding(RenderTargetCube renderTarget, CubeMapFace cubeMapFace)
        {
            RenderTarget = renderTarget ?? throw new ArgumentNullException(nameof(renderTarget));

            if (cubeMapFace < CubeMapFace.PositiveX || cubeMapFace > CubeMapFace.NegativeZ)
            {
                throw new ArgumentOutOfRangeException(nameof(cubeMapFace));
            }

            ArraySlice  = (int)cubeMapFace;
            DepthFormat = renderTarget.DepthStencilFormat;
        }
Example #37
0
 /// <summary>
 /// helper for creating a RenderTarget2D
 /// </summary>
 /// <param name="width">Width.</param>
 /// <param name="height">Height.</param>
 /// <param name="preferredFormat">Preferred format.</param>
 /// <param name="preferredDepthFormat">Preferred depth format.</param>
 public RenderTexture(int width, int height, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat)
 {
     renderTarget = new RenderTarget2D(
         Core.graphicsDevice,
         width,
         height,
         false,
         preferredFormat,
         preferredDepthFormat,
         0,
         RenderTargetUsage.PreserveContents);
 }
Example #38
0
        public void Draw(GraphicsDeviceManager gdm, SpriteBatch sb, Vector2 pos, Vector2 backTexPos)
        {
            DepthFormat oldDepthFormat = gdm.PreferredDepthStencilFormat;

            gdm.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;

            var m = Matrix.CreateOrthographicOffCenter(0,
                                                       gdm.GraphicsDevice.PresentationParameters.BackBufferWidth,
                                                       gdm.GraphicsDevice.PresentationParameters.BackBufferHeight,
                                                       0, 0, 1);

            var a = new AlphaTestEffect(gdm.GraphicsDevice)
            {
                Projection = m
            };


            var stencil1 = new DepthStencilState {
                StencilEnable     = true,
                StencilFunction   = CompareFunction.Always,
                StencilPass       = StencilOperation.Replace,
                ReferenceStencil  = 1,
                DepthBufferEnable = false,
            };

            var stencil2 = new DepthStencilState {
                StencilEnable     = true,
                StencilFunction   = CompareFunction.LessEqual,
                StencilPass       = StencilOperation.Keep,
                ReferenceStencil  = 1,
                DepthBufferEnable = false,
            };



            sb.End();

            sb.Begin(SpriteSortMode.Immediate, null, null, stencil1, null, a); //This is the mask shape
            sb.Draw(this.maskTex, pos, Color.White);
            sb.End();

            sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);
            sb.Draw(this.maskTex, pos, Color.Black);
            sb.End();

            sb.Begin(SpriteSortMode.Immediate, null, null, stencil2, null, a); //This is the mask filling
            sb.Draw(backTex, backTexPos, Color.White);
            sb.End();

            gdm.PreferredDepthStencilFormat = oldDepthFormat;
            sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);
        }
Example #39
0
			///<summary>Inverse of ToString(). String to DirectXDeviceFormat.</summary>
			public DirectXDeviceFormat(string directXFormat){
				if(directXFormat.IndexOf(';')<0){
					//Invalid format.
					return;
				}
				string[] settings=directXFormat.Split(new char[] {';'});
				adapter=Manager.Adapters[PIn.Int(settings[0])];
				deviceType=(DeviceType)Enum.Parse(typeof(DeviceType),settings[1]);
				createFlags=(CreateFlags)PIn.Int(settings[2]);
				depthStencilFormat=(DepthFormat)Enum.Parse(typeof(DepthFormat),settings[3]);
				backBufferFormat=(Format)Enum.Parse(typeof(Format),settings[4]);
				maxMultiSampleType=(MultiSampleType)Enum.Parse(typeof(MultiSampleType),settings[5]);
			}
        public RenderTargetGraphicsPresenter(DirectXDevice device, RenderTarget2D backBuffer,
                                             DepthFormat depthFormat = DepthFormat.None, bool disposeRenderTarget = false, bool depthAsShaderResource = false)
            : base(device, CreatePresentationParameters(backBuffer, depthFormat, depthAsShaderResource))
        {
            PresentInterval = Description.PresentationInterval;

            this.backBuffer = backBuffer;

            if (disposeRenderTarget)
            {
                ToDispose(this.backBuffer);
            }
        }
Example #41
0
		public RenderTarget3D(GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
			:base (graphicsDevice, width, height, depth, mipMap, preferredFormat, true)
		{
			DepthStencilFormat = preferredDepthFormat;
			MultiSampleCount = preferredMultiSampleCount;
			RenderTargetUsage = usage;

            // If we don't need a depth buffer then we're done.
            if (preferredDepthFormat == DepthFormat.None)
                return;

            PlatformConstruct(graphicsDevice, width, height, mipMap, preferredFormat, preferredDepthFormat, preferredMultiSampleCount, usage);
        }
        /// <summary>
        /// Creates a render target for render to textures. Use size type constructor for screen relative sizes.
        /// </summary>
        /// <param name="size">Render target size</param>
        /// <param name="_surfaceFormat">Surface format</param>
        /// <param name="_depthFormat">Depth Format</param>
        /// <param name="antialiasingType">Multi sampling type: System value or no antialiasing.</param>
        public RenderTarget(Size size, SurfaceFormat _surfaceFormat, DepthFormat _depthFormat, AntialiasingType antialiasingType = AntialiasingType.NoAntialiasing, bool mipMap = false)
        {
            Name = "Render Target";
            Size = size;

            SurfaceFormat = _surfaceFormat;
            DepthFormat = _depthFormat;
            Antialiasing = antialiasingType;
            MipMap = mipMap;

            Create();
            EngineManager.DeviceReset += OnScreenSizeChanged;
        } // RenderTarget
Example #43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PresentationParameters" /> class with default values.
 /// </summary>
 public PresentationParameters()
 {
     BackBufferWidth      = 800;
     BackBufferHeight     = 480;
     BackBufferFormat     = PixelFormat.R8G8B8A8.UNorm;
     PresentationInterval = PresentInterval.Immediate;
     DepthStencilFormat   = DepthFormat.Depth24Stencil8;
     MultiSampleCount     = MSAALevel.None;
     IsFullScreen         = false;
     RefreshRate          = new Rational(60, 1); // by default
     RenderTargetUsage    = Usage.BackBuffer | Usage.RenderTargetOutput;
     Flags = SwapChainFlags.AllowModeSwitch;
 }
Example #44
0
 /// <summary>
 /// Creates a new instance of <see cref="PresentationParameters"/>.
 /// </summary>
 /// <param name="format">The back buffer format..</param>
 /// <param name="depthFormat">The depth-stencil buffer format.</param>
 /// <param name="width">The back buffer width.</param>
 /// <param name="height">The back buffer height.</param>
 public PresentationParameters(SurfaceFormat format, DepthFormat depthFormat, int width, int height)
 {
     BackBufferFormat   = format;
     DepthStencilFormat = depthFormat;
     BackBufferWidth    = width;
     BackBufferHeight   = height;
     MultiSampleCount   = 0;
     MultiSampleQuality = 0;
     IsFullScreen       = false;
     PresentInterval    = PresentInterval.One;
     RenderTargetUsage  = RenderTargetUsage.PlatformDefault;
     DisplayOrientation = DisplayOrientation.Default;
 }
Example #45
0
        public RenderTarget2D(
            GraphicsDevice graphicsDevice,
            int width,
            int height,
            bool mipMap,
            SurfaceFormat preferredFormat,
            DepthFormat preferredDepthFormat,
            int preferredMultiSampleCount,
            RenderTargetUsage usage
            ) : base(
                graphicsDevice,
                width,
                height,
                mipMap,
                preferredFormat
                )
        {
            DepthStencilFormat = preferredDepthFormat;
            MultiSampleCount   = FNA3D.FNA3D_GetMaxMultiSampleCount(
                graphicsDevice.GLDevice,
                Format,
                MathHelper.ClosestMSAAPower(preferredMultiSampleCount)
                );
            RenderTargetUsage = usage;

            if (MultiSampleCount > 0)
            {
                glColorBuffer = FNA3D.FNA3D_GenColorRenderbuffer(
                    graphicsDevice.GLDevice,
                    Width,
                    Height,
                    Format,
                    MultiSampleCount,
                    texture
                    );
            }

            // If we don't need a depth buffer then we're done.
            if (DepthStencilFormat == DepthFormat.None)
            {
                return;
            }

            glDepthStencilBuffer = FNA3D.FNA3D_GenDepthStencilRenderbuffer(
                graphicsDevice.GLDevice,
                Width,
                Height,
                DepthStencilFormat,
                MultiSampleCount
                );
        }
 /// <summary>
 /// Initialize depth buffer format and multisampling
 /// </summary>
 /// <param name="setPreferredDepthStencilFormat">Set preferred depth
 /// stencil format</param>
 public static void InitializeDepthBufferFormatAndMultisampling(
     DepthFormat setPreferredDepthStencilFormat)
 {
     backBufferDepthFormat = setPreferredDepthStencilFormat;
     remMultiSampleType    =
         BaseGame.Device.PresentationParameters.MultiSampleType;
     if (remMultiSampleType == MultiSampleType.NonMaskable)
     {
         remMultiSampleType = MultiSampleType.None;
     }
     remMultiSampleQuality =
         BaseGame.Device.PresentationParameters.MultiSampleQuality;
     remDepthBuffer = BaseGame.Device.DepthStencilBuffer;
 }         // InitializeDepthBufferFormatAndMultisampling(setPreferredDepthStenci)
Example #47
0
        private void PlatformConstruct(GraphicsDevice graphicsDevice, int width, int height, bool mipMap,
                                       SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage, bool shared)
        {
            _frameBuffer = new FrameBuffer();
            _frameBuffer.SetColorTarget(_texture2D, 0);

            // If we don't need a depth buffer then we're done.
            if (preferredDepthFormat == DepthFormat.None)
            {
                return;
            }

            throw new NotImplementedException();
        }
Example #48
0
 public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap,
                       SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount,
                       RenderTargetUsage usage)
     : base(graphicsDevice, width, height, false, format)
 {
     if (GraphicsDevice.openGLESVersion == MonoTouch.OpenGLES.EAGLRenderingAPI.OpenGLES2)
     {
         GL20.GenFramebuffers(1, ref framebuffer);
     }
     else
     {
         allocateOpenGLTexture();
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="RenderTargetCube"/> class.
        /// </summary>
        /// <param name="graphicsDevice">The graphics device.</param>
        /// <param name="size">The width and height of a texture cube face in pixels.</param>
        /// <param name="mipMap">
        /// <see langword="true"/> to generate a full mipmap chain; otherwise <see langword="false"/>.
        /// </param>
        /// <param name="preferredFormat">The preferred format of the surface.</param>
        /// <param name="preferredDepthFormat">The preferred format of the depth-stencil buffer.</param>
        /// <param name="preferredMultiSampleCount">The preferred number of multisample locations.</param>
        /// <param name="usage">The usage mode of the render target.</param>
        public RenderTargetCube(
            int size,
            bool mipMap,
            SurfaceFormat preferredFormat,
            DepthFormat preferredDepthFormat,
            int preferredMultiSampleCount,
            RenderTargetUsage usage
            ) : base(
                size,
                mipMap,
                preferredFormat
                )
        {
            var graphicsDevice = GraphicsDeviceManager.Instance.GraphicsDevice;

            DepthStencilFormat = preferredDepthFormat;
            MultiSampleCount   = FNA3D.FNA3D_GetMaxMultiSampleCount(
                graphicsDevice.GLDevice,
                Format,
                MathHelper.ClosestMSAAPower(preferredMultiSampleCount)
                );
            RenderTargetUsage = usage;

            if (MultiSampleCount > 0)
            {
                glColorBuffer = FNA3D.FNA3D_GenColorRenderbuffer(
                    graphicsDevice.GLDevice,
                    Size,
                    Size,
                    Format,
                    MultiSampleCount,
                    texture
                    );
            }

            // If we don't need a depth buffer then we're done.
            if (DepthStencilFormat == DepthFormat.None)
            {
                return;
            }

            glDepthStencilBuffer = FNA3D.FNA3D_GenDepthStencilRenderbuffer(
                graphicsDevice.GLDevice,
                Size,
                Size,
                DepthStencilFormat,
                MultiSampleCount
                );
        }
#pragma warning restore 0067

        #endregion

        #region Public Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="RenderTargetCube"/> class.
        /// </summary>
        /// <param name="size">The width and height of a texture cube face in pixels.</param>
        /// <param name="mipMap">
        /// <see langword="true"/> to generate a full mipmap chain; otherwise <see langword="false"/>.
        /// </param>
        /// <param name="preferredFormat">The preferred format of the surface.</param>
        /// <param name="preferredDepthFormat">The preferred format of the depth-stencil buffer.</param>
        public RenderTargetCube(
            int size,
            bool mipMap,
            SurfaceFormat preferredFormat,
            DepthFormat preferredDepthFormat
            ) : this(
                size,
                mipMap,
                preferredFormat,
                preferredDepthFormat,
                0,
                RenderTargetUsage.DiscardContents
                )
        {
        }
Example #51
0
 public void SetRenderTargets(
     RenderTargetBinding[] renderTargets,
     IGLRenderbuffer renderbuffer,
     DepthFormat depthFormat
     )
 {
     ForceToMainThread(() =>
     {
         GLDevice.SetRenderTargets(
             renderTargets,
             renderbuffer,
             depthFormat
             );
     });             // End ForceToMainThread
 }
Example #52
0
 public RenderTargetRing(
     RenderCoordinator coordinator, int capacity, int width, int height,
     bool mipMap = false, SurfaceFormat preferredFormat = SurfaceFormat.Color,
     DepthFormat preferredDepthFormat = DepthFormat.None, int preferredMultiSampleCount = 1
     ) : base(
         coordinator, width, height, mipMap, preferredFormat,
         preferredDepthFormat, preferredMultiSampleCount
         )
 {
     Capacity = Math.Max(1, capacity);
     for (int i = 0; i < Capacity; i++)
     {
         AvailableTargets.Enqueue(CreateInstance());
     }
 }
Example #53
0
        public RenderTarget3D(GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
            : base(graphicsDevice, width, height, depth, mipMap, preferredFormat, true)
        {
            DepthStencilFormat = preferredDepthFormat;
            MultiSampleCount   = preferredMultiSampleCount;
            RenderTargetUsage  = usage;

            // If we don't need a depth buffer then we're done.
            if (preferredDepthFormat == DepthFormat.None)
            {
                return;
            }

            PlatformConstruct(graphicsDevice, width, height, mipMap, preferredFormat, preferredDepthFormat, preferredMultiSampleCount, usage);
        }
Example #54
0
        public RenderTargetBinding(RenderTargetCube renderTarget, CubeMapFace cubeMapFace)
        {
            if (renderTarget == null)
            {
                throw new ArgumentNullException("renderTarget");
            }
            if (cubeMapFace < CubeMapFace.PositiveX || cubeMapFace > CubeMapFace.NegativeZ)
            {
                throw new ArgumentOutOfRangeException("cubeMapFace");
            }

            _renderTarget = renderTarget;
            _arraySlice   = (int)cubeMapFace;
            _depthFormat  = renderTarget.DepthStencilFormat;
        }
Example #55
0
 /// <summary>
 /// Allows child class to specify the surface type, eg: a swap chain.
 /// </summary>
 protected RenderTarget2D(GraphicsDevice graphicsDevice,
                          int width,
                          int height,
                          bool mipMap,
                          SurfaceFormat format,
                          DepthFormat depthFormat,
                          int preferredMultiSampleCount,
                          RenderTargetUsage usage,
                          SurfaceType surfaceType)
     : base(graphicsDevice, width, height, mipMap, format, surfaceType)
 {
     DepthStencilFormat = depthFormat;
     MultiSampleCount   = preferredMultiSampleCount;
     RenderTargetUsage  = usage;
 }
Example #56
0
        public RenderTargetBinding(RenderTarget3D renderTarget, int arraySlice)
        {
            if (renderTarget == null)
            {
                throw new ArgumentNullException("renderTarget");
            }
            if (arraySlice < 0 || arraySlice >= renderTarget.Depth)
            {
                throw new ArgumentOutOfRangeException("arraySlice");
            }

            _renderTarget = renderTarget;
            _arraySlice   = arraySlice;
            _depthFormat  = renderTarget.DepthStencilFormat;
        }
Example #57
0
        public RenderTargetBinding(RenderTarget3D renderTarget, int arraySlice)
        {
            if (renderTarget == null)
            {
                throw new ArgumentNullException(nameof(renderTarget));
            }
            if (arraySlice < 0 || arraySlice >= renderTarget.Depth)
            {
                throw new ArgumentOutOfRangeException(nameof(arraySlice));
            }

            RenderTarget = renderTarget;
            ArraySlice   = arraySlice;
            DepthFormat  = renderTarget.DepthStencilFormat;
        }
Example #58
0
        /// <summary>
        /// Associates this graphics device manager to a game instances.
        /// </summary>
        /// <param name="game">The game instance to attach.</param>
        public GraphicsDeviceManager(Game game)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game", "Game cannot be null.");
            }

            _game = game;

            _supportedOrientations           = DisplayOrientation.Default;
            _preferredBackBufferFormat       = SurfaceFormat.Color;
            _preferredDepthStencilFormat     = DepthFormat.Depth24;
            _synchronizedWithVerticalRetrace = true;

            // Assume the window client size as the default back
            // buffer resolution in the landscape orientation.
            var clientBounds = _game.Window.ClientBounds;

            if (clientBounds.Width >= clientBounds.Height)
            {
                _preferredBackBufferWidth  = clientBounds.Width;
                _preferredBackBufferHeight = clientBounds.Height;
            }
            else
            {
                _preferredBackBufferWidth  = clientBounds.Height;
                _preferredBackBufferHeight = clientBounds.Width;
            }

            // Default to windowed mode... this is ignored on platforms that don't support it.
            _wantFullScreen = false;

            // XNA would read this from the manifest, but it would always default
            // to reach unless changed.  So lets mimic that without the manifest bit.
            GraphicsProfile = GraphicsProfile.Reach;

            // Let the plaform optionally overload construction defaults.
            PlatformConstruct();

            if (_game.Services.GetService(typeof(IGraphicsDeviceManager)) != null)
            {
                throw new ArgumentException("A graphics device manager is already registered.  The graphics device manager cannot be changed once it is set.");
            }
            _game.graphicsDeviceManager = this;

            _game.Services.AddService(typeof(IGraphicsDeviceManager), this);
            _game.Services.AddService(typeof(IGraphicsDeviceService), this);
        }
Example #59
0
 public void Clear()
 {
     autoDepthStencilFormat    = DepthFormat.Unknown;
     backBufferCount           = 0;
     backBufferFormat          = SurfaceFormat.Unknown;
     backBufferWidth           = 320;
     backBufferHeight          = 480;
     deviceWindowHandle        = IntPtr.Zero;
     enableAutoDepthStencil    = false;
     fullScreenRefreshRateInHz = 0;
     // isFullScreen = false;
     multiSampleQuality      = 0;
     multiSampleType         = MultiSampleType.None;
     swapEffect              = SwapEffect.Default;
     this.DisplayOrientation = DisplayOrientation.Default;
 }
        static public SharpDX.DXGI.Format ToFormat(DepthFormat format)
        {
            switch (format)
            {
            default:
            case DepthFormat.None:
                return(SharpDX.DXGI.Format.Unknown);

            case DepthFormat.Depth16:
                return(SharpDX.DXGI.Format.D16_UNorm);

            case DepthFormat.Depth24:
            case DepthFormat.Depth24Stencil8:
                return(SharpDX.DXGI.Format.D24_UNorm_S8_UInt);
            }
        }