2019-07-06 05:42:53 +00:00
|
|
|
/*
|
|
|
|
vulkan_draw.c
|
|
|
|
|
|
|
|
2D drawing support for Vulkan
|
|
|
|
|
2021-01-10 06:52:27 +00:00
|
|
|
Copyright (C) 2021 Bill Currie <bill@taniwha.org>
|
2019-07-06 05:42:53 +00:00
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
2021-01-10 06:52:27 +00:00
|
|
|
Date: 2021/1/10
|
2019-07-06 05:42:53 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-02-05 07:25:08 +00:00
|
|
|
#include "QF/cmem.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/draw.h"
|
|
|
|
#include "QF/dstring.h"
|
|
|
|
#include "QF/hash.h"
|
|
|
|
#include "QF/quakefs.h"
|
2021-01-13 01:43:23 +00:00
|
|
|
#include "QF/render.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
#include "QF/sys.h"
|
2021-04-18 11:40:43 +00:00
|
|
|
#include "QF/va.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
#include "QF/vid.h"
|
|
|
|
|
2021-01-10 06:52:27 +00:00
|
|
|
#include "compat.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
#include "QF/Vulkan/qf_draw.h"
|
2021-12-08 06:28:21 +00:00
|
|
|
#include "QF/Vulkan/qf_matrices.h"
|
2022-05-30 03:10:00 +00:00
|
|
|
#include "QF/Vulkan/qf_renderpass.h"
|
2022-08-31 10:23:30 +00:00
|
|
|
#include "QF/Vulkan/qf_texture.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
#include "QF/Vulkan/qf_vid.h"
|
2021-01-10 16:27:40 +00:00
|
|
|
#include "QF/Vulkan/barrier.h"
|
2021-01-12 02:27:41 +00:00
|
|
|
#include "QF/Vulkan/buffer.h"
|
|
|
|
#include "QF/Vulkan/command.h"
|
2021-04-18 11:40:43 +00:00
|
|
|
#include "QF/Vulkan/debug.h"
|
2021-01-10 06:52:27 +00:00
|
|
|
#include "QF/Vulkan/descriptor.h"
|
|
|
|
#include "QF/Vulkan/device.h"
|
|
|
|
#include "QF/Vulkan/image.h"
|
2021-12-02 13:48:50 +00:00
|
|
|
#include "QF/Vulkan/instance.h"
|
2021-01-21 07:39:11 +00:00
|
|
|
#include "QF/Vulkan/scrap.h"
|
2021-01-10 16:27:40 +00:00
|
|
|
#include "QF/Vulkan/staging.h"
|
2021-07-10 09:04:34 +00:00
|
|
|
#include "QF/ui/view.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
|
2022-08-31 10:23:30 +00:00
|
|
|
#include "r_font.h"
|
2022-09-04 11:56:38 +00:00
|
|
|
#include "r_text.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
#include "r_internal.h"
|
2021-01-10 06:52:27 +00:00
|
|
|
#include "vid_vulkan.h"
|
|
|
|
|
2021-01-12 02:27:41 +00:00
|
|
|
typedef struct {
|
|
|
|
float xy[2];
|
2021-01-12 04:51:41 +00:00
|
|
|
float st[2];
|
2021-01-12 02:27:41 +00:00
|
|
|
float color[4];
|
|
|
|
} drawvert_t;
|
|
|
|
|
2021-01-13 15:44:34 +00:00
|
|
|
typedef struct cachepic_s {
|
|
|
|
char *name;
|
|
|
|
qpic_t *pic;
|
|
|
|
} cachepic_t;
|
|
|
|
|
2022-09-09 08:06:33 +00:00
|
|
|
typedef struct vertqueue_s {
|
|
|
|
drawvert_t *verts;
|
|
|
|
int count;
|
|
|
|
int size;
|
|
|
|
} vertqueue_t;
|
|
|
|
|
2021-01-16 05:42:25 +00:00
|
|
|
typedef struct drawframe_s {
|
|
|
|
size_t vert_offset;
|
2022-09-02 05:23:19 +00:00
|
|
|
size_t iavert_offset;
|
2022-05-28 09:14:26 +00:00
|
|
|
size_t line_offset;
|
2022-09-09 08:06:33 +00:00
|
|
|
vertqueue_t quad_verts;
|
|
|
|
vertqueue_t iaquad_verts;
|
|
|
|
vertqueue_t line_verts;
|
2021-01-16 05:42:25 +00:00
|
|
|
VkCommandBuffer cmd;
|
|
|
|
VkDescriptorSet descriptors;
|
2022-09-02 05:23:19 +00:00
|
|
|
VkDescriptorSet iadescriptors;
|
2021-01-16 05:42:25 +00:00
|
|
|
} drawframe_t;
|
|
|
|
|
|
|
|
typedef struct drawframeset_s
|
|
|
|
DARRAY_TYPE (drawframe_t) drawframeset_t;
|
|
|
|
|
|
|
|
typedef struct drawctx_s {
|
|
|
|
VkSampler sampler;
|
|
|
|
scrap_t *scrap;
|
2022-08-31 10:23:30 +00:00
|
|
|
rfont_t *font;
|
|
|
|
qfv_tex_t *font_tex;
|
2021-01-16 05:42:25 +00:00
|
|
|
qfv_stagebuf_t *stage;
|
2021-12-18 04:07:56 +00:00
|
|
|
qpic_t *crosshair;
|
2021-01-16 05:42:25 +00:00
|
|
|
qpic_t *conchars;
|
|
|
|
qpic_t *conback;
|
|
|
|
qpic_t *white_pic;
|
2021-02-05 07:25:08 +00:00
|
|
|
// use two separate cmem blocks for pics and strings (cachepic names)
|
|
|
|
// to ensure the names are never in the same cacheline as a pic since the
|
|
|
|
// names are used only for lookup
|
|
|
|
memsuper_t *pic_memsuper;
|
|
|
|
memsuper_t *string_memsuper;
|
2021-01-16 05:42:25 +00:00
|
|
|
hashtab_t *pic_cache;
|
|
|
|
VkBuffer vert_buffer;
|
|
|
|
VkDeviceMemory vert_memory;
|
|
|
|
VkBuffer ind_buffer;
|
|
|
|
VkDeviceMemory ind_memory;
|
2022-05-28 09:14:26 +00:00
|
|
|
VkPipeline quad_pipeline;
|
2022-09-02 05:23:19 +00:00
|
|
|
VkPipeline iaquad_pipeline;
|
2022-05-28 09:14:26 +00:00
|
|
|
VkPipeline line_pipeline;
|
2021-01-16 05:42:25 +00:00
|
|
|
VkPipelineLayout layout;
|
|
|
|
drawframeset_t frames;
|
|
|
|
} drawctx_t;
|
|
|
|
|
|
|
|
// enough for a full screen of 8x8 chars at 1920x1080 plus some extras (368)
|
|
|
|
#define MAX_QUADS (32768)
|
2021-01-12 02:27:41 +00:00
|
|
|
#define VERTS_PER_QUAD (4)
|
|
|
|
#define INDS_PER_QUAD (5) // one per vert plus primitive reset
|
|
|
|
|
2022-05-28 09:14:26 +00:00
|
|
|
#define MAX_LINES (32768)
|
|
|
|
#define VERTS_PER_LINE (2)
|
|
|
|
|
2022-09-02 05:23:19 +00:00
|
|
|
#define QUADS_OFFSET 0
|
|
|
|
#define IAQUADS_OFFSET (MAX_QUADS * VERTS_PER_QUAD)
|
|
|
|
#define LINES_OFFSET (IAQUADS_OFFSET + (MAX_QUADS * VERTS_PER_QUAD))
|
|
|
|
|
|
|
|
#define VERTS_PER_FRAME (LINES_OFFSET + MAX_LINES*VERTS_PER_LINE)
|
2022-05-28 09:14:26 +00:00
|
|
|
|
2021-01-12 02:27:41 +00:00
|
|
|
static void
|
|
|
|
create_quad_buffers (vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
|
|
|
|
size_t vert_size;
|
|
|
|
size_t ind_size;
|
2021-02-05 01:22:32 +00:00
|
|
|
size_t frames = ctx->frames.size;
|
2021-01-16 05:42:25 +00:00
|
|
|
VkBuffer vbuf, ibuf;
|
|
|
|
VkDeviceMemory vmem, imem;
|
|
|
|
|
2022-05-28 09:14:26 +00:00
|
|
|
vert_size = frames * VERTS_PER_FRAME * sizeof (drawvert_t);
|
2021-01-16 05:42:25 +00:00
|
|
|
ind_size = MAX_QUADS * INDS_PER_QUAD * sizeof (uint32_t);
|
|
|
|
|
|
|
|
vbuf = QFV_CreateBuffer (device, vert_size,
|
|
|
|
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
|
|
|
|
ibuf = QFV_CreateBuffer (device, ind_size,
|
2021-01-16 06:09:39 +00:00
|
|
|
VK_BUFFER_USAGE_INDEX_BUFFER_BIT
|
|
|
|
| VK_BUFFER_USAGE_TRANSFER_DST_BIT);
|
2021-01-16 05:42:25 +00:00
|
|
|
vmem = QFV_AllocBufferMemory (device, vbuf,
|
|
|
|
VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
|
|
|
|
vert_size, 0);
|
|
|
|
imem = QFV_AllocBufferMemory (device, ibuf,
|
|
|
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
|
|
|
ind_size, 0);
|
|
|
|
QFV_BindBufferMemory (device, vbuf, vmem, 0);
|
|
|
|
QFV_BindBufferMemory (device, ibuf, imem, 0);
|
|
|
|
|
|
|
|
dctx->vert_buffer = vbuf;
|
|
|
|
dctx->vert_memory = vmem;
|
|
|
|
dctx->ind_buffer = ibuf;
|
|
|
|
dctx->ind_memory = imem;
|
|
|
|
|
2021-01-12 02:27:41 +00:00
|
|
|
void *data;
|
2021-01-16 05:42:25 +00:00
|
|
|
dfunc->vkMapMemory (device->dev, vmem, 0, vert_size, 0, &data);
|
|
|
|
drawvert_t *vert_data = data;
|
|
|
|
|
|
|
|
for (size_t f = 0; f < frames; f++) {
|
|
|
|
drawframe_t *frame = &dctx->frames.a[f];
|
2022-05-28 09:14:26 +00:00
|
|
|
size_t ind = f * VERTS_PER_FRAME;
|
2022-09-02 05:23:19 +00:00
|
|
|
size_t iaind = ind + IAQUADS_OFFSET;
|
|
|
|
size_t lind = ind + LINES_OFFSET;
|
2021-01-16 05:42:25 +00:00
|
|
|
frame->vert_offset = ind * sizeof (drawvert_t);
|
2022-09-02 05:23:19 +00:00
|
|
|
frame->iavert_offset = iaind;
|
2022-05-28 09:14:26 +00:00
|
|
|
frame->line_offset = lind;
|
2022-09-09 08:06:33 +00:00
|
|
|
frame->quad_verts = (vertqueue_t) {
|
|
|
|
.verts = vert_data + ind,
|
|
|
|
.size = MAX_QUADS,
|
|
|
|
};
|
|
|
|
frame->iaquad_verts = (vertqueue_t) {
|
|
|
|
.verts = frame->quad_verts.verts + IAQUADS_OFFSET,
|
|
|
|
.size = MAX_QUADS,
|
|
|
|
};
|
|
|
|
frame->line_verts = (vertqueue_t) {
|
|
|
|
.verts = frame->quad_verts.verts + LINES_OFFSET,
|
|
|
|
.size = MAX_LINES,
|
|
|
|
};
|
2021-01-16 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The indices will never change so pre-generate and stash them
|
|
|
|
qfv_packet_t *packet = QFV_PacketAcquire (ctx->staging);
|
|
|
|
uint32_t *ind = QFV_PacketExtend (packet, ind_size);
|
2021-01-12 02:27:41 +00:00
|
|
|
for (int i = 0; i < MAX_QUADS; i++) {
|
|
|
|
for (int j = 0; j < VERTS_PER_QUAD; j++) {
|
|
|
|
*ind++ = i * VERTS_PER_QUAD + j;
|
|
|
|
}
|
|
|
|
// mark end of primitive
|
|
|
|
*ind++ = -1;
|
|
|
|
}
|
2021-01-16 06:09:39 +00:00
|
|
|
|
2021-04-24 06:47:31 +00:00
|
|
|
qfv_bufferbarrier_t bb = bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
|
|
|
|
bb.barrier.buffer = ibuf;
|
|
|
|
bb.barrier.size = ind_size;
|
|
|
|
dfunc->vkCmdPipelineBarrier (packet->cmd, bb.srcStages, bb.dstStages,
|
|
|
|
0, 0, 0, 1, &bb.barrier, 0, 0);
|
2021-01-16 05:42:25 +00:00
|
|
|
VkBufferCopy copy_region = { packet->offset, 0, ind_size };
|
|
|
|
dfunc->vkCmdCopyBuffer (packet->cmd, ctx->staging->buffer, ibuf,
|
|
|
|
1, ©_region);
|
2021-04-24 06:47:31 +00:00
|
|
|
bb = bufferBarriers[qfv_BB_TransferWrite_to_IndexRead];
|
|
|
|
bb.barrier.buffer = ibuf;
|
|
|
|
bb.barrier.size = ind_size;
|
|
|
|
dfunc->vkCmdPipelineBarrier (packet->cmd, bb.srcStages, bb.dstStages,
|
|
|
|
0, 0, 0, 1, &bb.barrier, 0, 0);
|
2021-01-16 05:42:25 +00:00
|
|
|
QFV_PacketSubmit (packet);
|
2021-01-12 02:27:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_quad_buffers (vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
2021-01-12 02:27:41 +00:00
|
|
|
|
2021-01-16 05:42:25 +00:00
|
|
|
dfunc->vkUnmapMemory (device->dev, dctx->vert_memory);
|
|
|
|
dfunc->vkFreeMemory (device->dev, dctx->vert_memory, 0);
|
|
|
|
dfunc->vkFreeMemory (device->dev, dctx->ind_memory, 0);
|
|
|
|
dfunc->vkDestroyBuffer (device->dev, dctx->vert_buffer, 0);
|
|
|
|
dfunc->vkDestroyBuffer (device->dev, dctx->ind_buffer, 0);
|
2021-01-12 02:27:41 +00:00
|
|
|
}
|
2019-07-06 05:42:53 +00:00
|
|
|
|
2021-01-13 06:28:56 +00:00
|
|
|
static void
|
|
|
|
flush_draw_scrap (vulkan_ctx_t *ctx)
|
|
|
|
{
|
2021-01-16 05:42:25 +00:00
|
|
|
QFV_ScrapFlush (ctx->draw_context->scrap);
|
2021-01-13 06:28:56 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 15:44:34 +00:00
|
|
|
static void
|
2021-02-05 07:25:08 +00:00
|
|
|
pic_free (drawctx_t *dctx, qpic_t *pic)
|
2021-01-13 15:44:34 +00:00
|
|
|
{
|
2021-03-27 10:55:43 +00:00
|
|
|
subpic_t *subpic = *(subpic_t **) &pic->data[0];
|
2021-01-13 15:44:34 +00:00
|
|
|
QFV_SubpicDelete (subpic);
|
2021-02-05 07:25:08 +00:00
|
|
|
cmemfree (dctx->pic_memsuper, pic);
|
2021-01-13 15:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static cachepic_t *
|
2021-02-05 07:25:08 +00:00
|
|
|
new_cachepic (drawctx_t *dctx, const char *name, qpic_t *pic)
|
2021-01-13 15:44:34 +00:00
|
|
|
{
|
|
|
|
cachepic_t *cp;
|
2021-02-05 07:25:08 +00:00
|
|
|
size_t size = strlen (name) + 1;
|
2021-01-13 15:44:34 +00:00
|
|
|
|
2021-02-05 07:25:08 +00:00
|
|
|
cp = cmemalloc (dctx->pic_memsuper, sizeof (cachepic_t));
|
|
|
|
cp->name = cmemalloc (dctx->string_memsuper, size);
|
|
|
|
memcpy (cp->name, name, size);
|
2021-01-13 15:44:34 +00:00
|
|
|
cp->pic = pic;
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-02-05 07:25:08 +00:00
|
|
|
cachepic_free (void *_cp, void *_dctx)
|
2021-01-13 15:44:34 +00:00
|
|
|
{
|
2021-02-05 07:25:08 +00:00
|
|
|
drawctx_t *dctx = _dctx;
|
2021-01-13 15:44:34 +00:00
|
|
|
cachepic_t *cp = (cachepic_t *) _cp;
|
2021-02-05 07:25:08 +00:00
|
|
|
pic_free (dctx, cp->pic);
|
|
|
|
cmemfree (dctx->string_memsuper, cp->name);
|
|
|
|
cmemfree (dctx->pic_memsuper, cp);
|
2021-01-13 15:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
cachepic_getkey (const void *_cp, void *unused)
|
|
|
|
{
|
|
|
|
return ((cachepic_t *) _cp)->name;
|
|
|
|
}
|
|
|
|
|
2020-02-11 03:19:16 +00:00
|
|
|
static qpic_t *
|
2021-01-16 05:42:25 +00:00
|
|
|
pic_data (const char *name, int w, int h, const byte *data, drawctx_t *dctx)
|
2020-02-11 03:19:16 +00:00
|
|
|
{
|
|
|
|
qpic_t *pic;
|
2021-01-13 06:28:56 +00:00
|
|
|
subpic_t *subpic;
|
|
|
|
byte *picdata;
|
2020-02-11 03:19:16 +00:00
|
|
|
|
2021-02-05 07:25:08 +00:00
|
|
|
pic = cmemalloc (dctx->pic_memsuper,
|
|
|
|
field_offset (qpic_t, data[sizeof (subpic_t *)]));
|
2020-02-11 03:19:16 +00:00
|
|
|
pic->width = w;
|
|
|
|
pic->height = h;
|
2021-01-13 06:28:56 +00:00
|
|
|
|
2021-01-16 05:42:25 +00:00
|
|
|
subpic = QFV_ScrapSubpic (dctx->scrap, w, h);
|
2021-01-13 06:28:56 +00:00
|
|
|
*(subpic_t **) pic->data = subpic;
|
|
|
|
|
2021-01-16 05:42:25 +00:00
|
|
|
picdata = QFV_SubpicBatch (subpic, dctx->stage);
|
2021-01-13 06:28:56 +00:00
|
|
|
size_t size = w * h;
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
|
|
|
byte pix = *data++;
|
|
|
|
byte *col = vid.palette + pix * 3;
|
2022-08-30 05:29:22 +00:00
|
|
|
byte alpha = (pix == 255) - 1;
|
|
|
|
// pre-multiply alpha.
|
|
|
|
*picdata++ = *col++ & alpha;
|
|
|
|
*picdata++ = *col++ & alpha;
|
|
|
|
*picdata++ = *col++ & alpha;
|
|
|
|
*picdata++ = alpha;
|
2021-01-13 06:28:56 +00:00
|
|
|
}
|
2022-04-23 01:46:55 +00:00
|
|
|
//FIXME live updates of the scrap aren't
|
|
|
|
//syncronized properly for some reason and result in stale texels being
|
|
|
|
//rendered (flashing pink around the Q menu cursor the first time it's
|
|
|
|
//displayed). I suspect simple barriers aren't enough and more
|
|
|
|
//sophisticated syncronization (events? semaphores?) is needed.
|
2020-02-11 03:19:16 +00:00
|
|
|
return pic;
|
|
|
|
}
|
|
|
|
|
2019-07-06 05:42:53 +00:00
|
|
|
qpic_t *
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_MakePic (int width, int height, const byte *data,
|
|
|
|
vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-16 05:42:25 +00:00
|
|
|
return pic_data (0, width, height, data, ctx->draw_context);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_DestroyPic (qpic_t *pic, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
qpic_t *
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_PicFromWad (const char *name, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-13 06:28:56 +00:00
|
|
|
qpic_t *wadpic = W_GetLumpName (name);
|
|
|
|
|
|
|
|
if (!wadpic) {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-02-05 07:25:08 +00:00
|
|
|
return pic_data (name, wadpic->width, wadpic->height, wadpic->data,
|
|
|
|
ctx->draw_context);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qpic_t *
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_CachePic (const char *path, qboolean alpha, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-13 15:44:34 +00:00
|
|
|
qpic_t *p;
|
|
|
|
qpic_t *pic;
|
|
|
|
cachepic_t *cpic;
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
2021-01-13 15:44:34 +00:00
|
|
|
|
2021-01-16 05:42:25 +00:00
|
|
|
if ((cpic = Hash_Find (dctx->pic_cache, path))) {
|
2021-01-13 15:44:34 +00:00
|
|
|
return cpic->pic;
|
|
|
|
}
|
|
|
|
if (strlen (path) < 4 || strcmp (path + strlen (path) - 4, ".lmp")
|
|
|
|
|| !(p = (qpic_t *) QFS_LoadFile (QFS_FOpenFile (path), 0))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-16 05:42:25 +00:00
|
|
|
pic = pic_data (path, p->width, p->height, p->data, dctx);
|
2021-01-13 15:44:34 +00:00
|
|
|
free (p);
|
2021-02-05 07:25:08 +00:00
|
|
|
cpic = new_cachepic (dctx, path, pic);
|
2021-01-16 05:42:25 +00:00
|
|
|
Hash_Add (dctx->pic_cache, cpic);
|
2021-01-13 15:44:34 +00:00
|
|
|
return pic;
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_UncachePic (const char *path, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
Hash_Free (dctx->pic_cache, Hash_Del (dctx->pic_cache, path));
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 02:27:41 +00:00
|
|
|
void
|
|
|
|
Vulkan_Draw_Shutdown (vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-10 06:52:27 +00:00
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
2021-01-10 06:52:27 +00:00
|
|
|
|
2021-01-12 02:27:41 +00:00
|
|
|
destroy_quad_buffers (ctx);
|
|
|
|
|
2022-05-28 09:14:26 +00:00
|
|
|
dfunc->vkDestroyPipeline (device->dev, dctx->quad_pipeline, 0);
|
2022-09-02 05:23:19 +00:00
|
|
|
dfunc->vkDestroyPipeline (device->dev, dctx->iaquad_pipeline, 0);
|
2022-05-28 09:14:26 +00:00
|
|
|
dfunc->vkDestroyPipeline (device->dev, dctx->line_pipeline, 0);
|
2021-02-05 07:25:08 +00:00
|
|
|
Hash_DelTable (dctx->pic_cache);
|
|
|
|
delete_memsuper (dctx->pic_memsuper);
|
|
|
|
delete_memsuper (dctx->string_memsuper);
|
2021-01-16 05:42:25 +00:00
|
|
|
QFV_DestroyScrap (dctx->scrap);
|
|
|
|
QFV_DestroyStagingBuffer (dctx->stage);
|
2022-08-31 10:23:30 +00:00
|
|
|
if (dctx->font_tex) {
|
|
|
|
Vulkan_UnloadTex (ctx, dctx->font_tex);
|
|
|
|
}
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_Init (vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-10 06:52:27 +00:00
|
|
|
qfv_device_t *device = ctx->device;
|
2021-01-10 16:27:40 +00:00
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
2021-12-02 13:48:50 +00:00
|
|
|
qfvPushDebug (ctx, "draw init");
|
|
|
|
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = calloc (1, sizeof (drawctx_t));
|
|
|
|
ctx->draw_context = dctx;
|
|
|
|
|
2021-02-05 01:22:32 +00:00
|
|
|
size_t frames = ctx->frames.size;
|
2021-01-16 05:42:25 +00:00
|
|
|
DARRAY_INIT (&dctx->frames, frames);
|
|
|
|
DARRAY_RESIZE (&dctx->frames, frames);
|
|
|
|
dctx->frames.grow = 0;
|
|
|
|
|
2021-02-05 07:25:08 +00:00
|
|
|
dctx->pic_memsuper = new_memsuper ();
|
|
|
|
dctx->string_memsuper = new_memsuper ();
|
2021-01-16 05:42:25 +00:00
|
|
|
dctx->pic_cache = Hash_NewTable (127, cachepic_getkey, cachepic_free,
|
2021-02-05 07:25:08 +00:00
|
|
|
dctx, 0);
|
2021-01-13 15:44:34 +00:00
|
|
|
|
2021-01-12 02:27:41 +00:00
|
|
|
create_quad_buffers (ctx);
|
2021-01-31 10:58:55 +00:00
|
|
|
dctx->stage = QFV_CreateStagingBuffer (device, "draw", 4 * 1024 * 1024,
|
2021-01-19 16:23:24 +00:00
|
|
|
ctx->cmdpool);
|
2021-01-31 10:58:55 +00:00
|
|
|
dctx->scrap = QFV_CreateScrap (device, "draw_atlas", 2048, tex_rgba,
|
|
|
|
dctx->stage);
|
2021-02-04 08:03:49 +00:00
|
|
|
dctx->sampler = Vulkan_CreateSampler (ctx, "quakepic");
|
2021-01-12 02:27:41 +00:00
|
|
|
|
2021-03-21 02:37:36 +00:00
|
|
|
draw_chars = W_GetLumpName ("conchars");
|
|
|
|
if (draw_chars) {
|
|
|
|
for (int i = 0; i < 256 * 64; i++) {
|
|
|
|
if (draw_chars[i] == 0) {
|
|
|
|
draw_chars[i] = 255; // proper transparent color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dctx->conchars = pic_data ("conchars", 128, 128, draw_chars, dctx);
|
|
|
|
} else {
|
|
|
|
qpic_t *charspic = Draw_Font8x8Pic ();
|
|
|
|
dctx->conchars = pic_data ("conchars", charspic->width,
|
|
|
|
charspic->height, charspic->data, dctx);
|
2021-12-18 04:07:56 +00:00
|
|
|
free (charspic);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
qpic_t *hairpic = Draw_CrosshairPic ();
|
|
|
|
dctx->crosshair = pic_data ("crosshair", hairpic->width,
|
|
|
|
hairpic->height, hairpic->data, dctx);
|
|
|
|
free (hairpic);
|
2021-03-21 02:37:36 +00:00
|
|
|
}
|
2021-01-10 06:52:27 +00:00
|
|
|
|
2021-01-13 15:44:34 +00:00
|
|
|
byte white_block = 0xfe;
|
2021-01-16 05:42:25 +00:00
|
|
|
dctx->white_pic = pic_data ("white", 1, 1, &white_block, dctx);
|
2021-01-10 16:27:40 +00:00
|
|
|
|
2021-01-13 06:28:56 +00:00
|
|
|
flush_draw_scrap (ctx);
|
2021-01-10 16:27:40 +00:00
|
|
|
|
2022-05-28 09:14:26 +00:00
|
|
|
dctx->quad_pipeline = Vulkan_CreateGraphicsPipeline (ctx, "twod");
|
2022-09-02 05:23:19 +00:00
|
|
|
dctx->iaquad_pipeline = Vulkan_CreateGraphicsPipeline (ctx,
|
|
|
|
"twod_impalpha");
|
2022-05-28 09:14:26 +00:00
|
|
|
dctx->line_pipeline = Vulkan_CreateGraphicsPipeline (ctx, "lines");
|
2021-01-12 02:27:41 +00:00
|
|
|
|
2021-02-04 08:03:49 +00:00
|
|
|
dctx->layout = Vulkan_CreatePipelineLayout (ctx, "twod_layout");
|
2021-01-10 06:52:27 +00:00
|
|
|
|
2021-01-19 16:23:24 +00:00
|
|
|
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
|
2021-01-10 06:52:27 +00:00
|
|
|
for (size_t i = 0; i < layouts->size; i++) {
|
2021-02-04 08:03:49 +00:00
|
|
|
layouts->a[i] = Vulkan_CreateDescriptorSetLayout (ctx, "twod_set");
|
2021-01-10 06:52:27 +00:00
|
|
|
}
|
2021-02-04 08:03:49 +00:00
|
|
|
__auto_type pool = Vulkan_CreateDescriptorPool (ctx, "twod_pool");
|
2021-01-12 02:27:41 +00:00
|
|
|
|
|
|
|
VkDescriptorImageInfo imageInfo = {
|
2021-01-16 05:42:25 +00:00
|
|
|
dctx->sampler,
|
|
|
|
QFV_ScrapImageView (dctx->scrap),
|
2021-01-12 02:27:41 +00:00
|
|
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
|
|
};
|
2022-09-02 05:23:19 +00:00
|
|
|
VkDescriptorImageInfo iaimageInfo = {
|
|
|
|
dctx->sampler,
|
|
|
|
Vulkan_TexImageView (ctx->default_magenta),
|
|
|
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
|
|
};
|
2021-01-15 13:45:49 +00:00
|
|
|
__auto_type cmdBuffers = QFV_AllocCommandBufferSet (frames, alloca);
|
|
|
|
QFV_AllocateCommandBuffers (device, ctx->cmdpool, 1, cmdBuffers);
|
2021-01-12 02:27:41 +00:00
|
|
|
|
2021-01-10 06:52:27 +00:00
|
|
|
__auto_type sets = QFV_AllocateDescriptorSet (device, pool, layouts);
|
2022-09-02 05:23:19 +00:00
|
|
|
__auto_type iasets = QFV_AllocateDescriptorSet (device, pool, layouts);
|
2021-01-15 13:45:49 +00:00
|
|
|
for (size_t i = 0; i < frames; i++) {
|
2021-01-16 05:42:25 +00:00
|
|
|
__auto_type dframe = &dctx->frames.a[i];
|
|
|
|
dframe->descriptors = sets->a[i];
|
2022-09-02 05:23:19 +00:00
|
|
|
dframe->iadescriptors = iasets->a[i];
|
2021-01-12 02:27:41 +00:00
|
|
|
|
|
|
|
VkWriteDescriptorSet write[] = {
|
|
|
|
{ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 0,
|
2021-01-16 05:42:25 +00:00
|
|
|
dframe->descriptors, 0, 0, 1,
|
2021-01-12 02:27:41 +00:00
|
|
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
|
|
|
&imageInfo, 0, 0 },
|
2022-09-02 05:23:19 +00:00
|
|
|
{ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 0,
|
|
|
|
dframe->iadescriptors, 0, 0, 1,
|
|
|
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
|
|
|
&iaimageInfo, 0, 0 },
|
2021-01-12 02:27:41 +00:00
|
|
|
};
|
2022-09-02 05:23:19 +00:00
|
|
|
dfunc->vkUpdateDescriptorSets (device->dev, 2, write, 0, 0);
|
2021-01-16 05:42:25 +00:00
|
|
|
dframe->cmd = cmdBuffers->a[i];
|
2021-04-18 11:40:43 +00:00
|
|
|
QFV_duSetObjectName (device, VK_OBJECT_TYPE_COMMAND_BUFFER,
|
|
|
|
dframe->cmd,
|
|
|
|
va (ctx->va_ctx, "cmd:draw:%zd", i));
|
2021-01-12 02:27:41 +00:00
|
|
|
}
|
|
|
|
free (sets);
|
2021-12-02 13:48:50 +00:00
|
|
|
qfvPopDebug (ctx);
|
2021-01-12 02:27:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2022-09-09 11:05:31 +00:00
|
|
|
draw_pic (float x, float y, int w, int h, subpic_t *subpic,
|
2021-01-12 02:27:41 +00:00
|
|
|
int srcx, int srcy, int srcw, int srch,
|
2022-09-09 08:06:33 +00:00
|
|
|
float *color, vertqueue_t *queue)
|
2021-01-12 02:27:41 +00:00
|
|
|
{
|
2022-09-09 08:06:33 +00:00
|
|
|
if (queue->count >= queue->size) {
|
2021-01-12 02:27:41 +00:00
|
|
|
return;
|
2021-01-10 06:52:27 +00:00
|
|
|
}
|
2021-01-12 02:27:41 +00:00
|
|
|
|
2022-09-09 08:06:33 +00:00
|
|
|
drawvert_t *verts = queue->verts + queue->count * VERTS_PER_QUAD;
|
|
|
|
queue->count++;
|
2021-01-12 02:27:41 +00:00
|
|
|
|
2021-01-13 06:28:56 +00:00
|
|
|
srcx += subpic->rect->x;
|
|
|
|
srcy += subpic->rect->y;
|
|
|
|
|
|
|
|
float size = subpic->size;
|
2021-01-13 01:43:23 +00:00
|
|
|
float sl = (srcx + 0.03125) * size;
|
|
|
|
float sr = (srcx + srcw - 0.03125) * size;
|
|
|
|
float st = (srcy + 0.03125) * size;
|
|
|
|
float sb = (srcy + srch - 0.03125) * size;
|
2021-01-12 02:27:41 +00:00
|
|
|
|
|
|
|
verts[0].xy[0] = x;
|
|
|
|
verts[0].xy[1] = y;
|
|
|
|
verts[0].st[0] = sl;
|
|
|
|
verts[0].st[1] = st;
|
|
|
|
QuatCopy (color, verts[0].color);
|
|
|
|
|
|
|
|
verts[1].xy[0] = x;
|
|
|
|
verts[1].xy[1] = y + h;
|
|
|
|
verts[1].st[0] = sl;
|
|
|
|
verts[1].st[1] = sb;
|
|
|
|
QuatCopy (color, verts[1].color);
|
|
|
|
|
|
|
|
verts[2].xy[0] = x + w;
|
|
|
|
verts[2].xy[1] = y;
|
|
|
|
verts[2].st[0] = sr;
|
|
|
|
verts[2].st[1] = st;
|
|
|
|
QuatCopy (color, verts[2].color);
|
|
|
|
|
|
|
|
verts[3].xy[0] = x + w;
|
|
|
|
verts[3].xy[1] = y + h;
|
|
|
|
verts[3].st[0] = sr;
|
|
|
|
verts[3].st[1] = sb;
|
|
|
|
QuatCopy (color, verts[3].color);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
queue_character (int x, int y, byte chr, vulkan_ctx_t *ctx)
|
|
|
|
{
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
drawframe_t *frame = &dctx->frames.a[ctx->curFrame];
|
|
|
|
|
2021-01-12 02:27:41 +00:00
|
|
|
quat_t color = {1, 1, 1, 1};
|
|
|
|
int cx, cy;
|
|
|
|
cx = chr % 16;
|
|
|
|
cy = chr / 16;
|
|
|
|
|
2022-09-09 11:05:31 +00:00
|
|
|
subpic_t *subpic = *(subpic_t **) dctx->conchars->data;
|
|
|
|
draw_pic (x, y, 8, 8, subpic, cx * 8, cy * 8, 8, 8, color,
|
2022-09-09 08:06:33 +00:00
|
|
|
&frame->quad_verts);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
2022-09-15 05:24:33 +00:00
|
|
|
void
|
|
|
|
Vulkan_Draw_CharBuffer (int x, int y, draw_charbuffer_t *buffer,
|
|
|
|
vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const byte *line = (byte *) buffer->chars;
|
|
|
|
int width = buffer->width;
|
|
|
|
int height = buffer->height;
|
|
|
|
while (height-- > 0) {
|
|
|
|
for (int i = 0; i < width; i++) {
|
|
|
|
Vulkan_Draw_Character (x + i * 8, y, line[i], ctx);
|
|
|
|
}
|
|
|
|
line += width;
|
|
|
|
y += 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-06 05:42:53 +00:00
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_Character (int x, int y, unsigned int chr, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-12 02:27:41 +00:00
|
|
|
if (chr == ' ') {
|
|
|
|
return;
|
|
|
|
}
|
2022-09-21 08:31:18 +00:00
|
|
|
if (y <= -8 || y >= (int) vid.height) {
|
2021-01-12 02:27:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-09-21 08:31:18 +00:00
|
|
|
if (x <= -8 || x >= (int) vid.width) {
|
2021-01-12 02:27:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
queue_character (x, y, chr, ctx);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_String (int x, int y, const char *str, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-12 02:27:41 +00:00
|
|
|
byte chr;
|
|
|
|
|
|
|
|
if (!str || !str[0]) {
|
|
|
|
return;
|
|
|
|
}
|
2022-09-21 08:31:18 +00:00
|
|
|
if (y <= -8 || y >= (int) vid.height) {
|
2021-01-12 02:27:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (*str) {
|
2022-09-21 08:31:18 +00:00
|
|
|
if ((chr = *str++) != ' ' && x >= -8 && x < (int) vid.width) {
|
2021-01-12 02:27:41 +00:00
|
|
|
queue_character (x, y, chr, ctx);
|
|
|
|
}
|
|
|
|
x += 8;
|
|
|
|
}
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_nString (int x, int y, const char *str, int count,
|
|
|
|
vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-12 02:27:41 +00:00
|
|
|
byte chr;
|
|
|
|
|
|
|
|
if (!str || !str[0]) {
|
|
|
|
return;
|
|
|
|
}
|
2022-09-21 08:31:18 +00:00
|
|
|
if (y <= -8 || y >= (int) vid.height) {
|
2021-01-12 02:27:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (count-- > 0 && *str) {
|
2022-09-21 08:31:18 +00:00
|
|
|
if ((chr = *str++) != ' ' && x >= -8 && x < (int) vid.width) {
|
2021-01-12 02:27:41 +00:00
|
|
|
queue_character (x, y, chr, ctx);
|
|
|
|
}
|
|
|
|
x += 8;
|
|
|
|
}
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_AltString (int x, int y, const char *str, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-12 02:27:41 +00:00
|
|
|
byte chr;
|
|
|
|
|
|
|
|
if (!str || !str[0]) {
|
|
|
|
return;
|
|
|
|
}
|
2022-09-21 08:31:18 +00:00
|
|
|
if (y <= -8 || y >= (int) vid.height) {
|
2021-01-12 02:27:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (*str) {
|
|
|
|
if ((chr = *str++ | 0x80) != (' ' | 0x80)
|
2022-09-21 08:31:18 +00:00
|
|
|
&& x >= -8 && x < (int) vid.width) {
|
2021-01-12 02:27:41 +00:00
|
|
|
queue_character (x, y, chr, ctx);
|
|
|
|
}
|
|
|
|
x += 8;
|
|
|
|
}
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
2021-12-18 04:07:56 +00:00
|
|
|
static void
|
|
|
|
draw_crosshair_plus (int ch, int x, int y, vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_Character (x - 4, y - 4, '+', ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_crosshair_pic (int ch, int x, int y, vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
drawframe_t *frame = &dctx->frames.a[ctx->curFrame];
|
|
|
|
|
|
|
|
static const int pos[CROSSHAIR_COUNT][4] = {
|
|
|
|
{0, 0, CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT},
|
|
|
|
{CROSSHAIR_WIDTH, 0, CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT},
|
|
|
|
{0, CROSSHAIR_HEIGHT, CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT},
|
|
|
|
{CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT, CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT},
|
|
|
|
};
|
|
|
|
const int *p = pos[ch - 1];
|
|
|
|
|
2022-09-09 11:05:31 +00:00
|
|
|
subpic_t *subpic = *(subpic_t **) dctx->crosshair->data;
|
2021-12-18 04:07:56 +00:00
|
|
|
draw_pic (x - CROSSHAIR_WIDTH + 1, y - CROSSHAIR_HEIGHT + 1,
|
2022-09-09 11:05:31 +00:00
|
|
|
CROSSHAIR_WIDTH * 2, CROSSHAIR_HEIGHT * 2, subpic,
|
2022-09-09 08:06:33 +00:00
|
|
|
p[0], p[1], p[2], p[3], crosshair_color, &frame->quad_verts);
|
2021-12-18 04:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void (*crosshair_func[]) (int ch, int x, int y, vulkan_ctx_t *ctx) = {
|
|
|
|
draw_crosshair_plus,
|
|
|
|
draw_crosshair_pic,
|
|
|
|
draw_crosshair_pic,
|
|
|
|
draw_crosshair_pic,
|
|
|
|
draw_crosshair_pic,
|
|
|
|
};
|
|
|
|
|
2019-07-06 05:42:53 +00:00
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_CrosshairAt (int ch, int x, int y, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-12-18 04:07:56 +00:00
|
|
|
unsigned c = ch - 1;
|
|
|
|
|
|
|
|
if (c >= sizeof (crosshair_func) / sizeof (crosshair_func[0]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
crosshair_func[c] (c, x, y, ctx);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_Crosshair (vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-12-18 04:07:56 +00:00
|
|
|
int x, y;
|
|
|
|
|
2022-09-21 08:31:18 +00:00
|
|
|
x = vid.width / 2 + cl_crossx;
|
|
|
|
y = vid.height / 2 + cl_crossy;
|
2021-12-18 04:07:56 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Vulkan_Draw_CrosshairAt (crosshair, x, y, ctx);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 01:59:27 +00:00
|
|
|
void
|
|
|
|
Vulkan_Draw_TextBox (int x, int y, int width, int lines, byte alpha,
|
|
|
|
vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
drawframe_t *frame = &dctx->frames.a[ctx->curFrame];
|
|
|
|
|
|
|
|
quat_t color = {1, 1, 1, 1};
|
|
|
|
qpic_t *p;
|
|
|
|
int cx, cy, n;
|
2022-09-09 11:05:31 +00:00
|
|
|
#define draw(px, py, pp) \
|
|
|
|
do { \
|
|
|
|
subpic_t *subpic = *(subpic_t **) (pp)->data; \
|
|
|
|
draw_pic (px, py, pp->width, pp->height, subpic, \
|
|
|
|
0, 0, pp->width, pp->height, color, &frame->quad_verts); \
|
|
|
|
} while (0)
|
2021-07-11 01:59:27 +00:00
|
|
|
|
|
|
|
color[3] = alpha;
|
|
|
|
// draw left side
|
|
|
|
cx = x;
|
|
|
|
cy = y;
|
|
|
|
p = Vulkan_Draw_CachePic ("gfx/box_tl.lmp", true, ctx);
|
|
|
|
draw (cx, cy, p);
|
|
|
|
p = Vulkan_Draw_CachePic ("gfx/box_ml.lmp", true, ctx);
|
|
|
|
for (n = 0; n < lines; n++) {
|
|
|
|
cy += 8;
|
|
|
|
draw (cx, cy, p);
|
|
|
|
}
|
|
|
|
p = Vulkan_Draw_CachePic ("gfx/box_bl.lmp", true, ctx);
|
|
|
|
draw (cx, cy + 8, p);
|
|
|
|
|
|
|
|
// draw middle
|
|
|
|
cx += 8;
|
|
|
|
while (width > 0) {
|
|
|
|
cy = y;
|
|
|
|
p = Vulkan_Draw_CachePic ("gfx/box_tm.lmp", true, ctx);
|
|
|
|
draw (cx, cy, p);
|
|
|
|
p = Vulkan_Draw_CachePic ("gfx/box_mm.lmp", true, ctx);
|
|
|
|
for (n = 0; n < lines; n++) {
|
|
|
|
cy += 8;
|
|
|
|
if (n == 1)
|
|
|
|
p = Vulkan_Draw_CachePic ("gfx/box_mm2.lmp", true, ctx);
|
|
|
|
draw (cx, cy, p);
|
|
|
|
}
|
|
|
|
p = Vulkan_Draw_CachePic ("gfx/box_bm.lmp", true, ctx);
|
|
|
|
draw (cx, cy + 8, p);
|
|
|
|
width -= 2;
|
|
|
|
cx += 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw right side
|
|
|
|
cy = y;
|
|
|
|
p = Vulkan_Draw_CachePic ("gfx/box_tr.lmp", true, ctx);
|
|
|
|
draw (cx, cy, p);
|
|
|
|
p = Vulkan_Draw_CachePic ("gfx/box_mr.lmp", true, ctx);
|
|
|
|
for (n = 0; n < lines; n++) {
|
|
|
|
cy += 8;
|
|
|
|
draw (cx, cy, p);
|
|
|
|
}
|
|
|
|
p = Vulkan_Draw_CachePic ("gfx/box_br.lmp", true, ctx);
|
|
|
|
draw (cx, cy + 8, p);
|
|
|
|
#undef draw
|
|
|
|
}
|
|
|
|
|
2019-07-06 05:42:53 +00:00
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_Pic (int x, int y, qpic_t *pic, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
drawframe_t *frame = &dctx->frames.a[ctx->curFrame];
|
|
|
|
|
2021-01-13 06:28:56 +00:00
|
|
|
static quat_t color = { 1, 1, 1, 1};
|
2022-09-09 11:05:31 +00:00
|
|
|
subpic_t *subpic = *(subpic_t **) pic->data;
|
|
|
|
draw_pic (x, y, pic->width, pic->height, subpic,
|
2022-09-09 08:06:33 +00:00
|
|
|
0, 0, pic->width, pic->height, color, &frame->quad_verts);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_Picf (float x, float y, qpic_t *pic, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
drawframe_t *frame = &dctx->frames.a[ctx->curFrame];
|
|
|
|
|
2021-01-13 06:28:56 +00:00
|
|
|
static quat_t color = { 1, 1, 1, 1};
|
2022-09-09 11:05:31 +00:00
|
|
|
subpic_t *subpic = *(subpic_t **) pic->data;
|
|
|
|
draw_pic (x, y, pic->width, pic->height, subpic,
|
2022-09-09 08:06:33 +00:00
|
|
|
0, 0, pic->width, pic->height, color, &frame->quad_verts);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_SubPic (int x, int y, qpic_t *pic,
|
|
|
|
int srcx, int srcy, int width, int height,
|
|
|
|
vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
drawframe_t *frame = &dctx->frames.a[ctx->curFrame];
|
|
|
|
|
2021-01-13 15:44:34 +00:00
|
|
|
static quat_t color = { 1, 1, 1, 1};
|
2022-09-09 11:05:31 +00:00
|
|
|
subpic_t *subpic = *(subpic_t **) pic->data;
|
|
|
|
draw_pic (x, y, width, height, subpic, srcx, srcy, width, height,
|
2022-09-09 08:06:33 +00:00
|
|
|
color, &frame->quad_verts);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_ConsoleBackground (int lines, byte alpha, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-17 17:10:10 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
drawframe_t *frame = &dctx->frames.a[ctx->curFrame];
|
|
|
|
|
2022-08-30 05:29:22 +00:00
|
|
|
float a = bound (0, alpha, 255) / 255.0;
|
|
|
|
// use pre-multiplied alpha
|
|
|
|
quat_t color = { a, a, a, a};
|
2021-01-17 17:10:10 +00:00
|
|
|
qpic_t *cpic;
|
|
|
|
cpic = Vulkan_Draw_CachePic ("gfx/conback.lmp", false, ctx);
|
2022-09-28 09:29:53 +00:00
|
|
|
float frac = (vid.height - lines) / (float) vid.height;
|
|
|
|
int ofs = frac * cpic->height;
|
2022-09-09 11:05:31 +00:00
|
|
|
subpic_t *subpic = *(subpic_t **) cpic->data;
|
2022-09-21 08:31:18 +00:00
|
|
|
draw_pic (0, 0, vid.width, lines, subpic,
|
2022-09-28 09:29:53 +00:00
|
|
|
0, ofs, cpic->width, cpic->height - ofs, color,
|
|
|
|
&frame->quad_verts);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_TileClear (int x, int y, int w, int h, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_Fill (int x, int y, int w, int h, int c, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
drawframe_t *frame = &dctx->frames.a[ctx->curFrame];
|
|
|
|
|
2021-01-13 15:44:34 +00:00
|
|
|
quat_t color;
|
|
|
|
|
|
|
|
VectorScale (vid.palette + c * 3, 1.0f/255.0f, color);
|
|
|
|
color[3] = 1;
|
2022-09-09 11:05:31 +00:00
|
|
|
subpic_t *subpic = *(subpic_t **) dctx->white_pic->data;
|
|
|
|
draw_pic (x, y, w, h, subpic, 0, 0, 1, 1, color,
|
2022-09-09 08:06:33 +00:00
|
|
|
&frame->quad_verts);
|
2021-01-13 15:44:34 +00:00
|
|
|
}
|
|
|
|
|
2022-05-28 09:14:26 +00:00
|
|
|
void
|
|
|
|
Vulkan_Draw_Line (int x0, int y0, int x1, int y1, int c, vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
drawframe_t *frame = &dctx->frames.a[ctx->curFrame];
|
2022-09-09 08:06:33 +00:00
|
|
|
vertqueue_t *queue = &frame->line_verts;
|
2022-05-28 09:14:26 +00:00
|
|
|
|
2022-09-09 08:06:33 +00:00
|
|
|
if (queue->count >= queue->size) {
|
2022-05-28 09:14:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
quat_t color = { VectorExpand (vid.palette + c * 3), 255 };
|
|
|
|
QuatScale (color, 1/255.0, color);
|
2022-09-09 08:06:33 +00:00
|
|
|
drawvert_t *verts = queue->verts + queue->count * VERTS_PER_LINE;
|
2022-05-28 09:14:26 +00:00
|
|
|
|
2022-09-28 12:53:22 +00:00
|
|
|
subpic_t *subpic = *(subpic_t **) dctx->white_pic->data;
|
|
|
|
int srcx = subpic->rect->x;
|
|
|
|
int srcy = subpic->rect->y;
|
|
|
|
int srcw = subpic->rect->width;
|
|
|
|
int srch = subpic->rect->height;
|
|
|
|
float size = subpic->size;
|
|
|
|
float sl = (srcx + 0.03125) * size;
|
|
|
|
float sr = (srcx + srcw - 0.03125) * size;
|
|
|
|
float st = (srcy + 0.03125) * size;
|
|
|
|
float sb = (srcy + srch - 0.03125) * size;
|
|
|
|
|
2022-05-28 09:14:26 +00:00
|
|
|
verts[0] = (drawvert_t) {
|
|
|
|
.xy = { x0, y0 },
|
2022-09-28 12:53:22 +00:00
|
|
|
.st = {sl, st},
|
2022-05-28 09:14:26 +00:00
|
|
|
.color = { QuatExpand (color) },
|
|
|
|
};
|
|
|
|
verts[1] = (drawvert_t) {
|
|
|
|
.xy = { x1, y1 },
|
2022-09-28 12:53:22 +00:00
|
|
|
.st = {sr, sb},
|
2022-05-28 09:14:26 +00:00
|
|
|
.color = { QuatExpand (color) },
|
|
|
|
};
|
|
|
|
|
2022-09-09 08:06:33 +00:00
|
|
|
queue->count++;
|
2022-05-28 09:14:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 15:44:34 +00:00
|
|
|
static inline void
|
2021-01-16 05:42:25 +00:00
|
|
|
draw_blendscreen (quat_t color, vulkan_ctx_t *ctx)
|
2021-01-13 15:44:34 +00:00
|
|
|
{
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
drawframe_t *frame = &dctx->frames.a[ctx->curFrame];
|
|
|
|
|
2022-09-09 11:05:31 +00:00
|
|
|
subpic_t *subpic = *(subpic_t **) dctx->white_pic->data;
|
2022-09-21 08:31:18 +00:00
|
|
|
draw_pic (0, 0, vid.width, vid.height, subpic,
|
2022-09-09 08:06:33 +00:00
|
|
|
0, 0, 1, 1, color, &frame->quad_verts);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_FadeScreen (vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-13 15:44:34 +00:00
|
|
|
static quat_t color = { 0, 0, 0, 0.7 };
|
2021-01-16 05:42:25 +00:00
|
|
|
draw_blendscreen (color, ctx);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Set2D (vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Set2DScaled (vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_End2D (vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_DrawReset (vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_FlushText (qfv_renderframe_t *rFrame)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-12-02 12:58:29 +00:00
|
|
|
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
|
2021-01-15 13:50:04 +00:00
|
|
|
flush_draw_scrap (ctx);
|
|
|
|
|
2021-01-12 02:27:41 +00:00
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2021-02-05 01:22:32 +00:00
|
|
|
__auto_type cframe = &ctx->frames.a[ctx->curFrame];
|
2021-01-16 05:42:25 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
drawframe_t *dframe = &dctx->frames.a[ctx->curFrame];
|
|
|
|
|
2022-09-09 08:06:33 +00:00
|
|
|
if (!dframe->quad_verts.count && !dframe->iaquad_verts.count
|
|
|
|
&& !dframe->line_verts.count) {
|
2022-05-28 09:14:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-16 05:42:25 +00:00
|
|
|
VkCommandBuffer cmd = dframe->cmd;
|
2021-02-14 02:35:06 +00:00
|
|
|
//FIXME which pass?
|
2021-12-02 12:58:29 +00:00
|
|
|
DARRAY_APPEND (&rFrame->subpassCmdSets[QFV_passTranslucent], cmd);
|
2021-01-12 02:27:41 +00:00
|
|
|
|
2022-05-28 09:14:26 +00:00
|
|
|
VkMappedMemoryRange ranges[] = {
|
|
|
|
{ VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, 0,
|
|
|
|
dctx->vert_memory, dframe->vert_offset,
|
2022-09-09 08:06:33 +00:00
|
|
|
dframe->quad_verts.count * VERTS_PER_QUAD * sizeof (drawvert_t) },
|
2022-09-02 05:23:19 +00:00
|
|
|
{ VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, 0,
|
|
|
|
dctx->vert_memory, dframe->iavert_offset,
|
2022-09-09 08:06:33 +00:00
|
|
|
dframe->iaquad_verts.count * VERTS_PER_QUAD * sizeof (drawvert_t) },
|
2022-05-28 09:14:26 +00:00
|
|
|
{ VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, 0,
|
|
|
|
dctx->vert_memory, dframe->line_offset,
|
2022-09-09 08:06:33 +00:00
|
|
|
dframe->line_verts.count * VERTS_PER_LINE * sizeof (drawvert_t) },
|
2021-01-12 02:27:41 +00:00
|
|
|
};
|
2022-05-28 09:14:26 +00:00
|
|
|
dfunc->vkFlushMappedMemoryRanges (device->dev, 2, ranges);
|
2021-01-12 02:27:41 +00:00
|
|
|
|
|
|
|
dfunc->vkResetCommandBuffer (cmd, 0);
|
|
|
|
VkCommandBufferInheritanceInfo inherit = {
|
|
|
|
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0,
|
2021-12-02 12:58:29 +00:00
|
|
|
rFrame->renderpass->renderpass, QFV_passTranslucent,
|
2021-01-16 05:42:25 +00:00
|
|
|
cframe->framebuffer,
|
2021-01-12 02:27:41 +00:00
|
|
|
0, 0, 0
|
|
|
|
};
|
|
|
|
VkCommandBufferBeginInfo beginInfo = {
|
|
|
|
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 0,
|
|
|
|
VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
|
|
|
|
| VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, &inherit,
|
|
|
|
};
|
|
|
|
dfunc->vkBeginCommandBuffer (cmd, &beginInfo);
|
|
|
|
|
2021-04-18 11:40:43 +00:00
|
|
|
QFV_duCmdBeginLabel (device, cmd, "twod", { 0.6, 0.2, 0, 1});
|
|
|
|
|
2021-01-16 05:42:25 +00:00
|
|
|
VkDeviceSize offsets[] = {dframe->vert_offset};
|
|
|
|
dfunc->vkCmdBindVertexBuffers (cmd, 0, 1, &dctx->vert_buffer, offsets);
|
|
|
|
dfunc->vkCmdBindIndexBuffer (cmd, dctx->ind_buffer, 0,
|
2021-01-12 02:27:41 +00:00
|
|
|
VK_INDEX_TYPE_UINT32);
|
2022-09-09 08:06:33 +00:00
|
|
|
if (dframe->quad_verts.count) {
|
2022-09-02 05:23:19 +00:00
|
|
|
VkDescriptorSet set[2] = {
|
|
|
|
Vulkan_Matrix_Descriptors (ctx, ctx->curFrame),
|
|
|
|
dframe->descriptors,
|
|
|
|
};
|
|
|
|
VkPipelineLayout layout = dctx->layout;
|
|
|
|
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
layout, 0, 2, set, 0, 0);
|
|
|
|
|
2022-05-28 09:14:26 +00:00
|
|
|
dfunc->vkCmdBindPipeline (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
dctx->quad_pipeline);
|
|
|
|
dfunc->vkCmdSetViewport (cmd, 0, 1, &rFrame->renderpass->viewport);
|
|
|
|
dfunc->vkCmdSetScissor (cmd, 0, 1, &rFrame->renderpass->scissor);
|
2022-09-09 08:06:33 +00:00
|
|
|
dfunc->vkCmdDrawIndexed (cmd, dframe->quad_verts.count * INDS_PER_QUAD,
|
2022-09-02 05:23:19 +00:00
|
|
|
1, 0, QUADS_OFFSET, 0);
|
|
|
|
}
|
2022-09-09 08:06:33 +00:00
|
|
|
if (dframe->iaquad_verts.count) {
|
2022-09-02 05:23:19 +00:00
|
|
|
VkDescriptorImageInfo iaimageInfo = {
|
|
|
|
dctx->sampler,
|
|
|
|
Vulkan_TexImageView (dctx->font_tex),
|
|
|
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
|
|
};
|
|
|
|
VkWriteDescriptorSet write[] = {
|
|
|
|
{ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 0,
|
|
|
|
dframe->iadescriptors, 0, 0, 1,
|
|
|
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
|
|
|
&iaimageInfo, 0, 0 },
|
|
|
|
};
|
|
|
|
dfunc->vkUpdateDescriptorSets (device->dev, 1, write, 0, 0);
|
|
|
|
|
|
|
|
VkDescriptorSet set[2] = {
|
|
|
|
Vulkan_Matrix_Descriptors (ctx, ctx->curFrame),
|
|
|
|
dframe->iadescriptors,
|
|
|
|
};
|
|
|
|
VkPipelineLayout layout = dctx->layout;
|
|
|
|
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
layout, 0, 2, set, 0, 0);
|
|
|
|
|
|
|
|
dfunc->vkCmdBindPipeline (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
dctx->iaquad_pipeline);
|
|
|
|
dfunc->vkCmdSetViewport (cmd, 0, 1, &rFrame->renderpass->viewport);
|
|
|
|
dfunc->vkCmdSetScissor (cmd, 0, 1, &rFrame->renderpass->scissor);
|
2022-09-09 08:06:33 +00:00
|
|
|
dfunc->vkCmdDrawIndexed (cmd, dframe->iaquad_verts.count*INDS_PER_QUAD,
|
2022-09-02 05:23:19 +00:00
|
|
|
1, 0, IAQUADS_OFFSET, 0);
|
2022-05-28 09:14:26 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 08:06:33 +00:00
|
|
|
if (dframe->line_verts.count) {
|
2022-09-02 05:23:19 +00:00
|
|
|
VkDescriptorSet set[2] = {
|
|
|
|
Vulkan_Matrix_Descriptors (ctx, ctx->curFrame),
|
|
|
|
dframe->descriptors,
|
|
|
|
};
|
|
|
|
VkPipelineLayout layout = dctx->layout;
|
|
|
|
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
layout, 0, 2, set, 0, 0);
|
|
|
|
|
2022-05-28 09:14:26 +00:00
|
|
|
dfunc->vkCmdBindPipeline (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
dctx->line_pipeline);
|
2022-09-09 08:06:33 +00:00
|
|
|
dfunc->vkCmdDraw (cmd, dframe->line_verts.count * VERTS_PER_LINE,
|
2022-09-02 05:23:19 +00:00
|
|
|
1, LINES_OFFSET, 0);
|
2022-05-28 09:14:26 +00:00
|
|
|
}
|
2021-01-12 02:27:41 +00:00
|
|
|
|
2021-04-18 11:40:43 +00:00
|
|
|
QFV_duCmdEndLabel (device, cmd);
|
2021-01-12 02:27:41 +00:00
|
|
|
dfunc->vkEndCommandBuffer (cmd);
|
|
|
|
|
2022-09-09 08:06:33 +00:00
|
|
|
dframe->quad_verts.count = 0;
|
|
|
|
dframe->iaquad_verts.count = 0;
|
|
|
|
dframe->line_verts.count = 0;
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_BlendScreen (quat_t color, vulkan_ctx_t *ctx)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-13 15:44:34 +00:00
|
|
|
if (color[3]) {
|
2022-08-30 05:29:22 +00:00
|
|
|
quat_t c;
|
|
|
|
// pre-multiply alpha.
|
|
|
|
// FIXME this is kind of silly because q1source pre-multiplies alpha
|
|
|
|
// for blends, but this was un-done early in QF's history in order
|
|
|
|
// to avoid a pair of state changes
|
|
|
|
VectorScale (color, color[3], c);
|
|
|
|
c[3] = color[3];
|
|
|
|
draw_blendscreen (c, ctx);
|
2021-01-13 15:44:34 +00:00
|
|
|
}
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
2022-08-31 10:23:30 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Vulkan_Draw_AddFont (rfont_t *font, vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
|
|
|
|
if (dctx->font_tex) {
|
|
|
|
Vulkan_UnloadTex (ctx, dctx->font_tex);
|
|
|
|
dctx->font_tex = 0;
|
|
|
|
}
|
|
|
|
dctx->font = font;
|
|
|
|
if (dctx->font) {
|
|
|
|
tex_t tex = {
|
|
|
|
.width = font->scrap.width,
|
|
|
|
.height = font->scrap.height,
|
|
|
|
.format = tex_l,
|
|
|
|
.loaded = 1,
|
|
|
|
.data = font->scrap_bitmap,
|
|
|
|
};
|
|
|
|
dctx->font_tex = Vulkan_LoadTex (ctx, &tex, 0, "draw.font");
|
|
|
|
}
|
|
|
|
}
|
2022-09-02 02:38:09 +00:00
|
|
|
|
2022-09-04 11:56:38 +00:00
|
|
|
typedef struct {
|
|
|
|
drawframe_t *dframe;
|
|
|
|
subpic_t *subpic;
|
|
|
|
quat_t color;
|
|
|
|
} rgctx_t;
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_render_glyph (rglyph_t *glyph, int x, int y, void *_rgctx)
|
|
|
|
{
|
|
|
|
rgctx_t *rgctx = _rgctx;
|
|
|
|
|
|
|
|
*((vrect_t **) &rgctx->subpic->rect) = glyph->rect;
|
|
|
|
int gw = glyph->rect->width;
|
|
|
|
int gh = glyph->rect->height;
|
2022-09-09 11:05:31 +00:00
|
|
|
draw_pic (x, y, gw, gh, rgctx->subpic, 0, 0, gw, gh, rgctx->color,
|
2022-09-09 08:06:33 +00:00
|
|
|
&rgctx->dframe->iaquad_verts);
|
2022-09-04 11:56:38 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 02:38:09 +00:00
|
|
|
void
|
|
|
|
Vulkan_Draw_FontString (int x, int y, const char *str, vulkan_ctx_t *ctx)
|
|
|
|
{
|
2022-09-02 05:23:19 +00:00
|
|
|
drawctx_t *dctx = ctx->draw_context;
|
|
|
|
if (!dctx->font) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
drawframe_t *dframe = &dctx->frames.a[ctx->curFrame];
|
2022-09-04 11:56:38 +00:00
|
|
|
|
2022-09-09 08:06:33 +00:00
|
|
|
//FIXME ewwwwwww
|
2022-09-02 05:23:19 +00:00
|
|
|
subpic_t glyph_subpic = {
|
|
|
|
.width = dctx->font->scrap.width,
|
|
|
|
.height = dctx->font->scrap.height,
|
|
|
|
.size = 1.0 / dctx->font->scrap.width,
|
|
|
|
};
|
2022-09-04 11:56:38 +00:00
|
|
|
rgctx_t rgctx = {
|
|
|
|
.dframe = dframe,
|
2022-09-02 05:23:19 +00:00
|
|
|
.subpic = &glyph_subpic,
|
2022-09-04 11:56:38 +00:00
|
|
|
.color = { 0.5, 1, 0.6, 1 },
|
2022-09-02 05:23:19 +00:00
|
|
|
};
|
2022-09-04 11:56:38 +00:00
|
|
|
rtext_t text = {
|
|
|
|
.text = str,
|
|
|
|
.language = "en",
|
|
|
|
.script = HB_SCRIPT_LATIN,
|
|
|
|
.direction = HB_DIRECTION_LTR,
|
|
|
|
};
|
|
|
|
|
|
|
|
rshaper_t *shaper = RText_NewShaper (dctx->font);
|
|
|
|
RText_RenderText (shaper, &text, x, y, vulkan_render_glyph, &rgctx);
|
|
|
|
RText_DeleteShaper (shaper);
|
2022-09-02 02:38:09 +00:00
|
|
|
}
|