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
|
|
|
|
|
|
|
|
#define NH_DEFINE
|
|
|
|
#include "namehack.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/draw.h"
|
|
|
|
#include "QF/dstring.h"
|
|
|
|
#include "QF/hash.h"
|
|
|
|
#include "QF/quakefs.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#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"
|
|
|
|
#include "QF/Vulkan/qf_vid.h"
|
2021-01-10 06:52:27 +00:00
|
|
|
#include "QF/Vulkan/descriptor.h"
|
|
|
|
#include "QF/Vulkan/device.h"
|
|
|
|
#include "QF/Vulkan/image.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"
|
|
|
|
#include "vkparse.h"
|
|
|
|
|
|
|
|
//FIXME move into a context struct
|
|
|
|
VkImage conchars_image;
|
|
|
|
VkDeviceMemory conchars_memory;
|
|
|
|
VkImageView conchars_view;
|
|
|
|
VkSampler conchars_sampler;
|
|
|
|
|
|
|
|
VkPipeline twod;
|
2019-07-06 05:42:53 +00:00
|
|
|
|
2020-02-11 03:19:16 +00:00
|
|
|
static qpic_t *
|
|
|
|
pic_data (const char *name, int w, int h, const byte *data)
|
|
|
|
{
|
|
|
|
qpic_t *pic;
|
|
|
|
|
|
|
|
pic = malloc (field_offset (qpic_t, data[w * h]));
|
|
|
|
pic->width = w;
|
|
|
|
pic->height = h;
|
|
|
|
memcpy (pic->data, data, pic->width * pic->height);
|
|
|
|
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
|
|
|
{
|
2020-02-11 03:19:16 +00:00
|
|
|
return pic_data (0, width, height, data);
|
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
|
|
|
{
|
2020-02-11 03:19:16 +00:00
|
|
|
return pic_data (0, 1, 1, (const byte *)"");
|
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
|
|
|
{
|
2020-02-11 03:19:16 +00:00
|
|
|
return pic_data (0, 1, 1, (const byte *)"");
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_TextBox (int x, int y, int width, int lines, byte alpha,
|
|
|
|
vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Vulkan_Draw_Shutdown (void *data)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
2021-01-10 06:52:27 +00:00
|
|
|
vulkan_ctx_t *ctx = data;
|
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
|
|
|
dfunc->vkDestroyPipeline (device->dev, twod, 0);
|
|
|
|
dfunc->vkDestroyImageView (device->dev, conchars_view, 0);
|
|
|
|
dfunc->vkFreeMemory (device->dev, conchars_memory, 0);
|
|
|
|
dfunc->vkDestroyImage (device->dev, conchars_image, 0);
|
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
|
|
|
Sys_RegisterShutdown (Vulkan_Draw_Shutdown, ctx);
|
|
|
|
|
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qpic_t *charspic = Draw_Font8x8Pic ();
|
|
|
|
VkExtent3D extent = { charspic->width, charspic->height, 1 };
|
|
|
|
conchars_image = QFV_CreateImage (device, 0, VK_IMAGE_TYPE_2D,
|
|
|
|
VK_FORMAT_A8B8G8R8_UNORM_PACK32,
|
|
|
|
extent, 1, 1,
|
|
|
|
VK_SAMPLE_COUNT_1_BIT,
|
|
|
|
VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
|
|
|
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
|
|
|
| VK_IMAGE_USAGE_SAMPLED_BIT,
|
|
|
|
1);
|
|
|
|
conchars_memory = QFV_AllocImageMemory (device, conchars_image,
|
|
|
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
|
|
|
0, 0);
|
|
|
|
QFV_BindImageMemory (device, conchars_image, conchars_memory, 0);
|
|
|
|
conchars_view = QFV_CreateImageView (device, conchars_image,
|
|
|
|
VK_IMAGE_VIEW_TYPE_2D,
|
|
|
|
VK_FORMAT_A8B8G8R8_UNORM_PACK32,
|
|
|
|
VK_IMAGE_ASPECT_COLOR_BIT);
|
|
|
|
conchars_sampler = Hash_Find (ctx->samplers, "quakepic");
|
|
|
|
|
|
|
|
twod = Vulkan_CreatePipeline (ctx, "twod");
|
|
|
|
|
|
|
|
handleref_t *h;
|
|
|
|
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (ctx->framebuffers.size, alloca);
|
|
|
|
for (size_t i = 0; i < layouts->size; i++) {
|
|
|
|
h = Hash_Find (ctx->setLayouts, "twod");
|
|
|
|
layouts->a[i] = (VkDescriptorSetLayout) h->handle;
|
|
|
|
}
|
|
|
|
h = Hash_Find (ctx->descriptorPools, "twod");
|
|
|
|
__auto_type pool = (VkDescriptorPool) h->handle;
|
|
|
|
__auto_type sets = QFV_AllocateDescriptorSet (device, pool, layouts);
|
|
|
|
for (size_t i = 0; i < ctx->framebuffers.size; i++) {
|
|
|
|
ctx->framebuffers.a[i].twodDescriptors = sets->a[i];
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_Crosshair (vulkan_ctx_t *ctx)
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_FadeScreen (vulkan_ctx_t *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-01-10 06:52:27 +00:00
|
|
|
Vulkan_FlushText (vulkan_ctx_t *ctx)
|
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
|
|
|
{
|
|
|
|
}
|