Beispiel #1
0
        static void Main(string[] args)
        {
            var input = Console.ReadLine();

            while (input != "exit")
            {
                var     op5 = new PowerOperation();
                var     op4 = new DivideOperation(op5);
                var     op3 = new MultiplyOperation(op4);
                var     op2 = new SubstractOperation(op3);
                var     op1 = new AddOperation(op2);
                Command command;
                try
                {
                    command = new Command(input);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }

                var result = op1.Calculate(command);
                Console.Write(result == null
                    ? $"Operation {command.Operation} is not supported"
                    : $"{command} = {result} \n");

                input = Console.ReadLine();
            }
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            AddOperation add       = new AddOperation();
            var          addResult = add.Execute(2, 5);

            SubstractOperation subsctract = new SubstractOperation();
            var substractResult           = subsctract.Execute(5, 2);

            Console.WriteLine($"Add result: {addResult}");
            Console.WriteLine($"Substract result: {substractResult}");
            Console.ReadKey();
        }
        void Initialize()
        {
            // 1) We create vertex shader first.
            {
                vertexShader = new ShaderCode(BindingStage.VertexShader);
                vertexShader.InputOperation.AddInput(PinComponent.Position, PinFormat.Floatx2);



                // We now extend position
                ExpandOperation expandPositionOp = new ExpandOperation(PinFormat.Floatx4, ExpandType.AddOnesAtW);
                expandPositionOp.BindInputs(vertexShader.InputOperation.PinAsOutput(PinComponent.Position));
                Pin position = expandPositionOp.Outputs[0];

                // We now output position.
                vertexShader.OutputOperation.AddComponentAndLink(PinComponent.Position, position);
            }

            vertexShader.Immutable = true;

            // 2) We create pixel shader.
            {
                pixelShader = new ShaderCode(BindingStage.PixelShader);
                pixelShader.InputOperation.AddInput(PinComponent.Position, PinFormat.Floatx4);

                // We first use only XY.
                SwizzleOperation swizzleOp = new SwizzleOperation(SwizzleMask.XY);
                swizzleOp.BindInputs(pixelShader.InputOperation.PinAsOutput(PinComponent.Position));

                ConstantOperation constant = vertexShader.CreateConstant("Offset", PinFormat.Floatx2);

                // We first offset.
                SubstractOperation subOp = new SubstractOperation();
                subOp.BindInputs(swizzleOp.Outputs[0], constant.Outputs[0]);

                ConstantOperation interfaceOp = pixelShader.CreateConstant("Composite", PinFormat.Interface, Pin.DynamicArray);

                // We use the compositing operation.
                CompositingOperation op = new CompositingOperation();
                op.BindInputs(subOp.Outputs[0],
                              interfaceOp.Outputs[0]);

                // Compositing is bound to output.
                pixelShader.OutputOperation.AddComponentAndLink(PinComponent.RenderTarget0, op.Outputs[0]);
            }

            pixelShader.Immutable = true;

            // 3) Initialize states.

            // Depth-stencil state.
            depthStencilState = new DepthStencilState();
            depthStencilState.DepthTestEnabled  = false;
            depthStencilState.DepthWriteEnabled = false;

            // Blend state (no blending default).
            blendState = new BlendState();


            // Rasterization state.
            rasterizationState                      = new RasterizationState();
            rasterizationState.FrontFacing          = Facing.CCW;
            rasterizationState.CullMode             = CullMode.None;
            rasterizationState.FillMode             = FillMode.Solid;
            rasterizationState.MultiSamplingEnabled = true;


            // We intern all states.
            depthStencilState  = StateManager.Intern(depthStencilState);
            blendState         = StateManager.Intern(blendState);
            rasterizationState = StateManager.Intern(rasterizationState);

            // 4) We create geometry.
            alignedQuad = new Geometry(device);
            alignedQuad.AssociateBuffers = true;

            {
                // We create vertex buffer
                VertexBufferView vertexBuffer = VertexBufferView.Create(device, vertexFormat, Usage.Default,
                                                                        CPUAccess.None, GraphicsLocality.DeviceOrSystemMemory,
                                                                        new Vector2f(-1.0f, -1.0f), new Vector2f(1.0f, -1.0f),
                                                                        new Vector2f(1.0f, 1.0f), new Vector2f(-1.0f, -1.0f),
                                                                        new Vector2f(1.0f, 1.0f), new Vector2f(-1.0f, 1.0f));

                alignedQuad[0] = vertexBuffer;
            }

            // 5) We create pixel typeless buffer for constant buffer.
            pixelTypelessConstantBuffer = new TypelessBuffer(Usage.Dynamic, BufferUsage.ConstantBuffer,
                                                             CPUAccess.Write, GraphicsLocality.DeviceOrSystemMemory, ConstantBufferView.MaxSize);
        }