2012-07-16 00:15:47 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2013-01-01 00:37:37 +00:00
|
|
|
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2013 - Daniel De Matteis
|
2012-07-16 00:15:47 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-07-15 23:58:15 +00:00
|
|
|
#ifndef RARCH_XDK_RESOURCE_H
|
|
|
|
#define RARCH_XDK_RESOURCE_H
|
|
|
|
|
2012-07-16 00:15:47 +00:00
|
|
|
#include "xdk_defines.h"
|
2012-07-15 23:58:15 +00:00
|
|
|
|
|
|
|
DWORD XBResource_SizeOf( LPDIRECT3DRESOURCE pResource );
|
|
|
|
|
|
|
|
//structure member offsets matter
|
|
|
|
struct XBRESOURCE
|
|
|
|
{
|
|
|
|
#if defined(_XBOX1)
|
2013-01-09 06:27:05 +00:00
|
|
|
CHAR* strName;
|
|
|
|
DWORD dwOffset;
|
2012-07-15 23:58:15 +00:00
|
|
|
#elif defined(_XBOX360)
|
2013-01-09 06:27:05 +00:00
|
|
|
DWORD dwType;
|
|
|
|
DWORD dwOffset;
|
|
|
|
DWORD dwSize;
|
|
|
|
CHAR* strName;
|
2012-07-15 23:58:15 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2013-01-09 06:27:05 +00:00
|
|
|
RESOURCETYPE_USERDATA = ( ( 'U' << 24 ) | ( 'S' << 16 ) | ( 'E' << 8 ) | ( 'R' ) ),
|
|
|
|
RESOURCETYPE_TEXTURE = ( ( 'T' << 24 ) | ( 'X' << 16 ) | ( '2' << 8 ) | ( 'D' ) ),
|
|
|
|
RESOURCETYPE_VERTEXBUFFER = ( ( 'V' << 24 ) | ( 'B' << 16 ) | ( 'U' << 8 ) | ( 'F' ) ),
|
|
|
|
RESOURCETYPE_INDEXBUFFER = ( ( 'I' << 24 ) | ( 'B' << 16 ) | ( 'U' << 8 ) | ( 'F' ) ),
|
|
|
|
RESOURCETYPE_EOF = 0xffffffff
|
2012-07-15 23:58:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PackedResource
|
|
|
|
{
|
2013-01-09 06:27:05 +00:00
|
|
|
protected:
|
|
|
|
BYTE* m_pSysMemData; // Alloc'ed memory for resource headers etc.
|
|
|
|
DWORD m_dwSysMemDataSize;
|
|
|
|
|
|
|
|
BYTE* m_pVidMemData; // Alloc'ed memory for resource data, etc.
|
|
|
|
DWORD m_dwVidMemDataSize;
|
|
|
|
|
|
|
|
XBRESOURCE* m_pResourceTags; // Tags to associate names with the resources
|
|
|
|
DWORD m_dwNumResourceTags; // Number of resource tags
|
|
|
|
BOOL m_bInitialized; // Resource is fully initialized
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Loads the resources out of the specified bundle
|
2012-07-15 23:58:15 +00:00
|
|
|
#if defined(_XBOX1)
|
2013-01-09 06:27:05 +00:00
|
|
|
HRESULT Create( const char *strFilename, DWORD dwNumResourceTags = 0L,
|
|
|
|
XBRESOURCE* pResourceTags = NULL );
|
2012-07-15 23:58:15 +00:00
|
|
|
#elif defined(_XBOX360)
|
2013-01-09 06:27:05 +00:00
|
|
|
HRESULT Create( const char * strFilename );
|
2012-07-15 23:58:15 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-09 06:27:05 +00:00
|
|
|
void Destroy();
|
2012-07-15 23:58:15 +00:00
|
|
|
|
2013-01-09 06:27:05 +00:00
|
|
|
BOOL Initialized() const;
|
2012-07-15 23:58:15 +00:00
|
|
|
|
|
|
|
#ifdef _XBOX360
|
2013-01-09 06:27:05 +00:00
|
|
|
// Retrieves the resource tags
|
|
|
|
void GetResourceTags( DWORD* pdwNumResourceTags, XBRESOURCE** ppResourceTags );
|
2012-07-15 23:58:15 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-09 06:27:05 +00:00
|
|
|
// Helper function to make sure a resource is registered
|
|
|
|
LPDIRECT3DRESOURCE RegisterResource( LPDIRECT3DRESOURCE pResource ) const
|
|
|
|
{
|
2012-07-15 23:58:15 +00:00
|
|
|
#ifdef _XBOX1
|
2013-01-09 06:27:05 +00:00
|
|
|
// Register the resource, if it has not yet been registered. We mark
|
|
|
|
// a resource as registered by upping it's reference count.
|
|
|
|
if( pResource && ( pResource->Common & D3DCOMMON_REFCOUNT_MASK ) == 1 )
|
|
|
|
{
|
2012-07-15 23:58:15 +00:00
|
|
|
// Special case CPU-copy push buffers (which live in system memory)
|
|
|
|
if( ( pResource->Common & D3DCOMMON_TYPE_PUSHBUFFER ) &&
|
2013-01-09 06:27:05 +00:00
|
|
|
( pResource->Common & D3DPUSHBUFFER_RUN_USING_CPU_COPY ) )
|
|
|
|
pResource->Data += (DWORD)m_pSysMemData;
|
2012-07-15 23:58:15 +00:00
|
|
|
else
|
2013-01-09 06:27:05 +00:00
|
|
|
pResource->Register( m_pVidMemData );
|
2012-07-15 23:58:15 +00:00
|
|
|
|
|
|
|
pResource->AddRef();
|
2013-01-09 06:27:05 +00:00
|
|
|
}
|
2012-07-15 23:58:15 +00:00
|
|
|
#endif
|
2013-01-09 06:27:05 +00:00
|
|
|
return pResource;
|
|
|
|
}
|
2012-07-15 23:58:15 +00:00
|
|
|
|
2013-01-09 06:27:05 +00:00
|
|
|
// Functions to retrieve resources by their offset
|
|
|
|
void *GetData( DWORD dwOffset ) const
|
|
|
|
{ return &m_pSysMemData[dwOffset]; }
|
2012-07-15 23:58:15 +00:00
|
|
|
|
2013-01-09 06:27:05 +00:00
|
|
|
LPDIRECT3DRESOURCE GetResource( DWORD dwOffset ) const
|
|
|
|
{ return RegisterResource( (LPDIRECT3DRESOURCE)GetData(dwOffset) ); }
|
2012-07-15 23:58:15 +00:00
|
|
|
|
2013-01-09 06:27:05 +00:00
|
|
|
LPDIRECT3DTEXTURE GetTexture( DWORD dwOffset ) const
|
|
|
|
{ return (LPDIRECT3DTEXTURE)GetResource( dwOffset ); }
|
2012-07-15 23:58:15 +00:00
|
|
|
|
2013-01-09 06:27:05 +00:00
|
|
|
LPDIRECT3DVERTEXBUFFER GetVertexBuffer( DWORD dwOffset ) const
|
|
|
|
{ return (LPDIRECT3DVERTEXBUFFER)GetResource( dwOffset ); }
|
2012-07-15 23:58:15 +00:00
|
|
|
|
2013-01-09 06:27:05 +00:00
|
|
|
// Functions to retrieve resources by their name
|
|
|
|
void *GetData( const CHAR* strName ) const;
|
2012-07-15 23:58:15 +00:00
|
|
|
|
2013-01-09 06:27:05 +00:00
|
|
|
LPDIRECT3DRESOURCE GetResource( const CHAR* strName ) const
|
|
|
|
{ return RegisterResource( (LPDIRECT3DRESOURCE)GetData( strName ) ); }
|
2012-07-15 23:58:15 +00:00
|
|
|
|
2013-01-09 06:27:05 +00:00
|
|
|
LPDIRECT3DTEXTURE GetTexture( const CHAR* strName ) const
|
|
|
|
{ return (LPDIRECT3DTEXTURE)GetResource( strName ); }
|
2012-07-15 23:58:15 +00:00
|
|
|
|
2013-01-09 06:27:05 +00:00
|
|
|
LPDIRECT3DVERTEXBUFFER GetVertexBuffer( const CHAR* strName ) const
|
|
|
|
{ return (LPDIRECT3DVERTEXBUFFER)GetResource( strName ); }
|
2012-07-15 23:58:15 +00:00
|
|
|
|
2013-01-09 06:27:05 +00:00
|
|
|
// Constructor/destructor
|
|
|
|
PackedResource();
|
|
|
|
~PackedResource();
|
2012-07-15 23:58:15 +00:00
|
|
|
};
|
|
|
|
|
2013-01-22 00:05:48 +00:00
|
|
|
#endif /* RARCH_XDK_RESOURCE_H */
|