Subversion Repositories Kolibri OS

Rev

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