MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / makeRectangularTextureInternal

Method makeRectangularTextureInternal

Source/Graphics/textures.cpp:2240–2326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2238}
2239
2240unsigned int Textures::makeRectangularTextureInternal(int width, int height, GLint internal_format, GLint format) {
2241 CHECK_GL_ERROR();
2242 unsigned which = AllocateFreeSlot();
2243
2244 Texture& texture = textures[which];
2245 texture.Init();
2246 texture.width = width;
2247 texture.height = height;
2248 texture.internal_format = internal_format;
2249 texture.format = format;
2250 texture.tex_target = GL_TEXTURE_2D;
2251
2252 glGenTextures(1, &texture.gl_texture_id);
2253 LOG_ASSERT(texture.gl_texture_id != INVALID_ID);
2254 LOG_ASSERT(texture.gl_texture_id != UNLOADED_ID);
2255
2256 CHECK_GL_ERROR();
2257 glBindTexture(texture.tex_target, texture.gl_texture_id);
2258 CHECK_GL_ERROR();
2259 unsigned int totalTextureSize = 0;
2260 if (internal_format == GL_RGBA16F || internal_format == GL_RGBA32F || internal_format == GL_DEPTH_COMPONENT || internal_format == GL_DEPTH_COMPONENT24) {
2261 if (Graphics::Instance()->features().HDR_enable()) {
2262 glTexImage2D(texture.tex_target, 0, internal_format, width, height, 0,
2263 format, GL_UNSIGNED_BYTE, NULL);
2264 totalTextureSize += width * height * 8;
2265 int level = 0;
2266 while (width > 1 || height > 1) {
2267 width = max(1, width / 2);
2268 height = max(1, height / 2);
2269 ++level;
2270 glTexImage2D(texture.tex_target, level, internal_format, width, height, 0,
2271 format, GL_UNSIGNED_BYTE, NULL);
2272 totalTextureSize += width * height * 8;
2273 }
2274 CHECK_GL_ERROR();
2275 } else {
2276 glTexImage2D(texture.tex_target, 0, GL_RGBA, width, height, 0,
2277 format, GL_UNSIGNED_BYTE, NULL);
2278 totalTextureSize += width * height * 4;
2279 int level = 0;
2280 while (width > 1 || height > 1) {
2281 width = max(1, width / 2);
2282 height = max(1, height / 2);
2283 ++level;
2284 glTexImage2D(texture.tex_target, level, GL_RGBA, width, height, 0,
2285 format, GL_UNSIGNED_BYTE, NULL);
2286 totalTextureSize += width * height * 4;
2287 }
2288 CHECK_GL_ERROR();
2289 }
2290 } else {
2291 glTexImage2D(texture.tex_target, 0, internal_format, width, height, 0,
2292 format, GL_UNSIGNED_BYTE, NULL);
2293 totalTextureSize += width * height * 4;
2294 int level = 0;
2295 while (width > 1 || height > 1) {
2296 width = max(1, width / 2);
2297 height = max(1, height / 2);

Callers

nothing calls this directly

Calls 3

maxFunction · 0.85
HDR_enableMethod · 0.80
InitMethod · 0.45

Tested by

no test coverage detected