コード例 #1
0
ファイル: Program.cs プロジェクト: polytronicgr/larx
        protected override void OnLoad(EventArgs e)
        {
            multisampling = new Multisampling(4);

            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            GL.ClearColor(State.ClearColor);

            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);

            GL.CullFace(CullFaceMode.Back);
            GL.MinSampleShading(1.0f);

            Map.New(2048);
            debug   = new ObjectRenderer();
            camera  = new Camera();
            terrain = new TerrainRenderer(camera);
            water   = new WaterRenderer();
            light   = new Light();
            assets  = new AssetRenderer();
            ui      = new Ui();
            sky     = new SkyRenderer();
            shadows = new ShadowBox();
        }
コード例 #2
0
        public SwapChainPresenter CreateSwapChainPresenter(Format backBufferFormat   = Format.R8G8B8A8_UNORM_SRGB,
                                                           Format depthStencilFormat = Format.D24_UNORM_S8_UINT,
                                                           Multisampling msaa        = default(Multisampling))
        {
            var p = new SwapChainPresenter(new WindowContext
            {
                BackBufferWidth    = (int)Width,
                BackBufferHeight   = (int)Height,
                BackBufferFormat   = backBufferFormat,
                DepthStencilFormat = depthStencilFormat,
                Sampling           = msaa,
                WindowHandle       = Handle
            });

            _presenter = p;
            return(p);
        }
コード例 #3
0
        public SwapChainPresenter(IGraphicContext context)
        {
            if (_msaa.Count == 0)
            {
                _msaa.Count = 1;
            }

            _displaySize             = new Size(context.BackBufferWidth, context.BackBufferHeight);
            this._backBufferFormat   = context.BackBufferFormat;
            this._depthStencilFormat = context.DepthStencilFormat;
            this._msaa = context.Sampling;

            _viewport  = new ViewPort(0, 0, _displaySize.Width, _displaySize.Height);
            _swapChain = GraphicDeviceFactory.Device.CreateSwapChain(context);

            _depthBuffer = GraphicDeviceFactory.Device.CreateDepthStencil(
                context.BackBufferWidth,
                context.BackBufferHeight,
                _depthStencilFormat,
                _msaa);
        }
コード例 #4
0
 public static extern void SurfaceSetMultisampling(ObjectHandle surface, Multisampling quality);
コード例 #5
0
ファイル: RenderTarget.cs プロジェクト: still-scene/Operators
        private void Update(EvaluationContext context)
        {
            var resourceManager = ResourceManager.Instance();
            var device          = resourceManager.Device;

            Size2 size = Resolution.GetValue(context);

            if (size.Width == 0 || size.Height == 0)
            {
                size = context.RequestedResolution;
            }

            if (size.Width <= 0 || size.Height <= 0 || size.Width > MaximumTexture2DSize || size.Height > MaximumTexture2DSize)
            {
                Log.Warning("Invalid texture size: " + size);
                return;
            }

            _sampleCount = Multisampling.GetValue(context).Clamp(1, 32);

            bool generateMips    = GenerateMips.GetValue(context);
            var  withDepthBuffer = WithDepthBuffer.GetValue(context);

            UpdateTextures(device, size, TextureFormat.GetValue(context), withDepthBuffer ? Format.R32_Typeless : Format.Unknown, generateMips);

            var deviceContext = device.ImmediateContext;

            // Save settings in context
            var prevRequestedResolution = context.RequestedResolution;
            var prevViewports           = deviceContext.Rasterizer.GetViewports <RawViewportF>();
            var prevTargets             = deviceContext.OutputMerger.GetRenderTargets(2, out var prevDepthStencilView);
            var prevObjectToWorld       = context.ObjectToWorld;
            var prevWorldToCamera       = context.WorldToCamera;
            var prevCameraToClipSpace   = context.CameraToClipSpace;

            deviceContext.Rasterizer.SetViewport(new SharpDX.Viewport(0, 0, size.Width, size.Height, 0.0f, 1.0f));
            deviceContext.OutputMerger.SetTargets(_multiSampledDepthBufferDsv, _multiSampledColorBufferRtv);

            // Clear
            var clear = Clear.GetValue(context);
            var c     = ClearColor.GetValue(context);

            if (clear || !_wasClearedOnce)
            {
                try
                {
                    deviceContext.ClearRenderTargetView(_multiSampledColorBufferRtv, new Color(c.X, c.Y, c.Z, c.W));
                    if (_multiSampledDepthBufferDsv != null)
                    {
                        deviceContext.ClearDepthStencilView(_multiSampledDepthBufferDsv, DepthStencilClearFlags.Depth, 1.0f, 0);
                    }

                    _wasClearedOnce = true;
                }
                catch
                {
                    Log.Error($"{Parent.Symbol.Name}: Error clearing actual render target.", SymbolChildId);
                }
            }



            // Set default values for new sub tree
            context.RequestedResolution = size;
            context.SetDefaultCamera();

            if (TextureReference.IsConnected)
            {
                var reference = TextureReference.GetValue(context);
                reference.ColorTexture = ColorTexture;
                reference.DepthTexture = DepthTexture;
            }

            // Render
            Command.GetValue(context);

            // Restore context
            context.ObjectToWorld       = prevObjectToWorld;
            context.WorldToCamera       = prevWorldToCamera;
            context.CameraToClipSpace   = prevCameraToClipSpace;
            context.RequestedResolution = prevRequestedResolution;
            deviceContext.Rasterizer.SetViewports(prevViewports);
            deviceContext.OutputMerger.SetTargets(prevDepthStencilView, prevTargets);


            if (_sampleCount > 1)
            {
                try
                {
                    device.ImmediateContext.ResolveSubresource(_multiSampledColorBuffer,
                                                               0,
                                                               _resolvedColorBuffer, 0,
                                                               _resolvedColorBuffer.Description.Format);

                    if (withDepthBuffer)
                    {
                        ResolveDepthBuffer();
                    }
                }
                catch (Exception e)
                {
                    Log.Error("resolving render target buffer failed:" + e.Message);
                }
            }

            if (generateMips)
            {
                deviceContext.GenerateMips(DownSamplingRequired ? _resolvedColorBufferSrv : _multiSampledColorBufferSrv);
            }

            // Clean up ref counts for RTVs
            for (int i = 0; i < prevTargets.Length; i++)
            {
                prevTargets[i]?.Dispose();
            }

            prevDepthStencilView?.Dispose();

            ColorBuffer.Value = ColorTexture;
            ColorBuffer.DirtyFlag.Clear();
            DepthBuffer.Value = DepthTexture;
            DepthBuffer.DirtyFlag.Clear();
        }
コード例 #6
0
 public static Import.Multisampling GetUnmanagedMultisampling(this Multisampling multisampling)
 => (Import.Multisampling)multisampling;
コード例 #7
0
        public RenderTextureCube(int edgeSize, Format targetFormat, Format depthFormat, Multisampling sampling = default(Multisampling))
        {
            if (sampling.Count == 0)
            {
                sampling.Count = 1;
            }
            var device = GraphicDeviceFactory.Device;

            _texture = device.CreateTexture2D(new Texture2DDesc
            {
                ArraySize      = 6,
                Height         = edgeSize,
                Width          = edgeSize,
                Format         = targetFormat,
                SamplerDesc    = sampling,
                BindFlags      = BindFlags.RenderTarget | BindFlags.ShaderResource,
                Usage          = ResourceUsage.Default,
                MipLevels      = 1,
                CPUAccessFlags = CpuAccessFlags.None,
                Options        = ResourceOptionFlags.TextureCube
            });

            for (int i = 0; i < 6; i++)
            {
                int index = Graphics.Texture.CalcSubresource(0, i, 1);
                _targets[i] = device.CreateRenderTarget(_texture, index);
            }

            if (depthFormat != Format.UNKNOWN)
            {
                _depthStencil = device.CreateDepthStencil(
                    new DepthStencilDesc
                {
                    Width     = edgeSize,
                    Height    = edgeSize,
                    Format    = depthFormat,
                    Sampling  = sampling,
                    Dimension = DepthStencilDimension.TEXTURECUBE
                });
            }
        }
コード例 #8
0
        public RenderTexture2D(int width, int height, Format targetFormat, Format depthFormat = Format.UNKNOWN, Multisampling sampling = default(Multisampling), bool readable = false)
        {
            if (sampling.Count == 0)
            {
                sampling.Count = 1;
            }
            var device = GraphicDeviceFactory.Device;

            _texture = device.CreateTexture2D(new Texture2DDesc {
                Width          = width,
                Height         = height,
                Format         = targetFormat,
                SamplerDesc    = sampling,
                BindFlags      = BindFlags.RenderTarget | BindFlags.ShaderResource,
                ArraySize      = 1,
                MipLevels      = 1,
                Options        = ResourceOptionFlags.None,
                Usage          = ResourceUsage.Default,
                CPUAccessFlags = readable? CpuAccessFlags.Read: CpuAccessFlags.None
            });

            _target = device.CreateRenderTarget(_texture);

            if (depthFormat != Format.UNKNOWN)
            {
                _depthStencil = device.CreateDepthStencil(new DepthStencilDesc(width, height, depthFormat, sampling, false));
            }
        }