nn::gd::CTR::Resource Class

Syntax

class Resource

Description

The class of resource functions.

The term resource refers to two-dimensional regions like pixels (Texture2DResource), as well as regions like vertex buffers and index buffers (VertexBufferResource). When a resource is created, memory is allocated to the resource. Resources are created using the ResourceCreateTexture2DResource function or the ResourceCreateVertexBufferResource function. When a resource is released, the allocated memory is also released.


Note: Relation between resources and the NNGX command request queue

You need to be careful when releasing initialData passed to the Resource::CreateTexture2DResource function or the ResourceCreateVertexBufferResource function. If Texture2DResourceDescription.m_MemLocation has been set to MemoryVRAMA or MemoryVRAMB, problems can occur if initialData is released immediately after the resource has been created. If Texture2DResourceDescription.m_MemLocation is set to a VRAM location, then DMA transfer requests for the initialData data will accumulate in the command buffer. It is a copy of the actual data that is used when commands execute. For this reason, the user application must retain initialData until the commands have finished executing.
Remark: If initialData is created in FCRAM, then the data are transferred using the memcpy function, so it is all right to release initialData immediately after creating the resource.


For Texture2DResource resources

Texture2DResource resources cannot be bound directly to pipeline stages, so they must be created using Texture2DResource from inside the following objects:

Texture2 is created using the TextureStageCreateTexture2D function.
TextureCube is created using the TextureStageCreateTextureCube function.
RenderTarget is created using the OutputStageCreateRenderTarget function. Create DepthStencilTarget using the OutputStageCreateDepthStencilTarget function.

This mechanism allows you to use a single resource in a number of different ways in the user application. For example, after you have bound some Texture2DResource resource to a RenderTarget and completed the render task, you could use the result as a 2D texture.
Below is a list of functions that can be bound to pipeline stages and utilize Texture2DResource resources:

TextureStage::SetTexture(TextureUnitId, Texture2D &texture2D)
TextureStage::SetTextureUnit0(TextureCube &textureCube)
OutputStage::SetRenderTarget(const RenderTarget *renderTarget)
OutputStage::SetDepthStencilTarget(const DepthStencilTarget *depthStencil)


For vertex resources

Since there is only one way to use each buffer, you can directly bind vertex resources to VertexInputStage.
Below is a list of functions that can be bound to pipeline stages and utilize vertex resources:

VertexInputStage::SetIndexBuffer(VertexBufferResource *indexBuffer, IndexFormat format, u32 offset)
VertexInputStage::SetVertexBuffers(u32 startSlot, u32 numBuffers, VertexBufferResource **vertexBuffers, u32 *offsets)

Classes

nn::gd::CTR::Resource::Helper Utility function for converting the format of texture resources.

Enumerated Types

NativeFormat The enum values for native format texture resources.
Format The enum values for texture resource formats.
CompressedFormat The enum values for compressed texture resource formats.
MapUsage The method for mapping the resource,

Member Functions

Texture resources:
S CreateTexture2DResource Creates a 2D texture resource.
S CreateTexture2DResourceCastFrom Casts an existing Texture2DResource resource in a different format.
S GetTexture2DResourceProperties Gets detailed information about a 2D texture resource.
S ReleaseTexture2DResource Releases a 2D texture resource.
S MapTexture2DResource Obtains a data pointer to the specified resource.
S UnmapTexture2DResource Releases the data pointer to a resource.
Vertex buffer resources:
S CreateVertexBufferResource Creates a vertex buffer resource.
S GetVertexBufferResourceProperties Gets detailed information for a vertex buffer resource.
S MapVertexBufferResource Obtains a data pointer to the specified resource.
S UnmapVertexBufferResource Releases the data pointer to a resource.
S ReleaseVertexBufferResource Releases a vertex buffer resource.

Revision History

2011/02/15
Initial version.

CONFIDENTIAL