| 170 | } |
| 171 | |
| 172 | bool TextureCube::init(std::string_view positive_x, |
| 173 | std::string_view negative_x, |
| 174 | std::string_view positive_y, |
| 175 | std::string_view negative_y, |
| 176 | std::string_view positive_z, |
| 177 | std::string_view negative_z) |
| 178 | { |
| 179 | _imgPath[0] = positive_x; |
| 180 | _imgPath[1] = negative_x; |
| 181 | _imgPath[2] = positive_y; |
| 182 | _imgPath[3] = negative_y; |
| 183 | _imgPath[4] = positive_z; |
| 184 | _imgPath[5] = negative_z; |
| 185 | |
| 186 | std::vector<Image*> images(6); |
| 187 | |
| 188 | images[0] = createImage(positive_x); |
| 189 | images[1] = createImage(negative_x); |
| 190 | images[2] = createImage(positive_y); |
| 191 | images[3] = createImage(negative_y); |
| 192 | images[4] = createImage(positive_z); |
| 193 | images[5] = createImage(negative_z); |
| 194 | |
| 195 | int imageSize = images[0]->getHeight(); |
| 196 | for (int i = 0; i < 6; i++) |
| 197 | { |
| 198 | Image* img = images[i]; |
| 199 | if (img->getWidth() != img->getHeight()) |
| 200 | { |
| 201 | AXASSERT(false, "TextureCubemap: width should be equal to height!"); |
| 202 | return false; |
| 203 | } |
| 204 | if (imageSize != img->getWidth()) |
| 205 | { |
| 206 | AXASSERT(imageSize == img->getWidth(), "TextureCubmap: texture of each face should have same dimension"); |
| 207 | return false; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | backend::TextureDescriptor textureDescriptor; |
| 212 | textureDescriptor.width = textureDescriptor.height = imageSize; |
| 213 | textureDescriptor.textureType = backend::TextureType::TEXTURE_CUBE; |
| 214 | textureDescriptor.samplerDescriptor.minFilter = backend::SamplerFilter::LINEAR; |
| 215 | textureDescriptor.samplerDescriptor.magFilter = backend::SamplerFilter::LINEAR; |
| 216 | textureDescriptor.samplerDescriptor.sAddressMode = backend::SamplerAddressMode::CLAMP_TO_EDGE; |
| 217 | textureDescriptor.samplerDescriptor.tAddressMode = backend::SamplerAddressMode::CLAMP_TO_EDGE; |
| 218 | _texture = |
| 219 | static_cast<backend::TextureCubemapBackend*>(backend::DriverBase::getInstance()->newTexture(textureDescriptor)); |
| 220 | AXASSERT(_texture != nullptr, "TextureCubemap: texture can not be nullptr"); |
| 221 | |
| 222 | for (int i = 0; i < 6; i++) |
| 223 | { |
| 224 | Image* img = images[i]; |
| 225 | |
| 226 | backend::PixelFormat ePixelFmt; |
| 227 | unsigned char* pData = getImageData(img, ePixelFmt); |
| 228 | uint8_t* cData = nullptr; |
| 229 | uint8_t* useData = pData; |
no test coverage detected