MCPcopy Create free account
hub / github.com/bumptop/BumpTop / createTextureFromData

Method createTextureFromData

trunk/win/Source/BT_DXRender.cpp:558–596  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

556}
557
558IDirect3DTexture9 * DXRender::createTextureFromData(unsigned int width, unsigned int height, const unsigned char * data, unsigned int sourcePitch, bool flip, unsigned int mipmapLevels)
559{
560 IDirect3DTexture9 * texture = NULL;
561
562 if (!isDeviceReady())
563 return texture;
564
565 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
566 VASSERT(isPowerOfTwo(width) && isPowerOfTwo(height), QString_NT("Texture not POW2: %1, %2").arg(width).arg(height));
567
568 HRESULT hr = dxr->device->CreateTexture(width, height, mipmapLevels, D3DUSAGE_AUTOGENMIPMAP | D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL);
569 if (hr != D3D_OK)
570 {
571 VASSERT(D3D_OK == hr, QString_NT("Failed to create texture: hr = %1, width = %2, height = %3, mipmapLevels = %4").arg(hr).arg(width).arg(height).arg(mipmapLevels));
572 return NULL;
573 }
574
575 D3DLOCKED_RECT lockedRect = {0};
576 hr = texture->LockRect(0, &lockedRect, NULL, 0);
577 VASSERT(D3D_OK == hr, QString_NT("Could not lock texture: hr = %1").arg(hr));
578
579 if (width * 4 == lockedRect.Pitch && lockedRect.Pitch == sourcePitch && !flip)
580 memcpy(lockedRect.pBits, data, width * height * 4);
581 else if (flip)
582 {
583 for (unsigned int i = 0; i < height; i++)
584 memcpy((char *)lockedRect.pBits + (height - 1 - i) * lockedRect.Pitch, data + sourcePitch * i, sourcePitch);
585 }
586 else
587 {
588 for (unsigned int i = 0; i < height; i++)
589 memcpy((char *)lockedRect.pBits + i * lockedRect.Pitch, data + sourcePitch * i, sourcePitch);
590 }
591
592 hr = texture->UnlockRect(0);
593 VASSERT(D3D_OK == hr, QString_NT("Could not unlock texture: hr = %1").arg(hr));
594
595 return texture;
596}
597
598unsigned int DXRender::getBackBufferWidth()
599{

Callers 6

bindAsGLTextureMethod · 0.80
loadBlockingTextureMethod · 0.80
loadQueuedTextureMethod · 0.80
updateTextureMethod · 0.80

Calls 2

isPowerOfTwoFunction · 0.85
argMethod · 0.45

Tested by

no test coverage detected