Example #1
0
        void renderScene(IDeviceContext ic, ITextureView swapChainRgb, ITextureView swapChainDepthStencil)
        {
            ic.SetRenderTarget(swapChainRgb, swapChainDepthStencil, ResourceStateTransitionMode.Transition);

            // Clear the back buffer
            ic.ClearRenderTarget(swapChainRgb, clearColor);
            ic.ClearDepthStencil(swapChainDepthStencil, ClearDepthStencilFlags.DepthFlag, 1.0f, 0);

            // Map the buffer and write current world-view-projection matrix
            Matrix4x4 transposed = worldViewProjMatrix.transposed();

            ic.writeBuffer(vsConstants, ref transposed);

            // Bind vertex and index buffers
            ic.SetVertexBuffer(0, cubeVertexBuffer, 0);
            ic.SetIndexBuffer(cubeIndexBuffer, 0);

            // Set the pipeline state
            ic.SetPipelineState(pipelineState);
            // Commit shader resources. RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode makes sure that resources are transitioned to required states.
            ic.CommitShaderResources(resourceBinding);

            DrawIndexedAttribs draw = new DrawIndexedAttribs(false)
            {
                IndexType  = GpuValueType.Uint16,
                NumIndices = 36,
                Flags      = DrawFlags.VerifyAll
            };

            ic.DrawIndexed(ref draw);
        }
Example #2
0
        void renderScene(IDeviceContext ic, ITextureView swapChainRgb, ITextureView swapChainDepthStencil)
        {
            // ConsoleLogger.logDebug( "SpinningTeapot.render" );

            ic.SetRenderTarget(swapChainRgb, swapChainDepthStencil, ResourceStateTransitionMode.Transition);

            // Clear the back buffer
            ic.ClearRenderTarget(swapChainRgb, clearColor);
            ic.ClearDepthStencil(swapChainDepthStencil, ClearDepthStencilFlags.DepthFlag, 1.0f, 0, ResourceStateTransitionMode.Transition);

            if (resources.haveMesh)
            {
                Matrix4x4 world     = teapotWorld * Matrix4x4.CreateFromQuaternion(extraRotation * motion.rotation);
                Matrix4x4 view      = Matrix4x4.CreateTranslation(0, 0, 5);
                Vector3   cameraPos = new Vector3(0, -3, 0);
                view      = DiligentMatrices.createLookAt(cameraPos, Vector3.Zero, Vector3.UnitZ);
                worldView = world * view;

                float NearPlane = 0.1f;
                float FarPlane  = 100;
                // Projection matrix differs between DX and OpenGL
                Matrix4x4 projection = DiligentMatrices.createPerspectiveFieldOfView(0.25f * MathF.PI * motion.zoomFactor, context.aspectRatio, NearPlane, FarPlane, isOpenGlDevice);

                resources.draw(ic, ref worldView, ref projection);
            }
        }
Example #3
0
        public void Render(IDeviceContext context, ITexture2D meshRenderTexture)
        {
            context.SetRenderTarget(_backBuffer, _depthStencil);
            context.ClearRenderTarget(_backBuffer, Color.Red);
            context.ClearDepthStencil(_depthStencil);

            context.SetInputLayout(_inputLayout);

            context.SetVertexBuffer(_vertexBuffer);
            context.SetIndexBuffer(_indexBuffer);

            context.SetPixelShader(_pixelShader);
            context.SetVertexShader(_vertexShader);


            context.SetPixelShaderResource(meshRenderTexture);

            context.DrawIndexed(6, 0, 0);
        }
Example #4
0
 public void Render(IDeviceContext context)
 {
     context.ClearRenderTarget(_backBuffer, Color.Blue);
     context.ClearDepthStencil(_depthStencil);
 }