Subversion Repositories Kolibri OS

Rev

Rev 5256 | Rev 6108 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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