public FishRenderer(RenderBase rb, FishManager manager)
        {
            RenderBase = rb;
            Manager    = manager;

            paramsBuffer = new UConstantBuffer(RenderBase, Utilities.SizeOf <Vector4>() * 2);

            var shaderFlags =
#if DEBUG
                ShaderFlags.Debug;
#else
                ShaderFlags.None;
#endif

            vertexShader = new UVertexShader(RenderBase, "shaders/Vertex_PC_Explode.hlsl", VertexPositionNormal.InputElements);
            using (var pixelShaderByteCode = ShaderBytecode.CompileFromFile("shaders/Pixel_PC_FishPointLights.hlsl", "main", "ps_4_0", shaderFlags))
                pixelShader = new PixelShader(RenderBase.Device, pixelShaderByteCode);

            vertexBuffer    = new Buffer[3];
            vertexCount     = new int[vertexBuffer.Length];
            vertexBuffer[0] = Buffer.Create(RenderBase.Device, BindFlags.VertexBuffer, VertexPositionNormal.LoadSTL("models/fish.stl", out vertexCount[0]));
            vertexBuffer[1] = Buffer.Create(RenderBase.Device, BindFlags.VertexBuffer, VertexPositionNormal.LoadSTL("models/fish4.stl", out vertexCount[1]));
            vertexBuffer[2] = Buffer.Create(RenderBase.Device, BindFlags.VertexBuffer, VertexPositionNormal.LoadSTL("models/fish5.stl", out vertexCount[2]));

            coneVertexBuffer = Buffer.Create(RenderBase.Device, BindFlags.VertexBuffer,
                                             new VertexPositionColor[] { new VertexPositionColor(new Vector3(0.0f, 0.0f, 0.0f), Color.White), new VertexPositionColor(new Vector3(1.0f, 1.0f, 0.0f), Color.White), new VertexPositionColor(new Vector3(1.0f, -1.0f, 0.0f), Color.White) });
        }
Ejemplo n.º 2
0
        private bool InitializeBuffers(Device device)
        {
            try
            {
                // Create the vertex array.
                var vertices = new LightShader.Vertex[VertexCount];
                // Create the index array.
                var indices = new int[IndexCount];

                for (var i = 0; i < VertexCount; i++)
                {
                    vertices[i] = new LightShader.Vertex()
                    {
                        position = new Vector3(ModelObject[i].x, ModelObject[i].y, ModelObject[i].z),
                        texture  = new Vector2(ModelObject[i].tu, ModelObject[i].tv),
                        normal   = new Vector3(ModelObject[i].nx, ModelObject[i].ny, ModelObject[i].nz)
                    };

                    indices[i] = i;
                }

                // Create the vertex buffer.
                VertexBuffer = Buffer.Create(device, BindFlags.VertexBuffer, vertices);

                // Create the index buffer.
                IndexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, indices);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a quad for Multiple Render Target
        /// </summary>
        /// <param name="device">Device</param>
        /// <returns>Mesh</returns>
        public static SharpMesh CreateQuad(SharpDevice device, float size = 1, bool IsDoubleSide = false)
        {
            Vector3[] vertices = new Vector3[]
            {
                new Vector3(-1 * size, 1 * size, 0),
                new Vector3(-1 * size, -1 * size, 0),
                new Vector3(1 * size, 1 * size, 0),
                new Vector3(1 * size, -1 * size, 0)
            };

            int[] indices = IsDoubleSide
                                ? new int[] { 0, 2, 1, 2, 3, 1, 1, 2, 0, 3, 2, 1 }
                                : new int[] { 0, 2, 1, 2, 3, 1 };

            SharpMesh mesh = new SharpMesh(device, vertices, indices);

            mesh.VertexBuffer = Buffer11.Create <Vector3>(device.Device, BindFlags.VertexBuffer, vertices.ToArray());
            mesh.IndexBuffer  = Buffer11.Create(device.Device, BindFlags.IndexBuffer, indices.ToArray());
            mesh.VertexSize   = SharpDX.Utilities.SizeOf <Vector3>();

            mesh.SubSets.Add(new SharpSubSet()
            {
                DiffuseColor = new Vector4(1, 1, 1, 1),
                IndexCount   = indices.Count()
            });

            return(mesh);
        }
Ejemplo n.º 4
0
        // Initialize the vertex and index buffers that hold the geometry for the plane
        public virtual void Initialize(Device device)
        {
            try
            {
                // Create the dynamic vertex buffer description
                var vertexBufferDesc = new BufferDescription()
                {
                    Usage               = ResourceUsage.Dynamic,
                    SizeInBytes         = Utilities.SizeOf <TextureShader.Vertex>() * IndexCount,
                    BindFlags           = BindFlags.VertexBuffer,
                    CpuAccessFlags      = CpuAccessFlags.Write,
                    OptionFlags         = ResourceOptionFlags.None,
                    StructureByteStride = 0
                };
                // Create the dynamic vertex buffer
                VertexBuffer = Buffer.Create(device, _vertices, vertexBufferDesc);

                // Generate an index array for the vertices
                var indices = new int[IndexCount];
                for (var i = 0; i < IndexCount; i++)
                {
                    indices[i] = i;
                }

                // Create the index buffer
                IndexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, indices);
            }
            catch (Exception ex)
            {
                throw new Exception("Could not initialize plane: " + ex.Message);
            }
        }
Ejemplo n.º 5
0
        protected override void CreateVertexBinding()
        {
            var color = Color.LightGray;
            var data  = new[]
            {
                /*  Position: float x 3, Normal: Vector3, Color */
                new Vertex(new Vector3(-0.5f, 0f, -0.5f), Vector3.UnitY, color),
                new Vertex(new Vector3(-0.5f, 0f, 0.5f), Vector3.UnitY, color),
                new Vertex(new Vector3(0.5f, 0f, 0.5f), Vector3.UnitY, color),
                new Vertex(new Vector3(0.5f, 0f, -0.5f), Vector3.UnitY, color),
            };

            buffer_        = ToDispose(Buffer.Create(DeviceManager.Direct3DDevice, BindFlags.VertexBuffer, data));
            vertexBinding_ = new VertexBufferBinding(buffer_, Utilities.SizeOf <Vertex>(), 0);

            // v0    v1
            // |-----|
            // | \ A |
            // | B \ |
            // |-----|
            // v3    v2
            quadIndices = ToDispose(Buffer.Create(DeviceManager.Direct3DDevice, BindFlags.IndexBuffer, new ushort[] {
                0, 1, 2, // A
                2, 3, 0  // B
            }));
            PrimitiveCount = data.Length / 2;
        }
Ejemplo n.º 6
0
        protected void CreateBufferFromFile(Device device, string fileName)
        {
            DebugVertexType[] vertices;
            UInt16[]          indices;

            ModelLoader modelLoader = new ModelLoader(device);

            modelLoader.LoadPrimitveFromFile(fileName, out vertices, out indices);
            m_vertexCount = vertices.Length;
            m_indexCount  = indices.Length;

            BufferDescription vertexBufferDescription = new BufferDescription(Utilities.SizeOf <DebugVertexType>() * m_vertexCount, BindFlags.VertexBuffer, ResourceUsage.Default);

            m_vertexBuffer = Buffer.Create(device, vertices, vertexBufferDescription);
            m_indexBuffer  = Buffer.Create(device, BindFlags.IndexBuffer, indices);

            BufferDescription instanceBufferDesc = new BufferDescription()
            {
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags    = ResourceOptionFlags.None,
                SizeInBytes    = Utilities.SizeOf <PrimitivePerInstanceData>() * MAX_NUM_INSTANCES,
                Usage          = ResourceUsage.Dynamic
            };

            m_instanceBuffer = new Buffer(device, instanceBufferDesc);

            modelLoader.Dispose();
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="device">Device</param>
 /// <param name="data">Data to load inside</param>
 public SharpInstanceBuffer(SharpDevice device, T[] data)
 {
     _instanceBuffer = Buffer11.Create(device.Device, BindFlags.VertexBuffer, data);
     Device          = device;
     Stride          = Utilities.SizeOf <T>();
     Count           = data.Length;
 }
Ejemplo n.º 8
0
        public void Initialise()
        {
            vertices = Buffer.Create(dev, BindFlags.VertexBuffer, new[]
            {
                new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
            });

            // Vertex and Pixel shaders.
            vsByteCode = ShaderBytecode.CompileFromFile("triShader.hlsl", "VSMain", "vs_5_0", ShaderFlags.None, EffectFlags.None);
            vShader    = new VertexShader(dev, vsByteCode);

            psByteCode = ShaderBytecode.CompileFromFile("triShader.hlsl", "PSMain", "ps_5_0", ShaderFlags.None, EffectFlags.None);
            pShader    = new PixelShader(dev, psByteCode);

            signature = ShaderSignature.GetInputSignature(vsByteCode);

            // Input layout.
            layout = new InputLayout(dev, signature, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
            });
        }
Ejemplo n.º 9
0
        private void InitializeBuffers()
        {
            vertexCount = 6;
            indexCount  = 6;

            var vertices = new TextureVertex[vertexCount];

            foreach (var vertex in vertices)
            {
                //set to zero
            }

            int[] indices = new int[indexCount];
            for (int i = 0; i < indexCount; i++)
            {
                indices[i] = i;
            }

            var vertexBufferDesc = new BufferDescription()
            {
                Usage = ResourceUsage.Dynamic,
                //or size of constant buffer
                SizeInBytes         = Utilities.SizeOf <TextureVertex>() * vertexCount,
                BindFlags           = BindFlags.VertexBuffer,
                CpuAccessFlags      = CpuAccessFlags.Write,
                OptionFlags         = ResourceOptionFlags.None,
                StructureByteStride = 0
            };

            // Create the vertex buffer.
            vertexBuffer = Buffer.Create(device, vertices, vertexBufferDesc);

            // Create the index buffer.
            indexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, indices);
        }
Ejemplo n.º 10
0
        public void Initialize(IDirectXProvider directX)
        {
            BufferDescription vbDesc = new BufferDescription
            {
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                SizeInBytes    = VertexPositionColor.Stride,
                OptionFlags    = ResourceOptionFlags.None,
                Usage          = ResourceUsage.Dynamic
            };

            BufferDescription ibDesc = new BufferDescription
            {
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                SizeInBytes    = sizeof(ushort),
                OptionFlags    = ResourceOptionFlags.None,
                Usage          = ResourceUsage.Dynamic
            };

            vertexBuffer = Buffer.Create(directX.Direct3D.Device, vertices, vbDesc);
            indexBuffer  = Buffer.Create(directX.Direct3D.Device, indices, ibDesc);

            vertexBuffer.DebugName = "InterfaceMesh_vb";
            indexBuffer.DebugName  = "InterfaceMesh_ib";

            vbBinding = new VertexBufferBinding(vertexBuffer, vbDesc.SizeInBytes, 0);
        }
Ejemplo n.º 11
0
        protected bool InitializeBuffers(Device device)
        {
            try
            {
                // Calculate the number of the vertices in the terrain mesh.
                VertexCount = (TerrainWidth - 1) * (TerrainHeight - 1) * NumberOfVerticesPerQuad;
                // Set the index count to the same as the vertex count.
                IndexCount = VertexCount;

                ColorShader.Vertex[] vertices;
                int[] indices;
                FillArrays(out vertices, out indices);

                // Create the vertex buffer.
                VertexBuffer = Buffer.Create(device, BindFlags.VertexBuffer, vertices);

                // Create the index buffer.
                IndexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, indices);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 12
0
        public Rectangle(Renderer renderer, Vector2I screenSize, Vector2I position, Vector2I size, Vector4 color, float depth = 0.0f)
        {
            _shader    = renderer.ColorShader;
            Position   = position;
            ScreenSize = screenSize;
            Size       = size;
            _color     = color;
            _changed   = true;
            Depth      = depth;

            int vertexCount = 4;

            _indexCount = 6;

            _vertices = new VertexDefinition.PositionColor[vertexCount];
            UInt32[] indices = { 0, 1, 2, 0, 3, 1 };

            _vertexBuffer = Buffer.Create(renderer.DirectX.Device, _vertices,
                                          new BufferDescription
            {
                Usage               = ResourceUsage.Dynamic,
                SizeInBytes         = Utilities.SizeOf <VertexDefinition.PositionColor>() * vertexCount,
                BindFlags           = BindFlags.VertexBuffer,
                CpuAccessFlags      = CpuAccessFlags.Write,
                OptionFlags         = ResourceOptionFlags.None,
                StructureByteStride = 0
            });

            _indexBuffer = Buffer.Create(renderer.DirectX.Device, BindFlags.IndexBuffer, indices);
        }
Ejemplo n.º 13
0
            private void BuildGeometry()
            {
                lock (_terrain.Locker)
                {
                    _vertexBuffer?.Dispose();
                    _indexBuffer?.Dispose();
                }

                TerrainVertex[] vertices;
                ushort[]        indices;

                _terrain._surfaceExtractor.GenLodCell(this, 1, out vertices, out indices);


                if (vertices.Length == 0)
                {
                    _geometryDirty = false;
                    return;
                }

                lock (_terrain.Locker)
                {
                    _vertexBuffer        = Buffer.Create(Renderer.Device, BindFlags.VertexBuffer, vertices);
                    _indexBuffer         = Buffer.Create(Renderer.Device, BindFlags.IndexBuffer, indices);
                    _vertexBufferBinding = new VertexBufferBinding(_vertexBuffer, TerrainVertex.Stride, 0);
                }

                _indexCount    = indices.Length;
                _geometryDirty = false;
            }
Ejemplo n.º 14
0
        public BaseRenderer()
        {
            material = new Material(RenderState.device);
            mesh     = new Mesh();

            bufDescription = new BufferDescription
            {
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags    = ResourceOptionFlags.None,
                Usage          = ResourceUsage.Default,
            };

            VertexBuffer = Buffer.Create(RenderState.device, mesh.vertices, bufDescription);


            var context = RenderState.device.ImmediateContext;

            context.Rasterizer.State = new RasterizerState(RenderState.device, new RasterizerStateDescription
            {
                CullMode = CullMode.None,
                FillMode = FillMode.Solid
            });


            binding = new VertexBufferBinding(VertexBuffer, 32, 0);

            // Create Constant Buffer
            constantBuffer = new Buffer(RenderState.device, Utilities.SizeOf <Matrix>(),
                                        ResourceUsage.Default, BindFlags.ConstantBuffer,
                                        CpuAccessFlags.None, ResourceOptionFlags.None, 0);
        }
Ejemplo n.º 15
0
        private void Initialize <T>(ref T[] indices) where T : struct
        {
            var stride            = Marshal.SizeOf <T>();
            var bufferDescription = new BufferDescription(indices.Length * stride, BindFlags.IndexBuffer, ResourceUsage.Default);

            _nativeBuffer = Buffer.Create(_graphicsDevice, indices, bufferDescription);
        }
Ejemplo n.º 16
0
        public ControlCube(Device device, Control keyboardControl, Control mouseControl)
        {
            Vertices        = baseCubePositions.Select(v => new BezierCubeVertex(v.X, v.Y, v.Z, true)).ToArray();
            Camera          = new Camera(keyboardControl, mouseControl);
            Camera.Focused  = false;
            Camera.Position = new Vector3();

            var vertexArray = Vertices.Select(x => x.ToVertex).ToArray();

            vertexBuffer  = Buffer.Create(device, BindFlags.VertexBuffer, vertexArray);
            vertexBinding = new VertexBufferBinding(vertexBuffer, Utilities.SizeOf <Vertex>(), 0);

            indexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, new ushort[]
            {
                0, 1,
                0, 2,
                0, 4,
                1, 3,
                1, 5,
                2, 3,
                2, 6,
                3, 7,
                4, 5,
                4, 6,
                5, 7,
                6, 7,
            });
        }
Ejemplo n.º 17
0
        public void Rebuild()
        {
            if (vertices == null ||
                vertices.Length == 0 ||
                indices == null ||
                indices.Length == 0 ||
                normals == null ||
                normals.Length == 0 ||
                vertices.Length != normals.Length)
            {
                return;
            }

            VertexInputElement[] elements = new VertexInputElement[vertices.Length];
            for (int i = 0; i < elements.Length; i++)
            {
                elements[i] = new VertexInputElement()
                {
                    Position = vertices[i],
                    Normal   = normals[i]
                };
            }

            VertexBuffer = Buffer.Create(engine.GraphicsServices.GetService <Device>(), BindFlags.VertexBuffer, elements);
            IndexBuffer  = Buffer.Create(engine.GraphicsServices.GetService <Device>(), BindFlags.IndexBuffer, indices);
        }
Ejemplo n.º 18
0
 public override void InitBuffers(Device d3d, DeviceContext context)
 {
     vertexBuffer = Buffer.Create(d3d, BindFlags.VertexBuffer, Vertices);
     indexBuffer  = Buffer.Create(d3d, BindFlags.IndexBuffer, Indices);
     Shader       = RenderStorageSingleton.Instance.ShaderManager.shaders[1];
     BoundingBox.InitBuffers(d3d, context);
 }
Ejemplo n.º 19
0
    public UnmanagedRgbaImage Render(HashSet <int> surfaceIdxs)
    {
        var context = device.ImmediateContext;

        context.ClearRenderTargetView(textureTargetView, new Color4(0.5f, 0.5f, 1f, 1));

        VertexInfo[] vertexInfos  = MakeVertexInfos(surfaceIdxs);
        var          vertexBuffer = Buffer.Create(device, BindFlags.VertexBuffer, vertexInfos);

        context.ClearState();

        context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
        context.InputAssembler.InputLayout       = inputLayout;
        context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, VertexInfo.SizeInBytes, 0));
        context.VertexShader.Set(vertexShader);
        context.Rasterizer.State = rasterizerState;
        context.Rasterizer.SetViewport(0, 0, Size, Size);
        context.PixelShader.Set(pixelShader);
        context.OutputMerger.SetRenderTargets(textureTargetView);

        context.Draw(vertexInfos.Length, 0);

        context.ClearState();

        vertexBuffer.Dispose();

        context.ResolveSubresource(texture, 0, resolveTexture, 0, Format.B8G8R8A8_UNorm);

        return(DownloadImageFromGpu());
    }
Ejemplo n.º 20
0
        private bool InitialiseBuffers(Device device)
        {
            try
            {
                var vertices = new PositionTextureNormalVertex[_vertexCount];
                var indices  = new int[IndexCount];

                for (var i = 0; i < _vertexCount; ++i)
                {
                    vertices[i] = new PositionTextureNormalVertex()
                    {
                        position = new Vector3(ModelObject[i].x, ModelObject[i].y, ModelObject[i].z),
                        texture  = new Vector2(ModelObject[i].tu, ModelObject[i].tv),
                        //normal = new Vector3(ModelObject[i].nx, ModelObject[i].ny, ModelObject[i].nz)
                    };

                    indices[i] = i;
                }

                _vertexBuffer = Buffer.Create(device, BindFlags.VertexBuffer, vertices);
                _indexBuffer  = Buffer.Create(device, BindFlags.IndexBuffer, indices);

                return(true);
            }
            catch (Exception ex)
            {
                //Log.WriteToFile(ErrorLevel.Error, "Model.InitialiseBuffer", ex, true);

                return(false);
            }
        }
Ejemplo n.º 21
0
        static D3DBuffer CreateVertexBuffer <T>(ref D3DDevice device, T[] vertexData, ResourceUsage resourceUsage, CpuAccessFlags cpuAccessFlags) where T : struct
        {
            var vertexDataSize = vertexData.Length * Utilities.SizeOf <T>();

            if (vertexDataSize % 16 != 0)
            {
                throw new ArgumentException("vertex data size is not multiply of 16.");
            }

            var vertexBufferDesc = new BufferDescription()
            {
                /* Usage */
                Usage = resourceUsage,
                /* ByteWidth */
                SizeInBytes = vertexDataSize,
                /* BindFlags */
                BindFlags = BindFlags.VertexBuffer,
                /* CPUAccessFlags */
                CpuAccessFlags = cpuAccessFlags,
                /* MiscFlags */
                OptionFlags = ResourceOptionFlags.None,
                /* StructureByteStride */
                StructureByteStride = 0,
            };

            var vertexBuffer = D3DBuffer.Create(device, vertexData, vertexBufferDesc);

            return(vertexBuffer);
        }
Ejemplo n.º 22
0
        protected override void CreateDeviceDependentResources()
        {
            RemoveAndDispose(ref vertexBuffer);
            RemoveAndDispose(ref indexBuffer);

            // Retrieve our SharpDX.Direct3D11.Device1 instance
            var device = this.DeviceManager.Direct3DDevice;

            Vertex[] vertices;
            int[]    indices;
            //GeometricPrimitives.GenerateSphere(out vertices, out indices, color);
            GeometricPrimitives.GenerateSphere(out vertices, out indices, color, 0.5f, 16, false);

            vertexBuffer  = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, vertices));
            vertexBinding = new VertexBufferBinding(vertexBuffer, Utilities.SizeOf <Vertex>(), 0);

            indexBuffer      = ToDispose(Buffer.Create(device, BindFlags.IndexBuffer, indices));
            totalVertexCount = indices.Length;

            var max    = vertices.Max().Position;
            var min    = vertices.Min().Position;
            var center = (max - min) * .5f;

            meshExtent = new Mesh.MeshExtent
            {
                Min    = min,
                Max    = max,
                Radius = 0.5f,
                Center = Position// center
            };
        }
Ejemplo n.º 23
0
        public override void InitBuffers(Device d3d, DeviceContext d3dContext)
        {
            vertexBuffer = Buffer.Create(d3d, BindFlags.VertexBuffer, LODs[0].Vertices);
            indexBuffer  = Buffer.Create(d3d, BindFlags.IndexBuffer, LODs[0].Indices);

            InitTextures(d3d, d3dContext);
        }
Ejemplo n.º 24
0
        protected override void CreateVertexBinding()
        {
            var data = new[]
            {
                /*  Vertex Position                       Vertex Color */
                new Vector4(0.25f, 0.5f, -0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // Top-left
                new Vector4(0.75f, 0.5f, -0.5f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Top-right
                new Vector4(0.75f, 0.0f, -0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Base-right
                new Vector4(0.25f, 0.0f, -0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Base-left
            };

            buffer_        = ToDispose(Buffer.Create(DeviceManager.Direct3DDevice, BindFlags.VertexBuffer, data));
            vertexBinding_ = new VertexBufferBinding(buffer_, Utilities.SizeOf <Vector4>() * 2, 0);

            // v0    v1
            // |-----|
            // | \ A |
            // | B \ |
            // |-----|
            // v3    v2
            quadIndices = ToDispose(Buffer.Create(DeviceManager.Direct3DDevice, BindFlags.IndexBuffer, new ushort[] {
                0, 1, 2, // A
                2, 3, 0  // B
            }));
            PrimitiveCount = data.Length / 2;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Create any device dependent resources here.
        /// This method will be called when the device is first
        /// initialized or recreated after being removed or reset.
        /// </summary>
        protected override void CreateDeviceDependentResources()
        {
            // Ensure that if already set the device resources
            // are correctly disposed of before recreating
            RemoveAndDispose(ref quadVertices);
            RemoveAndDispose(ref quadIndices);

            // Retrieve our SharpDX.Direct3D11.Device1 instance
            var device = this.DeviceManager.Direct3DDevice;

            // Create vertex buffer for quad
            quadVertices = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, new Vertex[] {
                /*  Position: float x 3, Normal: Vector3, Color */
                new Vertex(-0.5f, 0f, -0.5f, Vector3.UnitY, color),
                new Vertex(-0.5f, 0f, 0.5f, Vector3.UnitY, color),
                new Vertex(0.5f, 0f, 0.5f, Vector3.UnitY, color),
                new Vertex(0.5f, 0f, -0.5f, Vector3.UnitY, color),
            }));
            quadBinding = new VertexBufferBinding(quadVertices, Utilities.SizeOf <Vertex>(), 0);

            // v0    v1
            // |-----|
            // | \ A |
            // | B \ |
            // |-----|
            // v3    v2
            quadIndices = ToDispose(Buffer.Create(device, BindFlags.IndexBuffer, new ushort[] {
                0, 2, 1, // A
                2, 0, 3  // B
            }));
        }
    public static Uint32IndexBuffer Make(Device device, List <Quad> faces)
    {
        int[]  indices     = Triangularize(faces);
        Buffer indexBuffer = indices.Length == 0 ? null : Buffer.Create(device, BindFlags.IndexBuffer, indices, 0, ResourceUsage.Immutable);

        return(new Uint32IndexBuffer(indices.Length, indexBuffer));
    }
Ejemplo n.º 27
0
        protected override void CreateDeviceDependentResources()
        {
            // Ensure that if already set the device resources
            // are correctly disposed of before recreating
            RemoveAndDispose(ref quadVertices);
            RemoveAndDispose(ref quadIndices);

            // Retrieve our SharpDX.Direct3D11.Device1 instance
            var device = this.DeviceManager.Direct3DDevice;

            // Create a quad (two triangles)
            quadVertices = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, new[] {
                /*  Vertex Position                       Vertex Color */
                new Vector4(0.25f, 0.5f, -0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // Top-left
                new Vector4(0.75f, 0.5f, -0.5f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Top-right
                new Vector4(0.75f, 0.0f, -0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Base-right
                new Vector4(0.25f, 0.0f, -0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Base-left
            }));
            quadBinding = new VertexBufferBinding(quadVertices, Utilities.SizeOf <Vector4>() * 2, 0);

            // v0    v1
            // |-----|
            // | \ A |
            // | B \ |
            // |-----|
            // v3    v2
            quadIndices = ToDispose(Buffer.Create(device, BindFlags.IndexBuffer, new ushort[] {
                0, 1, 2, // A
                2, 3, 0  // B
            }));
        }
Ejemplo n.º 28
0
        public UnitDisc(Device device, int segmentCount, bool invert = false)
        {
            SegmentCount = segmentCount;
            List <Vector3> verts = new List <Vector3>();
            List <uint>    inds  = new List <uint>();

            verts.Add(Vector3.Zero);
            float incr = (float)Math.PI * 2.0f / segmentCount;

            for (int i = 0; i < segmentCount; i++)
            {
                float a  = incr * i;
                float px = (float)Math.Sin(a);
                float py = (float)Math.Cos(a);
                verts.Add(new Vector3(px, py, 0));
            }
            for (int i = 0; i < segmentCount; i++)
            {
                uint ci = (uint)((i == 0) ? segmentCount : i);
                uint ni = (uint)i + 1;
                inds.Add(0);
                inds.Add(invert ? ni : ci);
                inds.Add(invert ? ci : ni);
            }
            IndexCount = inds.Count;

            VertexBuffer = Buffer.Create(device, BindFlags.VertexBuffer, verts.ToArray());
            IndexBuffer  = Buffer.Create(device, BindFlags.IndexBuffer, inds.ToArray());
            vbbinding    = new VertexBufferBinding(VertexBuffer, 12, 0);
        }
Ejemplo n.º 29
0
        protected override void CreateDeviceDependentResources()
        {
            base.CreateDeviceDependentResources();

            RemoveAndDispose(ref vertexBuffer);

            // Retrieve our SharpDX.Direct3D11.Device1 instance
            var device = this.DeviceManager.Direct3DDevice;

            List <Vertex> vertices = new List <Vertex>();

            vertices.AddRange(new[] {
                new Vertex(0, 0, -4, Vector3.UnitY, Color.Blue),
                new Vertex(0, 0, 4, Vector3.UnitY, Color.Blue),
                new Vertex(-4, 0, 0, Vector3.UnitY, Color.Red),
                new Vertex(4, 0, 0, Vector3.UnitY, Color.Red),
            });
            for (var i = -4f; i < -0.09f; i += 0.2f)
            {
                vertices.Add(new Vertex(i, 0, -4, Color.Gray));
                vertices.Add(new Vertex(i, 0, 4, Color.Gray));
                vertices.Add(new Vertex(-i, 0, -4, Color.Gray));
                vertices.Add(new Vertex(-i, 0, 4, Color.Gray));

                vertices.Add(new Vertex(-4, 0, i, Color.Gray));
                vertices.Add(new Vertex(4, 0, i, Color.Gray));
                vertices.Add(new Vertex(-4, 0, -i, Color.Gray));
                vertices.Add(new Vertex(4, 0, -i, Color.Gray));
            }
            vertexCount  = vertices.Count;
            vertexBuffer = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, vertices.ToArray()));
        }
        protected override void CreateDeviceDependentResources()
        {
            RemoveAndDispose(ref vertexBuffer);
            RemoveAndDispose(ref indexBuffer);

            // Retrieve our SharpDX.Direct3D11.Device1 instance
            var device = this.DeviceManager.Direct3DDevice;

            // Load texture (a DDS cube map)
            textureView = ShaderResourceView.FromFile(device, "CubeMap.dds");

            // Create our sampler state
            samplerState = new SamplerState(device, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Clamp,
                AddressV           = TextureAddressMode.Clamp,
                AddressW           = TextureAddressMode.Clamp,
                BorderColor        = new Color4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter             = Filter.MinMagMipLinear,
                MaximumLod         = 9, // Our cube map has 10 mip map levels (0-9)
                MinimumLod         = 0,
                MipLodBias         = 0.0f
            });

            Vertex[] vertices;
            int[]    indices;
            GeometricPrimitives.GenerateSphere(out vertices, out indices, Color.Gray);

            vertexBuffer  = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, vertices));
            vertexBinding = new VertexBufferBinding(vertexBuffer, Utilities.SizeOf <Vertex>(), 0);

            indexBuffer      = ToDispose(Buffer.Create(device, BindFlags.IndexBuffer, indices));
            totalVertexCount = indices.Length;
        }