Subversion Repositories Kolibri OS

Rev

Rev 5153 | Rev 5175 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5153 Rev 5171
1
include 'opengl_const.inc'
1
include 'opengl_const.inc'
2
include 'zbuffer.inc'
2
include 'zbuffer.inc'
3
include 'zmath.inc'
3
include 'zmath.inc'
4
 
4
 
5
;#define fputc(...) /*nothing*/
5
;#define fputc(...) /*nothing*/
6
;#define fprintf(...) /*nothing*/
6
;#define fprintf(...) /*nothing*/
7
;#define vfprintf(...) /*nothing*/
7
;#define vfprintf(...) /*nothing*/
8
;#undef stderr
8
;#undef stderr
9
;#define stderr ((FILE*)-1)
9
;#define stderr ((FILE*)-1)
10
 
10
 
11
 
11
 
12
;enum { OP_ ## a , ... }
12
;enum { OP_ ## a , ... }
13
s1 equ 0
13
s1 equ 0
14
macro ADD_OP a,b,c
14
macro ADD_OP a,b,c
15
{
15
{
16
	OP_#a equ s1
16
	OP_#a equ s1
17
	s1 equ (s1+1)
17
	s1 equ (s1+1)
18
}
18
}
19
include 'opinfo.inc'
19
include 'opinfo.inc'
20
 
20
 
21
 
21
 
22
;initially # of allocated GLVertexes (will grow when necessary)
22
;initially # of allocated GLVertexes (will grow when necessary)
23
POLYGON_MAX_VERTEX equ 16
23
POLYGON_MAX_VERTEX equ 16
24
 
24
 
25
;Max # of specular light pow buffers
25
;Max # of specular light pow buffers
26
MAX_SPECULAR_BUFFERS equ 8
26
MAX_SPECULAR_BUFFERS equ 8
27
;# of entries in specular buffer
27
;# of entries in specular buffer
28
SPECULAR_BUFFER_SIZE equ 1024
28
SPECULAR_BUFFER_SIZE equ 1024
29
;specular buffer granularity
29
;specular buffer granularity
30
SPECULAR_BUFFER_RESOLUTION equ 1024
30
SPECULAR_BUFFER_RESOLUTION equ 1024
31
 
31
 
32
 
32
 
33
MAX_MODELVIEW_STACK_DEPTH  equ 32
33
MAX_MODELVIEW_STACK_DEPTH  equ 32
34
MAX_PROJECTION_STACK_DEPTH equ 8
34
MAX_PROJECTION_STACK_DEPTH equ 8
35
MAX_TEXTURE_STACK_DEPTH    equ 8
35
MAX_TEXTURE_STACK_DEPTH    equ 8
36
MAX_NAME_STACK_DEPTH	   equ 64
36
MAX_NAME_STACK_DEPTH	   equ 64
37
MAX_TEXTURE_LEVELS	   equ 11
37
MAX_TEXTURE_LEVELS	   equ 11
38
MAX_LIGHTS		   equ 16
38
MAX_LIGHTS		   equ 16
39
 
39
 
40
VERTEX_HASH_SIZE equ 1031
40
VERTEX_HASH_SIZE equ 1031
41
 
41
 
42
MAX_DISPLAY_LISTS equ 1024
42
MAX_DISPLAY_LISTS equ 1024
43
OP_BUFFER_MAX_SIZE equ 512
43
OP_BUFFER_MAX_SIZE equ 512
44
 
44
 
45
TGL_OFFSET_FILL    equ 0x1
45
TGL_OFFSET_FILL    equ 0x1
46
TGL_OFFSET_LINE    equ 0x2
46
TGL_OFFSET_LINE    equ 0x2
47
TGL_OFFSET_POINT   equ 0x4
47
TGL_OFFSET_POINT   equ 0x4
48
 
48
 
49
struct GLSpecBuf
49
struct GLSpecBuf
50
	shininess_i dd ? ;int
50
	shininess_i dd ? ;int
51
	last_used dd ? ;int
51
	last_used dd ? ;int
52
	buf rd SPECULAR_BUFFER_SIZE+1 ;float[SPECULAR_BUFFER_SIZE+1]
52
	buf rd SPECULAR_BUFFER_SIZE+1 ;float[SPECULAR_BUFFER_SIZE+1]
53
	next dd ? ;struct GLSpecBuf*
53
	next dd ? ;struct GLSpecBuf*
54
ends
54
ends
55
 
55
 
56
struct GLLight
56
struct GLLight
57
	ambient V4
57
	ambient V4
58
	diffuse V4
58
	diffuse V4
59
	specular V4
59
	specular V4
60
	position V4	
60
	position V4	
61
	spot_direction V3
61
	spot_direction V3
62
	spot_exponent dd ? ;float
62
	spot_exponent dd ? ;float
63
	spot_cutoff dd ? ;float
63
	spot_cutoff dd ? ;float
64
	attenuation rd 3 ;float[3]
64
	attenuation rd 3 ;float[3]
65
	; precomputed values
65
	; precomputed values
66
	cos_spot_cutoff dd ? ;float
66
	cos_spot_cutoff dd ? ;float
67
	norm_spot_direction V3
67
	norm_spot_direction V3
68
	norm_position V3
68
	norm_position V3
69
	; we use a linked list to know which are the enabled lights
69
	; we use a linked list to know which are the enabled lights
70
	enabled dd ? ;int
70
	enabled dd ? ;int
71
	next dd ? ;struct GLLight*
71
	next dd ? ;struct GLLight*
72
	prev dd ? ;struct GLLight*
72
	prev dd ? ;struct GLLight*
73
ends
73
ends
74
 
74
 
75
offs_ligh_ambient equ 0 ;V4
75
offs_ligh_ambient equ 0 ;V4
76
offs_ligh_diffuse equ 16 ;V4
76
offs_ligh_diffuse equ 16 ;V4
77
offs_ligh_specular equ 32 ;V4
77
offs_ligh_specular equ 32 ;V4
78
offs_ligh_position equ 48 ;V4	
78
offs_ligh_position equ 48 ;V4	
79
offs_ligh_spot_direction equ 64 ;V3
79
offs_ligh_spot_direction equ 64 ;V3
80
offs_ligh_spot_exponent equ 76 ;dd ?
80
offs_ligh_spot_exponent equ 76 ;dd ?
81
offs_ligh_spot_cutoff equ 80 ;dd ?
81
offs_ligh_spot_cutoff equ 80 ;dd ?
82
offs_ligh_attenuation equ 84 ;rd 3
82
offs_ligh_attenuation equ 84 ;rd 3
83
offs_ligh_cos_spot_cutoff equ 96 ;dd ?
83
offs_ligh_cos_spot_cutoff equ 96 ;dd ?
84
offs_ligh_norm_spot_direction equ 100 ;V3
84
offs_ligh_norm_spot_direction equ 100 ;V3
85
offs_ligh_norm_position equ 112 ;V3
85
offs_ligh_norm_position equ 112 ;V3
86
offs_ligh_enabled equ 124 ;dd ?
86
offs_ligh_enabled equ 124 ;dd ?
87
offs_ligh_next equ 128 ;dd ?
87
offs_ligh_next equ 128 ;dd ?
88
offs_ligh_prev equ 132 ;dd ?
88
offs_ligh_prev equ 132 ;dd ?
89
 
89
 
90
struct GLMaterial
90
struct GLMaterial
91
	emission V4
91
	emission V4
92
	ambient  V4
92
	ambient  V4
93
	diffuse  V4
93
	diffuse  V4
94
	specular V4
94
	specular V4
95
	shininess dd ? ;float
95
	shininess dd ? ;float
96
 
96
 
97
	; computed values
97
	; computed values
98
	shininess_i dd ? ;int
98
	shininess_i dd ? ;int
99
	do_specular dd ? ;int
99
	do_specular dd ? ;int
100
ends
100
ends
101
 
101
 
102
offs_mate_emission   equ 0 ;V4
102
offs_mate_emission   equ 0 ;V4
103
offs_mate_ambient   equ 16 ;V4
103
offs_mate_ambient   equ 16 ;V4
104
offs_mate_diffuse   equ 32 ;V4
104
offs_mate_diffuse   equ 32 ;V4
105
offs_mate_specular  equ 48 ;V4
105
offs_mate_specular  equ 48 ;V4
106
offs_mate_shininess equ 64 ;dd
106
offs_mate_shininess equ 64 ;dd
107
offs_mate_shininess_i equ 68 ;dd
107
offs_mate_shininess_i equ 68 ;dd
108
offs_mate_do_specular equ 72 ;dd 
108
offs_mate_do_specular equ 72 ;dd 
109
 
109
 
110
struct GLViewport
110
struct GLViewport
111
	xmin dd ? ;int
111
	xmin dd ? ;int
112
	ymin dd ? ;int
112
	ymin dd ? ;int
113
	xsize dd ? ;int
113
	xsize dd ? ;int
114
	ysize dd ? ;int
114
	ysize dd ? ;int
115
	scale V3
115
	scale V3
116
	trans V3
116
	trans V3
117
	updated dd ? ;int
117
	updated dd ? ;int
118
ends
118
ends
119
 
119
 
120
offs_vpor_xmin   equ 0
120
offs_vpor_xmin   equ 0
121
offs_vpor_ymin   equ 4
121
offs_vpor_ymin   equ 4
122
offs_vpor_xsize  equ 8
122
offs_vpor_xsize  equ 8
123
offs_vpor_ysize equ 12
123
offs_vpor_ysize equ 12
124
offs_vpor_scale equ 16
124
offs_vpor_scale equ 16
125
offs_vpor_trans equ 28
125
offs_vpor_trans equ 28
126
offs_vpor_updated equ 40
126
offs_vpor_updated equ 40
127
 
127
 
128
struct GLParamBuffer
128
struct GLParamBuffer
129
	ops rd OP_BUFFER_MAX_SIZE ;GLParam[OP_BUFFER_MAX_SIZE]
129
	ops rd OP_BUFFER_MAX_SIZE ;GLParam[OP_BUFFER_MAX_SIZE]
130
	next dd ? ;struct GLParamBuffer*
130
	next dd ? ;struct GLParamBuffer*
131
ends
131
ends
-
 
132
 
-
 
133
offs_gpbu_ops equ 0
-
 
134
offs_gpbu_next equ 4*OP_BUFFER_MAX_SIZE
132
 
135
 
133
struct GLList
136
struct GLList
134
	first_op_buffer dd ? ;GLParamBuffer*
137
	first_op_buffer dd ? ;GLParamBuffer*
135
;  /* TODO: extensions for an hash table or a better allocating scheme */
138
	; TODO: extensions for an hash table or a better allocating scheme
136
ends
139
ends
137
 
140
 
138
struct GLVertex
141
struct GLVertex
139
	edge_flag dd ? ;int
142
	edge_flag dd ? ;int
140
	normal V3
143
	normal V3
141
	coord V4
144
	coord V4
142
	tex_coord V4
145
	tex_coord V4
143
	color V4
146
	color V4
144
 
147
 
145
	; computed values
148
	; computed values
146
	ec V4 ; eye coordinates
149
	ec V4 ; eye coordinates
147
	pc V4 ; coordinates in the normalized volume
150
	pc V4 ; coordinates in the normalized volume
148
	clip_code dd ? ;int ; clip code
151
	clip_code dd ? ;int ; clip code
149
	zp ZBufferPoint ; integer coordinates for the rasterization
152
	zp ZBufferPoint ; integer coordinates for the rasterization
150
ends
153
ends
151
 
154
 
152
offs_vert_edge_flag  equ 0
155
offs_vert_edge_flag  equ 0
153
offs_vert_normal     equ 4
156
offs_vert_normal     equ 4
154
offs_vert_coord     equ 16 
157
offs_vert_coord     equ 16 
155
offs_vert_tex_coord equ 32
158
offs_vert_tex_coord equ 32
156
offs_vert_color     equ 48
159
offs_vert_color     equ 48
157
offs_vert_ec        equ 64
160
offs_vert_ec        equ 64
158
offs_vert_pc        equ 80
161
offs_vert_pc        equ 80
159
offs_vert_clip_code equ 96
162
offs_vert_clip_code equ 96
160
offs_vert_zp       equ 100
163
offs_vert_zp       equ 100
161
 
164
 
162
struct GLImage
165
struct GLImage
163
	pixmap dd ? ;void*
166
	pixmap dd ? ;void*
164
	xsize dd ? ;int
167
	xsize dd ? ;int
165
	ysize dd ? ;int
168
	ysize dd ? ;int
166
ends
169
ends
167
 
170
 
168
offs_imag_pixmap equ 0
171
offs_imag_pixmap equ 0
169
 
172
 
170
; textures
173
; textures
171
 
174
 
172
TEXTURE_HASH_TABLE_SIZE equ 256 ;должно быть кратное 2, в коде берется остаток от деления (через and быстрее чем div)
175
TEXTURE_HASH_TABLE_SIZE equ 256 ;должно быть кратное 2, в коде берется остаток от деления (через and быстрее чем div)
173
 
176
 
174
struct GLTexture
177
struct GLTexture
175
	images rb sizeof.GLImage * MAX_TEXTURE_LEVELS ;GLImage[MAX_TEXTURE_LEVELS]
178
	images rb sizeof.GLImage * MAX_TEXTURE_LEVELS ;GLImage[MAX_TEXTURE_LEVELS]
176
	handle dd ? ;int
179
	handle dd ? ;int
177
	next dd ? ;struct GLTexture*
180
	next dd ? ;struct GLTexture*
178
	prev dd ? ;struct GLTexture*
181
	prev dd ? ;struct GLTexture*
179
ends
182
ends
180
 
183
 
181
offs_text_images equ 0
184
offs_text_images equ 0
182
offs_text_handle equ sizeof.GLImage*MAX_TEXTURE_LEVELS
185
offs_text_handle equ sizeof.GLImage*MAX_TEXTURE_LEVELS
183
offs_text_next equ 4+offs_text_handle
186
offs_text_next equ 4+offs_text_handle
184
offs_text_prev equ 8+offs_text_handle
187
offs_text_prev equ 8+offs_text_handle
185
 
188
 
186
; shared state
189
; shared state
187
 
190
 
188
struct GLSharedState
191
struct GLSharedState
189
	lists dd ? ;GLList**
192
	lists dd ? ;GLList**
190
	texture_hash_table dd ? ;GLTexture**
193
	texture_hash_table dd ? ;GLTexture**
191
ends
194
ends
192
 
195
 
193
 
196
 
194
; display context
197
; display context
195
 
198
 
196
struct GLContext
199
struct GLContext
197
	; Z buffer
200
	; Z buffer
198
	zb dd ? ;ZBuffer*
201
	zb dd ? ;ZBuffer*
199
 
202
 
200
	; lights
203
	; lights
201
	lights rb sizeof.GLLight * MAX_LIGHTS ;GLLight[MAX_LIGHTS]
204
	lights rb sizeof.GLLight * MAX_LIGHTS ;GLLight[MAX_LIGHTS]
202
	first_light dd ? ;GLLight*
205
	first_light dd ? ;GLLight*
203
	ambient_light_model V4
206
	ambient_light_model V4
204
	local_light_model dd ? ;int
207
	local_light_model dd ? ;int
205
	lighting_enabled dd ? ;int
208
	lighting_enabled dd ? ;int
206
	light_model_two_side dd ? ;int
209
	light_model_two_side dd ? ;int
207
 
210
 
208
	; materials
211
	; materials
209
	materials rb sizeof.GLMaterial * 2 ;GLMaterial[2]
212
	materials rb sizeof.GLMaterial * 2 ;GLMaterial[2]
210
	color_material_enabled dd ? ;int
213
	color_material_enabled dd ? ;int
211
	current_color_material_mode dd ? ;int
214
	current_color_material_mode dd ? ;int
212
	current_color_material_type dd ? ;int
215
	current_color_material_type dd ? ;int
213
 
216
 
214
	; textures
217
	; textures
215
	current_texture dd ? ;GLTexture*
218
	current_texture dd ? ;GLTexture*
216
	texture_2d_enabled dd ? ;int
219
	texture_2d_enabled dd ? ;int
217
 
220
 
218
	; shared state
221
	; shared state
219
	shared_state GLSharedState
222
	shared_state GLSharedState
220
 
223
 
221
	; current list
224
	; current list
222
	current_op_buffer dd ? ;GLParamBuffer*
225
	current_op_buffer dd ? ;GLParamBuffer*
223
	current_op_buffer_index dd ? ;int
226
	current_op_buffer_index dd ? ;int
224
	exec_flag dd ? ;int
227
	exec_flag dd ? ;int
225
	compile_flag dd ? ;int
228
	compile_flag dd ? ;int
226
	print_flag dd ? ;int
229
	print_flag dd ? ;int
227
 
230
 
228
	; matrix
231
	; matrix
229
 
232
 
230
	matrix_mode dd ? ;int режим активного вида матрицы (один из 3-х: GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE)
233
	matrix_mode dd ? ;int режим активного вида матрицы (один из 3-х: GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE)
231
	matrix_stack rd 3 ;*M4[3] указатель на начало массива матриц
234
	matrix_stack rd 3 ;*M4[3] указатель на начало массива матриц
232
	matrix_stack_ptr rd 3 ;*M4[3] указатель на активную матрицу из массива
235
	matrix_stack_ptr rd 3 ;*M4[3] указатель на активную матрицу из массива
233
	matrix_stack_depth_max rd 3 ;int[3] максимальное число матриц в массивах matrix_stack
236
	matrix_stack_depth_max rd 3 ;int[3] максимальное число матриц в массивах matrix_stack
234
 
237
 
235
	matrix_model_view_inv M4
238
	matrix_model_view_inv M4
236
	matrix_model_projection M4
239
	matrix_model_projection M4
237
	matrix_model_projection_updated dd ? ;int
240
	matrix_model_projection_updated dd ? ;int
238
	matrix_model_projection_no_w_transform dd ? ;int 
241
	matrix_model_projection_no_w_transform dd ? ;int 
239
	apply_texture_matrix dd ? ;int
242
	apply_texture_matrix dd ? ;int
240
 
243
 
241
	; viewport
244
	; viewport
242
	viewport GLViewport
245
	viewport GLViewport
243
 
246
 
244
	; current state
247
	; current state
245
	polygon_mode_back dd ? ;int
248
	polygon_mode_back dd ? ;int
246
	polygon_mode_front dd ? ;int
249
	polygon_mode_front dd ? ;int
247
 
250
 
248
	current_front_face dd ? ;int
251
	current_front_face dd ? ;int
249
	current_shade_model dd ? ;int
252
	current_shade_model dd ? ;int
250
	current_cull_face dd ? ;int
253
	current_cull_face dd ? ;int
251
	cull_face_enabled dd ? ;int
254
	cull_face_enabled dd ? ;int
252
	normalize_enabled dd ? ;int
255
	normalize_enabled dd ? ;int
253
	draw_triangle_front dd ? ;gl_draw_triangle_func
256
	draw_triangle_front dd ? ;gl_draw_triangle_func
254
	draw_triangle_back  dd ? ;gl_draw_triangle_func
257
	draw_triangle_back  dd ? ;gl_draw_triangle_func
255
 
258
 
256
	; selection
259
	; selection
257
	render_mode dd ? ;int
260
	render_mode dd ? ;int
258
	select_buffer dd ? ;unsigned int*
261
	select_buffer dd ? ;unsigned int*
259
	select_size dd ? ;int
262
	select_size dd ? ;int
260
	select_ptr dd ? ;unsigned int*
263
	select_ptr dd ? ;unsigned int*
261
	select_hit dd ? ;unsigned int*
264
	select_hit dd ? ;unsigned int*
262
	select_overflow dd ? ;int
265
	select_overflow dd ? ;int
263
	select_hits dd ? ;int
266
	select_hits dd ? ;int
264
 
267
 
265
	; names
268
	; names
266
	name_stack rd MAX_NAME_STACK_DEPTH ;unsigned int[MAX_NAME_STACK_DEPTH]
269
	name_stack rd MAX_NAME_STACK_DEPTH ;unsigned int[MAX_NAME_STACK_DEPTH]
267
	name_stack_size dd ? ;int
270
	name_stack_size dd ? ;int
268
 
271
 
269
	; clear
272
	; clear
270
	clear_depth dd ? ;float
273
	clear_depth dd ? ;float
271
	clear_color V4
274
	clear_color V4
272
 
275
 
273
	; current vertex state
276
	; current vertex state
274
	current_color V4
277
	current_color V4
275
	longcurrent_color rd 3 ;unsigned int[3] ;precomputed integer color
278
	longcurrent_color rd 3 ;unsigned int[3] ;precomputed integer color
276
	current_normal V4
279
	current_normal V4
277
	current_tex_coord V4
280
	current_tex_coord V4
278
	current_edge_flag dd ? ;int
281
	current_edge_flag dd ? ;int
279
 
282
 
280
	; glBegin / glEnd
283
	; glBegin / glEnd
281
	in_begin dd ? ;int
284
	in_begin dd ? ;int
282
	begin_type dd ? ;int
285
	begin_type dd ? ;int
283
	vertex_n dd ? ;int
286
	vertex_n dd ? ;int
284
	vertex_cnt dd ? ;int
287
	vertex_cnt dd ? ;int
285
	vertex_max dd ? ;int
288
	vertex_max dd ? ;int
286
	vertex dd ? ;GLVertex*
289
	vertex dd ? ;GLVertex*
287
 
290
 
288
	; opengl 1.1 arrays
291
	; opengl 1.1 arrays
289
	vertex_array dd ? ;float*
292
	vertex_array dd ? ;float*
290
	vertex_array_size dd ? ;int
293
	vertex_array_size dd ? ;int
291
	vertex_array_stride dd ? ;int
294
	vertex_array_stride dd ? ;int
292
	normal_array dd ? ;float*
295
	normal_array dd ? ;float*
293
	normal_array_stride dd ? ;int
296
	normal_array_stride dd ? ;int
294
	color_array dd ? ;float*
297
	color_array dd ? ;float*
295
	color_array_size dd ? ;int
298
	color_array_size dd ? ;int
296
	color_array_stride dd ? ;int
299
	color_array_stride dd ? ;int
297
	texcoord_array dd ? ;float*
300
	texcoord_array dd ? ;float*
298
	texcoord_array_size dd ? ;int
301
	texcoord_array_size dd ? ;int
299
	texcoord_array_stride dd ? ;int
302
	texcoord_array_stride dd ? ;int
300
	client_states dd ? ;int
303
	client_states dd ? ;int
301
 
304
 
302
	; opengl 1.1 polygon offset
305
	; opengl 1.1 polygon offset
303
	offset_factor dd ? ;float
306
	offset_factor dd ? ;float
304
	offset_units dd ? ;float
307
	offset_units dd ? ;float
305
	offset_states dd ? ;int
308
	offset_states dd ? ;int
306
 
309
 
307
	; specular buffer. could probably be shared between contexts, 
310
	; specular buffer. could probably be shared between contexts, 
308
	; but that wouldn't be 100% thread safe
311
	; but that wouldn't be 100% thread safe
309
	specbuf_first dd ? ;GLSpecBuf*
312
	specbuf_first dd ? ;GLSpecBuf*
310
	specbuf_used_counter dd ? ;int
313
	specbuf_used_counter dd ? ;int
311
	specbuf_num_buffers dd ? ;int
314
	specbuf_num_buffers dd ? ;int
312
 
315
 
313
	; opaque structure for user's use
316
	; opaque structure for user's use
314
	opaque dd ? ;void*
317
	opaque dd ? ;void*
315
	; resize viewport function
318
	; resize viewport function
316
	gl_resize_viewport dd ? ;(struct GLContext *c,int *xsize,int *ysize)
319
	gl_resize_viewport dd ? ;(struct GLContext *c,int *xsize,int *ysize)
317
 
320
 
318
	; depth test
321
	; depth test
319
	depth_test dd ? ;int
322
	depth_test dd ? ;int
320
ends
323
ends
321
 
324
 
322
offs_cont_s0 equ (4 + sizeof.GLLight * MAX_LIGHTS)
325
offs_cont_s0 equ (4 + sizeof.GLLight * MAX_LIGHTS)
323
offs_cont_s1 equ (32 + offs_cont_s0 + sizeof.GLMaterial * 2)
326
offs_cont_s1 equ (32 + offs_cont_s0 + sizeof.GLMaterial * 2)
324
offs_cont_s2 equ (228 + offs_cont_s1 + sizeof.GLViewport)
327
offs_cont_s2 equ (228 + offs_cont_s1 + sizeof.GLViewport)
325
offs_cont_s3 equ (64 + offs_cont_s2 + MAX_NAME_STACK_DEPTH * 4)
328
offs_cont_s3 equ (64 + offs_cont_s2 + MAX_NAME_STACK_DEPTH * 4)
326
 
329
 
327
offs_cont_zb	      equ 0 ;ZBuffer*
330
offs_cont_zb	      equ 0 ;ZBuffer*
328
offs_cont_lights      equ 4 ;GLLight[MAX_LIGHTS]
331
offs_cont_lights      equ 4 ;GLLight[MAX_LIGHTS]
329
offs_cont_first_light equ offs_cont_s0 ;GLLight*
332
offs_cont_first_light equ offs_cont_s0 ;GLLight*
330
offs_cont_ambient_light_model  equ 4+offs_cont_s0 ;V4
333
offs_cont_ambient_light_model  equ 4+offs_cont_s0 ;V4
331
offs_cont_local_light_model    equ 20+offs_cont_s0 ;int
334
offs_cont_local_light_model    equ 20+offs_cont_s0 ;int
332
offs_cont_lighting_enabled     equ 24+offs_cont_s0 ;int
335
offs_cont_lighting_enabled     equ 24+offs_cont_s0 ;int
333
offs_cont_light_model_two_side	equ 28+offs_cont_s0 ;int
336
offs_cont_light_model_two_side	equ 28+offs_cont_s0 ;int
334
offs_cont_materials		 equ 32+offs_cont_s0 ;GLMaterial[2]
337
offs_cont_materials		 equ 32+offs_cont_s0 ;GLMaterial[2]
335
offs_cont_color_material_enabled  equ offs_cont_s1 ;int
338
offs_cont_color_material_enabled  equ offs_cont_s1 ;int
336
offs_cont_current_color_material_mode equ 4+offs_cont_s1 ;int
339
offs_cont_current_color_material_mode equ 4+offs_cont_s1 ;int
337
offs_cont_current_color_material_type equ 8+offs_cont_s1 ;int
340
offs_cont_current_color_material_type equ 8+offs_cont_s1 ;int
338
offs_cont_current_texture	  equ 12+offs_cont_s1 ;GLTexture*
341
offs_cont_current_texture	  equ 12+offs_cont_s1 ;GLTexture*
339
offs_cont_texture_2d_enabled	  equ 16+offs_cont_s1 ;int
342
offs_cont_texture_2d_enabled	  equ 16+offs_cont_s1 ;int
340
offs_cont_shared_state		  equ 20+offs_cont_s1 ;GLSharedState
343
offs_cont_shared_state		  equ 20+offs_cont_s1 ;GLSharedState
341
offs_cont_current_op_buffer	  equ 28+offs_cont_s1 ;GLParamBuffer*
344
offs_cont_current_op_buffer	  equ 28+offs_cont_s1 ;GLParamBuffer*
342
offs_cont_current_op_buffer_index equ 32+offs_cont_s1 ;int
345
offs_cont_current_op_buffer_index equ 32+offs_cont_s1 ;int
343
offs_cont_exec_flag		  equ 36+offs_cont_s1 ;int
346
offs_cont_exec_flag		  equ 36+offs_cont_s1 ;int
344
offs_cont_compile_flag		  equ 40+offs_cont_s1 ;int
347
offs_cont_compile_flag		  equ 40+offs_cont_s1 ;int
345
offs_cont_print_flag		  equ 44+offs_cont_s1 ;int
348
offs_cont_print_flag		  equ 44+offs_cont_s1 ;int
346
offs_cont_matrix_mode		  equ 48+offs_cont_s1 ;int
349
offs_cont_matrix_mode		  equ 48+offs_cont_s1 ;int
347
offs_cont_matrix_stack		  equ 52+offs_cont_s1 ;*M4[3]
350
offs_cont_matrix_stack		  equ 52+offs_cont_s1 ;*M4[3]
348
offs_cont_matrix_stack_ptr	  equ 64+offs_cont_s1 ;*M4[3]
351
offs_cont_matrix_stack_ptr	  equ 64+offs_cont_s1 ;*M4[3]
349
offs_cont_matrix_stack_depth_max  equ 76+offs_cont_s1 ;int[3]
352
offs_cont_matrix_stack_depth_max  equ 76+offs_cont_s1 ;int[3]
350
offs_cont_matrix_model_view_inv   equ 88+offs_cont_s1 ;M4
353
offs_cont_matrix_model_view_inv   equ 88+offs_cont_s1 ;M4
351
offs_cont_matrix_model_projection equ 152+offs_cont_s1 ;M4
354
offs_cont_matrix_model_projection equ 152+offs_cont_s1 ;M4
352
offs_cont_matrix_model_projection_updated equ 216+offs_cont_s1 ;int
355
offs_cont_matrix_model_projection_updated equ 216+offs_cont_s1 ;int
353
offs_cont_matrix_model_projection_no_w_transform equ 220+offs_cont_s1 ;int 
356
offs_cont_matrix_model_projection_no_w_transform equ 220+offs_cont_s1 ;int 
354
offs_cont_apply_texture_matrix	  equ 224+offs_cont_s1 ;int
357
offs_cont_apply_texture_matrix	  equ 224+offs_cont_s1 ;int
355
offs_cont_viewport		 equ 228+offs_cont_s1 ;GLViewport
358
offs_cont_viewport		 equ 228+offs_cont_s1 ;GLViewport
356
offs_cont_polygon_mode_back	equ offs_cont_s2 ;int
359
offs_cont_polygon_mode_back	equ offs_cont_s2 ;int
357
offs_cont_polygon_mode_front   equ 4+offs_cont_s2 ;int
360
offs_cont_polygon_mode_front   equ 4+offs_cont_s2 ;int
358
offs_cont_current_front_face   equ 8+offs_cont_s2 ;int
361
offs_cont_current_front_face   equ 8+offs_cont_s2 ;int
359
offs_cont_current_shade_model  equ 12+offs_cont_s2 ;int
362
offs_cont_current_shade_model  equ 12+offs_cont_s2 ;int
360
offs_cont_current_cull_face    equ 16+offs_cont_s2 ;int
363
offs_cont_current_cull_face    equ 16+offs_cont_s2 ;int
361
offs_cont_cull_face_enabled    equ 20+offs_cont_s2 ;int
364
offs_cont_cull_face_enabled    equ 20+offs_cont_s2 ;int
362
offs_cont_normalize_enabled    equ 24+offs_cont_s2 ;int
365
offs_cont_normalize_enabled    equ 24+offs_cont_s2 ;int
363
offs_cont_draw_triangle_front  equ 28+offs_cont_s2 ;gl_draw_triangle_func
366
offs_cont_draw_triangle_front  equ 28+offs_cont_s2 ;gl_draw_triangle_func
364
offs_cont_draw_triangle_back   equ 32+offs_cont_s2 ;gl_draw_triangle_func
367
offs_cont_draw_triangle_back   equ 32+offs_cont_s2 ;gl_draw_triangle_func
365
offs_cont_render_mode	       equ 36+offs_cont_s2 ;int
368
offs_cont_render_mode	       equ 36+offs_cont_s2 ;int
366
offs_cont_select_buffer        equ 40+offs_cont_s2 ;unsigned int*
369
offs_cont_select_buffer        equ 40+offs_cont_s2 ;unsigned int*
367
offs_cont_select_size	       equ 44+offs_cont_s2 ;int
370
offs_cont_select_size	       equ 44+offs_cont_s2 ;int
368
offs_cont_select_ptr	       equ 48+offs_cont_s2 ;unsigned int*
371
offs_cont_select_ptr	       equ 48+offs_cont_s2 ;unsigned int*
369
offs_cont_select_hit	       equ 52+offs_cont_s2 ;unsigned int*
372
offs_cont_select_hit	       equ 52+offs_cont_s2 ;unsigned int*
370
offs_cont_select_overflow      equ 56+offs_cont_s2 ;int
373
offs_cont_select_overflow      equ 56+offs_cont_s2 ;int
371
offs_cont_select_hits	       equ 60+offs_cont_s2 ;int
374
offs_cont_select_hits	       equ 60+offs_cont_s2 ;int
372
offs_cont_name_stack	       equ 64+offs_cont_s2 ;unsigned int[MAX_NAME_STACK_DEPTH]
375
offs_cont_name_stack	       equ 64+offs_cont_s2 ;unsigned int[MAX_NAME_STACK_DEPTH]
373
offs_cont_name_stack_size     equ offs_cont_s3 ;int
376
offs_cont_name_stack_size     equ offs_cont_s3 ;int
374
offs_cont_clear_depth	     equ 4+offs_cont_s3 ;float
377
offs_cont_clear_depth	     equ 4+offs_cont_s3 ;float
375
offs_cont_clear_color	    equ 8+offs_cont_s3 ;V4
378
offs_cont_clear_color	    equ 8+offs_cont_s3 ;V4
376
offs_cont_current_color     equ 24+offs_cont_s3 ;V4
379
offs_cont_current_color     equ 24+offs_cont_s3 ;V4
377
offs_cont_longcurrent_color equ 40+offs_cont_s3 ;unsigned int[3]
380
offs_cont_longcurrent_color equ 40+offs_cont_s3 ;unsigned int[3]
378
offs_cont_current_normal    equ 52+offs_cont_s3 ;V4
381
offs_cont_current_normal    equ 52+offs_cont_s3 ;V4
379
offs_cont_current_tex_coord equ 68+offs_cont_s3 ;V4
382
offs_cont_current_tex_coord equ 68+offs_cont_s3 ;V4
380
offs_cont_current_edge_flag equ 84+offs_cont_s3 ;int
383
offs_cont_current_edge_flag equ 84+offs_cont_s3 ;int
381
offs_cont_in_begin	    equ 88+offs_cont_s3 ;int
384
offs_cont_in_begin	    equ 88+offs_cont_s3 ;int
382
offs_cont_begin_type	    equ 92+offs_cont_s3 ;int
385
offs_cont_begin_type	    equ 92+offs_cont_s3 ;int
383
offs_cont_vertex_n	    equ 96+offs_cont_s3 ;int
386
offs_cont_vertex_n	    equ 96+offs_cont_s3 ;int
384
offs_cont_vertex_cnt	    equ 100+offs_cont_s3 ;int
387
offs_cont_vertex_cnt	    equ 100+offs_cont_s3 ;int
385
offs_cont_vertex_max	    equ 104+offs_cont_s3 ;int
388
offs_cont_vertex_max	    equ 104+offs_cont_s3 ;int
386
offs_cont_vertex	    equ 108+offs_cont_s3 ;GLVertex*
389
offs_cont_vertex	    equ 108+offs_cont_s3 ;GLVertex*
387
offs_cont_vertex_array	    equ 112+offs_cont_s3 ;float*
390
offs_cont_vertex_array	    equ 112+offs_cont_s3 ;float*
388
offs_cont_vertex_array_size  equ 116+offs_cont_s3 ;int
391
offs_cont_vertex_array_size  equ 116+offs_cont_s3 ;int
389
offs_cont_vertex_array_stride equ 120+offs_cont_s3 ;int
392
offs_cont_vertex_array_stride equ 120+offs_cont_s3 ;int
390
offs_cont_normal_array	      equ 124+offs_cont_s3 ;float*
393
offs_cont_normal_array	      equ 124+offs_cont_s3 ;float*
391
offs_cont_normal_array_stride equ 128+offs_cont_s3 ;int
394
offs_cont_normal_array_stride equ 128+offs_cont_s3 ;int
392
offs_cont_color_array	      equ 132+offs_cont_s3 ;float*
395
offs_cont_color_array	      equ 132+offs_cont_s3 ;float*
393
offs_cont_color_array_size    equ 136+offs_cont_s3 ;int
396
offs_cont_color_array_size    equ 136+offs_cont_s3 ;int
394
offs_cont_color_array_stride  equ 140+offs_cont_s3 ;int
397
offs_cont_color_array_stride  equ 140+offs_cont_s3 ;int
395
offs_cont_texcoord_array      equ 144+offs_cont_s3 ;float*
398
offs_cont_texcoord_array      equ 144+offs_cont_s3 ;float*
396
offs_cont_texcoord_array_size  equ 148+offs_cont_s3 ;int
399
offs_cont_texcoord_array_size  equ 148+offs_cont_s3 ;int
397
offs_cont_texcoord_array_stride equ 152+offs_cont_s3 ;int
400
offs_cont_texcoord_array_stride equ 152+offs_cont_s3 ;int
398
offs_cont_client_states        equ 156+offs_cont_s3 ;int
401
offs_cont_client_states        equ 156+offs_cont_s3 ;int
399
offs_cont_offset_factor        equ 160+offs_cont_s3 ;float
402
offs_cont_offset_factor        equ 160+offs_cont_s3 ;float
400
offs_cont_offset_units	       equ 164+offs_cont_s3 ;float
403
offs_cont_offset_units	       equ 164+offs_cont_s3 ;float
401
offs_cont_offset_states        equ 168+offs_cont_s3 ;int
404
offs_cont_offset_states        equ 168+offs_cont_s3 ;int
402
offs_cont_specbuf_first        equ 172+offs_cont_s3 ;GLSpecBuf*
405
offs_cont_specbuf_first        equ 172+offs_cont_s3 ;GLSpecBuf*
403
offs_cont_specbuf_used_counter equ 176+offs_cont_s3 ;int
406
offs_cont_specbuf_used_counter equ 176+offs_cont_s3 ;int
404
offs_cont_specbuf_num_buffers  equ 180+offs_cont_s3 ;int
407
offs_cont_specbuf_num_buffers  equ 180+offs_cont_s3 ;int
405
offs_cont_opaque	           equ 184+offs_cont_s3 ;void*
408
offs_cont_opaque	           equ 184+offs_cont_s3 ;void*
406
offs_cont_gl_resize_viewport   equ 188+offs_cont_s3 ;(struct GLContext *c,int *xsize,int *ysize)
409
offs_cont_gl_resize_viewport   equ 188+offs_cont_s3 ;(struct GLContext *c,int *xsize,int *ysize)
407
offs_cont_depth_test	       equ 192+offs_cont_s3 ;int
410
offs_cont_depth_test	       equ 192+offs_cont_s3 ;int
408
 
411
 
409
align 16
412
align 16
410
gl_ctx dd ? ;extern GLContext*
413
gl_ctx dd ? ;extern GLContext*
411
 
414
 
412
align 16
415
align 16
413
proc gl_get_context
416
proc gl_get_context
414
	mov eax,[gl_ctx]
417
	mov eax,[gl_ctx]
415
	ret
418
	ret
416
endp
419
endp
417
 
420
 
418
; this clip epsilon is needed to avoid some rounding errors after
421
; this clip epsilon is needed to avoid some rounding errors after
419
; several clipping stages
422
; several clipping stages
420
 
423
 
421
CLIP_EPSILON dd 1.0e-5
424
CLIP_EPSILON dd 1.0e-5
422
 
425
 
423
align 4
426
align 4
424
proc gl_clipcode uses ebx, x:dword, y:dword, z:dword, w1:dword
427
proc gl_clipcode uses ebx, x:dword, y:dword, z:dword, w1:dword
425
	xor ebx,ebx
428
	xor ebx,ebx
426
 
429
 
427
	;ffree st0
430
	;ffree st0
428
	;fincstp
431
	;fincstp
429
	fld1
432
	fld1
430
	fadd dword[CLIP_EPSILON]
433
	fadd dword[CLIP_EPSILON]
431
	fmul dword[w1]
434
	fmul dword[w1]
432
 
435
 
433
	fcom dword[x]
436
	fcom dword[x]
434
	fstsw ax
437
	fstsw ax
435
	sahf
438
	sahf
436
	ja @f
439
	ja @f
437
		or ebx,2
440
		or ebx,2
438
	@@:
441
	@@:
439
	fcom dword[y]
442
	fcom dword[y]
440
	fstsw ax
443
	fstsw ax
441
	sahf
444
	sahf
442
	ja @f
445
	ja @f
443
		or ebx,8
446
		or ebx,8
444
	@@:
447
	@@:
445
	fcom dword[z]
448
	fcom dword[z]
446
	fstsw ax
449
	fstsw ax
447
	sahf
450
	sahf
448
	ja @f
451
	ja @f
449
		or ebx,32
452
		or ebx,32
450
	@@:
453
	@@:
451
 
454
 
452
	fchs
455
	fchs
453
	fcom dword[x]
456
	fcom dword[x]
454
	fstsw ax
457
	fstsw ax
455
	sahf
458
	sahf
456
	jbe @f
459
	jbe @f
457
		or ebx,1
460
		or ebx,1
458
	@@:
461
	@@:
459
	fcom dword[y]
462
	fcom dword[y]
460
	fstsw ax
463
	fstsw ax
461
	sahf
464
	sahf
462
	jbe @f
465
	jbe @f
463
		or ebx,4
466
		or ebx,4
464
	@@:
467
	@@:
465
	fcom dword[z]
468
	fcom dword[z]
466
	fstsw ax
469
	fstsw ax
467
	sahf
470
	sahf
468
	jbe @f
471
	jbe @f
469
		or ebx,16
472
		or ebx,16
470
	@@:
473
	@@:
471
 
474
 
472
	mov eax,ebx
475
	mov eax,ebx
473
if DEBUG ;gl_clipcode
476
if DEBUG ;gl_clipcode
474
push edi
477
push edi
475
	mov ecx,80
478
	mov ecx,80
476
	lea edi,[buf_param]
479
	lea edi,[buf_param]
477
	stdcall convert_int_to_str,ecx
480
	stdcall convert_int_to_str,ecx
478
	stdcall str_n_cat,edi,txt_nl,2
481
	stdcall str_n_cat,edi,txt_nl,2
479
	stdcall dbg_print,f_clipcode,buf_param
482
	stdcall dbg_print,f_clipcode,buf_param
480
pop edi
483
pop edi
481
end if
484
end if
482
	ret
485
	ret
483
endp
486
endp
484
 
487
 
485
;input:
488
;input:
486
; rf,gf,bf - значения float
489
; rf,gf,bf - значения float
487
; ri,gi,bi - адреса куда будут записаны rf,gf,bf преобразованые в int
490
; ri,gi,bi - адреса куда будут записаны rf,gf,bf преобразованые в int
488
align 4
491
align 4
489
proc RGBFtoRGBI uses eax, rf:dword,gf:dword,bf:dword, ri:dword,gi:dword,bi:dword
492
proc RGBFtoRGBI uses eax, rf:dword,gf:dword,bf:dword, ri:dword,gi:dword,bi:dword
490
locals
493
locals
491
	s dd ?
494
	s dd ?
492
endl
495
endl
493
	mov dword[s],(ZB_POINT_RED_MAX - ZB_POINT_RED_MIN)
496
	mov dword[s],(ZB_POINT_RED_MAX - ZB_POINT_RED_MIN)
494
	fild dword[s]
497
	fild dword[s]
495
	fmul dword[rf]
498
	fmul dword[rf]
496
	mov eax,[ri]
499
	mov eax,[ri]
497
	fistp dword[eax]
500
	fistp dword[eax]
498
	add dword[eax],ZB_POINT_RED_MIN
501
	add dword[eax],ZB_POINT_RED_MIN
499
 
502
 
500
	mov dword[s],(ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN)
503
	mov dword[s],(ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN)
501
	fild dword[s]
504
	fild dword[s]
502
	fmul dword[gf]
505
	fmul dword[gf]
503
	mov eax,[gi]
506
	mov eax,[gi]
504
	fistp dword[eax]
507
	fistp dword[eax]
505
	add dword[eax],ZB_POINT_GREEN_MIN
508
	add dword[eax],ZB_POINT_GREEN_MIN
506
 
509
 
507
	;bi = (unsigned int) (bf * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) + ZB_POINT_BLUE_MIN);
510
	;bi = (unsigned int) (bf * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) + ZB_POINT_BLUE_MIN);
508
	mov dword[s],(ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN)
511
	mov dword[s],(ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN)
509
	fild dword[s]
512
	fild dword[s]
510
	fmul dword[bf]
513
	fmul dword[bf]
511
	mov eax,[bi]
514
	mov eax,[bi]
512
	fistp dword[eax]
515
	fistp dword[eax]
513
	add dword[eax],ZB_POINT_BLUE_MIN
516
	add dword[eax],ZB_POINT_BLUE_MIN
514
	ret
517
	ret
515
endp
518
endp