29 #include "../../shared/parse.h"
36 #define UPDATE_THRESHOLD 0.02
50 float moduloPhase = phase - floor(phase);
52 if (moduloPhase < s->pulse.dutycycle) {
53 moduloPhase /= s->pulse.dutycycle;
54 s->pulse.dhz = (1.0 - cos(moduloPhase * (2 *
M_PI))) / 2.0;
61 s->stretch.dhz = (1.0 - cos(
refdef.
time * s->stretch.hz * (2 *
M_PI)) ) / 2.0;
62 s->stretch.damp = 1.5 - s->stretch.dhz * s->stretch.amp;
66 s->rotate.deg =
refdef.
time * s->rotate.hz * 360.0;
77 s->anim.dtime =
refdef.
time + (1.0 / s->anim.fps);
79 switch (s->anim.type) {
81 frame = s->anim.dframe % s->anim.num_frames;
84 frame = abs(s->anim.dframe % (s->anim.num_frames + 1) - (s->anim.num_frames / 2));
87 frame = s->anim.num_frames - 1;
88 frame -= s->anim.dframe % s->anim.num_frames;
91 frame = rand() % s->anim.num_frames;
94 frame = rand() % s->anim.num_frames;
95 if (s->image == s->anim.images[frame])
96 frame = (frame + 1) % s->anim.num_frames;
102 assert(frame < s->anim.num_frames);
103 s->image = s->anim.images[frame];
114 glowmap = stage->
image;
173 static bool identity =
true;
190 glTranslatef(-s, -t, 0.0);
192 glTranslatef(-s, -t, 0.0);
196 glTranslatef(-s, -t, 0.0);
197 glRotatef(stage->
rotate.
deg, 0.0, 0.0, 1.0);
198 glTranslatef(-s, -t, 0.0);
202 glScalef(stage->
scale.
s, 1.0, 1.0);
205 glScalef(1.0, stage->
scale.
t, 1.0);
208 glTranslatef(stage->
scroll.
ds, 0.0, 0.0);
211 glTranslatef(0.0, stage->
scroll.
dt, 0.0);
233 0.6, 0.5, 0.3, 0.4, 0.7, 0.3, 0.0, 0.4,
234 0.5, 0.2, 0.8, 0.5, 0.3, 0.2, 0.5, 0.3
261 const float delta = v[2] - stage->
tape.
center;
262 a = 1 - (delta / stage->
tape.
max);
264 const float delta = stage->
tape.
center - v[2];
265 a = 1 - (delta / stage->
tape.
min);
275 const vec3_t hash_mult = {1.3, 3.1, 7.3};
357 for (i = 0; i < surf->
numedges; i++) {
386 glDrawArrays(GL_TRIANGLE_FAN, 0, i);
422 #ifndef GL_VERSION_ES_CM_1_0
423 glEnable(GL_POLYGON_OFFSET_FILL);
425 glPolygonOffset(-1.
f, -1.
f);
427 glMatrixMode(GL_TEXTURE);
429 for (
int i = 0;
i < surfs->
count;
i++) {
452 glPolygonOffset(0.0, 0.0);
453 #ifndef GL_VERSION_ES_CM_1_0
454 glDisable(GL_POLYGON_OFFSET_FILL);
458 glMatrixMode(GL_MODELVIEW);
486 if (
Q_streq(c,
"GL_SRC_ALPHA"))
488 if (
Q_streq(c,
"GL_ONE_MINUS_SRC_ALPHA"))
489 return GL_ONE_MINUS_SRC_ALPHA;
490 if (
Q_streq(c,
"GL_SRC_COLOR"))
492 if (
Q_streq(c,
"GL_DST_COLOR"))
494 if (
Q_streq(c,
"GL_ONE_MINUS_SRC_COLOR"))
495 return GL_ONE_MINUS_SRC_COLOR;
496 if (
Q_streq(c,
"GL_ONE_MINUS_DST_COLOR"))
497 return GL_ONE_MINUS_DST_COLOR;
499 Com_Printf(
"R_ConstByName: Failed to resolve: %s\n", c);
526 Com_Printf(
"R_LoadAnimImages: Texture not defined in anim stage.\n");
532 int j = strlen(name);
534 if (name[j - 1] !=
'0') {
535 Com_Printf(
"R_LoadAnimImages: Texture name does not end in 0: %s\n", name);
547 const char* c =
va(
"%s%d", name,
i);
551 Com_Printf(
"R_LoadAnimImages: Failed to resolve texture: %s\n", c);
576 Com_Printf(
"R_LoadMaterials: Invalid glowscale value for %s\n", c);
587 Com_Printf(
"R_ParseStage: Failed to resolve texture: %s\n", c);
605 Com_Printf(
"R_ParseStage: Failed to resolve envmap: %s\n", c);
618 Com_Printf(
"R_ParseStage: Failed to resolve blend src: %s\n", c);
626 Com_Printf(
"R_ParseStage: Failed to resolve blend dest: %s\n", c);
635 for (i = 0; i < 3; i++) {
640 Com_Printf(
"R_ParseStage: Failed to resolve color: %s\n", c);
655 Com_Printf(
"R_ParseStage: Failed to resolve frequency: %s\n", c);
668 Com_Printf(
"R_ParseStage: Failed to resolve pulse duty cycle: %s\n", c);
680 Com_Printf(
"R_ParseStage: Failed to resolve amplitude: %s\n", c);
688 Com_Printf(
"R_ParseStage: Failed to resolve frequency: %s\n", c);
701 Com_Printf(
"R_ParseStage: Failed to resolve rotate: %s\n", c);
748 Com_Printf(
"R_ParseStage: Inverted terrain ceiling and floor "
756 Com_Printf(
"R_ParseStage: Zero height terrain specified for %s\n",
782 Com_Printf(
"R_ParseStage: Zero height tape specified for %s\n",
795 Com_Printf(
"R_ParseStage: Invalid dirtmap intensity for %s\n",
803 if (
char const*
const rest =
Q_strstart(c,
"anim")) {
825 Com_Printf(
"R_ParseStage: Invalid number of anim frames for %s (max is %i)\n",
834 Com_Printf(
"R_ParseStage: Invalid anim fps for %s\n",
845 if (
Q_streq(c,
"glowmaplink")) {
865 Com_Printf(
"R_ParseStage: Failed to resolve flare: %s\n", c);
878 " color: %3f %3f %3f\n"
880 " pulse duty cycle: %1.2f\n"
881 " stretch: %3f %3f\n"
887 " terrain.floor: %5f\n"
888 " terrain.ceil: %5f\n"
889 " anim.num_frames: %d\n"
912 Com_Printf(
"R_ParseStage: Malformed stage\n");
929 if (map[0] ==
'+' || map[0] ==
'-')
931 else if (map[0] ==
'-')
943 Com_Printf(
"load material file: '%s'\n", path);
945 Com_Printf(
"...ignore materials (r_materials is deactivated)\n");
948 const char* buffer = (
const char*)fileBuffer;
950 bool inmaterial =
false;
960 if (*c ==
'{' && !inmaterial) {
968 if (image ==
nullptr)
984 Com_Printf(
"R_LoadMaterials: Failed to resolve normalmap: %s\n", c);
994 Com_Printf(
"R_LoadMaterials: Failed to resolve glowmap: %s\n", c);
1001 if (m->
bump < 0.0) {
1002 Com_Printf(
"R_LoadMaterials: Invalid bump value for %s\n", image->
name);
1010 Com_Printf(
"R_LoadMaterials: Invalid parallax value for %s\n", image->
name);
1018 Com_Printf(
"R_LoadMaterials: Invalid hardness value for %s\n", image->
name);
1026 Com_Printf(
"R_LoadMaterials: Invalid specular value for %s\n", image->
name);
1031 if (
Q_streq(c,
"glowscale")) {
1034 Com_Printf(
"R_LoadMaterials: Invalid glowscale value for %s\n", image->
name);
1039 if (*c ==
'{' && inmaterial) {
1071 if (*c ==
'}' && inmaterial) {
#define VectorCopy(src, dest)
void R_EnableTexture(gltexunit_t *texunit, bool enable)
void R_EnableBumpmap(const image_t *normalmap)
Enables bumpmapping and binds the given normalmap.
#define VectorSet(v, x, y, z)
cvar_t * r_default_specular
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.
const char * Com_SkipPath(const char *pathname)
Returns just the filename from a given path.
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
void R_CreateSurfaceFlare(mBspSurface_t *surf)
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.
model_t * r_mapTiles[MAX_MAPTILES]
The world model(s)
void R_BindLightmapTexture(GLuint texnum)
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
GLfloat * vertex_array_3d
static void R_CreateMaterialData(void)
void R_BlendFunc(GLenum src, GLenum dest)
surfaces are assigned to arrays based on their primary rendering type and then sorted by world textur...
static void R_StageTextureMatrix(const mBspSurface_t *surf, const materialStage_t *stage)
Manages texture matrix manipulations for stages supporting rotations, scrolls, and stretches (rotate...
local graphics definitions
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.
static void R_SetSurfaceStageState(const mBspSurface_t *surf, const materialStage_t *stage)
Manages all state for the specified surface and stage.
static const float dirtmap[]
Array with 'random' alpha values for the dirtmap.
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
void Com_Printf(const char *const fmt,...)
image_t * r_envmaptextures[MAX_ENVMAPTEXTURES]
void VectorNormalizeFast(vec3_t v)
fast vector normalize routine that does not check to make sure that length != 0, nor does it return l...
void R_UpdateDefaultMaterial(const char *cvarName, const char *oldValue, const char *newValue, void *data)
Change listener callback for material value cvars.
model_t r_modelsInline[MAX_MOD_KNOWN]
const GLuint *typedef GLuint *typedef GLenum
static void R_UpdateMaterial(material_t *m)
Materials "think" every few milliseconds to advance animations.
#define DEFAULT_GLOWSCALE
#define Q_strvalid(string)
void R_SetSurfaceBumpMappingParameters(const mBspSurface_t *surf, const image_t *normalMap, const image_t *specularMap)
void R_Color(const vec4_t rgba)
Change the color to given value.
image_t * R_FindImage(const char *pname, imagetype_t type)
Finds or loads the given image.
static void R_StageVertex(const mBspSurface_t *surf, const materialStage_t *stage, const vec3_t in, vec3_t out)
Vertex deformation.
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
#define STAGE_TEXTURE_MATRIX
#define DotProduct(x, y)
Returns the distance between two 3-dimensional vectors.
cvar_t * r_default_hardness
void R_ImageClearMaterials(void)
Free previously loaded materials and their stages.
void R_ReallocateTexunitArray(gltexunit_t *texunit, int size)
Reallocate texcoord array of the specified texunit, if needed.
#define Vector4Set(v, r, g, b, a)
mBspSurface_t ** surfaces
#define MAX_ENVMAPTEXTURES
#define NUM_FLARETEXTURES
void R_ResetArrayState(void)
void R_EnableColorArray(bool enable)
struct image_s * images[MAX_ANIM_FRAMES]
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
static int R_LoadAnimImages(materialStage_t *s)
material_t defaultMaterial
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
struct image_s * specularmap
static void R_CreateMaterialData_(model_t *mod)
void R_DrawMaterialSurfaces(const mBspSurfaces_t *surfs, glElementIndex_t *indexPtr)
Iterates the specified surfaces list, updating materials as they are encountered, and rendering all v...
cvar_t * r_overridematerial
const char * Com_Parse(const char *data_p[], char *target, size_t size, bool replaceWhitespaces)
Parse a token out of a string.
r_program_t * world_program
image_t * r_flaretextures[NUM_FLARETEXTURES]
mBspSurfaces_t r_material_surfaces
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
static GLenum R_ConstByName(const char *c)
Translate string into glmode.
#define Vector2Copy(src, dest)
memPool_t * vid_imagePool
bool R_EnableLighting(r_program_t *program, bool enable)
Enables hardware-accelerated lighting with the specified program. This should be called after any tex...
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.
GLsizei const GLvoid * data
struct image_s * normalmap
#define Mem_PoolAllocType(type, pool)
#define STAGE_GLOWMAPLINK
void R_ReallocateStateArrays(int size)
Reallocate arrays of GL primitives if needed.
image_t * R_GetImage(const char *name)
QGL_EXTERN int GLboolean GLfloat * v
void R_ProgramParameter1f(const char *name, GLfloat value)
static void R_StageLighting(const mBspSurface_t *surf, const materialStage_t *stage)
Manages state for stages supporting static, dynamic, and per-pixel lighting.
void R_EnableModelLights(const light_t **lights, int numLights, bool inShadow, bool enable)
Enable or disable realtime dynamic lighting for models.
#define VectorSubtract(a, b, dest)
static void R_StageGlow(const materialStage_t *stage)
#define R_BindTexture(tn)
const struct image_s * active_normalmap
void R_EnableGlowMap(const image_t *image)
void R_EnableFog(bool enable)
struct materialStage_s * next
void FS_FreeFile(void *buffer)