Esempio n. 1
0
        void CreateDeviceObjects()
        {
            // set up a commandlist
            commandList = context.CommandList;

            // compile de shader
            imShader = new EffectInstance(effectSystem.LoadEffect("ImGuiShader").WaitForResult());
            imShader.UpdateEffect(device);

            var layout = new VertexDeclaration(
                VertexElement.Position <Vector2>(),
                VertexElement.TextureCoordinate <Vector2>(),
                VertexElement.Color(PixelFormat.R8G8B8A8_UNorm)
                );

            imVertLayout = layout;

            // de pipeline desc
            var pipeline = new PipelineStateDescription()
            {
                BlendState = BlendStates.NonPremultiplied,

                RasterizerState = new RasterizerStateDescription()
                {
                    CullMode  = CullMode.None,
                    DepthBias = 0,
                    FillMode  = FillMode.Solid,
                    MultisampleAntiAliasLine = false,
                    ScissorTestEnable        = true,
                    SlopeScaleDepthBias      = 0,
                },

                PrimitiveType     = PrimitiveType.TriangleList,
                InputElements     = imVertLayout.CreateInputElements(),
                DepthStencilState = DepthStencilStates.Default,

                EffectBytecode = imShader.Effect.Bytecode,
                RootSignature  = imShader.RootSignature,

                Output = new RenderOutputDescription(PixelFormat.R8G8B8A8_UNorm)
            };

            // finally set up the pipeline
            var pipelineState = PipelineState.New(device, ref pipeline);

            imPipeline = pipelineState;

            var is32Bits           = false;
            var indexBuffer        = Xenko.Graphics.Buffer.Index.New(device, INITIAL_INDEX_BUFFER_SIZE * sizeof(ushort), GraphicsResourceUsage.Dynamic);
            var indexBufferBinding = new IndexBufferBinding(indexBuffer, is32Bits, 0);

            indexBinding = indexBufferBinding;

            var vertexBuffer        = Xenko.Graphics.Buffer.Vertex.New(device, INITIAL_VERTEX_BUFFER_SIZE * imVertLayout.CalculateSize(), GraphicsResourceUsage.Dynamic);
            var vertexBufferBinding = new VertexBufferBinding(vertexBuffer, layout, 0);

            vertexBinding = vertexBufferBinding;
        }
Esempio n. 2
0
        //private Matrix viewprojection = new Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);


        protected override void InitializeCore()
        {
            base.InitializeCore();
            myCustomShader = new DynamicEffectInstance("test_shader1");
            myCustomShader.Initialize(Context.Services);
            pipelineState = new MutablePipelineState(Context.GraphicsDevice);
            pipelineState.State.SetDefaults();
            pipelineState.State.InputElements            = VertexDeclaration.CreateInputElements();
            pipelineState.State.PrimitiveType            = PrimitiveType.TriangleStrip;
            pipelineState.State.BlendState               = BlendStates.Default;
            pipelineState.State.RasterizerState.CullMode = CullMode.None;
        }
Esempio n. 3
0
            public DeviceResourceContext(GraphicsDevice device, VertexDeclaration declaration, ResourceBufferInfo resourceBufferInfo)
            {
                VertexDeclaration    = declaration;
                VertexCount          = resourceBufferInfo.VertexCount;
                IndexCount           = resourceBufferInfo.IndexCount;
                IsIndexBufferDynamic = resourceBufferInfo.IsIndexBufferDynamic;

                if (!IsIndexBufferDynamic)
                {
                    IndexBuffer        = Buffer.Index.New(device, resourceBufferInfo.StaticIndices).DisposeBy(this);
                    IndexBuffer.Reload = graphicsResource => ((Buffer)graphicsResource).Recreate(resourceBufferInfo.StaticIndices);
                }

                InputElements = declaration.CreateInputElements();
            }
Esempio n. 4
0
        private void Init()
        {
            _tribuf = Buffer.New(GraphicsDevice, new[]
            {
                new Vector4(-0.5f, 0.5f, 0, 1),
                new Vector4(0.5f, 0.5f, 0, 1),
                new Vector4(0, -0.5f, 0, 1)
            }, BufferFlags.VertexBuffer, GraphicsResourceUsage.Immutable);

            simpleEffect = new EffectInstance(new Effect(GraphicsDevice, SpriteEffect.Bytecode));
            simpleEffect.Parameters.Set(SpriteBaseKeys.MatrixTransform, Matrix.Identity);
            simpleEffect.UpdateEffect(GraphicsDevice);

            pipelineState = new MutablePipelineState(GraphicsDevice);
            pipelineState.State.SetDefaults();
            pipelineState.State.InputElements = VertexDeclaration.CreateInputElements();
            pipelineState.State.PrimitiveType = PrimitiveType;
        }