MCPcopy Create free account
hub / github.com/axmolengine/axmol / init

Method init

core/renderer/TextureCube.cpp:172–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172bool 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;

Callers 1

createMethod · 0.45

Calls 10

createImageFunction · 0.85
getInstanceFunction · 0.85
getImageDataFunction · 0.85
convertDataToFormatFunction · 0.85
newTextureMethod · 0.80
updateFaceDataMethod · 0.80
freeFunction · 0.50
getHeightMethod · 0.45
getWidthMethod · 0.45
getDataMethod · 0.45

Tested by

no test coverage detected