About Binary Resources

Setup and Cleanup

Binary resources are loaded from their files as ResGraphicsFile objects. You must run Setup before creating instances of the Model or other items from the loaded ResGraphicsFile. For the setup, use the Setup for ResGraphicsFile, or the Setup for ResModel. The main setup processes are as follows.

  1. Resolving references to shaders, textures, and lookup tables
  2. VRAM transfer for textures and vertex streams
  3. Generating rendering and shader commands
  4. Checking for data errors

After a properly setup binary resource is no longer needed, you must run Cleanup and then release it.

Process According to Setup Results

Running Setup on a binary resource returns a Result. The Result from Setup is a ResourceResult object. Error handling would look like the following.

Change Binary Resource Values

You can change binary resource values via the Res* class accessor. However, when changing values, you must also set the hash to 0. The following table shows how class and variable names correspond to hashes.

Class / Var Name Hash
ResMaterial::m_Flags ShadingParameterHash
ResShaderParameter ShaderParametersHash
ResTextureCoordinator TextureCoordinatorsHash
ResPixelBasedTextureMapper, ResStandardTextureSampler TextureMappersHash
ResMaterialColor MaterialColorHash
ResRasterization RasterizationHash
ResFragmentLighting FragmentLightingHash
ResFragmentLightingTable FragmentLightingTableHash
ResAlphaTest AlphaTestHash
ResTextureCombiner TextureCombinersHash
ResFragmentOperation FragmentOperationHash

Users Handling VRAM Transfers

When running Setup using multiple threads, the user must handle VRAM transfers. Handling all VRAM transfers at once is also more efficient than dealing with VRAM transfers within Setup. The process is as follows.

  1. Get the texture or vertex image data block.
    nw::gfx::ResGraphicsFile resFile = resourceSet->resource;
    void* imageData = resFile.GetImageBlockData();
                    
  2. Bundle the textures or vertices and transfer to VRAM.
    s32 size = resFile.GetImageBlockDataSize();
           
    void* vramAddr = nw::demo::AllocateGraphicsMemory(NN_GX_MEM_VRAMA, NN_GX_MEM_TEXTURE, 0, size);
            
    // Flush the data cache and transfer to VRAM.
    nngxUpdateBuffer( imageData, size );
    nngxAddVramDmaCommand( imageData, vramAddr, size );
                    
  3. Set the address of the transferred image data to the resource before running Setup.
    nw::gfx::TransferedVramAddressSetter locationSetter( imageData, vramAddr );
    resFile.ForeachTexture(locationSetter);
    resFile.ForeachIndexStream(locationSetter);
    resFile.ForeachVertexStream(locationSetter);
                    


CONFIDENTIAL