/// <summary>
        /// Are resources loaded for the given device?
        /// </summary>
        /// <param name="device">The device for which to check.</param>
        public override bool IsLoaded(EngineDevice device)
        {
            if (!m_localResources.HasObjectAt(device.DeviceIndex))
            {
                return(false);
            }

            SkyboxLocalResources geoResource = m_localResources[device.DeviceIndex];

            if (geoResource.CubeTexture == null)
            {
                return(false);
            }
            if (geoResource.CubeTexture.Key != m_cubeTextureKey)
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Renders this object.
        /// </summary>
        /// <param name="renderState">Render this object.</param>
        private void Render(RenderState renderState)
        {
            renderState.ClearChachedAppliedMaterial();

            D3D11.DeviceContext  deviceContext  = renderState.Device.DeviceImmediateContextD3D11;
            SkyboxLocalResources localResources = m_localResources[renderState.DeviceIndex];

            // Apply constants and shader resources
            deviceContext.VertexShader.Set(localResources.VertexShader.VertexShader);
            deviceContext.PixelShader.Set(localResources.PixelShader.PixelShader);
            deviceContext.PixelShader.SetShaderResource(0, localResources.CubeTexture.TextureView);

            // Bind index and vertex buffer
            deviceContext.InputAssembler.SetIndexBuffer(localResources.IndexBuffer, DXGI.Format.R32_UInt, 0);
            deviceContext.InputAssembler.SetVertexBuffers(0, new D3D11.VertexBufferBinding(
                                                              localResources.VertexBuffer,
                                                              StandardVertex.Size, 0));

            // Draw the skybox
            deviceContext.DrawIndexed(6 * 6, 0, 0);
        }
Beispiel #3
0
        /// <summary>
        /// Loads all resources of the object.
        /// </summary>
        /// <param name="device">Current graphics device.</param>
        /// <param name="resourceDictionary">Current resource dictionary.</param>
        public override void LoadResources(EngineDevice device, ResourceDictionary resourceDictionary)
        {
            // Define all vertices
            StandardVertex[] CreateVertices()
            {
                return(new[] {
                    // Front side
                    new StandardVertex(new Vector3(-1f, +1f, -1f), new Vector2(0f, 0f)),
                    new StandardVertex(new Vector3(-1f, -1f, -1f), new Vector2(0f, 1f)),
                    new StandardVertex(new Vector3(+1f, -1f, -1f), new Vector2(1f, 1f)),
                    new StandardVertex(new Vector3(+1f, +1f, -1f), new Vector2(1f, 0f)),

                    // Right side
                    new StandardVertex(new Vector3(+1f, +1f, -1f), new Vector2(0f, 0f)),
                    new StandardVertex(new Vector3(+1f, -1f, -1f), new Vector2(0f, 1f)),
                    new StandardVertex(new Vector3(+1f, -1f, +1f), new Vector2(1f, 1f)),
                    new StandardVertex(new Vector3(+1f, +1f, +1f), new Vector2(1f, 0f)),

                    // Back side
                    new StandardVertex(new Vector3(+1f, +1f, +1f), new Vector2(0f, 0f)),
                    new StandardVertex(new Vector3(+1f, -1f, +1f), new Vector2(0f, 1f)),
                    new StandardVertex(new Vector3(-1f, -1f, +1f), new Vector2(1f, 1f)),
                    new StandardVertex(new Vector3(-1f, +1f, +1f), new Vector2(1f, 0f)),

                    // Left side
                    new StandardVertex(new Vector3(-1f, +1f, +1f), new Vector2(0f, 0f)),
                    new StandardVertex(new Vector3(-1f, -1f, +1f), new Vector2(0f, 1f)),
                    new StandardVertex(new Vector3(-1f, -1f, -1f), new Vector2(1f, 1f)),
                    new StandardVertex(new Vector3(-1f, +1f, -1f), new Vector2(1f, 0f)),

                    // Top side
                    new StandardVertex(new Vector3(-1f, +1f, +1f), new Vector2(0f, 0f)),
                    new StandardVertex(new Vector3(-1f, +1f, -1f), new Vector2(0f, 1f)),
                    new StandardVertex(new Vector3(+1f, +1f, -1f), new Vector2(1f, 1f)),
                    new StandardVertex(new Vector3(+1f, +1f, +1f), new Vector2(1f, 0f)),

                    // Down side
                    new StandardVertex(new Vector3(+1f, -1f, -1f), new Vector2(0f, 0f)),
                    new StandardVertex(new Vector3(-1f, -1f, -1f), new Vector2(1f, 0f)),
                    new StandardVertex(new Vector3(-1f, -1f, +1f), new Vector2(1f, 1f)),
                    new StandardVertex(new Vector3(+1f, -1f, +1f), new Vector2(0f, 1f))
                });
            }

            // Define all indices
            int[] CreateIndices()
            {
                return(new[]
                {
                    0, 1, 2, 2, 3, 0,       // Font side
                    4, 5, 6, 6, 7, 4,       // Right side
                    8, 9, 10, 10, 11, 8,    // Back side
                    12, 13, 14, 14, 15, 12, // Left side
                    16, 17, 18, 18, 19, 16, // Top side
                    20, 21, 22, 22, 23, 20  // Down side
                });
            }

            // Create and fill resource container object
            var localResources = new SkyboxLocalResources
            {
                CubeTexture  = resourceDictionary.GetResourceAndEnsureLoaded <TextureResource>(this.CubeTextureKey),
                VertexBuffer = resourceDictionary.GetResourceAndEnsureLoaded(
                    ResourceKeys.RES_SKYBOX_VERTICES,
                    () => new ImmutableVertexBufferResource <StandardVertex>(CreateVertices)),
                IndexBuffer = resourceDictionary.GetResourceAndEnsureLoaded(
                    ResourceKeys.RES_SKYBOX_INDICES,
                    () => new ImmutableIndexBufferResource(CreateIndices)),
                VertexShader = resourceDictionary.GetResourceAndEnsureLoaded(
                    ResourceKeys.RES_SKYBOX_VERTEX_SHADER,
                    () => GraphicsHelper.Internals.GetVertexShaderResource(device, "SkyBox", "CommonVertexShader")),
                PixelShader = resourceDictionary.GetResourceAndEnsureLoaded(
                    ResourceKeys.RES_SKYBOX_PIXEL_SHADER,
                    () => GraphicsHelper.Internals.GetPixelShaderResource(device, "SkyBox", "CommonPixelShader"))
            };

            // Store resource container object
            _localResources.AddObject(localResources, device.DeviceIndex);
        }
        /// <summary>
        /// Loads all resources of the object.
        /// </summary>
        /// <param name="device">Current graphics device.</param>
        /// <param name="resourceDictionary">Current resource dicionary.</param>
        public override void LoadResources(EngineDevice device, ResourceDictionary resourceDictionary)
        {
            // Define all vertices
            StandardVertex[] vertices = new StandardVertex[]
            {
                // Front side
                new StandardVertex(new Vector3(-1f, +1f, -1f), new Vector2(0f, 0f)),
                new StandardVertex(new Vector3(-1f, -1f, -1f), new Vector2(0f, 1f)),
                new StandardVertex(new Vector3(+1f, -1f, -1f), new Vector2(1f, 1f)),
                new StandardVertex(new Vector3(+1f, +1f, -1f), new Vector2(1f, 0f)),

                // Right side
                new StandardVertex(new Vector3(+1f, +1f, -1f), new Vector2(0f, 0f)),
                new StandardVertex(new Vector3(+1f, -1f, -1f), new Vector2(0f, 1f)),
                new StandardVertex(new Vector3(+1f, -1f, +1f), new Vector2(1f, 1f)),
                new StandardVertex(new Vector3(+1f, +1f, +1f), new Vector2(1f, 0f)),

                // Back side
                new StandardVertex(new Vector3(+1f, +1f, +1f), new Vector2(0f, 0f)),
                new StandardVertex(new Vector3(+1f, -1f, +1f), new Vector2(0f, 1f)),
                new StandardVertex(new Vector3(-1f, -1f, +1f), new Vector2(1f, 1f)),
                new StandardVertex(new Vector3(-1f, +1f, +1f), new Vector2(1f, 0f)),

                // Left side
                new StandardVertex(new Vector3(-1f, +1f, +1f), new Vector2(0f, 0f)),
                new StandardVertex(new Vector3(-1f, -1f, +1f), new Vector2(0f, 1f)),
                new StandardVertex(new Vector3(-1f, -1f, -1f), new Vector2(1f, 1f)),
                new StandardVertex(new Vector3(-1f, +1f, -1f), new Vector2(1f, 0f)),

                // Top side
                new StandardVertex(new Vector3(-1f, +1f, +1f), new Vector2(0f, 0f)),
                new StandardVertex(new Vector3(-1f, +1f, -1f), new Vector2(0f, 1f)),
                new StandardVertex(new Vector3(+1f, +1f, -1f), new Vector2(1f, 1f)),
                new StandardVertex(new Vector3(+1f, +1f, +1f), new Vector2(1f, 0f)),

                // Down side
                new StandardVertex(new Vector3(+1f, -1f, -1f), new Vector2(0f, 0f)),
                new StandardVertex(new Vector3(-1f, -1f, -1f), new Vector2(1f, 0f)),
                new StandardVertex(new Vector3(-1f, -1f, +1f), new Vector2(1f, 1f)),
                new StandardVertex(new Vector3(+1f, -1f, +1f), new Vector2(0f, 1f)),
            };

            // Define all indices
            int[] indices = new int[]
            {
                0, 1, 2, 2, 3, 0,        // Font side
                4, 5, 6, 6, 7, 4,        // Right side
                8, 9, 10, 10, 11, 8,     // Back side
                12, 13, 14, 14, 15, 12,  // Left side
                16, 17, 18, 18, 19, 16,  // Top side
                20, 21, 22, 22, 23, 20   // Down side
            };

            // Create and fill resource container object
            SkyboxLocalResources localResources = new SkyboxLocalResources();

            localResources.DefaultResources = resourceDictionary.DefaultResources;
            localResources.CubeTexture      = resourceDictionary.GetResourceAndEnsureLoaded <TextureResource>(m_cubeTextureKey);
            localResources.VertexBuffer     = GraphicsHelper.CreateImmutableVertexBuffer(device, vertices);
            localResources.IndexBuffer      = GraphicsHelper.CreateImmutableIndexBuffer(device, indices);
            localResources.VertexShader     = resourceDictionary.GetResourceAndEnsureLoaded(
                ResourceKeys.RES_VERTEX_SHADER_SKYBOX,
                () => GraphicsHelper.GetVertexShaderResource(device, "Skybox", "CommonVertexShader"));
            localResources.PixelShader = resourceDictionary.GetResourceAndEnsureLoaded(
                ResourceKeys.RES_PIXEL_SHADER_SKYBOX,
                () => GraphicsHelper.GetPixelShaderResource(device, "Skybox", "CommonPixelShader"));

            // Store resource container object
            m_localResources.AddObject(localResources, device.DeviceIndex);
        }