Пример #1
0
        public void DestroyD3DResources()
        {
            // FIXME: Ogre doesn't do this Dispose call here (just sets to null).
            if (renderSurface != null)
            {
                renderSurface.Dispose();
                renderSurface = null;
            }
            // renderSurface = null;

            if (isSwapChain)
            {
                if (renderZBuffer != null)
                {
                    renderZBuffer.Dispose();
                    renderZBuffer = null;
                }
                if (swapChain != null)
                {
                    swapChain.Dispose();
                    swapChain = null;
                }
            }
            else
            {
                // FIXME: Ogre doesn't do this Dispose call here (just sets to null).
                if (renderZBuffer != null)
                {
                    renderZBuffer.Dispose();
                    renderZBuffer = null;
                }
                // renderZBuffer = null;
            }
        }
Пример #2
0
        private void CreateFullScreenDisplay()
        {
            DetachEvents();

            if (frm is frmFullScreen == false)
            {
                if (mBackBuffer != null)
                {
                    mBackBuffer.Dispose();
                }
                if (mSwap != null)
                {
                    mSwap.Dispose();
                }

                frm.Dispose();

                CreateWindow(true);
            }

            frm.Activate();
            frm.Refresh();

            CreateBackBuffer();

            frm.ClientSize = new System.Drawing.Size(mChooseWidth, mChooseHeight);

            System.Threading.Thread.Sleep(500);


            frm.Activate();

            AttachEvents();
            mIsFullscreen = true;
            Core.IsActive = true;
        }
Пример #3
0
        ///<summary>
        ///    @copydoc HardwarePixelBuffer.BlitToMemory
        ///</summary>
        public override void BlitToMemory(BasicBox srcBox, PixelBox dst)
        {
            // Decide on pixel format of temp surface
            PixelFormat tmpFormat = format;

            if (D3DHelper.ConvertEnum(dst.Format) == D3D.Format.Unknown)
            {
                tmpFormat = dst.Format;
            }
            if (surface != null)
            {
                Debug.Assert(srcBox.Depth == 1 && dst.Depth == 1);
                // Create temp texture
                D3D.Texture tmp =
                    new D3D.Texture(device, dst.Width, dst.Height,
                                    1, // 1 mip level ie topmost, generate no mipmaps
                                    0, D3DHelper.ConvertEnum(tmpFormat),
                                    Pool.Scratch);
                D3D.Surface subSurface = tmp.GetSurfaceLevel(0);
                // Copy texture to this temp surface
                Rectangle destRect, srcRect;
                srcRect  = ToD3DRectangle(srcBox);
                destRect = ToD3DRectangleExtent(dst);

                SurfaceLoader.FromSurface(subSurface, destRect, surface, srcRect, Filter.None, 0);

                // Lock temp surface and copy it to memory
                int            pitch; // Filled in by D3D
                GraphicsStream data = subSurface.LockRectangle(D3D.LockFlags.ReadOnly, out pitch);
                // Copy it
                PixelBox locked = new PixelBox(dst.Width, dst.Height, dst.Depth, tmpFormat);
                FromD3DLock(locked, pitch, data);
                PixelUtil.BulkPixelConversion(locked, dst);
                subSurface.UnlockRectangle();
                // Release temporary surface and texture
                subSurface.Dispose();
                tmp.Dispose();
            }
            else
            {
                // Create temp texture
                D3D.VolumeTexture tmp =
                    new D3D.VolumeTexture(device, dst.Width, dst.Height, dst.Depth,
                                          0, D3D.Usage.None,
                                          D3DHelper.ConvertEnum(tmpFormat),
                                          Pool.Scratch);
                D3D.Volume subVolume = tmp.GetVolumeLevel(0);
                // Volume
                D3D.Box ddestBox = ToD3DBoxExtent(dst);
                D3D.Box dsrcBox  = ToD3DBox(srcBox);

                VolumeLoader.FromVolume(subVolume, ddestBox, volume, dsrcBox, Filter.None, 0);
                // Lock temp surface and copy it to memory
                D3D.LockedBox  lbox;                // Filled in by D3D
                GraphicsStream data = subVolume.LockBox(LockFlags.ReadOnly, out lbox);
                // Copy it
                PixelBox locked = new PixelBox(dst.Width, dst.Height, dst.Depth, tmpFormat);
                FromD3DLock(locked, lbox, data);
                PixelUtil.BulkPixelConversion(locked, dst);
                subVolume.UnlockBox();
                // Release temporary surface and texture
                subVolume.Dispose();
                tmp.Dispose();
            }
        }
        public void Load(bool forceDynamic)
        {
            if (available && (!loaded || forceDynamic))
            {
                if (forceDynamic && textureName.Equals("zero.png"))
                {
                    textureName = string.Format("{0}_x{1}y{2}.{3}", parent.BaseName, m_tileLocationX, m_loadTileZ,
                                                parent.MosaicDesc.FileExt);
                }

                // Attempt to load the texture.  If the texture
                // is already loaded, then this will just return the
                // already loaded texture, so no extra work will be done.

                Texture texture = TextureManager.Instance.GetByName(textureName);
                if (texture != null)
                {
                    if (forceDynamic)
                    {
                        if (texture.Usage == DYNAMIC_TEXTURE_USAGE)
                        {
                            loaded = true;
                            return;
                        }
                    }
                    texture.Unload();
                    texture = null;
                }

                if (dynamicSurface != null)
                {
                    dynamicSurface.Dispose();
                    dynamicSurface = null;
                }

                if (!forceDynamic)
                {
                    try
                    {
                        texture = TextureManager.Instance.Load(textureName);
                    } // ReSharper disable EmptyGeneralCatchClause
                    catch // ReSharper restore EmptyGeneralCatchClause
                    {
                        // Ignore
                    }
                }

                // If we failed to load the texture, manually create it
                if (texture == null)
                {
                    texture = TextureManager.Instance.CreateManual(textureName, TextureType.TwoD, parent.MosaicDesc.TileSizeSamples,
                                                                   parent.MosaicDesc.TileSizeSamples, 0, DEFAULT_IMAGE_FORMAT, DYNAMIC_TEXTURE_USAGE);
                    texture.Load();
                    if (texture is D3DTexture)
                    {
                        D3D.Texture t = (texture as D3DTexture).DXTexture as D3D.Texture;
                        if (t != null)
                        {
                            dynamicSurface = t.Device.CreateOffscreenPlainSurface(texture.Width, texture.Height,
                                                                                  D3DHelper.ConvertEnum(texture.Format), D3D.Pool.Default);
                        }
                    }
                }

                loaded = true;
            }
        }