Exemple #1
0
            public void UnloadResources()
            {
                var texture = Texture;

                Texture = null;
                if (texture != null)
                {
                    texture.Dispose();
                }
            }
Exemple #2
0
 public void LoadResources(Direct3DDevice9 device)
 {
     if (device == null || Texture != null)
     {
         return;
     }
     using (var stream = m_iconDesc.GetImageStream())
     {
         Texture = D3DX9.CreateTextureFromStream(device, stream);
     }
 }
Exemple #3
0
 private void RenderSprite(
     D3DXSprite sprite,
     Direct3DTexture9 texture,
     Size srcSize,
     RectangleF dstRect,
     bool antiAlias)
 {
     sprite.Begin(D3DXSPRITEFLAG.NONE);
     try
     {
         if (!antiAlias)
         {
             Allocator.Device.SetSamplerState(0, D3DSAMPLERSTATETYPE.D3DSAMP_MINFILTER, (int)D3DTEXTUREFILTERTYPE.D3DTEXF_POINT);
             Allocator.Device.SetSamplerState(0, D3DSAMPLERSTATETYPE.D3DSAMP_MAGFILTER, (int)D3DTEXTUREFILTERTYPE.D3DTEXF_POINT);
             Allocator.Device.SetSamplerState(0, D3DSAMPLERSTATETYPE.D3DSAMP_MIPFILTER, (int)D3DTEXTUREFILTERTYPE.D3DTEXF_POINT);
         }
         D3DXHelper.Draw2D(sprite, texture, dstRect, srcSize);
     }
     finally
     {
         sprite.End();
     }
 }
Exemple #4
0
 protected override void UnloadSynchronized()
 {
     base.UnloadSynchronized();
     if (_texture0 != null)
     {
         _texture0.Dispose();
         _texture0 = null;
     }
     if (_textureMaskTv != null)
     {
         _textureMaskTv.Dispose();
         _textureMaskTv = null;
     }
     if (_sprite != null)
     {
         _sprite.Dispose();
         _sprite = null;
     }
     if (_spriteTv != null)
     {
         _spriteTv.Dispose();
         _spriteTv = null;
     }
 }
Exemple #5
0
        private void UpdateTextureSize(Size size)
        {
            if (_texture0 != null)
            {
                _texture0.Dispose();
                _texture0 = null;
            }
            if (_textureMaskTv != null)
            {
                _textureMaskTv.Dispose();
                _textureMaskTv = null;
            }

            _frameSize = size;
            var maxSize = Math.Max(size.Width, size.Height);
            var potSize = ScaleHelper.GetPotSize(maxSize);

            _texture0 = Allocator.Device.CreateTexture(
                potSize,
                potSize,
                1,
                D3DUSAGE.NONE,
                D3DFORMAT.D3DFMT_X8R8G8B8,
                D3DPOOL.D3DPOOL_MANAGED);
            _textureStride = potSize;

            var maskSizeTv = new Size(size.Width, size.Height * MimicTvRatio);
            var maxSizeTv  = Math.Max(maskSizeTv.Width, maskSizeTv.Height);
            var potSizeTv  = ScaleHelper.GetPotSize(maxSizeTv);

            _textureMaskTv = Allocator.Device.CreateTexture(
                potSizeTv,
                potSizeTv,
                1,
                D3DUSAGE.NONE,
                D3DFORMAT.D3DFMT_A8R8G8B8,
                D3DPOOL.D3DPOOL_MANAGED);
            _textureMaskTvStride = potSizeTv;
            var lockRect = _textureMaskTv.LockRectangle(0, D3DLOCK.NONE);

            try
            {
                var pixelColor = 0;
                var gapColor   = MimicTvAlpha << 24;
                unsafe
                {
                    var pdst = (int *)lockRect.pBits;
                    for (var y = 0; y < maskSizeTv.Height; y++)
                    {
                        pdst += potSizeTv;
                        var color = (y % MimicTvRatio) != (MimicTvRatio - 1) ? pixelColor : gapColor;
                        for (var x = 0; x < maskSizeTv.Width; x++)
                        {
                            pdst[x] = color;
                        }
                    }
                }
            }
            finally
            {
                _textureMaskTv.UnlockRectangle(0);
            }
        }
Exemple #6
-1
        public unsafe static void Draw2D(
            D3DXSprite sprite,
            Direct3DTexture9 texture,
            RectangleF dstRect,
            Size srcSize)
        {
            var scale = new D3DXVECTOR2(
                dstRect.Width / (float)srcSize.Width,
                dstRect.Height / (float)srcSize.Height);
            var       trans = new D3DXVECTOR2(dstRect.Location.X, dstRect.Location.Y);
            D3DMATRIX m;

            D3DMATRIX.Transformation2D(&m, null, 0f, &scale, null, 0f, &trans);
            sprite.SetTransform(ref m).CheckError();
            sprite.Draw(texture, null, null, null, 0xffffffff).CheckError();
        }