Beispiel #1
0
 public void Compile(ShaderCompiler compiler, ShaderCompiler.Operand position, ShaderCompiler.Operand texCoord,
                     ShaderCompiler.Operand[] attributes, ShaderCompiler.Operand borderDistance, ShaderCompiler.Operand[] constants,
                     ShaderCompiler.Operand outputColour)
 {
     // The colour is saved in attribute.
     compiler.Mov(attributes[0], outputColour);
 }
Beispiel #2
0
        public override ShaderCompiler.Operand[] Compile(ShaderCompiler compiler, ShaderCompiler.Operand[] operands, FixedShaderParameters parameters, ref DualShareContext shareContext)
        {
            // We prepare operands.
            ShaderCompiler.Operand[] ret = new ShaderCompiler.Operand[operands.Length];
            for (int i = 1; i < ret.Length; i++)
            {
                ret[i] = compiler.CreateTemporary(operands[i].Format, operands[i].ArraySize);
                compiler.Mov(operands[i], ret[i]);
            }

            // At index 0, we have indexer, we initialize to 0.
            ret[0] = compiler.CreateTemporary(PinFormat.UInteger, Pin.NotArray);
            compiler.Mov(compiler.CreateFixed(PinFormat.UInteger, Pin.NotArray, (uint)0), ret[0]);

            // We begin while.
            compiler.BeginWhile();

            // We exit if iteration count is exceeded.
            compiler.Break(compiler.Compare(CompareFunction.Less, ret[0], operands[0]));
            compiler.Add(ret[0], compiler.CreateFixed(PinFormat.UInteger, Pin.NotArray, (uint)1), ret[0]);

            // We also fill dual share context.
            ShaderCompiler.Operand[] shared = new ShaderCompiler.Operand[ret.Length - 1];
            for (int i = 1; i < ret.Length; i++)
            {
                shared[i - 1] = ret[i];
            }

            shareContext = new DualShareContext(shared, parent.outputOperation);

            // We now go forward.
            return(ret);
        }
Beispiel #3
0
        public override ShaderCompiler.Operand[] Compile(ShaderCompiler compiler, ShaderCompiler.Operand[] operands, FixedShaderParameters parameters, ref DualShareContext shareContext)
        {
            // We prepare operands.
            ShaderCompiler.Operand[] ret = new ShaderCompiler.Operand[operands.Length];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = compiler.CreateTemporary(operands[i].Format, operands[i].ArraySize);
                compiler.Mov(operands[i], ret[i]);
            }

            // We begin while.
            compiler.BeginWhile();

            // We also fill dual share context.
            ShaderCompiler.Operand[] shared = new ShaderCompiler.Operand[ret.Length];
            for (int i = 0; i < ret.Length; i++)
            {
                shared[i] = ret[i];
            }

            shareContext = new DualShareContext(shared, parent.outputOperation);

            // We now go forward.
            return(ret);
        }
Beispiel #4
0
 ShaderCompiler.Operand ICompositeInterface.GetPixel(ShaderCompiler compiler,
                                                     ShaderCompiler.Operand absolutePosition, Dictionary <ICompositeInterface, ShaderCompiler.Operand[]> constants)
 {
     return(compiler.Add(
                source1.Interface.GetPixel(compiler, absolutePosition, constants),
                source2.Interface.GetPixel(compiler, absolutePosition, constants)
                ));
 }
Beispiel #5
0
        public void Compile(ShaderCompiler compiler, ShaderCompiler.Operand position, ShaderCompiler.Operand texCoord, ShaderCompiler.Operand[] attributes,
                            ShaderCompiler.Operand borderDistance, ShaderCompiler.Operand[] constants, ShaderCompiler.Operand outputColour)
        {
            ShaderCompiler.Operand texture = constants[0];
            ShaderCompiler.Operand sampler = constants[1];

            // We perform a sampling.
            compiler.Sample(sampler, texture, texCoord, outputColour);
        }
Beispiel #6
0
        ShaderCompiler.Operand ICompositeInterface.GetPixel(ShaderCompiler compiler,
                                                            ShaderCompiler.Operand absolutePosition, Dictionary <ICompositeInterface, ShaderCompiler.Operand[]> constants)
        {
            ShaderCompiler.Operand[] inputs = constants[this];
            ShaderCompiler.Operand   offset = compiler.CreateFixed(PinFormat.Integerx2, Pin.NotArray, new Vector2i(0, 0));

            return(compiler.Load(inputs[0], compiler.Expand(
                                     compiler.Convert(absolutePosition, PinFormat.Integerx2),
                                     PinFormat.Integerx3, ExpandType.AddZeros), offset));
        }
        ShaderCompiler.Operand ICompositeInterface.GetPixel(ShaderCompiler compiler,
                                                            ShaderCompiler.Operand absolutePosition, Dictionary <ICompositeInterface, ShaderCompiler.Operand[]> constants)
        {
            ShaderCompiler.Operand[] inputs = constants[this];

            return(compiler.Sample(inputs[1], inputs[0],
                                   compiler.CreateFixed(PinFormat.Floatx2, Pin.NotArray, new Vector2f(0, 0)),
                                   compiler.Mul(absolutePosition, inputs[2])
                                   ));
        }
Beispiel #8
0
        ShaderCompiler.Operand ICompositeInterface.GetPixel(ShaderCompiler compiler,
                                                            ShaderCompiler.Operand absolutePosition, Dictionary <ICompositeInterface, ShaderCompiler.Operand[]> constants)
        {
            ShaderCompiler.Operand[] inputs = constants[this];

            return(compiler.Add(
                       compiler.Mul(source1.Interface.GetPixel(compiler, absolutePosition, constants), inputs[0]),
                       compiler.Mul(source2.Interface.GetPixel(compiler, absolutePosition, constants), inputs[1])
                       ));
        }
Beispiel #9
0
 public override ShaderCompiler.Operand[] Compile(ShaderCompiler compiler, ShaderCompiler.Operand[] operands,
                                                  FixedShaderParameters parameters, ref DualShareContext shareContext)
 {
     ShaderCompiler.Operand dst = compiler.CreateTemporary(operands[1].Format, operands[1].ArraySize);
     compiler.BeginIf(operands[0]);
     compiler.Mov(operands[1], dst);
     compiler.Else();
     compiler.Mov(operands[2], dst);
     compiler.EndIf();
     return(new ShaderCompiler.Operand[] { dst });
 }
Beispiel #10
0
        public ShaderCompiler.Operand[] Compile(ShaderCompiler compiler, ShaderCompiler.Operand[] operands, FixedShaderParameters parameters, ref DualShareContext shareContext)
        {
            ShaderCompiler.Operand[] results = new ShaderCompiler.Operand[outputs.Count];

            // We simply emit descriptors.
            int i = 0;

            foreach (KeyValuePair <PinComponent, Pin> pair in outputs)
            {
                results[i++] = compiler.CreateInput(pair.Value.Format, pair.Key);
            }

            return(results);
        }
Beispiel #11
0
        public ShaderCompiler.Operand[] Compile(ShaderCompiler compiler, ShaderCompiler.Operand[] operands, FixedShaderParameters parameters, ref SharpMedia.Graphics.Shaders.Operations.DualShareContext shareContext)
        {
            // We obtain interfaces (CPU resolve).
            object[] interfaces = InterfaceHelper.ResolveInterfaceArray(inputs[4], parameters);

            // We first register all our "constants" (for fill IDs).
            ShaderCompiler.Operand[] integerConstants = new ShaderCompiler.Operand[interfaces.Length];
            for (int i = 0; i < integerConstants.Length; i++)
            {
                integerConstants[i] = compiler.CreateFixed(PinFormat.Integer, Pin.NotArray, i);
            }

            // We pack out "attributes".
            ShaderCompiler.Operand[] attributes = new ShaderCompiler.Operand[] { operands[2] };

            // We create output colour constant.
            ShaderCompiler.Operand outColour = compiler.CreateTemporary(PinFormat.Floatx4, Pin.NotArray);

            // We switch
            compiler.BeginSwitch(operands[3]);

            // We go through all interfaces.
            for (int i = 0; i < interfaces.Length; i++)
            {
                compiler.BeginCase(integerConstants[i]);

                // We cast to fill.
                IFill fill = interfaces[i] as IFill;

                ShaderCompiler.Operand[] constants =
                    InterfaceHelper.RegisterInterfaceConstants(compiler,
                                                               string.Format("Fills[{0}]", i), parameters, fill);

                fill.Compile(compiler, operands[0], operands[1], attributes, null, constants, outColour);

                compiler.EndCase();
            }

            // We also add "default" handler.
            compiler.BeginDefault();
            compiler.Mov(compiler.CreateFixed(PinFormat.Floatx4, Pin.NotArray, new Math.Vector4f(1.0f, 0.0f, 0.0f, 1.0f)),
                         outColour);
            compiler.EndCase();

            // And end switch.
            compiler.EndSwitch();

            return(new ShaderCompiler.Operand[] { outColour });
        }
        /// <summary>
        /// Registers parameters of interface.
        /// </summary>
        /// <param name="xname"></param>
        /// <param name="interface"></param>
        /// <returns></returns>
        public static ShaderCompiler.Operand[] RegisterInterfaceConstants(
            ShaderCompiler compiler, string xname,
            FixedShaderParameters parameters, IInterface @interface)
        {
            // We first extract interface parameters and register them
            ParameterDescription[]   descs     = @interface.AdditionalParameters;
            ShaderCompiler.Operand[] constants = new ShaderCompiler.Operand[descs.Length];
            for (int j = 0; j < descs.Length; j++)
            {
                ParameterDescription desc = descs[j];

                string name = string.Format("{0}.{1}", xname, desc.Name);

                if (desc.IsFixed)
                {
                    if (PinFormatHelper.IsTexture(desc.Pin.Format))
                    {
                        // We check the id.
                        uint regId = (uint)parameters[name];

                        constants[j] = compiler.CreateTexture(desc.Pin.Format, desc.Pin.TextureFormat, regId);
                    }
                    else if (desc.Pin.Format == PinFormat.Sampler)
                    {
                        uint regId = (uint)parameters[name];

                        constants[j] = compiler.CreateSampler(regId);
                    }
                    else
                    {
                        throw new NotImplementedException("Fixed data not yet implemented.");
                    }
                }
                else
                {
                    uint layoutID;

                    // If it is not fixed, we create constant.
                    uint offset = parameters.GetOffset(name, out layoutID);

                    constants[j] = compiler.CreateConstant(desc.Pin.Format, desc.Pin.Size, layoutID, offset);
                }
            }

            return(constants);
        }
Beispiel #13
0
        public void Compile(ShaderCompiler compiler, ShaderCompiler.Operand position, ShaderCompiler.Operand texCoord, ShaderCompiler.Operand[] attributes,
                            ShaderCompiler.Operand borderDistance, ShaderCompiler.Operand[] constants, ShaderCompiler.Operand outputColour)
        {
            ShaderCompiler.Operand radius      = constants[0];
            ShaderCompiler.Operand centerPos   = constants[1];
            ShaderCompiler.Operand colourInner = constants[2];
            ShaderCompiler.Operand colourOuter = constants[3];

            // We now compute the distance.
            // float dist = |centerPos-textCoord|;
            // float f = min(1.0f, dist);
            // return (1-f)*inner + f*outer;
            ShaderCompiler.Operand dist = compiler.Call(ShaderFunction.Length, compiler.Sub(centerPos, texCoord));
            ShaderCompiler.Operand f    = compiler.Min(dist, compiler.CreateFixed(PinFormat.Float, Pin.NotArray, 1.0f));
            compiler.Add(compiler.Mul(compiler.Sub(compiler.CreateFixed(PinFormat.Float, Pin.NotArray, 1.0f), f), colourInner),
                         compiler.Mul(f, colourOuter), outputColour);
        }
Beispiel #14
0
        public void Compile(ShaderCompiler compiler, ShaderCompiler.Operand position,
                            ShaderCompiler.Operand texCoord, ShaderCompiler.Operand[] attributes,
                            ShaderCompiler.Operand borderDistance, ShaderCompiler.Operand[] constants,
                            ShaderCompiler.Operand outputColour)
        {
            // 1) We copy attributes.
            ShaderCompiler.Operand[] att1 = new ShaderCompiler.Operand[fill1.CustomAttributeCount];
            ShaderCompiler.Operand[] att2 = new ShaderCompiler.Operand[fill2.CustomAttributeCount];

            for (int i = 0; i < att1.Length; i++)
            {
                att1[i] = attributes[i];
            }

            for (int i = 0; i < att2.Length; i++)
            {
                att2[i] = attributes[i + att1.Length];
            }

            // 2) We copy constants.
            ShaderCompiler.Operand[] const1 = new ShaderCompiler.Operand[fill1.AdditionalParameters.Length];
            ShaderCompiler.Operand[] const2 = new ShaderCompiler.Operand[fill2.AdditionalParameters.Length];

            for (int i = 0; i < const1.Length; i++)
            {
                const1[i] = constants[i];
            }

            for (int i = 0; i < const2.Length; i++)
            {
                const2[i] = constants[i + const1.Length];
            }

            // 3) We compute partial colours.
            ShaderCompiler.Operand colour1 = compiler.CreateTemporary(PinFormat.Floatx4, Pin.NotArray);
            ShaderCompiler.Operand colour2 = compiler.CreateTemporary(PinFormat.Floatx4, Pin.NotArray);

            fill1.Compile(compiler, position, texCoord, att1, borderDistance, const1, colour1);
            fill2.Compile(compiler, position, texCoord, att2, borderDistance, const2, colour2);

            // 4) We combine them.
            compiler.Mov(compiler.Add(compiler.Mul(compiler.Sub(compiler.CreateFixed(PinFormat.Float,
                                                                                     Pin.NotArray, 1.0f), constants[constants.Length - 1]), colour1),
                                      compiler.Mul(constants[constants.Length - 1], colour2)), outputColour);
        }
Beispiel #15
0
        public override void Compile(ShaderCompiler compiler, ShaderCompiler.Operand position, ShaderCompiler.Operand texCoord,
                                     ShaderCompiler.Operand[] attributes, ShaderCompiler.Operand borderDistance, ShaderCompiler.Operand[] constants, ShaderCompiler.Operand outputColour)
        {
            // We first bind to out names.
            ShaderCompiler.Operand colour0   = constants[0];
            ShaderCompiler.Operand colour1   = constants[1];
            ShaderCompiler.Operand colour2   = constants[2];
            ShaderCompiler.Operand colour3   = constants[3];
            ShaderCompiler.Operand position0 = constants[4];
            ShaderCompiler.Operand position1 = constants[5];
            ShaderCompiler.Operand scaling   = constants[6];
            ShaderCompiler.Operand one       = compiler.CreateFixed(PinFormat.Float, Pin.NotArray, 1.0f);

            // float t = texcoord.x + texcoord.y;
            // t = t - floor(t);
            ShaderCompiler.Operand scaled = compiler.Mul(scaling, compiler.Swizzle(texCoord, SwizzleMask.XY));
            ShaderCompiler.Operand t      = compiler.Add(compiler.Swizzle(scaled, SwizzleMask.X), compiler.Swizzle(scaled, SwizzleMask.Y));
            t = compiler.Sub(t, compiler.Call(ShaderFunction.Floor, t));

            // if( t < position0) {
            //   float f = t/pos0;
            //   outColour = f*c1 + (1.0-f)*c0;
            // } else {
            compiler.BeginIf(compiler.Compare(CompareFunction.LessEqual, t, position0));
            ShaderCompiler.Operand f = compiler.Div(t, position0);
            compiler.Mov(compiler.Add(compiler.Mul(f, colour1), compiler.Mul(compiler.Sub(one, f), colour0)), outputColour);
            compiler.Else();
            // if(t < position1)
            //   float f = (t-pos0)/(pos1-pos0);
            //   outColour = f*c2 + (1.0-f)*c1;
            // } else {
            compiler.BeginIf(compiler.Compare(CompareFunction.LessEqual, t, position1));
            f = compiler.Div(compiler.Sub(t, position0), compiler.Sub(position1, position0));
            compiler.Mov(compiler.Add(compiler.Mul(f, colour2), compiler.Mul(compiler.Sub(one, f), colour1)), outputColour);

            // else {
            //   float f = (t-pos1)/(1-pos1);
            //   outColour = f*c3 + (1.0-f)*c2;
            compiler.Else();
            f = compiler.Div(compiler.Sub(t, position1), compiler.Sub(one, position1));
            compiler.Mov(compiler.Add(compiler.Mul(f, colour3), compiler.Mul(compiler.Sub(one, f), colour2)), outputColour);

            compiler.EndIf();
            compiler.EndIf();
        }
Beispiel #16
0
 ShaderCompiler.Operand ICompositeInterface.GetPixel(SharpMedia.Graphics.Shaders.ShaderCompiler compiler,
                                                     ShaderCompiler.Operand absolutePosition, Dictionary <ICompositeInterface, ShaderCompiler.Operand[]> constants)
 {
     return(constants[this][0]);
 }
Beispiel #17
0
        public unsafe void DAGUsageCases()
        {
            // We first initialize our shader.
            ShaderCode code = new ShaderCode(BindingStage.VertexShader);

            {
                // We write a simple Tranform code:
                code.InputOperation.AddInput(PinComponent.Position, PinFormat.Floatx3);
                Pin positon = code.InputOperation.PinAsOutput(PinComponent.Position);

                // We first need to expand our position to float4 (adding 1 at the end).
                ExpandOperation expand = new ExpandOperation(PinFormat.Floatx4, ExpandType.AddOnesAtW);
                expand.BindInputs(positon);
                Pin expPosition = expand.Outputs[0];

                // We now create constant transform matrix.
                ConstantOperation mvpConstant = code.CreateConstant("MVP", PinFormat.Float4x4);
                Pin MVP = mvpConstant.Outputs[0];

                // We multiply matrix and pin.
                MultiplyOperation mul = new MultiplyOperation();
                mul.BindInputs(MVP, expPosition);
                Pin transPosition = mul.Outputs[0];

                // We just bind transformed position to output.
                code.OutputOperation.AddComponentAndLink(PinComponent.Position, transPosition);
            }

            // Immutate it.
            code.Immutable = true;


            // We create constant buffer manually.
            ConstantBufferLayoutBuilder builder = new ConstantBufferLayoutBuilder();

            builder.AppendElement("MVP", PinFormat.Float4x4, Pin.NotArray);
            ConstantBufferLayout layout = builder.CreateLayout();

            // We now fill the data.
            FixedShaderParameters parameters = code.FixedParameters;

            parameters.AppendLayout(layout);
            if (!parameters.IsDefined)
            {
                throw new Exception();
            }



            using (GraphicsDevice device = InitializeDevice())
            {
                // We create shaders.

                // We have all parameters defined, compile the shader.
                VShader shader = code.Compile(device, parameters) as VShader;

                // Shader expects data in constant buffers.
                TypelessBuffer     tbuffer        = new TypelessBuffer(Usage.Dynamic, BufferUsage.ConstantBuffer, CPUAccess.Write, GraphicsLocality.DeviceOrSystemMemory, 4 * 4 * 4);
                ConstantBufferView constantBuffer = tbuffer.CreateConstantBuffer(layout);

                // We fill the buffer.
                constantBuffer.Map(MapOptions.Write);
                constantBuffer.SetConstant("MVP", new Math.Matrix.Matrix4x4f(1, 0, 0, 0,
                                                                             0, 1, 0, 0,
                                                                             0, 0, 1, 0,
                                                                             -0.5f, -0.5f, 0, 1));
                constantBuffer.UnMap();

                PShader pshader;
                VShader vshader = shader;
                using (ShaderCompiler compiler = device.CreateShaderCompiler())
                {
                    // And pixel shader.
                    compiler.Begin(BindingStage.PixelShader);
                    ShaderCompiler.Operand colour = compiler.CreateFixed(PinFormat.Floatx4, Pin.NotArray, new Vector4f(1, 0, 0, 1));
                    compiler.Output(colour, PinComponent.RenderTarget0);
                    pshader = compiler.End(null) as PShader;
                }

                // We create triangles.
                Geometry       geometry = new Geometry();
                TypelessBuffer buffer   = new TypelessBuffer(Usage.Static,
                                                             BufferUsage.VertexBuffer, CPUAccess.None, GraphicsLocality.DeviceOrSystemMemory, 4 * 4 * 3);

                byte[] d = buffer.Map(MapOptions.Read);
                fixed(byte *p = d)
                {
                    float *data = (float *)p;

                    // Vertex 0:
                    data[0] = -0.5f; data[1] = -0.5f; data[2] = 0.0f; data[3] = 1.0f;

                    // Vertex 1:
                    data[4] = 0.5f; data[5] = -0.5f; data[6] = 0.0f; data[7] = 1.0f;

                    // Vertex 2:
                    data[8] = 0.0f; data[9] = 0.5f; data[10] = 0.0f; data[11] = 1.0f;
                }

                buffer.UnMap();


                // Create vertex buffer and view.
                VertexBufferView vbuffer = buffer.CreateVertexBuffer(VertexFormat.Parse("P.Fx4"));

                // We construct geometry.
                geometry[0]       = vbuffer;
                geometry.Topology = Topology.Triangle;

                // Blend state.
                BlendState blendState = new BlendState();
                blendState[0] = false;

                blendState = StateManager.Intern(blendState);

                RasterizationState rastState = new RasterizationState();
                rastState.CullMode = CullMode.None;
                rastState.FillMode = FillMode.Solid;

                rastState = StateManager.Intern(rastState);

                DepthStencilState depthState = new DepthStencilState();
                depthState.DepthTestEnabled  = false;
                depthState.DepthWriteEnabled = false;

                depthState = StateManager.Intern(depthState);

                // Enter rendering loop.
                bool isClosed = false;
                window.Closed += delegate(Window w)
                {
                    isClosed = true;
                };

                for (uint i = 0; i < 1000; i++)
                {
                    window.DoEvents();

                    if (!isClosed)
                    {
                        SwapChain chain = device.SwapChain;

                        device.Enter();
                        try
                        {
                            // We just clear.
                            device.Clear(chain, Colour.Black);

                            // Set blend/rast.
                            device.SetBlendState(blendState, Colour.White, 0xFFFFFFFF);
                            device.RasterizationState = rastState;
                            device.SetDepthStencilState(depthState, 0);

                            // Sets states.
                            device.SetVertexShader(vshader, geometry, null, null, new ConstantBufferView[] { constantBuffer });
                            device.SetPixelShader(pshader, null, null, null, new RenderTargetView[] { chain }, null);

                            device.Viewport = new Region2i(0, 0, (int)chain.Width, (int)chain.Height);

                            // Render.
                            device.Draw(0, 3);
                        }
                        finally
                        {
                            device.Exit();
                        }

                        chain.Present();
                        //Thread.Sleep(10);

                        Console.WriteLine(device.DevicePerformance.CurrentFPS);
                    }
                }


                // Dispose all.
                vshader.Dispose();
                pshader.Dispose();
                geometry.Dispose();
                vbuffer.Dispose();
                buffer.Dispose();
            }
        }
Beispiel #18
0
        public unsafe void TriangleTest()
        {
            using (GraphicsDevice device = InitializeDevice())
            {
                // We create shaders.
                VShader vshader;
                PShader pshader;
                using (ShaderCompiler compiler = device.CreateShaderCompiler())
                {
                    // Vertex shader (copy paste position).
                    compiler.Begin(BindingStage.VertexShader);
                    ShaderCompiler.Operand position = compiler.CreateInput(PinFormat.Floatx4, PinComponent.Position);
                    compiler.Output(position, PinComponent.Position);
                    vshader = compiler.End(null) as VShader;

                    // And pixel shader.
                    compiler.Begin(BindingStage.PixelShader);
                    ShaderCompiler.Operand colour = compiler.CreateFixed(PinFormat.Floatx4, Pin.NotArray, new Vector4f(1, 0, 0, 1));
                    compiler.Output(colour, PinComponent.RenderTarget0);
                    pshader = compiler.End(null) as PShader;
                }

                // We create triangles.
                Geometry       geometry = new Geometry();
                TypelessBuffer buffer   = new TypelessBuffer(Usage.Static,
                                                             BufferUsage.VertexBuffer, CPUAccess.None, GraphicsLocality.DeviceOrSystemMemory, 4 * 4 * 3);

                byte[] d = buffer.Map(MapOptions.Read);
                fixed(byte *p = d)
                {
                    float *data = (float *)p;

                    // Vertex 0:
                    data[0] = -0.5f; data[1] = -0.5f; data[2] = 0.0f; data[3] = 1.0f;

                    // Vertex 1:
                    data[4] = 0.5f; data[5] = -0.5f; data[6] = 0.0f; data[7] = 1.0f;

                    // Vertex 2:
                    data[8] = 0.0f; data[9] = 0.5f; data[10] = 0.0f; data[11] = 1.0f;
                }

                buffer.UnMap();


                // Create vertex buffer and view.
                VertexBufferView vbuffer = buffer.CreateVertexBuffer(VertexFormat.Parse("P.Fx4"));

                // We construct geometry.
                geometry[0]       = vbuffer;
                geometry.Topology = Topology.Triangle;

                // Blend state.
                BlendState blendState = new BlendState();
                blendState[0] = false;

                blendState = StateManager.Intern(blendState);

                RasterizationState rastState = new RasterizationState();
                rastState.CullMode = CullMode.None;
                rastState.FillMode = FillMode.Solid;

                rastState = StateManager.Intern(rastState);

                DepthStencilState depthState = new DepthStencilState();
                depthState.DepthTestEnabled  = false;
                depthState.DepthWriteEnabled = false;

                depthState = StateManager.Intern(depthState);

                // Enter rendering loop.
                bool isClosed = false;
                window.Closed += delegate(Window w)
                {
                    isClosed = true;
                };

                while (!isClosed)
                {
                    window.DoEvents();

                    if (!isClosed)
                    {
                        SwapChain chain = device.SwapChain;

                        device.Enter();
                        try
                        {
                            // We just clear.
                            device.Clear(chain, Colour.Black);

                            // Set blend/rast.
                            device.SetBlendState(blendState, Colour.White, 0xFFFFFFFF);
                            device.RasterizationState = rastState;
                            device.SetDepthStencilState(depthState, 0);

                            // Sets states.
                            device.SetVertexShader(vshader, geometry, null, null, null);
                            device.SetPixelShader(pshader, null, null, null, new RenderTargetView[] { chain }, null);

                            device.Viewport = new Region2i(0, 0, (int)chain.Width, (int)chain.Height);

                            // Render.
                            device.Draw(0, 3);
                        }
                        finally
                        {
                            device.Exit();
                        }

                        chain.Present();
                        Thread.Sleep(10);
                    }
                }


                // Dispose all.
                vshader.Dispose();
                pshader.Dispose();
                geometry.Dispose();
                vbuffer.Dispose();
                buffer.Dispose();
            }
        }
Beispiel #19
0
 ShaderCompiler.Operand ICompositeInterface.GetPixel(ShaderCompiler compiler,
                                                     ShaderCompiler.Operand absolutePosition, Dictionary <ICompositeInterface, ShaderCompiler.Operand[]> constants)
 {
     return(source.Interface.GetPixel(compiler, compiler.Mul(absolutePosition, constants[this][0]),
                                      constants));
 }
Beispiel #20
0
 public abstract void Compile(ShaderCompiler compiler, ShaderCompiler.Operand position, ShaderCompiler.Operand texCoord,
                              ShaderCompiler.Operand[] attributes, ShaderCompiler.Operand borderDistance, ShaderCompiler.Operand[] constants,
                              ShaderCompiler.Operand outputColour);