D3D11TextureCube::D3D11TextureCube(uint32_t size, uint32_t numMipMaps, uint32_t array_size, ElementFormat format, uint32_t sample_count, uint32_t sample_quality, uint32_t access_hint, ElementInitData const * init_data) : D3D11Texture(TT_Cube, sample_count, sample_quality, access_hint) { if (0 == numMipMaps) { num_mip_maps_ = 1; uint32_t w = size; while (w != 1) { ++ num_mip_maps_; w = std::max<uint32_t>(1U, w / 2); } } else { num_mip_maps_ = numMipMaps; } D3D11RenderEngine const & re = *checked_cast<D3D11RenderEngine const *>(&Context::Instance().RenderFactoryInstance().RenderEngineInstance()); if (re.DeviceFeatureLevel() <= D3D_FEATURE_LEVEL_9_3) { if ((num_mip_maps_ > 1) && ((size & (size - 1)) != 0)) { // height or width is not a power of 2 and multiple mip levels are specified. This is not supported at feature levels below 10.0. num_mip_maps_ = 1; } } array_size_ = array_size; format_ = format; widths_.assign(1, size); desc_.Width = size; desc_.Height = size; desc_.MipLevels = num_mip_maps_; desc_.ArraySize = 6 * array_size_; desc_.Format = D3D11Mapping::MappingFormat(format_); desc_.SampleDesc.Count = 1; desc_.SampleDesc.Quality = 0; this->GetD3DFlags(desc_.Usage, desc_.BindFlags, desc_.CPUAccessFlags, desc_.MiscFlags); desc_.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE; std::vector<D3D11_SUBRESOURCE_DATA> subres_data(6 * num_mip_maps_); if (init_data != nullptr) { for (int face = 0; face < 6; ++ face) { for (uint32_t i = 0; i < num_mip_maps_; ++ i) { subres_data[face * num_mip_maps_ + i].pSysMem = init_data[face * num_mip_maps_ + i].data; subres_data[face * num_mip_maps_ + i].SysMemPitch = init_data[face * num_mip_maps_ + i].row_pitch; subres_data[face * num_mip_maps_ + i].SysMemSlicePitch = init_data[face * num_mip_maps_ + i].slice_pitch; } } } ID3D11Texture2D* d3d_tex; TIF(d3d_device_->CreateTexture2D(&desc_, (init_data != nullptr) ? &subres_data[0] : nullptr, &d3d_tex)); d3dTextureCube_ = MakeCOMPtr(d3d_tex); this->UpdateParams(); if ((access_hint & (EAH_GPU_Read | EAH_Generate_Mips)) && (num_mip_maps_ > 1)) { this->RetriveD3DShaderResourceView(0, array_size_, 0, num_mip_maps_); } }
D3D11Texture3D::D3D11Texture3D(uint32_t width, uint32_t height, uint32_t depth, uint32_t numMipMaps, uint32_t array_size, ElementFormat format, uint32_t sample_count, uint32_t sample_quality, uint32_t access_hint, ElementInitData const * init_data) : D3D11Texture(TT_3D, sample_count, sample_quality, access_hint) { BOOST_ASSERT(1 == array_size); if (0 == numMipMaps) { num_mip_maps_ = 1; uint32_t w = width; uint32_t h = height; uint32_t d = depth; while ((w != 1) || (h != 1) || (d != 1)) { ++ num_mip_maps_; w = std::max<uint32_t>(1U, w / 2); h = std::max<uint32_t>(1U, h / 2); d = std::max<uint32_t>(1U, d / 2); } } else { num_mip_maps_ = numMipMaps; } D3D11RenderEngine const & re = *checked_cast<D3D11RenderEngine const *>(&Context::Instance().RenderFactoryInstance().RenderEngineInstance()); if (re.DeviceFeatureLevel() <= D3D_FEATURE_LEVEL_9_3) { if ((num_mip_maps_ > 1) && (((width & (width - 1)) != 0) || ((height & (height - 1)) != 0) || ((depth & (depth - 1)) != 0))) { // height or width is not a power of 2 and multiple mip levels are specified. This is not supported at feature levels below 10.0. num_mip_maps_ = 1; } } array_size_ = array_size; format_ = format; widths_.assign(1, width); heights_.assign(1, height); depthes_.assign(1, depth); desc_.Width = width; desc_.Height = height; desc_.Depth = depth; desc_.MipLevels = num_mip_maps_; desc_.Format = D3D11Mapping::MappingFormat(format_); this->GetD3DFlags(desc_.Usage, desc_.BindFlags, desc_.CPUAccessFlags, desc_.MiscFlags); std::vector<D3D11_SUBRESOURCE_DATA> subres_data(num_mip_maps_); if (init_data != nullptr) { for (uint32_t i = 0; i < num_mip_maps_; ++ i) { subres_data[i].pSysMem = init_data[i].data; subres_data[i].SysMemPitch = init_data[i].row_pitch; subres_data[i].SysMemSlicePitch = init_data[i].slice_pitch; } } ID3D11Texture3D* d3d_tex; TIF(d3d_device_->CreateTexture3D(&desc_, (init_data != nullptr) ? &subres_data[0] : nullptr, &d3d_tex)); d3dTexture3D_ = MakeCOMPtr(d3d_tex); this->UpdateParams(); if ((access_hint & (EAH_GPU_Read | EAH_Generate_Mips)) && (num_mip_maps_ > 1)) { this->RetriveD3DShaderResourceView(0, array_size_, 0, num_mip_maps_); } }