vkQuake2 doxygen  1.0 dev
vk_draw.c File Reference
#include "vk_local.h"

Go to the source code of this file.

Functions

void Draw_InitLocal (void)
 
void Draw_Char (int x, int y, int num)
 
image_tDraw_FindPic (char *name)
 
void Draw_GetPicSize (int *w, int *h, char *pic)
 
void Draw_StretchPic (int x, int y, int w, int h, char *pic)
 
void Draw_Pic (int x, int y, char *pic)
 
void Draw_TileClear (int x, int y, int w, int h, char *pic)
 
void Draw_Fill (int x, int y, int w, int h, int c)
 
void Draw_FadeScreen (void)
 
void Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data)
 

Variables

image_tdraw_chars
 
unsigned r_rawpalette [256]
 
qvktexture_t vk_rawTexture
 

Function Documentation

◆ Draw_Char()

void Draw_Char ( int  x,
int  y,
int  num 
)

Definition at line 51 of file vk_draw.c.

52 {
53  int row, col;
54  float frow, fcol, size;
55 
56  num &= 255;
57 
58  if ((num & 127) == 32)
59  return; // space
60 
61  if (y <= -8)
62  return; // totally off screen
63 
64  cvar_t *scale = ri.Cvar_Get("hudscale", "1", 0);
65 
66  row = num >> 4;
67  col = num & 15;
68 
69  frow = row * 0.0625;
70  fcol = col * 0.0625;
71  size = 0.0625;
72 
73  float imgTransform[] = { (float)x / vid.width, (float)y / vid.height,
74  8.f * scale->value / vid.width, 8.f * scale->value / vid.height,
75  fcol, frow, size, size };
76  QVk_DrawTexRect(imgTransform, sizeof(imgTransform), &draw_chars->vk_texture);
77 }

Referenced by GetRefAPI().

◆ Draw_FadeScreen()

void Draw_FadeScreen ( void  )

Definition at line 227 of file vk_draw.c.

228 {
229  float imgTransform[] = { 0.f, 0.f, vid.width, vid.height, 0.f, 0.f, 0.f, .8f };
230  QVk_DrawColorRect(imgTransform, sizeof(imgTransform), RP_UI);
231 }

Referenced by GetRefAPI().

◆ Draw_Fill()

void Draw_Fill ( int  x,
int  y,
int  w,
int  h,
int  c 
)

Definition at line 200 of file vk_draw.c.

201 {
202  union
203  {
204  unsigned c;
205  byte v[4];
206  } color;
207 
208  if ((unsigned)c > 255)
209  ri.Sys_Error(ERR_FATAL, "Draw_Fill: bad color");
210 
211  color.c = d_8to24table[c];
212 
213  float imgTransform[] = { (float)x / vid.width, (float)y / vid.height,
214  (float)w / vid.width, (float)h / vid.height,
215  color.v[0] / 255.f, color.v[1] / 255.f, color.v[2] / 255.f, 1.f };
216  QVk_DrawColorRect(imgTransform, sizeof(imgTransform), RP_UI);
217 }

Referenced by GetRefAPI().

◆ Draw_FindPic()

image_t* Draw_FindPic ( char *  name)

Definition at line 84 of file vk_draw.c.

85 {
86  image_t *vk;
87  char fullname[MAX_QPATH];
88 
89  if (name[0] != '/' && name[0] != '\\')
90  {
91  Com_sprintf(fullname, sizeof(fullname), "pics/%s.pcx", name);
92  vk = Vk_FindImage(fullname, it_pic, NULL);
93  }
94  else
95  vk = Vk_FindImage(name + 1, it_pic, NULL);
96 
97  return vk;
98 }

Referenced by Draw_GetPicSize(), Draw_Pic(), Draw_StretchPic(), Draw_TileClear(), and GetRefAPI().

◆ Draw_GetPicSize()

void Draw_GetPicSize ( int w,
int h,
char *  pic 
)

Definition at line 105 of file vk_draw.c.

106 {
107  image_t *vk;
108 
109  vk = Draw_FindPic(pic);
110  if (!vk)
111  {
112  *w = *h = -1;
113  return;
114  }
115 
116  cvar_t *scale = ri.Cvar_Get("hudscale", "1", 0);
117 
118  *w = vk->width * scale->value;
119  *h = vk->height * scale->value;
120 }

◆ Draw_InitLocal()

void Draw_InitLocal ( void  )

Definition at line 33 of file vk_draw.c.

34 {
35  // load console characters (don't bilerp characters)
36  qvksampler_t samplerType = S_NEAREST;
37  draw_chars = Vk_FindImage("pics/conchars.pcx", it_pic, &samplerType);
38 }

◆ Draw_Pic()

void Draw_Pic ( int  x,
int  y,
char *  pic 
)

Definition at line 151 of file vk_draw.c.

152 {
153  image_t *vk;
154  cvar_t *scale = ri.Cvar_Get("hudscale", "1", 0);
155 
156  vk = Draw_FindPic(pic);
157  if (!vk)
158  {
159  ri.Con_Printf(PRINT_ALL, "Can't find pic: %s\n", pic);
160  return;
161  }
162 
163  Draw_StretchPic(x, y, vk->width*scale->value, vk->height*scale->value, pic);
164 }

Referenced by GetRefAPI().

◆ Draw_StretchPic()

void Draw_StretchPic ( int  x,
int  y,
int  w,
int  h,
char *  pic 
)

Definition at line 127 of file vk_draw.c.

128 {
129  image_t *vk;
130 
131  vk = Draw_FindPic(pic);
132  if (!vk)
133  {
134  ri.Con_Printf(PRINT_ALL, "Can't find pic: %s\n", pic);
135  return;
136  }
137 
138  float imgTransform[] = { (float)x / vid.width, (float)y / vid.height,
139  (float)w / vid.width, (float)h / vid.height,
140  vk->sl, vk->tl,
141  vk->sh - vk->sl, vk->th - vk->tl };
142  QVk_DrawTexRect(imgTransform, sizeof(imgTransform), &vk->vk_texture);
143 }

Referenced by Draw_Pic().

◆ Draw_StretchRaw()

void Draw_StretchRaw ( int  x,
int  y,
int  w,
int  h,
int  cols,
int  rows,
byte data 
)

Definition at line 245 of file vk_draw.c.

246 {
247  unsigned image32[256 * 256];
248  int i, j, trows;
249  byte *source;
250  int frac, fracstep;
251  float hscale;
252  int row;
253  float t;
254 
255  if (rows <= 256)
256  {
257  hscale = 1;
258  trows = rows;
259  }
260  else
261  {
262  hscale = rows / 256.0;
263  trows = 256;
264  }
265  t = rows * hscale / 256;
266 
267  unsigned *dest;
268 
269  for (i = 0; i < trows; i++)
270  {
271  row = (int)(i*hscale);
272  if (row > rows)
273  break;
274  source = data + cols * row;
275  dest = &image32[i * 256];
276  fracstep = cols * 0x10000 / 256;
277  frac = fracstep >> 1;
278  for (j = 0; j < 256; j++)
279  {
280  dest[j] = r_rawpalette[source[frac >> 16]];
281  frac += fracstep;
282  }
283  }
284 
285  if (vk_rawTexture.image != VK_NULL_HANDLE)
286  {
287  QVk_UpdateTextureData(&vk_rawTexture, (unsigned char*)&image32, 0, 0, 256, 256);
288  }
289  else
290  {
292  QVk_CreateTexture(&vk_rawTexture, (unsigned char*)&image32, 256, 256, vk_current_sampler);
293  QVk_DebugSetObjectName((uint64_t)vk_rawTexture.image, VK_OBJECT_TYPE_IMAGE, "Image: raw texture");
294  QVk_DebugSetObjectName((uint64_t)vk_rawTexture.imageView, VK_OBJECT_TYPE_IMAGE_VIEW, "Image View: raw texture");
295  QVk_DebugSetObjectName((uint64_t)vk_rawTexture.descriptorSet, VK_OBJECT_TYPE_DESCRIPTOR_SET, "Descriptor Set: raw texture");
296  QVk_DebugSetObjectName((uint64_t)vk_rawTexture.allocInfo.deviceMemory, VK_OBJECT_TYPE_DEVICE_MEMORY, "Memory: raw texture");
297  }
298 
299  float imgTransform[] = { (float)x / vid.width, (float)y / vid.height,
300  (float)w / vid.width, (float)h / vid.height,
301  0.f, 0.f, 1.f, t };
302  QVk_DrawTexRect(imgTransform, sizeof(imgTransform), &vk_rawTexture);
303 }

◆ Draw_TileClear()

void Draw_TileClear ( int  x,
int  y,
int  w,
int  h,
char *  pic 
)

Definition at line 174 of file vk_draw.c.

175 {
176  image_t *image;
177 
178  image = Draw_FindPic(pic);
179  if (!image)
180  {
181  ri.Con_Printf(PRINT_ALL, "Can't find pic: %s\n", pic);
182  return;
183  }
184 
185  float imgTransform[] = { (float)x / vid.width, (float)y / vid.height,
186  (float)w / vid.width, (float)h / vid.height,
187  (float)x / 64.0, (float)y / 64.0,
188  (float)w / 64.0, (float)h / 64.0 };
189  QVk_DrawTexRect(imgTransform, sizeof(imgTransform), &image->vk_texture);
190 }

Referenced by GetRefAPI().

Variable Documentation

◆ draw_chars

image_t* draw_chars

Definition at line 26 of file vk_draw.c.

Referenced by Draw_Char(), and Draw_InitLocal().

◆ r_rawpalette

unsigned r_rawpalette[256]

Definition at line 1572 of file gl_rmain.c.

Referenced by Draw_StretchRaw(), and R_SetPalette().

◆ vk_rawTexture

qvktexture_t vk_rawTexture

Definition at line 28 of file vk_image.c.

Referenced by Draw_StretchRaw(), Vk_ShutdownImages(), and Vk_TextureMode().

image_s::vk_texture
qvktexture_t vk_texture
Definition: vk_local.h:116
QVk_DebugSetObjectName
#define QVk_DebugSetObjectName(a, b, c)
Definition: qvk.h:317
MAX_QPATH
#define MAX_QPATH
Definition: q_shared.h:80
Draw_FindPic
image_t * Draw_FindPic(char *name)
Definition: vk_draw.c:84
int
CONST PIXELFORMATDESCRIPTOR int
Definition: qgl_win.c:35
QVk_DrawColorRect
void QVk_DrawColorRect(float *ubo, VkDeviceSize uboSize, qvkrenderpasstype_t rpType)
Definition: vk_common.c:2253
image_s::th
float th
Definition: gl_local.h:96
ri
refimport_t ri
Definition: r_main.c:25
v
GLdouble v
Definition: qgl_win.c:143
VmaAllocationInfo::deviceMemory
VkDeviceMemory deviceMemory
Handle to Vulkan memory object.
Definition: vk_mem_alloc.h:2545
draw_chars
image_t * draw_chars
Definition: vk_draw.c:26
refimport_t::Cvar_Get
cvar_t *(* Cvar_Get)(char *name, char *value, int flags)
Definition: ref.h:216
x
GLint GLenum GLint x
Definition: qgl_win.c:116
i
int i
Definition: q_shared.c:305
vk_current_sampler
qvksampler_t vk_current_sampler
Definition: vk_image.c:42
r_rawpalette
unsigned r_rawpalette[256]
Definition: gl_rmain.c:1572
cvar_s
Definition: q_shared.h:324
j
GLint j
Definition: qgl_win.c:150
qvktexture_t::descriptorSet
VkDescriptorSet descriptorSet
Definition: qvk.h:87
refimport_t::Con_Printf
void(* Con_Printf)(int print_level, char *str,...)
Definition: ref.h:202
PRINT_ALL
#define PRINT_ALL
Definition: qcommon.h:751
qvktexture_t::image
VkImage image
Definition: qvk.h:79
it_pic
@ it_pic
Definition: r_local.h:67
qvktexture_t::allocInfo
VmaAllocationInfo allocInfo
Definition: qvk.h:81
image_s::height
int height
Definition: r_local.h:75
viddef_t::width
unsigned width
Definition: vid.h:29
qvksampler_t
qvksampler_t
Definition: qvk.h:63
t
GLdouble t
Definition: qgl_win.c:328
QVk_CreateTexture
void QVk_CreateTexture(qvktexture_t *texture, const unsigned char *data, uint32_t width, uint32_t height, qvksampler_t samplerType)
Definition: vk_image.c:382
refimport_t::Sys_Error
void(* Sys_Error)(int err_level, char *str,...)
Definition: ref.h:194
viddef_t::height
unsigned height
Definition: vid.h:29
cvar_s::value
float value
Definition: q_shared.h:331
Vk_FindImage
image_t * Vk_FindImage(char *name, imagetype_t type, qvksampler_t *samplerType)
Definition: vk_image.c:1508
NULL
#define NULL
Definition: q_shared.h:67
image_s::width
int width
Definition: r_local.h:75
QVk_UpdateTextureData
void QVk_UpdateTextureData(qvktexture_t *texture, const unsigned char *data, uint32_t offset_x, uint32_t offset_y, uint32_t width, uint32_t height)
Definition: vk_image.c:402
image_s::tl
float tl
Definition: gl_local.h:96
qvktexture_t::imageView
VkImageView imageView
Definition: qvk.h:83
name
cvar_t * name
Definition: cl_main.c:79
ERR_FATAL
#define ERR_FATAL
Definition: qcommon.h:743
y
GLint y
Definition: qgl_win.c:115
S_NEAREST
@ S_NEAREST
Definition: qvk.h:65
RP_UI
@ RP_UI
Definition: qvk.h:197
d_8to24table
unsigned d_8to24table[256]
Definition: r_main.c:27
image_s::sl
float sl
Definition: gl_local.h:96
Draw_StretchPic
void Draw_StretchPic(int x, int y, int w, int h, char *pic)
Definition: vk_draw.c:127
QVk_DrawTexRect
void QVk_DrawTexRect(float *ubo, VkDeviceSize uboSize, qvktexture_t *texture)
Definition: vk_common.c:2268
vk_rawTexture
qvktexture_t vk_rawTexture
Definition: vk_image.c:28
w
GLdouble GLdouble GLdouble w
Definition: qgl_win.c:291
image_s
Definition: r_local.h:71
QVVKTEXTURE_CLEAR
#define QVVKTEXTURE_CLEAR(i)
Definition: qvk.h:104
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1223
image_s::sh
float sh
Definition: gl_local.h:96
vid
viddef_t vid
Definition: r_main.c:24