mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 19:20:46 +00:00
Glue code between internal light source management and the game.
git-svn-id: https://svn.eduke32.com/eduke32@1227 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
6fe53806c7
commit
dec76c4907
3 changed files with 71 additions and 82 deletions
|
@ -502,12 +502,6 @@ _equation equation(float x1, float y1, float x2, float y2);
|
||||||
int32_t sameside(_equation* eq, _point2d* p1, _point2d* p2);
|
int32_t sameside(_equation* eq, _point2d* p1, _point2d* p2);
|
||||||
int32_t wallvisible(int16_t wallnum);
|
int32_t wallvisible(int16_t wallnum);
|
||||||
|
|
||||||
#ifdef POLYMER
|
|
||||||
// polymer stuff for the game to provide it with the animatessprites ptr
|
|
||||||
typedef void (*animatespritesptr)(int32_t, int32_t, int32_t, int32_t);
|
|
||||||
EXTERN void polymer_setanimatesprites(animatespritesptr, int32_t, int32_t, int32_t, int32_t);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define STATUS2DSIZ 144
|
#define STATUS2DSIZ 144
|
||||||
void qsetmode640350(void);
|
void qsetmode640350(void);
|
||||||
void qsetmode640480(void);
|
void qsetmode640480(void);
|
||||||
|
@ -626,6 +620,10 @@ int32_t hash_find(hashtable_t *t, const char *s);
|
||||||
void hash_replace(hashtable_t *t, const char *s, int32_t key);
|
void hash_replace(hashtable_t *t, const char *s, int32_t key);
|
||||||
void hash_add(hashtable_t *t, const char *s, int32_t key);
|
void hash_add(hashtable_t *t, const char *s, int32_t key);
|
||||||
|
|
||||||
|
#ifdef POLYMER
|
||||||
|
# include "polymer.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -162,6 +162,8 @@ typedef struct s_prwall {
|
||||||
char controlstate;
|
char controlstate;
|
||||||
} _prwall;
|
} _prwall;
|
||||||
|
|
||||||
|
typedef void (*animatespritesptr)(int32_t, int32_t, int32_t, int32_t);
|
||||||
|
|
||||||
typedef struct s_pranimatespritesinfo {
|
typedef struct s_pranimatespritesinfo {
|
||||||
animatespritesptr animatesprites;
|
animatespritesptr animatesprites;
|
||||||
int32_t x, y, a, smoothratio;
|
int32_t x, y, a, smoothratio;
|
||||||
|
@ -169,6 +171,9 @@ typedef struct s_pranimatespritesinfo {
|
||||||
|
|
||||||
// LIGHTS
|
// LIGHTS
|
||||||
#define PR_MAXLIGHTS 128
|
#define PR_MAXLIGHTS 128
|
||||||
|
#define PR_SM3_MAXLIGHTS 4
|
||||||
|
#define STR_EXPAND(tok) #tok
|
||||||
|
#define STR(tok) STR_EXPAND(tok)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PR_LIGHT_POINT,
|
PR_LIGHT_POINT,
|
||||||
|
@ -179,6 +184,7 @@ typedef enum {
|
||||||
typedef struct s_prlight {
|
typedef struct s_prlight {
|
||||||
int32_t x, y, z, horiz, faderange, range;
|
int32_t x, y, z, horiz, faderange, range;
|
||||||
int16_t angle, sector;
|
int16_t angle, sector;
|
||||||
|
char color[3];
|
||||||
prlighttype type;
|
prlighttype type;
|
||||||
} _prlight;
|
} _prlight;
|
||||||
|
|
||||||
|
@ -196,6 +202,7 @@ void polymer_drawmasks(void);
|
||||||
void polymer_rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, char dapalnum, char dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2);
|
void polymer_rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, char dapalnum, char dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2);
|
||||||
void polymer_drawmaskwall(int32_t damaskwallcnt);
|
void polymer_drawmaskwall(int32_t damaskwallcnt);
|
||||||
void polymer_drawsprite(int32_t snum);
|
void polymer_drawsprite(int32_t snum);
|
||||||
|
void polymer_setanimatesprites(animatespritesptr animatesprites, int32_t x, int32_t y, int32_t a, int32_t smoothratio);
|
||||||
void polymer_resetlights(void);
|
void polymer_resetlights(void);
|
||||||
void polymer_addlight(_prlight light);
|
void polymer_addlight(_prlight light);
|
||||||
|
|
||||||
|
@ -238,9 +245,11 @@ static void polymer_loadmodelvbos(md3model_t* m);
|
||||||
// MATERIALS
|
// MATERIALS
|
||||||
static void polymer_getscratchmaterial(_prmaterial* material);
|
static void polymer_getscratchmaterial(_prmaterial* material);
|
||||||
static void polymer_getbuildmaterial(_prmaterial* material, int16_t tilenum, char pal, int8_t shade);
|
static void polymer_getbuildmaterial(_prmaterial* material, int16_t tilenum, char pal, int8_t shade);
|
||||||
static int32_t polymer_bindmaterial(_prmaterial material);
|
static int32_t polymer_bindmaterial(_prmaterial material, _prlight* lights, int lightcount);
|
||||||
static void polymer_unbindmaterial(int32_t programbits);
|
static void polymer_unbindmaterial(int32_t programbits);
|
||||||
static void polymer_compileprogram(int32_t programbits);
|
static void polymer_compileprogram(int32_t programbits);
|
||||||
|
// LIGHTS
|
||||||
|
static void polymer_transformlight(float* inpos, float* pos, float* matrix);
|
||||||
|
|
||||||
# endif // !POLYMER_C
|
# endif // !POLYMER_C
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
|
||||||
// vert_prog
|
// vert_prog
|
||||||
"",
|
"",
|
||||||
// frag_def
|
// frag_def
|
||||||
"#define LIGHTCOUNT 4\n"
|
"#define LIGHTCOUNT "STR(PR_SM3_MAXLIGHTS)"\n"
|
||||||
"\n",
|
"\n",
|
||||||
// frag_prog
|
// frag_prog
|
||||||
"",
|
"",
|
||||||
|
@ -1155,7 +1155,7 @@ static void polymer_drawplane(int16_t sectnum, int16_t wallnum, _prplane
|
||||||
|
|
||||||
bglNormal3f((float)(-plane->plane[0]), (float)(-plane->plane[1]), (float)(-plane->plane[2]));
|
bglNormal3f((float)(-plane->plane[0]), (float)(-plane->plane[1]), (float)(-plane->plane[2]));
|
||||||
|
|
||||||
materialbits = polymer_bindmaterial(plane->material);
|
materialbits = polymer_bindmaterial(plane->material, prlights, lightcount);
|
||||||
|
|
||||||
if (plane->vbo && (pr_vbos > 0))
|
if (plane->vbo && (pr_vbos > 0))
|
||||||
{
|
{
|
||||||
|
@ -2505,7 +2505,7 @@ static void polymer_drawmdsprite(spritetype *tspr)
|
||||||
mdspritematerial.nextframedatastride = sizeof(md3xyzn_t);
|
mdspritematerial.nextframedatastride = sizeof(md3xyzn_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
materialbits = polymer_bindmaterial(mdspritematerial);
|
materialbits = polymer_bindmaterial(mdspritematerial, prlights, lightcount);
|
||||||
|
|
||||||
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m->indices[surfi]);
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m->indices[surfi]);
|
||||||
bglDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_INT, 0);
|
bglDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_INT, 0);
|
||||||
|
@ -2526,7 +2526,7 @@ static void polymer_drawmdsprite(spritetype *tspr)
|
||||||
mdspritematerial.nextframedatastride = sizeof(md3xyzn_t);
|
mdspritematerial.nextframedatastride = sizeof(md3xyzn_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
materialbits = polymer_bindmaterial(mdspritematerial);
|
materialbits = polymer_bindmaterial(mdspritematerial, prlights, lightcount);
|
||||||
|
|
||||||
bglDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_INT, s->tris);
|
bglDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_INT, s->tris);
|
||||||
|
|
||||||
|
@ -2671,7 +2671,7 @@ static void polymer_getbuildmaterial(_prmaterial* material, int16_t tile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t polymer_bindmaterial(_prmaterial material)
|
static int32_t polymer_bindmaterial(_prmaterial material, _prlight* lights, int lightcount)
|
||||||
{
|
{
|
||||||
int32_t programbits;
|
int32_t programbits;
|
||||||
int32_t texunit;
|
int32_t texunit;
|
||||||
|
@ -2705,6 +2705,7 @@ static int32_t polymer_bindmaterial(_prmaterial material)
|
||||||
programbits |= prprogrambits[PR_BIT_DIFFUSE_MODULATION].bit;
|
programbits |= prprogrambits[PR_BIT_DIFFUSE_MODULATION].bit;
|
||||||
|
|
||||||
// PR_BIT_POINT_LIGHT
|
// PR_BIT_POINT_LIGHT
|
||||||
|
if (lightcount)
|
||||||
programbits |= prprogrambits[PR_BIT_POINT_LIGHT].bit;
|
programbits |= prprogrambits[PR_BIT_POINT_LIGHT].bit;
|
||||||
|
|
||||||
// PR_BIT_DIFFUSE_GLOW_MAP
|
// PR_BIT_DIFFUSE_GLOW_MAP
|
||||||
|
@ -2769,83 +2770,47 @@ static int32_t polymer_bindmaterial(_prmaterial material)
|
||||||
// PR_BIT_POINT_LIGHT
|
// PR_BIT_POINT_LIGHT
|
||||||
if (programbits & prprogrambits[PR_BIT_POINT_LIGHT].bit)
|
if (programbits & prprogrambits[PR_BIT_POINT_LIGHT].bit)
|
||||||
{
|
{
|
||||||
int lightCount;
|
int i;
|
||||||
float range[4];
|
float inpos[4], pos[4];
|
||||||
float color[8];
|
float range[2];
|
||||||
float pos[6];
|
float color[4];
|
||||||
float lightpos[8];
|
|
||||||
|
|
||||||
lightCount = 2;
|
i = 0;
|
||||||
|
|
||||||
pos[0] = 62208;
|
while (i < ((glinfo.sm4) ? lightcount : PR_SM3_MAXLIGHTS))
|
||||||
pos[1] = 42000 / 16.0;
|
{
|
||||||
pos[2] = -6919;
|
inpos[0] = lights[i].y;
|
||||||
|
inpos[1] = -lights[i].z / 16.0f;
|
||||||
|
inpos[2] = -lights[i].x;
|
||||||
|
|
||||||
lightpos[0] = pos[0] * rootmodelviewmatrix[0] +
|
polymer_transformlight(inpos, pos, rootmodelviewmatrix);
|
||||||
pos[1] * rootmodelviewmatrix[4] +
|
|
||||||
pos[2] * rootmodelviewmatrix[8] +
|
|
||||||
+ rootmodelviewmatrix[12];
|
|
||||||
lightpos[1] = pos[0] * rootmodelviewmatrix[1] +
|
|
||||||
pos[1] * rootmodelviewmatrix[5] +
|
|
||||||
pos[2] * rootmodelviewmatrix[9] +
|
|
||||||
+ rootmodelviewmatrix[13];
|
|
||||||
lightpos[2] = pos[0] * rootmodelviewmatrix[2] +
|
|
||||||
pos[1] * rootmodelviewmatrix[6] +
|
|
||||||
pos[2] * rootmodelviewmatrix[10] +
|
|
||||||
+ rootmodelviewmatrix[14];
|
|
||||||
|
|
||||||
color[0] = 0.1f;
|
range[0] = lights[i].faderange / 1000.0f;
|
||||||
color[1] = 0.1f;
|
range[1] = lights[i].range / 1000.0f;
|
||||||
color[2] = 1.0f;
|
|
||||||
|
|
||||||
range[0] = 1024.0f / 1000.0;
|
color[0] = lights[i].color[0] / 255.0f;
|
||||||
range[1] = 2048.0f / 1000.0;
|
color[1] = lights[i].color[1] / 255.0f;
|
||||||
|
color[2] = lights[i].color[2] / 255.0f;
|
||||||
|
|
||||||
pos[3] = globalposy;
|
bglLightfv(GL_LIGHT0 + i, GL_AMBIENT, pos);
|
||||||
pos[4] = -globalposz / 16.0;
|
bglLightfv(GL_LIGHT0 + i, GL_DIFFUSE, color);
|
||||||
pos[5] = -globalposx;
|
bglLightfv(GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, &range[0]);
|
||||||
|
bglLightfv(GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, &range[1]);
|
||||||
|
|
||||||
lightpos[4] = pos[3] * rootmodelviewmatrix[0] +
|
i++;
|
||||||
pos[4] * rootmodelviewmatrix[4] +
|
}
|
||||||
pos[5] * rootmodelviewmatrix[8] +
|
|
||||||
+ rootmodelviewmatrix[12];
|
|
||||||
lightpos[5] = pos[3] * rootmodelviewmatrix[1] +
|
|
||||||
pos[4] * rootmodelviewmatrix[5] +
|
|
||||||
pos[5] * rootmodelviewmatrix[9] +
|
|
||||||
+ rootmodelviewmatrix[13];
|
|
||||||
lightpos[6] = pos[3] * rootmodelviewmatrix[2] +
|
|
||||||
pos[4] * rootmodelviewmatrix[6] +
|
|
||||||
pos[5] * rootmodelviewmatrix[10] +
|
|
||||||
+ rootmodelviewmatrix[14];
|
|
||||||
|
|
||||||
color[4] = 0.5f;
|
|
||||||
color[5] = 0.5f;
|
|
||||||
color[6] = 0.5f;
|
|
||||||
|
|
||||||
range[2] = 0.0f / 1000.0;
|
|
||||||
range[3] = 2048.0f / 1000.0;
|
|
||||||
|
|
||||||
bglLightfv(GL_LIGHT0, GL_AMBIENT, lightpos);
|
|
||||||
bglLightfv(GL_LIGHT0, GL_DIFFUSE, color);
|
|
||||||
bglLightfv(GL_LIGHT0, GL_CONSTANT_ATTENUATION, &range[0]);
|
|
||||||
bglLightfv(GL_LIGHT0, GL_LINEAR_ATTENUATION, &range[1]);
|
|
||||||
|
|
||||||
bglLightfv(GL_LIGHT1, GL_AMBIENT, &lightpos[4]);
|
|
||||||
bglLightfv(GL_LIGHT1, GL_DIFFUSE, &color[4]);
|
|
||||||
bglLightfv(GL_LIGHT1, GL_CONSTANT_ATTENUATION, &range[2]);
|
|
||||||
bglLightfv(GL_LIGHT1, GL_LINEAR_ATTENUATION, &range[3]);
|
|
||||||
|
|
||||||
range[3] = 0;
|
|
||||||
|
|
||||||
bglLightfv(GL_LIGHT2, GL_LINEAR_ATTENUATION, &range[3]);
|
|
||||||
bglLightfv(GL_LIGHT3, GL_LINEAR_ATTENUATION, &range[3]);
|
|
||||||
bglLightfv(GL_LIGHT4, GL_LINEAR_ATTENUATION, &range[3]);
|
|
||||||
bglLightfv(GL_LIGHT5, GL_LINEAR_ATTENUATION, &range[3]);
|
|
||||||
bglLightfv(GL_LIGHT6, GL_LINEAR_ATTENUATION, &range[3]);
|
|
||||||
bglLightfv(GL_LIGHT7, GL_LINEAR_ATTENUATION, &range[3]);
|
|
||||||
|
|
||||||
if (glinfo.sm4)
|
if (glinfo.sm4)
|
||||||
bglUniform1iARB(prprograms[programbits].uniform_lightCount, lightCount);
|
bglUniform1iARB(prprograms[programbits].uniform_lightCount, lightcount);
|
||||||
|
else {
|
||||||
|
range[0] = 0.0f;
|
||||||
|
|
||||||
|
while (i < PR_SM3_MAXLIGHTS)
|
||||||
|
{
|
||||||
|
bglLightfv(GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, &range[0]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PR_BIT_DIFFUSE_GLOW_MAP
|
// PR_BIT_DIFFUSE_GLOW_MAP
|
||||||
|
@ -2983,4 +2948,21 @@ static void polymer_compileprogram(int32_t programbits)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LIGHTS
|
||||||
|
static void polymer_transformlight(float* inpos, float* pos, float* matrix)
|
||||||
|
{
|
||||||
|
pos[0] = inpos[0] * matrix[0] +
|
||||||
|
inpos[1] * matrix[4] +
|
||||||
|
inpos[2] * matrix[8] +
|
||||||
|
+ matrix[12];
|
||||||
|
pos[1] = inpos[0] * matrix[1] +
|
||||||
|
inpos[1] * matrix[5] +
|
||||||
|
inpos[2] * matrix[9] +
|
||||||
|
+ matrix[13];
|
||||||
|
pos[2] = inpos[0] * matrix[2] +
|
||||||
|
inpos[1] * matrix[6] +
|
||||||
|
inpos[2] * matrix[10] +
|
||||||
|
+ matrix[14];
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue