Subversion Repositories Kolibri OS

Rev

Rev 6243 | Rev 8063 | 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
6108 IgorA 34
MAX_NAME_STACK_DEPTH equ 64
35
MAX_TEXTURE_LEVELS   equ 11
36
MAX_LIGHTS equ 16
5153 IgorA 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
6243 IgorA 172
	xsize_log2 dd ? ;unsigned int
173
	s_bound dd ? ;unsigned int
174
	t_bound dd ? ;unsigned int
5153 IgorA 175
ends
176
 
177
offs_imag_pixmap equ 0
6108 IgorA 178
offs_imag_xsize equ 4
179
offs_imag_ysize equ 8
6243 IgorA 180
offs_imag_xsize_log2 equ 12
181
offs_imag_s_bound equ 16
182
offs_imag_t_bound equ 20
5153 IgorA 183
 
184
; textures
185
 
186
TEXTURE_HASH_TABLE_SIZE equ 256 ;должно быть кратное 2, в коде берется остаток от деления (через and быстрее чем div)
187
 
188
struct GLTexture
189
	images rb sizeof.GLImage * MAX_TEXTURE_LEVELS ;GLImage[MAX_TEXTURE_LEVELS]
190
	handle dd ? ;int
191
	next dd ? ;struct GLTexture*
192
	prev dd ? ;struct GLTexture*
193
ends
194
 
195
offs_text_images equ 0
196
offs_text_handle equ sizeof.GLImage*MAX_TEXTURE_LEVELS
197
offs_text_next equ 4+offs_text_handle
198
offs_text_prev equ 8+offs_text_handle
199
 
200
; shared state
201
 
202
struct GLSharedState
203
	lists dd ? ;GLList**
204
	texture_hash_table dd ? ;GLTexture**
205
ends
206
 
207
 
208
; display context
209
 
210
struct GLContext
211
	; Z buffer
212
	zb dd ? ;ZBuffer*
213
 
214
	; lights
215
	lights rb sizeof.GLLight * MAX_LIGHTS ;GLLight[MAX_LIGHTS]
216
	first_light dd ? ;GLLight*
217
	ambient_light_model V4
218
	local_light_model dd ? ;int
219
	lighting_enabled dd ? ;int
220
	light_model_two_side dd ? ;int
221
 
222
	; materials
223
	materials rb sizeof.GLMaterial * 2 ;GLMaterial[2]
224
	color_material_enabled dd ? ;int
225
	current_color_material_mode dd ? ;int
226
	current_color_material_type dd ? ;int
227
 
228
	; textures
229
	current_texture dd ? ;GLTexture*
230
	texture_2d_enabled dd ? ;int
231
 
232
	; shared state
233
	shared_state GLSharedState
234
 
235
	; current list
236
	current_op_buffer dd ? ;GLParamBuffer*
237
	current_op_buffer_index dd ? ;int
238
	exec_flag dd ? ;int
239
	compile_flag dd ? ;int
240
	print_flag dd ? ;int
241
 
242
	; matrix
243
 
244
	matrix_mode dd ? ;int режим активного вида матрицы (один из 3-х: GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE)
245
	matrix_stack rd 3 ;*M4[3] указатель на начало массива матриц
246
	matrix_stack_ptr rd 3 ;*M4[3] указатель на активную матрицу из массива
247
	matrix_stack_depth_max rd 3 ;int[3] максимальное число матриц в массивах matrix_stack
248
 
249
	matrix_model_view_inv M4
250
	matrix_model_projection M4
251
	matrix_model_projection_updated dd ? ;int
252
	matrix_model_projection_no_w_transform dd ? ;int
253
	apply_texture_matrix dd ? ;int
254
 
255
	; viewport
256
	viewport GLViewport
257
 
258
	; current state
259
	polygon_mode_back dd ? ;int
260
	polygon_mode_front dd ? ;int
261
 
262
	current_front_face dd ? ;int
263
	current_shade_model dd ? ;int
264
	current_cull_face dd ? ;int
265
	cull_face_enabled dd ? ;int
266
	normalize_enabled dd ? ;int
267
	draw_triangle_front dd ? ;gl_draw_triangle_func
268
	draw_triangle_back  dd ? ;gl_draw_triangle_func
269
 
270
	; selection
271
	render_mode dd ? ;int
272
	select_buffer dd ? ;unsigned int*
273
	select_size dd ? ;int
274
	select_ptr dd ? ;unsigned int*
275
	select_hit dd ? ;unsigned int*
276
	select_overflow dd ? ;int
277
	select_hits dd ? ;int
278
 
279
	; names
280
	name_stack rd MAX_NAME_STACK_DEPTH ;unsigned int[MAX_NAME_STACK_DEPTH]
281
	name_stack_size dd ? ;int
282
 
283
	; clear
284
	clear_depth dd ? ;float
285
	clear_color V4
286
 
287
	; current vertex state
288
	current_color V4
289
	longcurrent_color rd 3 ;unsigned int[3] ;precomputed integer color
290
	current_normal V4
291
	current_tex_coord V4
292
	current_edge_flag dd ? ;int
293
 
294
	; glBegin / glEnd
295
	in_begin dd ? ;int
296
	begin_type dd ? ;int
297
	vertex_n dd ? ;int
298
	vertex_cnt dd ? ;int
299
	vertex_max dd ? ;int
300
	vertex dd ? ;GLVertex*
301
 
302
	; opengl 1.1 arrays
303
	vertex_array dd ? ;float*
304
	vertex_array_size dd ? ;int
305
	vertex_array_stride dd ? ;int
306
	normal_array dd ? ;float*
307
	normal_array_stride dd ? ;int
308
	color_array dd ? ;float*
309
	color_array_size dd ? ;int
310
	color_array_stride dd ? ;int
311
	texcoord_array dd ? ;float*
312
	texcoord_array_size dd ? ;int
313
	texcoord_array_stride dd ? ;int
314
	client_states dd ? ;int
315
 
316
	; opengl 1.1 polygon offset
317
	offset_factor dd ? ;float
318
	offset_units dd ? ;float
319
	offset_states dd ? ;int
320
 
321
	; specular buffer. could probably be shared between contexts,
322
	; but that wouldn't be 100% thread safe
323
	specbuf_first dd ? ;GLSpecBuf*
324
	specbuf_used_counter dd ? ;int
325
	specbuf_num_buffers dd ? ;int
326
 
327
	; opaque structure for user's use
328
	opaque dd ? ;void*
329
	; resize viewport function
330
	gl_resize_viewport dd ? ;(struct GLContext *c,int *xsize,int *ysize)
331
 
332
	; depth test
333
	depth_test dd ? ;int
334
ends
335
 
336
align 16
337
gl_ctx dd ? ;extern GLContext*
338
 
339
align 16
340
proc gl_get_context
341
	mov eax,[gl_ctx]
342
	ret
343
endp
344
 
345
; this clip epsilon is needed to avoid some rounding errors after
346
; several clipping stages
347
 
348
CLIP_EPSILON dd 1.0e-5
349
 
350
align 4
351
proc gl_clipcode uses ebx, x:dword, y:dword, z:dword, w1:dword
352
	xor ebx,ebx
353
 
354
	fld1
355
	fadd dword[CLIP_EPSILON]
356
	fmul dword[w1]
357
 
358
	fcom dword[x]
359
	fstsw ax
360
	sahf
361
	ja @f
362
		or ebx,2
363
	@@:
364
	fcom dword[y]
365
	fstsw ax
366
	sahf
367
	ja @f
368
		or ebx,8
369
	@@:
370
	fcom dword[z]
371
	fstsw ax
372
	sahf
373
	ja @f
374
		or ebx,32
375
	@@:
376
 
377
	fchs
378
	fcom dword[x]
379
	fstsw ax
380
	sahf
381
	jbe @f
382
		or ebx,1
383
	@@:
384
	fcom dword[y]
385
	fstsw ax
386
	sahf
387
	jbe @f
388
		or ebx,4
389
	@@:
390
	fcom dword[z]
391
	fstsw ax
392
	sahf
393
	jbe @f
394
		or ebx,16
395
	@@:
396
 
5208 IgorA 397
	ffree st0
398
	fincstp
399
 
5153 IgorA 400
	mov eax,ebx
401
	ret
402
endp
403
 
404
;input:
405
; rf,gf,bf - значения float
406
; ri,gi,bi - адреса куда будут записаны rf,gf,bf преобразованые в int
407
align 4
408
proc RGBFtoRGBI uses eax, rf:dword,gf:dword,bf:dword, ri:dword,gi:dword,bi:dword
409
locals
410
	s dd ?
411
endl
412
	mov dword[s],(ZB_POINT_RED_MAX - ZB_POINT_RED_MIN)
413
	fild dword[s]
414
	fmul dword[rf]
415
	mov eax,[ri]
416
	fistp dword[eax]
417
	add dword[eax],ZB_POINT_RED_MIN
418
 
419
	mov dword[s],(ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN)
420
	fild dword[s]
421
	fmul dword[gf]
422
	mov eax,[gi]
423
	fistp dword[eax]
424
	add dword[eax],ZB_POINT_GREEN_MIN
425
 
426
	;bi = (unsigned int) (bf * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) + ZB_POINT_BLUE_MIN);
427
	mov dword[s],(ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN)
428
	fild dword[s]
429
	fmul dword[bf]
430
	mov eax,[bi]
431
	fistp dword[eax]
432
	add dword[eax],ZB_POINT_BLUE_MIN
433
	ret
434
endp