bool_t CC_CALL D3D9Texture2D::update(bool_t _newTexture, PixelFormat _format, int32_t _width, int32_t _height, lpvoid_t _imageData) { D3DSURFACE_DESC desc; D3DLOCKED_RECT rect; HRESULT hr = 0; int mipmaps = 0; D3DContext *d3dContext = (D3DContext *)iRenderContext->getContext(); LPDIRECT3DDEVICE9 d3dDev9 = d3dContext->D3DDev9; CC_ASSERT(d3dDev9 != NULL); if ( d3dDev9 == NULL ) return FALSE; updateTextureFormat(_format); if (_newTexture || (width != _width || height != _height)) { if(textureID) textureID->Release(); width = _width; height = _height; hr = d3dDev9->CreateTexture(width,height, mipmaps, // number of mipmaplevels (0 = automatic all) 0, d3dFormat, D3DPOOL_MANAGED, &textureID, 0); if(FAILED(hr)) { if (d3dFormat == D3DFMT_A8R8G8B8) d3dFormat = D3DFMT_A1R5G5B5; else if (d3dFormat == D3DFMT_R8G8B8) d3dFormat = D3DFMT_R5G6B5; else{ return FALSE; } hr = d3dDev9->CreateTexture(width,height, mipmaps, // number of mipmaplevels (0 = automatic all) 0, d3dFormat, D3DPOOL_MANAGED, &textureID, 0); if(FAILED(hr)) { return FALSE; } } } textureID->GetLevelDesc(0, &desc); hr = textureID->LockRect(0, &rect, 0, D3DLOCK_DISCARD); if (FAILED(hr)) { CC_ERROR_LOG(_T("Could not LockRect D3D9 Texture.")); } else { /* data passed in as 32 bit */ uint32_t bytesPerPixel = getBitsPerPixelForFormat(_format) / 8; copyImageScaling((byte_t*)_imageData, _width, _height, _format, bytesPerPixel, bytesPerPixel * _width, (byte_t *)rect.pBits, desc.Width, desc.Height, getD3DFormat(d3dFormat), rect.Pitch); hr = textureID->UnlockRect(0); if (FAILED(hr)) { CC_ERROR_LOG(_T("Could not UnlockRect D3D9 Texture.")); } } return TRUE; }
GLuint RenderbufferInterface::getStencilSize() const { return dx2es::GetStencilSize(getD3DFormat()); }