mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
Finally, load textures for iqm :)
This commit is contained in:
parent
a032aa5adf
commit
1375c3cf03
13 changed files with 139 additions and 10 deletions
|
@ -32,6 +32,13 @@
|
|||
|
||||
#include "QF/iqm.h"
|
||||
|
||||
typedef struct glsliqm_s {
|
||||
GLuint *textures;
|
||||
GLuint *normmaps;
|
||||
GLuint vertex_array;
|
||||
GLuint element_array;
|
||||
} glsliqm_t;
|
||||
|
||||
void glsl_R_InitIQM (void);
|
||||
void glsl_R_DrawIQM (void);
|
||||
void glsl_R_IQMBegin (void);
|
||||
|
|
|
@ -47,6 +47,8 @@ struct texture_s;
|
|||
int GLSL_LoadQuakeMipTex (const struct texture_s *tex);
|
||||
int GLSL_LoadRGBTexture (const char *identifier, int width, int height,
|
||||
byte *data);
|
||||
int GLSL_LoadRGBATexture (const char *identifier, int width, int height,
|
||||
byte *data);
|
||||
void GLSL_ReleaseTexture (int tex);
|
||||
void GLSL_TextureInit (void);
|
||||
|
||||
|
|
|
@ -139,6 +139,7 @@ typedef struct {
|
|||
iqmframe_t **frames;
|
||||
int num_anims;
|
||||
iqmanim *anims;
|
||||
void *extra_data;
|
||||
} iqm_t;
|
||||
|
||||
#endif//__QF_iqm_h__
|
||||
|
|
|
@ -93,7 +93,8 @@ typedef struct vid_model_funcs_s {
|
|||
void *(*Mod_LoadSkin) (byte *skin, int skinsize, int snum, int gnum,
|
||||
qboolean group, maliasskindesc_t *skindesc);
|
||||
void (*Mod_FinalizeAliasModel) (model_t *m, aliashdr_t *hdr);
|
||||
void (*Mod_LoadExternalSkins) (model_t * mod);
|
||||
void (*Mod_LoadExternalSkins) (model_t *mod);
|
||||
void (*Mod_IQMFinish) (model_t *mod);
|
||||
int alias_cache;
|
||||
void (*Mod_SpriteLoadTexture) (mspriteframe_t *pspriteframe, int framenum);
|
||||
|
||||
|
|
|
@ -12,21 +12,24 @@ void gl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
|
|||
void *gl_Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum,
|
||||
qboolean group, maliasskindesc_t *skindesc);
|
||||
void gl_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr);
|
||||
void gl_Mod_LoadExternalSkins (model_t * mod);
|
||||
void gl_Mod_LoadExternalSkins (model_t *mod);
|
||||
void gl_Mod_IQMFinish (model_t *mod);
|
||||
|
||||
void glsl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr,
|
||||
void *_m, int _s, int extra);
|
||||
void *glsl_Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum,
|
||||
qboolean group, maliasskindesc_t *skindesc);
|
||||
void glsl_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr);
|
||||
void glsl_Mod_LoadExternalSkins (model_t * mod);
|
||||
void glsl_Mod_LoadExternalSkins (model_t *mod);
|
||||
void glsl_Mod_IQMFinish (model_t *mod);
|
||||
|
||||
void sw_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
|
||||
int _s, int extra);
|
||||
void *sw_Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum,
|
||||
qboolean group, maliasskindesc_t *skindesc);
|
||||
void sw_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr);
|
||||
void sw_Mod_LoadExternalSkins (model_t * mod);
|
||||
void sw_Mod_LoadExternalSkins (model_t *mod);
|
||||
void sw_Mod_IQMFinish (model_t *mod);
|
||||
|
||||
void gl_Mod_LoadExternalTextures (model_t *mod);
|
||||
void gl_Mod_LoadLighting (bsp_t *bsp);
|
||||
|
|
|
@ -40,12 +40,91 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "QF/dstring.h"
|
||||
#include "QF/image.h"
|
||||
#include "QF/quakefs.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "QF/GLSL/defines.h"
|
||||
#include "QF/GLSL/funcs.h"
|
||||
//#include "QF/GLSL/qf_iqm.h"
|
||||
#include "QF/GLSL/qf_iqm.h"
|
||||
#include "QF/GLSL/qf_textures.h"
|
||||
|
||||
#include "mod_internal.h"
|
||||
#include "r_shared.h"
|
||||
|
||||
static byte null_texture[] = {
|
||||
204, 204, 204, 255,
|
||||
204, 204, 204, 255,
|
||||
204, 204, 204, 255,
|
||||
204, 204, 204, 255,
|
||||
};
|
||||
|
||||
static byte null_normmap[] = {
|
||||
127, 127, 255, 255,
|
||||
127, 127, 255, 255,
|
||||
127, 127, 255, 255,
|
||||
127, 127, 255, 255,
|
||||
};
|
||||
|
||||
static void
|
||||
glsl_iqm_clear (model_t *mod)
|
||||
{
|
||||
iqm_t *iqm = (iqm_t *) mod->aliashdr;
|
||||
glsliqm_t *glsl = (glsliqm_t *) iqm->extra_data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < iqm->num_meshes; i++) {
|
||||
GLSL_ReleaseTexture (glsl->textures[i]);
|
||||
GLSL_ReleaseTexture (glsl->normmaps[i]);
|
||||
}
|
||||
free (glsl);
|
||||
free (iqm->text);
|
||||
free (iqm->vertices);
|
||||
free (iqm->vertexarrays);
|
||||
free (iqm->elements);
|
||||
free (iqm->meshes);
|
||||
free (iqm->joints);
|
||||
free (iqm->baseframe);
|
||||
free (iqm->inverse_baseframe);
|
||||
free (iqm->anims);
|
||||
free (iqm->frames[0]);
|
||||
free (iqm->frames);
|
||||
free (iqm);
|
||||
}
|
||||
|
||||
static void
|
||||
glsl_iqm_load_textures (iqm_t *iqm)
|
||||
{
|
||||
glsliqm_t *glsl = (glsliqm_t *) iqm->extra_data;
|
||||
int i;
|
||||
dstring_t *str = dstring_new ();
|
||||
tex_t *tex;
|
||||
|
||||
glsl->textures = malloc (2 * iqm->num_meshes * sizeof (GLuint));
|
||||
glsl->normmaps = &glsl->textures[iqm->num_meshes];
|
||||
for (i = 0; i < iqm->num_meshes; i++) {
|
||||
dstring_copystr (str, iqm->text + iqm->meshes[i].material);
|
||||
QFS_StripExtension (str->str, str->str);
|
||||
if ((tex = LoadImage (va ("textures/%s", str->str))))
|
||||
glsl->textures[i] = GLSL_LoadRGBATexture (str->str, tex->width,
|
||||
tex->height, tex->data);
|
||||
else
|
||||
glsl->textures[i] = GLSL_LoadRGBATexture ("", 2, 2, null_texture);
|
||||
if ((tex = LoadImage (va ("textures/%s_norm", str->str))))
|
||||
glsl->normmaps[i] = GLSL_LoadRGBATexture (str->str, tex->width,
|
||||
tex->height, tex->data);
|
||||
else
|
||||
glsl->normmaps[i] = GLSL_LoadRGBATexture ("", 2, 2, null_normmap);
|
||||
}
|
||||
dstring_delete (str);
|
||||
}
|
||||
|
||||
void
|
||||
glsl_Mod_IQMFinish (model_t *mod)
|
||||
{
|
||||
iqm_t *iqm = (iqm_t *) mod->aliashdr;
|
||||
mod->clear = glsl_iqm_clear;
|
||||
iqm->extra_data = calloc (1, sizeof (glsliqm_t));
|
||||
glsl_iqm_load_textures (iqm);
|
||||
}
|
||||
|
|
|
@ -519,4 +519,5 @@ Mod_LoadIQM (model_t *mod, void *buffer)
|
|||
Sys_Error ("%s: error loading meshes", loadname);
|
||||
if (hdr->num_anims && !load_iqm_anims (mod, hdr, (byte *) buffer))
|
||||
Sys_Error ("%s: error loading anims", loadname);
|
||||
m_funcs->Mod_IQMFinish (mod);
|
||||
}
|
||||
|
|
|
@ -195,6 +195,7 @@ glsl_R_DrawIQM (void)
|
|||
entity_t *ent = currententity;
|
||||
model_t *model = ent->model;
|
||||
iqm_t *iqm = (iqm_t *) model->aliashdr;
|
||||
glsliqm_t *glsl = (glsliqm_t *) iqm->extra_data;
|
||||
dlight_t *lights[MAX_IQM_LIGHTS];
|
||||
int i;
|
||||
vec_t norm_mat[9];
|
||||
|
@ -256,6 +257,10 @@ glsl_R_DrawIQM (void)
|
|||
qfeglVertexAttrib4fv (iqm_shader.vcolor.location, color);
|
||||
set_arrays (iqm);
|
||||
for (i = 0; i < iqm->num_meshes; i++) {
|
||||
qfeglActiveTexture (GL_TEXTURE0 + 0);
|
||||
qfeglBindTexture (GL_TEXTURE_2D, glsl->textures[i]);
|
||||
qfeglActiveTexture (GL_TEXTURE0 + 1);
|
||||
qfeglBindTexture (GL_TEXTURE_2D, glsl->normmaps[i]);
|
||||
qfeglDrawElements (GL_TRIANGLES, 3 * iqm->meshes[i].num_triangles,
|
||||
GL_UNSIGNED_SHORT,
|
||||
iqm->elements + 3 * iqm->meshes[i].first_triangle);
|
||||
|
@ -276,6 +281,14 @@ glsl_R_IQMBegin (void)
|
|||
VectorCopy (glsl_Fog_GetColor (), fog);
|
||||
fog[3] = glsl_Fog_GetDensity () / 64.0;
|
||||
qfeglUniform4fv (iqm_shader.fog.location, 1, fog);
|
||||
|
||||
qfeglUniform1i (iqm_shader.texture.location, 0);
|
||||
qfeglActiveTexture (GL_TEXTURE0 + 0);
|
||||
qfeglEnable (GL_TEXTURE_2D);
|
||||
|
||||
qfeglUniform1i (iqm_shader.normalmap.location, 1);
|
||||
qfeglActiveTexture (GL_TEXTURE0 + 1);
|
||||
qfeglEnable (GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -75,7 +75,7 @@ GLSL_LoadQuakeTexture (const char *identifier, int width, int height,
|
|||
qfeglGenTextures (1, &tnum);
|
||||
qfeglBindTexture (GL_TEXTURE_2D, tnum);
|
||||
qfeglTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE,
|
||||
width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
|
||||
width, height, 0, GL_LUMINANCE, 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_NEAREST);
|
||||
|
@ -173,7 +173,7 @@ GLSL_LoadQuakeMipTex (const texture_t *tex)
|
|||
scaled = data + tex->offsets[lod];
|
||||
}
|
||||
qfeglTexImage2D (GL_TEXTURE_2D, lod, GL_LUMINANCE, swidth, sheight,
|
||||
0, GL_LUMINANCE, GL_UNSIGNED_BYTE, scaled);
|
||||
0, GL_LUMINANCE, GL_UNSIGNED_BYTE, scaled);
|
||||
}
|
||||
if (swidth > 1 || sheight > 1) {
|
||||
// mipmap will hold the reduced image, so this is more than enough
|
||||
|
@ -187,7 +187,7 @@ GLSL_LoadQuakeMipTex (const texture_t *tex)
|
|||
swidth = max (swidth, 1);
|
||||
sheight = max (sheight, 1);
|
||||
qfeglTexImage2D (GL_TEXTURE_2D, lod, GL_LUMINANCE, swidth, sheight,
|
||||
0, GL_LUMINANCE, GL_UNSIGNED_BYTE, mip);
|
||||
0, GL_LUMINANCE, GL_UNSIGNED_BYTE, mip);
|
||||
scaled = mip;
|
||||
mip += swidth * sheight;
|
||||
lod++;
|
||||
|
@ -207,7 +207,7 @@ GLSL_LoadRGBTexture (const char *identifier, int width, int height, byte *data)
|
|||
qfeglGenTextures (1, &tnum);
|
||||
qfeglBindTexture (GL_TEXTURE_2D, tnum);
|
||||
qfeglTexImage2D (GL_TEXTURE_2D, 0, GL_RGB,
|
||||
width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
width, height, 0, GL_RGB, 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_NEAREST);
|
||||
|
@ -217,6 +217,24 @@ GLSL_LoadRGBTexture (const char *identifier, int width, int height, byte *data)
|
|||
return tnum;
|
||||
}
|
||||
|
||||
int
|
||||
GLSL_LoadRGBATexture (const char *identifier, int width, int height, byte *data)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
void
|
||||
GLSL_ReleaseTexture (int tex)
|
||||
{
|
||||
|
@ -303,7 +321,7 @@ GLSL_CreateScrap (int size, int format)
|
|||
|
||||
qfeglBindTexture (GL_TEXTURE_2D, scrap->tnum);
|
||||
qfeglTexImage2D (GL_TEXTURE_2D, 0, format,
|
||||
size, size, 0, format, GL_UNSIGNED_BYTE, data);
|
||||
size, size, 0, format, 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);
|
||||
//FIXME parameterize (linear for lightmaps)
|
||||
|
|
|
@ -55,6 +55,7 @@ static vid_model_funcs_t model_funcs = {
|
|||
gl_Mod_LoadSkin,
|
||||
gl_Mod_FinalizeAliasModel,
|
||||
gl_Mod_LoadExternalSkins,
|
||||
0,
|
||||
1,
|
||||
gl_Mod_SpriteLoadTexture,
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ static vid_model_funcs_t model_funcs = {
|
|||
glsl_Mod_LoadSkin,
|
||||
glsl_Mod_FinalizeAliasModel,
|
||||
glsl_Mod_LoadExternalSkins,
|
||||
glsl_Mod_IQMFinish,
|
||||
0,
|
||||
glsl_Mod_SpriteLoadTexture,
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ static vid_model_funcs_t model_funcs = {
|
|||
sw_Mod_LoadSkin,
|
||||
sw_Mod_FinalizeAliasModel,
|
||||
sw_Mod_LoadExternalSkins,
|
||||
0,
|
||||
1,
|
||||
sw_Mod_SpriteLoadTexture,
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ static vid_model_funcs_t model_funcs = {
|
|||
sw_Mod_LoadSkin,
|
||||
sw_Mod_FinalizeAliasModel,
|
||||
sw_Mod_LoadExternalSkins,
|
||||
0,
|
||||
1,
|
||||
sw_Mod_SpriteLoadTexture,
|
||||
|
||||
|
|
Loading…
Reference in a new issue