本文整理汇总了C++中IDirect3DDevice9类的典型用法代码示例。如果您正苦于以下问题:C++ IDirect3DDevice9类的具体用法?C++ IDirect3DDevice9怎么用?C++ IDirect3DDevice9使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDirect3DDevice9类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Release
bool Texture3D::Create()
{
Release();
if (!graphics_ || !width_ || !height_)
return false;
if (graphics_->IsDeviceLost())
{
URHO3D_LOGWARNING("Texture creation while device is lost");
return true;
}
unsigned pool = usage_ > TEXTURE_STATIC ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
unsigned d3dUsage = usage_ == TEXTURE_DYNAMIC ? D3DUSAGE_DYNAMIC : 0;
IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
HRESULT hr = device->CreateVolumeTexture(
(UINT)width_,
(UINT)height_,
(UINT)depth_,
requestedLevels_,
d3dUsage,
(D3DFORMAT)format_,
(D3DPOOL)pool,
(IDirect3DVolumeTexture9**)&object_,
nullptr);
if (FAILED(hr))
{
URHO3D_LOGD3DERROR("Could not create texture", hr);
URHO3D_SAFE_RELEASE(object_.ptr_);
return false;
}
levels_ = ((IDirect3DVolumeTexture9*)object_.ptr_)->GetLevelCount();
return true;
}
示例2: getDevice
void Blit::initGeometry()
{
static const float quad[] =
{
-1, -1,
-1, 1,
1, -1,
1, 1
};
IDirect3DDevice9 *device = getDevice();
HRESULT hr = device->CreateVertexBuffer(sizeof(quad), D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &mQuadVertexBuffer, NULL);
if (FAILED(hr))
{
ASSERT(hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY);
return error(GL_OUT_OF_MEMORY);
}
void *lockPtr;
mQuadVertexBuffer->Lock(0, 0, &lockPtr, 0);
memcpy(lockPtr, quad, sizeof(quad));
mQuadVertexBuffer->Unlock();
static const D3DVERTEXELEMENT9 elements[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
D3DDECL_END()
};
hr = device->CreateVertexDeclaration(elements, &mQuadVertexDeclaration);
if (FAILED(hr))
{
ASSERT(hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY);
return error(GL_OUT_OF_MEMORY);
}
}
示例3: ASSERT
void DX9Texture::createFallbackTexture(HDResourceMgr *pMgr)
{
ASSERT(pMgr);
DX9ResourceMgr* pDX9Mgr = (DX9ResourceMgr*)pMgr;
IDirect3DDevice9* pDev = pDX9Mgr->getDX9Device();
HRESULT hr;
const int SIZE = 128;
hr = pDev->CreateTexture(SIZE, SIZE, 1, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &s_fallbackTexture, NULL);
if(FAILED(hr))
{
LOG("fallback texture create failed");
return;
}
D3DLOCKED_RECT lockRect;
hr = s_fallbackTexture->LockRect(0, &lockRect, NULL, 0);
if(SUCCEEDED(hr))
{
D3DCOLOR fallColor[2];
fallColor[0] = D3DCOLOR_ARGB(255,5,250,250);
fallColor[1] = D3DCOLOR_ARGB(255,5,0,5);
D3DCOLOR *pPixel = (D3DCOLOR *)lockRect.pBits;
for(int y=0; y<SIZE; y++)
{
for(int x=0; x<SIZE; x++)
{
int sel = (x/16)%2+(y/16+1)%2;
pPixel[y*SIZE+x] = fallColor[sel%2];
}
}
hr = s_fallbackTexture->UnlockRect(0);
}//endof if
}
示例4: initialize
gl::Error Blit9::formatConvert(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest)
{
gl::Error error = initialize();
if (error.isError())
{
return error;
}
IDirect3DTexture9 *texture = NULL;
error = copySurfaceToTexture(source, sourceRect, &texture);
if (error.isError())
{
return error;
}
IDirect3DDevice9 *device = mRenderer->getDevice();
saveState();
device->SetTexture(0, texture);
device->SetRenderTarget(0, dest);
setViewport(sourceRect, xoffset, yoffset);
setCommonBlitState();
error = setFormatConvertShaders(destFormat);
if (!error.isError())
{
render();
}
SafeRelease(texture);
restoreState();
return error;
}
示例5: TextureStorage9
TextureStorage9_2D::TextureStorage9_2D(Renderer *renderer, int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height)
: TextureStorage9(renderer, GetTextureUsage(Renderer9::makeRenderer9(renderer)->ConvertTextureInternalFormat(internalformat), usage, forceRenderable))
{
mTexture = NULL;
mRenderTarget = NULL;
// if the width or height is not positive this should be treated as an incomplete texture
// we handle that here by skipping the d3d texture creation
if (width > 0 && height > 0)
{
IDirect3DDevice9 *device = mRenderer->getDevice();
gl::MakeValidSize(false, gl::IsCompressed(internalformat), &width, &height, &mLodOffset);
HRESULT result = device->CreateTexture(width, height, levels ? levels + mLodOffset : 0, getUsage(),
mRenderer->ConvertTextureInternalFormat(internalformat), getPool(), &mTexture, NULL);
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
gl::error(GL_OUT_OF_MEMORY);
}
}
initializeRenderTarget();
}
示例6: ASSERT
gl::Error TextureStorage9_Cube::getBaseTexture(IDirect3DBaseTexture9 **outTexture)
{
// if the size is not positive this should be treated as an incomplete texture
// we handle that here by skipping the d3d texture creation
if (mTexture == NULL && mTextureWidth > 0 && mTextureHeight > 0)
{
ASSERT(mMipLevels > 0);
ASSERT(mTextureWidth == mTextureHeight);
IDirect3DDevice9 *device = mRenderer->getDevice();
HRESULT result = device->CreateCubeTexture(mTextureWidth, mMipLevels, getUsage(), mTextureFormat, getPool(),
&mTexture, NULL);
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create cube storage texture, result: 0x%X.", result);
}
}
*outTexture = mTexture;
return gl::Error(GL_NO_ERROR);
}
示例7: mySwapPresent
static HRESULT __stdcall mySwapPresent(IDirect3DSwapChain9 * ids, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
ods("D3D9: SwapChain Present");
if (bPresenting) {
ods("D3D9: Not doublepresenting in chain!");
} else {
IDirect3DDevice9 *idd = NULL;
ids->GetDevice(&idd);
if (idd) {
myAdditions(idd);
doPresent(idd);
idd->Release();
}
}
SwapPresentType oSwapPresent;
oSwapPresent = (SwapPresentType) hhSwapPresent.call;
hhSwapPresent.restore();
HRESULT hr = oSwapPresent(ids, pSourceRect,pDestRect,hDestWindowOverride,pDirtyRegion,dwFlags);
hhSwapPresent.inject();
return hr;
}
示例8:
//----------------------------------------------------------------------------
PdrTexture2D::PdrTexture2D (Renderer* renderer, bool isColorTexture,
const Texture2D* texture, bool autoGenMipMap)
{
IDirect3DDevice9* device = renderer->mData->mDevice;
HRESULT hr;
PX2_UNUSED(hr);
if (isColorTexture)
{
UINT levels = 1;
DWORD usage = gDX9BufferUsage[texture->GetUsage()];
if (autoGenMipMap)
{
levels = 0;
usage |= D3DUSAGE_AUTOGENMIPMAP;
}
hr = device->CreateTexture((UINT)texture->GetWidth(),
(UINT)texture->GetHeight(), levels, usage,
gDX9TextureFormat[texture->GetFormat()], D3DPOOL_DEFAULT,
&mTexture, 0);
assertion(hr == D3D_OK,
"Failed to create render target color texture: %s\n",
DXGetErrorString(hr));
}
else
{
hr = device->CreateTexture((UINT)texture->GetWidth(),
(UINT)texture->GetHeight(), 1,
gDX9BufferUsage[texture->GetUsage()],
gDX9TextureFormat[texture->GetFormat()],
D3DPOOL_DEFAULT, &mTexture, 0);
assertion(hr == D3D_OK,
"Failed to create render target depthstencil texture: %s\n",
DXGetErrorString(hr));
}
}
示例9:
void mini3d::D3D9VertexShader::LoadResource(void)
{
IDirect3DDevice9* pDevice = pGraphicsService->GetDevice();
if (pDevice == 0)
return;
// If the buffer exists tear it down.
if (pShaderBuffer != 0)
{
UnloadResource();
}
// compile the shader source
ID3DXBuffer* buffer;
LPD3DXBUFFER ppErroMessage;
D3DXCompileShader((LPCSTR)pShaderBytes, sizeInBytes, 0, 0, "main", "vs_2_0", 0, &buffer, &ppErroMessage, 0);
if (ppErroMessage != 0)
{
OutputDebugStringA((char*)(ppErroMessage->GetBufferPointer()));
isDirty = true;
return;
}
if( FAILED( pDevice->CreateVertexShader((DWORD*)buffer->GetBufferPointer(), &pShaderBuffer)))
{
isDirty = true;
return;
}
buffer->Release();
isDirty = false;
// load the vertex declaration into the pool
pGraphicsService->PoolVertexDeclaration(vertexDeclaration, vertexDataCount);
}
示例10: locker
bool MythRenderD3D9::DrawTexturedQuad(IDirect3DVertexBuffer9 *vertexbuffer)
{
if (!m_vertexbuffers.contains(vertexbuffer))
return false;
D3D9Locker locker(this);
IDirect3DDevice9* dev = locker.Acquire();
if (!dev)
return false;
IDirect3DTexture9 *texture = m_vertexbuffers[vertexbuffer].m_texture;
if (texture && !SetTexture(dev, texture))
return false;
EnableBlending(dev, true);
SetTextureVertices(dev, true);
MultiTexturing(dev, false);
HRESULT hr = dev->SetStreamSource(0, vertexbuffer,
0, sizeof(TEXTUREVERTEX));
if (FAILED(hr))
{
VERBOSE(VB_IMPORTANT, D3DERR + "SetStreamSource() failed");
return false;
}
hr = dev->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
if (FAILED(hr))
{
VERBOSE(VB_IMPORTANT, D3DERR + "DrawPrimitive() failed");
return false;
}
return true;
}
示例11: HELIUM_ASSERT
/// @copydoc D3D9DeviceResetListener::OnPostReset()
void D3D9DepthStencilSurface::OnPostReset( D3D9Renderer* pRenderer )
{
HELIUM_ASSERT( pRenderer );
IDirect3DDevice9* pDevice = pRenderer->GetD3DDevice();
HELIUM_ASSERT( pDevice );
D3DMULTISAMPLE_TYPE multisampleType = D3DMULTISAMPLE_NONE;
if( m_multisampleCountMinusOne != 0 )
{
multisampleType =
static_cast< D3DMULTISAMPLE_TYPE >( D3DMULTISAMPLE_2_SAMPLES + m_multisampleCountMinusOne - 1 );
}
HELIUM_ASSERT( !m_pSurface );
HELIUM_D3D9_VERIFY( pDevice->CreateDepthStencilSurface(
m_width,
m_height,
( m_bStencil ? D3DFMT_D24S8 : D3DFMT_D24X8 ),
multisampleType,
0,
FALSE,
&m_pSurface,
NULL ) );
}
示例12: GetD3DDevice
bool DeviceManager::TestDeviceReady()
{
IDirect3DDevice9* device = GetD3DDevice();
if ( !device )
{
return false;
}
if ( !m_IsLost )
{
return true;
}
HRESULT result = device->TestCooperativeLevel();
if ( result == D3DERR_DEVICENOTRESET )
{
Reset();
result = device->TestCooperativeLevel();
}
m_IsLost = result != D3D_OK;
return !m_IsLost;
}
示例13: Release
bool VertexBuffer::Create()
{
Release();
if (!vertexCount_ || elements_.Empty())
return true;
if (graphics_)
{
if (graphics_->IsDeviceLost())
{
ATOMIC_LOGWARNING("Vertex buffer creation while device is lost");
return true;
}
unsigned pool = dynamic_ ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
unsigned d3dUsage = dynamic_ ? D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY : 0;
IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
HRESULT hr = device->CreateVertexBuffer(
vertexCount_ * vertexSize_,
d3dUsage,
0,
(D3DPOOL)pool,
(IDirect3DVertexBuffer9**)&object_.ptr_,
0);
if (FAILED(hr))
{
ATOMIC_SAFE_RELEASE(object_.ptr_);
ATOMIC_LOGD3DERROR("Could not create vertex buffer", hr);
return false;
}
}
return true;
}
示例14:
Burger::Effect::~Effect()
{
D3DPixelShader *pPixelShader = m_pPixelShader;
if (pPixelShader != NULL) {
IDirect3DDevice9 *pDevice;
pPixelShader->GetDevice(&pDevice);
if (pDevice) {
pDevice->SetPixelShader(0);
}
pPixelShader->Release();
m_pPixelShader = NULL;
}
D3DVertexShader *pVertexShader = m_pVertexShader;
if (pVertexShader != NULL) {
IDirect3DDevice9 *pDevice;
pVertexShader->GetDevice(&pDevice);
if (pDevice) {
pDevice->SetVertexShader(0);
}
pVertexShader->Release();
m_pVertexShader = NULL;
}
}
示例15: getDevice
DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples)
{
IDirect3DDevice9 *device = getDevice();
mDepthStencil = NULL;
int supportedSamples = getContext()->getNearestSupportedSamples(D3DFMT_D24S8, samples);
if (supportedSamples == -1)
{
error(GL_OUT_OF_MEMORY);
return;
}
if (width > 0 && height > 0)
{
HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, es2dx::GetMultisampleTypeFromSamples(supportedSamples),
0, FALSE, &mDepthStencil, 0);
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{
error(GL_OUT_OF_MEMORY);
return;
}
ASSERT(SUCCEEDED(result));
}
mWidth = width;
mHeight = height;
mInternalFormat = GL_DEPTH24_STENCIL8_OES;
mD3DFormat = D3DFMT_D24S8;
mSamples = supportedSamples;
}