Subversion Repositories eduke32

Rev

Rev 4768 | 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);
1205 terminx 31
void uploadtexture(int32_t doalloc, int32_t xsiz, int32_t ysiz, int32_t intexfmt, int32_t texfmt, coltype *pic, int32_t tsizx, int32_t tsizy, int32_t dameth);
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;
1173 terminx 56
extern float alphahackarray[MAXTILES];
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()
4406 helixhorne 66
static inline int32_t eligible_for_tileshades(int32_t picnum, int32_t pal)
67
{
4605 terminx 68
    return (!usehightile || !hicfindsubst(picnum, pal)) &&
4406 helixhorne 69
        (!usemodels || md_tilehasmodel(picnum, pal) < 0);
70
}
71
 
3286 helixhorne 72
static inline float getshadefactor(int32_t shade)
73
{
74
    int32_t shadebound = (shadescale_unbounded || shade>=numshades) ? numshades : numshades-1;
75
    float 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))
4415 helixhorne 89
static inline int32_t get_floor_fogpal(const sectortype *sec)
90
{
4416 helixhorne 91
    return POLYMOST_CHOOSE_FOG_PAL(sec->fogpal, sec->floorpal);
4415 helixhorne 92
}
93
static inline int32_t get_ceiling_fogpal(const sectortype *sec)
94
{
4416 helixhorne 95
    return POLYMOST_CHOOSE_FOG_PAL(sec->fogpal, sec->ceilingpal);
4415 helixhorne 96
}
4460 helixhorne 97
static inline int32_t fogpal_shade(const sectortype *sec, int32_t shade)
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
 
4498 helixhorne 104
static inline int check_nonpow2(int32_t 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
 
4636 terminx 126
static inline float polymost_invsqrt(float x)
127
{
128
#ifdef B_LITTLE_ENDIAN
129
    const float haf = x*.5f;
130
    struct conv { union { uint32_t i; float f; } u; } * const n = (struct conv *)&x;
131
    n->u.i = 0x5f3759df-(n->u.i>>1);
132
    return n->u.f*(1.5f-haf*(n->u.f*n->u.f));
133
#else
134
    // this is the comment
135
    return 1.f/Bsqrtf(x);
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,
147
};
148
 
149
// DAMETH_CLAMPED -> PTH_CLAMPED conversion
4636 terminx 150
#define TO_PTH_CLAMPED(dameth) (((dameth)&DAMETH_CLAMPED)>>2)
4486 helixhorne 151
 
4498 helixhorne 152
// Do we want a NPOT-y-as-classic texture for this <dameth> and <ysiz>?
153
static inline int polymost_want_npotytex(int32_t dameth, int32_t ysiz)
154
{
155
    return getrendermode() != REND_POLYMER &&  // r_npotwallmode NYI in Polymer
156
        polymost_is_npotmode() && (dameth&DAMETH_WALL) && check_nonpow2(ysiz);
157
}
158
 
4486 helixhorne 159
// pthtyp pth->flags bits
160
enum {
161
    PTH_CLAMPED = 1,
162
    PTH_HIGHTILE = 2,
163
    PTH_SKYBOX = 4,
164
    PTH_HASALPHA = 8,
165
    PTH_HASFULLBRIGHT = 16,
4498 helixhorne 166
    PTH_NPOTWALL = DAMETH_WALL,  // r_npotwallmode=1 generated texture
4486 helixhorne 167
 
168
    PTH_INVALIDATED = 128,
169
};
170
 
1173 terminx 171
typedef struct pthtyp_t
172
{
173
    struct pthtyp_t *next;
4636 terminx 174
    struct pthtyp_t *ofb; // fullbright pixels
175
    hicreplctyp     *hicr;
1173 terminx 176
 
4636 terminx 177
    uint32_t        glpic;
178
    vec2f_t         scale;
179
    vec2_t          siz;
180
    int16_t         picnum;
181
 
182
    char            palnum;
183
    char            shade;
184
    char            effects;
185
    char            flags;      // 1 = clamped (dameth&4), 2 = hightile, 4 = skybox face, 8 = hasalpha, 16 = hasfullbright, 128 = invalidated
186
    char            skyface;
1173 terminx 187
} pthtyp;
188
 
4491 helixhorne 189
extern void gloadtile_art(int32_t,int32_t,int32_t,int32_t,pthtyp *,int32_t);
3758 terminx 190
extern int32_t gloadtile_hi(int32_t,int32_t,int32_t,hicreplctyp *,int32_t,pthtyp *,int32_t,char);
1173 terminx 191
 
1205 terminx 192
extern int32_t globalnoeffect;
193
extern int32_t drawingskybox;
3758 terminx 194
extern int32_t hicprecaching;
4605 terminx 195
extern float gyxscale, gxyaspect, ghalfx, grhalfxdown10;
4667 terminx 196
extern float fcosglobalang, fsinglobalang;
4768 hendricks2 197
extern float fxdim, fydim, fydimen, fviewingrange;
1341 terminx 198
 
3758 terminx 199
extern char ptempbuf[MAXWALLSB<<1];
200
 
4623 terminx 201
#include "texcache.h"
3782 terminx 202
 
4623 terminx 203
extern void polymost_setupglowtexture(int32_t texunits, int32_t tex);
204
extern void polymost_setupdetailtexture(int32_t texunits, int32_t tex);
3782 terminx 205
 
4768 hendricks2 206
#ifdef __cplusplus
207
}
1173 terminx 208
#endif
209
 
1174 qbix79 210
#endif
4768 hendricks2 211
 
212
#endif