Beispiel #1
0
        /// <summary>
        /// Creates a new texture with the specified generic texture description.
        /// </summary>
        /// <param name="graphicsDevice">The graphics device.</param>
        /// <param name="description">The description.</param>
        /// <returns>A Texture instance, either a RenderTarget or DepthStencilBuffer or Texture, depending on Binding flags.</returns>
        public static Texture New(Direct3D11.Device graphicsDevice, TextureDescription description)
        {
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("graphicsDevice");
            }

            if ((description.BindFlags & BindFlags.RenderTarget) != 0)
            {
                switch (description.Dimension)
                {
                case TextureDimension.Texture1D:
                    return(RenderTarget1D.New(graphicsDevice, description));

                case TextureDimension.Texture2D:
                    return(RenderTarget2D.New(graphicsDevice, description));

                case TextureDimension.Texture3D:
                    return(RenderTarget3D.New(graphicsDevice, description));

                case TextureDimension.TextureCube:
                    return(RenderTargetCube.New(graphicsDevice, description));
                }
            }
            else if ((description.BindFlags & BindFlags.DepthStencil) != 0)
            {
                return(DepthStencilBuffer.New(graphicsDevice, description));
            }
            else
            {
                switch (description.Dimension)
                {
                case TextureDimension.Texture1D:
                    return(Texture1D.New(graphicsDevice, description));

                case TextureDimension.Texture2D:
                    return(Texture2D.New(graphicsDevice, description));

                case TextureDimension.Texture3D:
                    return(Texture3D.New(graphicsDevice, description));

                case TextureDimension.TextureCube:
                    return(TextureCube.New(graphicsDevice, description));
                }
            }

            return(null);
        }
        void WPFHost.IScene.Attach(WPFHost.ISceneHost host)
        {
            this.host = host;
            camera = new Camera((float)host.RenderTargetWidth / host.RenderTargetHeight, (float)(75.0 * Math.PI / 180.0), 0.1f, 10000.0f);

            // device setup
            if (host.Device == null)
                throw new Exception("Scene host device is null");
            GraphicsDevice = GraphicsDevice.New(host.Device);
            RenderTarget2D backbufferRenderTarget = RenderTarget2D.New(GraphicsDevice, host.RenderTargetView, true);
            GraphicsDevice.Presenter = new RenderTargetGraphicsPresenter(GraphicsDevice, backbufferRenderTarget);
            GraphicsDevice.SetRenderTargets(backbufferRenderTarget);

            #if RAYMARCH_TERRAIN
            terrain = new TerrainRaymarcher(GraphicsDevice, (float)host.RenderTargetWidth / host.RenderTargetHeight);
            #else
            terrain = new TerrainRasterizer(GraphicsDevice);
            #endif
            terrain.HeightScale = terrainScale;

            // load shader
            sphereBillboardShader = new ShaderAutoReload("shader/spherebillboards.fx", GraphicsDevice);

            // vertex input layout
            sphereVertexInputLayout = VertexInputLayout.New(VertexBufferLayout.New(0, VertexElement.Position(SharpDX.DXGI.Format.R32G32B32_Float)));

            // generate sky
            skyShader = new ShaderAutoReload("shader/sky.fx", GraphicsDevice);
            skyShader.OnReload += ReGenerateSkyCubeMap;
            skyCubemap = RenderTargetCube.New(GraphicsDevice, CUBEMAP_RES, 0, PixelFormat.R8G8B8A8.SNorm);
            TimeOfDay = timeOfDay;

            // constant buffer to defaults
            SetupConstants();
        }