Пример #1
0
        /// <summary>
        /// Update the RenderWindow or RenderBitmap with the updated tile from
        /// Cycles render progress.
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="tx"></param>
        /// <param name="ty"></param>
        /// <param name="tw"></param>
        /// <param name="th"></param>
        public void DisplayBuffer(uint sessionId, uint tx, uint ty, uint tw, uint th)
        {
            if (IsStopped) return;
            var start = DateTime.Now;
            var rg = RenderBitmap;
            if (RenderWindow != null)
            {
                using (var channel = RenderWindow.OpenChannel(RenderWindow.StandardChannels.RGBA))
                {
                    if (channel != null)
                    {
                        var pixelbuffer = new PixelBuffer(CSycles.session_get_buffer(Client.Id, sessionId));
                        var size = Client.Scene.Camera.Size;
                        var rect = new Rectangle((int) tx, (int) ty, (int) tw, (int) th);
                        channel.SetValues(rect, size, pixelbuffer);
                        RenderWindow.InvalidateArea(rect);
                    }
                }
            }
            else if (rg != null)
            {
                uint buffer_size;
                uint buffer_stride;
                var width = RenderDimension.Width;
                CSycles.session_get_buffer_info(Client.Id, sessionId, out buffer_size, out buffer_stride);
                var pixels = CSycles.session_copy_buffer(Client.Id, sessionId, buffer_size);
                for (var x = (int)tx; x < (int)(tx + tw); x++)
                {
                    for (var y = (int)ty; y < (int)(ty + th); y++)
                    {
                        var i = y * width * 4 + x * 4;
                        var r = pixels[i];
                        var g = pixels[i + 1];
                        var b = pixels[i + 2];
                        var a = pixels[i + 3];

                        r = Math.Min(Math.Abs(r), 1.0f);
                        g = Math.Min(Math.Abs(g), 1.0f);
                        b = Math.Min(Math.Abs(b), 1.0f);
                        a = Math.Min(Math.Abs(a), 1.0f);

                        var c4_f = new Color4f(r, g, b, a);
                        rg.SetPixel(x, y, c4_f.AsSystemColor());
                    }
                }
            }
            var diff = (DateTime.Now - start).TotalMilliseconds;
        }