OGLESTexture2D::OGLESTexture2D(uint32_t width, uint32_t height, uint32_t numMipMaps, uint32_t array_size, ElementFormat format, uint32_t sample_count, uint32_t sample_quality, uint32_t access_hint) : OGLESTexture(TT_2D, array_size, sample_count, sample_quality, access_hint) { if (IsSRGB(format)) { format = this->SRGBToRGB(format); } format_ = format; if (0 == numMipMaps) { num_mip_maps_ = 1; uint32_t w = width; uint32_t h = height; while ((w != 1) || (h != 1)) { ++ num_mip_maps_; w = std::max<uint32_t>(1U, w / 2); h = std::max<uint32_t>(1U, h / 2); } } else { num_mip_maps_ = numMipMaps; } width_ = width; height_ = height; tex_data_.resize(array_size_ * num_mip_maps_); glBindTexture(target_type_, texture_); if (glloader_GLES_VERSION_3_0()) { glTexParameteri(target_type_, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(target_type_, GL_TEXTURE_MAX_LEVEL, num_mip_maps_ - 1); } else if (glloader_GLES_APPLE_texture_max_level()) { glTexParameteri(target_type_, GL_TEXTURE_MAX_LEVEL_APPLE, num_mip_maps_ - 1); } else { OGLESRenderEngine& re = *checked_cast<OGLESRenderEngine*>(&Context::Instance().RenderFactoryInstance().RenderEngineInstance()); if (re.HackForTegra()) { glTexParameteri(target_type_, GL_TEXTURE_MAX_LEVEL, num_mip_maps_ - 1); } } }
OGLESTextureCube::OGLESTextureCube(uint32_t size, uint32_t numMipMaps, uint32_t array_size, ElementFormat format, uint32_t sample_count, uint32_t sample_quality, uint32_t access_hint, ElementInitData const * init_data) : OGLESTexture(TT_Cube, array_size, sample_count, sample_quality, access_hint) { if (IsSRGB(format)) { format = this->SRGBToRGB(format); } format_ = format; if (0 == numMipMaps) { num_mip_maps_ = 1; uint32_t s = size; while (s > 1) { ++ num_mip_maps_; s = std::max<uint32_t>(1U, s / 2); } } else { num_mip_maps_ = numMipMaps; } array_size_ = 1; uint32_t texel_size = NumFormatBytes(format_); GLint glinternalFormat; GLenum glformat; GLenum gltype; OGLESMapping::MappingFormat(glinternalFormat, glformat, gltype, format_); glGenTextures(1, &texture_); glBindTexture(target_type_, texture_); glTexParameteri(target_type_, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(target_type_, GL_TEXTURE_MIN_FILTER, GL_NEAREST); if (glloader_GLES_VERSION_3_0()) { glTexParameteri(target_type_, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(target_type_, GL_TEXTURE_MAX_LEVEL, num_mip_maps_ - 1); } else if (glloader_GLES_APPLE_texture_max_level()) { glTexParameteri(target_type_, GL_TEXTURE_MAX_LEVEL_APPLE, num_mip_maps_ - 1); } tex_data_.resize(6 * num_mip_maps_); widths_.resize(6 * num_mip_maps_); for (int face = 0; face < 6; ++ face) { uint32_t s = size; for (uint32_t level = 0; level < num_mip_maps_; ++ level) { widths_[face * num_mip_maps_ + level] = s; if (IsCompressedFormat(format_)) { int block_size; if ((EF_BC1 == format_) || (EF_SIGNED_BC1 == format_) || (EF_BC1_SRGB == format_) || (EF_BC4 == format_) || (EF_SIGNED_BC4 == format_) || (EF_BC4_SRGB == format_)) { block_size = 8; } else { block_size = 16; } GLsizei const image_size = ((s + 3) / 4) * ((s + 3) / 4) * block_size; if (nullptr == init_data) { tex_data_[face * num_mip_maps_ + level].resize(image_size, 0); } else { tex_data_[face * num_mip_maps_ + level].resize(image_size); std::memcpy(&tex_data_[face * num_mip_maps_ + level][0], init_data[face * num_mip_maps_ + level].data, image_size); } glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, level, glinternalFormat, s, s, 0, image_size, &tex_data_[face * num_mip_maps_ + level][0]); } else { GLsizei const image_size = s * s * texel_size; if (nullptr == init_data) { tex_data_[face * num_mip_maps_ + level].resize(image_size, 0); } else { tex_data_[face * num_mip_maps_ + level].resize(image_size); std::memcpy(&tex_data_[face * num_mip_maps_ + level][0], init_data[face * num_mip_maps_ + level].data, image_size); } glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, level, glinternalFormat, s, s, 0, glformat, gltype, &tex_data_[face * num_mip_maps_ + level][0]); } s = std::max(1U, s / 2); } } }