mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-24 04:31:35 +00:00
[gl] Use a struct for glpoly_t's vertices
I always hated the float array for the different attributes.
This commit is contained in:
parent
bc9e85e429
commit
2203e2b4fd
6 changed files with 89 additions and 109 deletions
|
@ -117,13 +117,17 @@ typedef struct {
|
|||
texture_t *texture;
|
||||
} mtexinfo_t;
|
||||
|
||||
#define VERTEXSIZE 7
|
||||
typedef struct glvert_s {
|
||||
float pos[3];
|
||||
float tex_uv[2];
|
||||
float lm_uv[2];
|
||||
} glvert_t;
|
||||
|
||||
typedef struct glpoly_s {
|
||||
struct glpoly_s *next;
|
||||
int numverts;
|
||||
int flags; // for SURF_UNDERWATER
|
||||
float verts[4][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2)
|
||||
struct glpoly_s *next;
|
||||
int numverts;
|
||||
int flags; // for SURF_UNDERWATER
|
||||
glvert_t verts[4]; // variable
|
||||
} glpoly_t;
|
||||
|
||||
#define MAX_DLIGHTS 128
|
||||
|
|
|
@ -280,17 +280,16 @@ SubdividePolygon (int numverts, float *verts)
|
|||
return;
|
||||
}
|
||||
|
||||
poly = Hunk_Alloc (0, sizeof (glpoly_t) + (numverts - 4) * VERTEXSIZE *
|
||||
sizeof (float));
|
||||
poly = Hunk_Alloc (0, field_offset (glpoly_t, verts[numverts]));
|
||||
poly->next = warpface->polys;
|
||||
warpface->polys = poly;
|
||||
poly->numverts = numverts;
|
||||
for (i = 0; i < numverts; i++, verts += 3) {
|
||||
VectorCopy (verts, poly->verts[i]);
|
||||
VectorCopy (verts, poly->verts[i].pos);
|
||||
s = DotProduct (verts, warpface->texinfo->vecs[0]);
|
||||
t = DotProduct (verts, warpface->texinfo->vecs[1]);
|
||||
poly->verts[i][3] = s;
|
||||
poly->verts[i][4] = t;
|
||||
poly->verts[i].tex_uv[0] = s;
|
||||
poly->verts[i].tex_uv[1] = t;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -432,7 +432,6 @@ R_BuildLightMap_4 (const vec4f_t *transform, mod_brush_t *brush,
|
|||
void
|
||||
gl_R_BlendLightmaps (void)
|
||||
{
|
||||
float *v;
|
||||
instsurf_t *sc;
|
||||
glpoly_t *p;
|
||||
|
||||
|
@ -447,10 +446,10 @@ gl_R_BlendLightmaps (void)
|
|||
}
|
||||
for (p = sc->surface->polys; p; p = p->next) {
|
||||
qfglBegin (GL_POLYGON);
|
||||
v = p->verts[0];
|
||||
for (int j = 0; j < p->numverts; j++, v += VERTEXSIZE) {
|
||||
qfglTexCoord2fv (&v[5]);
|
||||
qfglVertex3fv (v);
|
||||
auto v = p->verts;
|
||||
for (int j = 0; j < p->numverts; j++, v++) {
|
||||
qfglTexCoord2fv (v->lm_uv);
|
||||
qfglVertex3fv (v->pos);
|
||||
}
|
||||
qfglEnd ();
|
||||
}
|
||||
|
|
|
@ -183,13 +183,11 @@ gl_R_ClearTextures (void)
|
|||
static void
|
||||
R_RenderFullbrights (void)
|
||||
{
|
||||
float *v;
|
||||
int i, j;
|
||||
glpoly_t *p;
|
||||
instsurf_t *sc;
|
||||
gltex_t *tex;
|
||||
|
||||
for (i = 0; i < r_num_texture_chains; i++) {
|
||||
for (int i = 0; i < r_num_texture_chains; i++) {
|
||||
if (!(tex = r_texture_chains[i]) || !tex->gl_fb_texturenum)
|
||||
continue;
|
||||
qfglBindTexture (GL_TEXTURE_2D, tex->gl_fb_texturenum);
|
||||
|
@ -202,11 +200,11 @@ R_RenderFullbrights (void)
|
|||
qfglColor4fv (sc->color);
|
||||
for (p = sc->surface->polys; p; p = p->next) {
|
||||
qfglBegin (GL_POLYGON);
|
||||
for (j = 0, v = p->verts[0]; j < p->numverts;
|
||||
j++, v += VERTEXSIZE)
|
||||
auto v = p->verts;
|
||||
for (int j = 0; j < p->numverts; j++, v++)
|
||||
{
|
||||
qfglTexCoord2fv (&v[3]);
|
||||
qfglVertex3fv (v);
|
||||
qfglTexCoord2fv (v->tex_uv);
|
||||
qfglVertex3fv (v->pos);
|
||||
}
|
||||
qfglEnd ();
|
||||
}
|
||||
|
@ -221,19 +219,15 @@ R_RenderFullbrights (void)
|
|||
static inline void
|
||||
R_RenderBrushPoly_3 (msurface_t *surf)
|
||||
{
|
||||
float *v;
|
||||
int i;
|
||||
|
||||
gl_ctx->brush_polys++;
|
||||
|
||||
qfglBegin (GL_POLYGON);
|
||||
v = surf->polys->verts[0];
|
||||
|
||||
for (i = 0; i < surf->polys->numverts; i++, v += VERTEXSIZE) {
|
||||
qglMultiTexCoord2fv (gl_mtex_enum + 0, &v[3]);
|
||||
qglMultiTexCoord2fv (gl_mtex_enum + 1, &v[5]);
|
||||
qglMultiTexCoord2fv (gl_mtex_enum + 2, &v[3]);
|
||||
qfglVertex3fv (v);
|
||||
auto v = surf->polys->verts;
|
||||
for (int i = 0; i < surf->polys->numverts; i++, v++) {
|
||||
qglMultiTexCoord2fv (gl_mtex_enum + 0, v->tex_uv);
|
||||
qglMultiTexCoord2fv (gl_mtex_enum + 1, v->lm_uv);
|
||||
qglMultiTexCoord2fv (gl_mtex_enum + 2, v->tex_uv);
|
||||
qfglVertex3fv (v->pos);
|
||||
}
|
||||
|
||||
qfglEnd ();
|
||||
|
@ -242,18 +236,14 @@ R_RenderBrushPoly_3 (msurface_t *surf)
|
|||
static inline void
|
||||
R_RenderBrushPoly_2 (msurface_t *surf)
|
||||
{
|
||||
float *v;
|
||||
int i;
|
||||
|
||||
gl_ctx->brush_polys++;
|
||||
|
||||
qfglBegin (GL_POLYGON);
|
||||
v = surf->polys->verts[0];
|
||||
|
||||
for (i = 0; i < surf->polys->numverts; i++, v += VERTEXSIZE) {
|
||||
qglMultiTexCoord2fv (gl_mtex_enum + 0, &v[3]);
|
||||
qglMultiTexCoord2fv (gl_mtex_enum + 1, &v[5]);
|
||||
qfglVertex3fv (v);
|
||||
auto v = surf->polys->verts;
|
||||
for (int i = 0; i < surf->polys->numverts; i++, v++) {
|
||||
qglMultiTexCoord2fv (gl_mtex_enum + 0, v->tex_uv);
|
||||
qglMultiTexCoord2fv (gl_mtex_enum + 1, v->lm_uv);
|
||||
qfglVertex3fv (v->pos);
|
||||
}
|
||||
|
||||
qfglEnd ();
|
||||
|
@ -262,17 +252,13 @@ R_RenderBrushPoly_2 (msurface_t *surf)
|
|||
static inline void
|
||||
R_RenderBrushPoly_1 (msurface_t *surf)
|
||||
{
|
||||
float *v;
|
||||
int i;
|
||||
|
||||
gl_ctx->brush_polys++;
|
||||
|
||||
qfglBegin (GL_POLYGON);
|
||||
v = surf->polys->verts[0];
|
||||
|
||||
for (i = 0; i < surf->polys->numverts; i++, v += VERTEXSIZE) {
|
||||
qfglTexCoord2fv (&v[3]);
|
||||
qfglVertex3fv (v);
|
||||
auto v = surf->polys->verts;
|
||||
for (int i = 0; i < surf->polys->numverts; i++, v++) {
|
||||
qfglTexCoord2fv (v->tex_uv);
|
||||
qfglVertex3fv (v->pos);
|
||||
}
|
||||
|
||||
qfglEnd ();
|
||||
|
@ -820,8 +806,7 @@ GL_BuildSurfaceDisplayList (mod_brush_t *brush, msurface_t *surf)
|
|||
lnumverts = surf->numedges;
|
||||
|
||||
// draw texture
|
||||
poly = Hunk_Alloc (0, sizeof (glpoly_t) + (lnumverts - 4) *
|
||||
VERTEXSIZE * sizeof (float));
|
||||
poly = Hunk_Alloc (0, field_offset (glpoly_t, verts[lnumverts]));
|
||||
poly->next = surf->polys;
|
||||
poly->flags = surf->flags;
|
||||
surf->polys = poly;
|
||||
|
@ -844,9 +829,9 @@ GL_BuildSurfaceDisplayList (mod_brush_t *brush, msurface_t *surf)
|
|||
t = DotProduct (vec, texinfo->vecs[1]) + texinfo->vecs[1][3];
|
||||
t /= texinfo->texture->height;
|
||||
|
||||
VectorCopy (vec, poly->verts[i]);
|
||||
poly->verts[i][3] = s;
|
||||
poly->verts[i][4] = t;
|
||||
VectorCopy (vec, poly->verts[i].pos);
|
||||
poly->verts[i].tex_uv[0] = s;
|
||||
poly->verts[i].tex_uv[1] = t;
|
||||
|
||||
// lightmap texture coordinates
|
||||
s = DotProduct (vec, texinfo->vecs[0]) + texinfo->vecs[0][3];
|
||||
|
@ -857,23 +842,22 @@ GL_BuildSurfaceDisplayList (mod_brush_t *brush, msurface_t *surf)
|
|||
t += surf->lightpic->rect->y * 16 + 8;
|
||||
s /= 16;
|
||||
t /= 16;
|
||||
poly->verts[i][5] = s * surf->lightpic->size;
|
||||
poly->verts[i][6] = t * surf->lightpic->size;
|
||||
poly->verts[i].lm_uv[0] = s * surf->lightpic->size;
|
||||
poly->verts[i].lm_uv[1] = t * surf->lightpic->size;
|
||||
}
|
||||
|
||||
// remove co-linear points - Ed
|
||||
if (!gl_keeptjunctions) {
|
||||
for (i = 0; i < lnumverts; ++i) {
|
||||
vec3_t v1, v2;
|
||||
float *prev, *this, *next;
|
||||
|
||||
prev = poly->verts[(i + lnumverts - 1) % lnumverts];
|
||||
this = poly->verts[i];
|
||||
next = poly->verts[(i + 1) % lnumverts];
|
||||
auto prev = &poly->verts[(i + lnumverts - 1) % lnumverts];
|
||||
auto this = &poly->verts[i];
|
||||
auto next = &poly->verts[(i + 1) % lnumverts];
|
||||
|
||||
VectorSubtract (this, prev, v1);
|
||||
VectorSubtract (this->pos, prev->pos, v1);
|
||||
VectorNormalize (v1);
|
||||
VectorSubtract (next, prev, v2);
|
||||
VectorSubtract (next->pos, prev->pos, v2);
|
||||
VectorNormalize (v2);
|
||||
|
||||
// skip co-linear points
|
||||
|
@ -881,13 +865,8 @@ GL_BuildSurfaceDisplayList (mod_brush_t *brush, msurface_t *surf)
|
|||
if ((fabs (v1[0] - v2[0]) <= COLINEAR_EPSILON) &&
|
||||
(fabs (v1[1] - v2[1]) <= COLINEAR_EPSILON) &&
|
||||
(fabs (v1[2] - v2[2]) <= COLINEAR_EPSILON)) {
|
||||
int j;
|
||||
|
||||
for (j = i + 1; j < lnumverts; ++j) {
|
||||
int k;
|
||||
|
||||
for (k = 0; k < VERTEXSIZE; ++k)
|
||||
poly->verts[j - 1][k] = poly->verts[j][k];
|
||||
for (int j = i + 1; j < lnumverts; ++j) {
|
||||
poly->verts[j - 1] = poly->verts[j];
|
||||
}
|
||||
--lnumverts;
|
||||
// retry next vertex next time, which is now current vertex
|
||||
|
|
|
@ -83,7 +83,7 @@ static const vec_t face_offset[] = { 1024, 1024, 1024, -1024, -1024, -1024 };
|
|||
struct face_def {
|
||||
int tex; // texture to bind to
|
||||
glpoly_t poly; // describe the polygon of this face
|
||||
float verts[32][VERTEXSIZE];
|
||||
glvert_t verts[32];
|
||||
};
|
||||
|
||||
struct visit_def {
|
||||
|
@ -224,31 +224,32 @@ find_cube_vertex (int face1, int face2, int face3, vec3_t v)
|
|||
static void
|
||||
set_vertex (struct box_def *box, int face, int ind, const vec3_t v)
|
||||
{
|
||||
VectorAdd (v, r_refdef.frame.position, box->face[face].poly.verts[ind]);
|
||||
auto poly = &box->face[face].poly;
|
||||
VectorAdd (v, r_refdef.frame.position, poly->verts[ind].pos);
|
||||
switch (face) {
|
||||
case 0:
|
||||
box->face[face].poly.verts[ind][3] = (1024 - v[1] + 4) / BOX_WIDTH;
|
||||
box->face[face].poly.verts[ind][4] = (1024 - v[2] + 4) / BOX_WIDTH;
|
||||
poly->verts[ind].tex_uv[0] = (1024 - v[1] + 4) / BOX_WIDTH;
|
||||
poly->verts[ind].tex_uv[1] = (1024 - v[2] + 4) / BOX_WIDTH;
|
||||
break;
|
||||
case 1:
|
||||
box->face[face].poly.verts[ind][3] = (1024 + v[0] + 4) / BOX_WIDTH;
|
||||
box->face[face].poly.verts[ind][4] = (1024 - v[2] + 4) / BOX_WIDTH;
|
||||
poly->verts[ind].tex_uv[0] = (1024 + v[0] + 4) / BOX_WIDTH;
|
||||
poly->verts[ind].tex_uv[1] = (1024 - v[2] + 4) / BOX_WIDTH;
|
||||
break;
|
||||
case 2:
|
||||
box->face[face].poly.verts[ind][3] = (1024 - v[1] + 4) / BOX_WIDTH;
|
||||
box->face[face].poly.verts[ind][4] = (1024 + v[0] + 4) / BOX_WIDTH;
|
||||
poly->verts[ind].tex_uv[0] = (1024 - v[1] + 4) / BOX_WIDTH;
|
||||
poly->verts[ind].tex_uv[1] = (1024 + v[0] + 4) / BOX_WIDTH;
|
||||
break;
|
||||
case 3:
|
||||
box->face[face].poly.verts[ind][3] = (1024 + v[1] + 4) / BOX_WIDTH;
|
||||
box->face[face].poly.verts[ind][4] = (1024 - v[2] + 4) / BOX_WIDTH;
|
||||
poly->verts[ind].tex_uv[0] = (1024 + v[1] + 4) / BOX_WIDTH;
|
||||
poly->verts[ind].tex_uv[1] = (1024 - v[2] + 4) / BOX_WIDTH;
|
||||
break;
|
||||
case 4:
|
||||
box->face[face].poly.verts[ind][3] = (1024 - v[0] + 4) / BOX_WIDTH;
|
||||
box->face[face].poly.verts[ind][4] = (1024 - v[2] + 4) / BOX_WIDTH;
|
||||
poly->verts[ind].tex_uv[0] = (1024 - v[0] + 4) / BOX_WIDTH;
|
||||
poly->verts[ind].tex_uv[1] = (1024 - v[2] + 4) / BOX_WIDTH;
|
||||
break;
|
||||
case 5:
|
||||
box->face[face].poly.verts[ind][3] = (1024 - v[1] + 4) / BOX_WIDTH;
|
||||
box->face[face].poly.verts[ind][4] = (1024 - v[0] + 4) / BOX_WIDTH;
|
||||
poly->verts[ind].tex_uv[0] = (1024 - v[1] + 4) / BOX_WIDTH;
|
||||
poly->verts[ind].tex_uv[1] = (1024 - v[0] + 4) / BOX_WIDTH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -300,7 +301,7 @@ insert_cube_vertices (struct box_def *box, struct visit_def visit, int count,
|
|||
int c = p->numverts - ind;
|
||||
const int vert_size = sizeof (p->verts[0]);
|
||||
|
||||
memmove (p->verts[ind + count], p->verts[ind], c * vert_size);
|
||||
memmove (&p->verts[ind + count], &p->verts[ind], c * vert_size);
|
||||
p->numverts += count;
|
||||
for (i = 0; i < count; i++)
|
||||
set_vertex (box, face, ind + i, *v[i]);
|
||||
|
@ -568,8 +569,8 @@ render_box (const struct box_def *box)
|
|||
qfglBindTexture (GL_TEXTURE_2D, box->face[i].tex);
|
||||
qfglBegin (GL_POLYGON);
|
||||
for (j = 0; j < box->face[i].poly.numverts; j++) {
|
||||
qfglTexCoord2fv (box->face[i].poly.verts[j] + 3);
|
||||
qfglVertex3fv (box->face[i].poly.verts[j]);
|
||||
qfglTexCoord2fv (box->face[i].poly.verts[j].tex_uv);
|
||||
qfglVertex3fv (box->face[i].poly.verts[j].pos);
|
||||
}
|
||||
qfglEnd ();
|
||||
}
|
||||
|
@ -598,14 +599,15 @@ R_DrawSkyBoxPoly (const glpoly_t *poly)
|
|||
Sys_Error ("too many verts!");
|
||||
}
|
||||
|
||||
VectorSubtract (poly->verts[poly->numverts - 1], r_refdef.frame.position, last_v);
|
||||
VectorSubtract (poly->verts[poly->numverts - 1].pos,
|
||||
r_refdef.frame.position, last_v);
|
||||
prev_face = determine_face (last_v);
|
||||
|
||||
box.visited_faces[0].face = prev_face;
|
||||
box.face_count = 1;
|
||||
|
||||
for (i = 0; i < poly->numverts; i++) {
|
||||
VectorSubtract (poly->verts[i], r_refdef.frame.position, v);
|
||||
VectorSubtract (poly->verts[i].pos, r_refdef.frame.position, v);
|
||||
face = determine_face (v);
|
||||
if (face != prev_face) {
|
||||
if ((face_axis[face]) == (face_axis[prev_face])) {
|
||||
|
@ -637,18 +639,16 @@ static void
|
|||
EmitSkyPolys (float speedscale, const instsurf_t *sc)
|
||||
{
|
||||
float length, s, t;
|
||||
float *v;
|
||||
int i;
|
||||
glpoly_t *p;
|
||||
vec3_t dir;
|
||||
msurface_t *surf = sc->surface;
|
||||
vec4f_t origin = r_refdef.frame.position;
|
||||
|
||||
//FIXME transform/color
|
||||
for (p = surf->polys; p; p = p->next) {
|
||||
for (auto p = surf->polys; p; p = p->next) {
|
||||
qfglBegin (GL_POLYGON);
|
||||
for (i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE) {
|
||||
VectorSubtract (v, origin, dir);
|
||||
auto v = p->verts;
|
||||
for (int i = 0; i < p->numverts; i++, v++) {
|
||||
VectorSubtract (v->pos, origin, dir);
|
||||
dir[2] *= 3.0; // flatten the sphere
|
||||
|
||||
length = DotProduct (dir, dir);
|
||||
|
@ -661,7 +661,7 @@ EmitSkyPolys (float speedscale, const instsurf_t *sc)
|
|||
t = speedscale + dir[1];
|
||||
|
||||
qfglTexCoord2f (s, t);
|
||||
qfglVertex3fv (v);
|
||||
qfglVertex3fv (v->pos);
|
||||
}
|
||||
qfglEnd ();
|
||||
}
|
||||
|
@ -674,7 +674,7 @@ draw_poly (const glpoly_t *poly)
|
|||
|
||||
qfglBegin (GL_POLYGON);
|
||||
for (i = 0; i < poly->numverts; i++) {
|
||||
qfglVertex3fv (poly->verts[i]);
|
||||
qfglVertex3fv (poly->verts[i].pos);
|
||||
}
|
||||
qfglEnd ();
|
||||
}
|
||||
|
@ -836,7 +836,7 @@ gl_R_DrawSkyChain (const instsurf_t *sky_chain)
|
|||
|
||||
qfglBegin (GL_LINE_LOOP);
|
||||
for (i = 0; i < p->numverts; i++) {
|
||||
qfglVertex3fv (p->verts[i]);
|
||||
qfglVertex3fv (p->verts[i].pos);
|
||||
}
|
||||
qfglEnd ();
|
||||
p = p->next;
|
||||
|
@ -862,7 +862,8 @@ gl_R_DrawSkyChain (const instsurf_t *sky_chain)
|
|||
vec3_t x, c = { 0, 0, 0 };
|
||||
|
||||
for (i = 0; i < p->numverts; i++) {
|
||||
VectorSubtract (p->verts[i], r_refdef.frame.position, x);
|
||||
VectorSubtract (p->verts[i].pos,
|
||||
r_refdef.frame.position, x);
|
||||
VectorAdd (x, c, c);
|
||||
}
|
||||
VectorScale (c, 1.0 / p->numverts, c);
|
||||
|
|
|
@ -55,29 +55,27 @@ void
|
|||
GL_EmitWaterPolys (msurface_t *surf)
|
||||
{
|
||||
float os, ot, s, t, timetemp;
|
||||
float *v;
|
||||
int i;
|
||||
glpoly_t *p;
|
||||
|
||||
timetemp = vr_data.realtime * TURBSCALE;
|
||||
|
||||
for (p = surf->polys; p; p = p->next) {
|
||||
for (auto p = surf->polys; p; p = p->next) {
|
||||
qfglBegin (GL_POLYGON);
|
||||
for (i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE) {
|
||||
os = turbsin[(int) (v[3] * TURBFRAC + timetemp) & 255];
|
||||
ot = turbsin[(int) (v[4] * TURBFRAC + timetemp) & 255];
|
||||
s = (v[3] + ot) * (1.0 / 64.0);
|
||||
t = (v[4] + os) * (1.0 / 64.0);
|
||||
auto v = p->verts;
|
||||
for (int i = 0; i < p->numverts; i++, v++) {
|
||||
os = turbsin[(int) (v->tex_uv[0] * TURBFRAC + timetemp) & 255];
|
||||
ot = turbsin[(int) (v->tex_uv[1] * TURBFRAC + timetemp) & 255];
|
||||
s = (v->tex_uv[0] + ot) * (1.0 / 64.0);
|
||||
t = (v->tex_uv[1] + os) * (1.0 / 64.0);
|
||||
qfglTexCoord2f (s, t);
|
||||
|
||||
if (r_waterripple != 0) {
|
||||
vec3_t nv;
|
||||
|
||||
VectorCopy (v, nv);
|
||||
VectorCopy (v->pos, nv);
|
||||
nv[2] += r_waterripple * os * ot * (1.0 / 64.0);
|
||||
qfglVertex3fv (nv);
|
||||
} else
|
||||
qfglVertex3fv (v);
|
||||
qfglVertex3fv (v->pos);
|
||||
}
|
||||
qfglEnd ();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue