Пример #1
0
        /// <summary>
        /// Create texture inplace with new parameters.
        /// Old texture will be completely discarded
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="format"></param>
        /// <param name="mips"></param>
        void CreateFromFile(byte[] fileInMemory, string name, bool forceSRgb)
        {
            IntPtr resource     = new IntPtr(0);
            IntPtr resourceView = new IntPtr(0);
            bool   result;

            lock (device.DeviceContext) {
                if ((char)fileInMemory[0] == 'D' &&
                    (char)fileInMemory[1] == 'D' &&
                    (char)fileInMemory[2] == 'S' &&
                    (char)fileInMemory[3] == ' ')
                {
                    result = DdsLoader.CreateTextureFromMemory(device.Device.NativePointer, fileInMemory, forceSRgb, ref resource, ref resourceView);
                }
                else
                {
                    result = WicLoader.CreateTextureFromMemory(device.Device.NativePointer, fileInMemory, forceSRgb, ref resource, ref resourceView);
                }

                if (!result)
                {
                    throw new GraphicsException("Failed to load texture: " + name);
                }

                tex2D = new D3D.Texture2D(resource);
                SRV   = new D3D.ShaderResourceView(resourceView);
            }

            Width    = tex2D.Description.Width;
            Height   = tex2D.Description.Height;
            Depth    = 1;
            mipCount = tex2D.Description.MipLevels;
            format   = Converter.Convert(tex2D.Description.Format);
        }
Пример #2
0
        /// <summary>
        /// Create texture inplace with new parameters.
        /// Old texture will be completely discarded
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="format"></param>
        /// <param name="mips"></param>
        void CreateFromFile(byte[] fileInMemory, string name, bool forceSRgb)
        {
            IntPtr resource     = new IntPtr(0);
            IntPtr resourceView = new IntPtr(0);

            var r = DdsLoader.CreateTextureFromMemory(device.Device.NativePointer, fileInMemory, forceSRgb, ref resource, ref resourceView);

            if (!r)
            {
                throw new GraphicsException("Failed to load texture: " + name);
            }

            texCube = new D3D.Texture2D(resource);
            SRV     = new D3D.ShaderResourceView(resourceView);

            Width    = texCube.Description.Width;
            Height   = texCube.Description.Height;
            Depth    = 1;
            mipCount = texCube.Description.MipLevels;
            format   = Converter.Convert(texCube.Description.Format);
        }