Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug line drawing #440

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion extern/Vulkan-Headers
Submodule Vulkan-Headers updated 86 files
+0 −34 .cmake-format.py
+8 −0 .gitattributes
+52 −0 .github/ISSUE_TEMPLATE/bug_report.md
+12 −0 .github/dependabot.yml
+18 −0 .github/pull_request_template.md
+83 −0 .github/workflows/ci.yml
+8 −0 .gitignore
+15 −0 .reuse/dep5
+38 −21 BUILD.gn
+25 −253 BUILD.md
+89 −42 CMakeLists.txt
+10 −0 CODE_OF_CONDUCT.adoc
+0 −1 CODE_OF_CONDUCT.md
+40 −0 CONTRIBUTING.md
+18 −0 LICENSE.md
+0 −0 LICENSES/Apache-2.0.txt
+9 −0 LICENSES/MIT.txt
+108 −0 Makefile.release
+35 −40 README.md
+11 −0 SECURITY.md
+0 −126 cmake/Copyright_cmake.txt
+0 −21 cmake/cmake_uninstall.cmake.in
+394 −0 include/vk_video/vulkan_video_codec_av1std.h
+109 −0 include/vk_video/vulkan_video_codec_av1std_decode.h
+143 −0 include/vk_video/vulkan_video_codec_av1std_encode.h
+312 −0 include/vk_video/vulkan_video_codec_h264std.h
+77 −0 include/vk_video/vulkan_video_codec_h264std_decode.h
+147 −0 include/vk_video/vulkan_video_codec_h264std_encode.h
+446 −0 include/vk_video/vulkan_video_codec_h265std.h
+67 −0 include/vk_video/vulkan_video_codec_h265std_decode.h
+157 −0 include/vk_video/vulkan_video_codec_h265std_encode.h
+36 −0 include/vk_video/vulkan_video_codecs_common.h
+33 −25 include/vulkan/vk_icd.h
+6 −27 include/vulkan/vk_layer.h
+5 −3 include/vulkan/vk_platform.h
+0 −69 include/vulkan/vk_sdk_platform.h
+8,248 −0 include/vulkan/vulkan.cppm
+14 −2 include/vulkan/vulkan.h
+17,283 −89,993 include/vulkan/vulkan.hpp
+43 −2 include/vulkan/vulkan_android.h
+171 −1 include/vulkan/vulkan_beta.h
+13,945 −4,546 include/vulkan/vulkan_core.h
+2 −1 include/vulkan/vulkan_directfb.h
+7,832 −0 include/vulkan/vulkan_enums.hpp
+3,386 −0 include/vulkan/vulkan_extension_inspection.hpp
+7,669 −0 include/vulkan/vulkan_format_traits.hpp
+216 −1 include/vulkan/vulkan_fuchsia.h
+28,803 −0 include/vulkan/vulkan_funcs.hpp
+3 −1 include/vulkan/vulkan_ggp.h
+17,760 −0 include/vulkan/vulkan_handles.hpp
+18,129 −0 include/vulkan/vulkan_hash.hpp
+326 −0 include/vulkan/vulkan_hpp_macros.hpp
+2 −1 include/vulkan/vulkan_ios.h
+2 −1 include/vulkan/vulkan_macos.h
+143 −2 include/vulkan/vulkan_metal.h
+24,717 −0 include/vulkan/vulkan_raii.hpp
+108 −0 include/vulkan/vulkan_screen.h
+1,159 −0 include/vulkan/vulkan_shared.hpp
+8,193 −0 include/vulkan/vulkan_static_assertions.hpp
+136,541 −0 include/vulkan/vulkan_structs.hpp
+9,538 −0 include/vulkan/vulkan_to_string.hpp
+2 −1 include/vulkan/vulkan_vi.h
+4,057 −0 include/vulkan/vulkan_video.hpp
+2 −1 include/vulkan/vulkan_wayland.h
+28 −1 include/vulkan/vulkan_win32.h
+2 −1 include/vulkan/vulkan_xcb.h
+2 −1 include/vulkan/vulkan_xlib.h
+2 −1 include/vulkan/vulkan_xlib_xrandr.h
+21 −0 registry/apiconventions.py
+148 −35 registry/cgenerator.py
+471 −84 registry/generator.py
+0 −641 registry/genvk.py
+404 −0 registry/parse_dependency.py
+390 −0 registry/profiles/VP_KHR_roadmap.json
+610 −173 registry/reg.py
+226 −21 registry/spec_tools/conventions.py
+1 −1 registry/spec_tools/util.py
+42 −0 registry/stripAPI.py
+90,648 −21,299 registry/validusage.json
+1,830 −0 registry/video.xml
+20,525 −6,486 registry/vk.xml
+80 −30 registry/vkconventions.py
+33 −0 tests/CMakeLists.txt
+73 −0 tests/integration/CMakeLists.txt
+14 −0 tests/vk_icd.c
+14 −0 tests/vk_layer.c
42 changes: 42 additions & 0 deletions inc/refresh/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.

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 the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef REFRESH_DEBUG_H_
#define REFRESH_DEBUG_H_

#define MAX_DEBUG_LINES 8192
#define MAX_DEBUG_VERTICES (MAX_DEBUG_LINES * 2)

typedef struct {
list_t entry;
vec3_t start, end;
color_t color;
uint32_t time;
bool depth_test;
} r_debug_line_t;

extern list_t r_debug_lines_free;
extern list_t r_debug_lines_active;

// Debug lines shared functionality
extern bool R_DebugTimeExpired(const uint32_t time);
extern void R_ExpireDebugLines(void);
extern void R_AddDebugText_Lines(const vec3_t vieworg, const vec3_t origin, const vec3_t angles, const char *text, float size, uint32_t color, uint32_t time, bool depth_test);
extern void R_InitDebugText(void);

#endif // REFRESH_DEBUG_H_
5 changes: 5 additions & 0 deletions inc/refresh/refresh.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ extern void (*R_DrawFill32)(int x, int y, int w, int h, uint32_t color);
extern void (*R_UpdateRawPic)(int pic_w, int pic_h, const uint32_t *pic);
extern void (*R_DiscardRawPic)(void);

// debug line entry points
extern bool (*R_SupportsDebugLines)(void);
extern void (*R_AddDebugText_)(const vec3_t origin, const vec3_t angles, const char *text,
float size, uint32_t color, uint32_t time, bool depth_test);

// video mode and refresh state management entry points
extern void (*R_BeginFrame)(void);
extern void (*R_EndFrame)(void);
Expand Down
38 changes: 38 additions & 0 deletions inc/shared/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.

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 the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#if USE_REF
void R_ClearDebugLines(void);
void R_AddDebugLine(const vec3_t start, const vec3_t end, uint32_t color, uint32_t time, bool depth_test);
void R_AddDebugText(const vec3_t origin, const vec3_t angles, const char *text,
float size, uint32_t color, uint32_t time, bool depth_test);
void R_AddDebugPoint(const vec3_t point, float size, uint32_t color, uint32_t time, bool depth_test);
void R_AddDebugAxis(const vec3_t origin, const vec3_t angles, float size, uint32_t time, bool depth_test);
void R_AddDebugBounds(const vec3_t mins, const vec3_t maxs, uint32_t color, uint32_t time, bool depth_test);
void R_AddDebugSphere(const vec3_t origin, float radius, uint32_t color, uint32_t time, bool depth_test);
void R_AddDebugCircle(const vec3_t origin, float radius, uint32_t color, uint32_t time, bool depth_test);
void R_AddDebugCylinder(const vec3_t origin, float half_height, float radius, uint32_t color, uint32_t time, bool depth_test);
void R_AddDebugArrow(const vec3_t start, const vec3_t end, float size, uint32_t line_color,
uint32_t arrow_color, uint32_t time, bool depth_test);
void R_AddDebugCurveArrow(const vec3_t start, const vec3_t ctrl, const vec3_t end, float size,
uint32_t line_color, uint32_t arrow_color, uint32_t time, bool depth_test);
#else
#define R_ClearDebugLines() (void)0
#endif
15 changes: 13 additions & 2 deletions inc/shared/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,14 @@ typedef struct vrect_s {
int x, y, width, height;
} vrect_t;

#define DEG2RAD(a) ((a) * (M_PI / 180))
#define RAD2DEG(a) ((a) * (180 / M_PI))
#ifndef M_PIf
#define M_PIf 3.14159265358979323846f
#define M_SQRT2f 1.41421356237309504880f
#define M_SQRT1_2f 0.70710678118654752440f
#endif

#define DEG2RAD(a) ((a) * (M_PIf / 180))
#define RAD2DEG(a) ((a) * (180 / M_PIf))

#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))

Expand Down Expand Up @@ -349,6 +355,11 @@ uint32_t Q_rand_uniform(uint32_t n);
#define clamp(a,b,c) ((a)<(b)?(a)=(b):(a)>(c)?(a)=(c):(a))
#define cclamp(a,b,c) ((b)>(c)?clamp(a,c,b):clamp(a,b,c))

static inline int Q_clip(int a, int b, int c)
{
return clamp(a, b, c);
}

#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ SET(HEADERS_COMMON
)

SET(SRC_REFRESH
refresh/debug.c
refresh/debug_text.c
refresh/images.c
refresh/models.c
refresh/model_iqm.c
Expand Down Expand Up @@ -255,6 +257,7 @@ SET(SRC_VKPT
refresh/vkpt/asvgf.c
refresh/vkpt/bloom.c
refresh/vkpt/bsp_mesh.c
refresh/vkpt/debug.c
refresh/vkpt/draw.c
refresh/vkpt/fog.c
refresh/vkpt/cameras.c
Expand Down Expand Up @@ -328,6 +331,8 @@ set(SRC_SHADERS
refresh/vkpt/shader/fsr_easu_fp32.comp
refresh/vkpt/shader/fsr_rcas_fp16.comp
refresh/vkpt/shader/fsr_rcas_fp32.comp
refresh/vkpt/shader/debug_line.frag
refresh/vkpt/shader/debug_line.vert
)

set(SRC_RT_SHADERS
Expand Down
12 changes: 12 additions & 0 deletions src/client/refresh.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,


#include "client.h"
#include "refresh/debug.h"
#include "refresh/images.h"
#include "refresh/models.h"
#include "shared/debug.h"

// Console variables that we need to access from this module
cvar_t *vid_rtx;
Expand Down Expand Up @@ -412,6 +414,10 @@ void CL_InitRefresh(void)
SCR_Init();
UI_Init();

R_ClearDebugLines();
Cmd_AddCommand("cleardebuglines", R_ClearDebugLines);
R_InitDebugText();

SCR_RegisterMedia();
Con_RegisterMedia();

Expand All @@ -434,6 +440,8 @@ void CL_ShutdownRefresh(void)
SCR_Shutdown();
UI_Shutdown();

Cmd_RemoveCommand("cleardebuglines");

vid_geometry->changed = NULL;
vid_fullscreen->changed = NULL;
vid_modelist->changed = NULL;
Expand Down Expand Up @@ -486,6 +494,10 @@ void(*R_AddDecal)(decal_t *d) = NULL;
bool(*R_InterceptKey)(unsigned key, bool down) = NULL;
bool(*R_IsHDR)(void) = NULL;

bool (*R_SupportsDebugLines)(void) = NULL;
void (*R_AddDebugText_)(const vec3_t origin, const vec3_t angles, const char *text,
float size, uint32_t color, uint32_t time, bool depth_test) = NULL;

void(*IMG_Unload)(image_t *image) = NULL;
void(*IMG_Load)(image_t *image, byte *pic) = NULL;
void(*IMG_ReadPixels)(screenshot_t *s) = NULL;
Expand Down
29 changes: 29 additions & 0 deletions src/client/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// cl_view.c -- player rendering positioning

#include "client.h"
#include "shared/debug.h"

//=============
//
Expand All @@ -44,6 +45,7 @@ static cvar_t *cl_testparticles;
static cvar_t *cl_testentities;
static cvar_t *cl_testlights;
static cvar_t *cl_testblend;
static cvar_t *cl_testdebuglines;

static cvar_t *cl_stats;
#endif
Expand Down Expand Up @@ -375,6 +377,30 @@ static void V_TestLights(void)
}
}

static void V_TestDebugLines(void)
{
static const uint32_t colors[] = {U32_RED, U32_GREEN, U32_BLUE, U32_YELLOW, U32_MAGENTA, U32_CYAN};
const float point_size = 16.f;
const float text_size = 0.5f;

bool depth_test = cl_testdebuglines->integer == 1 || cl_testdebuglines->integer == 3;
bool print_id = cl_testdebuglines->integer >= 3;
for (int i = 0; i < r_numentities; i++) {
const entity_t *ent = r_entities + i;
if (ent->id == 1 /* gun */)
continue;
uint32_t color = colors[ent->id % q_countof(colors)];
R_AddDebugPoint(ent->origin, point_size, color, 0, depth_test);

if (print_id) {
vec3_t text_org;
VectorCopy(ent->origin, text_org);
text_org[2] += point_size;
R_AddDebugText(text_org, NULL, va("%d", ent->id), text_size, color, 0, depth_test);
}
}
}

#endif

//===================================================================
Expand Down Expand Up @@ -511,6 +537,8 @@ void V_RenderView(void)
cl.refdef.blend[2] = 0.25f;
cl.refdef.blend[3] = 0.5f;
}
if (cl_testdebuglines->integer)
V_TestDebugLines();
#endif

if(cl_flashlight->integer)
Expand Down Expand Up @@ -620,6 +648,7 @@ void V_Init(void)
cl_testparticles = Cvar_Get("cl_testparticles", "0", 0);
cl_testentities = Cvar_Get("cl_testentities", "0", 0);
cl_testlights = Cvar_Get("cl_testlights", "0", CVAR_CHEAT);
cl_testdebuglines = Cvar_Get("cl_testdebuglines", "0", CVAR_CHEAT);

cl_stats = Cvar_Get("cl_stats", "0", 0);
#endif
Expand Down
Loading