예제 #1
0
 internal static ShaderBytecode Compile(string filePath, string entryPoint, string profile)
 {
     Shader shader = new Shader(filePath);
     return shader.ByteCode;
 }
예제 #2
0
 /// <summary>
 /// Releases all unmanaged resources that are held by this object and deletes all references to other objects.
 /// </summary>
 public override void Dispose()
 {
     if (!IsDisposed)
     {
         base.Dispose();
         ByteCode = null;
         SwapShader = null;
         Window = null;
     }
 }
예제 #3
0
        /// <summary>
        /// Compiles GPU shader programs and stores them in the appropriate static library.
        /// <para> </para>
        /// This function imports and compiles HLSL source code located within the "Shaders" directory found in the compiled <para/>
        /// program folder. Unfortunately, however, shader compilation depends on having a fully initialized rendering engine, <para/>
        /// which precludes being able to automate initialization within the static class here. This method is therefore called <para/>
        /// automatically during construction of the rendering window. Consequently, it should never be called manually.
        /// </summary>
        /// <param name="window">A reference to the Direct3D-capable window containing an active rendering engine.</param>
        internal static void Initialize(Window3D window)
        {
            Window = window;
            Window.OnClose += Dispose;

            string appPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string shaderPath = Path.Combine(appPath, "Shaders");

            string[] csFiles = Directory.GetFiles(shaderPath, "*.cx", SearchOption.AllDirectories);
            string[] dsFiles = Directory.GetFiles(shaderPath, "*.ds", SearchOption.AllDirectories);
            string[] gsFiles = Directory.GetFiles(shaderPath, "*.gs", SearchOption.AllDirectories);
            string[] hsFiles = Directory.GetFiles(shaderPath, "*.hs", SearchOption.AllDirectories);
            string[] psFiles = Directory.GetFiles(shaderPath, "*.ps", SearchOption.AllDirectories);
            string[] vsFiles = Directory.GetFiles(shaderPath, "*.vs", SearchOption.AllDirectories);

            Shader cs, ds, gs, hs, ps, vs;
            foreach (var csFile in csFiles)
            {
                cs = new Shader(Window, csFile);
                Compute.Add(cs.Name, cs);
            }
            foreach (var dsFile in dsFiles)
            {
                ds = new Shader(Window, dsFile);
                Domain.Add(ds.Name, ds);
            }
            foreach (var gsFile in gsFiles)
            {
                gs = new Shader(Window, gsFile);
                Geometry.Add(gs.Name, gs);
            }
            foreach (var hsFile in hsFiles)
            {
                hs = new Shader(Window, hsFile);
                Hull.Add(hs.Name, hs);
            }
            foreach (var psFile in psFiles)
            {
                ps = new Shader(Window, psFile);
                Pixel.Add(ps.Name, ps);
            }
            foreach (var vsFile in vsFiles)
            {
                vs = new Shader(Window, vsFile);
                Vertex.Add(vs.Name, vs);
            }
        }
예제 #4
0
        /// <summary>
        /// Deactivates the shader program in the GPU rendering pipeline, replacing it with whatever shader program was active before.
        /// </summary>
        public void Deactivate()
        {
            switch (Type)
            {
                case ShaderTypes.ComputeShader:
                    Window.ComputeShader = SwapShader;
                    SwapShader = null;
                    return;

                case ShaderTypes.DomainShader:
                    Window.DomainShader = SwapShader;
                    SwapShader = null;
                    return;

                case ShaderTypes.GeometryShader:
                    Window.GeometryShader = SwapShader;
                    SwapShader = null;
                    return;

                case ShaderTypes.HullShader:
                    Window.HullShader = SwapShader;
                    SwapShader = null;
                    return;

                case ShaderTypes.PixelShader:
                    Window.PixelShader = SwapShader;
                    SwapShader = null;
                    return;

                case ShaderTypes.VertexShader:
                    Window.VertexShader = SwapShader;
                    SwapShader = null;
                    return;

                default:
                    throw new Exception("This branch cannot be reached.");
            }
        }