MCPcopy Index your code
hub / github.com/assaultcube/AC / loadsurface

Function loadsurface

source/src/texture.cpp:331–399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

329bool uniformtexres = !hirestextures;
330
331GLuint loadsurface(const char *texname, int &xs, int &ys, int &bpp, int clamp = 0, bool mipmap = true, bool canreduce = false, float scale = 1.0f, bool trydl = false)
332{
333 const char *file = texname;
334 if(texname[0]=='<')
335 {
336 file = strchr(texname, '>');
337 if(!file) { if(!silent_texture_load) conoutf("could not load texture %s", texname); return 0; }
338 file++;
339 }
340
341 SDL_Surface *s = NULL;
342 const char *ffile = findfile(file, "rb");
343 if(findfilelocation == FFL_ZIP)
344 {
345 stream *z = openzipfile(file, "rb");
346 if(z)
347 {
348 SDL_RWops *rw = z->rwops();
349 if(rw)
350 {
351 s = IMG_Load_RW(rw, 0);
352 SDL_FreeRW(rw);
353 }
354 delete z;
355 }
356 }
357 else if(!s) s = IMG_Load(ffile);
358 if(!s)
359 {
360 if(trydl) requirepackage(PCK_TEXTURE, file);
361 else if(!silent_texture_load) conoutf("couldn't load texture %s", texname);
362 return 0;
363 }
364 s = fixsurfaceformat(s);
365 if(strstr(texname,"playermodel")) { fixcl(s, 45); }
366 else if(strstr(texname,"skin") && strstr(texname,"weapon")) { fixcl(s, 44); }
367
368 GLenum format = texformat(s->format->BitsPerPixel);
369 if(!format)
370 {
371 SDL_FreeSurface(s);
372 conoutf("texture must be 8, 16, 24, or 32 bpp: %s", texname);
373 return 0;
374 }
375 if(max(s->w, s->h) > (1<<12))
376 {
377 SDL_FreeSurface(s);
378 conoutf("texture size exceeded %dx%d pixels: %s", 1<<12, 1<<12, texname);
379 return 0;
380 }
381
382 if(texname[0]=='<')
383 {
384 const char *cmd = &texname[1], *arg1 = strchr(cmd, ':');//, *arg2 = arg1 ? strchr(arg1, ',') : NULL;
385 if(!arg1) arg1 = strchr(cmd, '>');
386 if(!strncmp(cmd, "decal", arg1-cmd)) { s = texdecal(s); format = texformat(s->format->BitsPerPixel); }
387 }
388

Callers 2

textureloadFunction · 0.85
reloadtextureFunction · 0.85

Calls 12

findfileFunction · 0.85
openzipfileFunction · 0.85
requirepackageFunction · 0.85
fixsurfaceformatFunction · 0.85
fixclFunction · 0.85
texformatFunction · 0.85
maxFunction · 0.85
texdecalFunction · 0.85
scalesurfaceFunction · 0.85
createtextureFunction · 0.85
rwopsMethod · 0.80
conoutfFunction · 0.70

Tested by

no test coverage detected