Exemplo n.º 1
0
LPDIRECT3DTEXTURE9 DepalShaderCacheDX9::GetClutTexture(const u32 clutID, u32 *rawClut) {
	GEPaletteFormat palFormat = gstate.getClutPaletteFormat();
	const u32 realClutID = clutID ^ palFormat;

	auto oldtex = texCache_.find(realClutID);
	if (oldtex != texCache_.end()) {
		oldtex->second->lastFrame = gpuStats.numFlips;
		return oldtex->second->texture;
	}

	D3DFORMAT dstFmt = DX9::getClutDestFormat(palFormat);
	int texturePixels = palFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512;

	DepalTextureDX9 *tex = new DepalTextureDX9();

	// Create texture
	D3DPOOL pool = D3DPOOL_MANAGED;
	int usage = 0;
	if (pD3DdeviceEx) {
		pool = D3DPOOL_DEFAULT;
		usage = D3DUSAGE_DYNAMIC;  // TODO: Switch to using a staging texture?
	}

	HRESULT hr = pD3Ddevice->CreateTexture(texturePixels, 1, 1, usage, (D3DFORMAT)D3DFMT(dstFmt), pool, &tex->texture, NULL);
	if (FAILED(hr)) {
		ERROR_LOG(G3D, "Failed to create D3D texture for depal");
		delete tex;
		return nullptr;
	}

	D3DLOCKED_RECT rect;
	hr = tex->texture->LockRect(0, &rect, NULL, 0);
	if (FAILED(hr)) {
		ERROR_LOG(G3D, "Failed to lock D3D texture for depal");
		delete tex;
		return nullptr;
	}
	// Regardless of format, the CLUT should always be 1024 bytes.
	memcpy(rect.pBits, rawClut, 1024);
	tex->texture->UnlockRect(0);

	pD3Ddevice->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
	pD3Ddevice->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
	pD3Ddevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);
	pD3Ddevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);

	tex->lastFrame = gpuStats.numFlips;
	texCache_[realClutID] = tex;
	return tex->texture;
}
Exemplo n.º 2
0
FramebufferManagerDX9::FramebufferManagerDX9() :
	displayFramebufPtr_(0),
	displayStride_(0),
	displayFormat_(GE_FORMAT_565),
	displayFramebuf_(0),
	prevDisplayFramebuf_(0),
	prevPrevDisplayFramebuf_(0),
	frameLastFramebufUsed(0),
	currentRenderVfb_(0),
	drawPixelsTex_(0),
	drawPixelsTexFormat_(GE_FORMAT_INVALID),
	convBuf(0)
{
	// And an initial clear. We don't clear per frame as the games are supposed to handle that
	// by themselves.
	ClearBuffer();

#ifdef _XBOX
	pD3Ddevice->CreateTexture(512, 272, 1, 0, D3DFMT(D3DFMT_A8R8G8B8), NULL, &drawPixelsTex_, NULL);
#else
	pD3Ddevice->CreateTexture(512, 272, 1, 0, D3DFMT(D3DFMT_A8R8G8B8), D3DPOOL_MANAGED, &drawPixelsTex_, NULL);
#endif
	useBufferedRendering_ = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
}