本文整理汇总了C++中IDirect3DSurface9::UnlockRect方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirect3DSurface9::UnlockRect方法的具体用法?C++ IDirect3DSurface9::UnlockRect怎么用?C++ IDirect3DSurface9::UnlockRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirect3DSurface9
的用法示例。
在下文中一共展示了IDirect3DSurface9::UnlockRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dxReadPixels
HRESULT dxReadPixels(IDirect3DDevice9* Device, void* Buffer, bool& Minimised, int& Width, int& Height, D3DFORMAT Format)
{
IDirect3DSurface9* RenderTarget = nullptr;
IDirect3DSurface9* DestTarget = nullptr;
HRESULT result = Device->GetRenderTarget(0, &RenderTarget);
if (result == S_OK)
{
if (Width == 0 || Height == 0 || Format == D3DFMT_UNKNOWN)
{
D3DSURFACE_DESC descriptor = {};
RenderTarget->GetDesc(&descriptor);
Width = descriptor.Width;
Height = descriptor.Height;
Format = descriptor.Format;
}
HDC DC = nullptr;
RenderTarget->GetDC(&DC);
Minimised = IsIconic(WindowFromDC(DC));
RenderTarget->ReleaseDC(DC);
result = Device->CreateOffscreenPlainSurface(Width, Height, Format, D3DPOOL_SYSTEMMEM, &DestTarget, nullptr);
result = Device->GetRenderTargetData(RenderTarget, DestTarget);
D3DLOCKED_RECT rect;
DestTarget->LockRect(&rect, 0, D3DLOCK_READONLY);
memcpy(Buffer, rect.pBits, Width * Height * 4);
DestTarget->UnlockRect();
}
SafeRelease(RenderTarget);
SafeRelease(DestTarget);
return result;
}
示例2:
void DirectX9Texture::setGrid(Grid<Color>* a_pGrid)
{
HRESULT hr=S_OK;
Grid<Color>* pGrid=NULL;
D3DSURFACE_DESC desc;
m_pTexture->GetLevelDesc(0, &desc);
//TODO: get texture format from color
if(D3DFMT_A32B32G32R32F==desc.Format)
{
IDirect3DSurface9* offscreenSurface;
hr = m_pRenderer->getDevice()->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &offscreenSurface, NULL );
if( FAILED(hr) )
return;
IDirect3DSurface9* destinationSurface;
m_pTexture->GetSurfaceLevel(0, &destinationSurface);
m_iWidth=desc.Width;
m_iHeight=desc.Height;
D3DLOCKED_RECT lockedRect;
HRESULT hr=S_OK;
if(!FAILED(offscreenSurface->LockRect(&lockedRect, NULL, D3DLOCK_DISCARD)))
{
for(unsigned int y=0; y<m_iHeight; y++)
{
void* dst=((char*)lockedRect.pBits)+(y*lockedRect.Pitch);
memcpy(dst, a_pGrid->getRawRowData(y), a_pGrid->getRawRowDataByteCount());
}
offscreenSurface->UnlockRect();
}
m_pRenderer->getDevice()->UpdateSurface(offscreenSurface, NULL, destinationSurface, NULL);
offscreenSurface->Release();
}
}
示例3: AssertFatal
//-----------------------------------------------------------------------------
// unLock
//-----------------------------------------------------------------------------
void GFXD3D9TextureObject::unlock(U32 mipLevel)
{
AssertFatal( mLocked, "GFXD3D9TextureObject::unlock - Attempting to unlock a surface that has not been locked" );
#ifndef TORQUE_OS_XENON
if( mProfile->isRenderTarget() )
{
IDirect3DSurface9 *dest;
GFXD3D9TextureObject *to = (GFXD3D9TextureObject *) &(*mLockTex);
D3D9Assert( to->get2DTex()->GetSurfaceLevel( 0, &dest ), NULL );
dest->UnlockRect();
dest->Release();
mLocked = false;
}
else
#endif
{
D3D9Assert( get2DTex()->UnlockRect(mipLevel),
"GFXD3D9TextureObject::unlock - could not unlock non-RT texture." );
mLocked = false;
}
}
示例4: createTexture
virtual IDirect3DTexture9* createTexture() {
IDirect3DTexture9* tex = CFixedTextureCreator::createTexture();
// create the offscreen surface
HRESULT hr;
CD3DDevice& dx = CD3DDevice::getInstance();
IDirect3DSurface9* srcSurf = 0;
hr = dx.getDevice().CreateOffscreenPlainSurface( mGameMap->getCellsX(), mGameMap->getCellsY(), D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &srcSurf, NULL );
assert( SUCCEEDED(hr) );
D3DLOCKED_RECT lr;
srcSurf->LockRect( &lr, NULL, D3DLOCK_DISCARD );
const char* linePtr = (const char*)lr.pBits;
for( int y = 0; y < mGameMap->getCellsY(); ++y ) {
D3DCOLOR* p = (D3DCOLOR*)linePtr;
for( int x = 0; x < mGameMap->getCellsX(); ++x ) {
const CGameMap::SCell& cell = mGameMap->getCell(x,y);
*p = gColors.minimap[cell.color][cell.type];
++p;
}
linePtr += lr.Pitch;
}
srcSurf->UnlockRect();
// now, filter this into the texture
IDirect3DSurface9* dstSurf = 0;
hr = tex->GetSurfaceLevel( 0, &dstSurf );
assert( SUCCEEDED(hr) );
hr = D3DXLoadSurfaceFromSurface( dstSurf, NULL, NULL, srcSurf, NULL, NULL, D3DX_FILTER_BOX, 0 );
dstSurf->Release();
srcSurf->Release();
D3DXFilterTexture( tex, NULL, 0, D3DX_FILTER_BOX );
return tex;
}
示例5: Dump2Surface
HRESULT Dump2Surface (void* pDst[3], void* pSurface, int iWidth, int iHeight, int iStride[2]) {
HRESULT hResult = E_FAIL;
if (!pDst[0] || !pDst[1] || !pDst[2] || !pSurface)
return hResult;
IDirect3DSurface9* pSurfaceData = (IDirect3DSurface9*)pSurface;
D3DLOCKED_RECT sD3DLockedRect = {0};
hResult = pSurfaceData->LockRect (&sD3DLockedRect, NULL, 0);
unsigned char* pInY = (unsigned char*)pDst[0];
unsigned char* pOutY = (unsigned char*)sD3DLockedRect.pBits;
int iOutStride = sD3DLockedRect.Pitch;
for (int j = 0; j < iHeight; j++)
memcpy (pOutY + j * iOutStride, pInY + j * iStride[0], iWidth); //confirmed_safe_unsafe_usage
unsigned char* pInU = (unsigned char*)pDst[1];
unsigned char* pInV = (unsigned char*)pDst[2];
unsigned char* pOutC = pOutY + iOutStride * iHeight;
for (int i = 0; i < iHeight / 2; i++) {
for (int j = 0; j < iWidth; j += 2) {
pOutC[i * iOutStride + j ] = pInU[i * iStride[1] + j / 2];
pOutC[i * iOutStride + j + 1] = pInV[i * iStride[1] + j / 2];
}
}
pSurfaceData->UnlockRect();
return hResult;
}
示例6: defined
RageSurface* RageDisplay_D3D::CreateScreenshot()
{
#if defined(XBOX)
return NULL;
#else
RageSurface * result = NULL;
// Get the back buffer.
IDirect3DSurface9* pSurface;
if( SUCCEEDED( g_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurface ) ) )
{
// Get the back buffer description.
D3DSURFACE_DESC desc;
pSurface->GetDesc( &desc );
// Copy the back buffer into a surface of a type we support.
IDirect3DSurface9* pCopy;
if( SUCCEEDED( g_pd3dDevice->CreateOffscreenPlainSurface( desc.Width, desc.Height, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pCopy, NULL ) ) )
{
if( SUCCEEDED( D3DXLoadSurfaceFromSurface( pCopy, NULL, NULL, pSurface, NULL, NULL, D3DX_FILTER_NONE, 0) ) )
{
// Update desc from the copy.
pCopy->GetDesc( &desc );
D3DLOCKED_RECT lr;
{
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = desc.Width;
rect.bottom = desc.Height;
pCopy->LockRect( &lr, &rect, D3DLOCK_READONLY );
}
RageSurface *surface = CreateSurfaceFromPixfmt( FMT_RGBA8, lr.pBits, desc.Width, desc.Height, lr.Pitch);
ASSERT( surface != NULL );
// We need to make a copy, since lr.pBits will go away when we call UnlockRect().
result =
CreateSurface( surface->w, surface->h,
surface->format->BitsPerPixel,
surface->format->Rmask, surface->format->Gmask,
surface->format->Bmask, surface->format->Amask );
RageSurfaceUtils::CopySurface( surface, result );
delete surface;
pCopy->UnlockRect();
}
pCopy->Release();
}
pSurface->Release();
}
return result;
#endif
}
示例7: dataFromBuffer
QByteArray MFTransform::dataFromBuffer(IMFMediaBuffer *buffer, int height, int *bytesPerLine)
{
QByteArray array;
BYTE *bytes;
DWORD length;
HRESULT hr = buffer->Lock(&bytes, NULL, &length);
if (SUCCEEDED(hr)) {
array = QByteArray((const char *)bytes, (int)length);
buffer->Unlock();
} else {
// try to lock as Direct3DSurface
IDirect3DSurface9 *surface = 0;
do {
if (FAILED(MFGetService(buffer, MR_BUFFER_SERVICE, IID_IDirect3DSurface9, (void**)&surface)))
break;
D3DLOCKED_RECT rect;
if (FAILED(surface->LockRect(&rect, NULL, D3DLOCK_READONLY)))
break;
if (bytesPerLine)
*bytesPerLine = (int)rect.Pitch;
array = QByteArray((const char *)rect.pBits, rect.Pitch * height);
surface->UnlockRect();
} while (false);
if (surface) {
surface->Release();
surface = 0;
}
}
return array;
}
示例8: color
void ModuleIrisGraphics::snap2Bitmap(IIrisBitmap *bitmap){
IDirect3DSurface9* EXSurface;
IDirect3DSurface9* ExchangeSurface;
ExchangeTexture->GetSurfaceLevel(0, &EXSurface);
Device->CreateOffscreenPlainSurface(width, height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &ExchangeSurface, 0);
Device->GetRenderTargetData(EXSurface, ExchangeSurface);
D3DLOCKED_RECT rc;
memset(&rc, 0, sizeof(rc));
ExchangeSurface->LockRect(&rc, 0, D3DLOCK_NOOVERWRITE);
PARGBQuad p2 = (PARGBQuad)rc.pBits;
PARGBQuad c2 = 0;
IrisColor color(0, 0, 0, 0);
for (int x = 0; x < width; x++){
for (int y = 0; y < height; y++){
c2 = p2 + x + y * rc.Pitch / sizeof(ARGBQuad);
color.set(c2->Red, c2->Green, c2->Blue, c2->Alpha);
bitmap->SetPixel(x, y, &color);
}
}
ExchangeSurface->UnlockRect();
EXSurface->Release();
ExchangeSurface->Release();
}
示例9: nvDebugCheck
void D3DXCompressorDXT1::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode alphaMode, uint w, uint h, uint d, void * data, const nvtt::CompressionOptions::Private & compressionOptions, const nvtt::OutputOptions::Private & outputOptions)
{
nvDebugCheck(d == 1);
IDirect3D9 * d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS presentParams;
ZeroMemory(&presentParams, sizeof(presentParams));
presentParams.Windowed = TRUE;
presentParams.SwapEffect = D3DSWAPEFFECT_COPY;
presentParams.BackBufferWidth = 8;
presentParams.BackBufferHeight = 8;
presentParams.BackBufferFormat = D3DFMT_UNKNOWN;
HRESULT err;
IDirect3DDevice9 * device = NULL;
err = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, GetDesktopWindow(), D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParams, &device);
IDirect3DTexture9 * texture = NULL;
err = D3DXCreateTexture(device, w, h, 1, 0, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &texture);
IDirect3DSurface9 * surface = NULL;
err = texture->GetSurfaceLevel(0, &surface);
RECT rect;
rect.left = 0;
rect.top = 0;
rect.bottom = h;
rect.right = w;
if (inputFormat == nvtt::InputFormat_BGRA_8UB)
{
err = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, data, D3DFMT_A8R8G8B8, w * 4, NULL, &rect, D3DX_DEFAULT, 0);
}
else
{
err = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, data, D3DFMT_A32B32G32R32F, w * 16, NULL, &rect, D3DX_DEFAULT, 0);
}
if (err != D3DERR_INVALIDCALL && err != D3DXERR_INVALIDDATA)
{
D3DLOCKED_RECT rect;
ZeroMemory(&rect, sizeof(rect));
err = surface->LockRect(&rect, NULL, D3DLOCK_READONLY);
if (outputOptions.outputHandler != NULL) {
int size = rect.Pitch * ((h + 3) / 4);
outputOptions.outputHandler->writeData(rect.pBits, size);
}
err = surface->UnlockRect();
}
surface->Release();
device->Release();
d3d->Release();
}
示例10: MAKEFOURCC
bool CDVDCodecUtils::CopyDXVA2Picture(YV12Image* pImage, DVDVideoPicture *pSrc)
{
#ifdef HAS_DX
// TODO: Optimize this later using shaders/swscale/etc.
switch (pSrc->extended_format)
{
case MAKEFOURCC('N','V','1','2'):
{
IDirect3DSurface9* surface = (IDirect3DSurface9*)pSrc->data[3];
D3DLOCKED_RECT rectangle;
if (FAILED(surface->LockRect(&rectangle, NULL, 0)))
return false;
// Copy Y
uint8_t* bits = (uint8_t*)(rectangle.pBits);
uint8_t* d = pImage->plane[0];
for (unsigned y = 0; y < pSrc->iHeight; y++)
{
memcpy(d, bits, pSrc->iWidth);
bits += rectangle.Pitch;
d += pImage->stride[0];
}
D3DSURFACE_DESC desc;
if (FAILED(surface->GetDesc(&desc)))
return false;
// Copy packed UV
uint8_t *s_uv = ((uint8_t*)(rectangle.pBits)) + desc.Height * rectangle.Pitch;
uint8_t *d_uv = pImage->plane[1];
for (unsigned y = 0; y < pSrc->iHeight >> 1; y++)
{
memcpy(d_uv, s_uv, pSrc->iWidth);
s_uv += rectangle.Pitch;
d_uv += pImage->stride[1];
}
if (FAILED(surface->UnlockRect()))
return false;
}
return true;
// Future...
/*case MAKEFOURCC('Y','V','1','2'):
return true;*/
/*case MAKEFOURCC('Y','V','V','Y'):
return true;*/
default:
CLog::Log(LOGWARNING, "CDVDCodecUtils::CopyDXVA2Picture colorspace not supported");
return false;
}
#endif
return false;
}
示例11: Update
HRESULT virtual Update()
{
if (S_OK == this->ULib_BaseCanvas::Update() /*此处做静态绑定 etc.*/)
{
switch (m_typWrkMod)
{
case DataOutput:
{
//TODO.
//See ULib_OpenGLCanvas.hpp.
return S_OK;
}
case DataInput:
{
LPDIRECT3DDEVICE9 pDx9Device = GutGetGraphicsDeviceDX9();
if (pDx9Device)
{
//创建一个渲染表面
IDirect3DSurface9* pSurface;
//此处参数与OpenGL不同, 由于Pixle对象为一个DWORD,而非BYTE,故宏定义使用ARGB表达,底层字节序按照小端存放为B,G,R,A, 依然与OpenGL相同(Win32平台下)
pDx9Device->CreateOffscreenPlainSurface(m_canvasWidth, m_canvasHeight, (D3DFORMAT)m_dataFormat, D3DPOOL_DEFAULT, &pSurface,0);
//上写锁
D3DLOCKED_RECT rc;
memset(&rc,0,sizeof(rc));
pSurface->LockRect(&rc,NULL,D3DLOCK_DISCARD);
DWORD* pBits = (DWORD*)rc.pBits;
memcpy(pBits, m_pTargetTexturePixels, m_canvasWidth * m_canvasHeight * sizeof(DWORD));
//释放写锁
pSurface->UnlockRect();
//获取D3D默认交换链中的后台缓存
IDirect3DSurface9 *backBuffer = 0;
pDx9Device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer);
//使用自定义渲染表面填充后台缓存
pDx9Device->StretchRect(pSurface, 0, backBuffer, 0, D3DTEXF_NONE);
//GetBackBuffer所得的缓存需要被释放
backBuffer->Release();
pDx9Device->Present(NULL, NULL, NULL, NULL);
return S_OK;
}else
{
return E_FAIL;
}
}
default:
{
return E_FAIL;
}
}
}else
{
return E_FAIL;
}
}
示例12: GetLockableRTSurface
/*
* Class: sun_java2d_d3d_D3DSurfaceData
* Method: dbGetPixelNative
* Signature: (JII)I
*/
JNIEXPORT jint JNICALL Java_sun_java2d_d3d_D3DSurfaceData_dbGetPixelNative
(JNIEnv *env, jclass clazz, jlong pData, jint x, jint y)
{
HRESULT res;
D3DSDOps *d3dsdo;
D3DContext *pCtx;
D3DPipelineManager *pMgr;
D3DResource *pLockableRes;
jint pixel = 0;
J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_dbGetPixelNative");
RETURN_STATUS_IF_NULL(d3dsdo = (D3DSDOps *)jlong_to_ptr(pData), pixel);
RETURN_STATUS_IF_NULL(d3dsdo->pResource, pixel);
RETURN_STATUS_IF_NULL(pMgr = D3DPipelineManager::GetInstance(), pixel);
if (FAILED(res = pMgr->GetD3DContext(d3dsdo->adapter, &pCtx))) {
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
return pixel;
}
RETURN_STATUS_IF_NULL(pCtx->GetResourceManager(), 0);
IDirect3DDevice9 *pd3dDevice = pCtx->Get3DDevice();
IDirect3DSurface9 *pSrc = d3dsdo->pResource->GetSurface();
D3DFORMAT srcFmt = d3dsdo->pResource->GetDesc()->Format;
pCtx->UpdateState(STATE_OTHEROP);
res = pCtx->GetResourceManager()->
GetLockableRTSurface(1, 1, srcFmt, &pLockableRes);
if (SUCCEEDED(res)) {
IDirect3DSurface9 *pTmpSurface;
RECT srcRect = { x, y, x+1, y+1};
RECT dstRect = { 0l, 0l, 1, 1 };
pTmpSurface = pLockableRes->GetSurface();
res = pd3dDevice->StretchRect(pSrc, &srcRect, pTmpSurface, &dstRect,
D3DTEXF_NONE);
if (SUCCEEDED(res)) {
D3DLOCKED_RECT lRect;
res = pTmpSurface->LockRect(&lRect, &dstRect, D3DLOCK_NOSYSLOCK);
if (SUCCEEDED(res)) {
if (srcFmt == D3DFMT_X8R8G8B8) {
pixel = *(jint*)lRect.pBits;
} else {
pixel = *(unsigned short*)lRect.pBits;
}
pTmpSurface->UnlockRect();
}
}
}
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
return pixel;
}
示例13: GFX_ReleaseSurfacePtr
// copy a rect from the SDL surface to the Direct3D9 backbuffer
void CDirect3D::UpdateRectFromSDLSurface(int x,int y,int w,int h) {
if (x < 0 || y < 0 || (unsigned int)(x+w) > d3dpp.BackBufferWidth || (unsigned int)(y+h) > d3dpp.BackBufferHeight)
return;
if (w <= 0 || h <= 0)
return;
IDirect3DSurface9 *bbsurf = NULL;
IDirect3DSurface9 *tsurf = NULL;
if (pD3DDevice9->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &bbsurf) == D3D_OK) {
if (pD3DDevice9->CreateOffscreenPlainSurface(w, h, d3dpp.BackBufferFormat, D3DPOOL_SYSTEMMEM, &tsurf, NULL) == D3D_OK) {
D3DLOCKED_RECT rl;
if (tsurf->LockRect(&rl, NULL, 0) == D3D_OK) {
unsigned char *GFX_GetSurfacePtr(size_t *pitch, unsigned int x, unsigned int y);
void GFX_ReleaseSurfacePtr(void);
size_t sdl_pitch = 0,sdl_copy;
unsigned char *sdl_surface = GFX_GetSurfacePtr(&sdl_pitch, x, y);
if (sdl_surface != NULL) {
sdl_copy = w * (bpp16 ? 2 : 4);
// fprintf(stderr,"sdl_copy=%u sdl_pitch=%u dxpitch=%u\n",
// (unsigned int)sdl_copy,(unsigned int)sdl_pitch,(unsigned int)rl.Pitch);
for (unsigned int iy=0;iy < (unsigned int)h;iy++) {
unsigned char *sp = sdl_surface + (iy * sdl_pitch);
unsigned char *dp = (unsigned char*)rl.pBits + (iy * rl.Pitch);
memcpy(dp, sp, sdl_copy);
}
GFX_ReleaseSurfacePtr();
}
tsurf->UnlockRect();
RECT rc;
POINT pt;
rc.top = 0;
rc.left = 0;
rc.right = w;
rc.bottom = h;
pt.x = 0;
pt.y = 0;
pD3DDevice9->UpdateSurface(/*source*/tsurf, &rc, /*dest*/bbsurf, &pt);
}
}
}
SAFE_RELEASE(bbsurf);
SAFE_RELEASE(tsurf);
}
示例14: findOrCreateStagingTexture
bool aiGraphicsDeviceD3D9::readTexture(void *outBuf, size_t bufsize, void *tex_, int width, int height, tTextureFormat format)
{
HRESULT hr;
IDirect3DTexture9 *tex = (IDirect3DTexture9*)tex_;
// D3D11 と同様 render target の内容は CPU からはアクセス不可能になっている。
// staging texture を用意してそれに内容を移し、CPU はそれ経由でデータを読む。
IDirect3DSurface9 *surfDst = findOrCreateStagingTexture(width, height, format);
if (surfDst == nullptr) { return false; }
IDirect3DSurface9* surfSrc = nullptr;
hr = tex->GetSurfaceLevel(0, &surfSrc);
if (FAILED(hr)){ return false; }
bool ret = false;
hr = m_device->GetRenderTargetData(surfSrc, surfDst);
if (SUCCEEDED(hr))
{
D3DLOCKED_RECT locked;
hr = surfDst->LockRect(&locked, nullptr, D3DLOCK_READONLY);
if (SUCCEEDED(hr))
{
char *wpixels = (char*)outBuf;
int wpitch = width * tGetPixelSize(format);
const char *rpixels = (const char*)locked.pBits;
int rpitch = locked.Pitch;
// D3D11 と同様表向き解像度と内部解像度が違うケースを考慮
// (しかし、少なくとも手元の環境では常に wpitch == rpitch っぽい)
if (wpitch == rpitch)
{
memcpy(wpixels, rpixels, bufsize);
}
else
{
for (int i = 0; i < height; ++i)
{
memcpy(wpixels, rpixels, wpitch);
wpixels += wpitch;
rpixels += rpitch;
}
}
surfDst->UnlockRect();
// D3D9 の ARGB32 のピクセルの並びは BGRA になっているので並べ替える
if (format == tTextureFormat_ARGB32) {
BGRA2RGBA((RGBA<uint8_t>*)outBuf, int(bufsize / 4));
}
ret = true;
}
}
surfSrc->Release();
return ret;
}
示例15: if
//! Regenerates the mip map levels of the texture. Useful after locking and
//! modifying the texture
void CD3D9Texture::regenerateMipMapLevels(void* mipmapData)
{
if (mipmapData)
{
core::dimension2du size = TextureSize;
u32 level=0;
do
{
if (size.Width>1)
size.Width /=2;
if (size.Height>1)
size.Height /=2;
++level;
IDirect3DSurface9* mipSurface = 0;
HRESULT hr = Texture->GetSurfaceLevel(level, &mipSurface);
if (FAILED(hr) || !mipSurface)
{
os::Printer::log("Could not get mipmap level", ELL_WARNING);
return;
}
D3DSURFACE_DESC mipDesc;
mipSurface->GetDesc(&mipDesc);
D3DLOCKED_RECT miplr;
// lock mipmap surface
if (FAILED(mipSurface->LockRect(&miplr, NULL, 0)))
{
mipSurface->Release();
os::Printer::log("Could not lock texture", ELL_WARNING);
return;
}
memcpy(miplr.pBits, mipmapData, size.getArea()*getPitch()/TextureSize.Width);
mipmapData = (u8*)mipmapData+size.getArea()*getPitch()/TextureSize.Width;
// unlock
mipSurface->UnlockRect();
// release
mipSurface->Release();
} while (size.Width != 1 || size.Height != 1);
}
else if (HasMipMaps)
{
// create mip maps.
#ifdef _IRR_USE_D3DXFilterTexture_
// The D3DXFilterTexture function seems to get linked wrong when
// compiling with both D3D8 and 9, causing it not to work in the D3D9 device.
// So mipmapgeneration is replaced with my own bad generation
HRESULT hr = D3DXFilterTexture(Texture, NULL, D3DX_DEFAULT, D3DX_DEFAULT);
if (FAILED(hr))
#endif
createMipMaps();
}
}