示例#1
0
 public static extern HRESULT D3DCompileFromFile([MarshalAs(UnmanagedType.LPWStr)] string pFileName, _D3D_SHADER_MACRO[] pDefines, ID3DInclude pInclude, [MarshalAs(UnmanagedType.LPStr)] string pEntrypoint, [MarshalAs(UnmanagedType.LPStr)] string pTarget, uint Flags1, uint Flags2, out ID3D10Blob ppCode, out ID3D10Blob ppErrorMsgs);
示例#2
0
        public static IComObject <ID3D11PixelShader> CreatePixelShader(this ID3D11Device device, ID3D10Blob blob, ID3D11ClassLinkage classLinkage = null)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            if (blob == null)
            {
                throw new ArgumentNullException(nameof(blob));
            }

            device.CreatePixelShader(blob.GetBufferPointer(), blob.GetBufferSize(), classLinkage, out var shader).ThrowOnError();
            return(new ComObject <ID3D11PixelShader>(shader));
        }
示例#3
0
        static void Compile(string source, string name, string entryPoint, string target, uint flag1, uint flag2, out ID3D10Blob dst)
        {
            var source_utf8 = Encoding.UTF8.GetBytes(source);
            // var name_utf8 = Encoding.UTF8.GetBytes(name + "\0\0");
            var entryPoint_utf8 = Encoding.UTF8.GetBytes(entryPoint + "\0\0");
            var target_utf8     = Encoding.UTF8.GetBytes(target + "\0\0");

            var def = new _D3D_SHADER_MACRO[]
            {
                new _D3D_SHADER_MACRO
                {
                }
            };

            // using (var error = new ID3D10Blob())
            using (var source_pin = PinPtr.Create(source_utf8))
                // using (var name_pin = PinPtr.Create(name_utf8))
                using (var entryPoint_pin = PinPtr.Create(entryPoint_utf8))
                    using (var target_pin = PinPtr.Create(target_utf8))
                    {
                        var hr = d3dcompiler.D3DCompile(
                            source_pin.Ptr,
                            (ulong)source.Length,
                            name,
                            ref def[0],
                            new IntPtr(1),
                            entryPoint,
                            target,
                            flag1,
                            flag2,
                            out dst,
                            out ID3D10Blob error
                            );
                        if (hr.Failed())
                        {
                            using (error)
                            {
                                var buffer = new Byte[error.GetBufferSize()];
                                Marshal.Copy(error.GetBufferPointer(), buffer, 0, buffer.Length);
                                //var encoding = Encoding.GetEncoding(932);
                                var encoding = Encoding.UTF8;
                                var msg      = encoding.GetString(buffer);
                                throw new Exception(msg);
                            }
                        }
                    }
        }
示例#4
0
        public static IComObject <ID3D11InputLayout> CreateInputLayout(this ID3D11Device device, D3D11_INPUT_ELEMENT_DESC[] inputElements, ID3D10Blob blob)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            if (blob == null)
            {
                throw new ArgumentNullException(nameof(blob));
            }

            if (inputElements == null)
            {
                throw new ArgumentNullException(nameof(inputElements));
            }

            if (inputElements.Length == 0)
            {
                throw new ArgumentException(null, nameof(inputElements));
            }

            device.CreateInputLayout(inputElements, inputElements.Length, blob.GetBufferPointer(), blob.GetBufferSize(), out var layout).ThrowOnError();
            return(new ComObject <ID3D11InputLayout>(layout));
        }