From 387f17dc0cff723470768c8d2ec0cec22f01132e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 15 Nov 2022 15:21:20 +0900 Subject: [PATCH] [scene] Add a color map component It's currently used only by the vulkan renderer, as it's the only renderer that can make good use of it for alias models, but now vulkan show shirt/pants colors (finally). --- include/QF/scene/entity.h | 5 +++++ include/QF/scene/scene.h | 1 + libs/scene/scene.c | 12 ++++++++++++ libs/video/renderer/vulkan/vulkan_alias.c | 5 +++++ nq/source/cl_ents.c | 5 +++++ qw/source/cl_ents.c | 12 ++++++++++++ 6 files changed, 40 insertions(+) diff --git a/include/QF/scene/entity.h b/include/QF/scene/entity.h index 488d9ed02..f0453e3d8 100644 --- a/include/QF/scene/entity.h +++ b/include/QF/scene/entity.h @@ -99,6 +99,11 @@ typedef struct entqueue_s { int num_queues; } entqueue_t; +typedef struct colormap_s { + byte top; + byte bottom; +} colormap_t; + #define ENTINLINE GNU89INLINE inline entqueue_t *EntQueue_New (int num_queues); diff --git a/include/QF/scene/scene.h b/include/QF/scene/scene.h index ae9a03871..9792e4f2e 100644 --- a/include/QF/scene/scene.h +++ b/include/QF/scene/scene.h @@ -47,6 +47,7 @@ enum scene_components { scene_renderer, scene_active, scene_old_origin, //XXX FIXME XXX should not be here + scene_colormap, //FIXME these should probably be private to the sw renderer (and in a //group, which needs to be implemented), but need to sort out a good diff --git a/libs/scene/scene.c b/libs/scene/scene.c index 90266d160..86932ca15 100644 --- a/libs/scene/scene.c +++ b/libs/scene/scene.c @@ -59,6 +59,13 @@ create_old_origin (void *_old_origin) *old_origin = (vec4f_t) {0, 0, 0, 1}; } +static void +create_colormap (void *_colormap) +{ + colormap_t *colormap = _colormap; + *colormap = (colormap_t) {1, 6}; +} + static void destroy_visibility (void *_visibility) { @@ -121,6 +128,11 @@ static const component_t scene_components[] = { .create = create_old_origin, .name = "old_origin", }, + [scene_colormap] = { + .size = sizeof (colormap_t), + .create = create_colormap, + .name = "colormap", + }, [scene_sw_matrix] = { .size = sizeof (mat4f_t), diff --git a/libs/video/renderer/vulkan/vulkan_alias.c b/libs/video/renderer/vulkan/vulkan_alias.c index 8d3630be7..11dae501a 100644 --- a/libs/video/renderer/vulkan/vulkan_alias.c +++ b/libs/video/renderer/vulkan/vulkan_alias.c @@ -163,6 +163,11 @@ Vulkan_DrawAlias (entity_t ent, qfv_renderframe_t *rFrame) } QuatCopy (renderer->colormod, constants.base_color); QuatCopy (skin->colors, constants.colors); + if (Ent_HasComponent (ent.id, scene_colormap, ent.reg)) { + colormap_t *colormap=Ent_GetComponent (ent.id, scene_colormap, ent.reg); + constants.colors[0] = colormap->top * 16 + 8; + constants.colors[1] = colormap->bottom * 16 + 8; + } QuatZero (constants.fog); emit_commands (aframe->cmdSet.a[QFV_aliasDepth], diff --git a/nq/source/cl_ents.c b/nq/source/cl_ents.c index 2545ec02e..b09a2977e 100644 --- a/nq/source/cl_ents.c +++ b/nq/source/cl_ents.c @@ -246,6 +246,11 @@ CL_RelinkEntities (void) old->skinnum = new->skinnum; renderer->skinnum = new->skinnum; if (i <= cl.maxclients) { + colormap_t colormap = { + .top = cl.players[i - 1].topcolor, + .bottom = cl.players[i - 1].bottomcolor, + }; + Ent_SetComponent (ent.id, scene_colormap, ent.reg, &colormap); renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin, i); mod_funcs->Skin_SetTranslation (i, cl.players[i - 1].topcolor, diff --git a/qw/source/cl_ents.c b/qw/source/cl_ents.c index 467fcce23..b1857f090 100644 --- a/qw/source/cl_ents.c +++ b/qw/source/cl_ents.c @@ -218,6 +218,11 @@ CL_LinkPacketEntities (void) && cl.players[new->colormap - 1].name->value[0] && new->modelindex == cl_playerindex) { player_info_t *player = &cl.players[new->colormap - 1]; + colormap_t colormap = { + .top = player->topcolor, + .bottom = player->bottomcolor, + }; + Ent_SetComponent (ent.id, scene_colormap, ent.reg, &colormap); renderer->skin = mod_funcs->Skin_SetSkin (renderer->skin, new->colormap, player->skinname->value); @@ -226,6 +231,7 @@ CL_LinkPacketEntities (void) } else { renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin, 0); + Ent_RemoveComponent (ent.id, scene_colormap, ent.reg); } } @@ -462,6 +468,12 @@ CL_LinkPlayers (void) && is_dead_body (&state->pls.es)) continue; + colormap_t colormap = { + .top = player->topcolor, + .bottom = player->bottomcolor, + }; + Ent_SetComponent (ent.id, scene_colormap, ent.reg, &colormap); + // predict only half the move to minimize overruns msec = 500 * (playertime - state->state_time); if (msec <= 0 || (!cl_predict_players) || cls.demoplayback2) {