Subversion Repositories Kolibri OS

Rev

Rev 1776 | Blame | Last modification | View Log | Download | RSS feed

  1. gouraud_triangle:
  2. ;------------------in - eax - x1 shl 16 + y1 ---------
  3. ;---------------------- ebx - x2 shl 16 + y2 ---------
  4. ;---------------------- ecx - x3 shl 16 + y3 ---------
  5. ;---------------------- edi - pointer to screen buffer
  6. ;---------------------- stack : colors----------------
  7. ;----------------- procedure don't save registers !!--
  8. .col1r equ ebp+4             ; each color as word
  9. .col1g equ ebp+6
  10. .col1b equ ebp+8
  11. .col2r equ ebp+10
  12. .col2g equ ebp+12
  13. .col2b equ ebp+14
  14. .col3r equ ebp+16
  15. .col3g equ ebp+18
  16. .col3b equ ebp+20
  17.  
  18. .x1    equ word[ebp-2]
  19. .y1    equ word[ebp-4]
  20. .x2    equ word[ebp-6]
  21. .y2    equ word[ebp-8]
  22. .x3    equ word[ebp-10]
  23. .y3    equ word[ebp-12]
  24.  
  25. .dx12  equ dword[ebp-16]
  26. .dc12r equ dword[ebp-20]
  27. .dc12g equ [ebp-24]
  28. .dc12b equ dword[ebp-28]
  29. .dx13  equ dword[ebp-32]
  30. .dc13r equ dword[ebp-36]
  31. .dc13g equ [ebp-40]
  32. .dc13b equ dword[ebp-44]
  33. .dx23  equ dword[ebp-48]
  34. .dc23r equ dword[ebp-52]
  35. .dc23g equ [ebp-56]
  36. .dc23b equ dword[ebp-60]
  37.  
  38. .c1r   equ dword[ebp-64]
  39. .c1g   equ [ebp-68]
  40. .c1b   equ dword[ebp-72]
  41. .c2r   equ dword[ebp-76]
  42. .c2g   equ [ebp-80]
  43. .c2b   equ dword[ebp-84]
  44.  
  45.  
  46.        mov ebp,esp
  47. ;       sub esp,72
  48.  
  49.  .sort3:                  ; sort triangle coordinates...
  50.        cmp ax,bx
  51.        jle .sort1
  52.        xchg eax,ebx
  53.        mov edx,dword[.col1r]
  54.        xchg edx,dword[.col2r]
  55.        mov dword[.col1r],edx
  56.        mov dx,word[.col1b]
  57.        xchg dx,word[.col2b]
  58.        mov word[.col1b],dx
  59.  .sort1:
  60.        cmp bx,cx
  61.        jle .sort2
  62.        xchg ebx,ecx
  63.        mov edx,dword[.col2r]
  64.        xchg edx,dword[.col3r]
  65.        mov dword[.col2r],edx
  66.        mov dx,word[.col2b]
  67.        xchg dx,word[.col3b]
  68.        mov word[.col2b],dx
  69.        jmp .sort3
  70.  .sort2:
  71.        push eax   ;store triangle coordinates in user friendly variables
  72.        push ebx
  73.        push ecx
  74.     ;   sub esp,72 ; set correctly value of esp
  75.  
  76.        mov edx,eax    ; check only X triangle coordinate
  77.        or edx,ebx
  78.        or edx,ecx
  79.        test edx,80000000h
  80.        jne .gt_loop2_end
  81.  
  82.        mov dx,[size_x_var]
  83.        dec dx
  84.        shr eax,16
  85.        cmp ax,dx  ;SIZE_X-1
  86.        jg .gt_loop2_end
  87.        shr ebx,16
  88.        cmp bx,dx  ;SIZE_X-1
  89.        jg .gt_loop2_end
  90.        shr ecx,16
  91.        cmp cx,dx  ;SIZE_X-1
  92.        jg .gt_loop2_end
  93.  
  94.  
  95.        mov bx,.y2       ; calc deltas
  96.        sub bx,.y1
  97.        jnz .gt_dx12_make
  98.        xor edx,edx
  99.        mov ecx,4
  100.      @@:
  101.        push edx
  102.        loop @b
  103.      ;  mov .dx12,0
  104.      ;  mov .dc12r,0
  105.      ;  mov .dc12g,0
  106.      ;  mov .dc12b,0
  107.        jmp .gt_dx12_done
  108.   .gt_dx12_make:
  109.  
  110.        mov ax,.x2
  111.        sub ax,.x1
  112.        cwde
  113.        movsx ebx,bx
  114.        shl eax,ROUND
  115.        cdq
  116.        idiv ebx
  117.      ;  mov .dx12,eax
  118.        push eax
  119.  
  120.        mov ax,word[.col2r]
  121.        sub ax,word[.col1r]
  122.        cwde
  123.        shl eax,ROUND
  124.        cdq
  125.        idiv ebx
  126.       ; mov .dc12r,eax
  127.        push eax
  128.  
  129.        mov ax,word[.col2g]
  130.        sub ax,word[.col1g]
  131.        cwde
  132.        shl eax,ROUND
  133.        cdq
  134.        idiv ebx
  135.      ;  mov .dc12g,eax
  136.        push eax
  137.  
  138.        mov ax,word[.col2b]
  139.        sub ax,word[.col1b]
  140.        cwde
  141.        shl eax,ROUND
  142.        cdq
  143.        idiv ebx
  144.      ;  mov .dc12b,eax
  145.        push eax
  146. .gt_dx12_done:
  147.        mov bx,.y3
  148.        sub bx,.y1
  149.        jnz .gt_dx13_make
  150.        xor edx,edx
  151.        mov ecx,4
  152.      @@:
  153.        push edx
  154.        loop @b
  155.    ;    mov .dx13,0
  156.    ;    mov .dc13r,0
  157.    ;    mov .dc13g,0
  158.    ;    mov .dc13b,0
  159.        jmp .gt_dx13_done
  160. .gt_dx13_make:
  161.        mov ax,.x3
  162.        sub ax,.x1
  163.        cwde
  164.        movsx ebx,bx
  165.        shl eax,ROUND
  166.        cdq
  167.        idiv ebx
  168.    ;    mov .dx13,eax
  169.        push eax
  170.  
  171.        mov ax,word[.col3r]
  172.        sub ax,word[.col1r]
  173.        cwde
  174.        shl eax,ROUND
  175.        cdq
  176.        idiv ebx
  177.     ;   mov .dc13r,eax
  178.        push eax
  179.  
  180.        mov ax,word[.col3g]
  181.        sub ax,word[.col1g]
  182.        cwde
  183.        shl eax,ROUND
  184.        cdq
  185.        idiv ebx
  186.      ;  mov .dc13g,eax
  187.        push eax
  188.        mov ax,word[.col3b]
  189.        sub ax,word[.col1b]
  190.        cwde
  191.        shl eax,ROUND
  192.        cdq
  193.        idiv ebx
  194.     ;   mov .dc13b,eax
  195.        push eax
  196. .gt_dx13_done:
  197.        mov bx,.y3
  198.        sub bx,.y2
  199.        jnz .gt_dx23_make
  200.        xor edx,edx
  201.        mov ecx,4
  202.      @@:
  203.        push edx
  204.        loop @b
  205.    ;    mov .dx23,0
  206.    ;    mov .dc23r,0
  207.    ;    mov .dc23g,0
  208.    ;    mov .dc23b,0
  209.        jmp .gt_dx23_done
  210. .gt_dx23_make:
  211.        mov ax,.x3
  212.        sub ax,.x2
  213.        cwde
  214.        movsx ebx,bx
  215.        shl eax,ROUND
  216.        cdq
  217.        idiv ebx
  218.      ; mov .dx23,eax
  219.        push eax
  220.  
  221.        mov ax,word[.col3r]
  222.        sub ax,word[.col2r]
  223.        cwde
  224.        shl eax,ROUND
  225.        cdq
  226.        idiv ebx
  227.       ; mov .dc23r,eax
  228.        push eax
  229.  
  230.  
  231.        mov ax,word[.col3g]
  232.        sub ax,word[.col2g]
  233.        cwde
  234.        shl eax,ROUND
  235.        cdq
  236.        idiv ebx
  237.      ;  mov .dc23g,eax
  238.        push eax
  239.  
  240.        mov ax,word[.col3b]
  241.        sub ax,word[.col2b]
  242.        cwde
  243.        shl eax,ROUND
  244.        cdq
  245.        idiv ebx
  246.     ;   mov .dc23b,eax
  247.        push eax
  248.  
  249. .gt_dx23_done:
  250.        sub esp,24
  251.        movsx eax,.x1
  252.        shl eax,ROUND
  253.        mov ebx,eax
  254.        movsx edx,word[.col1r]
  255.        shl edx,ROUND
  256.        mov .c1r,edx
  257.        mov .c2r,edx
  258.        movsx edx,word[.col1g]
  259.        shl edx,ROUND
  260.        mov .c1g,edx
  261.        mov .c2g,edx
  262.        movsx edx,word[.col1b]
  263.        shl edx,ROUND
  264.        mov .c1b,edx
  265.        mov .c2b,edx
  266.        mov cx,.y1
  267.        cmp cx,.y2
  268.        jge .gt_loop1_end
  269. .gt_loop1:
  270.        push eax                       ; eax - cur x1
  271.        push ebx                       ; ebx - cur x2
  272.        push cx                        ; cx  - cur y
  273.        push edi
  274.        push ebp
  275.  
  276.        sar ebx,ROUND
  277.        push bx
  278.        mov edx,.c2r              ; c2r,c2g,c2b,c1r,c1g,c1b - current colors
  279.        sar edx,ROUND
  280.        push dx
  281.        mov edx,.c2g
  282.        sar edx,ROUND
  283.        push dx
  284.        mov edx,.c2b
  285.        sar edx,ROUND
  286.        push dx
  287.  
  288.        sar eax,ROUND
  289.        push ax
  290.        mov edx,.c1r
  291.        sar edx,ROUND
  292.        push dx
  293.        mov edx,.c1g
  294.        sar edx,ROUND
  295.        push dx
  296.        mov edx,.c1b
  297.        sar edx,ROUND
  298.        push dx
  299.        push cx
  300.        call gouraud_line
  301.  
  302.        pop ebp
  303.        pop edi
  304.        pop cx
  305.        pop ebx
  306.        pop eax
  307.  
  308. if Ext >= MMX
  309.        movq mm0,.c1g
  310.        paddd mm0,.dc13g
  311.        movq .c1g,mm0
  312. else
  313.        mov edx,.dc13r
  314.        add .c1r,edx
  315.        mov edx,.dc13g
  316.        add .c1g,edx
  317. end if
  318.        mov edx,.dc13b
  319.        add .c1b,edx
  320. if Ext >= MMX
  321.        movq mm0,.c2g
  322.        paddd mm0,.dc12g
  323.        movq .c2g,mm0
  324. else
  325.        mov edx,.dc12r
  326.        add .c2r,edx
  327.        mov edx,.dc12g
  328.        add .c2g,edx
  329. end if
  330.        mov edx,.dc12b
  331.        add .c2b,edx
  332.  
  333.        add eax,.dx13
  334.        add ebx,.dx12
  335.        inc cx
  336.        cmp cx,.y2
  337.        jl .gt_loop1
  338. .gt_loop1_end:
  339.  
  340.        mov cx,.y2
  341.        cmp cx,.y3
  342.        jge .gt_loop2_end
  343.        movsx ebx,.x2
  344.        shl ebx,ROUND
  345.  
  346.        movsx edx,word[.col2r]
  347.        shl edx,ROUND
  348.        mov .c2r,edx
  349.        movsx edx,word[.col2g]
  350.        shl edx,ROUND
  351.        mov .c2g,edx
  352.        movsx edx,word[.col2b]
  353.        shl edx,ROUND
  354.        mov .c2b,edx
  355. .gt_loop2:
  356.        push eax                       ; eax - cur x1
  357.        push ebx                       ; ebx - cur x2
  358.        push cx
  359.        push edi
  360.        push ebp
  361.  
  362.        sar ebx,ROUND
  363.        push bx
  364.        mov edx,.c2r
  365.        sar edx,ROUND
  366.        push dx
  367.        mov edx,.c2g
  368.        sar edx,ROUND
  369.        push dx
  370.        mov edx,.c2b
  371.        sar edx,ROUND
  372.        push dx
  373.  
  374.        sar eax,ROUND
  375.        push ax
  376.        mov edx,.c1r
  377.        sar edx,ROUND
  378.        push dx
  379.        mov edx,.c1g
  380.        sar edx,ROUND
  381.        push dx
  382.        mov edx,.c1b
  383.        sar edx,ROUND
  384.        push dx
  385.        push cx
  386.        call gouraud_line
  387.  
  388.        pop ebp
  389.        pop edi
  390.        pop cx
  391.        pop ebx
  392.        pop eax
  393.  
  394. if Ext >= MMX
  395.        movq mm0,.c1g
  396.        paddd mm0,.dc13g
  397.        movq .c1g,mm0
  398. else
  399.        mov edx,.dc13r
  400.        add .c1r,edx
  401.        mov edx,.dc13g
  402.        add .c1g,edx
  403. end if
  404.        mov edx,.dc13b
  405.        add .c1b,edx
  406. if Ext >= MMX
  407.        movq mm0,.c2g
  408.        paddd mm0,.dc23g
  409.        movq .c2g,mm0
  410. else
  411.        mov edx,.dc23r
  412.        add .c2r,edx
  413.        mov edx,.dc23g
  414.        add .c2g,edx
  415. end if
  416.        mov edx,.dc23b
  417.        add .c2b,edx
  418.  
  419.        add eax,.dx13
  420.        add ebx,.dx23
  421.        inc cx
  422.        cmp cx,.y3
  423.        jl .gt_loop2
  424. .gt_loop2_end:
  425.  
  426.       ; add esp,84
  427.       mov esp,ebp
  428. ret 18
  429. gouraud_line:
  430. ;-------------in - edi - pointer to screen buffer
  431. ;----------------- stack - another parameters
  432. .y equ word [ebp+4]
  433. .col1b equ ebp+6
  434. .col1g equ ebp+8
  435. .col1r equ ebp+10
  436. .x1    equ [ebp+12]
  437. .col2b equ ebp+14
  438. .col2g equ ebp+16
  439. .col2r equ ebp+18
  440. .x2    equ [ebp+20]
  441. .dc_r equ dword[ebp-4]
  442. .dc_g equ dword[ebp-8]
  443. .dc_b equ dword[ebp-12]
  444.        mov ebp,esp
  445.  
  446.        mov ax,.y
  447.        or ax,ax
  448.        jl .gl_quit
  449.        mov  dx,[size_y_var]
  450.        dec  dx
  451.        cmp ax,dx    ;SIZE_Y-1
  452.        jg .gl_quit
  453.  
  454.        mov ax,.x1
  455.        cmp ax,.x2
  456.        je .gl_quit
  457.        jl .gl_ok
  458.  
  459. if Ext >= MMX
  460.        movq mm0,[.col1b]
  461.        movq mm1,[.col2b]
  462.        movq [.col1b],mm1
  463.        movq [.col2b],mm0
  464. else
  465.        mov eax,[.col1b]
  466.        xchg eax,[.col2b]
  467.        mov  [.col1b],eax
  468.        mov eax,[.col1r]
  469.        xchg eax,[.col2r]
  470.        mov [.col1r],eax
  471. end if
  472. .gl_ok:
  473.   ;     cmp .x1,SIZE_X-1  ;check
  474.   ;     jg .gl_quit
  475.   ;     cmp .x2,SIZE_X-1
  476.   ;     jl @f
  477.   ;     mov .x2,SIZE_X-1
  478.   ;  @@:
  479.   ;     cmp .x1,0
  480.   ;     jg @f
  481.   ;     mov .x1,0
  482.   ;  @@:
  483.   ;     cmp .x2,0
  484.   ;     jl .gl_quit
  485.  
  486.        movsx ecx,.y
  487.        movzx eax,word[size_x_var]
  488.        lea eax,[eax*3]
  489.   ;     mov eax,SIZE_X*3
  490.        mul ecx
  491.        movsx ebx,word .x1
  492.        lea ecx,[ebx*2+eax]
  493.        add edi,ecx
  494.        add edi,ebx
  495.  
  496.        mov ax,word[.col2r]
  497.        sub ax,word[.col1r]
  498.        cwde
  499.        shl eax,ROUND
  500.        cdq
  501.        mov cx,.x2
  502.        sub cx,.x1
  503.        movsx ecx,cx
  504.        idiv ecx
  505.        ;mov .dc_r,eax           ;first delta
  506.        push eax
  507.  
  508.        mov ax,word[.col2g]
  509.        sub ax,word[.col1g]
  510.        cwde
  511.        shl eax,ROUND
  512.        cdq
  513.        idiv ecx
  514.        ;mov .dc_g,eax
  515.        push eax
  516.  
  517.        mov ax,word[.col2b]
  518.        sub ax,word[.col1b]
  519.        cwde
  520.        shl eax,ROUND
  521.        cdq
  522.        idiv ecx
  523.       ; mov .dc_b,eax
  524.        push eax
  525.  
  526.        movsx ebx,word[.col1r]
  527.        shl ebx,ROUND
  528.        movsx edx,word[.col1g]
  529.        shl edx,ROUND
  530.        movsx esi,word[.col1b]
  531.        shl esi,ROUND
  532. .gl_draw:
  533.        mov eax,ebx
  534.        sar eax,ROUND
  535.        stosb
  536.        mov eax,edx
  537.        sar eax,ROUND
  538.        stosb
  539.        mov eax,esi
  540.        sar eax,ROUND
  541.        stosb
  542.        add ebx,.dc_r
  543.        add edx,.dc_g
  544.        add esi,.dc_b
  545.        loop .gl_draw
  546. .gl_quit:
  547.       ; add esp,12
  548.        mov esp,ebp
  549. ret 18
  550. if 0
  551. gouraud_line_SSE:        ; new
  552. ;-------------in - edi - pointer to screen buffer
  553. ;----------------- stack - another parameters
  554. .y equ word [ebp+4]
  555. .col1b equ ebp+6
  556. .col1g equ ebp+8
  557. .col1r equ ebp+10
  558. .x1    equ [ebp+12]
  559. .col2b equ ebp+14
  560. .col2g equ ebp+16
  561. .col2r equ ebp+18
  562. .x2    equ [ebp+20]
  563. .dc_r equ dword[ebp-4]
  564. .dc_g equ dword[ebp-8]
  565. .dc_b equ dword[ebp-12]
  566. .lenght equ [ebp-16]
  567. .factor equ [ebp-24]   ;new
  568.        mov ebp,esp
  569.  
  570.        mov ax,.y
  571.        or ax,ax
  572.        jl .gl_quit
  573.        cmp ax,SIZE_Y-1
  574.        jg .gl_quit
  575.  
  576.        mov ax,.x1
  577.        cmp ax,.x2
  578.        je .gl_quit
  579.        jl .gl_ok
  580.  
  581. if Ext >= MMX
  582.        movq mm0,[.col1b]
  583.        movq mm1,[.col2b]
  584.        movq [.col1b],mm1
  585.        movq [.col2b],mm0
  586. else
  587.        mov eax,[.col1b]
  588.        xchg eax,[.col2b]
  589.        mov  [.col1b],eax
  590.        mov eax,[.col1r]
  591.        xchg eax,[.col2r]
  592.        mov [.col1r],eax
  593. end if
  594. .gl_ok:
  595.   ;     cmp .x1,SIZE_X-1  ;check
  596.   ;     jg .gl_quit
  597.   ;     cmp .x2,SIZE_X-1
  598.   ;     jl @f
  599.   ;     mov .x2,SIZE_X-1
  600.   ;  @@:
  601.   ;     cmp .x1,0
  602.   ;     jg @f
  603.   ;     mov .x1,0
  604.   ;  @@:
  605.   ;     cmp .x2,0
  606.   ;     jl .gl_quit
  607.  
  608.        movsx ecx,.y
  609.        mov eax,SIZE_X*3
  610.        mul ecx
  611.        movsx ebx,word .x1
  612.        lea ecx,[ebx*2+eax]
  613.        add edi,ecx
  614.        add edi,ebx
  615.  
  616.        mov ax,word[.col2r]
  617.        sub ax,word[.col1r]
  618.        cwde
  619.        shl eax,ROUND
  620.        cdq
  621.        mov cx,.x2
  622.        sub cx,.x1
  623.        movsx ecx,cx
  624.        idiv ecx
  625.        ;mov .dc_r,eax           ;first delta
  626.        push eax
  627.  
  628.        mov ax,word[.col2g]
  629.        sub ax,word[.col1g]
  630.        cwde
  631.        shl eax,ROUND
  632.        cdq
  633.        idiv ecx
  634.        ;mov .dc_g,eax
  635.        push eax
  636.  
  637.        mov ax,word[.col2b]
  638.        sub ax,word[.col1b]
  639.        cwde
  640.        shl eax,ROUND
  641.        cdq
  642.        idiv ecx
  643.       ; mov .dc_b,eax
  644.        push eax
  645.  
  646.        movsx ebx,word[.col1r]
  647.        shl ebx,ROUND
  648.        movsx edx,word[.col1g]
  649.        shl edx,ROUND
  650.        movsx esi,word[.col1b]
  651.        shl esi,ROUND
  652.  
  653.        push      ecx         ; store line lenght
  654.        movd      mm3,.dc_r
  655.        psrlq     mm3,16      ; load dr to lowest word of mm3
  656.        pxor      mm2,mm2     ; clear mm2
  657.        movd      mm4,.dc_g
  658.        punpcklwd mm3,mm3     ; unpack dr to lower 2 words in in mm3
  659.        psrlq     mm4,16      ; load dg to lowest word of mm4
  660.        movd      mm5,.dc_b
  661.        psrlq     mm5,16      ; load db to lowest word of mm5
  662.        punpcklwd mm4,mm4     ; unpack dg to lower 2 words in in mm3
  663.        lea       ecx,[factor]
  664.        punpckldq mm3,mm3
  665.        punpcklwd mm5,mm5     ; unpack db to lower 2 words in in mm5
  666.        movq      mm6,[.col1b]
  667.        xor       eax,eax
  668.        pinsrw    mm6,eax,3     ; clear the highest word in mm6
  669.        mov       eax,010000h
  670.        punpckldq mm4,mm4     ; unpack dg to 4 words in mm4
  671.        mov       [ecx],eax
  672.        mov       eax,030002h
  673.        punpckldq mm5,mm5    ; unpack db to 4 words in mm5
  674.        movq      mm7,mm6    ; load r1r1,g1g1,b1b1 to the first three
  675.                             ; words of mm7
  676.        pxor      mm1,mm1    ; clear mm1
  677.  
  678.  
  679. .gl_draw:
  680.        mov eax,ebx
  681.        sar eax,ROUND
  682.        stosb
  683.        mov eax,edx
  684.        sar eax,ROUND
  685.        stosb
  686.        mov eax,esi
  687.        sar eax,ROUND
  688.        stosb
  689.        add ebx,.dc_r
  690.        add edx,.dc_g
  691.        add esi,.dc_b
  692.        loop .gl_draw
  693. .gl_quit:
  694.       ; add esp,12
  695.        mov esp,ebp
  696. ret 18
  697. end if
  698.