| 992 | } |
| 993 | |
| 994 | bool Image::LoadCubemapFromImage(const Image& image, const CubemapParams& params) |
| 995 | { |
| 996 | #if NAZARA_UTILITY_SAFE |
| 997 | if (!image.IsValid()) |
| 998 | { |
| 999 | NazaraError("Image must be valid"); |
| 1000 | return false; |
| 1001 | } |
| 1002 | |
| 1003 | ImageType type = image.GetType(); |
| 1004 | if (type != ImageType_2D) |
| 1005 | { |
| 1006 | NazaraError("Image type not handled (0x" + String::Number(type, 16) + ')'); |
| 1007 | return false; |
| 1008 | } |
| 1009 | #endif |
| 1010 | |
| 1011 | unsigned int width = image.GetWidth(); |
| 1012 | unsigned int height = image.GetHeight(); |
| 1013 | unsigned int faceSize = (params.faceSize == 0) ? std::max(width, height)/4 : params.faceSize; |
| 1014 | |
| 1015 | // Sans cette vérification, celles des rectangles pourrait réussir via un overflow |
| 1016 | if (width < faceSize || height < faceSize) |
| 1017 | { |
| 1018 | NazaraError("Image is too small for this face size"); |
| 1019 | return false; |
| 1020 | } |
| 1021 | |
| 1022 | // Calcul et vérification des surfaces |
| 1023 | unsigned limitX = width - faceSize; |
| 1024 | unsigned limitY = height - faceSize; |
| 1025 | |
| 1026 | Vector2ui backPos = params.backPosition * faceSize; |
| 1027 | if (backPos.x > limitX || backPos.y > limitY) |
| 1028 | { |
| 1029 | NazaraError("Back rectangle is out of image"); |
| 1030 | return false; |
| 1031 | } |
| 1032 | |
| 1033 | Vector2ui downPos = params.downPosition * faceSize; |
| 1034 | if (downPos.x > limitX || downPos.y > limitY) |
| 1035 | { |
| 1036 | NazaraError("Down rectangle is out of image"); |
| 1037 | return false; |
| 1038 | } |
| 1039 | |
| 1040 | Vector2ui forwardPos = params.forwardPosition * faceSize; |
| 1041 | if (forwardPos.x > limitX || forwardPos.y > limitY) |
| 1042 | { |
| 1043 | NazaraError("Forward rectangle is out of image"); |
| 1044 | return false; |
| 1045 | } |
| 1046 | |
| 1047 | Vector2ui leftPos = params.leftPosition * faceSize; |
| 1048 | if (leftPos.x > limitX || leftPos.y > limitY) |
| 1049 | { |
| 1050 | NazaraError("Left rectangle is out of image"); |
| 1051 | return false; |