[vulkan] Initialize resource image from tex_t

This moves the qfv_resobj_t image initialization code from the IQM
loader into the resource management code. This will allow me to reuse
the code for setting up glyph data. As a bonus, it cleans up the IQM
code nicely.
This commit is contained in:
Bill Currie 2022-10-02 15:24:38 +09:00
parent ac8d71733e
commit 0352af4542
3 changed files with 36 additions and 38 deletions

View file

@ -64,5 +64,8 @@ struct qfv_device_s;
int QFV_CreateResource (struct qfv_device_s *device, qfv_resource_t *resource);
void QFV_DestroyResource (struct qfv_device_s *device,
qfv_resource_t *resource);
struct tex_s;
void QFV_ResourceInitTexImage (qfv_resobj_t *image, const char *name,
int mips, const struct tex_s *tex);
#endif//__QF_Vulkan_resource_h

View file

@ -100,47 +100,17 @@ vulkan_iqm_init_image (iqm_t *iqm, int meshnum, qfv_resobj_t *image)
dstring_copystr (str, material);
QFS_StripExtension (str->str, str->str);
tex_t dummy_tex;
tex_t *tex;
if ((tex = LoadImage (va (0, "textures/%s", str->str), 0))) {
*image = (qfv_resobj_t) {
.name = material,
.type = qfv_res_image,
.image = {
.type = VK_IMAGE_TYPE_2D,
.format = QFV_ImageFormat (tex->format, 0),
.extent = {
.width = tex->width,
.height = tex->height,
.depth = 1,
},
.num_mipmaps = QFV_MipLevels (tex->width, tex->height),
.num_layers = 1,
.samples = VK_SAMPLE_COUNT_1_BIT,
.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT
| VK_IMAGE_USAGE_SAMPLED_BIT,
},
};
} else {
*image = (qfv_resobj_t) {
.name = material,
.type = qfv_res_image,
.image = {
.type = VK_IMAGE_TYPE_2D,
.format = QFV_ImageFormat (tex_rgba, 0),
.extent = {
.width = 2,
.height = 2,
.depth = 1,
},
.num_mipmaps = QFV_MipLevels (2, 2),
.num_layers = 1,
.samples = VK_SAMPLE_COUNT_1_BIT,
.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT
| VK_IMAGE_USAGE_SAMPLED_BIT,
},
if (!(tex = LoadImage (va (0, "textures/%s", str->str), 0))) {
dummy_tex = (tex_t) {
.width = 2,
.height = 2,
.format = tex_rgba,
};
tex = &dummy_tex;
}
QFV_ResourceInitTexImage (image, material, 1, tex);
dstring_delete (str);
}

View file

@ -269,3 +269,28 @@ QFV_DestroyResource (qfv_device_t *device, qfv_resource_t *resource)
}
dfunc->vkFreeMemory (device->dev, resource->memory, 0);
}
void
QFV_ResourceInitTexImage (qfv_resobj_t *image, const char *name,
int mips, const tex_t *tex)
{
*image = (qfv_resobj_t) {
.name = name,
.type = qfv_res_image,
.image = {
.type = VK_IMAGE_TYPE_2D,
.format = QFV_ImageFormat (tex->format, 0),
.extent = {
.width = tex->width,
.height = tex->height,
.depth = 1,
},
.num_mipmaps = mips ? QFV_MipLevels (tex->width, tex->height) : 1,
.num_layers = 1,
.samples = VK_SAMPLE_COUNT_1_BIT,
.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT
| VK_IMAGE_USAGE_SAMPLED_BIT,
},
};
}