| 64 | } |
| 65 | |
| 66 | void GLTextRenderer::upload_atlas() { |
| 67 | canvas_.glActiveTexture(GL_TEXTURE0); |
| 68 | canvas_.glBindTexture(GL_TEXTURE_2D, text_tex); |
| 69 | |
| 70 | text_texture_width = atlas_.texture_width; |
| 71 | text_texture_height = atlas_.texture_height; |
| 72 | |
| 73 | { |
| 74 | constexpr auto mipmap_levels = 5; |
| 75 | auto tex_level_width = static_cast<int>(text_texture_width); |
| 76 | auto tex_level_height = static_cast<int>(text_texture_height); |
| 77 | |
| 78 | for (int i = 0; i < mipmap_levels; ++i) { |
| 79 | canvas_.glTexImage2D(GL_TEXTURE_2D, |
| 80 | i, |
| 81 | GL_R8, |
| 82 | tex_level_width, |
| 83 | tex_level_height, |
| 84 | 0, |
| 85 | GL_RED, |
| 86 | GL_UNSIGNED_BYTE, |
| 87 | nullptr); |
| 88 | |
| 89 | tex_level_width = (std::max)(1, tex_level_width / 2); |
| 90 | tex_level_height = (std::max)(1, tex_level_height / 2); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | { |
| 95 | canvas_.glTexSubImage2D(GL_TEXTURE_2D, |
| 96 | 0, |
| 97 | 0, |
| 98 | 0, |
| 99 | static_cast<GLsizei>(text_texture_width), |
| 100 | static_cast<GLsizei>(text_texture_height), |
| 101 | GL_RED, |
| 102 | GL_UNSIGNED_BYTE, |
| 103 | atlas_.pixels.data()); |
| 104 | } |
| 105 | |
| 106 | text_texture_offsets = atlas_.offsets; |
| 107 | text_texture_advances = atlas_.advances; |
| 108 | text_texture_sizes = atlas_.sizes; |
| 109 | text_texture_tls = atlas_.tls; |
| 110 | |
| 111 | canvas_.glGenerateMipmap(GL_TEXTURE_2D); |
| 112 | canvas_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 113 | canvas_.glTexParameteri( |
| 114 | GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 115 | const auto& dialect = the_dialect(); |
| 116 | const auto wrap_mode = |
| 117 | dialect.has_texture_wrap_r ? GL_CLAMP_TO_BORDER : GL_CLAMP_TO_EDGE; |
| 118 | canvas_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode); |
| 119 | canvas_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode); |
| 120 | if (dialect.has_texture_wrap_r) { |
| 121 | canvas_.glTexParameteri( |
| 122 | GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER); |
| 123 | } |
nothing calls this directly
no test coverage detected