Subversion Repositories Kolibri OS

Rev

Rev 6101 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;
  2. ; функции для вычисления зеркального цвета (блики)
  3. ;
  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
  12.         mov ebx,[buf]
  13.         add ebx,offs_spec_buf
  14.         mov dword[ebx],0.0 ;buf.buf[0] = 0.0
  15.         xor ecx,ecx
  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]
  22. align 4
  23.         .cycle_0: ;for (i = 1; i <= SPECULAR_BUFFER_SIZE; i++)
  24.         cmp ecx,SPECULAR_BUFFER_SIZE
  25.         jg @f
  26.                 ;Вычисляем x^y
  27.  
  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.  
  40.                 add ebx,4
  41.                 fstp dword[ebx] ;buf.buf[i] = pow(val, shininess)
  42.                 ffree st0 ;испорченный shininess
  43.                 fincstp
  44.  
  45.                 fld dword[shininess] ;сначала берем y
  46.                 fld dword[val]
  47.                 fadd dword[f_inc]
  48.                 fst dword[val] ;val += f_inc
  49.         inc ecx
  50.         jmp .cycle_0
  51.         @@:
  52.         ffree st0 ;val
  53.         fincstp
  54.         ffree st0 ;shininess
  55.         fincstp
  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]
  66.         mov eax,[edx+GLContext.specbuf_first]
  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]
  87.                 mov ecx,[edx+GLContext.specbuf_used_counter]
  88.                 mov [eax+offs_spec_last_used],ecx ;found.last_used = context.specbuf_used_counter
  89.                 inc dword[edx+GLContext.specbuf_used_counter]
  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
  94.         cmp dword[edx+GLContext.specbuf_num_buffers],MAX_SPECULAR_BUFFERS
  95.         jge .end_1
  96.         @@:
  97.                 ; create new buffer
  98.         stdcall gl_malloc, sizeof.GLSpecBuf
  99.         or eax,eax
  100.         jnz @f
  101. ;gl_fatal_error("could not allocate specular buffer")
  102.         @@:
  103.         inc dword[edx+GLContext.specbuf_num_buffers]
  104.         mov ecx,[edx+GLContext.specbuf_first]
  105.         mov [eax+offs_spec_next],ecx
  106.         mov [edx+GLContext.specbuf_first],eax
  107.         mov ecx,[edx+GLContext.specbuf_used_counter]
  108.         mov [eax+offs_spec_last_used],ecx
  109.         inc dword[edx+GLContext.specbuf_used_counter]
  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
  118.         mov ecx,[edx+GLContext.specbuf_used_counter]
  119.         mov [eax+offs_spec_last_used],ecx
  120.         inc dword[edx+GLContext.specbuf_used_counter]
  121.         stdcall calc_buf, eax,dword[shininess]
  122.         .end_f:
  123.         ret
  124. endp
  125.