public void DoRectUpdate(int mipLevel, ClipStackEntry stackEntry, RectangleI srcRegion, RectangleI dstRegion)
        {
            // get an array of texture data
            int elementCount = dstRegion.Width * dstRegion.Height;
            uint[] dstData = new uint[elementCount];
            uint[] srcData = _textureData[mipLevel];

            // make local copies of the rectangle components for quick access
            int srcExtentX = srcRegion.Extent.X;
            int srcExtentY = srcRegion.Extent.Y;
            int srcIndex = srcRegion.Point.X + (srcRegion.Point.Y * (int)stackEntry.ScaleFactor * stackEntry.Texture.Width);

            for (int y = 0; y < srcExtentY; y++)
            {
                Array.Copy(srcData, srcIndex, dstData, y * srcExtentX, srcExtentX);
                srcIndex += (int)stackEntry.ScaleFactor * stackEntry.Texture.Width;
            }

            // send the new data to the stack entry texture
            MSXNA.Rectangle dstTextureRect = new MSXNA.Rectangle(dstRegion.X, dstRegion.Y, dstRegion.Width, dstRegion.Height);

            // replace the specified rect of texture data on the texture
            #if XBOX
               stackEntry.Texture.SetData<uint>(0, dstTextureRect, dstData, 0, elementCount, SetDataOptions.None);
            #else
            stackEntry.Texture.SetData<uint>(0, dstTextureRect, dstData, 0, elementCount, SetDataOptions.Discard);
            #endif
        }
        public void DoRectUpdate(int mipLevel, ClipStackEntry stackEntry, RectangleI srcRegion, RectangleI dstRegion)
        {
            // toggle updateToggle
            _updateToggle = (_updateToggle + 1) % 3;

            // find the index to start at
            int index = (stackEntry.Texture.Width * dstRegion.Point.Y) + dstRegion.Point.X;

            // get an array of texture data
            int elementCount = dstRegion.Width * dstRegion.Height;
            uint[] dstData = new uint[elementCount];

            // make local copies of the rectangle components for quick access
            int srcPointX = srcRegion.Point.X;
            int srcPointY = srcRegion.Point.Y;
            int srcExtentX = srcRegion.Extent.X;
            int srcExtentY = srcRegion.Extent.Y;
            float scaleFactor = stackEntry.ScaleFactor;

            for (int y = 0; y < srcExtentY; y++)
            {
                for (int x = 0; x < srcExtentX; x++)
                {
                    uint color = 0xFF000000;

                    int realX = x + srcPointX;
                    int realY = y + srcPointY;

                    int xFlag = realX & 4;
                    int yFlag = realY & 4;

                    // checker pattern
                    if ((xFlag ^ yFlag) != 0)
                        color += 0xFF;

                    // gradient based on x position across master texture
                    color += (uint)((float)realX / (float)(512f * scaleFactor) * 255) << 8;

                    // toggle colors
                    switch (_updateToggle)
                    {
                        case 0:
                            color += 0xFF0000;
                            break;
                        case 1:
                            color += 0xA00000;
                            break;
                    }

                    //(uint)(_updateToggle ? 0xFF0000 : 0x00);
                    //color += 0xFF;

                    dstData[(srcExtentX * y) + x] = color;
                }
            }

            // send the new data to the stack entry texture
            Rectangle dstTextureRect = new Rectangle(dstRegion.X, dstRegion.Y, dstRegion.Width, dstRegion.Height);
            stackEntry.Texture.SetData<uint>(0, dstTextureRect, dstData, 0, elementCount, SetDataOptions.None);
        }
 public void BeginRectUpdates(int mipLevel, ClipStackEntry stackEntry)
 {
 }
 public void FinishRectUpdates(int mipLevel, ClipStackEntry stackEntry)
 {
 }
        public void FinishRectUpdates(int mipLevel, ClipStackEntry stackEntry)
        {
            // grab a local reference to the graphics device
            GraphicsDevice device = GFXDevice.Instance.Device;

            // resolve the render target and refresh the clip stack texture reference
            device.SetRenderTarget(0, null);

            // get the render target texture from the current render target
            stackEntry.Texture = _renderTargets[mipLevel].GetTexture();

            // drop the normal render target and viewport back into place
            TorqueEngineComponent.Instance.ReapplyMainRenderTarget();
            device.Viewport = _sceneViewport;
            device.DepthStencilBuffer = _sceneDepthBuffer;
        }
        public void DoRectUpdate(int mipLevel, ClipStackEntry stackEntry, RectangleI srcRegion, RectangleI dstRegion)
        {
            // get a local reference to the GFXDevice's graphics device
            GraphicsDevice device = GFXDevice.Instance.Device;

            if (device.IsDisposed)
                return;

            // calculate the new destination texture coordinates
            // (custom viewports currently not fully supported on the XBox, so we use this method instead.
            // this is just as fast, so probably keep using this.)
            RectangleF dstCoords = new RectangleF(
                (float)dstRegion.X / (float)stackEntry.Texture.Width,
                (float)dstRegion.Y / (float)stackEntry.Texture.Height,
                (float)dstRegion.Width / (float)stackEntry.Texture.Width,
                (float)dstRegion.Height / (float)stackEntry.Texture.Height
                );

            // calculate the new texture coordinates
            RectangleF texCoords = new RectangleF(
                (float)srcRegion.X / ((float)stackEntry.Texture.Width * stackEntry.ScaleFactor),
                (float)srcRegion.Y / ((float)stackEntry.Texture.Height * stackEntry.ScaleFactor),
                (float)srcRegion.Width / ((float)stackEntry.Texture.Width * stackEntry.ScaleFactor),
                (float)srcRegion.Height / ((float)stackEntry.Texture.Height * stackEntry.ScaleFactor)
                );

            // custom viewports currently bugged on XBOX
            _UpdateRenderQuad(texCoords, dstCoords);

            // init the effect for this render
            _blender.SetupEffect(_toTexRenderState, null);

            // draw the quad
            while (_blender.SetupPass())
            {
                try
                {
                    device.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, _renderQuadVB, 0, 2);
                }
                catch (Exception x)
                {
                    break;
                }
            }
            // cleanup the effect after render
            _blender.CleanupEffect();
        }
        public void BeginRectUpdates(int mipLevel, ClipStackEntry stackEntry)
        {
            // grab a local reference to the graphics device
            GraphicsDevice device = GFXDevice.Instance.Device;

            // record the viewport (if PC)
            _sceneViewport = device.Viewport;
            _sceneDepthBuffer = device.DepthStencilBuffer;

            // replace it with our scratch render target for this mip level
            device.Viewport = _viewSlice;
            device.SetRenderTarget(0, _renderTargets[mipLevel]);
            device.DepthStencilBuffer = null;

            // set up the device to render our quad to a section of the texture
            device.RenderState.AlphaBlendEnable = false;
            device.RenderState.DepthBufferEnable = false;
            device.RenderState.CullMode = CullMode.None;
            //device.Indices = _renderQuadIB.Instance;
            device.VertexDeclaration = GFXDevice.Instance.GetVertexDeclarationVPT();
        }