internal RenderManager(Engine engine)
        {
            this.engine = engine;

            cameraManager = engine.CameraManager;

            sceneBuffer            = engine.Device.CreateBuffer <SceneBuffer>(BufferTypeEnum.ConstVertex, 1);
            objectBuffer           = engine.Device.CreateBuffer <ObjectBuffer>(BufferTypeEnum.ConstVertex, 1);
            pixelShaderSceneBuffer = engine.Device.CreateBuffer <PixelShaderSceneBuffer>(BufferTypeEnum.ConstPixel, 1);
            instancesBuffer        = engine.Device.CreateBuffer <Matrix>(BufferTypeEnum.Vertex, 1);

            instancesArray = new Matrix[1];

            renderers = new Dictionary <ShaderHandle, Dictionary <Material, Dictionary <Mesh, List <Transform> > > >();

            sceneData = new SceneBuffer();

            defaultSampler = engine.Device.CreateSampler();

            depthStencilZWrite   = engine.Device.CreateDepthStencilState(true);
            depthStencilNoZWrite = engine.Device.CreateDepthStencilState(false);

            renderTexture = engine.Device.CreateRenderTexture((int)engine.WindowHost.WindowWidth, (int)engine.WindowHost.WindowHeight);

            outlineTexture = engine.Device.CreateRenderTexture((int)engine.WindowHost.WindowWidth, (int)engine.WindowHost.WindowHeight);

            planeMesh = engine.MeshManager.CreateMesh(new ScreenPlane());

            blitShader   = engine.ShaderManager.LoadShader("../internalShaders/blit.shader");
            blitMaterial = engine.MaterialManager.CreateMaterial(blitShader);

            unlitMaterial = engine.MaterialManager.CreateMaterial(engine.ShaderManager.LoadShader("../internalShaders/unlit.shader"));
        }
Beispiel #2
0
        /// <summary>
        /// Function to clear the current target and its depth/stencil buffer.
        /// </summary>
        /// <param name="color">Color to clear with.</param>
        /// <param name="depth">Depth value to clear with.</param>
        /// <param name="stencil">Stencil value to clear with.</param>
        /// <remarks>Unlike a render target <see cref="GorgonLibrary.Graphics.GorgonRenderTargetView.Clear">Clear</see> method, this will respect any clipping and/or viewport.
        /// However, this only affects the color buffer, the depth/stencil will be cleared in their entirety.</remarks>
        public void Clear(GorgonColor color, float depth, byte stencil)
        {
            if ((_clip == null) && (_viewPort == null))
            {
                if (DepthStencil != null)
                {
                    DepthStencil.ClearDepth(depth);
                    DepthStencil.ClearStencil(stencil);
                }

                Target.Clear(color);

                return;
            }

            if (DepthStencil != null)
            {
                DepthStencil.ClearDepth(depth);
                DepthStencil.ClearStencil(stencil);
            }

            var currentBlend = Drawing.BlendingMode;

            Drawing.BlendingMode = BlendingMode.None;
            Drawing.FilledRectangle(new RectangleF(0, 0, _currentTarget.Width, _currentTarget.Height), color);
            Drawing.BlendingMode = currentBlend;
        }
        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));
            }
        }
Beispiel #4
0
 private void ClientResize(object sender, EventArgs args)
 {
     RenderTarget.Dispose();
     DepthStencil.Dispose();
     System.Drawing.Size size = Client.ClientSize;
     SwapChain.ResizeBuffers(1, size.Width, size.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None);
     initRenderTarget();
     initDepthStencil();
 }
Beispiel #5
0
 virtual public void Dispose()
 {
     UnloadContent();
     RenderTarget.Dispose();
     DepthStencil.Dispose();
     SwapChain.Dispose();
     if (Client != null && !Client.IsDisposed)
     {
         GetParentForm(Client).ResizeEnd -= ClientResize;
     }
     GraphicsDevice = null;
     Client         = null;
 }
        public override void Resize(Size size)
        {
            _viewport = new ViewPort(0, 0, size.Width, size.Height);

            _swapChain.ResizeBackBuffer(size.Width, size.Height);

            if (_depthBuffer != null)
            {
                _depthBuffer.Dispose();
            }

            _depthBuffer = GraphicDeviceFactory.Device.CreateDepthStencil(size.Width, size.Height, _depthStencilFormat, _msaa);

            OnSizeChanged(size);
        }
        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
                });
            }
        }
Beispiel #8
0
        public void Dispose()
        {
            if (isOwner)
            {
                if (RenderTargets != null)
                {
                    foreach (var renderTarget in RenderTargets)
                    {
                        if (renderTarget != null)
                        {
                            renderTarget.Dispose();
                        }
                    }
                }

                if (Descriptor.DepthFormat != RenderFrameDepthFormat.Shared && DepthStencil != null)
                {
                    DepthStencil.Dispose();
                }
            }
        }
        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);
        }
Beispiel #10
0
        public unsafe void ClearDepthStencil(DepthStencil target, float depth, int stencil)
        {
            context.Bindings.Framebuffers.Draw.Set(this);

            switch (target)
            {
            case DepthStencil.Both:
                GL.ClearBuffer((int)All.DepthStencil, 0, depth, stencil);
                return;

            case DepthStencil.Depth:
                GL.ClearBuffer((int)All.Depth, 0, &depth);
                return;

            case DepthStencil.Stencil:
                GL.ClearBuffer((int)All.Stencil, 0, &stencil);
                return;

            default:
                throw new ArgumentException("'target' must be either 'Both', 'Depth', or 'Stencil'");
            }
        }
Beispiel #11
0
        public void Dispose()
        {
            if (FullScreenQuad != null && !FullScreenQuad.Disposed)
            {
                FullScreenQuad.Dispose();
            }

            if (Effect != null && !Effect.Disposed)
            {
                Effect.Dispose();
            }

            if (AlarmTexture != null && !AlarmTexture.D3dTexture.Disposed)
            {
                AlarmTexture.dispose();
            }

            if (RenderTarget2D != null && !RenderTarget2D.Disposed)
            {
                RenderTarget2D.Dispose();
            }

            if (DepthStencil != null && !DepthStencil.Disposed)
            {
                DepthStencil.Dispose();
            }

            if (OldDepthStencil != null && !OldDepthStencil.Disposed)
            {
                OldDepthStencil.Dispose();
            }

            if (OldRenderTarget != null && !OldRenderTarget.Disposed)
            {
                OldRenderTarget.Dispose();
            }
        }
 protected override void OMSetRenderTargetsImp(int numTargets, RenderTarget[] renderTargets, DepthStencil dephtStencil)
 {
     throw new NotImplementedException();
 }
 protected override void OMSetRenderTargetImpl(RenderTarget renderTarget, DepthStencil dephtStencil)
 {
     throw new NotImplementedException();
 }
Beispiel #14
0
        public unsafe void ClearDepthStencil(DepthStencil target, float depth, int stencil)
        {
            context.Bindings.Framebuffers.Draw.Set(this);

            switch (target)
            {
                case DepthStencil.Both:
                    GL.ClearBuffer((int)All.DepthStencil, 0, depth, stencil);
                    return;
                case DepthStencil.Depth:
                    GL.ClearBuffer((int)All.Depth, 0, &depth);
                    return;
                case DepthStencil.Stencil:
                    GL.ClearBuffer((int)All.Stencil, 0, &stencil);
                    return;
                default:
                    throw new ArgumentException("'target' must be either 'Both', 'Depth', or 'Stencil'");
            }
        }
Beispiel #15
0
 public void ClearWindowDepthStencil(DepthStencil target, float depth, int stencil)
 {
     context.Bindings.Framebuffers.Draw.Set(null);
     context.GL.ClearBuffer((int)target, 0, depth, stencil);
 }