mvtdefs.h
8.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#ifndef __mvtdefs__
#define __mvtdefs__
/*====================================================================
* mvtdefs.h
*
* Copyright 1995, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
* Inc.; the contents of this file may not be disclosed to third
* parties, copied or duplicated in any form, in whole or in part,
* without the prior written permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights
* in Technical Data and Computer Software clause at DFARS
* 252.227-7013, and/or in similar or successor clauses in the FAR,
* DOD or NASA FAR Supplement. Unpublished - rights reserved under the
* Copyright Laws of the United States.
*====================================================================*/
/*
* Use the 32 bit encode/decode which only allows for -128,+127 of field
* of view but it also more compact.
*/
#define MVT_32_BIT_SPECIAL
/*
* These together form the max number of pixels in the MVT. Thus the
* MVT could actually be 64x128 or 32x160 or smaller. The number of tiles
* though must match the max size.
*/
#define MVT_MAX_TXSIZE 96
#define MVT_MAX_TYSIZE 96
#define MVT_MAX_TILES 9 /* must matched with max sizes */
/*
* For 32 bit textures, the max allowed in tmem is a 32x32x4 texture
*/
#define MVT_TILE_SIZE 1024
/*
* For viewing objects using the template, group and instance system,
*/
#define MVT_MAX_GROUPS 3
#define MVT_MAX_OBJECTS_PER_GROUP 1
#define MVT_MAX_OBJECTS MVT_MAX_OBJECTS_PER_GROUP*MVT_MAX_GROUPS
#define MVT_MAX_TEMPLATES 1
/*
* Parameters that define how the texture coordinates are scaled, should
* never really need to change these.
*/
#define MVT_XTEXSCALE 8
#define MVT_YTEXSCALE 16
#define MVT_XTEXSCALE_SHIFT 3
#define MVT_YTEXSCALE_SHIFT 4
#define MVT_TEXSCALE_MASK 5
/*
* The below are the macros used for packing and unpacking of MVT data.
*
* 32 bit special: allows for a -128 to +127 field of
* view and costs 6 bytes per pixel minimum, as opposed to 4 bytes in a
* normal texture. Further samples per pixel are compressed along the view
* point according to the color diff factor. Unfortunately, for
* radiosity scenes it doesn't compress to well. Other compression schemes
* could be used perhaps. Note that the compressed data stores "state"
* information from the previous decompression so that decompression of
* successive nearby view points takes approximately constant time (i.e.
* after the first frame, it doesn't have how many samples have been taken
* it takes time proportional to number of pixels and NOT number of samples).
*
*/
#ifndef MVTLOOKUP
#define MVTLOOKUP(V,X,Y) (V)->data[(Y)*txsize + (X)]
#endif
#ifdef MVT_32_BIT_SPECIAL
typedef unsigned short MVTDataType;
typedef unsigned int MVTTextureType;
#define MVT_SIZE_TEXT "32bit-special"
#define MVT_NORMAL_TEXEL 4
#define MVT_ENTRY_SIZE 2
#define MVT_ENTRY_HEADER 1
#define MVT_SET_NUM_ENTRIES(VIEW,X,Y,E) \
if (1) { \
u8 _tmp = MVTLOOKUP(VIEW,X,Y)[0] & 0xff; \
MVTLOOKUP(VIEW,X,Y)[0] = (E&0xff)<<8 | _tmp; \
} else
#define MVT_GET_NUM_ENTRIES(VIEW,X,Y,E) E=(MVTLOOKUP(VIEW,X,Y)[0]>>8)&0xff
#define MVT_GET_LAST_USED(VIEW,X,Y,L) L=(MVTLOOKUP(VIEW,X,Y)[0]&0xff)
#define MVT_SET_LAST_USED(VIEW,X,Y,L) \
if (1) { \
u16 _tmp = MVTLOOKUP(VIEW,X,Y)[0] & 0xff00; \
MVTLOOKUP(VIEW,X,Y)[0] = _tmp | (L&0xff); \
} else
#define MVT_GET_LAST_BASE(VIEW,X,Y,B) B=2*((MVTLOOKUP(VIEW,X,Y)[0]>>8)-1)+1
#define MVT_GET_BASE(VIEW,X,Y,N,B) B=2*(N)+1
#define MVT_GET_ENTRY_INDEX(VIEW,X,Y,BASE,INDEX) \
INDEX=(unsigned char)(MVTLOOKUP(VIEW,X,Y)[BASE+1]&0xff)-128
#define MVT_SET_ENTRY_INDEX(VIEW,X,Y,BASE,INDEX) \
if (1) { \
u16 _tmp = MVTLOOKUP(VIEW,X,Y)[BASE+1] & 0xff00; \
MVTLOOKUP(VIEW,X,Y)[BASE+1] = _tmp | (u8)(INDEX+128);\
} else
#define MVT_GET_ENTRY_COLOR(VIEW,X,Y,BASE,R,G,B) \
if (1) { \
R = (MVTLOOKUP(VIEW,X,Y)[BASE+0] >> 8) & 0xff; \
G = (MVTLOOKUP(VIEW,X,Y)[BASE+0] >> 0) & 0xff; \
B = (MVTLOOKUP(VIEW,X,Y)[BASE+1] >> 8) & 0xff; \
} else
#define MVT_SET_ENTRY_COLOR(VIEW,X,Y,BASE,R,G,B,INDEX) \
if (1) { \
u8 _tmp = (INDEX+128); \
MVTLOOKUP(VIEW,X,Y)[BASE+0] = (R&0xff)<<8 | (G&0xff);\
MVTLOOKUP(VIEW,X,Y)[BASE+1] = (B&0xff)<<8 | (_tmp); \
} else
#define MVT_GET_COLOR_FROM_FB(FB,PIXEL,R,G,B) \
if (1) { \
R = (FB[PIXEL] >> 24) & 0xff; \
G = (FB[PIXEL] >> 16) & 0xff; \
B = (FB[PIXEL] >> 8) & 0xff; \
} else
#define MVT_SET_COLOR_TO_FB(FB,PIXEL,R,G,B,A) \
if (1) { \
FB[PIXEL]=((R&0xff)<<24)|((G&0xff)<<16)|((B&0xff)<<8)|(A*255)&0xff;\
} else
#endif
/*
* This is for 16 bit MVTs. It allows -180 to +180 field of view. Not
* used for portals
*/
#ifdef MVT_16_BIT
typedef short MVTDataType;
typedef unsigned short MVTTextureType;
#define MVT_SIZE_TEXT "16bit"
#define MVT_NORMAL_TEXEL 2
#define MVT_ENTRY_HEADER 1
#define MVT_ENTRY_SIZE 2
#define MVT_SET_NUM_ENTRIES(VIEW,X,Y,E) \
if (1) { \
u8 _tmp = MVTLOOKUP(VIEW,X,Y)[0] & 0xff; \
MVTLOOKUP(VIEW,X,Y)[0] = (E&0xff)<<8 | _tmp; \
} else
#define MVT_GET_NUM_ENTRIES(VIEW,X,Y,E) E=(MVTLOOKUP(VIEW,X,Y)[0]>>8)&0xff
#define MVT_GET_LAST_USED(VIEW,X,Y,L) L=(MVTLOOKUP(VIEW,X,Y)[0]&0xff)
#define MVT_SET_LAST_USED(VIEW,X,Y,L) \
if (1) { \
u16 _tmp = MVTLOOKUP(VIEW,X,Y)[0] & 0xff00; \
MVTLOOKUP(VIEW,X,Y)[0] = _tmp | (L&0xff); \
} else
#define MVT_GET_LAST_BASE(VIEW,X,Y,B) B=2*((MVTLOOKUP(VIEW,X,Y)[0]>>8)-1)+1
#define MVT_GET_BASE(VIEW,X,Y,N,B) B=2*(N)+1
#define MVT_SET_ENTRY_INDEX(VIEW,X,Y,BASE,INDEX) MVTLOOKUP(VIEW,X,Y)[BASE]=INDEX
#define MVT_GET_ENTRY_INDEX(VIEW,X,Y,BASE,INDEX) INDEX=MVTLOOKUP(VIEW,X,Y)[BASE]
#define MVT_GET_ENTRY_COLOR(VIEW,X,Y,BASE,R,G,B) \
if (1) { \
R = (MVTLOOKUP(VIEW,X,Y)[BASE+1] >> 10) & 0x1f; \
G = (MVTLOOKUP(VIEW,X,Y)[BASE+1] >> 5) & 0x1f; \
B = (MVTLOOKUP(VIEW,X,Y)[BASE+1] >> 0) & 0x1f; \
} else
#define MVT_SET_ENTRY_COLOR(VIEW,X,Y,BASE,R,G,B,INDEX) \
if (1) { \
MVTLOOKUP(VIEW,X,Y)[BASE ] = INDEX; \
MVTLOOKUP(VIEW,X,Y)[BASE+1] = ((R&0x1f)<<10)|((G&0x1f)<<5)|(B&0x1f);\
} else
#define MVT_GET_COLOR_FROM_FB(FB,PIXEL,R,G,B) \
if (1) { \
R = (FB[PIXEL] >> 11) & 0x1f; \
G = (FB[PIXEL] >> 6) & 0x1f; \
B = (FB[PIXEL] >> 1) & 0x1f; \
} else
#define MVT_SET_COLOR_TO_FB(FB,PIXEL,R,G,B,A) \
if (1) { \
FB[PIXEL] = ((R&0x1f)<<11)|((G&0x1f)<<6)|((B&0x1f)<<1)|A&0x1;\
} else
#endif
/*
* This is the original 32 bit MVT scheme. It allows -180 to +180 field of
* view. Direct extension of the 16 bit scheme. Not used for portals.
*/
#ifdef MVT_32_BIT
typedef int MVTDataType;
typedef unsigned int MVTTextureType;
#define MVT_SIZE_TEXT "32bit"
#define MVT_NORMAL_TEXEL 4
#define MVT_ENTRY_HEADER 2
#define MVT_ENTRY_SIZE 2
#define MVT_SET_NUM_ENTRIES(VIEW,X,Y,E) (MVTLOOKUP(VIEW,X,Y)[0])=E
#define MVT_GET_NUM_ENTRIES(VIEW,X,Y,E) E=(MVTLOOKUP(VIEW,X,Y)[0])
#define MVT_SET_LAST_USED(VIEW,X,Y,L) (MVTLOOKUP(VIEW,X,Y)[1])=L
#define MVT_GET_LAST_USED(VIEW,X,Y,L) L=(MVTLOOKUP(VIEW,X,Y)[1])
#define MVT_GET_LAST_BASE(VIEW,X,Y,B) B=(2*MVTLOOKUP(VIEW,X,Y)[0])
#define MVT_GET_BASE(VIEW,X,Y,N,B) B=2*(N)+2
#define MVT_SET_ENTRY_INDEX(VIEW,X,Y,BASE,INDEX) MVTLOOKUP(VIEW,X,Y)[BASE]=INDEX
#define MVT_GET_ENTRY_INDEX(VIEW,X,Y,BASE,INDEX) INDEX=MVTLOOKUP(VIEW,X,Y)[BASE]
#define MVT_GET_ENTRY_COLOR(VIEW,X,Y,BASE,R,G,B) \
if (1) { \
R = (MVTLOOKUP(VIEW,X,Y)[BASE+1] >> 16) & 0xff; \
G = (MVTLOOKUP(VIEW,X,Y)[BASE+1] >> 8) & 0xff; \
B = (MVTLOOKUP(VIEW,X,Y)[BASE+1] >> 0) & 0xff; \
} else
#define MVT_SET_ENTRY_COLOR(VIEW,X,Y,BASE,R,G,B,INDEX) \
if (1) { \
MVTLOOKUP(VIEW,X,Y)[BASE ] = INDEX; \
MVTLOOKUP(VIEW,X,Y)[BASE+1] = (R<<16)|(G<<8)|(B); \
} else
#define MVT_GET_COLOR_FROM_FB(FB,PIXEL,R,G,B) \
if (1) { \
R = (FB[PIXEL] >> 24) & 0xff; \
G = (FB[PIXEL] >> 16) & 0xff; \
B = (FB[PIXEL] >> 8) & 0xff; \
} else
#define MVT_SET_COLOR_TO_FB(FB,PIXEL,R,G,B,A) \
if (1) { \
FB[PIXEL]=((R&0xff)<<24)|((G&0xff)<<16)|((B&0xff)<<8)|(A*255)&0xff;\
} else
#endif
/*
* Misc.
*/
#define SQR(X) ((X)*(X))
#define ABS(X) (((X) < 0) ? -(X) : (X))
#define DOT2(A,B) ((A)[0]*(B)[0] + (A)[1]*(B)[1])
#endif