Пример #1
0
    TextureDesc LoadTextureFormat(StringSection<::Assets::ResChar> filename)
    {
        ucs2 wfilename[MaxPath];
        Conversion::Convert(wfilename, dimof(wfilename), filename.begin(), filename.end());

        auto fmt = GetTexFmt(wfilename);
                
        using namespace DirectX;
        TexMetadata metadata;

        HRESULT hresult = -1;
        if (fmt == TexFmt::DDS) {
            hresult = GetMetadataFromDDSFile((const wchar_t*)wfilename, DDS_FLAGS_NONE, metadata);
        } else if (fmt == TexFmt::TGA) {
            hresult = GetMetadataFromTGAFile((const wchar_t*)wfilename, metadata);
        } else if (fmt == TexFmt::WIC) {
            hresult = GetMetadataFromWICFile((const wchar_t*)wfilename, WIC_FLAGS_NONE, metadata);
        } else {
            LogWarning << "Texture format not apparent from filename (" << filename.AsString().c_str() << ")";
        }

        if (SUCCEEDED(hresult)) {
            return BuildTextureDesc(metadata);
        }

        return TextureDesc::Empty();
    }
Пример #2
0
void Execute(StringSection<char> cmdLine)
{
    // We're going to run a simple process that loads a texture file, runs some shader
    // process, and then writes out an output file.
    // This is a command line app; so our instructions should be on the command line.
    // We're going to use a stream formatter & our "Document" asbtraction to interpret
    // the command line.
    // We could replace the formatter with a version specialized for
    // command lines if we wanted a unix style command line syntax (and, actually, some
    // syntax elements of this formatter [like ';'] might conflict on some OSs.

    MemoryMappedInputStream stream(cmdLine.begin(), cmdLine.end());
    InputStreamFormatter<char> formatter(stream);
    Document<InputStreamFormatter<char>> doc(formatter);

    auto outputFile = doc.Attribute("o").Value();
    auto shader = doc.Attribute("s").Value();

    if (outputFile.Empty() || shader.Empty()) {
        return;
    }

    auto xleDir = GetEnv("XLE_DIR");
    if (xleDir.empty()) {
        LogAlwaysError << "XLE_DIR environment variable isn't set. Expecting this to be set to root XLE directory";
        LogAlwaysError << "This program loads shaders from the $(XLE_DIR)\\Working\\Game\\xleres folder";
        return;
    }

    // we can now construct basic services
    auto cleanup = MakeAutoCleanup([]() {
        TerminateFileSystemMonitoring();
    });
    auto device = RenderCore::CreateDevice();
    Samples::MinimalAssetServices services(device.get());

    // We need to think about SRGB modes... do we want to do the processing in
    // linear or SRGB space? So we want to write out a linear or SRB texture?
    auto shaderParameters = CreateParameterBox(doc.Element("p"));

    auto resultTexture = ExecuteTransform(
                             *device, MakeStringSection(xleDir), shader, shaderParameters,
    {
        { "Sky", HosekWilkieSky },
        { "Compress", CompressTexture }
    });
    if (!resultTexture._pkt) {
        LogAlwaysError << "Error while performing texture transform";
        return;
    }

    // save "readback" as an output texture.
    // We will write a uncompressed format; normally a second command line
    // tool will be used to compress the result.
    resultTexture.Save(outputFile.AsString().c_str());
}
Пример #3
0
    void DirectorySearchRules::AddSearchDirectory(StringSection<ResChar> dir)
    {
            //  Attempt to fit this directory into our buffer.
            //  note that we have limited space in the buffer, but we can't really
            //  rely on all directory names remaining small and convenient... If we 
            //  overflow our fixed size buffer, we can use the dynamically 
            //  allocated "_bufferOverflow"
        assert((_startPointCount+1) <= dimof(_startOffsets));
        if ((_startPointCount+1) > dimof(_startOffsets)) {
                //  limited number of directories that can be pushed into a single "search rules"
                //  this allows us to avoid a little bit of awkward dynamic memory allocation
            return; 
        }

            // Check for duplicates
            //  Duplicates are bad because they will increase the number of search operations
        if (HasDirectory(dir)) return;

        unsigned allocationLength = (unsigned)(dir.Length() + 1);
        if (_bufferOverflow.empty() && (_bufferUsed + allocationLength <= dimof(_buffer))) {
                // just append this new string to our buffer, and add a new start offset
            XlCopyMemory(&_buffer[_bufferUsed], dir.begin(), (allocationLength-1) * sizeof(ResChar));
            _buffer[_bufferUsed+allocationLength-1] = '\0';
        } else {
            if (_bufferOverflow.empty()) {
                _bufferOverflow.resize(_bufferUsed + allocationLength);
                XlCopyMemory(AsPointer(_bufferOverflow.begin()), _buffer, _bufferUsed * sizeof(ResChar));
                XlCopyMemory(PtrAdd(AsPointer(_bufferOverflow.begin()), _bufferUsed * sizeof(ResChar)), dir.begin(), (allocationLength-1) * sizeof(ResChar));
                _bufferOverflow[_bufferUsed+allocationLength-1] = '\0';
            } else {
                assert(_bufferOverflow.size() == allocationLength);
                auto i = _bufferOverflow.insert(_bufferOverflow.end(), dir.begin(), dir.end());
                _bufferOverflow.insert(i + dir.Length(), 0);
            }
        }

        _startOffsets[_startPointCount++] = _bufferUsed;
        _bufferUsed += allocationLength;
    }
Пример #4
0
 intrusive_ptr<DataPacket> CreateStreamingTextureSource(
     StringSection<::Assets::ResChar> filename, TextureLoadFlags::BitField flags)
 {
     return make_intrusive<StreamingTexture>(filename.begin(), filename.end(), flags);
 }