summaryrefslogtreecommitdiffstats
path: root/src/VBox/GuestHost/OpenGL/packer/pack_bbox.h
blob: 8602f664b7c530bb8fb15d6bb1c012d0c0f2c4ca (plain)
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
/* Copyright (c) 2001, Stanford University
 * All rights reserved.
 *
 * See the file LICENSE.txt for information on redistributing this software.
 */

#ifndef CR_PACK_BBOX_H
#define CR_PACK_BBOX_H

#include "cr_pack.h"

#define UPDATE_1D_BBOX() \
if (pc->bounds_min.x > fx)    pc->bounds_min.x = fx;\
if (pc->bounds_min.y > 0.0f)  pc->bounds_min.y = 0.0f;\
if (pc->bounds_min.z > 0.0f)  pc->bounds_min.z = 0.0f;\
if (pc->bounds_max.x < fx)    pc->bounds_max.x = fx;\
if (pc->bounds_max.y < 0.0f)  pc->bounds_max.y = 0.0f;\
if (pc->bounds_max.z < 0.0f)  pc->bounds_max.z = 0.0f

#define UPDATE_2D_BBOX() \
if (pc->bounds_min.x > fx)    pc->bounds_min.x = fx;\
if (pc->bounds_min.y > fy)    pc->bounds_min.y = fy;\
if (pc->bounds_min.z > 0.0f)  pc->bounds_min.z = 0.0f;\
if (pc->bounds_max.x < fx)    pc->bounds_max.x = fx;\
if (pc->bounds_max.y < fy)    pc->bounds_max.y = fy;\
if (pc->bounds_max.z < 0.0f)  pc->bounds_max.z = 0.0f

#define UPDATE_3D_BBOX() \
if (pc->bounds_min.x > fx)    pc->bounds_min.x = fx; \
if (pc->bounds_min.y > fy)    pc->bounds_min.y = fy; \
if (pc->bounds_min.z > fz)    pc->bounds_min.z = fz; \
if (pc->bounds_max.x < fx)    pc->bounds_max.x = fx; \
if (pc->bounds_max.y < fy)    pc->bounds_max.y = fy; \
if (pc->bounds_max.z < fz)    pc->bounds_max.z = fz

#ifdef SIMD
#define UPDATE_3D_BBOX_SIMD() \
__asm {\
	__asm movups xmm0, fx\
	__asm movaps xmm1, pc->bounds_min.x\
	__asm movaps xmm2, pc->bounds_max.x\
	__asm minps xmm1, xmm0\
	__asm maxps xmm2, xmm0\
	__asm movaps pc->bounds_min.x, xmm1\
	__asm movaps pc->bounds_max.x, xmm2\
}
#define UPDATE_3D_BBOX_SIMD_PACK() \
__asm {\
	__asm mov ecx, [data_ptr]\
	__asm movups xmm0, fx\
	__asm movaps xmm1, pc->bounds_min.x\
	__asm movaps xmm2, pc->bounds_max.x\
	__asm minps xmm1, xmm0\
	__asm maxps xmm2, xmm0\
	__asm movaps pc->bounds_min.x, xmm1\
	__asm movaps pc->bounds_max.x, xmm2\
	__asm movups [ecx], xmm0\
}
#define UPDATE_3DV_BBOX_SIMD() \
__asm {\
	__asm mov eax, [v]\
	__asm mov ecx, [data_ptr]\
	__asm movups xmm0, [eax]\
	__asm movaps xmm1, pc->bounds_min.x\
	__asm movaps xmm2, pc->bounds_max.x\
	__asm minps xmm1, xmm0\
	__asm maxps xmm2, xmm0\
	__asm movaps pc->bounds_min.x, xmm1\
	__asm movaps pc->bounds_max.x, xmm2\
	__asm movups [ecx], xmm0\
}
#else
#define UPDATE_3DV_BBOX_SIMD() { CREATE_3D_VFLOATS(); UPDATE_3D_BBOX();}
#define UPDATE_3D_BBOX_SIMD()  UPDATE_3D_BBOX()
#endif

#define CREATE_1D_FLOATS() \
	GLfloat fx = (GLfloat) x;

#define CREATE_2D_FLOATS() \
	GLfloat fx = (GLfloat) x; \
	GLfloat fy = (GLfloat) y

#define CREATE_3D_FLOATS() \
	GLfloat fx = (GLfloat) x; \
	GLfloat fy = (GLfloat) y; \
	GLfloat fz = (GLfloat) z

#define CREATE_4D_FLOATS() \
	GLfloat fx = (GLfloat) x; \
	GLfloat fy = (GLfloat) y; \
	GLfloat fz = (GLfloat) z; \
	GLfloat fw = (GLfloat) w; \
	fx /= fw; fy /= fw; fz/= fw

/* For glVertexAttrib4N*ARB */
#define CREATE_3D_FLOATS_B_NORMALIZED() \
	GLfloat fx = (GLfloat) x * (1.0 / 128.0); \
	GLfloat fy = (GLfloat) y * (1.0 / 128.0); \
	GLfloat fz = (GLfloat) z * (1.0 / 128.0);

#define CREATE_3D_FLOATS_UB_NORMALIZED() \
	GLfloat fx = (GLfloat) x * (1.0 / 255.0); \
	GLfloat fy = (GLfloat) y * (1.0 / 255.0); \
	GLfloat fz = (GLfloat) z * (1.0 / 255.0);

#define CREATE_3D_FLOATS_US_NORMALIZED() \
	GLfloat fx = (GLfloat) x * (1.0 / 65535.0); \
	GLfloat fy = (GLfloat) y * (1.0 / 65535.0); \
	GLfloat fz = (GLfloat) z * (1.0 / 65535.0);


#define CREATE_1D_VFLOATS() \
	GLfloat fx = (GLfloat) v[0];

#define CREATE_2D_VFLOATS() \
	GLfloat fx = (GLfloat) v[0]; \
	GLfloat fy = (GLfloat) v[1]

#define CREATE_3D_VFLOATS() \
	GLfloat fx = (GLfloat) v[0]; \
	GLfloat fy = (GLfloat) v[1]; \
	GLfloat fz = (GLfloat) v[2]

#define CREATE_4D_VFLOATS() \
	GLfloat fx = (GLfloat) v[0]; \
	GLfloat fy = (GLfloat) v[1]; \
	GLfloat fz = (GLfloat) v[2]; \
	GLfloat fw = (GLfloat) v[3]; \
	fx /= fw; fy /= fw; fz/= fw

/* For glVertexAttrib4N*ARB */
#define CREATE_4D_FLOATS_UB_NORMALIZED() \
	GLfloat fx = (GLfloat) (x * (1.0 / 255.0)); \
	GLfloat fy = (GLfloat) (y * (1.0 / 255.0)); \
	GLfloat fz = (GLfloat) (z * (1.0 / 255.0)); \
	GLfloat fw = (GLfloat) (w * (1.0 / 255.0)); \
	fx /= fw; fy /= fw; fz/= fw

#define CREATE_4D_VFLOATS_B_NORMALIZED() \
	GLfloat fx = (GLfloat) (v[0] * (1.0 / 128.0)); \
	GLfloat fy = (GLfloat) (v[1] * (1.0 / 128.0)); \
	GLfloat fz = (GLfloat) (v[2] * (1.0 / 128.0)); \
	GLfloat fw = (GLfloat) (v[3] * (1.0 / 128.0)); \
	fx /= fw; fy /= fw; fz/= fw

#define CREATE_4D_VFLOATS_S_NORMALIZED() \
	GLfloat fx = (GLfloat) (2.0 * v[0] + 1.0) / ((GLfloat) (0xffff)); \
	GLfloat fy = (GLfloat) (2.0 * v[1] + 1.0) / ((GLfloat) (0xffff)); \
	GLfloat fz = (GLfloat) (2.0 * v[2] + 1.0) / ((GLfloat) (0xffff)); \
	GLfloat fw = (GLfloat) (2.0 * v[3] + 1.0) / ((GLfloat) (0xffff)); \
	fx /= fw; fy /= fw; fz/= fw

#define CREATE_4D_VFLOATS_I_NORMALIZED() \
	GLfloat fx = (GLfloat) (2.0 * v[0] + 1.0) / ((GLfloat) (0xffffffff)); \
	GLfloat fy = (GLfloat) (2.0 * v[1] + 1.0) / ((GLfloat) (0xffffffff)); \
	GLfloat fz = (GLfloat) (2.0 * v[2] + 1.0) / ((GLfloat) (0xffffffff)); \
	GLfloat fw = (GLfloat) (2.0 * v[3] + 1.0) / ((GLfloat) (0xffffffff)); \
	fx /= fw; fy /= fw; fz/= fw

#define CREATE_4D_VFLOATS_UB_NORMALIZED() \
	GLfloat fx = (GLfloat) (v[0] * (1.0 / 255.0)); \
	GLfloat fy = (GLfloat) (v[1] * (1.0 / 255.0)); \
	GLfloat fz = (GLfloat) (v[2] * (1.0 / 255.0)); \
	GLfloat fw = (GLfloat) (v[3] * (1.0 / 255.0)); \
	fx /= fw; fy /= fw; fz/= fw

#define CREATE_4D_VFLOATS_US_NORMALIZED() \
	GLfloat fx = (GLfloat) (v[0] * (1.0 / 65535.0)); \
	GLfloat fy = (GLfloat) (v[1] * (1.0 / 65535.0)); \
	GLfloat fz = (GLfloat) (v[2] * (1.0 / 65535.0)); \
	GLfloat fw = (GLfloat) (v[3] * (1.0 / 65535.0)); \
	fx /= fw; fy /= fw; fz/= fw

#define CREATE_4D_VFLOATS_UI_NORMALIZED() \
	GLfloat fx = v[0] / ((GLfloat) (0xffffffff)); \
	GLfloat fy = v[1] / ((GLfloat) (0xffffffff)); \
	GLfloat fz = v[2] / ((GLfloat) (0xffffffff)); \
	GLfloat fw = v[3] / ((GLfloat) (0xffffffff)); \
	fx /= fw; fy /= fw; fz/= fw

#endif /* CR_PACK_BBOX_H */