From 7ba7130f42382c1037be26b6f8a6e660b88f7bd7 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 11 Jan 2012 21:09:57 +0900 Subject: [PATCH] Load the sky texture as two separate textures. The sky texture is normally 256x128, with each 128 wide side being the two layers of the sky. --- include/QF/model.h | 1 + libs/models/brush/glsl_model_brush.c | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/QF/model.h b/include/QF/model.h index e1a04d83c..c5c888b57 100644 --- a/include/QF/model.h +++ b/include/QF/model.h @@ -93,6 +93,7 @@ typedef struct texture_s { unsigned int width, height; int gl_texturenum; int gl_fb_texturenum; + int sky_tex[2]; instsurf_t *tex_chain; // for gl_texsort drawing instsurf_t **tex_chain_tail; struct elechain_s *elechain; diff --git a/libs/models/brush/glsl_model_brush.c b/libs/models/brush/glsl_model_brush.c index cdf495b7e..b97b75b64 100644 --- a/libs/models/brush/glsl_model_brush.c +++ b/libs/models/brush/glsl_model_brush.c @@ -52,6 +52,8 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$"; #include "QF/sys.h" #include "QF/va.h" #include "QF/vid.h" +#include "QF/GLSL/defines.h" +#include "QF/GLSL/funcs.h" #include "QF/GLSL/qf_textures.h" #include "compat.h" @@ -59,7 +61,30 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$"; void Mod_ProcessTexture (texture_t *tx) { - tx->gl_texturenum = GL_LoadQuakeMipTex (tx); + if (!strncmp (tx->name, "sky", 3)) { + // sky textures need to be loaded as two separate textures to allow + // wrapping on both sky layers. + byte *data; + byte *tx_data; + int i, j; + + if (tx->width != 256 || tx->height != 128) + Sys_Error ("Mod_ProcessTexture: invalid sky texture: %dx%d\n", + tx->width, tx->height); + data = alloca (128 * 128); + tx_data = (byte *)tx + tx->offsets[0]; + for (i = 0; i < 2; i++) { + for (j = 0; j < 128; j++) + memcpy (&data[j * 128], &tx_data[j * 256 + i * 128], 128); + tx->sky_tex[i] = GL_LoadQuakeTexture (tx->name, 128, 128, data); + // GL_LoadQuakeTexture () leaves the texture bound + qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + } + tx->gl_texturenum = 0; + } else { + tx->gl_texturenum = GL_LoadQuakeMipTex (tx); + } } void