diff --git a/ref_vk/camera.c b/ref_vk/camera.c index 106cca19..c9839a22 100644 --- a/ref_vk/camera.c +++ b/ref_vk/camera.c @@ -1,9 +1,12 @@ #include "camera.h" #include "vk_common.h" #include "vk_math.h" +#include "vk_textures.h" #include "ref_params.h" #include "pm_movevars.h" +#include "pm_defs.h" +#include "pmtrace.h" vk_global_camera_t g_camera; @@ -157,3 +160,68 @@ int TriWorldToScreen( const float *world, float *screen ) return retval; } + +static const char *renderModeName( int rendermode ) { + switch (rendermode) { + case kRenderNormal: return "kRenderNormal"; + case kRenderTransColor: return "kRenderTransColor"; + case kRenderTransTexture: return "kRenderTransTexture"; + case kRenderGlow: return "kRenderGlow"; + case kRenderTransAlpha: return "kRenderTransAlpha"; + case kRenderTransAdd: return "kRenderTransAdd"; + default: return "UNKNOWN"; + } +} + +void XVK_CameraDebugPrintCenterEntity( void ) { + vec3_t vec_end; + pmtrace_t trace; + const msurface_t *surf; + char buf[1024], *p = buf, *end = buf + sizeof(buf); + const physent_t *physent = NULL; + const cl_entity_t *ent = NULL; + + VectorMA(g_camera.vieworg, 1e6, g_camera.vforward, vec_end); + + trace = gEngine.CL_TraceLine( g_camera.vieworg, vec_end, PM_NORMAL ); + surf = gEngine.EV_TraceSurface( Q_max(trace.ent, 0), g_camera.vieworg, vec_end ); + + if (trace.ent > 0) { + physent = gEngine.EV_GetPhysent( trace.ent ); + } + + ent = gEngine.GetEntityByIndex( (physent && physent->info > 0) ? physent->info : 0 ); + + p += Q_snprintf(p, end - p, + "o\n" + "cam.origin: %.03f %.03f %.03f\n", + // TODO cam dir + // TODO hit pos + g_camera.vieworg[0], g_camera.vieworg[1], g_camera.vieworg[2] + ); + + p += Q_snprintf(p, end - p, + "entity index: %d, name: %s\n", + (physent && physent->info > 0) ? physent->info : -1, + (ent && ent->model) ? ent->model->name : "N/A"); + + if (ent) { + p += Q_snprintf(p, end - p, + "ent type: %d, rendermode: %d(%s)\n", + ent->curstate.entityType, + ent->curstate.rendermode, + renderModeName(ent->curstate.rendermode)); + } + + if (surf && ent && ent->model && ent->model->surfaces) { + const int surface_index = surf - ent->model->surfaces; + const int tex_id = surf->texinfo->texture->gl_texturenum; + const vk_texture_t* const texture = findTexture( tex_id ); + + p += Q_snprintf(p, end - p, + "surface index: %d; texture: %s\n", + surface_index, texture ? texture->name : "NONE" + ); + } + gEngine.CL_CenterPrint(buf, 0.5f); +} diff --git a/ref_vk/camera.h b/ref_vk/camera.h index 49e06b2e..c0c9fb3f 100644 --- a/ref_vk/camera.h +++ b/ref_vk/camera.h @@ -31,3 +31,4 @@ void R_SetupCamera( const struct ref_viewpass_s *rvp ); int R_WorldToScreen( const vec3_t point, vec3_t screen ); int TriWorldToScreen( const float *world, float *screen ); +void XVK_CameraDebugPrintCenterEntity( void ); diff --git a/ref_vk/vk_cvar.c b/ref_vk/vk_cvar.c index a5c41c5f..735bb9a1 100644 --- a/ref_vk/vk_cvar.c +++ b/ref_vk/vk_cvar.c @@ -18,4 +18,5 @@ void VK_LoadCvars( void ) vk_rtx_light_begin = gEngine.Cvar_Get( "vk_rtx_light_begin", "0", 0, "DEBUG: disable lights with index lower than this"); vk_rtx_light_end = gEngine.Cvar_Get( "vk_rtx_light_end", "0", 0, "DEBUG: disable lights with index higher than this "); r_lightmap = gEngine.Cvar_Get( "r_lightmap", "0", FCVAR_CHEAT, "lightmap debugging tool" ); + ui_infotool = gEngine.Cvar_Get( "ui_infotool", "0", FCVAR_CHEAT, "DEBUG: print entity info under crosshair" ); } diff --git a/ref_vk/vk_cvar.h b/ref_vk/vk_cvar.h index 4e8346e7..19beb924 100644 --- a/ref_vk/vk_cvar.h +++ b/ref_vk/vk_cvar.h @@ -14,6 +14,7 @@ void VK_LoadCvars( void ); X(vk_rtx_light_begin) \ X(vk_rtx_light_end) \ X(r_lightmap) \ + X(ui_infotool) \ #define EXTERN_CVAR(cvar) extern cvar_t *cvar; DECLARE_CVAR(EXTERN_CVAR) diff --git a/ref_vk/vk_scene.c b/ref_vk/vk_scene.c index 94b3b904..5e759393 100644 --- a/ref_vk/vk_scene.c +++ b/ref_vk/vk_scene.c @@ -12,6 +12,7 @@ #include "vk_light.h" #include "vk_rtx.h" #include "vk_textures.h" +#include "vk_cvar.h" #include "camera.h" #include "com_strings.h" @@ -543,6 +544,7 @@ static void drawEntity( cl_entity_t *ent, int render_mode ) } static float g_frametime = 0; + void VK_SceneRender( const ref_viewpass_t *rvp ) { int current_pipeline_index = kRenderNormal; @@ -609,6 +611,9 @@ void VK_SceneRender( const ref_viewpass_t *rvp ) gEngine.CL_DrawEFX( g_frametime, true ); VK_RenderDebugLabelEnd(); + + if (ui_infotool->value > 0) + XVK_CameraDebugPrintCenterEntity(); } /*