コード例 #1
0
        private void DrawOffscreen()
        {
            _cl.SetFramebuffer(_offscreenFB);
            _cl.SetFullViewports();
            _cl.ClearColorTarget(0, RgbaFloat.Black);
            _cl.ClearDepthStencil(1f);

            _cl.SetPipeline(_offscreenPipeline);
            _cl.SetGraphicsResourceSet(0, _offscreenResourceSet);
            _cl.SetVertexBuffer(0, _dragonModel.VertexBuffer);
            _cl.SetIndexBuffer(_dragonModel.IndexBuffer, IndexFormat.UInt32);
            _cl.DrawIndexed(_dragonModel.IndexCount, 1, 0, 0, 0);
        }
コード例 #2
0
        protected override void Draw(float deltaSeconds)
        {
            UpdateAnimation(deltaSeconds);
            UpdateUniforms();
            _cl.Begin();
            _cl.SetFramebuffer(GraphicsDevice.SwapchainFramebuffer);
            _cl.ClearColorTarget(0, RgbaFloat.Black);
            _cl.ClearDepthStencil(1f);

            Matrix4x4 worldMatrix =
                Matrix4x4.CreateTranslation(0, 15000, -5000)
                * Matrix4x4.CreateRotationX(3 * (float)Math.PI / 2)
                * Matrix4x4.CreateScale(0.05f);

            _cl.UpdateBuffer(_worldBuffer, 0, ref worldMatrix);

            DrawMesh();

            worldMatrix =
                Matrix4x4.CreateTranslation(0, 15000, -5000)
                * Matrix4x4.CreateRotationX(3 * (float)Math.PI / 2)
                * Matrix4x4.CreateScale(0.07f);

            _cl.UpdateBuffer(_worldBuffer, 0, ref worldMatrix);
            DrawMesh();

            _cl.End();

            GraphicsDevice.SubmitCommands(_cl);
            GraphicsDevice.SwapBuffers();
        }
コード例 #3
0
ファイル: Sdl2Renderer.cs プロジェクト: darkfriend77/wom
        public void Tick()
        {
            if (!_window.Exists)
            {
                _runner.Shutdown();
                return;
            }

            _cl.Begin();

            _cl.SetFramebuffer(MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, RgbaFloat.Black);
            _cl.ClearDepthStencil(1f);
            _cl.SetPipeline(_pipeline);

            LastInput = _window.PumpEvents();
            if (_windowResized)
            {
                _windowResized = false;
                _gd.ResizeMainWindow((uint)_window.Width, (uint)_window.Height);
            }

            Render?.Invoke(_gd, _cl);

            _cl.End();
            GraphicsDevice.SubmitCommands(_cl);
            GraphicsDevice.SwapBuffers(MainSwapchain);
            GraphicsDevice.WaitForIdle();
        }
コード例 #4
0
        private static void Draw()
        {
            ticks = ticks + 0.0001f;
            _commandList.Begin();

            _commandList.UpdateBuffer(_projectionBuffer, 0, Matrix4x4.CreatePerspectiveFieldOfView(
                                          1.0f,
                                          (float)Width / Height,
                                          0.5f,
                                          100f
                                          ));

            _commandList.UpdateBuffer(_viewBuffer, 0, Matrix4x4.CreateLookAt(Vector3.UnitZ * 2.5f, Vector3.Zero, Vector3.UnitY));

            Matrix4x4 rotation = Matrix4x4.CreateFromAxisAngle(Vector3.UnitY, ticks) * Matrix4x4.CreateFromAxisAngle(Vector3.UnitX, ticks);

            _commandList.UpdateBuffer(_worldBuffer, 0, ref rotation);

            _commandList.SetFramebuffer(_graphicsDevice.MainSwapchain.Framebuffer);
            _commandList.ClearColorTarget(0, RgbaFloat.Red);
            _commandList.ClearDepthStencil(1f);
            _commandList.SetPipeline(_pipeline);
            _commandList.SetVertexBuffer(0, _vertexBuffer);
            _commandList.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16);
            _commandList.SetGraphicsResourceSet(0, _projViewSet);
            _commandList.SetGraphicsResourceSet(1, _worldTextureSet);
            _commandList.DrawIndexed(36, 1, 0, 0, 0);

            _commandList.End();
            _graphicsDevice.SubmitCommands(_commandList);
            _graphicsDevice.SwapBuffers(_graphicsDevice.MainSwapchain);
            _graphicsDevice.WaitForIdle();
        }
コード例 #5
0
        private RgbaByte RenderQuad(Veldrid.Shader[] shaders)
        {
            using (var pipeline = ResourceFactory.CreateGraphicsPipeline(new GraphicsPipelineDescription(
                                                                             BlendStateDescription.SingleOverrideBlend,
                                                                             DepthStencilStateDescription.DepthOnlyLessEqual,
                                                                             RasterizerStateDescription.CullNone,
                                                                             PrimitiveTopology.TriangleStrip,
                                                                             new ShaderSetDescription(new VertexLayoutDescription[0], shaders),
                                                                             new ResourceLayout[0],
                                                                             Framebuffer.OutputDescription
                                                                             )))
            {
                CommandList.Begin();
                CommandList.SetFramebuffer(Framebuffer);
                CommandList.SetFullViewports();
                CommandList.ClearColorTarget(0, RgbaFloat.Black);
                CommandList.ClearDepthStencil(1);
                CommandList.SetPipeline(pipeline);
                CommandList.Draw(4);
                CommandList.End();

                GraphicsDevice.SubmitCommands(CommandList);
                GraphicsDevice.WaitForIdle();

                var readRenderTargetPixel = ReadRenderTargetPixel();
                return(readRenderTargetPixel);
            }
        }
コード例 #6
0
        private void Record(GraphicsDevice device, ResourceFactory factory)
        {
            if (!_initialized)
            {
                Initialize(device, factory);
            }

            // Begin() must be called before commands can be issued.
            _commandList.Begin();

            // We want to render directly to the output window.
            _commandList.SetFramebuffer(Framebuffer);

            // TODO Set from Camera color ?
            _commandList.ClearColorTarget(0, RgbaFloat.Grey);
            _commandList.ClearDepthStencil(1f);

            //
            // Draw Opaque Geometry
            //
            DrawOpaqueRenderGroups(device, factory);

            //
            // Draw Transparent Geometry
            //
            if (_cullVisitor.TransparentRenderGroup.HasDrawableElements())
            {
                DrawTransparentRenderGroups(device, factory);
            }

            _commandList.End();
        }
コード例 #7
0
        public void Render(CommandList cl, ISystemComponents systemComponents)
        {
            var framebuffer = systemComponents.Device.SwapchainFramebuffer;

            _drawStageModel.ClearDynamicDrawQueue();

            CalculateAndDraw((int)framebuffer.Width, (int)framebuffer.Height);

            _drawStageModel.Process();

            cl.SetFramebuffer(framebuffer);

            cl.ClearDepthStencil(1.0f);

            var surface = new GpuSurface
            {
                Type                  = GpuSurfaceType.SwapChainOutput,
                Framebuffer           = framebuffer,
                Texture               = null,
                TextureView           = null,
                ResourceSet_TexMirror = null,
                ResourceSet_TexWrap   = null
            };

            _drawStageRenderer.Render(cl, _drawStageModel, surface, _camera);
        }
コード例 #8
0
        protected void Draw(float deltaSeconds)
        {
            _ticks += deltaSeconds * 1000f;
            _cl.Begin();

            //_cl.UpdateBuffer(_projectionBuffer, 0, Matrix4x4.CreatePerspectiveFieldOfView(
            //  1.0f,
///                (float)Window.Width / Window.Height,
            //0.5f,
            //100f));

            _cl.UpdateBuffer(_viewBuffer, 0, Matrix4x4.CreateLookAt(Vector3.UnitZ * 2.5f, Vector3.Zero, Vector3.UnitY));

            Matrix4x4 rotation =
                Matrix4x4.CreateFromAxisAngle(Vector3.UnitY, (_ticks / 1000f))
                * Matrix4x4.CreateFromAxisAngle(Vector3.UnitX, (_ticks / 3000f));

            _cl.UpdateBuffer(_worldBuffer, 0, ref rotation);

            //_cl.SetFramebuffer(MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, RgbaFloat.Black);
            _cl.ClearDepthStencil(1f);
            _cl.SetPipeline(_pipeline);
            _cl.SetVertexBuffer(0, _vertexBuffer);
            _cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16);
            _cl.SetGraphicsResourceSet(0, _projViewSet);
            _cl.SetGraphicsResourceSet(1, _worldTextureSet);
            _cl.DrawIndexed(36, 1, 0, 0, 0);

            _cl.End();
            //VeldridGL.graphicsDevice.SubmitCommands(_cl);
            //VeldridGL.graphicsDevice.SwapBuffers(MainSwapchain);
            //VeldridGL.graphicsDevice.WaitForIdle();
        }
コード例 #9
0
        private void _Submit()
        {
            this.CopyTo(_IndexedVertexBuffer); // in VR, we should do this just once.

            if (_Ext_CommandList != null)
            {
                _Submit(_Ext_CommandList);
                return;
            }

            _CommandList.Begin();
            _CommandList.SetFramebuffer(_Ext_FrameBuffer);

            if (_FillColor.HasValue)
            {
                var color = _FillColor.Value;
                var c     = new RgbaFloat(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f);
                _CommandList.ClearColorTarget(0, c);
            }

            // if (_FrameBuffer.DepthTarget != null)
            _CommandList.ClearDepthStencil(1);

            _Submit(_CommandList);

            _CommandList.End();
            _Factory.GraphicsDevice.SubmitCommands(_CommandList);
        }
コード例 #10
0
 public void StartSwapchainPass()
 {
     CommandList.SetFramebuffer(GraphicsDevice.SwapchainFramebuffer);
     CommandList.SetFullViewports();
     CommandList.SetFullScissorRects();
     CommandList.ClearColorTarget(0, _clearColour);
     CommandList.ClearDepthStencil(GraphicsDevice.IsDepthRangeZeroToOne ? 1f : 0f);
 }
コード例 #11
0
        //自转
        protected override void Draw(float deltaSeconds)
        {
            //地球自转的速度为
            var selfrockRate = 0.00007292;


            //_controller.Update(1f / 60f, InputTracker.FrameSnapshot);
            //_fta.AddTime(deltaSeconds);
            //SubmitUI();
            _ticks += deltaSeconds * 1000f;
            _cl.Begin();

            //投影矩阵
            var prj = _camera.ProjectionMatrix;

            var view =
                _camera.ViewMatrix;


            Matrix4x4 rotation =
                Matrix4x4.CreateFromAxisAngle(-Vector3.UnitY, (float)(_ticks / 10 * selfrockRate));
            //这里矩阵的定义和后者是有区别的,numberic中是行列,glsl中是列行,因此这里需要反向计算
            //            < pre >
            // *m[offset + 0] m[offset + 4] m[offset + 8] m[offset + 12]
            //* m[offset + 1] m[offset + 5] m[offset + 9] m[offset + 13]
            //* m[offset + 2] m[offset + 6] m[offset + 10] m[offset + 14]
            //* m[offset + 3] m[offset + 7] m[offset + 11] m[offset + 15] </ pre >

            //glsl是列主序,C#是行主序,虽然有所差异,但是并不需要装置,glsl中的第一行实际上就是传入矩阵的第一列,此列刚好能参与计算并返回正常值。
            //设置视点位置为2,2,2 ,target 为在0.2,0.2,0
            var eyePosition = _camera.Position;

            _ubo.prj                 = view * prj;
            _ubo.CameraEye           = eyePosition;
            _ubo.CameraEyeSquared    = eyePosition * eyePosition;
            _ubo.CameraLightPosition = eyePosition;

            _cl.UpdateBuffer(_projectionBuffer, 0, _ubo);

            _cl.SetFramebuffer(MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, RgbaFloat.Black);
            _cl.ClearDepthStencil(1f);

            _cl.SetPipeline(_pipeline);
            _cl.SetVertexBuffer(0, _vertexBuffer);
            _cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16);
            _cl.SetGraphicsResourceSet(0, _projViewSet);
            _cl.SetGraphicsResourceSet(1, _worldTextureSet);
            _cl.DrawIndexed((uint)_indices.Length, 1, 0, 0, 0);
            _controller.Render(GraphicsDevice, _cl);
            _cl.End();
            GraphicsDevice.SubmitCommands(_cl);

            GraphicsDevice.SwapBuffers(MainSwapchain);
            GraphicsDevice.WaitForIdle();
        }
コード例 #12
0
ファイル: FramebufferTests.cs プロジェクト: yvanoff/veldrid
        public void ClearSwapchainFramebuffer_Succeeds()
        {
            CommandList cl = RF.CreateCommandList();

            cl.Begin();
            cl.SetFramebuffer(GD.SwapchainFramebuffer);
            cl.ClearColorTarget(0, RgbaFloat.Red);
            cl.ClearDepthStencil(1f);
            cl.End();
        }
コード例 #13
0
ファイル: Camera.cs プロジェクト: Chapmania/Juniper
        public void Clear(CommandList commandList)
        {
            if (commandList is null)
            {
                throw new ArgumentNullException(nameof(commandList));
            }

            commandList.ClearColorTarget(0, ClearColor);
            commandList.ClearDepthStencil(1);
        }
コード例 #14
0
 protected override void BeginRender(CommandList cl)
 {
     cl.Begin();
     cl.SetFramebuffer(activeCamera.RenderTarget);
     cl.SetFullViewport(0);
     if (shouldClearBuffers)
     {
         cl.ClearColorTarget(0, Utils.ColorF.DarkGrey);
         cl.ClearDepthStencil(1f);
     }
 }
コード例 #15
0
        public void StartMainPass()
        {
            CommandList.SetFramebuffer(SceneContext.MainSceneFramebuffer);
            var fbWidth  = SceneContext.MainSceneFramebuffer.Width;
            var fbHeight = SceneContext.MainSceneFramebuffer.Height;

            CommandList.SetViewport(0, new Viewport(0, 0, fbWidth, fbHeight, 0, 1));
            CommandList.SetFullViewports();
            CommandList.SetFullScissorRects();
            CommandList.ClearColorTarget(0, _clearColour);
            CommandList.ClearDepthStencil(GraphicsDevice.IsDepthRangeZeroToOne ? 1f : 0f);
        }
コード例 #16
0
ファイル: FramebufferTests.cs プロジェクト: yvanoff/veldrid
        public void NoDepthTarget_ClearDepth_Fails()
        {
            Texture colorTarget = RF.CreateTexture(
                TextureDescription.Texture2D(1024, 1024, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget));
            Framebuffer fb = RF.CreateFramebuffer(new FramebufferDescription(null, colorTarget));

            CommandList cl = RF.CreateCommandList();

            cl.Begin();
            cl.SetFramebuffer(fb);
            Assert.Throws <VeldridException>(() => cl.ClearDepthStencil(1f));
        }
コード例 #17
0
		public void Draw()
		{
			if (!Ready)
			{
				return;
			}

			CommandList.Begin();

			CurrentTime = DateTime.Now;
			if (Animate)
			{
				double radians = Convert.ToDouble((CurrentTime - PreviousTime).TotalMilliseconds / 10.0);
				float degrees = Convert.ToSingle(radians * (System.Math.PI / 180.0));
				degrees *= Speed;

				ModelMatrix *= Matrix4x4.CreateFromAxisAngle(
					new Vector3(0, 0, _direction),
					degrees);
			}
			PreviousTime = CurrentTime;
			CommandList.UpdateBuffer(ModelBuffer, 0, ModelMatrix);

			CommandList.SetFramebuffer(Surface.Swapchain.Framebuffer);

			// These commands differ from the stock Veldrid "Getting Started"
			// tutorial in two ways. First, the viewport is cleared to pink
			// instead of black so as to more easily distinguish between errors
			// in creating a graphics context and errors drawing vertices within
			// said context. Second, this project creates its swapchain with a
			// depth buffer, and that buffer needs to be reset at the start of
			// each frame.
			CommandList.ClearColorTarget(0, RgbaFloat.Pink);
			CommandList.ClearDepthStencil(1.0f);

			CommandList.SetVertexBuffer(0, VertexBuffer);
			CommandList.SetIndexBuffer(IndexBuffer, IndexFormat.UInt16);
			CommandList.SetPipeline(Pipeline);
			CommandList.SetGraphicsResourceSet(0, ModelMatrixSet);

			CommandList.DrawIndexed(
				indexCount: 4,
				instanceCount: 1,
				indexStart: 0,
				vertexOffset: 0,
				instanceStart: 0);

			CommandList.End();

			Surface.GraphicsDevice.SubmitCommands(CommandList);
			Surface.GraphicsDevice.SwapBuffers(Surface.Swapchain);
		}
コード例 #18
0
        private void VeldridControlOnRendering()
        {
            _cl.Begin();
            _cl.SetFramebuffer(_veldridControl.MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, _clearColors[_frameIndex / _frameRepeatCount]);
            _cl.ClearDepthStencil(1);
            _cl.End();
            _veldridControl.GraphicsDevice.SubmitCommands(_cl);
            _veldridControl.GraphicsDevice.SwapBuffers(_veldridControl.MainSwapchain);

            // Do some math to loop our color picker index.
            _frameIndex = (_frameIndex + 1) % (_clearColors.Length * _frameRepeatCount);
        }
コード例 #19
0
        private void Draw(float deltaSeconds)
        {
            VeldridGeometry mesh = new VeldridGeometry();

            _cl.Begin();
            _cl.SetFramebuffer(MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, RgbaFloat.LightGrey);
            _cl.ClearDepthStencil(1f);

            _cl.End();
            GraphicsDevice.SubmitCommands(_cl);
            GraphicsDevice.SwapBuffers(MainSwapchain);
            GraphicsDevice.WaitForIdle();
        }
コード例 #20
0
ファイル: VxContext.cs プロジェクト: mellinoe/Vx
        private void FlushFrame()
        {
            InputSnapshot input = Window.PumpEvents();

            VxInput.UpdateFrameInput(input);

            if (!Window.Exists)
            {
                return;
            }
            _cl.Begin();
            _cl.SetFramebuffer(Device.MainSwapchain.Framebuffer);
            _cl.ClearDepthStencil(Device.IsDepthRangeZeroToOne ? 0f : 1f);
            _cl.ClearColorTarget(0, ClearColor);

            Vector3   cameraLookDir = Vector3.Transform(-Vector3.UnitZ, _cameraRotation);
            Matrix4x4 view          = Matrix4x4.CreateLookAt(_cameraPosition, _cameraPosition + cameraLookDir, Vector3.UnitY);
            Matrix4x4 projection    = MathUtil.CreatePerspective(
                Device, Device.IsDepthRangeZeroToOne,
                1f, (float)Window.Width / Window.Height,
                0.5f, 1000f);

            _cl.UpdateBuffer(_viewProjectionBuffer, 0, view * projection);

            SceneInfo sceneInfo = new SceneInfo
            {
                LightDir   = Vector4.Normalize(new Vector4(0.2f, -0.6f, -1f, 0)),
                LightColor = new Vector4(1, 1, 1, 1)
            };

            _cl.UpdateBuffer(_sceneInfoBuffer, 0, sceneInfo);

            _cl.SetPipeline(_modelPipeline);
            _cl.SetGraphicsResourceSet(0, _viewProjectionSet);
            _cl.SetGraphicsResourceSet(1, _worldSet);
            _cl.SetGraphicsResourceSet(2, _modelParamsSet);

            foreach (DrawSubmission submission in _drawSubmissions)
            {
                SubmitDraw(submission);
            }
            _drawSubmissions.Clear();
            _imguiRenderer.Render(Device, _cl);
            _imguiRenderer.Update(Vx.FrameTime, input);

            _cl.End();
            Device.SubmitCommands(_cl);
            Device.SwapBuffers(Device.MainSwapchain);
            Device.WaitForIdle();
        }
コード例 #21
0
ファイル: CommandProcessor.cs プロジェクト: limocute/yak2d
        private void ClearDepthTarget(CommandList cl, RenderCommandQueueItem command)
        {
            var surface = _surfaceManager.RetrieveSurface(command.Surface, new GpuSurfaceType[] { GpuSurfaceType.Texture, GpuSurfaceType.RenderTarget | GpuSurfaceType.Internal });

            //Textures (not rendertargets) are fixed content and do not have depth
            //Cannot use internal render targets as reserved for framework use

            if (surface == null)
            {
                return;
            }

            cl.SetFramebuffer(surface.Framebuffer);
            cl.ClearDepthStencil(1.0f);
        }
コード例 #22
0
        private void DrawScene()
        {
            _cl.SetFramebuffer(_gd.SwapchainFramebuffer);
            _cl.SetFullViewports();
            _cl.ClearColorTarget(0, RgbaFloat.Black);
            _cl.ClearDepthStencil(1f);

            _cl.SetPipeline(_pipeline);

            //_cl.UpdateBuffer(_projectionBuffer, 0, _projMatrixLight);
            //_cl.UpdateBuffer(_viewBuffer, 0, _viewMatrixLight);
            _cl.UpdateBuffer(_projectionBuffer, 0, _camera.ProjMatrix);
            _cl.UpdateBuffer(_viewBuffer, 0, _camera.ViewMatrix);

            _cl.UpdateBuffer(_directionLightBuffer, 0, _directionalLight);

            _cl.SetGraphicsResourceSet(0, _projectionViewMatricesLightSet);
            _cl.SetGraphicsResourceSet(1, _perObjectSet);

            foreach (var drawableMesh in _drawables)
            {
                drawableMesh.Draw(_cl, _modelBuffer);
            }
        }
コード例 #23
0
        private void Draw()
        {
            Debug.Assert(_window.Exists);
            int width  = _window.Width;
            int height = _window.Height;
            int x      = _window.X;
            int y      = _window.Y;

            if (_windowResized)
            {
                _windowResized = false;

                CFG.Current.GFX_Display_Width  = width;
                CFG.Current.GFX_Display_Height = height;

                _gd.ResizeMainWindow((uint)width, (uint)height);
                _resizeHandled?.Invoke(width, height);
                CommandList cl = _gd.ResourceFactory.CreateCommandList();
                cl.Begin();
                RecreateWindowFramebuffers(cl);
                ImguiRenderer.WindowResized(width, height);
                cl.End();
                _gd.SubmitCommands(cl);
                cl.Dispose();
            }

            if (_windowMoved)
            {
                _windowMoved = false;
                CFG.Current.GFX_Display_X = x;
                CFG.Current.GFX_Display_Y = y;
            }
            MainWindowCommandList.Begin();
            MainWindowCommandList.SetFramebuffer(_gd.SwapchainFramebuffer);
            MainWindowCommandList.ClearColorTarget(0, new RgbaFloat(0.176f, 0.176f, 0.188f, 1.0f));
            float depthClear = _gd.IsDepthRangeZeroToOne ? 1f : 0f;

            MainWindowCommandList.ClearDepthStencil(0.0f);
            MainWindowCommandList.SetFullViewport(0);
            var fence = Scene.Renderer.Frame(MainWindowCommandList, false);

            MainWindowCommandList.SetFullViewport(0);
            MainWindowCommandList.SetFullScissorRects();
            ImguiRenderer.Render(_gd, MainWindowCommandList);
            MainWindowCommandList.End();
            _gd.SubmitCommands(MainWindowCommandList, fence);
            _gd.SwapBuffers();
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: feliwir/SharpText
        private static void Draw()
        {
            commandList.Begin();
            commandList.SetFramebuffer(graphicsDevice.SwapchainFramebuffer);

            commandList.ClearColorTarget(0, RgbaFloat.CornflowerBlue);
            commandList.ClearDepthStencil(1f);

            infoTextRenderer.Draw();
            demoTextRenderer.Draw();

            commandList.End();
            graphicsDevice.SubmitCommands(commandList);
            graphicsDevice.WaitForIdle();

            graphicsDevice.SwapBuffers();
        }
コード例 #25
0
        protected virtual void Render()
        {
            _cl.Begin();
            _cl.SetFramebuffer(_sc.Framebuffer);
            var r = new Random();

            _cl.ClearColorTarget(
                0,
                new RgbaFloat(0, 0, 0, 1)); //(float)r.NextDouble()
            _cl.ClearDepthStencil(1);

            // Do your rendering here (or call a subclass, etc.)

            _cl.End();
            _gd.SubmitCommands(_cl);
            _gd.SwapBuffers(_sc);
        }
コード例 #26
0
ファイル: Program.cs プロジェクト: playmer/VeldridSonic06Test
        public void Draw()
        {
            double newElapsed   = mClock.Elapsed.TotalSeconds;
            float  deltaSeconds = (float)(newElapsed - mPreviousElapsed);

            mCommandList.Begin();

            mCommandList.UpdateBuffer(mProjectionBuffer, 0, Matrix4x4.CreatePerspectiveFieldOfView(
                                          1.0f,
                                          (float)mWindow.Width / mWindow.Height,
                                          0.5f,
                                          100f));

            mCommandList.UpdateBuffer(mViewBuffer, 0, Matrix4x4.CreateLookAt(Vector3.UnitZ * 2.5f, Vector3.Zero, Vector3.UnitY));

            Matrix4x4 rotation = Matrix4x4.CreateScale(mScale)
                                 * Matrix4x4.CreateFromAxisAngle(Vector3.UnitZ, mRotation.Z)
                                 * Matrix4x4.CreateFromAxisAngle(Vector3.UnitY, mRotation.Y)
                                 * Matrix4x4.CreateFromAxisAngle(Vector3.UnitX, mRotation.X)
                                 * Matrix4x4.CreateTranslation(mTranslation);

            mCommandList.UpdateBuffer(mWorldBuffer, 0, ref rotation);

            mCommandList.SetFramebuffer(mSwapchain.Framebuffer);
            mCommandList.ClearColorTarget(0, RgbaFloat.Black);
            mCommandList.ClearDepthStencil(1f);
            mCommandList.SetPipeline(mPipeline);
            mCommandList.SetVertexBuffer(0, mVertexBuffer);
            mCommandList.SetIndexBuffer(mIndexBuffer, IndexFormat.UInt16);
            mCommandList.SetGraphicsResourceSet(0, mProjViewSet);
            mCommandList.SetGraphicsResourceSet(1, mWorldTextureSet);
            mCommandList.DrawIndexed(36, 1, 0, 0, 0);

            mImguiRenderer.Render(mGraphicsDevice, mCommandList); // [3]
            mCommandList.End();
            mGraphicsDevice.SubmitCommands(mCommandList);
            mGraphicsDevice.SwapBuffers(mSwapchain);
            mGraphicsDevice.WaitForIdle();

            if (mWindowResized)
            {
                mWindowResized = false;
                mGraphicsDevice.ResizeMainWindow((uint)mWindow.Width, (uint)mWindow.Height);
                mImguiRenderer.WindowResized(mWindow.Width, mWindow.Height);
            }
        }
コード例 #27
0
 protected override void Draw(float deltaSeconds)
 {
     UpdateAnimation(deltaSeconds);
     UpdateUniforms();
     _cl.Begin();
     _cl.SetFramebuffer(GraphicsDevice.SwapchainFramebuffer);
     _cl.ClearColorTarget(0, RgbaFloat.Black);
     _cl.ClearDepthStencil(1f);
     _cl.SetPipeline(_pipeline);
     _cl.SetGraphicsResourceSet(0, _rs);
     _cl.SetVertexBuffer(0, _vertexBuffer);
     _cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt32);
     _cl.DrawIndexed(_indexCount);
     _cl.End();
     GraphicsDevice.SubmitCommands(_cl);
     GraphicsDevice.SwapBuffers();
 }
コード例 #28
0
        public void Draw()
        {
            tick += 0.0001F;
            _cl.Begin();


            Matrix4x4 modelMatrix =
                Matrix4x4.CreateTranslation(tick, 0, -0.01f)
                * Matrix4x4.CreateRotationX(0f)
                * Matrix4x4.CreateRotationY(0f)
                * Matrix4x4.CreateScale(1.0f);


            Matrix4x4 lookAtMatrix = Matrix4x4.CreateLookAt(machCamera._position, machCamera._position - machCamera._direction, machCamera._cameraUp);

            Matrix4x4 perspectiveMatrix = Matrix4x4.CreatePerspectiveFieldOfView(60.0f * (float)Math.PI / 180f, machCamera._width / (float)machCamera._height, machCamera._near, machCamera._far);


            _cl.UpdateBuffer(_modelBuffer, 0, ref modelMatrix);
            _cl.UpdateBuffer(_viewBuffer, 0, ref lookAtMatrix);
            _cl.UpdateBuffer(_projectionBuffer, 0, ref perspectiveMatrix);

            _cl.SetFramebuffer(_graphicsDevice.MainSwapchain.Framebuffer);

            _cl.ClearColorTarget(0, RgbaFloat.Black);
            _cl.ClearDepthStencil(1f);

            _cl.SetPipeline(pipelineDescription._pipeline);
            _cl.SetGraphicsResourceSet(0, shaderDescription.modelSet);
            _cl.SetGraphicsResourceSet(1, shaderDescription.vertexSet);
            _cl.SetVertexBuffer(0, _vertexBuffer);
            _cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16);

            _cl.DrawIndexed(
                indexCount: 36,
                instanceCount: 1,
                indexStart: 0,
                vertexOffset: 0,
                instanceStart: 0);

            _cl.End();
            _graphicsDevice.SubmitCommands(_cl);
            _graphicsDevice.SwapBuffers(_graphicsDevice.MainSwapchain);
            _graphicsDevice.WaitForIdle();
        }
コード例 #29
0
        private void HandleRender()
        {
            if (!IsDirty)
            {
                return;
            }
            IsDirty = false;

            fence.Reset();
            commandList.Begin();
            commandList.SetFramebuffer(Framebuffer);
            commandList.ClearColorTarget(0, ClearColor);
            commandList.ClearDepthStencil(1f);
            OnRender(commandList);
            commandList.End();
            Device.SubmitCommands(commandList, fence);
            WindowContainer.AddFenceOnce(fence);
        }
コード例 #30
0
        protected virtual void Render()
        {
            _cl.Begin();
            _cl.SetFramebuffer(_sc.Framebuffer);
            Random r = new Random();

            _cl.ClearColorTarget(0, _clearColors[(_frameIndex / _frameRepeatCount)]);
            _cl.ClearDepthStencil(1);

            // Do your rendering here (or call a subclass, etc.)

            _cl.End();
            _gd.SubmitCommands(_cl);
            _gd.SwapBuffers(_sc);

            // Do some math to loop our color picker index.
            _frameIndex = (_frameIndex + 1) % (_clearColors.Length * _frameRepeatCount);
        }