Subversion Repositories Kolibri OS

Rev

Rev 5153 | Rev 6189 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5153 Rev 6108
Line 7... Line 7...
7
	mov ebx,[context]
7
	mov ebx,[context]
8
	mov ebx,[ebx+offs_cont_shared_state+4] ;ebx = &texture_hash_table
8
	mov ebx,[ebx+offs_cont_shared_state+4] ;ebx = &texture_hash_table
9
	mov eax,[h]
9
	mov eax,[h]
10
	and eax,0xff
10
	and eax,0xff
11
	shl eax,2
11
	shl eax,2
12
	add eax,[ebx] ;eax = &context.shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE]
12
	add eax,ebx ;eax = &context.shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE]
Line 13... Line 13...
13
 
13
 
14
	; [eax] - указатель на текстуру, получаемую через хеш таблицу
14
	; [eax] - указатель на текстуру, получаемую через хеш таблицу
15
	mov ecx,[h] ; ecx - указатель на искомую текстуру
15
	mov ecx,[h] ; ecx - указатель на искомую текстуру
16
	@@:
16
	@@:
Line 25... Line 25...
25
	xor eax,eax ;ret NULL
25
	xor eax,eax ;ret NULL
26
	.found:
26
	.found:
27
	ret
27
	ret
28
endp
28
endp
Line 29... Line -...
29
 
-
 
30
;static void free_texture(GLContext *c,int h)
29
 
31
;{
30
align 4
32
;  GLTexture *t,**ht;
31
proc free_texture uses eax ebx ecx edx, context:dword, h:dword
33
;  GLImage *im;
-
 
34
;  int i;
32
	mov edx,[context]
35
;
33
 
36
;  t=find_texture(c,h);
34
	stdcall find_texture,edx,[h] ;t=find_texture(context,h)
-
 
35
	cmp dword[eax+offs_text_prev],0 ;if (t.prev==NULL)
37
;  if (t->prev==NULL) {
36
	jne .else
-
 
37
		mov edx,[edx+offs_cont_shared_state+4] ;edx = &context.shared_state.texture_hash_table[0]
-
 
38
		mov ebx,[eax+offs_text_handle]
-
 
39
		and ebx,0xff
38
;    ht=&c->shared_state.texture_hash_table
40
		shl ebx,2
-
 
41
		add edx,ebx ;edx = &context.shared_state.texture_hash_table[t.handle % TEXTURE_HASH_TABLE_SIZE]
39
;      [t->handle % TEXTURE_HASH_TABLE_SIZE];
42
		mov ebx,[eax+offs_text_next]
-
 
43
		mov [edx],ebx ;*ht=t.next
40
;    *ht=t->next;
44
		jmp @f
-
 
45
	.else:
41
;  } else {
46
		mov ebx,[eax+offs_text_prev]
-
 
47
		mov ecx,[eax+offs_text_next]
42
;    t->prev->next=t->next;
48
		mov [ebx+offs_text_next],ecx ;t.prev.next=t.next
-
 
49
	@@:
-
 
50
	cmp dword[eax+offs_text_next],0 ;if (t.next!=NULL)
-
 
51
	je @f
-
 
52
		mov ebx,[eax+offs_text_next]
43
;  }
53
		mov ecx,[eax+offs_text_prev]
-
 
54
		mov [ebx+offs_text_prev],ecx ;t.next.prev=t.prev
44
;  if (t->next!=NULL) t->next->prev=t->prev;
55
	@@:
-
 
56
 
-
 
57
	xor ebx,ebx
45
;
58
	mov ecx,[eax+offs_text_images] ;im=&t.images[0]
-
 
59
	.cycle_0: ;for(i=0;i
46
;  for(i=0;i
60
	cmp ebx,MAX_TEXTURE_LEVELS
47
;    im=&t->images[i];
61
	jge .cycle_0_end
-
 
62
		cmp dword[ecx+offs_imag_pixmap],0 ;if (im.pixmap != NULL)
-
 
63
		je @f
48
;    if (im->pixmap != NULL) gl_free(im->pixmap);
64
			stdcall gl_free,[ecx+offs_imag_pixmap]
-
 
65
		@@:
-
 
66
		add ecx,sizeof.GLImage
-
 
67
		inc ebx
-
 
68
		jmp .cycle_0
49
;  }
69
	.cycle_0_end:
50
;
70
 
-
 
71
	stdcall gl_free,eax
51
;  gl_free(t);
72
	ret
Line 52... Line 73...
52
;}
73
endp
53
 
74
 
54
;output:
75
;output:
55
; eax - указатель на память
76
; eax - указатель на память
Line 61... Line 82...
61
	mov ebx,[context]
82
	mov ebx,[context]
62
	mov ebx,[ebx+offs_cont_shared_state+4] ;ebx = &texture_hash_table
83
	mov ebx,[ebx+offs_cont_shared_state+4] ;ebx = &texture_hash_table
63
	mov ecx,[h]
84
	mov ecx,[h]
64
	and ecx,0xff
85
	and ecx,0xff
65
	shl ecx,2
86
	shl ecx,2
66
	add ecx,[ebx] ;ecx = &context.shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE]
87
	add ecx,ebx ;ecx = &context.shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE]
Line 67... Line 88...
67
 
88
 
68
	mov ebx,[ecx]
89
	mov ebx,[ecx]
69
	mov [eax+offs_text_next],ebx
90
	mov [eax+offs_text_next],ebx
70
	mov dword[eax+offs_text_prev],0 ;NULL
91
	mov dword[eax+offs_text_prev],0 ;NULL
Line 88... Line 109...
88
	stdcall find_texture,edx,0
109
	stdcall find_texture,edx,0
89
	mov dword[edx+offs_cont_current_texture],eax
110
	mov dword[edx+offs_cont_current_texture],eax
90
	ret
111
	ret
91
endp
112
endp
Line -... Line 113...
-
 
113
 
92
 
114
align 4
93
;void glGenTextures(int n, unsigned int *textures)
-
 
94
;{
115
proc glGenTextures uses eax ebx ecx edx esi, n:dword, textures:dword
95
;  GLContext *c=gl_get_context();
116
;edx - GLTexture *t
96
;  int max,i;
117
	call gl_get_context
97
;  GLTexture *t;
118
	add eax,offs_cont_shared_state+4 ;offset texture_hash_table = 4
98
;
119
 
-
 
120
	xor ebx,ebx ;max=0
99
;  max=0;
121
	xor ecx,ecx ;i=0
-
 
122
	.cycle_0: ;for(i=0;i
-
 
123
	cmp ecx,TEXTURE_HASH_TABLE_SIZE
-
 
124
	jge .cycle_0_end
-
 
125
		mov esi,ecx
-
 
126
		shl esi,2
100
;  for(i=0;i
127
		add esi,[eax]
101
;    t=c->shared_state.texture_hash_table[i];
128
		mov edx,dword[esi] ;t=context.shared_state.texture_hash_table[i]
-
 
129
		.cycle_1: ;while (t!=NULL)
-
 
130
		or edx,edx
-
 
131
		jz .cycle_1_end
-
 
132
			cmp [edx+offs_text_handle],ebx ;if (t.handle>max)
102
;    while (t!=NULL) {
133
			jle @f
-
 
134
				mov ebx,[edx+offs_text_handle] ;max=t.handle
-
 
135
			@@:
103
;      if (t->handle>max) max=t->handle;
136
			mov edx,[edx+offs_text_next] ;t=t.next
-
 
137
			jmp .cycle_1
104
;      t=t->next;
138
		.cycle_1_end:
-
 
139
		inc ecx
-
 
140
		jmp .cycle_0
105
;    }
141
	.cycle_0_end:
106
;
142
 
-
 
143
	xor ecx,ecx ;i=0
107
;  }
144
	mov esi,[textures]
-
 
145
	.cycle_2: ;for(i=0;i
-
 
146
	cmp ecx,[n]
-
 
147
	jge .cycle_2_end
108
;  for(i=0;i
148
		inc ebx
-
 
149
		mov [esi],ebx ;textures[i]=max+i+1
109
;    textures[i]=max+i+1;
150
		add esi,4
-
 
151
		inc ecx
-
 
152
		jmp .cycle_2
110
;  }
153
	.cycle_2_end:
111
;}
154
	ret
112
;
155
endp
-
 
156
 
113
;
157
align 4
114
;void glDeleteTextures(int n, const unsigned int *textures)
-
 
115
;{
158
proc glDeleteTextures uses eax ebx ecx edx, n:dword, textures:dword
116
;  GLContext *c=gl_get_context();
159
	call gl_get_context
117
;  int i;
160
	mov edx,eax
118
;  GLTexture *t;
161
	mov ecx,[textures]
-
 
162
 
119
;
163
	xor ebx,ebx
-
 
164
	.cycle_0: ;for(i=0;i
-
 
165
	cmp ebx,[n]
120
;  for(i=0;i
166
	jge .cycle_0_end
121
;    t=find_texture(c,textures[i]);
167
		stdcall find_texture,edx,[ecx] ;t=find_texture(context,textures[i])
-
 
168
		or eax,eax ;if (t!=0)
122
;    if (t!=NULL && t!=0) {
169
		jz @f
-
 
170
			cmp eax,[edx+offs_cont_current_texture] ;if (t==context.current_texture)
123
;      if (t==c->current_texture) {
171
			jne .end_1
124
;	glBindTexture(GL_TEXTURE_2D,0);
172
				stdcall glBindTexture,GL_TEXTURE_2D,0
125
;      }
173
			.end_1:
126
;      free_texture(c,textures[i]);
174
			stdcall free_texture, edx,[ecx]
-
 
175
		@@:
-
 
176
		add ecx,4
-
 
177
		inc ebx
-
 
178
		jmp .cycle_0
127
;    }
179
	.cycle_0_end:
128
;  }
180
	ret
Line 129... Line 181...
129
;}
181
endp
130
 
182
 
131
align 4
183
align 4
132
proc glopBindTexture uses eax ebx edx, context:dword, p:dword
184
proc glopBindTexture uses eax ebx edx, context:dword, p:dword
Line -... Line 185...
-
 
185
	mov ebx,[p]
-
 
186
	mov edx,[context]
-
 
187
 
-
 
188
	cmp dword[ebx+4],GL_TEXTURE_2D
-
 
189
	je @f
-
 
190
	;jne .error
133
	mov ebx,[p]
191
	;cmp dword[ebx+8],0
-
 
192
	;jge @f
Line 134... Line 193...
134
	mov edx,[context]
193
	.error:
135
 
194
		stdcall dbg_print,sz_glBindTexture,err_7
136
;  assert(p[1].i == GL_TEXTURE_2D && texture >= 0);
195
	@@:
137
 
196
 
138
	;[ebx+8] = p[2]
197
	mov ebx,[ebx+8] ;ebx = p[2]
139
	stdcall find_texture, edx,dword[ebx+8]
198
	stdcall find_texture, edx,ebx
140
	cmp eax,0 ;NULL
199
	or eax,eax ;if(t==NULL)
141
	jne @f
200
	jnz @f
142
		stdcall alloc_texture, edx,dword[ebx+8]
201
		stdcall alloc_texture, edx,ebx
Line 143... Line 202...
143
	@@:
202
	@@:
144
	mov [edx+offs_cont_current_texture],eax
203
	mov [edx+offs_cont_current_texture],eax
-
 
204
	ret
-
 
205
endp
-
 
206
 
145
	ret
207
align 4
-
 
208
proc glopTexImage2D, context:dword, p:dword
-
 
209
locals
146
endp
210
	pixels1 dd ?
147
 
211
	do_free dd ?
148
align 4
212
endl
149
proc glopTexImage2D, context:dword, p:dword
213
pushad
150
;{
214
	mov edi,[p]
-
 
215
	mov eax,[edi+4] ;target=p[1].i
-
 
216
	mov ebx,[edi+8] ;level=p[2].i
151
;  int target=p[1].i;
217
	mov ecx,[edi+12] ;components=p[3].i;
152
;  int level=p[2].i;
218
	mov edx,[edi+16] ;width=p[4].i;
153
;  int components=p[3].i;
219
	mov esi,[edi+20] ;height=p[5].i;
154
;  int width=p[4].i;
220
 
155
;  int height=p[5].i;
221
	cmp eax,GL_TEXTURE_2D ;if (param != GL_TEXTURE_2D)
156
;  int border=p[6].i;
222
	jne .error
157
;  int format=p[7].i;
223
	or ebx,ebx ;if (level != 0)
158
;  int type=p[8].i;
-
 
159
;  void *pixels=p[9].p;
-
 
160
;  GLImage *im;
224
	jnz .error
-
 
225
	cmp ecx,3 ;if (components != 3)
161
;  unsigned char *pixels1;
226
	jne .error
-
 
227
	cmp dword[edi+24],0 ;if (border != 0)
-
 
228
	jne .error
-
 
229
	cmp dword[edi+28],GL_RGB ;if (format != GL_RGB)
-
 
230
	jne .error
162
;  int do_free;
231
	cmp dword[edi+32],GL_UNSIGNED_BYTE ;if (type != GL_UNSIGNED_BYTE)
163
;
232
	jne .error
164
;  if (!(target == GL_TEXTURE_2D && level == 0 && components == 3 && 
233
 
165
;        border == 0 && format == GL_RGB &&
234
	jmp @f
-
 
235
	.error:
-
 
236
		stdcall dbg_print,sz_glTexImage2D,err_8 ;"glTexImage2D: combinaison of parameters not handled"
-
 
237
	@@:
-
 
238
 
-
 
239
	mov dword[do_free],0
-
 
240
	cmp edx,256
-
 
241
	jne .else
166
;        type == GL_UNSIGNED_BYTE)) {
242
	cmp esi,256
-
 
243
	jne .else
167
;    gl_fatal_error("glTexImage2D: combinaison of parameters not handled");
244
		mov eax,[edi+36]
168
;  }
245
		mov [pixels1],eax ;pixels1=pixels
169
;  
246
		jmp @f
170
;  do_free=0;
247
	.else: ;if (width != 256 || height != 256)
171
;  if (width != 256 || height != 256) {
248
		stdcall gl_malloc, 256*256*3
172
;    pixels1 = gl_malloc(256 * 256 * 3);
249
		mov [pixels1],eax ;pixels1 = gl_malloc(256 * 256 * 3)
173
;    /* no interpolation is done here to respect the original image aliasing ! */
-
 
174
;    gl_resizeImageNoInterpolate(pixels1,256,256,pixels,width,height);
-
 
175
;    do_free=1;
250
		; no interpolation is done here to respect the original image aliasing !
176
;    width=256;
251
;gl_resizeImageNoInterpolate(eax,256,256,[edi+36],edx,esi)
-
 
252
		mov dword[do_free],1
-
 
253
		mov edx,256
-
 
254
		mov esi,256
-
 
255
	@@:
177
;    height=256;
256
 
178
;  } else {
257
	mov ecx,[context]
179
;    pixels1=pixels;
258
	mov ecx,[ecx+offs_cont_current_texture]
180
;  }
259
	add ecx,offs_text_images
-
 
260
	imul ebx,sizeof.GLTexture
-
 
261
	add ecx,ebx ;ecx = &context.current_texture.images[level]
-
 
262
	mov dword[ecx+offs_imag_xsize],edx ;im.xsize=width
181
;
263
	mov dword[ecx+offs_imag_ysize],esi ;im.ysize=height
-
 
264
	cmp dword[ecx+offs_imag_pixmap],0 ;if (im.pixmap!=NULL) 
-
 
265
	je @f
-
 
266
		stdcall gl_free, [ecx+offs_imag_pixmap]
182
;  im=&c->current_texture->images[level];
267
	@@:
183
;  im->xsize=width;
268
if TGL_FEATURE_RENDER_BITS eq 24
-
 
269
	imul edx,esi
-
 
270
	imul edx,3
-
 
271
	stdcall gl_malloc,edx
-
 
272
	mov [ecx+offs_imag_pixmap],eax ;im.pixmap = gl_malloc(width*height*3)
184
;  im->ysize=height;
273
	or eax,eax ;if(im.pixmap)
185
;  if (im->pixmap!=NULL) gl_free(im->pixmap);
274
	jz @f
-
 
275
		mov edi,eax
186
;#if TGL_FEATURE_RENDER_BITS == 24 
276
		mov esi,[pixels1]
-
 
277
		mov ecx,edx
-
 
278
		rep movsb ;memcpy(im.pixmap,pixels1,width*height*3)
-
 
279
	@@:
-
 
280
end if
187
;  im->pixmap=gl_malloc(width*height*3);
281
if TGL_FEATURE_RENDER_BITS eq 32
188
;  if(im->pixmap) {
282
	mov ebx,edx
-
 
283
	imul edx,esi
189
;      memcpy(im->pixmap,pixels1,width*height*3);
284
	shl edx,2
190
;  }
285
	stdcall gl_malloc,edx
-
 
286
	mov [ecx+offs_imag_pixmap],eax ;im.pixmap = gl_malloc(width*height*4)
191
;#elif TGL_FEATURE_RENDER_BITS == 32
287
	or eax,eax ;if(im.pixmap)
-
 
288
	jz @f
-
 
289
;gl_convertRGB_to_8A8R8G8B(eax,[pixels1],ebx,esi)
-
 
290
	@@:
-
 
291
end if
192
;  im->pixmap=gl_malloc(width*height*4);
292
if TGL_FEATURE_RENDER_BITS eq 16
193
;  if(im->pixmap) {
293
	mov ebx,edx
-
 
294
	imul edx,esi
194
;      gl_convertRGB_to_8A8R8G8B(im->pixmap,pixels1,width,height);
295
	shl edx,1
195
;  }
296
	stdcall gl_malloc,edx
196
;#elif TGL_FEATURE_RENDER_BITS == 16
297
	mov [ecx+offs_imag_pixmap],eax ;im.pixmap = gl_malloc(width*height*2)
197
;  im->pixmap=gl_malloc(width*height*2);
298
	or eax,eax ;if(im.pixmap)
198
;  if(im->pixmap) {
299
	jz @f
199
;      gl_convertRGB_to_5R6G5B(im->pixmap,pixels1,width,height);
300
;gl_convertRGB_to_5R6G5B(eax,[pixels1],ebx,esi)
-
 
301
	@@:
-
 
302
end if
200
;  }
303
	cmp dword[do_free],0 ;if (do_free)
201
;#else
304
	je @f
Line 202... Line 305...
202
;#error TODO
305
		stdcall gl_free, [pixels1]
203
;#endif
306
	@@:
204
;  if (do_free) gl_free(pixels1);
307
popad
205
	ret
308
	ret
206
endp
309
endp
207
 
310
 
208
; TODO: not all tests are done
311
; TODO: not all tests are done
209
align 4
312
align 4
210
proc glopTexEnv, context:dword, p:dword
313
proc glopTexEnv uses eax ebx ecx, context:dword, p:dword
211
 
314
	mov ecx,[p]
212
;  int target=p[1].i;
315
	mov eax,[ecx+4] ;target=p[1].i
-
 
316
	mov ebx,[ecx+8] ;pname=p[2].i
-
 
317
	mov ecx,[ecx+12] ;param=p[3].i
213
;  int pname=p[2].i;
318
 
214
;  int param=p[3].i;
319
	cmp eax,GL_TEXTURE_ENV ;if (target != GL_TEXTURE_ENV)
-
 
320
	jne .error
-
 
321
	cmp ebx,GL_TEXTURE_ENV_MODE ;if (pname != GL_TEXTURE_ENV_MODE)
215
;
322
	jne .error
216
;  if (target != GL_TEXTURE_ENV) {
323
	cmp ecx,GL_DECAL ;if (param != GL_DECAL)
217
;  error:
-
 
218
;    gl_fatal_error("glTexParameter: unsupported option");
324
	jne .error
219
;  }
325
 
Line 220... Line 326...
220
;
326
	jmp @f
221
;  if (pname != GL_TEXTURE_ENV_MODE) goto error;
327
	.error:
222
;
328
		stdcall dbg_print,sz_glTexParameteri,err_6
-
 
329
	@@:
-
 
330
	ret
-
 
331
endp
-
 
332
 
-
 
333
; TODO: not all tests are done
-
 
334
align 4
-
 
335
proc glopTexParameter uses eax ebx ecx, context:dword, p:dword
-
 
336
	mov ecx,[p]
-
 
337
	mov eax,[ecx+4] ;target=p[1].i
-
 
338
	mov ebx,[ecx+8] ;pname=p[2].i
-
 
339
	mov ecx,[ecx+12] ;param=p[3].i
-
 
340
 
-
 
341
	cmp eax,GL_TEXTURE_2D ;if (target != GL_TEXTURE_2D)
-
 
342
	jne .error
-
 
343
	cmp ebx,GL_TEXTURE_WRAP_S
Line 223... Line -...
223
;  if (param != GL_DECAL) goto error;
-
 
224
	ret
-
 
225
endp
344
	je @f
226
 
-
 
227
; TODO: not all tests are done
-
 
228
align 4
345
	cmp ebx,GL_TEXTURE_WRAP_T
229
proc glopTexParameter, context:dword, p:dword
346
	je @f
230
 
347
		jmp .error
231
;  int target=p[1].i;
-
 
232
;  int pname=p[2].i;
-
 
233
;  int param=p[3].i;
-
 
234
;  
-
 
235
;  if (target != GL_TEXTURE_2D) {
-
 
236
;  error:
-
 
237
;    gl_fatal_error("glTexParameter: unsupported option");
-
 
238
;  }
348
	@@:
239
;
349
	cmp ecx,GL_REPEAT ;if (param != GL_REPEAT)
Line 240... Line 350...
240
;  switch(pname) {
350
	jne .error
241
;  case GL_TEXTURE_WRAP_S:
351
 
242
;  case GL_TEXTURE_WRAP_T:
352
	jmp @f
243
;    if (param != GL_REPEAT) goto error;
353
	.error:
244
;    break;
354
		stdcall dbg_print,sz_glTexParameteri,err_6
245
;  }
355
	@@:
246
	ret
356
	ret
-
 
357
endp
247
endp
358
 
-
 
359
align 4
-
 
360
proc glopPixelStore uses eax ebx, context:dword, p:dword
-
 
361
	mov ebx,[p]
-
 
362
	mov eax,[ebx+4] ;pname=p[1].i
248
 
363
	mov ebx,[ebx+8] ;param=p[2].i
249
align 4
364
 
250
proc glopPixelStore, context:dword, p:dword
365
	cmp eax,GL_UNPACK_ALIGNMENT ;if (pname != GL_UNPACK_ALIGNMENT)
251
 
366
	jne .error