コード例 #1
0
ファイル: SampleWindow.cs プロジェクト: acaly/ImGuiOnLightDx
        public void Run()
        {
            using (var form = new Form())
            {
                _form           = form;
                form.Text       = "ImGui.NET on LightDx";
                form.ClientSize = new Size(800, 600);
                form.KeyDown   += OnKeyDown;
                form.KeyUp     += OnKeyUp;

                using (var device = LightDevice.Create(form))
                {
                    _device = device;

                    var target = new RenderTarget(device.GetDefaultTarget());
                    target.Apply();

                    Pipeline pipeline = device.CompilePipeline(InputTopology.Triangle,
                                                               ShaderSource.FromResource("Shader.fx", ShaderType.Vertex | ShaderType.Pixel));;
                    _pipeline = pipeline;

                    pipeline.SetResource(0, CreateFontTexture());
                    pipeline.SetBlender(Blender.AlphaBlender);

                    pipeline.Apply();

                    var input = pipeline.CreateVertexDataProcessor <Vertex>();
                    _inputDataProcessor = input;

                    var constant = pipeline.CreateConstantBuffer <VSConstant>();
                    pipeline.SetConstant(ShaderType.Vertex, 0, constant);

                    void UpdateWindowSize()
                    {
                        constant.Value.Width  = device.ScreenWidth;
                        constant.Value.Height = device.ScreenHeight;
                        constant.Update();
                    }

                    device.ResolutionChanged += (sender, e) => UpdateWindowSize();
                    UpdateWindowSize();

                    form.Show();
                    device.RunLoop(delegate()
                    {
                        target.ClearAll();

                        RenderFrame();

                        device.Present(true);
                    });
                }
            }
        }
コード例 #2
0
        private void InitializeRendering()
        {
            _renderWindow = new Form();
            _renderWindow.FormBorderStyle = FormBorderStyle.None;
            _renderWindow.TopLevel        = false;
            _renderWindow.Parent          = this;
            _renderWindow.Dock            = DockStyle.Fill;
            _renderWindow.Show();

            _device            = LightDevice.Create(_renderWindow);
            _device.AutoResize = false; //We don't use loop, so AutoResize is not checked.

            _spriteDebug = new Sprite(_device);
            _spriteFont  = new TextureFontCache(_device, SystemFonts.DefaultFont);

            _target = new RenderTargetList(_device.GetDefaultTarget(Color.AliceBlue.WithAlpha(1)), _device.CreateDepthStencilTarget());
            _target.Apply();

            _modelPipeline = _device.CompilePipeline(InputTopology.Point,
                                                     ShaderSource.FromResource("Model.fx", ShaderType.Vertex | ShaderType.Geometry | ShaderType.Pixel));
            _inputProcessor = _modelPipeline.CreateVertexDataProcessor <Voxel>();

            _vsConstant = _modelPipeline.CreateConstantBuffer <Matrix4x4>();
            _modelPipeline.SetConstant(ShaderType.Vertex, 0, _vsConstant);
            _gsConstant = _modelPipeline.CreateConstantBuffer <GSConstant>();
            _modelPipeline.SetConstant(ShaderType.Geometry, 0, _gsConstant);

            _camera = new Camera(_device, new Vector3(0, 0, 0));
            _camera.SetForm(_renderWindow);

            _renderWindowLastWidth  = _renderWindow.ClientSize.Width;
            _renderWindowLastHeight = _renderWindow.ClientSize.Height;
            ResizeBegin            += RenderWindow_ResizeBegin;
            ResizeEnd += RenderWindow_ResizeEnd;
            _renderWindow.ResizeBegin       += RenderWindow_ResizeBegin;
            _renderWindow.ResizeEnd         += RenderWindow_ResizeEnd;
            _renderWindow.ClientSizeChanged += RenderWindow_ClientSizeChanged;

            _renderWindow.DoubleClick += delegate(object obj, EventArgs e)
            {
                ResetCamera();
            };
        }
コード例 #3
0
ファイル: Pipeline.cs プロジェクト: acaly/LightDx
        public unsafe VertexDataProcessor <T> CreateVertexDataProcessor <T>()
            where T : unmanaged
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("Pipeline");
            }
            var layoutDecl = VertexDataProcessor <T> .CreateLayoutFromType(0);

            using (var layout = new ComScopeGuard())
            {
                fixed(InputElementDescription *d = layoutDecl)
                {
                    Device.CreateInputLayout(_device.DevicePtr, d, (uint)layoutDecl.Length,
                                             Blob.GetBufferPointer(_signatureBlob), Blob.GetBufferSize(_signatureBlob), out layout.Ptr).Check();
                }

                return(new VertexDataProcessor <T>(_device, layout.Move()));
            }
        }
コード例 #4
0
        public Sprite(LightDevice device)
        {
            _device = device;
            device.AddComponent(this);

            _pipeline = device.CompilePipeline(InputTopology.Triangle,
                                               ShaderSource.FromString(PipelineCode, ShaderType.Vertex | ShaderType.Pixel));
            _pipeline.SetBlender(Blender.AlphaBlender);

            _vertexProcessor = _pipeline.CreateVertexDataProcessor <Vertex>();
            _array           = new[] {
                new Vertex {
                    TexCoord = new Vector4(0, 0, 0, 0), Position = new Vector4(0, 0, 0, 0)
                },
                new Vertex {
                    TexCoord = new Vector4(1, 0, 0, 0), Position = new Vector4(1, 0, 0, 0)
                },
                new Vertex {
                    TexCoord = new Vector4(0, 1, 0, 0), Position = new Vector4(0, 1, 0, 0)
                },

                new Vertex {
                    TexCoord = new Vector4(0, 1, 0, 0), Position = new Vector4(0, 1, 0, 0)
                },
                new Vertex {
                    TexCoord = new Vector4(1, 0, 0, 0), Position = new Vector4(1, 0, 0, 0)
                },
                new Vertex {
                    TexCoord = new Vector4(1, 1, 0, 0), Position = new Vector4(1, 1, 0, 0)
                },
            };
            _buffer = _vertexProcessor.CreateDynamicBuffer(6);

            _constant = _pipeline.CreateConstantBuffer <VSConstant>();
            _pipeline.SetConstant(ShaderType.Vertex, 0, _constant);
        }