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; }
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); } }
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 }
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; }
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(); }
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); }
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; }
HRESULT APPLICATION::Cleanup() { try { m_pFont->Release(); m_pLine->Release(); m_pDevice->Release(); debug.Print("Application terminated"); } catch(...){} return S_OK; }
//---------------------------------------------------------------------------- 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)); } }
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); }
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; }
/// @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 ) ); }
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; }
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; }
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; } }
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; }
//---------------------------------------------------------------------------- void PdrVertexBuffer::Disable (Renderer* renderer, unsigned int streamIndex) { IDirect3DDevice9* device = renderer->mData->mDevice; HRESULT hr; WM5_UNUSED(hr); #ifdef WM5_PDR_DEBUG // Verify that the active buffer is the one making the disable request. IDirect3DVertexBuffer9 *activeBuffer = 0; unsigned int activeOffset = 0, activeStride = 0; hr = device->GetStreamSource(streamIndex, &activeBuffer, &activeOffset, &activeStride); WM5_UNUSED(hr); assertion(hr == D3D_OK, "Failed to get stream source: %s\n", DXGetErrorString(hr)); assertion(activeBuffer == mBuffer, "Mismatched vertex buffers\n"); activeBuffer->Release(); #endif // Disable the buffer by clearing the state. hr = device->SetStreamSource(streamIndex, 0, 0, 0); assertion(hr == D3D_OK, "Failed to set stream source: %s\n", DXGetErrorString(hr)); }
fResult f2dGraphics2DImpl::Begin() { fResult tRet = f2dGraphicsImpl::Begin(); if(tRet != FCYERR_OK) return tRet; if(!(m_pIB && m_pVB)) return FCYERR_INTERNALERR; m_pParent->SubmitVD(NULL); setColorBlendType(m_ColorBlendType); IDirect3DDevice9* pDev = (IDirect3DDevice9*)m_pParent->GetHandle(); pDev->SetFVF(FVF); pDev->SetStreamSource(0, m_pVB, 0, sizeof(f2dGraphics2DVertex)); pDev->SetIndices(m_pIB); if(FAILED(pDev->BeginScene())) { m_bInRender = false; return FCYERR_INTERNALERR; } else { // 准备缓冲区 m_pVB->Lock(0, m_VBMaxCount*sizeof(f2dGraphics2DVertex), (void**)&m_pVBData, D3DLOCK_DISCARD); m_pIB->Lock(0, m_IBMaxCount*sizeof(fuShort), (void**)&m_pIBData, D3DLOCK_DISCARD); m_VBUsedCount = 0; m_IBUsedCount = 0; m_VBAlloced = 0; m_IBAlloced = 0; return FCYERR_OK; } }
bool IndexBuffer::Create() { Release(); if (!indexCount_) return true; if (graphics_) { if (graphics_->IsDeviceLost()) { ATOMIC_LOGWARNING("Index 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->CreateIndexBuffer( indexCount_ * indexSize_, d3dUsage, indexSize_ == sizeof(unsigned) ? D3DFMT_INDEX32 : D3DFMT_INDEX16, (D3DPOOL)pool, (IDirect3DIndexBuffer9**)&object_, 0); if (FAILED(hr)) { ATOMIC_SAFE_RELEASE(object_.ptr_) ATOMIC_LOGD3DERROR("Could not create index buffer", hr); return false; } } return true; }
void DevState::newTexture(unsigned int width, unsigned int height) { ods("D3D9: New texture %d x %d", width, height); if (texTexture) { texTexture->Release(); texTexture = NULL; } dev->CreateTexture(uiWidth, uiHeight, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texTexture, NULL); for (int i = 0; i < 4; ++i) { vertices[i].x = vertices[i].y = vertices[i].z = 0.0f; vertices[i].tu = vertices[i].tv = 0.0f; vertices[i].rhw = 1.0f; } }
HRESULT APPLICATION::Cleanup() { try { m_terrain.Release(); UnloadObjectResources(); m_pFont->Release(); m_pDevice->Release(); debug.Print("Application terminated"); } catch(...){} return S_OK; }
bool fcGraphicsDeviceD3D9::writeTexture(void *o_tex, int width, int height, fcTextureFormat format, const void *buf, size_t bufsize) { int psize = fcGetPixelSize(format); int pitch = psize * width; const size_t num_pixels = bufsize / psize; HRESULT hr; IDirect3DTexture9 *tex = (IDirect3DTexture9*)o_tex; // D3D11 と違い、D3D9 では書き込みも staging texture を経由する必要がある。 IDirect3DSurface9 *surf_src = findOrCreateStagingTexture(width, height, format); if (surf_src == nullptr) { return false; } IDirect3DSurface9* surf_dst = nullptr; hr = tex->GetSurfaceLevel(0, &surf_dst); if (FAILED(hr)){ return false; } bool ret = false; D3DLOCKED_RECT locked; hr = surf_src->LockRect(&locked, nullptr, D3DLOCK_DISCARD); if (SUCCEEDED(hr)) { const char *rpixels = (const char*)buf; int rpitch = psize * width; char *wpixels = (char*)locked.pBits; int wpitch = locked.Pitch; // こちらも ARGB32 の場合 BGRA に並べ替える必要がある if (format == fcTextureFormat_ARGB32) { copy_with_BGRA_RGBA_conversion((RGBA<uint8_t>*)wpixels, (RGBA<uint8_t>*)rpixels, bufsize / 4); } else { memcpy(wpixels, rpixels, bufsize); } surf_src->UnlockRect(); hr = m_device->UpdateSurface(surf_src, nullptr, surf_dst, nullptr); if (SUCCEEDED(hr)) { ret = true; } } surf_dst->Release(); return false; }
HRESULT APPLICATION::Update(float deltaTime) { //Control camera D3DXMATRIX matWorld; D3DXMatrixIdentity(&matWorld); m_pDevice->SetTransform(D3DTS_WORLD, &matWorld); //Update mouse m_mouse.Update(); //Update camera m_camera.Update(m_mouse, deltaTime); if(KEYDOWN(VK_ESCAPE)) Quit(); return S_OK; }
HRESULT APPLICATION::Render() { // Clear the viewport m_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0); //Set camera D3DXMATRIX view, proj, world, identity; D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(15.0f, 30.0f, -40.0f), &D3DXVECTOR3(0.0f, 11.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI * 0.3f, 1.33333f, 0.01f, 1000.0f); D3DXMatrixIdentity(&identity); m_pDevice->SetTransform(D3DTS_WORLD, &identity); m_pDevice->SetTransform(D3DTS_VIEW, &view); m_pDevice->SetTransform(D3DTS_PROJECTION, &proj); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { if(m_buildPrc < 1.0f) { m_build1.Render(m_buildPrc); //Progressbar m_pDevice->Clear(1, &SetRect(10, 560, 790, 590), D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0); m_pDevice->Clear(1, &SetRect(12, 562, 788, 588), D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0); m_pDevice->Clear(1, &SetRect(12, 562, (int)(12 + 774 * m_buildPrc), 588), D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0); } else m_build2.Render(); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }
HRESULT APPLICATION::Cleanup() { try { if(m_pHeightMap != NULL) { delete m_pHeightMap; m_pHeightMap = NULL; } m_pFont->Release(); m_pDevice->Release(); debug.Print("Application terminated"); } catch(...){} return S_OK; }
HRESULT APPLICATION::Render() { // Clear the viewport m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L ); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { //Set camera D3DXMATRIX view, proj; D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(0.0f, 10.0f, -50.0f), &D3DXVECTOR3(0.0f, 3.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); D3DXMatrixOrthoLH(&proj, 10.0f, 9.0f, 0.1f, 1000.0f); m_pDevice->SetTransform(D3DTS_VIEW, &view); m_pDevice->SetTransform(D3DTS_PROJECTION, &proj); if(m_wireframe)m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); else m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); m_farmer1.Render(); m_farmer2.RenderProgressive(); //Number of polygons char number[50]; std::string text = itoa(m_farmer2.GetNumProgressiveFaces(), number, 10); text += " polygons (UP/DOWN Arrow)"; RECT r[] = {{170, 520, 0, 0}, {530, 520, 0, 0}, {470, 540, 0, 0}, {130, 540, 0, 0}}; m_pFont->DrawText(NULL, "Original", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "Progressive Mesh", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, text.c_str(), -1, &r[2], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "(W)ireframe On/Off", -1, &r[3], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }
void sge::d3d9::devicefuncs::set_sampler_state( IDirect3DDevice9 &_device, sge::renderer::texture::stage const _stage, D3DSAMPLERSTATETYPE const _type, DWORD const _value ) { if( _device.SetSamplerState( _stage.get(), _type, _value ) != D3D_OK ) throw sge::renderer::exception( FCPPT_TEXT("SetSamplerState() failed!") ); }
IDirect3DSurface9* CopyToTextureD3D9::findOrCreateStagingTexture(int width, int height) { D3DFORMAT internal_format = D3DFMT_A32B32G32R32F; uint64_t hash = width + (height << 16); { auto it = m_staging_textures.find(hash); if (it != m_staging_textures.end()) { return it->second; } } IDirect3DSurface9 *ret = nullptr; HRESULT hr = m_device->CreateOffscreenPlainSurface(width, height, internal_format, D3DPOOL_SYSTEMMEM, &ret, NULL); if (SUCCEEDED(hr)) { m_staging_textures.insert(std::make_pair(hash, ret)); } return ret; }
void CopyToTextureD3D9::copy(void *texptr, int width, int height, const void *dataptr, int data_num, DataConversion conv) { int psize = 16; int pitch = psize * width; int bufsize = data_num * psize; dataptr = getDataPointer(dataptr, data_num, width*height, conv, true); HRESULT hr; IDirect3DTexture9 *tex = (IDirect3DTexture9*)texptr; // D3D11 と違い、D3D9 では書き込みも staging texture を経由する必要がある。 IDirect3DSurface9 *surf_src = findOrCreateStagingTexture(width, height); if (surf_src == nullptr) { return; } IDirect3DSurface9* surf_dst = nullptr; hr = tex->GetSurfaceLevel(0, &surf_dst); if (FAILED(hr)) { return; } bool ret = false; D3DLOCKED_RECT locked; hr = surf_src->LockRect(&locked, nullptr, D3DLOCK_DISCARD); if (SUCCEEDED(hr)) { const char *rpixels = (const char*)dataptr; int rpitch = psize * width; char *wpixels = (char*)locked.pBits; int wpitch = locked.Pitch; memcpy(wpixels, rpixels, bufsize); surf_src->UnlockRect(); hr = m_device->UpdateSurface(surf_src, nullptr, surf_dst, nullptr); if (SUCCEEDED(hr)) { ret = true; } } surf_dst->Release(); }
D3DDISPLAYMODE const sge::d3d9::devicefuncs::get_display_mode( IDirect3DDevice9 &_device, UINT const _swap_chain ) { D3DDISPLAYMODE ret; if( _device.GetDisplayMode( _swap_chain, &ret ) != D3D_OK ) throw sge::renderer::exception( FCPPT_TEXT("GetDisplayMode failed!") ); return ret; }