Rev 6101 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6100 | IgorA | 1 | ; |
2 | ; функции для вычисления зеркального цвета (блики) |
||
3 | ; |
||
5256 | IgorA | 4 | |
5 | align 4 |
||
6 | proc calc_buf uses ebx ecx, buf:dword, shininess:dword |
||
7 | locals |
||
8 | val dd ? ;float |
||
9 | f_inc dd ? ;float |
||
10 | endl |
||
11 | mov dword[f_inc],SPECULAR_BUFFER_SIZE |
||
5262 | IgorA | 12 | mov ebx,[buf] |
13 | add ebx,offs_spec_buf |
||
6101 | IgorA | 14 | mov dword[ebx],0.0 ;buf.buf[0] = 0.0 |
5256 | IgorA | 15 | xor ecx,ecx |
6101 | IgorA | 16 | inc ecx |
17 | fld dword[shininess] ;сначала берем y |
||
18 | fld1 |
||
19 | fidiv dword[f_inc] |
||
20 | fst dword[f_inc] ;f_inc = 1.0f/SPECULAR_BUFFER_SIZE |
||
21 | fst dword[val] |
||
5256 | IgorA | 22 | align 4 |
6101 | IgorA | 23 | .cycle_0: ;for (i = 1; i <= SPECULAR_BUFFER_SIZE; i++) |
5256 | IgorA | 24 | cmp ecx,SPECULAR_BUFFER_SIZE |
25 | jg @f |
||
26 | ;Вычисляем x^y |
||
6101 | IgorA | 27 | |
5256 | IgorA | 28 | fyl2x ;Стек FPU теперь содержит: st0=z=y*log2(x): |
29 | ;Теперь считаем 2**z: |
||
30 | fld st0 ;Создаем еще одну копию z |
||
31 | frndint ;Округляем |
||
32 | fsubr st0,st1 ;st1=z, st0=z-trunc(z) |
||
33 | f2xm1 ;st1=z, st0=2**(z-trunc(z))-1 |
||
34 | fld1 |
||
35 | faddp ;st1=z, st0=2**(z-trunc(z)) |
||
36 | fscale ;st1=z, st0=(2**trunc(z))*(2**(z-trunc(z)))=2**t |
||
37 | fxch st1 |
||
38 | fstp st ;Результат остается на вершине стека st0 |
||
39 | |||
6101 | IgorA | 40 | add ebx,4 |
5256 | IgorA | 41 | fstp dword[ebx] ;buf.buf[i] = pow(val, shininess) |
6101 | IgorA | 42 | ffree st0 ;испорченный shininess |
43 | fincstp |
||
5256 | IgorA | 44 | |
6101 | IgorA | 45 | fld dword[shininess] ;сначала берем y |
5256 | IgorA | 46 | fld dword[val] |
47 | fadd dword[f_inc] |
||
6101 | IgorA | 48 | fst dword[val] ;val += f_inc |
5256 | IgorA | 49 | inc ecx |
50 | jmp .cycle_0 |
||
51 | @@: |
||
6101 | IgorA | 52 | ffree st0 ;val |
53 | fincstp |
||
54 | ffree st0 ;shininess |
||
55 | fincstp |
||
5256 | IgorA | 56 | ret |
57 | endp |
||
58 | |||
59 | align 4 |
||
60 | proc specbuf_get_buffer uses ebx ecx edx, context:dword, shininess_i:dword, shininess:dword |
||
61 | locals |
||
62 | found dd ? ;GLSpecBuf * |
||
63 | oldest dd ? ;GLSpecBuf * |
||
64 | endl |
||
65 | mov edx,[context] |
||
6523 | IgorA | 66 | mov eax,[edx+GLContext.specbuf_first] |
5256 | IgorA | 67 | mov [found],eax |
68 | mov [oldest],eax |
||
69 | mov ebx,[shininess_i] |
||
70 | .cycle_0: |
||
71 | or eax,eax ;while (found) |
||
72 | jz @f |
||
73 | cmp [eax+offs_spec_shininess_i],ebx ;while (found.shininess_i != shininess_i) |
||
74 | je @f |
||
75 | mov ecx,[oldest] |
||
76 | mov ecx,[ecx+offs_spec_last_used] |
||
77 | cmp [eax+offs_spec_last_used],ecx ;if (found.last_used < oldest.last_used) |
||
78 | jge .end_0 |
||
79 | mov [oldest],eax ;oldest = found |
||
80 | .end_0: |
||
81 | mov eax,[eax+offs_spec_next] ;found = found.next |
||
82 | jmp .cycle_0 |
||
83 | @@: |
||
84 | cmp dword[found],0 ;if (found) /* hey, found one! */ |
||
85 | je @f |
||
86 | mov eax,[found] |
||
6523 | IgorA | 87 | mov ecx,[edx+GLContext.specbuf_used_counter] |
5256 | IgorA | 88 | mov [eax+offs_spec_last_used],ecx ;found.last_used = context.specbuf_used_counter |
6523 | IgorA | 89 | inc dword[edx+GLContext.specbuf_used_counter] |
5256 | IgorA | 90 | jmp .end_f ;return found |
91 | @@: |
||
92 | cmp dword[oldest],0 ;if (oldest == NULL || context.specbuf_num_buffers < MAX_SPECULAR_BUFFERS) |
||
93 | je @f |
||
6523 | IgorA | 94 | cmp dword[edx+GLContext.specbuf_num_buffers],MAX_SPECULAR_BUFFERS |
6100 | IgorA | 95 | jge .end_1 |
5256 | IgorA | 96 | @@: |
97 | ; create new buffer |
||
98 | stdcall gl_malloc, sizeof.GLSpecBuf |
||
6100 | IgorA | 99 | or eax,eax |
100 | jnz @f |
||
101 | ;gl_fatal_error("could not allocate specular buffer") |
||
102 | @@: |
||
6523 | IgorA | 103 | inc dword[edx+GLContext.specbuf_num_buffers] |
104 | mov ecx,[edx+GLContext.specbuf_first] |
||
5256 | IgorA | 105 | mov [eax+offs_spec_next],ecx |
6523 | IgorA | 106 | mov [edx+GLContext.specbuf_first],eax |
107 | mov ecx,[edx+GLContext.specbuf_used_counter] |
||
5256 | IgorA | 108 | mov [eax+offs_spec_last_used],ecx |
6523 | IgorA | 109 | inc dword[edx+GLContext.specbuf_used_counter] |
5256 | IgorA | 110 | mov [eax+offs_spec_shininess_i],ebx |
111 | stdcall calc_buf, eax,dword[shininess] |
||
112 | jmp .end_f |
||
113 | .end_1: |
||
114 | ; overwrite the lru buffer |
||
115 | ;tgl_trace("overwriting spec buffer :(\n"); |
||
116 | mov eax,[oldest] |
||
117 | mov [eax+offs_spec_shininess_i],ebx |
||
6523 | IgorA | 118 | mov ecx,[edx+GLContext.specbuf_used_counter] |
5256 | IgorA | 119 | mov [eax+offs_spec_last_used],ecx |
6523 | IgorA | 120 | inc dword[edx+GLContext.specbuf_used_counter] |
5256 | IgorA | 121 | stdcall calc_buf, eax,dword[shininess] |
122 | .end_f: |
||
123 | ret |
||
124 | endp>>=> |