Пример #1
0
// interface functions
void MFTexture_CreatePlatformSpecific(MFTexture *pTexture, bool generateMipChain)
{
	MFTextureTemplateData *pTemplate = pTexture->pTemplateData;

	// create texture
	D3DFORMAT platformFormat = (D3DFORMAT)MFTexture_GetPlatformFormatID(pTemplate->imageFormat, MFDD_XBOX);

#if defined(XB_XGTEXTURES)
	pTexture->pTexture = &pTexture->texture;
	XGSetTextureHeader(pTemplate->pSurfaces[0].width, pTemplate->pSurfaces[0].height, 1, 0, platformFormat, 0, pTexture->pTexture, 0, 0);
	pTexture->pTexture->Register(pTemplate->pSurfaces[0].pImageData);

	if(pTemplate->imageFormat >= TexFmt_XB_A8R8G8B8s && pTemplate->imageFormat <= TexFmt_XB_R4G4B4A4s)
	{
		XGSwizzleRect(pTemplate->pSurfaces[0].pImageData, 0, NULL, pTemplate->pSurfaces[0].pImageData, pTemplate->pSurfaces[0].width, pTemplate->pSurfaces[0].height, NULL, pTemplate->pSurfaces[0].bitsPerPixel/8);
	}
#else

	HRESULT hr;
	hr = D3DXCreateTexture(pd3dDevice, pTemplate->pSurfaces[0].width, pTemplate->pSurfaces[0].height, generateMipChain ? 0 : 1, 0, platformFormat, 0, &pTexture->pTexture);

	MFDebug_Assert(hr != D3DERR_NOTAVAILABLE, MFStr("LoadTexture failed: D3DERR_NOTAVAILABLE, 0x%08X", hr));
	MFDebug_Assert(hr != D3DERR_OUTOFVIDEOMEMORY, MFStr("LoadTexture failed: D3DERR_OUTOFVIDEOMEMORY, 0x%08X", hr));
	MFDebug_Assert(hr != D3DERR_INVALIDCALL, MFStr("LoadTexture failed: D3DERR_INVALIDCALL, 0x%08X", hr));
	MFDebug_Assert(hr != D3DXERR_INVALIDDATA, MFStr("LoadTexture failed: D3DXERR_INVALIDDATA, 0x%08X", hr));

	MFDebug_Assert(hr == D3D_OK, MFStr("Failed to create texture '%s'.", pTexture->name));

	// copy image data
	D3DLOCKED_RECT rect;
	pTexture->pTexture->LockRect(0, &rect, NULL, 0);

	if(pTemplate->imageFormat >= TexFmt_XB_A8R8G8B8s && pTemplate->imageFormat <= TexFmt_XB_R4G4B4A4s)
	{
		XGSwizzleRect(pTemplate->pSurfaces[0].pImageData, 0, NULL, rect.pBits, pTemplate->pSurfaces[0].width, pTemplate->pSurfaces[0].height, NULL, pTemplate->pSurfaces[0].bitsPerPixel/8);
	}
	else
	{
		MFCopyMemory(rect.pBits, pTemplate->pSurfaces[0].pImageData, pTemplate->pSurfaces[0].bufferLength);
	}

	pTexture->pTexture->UnlockRect(0);

	// filter mip levels
	if(generateMipChain)
		D3DXFilterTexture(pTexture->pTexture, NULL, 0, D3DX_DEFAULT);
#endif
}
Пример #2
0
bool CRGBRenderer::Create444PTexture()
{
  CSingleLock lock(g_graphicsContext);
  if (!m_444PTexture[FIELD_FULL])
  {
    unsigned stride = ALIGN(m_iSourceWidth<<2,D3DTEXTURE_ALIGNMENT);
    void* data = D3D_AllocContiguousMemory( stride*m_iSourceHeight, D3DTEXTURE_ALIGNMENT );

    for(int f=0;f<MAX_FIELDS;f++)
    {
      m_444PTexture[f] = new D3DTexture();
      m_444PTexture[f]->AddRef();
    }

    XGSetTextureHeader(m_iSourceWidth, m_iSourceHeight,    1, 0, D3DFMT_LIN_A8R8G8B8, 0, m_444PTexture[0], 0,      stride);
    XGSetTextureHeader(m_iSourceWidth, m_iSourceHeight>>1, 1, 0, D3DFMT_LIN_A8R8G8B8, 0, m_444PTexture[1], 0,      stride<<1);
    XGSetTextureHeader(m_iSourceWidth, m_iSourceHeight>>1, 1, 0, D3DFMT_LIN_A8R8G8B8, 0, m_444PTexture[2], stride, stride<<1);

    for(int f=0;f<MAX_FIELDS;f++)
      m_444PTexture[f]->Register(data);

    CLog::Log(LOGINFO, "Created 444P texture");
  }