Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Macros | Functions | Variables
texture.cpp File Reference

Main texture loading and organizing routines. More...

#include <SDL_opengl.h>
#include <boost/algorithm/clamp.hpp>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <map>
#include <memory>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include "SDL_pixels.h"
#include "SDL_surface.h"
#include "inexor/engine/glexts.hpp"
#include "inexor/engine/renderbackground.hpp"
#include "inexor/engine/rendergl.hpp"
#include "inexor/io/Logging.hpp"
#include "inexor/io/legacy/stream.hpp"
#include "inexor/network/SharedVar.hpp"
#include "inexor/shared/command.hpp"
#include "inexor/shared/cube_formatting.hpp"
#include "inexor/shared/cube_loops.hpp"
#include "inexor/shared/cube_tools.hpp"
#include "inexor/shared/geom.hpp"
#include "inexor/shared/tools.hpp"
#include "inexor/texture/SDL_loading.hpp"
#include "inexor/texture/additionaltools.hpp"
#include "inexor/texture/compressedtex.hpp"
#include "inexor/texture/cubemap.hpp"
#include "inexor/texture/format.hpp"
#include "inexor/texture/image.hpp"
#include "inexor/texture/slot.hpp"
#include "inexor/texture/texsettings.hpp"
#include "inexor/texture/texture.hpp"

Macros

#define PARSETEXCOMMANDS(cmds)
 

Functions

 COMMAND (gendds,"ss")
 
 COMMAND (flipnormalmapy,"ss")
 
 COMMAND (mergenormalmaps,"ss")
 
void setuptexcompress ()
 
void uploadtexture (GLenum target, GLenum internal, int tw, int th, GLenum format, GLenum type, void *pixels, int pw, int ph, int pitch, bool mipmap)
 
void uploadcompressedtexture (GLenum target, GLenum subtarget, GLenum format, int w, int h, uchar *data, int align, int blocksize, int levels, bool mipmap)
 
void setuptexparameters (int tnum, void *pixels, int clamp, int filter, GLenum format, GLenum target)
 
void createtexture (int tnum, int w, int h, void *pixels, int clamp, int filter, GLenum component, GLenum subtarget, int pw, int ph, int pitch, bool resize, GLenum format)
 
void createcompressedtexture (int tnum, int w, int h, uchar *data, int align, int blocksize, int levels, int clamp, int filter, GLenum format, GLenum subtarget)
 
Textureregistertexture (const char *name)
 Registers a texture to the texture registry, so it wont be loaded twice (but looked up the other time). More...
 
Texturegettexture (const char *name)
 Receives a texture from the hashtable of all loaded textures if name is equal. More...
 
int texalign (void *data, int w, int bpp)
 
Texturenewtexture (Texture *t, const char *rname, ImageData &s, int clamp, bool mipit, bool canreduce, bool transient, int compress)
 
static vec parsevec (const char *arg)
 
 VAR (usedds, 0, 1, 1)
 
 VAR (scaledds, 0, 2, 4)
 
bool texturedata (ImageData &d, const char *tname, Slot::Tex *tex, bool msg, int *compress)
 
ucharloadalphamask (Texture *t)
 
Texturetextureload (const char *name, int clamp, bool mipit, bool msg, bool threadsafe)
 
bool settexture (const char *name, int clamp)
 
void cleanuptexture (Texture *t)
 Clean up texture t: delete texture from gpu, only remove from registry if transient. More...
 
void cleanuptextures ()
 
bool reloadtexture (const char *name)
 
bool reloadtexture (Texture &tex)
 
void reloadtex (char *name)
 
 COMMAND (reloadtex,"s")
 
void reloadtextures ()
 
bool loadimage (const char *filename, ImageData &image)
 

Variables

std::unordered_map
< std::string, Texture
textures
 
Texturenotexture = nullptr
 Global used to specify this texture has not be found. More...
 

Detailed Description

Main texture loading and organizing routines.

Macro Definition Documentation

#define PARSETEXCOMMANDS (   cmds)
Value:
const char *cmd = NULL, *end = NULL, *arg[4] = { NULL, NULL, NULL, NULL }; \
cmd = &cmds[1]; \
end = strchr(cmd, '>'); \
if(!end) break; \
cmds = strchr(cmd, '<'); \
size_t len = strcspn(cmd, ":,><"); \
loopi(4) \
{ \
arg[i] = strchr(i ? arg[i-1] : cmd, i ? ',' : ':'); \
if(!arg[i] || arg[i] >= end) arg[i] = ""; \
else arg[i]++; \
}
else loopi(numargs)
Definition: command.cpp:3019
#define NULL
Definition: cube_types.hpp:35
if(NOT DEFINED PROJECT_ARCH) message(FATAL_ERROR"You are generating from the wrong folder! \"Where is the Source
Definition: CMakeLists.txt:2
int end()
Definition: glemu.cpp:256

Referenced by texturedata().

Function Documentation

void cleanuptexture ( Texture t)

Clean up texture t: delete texture from gpu, only remove from registry if transient.

References Texture::alphamask, DELETEA, Texture::id, Texture::name, Texture::TRANSIENT, and Texture::type.

Referenced by cleanuptextures(), and clearenvmaps().

void cleanuptextures ( )
COMMAND ( gendds  ,
"ss"   
)
COMMAND ( flipnormalmapy  ,
"ss"   
)
COMMAND ( mergenormalmaps  ,
"ss"   
)
COMMAND ( reloadtex  ,
"s"   
)
void createcompressedtexture ( int  tnum,
int  w,
int  h,
uchar data,
int  align,
int  blocksize,
int  levels,
int  clamp,
int  filter,
GLenum  format,
GLenum  subtarget 
)
void createtexture ( int  tnum,
int  w,
int  h,
void pixels,
int  clamp,
int  filter,
GLenum  component,
GLenum  subtarget,
int  pw,
int  ph,
int  pitch,
bool  resize,
GLenum  format 
)
Texture* gettexture ( const char *  name)

Receives a texture from the hashtable of all loaded textures if name is equal.

Warning
not threadsafe.

References copystring(), and path().

Referenced by Slot::combinetextures(), cubemaploadwildcard(), gendds(), Slot::loadthumbnail(), reloadtex(), reloadtexture(), and textureload().

uchar* loadalphamask ( Texture t)
bool loadimage ( const char *  filename,
ImageData image 
)
Texture* newtexture ( Texture t,
const char *  rname,
ImageData s,
int  clamp,
bool  mipit,
bool  canreduce,
bool  transient,
int  compress 
)
static vec parsevec ( const char *  arg)
static

Referenced by texturedata().

Texture* registertexture ( const char *  name)

Registers a texture to the texture registry, so it wont be loaded twice (but looked up the other time).

References copystring(), Texture::name, newstring(), path(), and anonymous_namespace{utilTest.cpp}::t().

Referenced by cubemaploadwildcard(), and newtexture().

void reloadtex ( char *  name)
bool reloadtexture ( const char *  name)
bool reloadtexture ( Texture tex)
void reloadtextures ( )

References loadprogress, and reloadtexture().

Referenced by resetgl().

bool settexture ( const char *  name,
int  clamp 
)
void setuptexcompress ( )

References GLenum(), texcompressquality, and usetexcompress.

Referenced by gendds(), and gl_init().

void setuptexparameters ( int  tnum,
void pixels,
int  clamp,
int  filter,
GLenum  format,
GLenum  target 
)
int texalign ( void data,
int  w,
int  bpp 
)
bool texturedata ( ImageData d,
const char *  tname,
Slot::Tex tex,
bool  msg,
int *  compress 
)
Texture* textureload ( const char *  name,
int  clamp = 0,
bool  mipit = true,
bool  msg = true,
bool  threadsafe = false 
)
Parameters
nameName of texture
clampthe last pixel of texture image will be stretched to infinity
mipitspecifies whether mipmap (lower quality versions; usually used when far away or small) textures should be created.
msgspecifies whether a renderprogress bar should be displayed while loading. Always off if threadsafe = true.
threadsafeif true, the texture wont be automatically registerd to the global texture registry, you need to check whether it is loaded via gettexture beforehand in a nonthreaded environment and register it afterwards with registertexture.

References tiger::compress(), copystring(), gettexture(), newtexture(), notexture, anonymous_namespace{utilTest.cpp}::t(), and texturedata().

Referenced by bind_bomb_items_texture(), bind_items_texture(), gui::button_(), draw_g3d_cursor(), drawdamagescreen(), gui::drawskin(), fonttex(), gendds(), gengrassquads(), guiimage(), gui::icon_(), decalrenderer::init(), blobrenderer::init(), gui::line_(), md5::md5mesh::load(), load_world(), loadcaustics(), loadcrosshair(), loadsky(), loadskyoverlay(), main(), gui::modelpreview(), newfont(), gui::playerpreview(), gui::prefabpreview(), gui::previewslot(), flarerenderer::render(), listrenderer::render(), varenderer< T >::render(), renderbackground(), renderprogress(), modelcommands< MDL, struct MDL::vertmesh >::setbumpmap(), modelcommands< MDL, struct MDL::vertmesh >::setskin(), and settexture().

void uploadcompressedtexture ( GLenum  target,
GLenum  subtarget,
GLenum  format,
int  w,
int  h,
uchar data,
int  align,
int  blocksize,
int  levels,
bool  mipmap 
)
void uploadtexture ( GLenum  target,
GLenum  internal,
int  tw,
int  th,
GLenum  format,
GLenum  type,
void pixels,
int  pw,
int  ph,
int  pitch,
bool  mipmap 
)
VAR ( usedds  ,
,
,
 
)
VAR ( scaledds  ,
,
,
 
)

Variable Documentation

Texture* notexture = nullptr
std::unordered_map<std::string, Texture> textures