Class: texture

Bitmaps that store color information.
There is two kind of textures: loaded from file and created in memory. Filebased textures are 'load'ed while pure memory textures are created with 'new'. Loading defaults to mipmap true and keepdata false.When a texturename looks like 'USER_TEX(myname)' then luxinia will check if a loaded texture was registered as usertex with 'myname' or if a user created texture with that name exists.

Hierarchy

o-+ resource
  o-+ texture

Interfaces:

Methods:

Method overview:


arraydecal (texture, floatarray, int x,y,w,h,[float alphamul],[boolean mask r,g,b,a])
returns: ()
decal blends the floatarray (4 floats per pixel) on top of current imagedata rectangle, defined by x,y,w,h. Optionally you can mask off certain channels.
arrayset (texture, floatarray, int x,y,w,h,[boolean mask r,g,b,a])
returns: ()
sets pixels from floatarry (4 floats per pixel). Optionally you can mask off certain channels.
clamp (texture,[boolean all]/[boolean x,y,z])
returns: ([boolean x,y,z])
sets or gets clamping of the texture. If not set texture will repeat, default is off. By passing one boolean you will toggle all, else you can specify in detail which axis to repeat/clamp.
combine2d (stringstack,[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
combines all 2d textures to a single row, ideally number of textures should be power of 2, max 64 textures
combinecube (stringstack,[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
combines all 2d textures to a single cubemap, 6 textures are required
convfilterboxdata (texture,int kernelsize,[boolean wrap])
returns: ()
runs convolution boxcar filter on the imagedata. wrap defaults to true
convfiltergaussdata (texture,int kernelsize,[boolean wrap])
returns: ()
runs convolution gauss filter on the imagedata. wrap defaults to true
create2d (string name, int width, int height,textype, [boolean keepdata], [boolean nofilter],[boolean mipmap],[int data 0..2])
returns: (texture)
creates a new empty texture in memory. Width and height must be power of two (unless capability for rectangle textures). Data are 0 = Unsigned Byte (default), 1 = Float, 2 = HalfFloat (need capability). Automatically registered as USER_TEX. No compression supported. Mipmapping will only work when keepdata + reloaddata is used, or when hardware mipmapping exists.
create3d (string name, int width, int height, int depth, textype, [boolean keepdata], [boolean nofilter],[boolean mipmap],[int data 0..2])
returns: (texture)
creates a new empty texture in memory. Sizes must be power of two (unless np2 supported). Automatically registered as USER_TEX. Same creation, compression and mipmap rules as for new2d
createcube (string name, int size, textype, [boolean keepdata], [boolean nofilter],[boolean mipmap],[int data 0..2])
returns: (texture)
creates a new empty texture in memory. Size must be power of two. Automatically registered as USER_TEX. Same creation, compression and mipmap rules as for new2d
createfullwindow (string name,[textype],[nofilter],[int datatype])
returns: (texture)
creates a new empty windowsized texture. Should only be used within materials or as rendertargets, else you might need to set texture matrices manually (needed if capability for rectangle textures exists). Automatically registered as USER_TEX. No mipmapping nor compression supported. By default nofilter is true and textype is rgba (internally whatever is closest to window is used). The speciality about windowsized textures is that if you change window resolution they are automatically resized.
datapointer (texture)
returns: (int start, int end)
if the texture was loaded with keepdata you can access the memory directly in other lua dlls. Be aware that you must make sure to not corrupt memory, make sure you are always smaller than the 'end' pointer.
defaultpath ([string])
returns: ([string])
returns or sets the default resource path. Luxinia will search in those when resources are not found.
deletedata (texture)
returns: ()
deletes the imagedata in system memory. you can now longer change or sample it.
deletevid (texture)
returns: ()
unloads the texture from video memory, can result into errors when you free a still in use texture.
dimension (texture)
returns: (int width,height,depth,bpp,origwidth,origheight)
will return infos about the texture. It returns the size in memory and the original size. If system.detail() is <2, the loaded textures are resized at half of their size! If you do any calculations on the image depending on its size, you have to take this into account!
filter (texture,[boolean both]/[boolean min,mag])
returns: ([boolean min,mag])
returns or sets if texture filtering is used for minfication or/and magnification.
getdata (texture)
returns: ()
if texture was not loaded with keepdata, we can retrieve imagedata this way and set keepdata
getrestype ()
returns: (int restype)
returns the resource type as int value, useful for resdata or reschunk functions
lightmapscale (texture,[float])
returns: ([float])
returns or sets how much the output is scaled, when this texture is used as lightmap outside of shaders (or when lightmapscale is used in shader stage)
load (string file,[boolean mipmap],[boolean keepdata],[int type])
returns: (Texture tex)
loads a color 1d/2d texture (RGB or RGBA depending on file). Dimension depends on file.
load3d (string file,[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
loads a color 3d texture (RGB or RGBA depending on file). 3D textures are either .dds or a 2d image whose slices are stored vertically along image height. So that depth = height/width, height = width
load3dalpha (string file,[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
loads a alpha 3d texture
load3dlum (string file,[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
loads a luminance 3d texture.
loadalpha (string file,[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
loads a alpha 1d/2d texture.
loadcube (string file,[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
loads a color cube texture (RGB or RGBA depending on file). Cube texture are either .dds or 2d image whose sides are stored (+x,-x,+y,-y,+z,-z) vertically. So that height = width*6.
loadcubealpha (string file,[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
loads a alpha cube texture
loadcubedotz (string file,[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
loads a special color cubemap texture, generated from a single 1d image to create a vector.dot.+Z cubemap, cube.size is half of width. -1 is left and +1 is right. if nothing is specified we will use mipmapping.
loadcubelum (string file,[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
loads a luminance cube texture.
loadcubeproj (string file,[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
loads a special color cubemap texture, generated from a single 2d image to fix backprojection problems, if nothing is specified we will use mipmapping.
loaddata (string file)
returns: (Texture tex)
loads a texture, but it will not be renderable. (autosets keepdata)
loadlum (string file,[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
loads a luminance 1d/2d texture.
mipmapping (texture,[boolean])
returns: ([boolean])
turn on/off mipmapping for the texture. Only works when texture was created with mipmap support.
name (texture tex)
returns: (string)
returns name of texture
pack2d (string filenameR, string filenameG, string filenameB,[string filenameA],[boolean mipmap],[boolean keepdata])
returns: (Texture tex)
combines all 2d textures to a single image where each image file becomes one color channel. 3 or 4 filenames required.
pixel (texture,int x,y,[z],[float r,g,b,a])
returns: ([float r,g,b,a])
same as sample but works with discrete coordinates and can set pixels. Writing to texture is not visible until uploaddata or reloaddata was called. Z can be 0-5 for cubemap side, and 0-depth for 3d textures. If internal format is BGR/BGRA/ABGR values must be manually reordered, LUMALPHA uses R and G channels. ALPHA/LUM use R channel.)
pixelbyte (texture,int x,y,[z],[int r,g,b,a])
returns: ([int r,g,b,a])
same as pixel but assumes channels as byte values (0-255).
registerusertex (texture,string username)
returns: ()
registers the texture as USER_TEX. If anyone access a texture with the name 'USER_TEX(username)' this texture will be used. The name will be unavailable once texture was deleted.
reload
() : (texture,[string filename,boolean keepoldsize] - reloads the texture with original (or new filename) with same specifications as on first load. The internal filename remains to be the original filename. Optionally the texture can be forced to the current texturesize.
reloaddata (texture)
returns: ()
deletes old image in videomemory, and uploads a new one with the current imagedata. this is slower than uploaddata but supports all textures.
resize (texture,int width, int height)
returns: ()
resizing textures. previous data is lost.
sample (texture,float u,v,[w],[boolean clamp])
returns: ([float r,g,b,a])
gets color from data texture, does clamped,bilinear filtering. More details under pixel function.
savetofile (texture,string filename,[int quality],[int cubeside])
returns: ()
saves texture to file. quality must be within 1 and 100 and is used for .jpg (default is 85). cubeside can be 0-5 for cubemap textures (default 0)
swap (texture,texture)
returns: ()
swaps both texture contents, all images who already referenced one of either, now uses the other data. Names stay as they were.
uploaddata (texture,[int x,y,z,w,h,d/int side],[floatarray/staticarray uploaddata])
returns: ()
will upload the current data to video memory. Only works on user-created textures with data, or if dataarray is passed. x,y,z are the starting points, w,h,d the dimension of the updated area. If arraysize does not match full texture dimension, then dataarray is assumed to be only the update rectangle. Side is for cubemaps (0-5), else cubemaps take Z as side. All numbers passed must be positive

Inherited Methods:

From resource

condition, getresname, getresshortname, resuserstring