当前位置: 首页>>代码示例>>C#>>正文


C# Texture.Dispose方法代码示例

本文整理汇总了C#中Texture.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Texture.Dispose方法的具体用法?C# Texture.Dispose怎么用?C# Texture.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Texture的用法示例。


在下文中一共展示了Texture.Dispose方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateMinimap

        public void CreateMinimap(ADT.IADTFile file)
        {
            string fileName = "";
            if (!gMinimapDir.getMinimapEntry(file.Continent, (int)file.IndexX, (int)file.IndexY, ref fileName))
                return;

            Video.ShaderCollection.TerrainShader.SetValue("minimapMode", true);
            var oldCamera = Game.GameManager.GraphicsThread.GraphicsManager.Camera;
            var oldTarget = Game.GameManager.GraphicsThread.GraphicsManager.Device.GetRenderTarget(0);
            Game.GameManager.GraphicsThread.GraphicsManager.Device.SetRenderTarget(0, mRenderSurface);
            Game.GameManager.GraphicsThread.GraphicsManager.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.CornflowerBlue, 1, 0);

            var newCamera = new Video.OrthogonalCamera(1, 1, false);
            newCamera.ViewFrustum.PassAllTests = true;
            newCamera.PreventWorldUpdate = true;
            Game.GameManager.GraphicsThread.GraphicsManager.Camera = newCamera;
            Game.GameManager.GraphicsThread.GraphicsManager.Camera.SetPosition(new Vector3(Utils.Metrics.Tilesize / 2.0f, Utils.Metrics.Tilesize / 2.0f, 1000.0f), true);

            file.RenderADT(Matrix.Translation(-file.IndexX * Utils.Metrics.Tilesize + Utils.Metrics.MidPoint, -file.IndexY * Utils.Metrics.Tilesize + Utils.Metrics.MidPoint, 0));
            Game.GameManager.GraphicsThread.GraphicsManager.Device.SetRenderTarget(0, oldTarget);

            Game.GameManager.WorldManager.FogStart = 530.0f;
            Game.GameManager.GraphicsThread.GraphicsManager.Camera = oldCamera;

            Texture saveTexture = new Texture(mRenderSurface.Device, 256, 256, 1, Usage.None, Format.X8R8G8B8, Pool.Managed);
            Surface surf = saveTexture.GetSurfaceLevel(0);
            Surface.FromSurface(surf, mRenderSurface, Filter.Box, 0);
            surf.Dispose();

            Video.TextureConverter.SaveTextureAsBlp(Video.TextureConverter.BlpCompression.Dxt3, saveTexture, fileName);
            saveTexture.Dispose();
            Video.ShaderCollection.TerrainShader.SetValue("minimapMode", false);
        }
开发者ID:remixod,项目名称:sharpwow,代码行数:33,代码来源:MinimapRender.cs

示例2: Render


//.........这里部分代码省略.........
              {
                g_Player.Stop();
              }
              GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.LOST;
            }
          }
          else if (GUIGraphicsContext.Render3DMode == GUIGraphicsContext.eRender3DMode.SideBySide ||
                   GUIGraphicsContext.Render3DMode == GUIGraphicsContext.eRender3DMode.TopAndBottom)
          {
            // 3D output either SBS or TAB

            Surface backbuffer = GUIGraphicsContext.DX9Device.GetBackBuffer(0, 0, BackBufferType.Mono);

            // create texture/surface for preparation for 3D output if they don't exist

            Texture auto3DTexture = new Texture(GUIGraphicsContext.DX9Device,
                                                             backbuffer.Description.Width,
                                                             backbuffer.Description.Height, 0, Usage.RenderTarget,
                                                             backbuffer.Description.Format, Pool.Default);

            Surface auto3DSurface = auto3DTexture.GetSurfaceLevel(0);

            if (GUIGraphicsContext.Render3DMode == GUIGraphicsContext.eRender3DMode.SideBySide)
            {
              // left half (or right if switched)

              PlaneScene.RenderFor3DMode(GUIGraphicsContext.Switch3DSides ? GUIGraphicsContext.eRender3DModeHalf.SBSRight : GUIGraphicsContext.eRender3DModeHalf.SBSLeft,
                              timePassed, backbuffer, auto3DSurface,
                              new Rectangle(0, 0, backbuffer.Description.Width / 2, backbuffer.Description.Height));

              // right half (or right if switched)

              PlaneScene.RenderFor3DMode(GUIGraphicsContext.Switch3DSides ? GUIGraphicsContext.eRender3DModeHalf.SBSLeft : GUIGraphicsContext.eRender3DModeHalf.SBSRight,
                              timePassed, backbuffer, auto3DSurface,
                              new Rectangle(backbuffer.Description.Width / 2, 0, backbuffer.Description.Width / 2, backbuffer.Description.Height));
            }
            else
            {
              // upper half (or lower if switched)
              PlaneScene.RenderFor3DMode(GUIGraphicsContext.Switch3DSides ? GUIGraphicsContext.eRender3DModeHalf.TABBottom : GUIGraphicsContext.eRender3DModeHalf.TABTop, 
                              timePassed, backbuffer, auto3DSurface,
                              new Rectangle(0, 0, backbuffer.Description.Width, backbuffer.Description.Height/2));

              // lower half (or upper if switched)
              PlaneScene.RenderFor3DMode(GUIGraphicsContext.Switch3DSides ? GUIGraphicsContext.eRender3DModeHalf.TABTop : GUIGraphicsContext.eRender3DModeHalf.TABBottom, 
                              timePassed, backbuffer, auto3DSurface,
                              new Rectangle(0, backbuffer.Description.Height/2, backbuffer.Description.Width, backbuffer.Description.Height/2));
            }

            GUIGraphicsContext.DX9Device.Present();
            backbuffer.Dispose();

            auto3DSurface.Dispose();
            auto3DTexture.Dispose();
          }
        }
      }
      catch (DirectXException dex)
      {
        switch (dex.ErrorCode)
        {
          case D3DERR_INVALIDCALL:
            _errorCounter++;
            if (AdapterInfo.AdapterOrdinal > -1 && Manager.Adapters.Count > AdapterInfo.AdapterOrdinal)
            {
              double refreshRate = Manager.Adapters[AdapterInfo.AdapterOrdinal].CurrentDisplayMode.RefreshRate;
              if (refreshRate > 0 && _errorCounter > 5*refreshRate) // why 5 * refreshRate???
              {
                _errorCounter = 0; //reset counter
                Log.Info("Main: D3DERR_INVALIDCALL - {0}", dex.ToString());
                GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.LOST;
              }
            }
            break;

          case D3DERR_DEVICEHUNG:
          case D3DERR_DEVICEREMOVED:
            Log.Info("Main: GPU_HUNG - {0}", dex.ToString());
            if (!RefreshRateChanger.RefreshRateChangePending)
            {
              g_Player.Stop();
            }
            GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.LOST;
            break;

          default:
            Log.Error(dex);
            break;
        }
      }
      catch (Exception ex)
      {
        Log.Error(ex);
      }
      finally
      {
        _isRendering = false;
      }
    }
  }
开发者ID:Eddie-Jee,项目名称:MediaPortal-1,代码行数:101,代码来源:MediaPortal.cs

示例3: CreateTexture

        // Create a systemmem texture, fill with the given color and copy it to a more hardware-friendly memory pool
        public static Texture CreateTexture(int w, int h, Format format, Color4 color)
        {
            Texture texture = new Texture(Renderer.Instance.device, w, h, 1, Usage.None, format, Pool.SystemMemory);
            DataRectangle drect = texture.LockRectangle(0, LockFlags.None);
            DataStream ds = drect.Data;

            // pixelsize in bytes
            int fieldsize = 8;
            switch (format)
            {
                case Format.A8R8G8B8:
                    fieldsize = 4;
                    break;
                case Format.A16B16G16R16F:
                    fieldsize = 8;
                    break;
            }

            // Fill texture with color
            for (int j = 0; j < (w * h); j++)
            {
                int x = ((j) % (w));
                int y = ((j) / (w));

                ds.Seek((long)(y * fieldsize) + (long)(x * fieldsize), System.IO.SeekOrigin.Begin);

                switch (format)
                {
                    case Format.A8R8G8B8:
                        ds.Write<int>(color.ToArgb());
                        break;
                    case Format.A16B16G16R16F:
                        Half[] half = Half.ConvertToHalf(new float[] { color.Red, color.Green, color.Blue, color.Alpha });
                        ds.Write<Half4>(new Half4(half[0], half[1], half[2], half[3]));
                        break;
                }

            }
            texture.UnlockRectangle(0);
            Texture realtexture = new Texture(Renderer.Instance.device, w, h, 1, Usage.None, format, Pool.Default);
            Renderer.Instance.device.UpdateTexture(texture, realtexture);
            texture.Dispose();
            return realtexture;
        }
开发者ID:maesse,项目名称:CubeHags,代码行数:45,代码来源:TextureManager.cs

示例4: InternalPresentImage

    private void InternalPresentImage(int width, int height, int arWidth, int arHeight, bool isRepaint)
    {
      if (_reEntrant)
      {
        Log.Error("PlaneScene: re-entrancy in PresentImage");
        return;
      }
      if (GUIGraphicsContext.CurrentState == GUIGraphicsContext.State.LOST)
      {
        return;
      }
      try
      {
        //Direct3D.Surface backBuffer=null;
        _debugStep = 0;
        _reEntrant = true;
        if (GUIGraphicsContext.VideoRenderer != GUIGraphicsContext.VideoRendererType.madVR)
          GUIGraphicsContext.InVmr9Render = true;
        if (width > 0 && height > 0)
        {
          _vmr9Util.VideoWidth = width;
          _vmr9Util.VideoHeight = height;
          _vmr9Util.VideoAspectRatioX = arWidth;
          _vmr9Util.VideoAspectRatioY = arHeight;
          _arVideoWidth = arWidth;
          _arVideoHeight = arHeight;
        }

        //if we're stopping then just return
        float timePassed = GUIGraphicsContext.TimePassed;
        if (_stopPainting)
        {
          return;
        }
        //sanity checks
        if (GUIGraphicsContext.DX9Device == null)
        {
          return;
        }
        if (GUIGraphicsContext.DX9Device.Disposed)
        {
          return;
        }
        if (GUIWindowManager.IsSwitchingToNewWindow && !_vmr9Util.InMenu)
        {
          return; //dont present video during window transitions
        }

        _debugStep = 1;
        if (_renderTarget != null)
        {
          if (!_renderTarget.Disposed)
          {
            GUIGraphicsContext.DX9Device.SetRenderTarget(0, _renderTarget);
          }
        }

        _debugStep = 2;

        //first time, fade in the video in 12 steps
        int iMaxSteps = 12;
        if (_fadeFrameCounter < iMaxSteps)
        {
          if (_vmr9Util.InMenu)
          {
            _diffuseColor = 0xFFffffff;
          }
          else
          {
            // fade in
            int iStep = 0xff/iMaxSteps;
            if (_fadingIn)
            {
              _diffuseColor = iStep*_fadeFrameCounter;
              _diffuseColor <<= 24;
              _diffuseColor |= 0xffffff;
            }
            else
            {
              _diffuseColor = (iMaxSteps - iStep)*_fadeFrameCounter;
              _diffuseColor <<= 24;
              _diffuseColor |= 0xffffff;
            }
          }
          _fadeFrameCounter++;
        }
        else
        {
          //after 12 steps, just present the video texture
          _diffuseColor = 0xFFffffff;
        }

        _debugStep = 3;
        //get desired video window
        if (width > 0 && height > 0 && _textureAddress != 0)
        {
          Size nativeSize = new Size(width, height);
          _shouldRenderTexture = SetVideoWindow(nativeSize);
        }
        else
//.........这里部分代码省略.........
开发者ID:MediaPortal,项目名称:MediaPortal-1,代码行数:101,代码来源:PlaneScene.cs

示例5: GenerateGaussianTexture

        private void GenerateGaussianTexture()
        {
            Surface pBlobTemp = null;
            Surface pBlobNew = null;

            // Create a temporary texture
            Texture texTemp;
            texTemp = new Texture(device, GaussianTexsize, GaussianTexsize, 1, Usage.Dynamic, Format.R32F, Pool.Default);
            // Create the gaussian texture
            pTexBlob = new Texture(device, GaussianTexsize, GaussianTexsize, 1, Usage.Dynamic, blobTexFormat, Pool.Default);

            // Fill in the gaussian texture data
            GraphicsStream Rect = texTemp.LockRectangle(0, LockFlags.None);
            float dx, dy, I;

            int margin = (int)(GaussianTexsize * 0.1f);
            float size = GaussianTexsize - margin;

            //Rect.Seek(4 * margin * GaussianTexsize, System.IO.SeekOrigin.Begin);
            for (int v = 0; v < GaussianTexsize; v++)
            {
                for (int u = 0; u < GaussianTexsize; u++)
                {
                    dx = 2.0f * (float)u / (float)GaussianTexsize - 1.0f;
                    dy = 2.0f * (float)v / (float)GaussianTexsize - 1.0f;
                    I = GaussianHeight * (float)Math.Exp(-(dx * dx + dy * dy) / GaussianDeviation);

                    byte[] data = BitConverter.GetBytes(I);
                    Rect.Write(data, 0, data.Length);
                }
            }

            texTemp.UnlockRectangle(0);

            // Copy the temporary surface to the stored gaussian texture
            pBlobTemp = texTemp.GetSurfaceLevel(0);
            pBlobNew = pTexBlob.GetSurfaceLevel(0);
            SurfaceLoader.FromSurface(pBlobNew, pBlobTemp, Filter.None, 0);

            pBlobTemp.Dispose();
            pBlobNew.Dispose();
            texTemp.Dispose();
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:43,代码来源:MetaBlobsEffect.cs

示例6: GetSceneImage

        public Image GetSceneImage(Scene scene)
        {
            RecalculateData(scene);

            pp = new PresentParameters();
            pp.SwapEffect = SwapEffect.Discard;
            pp.Windowed = true;
            pp.BackBufferWidth = 512;
            pp.BackBufferHeight = 512;
            pp.BackBufferFormat = Format.A8R8G8B8;

            if(d3d != null)
            {
                d3d.Dispose();
            }
            if(device != null)
            {
                device.Dispose();
            }

            d3d = new Direct3D();
            device = new Device(d3d, 0, DeviceType.Hardware, handle, CreateFlags.HardwareVertexProcessing, pp);

            device.SetRenderState(RenderState.Lighting, true);

            for(int i = scene.lights.Count; i < maxLights; ++i)
            {
                device.EnableLight(i, false);
            }
            maxLights = scene.lights.Count;

            Modeler.Transformations.BoundingBox bb = new Modeler.Transformations.BoundingBox(scene);
            Camera cam = new Camera();
            Vector3 dir = Vector3.Normalize(bb.minBB - bb.maxBB);
            cam.position = bb.maxBB - 1 * (float)Math.Sqrt((bb.minBB.x - bb.maxBB.x) * (bb.minBB.x - bb.maxBB.x) +
                (bb.minBB.y - bb.maxBB.y) * (bb.minBB.y - bb.maxBB.y) + (bb.minBB.z - bb.maxBB.z) * (bb.minBB.z - bb.maxBB.z)) * dir;
            cam.lookAt = bb.maxBB;
            cam.fovAngle = 40;
            cam.rotateAngle = 0;

            Vector3 oldDir = defLight.Direction;

            Vector3 dirLight = new Vector3();
            dirLight.X = dir.X * (float)Math.Cos(-Math.PI / 4) + dir.Z * (float)Math.Sin(-Math.PI / 4);
            dirLight.Y = dir.Y;
            dirLight.Z = dir.Z * (float)Math.Cos(-Math.PI / 4) - dir.X * (float)Math.Sin(-Math.PI / 4);
            dir.Normalize();
            defLight.Direction = dirLight;
            device.SetLight(0, defLight);
            device.EnableLight(0, true);

            device.SetRenderState(RenderState.FillMode, FillMode.Solid);
            device.SetRenderState(RenderState.CullMode, Cull.None);
            device.SetRenderState(RenderState.ShadeMode, ShadeMode.Gouraud);

            Mesh mesh = numIndices >= 3 ? new Mesh(device, (int)numIndices / 3, scene.points.Count, MeshFlags.Managed | MeshFlags.Use32Bit, vertexElems) : null;
            VertexBuffer vb = mesh != null ? mesh.VertexBuffer : null;
            IndexBuffer ib = mesh != null ? mesh.IndexBuffer : null;

            if(mesh != null)
            {
                vb.Lock(0, 0, LockFlags.None).WriteRange(vertices);
                vb.Unlock();

                ib.Lock(0, 0, LockFlags.None).WriteRange(indices, 0, (int)numIndices);
                ib.Unlock();
            }

            Mesh selMesh = numSelIndices >= 3 ? new Mesh(device, (int)numSelIndices / 3, scene.points.Count, MeshFlags.Managed | MeshFlags.Use32Bit, vertexElems) : null;
            VertexBuffer selvb = selMesh != null ? selMesh.VertexBuffer : null;
            IndexBuffer selib = selMesh != null ? selMesh.IndexBuffer : null;

            if(selMesh != null)
            {
                selvb.Lock(0, 0, LockFlags.None).WriteRange(vertices);
                selvb.Unlock();

                selib.Lock(0, 0, LockFlags.None).WriteRange(selIndices, 0, (int)numSelIndices);
                selib.Unlock();
            }

            Viewport viewport = new Viewport(0, 0, 512, 512, 0, 1);

            Texture texture = new Texture(device, 64, 64, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
            device.SetRenderTarget(0, texture.GetSurfaceLevel(0));

            float camRotAngle = cam.rotateAngle;
            float aspect = 1;
            float camAngle = 2.0f * (float)Math.Atan(Math.Tan(Utilities.DegToRad(cam.fovAngle) / 2.0f) / aspect);

            device.SetTransform(TransformState.View, Matrix.LookAtRH(
                cam.position,
                cam.lookAt,
                Utilities.RotatePointAroundVector(new Vector3(0, 1, 0),
                Vector3.Normalize(cam.lookAt - cam.position), camRotAngle)));

            device.SetTransform(TransformState.Projection, Matrix.PerspectiveFovRH(
                camAngle,
                aspect,
                0.01f,
//.........这里部分代码省略.........
开发者ID:BGCX261,项目名称:zpi-modeler-svn-to-git,代码行数:101,代码来源:Renderer.cs

示例7: GetBezierImage

        public Image GetBezierImage(BezierSurface bezier)
        {
            pp = new PresentParameters();
            pp.SwapEffect = SwapEffect.Discard;
            pp.Windowed = true;
            pp.BackBufferWidth = 512;
            pp.BackBufferHeight = 512;
            pp.BackBufferFormat = Format.A8R8G8B8;

            if (d3dBezier != null)
            {
                d3dBezier.Dispose();
            }
            if (deviceBezier != null)
            {
                deviceBezier.Dispose();
            }

            d3dBezier = new Direct3D();
            deviceBezier = new Device(d3d, 0, DeviceType.Hardware, handle, CreateFlags.HardwareVertexProcessing, pp);

            deviceBezier.SetRenderState(RenderState.Lighting, true);

            deviceBezier.SetLight(0, defLight);
            deviceBezier.EnableLight(0, true);

            deviceBezier.SetRenderState(RenderState.FillMode, FillMode.Solid);
            deviceBezier.SetRenderState(RenderState.CullMode, Cull.None);
            deviceBezier.SetRenderState(RenderState.ShadeMode, ShadeMode.Gouraud);

            Vertex[] gridVertices = new Vertex[bezier.OutputPoints.Length];
            Vertex[] controlVertices = new Vertex[bezier.ControlPoints.Length];

            List<int>[] vertexTriangle = new List<int>[bezier.OutputPoints.Length];
            Parallel.For(0, vertexTriangle.Length, index => vertexTriangle[index] = new List<int>());
            /*for(int i = 0; i < vertexTriangle.Length; ++i)
            {
                vertexTriangle[i] = new List<int>();
            }*/

            int[] indices = new int[3 * bezier.triangles.Count];
            //int[] selIndices = new int[3 * scene.triangles.Count];
            uint numIndices = 0;
            //uint numSelIndices = 0;

            //bool[] selPoints = new bool[scene.points.Count];
            //Parallel.For(0, selPoints.Length, index => selPoints[index] = false);

            for (int i = 0; i < bezier.triangles.Count; i++)
            {
                indices[numIndices++] = (int)bezier.triangles[i].p1;
                indices[numIndices++] = (int)bezier.triangles[i].p2;
                indices[numIndices++] = (int)bezier.triangles[i].p3;

                vertexTriangle[bezier.triangles[i].p1].Add(i);
                vertexTriangle[bezier.triangles[i].p2].Add(i);
                vertexTriangle[bezier.triangles[i].p3].Add(i);
            }

            // Liczenie normalnych siatki trojkątów
            for (int i = 0; i < bezier.OutputPoints.Length; i++)
            {
                Vector3 normal = new Vector3();
                foreach (int face in vertexTriangle[i])
                {
                    normal += Utilities.CalculateNormal(bezier.OutputPoints[(int)bezier.triangles[face].p3], bezier.OutputPoints[(int)bezier.triangles[face].p2],
                            bezier.OutputPoints[(int)bezier.triangles[face].p1]);
                }
                normal.Normalize();

                gridVertices[i].Position = new Vector3(bezier.OutputPoints[i].x, bezier.OutputPoints[i].y, bezier.OutputPoints[i].z);
                gridVertices[i].Normal = normal;
                gridVertices[i].Color = Color.Beige.ToArgb();

            }

            Mesh gridMesh = numIndices > 2 ? new Mesh(deviceBezier, (int)numIndices / 3, bezier.OutputPoints.Length, MeshFlags.Managed | MeshFlags.Use32Bit,
                                                        vertexElems) : null;
            VertexBuffer vb = gridMesh != null ? gridMesh.VertexBuffer : null;
            IndexBuffer ib = gridMesh != null ? gridMesh.IndexBuffer : null;

            if (gridMesh != null)
            {
                vb.Lock(0, 0, LockFlags.None).WriteRange(gridVertices);
                vb.Unlock();

                ib.Lock(0, 0, LockFlags.None).WriteRange(indices, 0, (int)numIndices);
                ib.Unlock();
            }

            Viewport viewport = new Viewport(0, 0, 512, 512, 0, 1);

            Texture texture = new Texture(deviceBezier, 64, 64, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
            deviceBezier.SetRenderTarget(0, texture.GetSurfaceLevel(0));

            float aspect = (float)perspective.Width / perspective.Height;

            deviceBezier.SetTransform(TransformState.View, Matrix.LookAtRH(
                bezierCam.position,
                bezierCam.lookAt,
//.........这里部分代码省略.........
开发者ID:BGCX261,项目名称:zpi-modeler-svn-to-git,代码行数:101,代码来源:Renderer.cs

示例8: Load

        public override void Load(string a_sFilename)
        {
            if (m_tx!=null)
                m_tx.Dispose();

            Bitmap bmp = m_mb.LoadIntoBitmap(a_sFilename);
            ImageInformation m_info;
            System.IO.Stream stream = null;

            if (m_mb.GotAnimation || m_mb.FileFullName.ToLower().IndexOf(".tif") > 0)
            {
                //it's probably an animated GIF. The loader above has already created a tileset of the animation frames
                //The following method is kind of silly...
                //writing the bitmap into a memory stream for the TextureLoader to read from,
                //because loading directly from a bitmap doesn't provide enough options.
                //Hopefully changed in a later version.

                //TODO: something goes wrong with alpha in GIFs - a lot of alpha where there should be none...
                stream = new System.IO.MemoryStream();
                ImageCodecInfo codec = Endogine.BitmapHelpers.BitmapHelper.GetEncoderInfo("PNG");
                bmp.Save(stream, codec, null);
                bmp.Dispose();
                stream.Position = 0;
            }
            else
            {
                bmp.Dispose();
                stream = new System.IO.FileStream(m_mb.FileFullName, System.IO.FileMode.Open);
            }

            m_info = TextureLoader.ImageInformationFromStream(stream);
            stream.Position = 0;

            int nMipLevels = 1;
            //format = EH.Instance.Stage.D3DDevice.PresentationParameters.BackBufferFormat;
            Format format = Format.A8R8G8B8; //TODO: should check render device format
            //TODO: should allow user to NOT create alpha for all textures

            int nColorKey = 0; //this.m_mb.ColorKey.ToArgb();
            //Tests:
            //nColorKey = (unchecked((int)0xff000000));
            //nColorKey = (unchecked((int)0xffffffff));

            m_tx = TextureLoader.FromStream(
                m_endogine.Stage.D3DDevice, stream, m_info.Width, m_info.Height,
                nMipLevels, Usage.None, format, Pool.Managed,
                Filter.Linear, Filter.Point, nColorKey, ref m_info);
            stream.Position = 0;

            //TODO: Check pixel for alpha should be an option (enum with LeftTop, RightTop etc)
            bool bAlreadyGotAlpha = TextureFormatGotAlpha(m_info.Format);
            this.m_mb.GotAlpha = bAlreadyGotAlpha;

            bool bCheckPixelForAlpha = true;
            if (!bAlreadyGotAlpha && bCheckPixelForAlpha)
            {
                int nPitch=0;
                int nLevelToLock = 0;
                Microsoft.DirectX.GraphicsStream gs = m_tx.LockRectangle(
                    nLevelToLock,
                    new Rectangle(0,0,m_info.Width,m_info.Height),
                    LockFlags.None, out nPitch);
                //TODO: this depends on texture format:
                byte[] buf = new byte[4];
                int nNumRead = gs.Read(buf, 0, 4);
                Color clr = Color.FromArgb((int)buf[3],(int)buf[0],(int)buf[1],(int)buf[2]);
                //If there already is a transparent pixel here, then the colorKey was right to begin with
                //I.e., only need to reload if Alpha != 0
                if (clr.A != 0)
                {
                    nColorKey = clr.ToArgb();
                    //TODO: manually process pixels and add alpha
                    //I don't know what data formats to expect, though. E.g. can it be Yuv?
                    //					for (int x = 0; x < m_info.Width; x++)
                    //					{
                    //						for (int y = 0; y < m_info.Height; y++)
                    //						{
                    //							gs.Read(buf, 0, 3);
                    //						}
                    //					}
                    m_tx.UnlockRectangle(nLevelToLock);

                    m_tx.Dispose();

                    m_tx = TextureLoader.FromStream(
                        m_endogine.Stage.D3DDevice, stream, m_info.Width, m_info.Height,
                        nMipLevels, Usage.None, format, Pool.Managed,
                        Filter.Linear, Filter.Point, nColorKey, ref m_info);
                }
            }
            stream.Close();
        }
开发者ID:timdetering,项目名称:Endogine,代码行数:92,代码来源:MemberSpriteBitmapRender3DStrategy.cs

示例9: LoadSurfaceFromVolumeSlice

        public static void LoadSurfaceFromVolumeSlice( VolumeTexture volumeTex, int mip, int slice, Filter filter, Surface surface)
        {
            VolumeDescription vd = volumeTex.GetLevelDescription(mip);
            OpsFormatHelper formatHelp = OpsFormatHelper.FindByFormat( vd.Format );

            Texture sliceTex = new Texture(volumeTex.Device, vd.Width, vd.Height, 1, Usage.None, formatHelp.Format, Pool.SystemMemory);

            Box box = new Box();
            box.Left = 0;
            box.Right = vd.Width;
            box.Top = 0;
            box.Bottom = vd.Height;
            box.Front = slice;
            box.Back = slice + 1;
            
            LockedBox volumeLB;
            GraphicsStream volumeData = volumeTex.LockBox(0, box, LockFlags.ReadOnly, out volumeLB);

            int slicePitch;
            GraphicsStream sliceData = sliceTex.LockRectangle(mip, LockFlags.None, out slicePitch);

            CopyTextureData(volumeData, vd.Width, vd.Height, formatHelp, volumeLB.RowPitch, sliceData, slicePitch);

            sliceTex.UnlockRectangle(0);
            volumeTex.UnlockBox(mip);

            SurfaceLoader.FromSurface(surface, sliceTex.GetSurfaceLevel(0), filter, 0);

            sliceTex.Dispose();
         }
开发者ID:steadyfield,项目名称:SourceEngine2007,代码行数:30,代码来源:TextureHelper.cs

示例10: GenerateVolumeTexture

        public static VolumeTexture GenerateVolumeTexture(string path, string name, Device device, int width, int height, int depth, int levels,
                                                 NoisePresetValues settings, Usage usage, Pool pool)
        {
            PerlinModuleWrapper noiseModule = new PerlinModuleWrapper();

            // apply any presets
            if (settings != null)
            {
                if (settings.Seed != -1)
                    noiseModule.Seed = settings.Seed;
                if (!double.IsNaN(settings.Frequency))
                    noiseModule.Frequency = settings.Frequency;
                if (!double.IsNaN(settings.Lacunarity))
                    noiseModule.Lacunarity = settings.Lacunarity;
                if (!double.IsNaN(settings.OctaveCount))
                    noiseModule.OctaveCount = settings.OctaveCount;
                if (!double.IsNaN(settings.Persistence))
                    noiseModule.Persistence = settings.Persistence;
                if (settings.Quality != (PerlinModuleWrapper.NoiseQuality)(int)-1)
                    noiseModule.Quality = settings.Quality;
            }

            // generate slices
            // vol needs to be 32-bit stride
            //VolumeTexture volumeTex = new VolumeTexture(device, 2, 2, 2, 1, usage, Format.A8B8G8R8, pool);
            
            float sliceStep = 0;
            if (levels > 1)
                sliceStep = (float)depth / (levels - 1);

            float z = depth;
            for (int level = 0; level < levels; level++)
            {
                // sample texels for slice
                //Volume vol = volumeTex.GetVolumeLevel(level);
                Texture tex = new Texture(device, width, height, 1, Usage.None, Format.X8R8G8B8, Pool.Managed);
                //GraphicsStream lvlStream = vol.LockBox(LockFlags.None);
                GraphicsStream lvlStream = tex.LockRectangle(0, LockFlags.None);
                for (float x = 0; x < width; x++)
                {
                    for (float y = 0; y < height; y++)
                    {
                        // sample texel value
                        double value = noiseModule.GetPerlinNoiseValue(x / 3f, y / 3f, z / 3f);
                        // convert to colour data
                        // just write in direct range of -1 -> 1 as 32-bit float
                        //float valueF = (float)value;
                        //lvlStream.Write(valueF);
                        value++;
                        if (value < 0)
                            value = 0;
                        if (value > 2)
                            value = 2;
                        byte R = (byte)(value * 127f);
                        lvlStream.Write((byte)255);
                        lvlStream.Write(R);
                        lvlStream.Write(R);
                        lvlStream.Write(R);
                    }
                }
                tex.UnlockRectangle(0);
                TextureLoader.Save(path + name + level.ToString() + ".dds", ImageFileFormat.Dds, tex);
                tex.Dispose();
                //vol.UnlockBox();
                z += sliceStep;
            }

            return null;// volumeTex;
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:69,代码来源:PerlinGenerator.cs


注:本文中的Texture.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。