void D10State::newTexture(unsigned int w, unsigned int h) { HRESULT hr; ods("D3D10: newTexture %d %d", w, h); if (pTexture) { pTexture->Release(); pTexture = NULL; } if (pSRView) { pSRView->Release(); pSRView = NULL; } D3D10_TEXTURE2D_DESC desc; ZeroMemory(&desc, sizeof(desc)); desc.Width = w; desc.Height = h; desc.MipLevels = desc.ArraySize = 1; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.SampleDesc.Count = 1; desc.Usage = D3D10_USAGE_DYNAMIC; desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; hr = pDevice->CreateTexture2D(&desc, NULL, &pTexture); if (FAILED(hr)) { pTexture = NULL; ods("D3D10: Failed to create texture."); return; } D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc; ZeroMemory(&srvDesc, sizeof(srvDesc)); srvDesc.Format = desc.Format; srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.MipLevels = desc.MipLevels; hr = pDevice->CreateShaderResourceView(pTexture, &srvDesc, &pSRView); if (FAILED(hr)) { pSRView = NULL; pTexture->Release(); pTexture = NULL; ods("D3D10: Failed to create resource view."); return; } }
/** * @fn Resize (int w, int h) * * @brief Resizes the render target, creates new textures and views * * @param w - New resource width * * @param h - New resource height */ void CDXRenderTarget::Resize(int resW, int resH) { HRESULT hr; SAFE_RELEASE(m_pSRV); SAFE_RELEASE(m_pRTV); SAFE_RELEASE(m_pTexture); SAFE_RELEASE(m_pTextureCPU); // Save the new values m_width = resW; m_height = resH; // Get the device ID3D10Device *pDev = DXUTGetD3D10Device(); // Create the texture here CD3D10_TEXTURE2D_DESC desc(m_fmt, resW, resH, 1, 1); desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE; desc.Usage = D3D10_USAGE_DEFAULT; hr = pDev->CreateTexture2D(&desc, NULL, &m_pTexture); assert(hr == S_OK); // Create the CPU version of the texture here CD3D10_TEXTURE2D_DESC descCPU(m_fmt, resW, resH, 1, 1); descCPU.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; descCPU.Usage = D3D10_USAGE_DYNAMIC; hr = pDev->CreateTexture2D(&descCPU, NULL, &m_pTextureCPU); assert(hr == S_OK); // Create the shader resource view D3D10_SHADER_RESOURCE_VIEW_DESC resDesc; resDesc.Format = m_fmt; resDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; resDesc.Texture2D.MipLevels = 1; resDesc.Texture2D.MostDetailedMip = 0; hr = pDev->CreateShaderResourceView(m_pTexture, &resDesc, &m_pSRV); assert(hr == S_OK); // Create the render target view D3D10_RENDER_TARGET_VIEW_DESC rtDesc; rtDesc.Format = m_fmt; rtDesc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D; rtDesc.Texture2D.MipSlice = 0; hr = pDev->CreateRenderTargetView(m_pTexture, &rtDesc, &m_pRTV); assert(hr == S_OK); } // End of resize()
void D3D10Texture::Allocate(UINT Width, UINT Height, bool ConstructMipmaps, DXGI_FORMAT Format, const Bitmap &Bmp) { FreeMemory(); PersistentAssert(_GD != NULL, "D3D10Texture::Allocate on unassociated texture"); ID3D10Device* Device = _GD->CastD3D10().GetDevice(); D3D10_TEXTURE2D_DESC TextureDesc; TextureDesc.Width = Width; TextureDesc.Height = Height; TextureDesc.MipLevels = 0; if(!ConstructMipmaps) { TextureDesc.MipLevels = 1; } TextureDesc.ArraySize = 1; TextureDesc.Format = Format; TextureDesc.SampleDesc.Count = 1; TextureDesc.SampleDesc.Quality = 0; TextureDesc.Usage = D3D10_USAGE_DEFAULT; TextureDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET; TextureDesc.CPUAccessFlags = 0; TextureDesc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS; D3D10_SUBRESOURCE_DATA Data[12]; for(UINT Index = 0; Index < 12; Index++) { Data[Index].pSysMem = &(Bmp[0][0]); Data[Index].SysMemPitch = Bmp.Width() * sizeof(RGBColor); } HRESULT hr = Device->CreateTexture2D(&TextureDesc, Data, &_Texture); PersistentAssert(SUCCEEDED(hr), "CreateTexture2D failed"); _Texture->GetDesc(&TextureDesc); D3D10_SHADER_RESOURCE_VIEW_DESC ViewDesc; ViewDesc.Format = Format; ViewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; ViewDesc.Texture2D.MostDetailedMip = 0; ViewDesc.Texture2D.MipLevels = TextureDesc.MipLevels; hr = Device->CreateShaderResourceView(_Texture, &ViewDesc, &_View); PersistentAssert(SUCCEEDED(hr), "CreateShaderResourceView failed"); Device->GenerateMips(_View); }
Texture3D::Texture3D(Texture3D_Desc& desc, Renderer* pRender) { HRESULT hr; ID3D10Device* pDevice = pRender->GetDevice(); V(pDevice->CreateTexture3D( &desc, //[in] const D3D10_TEXTURE3D_DESC *pDesc, NULL, //[in] const D3D10_SUBRESOURCE_DATA *pInitialData, &_ptr //[out] ID3D10Texture3D **ppTexture3D )); if (SUCCEEDED(hr)) { _width = (float)desc.Width; _height = (float)desc.Height; _depth = (float)desc.Depth; _invW = 1.0f / _width; _invH = 1.0f / _height; _invD = 1.0f / _depth; D3D10_SHADER_RESOURCE_VIEW_DESC resourceViewDesc; resourceViewDesc.Format = desc.Format; resourceViewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE3D; resourceViewDesc.Texture3D.MostDetailedMip = 0; resourceViewDesc.Texture3D.MipLevels = desc.MipLevels; ID3D10ShaderResourceView* pResourceView; V(pDevice->CreateShaderResourceView( (ID3D10Resource *)_ptr, //[in] ID3D10Resource *pResource, &resourceViewDesc, //[in] const D3D10_SHADER_RESOURCE_VIEW_DESC *pDesc, &pResourceView //[out] ID3D10ShaderResourceView **ppSRView )); if (SUCCEEDED(hr)) { _ResourceView = pResourceView; } } else { _ptr = NULL; _width = 0; _height = 0; _depth = 0; _invW = 0; _invH = 0; _invD = 0; } }
bool CGutFontUniCodeDX10::CreateTexture(int w, int h) { m_iTextureW = w; m_iTextureH = h; ID3D10Device *pDevice = GutGetGraphicsDeviceDX10(); // { D3D10_TEXTURE2D_DESC desc; ZeroMemory( &desc, sizeof(desc) ); desc.Width = w; desc.Height = h; desc.MipLevels = 1; desc.ArraySize = 1; desc.SampleDesc.Count = 1; desc.Format = DXGI_FORMAT_A8_UNORM; desc.Usage = D3D10_USAGE_DEFAULT; desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; pDevice->CreateTexture2D( &desc, NULL, &m_pFontTexture2D ); } // { D3D10_SHADER_RESOURCE_VIEW_DESC desc; ZeroMemory(&desc, sizeof(desc)); desc.Format = DXGI_FORMAT_A8_UNORM; desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; desc.Texture2D.MostDetailedMip = 0; desc.Texture2D.MipLevels = 1; pDevice->CreateShaderResourceView(m_pFontTexture2D, &desc, &m_pFontTexture); } return true; }