convert single surface into tiles according w/h register tiles in texture raws and return handles
| 129 | // convert single surface into tiles according w/h |
| 130 | // register tiles in texture raws and return handles |
| 131 | std::vector<TexposHandle> slice_tileset(SDL_Surface* surface, int tile_px_w, int tile_px_h, |
| 132 | bool reserved) { |
| 133 | std::vector<TexposHandle> handles{}; |
| 134 | if (!surface) |
| 135 | return handles; |
| 136 | |
| 137 | int dimx = surface->w / tile_px_w; |
| 138 | int dimy = surface->h / tile_px_h; |
| 139 | |
| 140 | if (reserved && (dimx * dimy > reserved_range.end - reserved_range.current)) { |
| 141 | WARN(textures).print( |
| 142 | "there is not enough space in reserved range for whole tileset, using dynamic range\n"); |
| 143 | reserved = false; |
| 144 | } |
| 145 | |
| 146 | for (int y = 0; y < dimy; y++) { |
| 147 | for (int x = 0; x < dimx; x++) { |
| 148 | SDL_Surface* tile = DFSDL_CreateRGBSurface( |
| 149 | 0, tile_px_w, tile_px_h, 32, surface->format->Rmask, surface->format->Gmask, |
| 150 | surface->format->Bmask, surface->format->Amask); |
| 151 | SDL_Rect vp{tile_px_w * x, tile_px_h * y, tile_px_w, tile_px_h}; |
| 152 | DFSDL_UpperBlit(surface, &vp, tile, NULL); |
| 153 | auto handle = Textures::loadTexture(tile, reserved); |
| 154 | handles.push_back(handle); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | DFSDL_FreeSurface(surface); |
| 159 | return handles; |
| 160 | } |
| 161 | |
| 162 | TexposHandle Textures::loadTexture(SDL_Surface* surface, bool reserved) { |
| 163 | if (!surface || !enabler) |
no test coverage detected