tool/vfx/vfxSection.cpp
bool Section::ReadFile(
    const std::string&    docFilename,      // [in] File name of parent document
    const std::string&    fileName,         // [in] File name
    bool                  isBinary,         // Whether file is SPIRV binary file
    std::vector<uint8_t>* pBinaryData,      // [out] Binary data
    std::string*          pTextData,        // [out] Text data
    std::string*          pErrorMsg)        // [out] Error message
{
    bool result = true;

    // Prepend directory from "docFilename" to the given filename.
    std::string path;
    auto separatorIndex = docFilename.find_last_of("/\\");
    if (separatorIndex != std::string::npos)
    {
        path = docFilename.substr(0, separatorIndex + 1);
    }
    path += fileName;

    // Open file
    FILE* pInFile = fopen(path.c_str(), isBinary ? "rb" : "r");
    if (pInFile == nullptr)
    {
        PARSE_ERROR(*pErrorMsg, 0, "Fails to open input file: %s\n", path.c_str());
        return false;
    }

    // Get file size
    fseek(pInFile, 0, SEEK_END);
    size_t fileSize = ftell(pInFile);
    fseek(pInFile, 0, SEEK_SET);

    // Allocate temp buffer and read file
    char* pData = new char[fileSize + 1];
    VFX_ASSERT(pData != nullptr);
    memset(pData, 0, fileSize + 1);
    size_t readSize = fread(pData, 1, fileSize, pInFile);

    // Copy to destination
    if (isBinary)
    {
        (*pBinaryData).resize(readSize);
        memcpy(&(*pBinaryData)[0], pData, readSize);
    }
    else
    {
        *pTextData = pData;
    }

    // Clean up
    delete[] pData;
    fclose(pInFile);

    return result;
}
// =====================================================================================================================
// Reads whole file content
// NOTE: The input file name is  from class member "fileName" and read result is stored in shaderSource or m_spvBin
// according to file type
Reads whole file content
NOTE: The input file name is  from class member "fileName" and read result is stored in shaderSource or m_spvBin
according to file type
Reads whole file content NOTE : The input file name is from class member " fileName " and read result is stored in shaderSource or m_spvBin according to file type
bool Section::ReadFile(
    const std::string&    docFilename,      
    const std::string&    fileName,         
    bool                  isBinary,         
    std::vector<uint8_t>* pBinaryData,      
    std::string*          pTextData,        
    std::string*          pErrorMsg)        
{
    bool result = true;
    std::string path;
    auto separatorIndex = docFilename.find_last_of("/\\");
    if (separatorIndex != std::string::npos)
    {
        path = docFilename.substr(0, separatorIndex + 1);
    }
    path += fileName;
    FILE* pInFile = fopen(path.c_str(), isBinary ? "rb" : "r");
    if (pInFile == nullptr)
    {
        PARSE_ERROR(*pErrorMsg, 0, "Fails to open input file: %s\n", path.c_str());
        return false;
    }
    fseek(pInFile, 0, SEEK_END);
    size_t fileSize = ftell(pInFile);
    fseek(pInFile, 0, SEEK_SET);
    char* pData = new char[fileSize + 1];
    VFX_ASSERT(pData != nullptr);
    memset(pData, 0, fileSize + 1);
    size_t readSize = fread(pData, 1, fileSize, pInFile);
    if (isBinary)
    {
        (*pBinaryData).resize(readSize);
        memcpy(&(*pBinaryData)[0], pData, readSize);
    }
    else
    {
        *pTextData = pData;
    }
    delete[] pData;
    fclose(pInFile);
    return result;
}
bool Section :: ReadFile ( const std :: string & docFilename , const std :: string & fileName , bool isBinary , std :: vector < uint8_t > * pBinaryData , std :: string * pTextData , std :: string * pErrorMsg ) { bool result = true ; std :: string path ; auto separatorIndex = docFilename . find_last_of ( " \\ " ) ; if ( separatorIndex != std :: string :: npos ) { path = docFilename . substr ( 0 , separatorIndex + 1 ) ; } path += fileName ; FILE * pInFile = fopen ( path . c_str ( ) , isBinary ? " " : " " ) ; if ( pInFile == nullptr ) { PARSE_ERROR ( * pErrorMsg , 0 , " \n " , path . c_str ( ) ) ; return false ; } fseek ( pInFile , 0 , SEEK_END ) ; size_t fileSize = ftell ( pInFile ) ; fseek ( pInFile , 0 , SEEK_SET ) ; char * pData = new char [ fileSize + 1 ] ; VFX_ASSERT ( pData != nullptr ) ; memset ( pData , 0 , fileSize + 1 ) ; size_t readSize = fread ( pData , 1 , fileSize , pInFile ) ; if ( isBinary ) { ( * pBinaryData ) . resize ( readSize ) ; memcpy ( & ( * pBinaryData ) [ 0 ] , pData , readSize ) ; } else { * pTextData = pData ; } delete [ ] pData ; fclose ( pInFile ) ; return result ; }
Reads whole file content
NOTE: The input file name is  from class member "fileName" and read result is stored in shaderSource or m_spvBin
according to file type
Reads whole file content NOTE : The input file name is from class member " fileName " and read result is stored in shaderSource or m_spvBin according to file type
// [in] File name of parent document // [in] File name // Whether file is SPIRV binary file // [out] Binary data // [out] Text data // [out] Error message // Prepend directory from "docFilename" to the given filename. // Open file // Get file size // Allocate temp buffer and read file // Copy to destination // Clean up