vkQuake2 doxygen  1.0 dev
vk_draw.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 Copyright (C) 2018-2019 Krzysztof Kondrak
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 
14 See the GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 
20 */
21 
22 // draw.c
23 
24 #include "vk_local.h"
25 
27 
28 /*
29 ===============
30 Draw_InitLocal
31 ===============
32 */
33 void Draw_InitLocal (void)
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 }
39 
40 
41 
42 /*
43 ================
44 Draw_Char
45 
46 Draws one 8*8 graphics character with 0 being transparent.
47 It can be clipped to the top of the screen to allow the console to be
48 smoothly scrolled off.
49 ================
50 */
51 void Draw_Char (int x, int y, int num)
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 }
78 
79 /*
80 =============
81 Draw_FindPic
82 =============
83 */
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 }
99 
100 /*
101 =============
102 Draw_GetPicSize
103 =============
104 */
105 void Draw_GetPicSize (int *w, int *h, char *pic)
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 }
121 
122 /*
123 =============
124 Draw_StretchPic
125 =============
126 */
127 void Draw_StretchPic (int x, int y, int w, int h, char *pic)
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 }
144 
145 
146 /*
147 =============
148 Draw_Pic
149 =============
150 */
151 void Draw_Pic (int x, int y, char *pic)
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 }
165 
166 /*
167 =============
168 Draw_TileClear
169 
170 This repeats a 64*64 tile graphic to fill the screen around a sized down
171 refresh window.
172 =============
173 */
174 void Draw_TileClear (int x, int y, int w, int h, char *pic)
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 }
191 
192 
193 /*
194 =============
195 Draw_Fill
196 
197 Fills a box of pixels with a single color
198 =============
199 */
200 void Draw_Fill (int x, int y, int w, int h, int 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 }
218 
219 //=============================================================================
220 
221 /*
222 ================
223 Draw_FadeScreen
224 
225 ================
226 */
227 void Draw_FadeScreen (void)
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 }
232 
233 
234 //====================================================================
235 
236 
237 /*
238 =============
239 Draw_StretchRaw
240 =============
241 */
242 extern unsigned r_rawpalette[256];
244 
245 void Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data)
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 }
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
vk_local.h
Draw_Fill
void Draw_Fill(int x, int y, int w, int h, int c)
Definition: vk_draw.c:200
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
Draw_GetPicSize
void Draw_GetPicSize(int *w, int *h, char *pic)
Definition: vk_draw.c:105
ri
refimport_t ri
Definition: r_main.c:25
Draw_Char
void Draw_Char(int x, int y, int num)
Definition: vk_draw.c:51
Draw_FadeScreen
void Draw_FadeScreen(void)
Definition: vk_draw.c:227
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
Draw_InitLocal
void Draw_InitLocal(void)
Definition: vk_draw.c:33
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
Draw_TileClear
void Draw_TileClear(int x, int y, int w, int h, char *pic)
Definition: vk_draw.c:174
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
Draw_Pic
void Draw_Pic(int x, int y, char *pic)
Definition: vk_draw.c:151
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
Draw_StretchRaw
void Draw_StretchRaw(int x, int y, int w, int h, int cols, int rows, byte *data)
Definition: vk_draw.c:245
w
GLdouble GLdouble GLdouble w
Definition: qgl_win.c:291
image_s
Definition: r_local.h:71
qvktexture_t
Definition: qvk.h:77
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