예제 #1
0
 public void Dispose()
 {
     if (BatchDisposing != null)
     {
         BatchDisposing(this, new EventArgs());
     }
     if (TextureD3D10 != null && !TextureD3D10.Disposed)
     {
         TextureD3D10.Dispose();
     }
     if (TextureD3D11 != null && !TextureD3D11.Disposed)
     {
         TextureD3D11.Dispose();
     }
     if (MutexD3D10 != null && !MutexD3D10.Disposed)
     {
         MutexD3D10.Dispose();
     }
     if (MutexD3D11 != null && !MutexD3D11.Disposed)
     {
         MutexD3D11.Dispose();
     }
     if (DWRenderTarget != null && !DWRenderTarget.Disposed)
     {
         DWRenderTarget.Dispose();
     }
     if (VertexBuffer != null && !VertexBuffer.Disposed)
     {
         VertexBuffer.Dispose();
     }
     if (VertexInputLayout != null && !VertexInputLayout.Disposed)
     {
         VertexInputLayout.Dispose();
     }
     if (SpriteEffect != null && !SpriteEffect.Disposed)
     {
         SpriteEffect.Dispose();
     }
     if (sampler != null && !sampler.Disposed)
     {
         sampler.Dispose();
     }
     //以下の二つはRenderContextがDisposeされるときに呼ばれないとバグが出る。(画面真っ黒)
     //これは同じ種類のブレンドステートがDisposeされてしまうからだと予測できる。
     //このため、Dispose予定リストに含めておき、RenderContextの破棄時に処理をする
     context.Disposables.Add(TransParentBlendState);
     context.Disposables.Add(state);
 }
예제 #2
0
        public void Resize()
        {
            Viewport vp     = DeviceManager.Context.Rasterizer.GetViewports()[0];
            int      width  = (int)vp.Width;
            int      height = (int)vp.Height;

            if (height == 0 || width == 0)
            {
                return;
            }
            TextureSize = new Vector2(width, height);
            float       w = width / 2f, h = height / 2f;
            List <byte> vertexBytes = new List <byte>();

            CGHelper.AddListBuffer(new Vector3(-w, h, 0), vertexBytes);
            CGHelper.AddListBuffer(new Vector2(0, 0), vertexBytes);
            CGHelper.AddListBuffer(new Vector3(w, h, 0), vertexBytes);
            CGHelper.AddListBuffer(new Vector2(1, 0), vertexBytes);
            CGHelper.AddListBuffer(new Vector3(-w, -h, 0), vertexBytes);
            CGHelper.AddListBuffer(new Vector2(0, 1), vertexBytes);
            CGHelper.AddListBuffer(new Vector3(w, h, 0), vertexBytes);
            CGHelper.AddListBuffer(new Vector2(1, 0), vertexBytes);
            CGHelper.AddListBuffer(new Vector3(w, -h, 0), vertexBytes);
            CGHelper.AddListBuffer(new Vector2(1, 1), vertexBytes);
            CGHelper.AddListBuffer(new Vector3(-w, -h, 0), vertexBytes);
            CGHelper.AddListBuffer(new Vector2(0, 1), vertexBytes);
            using (DataStream ds = new DataStream(vertexBytes.ToArray(), true, true))
            {
                BufferDescription bufDesc = new BufferDescription()
                {
                    BindFlags   = BindFlags.VertexBuffer,
                    SizeInBytes = (int)ds.Length
                };
                if (VertexBuffer != null && !VertexBuffer.Disposed)
                {
                    VertexBuffer.Dispose();
                }
                VertexBuffer = new SlimDX.Direct3D11.Buffer(DeviceManager.Device, ds, bufDesc);
            }
            SpriteProjectionMatrix = Matrix.OrthoLH(width, height, 0, 100);
            spriteViewport         = new Viewport()
            {
                Width  = width,
                Height = height,
                MaxZ   = 1
            };


            ViewMatrix = Matrix.LookAtLH(new Vector3(0, 0, -1), new Vector3(0, 0, 0), new Vector3(0, 1, 0));

            //DirectX11用テクスチャの作成
            if (TextureD3D11 != null && !TextureD3D11.Disposed)
            {
                TextureD3D11.Dispose();
            }
            TextureD3D11 = new Texture2D(DeviceManager.Device, new Texture2DDescription()
            {
                Width             = width,
                Height            = height,
                MipLevels         = 1,
                ArraySize         = 1,
                Format            = Format.B8G8R8A8_UNorm,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
                BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags    = CpuAccessFlags.None,
                OptionFlags       = ResourceOptionFlags.KeyedMutex
            });
            //DX11のテクスチャリソースをDX10とシェアする
            Resource sharedResource = new Resource(TextureD3D11);

            if (TextureD3D10 != null && !TextureD3D10.Disposed)
            {
                TextureD3D10.Dispose();
            }
            TextureD3D10 = DeviceManager.Device10.OpenSharedResource <SlimDX.Direct3D10.Texture2D>(sharedResource.SharedHandle);
            if (MutexD3D10 != null && !MutexD3D10.Disposed)
            {
                MutexD3D10.Dispose();
            }
            if (MutexD3D11 != null && !MutexD3D11.Disposed)
            {
                MutexD3D11.Dispose();
            }
            MutexD3D10 = new KeyedMutex(TextureD3D10);
            MutexD3D11 = new KeyedMutex(TextureD3D11);
            sharedResource.Dispose();
            Surface surface            = TextureD3D10.AsSurface();
            RenderTargetProperties rtp = new RenderTargetProperties();

            rtp.MinimumFeatureLevel = FeatureLevel.Direct3D10;
            rtp.Type        = RenderTargetType.Hardware;
            rtp.Usage       = RenderTargetUsage.None;
            rtp.PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied);
            if (DWRenderTarget != null && !DWRenderTarget.Disposed)
            {
                DWRenderTarget.Dispose();
            }
            DWRenderTarget = RenderTarget.FromDXGI(context.D2DFactory, surface, rtp);
            surface.Dispose();

            if (RenderTargetRecreated != null)
            {
                RenderTargetRecreated(this, new EventArgs());
            }
        }