2021-01-19 16:25:54 +00:00
|
|
|
/*
|
|
|
|
vulkan_main.c
|
|
|
|
|
|
|
|
Vulkan rendering
|
|
|
|
|
|
|
|
Copyright (C) 2021 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2021/1/19
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include "string.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include "strings.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/image.h"
|
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/screen.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2021-01-19 16:25:54 +00:00
|
|
|
#include "QF/Vulkan/qf_vid.h"
|
2021-01-26 11:58:24 +00:00
|
|
|
#include "QF/Vulkan/qf_alias.h"
|
2021-01-19 16:25:54 +00:00
|
|
|
#include "QF/Vulkan/qf_bsp.h"
|
|
|
|
//#include "QF/Vulkan/qf_iqm.h"
|
2021-03-03 09:14:16 +00:00
|
|
|
#include "QF/Vulkan/qf_lighting.h"
|
2021-01-19 16:25:54 +00:00
|
|
|
#include "QF/Vulkan/qf_lightmap.h"
|
|
|
|
#include "QF/Vulkan/qf_main.h"
|
|
|
|
#include "QF/Vulkan/qf_particles.h"
|
2021-12-14 16:22:05 +00:00
|
|
|
#include "QF/Vulkan/qf_sprite.h"
|
2021-01-19 16:25:54 +00:00
|
|
|
//#include "QF/Vulkan/qf_textures.h"
|
2021-12-02 12:58:29 +00:00
|
|
|
#include "QF/Vulkan/renderpass.h"
|
2021-01-19 16:25:54 +00:00
|
|
|
|
|
|
|
#include "mod_internal.h"
|
|
|
|
#include "r_internal.h"
|
|
|
|
#include "vid_vulkan.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_frame (vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
R_AnimateLight ();
|
2022-03-04 16:48:10 +00:00
|
|
|
EntQueue_Clear (r_ent_queue);
|
2021-01-19 16:25:54 +00:00
|
|
|
r_framecount++;
|
|
|
|
|
2022-03-08 09:41:09 +00:00
|
|
|
vec4f_t position = r_refdef.viewposition;
|
|
|
|
vec4f_t rotation = r_refdef.viewrotation;
|
|
|
|
VectorCopy (qvmulf (rotation, (vec4f_t) { 1, 0, 0, 0 }), vpn);
|
|
|
|
VectorCopy (qvmulf (rotation, (vec4f_t) { 0, -1, 0, 0 }), vright);
|
|
|
|
VectorCopy (qvmulf (rotation, (vec4f_t) { 0, 0, 1, 0 }), vup);
|
2021-03-19 11:18:45 +00:00
|
|
|
|
2021-01-19 16:25:54 +00:00
|
|
|
R_SetFrustum ();
|
|
|
|
|
2022-03-08 09:41:09 +00:00
|
|
|
r_viewleaf = Mod_PointInLeaf (&position[0], r_worldentity.renderer.model);
|
2021-01-19 16:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_RenderEntities (qfv_renderframe_t *rFrame)
|
2021-01-19 16:25:54 +00:00
|
|
|
{
|
|
|
|
if (!r_drawentities->int_val)
|
|
|
|
return;
|
|
|
|
#define RE_LOOP(type_name, Type) \
|
|
|
|
do { \
|
2021-01-27 07:16:28 +00:00
|
|
|
int begun = 0; \
|
2022-03-04 16:48:10 +00:00
|
|
|
for (size_t i = 0; i < r_ent_queue->ent_queues[mod_##type_name].size; \
|
|
|
|
i++) { \
|
|
|
|
entity_t *ent = r_ent_queue->ent_queues[mod_##type_name].a[i]; \
|
2021-01-19 16:25:54 +00:00
|
|
|
if (!begun) { \
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_##Type##Begin (rFrame); \
|
2021-01-19 16:25:54 +00:00
|
|
|
begun = 1; \
|
|
|
|
} \
|
2021-07-25 05:03:25 +00:00
|
|
|
/* hack the depth range to prevent view model */\
|
|
|
|
/* from poking into walls */\
|
|
|
|
if (ent == vr_data.view_model) { \
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_AliasDepthRange (rFrame, 0, 0.3); \
|
2021-07-25 05:03:25 +00:00
|
|
|
} \
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_Draw##Type (ent, rFrame); \
|
2021-07-25 05:03:25 +00:00
|
|
|
/* unhack in case the view_model is not the last */\
|
|
|
|
if (ent == vr_data.view_model) { \
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_AliasDepthRange (rFrame, 0, 1); \
|
2021-07-25 05:03:25 +00:00
|
|
|
} \
|
2021-01-19 16:25:54 +00:00
|
|
|
} \
|
|
|
|
if (begun) \
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_##Type##End (rFrame); \
|
2021-01-19 16:25:54 +00:00
|
|
|
} while (0)
|
|
|
|
|
2021-01-26 11:58:24 +00:00
|
|
|
RE_LOOP (alias, Alias);
|
2021-01-19 16:25:54 +00:00
|
|
|
//RE_LOOP (iqm, IQM);
|
2021-12-14 16:22:05 +00:00
|
|
|
RE_LOOP (sprite, Sprite);
|
2021-01-19 16:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-07-25 05:03:25 +00:00
|
|
|
Vulkan_DrawViewModel (vulkan_ctx_t *ctx)
|
2021-01-19 16:25:54 +00:00
|
|
|
{
|
2021-07-22 06:39:28 +00:00
|
|
|
entity_t *ent = vr_data.view_model;
|
2021-01-19 16:25:54 +00:00
|
|
|
if (vr_data.inhibit_viewmodel
|
|
|
|
|| !r_drawviewmodel->int_val
|
|
|
|
|| !r_drawentities->int_val
|
2021-07-22 06:39:28 +00:00
|
|
|
|| !ent->renderer.model)
|
2021-01-19 16:25:54 +00:00
|
|
|
return;
|
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
EntQueue_AddEntity (r_ent_queue, ent, ent->renderer.model->type);
|
2021-01-19 16:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_RenderView (qfv_renderframe_t *rFrame)
|
2021-01-19 16:25:54 +00:00
|
|
|
{
|
2021-12-02 12:58:29 +00:00
|
|
|
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
|
2021-12-17 06:52:17 +00:00
|
|
|
double t[10] = {};
|
2021-01-19 16:25:54 +00:00
|
|
|
int speeds = r_speeds->int_val;
|
|
|
|
|
2021-12-02 09:30:57 +00:00
|
|
|
if (!r_worldentity.renderer.model) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-19 16:25:54 +00:00
|
|
|
if (speeds)
|
|
|
|
t[0] = Sys_DoubleTime ();
|
|
|
|
setup_frame (ctx);
|
|
|
|
if (speeds)
|
|
|
|
t[1] = Sys_DoubleTime ();
|
|
|
|
R_MarkLeaves ();
|
|
|
|
if (speeds)
|
|
|
|
t[2] = Sys_DoubleTime ();
|
|
|
|
R_PushDlights (vec3_origin);
|
|
|
|
if (speeds)
|
|
|
|
t[3] = Sys_DoubleTime ();
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_DrawWorld (rFrame);
|
2021-01-19 16:25:54 +00:00
|
|
|
if (speeds)
|
|
|
|
t[4] = Sys_DoubleTime ();
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_DrawSky (rFrame);
|
2021-01-19 16:25:54 +00:00
|
|
|
if (speeds)
|
|
|
|
t[5] = Sys_DoubleTime ();
|
2021-07-25 05:03:25 +00:00
|
|
|
Vulkan_DrawViewModel (ctx);
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_RenderEntities (rFrame);
|
2021-01-19 16:25:54 +00:00
|
|
|
if (speeds)
|
|
|
|
t[6] = Sys_DoubleTime ();
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_DrawWaterSurfaces (rFrame);
|
2021-01-19 16:25:54 +00:00
|
|
|
if (speeds)
|
|
|
|
t[7] = Sys_DoubleTime ();
|
|
|
|
Vulkan_DrawParticles (ctx);
|
|
|
|
if (speeds)
|
|
|
|
t[8] = Sys_DoubleTime ();
|
2021-12-17 06:52:17 +00:00
|
|
|
Vulkan_Bsp_Flush (ctx);
|
|
|
|
if (speeds)
|
|
|
|
t[9] = Sys_DoubleTime ();
|
2021-01-19 16:25:54 +00:00
|
|
|
if (speeds) {
|
2021-12-17 06:52:17 +00:00
|
|
|
double total = (t[9] - t[0]) * 1000;
|
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
|
t[i] = (t[i + 1] - t[i]) * 1000;
|
|
|
|
}
|
2021-01-19 16:25:54 +00:00
|
|
|
Sys_Printf ("frame: %g, setup: %g, mark: %g, pushdl: %g, world: %g,"
|
2021-12-17 06:52:17 +00:00
|
|
|
" sky: %g, ents: %g, water: %g, flush: %g, part: %g\n",
|
|
|
|
total,
|
|
|
|
t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8]);
|
2021-01-19 16:25:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Vulkan_NewMap (model_t *worldmodel, struct model_s **models, int num_models,
|
|
|
|
vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
d_lightstylevalue[i] = 264; // normal light value
|
|
|
|
}
|
|
|
|
|
|
|
|
memset (&r_worldentity, 0, sizeof (r_worldentity));
|
2021-03-09 14:52:40 +00:00
|
|
|
r_worldentity.renderer.model = worldmodel;
|
2021-01-19 16:25:54 +00:00
|
|
|
|
|
|
|
// Force a vis update
|
|
|
|
r_viewleaf = NULL;
|
|
|
|
R_MarkLeaves ();
|
|
|
|
|
2021-12-19 04:08:39 +00:00
|
|
|
R_ClearParticles ();
|
2021-01-19 16:25:54 +00:00
|
|
|
Vulkan_RegisterTextures (models, num_models, ctx);
|
2021-03-20 09:02:27 +00:00
|
|
|
//Vulkan_BuildLightmaps (models, num_models, ctx);
|
2021-01-19 16:25:54 +00:00
|
|
|
Vulkan_BuildDisplayLists (models, num_models, ctx);
|
2021-03-20 07:08:44 +00:00
|
|
|
Vulkan_LoadLights (worldmodel, worldmodel->brush.entities, ctx);
|
2021-01-19 16:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*void
|
|
|
|
glsl_R_LineGraph (int x, int y, int *h_vals, int count)
|
|
|
|
{
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/*void
|
|
|
|
glsl_R_TimeRefresh_f (void)
|
|
|
|
{
|
|
|
|
double start, stop, time;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
glsl_ctx->end_rendering ();
|
|
|
|
|
|
|
|
start = Sys_DoubleTime ();
|
|
|
|
for (i = 0; i < 128; i++) {
|
|
|
|
r_refdef.viewangles[1] = i * (360.0 / 128.0);
|
|
|
|
Vulkan_RenderView (ctx);
|
|
|
|
glsl_ctx->end_rendering ();
|
|
|
|
}
|
|
|
|
|
|
|
|
stop = Sys_DoubleTime ();
|
|
|
|
time = stop - start;
|
|
|
|
Sys_Printf ("%g seconds (%g fps)\n", time, 128 / time);
|
|
|
|
}*/
|