* Interface implementations */
| 30 | * Interface implementations |
| 31 | */ |
| 32 | Texture::Texture(std::vector<std::string>& asset_paths, |
| 33 | AAssetManager* asset_manager) { |
| 34 | // For Cubemap, we use world normal to sample the textures |
| 35 | // so no texture vbo necessary |
| 36 | |
| 37 | int32_t imgWidth, imgHeight, channelCount; |
| 38 | std::vector<uint8_t> fileBits; |
| 39 | |
| 40 | if (!asset_manager || asset_paths.size() != 6) { |
| 41 | assert(false); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | glGenTextures(1, &texId_); |
| 46 | glBindTexture(GL_TEXTURE_CUBE_MAP, texId_); |
| 47 | |
| 48 | if (texId_ == GL_INVALID_VALUE) { |
| 49 | assert(false); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | for (GLuint i = 0; i < 6; i++) { |
| 54 | fileBits.clear(); |
| 55 | AssetReadFile(asset_manager, asset_paths[i], fileBits); |
| 56 | |
| 57 | // tga/bmp asset_paths are saved as vertical mirror images ( at least more |
| 58 | // than half ). |
| 59 | stbi_set_flip_vertically_on_load(1); |
| 60 | |
| 61 | uint8_t* imageBits = |
| 62 | stbi_load_from_memory(fileBits.data(), fileBits.size(), &imgWidth, |
| 63 | &imgHeight, &channelCount, 4); |
| 64 | |
| 65 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA, imgWidth, |
| 66 | imgHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageBits); |
| 67 | stbi_image_free(imageBits); |
| 68 | } |
| 69 | |
| 70 | glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 71 | glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 72 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 73 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 74 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 75 | |
| 76 | glActiveTexture(GL_TEXTURE0); |
| 77 | } |
| 78 | |
| 79 | Texture::~Texture() { |
| 80 | if (texId_ != GL_INVALID_VALUE) { |
nothing calls this directly
no test coverage detected