Rev 6523 | 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 | struct GLMaterial |
||
79 | emission V4 |
||
80 | ambient V4 |
||
81 | diffuse V4 |
||
82 | specular V4 |
||
83 | shininess dd ? ;float |
||
84 | |||
85 | ; computed values |
||
86 | shininess_i dd ? ;int |
||
87 | do_specular dd ? ;int |
||
88 | ends |
||
89 | |||
90 | struct GLViewport |
||
91 | xmin dd ? ;int |
||
92 | ymin dd ? ;int |
||
93 | xsize dd ? ;int |
||
94 | ysize dd ? ;int |
||
95 | scale V3 |
||
96 | trans V3 |
||
97 | updated dd ? ;int |
||
98 | ends |
||
99 | |||
100 | offs_vpor_xmin equ 0 |
||
101 | offs_vpor_ymin equ 4 |
||
102 | offs_vpor_xsize equ 8 |
||
103 | offs_vpor_ysize equ 12 |
||
104 | offs_vpor_scale equ 16 |
||
105 | offs_vpor_trans equ 28 |
||
106 | offs_vpor_updated equ 40 |
||
107 | |||
108 | struct GLParamBuffer |
||
109 | ops rd OP_BUFFER_MAX_SIZE ;GLParam[OP_BUFFER_MAX_SIZE] |
||
110 | next dd ? ;struct GLParamBuffer* |
||
111 | ends |
||
112 | |||
5171 | IgorA | 113 | offs_gpbu_ops equ 0 |
114 | offs_gpbu_next equ 4*OP_BUFFER_MAX_SIZE |
||
115 | |||
5153 | IgorA | 116 | struct GLList |
117 | first_op_buffer dd ? ;GLParamBuffer* |
||
5171 | IgorA | 118 | ; TODO: extensions for an hash table or a better allocating scheme |
5153 | IgorA | 119 | ends |
120 | |||
121 | struct GLVertex |
||
122 | edge_flag dd ? ;int |
||
123 | normal V3 |
||
124 | coord V4 |
||
125 | tex_coord V4 |
||
126 | color V4 |
||
127 | |||
128 | ; computed values |
||
129 | ec V4 ; eye coordinates |
||
130 | pc V4 ; coordinates in the normalized volume |
||
131 | clip_code dd ? ;int ; clip code |
||
132 | zp ZBufferPoint ; integer coordinates for the rasterization |
||
133 | ends |
||
134 | |||
135 | struct GLImage |
||
136 | pixmap dd ? ;void* |
||
137 | xsize dd ? ;int |
||
138 | ysize dd ? ;int |
||
6243 | IgorA | 139 | xsize_log2 dd ? ;unsigned int |
140 | s_bound dd ? ;unsigned int |
||
141 | t_bound dd ? ;unsigned int |
||
5153 | IgorA | 142 | ends |
143 | |||
144 | offs_imag_pixmap equ 0 |
||
6108 | IgorA | 145 | offs_imag_xsize equ 4 |
146 | offs_imag_ysize equ 8 |
||
6243 | IgorA | 147 | offs_imag_xsize_log2 equ 12 |
148 | offs_imag_s_bound equ 16 |
||
149 | offs_imag_t_bound equ 20 |
||
5153 | IgorA | 150 | |
151 | ; textures |
||
152 | |||
153 | TEXTURE_HASH_TABLE_SIZE equ 256 ;должно быть кратное 2, в коде берется остаток от деления (через and быстрее чем div) |
||
154 | |||
155 | struct GLTexture |
||
156 | images rb sizeof.GLImage * MAX_TEXTURE_LEVELS ;GLImage[MAX_TEXTURE_LEVELS] |
||
157 | handle dd ? ;int |
||
158 | next dd ? ;struct GLTexture* |
||
159 | prev dd ? ;struct GLTexture* |
||
160 | ends |
||
161 | |||
162 | offs_text_images equ 0 |
||
163 | offs_text_handle equ sizeof.GLImage*MAX_TEXTURE_LEVELS |
||
164 | offs_text_next equ 4+offs_text_handle |
||
165 | offs_text_prev equ 8+offs_text_handle |
||
166 | |||
167 | ; shared state |
||
168 | |||
169 | struct GLSharedState |
||
170 | lists dd ? ;GLList** |
||
171 | texture_hash_table dd ? ;GLTexture** |
||
172 | ends |
||
173 | |||
174 | |||
175 | ; display context |
||
176 | |||
177 | struct GLContext |
||
178 | ; Z buffer |
||
179 | zb dd ? ;ZBuffer* |
||
180 | |||
181 | ; lights |
||
182 | lights rb sizeof.GLLight * MAX_LIGHTS ;GLLight[MAX_LIGHTS] |
||
183 | first_light dd ? ;GLLight* |
||
184 | ambient_light_model V4 |
||
185 | local_light_model dd ? ;int |
||
186 | lighting_enabled dd ? ;int |
||
187 | light_model_two_side dd ? ;int |
||
188 | |||
189 | ; materials |
||
190 | materials rb sizeof.GLMaterial * 2 ;GLMaterial[2] |
||
191 | color_material_enabled dd ? ;int |
||
192 | current_color_material_mode dd ? ;int |
||
193 | current_color_material_type dd ? ;int |
||
194 | |||
195 | ; textures |
||
196 | current_texture dd ? ;GLTexture* |
||
197 | texture_2d_enabled dd ? ;int |
||
198 | |||
199 | ; shared state |
||
200 | shared_state GLSharedState |
||
201 | |||
202 | ; current list |
||
203 | current_op_buffer dd ? ;GLParamBuffer* |
||
204 | current_op_buffer_index dd ? ;int |
||
205 | exec_flag dd ? ;int |
||
206 | compile_flag dd ? ;int |
||
207 | print_flag dd ? ;int |
||
208 | |||
209 | ; matrix |
||
210 | |||
211 | matrix_mode dd ? ;int режим активного вида матрицы (один из 3-х: GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE) |
||
212 | matrix_stack rd 3 ;*M4[3] указатель на начало массива матриц |
||
213 | matrix_stack_ptr rd 3 ;*M4[3] указатель на активную матрицу из массива |
||
214 | matrix_stack_depth_max rd 3 ;int[3] максимальное число матриц в массивах matrix_stack |
||
215 | |||
216 | matrix_model_view_inv M4 |
||
217 | matrix_model_projection M4 |
||
218 | matrix_model_projection_updated dd ? ;int |
||
219 | matrix_model_projection_no_w_transform dd ? ;int |
||
220 | apply_texture_matrix dd ? ;int |
||
221 | |||
222 | ; viewport |
||
223 | viewport GLViewport |
||
224 | |||
225 | ; current state |
||
226 | polygon_mode_back dd ? ;int |
||
227 | polygon_mode_front dd ? ;int |
||
228 | |||
229 | current_front_face dd ? ;int |
||
230 | current_shade_model dd ? ;int |
||
231 | current_cull_face dd ? ;int |
||
232 | cull_face_enabled dd ? ;int |
||
233 | normalize_enabled dd ? ;int |
||
234 | draw_triangle_front dd ? ;gl_draw_triangle_func |
||
235 | draw_triangle_back dd ? ;gl_draw_triangle_func |
||
236 | |||
237 | ; selection |
||
238 | render_mode dd ? ;int |
||
239 | select_buffer dd ? ;unsigned int* |
||
240 | select_size dd ? ;int |
||
241 | select_ptr dd ? ;unsigned int* |
||
242 | select_hit dd ? ;unsigned int* |
||
243 | select_overflow dd ? ;int |
||
244 | select_hits dd ? ;int |
||
245 | |||
246 | ; names |
||
247 | name_stack rd MAX_NAME_STACK_DEPTH ;unsigned int[MAX_NAME_STACK_DEPTH] |
||
248 | name_stack_size dd ? ;int |
||
249 | |||
250 | ; clear |
||
251 | clear_depth dd ? ;float |
||
252 | clear_color V4 |
||
253 | |||
254 | ; current vertex state |
||
255 | current_color V4 |
||
256 | longcurrent_color rd 3 ;unsigned int[3] ;precomputed integer color |
||
257 | current_normal V4 |
||
258 | current_tex_coord V4 |
||
259 | current_edge_flag dd ? ;int |
||
260 | |||
261 | ; glBegin / glEnd |
||
262 | in_begin dd ? ;int |
||
263 | begin_type dd ? ;int |
||
264 | vertex_n dd ? ;int |
||
265 | vertex_cnt dd ? ;int |
||
266 | vertex_max dd ? ;int |
||
267 | vertex dd ? ;GLVertex* |
||
268 | |||
269 | ; opengl 1.1 arrays |
||
270 | vertex_array dd ? ;float* |
||
271 | vertex_array_size dd ? ;int |
||
272 | vertex_array_stride dd ? ;int |
||
273 | normal_array dd ? ;float* |
||
274 | normal_array_stride dd ? ;int |
||
275 | color_array dd ? ;float* |
||
276 | color_array_size dd ? ;int |
||
277 | color_array_stride dd ? ;int |
||
278 | texcoord_array dd ? ;float* |
||
279 | texcoord_array_size dd ? ;int |
||
280 | texcoord_array_stride dd ? ;int |
||
281 | client_states dd ? ;int |
||
282 | |||
283 | ; opengl 1.1 polygon offset |
||
284 | offset_factor dd ? ;float |
||
285 | offset_units dd ? ;float |
||
286 | offset_states dd ? ;int |
||
287 | |||
288 | ; specular buffer. could probably be shared between contexts, |
||
289 | ; but that wouldn't be 100% thread safe |
||
290 | specbuf_first dd ? ;GLSpecBuf* |
||
291 | specbuf_used_counter dd ? ;int |
||
292 | specbuf_num_buffers dd ? ;int |
||
293 | |||
294 | ; opaque structure for user's use |
||
295 | opaque dd ? ;void* |
||
296 | ; resize viewport function |
||
297 | gl_resize_viewport dd ? ;(struct GLContext *c,int *xsize,int *ysize) |
||
298 | |||
299 | ; depth test |
||
300 | depth_test dd ? ;int |
||
301 | ends |
||
302 | |||
303 | align 16 |
||
304 | gl_ctx dd ? ;extern GLContext* |
||
305 | |||
306 | align 16 |
||
307 | proc gl_get_context |
||
308 | mov eax,[gl_ctx] |
||
309 | ret |
||
310 | endp |
||
311 | |||
312 | ; this clip epsilon is needed to avoid some rounding errors after |
||
313 | ; several clipping stages |
||
314 | |||
315 | CLIP_EPSILON dd 1.0e-5 |
||
316 | |||
317 | align 4 |
||
318 | proc gl_clipcode uses ebx, x:dword, y:dword, z:dword, w1:dword |
||
319 | xor ebx,ebx |
||
320 | |||
321 | fld1 |
||
322 | fadd dword[CLIP_EPSILON] |
||
323 | fmul dword[w1] |
||
324 | |||
325 | fcom dword[x] |
||
326 | fstsw ax |
||
327 | sahf |
||
328 | ja @f |
||
329 | or ebx,2 |
||
330 | @@: |
||
331 | fcom dword[y] |
||
332 | fstsw ax |
||
333 | sahf |
||
334 | ja @f |
||
335 | or ebx,8 |
||
336 | @@: |
||
337 | fcom dword[z] |
||
338 | fstsw ax |
||
339 | sahf |
||
340 | ja @f |
||
341 | or ebx,32 |
||
342 | @@: |
||
343 | |||
344 | fchs |
||
345 | fcom dword[x] |
||
346 | fstsw ax |
||
347 | sahf |
||
348 | jbe @f |
||
349 | or ebx,1 |
||
350 | @@: |
||
351 | fcom dword[y] |
||
352 | fstsw ax |
||
353 | sahf |
||
354 | jbe @f |
||
355 | or ebx,4 |
||
356 | @@: |
||
357 | fcom dword[z] |
||
358 | fstsw ax |
||
359 | sahf |
||
360 | jbe @f |
||
361 | or ebx,16 |
||
362 | @@: |
||
363 | |||
5208 | IgorA | 364 | ffree st0 |
365 | fincstp |
||
366 | |||
5153 | IgorA | 367 | mov eax,ebx |
368 | ret |
||
369 | endp |
||
370 | |||
371 | ;input: |
||
372 | ; rf,gf,bf - значения float |
||
373 | ; ri,gi,bi - адреса куда будут записаны rf,gf,bf преобразованые в int |
||
374 | align 4 |
||
375 | proc RGBFtoRGBI uses eax, rf:dword,gf:dword,bf:dword, ri:dword,gi:dword,bi:dword |
||
376 | locals |
||
377 | s dd ? |
||
378 | endl |
||
379 | mov dword[s],(ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) |
||
380 | fild dword[s] |
||
381 | fmul dword[rf] |
||
382 | mov eax,[ri] |
||
383 | fistp dword[eax] |
||
384 | add dword[eax],ZB_POINT_RED_MIN |
||
385 | |||
386 | mov dword[s],(ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN) |
||
387 | fild dword[s] |
||
388 | fmul dword[gf] |
||
389 | mov eax,[gi] |
||
390 | fistp dword[eax] |
||
391 | add dword[eax],ZB_POINT_GREEN_MIN |
||
392 | |||
393 | ;bi = (unsigned int) (bf * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) + ZB_POINT_BLUE_MIN); |
||
394 | mov dword[s],(ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) |
||
395 | fild dword[s] |
||
396 | fmul dword[bf] |
||
397 | mov eax,[bi] |
||
398 | fistp dword[eax] |
||
399 | add dword[eax],ZB_POINT_BLUE_MIN |
||
400 | ret |
||
401 | endp |