MCPcopy Create free account
hub / github.com/OpenImageDebugger/OpenImageDebugger / texture_for

Method texture_for

src/host/ui/svg_icon_cache.cpp:93–134  ·  view source on GitHub ↗

The GL calls below are used raw (not via GlfwCanvas's dispatch table): glGenTextures/glBindTexture/glTexParameteri/glTexImage2D/glDeleteTextures are OpenGL 1.0/1.1 entry points, exported directly by every desktop GL library the app links (OpenGL.framework, libGL, opengl32) -- no glfwGetProcAddress loading is required for them, unlike the post-1.1 functions GlfwCanvas has to load. Do not extrapolat

Source from the content-addressed store, hash-verified

91// functions GlfwCanvas has to load. Do not extrapolate this to newer GL
92// functions.
93GLuint SvgIconCache::texture_for(IconId id, int logical_w, int logical_h) {
94 Entry& entry = entries_[static_cast<std::size_t>(id)];
95 if (entry.cached) {
96 return entry.failed ? 0 : entry.tex;
97 }
98
99 const auto out_w =
100 static_cast<int>(static_cast<float>(logical_w) * content_scale_);
101 const auto out_h =
102 static_cast<int>(static_cast<float>(logical_h) * content_scale_);
103
104 const auto [svg_data, svg_size] = svg_source_for(id);
105 const std::vector<unsigned char> rgba =
106 rasterize_svg(svg_data, svg_size, out_w, out_h);
107 if (rgba.empty()) {
108 entry = Entry{/*tex=*/0, /*failed=*/true, /*cached=*/true};
109 return 0;
110 }
111
112 // Mirror ThumbnailCache's texture parameterization (thumbnail_cache.cpp)
113 // -- linear filtering, clamp to edge -- so these icons scale/sample the
114 // same way the buffer-list thumbnails do.
115 GLuint tex = 0;
116 glGenTextures(1, &tex);
117 glBindTexture(GL_TEXTURE_2D, tex);
118 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
119 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
120 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
121 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
122 glTexImage2D(GL_TEXTURE_2D,
123 0,
124 GL_RGBA8,
125 out_w,
126 out_h,
127 0,
128 GL_RGBA,
129 GL_UNSIGNED_BYTE,
130 rgba.data());
131
132 entry = Entry{tex, /*failed=*/false, /*cached=*/true};
133 return tex;
134}
135
136} // namespace oid::host

Callers 3

draw_goto_axis_fieldFunction · 0.45
draw_contrast_panelFunction · 0.45
draw_buffer_list_rowFunction · 0.45

Calls 3

svg_source_forFunction · 0.85
rasterize_svgFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected