Material related code. More...
#include "r_local.h"
#include "r_error.h"
#include "r_lightmap.h"
#include "../../shared/parse.h"
Go to the source code of this file.
Defines | |
#define | UPDATE_THRESHOLD 0.02 |
Functions | |
static void | R_UpdateMaterial (material_t *m) |
Materials "think" every few milliseconds to advance animations. | |
static void | R_StageGlow (const materialStage_t *stage) |
static void | R_StageLighting (const mBspSurface_t *surf, const materialStage_t *stage) |
Manages state for stages supporting static, dynamic, and per-pixel lighting. | |
static void | R_StageVertex (const mBspSurface_t *surf, const materialStage_t *stage, const vec3_t in, vec3_t out) |
Vertex deformation. | |
static void | R_StageTextureMatrix (const mBspSurface_t *surf, const materialStage_t *stage) |
Manages texture matrix manipulations for stages supporting rotations, scrolls, and stretches (rotate, translate, scale). | |
static void | R_StageTexCoord (const materialStage_t *stage, const vec3_t v, const vec2_t in, vec2_t out) |
Generates a single texture coordinate for the specified stage and vertex. | |
static void | R_StageColor (const materialStage_t *stage, const vec3_t v, vec4_t color) |
Generates a single color for the specified stage and vertex. | |
static void | R_SetSurfaceStageState (const mBspSurface_t *surf, const materialStage_t *stage) |
Manages all state for the specified surface and stage. | |
static void | R_DrawSurfaceStage (mBspSurface_t *surf, materialStage_t *stage) |
Render the specified stage for the surface. Resolve vertex attributes via helper functions, outputting to the default vertex arrays. | |
void | R_DrawMaterialSurfaces (mBspSurfaces_t *surfs) |
Iterates the specified surfaces list, updating materials as they are encountered, and rendering all visible stages. State is lazily managed throughout the iteration, so there is a concerted effort to restore the state after all surface stages have been rendered. | |
static GLenum | R_ConstByName (const char *c) |
Translate string into glmode. | |
static void | R_CreateMaterialData_ (model_t *mod) |
static void | R_CreateMaterialData (void) |
static int | R_LoadAnimImages (materialStage_t *s) |
static int | R_ParseStage (materialStage_t *s, const char **buffer) |
Material stage parser. | |
void | R_LoadMaterials (const char *map) |
Load material definitions for each map that has one. | |
Variables | |
mBspSurfaces_t | r_material_surfaces |
static const float | dirtmap [] |
Array with 'random' alpha values for the dirtmap. |
Material related code.
Definition in file r_material.c.
#define UPDATE_THRESHOLD 0.02 |
Definition at line 33 of file r_material.c.
Referenced by R_UpdateMaterial().
static GLenum R_ConstByName | ( | const char * | c | ) | [static] |
Translate string into glmode.
Definition at line 456 of file r_material.c.
References Com_Printf().
Referenced by R_ParseStage().
static void R_CreateMaterialData | ( | void | ) | [static] |
Definition at line 490 of file r_material.c.
References i, R_CreateMaterialData_(), r_mapTiles, r_modelsInline, r_numMapTiles, and r_numModelsInline.
Referenced by R_LoadMaterials().
static void R_CreateMaterialData_ | ( | model_t * | mod | ) | [static] |
Definition at line 479 of file r_material.c.
References model_s::bsp, i, mBspModel_s::numsurfaces, R_CreateSurfaceFlare(), and mBspModel_s::surfaces.
Referenced by R_CreateMaterialData().
void R_DrawMaterialSurfaces | ( | mBspSurfaces_t * | surfs | ) |
Iterates the specified surfaces list, updating materials as they are encountered, and rendering all visible stages. State is lazily managed throughout the iteration, so there is a concerted effort to restore the state after all surface stages have been rendered.
Definition at line 372 of file r_material.c.
References rstate_t::blend_enabled, mBspSurfaces_s::count, f, materialStage_s::flags, rlocals_s::frame, mBspSurface_s::frame, i, mBspTexInfo_s::image, cvar_s::integer, m, image_s::material, materialStage_s::next, qfalse, qtrue, R_BlendFunc(), R_Color(), R_DrawSurfaceStage(), R_EnableBumpmap(), R_EnableColorArray(), R_EnableDynamicLights(), R_EnableFog(), R_EnableGlowMap(), R_EnableLighting(), R_EnableTexture(), r_locals, r_materials, R_ResetArrayState(), R_SetSurfaceStageState(), r_state, R_UpdateMaterial(), r_wire, STAGE_RENDER, material_s::stages, mBspSurfaces_s::surfaces, mBspSurface_s::texinfo, texunit_lightmap, and rstate_t::world_program.
Referenced by R_DrawBspModelSurfaces(), and R_RenderFrame().
static void R_DrawSurfaceStage | ( | mBspSurface_t * | surf, | |
materialStage_t * | stage | |||
) | [static] |
Render the specified stage for the surface. Resolve vertex attributes via helper functions, outputting to the default vertex arrays.
Definition at line 325 of file r_material.c.
References model_s::bsp, rstate_t::bumpmap_enabled, rstate_t::color_array, rstate_t::color_array_enabled, Com_Error(), ERR_DROP, i, mBspSurface_s::index, rstate_t::lighting_enabled, mBspModel_s::lmtexcoords, MAX_GL_ARRAY_LENGTH, rstate_t::normal_array, mBspModel_s::normals, mBspSurface_s::numedges, R_CheckError, r_mapTiles, R_StageColor(), R_StageTexCoord(), R_StageVertex(), r_state, st, rstate_t::tangent_array, mBspModel_s::tangents, mBspModel_s::texcoords, texunit_diffuse, texunit_lightmap, mBspSurface_s::tile, rstate_t::vertex_array_3d, and mBspModel_s::verts.
Referenced by R_DrawMaterialSurfaces().
static int R_LoadAnimImages | ( | materialStage_t * | s | ) | [static] |
Definition at line 501 of file r_material.c.
References materialStage_s::anim, Com_Printf(), materialStage_s::flags, image_s::glowmap, i, materialStage_s::image, anim_s::images, it_material, MAX_QPATH, image_s::name, name, anim_s::num_frames, Q_strncpyz(), R_FindImage(), r_noTexture, STAGE_GLOWMAPLINK, and va().
Referenced by R_LoadMaterials().
void R_LoadMaterials | ( | const char * | map | ) |
Load material definitions for each map that has one.
[in] | map | the base name of the map to load the material for |
Definition at line 891 of file r_material.c.
References material_s::bump, byte, Com_DPrintf(), Com_Parse(), Com_Printf(), Com_SkipPath(), Com_sprintf(), DEBUG_RENDERER, DEFAULT_BUMP, DEFAULT_GLOWSCALE, DEFAULT_HARDNESS, DEFAULT_PARALLAX, DEFAULT_SPECULAR, material_s::flags, materialStage_s::flags, FS_FreeFile(), FS_LoadFile(), image_s::glowmap, materialStage_s::glowscale, material_s::glowscale, material_s::hardness, it_glowmap, it_normalmap, m, image_s::material, MAX_QPATH, Mem_Free, Mem_PoolAlloc, image_s::name, materialStage_s::next, image_s::normalmap, material_s::num_stages, material_s::parallax, qfalse, qtrue, R_CreateMaterialData(), R_FindImage(), R_GetImage(), R_ImageClearMaterials(), R_LoadAnimImages(), r_noTexture, R_ParseStage(), material_s::specular, STAGE_ANIM, material_s::stages, va(), and vid_imagePool.
Referenced by R_ModEndLoading().
static int R_ParseStage | ( | materialStage_t * | s, | |
const char ** | buffer | |||
) | [static] |
Material stage parser.
Definition at line 548 of file r_material.c.
References stretch_s::amp, materialStage_s::anim, ANIM_ALTERNATE, ANIM_BACKWARDS, ANIM_NORMAL, ANIM_RANDOM, ANIM_RANDOMFORCE, materialStage_s::blend, tape_s::ceil, terrain_s::ceil, tape_s::center, materialStage_s::color, Com_DPrintf(), Com_Parse(), Com_Printf(), DEBUG_RENDERER, DEFAULT_GLOWSCALE, blendmode_s::dest, materialStage_s::dirt, materialStage_s::flags, tape_s::floor, terrain_s::floor, anim_s::fps, materialStage_s::glowscale, tape_s::height, terrain_s::height, rotate_s::hz, stretch_s::hz, pulse_s::hz, i, materialStage_s::image, dirt_s::intensity, it_material, tape_s::max, MAX_ANIM_FRAMES, MAX_ENVMAPTEXTURES, tape_s::min, image_s::name, NUM_FLARETEXTURES, anim_s::num_frames, materialStage_s::pulse, qtrue, R_ConstByName(), r_envmaptextures, R_FindImage(), r_flaretextures, r_noTexture, materialStage_s::rotate, scale_s::s, scroll_s::s, materialStage_s::scale, materialStage_s::scroll, blendmode_s::src, STAGE_ANIM, STAGE_BLEND, STAGE_COLOR, STAGE_DIRTMAP, STAGE_ENVMAP, STAGE_FLARE, STAGE_GLOWMAPLINK, STAGE_LIGHTING, STAGE_LIGHTMAP, STAGE_PULSE, STAGE_RENDER, STAGE_ROTATE, STAGE_SCALE_S, STAGE_SCALE_T, STAGE_SCROLL_S, STAGE_SCROLL_T, STAGE_STRETCH, STAGE_TAPE, STAGE_TERRAIN, STAGE_TEXTURE, materialStage_s::stretch, scale_s::t, scroll_s::t, materialStage_s::tape, materialStage_s::terrain, anim_s::type, and va().
Referenced by R_LoadMaterials().
static void R_SetSurfaceStageState | ( | const mBspSurface_t * | surf, | |
const materialStage_t * | stage | |||
) | [static] |
Manages all state for the specified surface and stage.
Definition at line 268 of file r_material.c.
References materialStage_s::blend, mBspSurface_s::color, materialStage_s::color, rstate_t::color_array_enabled, blendmode_s::dest, pulse_s::dhz, materialStage_s::flags, materialStage_s::image, materialStage_s::pulse, qfalse, qtrue, R_BindTexture, R_BlendFunc(), R_Color(), R_EnableColorArray(), R_EnableFog(), R_StageGlow(), R_StageLighting(), R_StageTextureMatrix(), r_state, blendmode_s::src, STAGE_BLEND, STAGE_COLOR, STAGE_DIRTMAP, STAGE_ENVMAP, STAGE_PULSE, STAGE_TAPE, STAGE_TERRAIN, image_s::texnum, VectorCopy, and VectorSet.
Referenced by R_DrawMaterialSurfaces().
static void R_StageColor | ( | const materialStage_t * | stage, | |
const vec3_t | v, | |||
vec4_t | color | |||
) | [static] |
Generates a single color for the specified stage and vertex.
Definition at line 217 of file r_material.c.
References terrain_s::ceil, tape_s::center, materialStage_s::color, materialStage_s::dirt, dirtmap, materialStage_s::flags, terrain_s::floor, terrain_s::height, int(), dirt_s::intensity, lengthof, tape_s::max, tape_s::min, STAGE_COLOR, STAGE_DIRTMAP, STAGE_TAPE, STAGE_TERRAIN, materialStage_s::tape, materialStage_s::terrain, Vector4Set, VectorCopy, VectorLength(), and VectorSet.
Referenced by R_DrawSurfaceStage().
static void R_StageGlow | ( | const materialStage_t * | stage | ) | [static] |
Definition at line 97 of file r_material.c.
References image_s::glowmap, rstate_t::glowmap_enabled, materialStage_s::glowscale, materialStage_s::image, qfalse, qtrue, R_EnableGlowMap(), R_ProgramParameter1f(), and r_state.
Referenced by R_SetSurfaceStageState().
static void R_StageLighting | ( | const mBspSurface_t * | surf, | |
const materialStage_t * | stage | |||
) | [static] |
Manages state for stages supporting static, dynamic, and per-pixel lighting.
Definition at line 111 of file r_material.c.
References materialStage_s::flags, mBspSurface_s::flags, materialStage_s::image, mBspSurface_s::lightmap_texnum, MSURF_LIGHTMAP, image_s::normalmap, qfalse, qtrue, R_BindLightmapTexture(), R_EnableLighting(), R_EnableTexture(), R_SetSurfaceBumpMappingParameters(), r_state, STAGE_LIGHTING, STAGE_LIGHTMAP, texunit_lightmap, and rstate_t::world_program.
Referenced by R_SetSurfaceStageState().
static void R_StageTexCoord | ( | const materialStage_t * | stage, | |
const vec3_t | v, | |||
const vec2_t | in, | |||
vec2_t | out | |||
) | [static] |
Generates a single texture coordinate for the specified stage and vertex.
Definition at line 195 of file r_material.c.
References materialStage_s::flags, refdef, STAGE_ENVMAP, Vector2Copy, VectorNormalize(), VectorSubtract, and rendererData_t::viewOrigin.
Referenced by R_DrawSurfaceStage().
static void R_StageTextureMatrix | ( | const mBspSurface_t * | surf, | |
const materialStage_t * | stage | |||
) | [inline, static] |
Manages texture matrix manipulations for stages supporting rotations, scrolls, and stretches (rotate, translate, scale).
Definition at line 147 of file r_material.c.
References stretch_s::damp, rotate_s::deg, scroll_s::ds, scroll_s::dt, materialStage_s::flags, image_s::height, mBspTexInfo_s::image, qfalse, qtrue, materialStage_s::rotate, scale_s::s, materialStage_s::scale, materialStage_s::scroll, STAGE_ROTATE, STAGE_SCALE_S, STAGE_SCALE_T, STAGE_SCROLL_S, STAGE_SCROLL_T, STAGE_STRETCH, STAGE_TEXTURE_MATRIX, mBspSurface_s::stcenter, materialStage_s::stretch, scale_s::t, mBspSurface_s::texinfo, and image_s::width.
Referenced by R_SetSurfaceStageState().
static void R_StageVertex | ( | const mBspSurface_t * | surf, | |
const materialStage_t * | stage, | |||
const vec3_t | in, | |||
vec3_t | out | |||
) | [inline, static] |
Vertex deformation.
Definition at line 138 of file r_material.c.
References VectorCopy.
Referenced by R_DrawSurfaceStage().
static void R_UpdateMaterial | ( | material_t * | m | ) | [static] |
Materials "think" every few milliseconds to advance animations.
Definition at line 37 of file r_material.c.
References stretch_s::amp, materialStage_s::anim, ANIM_ALTERNATE, ANIM_BACKWARDS, ANIM_NORMAL, ANIM_RANDOM, ANIM_RANDOMFORCE, stretch_s::damp, rotate_s::deg, anim_s::dframe, stretch_s::dhz, pulse_s::dhz, scroll_s::ds, scroll_s::dt, anim_s::dtime, materialStage_s::flags, anim_s::fps, rotate_s::hz, stretch_s::hz, pulse_s::hz, materialStage_s::image, anim_s::images, materialStage_s::next, anim_s::num_frames, materialStage_s::pulse, refdef, materialStage_s::rotate, scroll_s::s, materialStage_s::scroll, STAGE_ANIM, STAGE_PULSE, STAGE_ROTATE, STAGE_SCROLL_S, STAGE_SCROLL_T, STAGE_STRETCH, material_s::stages, materialStage_s::stretch, scroll_s::t, material_s::time, rendererData_t::time, anim_s::type, and UPDATE_THRESHOLD.
Referenced by R_DrawMaterialSurfaces().
const float dirtmap[] [static] |
{ 0.6, 0.5, 0.3, 0.4, 0.7, 0.3, 0.0, 0.4, 0.5, 0.2, 0.8, 0.5, 0.3, 0.2, 0.5, 0.3 }
Array with 'random' alpha values for the dirtmap.
Definition at line 209 of file r_material.c.
Referenced by R_StageColor().
Definition at line 31 of file r_material.c.