本文整理汇总了C++中IDirect3DDevice9::GetRenderTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirect3DDevice9::GetRenderTarget方法的具体用法?C++ IDirect3DDevice9::GetRenderTarget怎么用?C++ IDirect3DDevice9::GetRenderTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirect3DDevice9
的用法示例。
在下文中一共展示了IDirect3DDevice9::GetRenderTarget方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Enable
//----------------------------------------------------------------------------
void PdrRenderTarget::Enable (Renderer* renderer)
{
IDirect3DDevice9* device = renderer->mData->mDevice;
HRESULT hr;
WM5_UNUSED(hr);
hr = device->GetRenderTarget(0, &mSaveColorSurface);
assertion(hr == D3D_OK, "Failed to get old rt 0 color surface: %s\n",
DXGetErrorString(hr));
// The viewport is automatically set by this call.
hr = device->SetRenderTarget(0, mColorSurfaces[0]);
assertion(hr == D3D_OK, "Failed to set new rt 0 color surface: %s\n",
DXGetErrorString(hr));
for (int i = 1; i < mNumTargets; ++i)
{
hr = device->SetRenderTarget((DWORD)i, mColorSurfaces[i]);
assertion(hr == D3D_OK, "Failed to set new rt %d color surface: %s\n",
i, DXGetErrorString(hr));
}
if (mHasDepthStencil)
{
hr = device->GetDepthStencilSurface(&mSaveDepthStencilSurface);
assertion(hr == D3D_OK,
"Failed to get old rt depthstencil surface: %s\n",
DXGetErrorString(hr));
hr = device->SetDepthStencilSurface(mDepthStencilSurface);
assertion(hr == D3D_OK,
"Failed to set new rt depthstencil surface: %s\n",
DXGetErrorString(hr));
}
}
示例2: if
bool MythRenderD3D9::SetRenderTarget(IDirect3DTexture9 *texture)
{
D3D9Locker locker(this);
IDirect3DDevice9* dev = locker.Acquire();
if (!dev)
return false;
bool ret = true;
HRESULT hr;
if (texture && m_textures.contains(texture))
{
if (!m_default_surface)
{
hr = dev->GetRenderTarget(0, &m_default_surface);
if (FAILED(hr))
{
LOG(VB_GENERAL, LOG_ERR, D3DLOC +
"Failed to get default surface.");
return false;
}
}
IDirect3DSurface9 *new_surface = NULL;
hr = texture->GetSurfaceLevel(0, &new_surface);
if (FAILED(hr))
LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to get surface level.");
else
{
if (m_current_surface && m_current_surface != new_surface)
m_current_surface->Release();
m_current_surface = new_surface;
hr = dev->SetRenderTarget(0, m_current_surface);
if (FAILED(hr))
LOG(VB_GENERAL, LOG_ERR, D3DLOC +
"Failed to set render target.");
}
}
else if (!texture)
{
if (m_default_surface)
{
hr = dev->SetRenderTarget(0, m_default_surface);
if (FAILED(hr))
LOG(VB_GENERAL, LOG_ERR, D3DLOC +
"Failed to set render target.");
}
else
LOG(VB_GENERAL, LOG_ERR, D3DLOC +
"No default surface for render target.");
}
else
ret = false;
return ret;
}
示例3: saveState
void Blit::saveState()
{
IDirect3DDevice9 *device = getDevice();
HRESULT hr;
device->GetDepthStencilSurface(&mSavedDepthStencil);
device->GetRenderTarget(0, &mSavedRenderTarget);
if (mSavedStateBlock == NULL)
{
hr = device->BeginStateBlock();
ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY);
setCommonBlitState();
static const float dummyConst[4] = { 0, 0, 0, 0 };
device->SetVertexShader(NULL);
device->SetVertexShaderConstantF(0, dummyConst, 1);
device->SetPixelShader(NULL);
device->SetPixelShaderConstantF(0, dummyConst, 1);
D3DVIEWPORT9 dummyVp;
dummyVp.X = 0;
dummyVp.Y = 0;
dummyVp.Width = 1;
dummyVp.Height = 1;
dummyVp.MinZ = 0;
dummyVp.MaxZ = 1;
device->SetViewport(&dummyVp);
device->SetTexture(0, NULL);
device->SetStreamSource(0, mQuadVertexBuffer, 0, 0);
device->SetVertexDeclaration(mQuadVertexDeclaration);
hr = device->EndStateBlock(&mSavedStateBlock);
ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY);
}
ASSERT(mSavedStateBlock != NULL);
if (mSavedStateBlock != NULL)
{
hr = mSavedStateBlock->Capture();
ASSERT(SUCCEEDED(hr));
}
}
示例4: onRender
void RootViewPlay::onRender(const ::bootes::lib::framework::GameTime* gt)
{
HRESULT hr;
::bootes::lib::util::Timer timer;
int dt[10];
int ti = 0;
IDirect3DDevice9* pDev = g_pFnd->getD3D9Device();
if (pDev == NULL) { return; }
hr = pDev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1, 0 );
timer.start();
_pGameView->onRender(gt);
timer.get(NULL, &dt[ti++]);
timer.start();
do {
//IDirect3DTexture9* pTex = scene.refTexture(); //test
Scene scene = _pGameView->getScene(true);
IDirect3DTexture9* pTex = scene.refTexture();
if (pTex == NULL) { break; }
IDirect3DSurface9* pSrc;
pTex->GetSurfaceLevel(0, &pSrc);
IDirect3DSurface9* pDst;
hr = pDev->GetRenderTarget(0, &pDst);
//hr = pDev->StretchRect(pSrc, NULL, pDst, NULL, D3DTEXF_NONE); //D3DPOOL_DEFUALT
hr = pDev->UpdateSurface(pSrc, NULL, pDst, NULL); //D3DPOOL_SYSTEM
if (hr == D3DERR_INVALIDCALL) {
DbgBreak("");
}
pDst->Release();
pSrc->Release();
pTex->Release();
} while(0);
pDev->EndScene();
/*
do {
ID3DXLine* pLine;
D3DXCreateLine(pDev, &pLine);
D3DXVECTOR2 points[] = {
D3DXVECTOR2(0,0), D3DXVECTOR2(100,100),
};
pLine->Begin();
pLine->Draw(points, 2, D3DCOLOR_ARGB(255,255,255,255));
pLine->End();
} while(0);
*/
timer.reset();
}
示例5: ASSERT
RenderTarget9::RenderTarget9(Renderer *renderer, GLsizei width, GLsizei height, GLenum internalFormat, GLsizei samples)
{
mRenderer = Renderer9::makeRenderer9(renderer);
mRenderTarget = NULL;
D3DFORMAT renderFormat = gl_d3d9::GetRenderFormat(internalFormat, mRenderer);
int supportedSamples = mRenderer->getNearestSupportedSamples(renderFormat, samples);
if (supportedSamples == -1)
{
gl::error(GL_OUT_OF_MEMORY);
return;
}
HRESULT result = D3DERR_INVALIDCALL;
GLuint clientVersion = mRenderer->getCurrentClientVersion();
if (width > 0 && height > 0)
{
IDirect3DDevice9 *device = mRenderer->getDevice();
bool requiresInitialization = false;
if (gl::GetDepthBits(internalFormat, clientVersion) > 0 ||
gl::GetStencilBits(internalFormat, clientVersion) > 0)
{
result = device->CreateDepthStencilSurface(width, height, renderFormat,
gl_d3d9::GetMultisampleType(supportedSamples),
0, FALSE, &mRenderTarget, NULL);
}
else
{
requiresInitialization = gl_d3d9::RequiresTextureDataInitialization(internalFormat);
result = device->CreateRenderTarget(width, height, renderFormat,
gl_d3d9::GetMultisampleType(supportedSamples),
0, FALSE, &mRenderTarget, NULL);
}
if (result == D3DERR_OUTOFVIDEOMEMORY ||
result == E_INVALIDARG ||
result == E_OUTOFMEMORY)
{
gl::error(GL_OUT_OF_MEMORY);
return;
}
ASSERT(SUCCEEDED(result));
if (requiresInitialization)
{
// This format requires that the data be initialized before the render target can be used
// Unfortunately this requires a Get call on the d3d device but it is far better than having
// to mark the render target as lockable and copy data to the gpu.
IDirect3DSurface9 *prevRenderTarget = NULL;
device->GetRenderTarget(0, &prevRenderTarget);
device->SetRenderTarget(0, mRenderTarget);
device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0, 0, 0, 255), 0.0f, 0);
device->SetRenderTarget(0, prevRenderTarget);
}
}
mWidth = width;
mHeight = height;
mDepth = 1;
mInternalFormat = internalFormat;
mSamples = supportedSamples;
mActualFormat = d3d9_gl::GetInternalFormat(renderFormat);
}
示例6: ReadColor
//----------------------------------------------------------------------------
void PdrRenderTarget::ReadColor (int i, Renderer* renderer,
Texture2D*& texture)
{
if (i < 0 || i >= mNumTargets)
{
assertion(false, "Invalid target index.\n");
return;
}
IDirect3DDevice9* device = renderer->mData->mDevice;
HRESULT hr;
WM5_UNUSED(hr);
// Enable the input render target surface.
if (i == 0)
{
hr = device->GetRenderTarget(0, &mSaveColorSurface);
assertion(hr == D3D_OK, "Failed to get old rt 0 color surface: %s\n",
DXGetErrorString(hr));
}
hr = device->SetRenderTarget((DWORD)i, mColorSurfaces[i]);
assertion(hr == D3D_OK,
"Failed to set new rt %d color surface: %s\n", i,
DXGetErrorString(hr));
// Make a duplicate in system memory.
IDirect3DTexture9* copyTexture = 0;
hr = D3DXCreateTexture
(
device,
(UINT)mWidth,
(UINT)mHeight,
0,
0,
gDX9TextureFormat[mFormat],
D3DPOOL_SYSTEMMEM,
©Texture
);
assertion(hr == D3D_OK,
"Failed to create copy texture: %s\n",
DXGetErrorString(hr));
// Get the surface associated with the copy.
IDirect3DSurface9* copySurface = 0;
hr = copyTexture->GetSurfaceLevel(0, ©Surface);
assertion(hr == D3D_OK,
"Failed to get surface level for copy texture: %s\n",
DXGetErrorString(hr));
// Copy the render target surface.
hr = device->GetRenderTargetData(mColorSurfaces[i], copySurface);
assertion(hr == D3D_OK,
"Failed to copy the rt %d surface: %s\n", i,
DXGetErrorString(hr));
// Get the data to write to disk.
D3DLOCKED_RECT rect;
hr = copySurface->LockRect(&rect, 0, 0);
assertion(hr == D3D_OK,
"Failed to lock copy surface: %s\n",
DXGetErrorString(hr));
if (texture)
{
if (texture->GetFormat() != mFormat ||
texture->GetWidth() != (int)mWidth ||
texture->GetHeight() != (int)mHeight)
{
assertion(false, "Incompatible texture.\n");
delete0(texture);
texture = new0 Texture2D(mFormat, mWidth, mHeight, 1);
}
}
else
{
texture = new0 Texture2D(mFormat, mWidth, mHeight, 1);
}
memcpy(texture->GetData(0), rect.pBits, texture->GetNumLevelBytes(0));
hr = copySurface->UnlockRect();
assertion(hr == D3D_OK,
"Failed to unlock copy surface: %s\n",
DXGetErrorString(hr));
copySurface->Release();
copyTexture->Release();
// Restore the previous render target surface.
if (i == 0)
{
hr = device->SetRenderTarget(0, mSaveColorSurface);
assertion(hr == D3D_OK,
"Failed to set old rt 0 color surface: %s\n",
DXGetErrorString(hr));
mSaveColorSurface->Release();
}
}