| 1944 | |
| 1945 | template<typename T> |
| 1946 | TextureCubeMapRef TextureCubeMap::createTextureCubeMapImpl( const ImageSourceRef &imageSource, const Format &format ) |
| 1947 | { |
| 1948 | std::vector<CubeMapFaceRegion> faceRegions; |
| 1949 | |
| 1950 | // Infer the layout based on image aspect ratio |
| 1951 | ivec2 imageSize( imageSource->getWidth(), imageSource->getHeight() ); |
| 1952 | float minDim = (float)std::min( imageSize.x, imageSize.y ); |
| 1953 | float maxDim = (float)std::max( imageSize.x, imageSize.y ); |
| 1954 | float aspect = minDim / maxDim; |
| 1955 | if( abs( aspect - 1 / 6.0f ) < abs( aspect - 3 / 4.0f ) ) { // closer to 1:6 than to 4:3, so row or column |
| 1956 | faceRegions = ( imageSize.x > imageSize.y ) ? calcCubeMapHorizontalRegions( imageSource ) : calcCubeMapVerticalRegions( imageSource ); |
| 1957 | } |
| 1958 | else { // else, horizontal or vertical cross |
| 1959 | faceRegions = ( imageSize.x > imageSize.y ) ? calcCubeMapHorizontalCrossRegions( imageSource ) : calcCubeMapVerticalCrossRegions( imageSource ); |
| 1960 | } |
| 1961 | |
| 1962 | Area faceArea = faceRegions.front().mArea; |
| 1963 | ivec2 faceSize = faceArea.getSize(); |
| 1964 | |
| 1965 | SurfaceT<T> masterSurface( imageSource, SurfaceConstraintsDefault() ); |
| 1966 | SurfaceT<T> images[6]; |
| 1967 | |
| 1968 | for( uint8_t f = 0; f < 6; ++f ) { |
| 1969 | images[f] = SurfaceT<T>( faceSize.x, faceSize.y, masterSurface.hasAlpha(), SurfaceConstraints() ); |
| 1970 | images[f].copyFrom( masterSurface, faceRegions[f].mArea, faceRegions[f].mOffset ); |
| 1971 | if( faceRegions[f].mFlip ) { |
| 1972 | ip::flipVertical( &images[f] ); |
| 1973 | ip::flipHorizontal( &images[f] ); |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | if( format.mDeleter ) |
| 1978 | return TextureCubeMapRef( new TextureCubeMap( images, format ), format.mDeleter ); |
| 1979 | else |
| 1980 | return TextureCubeMapRef( new TextureCubeMap( images, format ) ); |
| 1981 | } |
| 1982 | |
| 1983 | TextureCubeMapRef TextureCubeMap::create( const ImageSourceRef images[6], const Format &format ) |
| 1984 | { |
nothing calls this directly
no test coverage detected