Esempio n. 1
0
        private int Open(IntPtr thisPtr, D3D.INCLUDE_TYPE includeType, IntPtr pFileName, IntPtr pParentData, ref IntPtr ppData, ref int pBytes)
        {
            string result           = null;
            string filepath         = pFileName == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(pFileName);
            string parent_directory = DirectoryMap[pParentData];
            //TODO Support non relative directories
            string this_directory = System.IO.Path.GetDirectoryName(System.IO.Path.Combine(parent_directory, filepath));
            int    hresult        = Open(includeType, filepath, parent_directory, ref result);

            if (hresult != 0)
            {
                return(hresult);
            }

            if (result != null)
            {
                //NOTE: DON'T INCLUDE END BYTE!! byte[] data = Encoding.ASCII.GetBytes(result + char.MinValue);
                byte[] data = Encoding.ASCII.GetBytes(result);
                var    ptr  = Marshal.AllocHGlobal(data.Length);
                Marshal.Copy(data, 0, ptr, data.Length);

                ppData = ptr;
                pBytes = data.Length;

                DirectoryMap[ppData] = this_directory;
            }

            return(hresult);
        }
            protected override int Open(D3D.INCLUDE_TYPE includeType, string filepath, string directory, ref string hlsl_source)
            {
                switch (includeType)
                {
                case D3D.INCLUDE_TYPE.D3D_INCLUDE_LOCAL:
                    hlsl_source = ReadResource(filepath, directory);
                    return(0);

                case D3D.INCLUDE_TYPE.D3D_INCLUDE_SYSTEM:
                    hlsl_source = ReadResource(filepath, base.DirectoryMap[IntPtr.Zero]);
                    return(0);

                default:
                    throw new Exception("Unimplemented include type");
                }
            }
Esempio n. 3
0
        private int Open(IntPtr thisPtr, D3D.INCLUDE_TYPE includeType, IntPtr pFileName, IntPtr pParentData, ref IntPtr ppData, ref int pBytes)
        {
            string result  = null;
            int    hresult = Open(includeType, Marshal.PtrToStringAnsi(pFileName), ref result);

            if (hresult != 0)
            {
                return(hresult);
            }

            if (result != null)
            {
                byte[] data = Encoding.ASCII.GetBytes(result + char.MinValue);
                var    ptr  = Marshal.AllocHGlobal(data.Length);
                Marshal.Copy(data, 0, ptr, data.Length);

                ppData = ptr;
                pBytes = data.Length;
            }

            return(hresult);
        }
Esempio n. 4
0
 protected abstract int Open(D3D.INCLUDE_TYPE includeType, string filename, string directory, ref string result);