コード例 #1
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);
        }
コード例 #2
0
 public SharpMesh(SharpDevice device, Vector3[] vertice = null, int[] inds = null)
 {
     Device  = device;
     SubSets = new List <SharpSubSet>( );
     Vertice = vertice;
     Indices = inds;
 }
コード例 #3
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;
 }
コード例 #4
0
 /// <summary>
 /// Create a batch manager for drawing text and sprite
 /// </summary>
 /// <param name="device">Device pointer</param>
 /// <param name="filename">Path of the font file</param>
 public SharpBatch(SharpDevice device, string filename)
 {
     Device         = device;
     GraphicsDevice = GraphicsDevice.New(Device.Device);
     GraphicsDevice.SetViewports(Device.DeviceContext.Rasterizer.GetViewports()[0]);
     Batch = new SpriteBatch(GraphicsDevice);
     Font  = SpriteFont.Load(GraphicsDevice, filename);
 }
コード例 #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="device">Device</param>
        /// <param name="size">Buffer size</param>
        public SharpOutputBuffer(SharpDevice device, int size)
        {
            Device = device;
            BufferDescription desc = new BufferDescription()
            {
                SizeInBytes = size,
                BindFlags   = BindFlags.VertexBuffer | BindFlags.StreamOutput,
                Usage       = ResourceUsage.Default,
            };

            _buffer = new Buffer11(Device.Device, desc);
        }
コード例 #6
0
        /// <summary>
        /// Create a mesh from wavefront obj file format using Tangent and Binormal vertex format
        /// </summary>
        /// <param name="device">Device</param>
        /// <param name="filename">Filename</param>
        /// <returns>Mesh</returns>
        public static SharpMesh CreateNormalMappedFromObj(SharpDevice device, string filename)
        {
            SharpMesh mesh = new SharpMesh(device);

            WaveFrontModel[] modelParts = WaveFrontModel.CreateFromObj(filename);
            mesh.Device  = device;
            mesh.SubSets = new List <SharpSubSet>();

            List <TangentVertex> vertices = new List <TangentVertex>();
            List <int>           indices  = new List <int>();

            int vcount = 0;
            int icount = 0;

            foreach (WaveFrontModel model in modelParts)
            {
                vertices.AddRange(model.TangentData);
                indices.AddRange(model.IndexData.Select(i => i + vcount));

                var mate = model.MeshMaterial.First();


                ShaderResourceView tex  = null;
                ShaderResourceView ntex = null;

                if (!string.IsNullOrEmpty(mate.DiffuseMap))
                {
                    string textureFile = Path.GetDirectoryName(filename) + "\\" + Path.GetFileName(mate.DiffuseMap);
                    tex = device.LoadTextureFromFile(textureFile);

                    string normalMap = Path.GetDirectoryName(textureFile) + "\\" + Path.GetFileNameWithoutExtension(textureFile) + "N" + Path.GetExtension(textureFile);
                    ntex = device.LoadTextureFromFile(normalMap);
                }

                mesh.SubSets.Add(new SharpSubSet()
                {
                    IndexCount = model.IndexData.Count,
                    StartIndex = icount,
                    DiffuseMap = tex,
                    NormalMap  = ntex
                });

                vcount += model.VertexData.Count;
                icount += model.IndexData.Count;
            }

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

            return(mesh);
        }
コード例 #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="device">Device</param>
        /// <param name="breakOnWarning">Generate an error on warning</param>
        public SharpDebugger(SharpDevice device, bool breakOnWarning)
        {
            _device = device;
            //init the debug device
            Debug = new DeviceDebug(device.Device);
            //init the queue interface
            Queue = Debug.QueryInterface <InfoQueue>();

            if (breakOnWarning)
            {
                Queue.SetBreakOnSeverity(MessageSeverity.Warning, true);
            }
        }
コード例 #8
0
        /// <summary>
        /// Create From Vertices and Indices array
        /// </summary>
        /// <typeparam name="VType">Vertex Type</typeparam>
        /// <param name="device">Device</param>
        /// <param name="vertices">Vertices</param>
        /// <param name="indices">Indices</param>
        /// <returns>Mesh</returns>
        public static SharpMesh Create <VType>(SharpDevice device, VType[] vertices, int[] indices) where VType : struct
        {
            SharpMesh mesh = new SharpMesh(device);

            mesh.VertexBuffer = Buffer11.Create <VType>(device.Device, BindFlags.VertexBuffer, vertices);
            mesh.IndexBuffer  = Buffer11.Create(device.Device, BindFlags.IndexBuffer, indices);
            mesh.VertexSize   = SharpDX.Utilities.SizeOf <VType>();
            mesh.SubSets.Add(new SharpSubSet()
            {
                DiffuseColor = new Vector4(1, 1, 1, 1),
                IndexCount   = indices.Count()
            });
            return(mesh);
        }
コード例 #9
0
        /// <summary>
        /// Load texture from file
        /// </summary>
        /// <param name="device">Device</param>
        /// <param name="filename">Filename</param>
        /// <returns>Shader Resource View</returns>
        public static ShaderResourceView LoadTextureFromFile(this SharpDevice device, string filename)
        {
            string ext = System.IO.Path.GetExtension(filename);

            if (ext.ToLower() == ".dds")
            {
                bool isCube;
                return(CreateTextureFromDDS(device.Device, device.DeviceContext, System.IO.File.ReadAllBytes(filename), out isCube));
            }
            else
            {
                return(CreateTextureFromBitmap(device.Device, device.DeviceContext, filename));
            }
        }
コード例 #10
0
ファイル: SharpShader.cs プロジェクト: Layven/water
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="device">Device</param>
        /// <param name="filename">Path of shader file</param>
        /// <param name="description">Description structure</param>
        /// <param name="elements">Input Layout Elements</param>
        public SharpShader(SharpDevice device, string filename, SharpShaderDescription description, InputElement[] elements)
        {
            Device = device;
            // Compile Vertex and Pixel shaders
            var vertexShaderByteCode = ShaderBytecode.CompileFromFile(filename, description.VertexShaderFunction, "vs_5_0");

            VertexShader = new VertexShader(Device.Device, vertexShaderByteCode);

            //create pixel shader
            if (!string.IsNullOrEmpty(description.PixelShaderFunction))
            {
                var pixelShaderByteCode = ShaderBytecode.CompileFromFile(filename, description.PixelShaderFunction, "ps_5_0");
                PixelShader = new PixelShader(Device.Device, pixelShaderByteCode);
            }

            if (!string.IsNullOrEmpty(description.GeometryShaderFunction))
            {
                var geometryShaderByteCode = ShaderBytecode.CompileFromFile(filename, description.GeometryShaderFunction, "gs_5_0");

                if (description.GeometrySO == null)
                {
                    GeometryShader = new GeometryShader(Device.Device, geometryShaderByteCode);
                }
                else
                {
                    int[] size = new int[] { description.GeometrySO.Select(e => e.ComponentCount * 4).Sum() };

                    GeometryShader = new GeometryShader(Device.Device, geometryShaderByteCode, description.GeometrySO, size, -1);
                }
            }

            if (!string.IsNullOrEmpty(description.DomainShaderFunction))
            {
                var domainShaderByteCode = ShaderBytecode.CompileFromFile(filename, description.DomainShaderFunction, "ds_5_0");
                DomainShader = new DomainShader(Device.Device, domainShaderByteCode);
            }

            if (!string.IsNullOrEmpty(description.HullShaderFunction))
            {
                var hullShaderByteCode = ShaderBytecode.CompileFromFile(filename, description.HullShaderFunction, "hs_5_0");
                HullShader = new HullShader(Device.Device, hullShaderByteCode);
            }

            var signature = ShaderSignature.GetInputSignature(vertexShaderByteCode);

            // Layout from VertexShader input signature
            Layout = new InputLayout(Device.Device, signature, elements);
        }
コード例 #11
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="device">Device</param>
        /// <param name="size">Cube Size</param>
        /// <param name="format">Color Format</param>
        public SharpCubeTarget(SharpDevice device, int size, Format format)
        {
            Device = device;
            Size   = size;

            Texture2D target = new Texture2D(device.Device, new Texture2DDescription()
            {
                Format            = format,
                Width             = size,
                Height            = size,
                ArraySize         = 6,
                BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags    = CpuAccessFlags.None,
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.TextureCube,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
            });


            _target = new RenderTargetView(device.Device, target);

            _resource = new ShaderResourceView(device.Device, target);

            target.Dispose();

            var _zbufferTexture = new Texture2D(Device.Device, new Texture2DDescription()
            {
                Format            = Format.D16_UNorm,
                ArraySize         = 6,
                MipLevels         = 1,
                Width             = size,
                Height            = size,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
                BindFlags         = BindFlags.DepthStencil,
                CpuAccessFlags    = CpuAccessFlags.None,
                OptionFlags       = ResourceOptionFlags.TextureCube
            });

            // Create the depth buffer view
            _zbuffer = new DepthStencilView(Device.Device, _zbufferTexture);
            _zbufferTexture.Dispose();
        }
コード例 #12
0
 private SharpMesh(SharpDevice device)
 {
     Device  = device;
     SubSets = new List <SharpSubSet>();
 }
コード例 #13
0
ファイル: Sharp2D.cs プロジェクト: ttvAmavisca/rc_car
 /// <summary>
 /// Create a batch manager for drawing text and sprite
 /// </summary>
 /// <param name="device">Device pointer</param>
 internal Sharp2D(SharpDevice device)
 {
     Device = device;
 }