Пример #1
0
 // Build a shader for all supported feature levels and save its
 // bytecode to the shader library.
 private static void saveToLibrary(PlanetShaderKey k)
 {
     var planetShader = new PlanetShader11(k);
     foreach (var level in ShaderLibrary.ShaderLevels)
     {
         planetShader.BuildShader(level.vertexProfile, level.pixelProfile);
     }
 }
Пример #2
0
        /// <summary>
        /// Get the planet shader for the specified shader key. The shader is created
        /// if it's not already in the shader library.
        /// </summary>
        /// <param name="device">Direct3D device</param>
        /// <param name="key">Planet surface shader key</param>
        /// <returns>A Direct3D shader to produce the requested effect.</returns>
        public static PlanetShader11 GetPlanetShader(Device device, PlanetShaderKey key)
        {
            PlanetShader11 shader;

            if (shaderLibrary == null || regenerateShaders)
            {
                shaderLibraryComparer = new PlanetShaderKeyComparer();
                shaderLibrary = new Dictionary<PlanetShaderKey, PlanetShader11>(shaderLibraryComparer);
                regenerateShaders = false;
            }

            // Retrieve the shader from the library of compiled shaders;
            // if the shader isn't in the shader library, create it and
            // add it.
            if (!shaderLibrary.TryGetValue(key, out shader))
            {
                if (shader == null)
                {
                    // Shader was not retrieved from the cache of precompiled shaders
                    shader = new PlanetShader11(key);
                    shader.BuildShader(RenderContext11.VertexProfile, RenderContext11.PixelProfile);
                    shader.Realize(device);

                    shaderLibrary[key] = shader;
                }
            }
            return shader;
        }