21 #include "common/prompt.h"
51 static void GL_Upload32(
byte *data,
int width,
int height,
int baselevel, imagetype_t type, imageflags_t flags);
52 static void GL_Upscale32(
byte *data,
int width,
int height,
int maxlevel, imagetype_t type, imageflags_t flags);
61 {
"GL_NEAREST", GL_NEAREST, GL_NEAREST },
62 {
"GL_LINEAR", GL_LINEAR, GL_LINEAR },
63 {
"GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST },
64 {
"GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR },
65 {
"GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST },
66 {
"GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR }
82 Com_WPrintf(
"Bad texture mode: %s\n", self->string);
93 if (image->type == IT_WALL || image->type == IT_SKIN) {
124 if (image->type == IT_WALL || image->type == IT_SKIN) {
138 if (image->type == IT_FONT) {
152 if (image->type == IT_PIC) {
165 #ifdef GL_VERSION_1_1
166 }
else if (self->integer > 16) {
169 }
else if (self->integer > 8) {
172 }
else if (self->integer > 0) {
193 #define SCRAP_BLOCK_WIDTH 256
194 #define SCRAP_BLOCK_HEIGHT 256
200 #define Scrap_AllocBlock(w, h, s, t) \
201 GL_AllocBlock(SCRAP_BLOCK_WIDTH, SCRAP_BLOCK_HEIGHT, scrap_inuse, w, h, s, t)
265 if (flags & IF_TURBULENT)
271 c = inwidth * inheight;
273 for (i = 0; i <
c; i++, p += 4) {
277 y = LUMINANCE(r, g, b);
307 c = inwidth * inheight;
309 if (type == IT_WALL || type == IT_SKIN) {
310 for (i = 0; i <
c; i++, p += 4) {
316 for (i = 0; i <
c; i++, p += 4) {
331 if (flags & IF_TURBULENT)
337 c = inwidth * inheight;
339 for (i = 0; i <
c; i++, p += 4) {
353 for (i = 0; i <
c; i++, scan += 4) {
383 int scaled_width, scaled_height, comp;
384 qboolean power_of_two;
386 scaled_width =
width;
393 if (scaled_width >
width)
395 if (scaled_height >
height)
410 if (scaled_width < 1)
412 if (scaled_height < 1)
423 if (scaled_width ==
width && scaled_height ==
height) {
426 }
else if (power_of_two) {
429 while (
width > scaled_width ||
height > scaled_height) {
435 scaled = FS_AllocTempMem(scaled_width * scaled_height * 4);
437 scaled_width, scaled_height);
440 if (flags & IF_TRANSPARENT) {
442 }
else if (flags & IF_OPAQUE) {
454 scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
458 if (type == IT_WALL || type == IT_SKIN) {
464 while (scaled_width > 1 || scaled_height > 1) {
465 IMG_MipMap(scaled, scaled, scaled_width, scaled_height);
468 if (scaled_width < 1)
470 if (scaled_height < 1)
474 scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
479 if (scaled != data) {
480 FS_FreeTempMem(scaled);
489 if (type != IT_PIC && type != IT_FONT && type != IT_SPRITE)
493 if (!(flags & (IF_PALETTED | IF_SCRAP)))
516 buffer = FS_AllocTempMem((
width *
height) << ((maxlevel + 1) * 2));
528 FS_FreeTempMem(buffer);
532 #ifdef GL_TEXTURE_MAX_LEVEL
537 #ifdef GL_TEXTURE_LOD_BIAS
542 float bias = -log(max(du, dv)) / M_LN2;
552 if (type == IT_WALL || type == IT_SKIN) {
558 if (flags & IF_NEAREST) {
560 }
else if (type == IT_FONT) {
562 }
else if (type == IT_PIC) {
563 if (flags & IF_SCRAP)
573 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
576 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
591 if (type == IT_WALL || type == IT_SKIN)
597 if (type == IT_WALL || type == IT_SKIN || (flags & IF_REPEAT)) {
600 #ifdef GL_CLAMP_TO_EDGE
621 int i, s, t, maxlevel;
624 width = image->upload_width;
625 height = image->upload_height;
628 if (image->type == IT_PIC &&
width < 64 &&
height < 64 &&
632 for (i = 0; i <
height; i++) {
633 memcpy(dst, src,
width * 4);
639 image->flags |= IF_SCRAP | IF_TRANSPARENT;
647 image->flags |= IF_UPSCALED;
657 image->flags |= IF_UPSCALED;
665 image->flags |= IF_TRANSPARENT;
681 if (image->texnum && !(image->flags & IF_SCRAP)) {
695 for (i = 0; i < 256; i++) {
715 for (i = 0; i < 256; i++) {
720 for (i = 0; i < 256; i++) {
721 inf = 255 * pow(i / 255.0, g);
738 {0, 0, 0, 0, 0, 0, 0, 0},
739 {0, 0, 1, 1, 0, 0, 0, 0},
740 {0, 1, 1, 1, 1, 0, 0, 0},
741 {0, 1, 1, 1, 1, 0, 0, 0},
742 {0, 0, 1, 1, 0, 0, 0, 0},
743 {0, 0, 0, 0, 0, 0, 0, 0},
744 {0, 0, 0, 0, 0, 0, 0, 0},
745 {0, 0, 0, 0, 0, 0, 0, 0},
751 byte pixels[8 * 8 * 4];
756 for (i = 0; i < 8; i++) {
757 for (j = 0; j < 8; j++) {
767 GL_Upload32(pixels, 8, 8, 0, IT_WALL, IF_TURBULENT);
772 ntx->width = ntx->upload_width = 8;
773 ntx->height = ntx->upload_height = 8;
785 byte pixels[16 * 16 * 4];
791 for (i = 0; i < 16; i++) {
792 for (j = 0; j < 16; j++) {
793 x = j - 16 / 2 + 0.5f;
794 y = i - 16 / 2 + 0.5f;
795 f = sqrt(x * x + y * y);
796 f = 1.0f - f / (16 / 2 - 0.5f);
800 dst[3] = 255 * clamp(f, 0, 1);
806 GL_Upload32(pixels, 16, 16, 0, IT_SPRITE, IF_NONE);
816 GL_Upload32((
byte *)&pixel, 1, 1, 0, IT_SPRITE, IF_REPEAT | IF_NEAREST);
821 GL_Upload32((
byte *)&pixel, 1, 1, 0, IT_SPRITE, IF_REPEAT | IF_NEAREST);
827 byte pixels[16 * 16 * 4];
833 for (i = 0; i < 16; i++) {
834 for (j = 0; j < 16; j++) {
835 f = abs(j - 16 / 2) - 0.5f;
836 f = 1.0f - f / (16 / 2 - 2.5f);
840 dst[3] = 255 * clamp(f, 0, 1);
846 GL_Upload32(pixels, 16, 16, 0, IT_SPRITE, IF_NONE);
862 "GL_LINEAR_MIPMAP_LINEAR", CVAR_ARCHIVE);
880 if (
r_config.flags & QVF_GAMMARAMP) {
903 if (
r_config.flags & QVF_GAMMARAMP) {