Exemplo n.º 1
0
        public void Run()
        {
            application.RunEvents();            // run this once before checking window
            while (!window.IsClosed())
            {
                device.BeginFrame();
                commandList.Start();
                commandList.BeginRenderPass(renderPass);
                var windowSize = window.GetSize(WindowSizeType.WorkingArea);
                commandList.SetViewPort(new ViewPort(new Rect2(0, 0, windowSize.width, windowSize.height)));
                commandList.SetRenderState(renderState);
                commandList.Draw();
                commandList.EndRenderPass();
                commandList.Finish();
                commandList.Execute();
                device.EndFrame();

                // update constant buffer
                constantBufferObject.offset = (float)Math.Sin(rot);
                rot += 0.1f;
                constantBuffer.Update(constantBufferObject);

                // run application events
                application.RunEvents();
            }
        }
Exemplo n.º 2
0
        public void Run()
        {
            application.RunEvents();            // run this once before checking window
            while (!window.IsClosed())
            {
                // get window size and viewport
                var windowSize = window.GetSize(WindowSizeType.WorkingArea);
                var viewPort   = new ViewPort(new Rect2(0, 0, windowSize.width, windowSize.height));

                // update camera
                camera.position = new Vec3(MathF.Cos(rot), .5f, MathF.Sin(rot)) * 3;
                camera.aspect   = viewPort.GetAspect();
                camera.LookAt(Vec3.zero);

                // update constant buffer
                if (!constantBuffer.BeginUpdate(device.swapChain))
                {
                    throw new Exception("Failed to update ConstantBuffer");
                }
                constantBuffer.Update(MathF.Abs(MathF.Cos(rot * .5f)), shaderEffectVar_Constrast);
                constantBuffer.Update(camera.matrix, shaderEffectVar_Camera);
                constantBuffer.EndUpdate();
                rot += 0.01f;

                // render frame and present
                device.BeginFrame();

                commandList.Start(device.swapChain);                // RENDER INTO: RenderTexture
                commandList.BeginRenderPass(renderTextureTest.renderPass);
                commandList.SetViewPort(new ViewPort(0, 0, renderTextureTest.renderTexture.width, renderTextureTest.renderTexture.height));
                commandList.SetRenderState(renderTextureTest.renderState);
                commandList.Draw();
                commandList.EndRenderPass();
                commandList.Finish();
                commandList.Execute();

                // execute compute shader
                commandList_Compute.Start(device.swapChain);
                commandList_Compute.SetComputeState(computeState);
                commandList_Compute.ExecuteComputeShader(renderTextureTest.renderTexture.width / 8, renderTextureTest.renderTexture.height / 8, 1);
                commandList_Compute.Finish();
                commandList_Compute.Execute();

                commandList.Start(device.swapChain);                // RENDER INTO: SwapChain
                commandList.BeginRenderPass(renderPass);
                commandList.SetViewPort(viewPort);
                commandList.SetRenderState(renderState);
                commandList.Draw();
                commandList.EndRenderPass();
                commandList.Finish();
                commandList.Execute();

                // copy render-texture into swap-chain surface
                if (renderTextureMSAA.msaaLevel != MSAALevel.Disabled)
                {
                    device.swapChain.ResolveMSAA(renderTextureMSAA);
                }
                else
                {
                    device.swapChain.CopyTexture(renderTextureMSAA);
                }
                device.EndFrame();

                // run application events
                application.RunEvents();
            }
        }
Exemplo n.º 3
0
 public override void BeginFrame()
 {
     activeDevice = devices[activeDeviceIndex];
     activeDevice.BeginFrame();
 }