vk: Prepare to share R_LightPoint

This commit is contained in:
Denis Pauk 2023-10-07 01:21:19 +03:00
parent 0311194305
commit 262a1ee5ef
11 changed files with 314 additions and 290 deletions

View file

@ -27,11 +27,9 @@
#include "header/local.h"
int r_dlightframecount;
cplane_t *lightplane; /* used as shadow plane */
vec3_t lightspot;
static float s_blocklights[256 * 256 * 3];
void
static void
R_RenderDlight(dlight_t *light)
{
int i, j;
@ -232,7 +230,7 @@ R_LightPoint(const entity_t *currententity, refdef_t *refdef, const msurface_t *
VectorScale(color, modulate, color);
}
void
static void
R_AddDynamicLights(msurface_t *surf)
{
int lnum;
@ -243,7 +241,7 @@ R_AddDynamicLights(msurface_t *surf)
int i;
int smax, tmax;
dlight_t *dl;
float *pfBL;
float *plightdest;
float fsacc, ftacc;
smax = (surf->extents[0] >> surf->lmshift) + 1;
@ -283,7 +281,7 @@ R_AddDynamicLights(msurface_t *surf)
local[1] = DotProduct(impact, surf->lmvecs[1]) +
surf->lmvecs[1][3] - surf->texturemins[1];
pfBL = s_blocklights;
plightdest = s_blocklights;
for (t = 0, ftacc = 0; t < tmax; t++, ftacc += (1 << surf->lmshift))
{
@ -296,7 +294,7 @@ R_AddDynamicLights(msurface_t *surf)
td *= surf->lmvlen[1];
for (s = 0, fsacc = 0; s < smax; s++, fsacc += (1 << surf->lmshift), pfBL += 3)
for (s = 0, fsacc = 0; s < smax; s++, fsacc += (1 << surf->lmshift), plightdest += 3)
{
sd = Q_ftol(local[0] - fsacc);
@ -316,13 +314,13 @@ R_AddDynamicLights(msurface_t *surf)
fdist = td + (sd >> 1);
}
if (fdist < fminlight)
if ((fdist < fminlight) && (plightdest < (s_blocklights_max - 3)))
{
float diff = frad - fdist;
pfBL[0] += diff * dl->color[0];
pfBL[1] += diff * dl->color[1];
pfBL[2] += diff * dl->color[2];
plightdest[0] += diff * dl->color[0];
plightdest[1] += diff * dl->color[1];
plightdest[2] += diff * dl->color[2];
}
}
}
@ -342,6 +340,8 @@ R_SetCacheState(msurface_t *surf)
}
}
float *s_blocklights = NULL, *s_blocklights_max = NULL;
/*
* Combine and scale multiple lightmaps into the floating format in blocklights
*/
@ -366,9 +366,27 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
tmax = (surf->extents[1] >> surf->lmshift) + 1;
size = smax * tmax;
if (size > (sizeof(s_blocklights) >> 4))
if (!s_blocklights || (s_blocklights + (size * 3) >= s_blocklights_max))
{
ri.Sys_Error(ERR_DROP, "Bad s_blocklights size");
int new_size = ROUNDUP(size * 3, 1024);
if (new_size < 4096)
{
new_size = 4096;
}
if (s_blocklights)
{
free(s_blocklights);
}
s_blocklights = malloc(new_size * sizeof(float));
s_blocklights_max = s_blocklights + new_size;
if (!s_blocklights)
{
ri.Sys_Error(ERR_DROP, "Can't alloc s_blocklights");
}
}
/* set to full bright if no light data */

View file

@ -153,7 +153,7 @@ R_RotateForEntity(entity_t *e)
glRotatef(-e->angles[2], 1, 0, 0);
}
void
static void
R_DrawSpriteModel(entity_t *currententity, const model_t *currentmodel)
{
float alpha = 1.0F;
@ -245,7 +245,7 @@ R_DrawSpriteModel(entity_t *currententity, const model_t *currentmodel)
glColor4f(1, 1, 1, 1);
}
void
static void
R_DrawNullModel(entity_t *currententity)
{
vec3_t shadelight;
@ -304,7 +304,7 @@ R_DrawNullModel(entity_t *currententity)
glEnable(GL_TEXTURE_2D);
}
void
static void
R_DrawEntitiesOnList(void)
{
int i;
@ -396,8 +396,9 @@ R_DrawEntitiesOnList(void)
R_DrawSpriteModel(currententity, currentmodel);
break;
default:
ri.Sys_Error(ERR_DROP, "Bad modeltype");
break;
R_Printf(PRINT_ALL, "%s: Bad modeltype %d\n",
__func__, currentmodel->type);
return;
}
}
}
@ -439,7 +440,7 @@ R_DrawParticles2(int num_particles, const particle_t particles[],
( p->origin [ 1 ] - r_origin [ 1 ] ) * vpn [ 1 ] +
( p->origin [ 2 ] - r_origin [ 2 ] ) * vpn [ 2 ];
if ( scale < 20 )
if (scale < 20)
{
scale = 1;
}
@ -506,7 +507,7 @@ R_DrawParticles2(int num_particles, const particle_t particles[],
YQ2_VLAFREE(clr);
}
void
static void
R_DrawParticles(void)
{
qboolean stereo_split_tb = ((gl_state.stereo_mode == STEREO_SPLIT_VERTICAL) && gl_state.camera_separation);
@ -574,7 +575,7 @@ R_DrawParticles(void)
}
}
void
static void
R_PolyBlend(void)
{
if (!gl_polyblend->value)
@ -620,7 +621,7 @@ R_PolyBlend(void)
glColor4f(1, 1, 1, 1);
}
void
static void
R_SetupFrame(void)
{
int i;
@ -1075,8 +1076,10 @@ R_RenderView(refdef_t *fd)
if (r_speeds->value)
{
R_Printf(PRINT_ALL, "%4i wpoly %4i epoly %i tex %i lmaps\n",
c_brush_polys, c_alias_polys, c_visible_textures,
c_visible_lightmaps);
c_brush_polys,
c_alias_polys,
c_visible_textures,
c_visible_lightmaps);
}
switch (gl_state.stereo_mode) {
@ -1165,6 +1168,10 @@ RI_RenderFrame(refdef_t *fd)
void
R_Register(void)
{
/* Init default value */
s_blocklights = NULL;
s_blocklights_max = NULL;
gl_lefthand = ri.Cvar_Get("hand", "0", CVAR_USERINFO | CVAR_ARCHIVE);
r_gunfov = ri.Cvar_Get("r_gunfov", "80", CVAR_ARCHIVE);
r_farsee = ri.Cvar_Get("r_farsee", "0", CVAR_LATCH | CVAR_ARCHIVE);
@ -1330,7 +1337,7 @@ SetMode_impl(int *pwidth, int *pheight, int mode, int fullscreen)
return rserr_ok;
}
qboolean
static qboolean
R_SetMode(void)
{
rserr_t err;
@ -1426,7 +1433,7 @@ RI_Init(void)
if (!R_SetMode())
{
QGL_Shutdown();
R_Printf(PRINT_ALL, "ref_gl::R_Init() - could not R_SetMode()\n");
R_Printf(PRINT_ALL, "%s() - could not R_SetMode()\n", __func__);
return false;
}
@ -1590,9 +1597,18 @@ RI_Shutdown(void)
/* shutdown our QGL subsystem */
QGL_Shutdown();
/* Cleanup buffers */
if (s_blocklights)
{
free(s_blocklights);
}
s_blocklights = NULL;
s_blocklights_max = NULL;
}
void
static void
RI_BeginFrame(float camera_separation)
{
gl_state.camera_separation = camera_separation;
@ -1750,7 +1766,7 @@ RI_BeginFrame(float camera_separation)
R_Clear();
}
void
static void
RI_SetPalette(const unsigned char *palette)
{
int i;
@ -1785,7 +1801,6 @@ RI_SetPalette(const unsigned char *palette)
glClearColor(1, 0, 0.5, 0.5);
}
/* R_DrawBeam */
void
R_DrawBeam(entity_t *e)
{
@ -1946,9 +1961,9 @@ GetRefAPI(refimport_t imp)
re.EndWorldRenderpass = RI_EndWorldRenderpass;
re.EndFrame = RI_EndFrame;
// Tell the client that we're unsing the
// Tell the client that we're unsing the
// new renderer restart API.
ri.Vid_RequestRestart(RESTART_NO);
ri.Vid_RequestRestart(RESTART_NO);
return re;
}

View file

@ -46,8 +46,8 @@ float *shadedots = r_avertexnormal_dots[0];
static void
R_LerpVerts(entity_t *currententity, int nverts, dtrivertx_t *v, dtrivertx_t *ov,
dtrivertx_t *verts, float *lerp, float move[3],
float frontv[3], float backv[3])
dtrivertx_t *verts, float *lerp, const float move[3],
const float frontv[3], const float backv[3])
{
int i;

View file

@ -70,15 +70,6 @@
#define MAX_LIGHTMAPS 256
#define GL_LIGHTMAP_FORMAT GL_RGBA
/* up / down */
#define PITCH 0
/* left / right */
#define YAW 1
/* fall over */
#define ROLL 2
extern viddef_t vid;
@ -246,6 +237,7 @@ void R_LightPoint(const entity_t *currententity, refdef_t *refdef, const msurfac
const mnode_t *nodes, vec3_t p, vec3_t color, float modulate, vec3_t lightspot);
void R_PushDlights(void);
extern float *s_blocklights, *s_blocklights_max;
extern model_t *r_worldmodel;
extern unsigned d_8to24table[256];
extern int registration_sequence;
@ -255,7 +247,6 @@ void V_AddBlend(float r, float g, float b, float a, float *v_blend);
void R_ScreenShot(void);
void R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel);
void R_DrawBrushModel(entity_t *currententity, const model_t *currentmodel);
void R_DrawSpriteModel(entity_t *currententity, const model_t *currentmodel);
void R_DrawBeam(entity_t *e);
void R_DrawWorld(void);
void R_RenderDlights(void);

View file

@ -46,6 +46,8 @@
#endif
#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
/*
* skins will be outline flood filled and mip mapped
* pics and sprites with alpha will be outline flood filled

View file

@ -1416,10 +1416,12 @@ RE_RenderFrame (refdef_t *fd)
R_DrawAlphaSurfaces(&ent);
// Save off light value for server to look at (BIG HACK!)
R_SetLightLevel (&ent);
R_SetLightLevel(&ent);
if (r_dowarp)
{
D_WarpScreen ();
}
if (r_dspeeds->value)
{

View file

@ -18,13 +18,18 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* Local header for the refresher.
*
* =======================================================================
*/
#ifndef __VK_LOCAL_H__
#define __VK_LOCAL_H__
#include <math.h>
#include <stdio.h>
#include <math.h>
#if defined(__APPLE__)
#include <SDL.h>
@ -53,26 +58,17 @@
} \
}
// up / down
#define PITCH 0
// left / right
#define YAW 1
// fall over
#define ROLL 2
extern viddef_t vid;
extern viddef_t vid;
typedef struct image_s
{
char name[MAX_QPATH]; // game path, including extension
imagetype_t type;
int width, height; // source image
int upload_width, upload_height; // after power of two and picmip
int registration_sequence; // 0 = free
struct msurface_s *texturechain; // for sort-by-texture world drawing
qvktexture_t vk_texture; // Vulkan texture handle
char name[MAX_QPATH]; /* game path, including extension */
imagetype_t type;
int width, height; /* source image */
int upload_width, upload_height; /* after power of two and picmip */
int registration_sequence; /* 0 = free */
struct msurface_s *texturechain; /* for sort-by-texture world drawing */
qvktexture_t vk_texture; /* Vulkan texture handle */
} image_t;
#define MAX_VKTEXTURES 1024
@ -164,9 +160,6 @@ extern float r_viewproj_matrix[16];
extern float *s_blocklights, *s_blocklights_max;
void R_LightPoint (vec3_t p, vec3_t color, entity_t *currententity);
void R_PushDlights (void);
//====================================================================
extern model_t *r_worldmodel;
@ -192,9 +185,12 @@ 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_LightPoint(const entity_t *currententity, refdef_t *refdef, const msurface_t *surfaces,
const mnode_t *nodes, vec3_t p, vec3_t color, float modulate, vec3_t lightspot);
void R_PushDlights(void);
void R_DrawAliasModel(entity_t *currententity, const 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);
@ -207,12 +203,12 @@ 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,
void EmitWaterPolys(msurface_t *fa, image_t *texture,
float *modelMatrix, const float *color,
qboolean solid_surface);
void R_AddSkySurface (msurface_t *fa);
void R_ClearSkyBox (void);
void R_DrawSkyBox (void);
void R_AddSkySurface(msurface_t *fa);
void R_ClearSkyBox(void);
void R_DrawSkyBox(void);
void R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node,
int r_dlightframecount);
@ -316,13 +312,13 @@ typedef struct
float inverse_intensity;
qboolean fullscreen;
int prev_mode;
int prev_mode;
unsigned char *d_16to8table;
qvktexture_t lightmap_textures[MAX_LIGHTMAPS*2];
int currenttextures[2];
int currenttextures[2];
int currenttmu;
float camera_separation;

View file

@ -25,8 +25,6 @@
#include "../volk/volk.h"
#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
typedef struct BufferResource_s {
VkBuffer buffer;
// shared memory used for buffer

View file

@ -119,6 +119,12 @@ R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframeco
int sidebit;
float dist;
if (surf->dlightframe != r_dlightframecount)
{
surf->dlightbits = 0;
surf->dlightframe = r_dlightframecount;
}
dist = DotProduct(light->origin, surf->plane->normal) - surf->plane->dist;
if (dist >= 0)
@ -135,12 +141,6 @@ R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframeco
continue;
}
if (surf->dlightframe != r_dlightframecount)
{
surf->dlightbits = 0;
surf->dlightframe = r_dlightframecount;
}
surf->dlightbits |= bit;
}
}
@ -169,14 +169,15 @@ R_PushDlights(void)
}
void
R_LightPoint(vec3_t p, vec3_t color, entity_t *currententity)
R_LightPoint(const entity_t *currententity, refdef_t *refdef, const msurface_t *surfaces,
const mnode_t *nodes, vec3_t p, vec3_t color, float modulate, vec3_t lightspot)
{
vec3_t end, dist, pointcolor = {0, 0, 0};
float r;
int lnum;
dlight_t *dl;
if (!r_worldmodel->lightdata || !currententity)
if (!currententity)
{
color[0] = color[1] = color[2] = 1.0;
return;
@ -186,8 +187,8 @@ R_LightPoint(vec3_t p, vec3_t color, entity_t *currententity)
end[1] = p[1];
end[2] = p[2] - 2048;
r = R_RecursiveLightPoint(r_worldmodel->surfaces, r_worldmodel->nodes,
r_newrefdef.lightstyles, p, end, pointcolor, lightspot, r_modulate->value);
r = R_RecursiveLightPoint(surfaces, nodes, refdef->lightstyles,
p, end, pointcolor, lightspot, modulate);
if (r == -1)
{
@ -199,16 +200,16 @@ R_LightPoint(vec3_t p, vec3_t color, entity_t *currententity)
}
/* add dynamic lights */
dl = r_newrefdef.dlights;
dl = refdef->dlights;
for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++, dl++)
for (lnum = 0; lnum < refdef->num_dlights; lnum++, dl++)
{
float add;
VectorSubtract(currententity->origin,
dl->origin, dist);
add = dl->intensity - VectorLength(dist);
add *= (1.0 / 256);
add *= (1.0f / 256.0f);
if (add > 0)
{
@ -216,7 +217,7 @@ R_LightPoint(vec3_t p, vec3_t color, entity_t *currententity)
}
}
VectorScale(color, r_modulate->value, color);
VectorScale(color, modulate, color);
}
static void

View file

@ -18,6 +18,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* Refresher setup and main part of the frame generation
*
* =======================================================================
*/
#include "header/local.h"
@ -154,45 +159,31 @@ void R_RotateForEntity (entity_t *e, float *mvMatrix)
Mat_Translate(mvMatrix, e->origin[0], e->origin[1], e->origin[2]);
}
/*
=============================================================
SPRITE MODELS
=============================================================
*/
/*
=================
R_DrawSpriteModel
=================
*/
void R_DrawSpriteModel (entity_t *currententity, model_t *currentmodel)
static void
R_DrawSpriteModel(entity_t *currententity, const model_t *currentmodel)
{
float alpha = 1.0F;
vec3_t point;
dsprframe_t *frame;
float *up, *right;
dsprite_t *psprite;
image_t *skin;
// don't even bother culling, because it's just a single
// polygon without a surface cache
vec3_t point;
dsprframe_t *frame;
float *up, *right;
dsprite_t *psprite;
image_t *skin;
/* don't even bother culling, because it's just
a single polygon without a surface cache */
psprite = (dsprite_t *)currentmodel->extradata;
currententity->frame %= psprite->numframes;
frame = &psprite->frames[currententity->frame];
// normal sprite
/* normal sprite */
up = vup;
right = vright;
if (currententity->flags & RF_TRANSLUCENT)
{
alpha = currententity->alpha;
}
vec3_t spriteQuad[4];
@ -240,23 +231,22 @@ void R_DrawSpriteModel (entity_t *currententity, model_t *currentmodel)
vkCmdDraw(vk_activeCmdbuffer, 6, 1, 0, 0);
}
//==================================================================================
/*
=============
R_DrawNullModel
=============
*/
static void
R_DrawNullModel (entity_t *currententity)
R_DrawNullModel(entity_t *currententity)
{
vec3_t shadelight;
int i,j;
vec3_t shadelight;
int i, j;
if (currententity->flags & RF_FULLBRIGHT)
if (currententity->flags & RF_FULLBRIGHT || !r_worldmodel || !r_worldmodel->lightdata)
{
shadelight[0] = shadelight[1] = shadelight[2] = 1.0F;
}
else
R_LightPoint(currententity->origin, shadelight, currententity);
{
R_LightPoint(currententity, &r_newrefdef, r_worldmodel->surfaces,
r_worldmodel->nodes, currententity->origin, shadelight,
r_modulate->value, lightspot);
}
float model[16];
Mat_Identity(model);
@ -314,25 +304,25 @@ R_DrawNullModel (entity_t *currententity)
vkCmdDrawIndexed(vk_activeCmdbuffer, 12, 1, 0, 6, 0);
}
/*
=============
R_DrawEntitiesOnList
=============
*/
static void
R_DrawEntitiesOnList (void)
R_DrawEntitiesOnList(void)
{
int i;
int i;
if (!r_drawentities->value)
return;
// draw non-transparent first
for (i = 0; i<r_newrefdef.num_entities; i++)
{
entity_t *currententity = &r_newrefdef.entities[i];
return;
}
/* draw non-transparent first */
for (i = 0; i < r_newrefdef.num_entities; i++)
{
entity_t *currententity = &r_newrefdef.entities[i];
if (currententity->flags & RF_TRANSLUCENT)
continue; // solid
{
continue; /* solid */
}
if (currententity->flags & RF_BEAM)
{
@ -340,38 +330,45 @@ R_DrawEntitiesOnList (void)
}
else
{
model_t *currentmodel = currententity->model;
const model_t *currentmodel = currententity->model;
if (!currentmodel)
{
R_DrawNullModel(currententity);
continue;
}
switch (currentmodel->type)
{
case mod_alias:
R_DrawAliasModel(currententity, currentmodel);
break;
case mod_brush:
R_DrawBrushModel(currententity, currentmodel);
break;
case mod_sprite:
R_DrawSpriteModel(currententity, currentmodel);
break;
default:
R_Printf(PRINT_ALL, "%s: Bad modeltype %d\n",
__func__, currentmodel->type);
return;
case mod_alias:
R_DrawAliasModel(currententity, currentmodel);
break;
case mod_brush:
R_DrawBrushModel(currententity, currentmodel);
break;
case mod_sprite:
R_DrawSpriteModel(currententity, currentmodel);
break;
default:
R_Printf(PRINT_ALL, "%s: Bad modeltype %d\n",
__func__, currentmodel->type);
return;
}
}
}
// draw transparent entities
// we could sort these if it ever becomes a problem...
for (i = 0; i<r_newrefdef.num_entities; i++)
/* draw transparent entities
we could sort these if it ever
becomes a problem... */
for (i = 0; i < r_newrefdef.num_entities; i++)
{
entity_t *currententity = &r_newrefdef.entities[i];
entity_t *currententity = &r_newrefdef.entities[i];
if (!(currententity->flags & RF_TRANSLUCENT))
continue; // solid
{
continue; /* solid */
}
if (currententity->flags & RF_BEAM)
{
@ -379,37 +376,34 @@ R_DrawEntitiesOnList (void)
}
else
{
model_t *currentmodel = currententity->model;
const model_t *currentmodel = currententity->model;
if (!currentmodel)
{
R_DrawNullModel(currententity);
continue;
}
switch (currentmodel->type)
{
case mod_alias:
R_DrawAliasModel(currententity, currentmodel);
break;
case mod_brush:
R_DrawBrushModel(currententity, currentmodel);
break;
case mod_sprite:
R_DrawSpriteModel(currententity, currentmodel);
break;
default:
R_Printf(PRINT_ALL, "%s: Bad modeltype %d\n",
__func__, currentmodel->type);
return;
case mod_alias:
R_DrawAliasModel(currententity, currentmodel);
break;
case mod_brush:
R_DrawBrushModel(currententity, currentmodel);
break;
case mod_sprite:
R_DrawSpriteModel(currententity, currentmodel);
break;
default:
R_Printf(PRINT_ALL, "%s: Bad modeltype %d\n",
__func__, currentmodel->type);
return;
}
}
}
}
/*
** Vk_DrawParticles
**
*/
static void
Vk_DrawParticles(int num_particles, const particle_t particles[], const unsigned *colortable)
{
@ -447,9 +441,13 @@ Vk_DrawParticles(int num_particles, const particle_t particles[], const unsigned
(p->origin[2] - r_origin[2]) * vpn[2];
if (scale < 20)
{
scale = 1;
}
else
{
scale = 1 + scale * 0.004;
}
*(int *)color = colortable[p->color];
@ -520,13 +518,8 @@ Vk_DrawParticles(int num_particles, const particle_t particles[], const unsigned
vkCmdDraw(vk_activeCmdbuffer, (currentvertex - visibleParticles), 1, 0, 0);
}
/*
===============
R_DrawParticles
===============
*/
static void
R_DrawParticles (void)
R_DrawParticles(void)
{
if (vk_custom_particles->value == 1)
{
@ -600,44 +593,37 @@ R_DrawParticles (void)
}
}
/*
============
R_PolyBlend
============
*/
static void
R_PolyBlend (void)
R_PolyBlend(void)
{
if (!r_polyblend->value)
{
return;
}
if (!v_blend[3])
{
return;
}
float polyTransform[] = { 0.f, 0.f, vid.width, vid.height, v_blend[0], v_blend[1], v_blend[2], v_blend[3] };
QVk_DrawColorRect(polyTransform, sizeof(polyTransform), RP_WORLD);
}
//=======================================================================
/*
===============
R_SetupFrame
===============
*/
static void
R_SetupFrame (void)
R_SetupFrame(void)
{
int i;
mleaf_t *leaf;
mleaf_t *leaf;
r_framecount++;
// build the transformation matrix for the given view angles
/* build the transformation matrix for the given view angles */
VectorCopy(r_newrefdef.vieworg, r_origin);
AngleVectors(r_newrefdef.viewangles, vpn, vright, vup);
// current viewcluster
/* current viewcluster */
if (!(r_newrefdef.rdflags & RDF_NOWORLDMODEL))
{
if (!r_worldmodel)
@ -651,39 +637,49 @@ R_SetupFrame (void)
leaf = Mod_PointInLeaf(r_origin, r_worldmodel->nodes);
r_viewcluster = r_viewcluster2 = leaf->cluster;
// check above and below so crossing solid water doesn't draw wrong
/* check above and below so crossing solid water doesn't draw wrong */
if (!leaf->contents)
{ // look down a bit
vec3_t temp;
{
/* look down a bit */
vec3_t temp;
VectorCopy(r_origin, temp);
temp[2] -= 16;
leaf = Mod_PointInLeaf(temp, r_worldmodel->nodes);
if (!(leaf->contents & CONTENTS_SOLID) &&
(leaf->cluster != r_viewcluster2))
{
r_viewcluster2 = leaf->cluster;
}
}
else
{ // look up a bit
vec3_t temp;
{
/* look up a bit */
vec3_t temp;
VectorCopy(r_origin, temp);
temp[2] += 16;
leaf = Mod_PointInLeaf(temp, r_worldmodel->nodes);
if (!(leaf->contents & CONTENTS_SOLID) &&
(leaf->cluster != r_viewcluster2))
{
r_viewcluster2 = leaf->cluster;
}
}
}
for (i = 0; i < 4; i++)
{
v_blend[i] = r_newrefdef.blend[i];
}
c_brush_polys = 0;
c_alias_polys = 0;
// clear out the portion of the screen that the NOWORLDMODEL defines
// unlike OpenGL, draw a rectangle in proper location - it's easier to do in Vulkan
/* clear out the portion of the screen that the NOWORLDMODEL defines
unlike OpenGL, draw a rectangle in proper location - it's easier to do in Vulkan */
if (r_newrefdef.rdflags & RDF_NOWORLDMODEL)
{
float clearArea[] = { (float)r_newrefdef.x / vid.width, (float)r_newrefdef.y / vid.height,
@ -902,15 +898,20 @@ RE_RenderView
r_newrefdef must be set before the first call
================
*/
static void RE_RenderView (refdef_t *fd)
static void
RE_RenderView(refdef_t *fd)
{
if (r_norefresh->value)
{
return;
}
r_newrefdef = *fd;
if (!r_worldmodel && !(r_newrefdef.rdflags & RDF_NOWORLDMODEL))
{
ri.Sys_Error(ERR_DROP, "%s: NULL worldmodel", __func__);
}
if (r_speeds->value)
{
@ -939,13 +940,15 @@ static void RE_RenderView (refdef_t *fd)
// added for compatibility sake with OpenGL implementation - don't use it!
if (vk_finish->value)
{
vkDeviceWaitIdle(vk_device.logical);
}
R_SetupFrame();
R_SetupVulkan();
R_MarkLeaves(); // done here so we know if we're in water
R_MarkLeaves(); /* done here so we know if we're in water */
R_DrawWorld();
@ -1032,7 +1035,8 @@ qboolean RE_EndWorldRenderpass(void)
return true;
}
static void R_SetVulkan2D (const VkViewport* viewport, const VkRect2D* scissor)
static void
R_SetVulkan2D(const VkViewport* viewport, const VkRect2D* scissor)
{
// player configuration screen renders a model using the UI renderpass, so skip finishing RP_WORLD twice
if (!(r_newrefdef.rdflags & RDF_NOWORLDMODEL))
@ -1056,63 +1060,63 @@ static void R_SetVulkan2D (const VkViewport* viewport, const VkRect2D* scissor)
}
}
/*
====================
R_SetLightLevel
====================
*/
static void
R_SetLightLevel (void)
R_SetLightLevel(entity_t *currententity)
{
vec3_t shadelight;
vec3_t shadelight = {0};
if (r_newrefdef.rdflags & RDF_NOWORLDMODEL)
{
return;
}
// save off light value for server to look at (BIG HACK!)
/* save off light value for server to look at */
R_LightPoint(currententity, &r_newrefdef, r_worldmodel->surfaces,
r_worldmodel->nodes, r_newrefdef.vieworg, shadelight,
r_modulate->value, lightspot);
R_LightPoint(r_newrefdef.vieworg, shadelight, NULL);
// pick the greatest component, which should be the same
// as the mono value returned by software
/* pick the greatest component, which should be the
* same as the mono value returned by software */
if (shadelight[0] > shadelight[1])
{
if (shadelight[0] > shadelight[2])
{
r_lightlevel->value = 150 * shadelight[0];
}
else
{
r_lightlevel->value = 150 * shadelight[2];
}
}
else
{
if (shadelight[1] > shadelight[2])
{
r_lightlevel->value = 150 * shadelight[1];
}
else
{
r_lightlevel->value = 150 * shadelight[2];
}
}
}
/*
=====================
RE_RenderFrame
=====================
*/
static void
RE_RenderFrame (refdef_t *fd)
RE_RenderFrame(refdef_t *fd)
{
if (!vk_frameStarted)
{
return;
}
RE_RenderView( fd );
R_SetLightLevel ();
RE_RenderView(fd);
R_SetLightLevel(NULL);
R_SetVulkan2D (&vk_viewport, &vk_scissor);
}
static void
R_Register( void )
R_Register(void)
{
/* Init default value */
s_blocklights = NULL;
@ -1199,7 +1203,9 @@ R_Register( void )
ri.Cmd_AddCommand("modellist", Mod_Modellist_f);
}
/*
* Changes the video mode
*/
static int
Vkimp_SetMode(int *pwidth, int *pheight, int mode, int fullscreen)
{
@ -1233,13 +1239,8 @@ Vkimp_SetMode(int *pwidth, int *pheight, int mode, int fullscreen)
return rserr_ok;
}
/*
==================
R_SetMode
==================
*/
static qboolean
R_SetMode (void)
R_SetMode(void)
{
rserr_t err;
int fullscreen;
@ -1312,6 +1313,7 @@ static qboolean RE_Init( void )
R_Printf(PRINT_ALL, "%s() - could not R_SetMode()\n", __func__);
return false;
}
ri.Vid_MenuInit();
// print device information during startup
@ -1329,24 +1331,21 @@ static qboolean RE_Init( void )
** subsystem.
**
*/
static void RE_ShutdownContext( void )
static void
RE_ShutdownContext(void)
{
// Shutdown Vulkan subsystem
QVk_WaitAndShutdownAll();
}
/*
===============
RE_Shutdown
===============
*/
void RE_Shutdown (void)
void
RE_Shutdown(void)
{
ri.Cmd_RemoveCommand("modellist");
ri.Cmd_RemoveCommand("screenshot");
ri.Cmd_RemoveCommand("imagelist");
ri.Cmd_RemoveCommand("vk_strings");
ri.Cmd_RemoveCommand("vk_mem");
ri.Cmd_RemoveCommand("imagelist");
ri.Cmd_RemoveCommand("screenshot");
ri.Cmd_RemoveCommand("modellist");
QVk_WaitAndShutdownAll();
@ -1360,13 +1359,8 @@ void RE_Shutdown (void)
s_blocklights_max = NULL;
}
/*
=====================
RE_BeginFrame
=====================
*/
static void
RE_BeginFrame( float camera_separation )
RE_BeginFrame(float camera_separation)
{
// world has not rendered yet
world_rendered = false;
@ -1430,7 +1424,7 @@ RE_EndFrame
=====================
*/
static void
RE_EndFrame( void )
RE_EndFrame(void)
{
QVk_EndFrame(false);
@ -1438,17 +1432,12 @@ RE_EndFrame( void )
world_rendered = false;
}
/*
=============
RE_SetPalette
=============
*/
unsigned r_rawpalette[256];
static void
RE_SetPalette (const unsigned char *palette)
RE_SetPalette(const unsigned char *palette)
{
int i;
int i;
byte *rp = (byte *)r_rawpalette;
@ -1474,19 +1463,17 @@ RE_SetPalette (const unsigned char *palette)
}
}
/*
** R_DrawBeam
*/
void R_DrawBeam( entity_t *currententity )
void
R_DrawBeam(entity_t *currententity )
{
#define NUM_BEAM_SEGS 6
int i;
int i;
float r, g, b;
vec3_t perpvec;
vec3_t direction, normalized_direction;
vec3_t start_points[NUM_BEAM_SEGS], end_points[NUM_BEAM_SEGS];
vec3_t start_points[NUM_BEAM_SEGS], end_points[NUM_BEAM_SEGS];
vec3_t oldorigin, origin;
oldorigin[0] = currententity->oldorigin[0];
@ -1502,7 +1489,9 @@ void R_DrawBeam( entity_t *currententity )
normalized_direction[2] = direction[2] = oldorigin[2] - origin[2];
if (VectorNormalize(normalized_direction) == 0)
{
return;
}
PerpendicularVector(perpvec, normalized_direction);
VectorScale(perpvec, currententity->frame / 2, perpvec);
@ -1745,16 +1734,15 @@ GetRefAPI(refimport_t imp)
refexport.EndWorldRenderpass = RE_EndWorldRenderpass;
refexport.EndFrame = RE_EndFrame;
// Tell the client that we're unsing the
// Tell the client that we're unsing the
// new renderer restart API.
ri.Vid_RequestRestart(RESTART_NO);
ri.Vid_RequestRestart(RESTART_NO);
Swap_Init ();
return refexport;
}
// this is only here so the functions in q_shared.c and q_shwin.c can link
void R_Printf(int level, const char* msg, ...)
{
va_list argptr;
@ -1763,21 +1751,25 @@ void R_Printf(int level, const char* msg, ...)
va_end(argptr);
}
/*
* this is only here so the functions in shared source files
* (shared.c, rand.c, flash.c, mem.c/hunk.c) can link
*/
void
Sys_Error (const char *error, ...)
Sys_Error(const char *error, ...)
{
va_list argptr;
char text[4096]; // MAXPRINTMSG == 4096
va_list argptr;
char text[4096]; // MAXPRINTMSG == 4096
va_start(argptr, error);
vsnprintf(text, sizeof(text), error, argptr);
va_end(argptr);
ri.Sys_Error (ERR_FATAL, "%s", text);
ri.Sys_Error(ERR_FATAL, "%s", text);
}
void
Com_Printf (const char *msg, ...)
Com_Printf(const char *msg, ...)
{
va_list argptr;
va_start(argptr, msg);

View file

@ -235,9 +235,9 @@ void Mesh_Free (void)
static void
Vk_LerpVerts(int nverts, dtrivertx_t *v, dtrivertx_t *ov, dtrivertx_t *verts,
float *lerp, const float move[3], const float frontv[3], const float backv[3],
entity_t *currententity)
R_LerpVerts(entity_t *currententity, int nverts, dtrivertx_t *v, dtrivertx_t *ov,
dtrivertx_t *verts, float *lerp, const float move[3],
const float frontv[3], const float backv[3])
{
int i;
@ -466,8 +466,8 @@ FIXME: batch lerp all vertexes
=============
*/
static void
Vk_DrawAliasFrameLerp(dmdl_t *paliashdr, float backlerp, image_t *skin,
float *modelMatrix, int leftHandOffset, int translucentIdx, entity_t *currententity)
Vk_DrawAliasFrameLerp(entity_t *currententity, dmdl_t *paliashdr, float backlerp, image_t *skin,
float *modelMatrix, int leftHandOffset, int translucentIdx)
{
daliasframe_t *frame, *oldframe;
dtrivertx_t *v, *ov, *verts;
@ -530,7 +530,7 @@ Vk_DrawAliasFrameLerp(dmdl_t *paliashdr, float backlerp, image_t *skin,
lerp = s_lerped[0];
Vk_LerpVerts(paliashdr->num_xyz, v, ov, verts, lerp, move, frontv, backv, currententity );
R_LerpVerts(currententity, paliashdr->num_xyz, v, ov, verts, lerp, move, frontv, backv);
num_mesh_nodes = (paliashdr->ofs_skins - sizeof(dmdl_t)) / sizeof(short) / 2;
mesh_nodes = (short *)((char*)paliashdr + sizeof(dmdl_t));
@ -650,7 +650,7 @@ Vk_DrawAliasShadow(int *order, int *order_end, int posenum,
}
static qboolean
R_CullAliasModel(vec3_t bbox[8], entity_t *e, model_t *currentmodel )
R_CullAliasModel(const model_t *currentmodel, vec3_t bbox[8], entity_t *e)
{
int i;
vec3_t mins, maxs;
@ -810,7 +810,7 @@ R_CullAliasModel(vec3_t bbox[8], entity_t *e, model_t *currentmodel )
}
void
R_DrawAliasModel(entity_t *currententity, model_t *currentmodel)
R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
{
int i;
int leftHandOffset = 0;
@ -822,7 +822,7 @@ R_DrawAliasModel(entity_t *currententity, model_t *currentmodel)
{
vec3_t bbox[8];
if (R_CullAliasModel( bbox, currententity, currentmodel))
if (R_CullAliasModel(currentmodel, bbox, currententity))
{
return;
}
@ -889,7 +889,16 @@ R_DrawAliasModel(entity_t *currententity, model_t *currentmodel)
}
else
{
R_LightPoint(currententity->origin, shadelight, currententity);
if (!r_worldmodel || !r_worldmodel->lightdata)
{
shadelight[0] = shadelight[1] = shadelight[2] = 1.0F;
}
else
{
R_LightPoint(currententity, &r_newrefdef, r_worldmodel->surfaces,
r_worldmodel->nodes, currententity->origin, shadelight,
r_modulate->value, lightspot);
}
}
/* player lighting hack for communication back to server */
@ -1058,7 +1067,7 @@ R_DrawAliasModel(entity_t *currententity, model_t *currentmodel)
if ( !r_lerpmodels->value )
currententity->backlerp = 0;
Vk_DrawAliasFrameLerp (paliashdr, currententity->backlerp, skin, model, leftHandOffset, (currententity->flags & RF_TRANSLUCENT) ? 1 : 0, currententity);
Vk_DrawAliasFrameLerp(currententity, paliashdr, currententity->backlerp, skin, model, leftHandOffset, (currententity->flags & RF_TRANSLUCENT) ? 1 : 0);
}
if ( ( currententity->flags & RF_WEAPONMODEL ) && ( r_lefthand->value == 1.0F ) )