Subversion Repositories Kolibri OS

Rev

Rev 5262 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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