33 #include "../cl_console.h"
40 #define MAX_CHARS 8192
57 #define MAX_BATCH_ENTRIES 512
70 #define MAX_BBOX_ENTRIES 256
87 Com_Printf(
"Could not find shadow image in game pics/sfx directory!\n");
103 if ((num & 127) ==
' ')
112 int row = (
int) num >> 4;
113 int col = (
int) num & 15;
116 float frow = row * 0.0625;
117 float fcol = col * 0.0625;
167 glVertexPointer(2, GL_SHORT, 0, r_char_arrays.
verts);
194 const int r = color[0] * 255.0;
195 const int g = color[1] * 255.0;
196 const int b = color[2] * 255.0;
197 const int a = color[3] * 255.0;
198 const uint32_t c =
LittleLong((r << 0) + (g << 8) + (b << 16) + (a << 24));
243 glVertexPointer(2, GL_SHORT, 0, r_fill_arrays.
verts);
274 int scaledWidth, scaledHeight;
276 #ifdef GL_VERSION_ES_CM_1_0
287 for (
unsigned const*
i = frame, *
const end =
i + scaledHeight * scaledWidth;
i != end; ++
i) {
288 if ((*
i & 0xFF000000U) != 0xFF000000U) {
294 if (scaledWidth != width || scaledHeight != height) {
296 R_ScaleTexture(frame, width, height, scaled, scaledWidth, scaledHeight);
303 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, scaledWidth, scaledHeight, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
310 glTexImage2D(GL_TEXTURE_2D, 0, samples, scaledWidth, scaledHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
360 glVertexPointer(2, GL_FLOAT, 0, verts);
361 R_BindArray(GL_TEXTURE_COORD_ARRAY, GL_FLOAT, texcoords);
363 if (image !=
nullptr)
366 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
390 void R_DrawRect (
int x,
int y,
int w,
int h,
const vec4_t color,
float lineWidth,
int pattern)
396 const vec2_t points[] = { { nx, ny }, { nx + nw, ny }, { nx + nw, ny + nh }, { nx, ny + nh } };
400 glDisable(GL_TEXTURE_2D);
401 glLineWidth(lineWidth);
402 #ifndef GL_VERSION_ES_CM_1_0
403 glLineStipple(2, pattern);
404 glEnable(GL_LINE_STIPPLE);
407 glVertexPointer(2, GL_FLOAT, 0, points);
408 glDrawArrays(GL_LINE_LOOP, 0, 4);
413 glEnable(GL_TEXTURE_2D);
415 #ifndef GL_VERSION_ES_CM_1_0
416 glDisable(GL_LINE_STIPPLE);
425 const size_t steps =
lengthof(points);
427 glEnable(GL_LINE_SMOOTH);
428 glLineWidth(thickness);
432 for (
unsigned int i = 0;
i < steps;
i++) {
433 const float a = 2.0f *
M_PI * (float)
i / (
float) steps;
434 VectorSet(points[
i], shift[0] + radius * cos(a), shift[1] + radius * sin(a), shift[2]);
438 glDrawArrays(GL_LINE_LOOP, 0, steps);
446 glDisable(GL_LINE_SMOOTH);
449 #define MAX_LINEVERTS 256
460 for (
int i = 0;
i < points * 2;
i += 2) {
465 glDisable(GL_TEXTURE_2D);
466 glDrawArrays(mode, 0, points);
467 glEnable(GL_TEXTURE_2D);
497 glLineWidth(thickness);
521 #define MAX_CLIPRECT 16
535 out->
x = (a->
x > b->
x) ? a->
x : b->
x;
536 out->
y = (a->
y > b->
y) ? a->
y : b->
y;
569 glScissor(clipRect[depth].x, clipRect[depth].y, clipRect[depth].width, clipRect[depth].height);
572 glEnable(GL_SCISSOR_TEST);
584 glDisable(GL_SCISSOR_TEST);
587 glScissor(clipRect[depth].x, clipRect[depth].y, clipRect[depth].width, clipRect[depth].height);
600 const int nwidth = width *
viddef.
rx;
601 const int nheight = height *
viddef.
ry;
602 const GLboolean hasDepthTest = glIsEnabled(GL_DEPTH_TEST);
603 const GLfloat bigZ = 2000.0f;
604 const vec3_t points [] = { { nx, ny, bigZ }, { nx + nwidth, ny, bigZ }, { nx + nwidth, ny + nheight, bigZ }, { nx, ny + nheight, bigZ } };
607 glGetIntegerv(GL_DEPTH_FUNC, &depthFunc);
610 glEnable(GL_DEPTH_TEST);
611 glDepthFunc(GL_ALWAYS);
612 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
615 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
620 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
622 glDisable(GL_DEPTH_TEST);
623 glDepthFunc(depthFunc);
633 for (
int i = 0;
i < 8;
i++) {
634 bbox[
i][0] = (
i & 1) ? mins[0] : maxs[0];
635 bbox[
i][1] = (
i & 2) ? mins[1] : maxs[1];
636 bbox[
i][2] = (
i & 4) ? mins[2] : maxs[2];
642 const int step = 3 * 8;
644 const GLushort indexes[] = { 2, 1, 0, 1, 4, 5, 1, 7, 3, 2, 7, 6, 2, 4, 0 };
645 const GLushort indexes2[] = { 4, 6, 7 };
650 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
654 for (
int i = 0;
i < bboxes;
i++) {
655 const float* bbox = &r_bbox_array.
bboxes[
i * step];
658 glDrawElements(GL_TRIANGLE_FAN, 15, GL_UNSIGNED_SHORT, indexes);
660 glDrawElements(GL_TRIANGLE_FAN, 3, GL_UNSIGNED_SHORT, indexes2);
665 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
680 for (
int i = 0;
i < 8;
i++) {
693 const GLushort indexes[] = { 2, 1, 0, 1, 4, 5, 1, 7, 3, 2, 7, 6, 2, 4, 0 };
694 const GLushort indexes2[] = { 4, 6, 7 };
698 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
702 glDrawElements(GL_TRIANGLE_STRIP, 15, GL_UNSIGNED_SHORT, indexes);
704 glDrawElements(GL_TRIANGLE_STRIP, 3, GL_UNSIGNED_SHORT, indexes2);
707 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
716 const GLfloat texcoords[] = { 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, };
718 { a0[0], a0[1], a0[2] }, { a0[0], a0[1], a1[2] }, { a1[0], a0[1], a1[2] }, { a1[0], a0[1], a0[2] },
719 { a1[0], a1[1], a0[2] }, { a1[0], a1[1], a1[2] }, { a0[0], a1[1], a1[2] }, { a0[0], a1[1], a0[2] },
720 { a0[0], a0[1], a0[2] }, { a0[0], a0[1], a1[2] }, { a1[0], a0[1], a1[2] }, { a1[0], a0[1], a0[2] },
721 { a1[0], a1[1], a0[2] }, { a1[0], a1[1], a1[2] }, { a0[0], a1[1], a1[2] }, { a0[0], a1[1], a0[2] } };
722 const GLushort indexes[] = { 0, 1, 2, 1, 2, 3, 4, 5, 6, 6, 7, 4, 2 + 8, 3 + 8, 4 + 8, 2 + 8, 5 + 8, 4 + 8, 6 + 8, 7 + 8,
723 0 + 8, 0 + 8, 1 + 8, 6 + 8, };
725 R_BindArray(GL_TEXTURE_COORD_ARRAY, GL_FLOAT, texcoords);
729 glDrawElements(GL_TRIANGLES, 8 * 3, GL_UNSIGNED_SHORT, indexes);
void R_DrawChar(int x, int y, int num, uint32_t color)
Draws one 8*8 graphics character with 0 being transparent. It can be clipped to the top of the screen...
static ipos3_t shift
The shift array is used for random map assemblies (RMA) to shift the mins/maxs and stuff like that...
#define VectorCopy(src, dest)
void R_EnableTexture(gltexunit_t *texunit, bool enable)
#define VectorSet(v, x, y, z)
static void R_RectIntersection(const rect_t *a, const rect_t *b, rect_t *out)
Compute the intersection of 2 rect.
array to store batched vertices and colors per frame
void R_DrawImage(float x, float y, const image_t *image)
Draws an image or parts of it.
const image_t * R_DrawImageArray(const vec2_t texcoords[4], const vec2_t verts[4], const image_t *image)
void R_DrawLineStrip(int points, int *verts)
2 dimensional line strip
static void R_ComputeBoundingBox(const vec3_t mins, const vec3_t maxs, vec3_t bbox[8])
Compute the bounding box for an entity out of the mins, maxs.
GLfloat * vertex_array_3d
const GLenum *typedef GLint
static char_arrays_t r_char_arrays
GLshort verts[MAX_CHARS *4 *2]
void R_ScaleTexture(const unsigned *in, int inwidth, int inheight, unsigned *out, int outwidth, int outheight)
static int currentClipRect
local graphics definitions
void R_DrawStretchImage(float x, float y, int w, int h, const image_t *image)
static bbox_arrays_t r_bbox_array
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
void Com_Printf(const char *const fmt,...)
GLint *typedef GLboolean(APIENTRY *IsFramebufferEXT_t)(GLuint)
const GLuint *typedef GLuint *typedef GLenum
void R_DrawBoundingBox(const AABB &absBox)
Draws the model bounding box.
void R_DrawBoundingBoxes(void)
GLshort * vertex_array_2d
void R_Color(const vec4_t rgba)
Change the color to given value.
struct bbox_arrays_s bbox_arrays_t
void Com_Error(int code, const char *fmt,...)
image_t * R_FindImage(const char *pname, imagetype_t type)
Finds or loads the given image.
void R_DrawCircle(float radius, const vec4_t color, float thickness, const vec3_t shift)
void R_DrawTexture(int texnum, int x, int y, int w, int h)
Bind and draw a texture.
void R_DrawPolygon(int points, int *verts)
void R_DrawLineLoop(int points, int *verts)
GLshort verts[MAX_BATCH_ENTRIES *4 *2]
void R_EnableColorArray(bool enable)
static rect_t clipRect[MAX_CLIPRECT]
int gl_compressed_alpha_format
void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *texels)
void R_BindDefaultArray(GLenum target)
Binds the appropriate shared vertex array to the specified target.
int R_UploadData(const char *name, unsigned *frame, int width, int height)
Uploads image data.
struct char_arrays_s char_arrays_t
Characters are batched per frame and drawn in one shot accumulate coordinates and colors as vertex ar...
static image_t * draw_chars
GLfloat texcoords[MAX_CHARS *4 *2]
void R_DrawLine(int *verts, float thickness)
Draws one line with only one start and one end point.
void glTexParameterf(GLenum target, GLenum pname, GLfloat param)
#define Mem_PoolAllocTypeN(type, n, pool)
static void R_Draw2DArray(int points, int *verts, GLenum mode)
#define Vector2FromInt(x, y)
GLbyte colors[MAX_CHARS *4 *4]
GLbyte colors[MAX_BATCH_ENTRIES *4 *4]
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
void R_DrawArrays(GLint first, GLsizei count)
#define MAX_BATCH_ENTRIES
void R_GetScaledTextureSize(int width, int height, int *scaledWidth, int *scaledHeight)
Calculates the texture size that should be used to upload the texture data.
memPool_t * vid_imagePool
void R_DrawRect(int x, int y, int w, int h, const vec4_t color, float lineWidth, int pattern)
Draws a rect to the screen. Also has support for stippled rendering of the rect.
void R_DrawInitLocal(void)
Loads some textures and init the 3d globe.
void R_DrawFill(int x, int y, int w, int h, const vec4_t color)
Fills a box of pixels with a single color.
static batch_arrays_t r_fill_arrays
Functions to generate and render spheres.
void R_DrawBoundingBoxBatched(const AABB &absbox)
void R_DrawTexturedBox(const vec3_t a0, const vec3_t a1)
Draws the textured box, the caller should bind the texture.
Characters are batched per frame and drawn in one shot accumulate coordinates and colors as vertex ar...
const vec2_t default_texcoords[4]
void R_CleanupDepthBuffer(int x, int y, int width, int height)
"Clean up" the depth buffer into a rect
float bboxes[3 *8 *MAX_BBOX_ENTRIES]
struct batch_arrays_s batch_arrays_t
array to store batched vertices and colors per frame
#define R_BindTexture(tn)
int gl_compressed_solid_format
void R_BindArray(GLenum target, GLenum type, const void *array)
void R_PushClipRect(int x, int y, int width, int height)
Force to draw only on a rect.