Subversion Repositories Kolibri OS

Rev

Rev 8063 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5153 IgorA 1
;строки с именами функций
2
op_table_str:
3
macro ADD_OP a,b,c
4
{
5
	db 'gl',`a,' ',c,0
6
}
7
include 'opinfo.inc'
8
 
9
;указатели на функции ;static void (*op_table_func[])(GLContext *,GLParam *)=
8063 IgorA 10
align 4
5153 IgorA 11
op_table_func:
12
macro ADD_OP a,b,c
13
{
14
	dd glop#a
15
}
16
include 'opinfo.inc'
17
 
18
;число параметров в функциях
8063 IgorA 19
align 4
5153 IgorA 20
op_table_size:
21
macro ADD_OP a,b,c
22
{
23
	dd b+1
24
}
25
include 'opinfo.inc'
26
 
8063 IgorA 27
;коды функций у которых нет входных параметров
28
align 4
29
macro ADD_OP a,b,c
30
{
31
if b eq 0
32
	op_#a dd OP_#a
33
end if
34
}
35
include 'opinfo.inc'
5153 IgorA 36
 
8063 IgorA 37
 
5153 IgorA 38
;output:
39
; eax = context.shared_state.lists[list]
40
align 4
41
proc find_list uses ebx, context:dword, list:dword
42
	mov eax,[context]
6523 IgorA 43
	mov eax,[eax+GLContext.shared_state]
5153 IgorA 44
	mov ebx,[list]
8063 IgorA 45
	lea eax,[eax+4*ebx]
5153 IgorA 46
	mov eax,[eax]
47
	ret
48
endp
49
 
5171 IgorA 50
align 4
51
proc delete_list uses eax ebx ecx edx, context:dword, list:dword
52
	mov ebx,[context]
53
	stdcall find_list,ebx,[list]
54
	mov edx,eax
5153 IgorA 55
;  assert(l != NULL);
56
 
5171 IgorA 57
	; free param buffer
58
	mov eax,[edx] ;eax = GLList.first_op_buffer
59
	@@:
60
	cmp eax,0
61
	je .end_w
62
		mov ecx,[eax+offs_gpbu_next]
63
		stdcall gl_free,eax
64
		mov eax,ecx
65
		jmp @b
66
	.end_w:
5153 IgorA 67
 
5171 IgorA 68
	stdcall gl_free,edx
8063 IgorA 69
	mov ebx,[ebx+GLContext.shared_state] ;ebx = &context.shared_state.lists
5171 IgorA 70
	mov ecx,[list]
8063 IgorA 71
	lea ebx,[ebx+4*ecx]
5171 IgorA 72
	mov dword[ebx],0 ;=NULL
73
	ret
74
endp
5153 IgorA 75
 
5171 IgorA 76
align 4
77
proc alloc_list uses ebx ecx, context:dword, list:dword
78
	stdcall gl_zalloc,sizeof.GLParamBuffer
79
	mov ecx,eax
80
	stdcall gl_zalloc,sizeof.GLList
5153 IgorA 81
 
5171 IgorA 82
	mov dword[ecx+offs_gpbu_next],0 ;ob.next=NULL
83
	mov dword[eax],ecx ;l.first_op_buffer=ob
5153 IgorA 84
 
5171 IgorA 85
	mov dword[ecx+offs_gpbu_ops],OP_EndList ;ob.ops[0].op=OP_EndList
5153 IgorA 86
 
5171 IgorA 87
	mov ebx,[context]
6523 IgorA 88
	mov ebx,[ebx+GLContext.shared_state]
5171 IgorA 89
	mov ecx,[list]
8063 IgorA 90
	lea ebx,[ebx+4*ecx]
5171 IgorA 91
	mov [ebx],eax ;context.shared_state.lists[list]=l
92
	ret
93
endp
5153 IgorA 94
 
95
;void gl_print_op(FILE *f,GLParam *p)
96
;{
97
;  int op;
98
;  char *s;
99
 
100
;  op=p[0].op;
101
;  p++;
102
;  s=op_table_str[op];
103
;  while (*s != 0) {
104
;    if (*s == '%') {
105
;      s++;
106
;      switch (*s++) {
107
;      case 'f':
108
;       fprintf(f,"%g",p[0].f);
109
;       break;
110
;      default:
111
;       fprintf(f,"%d",p[0].i);
112
;       break;
113
;      }
114
;      p++;
115
;    } else {
116
;      fputc(*s,f);
117
;      s++;
118
;    }
119
;  }
120
;  fprintf(f,"\n");
121
;}
122
 
123
align 4
5171 IgorA 124
proc gl_compile_op, context:dword, p:dword
125
pushad
126
	mov edx,[context]
5153 IgorA 127
 
5171 IgorA 128
	mov ecx,[p]
8063 IgorA 129
	mov ecx,[ecx] ;код операции
130
	lea ecx,[op_table_size+4*ecx]
5171 IgorA 131
	mov ecx,[ecx] ;ecx = кол-во параметров в компилируемой функции
6523 IgorA 132
	mov ebx,[edx+GLContext.current_op_buffer_index]
133
	mov eax,[edx+GLContext.current_op_buffer]
5153 IgorA 134
 
5171 IgorA 135
	; we should be able to add a NextBuffer opcode
8063 IgorA 136
	lea esi,[ebx+ecx]
5171 IgorA 137
	cmp esi,(OP_BUFFER_MAX_SIZE-2)
138
	jle @f
139
		mov edi,eax
140
		stdcall gl_zalloc,sizeof.GLParamBuffer
141
		mov dword[eax+offs_gpbu_next],0 ;=NULL
5153 IgorA 142
 
5171 IgorA 143
		mov dword[edi+offs_gpbu_next],eax
8063 IgorA 144
		lea esi,[edi+4*ebx]
5171 IgorA 145
		mov dword[esi+offs_gpbu_ops],OP_NextBuffer
146
		mov dword[esi+offs_gpbu_ops+4],eax
5153 IgorA 147
 
6523 IgorA 148
		mov dword[edx+GLContext.current_op_buffer],eax
5171 IgorA 149
		xor ebx,ebx
150
	@@:
5153 IgorA 151
 
5171 IgorA 152
	mov esi,[p]
153
	@@:
8063 IgorA 154
		lea edi,[eax+4*ebx]
5171 IgorA 155
		movsd
156
		inc ebx
157
	loop @b
6523 IgorA 158
	mov dword[edx+GLContext.current_op_buffer_index],ebx
5171 IgorA 159
popad
5153 IgorA 160
	ret
161
endp
162
 
163
align 4
164
proc gl_add_op uses eax ebx ecx, p:dword ;GLParam*
5171 IgorA 165
if DEBUG ;gl_add_op
5153 IgorA 166
push edi esi
167
	mov ebx,[p]
168
	mov ebx,[ebx]
169
	lea eax,[op_table_str]
170
	@@:
171
		cmp ebx,0
172
		je @f
173
		cmp byte[eax],0
174
		jne .no_dec
175
			dec ebx
176
		.no_dec:
177
		inc eax
178
		jmp @b
179
	@@:
180
	stdcall dbg_print,eax,txt_nl
181
 
182
	mov esi,eax
183
	mov word[NumberSymbolsAD],3
184
	mov ebx,[p]
185
	lea edi,[buf_param]
186
	mov byte[edi],0
187
	mov ecx,80
188
	.cycle_0:
189
		cmp byte[esi],'%'
190
		jne .no_param
191
			cmp ebx,[p]
192
			je @f
193
				stdcall str_n_cat,edi,txt_zp_sp,2
194
				stdcall str_len,edi
195
				add edi,eax
196
			@@:
197
			add ebx,4
198
			inc esi
199
 
200
			cmp byte[esi],'f'
201
			jne @f
202
				fld dword[ebx]
203
				fstp qword[Data_Double]
204
				call DoubleFloat_to_String
205
				stdcall str_cat, edi,Data_String
206
			@@:
207
			cmp byte[esi],'d'
208
			jne @f
209
				stdcall str_len,edi
210
				add edi,eax
211
				sub ecx,eax
212
				mov eax,dword[ebx]
213
				stdcall convert_int_to_str,ecx
214
			@@:
215
		.no_param:
216
		inc esi
217
		cmp byte[esi],0
218
		jne .cycle_0
219
	stdcall str_cat, edi,txt_nl
220
	stdcall dbg_print,txt_sp,buf_param
221
pop esi edi
222
end if
223
	call gl_get_context
224
	mov ebx,[p]
225
 
6523 IgorA 226
	cmp dword[eax+GLContext.exec_flag],0
5153 IgorA 227
	je @f
228
		push ebx
229
		push eax
230
		mov ecx,dword[ebx] ;ecx = OP_...
231
		shl ecx,2
232
		lea ebx,[op_table_func]
233
		add ecx,ebx
234
		call dword[ecx] ;op_table_func[op](c,p)
235
	@@:
5171 IgorA 236
	call gl_get_context
6523 IgorA 237
	cmp dword[eax+GLContext.compile_flag],0
5153 IgorA 238
	je @f
239
		stdcall gl_compile_op,eax,[p]
240
	@@:
6523 IgorA 241
	cmp dword[eax+GLContext.print_flag],0
5153 IgorA 242
	je @f
243
		;gl_print_op(stderr,p);
244
	@@:
245
	ret
246
endp
247
 
248
; this opcode is never called directly
249
align 4
250
proc glopEndList, context:dword, p:dword
251
;  assert(0);
252
	ret
253
endp
254
 
255
; this opcode is never called directly
256
align 4
257
proc glopNextBuffer, context:dword, p:dword
258
;  assert(0);
259
	ret
260
endp
261
 
5171 IgorA 262
align 4
263
proc glopCallList uses eax ebx ecx edx edi, context:dword, p:dword
264
	mov edx,[context]
265
	mov ebx,[p]
5153 IgorA 266
 
5171 IgorA 267
	stdcall find_list,edx,[ebx+4]
6108 IgorA 268
	or eax,eax
269
	jnz @f
270
		;gl_fatal_error("list %d not defined",[ebx+4])
5171 IgorA 271
	@@:
272
	mov edi,[eax] ;edi = &GLList.first_op_buffer.ops
5153 IgorA 273
 
5171 IgorA 274
align 4
275
	.cycle_0: ;while (1)
276
	cmp dword[edi],OP_EndList
277
	je .end_f ;if (op == OP_EndList) break
278
	cmp dword[edi],OP_NextBuffer
279
	jne .els_0 ;if (op == OP_NextBuffer)
280
		mov edi,[edi+4] ;p=p[1].p
281
		jmp .cycle_0
282
	.els_0:
283
		mov ecx,dword[edi] ;ecx = OP_...
284
		shl ecx,2
285
		lea ebx,[op_table_func]
286
		add ecx,ebx
287
		stdcall dword[ecx],edx,edi ;op_table_func[op](context,p)
288
 
289
		mov ecx,dword[edi] ;ecx = OP_...
290
		shl ecx,2
291
		lea ebx,[op_table_size]
292
		add ecx,ebx
293
		mov ecx,[ecx]
294
		shl ecx,2
295
		add edi,ecx ;edi += op_table_size[op]
296
	jmp .cycle_0
297
	.end_f:
298
	ret
299
endp
300
 
301
align 4
302
proc glNewList uses eax ebx, list:dword, mode:dword
303
	call gl_get_context
304
	mov ebx,eax
305
 
5153 IgorA 306
;  assert(mode == GL_COMPILE || mode == GL_COMPILE_AND_EXECUTE);
5171 IgorA 307
;  assert(ebx->compile_flag == 0);
5153 IgorA 308
 
5171 IgorA 309
	stdcall find_list,ebx,[list]
310
	cmp eax,0
311
	je @f
312
		stdcall delete_list,ebx,[list]
313
	@@:
314
	stdcall alloc_list,ebx,[list]
5153 IgorA 315
 
5171 IgorA 316
	mov eax,[eax] ;eax = GLList.first_op_buffer
6523 IgorA 317
	mov [ebx+GLContext.current_op_buffer],eax
318
	mov dword[ebx+GLContext.current_op_buffer_index],0
5171 IgorA 319
 
6523 IgorA 320
	mov dword[ebx+GLContext.compile_flag],1
5171 IgorA 321
	xor eax,eax
322
	cmp dword[mode],GL_COMPILE_AND_EXECUTE
323
	jne @f
324
		inc eax ;eax = (mode == GL_COMPILE_AND_EXECUTE)
325
	@@:
6523 IgorA 326
	mov [ebx+GLContext.exec_flag],eax
5171 IgorA 327
	ret
328
endp
329
 
330
align 4
8069 IgorA 331
proc glEndList uses eax
5171 IgorA 332
	call gl_get_context
333
 
5153 IgorA 334
;  assert(c->compile_flag == 1);
335
 
5171 IgorA 336
	; end of list
8069 IgorA 337
	stdcall gl_compile_op,eax,op_EndList
5153 IgorA 338
 
6523 IgorA 339
	mov dword[eax+GLContext.compile_flag],0
340
	mov dword[eax+GLContext.exec_flag],1
5171 IgorA 341
	ret
342
endp
5153 IgorA 343
 
344
;output:
345
; eax = (find_list(gl_get_context,list) != NULL)
346
align 4
347
proc glIsList, list:dword
348
	call gl_get_context
349
	stdcall find_list, eax,[list]
350
	cmp eax,0 ;NULL
351
	je @f
352
		mov eax,1
353
	@@:
354
	ret
355
endp
356
 
5171 IgorA 357
align 4
358
proc glGenLists uses ebx ecx edx edi esi, range:dword
359
	call gl_get_context
360
	mov edi,eax
5153 IgorA 361
 
6523 IgorA 362
	mov ebx,[eax+GLContext.shared_state] ;ebx=context.shared_state.lists
5171 IgorA 363
	xor edx,edx ;count=0
364
	mov ecx,MAX_DISPLAY_LISTS
365
	xor esi,esi
366
	.cycle_0: ;for(esi=0;esi
367
		cmp dword[ebx],0 ;if (ebx[i]==NULL)
5412 IgorA 368
		jne .els_0
5171 IgorA 369
			inc edx
370
			cmp edx,[range] ;if (count == range)
371
			jne .els_1
372
			mov ecx,[range]
373
			inc esi
374
			sub esi,ecx ;esi = (esi-range+1)
375
			.cycle_1: ;for(i=0;i
376
				stdcall alloc_list,edi,esi
377
				inc esi
378
			loop .cycle_1
379
			mov eax,esi
380
			jmp .end_f
381
		.els_0:
382
			xor edx,edx ;count=0
383
		.els_1:
384
		add ebx,4
385
		inc esi
386
	loop .cycle_0
387
	xor eax,eax
388
	.end_f:
389
	ret
390
endp