Classes | |
struct | TextureFormat |
Static Public Member Functions | |
static bool | loadOverride (FTextureInfo &Info, DWORD PolyFlags) |
static void | convertAndCache (FTextureInfo &Info, DWORD PolyFlags) |
static void | update (FTextureInfo &Info, DWORD PolyFlags) |
Static Private Member Functions | |
static void | convertMip (FTextureInfo &Info, TextureFormat &format, DWORD PolyFlags, int mipLevel, D3D10_SUBRESOURCE_DATA &data) |
static D3D::TextureMetaData | buildMetaData (FTextureInfo &Info, DWORD PolyFlags, DWORD customPolyFlags=0) |
Format conversion functions | |
static void | fromPaletted (FTextureInfo &Info, DWORD PolyFlags, void *target, int mipLevel) |
static void | fromBGRA7 (FTextureInfo &Info, DWORD PolyFlags, void *target, int mipLevel) |
Static Private Attributes | |
static TexConversion::TextureFormat | formats [] |
Functions to convert from Unreal format textures to standard R8G8B8A8 Direct3D 10 format inital data. Uses both Unreal and Direct3D datatypes, but no access to D3D objects like the device etc.
The game has two types of textures: static ones and dynamic. Dynamic texures are parametric ones such as water, etc. After trying multiple methods, it was determined best to create static textures as USAGE_IMMUTABLE, and dynamic ones as USAGE_DEFAULT (i.e. not USAGE_DYNAMIC). USAGE_DEFAULT textures cannot be mapped, but they are updated using a copy operation. A nice thing about this is that it allows the texture handling to be streamlined; it used to have seperate paths for map()-able and immutable textures. However copy-able and immutable textures can be handled about the same way as they both are created from initial data, instead of being filled after their creation.
Some texture types can be used by D3D without conversion; depending on the type (see formats array below) direct assignments can take place.
New textures are created by having the D3D class create a texture out of their converted/assigned mips stored as D3D_SUBRESOURCE_DATA; the texture conversion function sets the TEXTURE_2D_DESC parameters for this depending on the texture size, if it is dynamic, etc. Existing textures are updated by passing a new mip to the D3D class; only the 0th mip is updated, which should be fine (afaik there's no dynamic textures with >1 mips).
Texture conversion functions write to a void pointer so they can work unmodified regardless of the underlying memory.
Additional notes:
Override/extra textures: Textures can be overridden by external .dds files. Additionally, extra layers (bump, detail) can be provided even if the texture didn't come with these. These are stored in the texture's extraExternalTextures array. When a diffuse texture is applied, the extra textures set here will be used instead of the bump/detail layers provided by the game (if any). Implementation wise this means that override textures replace the originals in the texture cache. However, extra textures are linked to their parent, so the originals, if there are any, are still present in the cache (as these can be used by other textures).
Only real textures, not lightmaps, fogmaps etc. can be overridden. Every overrideable texture type can have extra textures assigned. However, the renderer chooses when to apply these, which only makes sense for diffuse textures.
Finally, each override texture can have custom polyflags in a file, these are loaded and ORed by the renderer with the flags provided to draw calls. Especially useful to force alpha blending instead of masking.
D3D::TextureMetaData TexConversion::buildMetaData | ( | FTextureInfo & | Info, | |
DWORD | PolyFlags, | |||
DWORD | customPolyFlags = 0 | |||
) | [static, private] |
Build metadata from Unreal info
void TexConversion::convertAndCache | ( | FTextureInfo & | Info, | |
DWORD | PolyFlags | |||
) | [static] |
Fill texture info structure and execute proper conversion of pixel data.
Info | Unreal texture information, includes cache id, size information, texture data. | |
PolyFlags | Polyflags, see polyflags.h. |
void TexConversion::convertMip | ( | FTextureInfo & | Info, | |
TextureFormat & | format, | |||
DWORD | PolyFlags, | |||
int | mipLevel, | |||
D3D10_SUBRESOURCE_DATA & | data | |||
) | [static, private] |
Fills a D3D10_SUBRESOURCE_DATA structure with converted texture data for a mipmap; if possible, assigns instead of converts.
Info | Unreal texture info. | |
format | Conversion parameters for the texture. | |
PolyFlags | Polyflags. See polyflags.h. | |
mipLevel | Which mip to convert. | |
data | Direct3D 10 structure which will be filled. |
void TexConversion::fromBGRA7 | ( | FTextureInfo & | Info, | |
DWORD | PolyFlags, | |||
void * | target, | |||
int | mipLevel | |||
) | [static, private] |
BGRA7 to RGBA8. Used for lightmaps and fog. Straightforward, just multiply by 2.
void TexConversion::fromPaletted | ( | FTextureInfo & | Info, | |
DWORD | PolyFlags, | |||
void * | target, | |||
int | mipLevel | |||
) | [static, private] |
Convert from palleted 8bpp to r8g8b8a8.
bool TexConversion::loadOverride | ( | FTextureInfo & | Info, | |
DWORD | PolyFlags | |||
) | [static] |
Load a texture from file instead of the one passed by the game.
void TexConversion::update | ( | FTextureInfo & | Info, | |
DWORD | PolyFlags | |||
) | [static] |
Update a dynamic texture by converting its 0th mip and letting D3D update it.
TexConversion::TextureFormat TexConversion::formats [static, private] |
{ {true,0,false,DXGI_FORMAT_R8G8B8A8_UNORM,&TexConversion::fromPaletted}, {true,0,true,DXGI_FORMAT_R8G8B8A8_UNORM,NULL}, {false,0,true,DXGI_FORMAT_R8G8B8A8_UNORM,NULL}, {true,4,true,DXGI_FORMAT_BC1_UNORM,NULL}, {false,0,true,DXGI_FORMAT_UNKNOWN,NULL}, {true,0,true,DXGI_FORMAT_R8G8B8A8_UNORM,NULL}, }
Mappings from Unreal to our texture info