Quake II RTX doxygen  1.0 dev
draw.c File Reference
#include "gl.h"

Go to the source code of this file.

Macros

#define GL_StretchPic(x, y, w, h, s1, t1, s2, t2, color, image)   _GL_StretchPic(x,y,w,h,s1,t1,s2,t2,color,(image)->texnum,(image)->flags)
 
#define DIV64   (1.0f / 64.0f)
 

Functions

static void _GL_StretchPic (float x, float y, float w, float h, float s1, float t1, float s2, float t2, uint32_t color, int texnum, int flags)
 
void GL_Blend (void)
 
void R_ClearColor_GL (void)
 
void R_SetAlpha_GL (float alpha)
 
void R_SetAlphaScale_GL (float alpha)
 
void R_SetColor_GL (uint32_t color)
 
void R_SetClipRect_GL (const clipRect_t *clip)
 
void R_SetScale_GL (float scale)
 
void R_DrawStretchPic_GL (int x, int y, int w, int h, qhandle_t pic)
 
void R_DrawPic_GL (int x, int y, qhandle_t pic)
 
void R_TileClear_GL (int x, int y, int w, int h, qhandle_t pic)
 
void R_DrawFill8_GL (int x, int y, int w, int h, int c)
 
void R_DrawFill32_GL (int x, int y, int w, int h, uint32_t color)
 
static void draw_char (int x, int y, int flags, int c, image_t *image)
 
void R_DrawChar_GL (int x, int y, int flags, int c, qhandle_t font)
 
int R_DrawString_GL (int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font)
 

Variables

drawStatic_t draw
 

Macro Definition Documentation

◆ DIV64

#define DIV64   (1.0f / 64.0f)

Definition at line 187 of file draw.c.

◆ GL_StretchPic

#define GL_StretchPic (   x,
  y,
  w,
  h,
  s1,
  t1,
  s2,
  t2,
  color,
  image 
)    _GL_StretchPic(x,y,w,h,s1,t1,s2,t2,color,(image)->texnum,(image)->flags)

Definition at line 76 of file draw.c.

Function Documentation

◆ _GL_StretchPic()

static void _GL_StretchPic ( float  x,
float  y,
float  w,
float  h,
float  s1,
float  t1,
float  s2,
float  t2,
uint32_t  color,
int  texnum,
int  flags 
)
inlinestatic

Definition at line 23 of file draw.c.

27 {
28  vec_t *dst_vert;
29  uint32_t *dst_color;
30  QGL_INDEX_TYPE *dst_indices;
31 
32  if (tess.numverts + 4 > TESS_MAX_VERTICES ||
34  (tess.numverts && tess.texnum[0] != texnum)) {
35  GL_Flush2D();
36  }
37 
38  tess.texnum[0] = texnum;
39 
40  dst_vert = tess.vertices + tess.numverts * 4;
41  Vector4Set(dst_vert, x, y, s1, t1);
42  Vector4Set(dst_vert + 4, x + w, y, s2, t1);
43  Vector4Set(dst_vert + 8, x + w, y + h, s2, t2);
44  Vector4Set(dst_vert + 12, x, y + h, s1, t2);
45 
46  dst_color = (uint32_t *)tess.colors + tess.numverts;
47  dst_color[0] = color;
48  dst_color[1] = color;
49  dst_color[2] = color;
50  dst_color[3] = color;
51 
52  dst_indices = tess.indices + tess.numindices;
53  dst_indices[0] = tess.numverts + 0;
54  dst_indices[1] = tess.numverts + 2;
55  dst_indices[2] = tess.numverts + 3;
56  dst_indices[3] = tess.numverts + 0;
57  dst_indices[4] = tess.numverts + 1;
58  dst_indices[5] = tess.numverts + 2;
59 
60  if (flags & IF_TRANSPARENT) {
61  if ((flags & IF_PALETTED) && draw.scale == 1) {
62  tess.flags |= 1;
63  } else {
64  tess.flags |= 2;
65  }
66  }
67 
68  if ((color & U32_ALPHA) != U32_ALPHA) {
69  tess.flags |= 2;
70  }
71 
72  tess.numverts += 4;
73  tess.numindices += 6;
74 }

Referenced by GL_Blend(), R_DrawFill32_GL(), and R_DrawFill8_GL().

◆ draw_char()

static void draw_char ( int  x,
int  y,
int  flags,
int  c,
image_t image 
)
inlinestatic

Definition at line 209 of file draw.c.

210 {
211  float s, t;
212 
213  if ((c & 127) == 32) {
214  return;
215  }
216 
217  if (flags & UI_ALTCOLOR) {
218  c |= 0x80;
219  }
220  if (flags & UI_XORCOLOR) {
221  c ^= 0x80;
222  }
223 
224  s = (c & 15) * 0.0625f;
225  t = (c >> 4) * 0.0625f;
226 
227  if (gl_fontshadow->integer > 0 && c != 0x83) {
228  uint32_t black = MakeColor(0, 0, 0, draw.colors[0].u8[3]);
229 
230  GL_StretchPic(x + 1, y + 1, CHAR_WIDTH, CHAR_HEIGHT, s, t,
231  s + 0.0625f, t + 0.0625f, black, image);
232 
233  if (gl_fontshadow->integer > 1)
234  GL_StretchPic(x + 2, y + 2, CHAR_WIDTH, CHAR_HEIGHT, s, t,
235  s + 0.0625f, t + 0.0625f, black, image);
236  }
237 
238  GL_StretchPic(x, y, CHAR_WIDTH, CHAR_HEIGHT, s, t,
239  s + 0.0625f, t + 0.0625f, draw.colors[c >> 7].u32, image);
240 }

Referenced by R_DrawChar_GL(), and R_DrawString_GL().

◆ GL_Blend()

void GL_Blend ( void  )

Definition at line 79 of file draw.c.

80 {
81  color_t color;
82 
83  color.u8[0] = glr.fd.blend[0] * 255;
84  color.u8[1] = glr.fd.blend[1] * 255;
85  color.u8[2] = glr.fd.blend[2] * 255;
86  color.u8[3] = glr.fd.blend[3] * 255;
87 
88  _GL_StretchPic(glr.fd.x, glr.fd.y, glr.fd.width, glr.fd.height, 0, 0, 1, 1,
89  color.u32, TEXNUM_WHITE, 0);
90 }

Referenced by R_RenderFrame_GL().

◆ R_ClearColor_GL()

void R_ClearColor_GL ( void  )

Definition at line 92 of file draw.c.

93 {
94  draw.colors[0].u32 = U32_WHITE;
95  draw.colors[1].u32 = U32_WHITE;
96 }

Referenced by R_RegisterFunctionsGL().

◆ R_DrawChar_GL()

void R_DrawChar_GL ( int  x,
int  y,
int  flags,
int  c,
qhandle_t  font 
)

Definition at line 242 of file draw.c.

243 {
244  draw_char(x, y, flags, c & 255, IMG_ForHandle(font));
245 }

Referenced by R_RegisterFunctionsGL().

◆ R_DrawFill32_GL()

void R_DrawFill32_GL ( int  x,
int  y,
int  w,
int  h,
uint32_t  color 
)

Definition at line 202 of file draw.c.

203 {
204  if (!w || !h)
205  return;
206  _GL_StretchPic(x, y, w, h, 0, 0, 1, 1, color, TEXNUM_WHITE, 0);
207 }

Referenced by R_RegisterFunctionsGL().

◆ R_DrawFill8_GL()

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

Definition at line 195 of file draw.c.

196 {
197  if (!w || !h)
198  return;
199  _GL_StretchPic(x, y, w, h, 0, 0, 1, 1, d_8to24table[c & 0xff], TEXNUM_WHITE, 0);
200 }

Referenced by R_RegisterFunctionsGL().

◆ R_DrawPic_GL()

void R_DrawPic_GL ( int  x,
int  y,
qhandle_t  pic 
)

Definition at line 179 of file draw.c.

180 {
181  image_t *image = IMG_ForHandle(pic);
182 
183  GL_StretchPic(x, y, image->width, image->height,
184  image->sl, image->tl, image->sh, image->th, draw.colors[0].u32, image);
185 }

Referenced by R_RegisterFunctionsGL().

◆ R_DrawStretchPic_GL()

void R_DrawStretchPic_GL ( int  x,
int  y,
int  w,
int  h,
qhandle_t  pic 
)

Definition at line 171 of file draw.c.

172 {
173  image_t *image = IMG_ForHandle(pic);
174 
175  GL_StretchPic(x, y, w, h, image->sl, image->tl, image->sh, image->th,
176  draw.colors[0].u32, image);
177 }

Referenced by R_RegisterFunctionsGL().

◆ R_DrawString_GL()

int R_DrawString_GL ( int  x,
int  y,
int  flags,
size_t  maxlen,
const char *  s,
qhandle_t  font 
)

Definition at line 247 of file draw.c.

248 {
249  image_t *image = IMG_ForHandle(font);
250 
251  while (maxlen-- && *s) {
252  byte c = *s++;
253  draw_char(x, y, flags, c, image);
254  x += CHAR_WIDTH;
255  }
256 
257  return x;
258 }

Referenced by R_RegisterFunctionsGL().

◆ R_SetAlpha_GL()

void R_SetAlpha_GL ( float  alpha)

Definition at line 98 of file draw.c.

99 {
100  draw.colors[0].u8[3] =
101  draw.colors[1].u8[3] = alpha * 255;
102 }

Referenced by R_RegisterFunctionsGL().

◆ R_SetAlphaScale_GL()

void R_SetAlphaScale_GL ( float  alpha)

Definition at line 104 of file draw.c.

105 {
106  // nop - only used by the RTX renderer
107 }

Referenced by R_RegisterFunctionsGL().

◆ R_SetClipRect_GL()

void R_SetClipRect_GL ( const clipRect_t *  clip)

Definition at line 115 of file draw.c.

116 {
117  clipRect_t rc;
118  float scale;
119 
120  GL_Flush2D();
121 
122  if (!clip) {
123 clear:
124  if (draw.scissor) {
125  qglDisable(GL_SCISSOR_TEST);
126  draw.scissor = qfalse;
127  }
128  return;
129  }
130 
131  scale = 1 / draw.scale;
132 
133  rc.left = clip->left * scale;
134  rc.top = clip->top * scale;
135  rc.right = clip->right * scale;
136  rc.bottom = clip->bottom * scale;
137 
138  if (rc.left < 0)
139  rc.left = 0;
140  if (rc.top < 0)
141  rc.top = 0;
142  if (rc.right > r_config.width)
143  rc.right = r_config.width;
144  if (rc.bottom > r_config.height)
145  rc.bottom = r_config.height;
146  if (rc.right < rc.left)
147  goto clear;
148  if (rc.bottom < rc.top)
149  goto clear;
150 
151  qglEnable(GL_SCISSOR_TEST);
152  qglScissor(rc.left, r_config.height - rc.bottom,
153  rc.right - rc.left, rc.bottom - rc.top);
154  draw.scissor = qtrue;
155 }

Referenced by R_RegisterFunctionsGL().

◆ R_SetColor_GL()

void R_SetColor_GL ( uint32_t  color)

Definition at line 109 of file draw.c.

110 {
111  draw.colors[0].u32 = color;
112  draw.colors[1].u8[3] = draw.colors[0].u8[3];
113 }

Referenced by R_RegisterFunctionsGL().

◆ R_SetScale_GL()

void R_SetScale_GL ( float  scale)

Definition at line 157 of file draw.c.

158 {
159  if (draw.scale == scale) {
160  return;
161  }
162 
163  GL_Flush2D();
164 
165  GL_Ortho(0, Q_rint(r_config.width * scale),
166  Q_rint(r_config.height * scale), 0, -1, 1);
167 
168  draw.scale = scale;
169 }

Referenced by R_RegisterFunctionsGL().

◆ R_TileClear_GL()

void R_TileClear_GL ( int  x,
int  y,
int  w,
int  h,
qhandle_t  pic 
)

Definition at line 189 of file draw.c.

190 {
191  GL_StretchPic(x, y, w, h, x * DIV64, y * DIV64,
192  (x + w) * DIV64, (y + h) * DIV64, U32_WHITE, IMG_ForHandle(pic));
193 }

Referenced by R_RegisterFunctionsGL().

Variable Documentation

◆ draw

TESS_MAX_INDICES
#define TESS_MAX_INDICES
Definition: gl.h:460
image_t
struct image_s image_t
Definition: material.h:27
tesselator_t::numindices
int numindices
Definition: gl.h:468
GL_Ortho
void GL_Ortho(GLfloat xmin, GLfloat xmax, GLfloat ymin, GLfloat ymax, GLfloat znear, GLfloat zfar)
Definition: state.c:230
drawStatic_t::colors
color_t colors[2]
Definition: gl.h:402
d_8to24table
uint32_t d_8to24table[256]
Definition: images.c:654
GL_Flush2D
void GL_Flush2D(void)
Definition: tess.c:31
DIV64
#define DIV64
Definition: draw.c:187
draw
drawStatic_t draw
Definition: draw.c:21
TESS_MAX_VERTICES
#define TESS_MAX_VERTICES
Definition: gl.h:459
GL_StretchPic
#define GL_StretchPic(x, y, w, h, s1, t1, s2, t2, color, image)
Definition: draw.c:76
qglScissor
#define qglScissor
Definition: fixed.h:99
tesselator_t::indices
QGL_INDEX_TYPE indices[TESS_MAX_INDICES]
Definition: gl.h:464
qglDisable
#define qglDisable
Definition: fixed.h:54
_GL_StretchPic
static void _GL_StretchPic(float x, float y, float w, float h, float s1, float t1, float s2, float t2, uint32_t color, int texnum, int flags)
Definition: draw.c:23
draw_char
static void draw_char(int x, int y, int flags, int c, image_t *image)
Definition: draw.c:209
tesselator_t::texnum
GLuint texnum[MAX_TMUS]
Definition: gl.h:466
tesselator_t::flags
int flags
Definition: gl.h:469
c
statCounters_t c
Definition: main.c:30
glr
glRefdef_t glr
Definition: main.c:27
tesselator_t::colors
GLubyte colors[4 *TESS_MAX_VERTICES]
Definition: gl.h:465
tess
tesselator_t tess
Definition: tess.c:21
TEXNUM_WHITE
#define TEXNUM_WHITE
Definition: draw.c:30
color
static vec4_t color
Definition: mesh.c:33
IMG_ForHandle
image_t * IMG_ForHandle(qhandle_t h)
Definition: images.c:1156
drawStatic_t::scale
float scale
Definition: gl.h:404
QGL_INDEX_TYPE
#define QGL_INDEX_TYPE
Definition: gl.h:48
tesselator_t::vertices
GLfloat vertices[VERTEX_SIZE *TESS_MAX_VERTICES]
Definition: gl.h:463
drawStatic_t::scissor
qboolean scissor
Definition: gl.h:403
gl_fontshadow
cvar_t * gl_fontshadow
Definition: main.c:54
r_config
refcfg_t r_config
Definition: refresh.c:401
glRefdef_t::fd
refdef_t fd
Definition: gl.h:81
tesselator_t::numverts
int numverts
Definition: gl.h:467
qglEnable
#define qglEnable
Definition: fixed.h:58