mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-21 11:21:52 +00:00
gl1,gl3,gl4,vk: Reuse mpoly_t
This commit is contained in:
parent
821490bbbd
commit
a381c9dc5d
21 changed files with 814 additions and 753 deletions
|
@ -41,7 +41,6 @@ void
|
|||
LM_UploadBlock(qboolean dynamic)
|
||||
{
|
||||
int texture;
|
||||
int height = 0;
|
||||
|
||||
if (dynamic)
|
||||
{
|
||||
|
@ -59,6 +58,7 @@ LM_UploadBlock(qboolean dynamic)
|
|||
if (dynamic)
|
||||
{
|
||||
int i;
|
||||
int height = 0;
|
||||
|
||||
for (i = 0; i < BLOCK_WIDTH; i++)
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ LM_UploadBlock(qboolean dynamic)
|
|||
if (++gl_lms.current_lightmap_texture == MAX_LIGHTMAPS)
|
||||
{
|
||||
ri.Sys_Error(ERR_DROP,
|
||||
"LM_UploadBlock() - MAX_LIGHTMAPS exceeded\n");
|
||||
"%s() - MAX_LIGHTMAPS exceeded\n", __func__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,13 +93,14 @@ LM_UploadBlock(qboolean dynamic)
|
|||
qboolean
|
||||
LM_AllocBlock(int w, int h, int *x, int *y)
|
||||
{
|
||||
int i, j;
|
||||
int best, best2;
|
||||
int i, best;
|
||||
|
||||
best = BLOCK_HEIGHT;
|
||||
|
||||
for (i = 0; i < BLOCK_WIDTH - w; i++)
|
||||
{
|
||||
int j, best2;
|
||||
|
||||
best2 = 0;
|
||||
|
||||
for (j = 0; j < w; j++)
|
||||
|
@ -139,12 +140,12 @@ LM_AllocBlock(int w, int h, int *x, int *y)
|
|||
void
|
||||
LM_BuildPolygonFromSurface(model_t *currentmodel, msurface_t *fa)
|
||||
{
|
||||
int i, lindex, lnumverts;
|
||||
int i, lnumverts;
|
||||
medge_t *pedges, *r_pedge;
|
||||
float *vec;
|
||||
float s, t;
|
||||
mpoly_t *poly;
|
||||
vec3_t total;
|
||||
vec3_t normal;
|
||||
|
||||
/* reconstruct the polygon */
|
||||
pedges = currentmodel->edges;
|
||||
|
@ -154,14 +155,29 @@ LM_BuildPolygonFromSurface(model_t *currentmodel, msurface_t *fa)
|
|||
|
||||
/* draw texture */
|
||||
poly = Hunk_Alloc(sizeof(mpoly_t) +
|
||||
(lnumverts - 4) * sizeof(glvk_vtx_t));
|
||||
(lnumverts - 4) * sizeof(mvtx_t));
|
||||
poly->next = fa->polys;
|
||||
poly->flags = fa->flags;
|
||||
fa->polys = poly;
|
||||
poly->numverts = lnumverts;
|
||||
|
||||
VectorCopy(fa->plane->normal, normal);
|
||||
|
||||
if(fa->flags & SURF_PLANEBACK)
|
||||
{
|
||||
// if for some reason the normal sticks to the back of the plane, invert it
|
||||
// so it's usable for the shader
|
||||
for (i=0; i<3; ++i) normal[i] = -normal[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < lnumverts; i++)
|
||||
{
|
||||
mvtx_t* vert;
|
||||
float s, t;
|
||||
int lindex;
|
||||
|
||||
vert = &poly->verts[i];
|
||||
|
||||
lindex = currentmodel->surfedges[fa->firstedge + i];
|
||||
|
||||
if (lindex > 0)
|
||||
|
@ -182,9 +198,9 @@ LM_BuildPolygonFromSurface(model_t *currentmodel, msurface_t *fa)
|
|||
t /= fa->texinfo->image->height;
|
||||
|
||||
VectorAdd(total, vec, total);
|
||||
VectorCopy(vec, poly->verts[i]);
|
||||
poly->verts[i][3] = s;
|
||||
poly->verts[i][4] = t;
|
||||
VectorCopy(vec, vert->pos);
|
||||
vert->texCoord[0] = s;
|
||||
vert->texCoord[1] = t;
|
||||
|
||||
/* lightmap texture coordinates */
|
||||
s = DotProduct(vec, fa->lmvecs[0]) + fa->lmvecs[0][3];
|
||||
|
@ -199,8 +215,11 @@ LM_BuildPolygonFromSurface(model_t *currentmodel, msurface_t *fa)
|
|||
t += (1 << fa->lmshift) * 0.5;
|
||||
t /= BLOCK_HEIGHT * (1 << fa->lmshift);
|
||||
|
||||
poly->verts[i][5] = s;
|
||||
poly->verts[i][6] = t;
|
||||
vert->lmTexCoord[0] = s;
|
||||
vert->lmTexCoord[1] = t;
|
||||
|
||||
VectorCopy(normal, vert->normal);
|
||||
vert->lightFlags = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -306,8 +306,8 @@ calcTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl
|
|||
else
|
||||
{
|
||||
// LM_BuildPolygonFromSurface(out);
|
||||
// => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(glvk_vtx_t));
|
||||
int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(glvk_vtx_t);
|
||||
// => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t));
|
||||
int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t);
|
||||
polySize = (polySize + 31) & ~31;
|
||||
ret += polySize;
|
||||
}
|
||||
|
@ -382,8 +382,8 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t
|
|||
else
|
||||
{
|
||||
// LM_BuildPolygonFromSurface(out);
|
||||
// => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(glvk_vtx_t));
|
||||
int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(glvk_vtx_t);
|
||||
// => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t));
|
||||
int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t);
|
||||
polySize = (polySize + 31) & ~31;
|
||||
ret += polySize;
|
||||
}
|
||||
|
|
|
@ -45,26 +45,24 @@ void R_BuildLightMap(msurface_t *surf, byte *dest, int stride);
|
|||
static void
|
||||
R_DrawGLPoly(mpoly_t *p)
|
||||
{
|
||||
float *v;
|
||||
mvtx_t* vert = p->verts;
|
||||
|
||||
v = p->verts[0];
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glEnableClientState( GL_VERTEX_ARRAY );
|
||||
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(mvtx_t), vert->pos);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(mvtx_t), vert->texCoord);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, p->numverts);
|
||||
|
||||
glVertexPointer( 3, GL_FLOAT, sizeof(glvk_vtx_t), v );
|
||||
glTexCoordPointer( 2, GL_FLOAT, sizeof(glvk_vtx_t), v+3 );
|
||||
glDrawArrays( GL_TRIANGLE_FAN, 0, p->numverts );
|
||||
|
||||
glDisableClientState( GL_VERTEX_ARRAY );
|
||||
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
static void
|
||||
R_DrawGLFlowingPoly(msurface_t *fa)
|
||||
{
|
||||
int i;
|
||||
float *v;
|
||||
mvtx_t* vert;
|
||||
mpoly_t *p;
|
||||
float scroll;
|
||||
|
||||
|
@ -77,27 +75,26 @@ R_DrawGLFlowingPoly(msurface_t *fa)
|
|||
scroll = -64.0;
|
||||
}
|
||||
|
||||
YQ2_VLA(GLfloat, tex, 2*p->numverts);
|
||||
unsigned int index_tex = 0;
|
||||
YQ2_VLA(GLfloat, tex, 2*p->numverts);
|
||||
unsigned int index_tex = 0;
|
||||
|
||||
v = p->verts [ 0 ];
|
||||
vert = p->verts;
|
||||
|
||||
for ( i = 0; i < p->numverts; i++, v += VERTEXSIZE )
|
||||
{
|
||||
tex[index_tex++] = v [ 3 ] + scroll;
|
||||
tex[index_tex++] = v [ 4 ];
|
||||
}
|
||||
v = p->verts [ 0 ];
|
||||
for ( i = 0; i < p->numverts; i++, vert++)
|
||||
{
|
||||
tex[index_tex++] = vert->texCoord[0] + scroll;
|
||||
tex[index_tex++] = vert->texCoord[1];
|
||||
}
|
||||
|
||||
glEnableClientState( GL_VERTEX_ARRAY );
|
||||
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glVertexPointer( 3, GL_FLOAT, sizeof(glvk_vtx_t), v );
|
||||
glTexCoordPointer( 2, GL_FLOAT, 0, tex );
|
||||
glDrawArrays( GL_TRIANGLE_FAN, 0, p->numverts );
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(mvtx_t), p->verts->pos);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, tex);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, p->numverts);
|
||||
|
||||
glDisableClientState( GL_VERTEX_ARRAY );
|
||||
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
YQ2_VLAFREE(tex);
|
||||
}
|
||||
|
@ -131,23 +128,23 @@ R_DrawTriangleOutlines(void)
|
|||
{
|
||||
for (j = 2; j < p->numverts; j++)
|
||||
{
|
||||
GLfloat vtx[12];
|
||||
unsigned int k;
|
||||
GLfloat vtx[12];
|
||||
unsigned int k;
|
||||
|
||||
for (k=0; k<3; k++)
|
||||
{
|
||||
vtx[0+k] = p->verts [ 0 ][ k ];
|
||||
vtx[3+k] = p->verts [ j - 1 ][ k ];
|
||||
vtx[6+k] = p->verts [ j ][ k ];
|
||||
vtx[9+k] = p->verts [ 0 ][ k ];
|
||||
}
|
||||
for (k=0; k<3; k++)
|
||||
{
|
||||
vtx[0+k] = p->verts[0 ].pos[k];
|
||||
vtx[3+k] = p->verts[j - 1].pos[k];
|
||||
vtx[6+k] = p->verts[j ].pos[k];
|
||||
vtx[9+k] = p->verts[0 ].pos[k];
|
||||
}
|
||||
|
||||
glEnableClientState( GL_VERTEX_ARRAY );
|
||||
glEnableClientState( GL_VERTEX_ARRAY );
|
||||
|
||||
glVertexPointer( 3, GL_FLOAT, 0, vtx );
|
||||
glDrawArrays( GL_LINE_STRIP, 0, 4 );
|
||||
glVertexPointer( 3, GL_FLOAT, 0, vtx );
|
||||
glDrawArrays( GL_LINE_STRIP, 0, 4 );
|
||||
|
||||
glDisableClientState( GL_VERTEX_ARRAY );
|
||||
glDisableClientState( GL_VERTEX_ARRAY );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,19 +161,17 @@ R_DrawGLPolyChain(mpoly_t *p, float soffset, float toffset)
|
|||
{
|
||||
for ( ; p != 0; p = p->chain)
|
||||
{
|
||||
float *v;
|
||||
mvtx_t* vert = p->verts;
|
||||
|
||||
v = p->verts[0];
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glEnableClientState( GL_VERTEX_ARRAY );
|
||||
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(mvtx_t), vert->pos);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(mvtx_t), vert->lmTexCoord);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, p->numverts);
|
||||
|
||||
glVertexPointer( 3, GL_FLOAT, sizeof(glvk_vtx_t), v );
|
||||
glTexCoordPointer( 2, GL_FLOAT, sizeof(glvk_vtx_t), v+5 );
|
||||
glDrawArrays( GL_TRIANGLE_FAN, 0, p->numverts );
|
||||
|
||||
glDisableClientState( GL_VERTEX_ARRAY );
|
||||
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -195,36 +190,36 @@ R_DrawGLPolyChain(mpoly_t *p, float soffset, float toffset)
|
|||
|
||||
for ( ; p != 0; p = p->chain)
|
||||
{
|
||||
float *v;
|
||||
mvtx_t* vert;
|
||||
int j;
|
||||
|
||||
v = p->verts[0];
|
||||
vert = p->verts;
|
||||
#ifndef _MSC_VER // we have real VLAs, so it's safe to use one in this loop
|
||||
YQ2_VLA(GLfloat, tex, 2*p->numverts);
|
||||
YQ2_VLA(GLfloat, tex, 2*p->numverts);
|
||||
#endif
|
||||
|
||||
unsigned int index_tex = 0;
|
||||
unsigned int index_tex = 0;
|
||||
|
||||
for ( j = 0; j < p->numverts; j++, v += VERTEXSIZE )
|
||||
for (j = 0; j < p->numverts; j++, vert++)
|
||||
{
|
||||
tex[index_tex++] = v [ 5 ] - soffset;
|
||||
tex[index_tex++] = v [ 6 ] - toffset;
|
||||
tex[index_tex++] = vert->lmTexCoord[0] - soffset;
|
||||
tex[index_tex++] = vert->lmTexCoord[1] - toffset;
|
||||
}
|
||||
|
||||
v = p->verts [ 0 ];
|
||||
vert = p->verts;
|
||||
|
||||
glEnableClientState( GL_VERTEX_ARRAY );
|
||||
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glVertexPointer( 3, GL_FLOAT, sizeof(glvk_vtx_t), v );
|
||||
glTexCoordPointer( 2, GL_FLOAT, 0, tex );
|
||||
glDrawArrays( GL_TRIANGLE_FAN, 0, p->numverts );
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(mvtx_t), vert->pos);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, tex);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, p->numverts);
|
||||
|
||||
glDisableClientState( GL_VERTEX_ARRAY );
|
||||
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
YQ2_VLAFREE( tex );
|
||||
YQ2_VLAFREE(tex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -637,15 +632,15 @@ R_DrawTextureChains(entity_t *currententity)
|
|||
static void
|
||||
R_DrawInlineBModel(entity_t *currententity, const model_t *currentmodel)
|
||||
{
|
||||
int i, k;
|
||||
cplane_t *pplane;
|
||||
float dot;
|
||||
int i;
|
||||
msurface_t *psurf;
|
||||
dlight_t *lt;
|
||||
|
||||
/* calculate dynamic lighting for bmodel */
|
||||
if (!gl1_flashblend->value)
|
||||
{
|
||||
dlight_t *lt;
|
||||
int k;
|
||||
|
||||
lt = r_newrefdef.dlights;
|
||||
|
||||
for (k = 0; k < r_newrefdef.num_dlights; k++, lt++)
|
||||
|
@ -668,6 +663,9 @@ R_DrawInlineBModel(entity_t *currententity, const model_t *currentmodel)
|
|||
/* draw texture */
|
||||
for (i = 0; i < currentmodel->nummodelsurfaces; i++, psurf++)
|
||||
{
|
||||
cplane_t *pplane;
|
||||
float dot;
|
||||
|
||||
/* find which side of the node we are on */
|
||||
pplane = psurf->plane;
|
||||
|
||||
|
@ -707,7 +705,6 @@ void
|
|||
R_DrawBrushModel(entity_t *currententity, const model_t *currentmodel)
|
||||
{
|
||||
vec3_t mins, maxs;
|
||||
int i;
|
||||
qboolean rotated;
|
||||
|
||||
if (currentmodel->nummodelsurfaces == 0)
|
||||
|
@ -719,6 +716,8 @@ R_DrawBrushModel(entity_t *currententity, const model_t *currentmodel)
|
|||
|
||||
if (currententity->angles[0] || currententity->angles[1] || currententity->angles[2])
|
||||
{
|
||||
int i;
|
||||
|
||||
rotated = true;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
|
@ -794,7 +793,7 @@ R_RecursiveWorldNode(entity_t *currententity, mnode_t *node)
|
|||
{
|
||||
int c, side, sidebit;
|
||||
cplane_t *plane;
|
||||
msurface_t *surf, **mark;
|
||||
msurface_t *surf;
|
||||
mleaf_t *pleaf;
|
||||
float dot;
|
||||
image_t *image;
|
||||
|
@ -817,6 +816,8 @@ R_RecursiveWorldNode(entity_t *currententity, mnode_t *node)
|
|||
/* if a leaf node, draw stuff */
|
||||
if (node->contents != CONTENTS_NODE)
|
||||
{
|
||||
msurface_t **mark;
|
||||
|
||||
pleaf = (mleaf_t *)node;
|
||||
|
||||
/* check for door connected areas */
|
||||
|
@ -960,9 +961,8 @@ R_MarkLeaves(void)
|
|||
const byte *vis;
|
||||
YQ2_ALIGNAS_TYPE(int) byte fatvis[MAX_MAP_LEAFS / 8];
|
||||
mnode_t *node;
|
||||
int i, c;
|
||||
int i;
|
||||
mleaf_t *leaf;
|
||||
int cluster;
|
||||
|
||||
if ((r_oldviewcluster == r_viewcluster) &&
|
||||
(r_oldviewcluster2 == r_viewcluster2) &&
|
||||
|
@ -1004,6 +1004,8 @@ R_MarkLeaves(void)
|
|||
/* may have to combine two clusters because of solid water boundaries */
|
||||
if (r_viewcluster2 != r_viewcluster)
|
||||
{
|
||||
int c;
|
||||
|
||||
memcpy(fatvis, vis, (r_worldmodel->numleafs + 7) / 8);
|
||||
vis = Mod_ClusterPVS(r_viewcluster2, r_worldmodel);
|
||||
c = (r_worldmodel->numleafs + 31) / 32;
|
||||
|
@ -1020,6 +1022,8 @@ R_MarkLeaves(void)
|
|||
i < r_worldmodel->numleafs;
|
||||
i++, leaf++)
|
||||
{
|
||||
int cluster;
|
||||
|
||||
cluster = leaf->cluster;
|
||||
|
||||
if (cluster == -1)
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
static float skyrotate;
|
||||
static int skyautorotate;
|
||||
static vec3_t skyaxis;
|
||||
image_t *sky_images[6];
|
||||
int skytexorder[6] = {0, 2, 1, 3, 4, 5};
|
||||
static image_t *sky_images[6];
|
||||
static int skytexorder[6] = {0, 2, 1, 3, 4, 5};
|
||||
|
||||
GLfloat vtx_sky[12];
|
||||
GLfloat tex_sky[8];
|
||||
|
@ -49,7 +49,7 @@ float r_turbsin[] = {
|
|||
#include "../constants/warpsin.h"
|
||||
};
|
||||
|
||||
vec3_t skyclip[6] = {
|
||||
static vec3_t skyclip[6] = {
|
||||
{1, 1, 0},
|
||||
{1, -1, 0},
|
||||
{0, -1, 1},
|
||||
|
@ -59,7 +59,7 @@ vec3_t skyclip[6] = {
|
|||
};
|
||||
int c_sky;
|
||||
|
||||
int st_to_vec[6][3] = {
|
||||
static int st_to_vec[6][3] = {
|
||||
{3, -1, 2},
|
||||
{-3, 1, 2},
|
||||
|
||||
|
@ -70,7 +70,7 @@ int st_to_vec[6][3] = {
|
|||
{2, -1, -3} /* look straight down */
|
||||
};
|
||||
|
||||
int vec_to_st[6][3] = {
|
||||
static int vec_to_st[6][3] = {
|
||||
{-2, 3, 1},
|
||||
{2, 3, -1},
|
||||
|
||||
|
@ -81,34 +81,34 @@ int vec_to_st[6][3] = {
|
|||
{-2, 1, -3}
|
||||
};
|
||||
|
||||
float skymins[2][6], skymaxs[2][6];
|
||||
float sky_min, sky_max;
|
||||
static float skymins[2][6], skymaxs[2][6];
|
||||
static float sky_min, sky_max;
|
||||
|
||||
void
|
||||
R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
||||
{
|
||||
int i, j, k;
|
||||
vec3_t mins, maxs;
|
||||
float m;
|
||||
float *v;
|
||||
vec3_t front[64], back[64];
|
||||
int f, b;
|
||||
float dist[64];
|
||||
float frac;
|
||||
mpoly_t *poly;
|
||||
float s, t;
|
||||
vec3_t total;
|
||||
float total_s, total_t;
|
||||
|
||||
if (numverts > 60)
|
||||
{
|
||||
ri.Sys_Error(ERR_DROP, "numverts = %i", numverts);
|
||||
ri.Sys_Error(ERR_DROP, "%s: numverts = %i", __func__, numverts);
|
||||
}
|
||||
|
||||
R_BoundPoly(numverts, verts, mins, maxs);
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
float m;
|
||||
|
||||
m = (mins[i] + maxs[i]) * 0.5;
|
||||
m = SUBDIVIDE_SIZE * floor(m / SUBDIVIDE_SIZE + 0.5);
|
||||
|
||||
|
@ -178,7 +178,7 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
|||
}
|
||||
|
||||
/* add a point in the center to help keep warp valid */
|
||||
poly = Hunk_Alloc(sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(glvk_vtx_t));
|
||||
poly = Hunk_Alloc(sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t));
|
||||
poly->next = warpface->polys;
|
||||
warpface->polys = poly;
|
||||
poly->numverts = numverts + 2;
|
||||
|
@ -188,7 +188,9 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
|||
|
||||
for (i = 0; i < numverts; i++, verts += 3)
|
||||
{
|
||||
VectorCopy(verts, poly->verts[i + 1]);
|
||||
float s, t;
|
||||
|
||||
VectorCopy(verts, poly->verts[i + 1].pos);
|
||||
s = DotProduct(verts, warpface->texinfo->vecs[0]);
|
||||
t = DotProduct(verts, warpface->texinfo->vecs[1]);
|
||||
|
||||
|
@ -196,16 +198,16 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
|||
total_t += t;
|
||||
VectorAdd(total, verts, total);
|
||||
|
||||
poly->verts[i + 1][3] = s;
|
||||
poly->verts[i + 1][4] = t;
|
||||
poly->verts[i + 1].texCoord[0] = s;
|
||||
poly->verts[i + 1].texCoord[1] = t;
|
||||
}
|
||||
|
||||
VectorScale(total, (1.0 / numverts), poly->verts[0]);
|
||||
poly->verts[0][3] = total_s / numverts;
|
||||
poly->verts[0][4] = total_t / numverts;
|
||||
VectorScale(total, (1.0 / numverts), poly->verts[0].pos);
|
||||
poly->verts[0].texCoord[0] = total_s / numverts;
|
||||
poly->verts[0].texCoord[1] = total_t / numverts;
|
||||
|
||||
/* copy first vertex to last */
|
||||
memcpy(poly->verts[i + 1], poly->verts[1], sizeof(poly->verts[0]));
|
||||
memcpy(&poly->verts[i + 1], &poly->verts[1], sizeof(mvtx_t));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -219,7 +221,6 @@ R_SubdivideSurface(model_t *loadmodel, msurface_t *fa)
|
|||
vec3_t verts[64];
|
||||
int numverts;
|
||||
int i;
|
||||
int lindex;
|
||||
float *vec;
|
||||
|
||||
/* convert edges back to a normal polygon */
|
||||
|
@ -227,6 +228,8 @@ R_SubdivideSurface(model_t *loadmodel, msurface_t *fa)
|
|||
|
||||
for (i = 0; i < fa->numedges; i++)
|
||||
{
|
||||
int lindex;
|
||||
|
||||
lindex = loadmodel->surfedges[fa->firstedge + i];
|
||||
|
||||
if (lindex > 0)
|
||||
|
@ -252,7 +255,7 @@ void
|
|||
R_EmitWaterPolys(msurface_t *fa)
|
||||
{
|
||||
mpoly_t *p, *bp;
|
||||
float *v;
|
||||
mvtx_t *v;
|
||||
int i;
|
||||
float s, t, os, ot;
|
||||
float scroll;
|
||||
|
@ -283,14 +286,14 @@ R_EmitWaterPolys(msurface_t *fa)
|
|||
{
|
||||
p = bp;
|
||||
#ifndef _MSC_VER // we have real VLAs, so it's safe to use one in this loop
|
||||
YQ2_VLA(GLfloat, tex, 2*p->numverts);
|
||||
YQ2_VLA(GLfloat, tex, 2 * p->numverts);
|
||||
#endif
|
||||
unsigned int index_tex = 0;
|
||||
unsigned int index_tex = 0;
|
||||
|
||||
for ( i = 0, v = p->verts [ 0 ]; i < p->numverts; i++, v += VERTEXSIZE )
|
||||
for ( i = 0, v = p->verts; i < p->numverts; i++, v++)
|
||||
{
|
||||
os = v [ 3 ];
|
||||
ot = v [ 4 ];
|
||||
os = v->texCoord[0];
|
||||
ot = v->texCoord[1];
|
||||
|
||||
s = os + r_turbsin [ (int) ( ( ot * 0.125 + r_newrefdef.time ) * TURBSCALE ) & 255 ];
|
||||
s += scroll;
|
||||
|
@ -300,23 +303,23 @@ R_EmitWaterPolys(msurface_t *fa)
|
|||
tex[index_tex++] = t * ( 1.0 / 64 );
|
||||
}
|
||||
|
||||
v = p->verts [ 0 ];
|
||||
v = p->verts;
|
||||
|
||||
glEnableClientState( GL_VERTEX_ARRAY );
|
||||
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glVertexPointer( 3, GL_FLOAT, sizeof(glvk_vtx_t), v );
|
||||
glTexCoordPointer( 2, GL_FLOAT, 0, tex );
|
||||
glDrawArrays( GL_TRIANGLE_FAN, 0, p->numverts );
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(mvtx_t), v->pos);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, tex);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, p->numverts);
|
||||
|
||||
glDisableClientState( GL_VERTEX_ARRAY );
|
||||
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
YQ2_VLAFREE( tex );
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
R_DrawSkyPolygon(int nump, vec3_t vecs)
|
||||
{
|
||||
int i, j;
|
||||
|
@ -556,7 +559,7 @@ R_AddSkySurface(msurface_t *fa)
|
|||
{
|
||||
for (i = 0; i < p->numverts; i++)
|
||||
{
|
||||
VectorSubtract(p->verts[i], r_origin, verts[i]);
|
||||
VectorSubtract(p->verts[i].pos, r_origin, verts[i]);
|
||||
}
|
||||
|
||||
R_ClipSkyPolygon(p->numverts, verts[0], 0);
|
||||
|
@ -696,12 +699,12 @@ R_DrawSkyBox(void)
|
|||
R_MakeSkyVec( skymaxs [ 0 ] [ i ], skymaxs [ 1 ] [ i ], i );
|
||||
R_MakeSkyVec( skymaxs [ 0 ] [ i ], skymins [ 1 ] [ i ], i );
|
||||
|
||||
glVertexPointer( 3, GL_FLOAT, 0, vtx_sky );
|
||||
glTexCoordPointer( 2, GL_FLOAT, 0, tex_sky );
|
||||
glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
|
||||
glVertexPointer( 3, GL_FLOAT, 0, vtx_sky );
|
||||
glTexCoordPointer( 2, GL_FLOAT, 0, tex_sky );
|
||||
glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
|
||||
|
||||
glDisableClientState( GL_VERTEX_ARRAY );
|
||||
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glDisableClientState( GL_VERTEX_ARRAY );
|
||||
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
|
|
@ -124,7 +124,7 @@ GL3_LM_BuildPolygonFromSurface(gl3model_t *currentmodel, msurface_t *fa)
|
|||
medge_t *pedges, *r_pedge;
|
||||
float *vec;
|
||||
float s, t;
|
||||
glpoly_t *poly;
|
||||
mpoly_t *poly;
|
||||
vec3_t total;
|
||||
vec3_t normal;
|
||||
|
||||
|
@ -135,7 +135,7 @@ GL3_LM_BuildPolygonFromSurface(gl3model_t *currentmodel, msurface_t *fa)
|
|||
VectorClear(total);
|
||||
|
||||
/* draw texture */
|
||||
poly = Hunk_Alloc(sizeof(glpoly_t) +
|
||||
poly = Hunk_Alloc(sizeof(mpoly_t) +
|
||||
(lnumverts - 4) * sizeof(mvtx_t));
|
||||
poly->next = fa->polys;
|
||||
poly->flags = fa->flags;
|
||||
|
@ -153,7 +153,7 @@ GL3_LM_BuildPolygonFromSurface(gl3model_t *currentmodel, msurface_t *fa)
|
|||
|
||||
for (i = 0; i < lnumverts; i++)
|
||||
{
|
||||
mvtx_t* vert = &poly->vertices[i];
|
||||
mvtx_t* vert = &poly->verts[i];
|
||||
|
||||
lindex = currentmodel->surfedges[fa->firstedge + i];
|
||||
|
||||
|
|
|
@ -294,7 +294,7 @@ calcTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl
|
|||
|
||||
// GL3_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
|
||||
// for each (pot. recursive) call to R_SubdividePolygon():
|
||||
// sizeof(glpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t)
|
||||
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t)
|
||||
|
||||
// this is tricky, how much is allocated depends on the size of the surface
|
||||
// which we don't know (we'd need the vertices etc to know, but we can't load
|
||||
|
@ -306,8 +306,8 @@ calcTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl
|
|||
else
|
||||
{
|
||||
// GL3_LM_BuildPolygonFromSurface(out);
|
||||
// => poly = Hunk_Alloc(sizeof(glpoly_t) + (numverts - 4) * sizeof(mvtx_t));
|
||||
int polySize = sizeof(glpoly_t) + (numverts - 4) * sizeof(mvtx_t);
|
||||
// => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t));
|
||||
int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t);
|
||||
polySize = (polySize + 31) & ~31;
|
||||
ret += polySize;
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t
|
|||
|
||||
// GL3_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
|
||||
// for each (pot. recursive) call to R_SubdividePolygon():
|
||||
// sizeof(glpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t)
|
||||
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t)
|
||||
|
||||
// this is tricky, how much is allocated depends on the size of the surface
|
||||
// which we don't know (we'd need the vertices etc to know, but we can't load
|
||||
|
@ -382,8 +382,8 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t
|
|||
else
|
||||
{
|
||||
// GL3_LM_BuildPolygonFromSurface(out);
|
||||
// => poly = Hunk_Alloc(sizeof(glpoly_t) + (numverts - 4) * sizeof(mvtx_t));
|
||||
int polySize = sizeof(glpoly_t) + (numverts - 4) * sizeof(mvtx_t);
|
||||
// => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t));
|
||||
int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t);
|
||||
polySize = (polySize + 31) & ~31;
|
||||
ret += polySize;
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ SetLightFlags(msurface_t *surf)
|
|||
lightFlags = surf->dlightbits;
|
||||
}
|
||||
|
||||
mvtx_t* verts = surf->polys->vertices;
|
||||
mvtx_t* verts = surf->polys->verts;
|
||||
|
||||
int numVerts = surf->polys->numverts;
|
||||
for(int i=0; i<numVerts; ++i)
|
||||
|
@ -155,7 +155,7 @@ SetAllLightFlags(msurface_t *surf)
|
|||
{
|
||||
unsigned int lightFlags = 0xffffffff;
|
||||
|
||||
mvtx_t* verts = surf->polys->vertices;
|
||||
mvtx_t* verts = surf->polys->verts;
|
||||
|
||||
int numVerts = surf->polys->numverts;
|
||||
for(int i=0; i<numVerts; ++i)
|
||||
|
@ -167,18 +167,18 @@ SetAllLightFlags(msurface_t *surf)
|
|||
void
|
||||
GL3_DrawGLPoly(msurface_t *fa)
|
||||
{
|
||||
glpoly_t *p = fa->polys;
|
||||
mpoly_t *p = fa->polys;
|
||||
|
||||
GL3_BindVAO(gl3state.vao3D);
|
||||
GL3_BindVBO(gl3state.vbo3D);
|
||||
|
||||
GL3_BufferAndDraw3D(p->vertices, p->numverts, GL_TRIANGLE_FAN);
|
||||
GL3_BufferAndDraw3D(p->verts, p->numverts, GL_TRIANGLE_FAN);
|
||||
}
|
||||
|
||||
void
|
||||
GL3_DrawGLFlowingPoly(msurface_t *fa)
|
||||
{
|
||||
glpoly_t *p;
|
||||
mpoly_t *p;
|
||||
float scroll;
|
||||
|
||||
p = fa->polys;
|
||||
|
@ -199,7 +199,7 @@ GL3_DrawGLFlowingPoly(msurface_t *fa)
|
|||
GL3_BindVAO(gl3state.vao3D);
|
||||
GL3_BindVBO(gl3state.vbo3D);
|
||||
|
||||
GL3_BufferAndDraw3D(p->vertices, p->numverts, GL_TRIANGLE_FAN);
|
||||
GL3_BufferAndDraw3D(p->verts, p->numverts, GL_TRIANGLE_FAN);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -208,7 +208,7 @@ DrawTriangleOutlines(void)
|
|||
STUB_ONCE("TODO: Implement for r_showtris support!");
|
||||
#if 0
|
||||
int i, j;
|
||||
glpoly_t *p;
|
||||
mpoly_t *p;
|
||||
|
||||
if (!r_showtris->value)
|
||||
{
|
||||
|
@ -238,10 +238,10 @@ DrawTriangleOutlines(void)
|
|||
|
||||
for (k=0; k<3; k++)
|
||||
{
|
||||
vtx[0+k] = p->vertices [ 0 ][ k ];
|
||||
vtx[3+k] = p->vertices [ j - 1 ][ k ];
|
||||
vtx[6+k] = p->vertices [ j ][ k ];
|
||||
vtx[9+k] = p->vertices [ 0 ][ k ];
|
||||
vtx[0+k] = p->verts [ 0 ][ k ];
|
||||
vtx[3+k] = p->verts [ j - 1 ][ k ];
|
||||
vtx[6+k] = p->verts [ j ][ k ];
|
||||
vtx[9+k] = p->verts [ 0 ][ k ];
|
||||
}
|
||||
|
||||
glEnableClientState( GL_VERTEX_ARRAY );
|
||||
|
|
|
@ -40,7 +40,7 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
|||
int f, b;
|
||||
float dist[64];
|
||||
float frac;
|
||||
glpoly_t *poly;
|
||||
mpoly_t *poly;
|
||||
float s, t;
|
||||
vec3_t total;
|
||||
float total_s, total_t;
|
||||
|
@ -126,7 +126,7 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
|||
}
|
||||
|
||||
/* add a point in the center to help keep warp valid */
|
||||
poly = Hunk_Alloc(sizeof(glpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t));
|
||||
poly = Hunk_Alloc(sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t));
|
||||
poly->next = warpface->polys;
|
||||
warpface->polys = poly;
|
||||
poly->numverts = numverts + 2;
|
||||
|
@ -136,7 +136,7 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
|||
|
||||
for (i = 0; i < numverts; i++, verts += 3)
|
||||
{
|
||||
VectorCopy(verts, poly->vertices[i + 1].pos);
|
||||
VectorCopy(verts, poly->verts[i + 1].pos);
|
||||
s = DotProduct(verts, warpface->texinfo->vecs[0]);
|
||||
t = DotProduct(verts, warpface->texinfo->vecs[1]);
|
||||
|
||||
|
@ -144,20 +144,20 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
|||
total_t += t;
|
||||
VectorAdd(total, verts, total);
|
||||
|
||||
poly->vertices[i + 1].texCoord[0] = s;
|
||||
poly->vertices[i + 1].texCoord[1] = t;
|
||||
VectorCopy(normal, poly->vertices[i + 1].normal);
|
||||
poly->vertices[i + 1].lightFlags = 0;
|
||||
poly->verts[i + 1].texCoord[0] = s;
|
||||
poly->verts[i + 1].texCoord[1] = t;
|
||||
VectorCopy(normal, poly->verts[i + 1].normal);
|
||||
poly->verts[i + 1].lightFlags = 0;
|
||||
}
|
||||
|
||||
VectorScale(total, (1.0 / numverts), poly->vertices[0].pos);
|
||||
poly->vertices[0].texCoord[0] = total_s / numverts;
|
||||
poly->vertices[0].texCoord[1] = total_t / numverts;
|
||||
VectorCopy(normal, poly->vertices[0].normal);
|
||||
VectorScale(total, (1.0 / numverts), poly->verts[0].pos);
|
||||
poly->verts[0].texCoord[0] = total_s / numverts;
|
||||
poly->verts[0].texCoord[1] = total_t / numverts;
|
||||
VectorCopy(normal, poly->verts[0].normal);
|
||||
|
||||
/* copy first vertex to last */
|
||||
//memcpy(poly->vertices[i + 1], poly->vertices[1], sizeof(poly->vertices[0]));
|
||||
poly->vertices[i + 1] = poly->vertices[1];
|
||||
//memcpy(poly->verts[i + 1], poly->verts[1], sizeof(poly->verts[0]));
|
||||
poly->verts[i + 1] = poly->verts[1];
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -198,12 +198,12 @@ GL3_SubdivideSurface(msurface_t *fa, gl3model_t* loadmodel)
|
|||
}
|
||||
|
||||
/*
|
||||
* Does a water warp on the pre-fragmented glpoly_t chain
|
||||
* Does a water warp on the pre-fragmented mpoly_t chain
|
||||
*/
|
||||
void
|
||||
GL3_EmitWaterPolys(msurface_t *fa)
|
||||
{
|
||||
glpoly_t *bp;
|
||||
mpoly_t *bp;
|
||||
float scroll = 0.0f;
|
||||
|
||||
if (fa->texinfo->flags & SURF_FLOWING)
|
||||
|
@ -244,7 +244,7 @@ GL3_EmitWaterPolys(msurface_t *fa)
|
|||
|
||||
for (bp = fa->polys; bp != NULL; bp = bp->next)
|
||||
{
|
||||
GL3_BufferAndDraw3D(bp->vertices, bp->numverts, GL_TRIANGLE_FAN);
|
||||
GL3_BufferAndDraw3D(bp->verts, bp->numverts, GL_TRIANGLE_FAN);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -565,14 +565,14 @@ GL3_AddSkySurface(msurface_t *fa)
|
|||
{
|
||||
int i;
|
||||
vec3_t verts[MAX_CLIP_VERTS];
|
||||
glpoly_t *p;
|
||||
mpoly_t *p;
|
||||
|
||||
/* calculate vertex values for sky box */
|
||||
for (p = fa->polys; p; p = p->next)
|
||||
{
|
||||
for (i = 0; i < p->numverts; i++)
|
||||
{
|
||||
VectorSubtract(p->vertices[i].pos, gl3_origin, verts[i]);
|
||||
VectorSubtract(p->verts[i].pos, gl3_origin, verts[i]);
|
||||
}
|
||||
|
||||
ClipSkyPolygon(p->numverts, verts[0], 0);
|
||||
|
|
|
@ -36,15 +36,6 @@ typedef struct gl3_alias_vtx_s {
|
|||
|
||||
/* in memory representation */
|
||||
|
||||
typedef struct glpoly_s
|
||||
{
|
||||
struct glpoly_s *next;
|
||||
struct glpoly_s *chain;
|
||||
int numverts;
|
||||
int flags; /* for SURF_UNDERWATER (not needed anymore?) */
|
||||
mvtx_t vertices[4]; /* variable sized */
|
||||
} glpoly_t;
|
||||
|
||||
typedef struct msurface_s
|
||||
{
|
||||
int visframe; /* should be drawn when node is crossed */
|
||||
|
@ -62,7 +53,7 @@ typedef struct msurface_s
|
|||
int light_s, light_t; /* gl lightmap coordinates */
|
||||
int dlight_s, dlight_t; /* gl lightmap coordinates for dynamic lightmaps */
|
||||
|
||||
glpoly_t *polys; /* multiple if warped */
|
||||
mpoly_t *polys; /* multiple if warped */
|
||||
struct msurface_s *texturechain;
|
||||
// struct msurface_s *lightmapchain; not used/needed anymore
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ GL4_LM_BuildPolygonFromSurface(gl4model_t *currentmodel, msurface_t *fa)
|
|||
medge_t *pedges, *r_pedge;
|
||||
float *vec;
|
||||
float s, t;
|
||||
glpoly_t *poly;
|
||||
mpoly_t *poly;
|
||||
vec3_t total;
|
||||
vec3_t normal;
|
||||
|
||||
|
@ -135,7 +135,7 @@ GL4_LM_BuildPolygonFromSurface(gl4model_t *currentmodel, msurface_t *fa)
|
|||
VectorClear(total);
|
||||
|
||||
/* draw texture */
|
||||
poly = Hunk_Alloc(sizeof(glpoly_t) +
|
||||
poly = Hunk_Alloc(sizeof(mpoly_t) +
|
||||
(lnumverts - 4) * sizeof(mvtx_t));
|
||||
poly->next = fa->polys;
|
||||
poly->flags = fa->flags;
|
||||
|
@ -153,7 +153,7 @@ GL4_LM_BuildPolygonFromSurface(gl4model_t *currentmodel, msurface_t *fa)
|
|||
|
||||
for (i = 0; i < lnumverts; i++)
|
||||
{
|
||||
mvtx_t* vert = &poly->vertices[i];
|
||||
mvtx_t* vert = &poly->verts[i];
|
||||
|
||||
lindex = currentmodel->surfedges[fa->firstedge + i];
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ static int calcTexinfoAndFacesSize(byte *mod_base, const lump_t *fl, const lump_
|
|||
|
||||
// GL4_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
|
||||
// for each (pot. recursive) call to R_SubdividePolygon():
|
||||
// sizeof(glpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t)
|
||||
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t)
|
||||
|
||||
// this is tricky, how much is allocated depends on the size of the surface
|
||||
// which we don't know (we'd need the vertices etc to know, but we can't load
|
||||
|
@ -301,8 +301,8 @@ static int calcTexinfoAndFacesSize(byte *mod_base, const lump_t *fl, const lump_
|
|||
else
|
||||
{
|
||||
// GL4_LM_BuildPolygonFromSurface(out);
|
||||
// => poly = Hunk_Alloc(sizeof(glpoly_t) + (numverts - 4) * sizeof(mvtx_t));
|
||||
int polySize = sizeof(glpoly_t) + (numverts - 4) * sizeof(mvtx_t);
|
||||
// => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t));
|
||||
int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t);
|
||||
polySize = (polySize + 31) & ~31;
|
||||
ret += polySize;
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ SetLightFlags(msurface_t *surf)
|
|||
lightFlags = surf->dlightbits;
|
||||
}
|
||||
|
||||
mvtx_t* verts = surf->polys->vertices;
|
||||
mvtx_t* verts = surf->polys->verts;
|
||||
|
||||
int numVerts = surf->polys->numverts;
|
||||
for(int i=0; i<numVerts; ++i)
|
||||
|
@ -155,7 +155,7 @@ SetAllLightFlags(msurface_t *surf)
|
|||
{
|
||||
unsigned int lightFlags = 0xffffffff;
|
||||
|
||||
mvtx_t* verts = surf->polys->vertices;
|
||||
mvtx_t* verts = surf->polys->verts;
|
||||
|
||||
int numVerts = surf->polys->numverts;
|
||||
for(int i=0; i<numVerts; ++i)
|
||||
|
@ -167,18 +167,18 @@ SetAllLightFlags(msurface_t *surf)
|
|||
void
|
||||
GL4_DrawGLPoly(msurface_t *fa)
|
||||
{
|
||||
glpoly_t *p = fa->polys;
|
||||
mpoly_t *p = fa->polys;
|
||||
|
||||
GL4_BindVAO(gl4state.vao3D);
|
||||
GL4_BindVBO(gl4state.vbo3D);
|
||||
|
||||
GL4_BufferAndDraw3D(p->vertices, p->numverts, GL_TRIANGLE_FAN);
|
||||
GL4_BufferAndDraw3D(p->verts, p->numverts, GL_TRIANGLE_FAN);
|
||||
}
|
||||
|
||||
void
|
||||
GL4_DrawGLFlowingPoly(msurface_t *fa)
|
||||
{
|
||||
glpoly_t *p;
|
||||
mpoly_t *p;
|
||||
float scroll;
|
||||
|
||||
p = fa->polys;
|
||||
|
@ -199,7 +199,7 @@ GL4_DrawGLFlowingPoly(msurface_t *fa)
|
|||
GL4_BindVAO(gl4state.vao3D);
|
||||
GL4_BindVBO(gl4state.vbo3D);
|
||||
|
||||
GL4_BufferAndDraw3D(p->vertices, p->numverts, GL_TRIANGLE_FAN);
|
||||
GL4_BufferAndDraw3D(p->verts, p->numverts, GL_TRIANGLE_FAN);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -208,7 +208,7 @@ DrawTriangleOutlines(void)
|
|||
STUB_ONCE("TODO: Implement for r_showtris support!");
|
||||
#if 0
|
||||
int i, j;
|
||||
glpoly_t *p;
|
||||
mpoly_t *p;
|
||||
|
||||
if (!r_showtris->value)
|
||||
{
|
||||
|
@ -238,10 +238,10 @@ DrawTriangleOutlines(void)
|
|||
|
||||
for (k=0; k<3; k++)
|
||||
{
|
||||
vtx[0+k] = p->vertices [ 0 ][ k ];
|
||||
vtx[3+k] = p->vertices [ j - 1 ][ k ];
|
||||
vtx[6+k] = p->vertices [ j ][ k ];
|
||||
vtx[9+k] = p->vertices [ 0 ][ k ];
|
||||
vtx[0+k] = p->verts [ 0 ][ k ];
|
||||
vtx[3+k] = p->verts [ j - 1 ][ k ];
|
||||
vtx[6+k] = p->verts [ j ][ k ];
|
||||
vtx[9+k] = p->verts [ 0 ][ k ];
|
||||
}
|
||||
|
||||
glEnableClientState( GL_VERTEX_ARRAY );
|
||||
|
|
|
@ -40,7 +40,7 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
|||
int f, b;
|
||||
float dist[64];
|
||||
float frac;
|
||||
glpoly_t *poly;
|
||||
mpoly_t *poly;
|
||||
float s, t;
|
||||
vec3_t total;
|
||||
float total_s, total_t;
|
||||
|
@ -126,7 +126,7 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
|||
}
|
||||
|
||||
/* add a point in the center to help keep warp valid */
|
||||
poly = Hunk_Alloc(sizeof(glpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t));
|
||||
poly = Hunk_Alloc(sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t));
|
||||
poly->next = warpface->polys;
|
||||
warpface->polys = poly;
|
||||
poly->numverts = numverts + 2;
|
||||
|
@ -136,7 +136,7 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
|||
|
||||
for (i = 0; i < numverts; i++, verts += 3)
|
||||
{
|
||||
VectorCopy(verts, poly->vertices[i + 1].pos);
|
||||
VectorCopy(verts, poly->verts[i + 1].pos);
|
||||
s = DotProduct(verts, warpface->texinfo->vecs[0]);
|
||||
t = DotProduct(verts, warpface->texinfo->vecs[1]);
|
||||
|
||||
|
@ -144,20 +144,20 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
|||
total_t += t;
|
||||
VectorAdd(total, verts, total);
|
||||
|
||||
poly->vertices[i + 1].texCoord[0] = s;
|
||||
poly->vertices[i + 1].texCoord[1] = t;
|
||||
VectorCopy(normal, poly->vertices[i + 1].normal);
|
||||
poly->vertices[i + 1].lightFlags = 0;
|
||||
poly->verts[i + 1].texCoord[0] = s;
|
||||
poly->verts[i + 1].texCoord[1] = t;
|
||||
VectorCopy(normal, poly->verts[i + 1].normal);
|
||||
poly->verts[i + 1].lightFlags = 0;
|
||||
}
|
||||
|
||||
VectorScale(total, (1.0 / numverts), poly->vertices[0].pos);
|
||||
poly->vertices[0].texCoord[0] = total_s / numverts;
|
||||
poly->vertices[0].texCoord[1] = total_t / numverts;
|
||||
VectorCopy(normal, poly->vertices[0].normal);
|
||||
VectorScale(total, (1.0 / numverts), poly->verts[0].pos);
|
||||
poly->verts[0].texCoord[0] = total_s / numverts;
|
||||
poly->verts[0].texCoord[1] = total_t / numverts;
|
||||
VectorCopy(normal, poly->verts[0].normal);
|
||||
|
||||
/* copy first vertex to last */
|
||||
//memcpy(poly->vertices[i + 1], poly->vertices[1], sizeof(poly->vertices[0]));
|
||||
poly->vertices[i + 1] = poly->vertices[1];
|
||||
//memcpy(poly->verts[i + 1], poly->verts[1], sizeof(poly->verts[0]));
|
||||
poly->verts[i + 1] = poly->verts[1];
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -198,12 +198,12 @@ GL4_SubdivideSurface(msurface_t *fa, gl4model_t* loadmodel)
|
|||
}
|
||||
|
||||
/*
|
||||
* Does a water warp on the pre-fragmented glpoly_t chain
|
||||
* Does a water warp on the pre-fragmented mpoly_t chain
|
||||
*/
|
||||
void
|
||||
GL4_EmitWaterPolys(msurface_t *fa)
|
||||
{
|
||||
glpoly_t *bp;
|
||||
mpoly_t *bp;
|
||||
float scroll = 0.0f;
|
||||
|
||||
if (fa->texinfo->flags & SURF_FLOWING)
|
||||
|
@ -244,7 +244,7 @@ GL4_EmitWaterPolys(msurface_t *fa)
|
|||
|
||||
for (bp = fa->polys; bp != NULL; bp = bp->next)
|
||||
{
|
||||
GL4_BufferAndDraw3D(bp->vertices, bp->numverts, GL_TRIANGLE_FAN);
|
||||
GL4_BufferAndDraw3D(bp->verts, bp->numverts, GL_TRIANGLE_FAN);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -565,14 +565,14 @@ GL4_AddSkySurface(msurface_t *fa)
|
|||
{
|
||||
int i;
|
||||
vec3_t verts[MAX_CLIP_VERTS];
|
||||
glpoly_t *p;
|
||||
mpoly_t *p;
|
||||
|
||||
/* calculate vertex values for sky box */
|
||||
for (p = fa->polys; p; p = p->next)
|
||||
{
|
||||
for (i = 0; i < p->numverts; i++)
|
||||
{
|
||||
VectorSubtract(p->vertices[i].pos, gl4_origin, verts[i]);
|
||||
VectorSubtract(p->verts[i].pos, gl4_origin, verts[i]);
|
||||
}
|
||||
|
||||
ClipSkyPolygon(p->numverts, verts[0], 0);
|
||||
|
|
|
@ -36,15 +36,6 @@ typedef struct gl4_alias_vtx_s {
|
|||
|
||||
/* in memory representation */
|
||||
|
||||
typedef struct glpoly_s
|
||||
{
|
||||
struct glpoly_s *next;
|
||||
struct glpoly_s *chain;
|
||||
int numverts;
|
||||
int flags; /* for SURF_UNDERWATER (not needed anymore?) */
|
||||
mvtx_t vertices[4]; /* variable sized */
|
||||
} glpoly_t;
|
||||
|
||||
typedef struct msurface_s
|
||||
{
|
||||
int visframe; /* should be drawn when node is crossed */
|
||||
|
@ -62,7 +53,7 @@ typedef struct msurface_s
|
|||
int light_s, light_t; /* gl lightmap coordinates */
|
||||
int dlight_s, dlight_t; /* gl lightmap coordinates for dynamic lightmaps */
|
||||
|
||||
glpoly_t *polys; /* multiple if warped */
|
||||
mpoly_t *polys; /* multiple if warped */
|
||||
struct msurface_s *texturechain;
|
||||
// struct msurface_s *lightmapchain; not used/needed anymore
|
||||
|
||||
|
|
|
@ -1,18 +1,6 @@
|
|||
#define VERTEXSIZE 7
|
||||
|
||||
/* in memory representation */
|
||||
|
||||
typedef float glvk_vtx_t[VERTEXSIZE];
|
||||
|
||||
typedef struct mpoly_s
|
||||
{
|
||||
struct mpoly_s *next;
|
||||
struct mpoly_s *chain;
|
||||
int numverts;
|
||||
int flags; /* for SURF_UNDERWATER (not needed anymore?) */
|
||||
glvk_vtx_t verts[4]; /* variable sized (xyz s1t1 s2t2) */
|
||||
} mpoly_t;
|
||||
|
||||
typedef struct msurface_s
|
||||
{
|
||||
int visframe; /* should be drawn when node is crossed */
|
||||
|
|
|
@ -191,6 +191,15 @@ typedef struct mvtx_s {
|
|||
int lightFlags; /* bit i set means: dynlight i affects surface */
|
||||
} mvtx_t;
|
||||
|
||||
typedef struct mpoly_s
|
||||
{
|
||||
struct mpoly_s *next;
|
||||
struct mpoly_s *chain;
|
||||
int numverts;
|
||||
int flags; /* for SURF_UNDERWATER (not needed anymore?) */
|
||||
mvtx_t verts[4]; /* variable sized */
|
||||
} mpoly_t;
|
||||
|
||||
/* BSPX Light octtree */
|
||||
#define LGNODE_LEAF (1u<<31)
|
||||
#define LGNODE_MISSING (1u<<30)
|
||||
|
|
|
@ -201,20 +201,20 @@ void Vk_ScreenShot_f (void);
|
|||
void Vk_Strings_f(void);
|
||||
void Vk_Mem_f(void);
|
||||
|
||||
void R_DrawAliasModel (entity_t *currententity, model_t *currentmodel);
|
||||
void R_DrawBrushModel (entity_t *currententity, model_t *currentmodel);
|
||||
void R_DrawSpriteModel (entity_t *currententity, model_t *currentmodel);
|
||||
void R_DrawBeam (entity_t *currententity);
|
||||
void R_DrawWorld (void);
|
||||
void R_RenderDlights (void);
|
||||
void R_SetCacheState( msurface_t *surf );
|
||||
void R_BuildLightMap (msurface_t *surf, byte *dest, int stride);
|
||||
void R_DrawAlphaSurfaces (void);
|
||||
void RE_InitParticleTexture (void);
|
||||
void Draw_InitLocal (void);
|
||||
void Vk_SubdivideSurface (msurface_t *fa, model_t *loadmodel);
|
||||
void R_RotateForEntity (entity_t *e, float *mvMatrix);
|
||||
void R_MarkLeaves (void);
|
||||
void R_DrawAliasModel(entity_t *currententity, model_t *currentmodel);
|
||||
void R_DrawBrushModel(entity_t *currententity, const model_t *currentmodel);
|
||||
void R_DrawSpriteModel(entity_t *currententity, model_t *currentmodel);
|
||||
void R_DrawBeam(entity_t *currententity);
|
||||
void R_DrawWorld(void);
|
||||
void R_RenderDlights(void);
|
||||
void R_SetCacheState(msurface_t *surf );
|
||||
void R_BuildLightMap(msurface_t *surf, byte *dest, int stride);
|
||||
void R_DrawAlphaSurfaces(void);
|
||||
void RE_InitParticleTexture(void);
|
||||
void Draw_InitLocal(void);
|
||||
void Vk_SubdivideSurface(msurface_t *fa, model_t *loadmodel);
|
||||
void R_RotateForEntity(entity_t *e, float *mvMatrix);
|
||||
void R_MarkLeaves(void);
|
||||
|
||||
void EmitWaterPolys (msurface_t *fa, image_t *texture,
|
||||
float *modelMatrix, const float *color,
|
||||
|
@ -248,7 +248,7 @@ void Vk_TextureMode( char *string );
|
|||
void Vk_LmapTextureMode( char *string );
|
||||
void Vk_ImageList_f (void);
|
||||
|
||||
void Vk_BuildPolygonFromSurface(msurface_t *fa, model_t *currentmodel);
|
||||
void Vk_BuildPolygonFromSurface(model_t *currentmodel, msurface_t *fa);
|
||||
void Vk_CreateSurfaceLightmap (msurface_t *surf);
|
||||
void Vk_EndBuildingLightmaps (void);
|
||||
void Vk_BeginBuildingLightmaps (model_t *m);
|
||||
|
@ -345,7 +345,7 @@ qboolean Vkimp_CreateSurface(SDL_Window *window);
|
|||
|
||||
// buffers reallocate
|
||||
typedef struct {
|
||||
float vertex[3];
|
||||
vec3_t vertex;
|
||||
float texCoord[2];
|
||||
} polyvert_t;
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ BRUSH MODELS
|
|||
==============================================================================
|
||||
*/
|
||||
|
||||
|
||||
//
|
||||
// in memory representation
|
||||
//
|
||||
|
|
|
@ -264,7 +264,7 @@ calcTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl
|
|||
|
||||
// Vk_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
|
||||
// for each (pot. recursive) call to R_SubdividePolygon():
|
||||
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(glvk_vtx_t)
|
||||
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t)
|
||||
|
||||
// this is tricky, how much is allocated depends on the size of the surface
|
||||
// which we don't know (we'd need the vertices etc to know, but we can't load
|
||||
|
@ -276,8 +276,8 @@ calcTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl
|
|||
else
|
||||
{
|
||||
// Vk_BuildPolygonFromSurface(out);
|
||||
// => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(glvk_vtx_t));
|
||||
int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(glvk_vtx_t);
|
||||
// => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t));
|
||||
int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t);
|
||||
polySize = (polySize + 31) & ~31;
|
||||
ret += polySize;
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t
|
|||
|
||||
// Vk_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
|
||||
// for each (pot. recursive) call to R_SubdividePolygon():
|
||||
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(glvk_vtx_t)
|
||||
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t)
|
||||
|
||||
// this is tricky, how much is allocated depends on the size of the surface
|
||||
// which we don't know (we'd need the vertices etc to know, but we can't load
|
||||
|
@ -352,8 +352,8 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t
|
|||
else
|
||||
{
|
||||
// Vk_BuildPolygonFromSurface(out);
|
||||
// => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(glvk_vtx_t));
|
||||
int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(glvk_vtx_t);
|
||||
// => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t));
|
||||
int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t);
|
||||
polySize = (polySize + 31) & ~31;
|
||||
ret += polySize;
|
||||
}
|
||||
|
@ -546,7 +546,7 @@ Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
|
|||
|
||||
if (!(out->texinfo->flags & SURF_WARP))
|
||||
{
|
||||
Vk_BuildPolygonFromSurface(out, loadmodel);
|
||||
Vk_BuildPolygonFromSurface(loadmodel, out);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -669,7 +669,7 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
|
|||
|
||||
if (!(out->texinfo->flags & SURF_WARP))
|
||||
{
|
||||
Vk_BuildPolygonFromSurface(out, loadmodel);
|
||||
Vk_BuildPolygonFromSurface(loadmodel, out);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -20,82 +20,140 @@
|
|||
*
|
||||
* =======================================================================
|
||||
*
|
||||
* Sky and water polygons
|
||||
* Warps. Used on water surfaces und for skybox rotation.
|
||||
*
|
||||
* =======================================================================
|
||||
*/
|
||||
|
||||
#include "header/local.h"
|
||||
|
||||
static float skyrotate;
|
||||
static int skyautorotate;
|
||||
static vec3_t skyaxis;
|
||||
static image_t *sky_images[6];
|
||||
#define SUBDIVIDE_SIZE 64
|
||||
#define ON_EPSILON 0.1 /* point on plane side epsilon */
|
||||
#define MAX_CLIP_VERTS 64
|
||||
|
||||
#define SUBDIVIDE_SIZE 64
|
||||
static float skyrotate;
|
||||
static int skyautorotate;
|
||||
static vec3_t skyaxis;
|
||||
static image_t *sky_images[6];
|
||||
static int skytexorder[6] = {0, 2, 1, 3, 4, 5};
|
||||
|
||||
static vec3_t skyclip[6] = {
|
||||
{1, 1, 0},
|
||||
{1, -1, 0},
|
||||
{0, -1, 1},
|
||||
{0, 1, 1},
|
||||
{1, 0, 1},
|
||||
{-1, 0, 1}
|
||||
};
|
||||
|
||||
static int st_to_vec[6][3] = {
|
||||
{3, -1, 2},
|
||||
{-3, 1, 2},
|
||||
|
||||
{1, 3, 2},
|
||||
{-1, -3, 2},
|
||||
|
||||
{-2, -1, 3}, /* 0 degrees yaw, look straight up */
|
||||
{2, -1, -3} /* look straight down */
|
||||
};
|
||||
|
||||
static int vec_to_st[6][3] = {
|
||||
{-2, 3, 1},
|
||||
{2, 3, -1},
|
||||
|
||||
{1, 3, 2},
|
||||
{-1, 3, -2},
|
||||
|
||||
{-2, -1, 3},
|
||||
{-2, 1, -3}
|
||||
};
|
||||
|
||||
static float skymins[2][6], skymaxs[2][6];
|
||||
static float sky_min, sky_max;
|
||||
|
||||
static void
|
||||
R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
||||
{
|
||||
int i, j, k;
|
||||
vec3_t mins, maxs;
|
||||
float *v;
|
||||
vec3_t front[64], back[64];
|
||||
int f, b;
|
||||
float dist[64];
|
||||
float frac;
|
||||
mpoly_t *poly;
|
||||
vec3_t total;
|
||||
float total_s, total_t;
|
||||
int i, j, k;
|
||||
vec3_t mins, maxs;
|
||||
float *v;
|
||||
vec3_t front[64], back[64];
|
||||
int f, b;
|
||||
float dist[64];
|
||||
float frac;
|
||||
mpoly_t *poly;
|
||||
vec3_t total;
|
||||
float total_s, total_t;
|
||||
|
||||
if (numverts > 60)
|
||||
ri.Sys_Error (ERR_DROP, "%s: numverts = %i", __func__, numverts);
|
||||
{
|
||||
ri.Sys_Error(ERR_DROP, "%s: numverts = %i", __func__, numverts);
|
||||
}
|
||||
|
||||
R_BoundPoly(numverts, verts, mins, maxs);
|
||||
|
||||
for (i=0 ; i<3 ; i++)
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
float m;
|
||||
float m;
|
||||
|
||||
m = (mins[i] + maxs[i]) * 0.5;
|
||||
m = SUBDIVIDE_SIZE * floor (m/SUBDIVIDE_SIZE + 0.5);
|
||||
m = SUBDIVIDE_SIZE * floor(m / SUBDIVIDE_SIZE + 0.5);
|
||||
|
||||
if (maxs[i] - m < 8)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m - mins[i] < 8)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// cut it
|
||||
/* cut it */
|
||||
v = verts + i;
|
||||
for (j=0 ; j<numverts ; j++, v+= 3)
|
||||
dist[j] = *v - m;
|
||||
|
||||
// wrap cases
|
||||
for (j = 0; j < numverts; j++, v += 3)
|
||||
{
|
||||
dist[j] = *v - m;
|
||||
}
|
||||
|
||||
/* wrap cases */
|
||||
dist[j] = dist[0];
|
||||
v-=i;
|
||||
v -= i;
|
||||
VectorCopy(verts, v);
|
||||
|
||||
f = b = 0;
|
||||
v = verts;
|
||||
for (j=0 ; j<numverts ; j++, v+= 3)
|
||||
|
||||
for (j = 0; j < numverts; j++, v += 3)
|
||||
{
|
||||
if (dist[j] >= 0)
|
||||
{
|
||||
VectorCopy(v, front[f]);
|
||||
f++;
|
||||
}
|
||||
|
||||
if (dist[j] <= 0)
|
||||
{
|
||||
VectorCopy(v, back[b]);
|
||||
b++;
|
||||
}
|
||||
if (dist[j] == 0 || dist[j+1] == 0)
|
||||
continue;
|
||||
if ( (dist[j] > 0) != (dist[j+1] > 0) )
|
||||
|
||||
if ((dist[j] == 0) || (dist[j + 1] == 0))
|
||||
{
|
||||
// clip point
|
||||
frac = dist[j] / (dist[j] - dist[j+1]);
|
||||
for (k=0 ; k<3 ; k++)
|
||||
front[f][k] = back[b][k] = v[k] + frac*(v[3+k] - v[k]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((dist[j] > 0) != (dist[j + 1] > 0))
|
||||
{
|
||||
/* clip point */
|
||||
frac = dist[j] / (dist[j] - dist[j + 1]);
|
||||
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
front[f][k] = back[b][k] = v[k] + frac * (v[3 + k] - v[k]);
|
||||
}
|
||||
|
||||
f++;
|
||||
b++;
|
||||
}
|
||||
|
@ -106,68 +164,70 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
|
|||
return;
|
||||
}
|
||||
|
||||
// add a point in the center to help keep warp valid
|
||||
poly = Hunk_Alloc (sizeof(mpoly_t) + ((numverts-4)+2) * sizeof(glvk_vtx_t));
|
||||
/* add a point in the center to help keep warp valid */
|
||||
poly = Hunk_Alloc(sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t));
|
||||
poly->next = warpface->polys;
|
||||
warpface->polys = poly;
|
||||
poly->numverts = numverts+2;
|
||||
VectorClear (total);
|
||||
poly->numverts = numverts + 2;
|
||||
VectorClear(total);
|
||||
total_s = 0;
|
||||
total_t = 0;
|
||||
for (i=0 ; i<numverts ; i++, verts+= 3)
|
||||
|
||||
for (i = 0; i < numverts; i++, verts += 3)
|
||||
{
|
||||
float s, t;
|
||||
|
||||
VectorCopy(verts, poly->verts[i+1]);
|
||||
VectorCopy(verts, poly->verts[i + 1].pos);
|
||||
s = DotProduct(verts, warpface->texinfo->vecs[0]);
|
||||
t = DotProduct(verts, warpface->texinfo->vecs[1]);
|
||||
|
||||
total_s += s;
|
||||
total_t += t;
|
||||
VectorAdd (total, verts, total);
|
||||
VectorAdd(total, verts, total);
|
||||
|
||||
poly->verts[i+1][3] = s;
|
||||
poly->verts[i+1][4] = t;
|
||||
poly->verts[i + 1].texCoord[0] = s;
|
||||
poly->verts[i + 1].texCoord[1] = t;
|
||||
}
|
||||
|
||||
VectorScale(total, (1.0/numverts), poly->verts[0]);
|
||||
poly->verts[0][3] = total_s/numverts;
|
||||
poly->verts[0][4] = total_t/numverts;
|
||||
VectorScale(total, (1.0 / numverts), poly->verts[0].pos);
|
||||
poly->verts[0].texCoord[0] = total_s / numverts;
|
||||
poly->verts[0].texCoord[1] = total_t / numverts;
|
||||
|
||||
// copy first vertex to last
|
||||
memmove (poly->verts[i+1], poly->verts[1], sizeof(poly->verts[0]));
|
||||
/* copy first vertex to last */
|
||||
memcpy(&poly->verts[i + 1], &poly->verts[1], sizeof(mvtx_t));
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
Vk_SubdivideSurface
|
||||
|
||||
Breaks a polygon up along axial 64 unit
|
||||
boundaries so that turbulent and sky warps
|
||||
can be done reasonably.
|
||||
================
|
||||
*/
|
||||
void Vk_SubdivideSurface (msurface_t *fa, model_t *loadmodel)
|
||||
* Breaks a polygon up along axial 64 unit
|
||||
* boundaries so that turbulent and sky warps
|
||||
* can be done reasonably.
|
||||
*/
|
||||
void
|
||||
Vk_SubdivideSurface (msurface_t *fa, model_t *loadmodel)
|
||||
{
|
||||
vec3_t verts[64];
|
||||
int numverts;
|
||||
int i;
|
||||
float *vec;
|
||||
vec3_t verts[64];
|
||||
int numverts;
|
||||
int i;
|
||||
float *vec;
|
||||
|
||||
//
|
||||
// convert edges back to a normal polygon
|
||||
//
|
||||
/* convert edges back to a normal polygon */
|
||||
numverts = 0;
|
||||
for (i=0 ; i<fa->numedges ; i++)
|
||||
|
||||
for (i = 0; i < fa->numedges; i++)
|
||||
{
|
||||
int lindex;
|
||||
|
||||
lindex = loadmodel->surfedges[fa->firstedge + i];
|
||||
|
||||
if (lindex > 0)
|
||||
{
|
||||
vec = loadmodel->vertexes[loadmodel->edges[lindex].v[0]].position;
|
||||
}
|
||||
else
|
||||
{
|
||||
vec = loadmodel->vertexes[loadmodel->edges[-lindex].v[1]].position;
|
||||
}
|
||||
|
||||
VectorCopy(vec, verts[numverts]);
|
||||
numverts++;
|
||||
}
|
||||
|
@ -175,22 +235,16 @@ void Vk_SubdivideSurface (msurface_t *fa, model_t *loadmodel)
|
|||
R_SubdividePolygon(numverts, verts[0], fa);
|
||||
}
|
||||
|
||||
//=========================================================
|
||||
|
||||
/*
|
||||
=============
|
||||
EmitWaterPolys
|
||||
|
||||
Does a water warp on the pre-fragmented mpoly_t chain
|
||||
=============
|
||||
*/
|
||||
* Does a water warp on the pre-fragmented mpoly_t chain
|
||||
*/
|
||||
void
|
||||
EmitWaterPolys (msurface_t *fa, image_t *texture, float *modelMatrix,
|
||||
EmitWaterPolys(msurface_t *fa, image_t *texture, float *modelMatrix,
|
||||
const float *color, qboolean solid_surface)
|
||||
{
|
||||
mpoly_t *p, *bp;
|
||||
float *v;
|
||||
int i;
|
||||
mpoly_t *p, *bp;
|
||||
mvtx_t *v;
|
||||
int i;
|
||||
|
||||
struct {
|
||||
float model[16];
|
||||
|
@ -206,9 +260,13 @@ EmitWaterPolys (msurface_t *fa, image_t *texture, float *modelMatrix,
|
|||
polyUbo.time = r_newrefdef.time;
|
||||
|
||||
if (fa->texinfo->flags & SURF_FLOWING)
|
||||
polyUbo.scroll = (-64 * ((r_newrefdef.time*0.5) - (int)(r_newrefdef.time*0.5))) / 64.f;
|
||||
{
|
||||
polyUbo.scroll = (-64 * ((r_newrefdef.time * 0.5) - (int)(r_newrefdef.time * 0.5))) / 64.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
polyUbo.scroll = 0;
|
||||
}
|
||||
|
||||
if (modelMatrix)
|
||||
{
|
||||
|
@ -270,13 +328,11 @@ EmitWaterPolys (msurface_t *fa, image_t *texture, float *modelMatrix,
|
|||
ri.Sys_Error(ERR_FATAL, "%s: can't allocate memory", __func__);
|
||||
}
|
||||
|
||||
for (i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE)
|
||||
for (i = 0, v = p->verts; i < p->numverts; i++, v++)
|
||||
{
|
||||
verts_buffer[i].vertex[0] = v[0];
|
||||
verts_buffer[i].vertex[1] = v[1];
|
||||
verts_buffer[i].vertex[2] = v[2];
|
||||
verts_buffer[i].texCoord[0] = v[3] / 64.f;
|
||||
verts_buffer[i].texCoord[1] = v[4] / 64.f;
|
||||
VectorCopy(v->pos, verts_buffer[i].vertex);
|
||||
verts_buffer[i].texCoord[0] = v->texCoord[0] / 64.f;
|
||||
verts_buffer[i].texCoord[1] = v->texCoord[1] / 64.f;
|
||||
}
|
||||
|
||||
uint8_t *vertData = QVk_GetVertexBuffer(sizeof(polyvert_t) * p->numverts, &vbo, &vboOffset);
|
||||
|
@ -291,52 +347,8 @@ EmitWaterPolys (msurface_t *fa, image_t *texture, float *modelMatrix,
|
|||
|
||||
//===================================================================
|
||||
|
||||
|
||||
static vec3_t skyclip[6] = {
|
||||
{1,1,0},
|
||||
{1,-1,0},
|
||||
{0,-1,1},
|
||||
{0,1,1},
|
||||
{1,0,1},
|
||||
{-1,0,1}
|
||||
};
|
||||
|
||||
// 1 = s, 2 = t, 3 = 2048
|
||||
static int st_to_vec[6][3] =
|
||||
{
|
||||
{3,-1,2},
|
||||
{-3,1,2},
|
||||
|
||||
{1,3,2},
|
||||
{-1,-3,2},
|
||||
|
||||
{-2,-1,3}, // 0 degrees yaw, look straight up
|
||||
{2,-1,-3} // look straight down
|
||||
|
||||
// {-1,2,3},
|
||||
// {1,2,-3}
|
||||
};
|
||||
|
||||
// s = [0]/[2], t = [1]/[2]
|
||||
static int vec_to_st[6][3] =
|
||||
{
|
||||
{-2,3,1},
|
||||
{2,3,-1},
|
||||
|
||||
{1,3,2},
|
||||
{-1,3,-2},
|
||||
|
||||
{-2,-1,3},
|
||||
{-2,1,-3}
|
||||
|
||||
// {-1,2,3},
|
||||
// {1,2,-3}
|
||||
};
|
||||
|
||||
static float skymins[2][6], skymaxs[2][6];
|
||||
static float sky_min, sky_max;
|
||||
|
||||
static void DrawSkyPolygon (int nump, vec3_t vecs)
|
||||
static void
|
||||
DrawSkyPolygon(int nump, vec3_t vecs)
|
||||
{
|
||||
int i;
|
||||
vec3_t v, av;
|
||||
|
@ -409,25 +421,25 @@ static void DrawSkyPolygon (int nump, vec3_t vecs)
|
|||
}
|
||||
}
|
||||
|
||||
#define ON_EPSILON 0.1 // point on plane side epsilon
|
||||
#define MAX_CLIP_VERTS 64
|
||||
static void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
|
||||
static void
|
||||
ClipSkyPolygon(int nump, vec3_t vecs, int stage)
|
||||
{
|
||||
float *norm;
|
||||
float *v;
|
||||
qboolean front, back;
|
||||
float d, e;
|
||||
float dists[MAX_CLIP_VERTS];
|
||||
int sides[MAX_CLIP_VERTS];
|
||||
vec3_t newv[2][MAX_CLIP_VERTS];
|
||||
int newc[2];
|
||||
int i, j;
|
||||
float *norm;
|
||||
float *v;
|
||||
qboolean front, back;
|
||||
float d, e;
|
||||
float dists[MAX_CLIP_VERTS];
|
||||
int sides[MAX_CLIP_VERTS];
|
||||
vec3_t newv[2][MAX_CLIP_VERTS];
|
||||
int newc[2];
|
||||
int i, j;
|
||||
|
||||
if (nump > MAX_CLIP_VERTS-2)
|
||||
ri.Sys_Error (ERR_DROP, "%s: MAX_CLIP_VERTS", __func__);
|
||||
if (nump > MAX_CLIP_VERTS - 2)
|
||||
ri.Sys_Error(ERR_DROP, "%s: MAX_CLIP_VERTS", __func__);
|
||||
if (stage == 6)
|
||||
{ // fully clipped, so draw it
|
||||
DrawSkyPolygon (nump, vecs);
|
||||
{
|
||||
/* fully clipped, so draw it */
|
||||
DrawSkyPolygon(nump, vecs);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -436,6 +448,7 @@ static void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
|
|||
for (i=0, v = vecs ; i<nump ; i++, v+=3)
|
||||
{
|
||||
d = DotProduct(v, norm);
|
||||
|
||||
if (d > ON_EPSILON)
|
||||
{
|
||||
front = true;
|
||||
|
@ -447,13 +460,16 @@ static void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
|
|||
sides[i] = SIDE_BACK;
|
||||
}
|
||||
else
|
||||
{
|
||||
sides[i] = SIDE_ON;
|
||||
}
|
||||
|
||||
dists[i] = d;
|
||||
}
|
||||
|
||||
if (!front || !back)
|
||||
{ // not clipped
|
||||
ClipSkyPolygon (nump, vecs, stage+1);
|
||||
ClipSkyPolygon(nump, vecs, stage + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -516,11 +532,11 @@ void R_AddSkySurface (msurface_t *fa)
|
|||
// calculate vertex values for sky box
|
||||
for (p=fa->polys ; p ; p=p->next)
|
||||
{
|
||||
for (i=0 ; i<p->numverts ; i++)
|
||||
for (i = 0; i < p->numverts; i++)
|
||||
{
|
||||
VectorSubtract(p->verts[i], r_origin, verts[i]);
|
||||
VectorSubtract(p->verts[i].pos, r_origin, verts[i]);
|
||||
}
|
||||
ClipSkyPolygon (p->numverts, verts[0], 0);
|
||||
ClipSkyPolygon(p->numverts, verts[0], 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -586,24 +602,26 @@ static void MakeSkyVec (float s, float t, int axis, float *vertexData)
|
|||
vertexData[4] = t;
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
R_DrawSkyBox
|
||||
==============
|
||||
*/
|
||||
static int skytexorder[6] = {0,2,1,3,4,5};
|
||||
void R_DrawSkyBox (void)
|
||||
void
|
||||
R_DrawSkyBox(void)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
if (skyrotate)
|
||||
{ // check for no sky at all
|
||||
for (i = 0; i<6; i++)
|
||||
if (skymins[0][i] < skymaxs[0][i]
|
||||
&& skymins[1][i] < skymaxs[1][i])
|
||||
{ /* check for no sky at all */
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
if ((skymins[0][i] < skymaxs[0][i]) &&
|
||||
(skymins[1][i] < skymaxs[1][i]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 6)
|
||||
return; // nothing visible
|
||||
{
|
||||
return; /* nothing visible */
|
||||
}
|
||||
}
|
||||
|
||||
float model[16];
|
||||
|
@ -622,19 +640,21 @@ void R_DrawSkyBox (void)
|
|||
uint8_t *uboData = QVk_GetUniformBuffer(sizeof(model), &uboOffset, &uboDescriptorSet);
|
||||
memcpy(uboData, model, sizeof(model));
|
||||
|
||||
for (i = 0; i<6; i++)
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
if (skyrotate)
|
||||
{ // hack, forces full sky to draw when rotating
|
||||
{
|
||||
skymins[0][i] = -1;
|
||||
skymins[1][i] = -1;
|
||||
skymaxs[0][i] = 1;
|
||||
skymaxs[1][i] = 1;
|
||||
}
|
||||
|
||||
if (skymins[0][i] >= skymaxs[0][i]
|
||||
|| skymins[1][i] >= skymaxs[1][i])
|
||||
if ((skymins[0][i] >= skymaxs[0][i]) ||
|
||||
(skymins[1][i] >= skymaxs[1][i]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
MakeSkyVec(skymins[0][i], skymins[1][i], i, skyVerts[0].data);
|
||||
MakeSkyVec(skymins[0][i], skymaxs[1][i], i, skyVerts[1].data);
|
||||
|
|
Loading…
Reference in a new issue