Exemplo n.º 1
1
        protected void Blit(D3D9.Device d3d9Device, HardwarePixelBuffer rsrc, BasicBox srcBox, BasicBox dstBox,
                            BufferResources srcBufferResources, BufferResources dstBufferResources)
        {
            if (dstBufferResources.Surface != null && srcBufferResources.Surface != null)
            {
                // Surface-to-surface
                var dsrcRect  = ToD3DRectangle(srcBox);
                var ddestRect = ToD3DRectangle(dstBox);

                var srcDesc = srcBufferResources.Surface.Description;

                // If we're blitting from a RTT, try GetRenderTargetData
                // if we're going to try to use GetRenderTargetData, need to use system mem pool

                // romeoxbm: not used even in Ogre
                //var tryGetRenderTargetData = false;

                if ((srcDesc.Usage & D3D9.Usage.RenderTarget) != 0 && srcDesc.MultiSampleType == D3D9.MultisampleType.None)
                {
                    // Temp texture
                    var tmptex = new D3D9.Texture(d3d9Device, srcDesc.Width, srcDesc.Height, 1,
                                                  // 1 mip level ie topmost, generate no mipmaps
                                                  0, srcDesc.Format, D3D9.Pool.SystemMemory);

                    var tmpsurface = tmptex.GetSurfaceLevel(0);

                    d3d9Device.GetRenderTargetData(srcBufferResources.Surface, tmpsurface);
                    D3D9.Surface.FromSurface(dstBufferResources.Surface, tmpsurface, D3D9.Filter.Default, 0, dsrcRect,
                                             ddestRect);
                    tmpsurface.SafeDispose();
                    tmptex.SafeDispose();
                    return;
                }

                // Otherwise, try the normal method
                D3D9.Surface.FromSurface(dstBufferResources.Surface, srcBufferResources.Surface, D3D9.Filter.Default, 0,
                                         dsrcRect, ddestRect);
            }
            else if (dstBufferResources.Volume != null && srcBufferResources.Volume != null)
            {
                // Volume-to-volume
                var dsrcBox  = ToD3DBox(srcBox);
                var ddestBox = ToD3DBox(dstBox);

                D3D9.Volume.FromVolume(dstBufferResources.Volume, srcBufferResources.Volume, D3D9.Filter.Default, 0,
                                       dsrcBox, ddestBox);
            }
            else
            {
                // Software fallback
                base.Blit(rsrc, srcBox, dstBox);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="c"></param>
        /// <param name="texId"></param>
        /// <param name="nx"></param>
        /// <param name="ny"></param>
        /// <param name="nz"></param>
        private unsafe void UpdateVolTextureData(Cell[,,] c, VolTextureId texId, int nx, int ny, int nz)
        {
            HardwarePixelBuffer buffer = _volTextures[(int)texId].GetBuffer(0, 0);

            buffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
            PixelBox pb = buffer.CurrentLock;
            uint     x = 0; uint y = 0; uint z = 0;

            unsafe
            {
                byte *pbptr = (byte *)pb.data;


                for (z = pb.box.front; z < pb.box.back; z++)
                {
                    for (y = pb.box.top; y < pb.box.bottom; y++)
                    {
                        for (x = pb.box.left; x < pb.box.right; x++)
                        {
                            PixelConverter.PackColour(0, 0, (uint)c[x, y, z].Dens, (uint)c[x, y, z].Light, PixelFormat.PF_BYTE_RGB, &pbptr[x]);
                        }
                        pbptr += pb.rowPitch;
                    }
                    pbptr += pb.SliceSkip;
                }
            }
            buffer.Unlock();
        }
Exemplo n.º 3
0
        ///<summary>
        ///    @copydoc HardwarePixelBuffer.Blit
        ///</summary>
        public override void Blit(HardwarePixelBuffer _src, BasicBox srcBox, BasicBox dstBox)
        {
            D3DHardwarePixelBuffer src = (D3DHardwarePixelBuffer)_src;

            if (surface != null && src.surface != null)
            {
                // Surface-to-surface
                Rectangle dsrcRect  = ToD3DRectangle(srcBox);
                Rectangle ddestRect = ToD3DRectangle(dstBox);
                // D3DXLoadSurfaceFromSurface
                SurfaceLoader.FromSurface(surface, ddestRect, src.surface, dsrcRect, Filter.None, 0);
            }
            else if (volume != null && src.volume != null)
            {
                // Volume-to-volume
                Box dsrcBox  = ToD3DBox(srcBox);
                Box ddestBox = ToD3DBox(dstBox);
                // D3DXLoadVolumeFromVolume
                VolumeLoader.FromVolume(volume, ddestBox, src.volume, dsrcBox, Filter.None, 0);
            }
            else
            {
                // Software fallback
                base.Blit(_src, srcBox, dstBox);
            }
        }
Exemplo n.º 4
0
 void UpdateTexture()
 {
     lock ( renderBufferLock )
     {
         if (renderBuffer != null && renderBufferForSize == ViewSize && renderBuffer.Length == ViewSize.X * ViewSize.Y * 4)
         {
             try
             {
                 HardwarePixelBuffer pixelBuffer = texture.GetBuffer();
                 pixelBuffer.Lock(HardwareBuffer.LockOptions.Discard);
                 PixelBox pixelBox = pixelBuffer.GetCurrentLock();
                 unsafe
                 {
                     fixed(byte *ptr = renderBuffer)
                     pixelBox.WriteDataUnmanaged((IntPtr)ptr, ViewSize.X, ViewSize.Y);
                 }
                 pixelBuffer.Unlock();
             }
             catch (Exception ex)
             {
                 Log.Error("WebBrowserControl: Caught exception in UpdateTexture(): " + ex.Message);
             }
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Bitmaps to texture.
        /// </summary>
        /// <param name="bmp">The BMP.</param>
        /// <param name="texture">The texture.</param>
        public unsafe static void BitmapToTexture(Bitmap bitmap, Texture texture)
        {
            var bmp = bitmap.Clone(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            var bitmapData = bmp.LockBits(
                new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
                ImageLockMode.ReadOnly,
                bmp.PixelFormat);

            HardwarePixelBuffer buffer = texture.GetBuffer();

            buffer.Lock(Axiom.Graphics.BufferLocking.Discard);
            PixelBox pixelBox = buffer.CurrentLock;

            UInt32 *texData = (UInt32 *)pixelBox.Data;
            UInt32 *mapData = (UInt32 *)bitmapData.Scan0;

            var height = Math.Min(pixelBox.Height, bmp.Height);
            var width  = Math.Min(pixelBox.Width, bmp.Width);

            for (var y = 0; y < height; ++y)
            {
                for (var x = 0; x < width; ++x)
                {
                    texData[pixelBox.RowPitch * y + x] = mapData[bitmapData.Stride / 4 * y + x];
                }
            }

            buffer.Unlock();
            bmp.UnlockBits(bitmapData);
        }
Exemplo n.º 6
0
        protected override void SetupContent()
        {
            SceneManager.SetSkyBox(true, "Examples/StormySkyBox", 5000); // add a skybox

            // setup some basic lighting for our scene
            SceneManager.AmbientLight = new ColorEx(0.5f, 0.5f, 0.5f);
            SceneManager.CreateLight("DynTexLight1").Position = new Vector3(20, 80, 50);

            // set initial camera position
            CameraManager.setStyle(CameraStyle.Manual);
            Camera.Position = new Vector3(0, 0, 200);

            TrayManager.ShowCursor();

            // create our dynamic texture with 8-bit luminance texels
            var tex = TextureManager.Instance.CreateManual("thaw", ResourceGroupManager.DefaultResourceGroupName,
                                                           TextureType.TwoD, TEXTURE_SIZE, TEXTURE_SIZE, 0, PixelFormat.L8,
                                                           TextureUsage.DynamicWriteOnly);

            this.mTexBuf = tex.GetBuffer(); // save off the texture buffer

            // initialise the texture to have full luminance
            this.mTexBuf.Lock(BufferLocking.Discard);
            Memory.Set(this.mTexBuf.CurrentLock.Data, 0xff, this.mTexBuf.Size);
            this.mTexBuf.Unlock();

            // create a penguin and attach him to our penguin node
            var penguin = SceneManager.CreateEntity("Penguin", "penguin.mesh");

            this.mPenguinNode = SceneManager.RootSceneNode.CreateChildSceneNode();
            this.mPenguinNode.AttachObject(penguin);

            // get and enable the penguin idle animation
            this.mPenguinAnimState           = penguin.GetAnimationState("amuse");
            this.mPenguinAnimState.IsEnabled = true;

            // create a snowstorm over the scene, and fast forward it a little
            var ps = ParticleSystemManager.Instance.CreateSystem("Snow", "Examples/Snow");

            SceneManager.RootSceneNode.AttachObject(ps);
            ps.FastForward(30);

            // create a frosted screen in front of the camera, using our dynamic texture to "thaw" certain areas
            var ent = SceneManager.CreateEntity("Plane", PrefabEntity.Plane);

            ent.MaterialName = "Examples/Frost";
            var node = SceneManager.RootSceneNode.CreateChildSceneNode();

            node.Position = new Vector3(0, 0, 50);
            node.AttachObject(ent);

            this.mPlaneSize = ent.BoundingBox.Size.x;                   // remember the size of the plane

            this.mCursorQuery = SceneManager.CreateRayQuery(new Ray()); // create a ray scene query for the cursor

            this.mTimeSinceLastFreeze = 0;
            this.mWiping = false;
        }
        public HardwarePixelBuffer __deref__()
        {
            global::System.IntPtr cPtr = OgrePINVOKE.HardwarePixelBufferPtr___deref__(swigCPtr);
            HardwarePixelBuffer   ret  = (cPtr == global::System.IntPtr.Zero) ? null : new HardwarePixelBuffer(cPtr, false);

            if (OgrePINVOKE.SWIGPendingException.Pending)
            {
                throw OgrePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Exemplo n.º 8
0
        protected void Generate()
        {
            var   julia  = new Julia(this.globalReal, this.globalImag, this.globalTheta);
            float scale  = 2.5f;
            float vcut   = 29.0f;
            float vscale = 1.0f / vcut;

            HardwarePixelBuffer buffer = this.ptex.GetBuffer(0, 0);

            LogManager.Instance.Write("Volume Texture Sample [info]: HardwarePixelBuffer " + buffer.Width + "x" + buffer.Height);

            buffer.Lock(BufferLocking.Normal);
            PixelBox pb = buffer.CurrentLock;

            LogManager.Instance.Write("Volume Texture Sample [info]: PixelBox " + pb.Width + "x" + pb.Height + "x" + pb.Depth);

            unsafe
            {
                var pbptr = (BufferBase)pb.Data.Clone();
                for (int z = pb.Front; z < pb.Back; z++)
                {
                    for (int y = pb.Top; y < pb.Bottom; y++)
                    {
                        pbptr += pb.Left * sizeof(uint);
                        for (int x = pb.Left; x < pb.Right; x++)
                        {
                            if (z == pb.Front || z == (pb.Back - 1) || y == pb.Top || y == (pb.Bottom - 1) || x == pb.Left ||
                                x == (pb.Right - 1))
                            {
                                pbptr.ToUIntPointer()[0] = 0;
                            }
                            else
                            {
                                float val = julia.Eval(((float)x / pb.Width - 0.5f) * scale, ((float)y / pb.Height - 0.5f) * scale,
                                                       ((float)z / pb.Depth - 0.5f) * scale);
                                if (val > vcut)
                                {
                                    val = vcut;
                                }

                                PixelConverter.PackColor((float)x / pb.Width, (float)y / pb.Height, (float)z / pb.Depth,
                                                         (1.0f - (val * vscale)) * 0.7f, PixelFormat.A8R8G8B8, pbptr);
                            }
                            pbptr++;
                        }
                        pbptr += (pb.RowPitch - pb.Right) * sizeof(uint);
                    }
                    pbptr += pb.SliceSkip * sizeof(uint);
                }
                buffer.Unlock();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// </summary>
        /// <param name="src"> </param>
        /// <param name="srcBox"> </param>
        /// <param name="dstBox"> </param>
        public override void Blit(HardwarePixelBuffer src, BasicBox srcBox, BasicBox dstBox)
        {
            var srct = (GLESTextureBuffer)src;

            /// TODO: Check for FBO support first
            /// Destination texture must be 2D
            /// Source texture must be 2D
            if ((((int)src.Usage & (int)TextureUsage.RenderTarget) != (int)TextureUsage.RenderTarget) && (srct._target == All.Texture2D))
            {
                BlitFromTexture(srct, srcBox, dstBox);
            }
            else
            {
                base.Blit(src, srcBox, dstBox);
            }
        }
Exemplo n.º 10
0
        public override void Blit(HardwarePixelBuffer src, BasicBox srcBox, BasicBox dstBox)
        {
            var srct = (src as GLES2TextureBuffer);

            //Ogre TODO: Check for FBO support first
            //Destination texture must be 2D or Cube
            //Source texture must be 2D
            //Todo: src.Usage is a BufferUsage, but Ogre uses it as a TextureUsage
            if (false && (srct.target == All.Texture2D))
            {
                this.BlitFromTexture(srct, srcBox, dstBox);
            }
            else
            {
                base.Blit(src, srcBox, dstBox);
            }
        }
Exemplo n.º 11
0
        public TerrainLayerBlendMap(Terrain parent, byte layerIdx, HardwarePixelBuffer buf)
        {
            this.mParent   = parent;
            this.mLayerIdx = layerIdx;
            this.mChannel  = (byte)((this.mLayerIdx - 1) % 4);
            this.mDirty    = false;
            this.mBuffer   = buf;
            this.mData     = new float[this.mBuffer.Width * this.mBuffer.Height * sizeof(float)];

            // we know which of RGBA we need to look at, now find it in the format
            // because we can't guarantee what precise format the RS gives us
            PixelFormat fmt       = this.mBuffer.Format;
            var         rgbaShift = PixelUtil.GetBitShifts(fmt);

            this.mChannelOffset = (byte)(rgbaShift[this.mChannel] / 8); // /8 convert to bytes
#if AXIOM_BIG_ENDIAN
            // invert (dealing bytewise)
            mChannelOffset = (byte)(PixelUtil.GetNumElemBytes(fmt) - mChannelOffset - 1);
#endif
            Download();
        }
Exemplo n.º 12
0
        public override void Blit(HardwarePixelBuffer rsrc, BasicBox srcBox, BasicBox dstBox)
        {
            //Entering critical section
            LockDeviceAccess();

            var _src = (D3D9HardwarePixelBuffer)rsrc;

            foreach (var it in this.mapDeviceToBufferResources)
            {
                var srcBufferResources = ((D3D9HardwarePixelBuffer)rsrc).GetBufferResources(it.Key);
                var dstBufferResources = it.Value;

                if (srcBufferResources == null)
                {
                    throw new AxiomException("There are no matching resources attached to the source pixel buffer !!");
                }

                Blit(it.Key, rsrc, srcBox, dstBox, srcBufferResources, dstBufferResources);
            }

            //Leaving critical section
            UnlockDeviceAccess();
        }
Exemplo n.º 13
0
        public void Replace(byte[] bytes, string textureName)
        {
            if (this.IndexOf(textureName) < 0)
            {
                throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist");
            }
            Mogre.Image   image = new Mogre.Image();
            MemoryStream  ms    = new MemoryStream(bytes);
            DataStreamPtr fs2   = new DataStreamPtr(new ManagedDataStream(ms));

            image.Load(fs2);
            PixelBox            imagBox         = image.GetPixelBox();
            TexturePtr          pTexture        = this[textureName];
            TextureManager      lTextureManager = TextureManager.Singleton;
            HardwarePixelBuffer buffer          = pTexture.GetBuffer();

            unsafe
            {
                buffer.BlitFromMemory(imagBox);
            }
            image.Dispose();
            fs2.Close();
            ms.Close();
        }
Exemplo n.º 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="texture"></param>
        /// <param name="channel"></param>
        private ColorMap(Texture texture, MapChannel channel)
        {
            Debug.Assert(texture != null);
            mFilter = MapFilter.Bilinear;
            //Add self to selfList
            mSelfKey = texture.Name + (int)channel;
            mSelfList.Add(mSelfKey, this);
            mRefCount = 0;

            //Get the texture buffer
            HardwarePixelBuffer buff = texture.GetBuffer();

#warning Root::getSingleton().getRenderSystem()->getColourVertexElementType();

            //Prepare a PixelBox (24-bit RGB) to receive the color values
            VertexElementType format = VertexElementType.Color_ARGB;
            switch (format)
            {
            case VertexElementType.Color_ARGB:
                //DirectX9
                mPixels = new PixelBox(new BasicBox(0, 0, buff.Width, buff.Height), PixelFormat.A8B8G8R8);
                break;

            case VertexElementType.Color_ABGR:
                //OpenGL
                mPixels = new PixelBox(new BasicBox(0, 0, buff.Width, buff.Height), PixelFormat.A8B8G8R8);
                //Patch for Ogre's incorrect blitToMemory() when copying from PF_L8 in OpenGL
                if (buff.Format == PixelFormat.L8)
                {
                    channel = MapChannel.Red;
                }
                break;

            default:
                throw new Exception("Unknown RenderSystem color format");
            }

            byte[] pixelData = new byte[mPixels.ConsecutiveSize];
            mPixelPtr    = Memory.PinObject(pixelData);
            mPixels.Data = mPixelPtr;

            if (channel == MapChannel.Color)
            {
                //Copy to the color map directly if no channel extraction is necessary
                buff.BlitToMemory(mPixels);
            }
            else
            {
                unsafe
                {
                    //If channel extraction is necessary, first convert to a PF_R8G8B8A8 format PixelBox
                    //This is necessary for the code below to properly extract the desired channel
                    PixelBox tmpPixels = new PixelBox(new BasicBox(0, 0, buff.Width, buff.Height), PixelFormat.R8G8B8A8);
                    byte[]   tmpPix    = new byte[tmpPixels.ConsecutiveSize];
                    byte *   pixPtr    = (byte *)Memory.PinObject(tmpPix);
                    tmpPixels.Data = (IntPtr)pixPtr;
                    buff.BlitToMemory(tmpPixels);

                    //Pick out a channel from the pixel buffer
                    int channelOffset = 0;
                    switch (channel)
                    {
                    case MapChannel.Red:
                        channelOffset = 3;
                        break;

                    case MapChannel.Green:
                        channelOffset = 2;
                        break;

                    case MapChannel.Blue:
                        channelOffset = 1;
                        break;

                    case MapChannel.Alpha:
                        channelOffset = 0;
                        break;

                    default:
                        //should never happen
                        throw new Exception("Invalid channel");
                    }

                    //And copy that channel into the density map
                    byte *inputPtr     = (byte *)pixPtr + channelOffset;
                    byte *outputPtr    = (byte *)pixPtr + channelOffset;
                    byte *outputEndPtr = outputPtr + mPixels.ConsecutiveSize;
                    while (outputPtr != outputEndPtr)
                    {
                        *outputPtr++ = *inputPtr;
                        *outputPtr++ = *inputPtr;
                        *outputPtr++ = *inputPtr;
                        *outputPtr++ = 0xFF;    //Full alpha
                        inputPtr += 4;
                    }

                    //Finally, delete the temporary PF_R8G8B8A8 pixel buffer
                    Memory.UnpinObject(tmpPix);
                    tmpPixels = null;
                    tmpPix    = null;
                }
            }
        }
        private bool CreateRenderTarget()
        {
            DestroyRenderTarget();

            if (RendererWorld.Instance == null)
            {
                return(false);
            }

            Vec2I textureSize = GetDemandTextureSize();

            if (textureSize.X < 1 || textureSize.Y < 1)
            {
                return(false);
            }

            string textureName = TextureManager.Instance.GetUniqueName("WPFRenderTexture");

            int hardwareFSAA = 0;

            if (!RendererWorld.InitializationOptions.AllowSceneMRTRendering)
            {
                if (!int.TryParse(RendererWorld.InitializationOptions.FullSceneAntialiasing, out hardwareFSAA))
                {
                    hardwareFSAA = 0;
                }
            }

            texture = TextureManager.Instance.Create(textureName, Texture.Type.Type2D, textureSize,
                                                     1, 0, Engine.Renderer.PixelFormat.R8G8B8, Texture.Usage.RenderTarget, false, hardwareFSAA);

            if (texture == null)
            {
                return(false);
            }

            currentTextureSize = textureSize;

            renderTexture                     = texture.GetBuffer().GetRenderTarget();
            renderTexture.AutoUpdate          = false;
            renderTexture.AllowAdditionalMRTs = true;

            camera = SceneManager.Instance.CreateCamera(
                SceneManager.Instance.GetUniqueCameraName("UserControl"));
            camera.Purpose = Camera.Purposes.MainCamera;

            //update camera settings
            camera.NearClipDistance = cameraNearFarClipDistance.Minimum;
            camera.FarClipDistance  = cameraNearFarClipDistance.Maximum;
            camera.AspectRatio      = (float)texture.Size.X / (float)texture.Size.Y;
            camera.FixedUp          = cameraFixedUp;
            camera.Position         = cameraPosition;
            camera.Direction        = cameraDirection;
            camera.Fov               = cameraFov;
            camera.ProjectionType    = cameraProjectionType;
            camera.OrthoWindowHeight = cameraOrthoWindowHeight;

            viewport = renderTexture.AddViewport(camera);

            //Initialize HDR compositor for HDR render technique
            if (EngineApp.RenderTechnique == "HDR")
            {
                viewport.AddCompositor("HDR", 0);
                viewport.SetCompositorEnabled("HDR", true);
            }

            //Initialize Fast Approximate Antialiasing (FXAA)
            {
                bool   useMRT = RendererWorld.InitializationOptions.AllowSceneMRTRendering;
                string fsaa   = RendererWorld.InitializationOptions.FullSceneAntialiasing;
                if ((useMRT && (fsaa == "" || fsaa == "RecommendedSetting") && IsActivateFXAAByDefault()) ||
                    fsaa == "FXAA")
                {
                    if (RenderSystem.Instance.HasShaderModel3())
                    {
                        InitializeFXAACompositor();
                    }
                }
            }

            //add listener
            renderTargetListener = new ViewRenderTargetListener(this);
            renderTexture.AddListener(renderTargetListener);

            if (guiRenderer == null)
            {
                guiRenderer = new GuiRenderer(viewport);
            }
            else
            {
                guiRenderer.ChangeViewport(viewport);
            }

            if (controlManager == null)
            {
                controlManager = new ScreenControlManager(guiRenderer);
            }

            //initialize D3DImage output
            if (d3dImageIsSupported && allowUsingD3DImage)
            {
                // create a D3DImage to host the scene and monitor it for changes in front buffer availability
                if (d3dImage == null)
                {
                    d3dImage = new D3DImage();
                    d3dImage.IsFrontBufferAvailableChanged += D3DImage_IsFrontBufferAvailableChanged;
                    CompositionTarget.Rendering            += D3DImage_OnRendering;
                }

                // set output to background image
                Background = new ImageBrush(d3dImage);

                // set the back buffer using the new scene pointer
                HardwarePixelBuffer            buffer = texture.GetBuffer(0, 0);
                GetD3D9HardwarePixelBufferData data   = new GetD3D9HardwarePixelBufferData();
                data.hardwareBuffer = buffer._GetRealObject();
                data.outPointer     = IntPtr.Zero;
                unsafe
                {
                    GetD3D9HardwarePixelBufferData *pData = &data;
                    if (!RenderSystem.Instance.CallCustomMethod("Get D3D9HardwarePixelBuffer getSurface", (IntPtr)pData))
                    {
                        Log.Fatal("Get D3D9HardwarePixelBuffer getSurface failed.");
                    }
                }
                d3dImage.Lock();
                d3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, data.outPointer);
                d3dImage.Unlock();
            }

            return(true);
        }
Exemplo n.º 16
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(HardwarePixelBuffer obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
 public D3DRenderTexture(string name, HardwarePixelBuffer buffer)
     : base(buffer, 0)
 {
     this.name = name;
 }
Exemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="texture"></param>
        /// <param name="channel"></param>
        private DensityMap(Texture texture, MapChannel channel)
        {
            Debug.Assert(texture != null);
            mFilter = MapFilter.Bilinear;

            //Add self to selfList
            mSelfKey = texture.Name + (int)channel;
            mSelfList.Add(mSelfKey, this);
            mRefCount = 0;

            //Get the texture buffer
            HardwarePixelBuffer buff = texture.GetBuffer();

            //Prepare a PixelBox (8-bit greyscale) to receive the density values
            mPixels = new PixelBox(new BasicBox(0, 0, buff.Width, buff.Height), PixelFormat.BYTE_L);
            byte[] pixelData = new byte[mPixels.ConsecutiveSize];
            mPixelPtr    = Memory.PinObject(pixelData);
            mPixels.Data = mPixelPtr;

            if (channel == MapChannel.Color)
            {
                //Copy to the greyscale density map directly if no channel extraction is necessary
                buff.BlitToMemory(mPixels);
            }
            else
            {
                unsafe
                {
                    //If channel extraction is necessary, first convert to a PF_R8G8B8A8 format PixelBox
                    //This is necessary for the code below to properly extract the desired channel
                    PixelBox tmpPixels = new PixelBox(new BasicBox(0, 0, buff.Width, buff.Height), PixelFormat.R8G8B8A8);
                    byte[]   tmpPix    = new byte[tmpPixels.ConsecutiveSize];
                    byte *   pixPtr    = (byte *)Memory.PinObject(tmpPix);
                    tmpPixels.Data = (IntPtr)pixPtr;
                    buff.BlitToMemory(tmpPixels);

                    //Pick out a channel from the pixel buffer
                    int channelOffset = 0;
                    switch (channel)
                    {
                    case MapChannel.Red:
                        channelOffset = 3;
                        break;

                    case MapChannel.Green:
                        channelOffset = 2;
                        break;

                    case MapChannel.Blue:
                        channelOffset = 1;
                        break;

                    case MapChannel.Alpha:
                        channelOffset = 0;
                        break;

                    default:
                        //should never happen
                        throw new Exception("Invalid channel");
                    }

                    //And copy that channel into the density map
                    byte *inputPtr     = (byte *)pixPtr + channelOffset;
                    byte *outputPtr    = (byte *)pixPtr + channelOffset;
                    byte *outputEndPtr = outputPtr + mPixels.ConsecutiveSize;
                    while (outputPtr != outputEndPtr)
                    {
                        *outputPtr++ = *inputPtr++;
                        inputPtr += 4;
                    }

                    //Finally, delete the temporary PF_R8G8B8A8 pixel buffer
                    Memory.UnpinObject(tmpPix);
                    tmpPixels = null;
                }
            }
        }
Exemplo n.º 19
0
 public XnaRenderTexture(string name, HardwarePixelBuffer buffer)
     : base(buffer, 0)
 {
     base.name = name;
 }