예제 #1
0
 protected override void UnloadImpl()
 {
     if (vertexShader != null)
     {
         vertexShader.Dispose();
         vertexShader = null;
     }
 }
예제 #2
0
 protected override void LoadFromMicrocode(GraphicsStream microcode)
 {
     // create the new vertex shader
     try
     {
         vertexShader = new VertexShader(device, microcode);
     }
     catch (Exception)
     {
         LogManager.Instance.Write("Error loading microcode for vertex program: {0}", Name);
     }
 }
예제 #3
0
        private void InitDirect3D()
        {
            Direct3D.PresentParameters presentParams;
            presentParams = new Direct3D.PresentParameters();

            presentParams.Windowed               = windowed;
            presentParams.EnableAutoDepthStencil = true;
            presentParams.AutoDepthStencilFormat = Direct3D.DepthFormat.D16;

            if(windowed)
            {
                presentParams.SwapEffect = Direct3D.SwapEffect.Copy;
            }
            else
            {
                presentParams.SwapEffect       = Direct3D.SwapEffect.Flip;
                presentParams.BackBufferFormat = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Format;
                presentParams.BackBufferWidth  = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Width;
                presentParams.BackBufferHeight = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Height;
                presentParams.FullScreenRefreshRateInHz = Direct3D.PresentParameters.DefaultPresentRate;
                presentParams.PresentationInterval      = Direct3D.PresentInterval.One;
            }

            Direct3D.DeviceType deviceType = Direct3D.DeviceType.Hardware;

            // If the hardware doesn't support shaders, emulate them with the reference rasterizer
            Direct3D.Caps caps = Direct3D.Manager.GetDeviceCaps(0, Direct3D.DeviceType.Hardware);
            if(caps.VertexShaderVersion < new System.Version(1, 1) || caps.PixelShaderVersion < new System.Version(1, 1))
            {
                string msg = "The hardware does not support the required shader version (VS " + caps.VertexShaderVersion.ToString() + " PS " + caps.PixelShaderVersion.ToString() + "). Switching to the Reference Rasterizer.";
                System.Windows.Forms.MessageBox.Show(null,
                                                     msg,
                                                     "Shaders unsupported");
                deviceType = Direct3D.DeviceType.Reference;
            }

            device = new Direct3D.Device(0,
                                         deviceType,
                                         this,
                                         Direct3D.CreateFlags.SoftwareVertexProcessing,
                                         presentParams);

            device.DeviceReset += new System.EventHandler(this.OnDeviceReset);

            Direct3D.ShaderFlags shaderFlags = Direct3D.ShaderFlags.None;
            #if (DEBUG)
            shaderFlags |= Direct3D.ShaderFlags.Debug;
            #endif

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            System.IO.Stream stream;

            Direct3D.GraphicsStream gs;
            stream = assembly.GetManifestResourceStream("_6_ShaderAsm.VertexShader.vsh");
            gs = Direct3D.ShaderLoader.FromStream(stream, null, shaderFlags);
            vertexShader = new Direct3D.VertexShader(device, gs);
            gs.Close();
            stream.Close();

            stream = assembly.GetManifestResourceStream("_6_ShaderAsm.PixelShader.psh");
            gs = Direct3D.ShaderLoader.FromStream(stream, null, shaderFlags);
            pixelShader = new Direct3D.PixelShader(device, gs);
            gs.Close();
            stream.Close();

            Direct3D.VertexElement[] decl = new Direct3D.VertexElement[] { new Direct3D.VertexElement(0,  0, Direct3D.DeclarationType.Float3, Direct3D.DeclarationMethod.Default, Direct3D.DeclarationUsage.Position, 0),
                                                                           new Direct3D.VertexElement(0, 12, Direct3D.DeclarationType.Color,  Direct3D.DeclarationMethod.Default, Direct3D.DeclarationUsage.Color, 0),
                                                                           new Direct3D.VertexElement(0, 16, Direct3D.DeclarationType.Float2, Direct3D.DeclarationMethod.Default, Direct3D.DeclarationUsage.TextureCoordinate, 0),
                                                                           Direct3D.VertexElement.VertexDeclarationEnd };
            device.VertexDeclaration = new Direct3D.VertexDeclaration(device, decl);

            OnDeviceReset(device, null);
        }
 protected override void UnloadImpl()
 {
     if (vertexShader != null) {
         vertexShader.Dispose();
         vertexShader = null;
     }
 }
 protected override void LoadFromMicrocode(GraphicsStream microcode)
 {
     // create the new vertex shader
     try
     {
         vertexShader = new VertexShader(device, microcode);
     }
     catch (Exception)
     {
         LogManager.Instance.Write("Error loading microcode for vertex program: {0}", Name);
     }
 }