Esempio n. 1
0
            public byte[] LoadTexture(string textureName, ReadAheadBinaryReader reader, int textureSize)
            {
                if (textureSize > 4e6)
                {
                    AcToolsLogging.Write($"{textureName}: {(double)textureSize / 1024 / 1024:F1} MB");
                }

                MemoryChunk.Bytes(textureSize).Execute(() => {
                    var bytes = reader.ReadBytes(textureSize);

                    // FromStream simply reads Stream to byte[] underneath, so we could just do it here in
                    // a more controlled manner

                    try {
                        lock (_device) {
                            if (OptionLoadView)
                            {
                                var view            = ShaderResourceView.FromMemory(_device, bytes); // new ShaderResourceView(_device, texture);
                                _ready[textureName] = new Tuple <Texture2D, ShaderResourceView>(null, view);
                            }
                            else
                            {
                                var texture         = Texture2D.FromMemory(_device, bytes);
                                var view            = new ShaderResourceView(_device, texture);
                                _ready[textureName] = new Tuple <Texture2D, ShaderResourceView>(texture, view);
                            }
                        }
                    } catch (SEHException e) {
                        AcToolsLogging.NonFatalErrorNotify("Can’t load texture", "Try again?", e);
                    }
                });

                return(null);
            }
Esempio n. 2
0
            public byte[] LoadTexture(string textureName, Stream stream, int textureSize)
            {
                AcToolsLogging.Write(textureName + ": " + textureSize / 1024 / 1024 + " MB");

                MemoryChunk.Bytes(textureSize).Execute(() => {
                    var bytes = new byte[textureSize];
                    AcToolsLogging.Write("Bytes are ready");

                    stream.Read(bytes, 0, textureSize);
                    AcToolsLogging.Write("Texture has been read");

                    // FromStream simply reads Stream to byte[] underneath, so we could just do it here in
                    // a more controlled manner
                    _ready[textureName] = ShaderResourceView.FromMemory(_device, bytes);
                    AcToolsLogging.Write("Texture has been loaded");
                });

                return(null);
            }