Example #1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _wadRenderer?.Dispose();
         _textureAllocator?.Dispose();
     }
     base.Dispose(disposing);
 }
Example #2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _rasterizerWireframe?.Dispose();
         _plane?.Dispose();
         _wadRenderer?.Dispose();
     }
     base.Dispose(disposing);
 }
Example #3
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _fontTexture?.Dispose();
         _fontDefault?.Dispose();
         _rasterizerWireframe?.Dispose();
         _vertexBufferVisibility?.Dispose();
         _gizmo?.Dispose();
         _plane?.Dispose();
         _wadRenderer?.Dispose();
     }
     base.Dispose(disposing);
 }
Example #4
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _fontTexture?.Dispose();
         _fontDefault?.Dispose();
         _gizmo?.Dispose();
         _plane?.Dispose();
         _model?.Dispose();
         _skinModel?.Dispose();
         _wadRenderer?.Dispose();
         _vertexBufferVisibility?.Dispose();
     }
     base.Dispose(disposing);
 }
Example #5
0
        protected override void OnDraw()
        {
            // To make sure things are in a defined state for legacy rendering...
            ((TombLib.Rendering.DirectX11.Dx11RenderingSwapChain)SwapChain).BindForce();
            ((TombLib.Rendering.DirectX11.Dx11RenderingDevice)Device).ResetState();

            _device.SetDepthStencilState(_device.DepthStencilStates.Default);
            _device.SetRasterizerState(_device.RasterizerStates.CullBack);
            _device.SetBlendState(_device.BlendStates.Opaque);

            Matrix4x4 viewProjection = Camera.GetViewProjectionMatrix(ClientSize.Width, ClientSize.Height);
            Effect    solidEffect    = _deviceManager.___LegacyEffects["Solid"];

            _wadRenderer.Dispose();
            if (Skeleton != null)
            {
                var effect = _deviceManager.___LegacyEffects["Model"];

                effect.Parameters["TextureSampler"].SetResource(_device.SamplerStates.Default);

                foreach (var node in Skeleton)
                {
                    // TODO Keep data on GPU, optimize data upload
                    // Use new renderer
                    var mesh = _wadRenderer.GetStatic(new WadStatic(new WadStaticId(0))
                    {
                        Mesh = node.WadMesh
                    });

                    effect.Parameters["Texture"].SetResource(_wadRenderer.Texture);
                    effect.Parameters["ModelViewProjection"].SetValue((node.GlobalTransform * viewProjection).ToSharpDX());
                    effect.Techniques[0].Passes[0].Apply();

                    foreach (var mesh_ in mesh.Meshes)
                    {
                        _device.SetVertexBuffer(0, mesh_.VertexBuffer);
                        _device.SetIndexBuffer(mesh_.IndexBuffer, true);
                        _device.SetVertexInputLayout(VertexInputLayout.FromBuffer(0, mesh_.VertexBuffer));

                        foreach (var submesh in mesh_.Submeshes)
                        {
                            _device.Draw(PrimitiveType.TriangleList, submesh.Value.NumIndices, submesh.Value.BaseIndex);
                        }
                    }
                    //foreach (var submesh in mesh_.Submeshes)
                    //    _device.DrawIndexed(PrimitiveType.TriangleList, submesh.Value.NumIndices, submesh.Value.MeshBaseIndex);
                }

                // Draw box
                if (SelectedNode != null)
                {
                    _vertexBufferVisibility?.Dispose();
                    _vertexBufferVisibility = GetVertexBufferFromBoundingBox(SelectedNode.WadMesh.BoundingBox);

                    _device.SetVertexBuffer(_vertexBufferVisibility);
                    _device.SetVertexInputLayout(VertexInputLayout.FromBuffer(0, _vertexBufferVisibility));
                    _device.SetIndexBuffer(null, false);

                    solidEffect.Parameters["ModelViewProjection"].SetValue((SelectedNode.GlobalTransform * viewProjection).ToSharpDX());
                    solidEffect.Parameters["Color"].SetValue(new Vector4(0.0f, 1.0f, 0.0f, 1.0f));
                    solidEffect.CurrentTechnique.Passes[0].Apply();

                    _device.Draw(PrimitiveType.LineList, _vertexBufferVisibility.ElementCount);
                }
            }

            if (DrawGrid)
            {
                _device.SetRasterizerState(_rasterizerWireframe);

                // Draw the grid
                _device.SetVertexBuffer(0, _plane.VertexBuffer);
                _device.SetVertexInputLayout(VertexInputLayout.FromBuffer(0, _plane.VertexBuffer));
                _device.SetIndexBuffer(_plane.IndexBuffer, true);

                solidEffect.Parameters["ModelViewProjection"].SetValue(viewProjection.ToSharpDX());
                solidEffect.Parameters["Color"].SetValue(Vector4.One);
                solidEffect.Techniques[0].Passes[0].Apply();

                _device.Draw(PrimitiveType.LineList, _plane.VertexBuffer.ElementCount);
            }

            if (DrawGizmo && SelectedNode != null)
            {
                // Draw the gizmo
                SwapChain.ClearDepth();
                _gizmo.Draw(viewProjection);
            }

            // Draw debug strings
            if (SelectedNode != null)
            {
                ((TombLib.Rendering.DirectX11.Dx11RenderingDevice)Device).ResetState(); // To make sure SharpDx.Toolkit didn't change settings.
                Matrix4x4 worldViewProjection = SelectedNode.GlobalTransform * viewProjection;
                SwapChain.RenderText(new Text
                {
                    Font            = _fontDefault,
                    Pos             = worldViewProjection.TransformPerspectively(SelectedNode.Centre - Vector3.UnitY * 128.0f).To2(),
                    TextAlignment   = new Vector2(0, 0),
                    ScreenAlignment = new Vector2(0.5f, 0.5f),
                    String          =
                        "Name: " + SelectedNode.Bone.Name +
                        "\nLocal offset: " + SelectedNode.Bone.Translation
                });
            }
        }
Example #6
0
        protected override void OnDraw()
        {
            // To make sure things are in a defined state for legacy rendering...
            ((TombLib.Rendering.DirectX11.Dx11RenderingSwapChain)SwapChain).BindForce();
            ((TombLib.Rendering.DirectX11.Dx11RenderingDevice)Device).ResetState();

            _device.SetDepthStencilState(_device.DepthStencilStates.Default);
            _device.SetRasterizerState(_device.RasterizerStates.CullBack);
            _device.SetBlendState(_device.BlendStates.Opaque);

            Matrix4x4 viewProjection = Camera.GetViewProjectionMatrix(ClientSize.Width, ClientSize.Height);

            Effect solidEffect = DeviceManager.DefaultDeviceManager.___LegacyEffects["Solid"];

            _wadRenderer.Dispose();
            if (Mesh != null)
            {
                // TODO Keep data on GPU, optimize data upload
                // Use new renderer
                var mesh = _wadRenderer.GetStatic(new WadStatic(new WadStaticId(0))
                {
                    Mesh = Mesh
                });
                var effect = DeviceManager.DefaultDeviceManager.___LegacyEffects["StaticModel"];
                var world  = Matrix4x4.Identity;

                effect.Parameters["ModelViewProjection"].SetValue((world * viewProjection).ToSharpDX());
                effect.Parameters["Color"].SetValue(Vector4.One);
                effect.Parameters["Texture"].SetResource(_wadRenderer.Texture);
                effect.Parameters["TextureSampler"].SetResource(_device.SamplerStates.Default);

                effect.Parameters["ModelViewProjection"].SetValue((world * viewProjection).ToSharpDX());
                effect.Techniques[0].Passes[0].Apply();

                foreach (var mesh_ in mesh.Meshes)
                {
                    _device.SetVertexBuffer(0, mesh_.VertexBuffer);
                    _device.SetIndexBuffer(mesh_.IndexBuffer, true);
                    _layout = VertexInputLayout.FromBuffer(0, mesh_.VertexBuffer);
                    _device.SetVertexInputLayout(_layout);

                    foreach (var submesh in mesh_.Submeshes)
                    {
                        _device.DrawIndexed(PrimitiveType.TriangleList, submesh.Value.NumIndices, submesh.Value.MeshBaseIndex);
                    }
                }
            }

            if (DrawGrid)
            {
                _device.SetRasterizerState(_rasterizerWireframe);

                // Draw the grid
                _device.SetVertexBuffer(0, _plane.VertexBuffer);
                _device.SetVertexInputLayout(VertexInputLayout.FromBuffer(0, _plane.VertexBuffer));
                _device.SetIndexBuffer(_plane.IndexBuffer, true);

                solidEffect.Parameters["ModelViewProjection"].SetValue(viewProjection.ToSharpDX());
                solidEffect.Parameters["Color"].SetValue(Vector4.One);
                solidEffect.Techniques[0].Passes[0].Apply();

                _device.Draw(PrimitiveType.LineList, _plane.VertexBuffer.ElementCount);
            }
        }