2011-12-26 09:34:51 +00:00
|
|
|
/*
|
|
|
|
glsl_textures.c
|
|
|
|
|
|
|
|
Texture format setup.
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 2001 Ragnvald Maartmann-Moe IV
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
#define NH_DEFINE
|
|
|
|
#include "namehack.h"
|
|
|
|
|
2011-12-26 09:34:51 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2012-01-06 07:24:13 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-01-07 06:34:31 +00:00
|
|
|
#include "QF/cmd.h"
|
2012-01-06 07:24:13 +00:00
|
|
|
#include "QF/mathlib.h"
|
2012-01-07 09:05:54 +00:00
|
|
|
#include "QF/model.h"
|
2021-01-12 12:10:22 +00:00
|
|
|
#include "QF/render.h"
|
2012-01-06 07:24:13 +00:00
|
|
|
#include "QF/sys.h"
|
2011-12-26 09:34:51 +00:00
|
|
|
|
|
|
|
#include "QF/GLSL/defines.h"
|
|
|
|
#include "QF/GLSL/funcs.h"
|
|
|
|
#include "QF/GLSL/qf_textures.h"
|
|
|
|
|
2021-06-12 13:50:51 +00:00
|
|
|
#include "QF/ui/vrect.h"
|
|
|
|
|
2021-01-12 12:10:22 +00:00
|
|
|
#include "r_scrap.h"
|
|
|
|
|
2012-01-06 07:24:13 +00:00
|
|
|
struct scrap_s {
|
2021-01-12 12:10:22 +00:00
|
|
|
rscrap_t rscrap;
|
2012-01-06 07:24:13 +00:00
|
|
|
GLuint tnum;
|
|
|
|
int format;
|
|
|
|
int bpp;
|
2012-07-02 11:01:28 +00:00
|
|
|
byte *data; // local copy of the texture so updates can be batched
|
|
|
|
vrect_t *batch;
|
2012-01-17 04:00:43 +00:00
|
|
|
subpic_t *subpics;
|
2012-01-06 07:24:13 +00:00
|
|
|
struct scrap_s *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
static scrap_t *scrap_list;
|
|
|
|
|
|
|
|
static int max_tex_size;
|
|
|
|
|
2011-12-26 09:34:51 +00:00
|
|
|
int
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_LoadQuakeTexture (const char *identifier, int width, int height,
|
2021-12-13 15:42:22 +00:00
|
|
|
const byte *data)
|
2011-12-26 09:34:51 +00:00
|
|
|
{
|
|
|
|
GLuint tnum;
|
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGenTextures (1, &tnum);
|
|
|
|
qfeglBindTexture (GL_TEXTURE_2D, tnum);
|
|
|
|
qfeglTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE,
|
2012-05-14 14:02:06 +00:00
|
|
|
width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
qfeglGenerateMipmap (GL_TEXTURE_2D);
|
2011-12-26 09:34:51 +00:00
|
|
|
|
|
|
|
return tnum;
|
|
|
|
}
|
2011-12-31 11:36:24 +00:00
|
|
|
|
2012-01-07 09:05:54 +00:00
|
|
|
static void
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_Resample8BitTexture (unsigned char *in, int inwidth, int inheight,
|
2012-01-07 09:05:54 +00:00
|
|
|
unsigned char *out, int outwidth, int outheight)
|
|
|
|
{
|
|
|
|
// Improvements here should be mirrored in build_skin_8 in gl_skin.c
|
|
|
|
unsigned char *inrow;
|
|
|
|
int i, j;
|
|
|
|
unsigned int frac, fracstep;
|
|
|
|
|
|
|
|
if (!outwidth || !outheight)
|
|
|
|
return;
|
|
|
|
fracstep = inwidth * 0x10000 / outwidth;
|
|
|
|
for (i = 0; i < outheight; i++, out += outwidth) {
|
|
|
|
inrow = in + inwidth * (i * inheight / outheight);
|
|
|
|
frac = fracstep >> 1;
|
|
|
|
for (j = 0; j < outwidth; j ++) {
|
|
|
|
out[j] = inrow[frac >> 16];
|
|
|
|
frac += fracstep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-14 10:02:06 +00:00
|
|
|
static void
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_Mipmap8BitTexture (const byte *src, unsigned width, unsigned height,
|
2012-01-14 10:02:06 +00:00
|
|
|
byte *mip)
|
|
|
|
{
|
|
|
|
unsigned mw = width >> 1;
|
|
|
|
unsigned mh = height >> 1;
|
|
|
|
unsigned i, j;
|
|
|
|
|
|
|
|
mw = max (mw, 1);
|
|
|
|
mh = max (mh, 1);
|
|
|
|
|
|
|
|
for (j = 0; j < mh; j++) {
|
|
|
|
for (i = 0; i < mw; i++) {
|
|
|
|
*mip++ = src [j * 2 * width + i * 2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-07 09:05:54 +00:00
|
|
|
int
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_LoadQuakeMipTex (const texture_t *tex)
|
2012-01-07 09:05:54 +00:00
|
|
|
{
|
|
|
|
unsigned swidth, sheight;
|
|
|
|
GLuint tnum;
|
|
|
|
byte *data = (byte *) tex;
|
2012-01-14 10:02:06 +00:00
|
|
|
byte *buffer = 0;
|
|
|
|
byte *scaled;
|
2012-01-07 09:05:54 +00:00
|
|
|
int lod;
|
|
|
|
|
|
|
|
for (swidth = 1; swidth < tex->width; swidth <<= 1);
|
|
|
|
for (sheight = 1; sheight < tex->height; sheight <<= 1);
|
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGenTextures (1, &tnum);
|
|
|
|
qfeglBindTexture (GL_TEXTURE_2D, tnum);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
2012-01-14 10:02:06 +00:00
|
|
|
GL_NEAREST_MIPMAP_NEAREST);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2012-01-07 09:05:54 +00:00
|
|
|
|
2012-01-14 10:02:06 +00:00
|
|
|
if (swidth != tex->width || sheight != tex->height)
|
|
|
|
buffer = malloc (swidth * sheight);
|
|
|
|
|
|
|
|
// preshift so swidth and sheight are the correct sizes end the end of
|
|
|
|
// the loop
|
|
|
|
swidth <<= 1;
|
|
|
|
sheight <<= 1;
|
|
|
|
for (lod = 0; lod < MIPLEVELS; lod++) {
|
|
|
|
// preshift so swidth and sheight are the correct sizes end the end of
|
|
|
|
// the loop
|
|
|
|
swidth >>= 1;
|
|
|
|
sheight >>= 1;
|
|
|
|
swidth = max (swidth, 1);
|
|
|
|
sheight = max (sheight, 1);
|
|
|
|
if (buffer) {
|
|
|
|
unsigned w = tex->width;
|
|
|
|
unsigned h = tex->height;
|
|
|
|
|
|
|
|
w = max (w >> lod, 1);
|
|
|
|
h = max (h >> lod, 1);
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_Resample8BitTexture (data + tex->offsets[lod], w, h,
|
2012-01-14 10:02:06 +00:00
|
|
|
buffer, swidth, sheight);
|
|
|
|
scaled = buffer;
|
|
|
|
} else {
|
|
|
|
scaled = data + tex->offsets[lod];
|
2012-01-07 09:05:54 +00:00
|
|
|
}
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglTexImage2D (GL_TEXTURE_2D, lod, GL_LUMINANCE, swidth, sheight,
|
2012-05-14 14:02:06 +00:00
|
|
|
0, GL_LUMINANCE, GL_UNSIGNED_BYTE, scaled);
|
2012-01-14 10:02:06 +00:00
|
|
|
}
|
|
|
|
if (swidth > 1 || sheight > 1) {
|
|
|
|
// mipmap will hold the reduced image, so this is more than enough
|
|
|
|
byte *mipmap = malloc (swidth * sheight);
|
|
|
|
byte *mip = mipmap;
|
|
|
|
while (swidth > 1 || sheight > 1) {
|
|
|
|
// scaled holds the source of the last lod uploaded
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_Mipmap8BitTexture (scaled, swidth, sheight, mip);
|
2012-01-07 09:05:54 +00:00
|
|
|
swidth >>= 1;
|
|
|
|
sheight >>= 1;
|
|
|
|
swidth = max (swidth, 1);
|
|
|
|
sheight = max (sheight, 1);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglTexImage2D (GL_TEXTURE_2D, lod, GL_LUMINANCE, swidth, sheight,
|
2012-05-14 14:02:06 +00:00
|
|
|
0, GL_LUMINANCE, GL_UNSIGNED_BYTE, mip);
|
2012-01-14 10:02:06 +00:00
|
|
|
scaled = mip;
|
|
|
|
mip += swidth * sheight;
|
|
|
|
lod++;
|
2012-01-07 09:05:54 +00:00
|
|
|
}
|
2012-01-14 10:02:06 +00:00
|
|
|
free (mipmap);
|
2012-01-07 09:05:54 +00:00
|
|
|
}
|
2012-01-14 10:02:06 +00:00
|
|
|
if (buffer)
|
|
|
|
free (buffer);
|
2012-01-07 09:05:54 +00:00
|
|
|
return tnum;
|
|
|
|
}
|
|
|
|
|
2012-01-02 04:15:19 +00:00
|
|
|
int
|
2021-12-13 15:42:22 +00:00
|
|
|
GLSL_LoadRGBTexture (const char *identifier, int width, int height,
|
|
|
|
const byte *data)
|
2012-01-02 04:15:19 +00:00
|
|
|
{
|
|
|
|
GLuint tnum;
|
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGenTextures (1, &tnum);
|
|
|
|
qfeglBindTexture (GL_TEXTURE_2D, tnum);
|
|
|
|
qfeglTexImage2D (GL_TEXTURE_2D, 0, GL_RGB,
|
2012-05-14 14:02:06 +00:00
|
|
|
width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
qfeglGenerateMipmap (GL_TEXTURE_2D);
|
2012-01-02 04:15:19 +00:00
|
|
|
|
|
|
|
return tnum;
|
|
|
|
}
|
|
|
|
|
2012-05-14 14:02:06 +00:00
|
|
|
int
|
2021-12-13 15:42:22 +00:00
|
|
|
GLSL_LoadRGBATexture (const char *identifier, int width, int height,
|
|
|
|
const byte *data)
|
2012-05-14 14:02:06 +00:00
|
|
|
{
|
|
|
|
GLuint tnum;
|
|
|
|
|
|
|
|
qfeglGenTextures (1, &tnum);
|
|
|
|
qfeglBindTexture (GL_TEXTURE_2D, tnum);
|
|
|
|
qfeglTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA,
|
|
|
|
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
qfeglGenerateMipmap (GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
return tnum;
|
|
|
|
}
|
|
|
|
|
2011-12-31 11:36:24 +00:00
|
|
|
void
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_ReleaseTexture (int tex)
|
2011-12-31 11:36:24 +00:00
|
|
|
{
|
|
|
|
GLuint tnum = tex;
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglDeleteTextures (1, &tnum);
|
2011-12-31 11:36:24 +00:00
|
|
|
}
|
2012-01-06 07:24:13 +00:00
|
|
|
|
2012-01-07 06:34:31 +00:00
|
|
|
static void
|
|
|
|
glsl_scraps_f (void)
|
|
|
|
{
|
|
|
|
scrap_t *scrap;
|
|
|
|
int area;
|
2021-01-12 12:10:22 +00:00
|
|
|
int size;
|
2012-01-07 06:34:31 +00:00
|
|
|
|
|
|
|
if (!scrap_list) {
|
|
|
|
Sys_Printf ("No scraps\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (scrap = scrap_list; scrap; scrap = scrap->next) {
|
2021-01-12 12:10:22 +00:00
|
|
|
area = R_ScrapArea (&scrap->rscrap);
|
|
|
|
// always square
|
|
|
|
size = scrap->rscrap.width;
|
2012-01-07 06:34:31 +00:00
|
|
|
Sys_Printf ("tnum=%u size=%d format=%04x bpp=%d free=%d%%\n",
|
2021-01-12 12:10:22 +00:00
|
|
|
scrap->tnum, size, scrap->format, scrap->bpp,
|
|
|
|
area * 100 / (size * size));
|
2012-01-08 16:31:29 +00:00
|
|
|
if (Cmd_Argc () > 1) {
|
2021-01-12 12:10:22 +00:00
|
|
|
R_ScrapDump (&scrap->rscrap);
|
2012-01-08 16:31:29 +00:00
|
|
|
}
|
2012-01-07 06:34:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-06 07:24:13 +00:00
|
|
|
void
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_TextureInit (void)
|
2012-01-06 07:24:13 +00:00
|
|
|
{
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_tex_size);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_glsl, "max texture size: %d\n", max_tex_size);
|
2012-01-07 06:34:31 +00:00
|
|
|
|
|
|
|
Cmd_AddCommand ("glsl_scraps", glsl_scraps_f, "Dump GLSL scrap stats");
|
2012-01-06 07:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
scrap_t *
|
2012-07-03 03:10:24 +00:00
|
|
|
GLSL_CreateScrap (int size, int format, int linear)
|
2012-01-06 07:24:13 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int bpp;
|
|
|
|
scrap_t *scrap;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
if (size <= 1 << i)
|
|
|
|
break;
|
|
|
|
size = 1 << i;
|
|
|
|
size = min (size, max_tex_size);
|
|
|
|
switch (format) {
|
|
|
|
case GL_ALPHA:
|
|
|
|
case GL_LUMINANCE:
|
|
|
|
bpp = 1;
|
|
|
|
break;
|
|
|
|
case GL_LUMINANCE_ALPHA:
|
|
|
|
bpp = 2;
|
|
|
|
break;
|
|
|
|
case GL_RGB:
|
|
|
|
bpp = 3;
|
|
|
|
break;
|
|
|
|
case GL_RGBA:
|
|
|
|
bpp = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Sys_Error ("GL_CreateScrap: Invalid texture format");
|
|
|
|
}
|
|
|
|
scrap = malloc (sizeof (scrap_t));
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGenTextures (1, &scrap->tnum);
|
2021-01-12 12:10:22 +00:00
|
|
|
R_ScrapInit (&scrap->rscrap, size, size);
|
2012-01-06 07:24:13 +00:00
|
|
|
scrap->format = format;
|
|
|
|
scrap->bpp = bpp;
|
2012-01-17 04:00:43 +00:00
|
|
|
scrap->subpics = 0;
|
2012-01-06 07:24:13 +00:00
|
|
|
scrap->next = scrap_list;
|
|
|
|
scrap_list = scrap;
|
|
|
|
|
2012-07-02 11:01:28 +00:00
|
|
|
scrap->data = calloc (1, size * size * bpp);
|
|
|
|
scrap->batch = 0;
|
2012-01-06 07:24:13 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglBindTexture (GL_TEXTURE_2D, scrap->tnum);
|
|
|
|
qfeglTexImage2D (GL_TEXTURE_2D, 0, format,
|
2012-07-02 11:01:28 +00:00
|
|
|
size, size, 0, format, GL_UNSIGNED_BYTE, scrap->data);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2012-07-03 03:10:24 +00:00
|
|
|
if (linear) {
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
} else {
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
}
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGenerateMipmap (GL_TEXTURE_2D);
|
2012-01-06 07:24:13 +00:00
|
|
|
|
|
|
|
return scrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_ScrapClear (scrap_t *scrap)
|
2012-01-06 07:24:13 +00:00
|
|
|
{
|
2012-01-17 04:00:43 +00:00
|
|
|
subpic_t *sp;
|
|
|
|
while (scrap->subpics) {
|
|
|
|
sp = scrap->subpics;
|
|
|
|
scrap->subpics = (subpic_t *) sp->next;
|
|
|
|
free (sp);
|
|
|
|
}
|
2021-01-12 12:10:22 +00:00
|
|
|
R_ScrapClear (&scrap->rscrap);
|
2012-01-17 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_DestroyScrap (scrap_t *scrap)
|
2012-01-17 04:00:43 +00:00
|
|
|
{
|
|
|
|
scrap_t **s;
|
|
|
|
|
|
|
|
for (s = &scrap_list; *s; s = &(*s)->next) {
|
|
|
|
if (*s == scrap) {
|
|
|
|
*s = scrap->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_ScrapClear (scrap);
|
2021-01-12 12:10:22 +00:00
|
|
|
R_ScrapDelete (&scrap->rscrap);
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_ReleaseTexture (scrap->tnum);
|
2012-07-02 11:01:28 +00:00
|
|
|
free (scrap->data);
|
2012-01-06 07:24:13 +00:00
|
|
|
free (scrap);
|
|
|
|
}
|
|
|
|
|
2012-01-09 12:13:40 +00:00
|
|
|
int
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_ScrapTexture (scrap_t *scrap)
|
2012-01-09 12:13:40 +00:00
|
|
|
{
|
|
|
|
return scrap->tnum;
|
|
|
|
}
|
|
|
|
|
2012-01-06 07:24:13 +00:00
|
|
|
subpic_t *
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_ScrapSubpic (scrap_t *scrap, int width, int height)
|
2012-01-06 07:24:13 +00:00
|
|
|
{
|
2021-01-12 12:10:22 +00:00
|
|
|
vrect_t *rect;
|
2012-01-06 07:24:13 +00:00
|
|
|
subpic_t *subpic;
|
|
|
|
|
2021-01-12 12:10:22 +00:00
|
|
|
rect = R_ScrapAlloc (&scrap->rscrap, width, height);
|
|
|
|
if (!rect) {
|
|
|
|
return 0;
|
2012-01-06 07:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
subpic = malloc (sizeof (subpic_t));
|
2012-01-17 04:00:43 +00:00
|
|
|
*((subpic_t **) &subpic->next) = scrap->subpics;
|
|
|
|
scrap->subpics = subpic;
|
2012-01-06 07:24:13 +00:00
|
|
|
*((scrap_t **) &subpic->scrap) = scrap;
|
|
|
|
*((vrect_t **) &subpic->rect) = rect;
|
|
|
|
*((int *) &subpic->width) = width;
|
|
|
|
*((int *) &subpic->height) = height;
|
2021-01-12 12:10:22 +00:00
|
|
|
*((float *) &subpic->size) = 1.0 / scrap->rscrap.width;
|
2012-01-06 07:24:13 +00:00
|
|
|
return subpic;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_SubpicDelete (subpic_t *subpic)
|
2012-01-06 07:24:13 +00:00
|
|
|
{
|
|
|
|
scrap_t *scrap = (scrap_t *) subpic->scrap;
|
|
|
|
vrect_t *rect = (vrect_t *) subpic->rect;
|
2012-01-17 04:00:43 +00:00
|
|
|
subpic_t **sp;
|
2012-01-06 07:24:13 +00:00
|
|
|
|
2012-01-17 04:00:43 +00:00
|
|
|
for (sp = &scrap->subpics; *sp; sp = (subpic_t **) &(*sp)->next)
|
|
|
|
if (*sp == subpic)
|
|
|
|
break;
|
|
|
|
if (*sp != subpic)
|
2012-02-17 09:57:13 +00:00
|
|
|
Sys_Error ("GLSL_ScrapDelSubpic: broken subpic");
|
2012-01-17 04:00:43 +00:00
|
|
|
*sp = (subpic_t *) subpic->next;
|
2012-01-06 07:24:13 +00:00
|
|
|
free (subpic);
|
2021-01-12 12:10:22 +00:00
|
|
|
R_ScrapFree (&scrap->rscrap, rect);
|
2012-01-06 07:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-07-02 11:01:28 +00:00
|
|
|
GLSL_SubpicUpdate (subpic_t *subpic, byte *data, int batch)
|
2012-01-06 07:24:13 +00:00
|
|
|
{
|
|
|
|
scrap_t *scrap = (scrap_t *) subpic->scrap;
|
|
|
|
vrect_t *rect = (vrect_t *) subpic->rect;
|
2012-07-02 11:01:28 +00:00
|
|
|
byte *dest;
|
|
|
|
int step, sbytes;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (batch) {
|
|
|
|
if (scrap->batch) {
|
|
|
|
vrect_t *r = scrap->batch;
|
|
|
|
scrap->batch = VRect_Union (r, rect);
|
|
|
|
VRect_Delete (r);
|
|
|
|
} else {
|
|
|
|
scrap->batch = VRect_New (rect->x, rect->y,
|
|
|
|
rect->width, rect->height);
|
|
|
|
}
|
2021-01-12 12:10:22 +00:00
|
|
|
step = scrap->rscrap.width * scrap->bpp;
|
2012-07-02 11:01:28 +00:00
|
|
|
sbytes = subpic->width * scrap->bpp;
|
|
|
|
dest = scrap->data + rect->y * step + rect->x * scrap->bpp;
|
|
|
|
for (i = 0; i < subpic->height; i++, dest += step, data += sbytes)
|
|
|
|
memcpy (dest, data, sbytes);
|
|
|
|
} else {
|
|
|
|
qfeglBindTexture (GL_TEXTURE_2D, scrap->tnum);
|
|
|
|
qfeglTexSubImage2D (GL_TEXTURE_2D, 0, rect->x, rect->y,
|
|
|
|
subpic->width, subpic->height, scrap->format,
|
|
|
|
GL_UNSIGNED_BYTE, data);
|
|
|
|
}
|
|
|
|
}
|
2012-01-06 07:24:13 +00:00
|
|
|
|
2012-07-02 11:01:28 +00:00
|
|
|
void
|
|
|
|
GLSL_ScrapFlush (scrap_t *scrap)
|
|
|
|
{
|
2021-01-09 11:42:23 +00:00
|
|
|
vrect_t *rect = scrap->batch;
|
2021-01-12 12:10:22 +00:00
|
|
|
int size = scrap->rscrap.width;
|
2012-07-02 11:01:28 +00:00
|
|
|
|
|
|
|
if (!rect)
|
|
|
|
return;
|
|
|
|
//FIXME: it seems gl (as opposed to egl) allows row step to be specified.
|
|
|
|
//should update to not update the entire horizontal block
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglBindTexture (GL_TEXTURE_2D, scrap->tnum);
|
2012-07-02 11:01:28 +00:00
|
|
|
qfeglTexSubImage2D (GL_TEXTURE_2D, 0, 0, rect->y,
|
2021-01-12 12:10:22 +00:00
|
|
|
size, rect->height, scrap->format,
|
2012-07-02 11:01:28 +00:00
|
|
|
GL_UNSIGNED_BYTE,
|
2021-01-12 12:10:22 +00:00
|
|
|
scrap->data + rect->y * size * scrap->bpp);
|
2012-07-02 11:01:28 +00:00
|
|
|
VRect_Delete (rect);
|
|
|
|
scrap->batch = 0;
|
2012-01-06 07:24:13 +00:00
|
|
|
}
|