diff --git a/include/QF/skin.h b/include/QF/skin.h index 9c7ca1fc6..649839c70 100644 --- a/include/QF/skin.h +++ b/include/QF/skin.h @@ -57,7 +57,10 @@ typedef struct skin_s { } skin_t; skin_t *Skin_SetColormap (skin_t *skin, int cmap); +void Skin_SetColormap_ (skin_t *skin, int cmap); void Skin_SetTranslation (int cmap, int top, int bottom); +void Skin_ProcessTranslation (int cmap, const byte *translation); +void Skin_InitTranslations (void); extern byte player_8bit_texels[640 * 400]; extern skin_t skin_cache[MAX_CACHED_SKINS]; diff --git a/libs/models/Makefile.am b/libs/models/Makefile.am index 0e74c6912..43cf30053 100644 --- a/libs/models/Makefile.am +++ b/libs/models/Makefile.am @@ -18,19 +18,19 @@ gl_LIBS= \ alias/libalias_gl.la brush/libbrush_gl.la sprite/libsprite_gl.la libQFmodels_gl_la_LDFLAGS= -version-info $(QUAKE_LIBRARY_VERSION_INFO) -rpath $(libdir) libQFmodels_gl_la_LIBADD= $(gl_LIBS) $(top_builddir)/libs/util/libQFutil.la -libQFmodels_gl_la_SOURCES= $(models_sources) gl_model_fullbright.c +libQFmodels_gl_la_SOURCES= $(models_sources) gl_model_fullbright.c gl_skin.c libQFmodels_gl_la_DEPENDENCIES= $(gl_LIBS) glsl_LIBS= \ alias/libalias_glsl.la brush/libbrush_glsl.la sprite/libsprite_glsl.la libQFmodels_glsl_la_LDFLAGS= -version-info $(QUAKE_LIBRARY_VERSION_INFO) -rpath $(libdir) libQFmodels_glsl_la_LIBADD= $(glsl_LIBS) $(top_builddir)/libs/util/libQFutil.la -libQFmodels_glsl_la_SOURCES= $(models_sources) gl_model_fullbright.c +libQFmodels_glsl_la_SOURCES= $(models_sources) glsl_skin.c libQFmodels_glsl_la_DEPENDENCIES= $(glsl_LIBS) sw_LIBS= \ alias/libalias_sw.la brush/libbrush_sw.la sprite/libsprite_sw.la libQFmodels_sw_la_LDFLAGS= -version-info $(QUAKE_LIBRARY_VERSION_INFO) -rpath $(libdir) -no-undefined libQFmodels_sw_la_LIBADD= $(sw_LIBS) $(top_builddir)/libs/util/libQFutil.la -libQFmodels_sw_la_SOURCES= $(models_sources) +libQFmodels_sw_la_SOURCES= $(models_sources) sw_skin.c libQFmodels_sw_la_DEPENDENCIES= $(sw_LIBS) diff --git a/libs/models/gl_skin.c b/libs/models/gl_skin.c new file mode 100644 index 000000000..e05f254d1 --- /dev/null +++ b/libs/models/gl_skin.c @@ -0,0 +1,70 @@ +/* + glsl_skin.c + + GLSL Skin support + + Copyright (C) 2012 Bill Currie + + Author: Bill Currie + Date: 2012/1/23 + + 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 + +static __attribute__ ((used)) const char rcsid[] = "$Id$"; + +#ifdef HAVE_STRING_H +# include "string.h" +#endif +#ifdef HAVE_STRINGS_H +# include "strings.h" +#endif + +#include + +#include "QF/image.h" +#include "QF/model.h" +#include "QF/skin.h" +#include "QF/sys.h" + +#include "QF/GL/defines.h" +#include "QF/GL/funcs.h" + +// if more than 32 clients are to be supported, then this will need to be +// updated +#define MAX_TRANSLATIONS 32 + +void +Skin_ProcessTranslation (int cmap, const byte *translation) +{ +} + +void +Skin_SetColormap_ (skin_t *skin, int cmap) +{ +} + +void +Skin_InitTranslations (void) +{ +} diff --git a/libs/models/glsl_skin.c b/libs/models/glsl_skin.c new file mode 100644 index 000000000..001e11842 --- /dev/null +++ b/libs/models/glsl_skin.c @@ -0,0 +1,128 @@ +/* + glsl_skin.c + + GLSL Skin support + + Copyright (C) 2012 Bill Currie + + Author: Bill Currie + Date: 2012/1/23 + + 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 + +static __attribute__ ((used)) const char rcsid[] = "$Id$"; + +#ifdef HAVE_STRING_H +# include "string.h" +#endif +#ifdef HAVE_STRINGS_H +# include "strings.h" +#endif + +#include + +#include "QF/image.h" +#include "QF/model.h" +#include "QF/skin.h" +#include "QF/sys.h" + +#include "QF/GLSL/defines.h" +#include "QF/GLSL/funcs.h" + +// if more than 32 clients are to be supported, then this will need to be +// updated +#define MAX_TRANSLATIONS 32 +static GLuint cmap_tex[MAX_TRANSLATIONS]; + +void +Skin_ProcessTranslation (int cmap, const byte *translation) +{ + byte top[4 * VID_GRADES * 16]; + byte bottom[4 * VID_GRADES * 16]; + const byte *src; + byte *dst; + int i, j; + + src = translation + TOP_RANGE; + for (i = 0, dst = top; i < VID_GRADES; i++, src += 256 - 16) { + for (j = 0; j < 16; j++) { + byte c = *src++; + byte *in = vid.palette + c * 3; + *dst++ = *in++; + *dst++ = *in++; + *dst++ = *in++; + *dst++ = 255; // alpha = 1 + } + } + src = translation + BOTTOM_RANGE; + for (i = 0, dst = bottom; i < VID_GRADES; i++, src += 256 - 16) { + for (j = 0; j < 16; j++) { + byte c = *src++; + byte *in = vid.palette + c * 3; + *dst++ = *in++; + *dst++ = *in++; + *dst++ = *in++; + *dst++ = 255; // alpha = 1 + } + } + qfglBindTexture (GL_TEXTURE_2D, cmap_tex[cmap - 1]); + qfglTexSubImage2D (GL_TEXTURE_2D, 0, TOP_RANGE, 0, 16, VID_GRADES, + GL_RGBA, GL_UNSIGNED_BYTE, top); + qfglTexSubImage2D (GL_TEXTURE_2D, 0, BOTTOM_RANGE, 0, 16, VID_GRADES, + GL_RGBA, GL_UNSIGNED_BYTE, bottom); +} + +void +Skin_SetColormap_ (skin_t *skin, int cmap) +{ + if (cmap) + skin->auxtex = cmap_tex[cmap - 1]; +} + +void +Skin_InitTranslations (void) +{ + byte map[4 * VID_GRADES * 256]; + byte *src, *dst; + int i; + + for (i = 0, dst = map, src = vid.colormap8; i < 256 * VID_GRADES; i++) { + byte c = *src++; + byte *in = vid.palette + c * 3; + *dst++ = *in++; + *dst++ = *in++; + *dst++ = *in++; + *dst++ = 255; // alpha = 1 + } + qfglGenTextures (MAX_TRANSLATIONS, cmap_tex); + for (i = 0; i < MAX_TRANSLATIONS; i++) { + qfglBindTexture (GL_TEXTURE_2D, cmap_tex[i]); + qfglTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 256, VID_GRADES, 0, + GL_RGBA, GL_UNSIGNED_BYTE, map); + qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } +} diff --git a/libs/models/skin.c b/libs/models/skin.c index 35cca1b32..7198c1eb3 100644 --- a/libs/models/skin.c +++ b/libs/models/skin.c @@ -94,6 +94,7 @@ Skin_SetTranslation (int cmap, int top, int bottom) for (j = 0; j < 16; j++) dest[BOTTOM_RANGE + j] = source[bottom + 15 - j]; } + Skin_ProcessTranslation (cmap, translations[cmap - 1]); } skin_t * @@ -102,9 +103,18 @@ Skin_SetColormap (skin_t *skin, int cmap) if (!skin) skin = new_skin (); skin->colormap = 0; - if (cmap < 0 || cmap > MAX_TRANSLATIONS) + if (cmap < 0 || cmap > MAX_TRANSLATIONS) { Sys_MaskPrintf (SYS_SKIN, "invalid skin slot: %d\n", cmap); - if (cmap > 0 && cmap <= MAX_TRANSLATIONS) + cmap = 0; + } + if (cmap) skin->colormap = translations[cmap - 1]; + Skin_SetColormap_ (skin, cmap); return skin; } + +void +Skin_Init (void) +{ + Skin_InitTranslations (); +} diff --git a/libs/models/sw_skin.c b/libs/models/sw_skin.c new file mode 100644 index 000000000..f0f1d52d8 --- /dev/null +++ b/libs/models/sw_skin.c @@ -0,0 +1,51 @@ +/* + sw_skin.c + + SW Skin support + + Copyright (C) 2012 Bill Currie + + Author: Bill Currie + Date: 2012/1/23 + + 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 + +static __attribute__ ((used)) const char rcsid[] = "$Id$"; + +#include "QF/skin.h" + +void +Skin_ProcessTranslation (int cmap, const byte *translation) +{ +} + +void +Skin_SetColormap_ (skin_t *skin, int cmap) +{ +} + +void +Skin_InitTranslations (void) +{ +} diff --git a/libs/video/renderer/glsl/glsl_alias.c b/libs/video/renderer/glsl/glsl_alias.c index 139ed57d9..b054892b4 100644 --- a/libs/video/renderer/glsl/glsl_alias.c +++ b/libs/video/renderer/glsl/glsl_alias.c @@ -203,6 +203,7 @@ R_DrawAlias (void) vec_t norm_mat[9]; mat4_t mvp_mat; int skin_tex; + int colormap; aliasvrt_t *pose1 = 0; // VBO's are null based aliasvrt_t *pose2 = 0; // VBO's are null based @@ -226,7 +227,10 @@ R_DrawAlias (void) Mat4Mult (ent->transform, mvp_mat, mvp_mat); Mat4Mult (alias_vp, mvp_mat, mvp_mat); - if (ent->skin) { + colormap = glsl_colormap; + if (ent->skin && ent->skin->auxtex) + colormap = ent->skin->auxtex; + if (ent->skin && ent->skin->texnum) { skin_t *skin = ent->skin; skin_tex = skin->texnum; } else { @@ -242,6 +246,9 @@ R_DrawAlias (void) skin_size[0] = hdr->mdl.skinwidth; skin_size[1] = hdr->mdl.skinheight; + qfglActiveTexture (GL_TEXTURE0 + 1); + qfglBindTexture (GL_TEXTURE_2D, colormap); + qfglActiveTexture (GL_TEXTURE0 + 0); qfglBindTexture (GL_TEXTURE_2D, skin_tex); #ifndef TETRAHEDRON @@ -297,7 +304,6 @@ R_AliasBegin (void) qfglUniform1i (quake_mdl.colormap.location, 1); qfglActiveTexture (GL_TEXTURE0 + 1); qfglEnable (GL_TEXTURE_2D); - qfglBindTexture (GL_TEXTURE_2D, glsl_colormap); qfglUniform1i (quake_mdl.skin.location, 0); qfglActiveTexture (GL_TEXTURE0 + 0); diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index dfefb4762..12d1e9314 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -403,7 +403,8 @@ CL_ClearState (void) memset (&cl, 0, sizeof (cl)); r_force_fullscreen = 0; - // Note: we should probably hack around this and give diff values for diff gamedirs + // Note: we should probably hack around this and give diff values for + // diff gamedirs cl.fpd = FPD_DEFAULT; cl.fbskins = FBSKINS_DEFAULT; diff --git a/qw/source/cl_parse.c b/qw/source/cl_parse.c index cbf2db58f..1b7ccbcf2 100644 --- a/qw/source/cl_parse.c +++ b/qw/source/cl_parse.c @@ -1097,7 +1097,8 @@ CL_ProcessUserInfo (int slot, player_info_t *player) s = Info_ValueForKey (player->userinfo, "name"); if (!*s && player->userid) - Info_SetValueForKey (player->userinfo, "name", va ("user-%i [exploit]", player->userid), 1); + Info_SetValueForKey (player->userinfo, "name", + va ("user-%i [exploit]", player->userid), 1); strncpy (player->name, Info_ValueForKey (player->userinfo, "name"), sizeof (player->name) - 1); player->_topcolor = player->_bottomcolor = -1; diff --git a/qw/source/cl_skin.c b/qw/source/cl_skin.c index ebb9295f8..8f6d9d317 100644 --- a/qw/source/cl_skin.c +++ b/qw/source/cl_skin.c @@ -42,6 +42,7 @@ static __attribute__ ((used)) const char rcsid[] = #include "QF/cvar.h" #include "QF/msg.h" #include "QF/screen.h" +#include "QF/skin.h" #include "QF/sys.h" #include "QF/va.h" @@ -192,7 +193,7 @@ skin_f (cvar_t *var) void CL_Skin_Init (void) { - //Skin_Init (); + Skin_Init (); //Skin_Init_Cvars (); Cmd_AddCommand ("skins", CL_Skins_f, "Download all skins that are " "currently in use");