Пример #1
0
        public override Endogine.BitmapHelpers.PixelDataProvider TransformIntoRenderTarget(Endogine.BitmapHelpers.PixelDataProvider pdp)
        {
            Surface surf     = ((PixelDataProvider)pdp).Texture.GetSurfaceLevel(0);
            bool    isTarget = ((int)surf.Description.Usage & (int)Usage.RenderTarget) != 0;

            if (isTarget)
            {
                return(pdp);
            }

            Surface oldSurfRT = this._device.GetRenderTarget(0);

            PixelDataProvider pdpRT = new PixelDataProvider(pdp.Width, pdp.Height, pdp.BitsPerPixel / 8, this._device, Usage.RenderTarget);

            this.RenderTarget = pdpRT;

            Endogine.SpriteRenderStrategy rs = this.CreateRenderStrategy();
            rs.Init();
            rs.SetPixelDataProvider(pdp);
            ERectangleF rctDrawTarget = new ERectangleF(0, 0, pdp.Width, pdp.Height);//-pdp.Width, -pdp.Height, pdp.Width * 2, pdp.Height * 2) * 2;

            //rs.SourceClipRect = sourceClipRect;
            rs.CalcRenderRegion(rctDrawTarget, 0, new EPoint(), new EPoint(pdp.Width, pdp.Height));

            //render:
            this.PreUpdate();
            rs.SubDraw();
            this.EndUpdate();

            //reset renderer and finish up:
            this._device.SetRenderTarget(0, oldSurfRT);
            this.PostUpdate();

            return(pdpRT);
        }
Пример #2
0
        public override Endogine.BitmapHelpers.PixelDataProvider CreatePixelDataProvider(System.Drawing.Bitmap bmp)
        {
            PixelDataProvider pdpTx = null;
            Texture           tx    = null;

            if (true)
            {
                //TODO: Saving bitmap to a MemoryStream and using TextureLoader.FromStream() might be faster
                tx    = new Texture(this._device, bmp.Width, bmp.Height, 1, Usage.None, Format.X8R8G8B8, Pool.Managed);
                pdpTx = new PixelDataProvider(tx);
                Endogine.BitmapHelpers.Canvas canvasTx = Endogine.BitmapHelpers.Canvas.Create(pdpTx);
                canvasTx.Locked = true;

                //TODO: remove when MDX 2.0 gets up to speed...
                Endogine.BitmapHelpers.PixelDataProviderGDI pdpGDI = new Endogine.BitmapHelpers.PixelDataProviderGDI(bmp);
                Endogine.BitmapHelpers.Canvas canvasSrc            = Endogine.BitmapHelpers.Canvas.Create(pdpGDI);
                canvasSrc.Locked = true;
                for (int y = canvasSrc.Height - 1; y >= 0; y--)
                {
                    for (int x = canvasSrc.Width - 1; x >= 0; x--)
                    {
                        canvasTx.SetPixel(x, y, canvasSrc.GetPixel(x, y));
                    }
                }
                canvasSrc.Locked = false;
                canvasTx.Locked  = false;
            }
            else
            {
                tx    = new Texture(this._device, bmp, Usage.None, Pool.Managed);
                pdpTx = new PixelDataProvider(tx);
            }
            return(pdpTx);
        }
Пример #3
0
        public override void CreateFromBitmap(Bitmap a_bmp)
        {
            if (m_tx != null)
            {
                m_tx.Dispose();
            }


            if (true)
            {
                m_tx = new Texture(this._device, a_bmp, Usage.None, Pool.Managed); //TODO: why is this so slow sometimes?
            }
            else
            {
                Endogine.BitmapHelpers.Canvas canvasX = Endogine.BitmapHelpers.Canvas.Create(a_bmp);
                PixelDataProvider             pdp     = new PixelDataProvider(a_bmp.Width, a_bmp.Height, canvasX.BitsPerPixel / 8, this._device, Usage.None);

                Endogine.BitmapHelpers.Canvas canvas = Endogine.BitmapHelpers.Canvas.Create(pdp);
                System.Drawing.Graphics       g      = canvas.GetGraphics();
                g.DrawImageUnscaled(a_bmp, new Point(0, 0));
                //for (int y = canvas.Height-1; y >= 0; y--)
                //{
                //    for (int x = canvas.Width - 1; x >= 0; x--)
                //    {
                //        canvas.SetPixel
                //    }
                //}
                canvas.Locked = false;

                m_tx = pdp.Texture;
            }
        }
Пример #4
0
        public override Endogine.BitmapHelpers.PixelDataProvider UglyConvertRenderTargetToReadable(Endogine.BitmapHelpers.PixelDataProvider pdpTarget)
        {
            PixelDataProvider pdp3DTarget = (PixelDataProvider)pdpTarget;

            //http://www.gamedev.net/community/forums/topic.asp?topic_id=388869
            //http://www.gamedev.net/community/forums/topic.asp?topic_id=384658&whichpage=1&
            //http://www.gamedev.net/community/forums/topic.asp?topic_id=388736

            //TODO: EXTREMELY ugly!! First copy to system memory, then back to card!!
            Surface sfSrc = pdp3DTarget.Texture.GetSurfaceLevel(0);

            //this._device.StretchRectangle(sfSrc, new System.Drawing.Rectangle(0,0,pdpTarget.Width,pdpTarget.Height),

            Surface sfDst = this._device.CreateOffscreenPlainSurface(pdp3DTarget.Width, pdp3DTarget.Height,
                                                                     pdp3DTarget.SurfaceDescription.Format, Pool.SystemMemory); //Pool.SystemMemory Managed

            this._device.GetRenderTargetData(sfSrc, sfDst);

            //Surface sfDst2 = new Surface(this._device,
            //SurfaceLoader.FromSurface(sfDst2,
            Texture tx = new Texture(this._device, pdp3DTarget.Width, pdp3DTarget.Height, 1, Usage.None, pdp3DTarget.SurfaceDescription.Format, Pool.Managed);
            //this._device.UpdateSurface(sfDst, sf);

            //unsafe
            //{
            //    byte* ptr;
            //    //byte[] array = (byte[])ptr;
            //    Buffer.BlockCopy(ptr, 0, ptr, 0, 20000);
            //}
            PixelDataProvider pdpCP = new PixelDataProvider(sfDst);

            Endogine.BitmapHelpers.Canvas cCP = Endogine.BitmapHelpers.Canvas.Create(pdpCP);
            cCP.Locked = true;

            PixelDataProvider pdp = new PixelDataProvider(tx);

            Endogine.BitmapHelpers.Canvas c1 = Endogine.BitmapHelpers.Canvas.Create(pdp);
            c1.Locked = true;
            for (int y = c1.Height - 1; y >= 0; y--)
            {
                for (int x = c1.Width - 1; x >= 0; x--)
                {
                    c1.SetPixel(x, y, cCP.GetPixel(x, y));
                }
            }
            c1.Locked  = false;
            cCP.Locked = false;

            //return pdpCP;
            return(pdp);
        }
Пример #5
0
        public override Endogine.BitmapHelpers.PixelDataProvider CreateSimilar(int width, int height, int numChannels)
        {
            Format pf = this._sd.Format;

            switch (numChannels)
            {
            case 1:
                pf = Format.A8;
                break;

            case 3:
                pf = Format.R8G8B8;
                break;

            case 4:
                pf = Format.X8R8G8B8;
                break;

            case 8:
                pf = Format.A16B16G16R16;
                break;
            }

            //TODO: find possible formats...
            if (pf == Format.R8G8B8)
            {
                pf = Format.X8R8G8B8;
            }

            //TODO: merge with constructor above...
            PixelDataProvider pdp = null;

            if (this._tx != null)
            {
                Texture tx = new Texture(this._tx.Device, width, height, 1, this._sd.Usage, pf, this._sd.Pool); //Pool.Managed);
                pdp = new PixelDataProvider(tx);
            }
            else if (this._surf != null)
            {
                //TODO: Is there no way I can use the current surface to set pixelformat etc?
                Texture tx = new Texture(this._surf.Device, width, height, 1, this._sd.Usage, pf, this._sd.Pool); //Pool.Managed);
                pdp = new PixelDataProvider(tx);
                //Surface surf = new Surface(this._surf.Device, (System.Drawing.Bitmap)null, this._sd.Pool); //Pool.Managed);
                //pdp = new PixelDataProvider(surf);
            }
            return(pdp);
        }
Пример #6
0
        public override Endogine.BitmapHelpers.PixelDataProvider UglyConvertRenderTargetToReadable(Endogine.BitmapHelpers.PixelDataProvider pdpTarget)
        {
            PixelDataProvider pdp3DTarget = (PixelDataProvider)pdpTarget;

            //http://www.gamedev.net/community/forums/topic.asp?topic_id=388869
            //http://www.gamedev.net/community/forums/topic.asp?topic_id=384658&whichpage=1&
            //http://www.gamedev.net/community/forums/topic.asp?topic_id=388736

            //TODO: EXTREMELY ugly!! First copy to system memory, then back to card!!
            Surface sfSrc = pdp3DTarget.Texture.GetSurfaceLevel(0);

            //this._device.StretchRectangle(sfSrc, new System.Drawing.Rectangle(0,0,pdpTarget.Width,pdpTarget.Height),

            Surface sfDst = this._device.CreateOffscreenPlainSurface(pdp3DTarget.Width, pdp3DTarget.Height,
                pdp3DTarget.SurfaceDescription.Format, Pool.SystemMemory); //Pool.SystemMemory Managed

            this._device.GetRenderTargetData(sfSrc, sfDst);

            //Surface sfDst2 = new Surface(this._device,
            //SurfaceLoader.FromSurface(sfDst2,
            Texture tx = new Texture(this._device, pdp3DTarget.Width, pdp3DTarget.Height, 1, Usage.None, pdp3DTarget.SurfaceDescription.Format, Pool.Managed);
            //this._device.UpdateSurface(sfDst, sf);

            //unsafe
            //{
            //    byte* ptr;
            //    //byte[] array = (byte[])ptr;
            //    Buffer.BlockCopy(ptr, 0, ptr, 0, 20000);
            //}
            PixelDataProvider pdpCP = new PixelDataProvider(sfDst);
            Endogine.BitmapHelpers.Canvas cCP = Endogine.BitmapHelpers.Canvas.Create(pdpCP);
            cCP.Locked = true;

            PixelDataProvider pdp = new PixelDataProvider(tx);
            Endogine.BitmapHelpers.Canvas c1 = Endogine.BitmapHelpers.Canvas.Create(pdp);
            c1.Locked = true;
            for (int y = c1.Height-1; y >= 0; y--)
            {
                for (int x = c1.Width - 1; x >= 0; x--)
                    c1.SetPixel(x, y, cCP.GetPixel(x, y));
            }
            c1.Locked = false;
            cCP.Locked = false;

            //return pdpCP;
            return pdp;
        }
Пример #7
0
        public override Endogine.BitmapHelpers.PixelDataProvider TransformIntoRenderTarget(Endogine.BitmapHelpers.PixelDataProvider pdp)
        {
            Surface surf = ((PixelDataProvider)pdp).Texture.GetSurfaceLevel(0);
            bool isTarget = ((int)surf.Description.Usage & (int)Usage.RenderTarget) != 0;
            if (isTarget)
                return pdp;

            Surface oldSurfRT = this._device.GetRenderTarget(0);

            PixelDataProvider pdpRT = new PixelDataProvider(pdp.Width, pdp.Height, pdp.BitsPerPixel / 8, this._device, Usage.RenderTarget);
            this.RenderTarget = pdpRT;

            Endogine.SpriteRenderStrategy rs = this.CreateRenderStrategy();
            rs.Init();
            rs.SetPixelDataProvider(pdp);
            ERectangleF rctDrawTarget = new ERectangleF(0,0, pdp.Width, pdp.Height);//-pdp.Width, -pdp.Height, pdp.Width * 2, pdp.Height * 2) * 2;
            //rs.SourceClipRect = sourceClipRect;
            rs.CalcRenderRegion(rctDrawTarget, 0, new EPoint(), new EPoint(pdp.Width, pdp.Height));

            //render:
            this.PreUpdate();
            rs.SubDraw();
            this.EndUpdate();

            //reset renderer and finish up:
            this._device.SetRenderTarget(0, oldSurfRT);
            this.PostUpdate();

            return pdpRT;
        }
Пример #8
0
        public override Endogine.BitmapHelpers.PixelDataProvider CreatePixelDataProvider(System.Drawing.Bitmap bmp)
        {
            PixelDataProvider pdpTx = null;
            Texture tx = null;
            if (true)
            {
                //TODO: Saving bitmap to a MemoryStream and using TextureLoader.FromStream() might be faster
                tx = new Texture(this._device, bmp.Width, bmp.Height, 1, Usage.None, Format.X8R8G8B8, Pool.Managed);
                pdpTx = new PixelDataProvider(tx);
                Endogine.BitmapHelpers.Canvas canvasTx = Endogine.BitmapHelpers.Canvas.Create(pdpTx);
                canvasTx.Locked = true;

                //TODO: remove when MDX 2.0 gets up to speed...
                Endogine.BitmapHelpers.PixelDataProviderGDI pdpGDI = new Endogine.BitmapHelpers.PixelDataProviderGDI(bmp);
                Endogine.BitmapHelpers.Canvas canvasSrc = Endogine.BitmapHelpers.Canvas.Create(pdpGDI);
                canvasSrc.Locked = true;
                for (int y = canvasSrc.Height-1; y >= 0 ; y--)
                {
                    for (int x = canvasSrc.Width - 1; x >= 0; x--)
                        canvasTx.SetPixel(x, y, canvasSrc.GetPixel(x, y));
                }
                canvasSrc.Locked = false;
                canvasTx.Locked = false;
            }
            else
            {
                tx = new Texture(this._device, bmp, Usage.None, Pool.Managed);
                pdpTx = new PixelDataProvider(tx);
            }
            return pdpTx;
        }
Пример #9
0
        public override Endogine.BitmapHelpers.PixelDataProvider CreateSimilar(int width, int height, int numChannels)
        {
            Format pf = this._sd.Format;
            switch (numChannels)
            {
                case 1:
                    pf = Format.A8;
                    break;
                case 3:
                    pf = Format.R8G8B8;
                    break;
                case 4:
                    pf = Format.X8R8G8B8;
                    break;
                case 8:
                    pf = Format.A16B16G16R16;
                    break;
            }

            //TODO: find possible formats...
            if (pf == Format.R8G8B8)
                pf = Format.X8R8G8B8;

            //TODO: merge with constructor above...
            PixelDataProvider pdp = null;
            if (this._tx != null)
            {
                Texture tx = new Texture(this._tx.Device, width, height, 1, this._sd.Usage, pf, this._sd.Pool); //Pool.Managed);
                pdp = new PixelDataProvider(tx);
            }
            else if (this._surf != null)
            {
                //TODO: Is there no way I can use the current surface to set pixelformat etc?
                Texture tx = new Texture(this._surf.Device, width, height, 1, this._sd.Usage, pf, this._sd.Pool); //Pool.Managed);
                pdp = new PixelDataProvider(tx);
                //Surface surf = new Surface(this._surf.Device, (System.Drawing.Bitmap)null, this._sd.Pool); //Pool.Managed);
                //pdp = new PixelDataProvider(surf);
            }
            return pdp;
        }