Subversion Repositories Kolibri OS

Rev

Rev 6189 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5153 IgorA 1
;
2
; Texture Manager
3
;
4
 
5
align 4
6
proc find_texture uses ebx ecx, context:dword, h:dword
7
	mov ebx,[context]
8
	mov ebx,[ebx+offs_cont_shared_state+4] ;ebx = &texture_hash_table
9
	mov eax,[h]
10
	and eax,0xff
11
	shl eax,2
12
	add eax,[ebx] ;eax = &context.shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE]
13
 
14
	; [eax] - указатель на текстуру, получаемую через хеш таблицу
15
	mov ecx,[h] ; ecx - указатель на искомую текстуру
16
	@@:
17
		cmp dword[eax],0
18
		je .no_found
19
		mov ebx,[eax]
20
		cmp dword[ebx+offs_text_handle],ecx
21
		je .found
22
		mov eax,[ebx+offs_text_next]
23
		jmp @b
24
	.no_found:
25
	xor eax,eax ;ret NULL
26
	.found:
27
	ret
28
endp
29
 
30
;static void free_texture(GLContext *c,int h)
31
;{
32
;  GLTexture *t,**ht;
33
;  GLImage *im;
34
;  int i;
35
;
36
;  t=find_texture(c,h);
37
;  if (t->prev==NULL) {
38
;    ht=&c->shared_state.texture_hash_table
39
;      [t->handle % TEXTURE_HASH_TABLE_SIZE];
40
;    *ht=t->next;
41
;  } else {
42
;    t->prev->next=t->next;
43
;  }
44
;  if (t->next!=NULL) t->next->prev=t->prev;
45
;
46
;  for(i=0;i
47
;    im=&t->images[i];
48
;    if (im->pixmap != NULL) gl_free(im->pixmap);
49
;  }
50
;
51
;  gl_free(t);
52
;}
53
 
54
;output:
55
; eax - указатель на память
56
align 4
57
proc alloc_texture uses ebx ecx, context:dword, h:dword
58
 
59
	stdcall gl_zalloc,sizeof.GLTexture
60
 
61
	mov ebx,[context]
62
	mov ebx,[ebx+offs_cont_shared_state+4] ;ebx = &texture_hash_table
63
	mov ecx,[h]
64
	and ecx,0xff
65
	shl ecx,2
66
	add ecx,[ebx] ;ecx = &context.shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE]
67
 
68
	mov ebx,[ecx]
69
	mov [eax+offs_text_next],ebx
70
	mov dword[eax+offs_text_prev],0 ;NULL
71
	cmp dword[eax+offs_text_next],0 ;NULL
72
	je @f
73
		mov [eax+offs_text_prev],eax
74
	@@:
75
	mov [ecx],eax
76
 
77
	mov ebx,[h]
78
	mov [eax+offs_text_handle],ebx
79
 
80
	ret
81
endp
82
 
83
align 4
84
proc glInitTextures uses eax edx, context:dword
85
	; textures
86
	mov edx,[context]
87
	mov dword[edx+offs_cont_texture_2d_enabled],0
88
	stdcall find_texture,edx,0
89
	mov dword[edx+offs_cont_current_texture],eax
90
	ret
91
endp
92
 
93
;void glGenTextures(int n, unsigned int *textures)
94
;{
95
;  GLContext *c=gl_get_context();
96
;  int max,i;
97
;  GLTexture *t;
98
;
99
;  max=0;
100
;  for(i=0;i
101
;    t=c->shared_state.texture_hash_table[i];
102
;    while (t!=NULL) {
103
;      if (t->handle>max) max=t->handle;
104
;      t=t->next;
105
;    }
106
;
107
;  }
108
;  for(i=0;i
109
;    textures[i]=max+i+1;
110
;  }
111
;}
112
;
113
;
114
;void glDeleteTextures(int n, const unsigned int *textures)
115
;{
116
;  GLContext *c=gl_get_context();
117
;  int i;
118
;  GLTexture *t;
119
;
120
;  for(i=0;i
121
;    t=find_texture(c,textures[i]);
122
;    if (t!=NULL && t!=0) {
123
;      if (t==c->current_texture) {
124
;	glBindTexture(GL_TEXTURE_2D,0);
125
;      }
126
;      free_texture(c,textures[i]);
127
;    }
128
;  }
129
;}
130
 
131
align 4
132
proc glopBindTexture uses eax ebx edx, context:dword, p:dword
133
	mov ebx,[p]
134
	mov edx,[context]
135
 
136
;  assert(p[1].i == GL_TEXTURE_2D && texture >= 0);
137
 
138
	;[ebx+8] = p[2]
139
	stdcall find_texture, edx,dword[ebx+8]
140
	cmp eax,0 ;NULL
141
	jne @f
142
		stdcall alloc_texture, edx,dword[ebx+8]
143
	@@:
144
	mov [edx+offs_cont_current_texture],eax
145
	ret
146
endp
147
 
148
align 4
149
proc glopTexImage2D, context:dword, p:dword
150
;{
151
;  int target=p[1].i;
152
;  int level=p[2].i;
153
;  int components=p[3].i;
154
;  int width=p[4].i;
155
;  int height=p[5].i;
156
;  int border=p[6].i;
157
;  int format=p[7].i;
158
;  int type=p[8].i;
159
;  void *pixels=p[9].p;
160
;  GLImage *im;
161
;  unsigned char *pixels1;
162
;  int do_free;
163
;
164
;  if (!(target == GL_TEXTURE_2D && level == 0 && components == 3 &&
165
;        border == 0 && format == GL_RGB &&
166
;        type == GL_UNSIGNED_BYTE)) {
167
;    gl_fatal_error("glTexImage2D: combinaison of parameters not handled");
168
;  }
169
;
170
;  do_free=0;
171
;  if (width != 256 || height != 256) {
172
;    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;
176
;    width=256;
177
;    height=256;
178
;  } else {
179
;    pixels1=pixels;
180
;  }
181
;
182
;  im=&c->current_texture->images[level];
183
;  im->xsize=width;
184
;  im->ysize=height;
185
;  if (im->pixmap!=NULL) gl_free(im->pixmap);
186
;#if TGL_FEATURE_RENDER_BITS == 24
187
;  im->pixmap=gl_malloc(width*height*3);
188
;  if(im->pixmap) {
189
;      memcpy(im->pixmap,pixels1,width*height*3);
190
;  }
191
;#elif TGL_FEATURE_RENDER_BITS == 32
192
;  im->pixmap=gl_malloc(width*height*4);
193
;  if(im->pixmap) {
194
;      gl_convertRGB_to_8A8R8G8B(im->pixmap,pixels1,width,height);
195
;  }
196
;#elif TGL_FEATURE_RENDER_BITS == 16
197
;  im->pixmap=gl_malloc(width*height*2);
198
;  if(im->pixmap) {
199
;      gl_convertRGB_to_5R6G5B(im->pixmap,pixels1,width,height);
200
;  }
201
;#else
202
;#error TODO
203
;#endif
204
;  if (do_free) gl_free(pixels1);
205
	ret
206
endp
207
 
208
; TODO: not all tests are done
209
align 4
210
proc glopTexEnv, context:dword, p:dword
211
 
212
;  int target=p[1].i;
213
;  int pname=p[2].i;
214
;  int param=p[3].i;
215
;
216
;  if (target != GL_TEXTURE_ENV) {
217
;  error:
218
;    gl_fatal_error("glTexParameter: unsupported option");
219
;  }
220
;
221
;  if (pname != GL_TEXTURE_ENV_MODE) goto error;
222
;
223
;  if (param != GL_DECAL) goto error;
224
	ret
225
endp
226
 
227
; TODO: not all tests are done
228
align 4
229
proc glopTexParameter, context:dword, p:dword
230
 
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
;  }
239
;
240
;  switch(pname) {
241
;  case GL_TEXTURE_WRAP_S:
242
;  case GL_TEXTURE_WRAP_T:
243
;    if (param != GL_REPEAT) goto error;
244
;    break;
245
;  }
246
	ret
247
endp
248
 
249
align 4
250
proc glopPixelStore, context:dword, p:dword
251
 
252
;  int pname=p[1].i;
253
;  int param=p[2].i;
254
;
255
;  if (pname != GL_UNPACK_ALIGNMENT ||
256
;      param != 1) {
257
;    gl_fatal_error("glPixelStore: unsupported option");
258
;  }
259
	ret
260
endp