Subversion Repositories eduke32

Rev

Rev 5056 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4747 terminx 1
#ifndef polymost_h_
2
# define polymost_h_
1173 terminx 3
 
1820 terminx 4
#ifdef USE_OPENGL
1173 terminx 5
 
4317 hendricks2 6
#include "glbuild.h"
1488 terminx 7
#include "hightile.h"
4764 helixhorne 8
#include "baselayer.h"  // glinfo
1488 terminx 9
 
4768 hendricks2 10
#ifdef __cplusplus
11
extern "C" {
12
#endif
13
 
4636 terminx 14
typedef struct { uint8_t r, g, b, a; } coltype;
1173 terminx 15
 
1205 terminx 16
extern int32_t rendmode;
1173 terminx 17
extern float gtang;
18
extern float glox1, gloy1;
4605 terminx 19
extern float gxyaspect, grhalfxdown10x;
20
extern float gcosang, gsinang, gcosang2, gsinang2;
21
extern float gchang, gshang, gctang, gstang, gvisibility;
1173 terminx 22
 
23
struct glfiltermodes {
1799 helixhorne 24
        const char *name;
1205 terminx 25
        int32_t min,mag;
1173 terminx 26
};
3041 helixhorne 27
#define NUMGLFILTERMODES 6
28
extern struct glfiltermodes glfiltermodes[NUMGLFILTERMODES];
1173 terminx 29
 
2248 helixhorne 30
//void phex(char v, char *s);
5075 terminx 31
void uploadtexture(int32_t doalloc, vec2_t siz, int32_t intexfmt, int32_t texfmt, coltype *pic, vec2_t tsiz, int32_t dameth);
1205 terminx 32
void polymost_drawsprite(int32_t snum);
33
void polymost_drawmaskwall(int32_t damaskwallcnt);
34
void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum,
3609 hendricks2 35
                             int8_t dashade, char dapalnum, int32_t dastat, uint8_t daalpha, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2, int32_t uniqid);
1205 terminx 36
void polymost_fillpolygon(int32_t npoints);
1173 terminx 37
void polymost_initosdfuncs(void);
38
void polymost_drawrooms(void);
39
 
40
void polymost_glinit(void);
41
void polymost_glreset(void);
42
 
3765 terminx 43
enum {
44
    INVALIDATE_ALL,
45
    INVALIDATE_ART
46
};
47
 
1205 terminx 48
void gltexinvalidate(int32_t dapicnum, int32_t dapalnum, int32_t dameth);
3765 terminx 49
void gltexinvalidatetype(int32_t type);
1644 helixhorne 50
int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize);
1173 terminx 51
 
1221 terminx 52
extern float curpolygonoffset;
53
 
1173 terminx 54
extern float shadescale;
1848 helixhorne 55
extern int32_t shadescale_unbounded;
5075 terminx 56
extern uint8_t alphahackarray[MAXTILES];
1173 terminx 57
 
1943 helixhorne 58
extern int32_t r_usenewshading;
3761 terminx 59
extern int32_t r_usetileshades;
4498 helixhorne 60
extern int32_t r_npotwallmode;
1943 helixhorne 61
 
3763 terminx 62
extern int16_t globalpicnum;
63
extern int32_t globalpal;
64
 
4407 helixhorne 65
// Compare with polymer_eligible_for_artmap()
5075 terminx 66
static inline int32_t eligible_for_tileshades(int32_t const picnum, int32_t const pal)
4406 helixhorne 67
{
4605 terminx 68
    return (!usehightile || !hicfindsubst(picnum, pal)) &&
4406 helixhorne 69
        (!usemodels || md_tilehasmodel(picnum, pal) < 0);
70
}
71
 
5075 terminx 72
static inline float getshadefactor(int32_t const shade)
3286 helixhorne 73
{
5075 terminx 74
    int32_t const shadebound = (shadescale_unbounded || shade>=numshades) ? numshades : numshades-1;
75
    float const clamped_shade = min(max(shade*shadescale, 0), shadebound);
4395 helixhorne 76
 
77
    // 8-bit tiles, i.e. non-hightiles and non-models, don't get additional
78
    // glColor() shading with r_usetileshades!
3784 terminx 79
    if (getrendermode() == REND_POLYMOST && r_usetileshades &&
5056 hendricks2 80
            !(globalflags & GLOBAL_NO_GL_TILESHADES) &&
4406 helixhorne 81
            eligible_for_tileshades(globalpicnum, globalpal))
4395 helixhorne 82
        return 1.f;
83
 
3286 helixhorne 84
    return ((float)(numshades-clamped_shade))/(float)numshades;
85
}
86
 
4416 helixhorne 87
#define POLYMOST_CHOOSE_FOG_PAL(fogpal, pal) \
88
    ((fogpal) ? (fogpal) : (pal))
5075 terminx 89
static inline int32_t get_floor_fogpal(tsectortype const * const sec)
4415 helixhorne 90
{
4416 helixhorne 91
    return POLYMOST_CHOOSE_FOG_PAL(sec->fogpal, sec->floorpal);
4415 helixhorne 92
}
5075 terminx 93
static inline int32_t get_ceiling_fogpal(tsectortype const * const sec)
4415 helixhorne 94
{
4416 helixhorne 95
    return POLYMOST_CHOOSE_FOG_PAL(sec->fogpal, sec->ceilingpal);
4415 helixhorne 96
}
5075 terminx 97
static inline int32_t fogpal_shade(tsectortype const * const sec, int32_t const shade)
4460 helixhorne 98
{
99
    // When fogging is due to sector[].fogpal, don't make the fog parameters
100
    // depend on the shade of the object.
101
    return sec->fogpal ? 0 : shade;
102
}
4415 helixhorne 103
 
5075 terminx 104
static inline int check_nonpow2(int32_t const x)
4488 helixhorne 105
{
4498 helixhorne 106
    return (x > 1 && (x&(x-1)));
4488 helixhorne 107
}
108
 
4498 helixhorne 109
// Are we using the mode that uploads non-power-of-two wall textures like they
110
// render in classic?
111
static inline int polymost_is_npotmode(void)
112
{
113
    // The glinfo.texnpot check is so we don't have to deal with that case in
114
    // gloadtile_art().
115
    return glinfo.texnpot &&
116
        // r_npotwallmode is NYI for hightiles. We require r_hightile off
117
        // because in calc_ypanning(), the repeat would be multiplied by a
118
        // factor even if no modified texture were loaded.
119
        !usehightile &&
120
#ifdef NEW_MAP_FORMAT
121
        g_loadedMapVersion < 10 &&
122
#endif
123
        r_npotwallmode;
124
}
125
 
5075 terminx 126
static inline float polymost_invsqrt_approximation(float x)
4636 terminx 127
{
128
#ifdef B_LITTLE_ENDIAN
5075 terminx 129
    float const haf = x * .5f;
4636 terminx 130
    struct conv { union { uint32_t i; float f; } u; } * const n = (struct conv *)&x;
5075 terminx 131
    n->u.i = 0x5f3759df - (n->u.i >> 1);
132
    return n->u.f * (1.5f - haf * (n->u.f * n->u.f));
4636 terminx 133
#else
134
    // this is the comment
5075 terminx 135
    return 1.f / Bsqrtf(x);
4636 terminx 136
#endif
137
}
138
 
4486 helixhorne 139
// Flags of the <dameth> argument of various functions
140
enum {
141
    DAMETH_CLAMPED = 4,
142
 
4498 helixhorne 143
    DAMETH_WALL = 32,  // signals a texture for a wall (for r_npotwallmode)
144
 
4486 helixhorne 145
    DAMETH_NOCOMPRESS = 4096,
146
    DAMETH_HI = 8192,
5075 terminx 147
    DAMETH_NOFIX = 16384,
4486 helixhorne 148
};
149
 
150
// DAMETH_CLAMPED -> PTH_CLAMPED conversion
4636 terminx 151
#define TO_PTH_CLAMPED(dameth) (((dameth)&DAMETH_CLAMPED)>>2)
4486 helixhorne 152
 
4498 helixhorne 153
// Do we want a NPOT-y-as-classic texture for this <dameth> and <ysiz>?
154
static inline int polymost_want_npotytex(int32_t dameth, int32_t ysiz)
155
{
156
    return getrendermode() != REND_POLYMER &&  // r_npotwallmode NYI in Polymer
157
        polymost_is_npotmode() && (dameth&DAMETH_WALL) && check_nonpow2(ysiz);
158
}
159
 
4486 helixhorne 160
// pthtyp pth->flags bits
161
enum {
162
    PTH_CLAMPED = 1,
163
    PTH_HIGHTILE = 2,
164
    PTH_SKYBOX = 4,
165
    PTH_HASALPHA = 8,
166
    PTH_HASFULLBRIGHT = 16,
4498 helixhorne 167
    PTH_NPOTWALL = DAMETH_WALL,  // r_npotwallmode=1 generated texture
4486 helixhorne 168
 
169
    PTH_INVALIDATED = 128,
170
};
171
 
1173 terminx 172
typedef struct pthtyp_t
173
{
174
    struct pthtyp_t *next;
4636 terminx 175
    struct pthtyp_t *ofb; // fullbright pixels
176
    hicreplctyp     *hicr;
1173 terminx 177
 
4636 terminx 178
    uint32_t        glpic;
179
    vec2f_t         scale;
180
    vec2_t          siz;
181
    int16_t         picnum;
182
 
183
    char            palnum;
184
    char            shade;
185
    char            effects;
186
    char            flags;      // 1 = clamped (dameth&4), 2 = hightile, 4 = skybox face, 8 = hasalpha, 16 = hasfullbright, 128 = invalidated
187
    char            skyface;
1173 terminx 188
} pthtyp;
189
 
4491 helixhorne 190
extern void gloadtile_art(int32_t,int32_t,int32_t,int32_t,pthtyp *,int32_t);
3758 terminx 191
extern int32_t gloadtile_hi(int32_t,int32_t,int32_t,hicreplctyp *,int32_t,pthtyp *,int32_t,char);
1173 terminx 192
 
1205 terminx 193
extern int32_t globalnoeffect;
194
extern int32_t drawingskybox;
3758 terminx 195
extern int32_t hicprecaching;
4605 terminx 196
extern float gyxscale, gxyaspect, ghalfx, grhalfxdown10;
4667 terminx 197
extern float fcosglobalang, fsinglobalang;
4768 hendricks2 198
extern float fxdim, fydim, fydimen, fviewingrange;
1341 terminx 199
 
3758 terminx 200
extern char ptempbuf[MAXWALLSB<<1];
201
 
4623 terminx 202
#include "texcache.h"
3782 terminx 203
 
4623 terminx 204
extern void polymost_setupglowtexture(int32_t texunits, int32_t tex);
205
extern void polymost_setupdetailtexture(int32_t texunits, int32_t tex);
3782 terminx 206
 
4768 hendricks2 207
#ifdef __cplusplus
208
}
1173 terminx 209
#endif
210
 
1174 qbix79 211
#endif
4768 hendricks2 212
 
213
#endif