Game Development Reference
In-Depth Information
public:
D3DTextureResourceExtraData11();
virtual
D3DTextureResourceExtraData11()
{ SAFE_RELEASE(m_pTexture); SAFE_RELEASE(m_pSamplerLinear); }
virtual std::string VToString() { return
˜
D3DTextureResourceExtraData11
;}
ID3D11ShaderResourceView * const *GetTexture() { return &m_pTexture; }
ID3D11SamplerState * const *GetSampler() { return &m_pSamplerLinear; }
protected:
ID3D11ShaderResourceView *m_pTexture;
ID3D11SamplerState* m_pSamplerLinear;
};
This class simply encapsulates the two interfaces Direct3D 11 needs to access tex-
tures. Next, we define a loader class for textures:
class TextureResourceLoader : public IResourceLoader
{
public:
virtual bool VUseRawFile() { return false; }
virtual bool VDiscardRawBufferAfterLoad() { return true; }
virtual unsigned int VGetLoadedResourceSize(char *rawBuffer,
unsigned int rawSize)
{ return 0; }
virtual bool VLoadResource(char *rawBuffer, unsigned int rawSize,
shared_ptr<ResHandle> handle);
};
The class helps the resource cache know how to process the raw texture bits. First,
VUseRawFile() tells the resource cache to expect some processing after the raw
bits are available in memory. The method VDiscardRawBufferAfterLoad() tells
the resource cache that once the raw bits have been processed they are no longer
needed and don ' t have to be counted as taking up space in the resource cache,
which also describes why VGetLoadedResourceSize() returns zero. For textures,
Direct3D 11 manages texture memory, and while we probably could create a more
complicated relationship between our resource cache and Direct3D 11, for now
we
ll stick to something simpler. The last method is what does the processing of the
raw texture bits into something Direct3D 11 can consume. If you weren
'
t using a
resource cache at all, this method is all you really would need after the texture file
is read into memory:
'
bool TextureResourceLoader::VLoadResource(char *rawBuffer,
unsigned int rawSize, shared_ptr<ResHandle> handle)
Search WWH ::




Custom Search