UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
r_image.cpp File Reference
#include "r_local.h"
#include "r_error.h"
#include "r_geoscape.h"
#include "../../shared/images.h"
#include "../cl_screen.h"

Go to the source code of this file.

Data Structures

struct  imageArray_s
 
struct  glTextureMode_t
 
struct  gltmode_t
 

Macros

#define MAX_IMAGEHASH   256
 
#define IMAGE_ARRAY_SIZE   128
 
#define FOR_EACH_IMAGE(i, image, imageArray)
 
#define MAX_TEXTURE_SIZE   8192
 

Typedefs

typedef struct imageArray_s imageArray_t
 

Functions

void R_ImageClearMaterials (void)
 Free previously loaded materials and their stages. More...
 
void R_ImageList_f (void)
 Shows all loaded images. More...
 
void R_LoadImage (const char *name, byte **pic, int *width, int *height)
 Generic image-data loading fucntion. More...
 
void R_ScaleTexture (const unsigned *in, int inwidth, int inheight, unsigned *out, int outwidth, int outheight)
 
void R_GetScaledTextureSize (int width, int height, int *scaledWidth, int *scaledHeight)
 Calculates the texture size that should be used to upload the texture data. More...
 
static bool R_IsClampedImageType (imagetype_t type)
 
void R_UploadTexture (const unsigned *data, int width, int height, image_t *image)
 Uploads the opengl texture to the server. More...
 
void R_SoftenTexture (byte *in, int width, int height, int bpp)
 Applies blurring to a texture. More...
 
void R_UploadAlpha (const image_t *image, const byte *alphaData)
 
static void R_DeleteImage (image_t *image)
 
image_tR_GetImage (const char *name)
 
image_tR_LoadImageData (const char *name, const byte *pic, int width, int height, imagetype_t type)
 Creates a new image from RGBA data. Stores it in the gltextures array and also uploads it. More...
 
image_tR_RenderToTexture (const char *name, int x, int y, int w, int h)
 
static void R_ChangeImageType (image_t *img, imagetype_t type)
 Set up new image type and change texturemapping paramenters accordingly. More...
 
image_tR_FindImage (const char *pname, imagetype_t type)
 Finds or loads the given image. More...
 
const image_tR_FindPics (const char *name)
 Searches for an image in the image array. More...
 
bool R_ImageExists (const char *pname,...)
 
int R_GetImageIndex (image_t *imagePtr)
 Returns an index of the image pointer in the r_images linked list, as if r_images would be a plain contiguous array. More...
 
image_tR_GetImageAtIndex (int i)
 Returns an image pointer from the r_images linked list, as if r_images would be a plain contiguous array. More...
 
void R_FreeImage (image_t *image)
 Free the image and its assigned maps (roughness, normal, specular, glow - if there are any) More...
 
void R_FreeWorldImages (void)
 Any image that is a mesh or world texture will be removed here. More...
 
void R_InitImages (void)
 
void R_ShutdownImages (void)
 
static void R_ReloadImageData (image_t *image)
 
void R_ReloadImages (void)
 
void R_TextureMode (const char *string)
 
void R_TextureAlphaMode (const char *string)
 
void R_TextureSolidMode (const char *string)
 

Variables

static image_timageHash [MAX_IMAGEHASH]
 
imageArray_t r_images
 
int r_numImages
 
image_tr_envmaptextures [MAX_ENVMAPTEXTURES]
 
image_tr_flaretextures [NUM_FLARETEXTURES]
 
static const glTextureMode_t gl_texture_modes []
 
static const gltmode_t gl_alpha_modes []
 
static const gltmode_t gl_solid_modes []
 

Macro Definition Documentation

#define FOR_EACH_IMAGE (   i,
  image,
  imageArray 
)
Value:
for (i = 0, imageArray = &r_images, image = &imageArray->images[0]; i < r_numImages; i++, image++, \
(i % IMAGE_ARRAY_SIZE) ? 0 : (image = (imageArray = imageArray->next) ? &imageArray->images[0] : nullptr))
int r_numImages
Definition: r_image.cpp:41
image_t images[IMAGE_ARRAY_SIZE]
Definition: r_image.cpp:36
QGL_EXTERN GLint i
Definition: r_gl.h:113
imageArray_t r_images
Definition: r_image.cpp:40
#define IMAGE_ARRAY_SIZE
Definition: r_image.cpp:34

Definition at line 44 of file r_image.cpp.

Referenced by R_FreeWorldImages(), R_ImageClearMaterials(), R_ImageList_f(), R_LoadImageData(), R_ReloadImages(), R_ShutdownImages(), and R_TextureMode().

#define IMAGE_ARRAY_SIZE   128

Definition at line 34 of file r_image.cpp.

Referenced by R_GetImageAtIndex(), R_GetImageIndex(), and R_LoadImageData().

#define MAX_IMAGEHASH   256

Definition at line 31 of file r_image.cpp.

Referenced by R_DeleteImage(), R_GetImage(), and R_LoadImageData().

#define MAX_TEXTURE_SIZE   8192

Definition at line 55 of file r_image.cpp.

Referenced by R_GetScaledTextureSize(), and R_ScaleTexture().

Typedef Documentation

typedef struct imageArray_s imageArray_t

Function Documentation

static void R_ChangeImageType ( image_t img,
imagetype_t  type 
)
static

Set up new image type and change texturemapping paramenters accordingly.

Note
Mipmapping mode is not updated

Definition at line 575 of file r_image.cpp.

References glTexParameterf(), R_BindTexture, R_IsClampedImageType(), image_s::texnum, image_s::type, and type.

Referenced by R_FindImage().

static void R_DeleteImage ( image_t image)
inlinestatic
image_t* R_FindImage ( const char *  pname,
imagetype_t  type 
)

Finds or loads the given image.

See also
R_RegisterImage
Parameters
[in]pnameImage name Path relative to the game dir (e.g. textures/tex_common/nodraw)
[in]typeThe type of the image. This has influence on image filters and texture parameters when uploading the image data
Note
the image name has to be at least 5 chars long
See also
R_LoadTGA
R_LoadJPG
R_LoadPNG
Todo:
should also check the mipmapping

Definition at line 603 of file r_image.cpp.

Referenced by CL_AddActor(), Con_DrawConsole(), HUD_UpdateCursor(), R_AliasModelGetSkin(), R_Draw3DGlobe(), R_DrawEntityEffects(), R_DrawFlatGeoscape(), R_DrawFloor(), R_DrawGrass(), R_DrawImageCentered(), R_DrawInitLocal(), R_FindImage(), R_FindPics(), R_InitImages(), R_LoadAnimImages(), R_LoadMaterials(), R_ModLoadTexinfo(), R_ParseStage(), R_UploadData(), SCR_DrawCursor(), SCR_DrawLoadingScreen(), SCR_TouchPics(), SEQ_Render2D(), UI_InitRadar(), UI_LoadImage(), and UI_LoadWrappedImage().

const image_t* R_FindPics ( const char *  name)

Searches for an image in the image array.

Parameters
[in]nameThe name of the image relative to pics/
Note
name may not be null and has to be longer than 4 chars
Returns
nullptr on error or image_t pointer on success
See also
R_FindImage

Definition at line 673 of file r_image.cpp.

References it_pic, R_FindImage(), r_noTexture, and va().

Referenced by CL_ParticleLoadArt(), LE_BrushModelAction(), and SEQ_ExecutePrecache().

void R_FreeImage ( image_t image)

Free the image and its assigned maps (roughness, normal, specular, glow - if there are any)

Parameters
imageThe image that should be freed

Definition at line 735 of file r_image.cpp.

References image_s::glowmap, image_s::normalmap, R_DeleteImage(), image_s::roughnessmap, image_s::specularmap, and image_s::texnum.

Referenced by R_Draw3DGlobe(), and R_FreeWorldImages().

void R_FreeWorldImages ( void  )

Any image that is a mesh or world texture will be removed here.

See also
R_ShutdownImages

Definition at line 757 of file r_image.cpp.

References FOR_EACH_IMAGE, i, imageArray_s::images, it_world, R_CheckError, R_FreeImage(), and image_s::type.

Referenced by CL_Disconnect().

image_t* R_GetImage ( const char *  name)
image_t* R_GetImageAtIndex ( int  i)

Returns an image pointer from the r_images linked list, as if r_images would be a plain contiguous array.

Parameters
iThe image index inside r_images

Definition at line 718 of file r_image.cpp.

References IMAGE_ARRAY_SIZE, imageArray_s::images, imageArray_s::next, and r_numImages.

Referenced by uiMaterialEditorNode::draw(), uiMaterialEditorNode::onMouseDown(), UI_MaterialEditorChangeValue_f(), UI_MaterialEditorNewStage_f(), UI_MaterialEditorNodeGetImageAtPosition(), UI_MaterialEditorNodeGetImageCount(), UI_MaterialEditorRemoveStage_f(), and UI_MaterialEditorSelectStage_f().

int R_GetImageIndex ( image_t imagePtr)

Returns an index of the image pointer in the r_images linked list, as if r_images would be a plain contiguous array.

Parameters
imagePtrThe image pointer

Definition at line 702 of file r_image.cpp.

References IMAGE_ARRAY_SIZE, imageArray_s::images, and imageArray_s::next.

Referenced by R_SortSurfacesArrays(), and R_SortSurfacesArrays_().

void R_GetScaledTextureSize ( int  width,
int  height,
int scaledWidth,
int scaledHeight 
)

Calculates the texture size that should be used to upload the texture data.

Parameters
[in]widthThe width of the source texture data
[in]heightThe heigt of the source texture data
[out]scaledWidthThe resulting width - can be the same as the given width
[out]scaledHeightThe resulting height - can be the same as the given height

Definition at line 220 of file r_image.cpp.

References MAX_TEXTURE_SIZE, rconfig_t::maxTextureSize, and r_config.

Referenced by R_UploadData(), and R_UploadTexture().

void R_ImageClearMaterials ( void  )

Free previously loaded materials and their stages.

See also
R_LoadMaterials

Definition at line 61 of file r_image.cpp.

References defaultMaterial, FOR_EACH_IMAGE, i, imageArray_s::images, m, image_s::material, Mem_Free, materialStage_s::next, and material_s::stages.

Referenced by R_LoadMaterials().

bool R_ImageExists ( const char *  pname,
  ... 
)
void R_InitImages ( void  )
static bool R_IsClampedImageType ( imagetype_t  type)
inlinestatic

Definition at line 241 of file r_image.cpp.

References it_pic, and it_worldrelated.

Referenced by R_ChangeImageType(), R_FindImage(), and R_UploadTexture().

void R_LoadImage ( const char *  name,
byte **  pic,
int width,
int height 
)

Generic image-data loading fucntion.

Parameters
[in]name(Full) pathname to the image to load. Extension (if given) will be ignored.
[out]picImage data.
[out]widthWidth of the loaded image.
[out]heightHeight of the loaded image.
See also
R_FindImage

Definition at line 152 of file r_image.cpp.

References Com_Error(), Com_StripExtension(), ERR_FATAL, Img_LoadImage(), MAX_QPATH, Mem_PoolAllocTypeN, Q_strnull(), and vid_imagePool.

Referenced by GAME_GetImportData().

image_t* R_LoadImageData ( const char *  name,
const byte pic,
int  width,
int  height,
imagetype_t  type 
)

Creates a new image from RGBA data. Stores it in the gltextures array and also uploads it.

Note
This is also used as an entry point for the generated r_noTexture
Parameters
[in]nameThe name of the newly created image
[in]picThe RGBA data of the image
[in]widthThe width of the image (power of two, please)
[in]heightThe height of the image (power of two, please)
[in]typeThe image type
See also
imagetype_t
Todo:
Instead of this hack, unit tests' build should link to the dummy GL driver

Definition at line 475 of file r_image.cpp.

Referenced by uiGeoscapeNode::onLoading(), R_FindImage(), R_InitMiscTexture(), and R_RenderToTexture().

static void R_ReloadImageData ( image_t image)
static
void R_ScaleTexture ( const unsigned *  in,
int  inwidth,
int  inheight,
unsigned *  out,
int  outwidth,
int  outheight 
)

Definition at line 172 of file r_image.cpp.

References i, index, int(), and MAX_TEXTURE_SIZE.

Referenced by R_UploadData(), and R_UploadTexture().

void R_ShutdownImages ( void  )
void R_SoftenTexture ( byte in,
int  width,
int  height,
int  bpp 
)

Applies blurring to a texture.

Definition at line 391 of file r_image.cpp.

References Com_Error(), dest, ERR_FATAL, i, Mem_Free, Mem_PoolAllocTypeN, and vid_imagePool.

Referenced by GAME_GetImportData().

void R_TextureAlphaMode ( const char *  string)
void R_TextureSolidMode ( const char *  string)

Variable Documentation

const gltmode_t gl_alpha_modes[]
static
Initial value:
= {
{"GL_RGBA", GL_RGBA},
{"GL_RGBA8", GL_RGBA8},
{"GL_RGB5_A1", GL_RGB5_A1},
{"GL_RGBA4", GL_RGBA4},
{"GL_RGBA2", GL_RGBA2},
{"GL_LUMINANCE4_ALPHA4", GL_LUMINANCE4_ALPHA4},
{"GL_LUMINANCE6_ALPHA2", GL_LUMINANCE6_ALPHA2},
{"GL_LUMINANCE8_ALPHA8", GL_LUMINANCE8_ALPHA8},
{"GL_LUMINANCE12_ALPHA4", GL_LUMINANCE12_ALPHA4},
{"GL_LUMINANCE12_ALPHA12", GL_LUMINANCE12_ALPHA12},
{"GL_LUMINANCE16_ALPHA16", GL_LUMINANCE16_ALPHA16}
}

Definition at line 916 of file r_image.cpp.

const gltmode_t gl_solid_modes[]
static
Initial value:
= {
{"GL_RGB", GL_RGB},
{"GL_RGB8", GL_RGB8},
{"GL_RGB5", GL_RGB5},
{"GL_RGB4", GL_RGB4},
{"GL_R3_G3_B2", GL_R3_G3_B2},
{"GL_RGB2", GL_RGB2_EXT},
{"GL_RGB4", GL_RGB4_EXT},
{"GL_RGB5", GL_RGB5_EXT},
{"GL_RGB8", GL_RGB8_EXT},
{"GL_RGB10", GL_RGB10_EXT},
{"GL_RGB12", GL_RGB12_EXT},
{"GL_RGB16", GL_RGB16_EXT},
{"GL_LUMINANCE", GL_LUMINANCE},
{"GL_LUMINANCE4", GL_LUMINANCE4},
{"GL_LUMINANCE8", GL_LUMINANCE8},
{"GL_LUMINANCE12", GL_LUMINANCE12},
{"GL_LUMINANCE16", GL_LUMINANCE16}
}

Definition at line 946 of file r_image.cpp.

const glTextureMode_t gl_texture_modes[]
static
Initial value:
= {
{"GL_NEAREST", GL_NEAREST, GL_NEAREST},
{"GL_LINEAR", GL_LINEAR, GL_LINEAR},
{"GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST},
{"GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR},
{"GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST},
{"GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR}
}

Definition at line 860 of file r_image.cpp.

image_t* imageHash[MAX_IMAGEHASH]
static

Definition at line 32 of file r_image.cpp.

image_t* r_envmaptextures[MAX_ENVMAPTEXTURES]

Definition at line 50 of file r_image.cpp.

Referenced by R_DrawMeshModelShell(), and R_ParseStage().

image_t* r_flaretextures[NUM_FLARETEXTURES]

Definition at line 53 of file r_image.cpp.

Referenced by R_DrawFlareSurfaces(), and R_ParseStage().

imageArray_t r_images

Definition at line 40 of file r_image.cpp.