SHARE
TWEET

Untitled

a guest Oct 23rd, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using DiscSim;
  2. using SlimDX;
  3. using SlimDX.Direct3D10;
  4. using SlimDX.DXGI;
  5. using System.Windows.Forms;
  6. using System.Drawing;
  7. using Device = SlimDX.Direct3D10.Device;
  8. using Vector2 = SlimDX.Vector2;
  9. using Resource = SlimDX.Direct3D10.Resource;
  10.  
  11. namespace DiscSimSlimDX
  12. {
  13.     class Camera_DX10 : Camera
  14.     {
  15.         private RenderTargetView renderTarget;
  16.         private Device device;
  17.         private SwapChain swapChain;
  18.         private Sprite sprite;
  19.         private SpriteInstance[] spriteInstances;
  20.  
  21.         public Camera_DX10(ISimulation simulation, Form form, string spritePath)
  22.             : base(simulation, form, spritePath)
  23.         {
  24.             var swapChainDescription = new SwapChainDescription()
  25.             {
  26.                 BufferCount = 1,
  27.                 ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
  28.                 IsWindowed = true,
  29.                 OutputHandle = form.Handle,
  30.                 SampleDescription = new SampleDescription(1, 0),
  31.                 Flags = SwapChainFlags.AllowModeSwitch,
  32.                 SwapEffect = SwapEffect.Discard,
  33.                 Usage = Usage.RenderTargetOutput
  34.             };
  35.  
  36.             Device.CreateWithSwapChain(null,
  37.                 DriverType.Hardware,
  38.                 DeviceCreationFlags.Debug,
  39.                 swapChainDescription,
  40.                 out device,
  41.                 out swapChain);
  42.  
  43.             using (var backBuffer = Resource.FromSwapChain<Texture2D>(swapChain, 0))
  44.             {
  45.                 renderTarget = new RenderTargetView(device, backBuffer);
  46.                 RenderTargetViewDescription r = renderTarget.Description;
  47.             }
  48.  
  49.             device.OutputMerger.SetTargets(renderTarget);
  50.             device.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0, 1));
  51.  
  52.             device.OutputMerger.BlendState = BlendState.FromDescription(device,
  53.                 new BlendStateDescription()
  54.                 {
  55.                     IsAlphaToCoverageEnabled = true,
  56.                 });
  57.  
  58.             sprite = new Sprite(device, 512 * 512); // How big should the buffer size be?
  59.             sprite.ProjectionTransform = Matrix.Identity; // ?
  60.             sprite.ViewTransform = Matrix.Identity; // ?
  61.  
  62.             ShaderResourceView texView = ShaderResourceView.FromFile(device, "Resources/World.png");
  63.             var spriteInstance = new SpriteInstance(texView, Vector2.Zero, new Vector2(1, 1));
  64.             spriteInstance.Transform = Matrix.Identity; // ?
  65.  
  66.             spriteInstances = new SpriteInstance[1] { spriteInstance };
  67.  
  68.             form.ResizeEnd += (s, e) =>
  69.             {
  70.                 // How do I resize the backbuffer or what do I need to do
  71.                 // to adjust for the new window size?
  72.  
  73.             };
  74.         }
  75.  
  76.         public override void Draw()
  77.         {
  78.             device.ClearRenderTargetView(renderTarget, Color.Black);
  79.             sprite.Begin(SpriteFlags.None);
  80.             sprite.DrawBuffered(spriteInstances);
  81.             sprite.End();
  82.             swapChain.Present(0, PresentFlags.None);
  83.         }
  84.     }
  85. }
RAW Paste Data
Top