Beispiel #1
0
        public FlatBufferBuilder BuildRender(int index, IEnumerable <IRenderCommand> renderCommands)
        {
            var builder  = new FlatBufferBuilder(100);
            var messages = new List <Offset <RenderMessage> >();

            foreach (var command in renderCommands)
            {
                if (command is ClearScreenCommand)
                {
                    //NOOP
                    break;
                }
                else if (command is Line2D3DCommand line2d3d)
                {
                    Line2D3D(line2d3d, builder, messages);
                }
                else if (command is Line2DCommand line2d)
                {
                    Line2D(line2d, builder, messages);
                }
                else if (command is Line3DCommand line3d)
                {
                    Line3D(line3d, builder, messages);
                }
                else if (command is PolyLine2DCommand polyLine2d)
                {
                    PolyLine2D(polyLine2d, builder, messages);
                }
                else if (command is PolyLine3DCommand polyLine3d)
                {
                    PolyLine3D(polyLine3d, builder, messages);
                }
                else if (command is Rectangle2DCommand rectangle2d)
                {
                    Rectangle2D(rectangle2d, builder, messages);
                }
                else if (command is Rectangle3DCommand rectangle3d)
                {
                    Rectangle3D(rectangle3d, builder, messages);
                }
                else if (command is String2DCommand string2d)
                {
                    String2D(string2d, builder, messages);
                }
                else if (command is String3DCommand string3d)
                {
                    String3D(string3d, builder, messages);
                }
            }

            var messagesVector = RenderGroup.CreateRenderMessagesVector(builder, messages.ToArray());
            var renderGroup    = RenderGroup.CreateRenderGroup(builder, messagesVector, index);

            builder.Finish(renderGroup.Value);
            return(builder);
        }
Beispiel #2
0
        /// <summary>
        /// Finishes the render packet and returns the complete packet.
        /// </summary>
        /// <returns>Returns the completed render packet.</returns>
        protected RenderPacket DoFinishPacket()
        {
            var offsets           = _renderMessageOffsets.ToArray();
            var messagesOffset    = RenderGroup.CreateRenderMessagesVector(Builder, offsets);
            var renderGroupOffset = RenderGroup.CreateRenderGroup(Builder, messagesOffset, _index);

            Builder.Finish(renderGroupOffset.Value);
            var bytes = Builder.SizedByteArray();

            ResetPacket();
            return(new RenderPacket(bytes));
        }
Beispiel #3
0
        /// <summary>
        /// If this renderer has previously drawn anything on the screen, it will be erased.
        /// This can be called at any time. It will not interrupt any packet construction
        /// that may be in progress.
        /// </summary>
        public void EraseFromScreen()
        {
            var eraseBuilder = new FlatBufferBuilder(10);
            var vectorOffset = RenderGroup.CreateRenderMessagesVector(eraseBuilder, new Offset <RenderMessage> [0]);

            RenderGroup.StartRenderGroup(eraseBuilder);
            RenderGroup.AddRenderMessages(eraseBuilder, vectorOffset);
            RenderGroup.AddId(eraseBuilder, _index);
            eraseBuilder.Finish(RenderGroup.EndRenderGroup(eraseBuilder).Value);

            RenderPacket emptyPacket = new RenderPacket(eraseBuilder.SizedByteArray());

            SendPacket(emptyPacket);
        }