zw?vdonlDd)%`x8&q$PV!-2cN%ruV0tdKq_KEP>i*pa=!B)8b_zb*m(K=7>q8VRAIj1^D87
zQk0qZIEYtIp6iJqG_XA^Pm(xB@~r?rfmDsMG88{W{j(9Pa9+$Eh|=gSvyEk3nGIVS
zNck6)k=uK~U7noWaX(lx$Hwct&S~NRKYEg*9t&A07fV!7>JH80xJO|BtPTE_y17pw
zMy}P5#kKvC3;Za@ZUrBOi7C&7f*uxVutu`o4El0T5q4BRS0N>a`*NP!l?1(I0WsR4
zc+McoP?|H5=IpU{In^)8i2;SgvW5Q6APYF*1rM2qYbqQfc)^J`cop4&hlo
z)0HBdvxufQ$C2~RwcGh>kfb}ebMfJ*#`vkP9%Bm8QxJjSPLvUZ$Z)9d-8}bujl$$Q
zKLl>G-Id@RnF!98E27oczOpP@5v11}4iq9U@Yh-D(`o~bL
zEtT>Gsk0)nF*U#wH?*Qaix1ZzJSH;LIL6L~VO(vFVbq^=Y
z+q)30*V+&wajXM9(qbqC~B{6iqONlOE%R2|(
zkiEy5arhvIBPZTw#h3{4GWZ@}5E9*DhFV49d@zR`8%vP|{3pG($m3Itg_sB^GWlia
z!{-!u%?u?hEPbO{`ODd|w;>q|$lfzbll2vRQ`;HD(Gku}(of4LEQLNcO$wW((CUx>
z&q6=71d<>GffLW{K3GnhGHrLI+Fqw
zNBVnE*h;!`%|IxD%PNNsM0>;Mz|MxqSDA-xsFyA|T1noG`Bi@?GoR#Y#mwsuFMzZQ
ztSB{&e_P{}GMIe)4uzRZJoKID`@Y2&sGNL|KsVuIF5=`8qo?wXh7yZZ4M+M;cy$(K
zuj)_nd2aL|+DRREv%*J;_56=K30O#8)9^`0Y&3ri!RCL=0cg&dCDM`T^!Z#Q6PLC&
zu*%zoq`MgaL}K{QboIv|tuG4@mIfIN!iZbSZp3e9nGR~L{>F+_Vi2&bgF~akz#OjB
znLN2{PlE~83I2H>
zQ%n;IJJhWQtf|5Js>rntkQ>_4CydZzLwjH;|0mm;{F0&vcuk%oIU1oOfdb;5DVvC$
z!k;%U=G}G!F(_+ojQ~>1MeH6gbm*jzaCajSQjAvLYYM}wN+e;ipd>
z+?h%_{c5)1y^}4|8uc_3g|hFW0_MKKENO_@8x&KW;An?X6A@40?HI)r-z)5IVS
zu!*`1X*0zl;OOPS$lkU&tFe__{!d&4#U`k_Cn`7mU7?$N~R-%uhJkS^#399NcB+oE3bC-}J(WbY3LpV}%i
z1<65K(g)&GhVmjy(e=q9T9`Pej`*m>dAiNtxq0;Gr+e-D_w
zvi}V?+S#y8)XFI=ssU9nVhz-%_mvTaZ-JZS07Mkte-6r#7d4UoJ*o3G1Z~*+;sfOQ
z9+ZHKDCw-=KLKOPv9RDgF$&Ca5VJupyMI;#mY^2yIt+wsbRkJA?SldioOIY&;C1H$
zq$!otKkr%AmM-O(3Pks7#;*uu`8H-304rGkNuq0K`EQ04MjWqDeCCqcs9`VrbSh?K
zA6u*<`D0N|AXHtq$#XBVw&bk^r7;^aXI@<^QPCR9aLzm`rtO>=W(__OpIH{-%2%anIn5+}ycLh=;6czdkr57j#aONX*lLCk9sIxo_mZ#~Nr
zD}BE9-IZuR)A;?nf@gU#_*|sG@NFkZ32uR_Fcf6O_@jZMfXe|)_L&2*=*wA3OAW{v
z(SiF}hf;N;i8IcMq7u-4=8Ifv1ZMF6lz)2$`7GZrp=wVgmI?Hu$zsAzA+g{E_=-tj
z8Gm+PB~-4^_p21fo(^-&dm7(RyOl(F9V9aY*<57Ke5K0U{@)mZb8|H&K&Yh_FVxF<
z<&sZR4n^3|jV!ounLg20k81o|OALyxx3iJWCNfsP;DCb9AgwHKFSv*me*y3~`yYZ3
z2etpYe5YfoJ`ney=Bl}h3stFW=70i|F69qC2N7}*g-Q@eIj7)^-V)YRAiY%30MdmC
zg)Q^^hZU(f7=sfs;1_Q8jw#W>9}3x3kmN#b!t5`R;fp`<02i=7icn>Z4AqEH01~9Y
zQEZR)AIaqlvIx1om@*qq3j|c|XB`C!G%FzXD1j5Icz_9HkbHe++)8?16Ch_Y{8!P&
zaFrL9=zkD|Q(GpjNXD>Qkn8$Lk?BeGE_@^z`YnC22%0aHTSE}~rrNEP%j-NPY}vEK
z4aCa)@^;N$Ns8?E^K^euF{J)S%P;Po9%hjLWrjY$fcnmQl!F%y9s%aV1Q3m?@w-yj
zr0`)u4-qbBS8B+vRY?^vftcHU2#bt)Cn`18Kc9%PB8BPic4cYpo9VQQ0lgqj)iWjbi}Pi2fJ2Od$PU$@1zQeeT0N@0(BRe8?x(lBUZ7S^WCl
zOg$OR%Gw8QEmW6em@5!AW!8I>*B{dXmi_Q_qFDL!<`LlLEGau+qBe$hn!YpWk1Iro
zMsjTFCRx}?G5mk&^T!7*34jW{ZZt!+MONx_F;a{gaNSf$W_+W^p|zU|5DBh8;-9c4hR&W%&N)pI7t%{zvAD-nH%{s
z74-4aJEWxLzUp-YZ@7Ts>44McR9`ufP|}ME5OBS75Ef
zaBC2a9Y2uJ*T}33JR}Q1Z$VfK4nlXgdtU#&TR|S6RTfYkD%9)ko*OS|*^}v0VbJ~Q
z>lWC>RPK+24^~va&tQ8VX!WK$u$(B7bV>T+UK5ig-z8c7R++6+N_xKjMo+FY#D6KnC}6a-ep|hW#KFmK~hs{0DVA)Zd!N8MVHg-ZVx_
zUp~iSSj_Hg;lP#elcQ5w-CNhCxbD@{&Xa3N33a>rL%Hju0XkatyBaE2%<#Aa?=$ym
zLTj68e*)(^uLLA@*Soa{$t5vlA3#se@vGlwyt9e?-hzr1=*p|#%Dri=mjVPVgB#eN
zf4vt6lJ&$t13Js-ABhXTl
zXio!Dd}sKs0AEhTK$Q;zU@1tVIt^y9IV(@uZ>+A86w_Z_I#>t?ybcnr{^o5@PB0OU
z1kMa@YA>(fIDpkWr9Tfax7e=j^PK@|Z2CqI(DbX+i$*mlT6C7x@biLP>h8L1jb1sR
zUna#0PGLLub9~P^I~)Bsx`1aqhiwkCvo^jd-?NYegd@Gf*%2A`<1CDlRTnr)9xMEu
z0+mt{+HC3o$~4VgpiU*?;KUdVrF|mlgeO(lz?SlH*6SDTcXa-m&o~)Q7O)<~Vy&qV
ze}2PE!kNOE;@@h2(S)RZBKAip@_`H;Q{i9Y4^mLwIr~Vn$uDHd`CC$5$gs8JOBBG)
zl9B}v32IcWGfhzC-Zv@RKvWee*tQ^jJevW}OuZkVe_!0*GWAE
z!vFbkdc8RwAt~#gIbOSgc(xwAiNIjf}5%rOnq!J-Ql@V&WVU`y?+20vv*0MW!ky
z6|<|zxjl{Ri~m2QA;M{S-_oW^$;v5Ry>QPwZV3mY?uqFKhJf<2#_ORFAong(S;`n@
zYV+>?a|%8UOgI_A)>=4b4}3eMAAt-MZ^wlBIQ6jf-!i_^$F(`2N9n1X{TlJ)@r@@r
zz)=)pLR~VpjC_Fp*&nJz2rIaDRaJ#z&gVZmo(l$&h>jX)fc;(u{0>E?Xa%Wj`_YXC
z{bE<+26S7zVAf=v6rPCBAvNZ{NK&UUJY|7f!tanT6|cQIDd_;JmEFe)Wa{h=h*T8&
zn8OQcEHc$3IQ>X}1%92C#edQl@@37ua^tMr2huGgw5MVw@ld$OQnY`(V$Iyyf!F>F
z2g(I}De{TYeJY?s5mQgfgQMK92^pujbRGxo1672=6LR1sFcl;NjK_=7Y^Mk=a+9Ph
zrv93(CGVIR?+Gv%36N-xy$EE+f5=y-8)gZoLm|RCzbwB{GypPJ8`q!9ZJeI3+ll%$
zEv^BWYrB|oB>(ZgRMFKP$Xa_UCw|8(fnT*BRdE8qn&71$C(et}Wj1Cj7W^7EK*g!M
z2(0PhcHo|_ABnUpvo0D6u|TQzmFaNyAJtjCAO#)}PmZQTy`@7RW{0tV0RVIu(z0>6
z+6!bjX+<4C0>z5R!O&%z;8XkL=+&5l2v$JH_(U_t%Hl#cz6abq1uu7uO(=bex|3c6v%HENJ;hX|7(vJ8Uwk6KBadsf{EZl0mu}1+4F2(v
zk>Z3qx8j75MDOVUtvtXjOIJ*7-DpK1>~lqtTc8LRyK
zMAvrYBNHpIi}x-nq^aq=79l7yn(yYg-##_#7nA)_!6Z%|Fbu1IpTHSJpF^Jshyev=
z>?zY#7Ci$wo;spdN@FbUqkEqxb$@OiHWzC(A$M~0u2@^(c)y1^Oizs5#od8Wp+u1Z
zV@1p2A2{%)X1Z4L@{<#Hl(en7&m)*_Rp_U{uE58>e<=kGS8QvrYe3n79f6N#UdM_T
z)rONU&jP#iAUtv-?V7bv*ahAB=1=eVFin}ld;F#rTmx~4
zT-FEmTH1IH+@N2hgP%WoOfD&t(pQCP9Nz6G9(;yj_9^R;sUzQ6@|^rw+b;jWUW_gw
z(j2wBn6Z!`3+{Rv#`p7qFi_|d-`}U!A<+rqSW=+sQ2y)iyl{k
zTVeQDH!WdxVeDbN!U-`>;hS>>J{safI%*)O`-^a7Nq_96m$2K3R#FmgF}?K?_Ka
z=r5i|l_JquEjFy6mq=c8@pT)R8yN?tV?PRSd(BmPP_kxEEhjmTo_65C^f|ko=^@}$cFuDPy(BF%9`%fJA
zKfR_bO`9j>pM~)*6;X_+V8{L1fL_T$C_~W&eAR>*H0_@f
zsp|Hu3cE&z4ddLAx9(fSX5)~W`K?$CH6hv1X1h&wlNzEaWV?x=8x=%Y=i=re+xo
z3LG>IC~9hcF@(HwmOzQ19Oc@Z&NW?rC;|JlDo8|w*L?QaBdLoxKZv&;4Lgk@M={vb
z{vuWLYlBEdg`Oqv_I86WA0LVxO16G!clXscT#dvI#u7ca(~_$iyDYwF=W>&l33-pO
zs7VC2_DI=#ro5u-jg!7{!~d7?o#LlWeGbU?fMO+`xS70We5HxcAt^Sx<6*fQSZ_tj
zW{7R$n_|FZdTV#8wce2*wj)KWo9K1L0MXVza1+C+T`}cif@}p_ao{}S1D<5CW)F_}
z{S&X3NN=)NN#AgIVclWJX!L3aq
zA>S%Kr&oKA`b5h71(~enApX!tyBwO3N1{^?B&5yCpA?o9R=4Rp?SO?~^NHg?u}{-W
zhGDkVSO+7ko3_Yo;>Q@~dHwi)qOPh|;GyH?hu7vA55h4Y)on2kTc&_d9f0lx`a+((
z_Kw5R`RgXQF>xs(Kf39%KOP;`v6MSRS@)Y#u)G#-cXZfIWi$kfV`7r2#=f61ZC3{R
z2cX+s1>}Bf_DHZ$@|;~qpt;(;MUJR;-+@l;*k!H^37iC}_U)Esc7I28J@ouSI;h9CndWzgNpTC~eIN=7wzC1Uk#su!eukUvsBDd{_zbtN76-
zg6bB_(wBowB;-8a5(Qs+K5_9rv&&OKzai_LXR6nTOR6EDb*nv$>mU=|BSsS5ZkEJe*NbN^P~8V6H1GkUOE
zeOMXP!gy#_=)SQ)1t85@mn(}}bGOG(&F-|K1I8}yHe@w+7ky*icy1(QwFA!99=ZN}
zsxZ34-&3>GvHZ5UQN-}h)}XRGX3#L43(-`IZPGg6sImkR(mJWvLmHwZQ#ioJFocCo
z>^81g`q^b|hASn|f7n3xaH6-17|TcT81JUsFGg{}YfOzzgFYbYAR)#b*d%E=XI&%@x@(
z)+i})ii4jId~Tf5^emyKrx^FIEs-Qfy&i?|o*#i0qPqP+f*q>_*J1fl)Udi+XkD$JzN8QKp|#AHaiJT@et0WIa=0@uHgfUb_?vi7
z)SM>c%Qo9R@u*Or#^}~5UOIbv$bvG8<*y}OS(eq%b^Swm!iOARZoa=GATwW_ru^*~
zdj&qU2f7Q?^YbwULZE3!fdYRJYe&p(*GYrrJvkb@K!G}{KBX(wqZ<4>PG2`=YMpY?
zpQXxEw`eN)3{@x@oD!>tj4#-I2w1Hb?0~+-sS(;To!9(860+eZy7U_Lahh`mpXTuX
z!U9D(;Sw9|ned^-c2NO6Y2S*IDPp2Fq>!FR~0E0@Psd
zZa>2NCQJF_7xR-}9Roj4Um*=zXOBt7_P+%^@%=?fQqhUm!8c!_PR&bdZ-Pt~gO
z#_HVksx4l494fQS@~WFa$^o(PHddT;!fm|IIe^-3S9afm?SUvgkJeVbtm(W8c@Zjm
zl3W*KE^Hl3^>yl=qE=~b3>4hYWG*}ukj#BaB28q8
zw<2wxapt*!iUfyA98?_|-TU-8z96q=>oGO6MOYBtYRymfH|?X4;{|06v!3UH!z$n
zqqiOmETD%Su{Z611uGa^ot0(RR>9|!H(l&(ZVNkE0_zFTBe}Y%u^t}5Q^9C=km%PM
zqHfWFf5KA~8K~?Etl%e?kxl2}EHmC$^Tw2p`&y{T`g`eq6VWB;EibJ7ue@~Ko0Uka
zFn8#st*tse<0e9(mC)$N?v4J2YN#zTkD=$&E*VgUfj*C|$XE3{{~?JOw^IgTx!K;M
zFCJ%2|FsIGrr>MrH?jNe;)lrTFpZv?&FPGK$i1}kSC$h^Hk?0iM3g8)IxG|MkuOO@
z$o+&5F;U%qgGse!k7^vfp_haMnRid#W0uA7&$*GwKJ=;OJrl+e9v_#D*v-PXF>$~s
zgd*D~23$`-nl~NW7CKu;R*w6`^n_cRZfQRk(fIQ-4y9sN^m3O|s1W6~B*<-70{CH%
zMd)=FGa1Hx(g=wdp8t?9;czWDMExDtFblla-|Ob&2oIe1TM0hMbj={;9D9XfJ5quS
zLDX&bz7FH)FpL7e6KL_0=n^L`tU2<%A~+I7spHWrw_Lx1{MEuHxOS;AZcq)0kosiiDB*
z3umzNbQ3aF#5D26s>Qtd2Xi`t0n>nIFufwDD1QIWrMvM(j2%|Sp%p3
z&PP>*>>PVWZ+jU@(`sY+d#7gKxT?(xShxzh^@6m>ZA8AdeBN;{wNmw=oDmt-sHSac
z_LGRS+`U3TJ|MuY3!9GlBgdisHS4WEEgTze!(^j#l+VKW9lp^e|CST2!}Faoy%DZe
zd`M{}{+eNb6cF+^0LA?B(qb-h4#c${wDF|Y%OJ|kr<=6pi(X9%=QM^@^VGc|f!ZE!
zlljrz7$||t)<22eG`5>%z+}PQjU-tS2kDphebnhZ#m!Q4xl%O
z(QKh{A%_J_%CmsDj+SU2u*B6jj*^SIdme5vKbc9Kg@AM1vyS#hk->AOH@vR0HTrwq
z->qB>$Y6fv?fj)h5!1(giAuPal6)NhHd$W1v=m5}+01n8jDUqss~t9oz^Dmkv`(fg$7ljjSg9VA;r
zu0;Vdz36ukSp5|F4&M63mp~d{wmDv77mG{2)pNZI+nE6CCHq)Esik$xflPke5jyj@
zP}z}{S!06R_c)?7;-Op=K?xb<_tE?gDf}CCEmuDi`5orXJYbyipw{
zpkFzGXkcCak7@LC81D~0u$%1z1D56A2$52PG2m{E`WF{H{6rwTPO1&XBWB89m`M
z9pMb?bl&{FrQ&xLbx?-=BC?}=4W7p;N4QxKG*&3xBlrt^6*){tUH;jQj$M-vekXU3KIN}@}!)TNF
z&wnY(swbpG-POacD^ZaT2@xO+UALhTJ!O8fDjZwGnprZOlNl(Srtc21j#a@hJL)Fg
zOToNs68_wcv0!)YM)F5sq1xxNRc8>chO6D^kUO4!MO4QUrSdvsb>PdLFZ6QUvP$^J
z?y6ADR{Ro>}g#
zZZ*v2PeZL3GYxoa3lVVOgPeY=zyo;KE*4f?fc?wgJ%EmqoA{yFs;=7$ntgbY3G
zPR5^a@j<&Ba!+#4`mooZ=EE~Jz#$pheQ`CLKx{sJt}y=72)@L7S~tiXePoNgsBd+v
z!Gsuz~e8uJ;-_hQ3&?4*siky#%HS*(c)!H9oFu>M&+XvWZkdrH)^_Hctk0&W#Vi5*H4f^1m-d{7#3*wJqS
zw^&(tDSsgJjZ;&b^)0PNY3PB+gp;(bOme}UD=Z){s`#5qZhvyt_SZK&05|-9i{y?b!_PG=rGnkq!8OZ#>CwbgO9kR`m7|ea>mP-|8hV%9lfS|72`D+t%`Kv9Rjso0~@P{&@6seczhut(SO&6PwV3J!eP*(+;xGE7Oa1Xj~
zcQP*OpIrY|609Ev7$H-&5NeHNDU9`66oHy1kgK20>}eej^Q`2ARx90E2r5a+mI!`Wu`@J$|ZNqNDV0RTz4bw?-
zhtH7BPz=Argz1g+JahIoFCj*7
zwR*RTW#0L5)c!b#_R!|RKEL*X5_Yxb8ODAtpm0!9#u62f)pVX>+2hEn61LlcmT#E0
z{?_LhLE7N64z?X(%;jVOb@7tlB0Q`fnFCDo^Jwp%9AzKpNIJNsbpXL?$GE*Rh&BGk
z24$U&w!kyrJZTzt@FS_|@v6G{8aH{c8eeX*Edw}aeKEXXHo5B0_=);AnO*m5MUt#`o%W$%Ea}UtM`C!>Y553;+XQg;
z3-17y5s1w4suvraRxuCc6HF1q|ICsPp1&Jli8BnLxb`S>Q)5i9PeQ%PUZ?Max!AtN
zDfoOQT%V)HLY4>G>siY7ceS1RM;@5fdwTZpee`r}y-)+pcYS$>5GRFxBM!M4_W?^b
ze2!=u+YGqy}X=@@S}4P&}OQ?ZEAUez<}rIHVH)OAlAI)ua$iWuf*;-KOSZj_K5Nf&Rx~J^%c9
zUmN9-A9n`o+i8P|J<7)-0K2A2hI;xkaDj5d7|t1c)y#c6c2&;T5cLb55plH-{-M9k
z_tCDVYb2R>Xz@9W3r)`nY)z=QiB&OkTsnt&HU!@OP;#3qzxEFhK&PhtLev=SI72d58d&uWab>6$z}!)`5Yg*RlKp@W;+lUvpk$#>tz|iHENmtU%CE;
zK13OPGXwVJuQA_e42|~eH*OB5wYn{DOC@aAa~_@U1aB6n$e2dLUV271Han
zZEk{^p^8br9m)=OiS)MZ6Kqj#>b#QXTN!3Jj6%|uicYt!
zql25l!sE8|gKG_g@{6P)3
zp()~c*Dq=^!Ld&5c0cwr;
zyY^M)^Zb#9Hnuh0!WKi(U1h4ChrPR<$2i*B(jfkywVR5p7ZR?7hY6+!Wzd2|@8#Nq
z=IyMDYWe6Hy&IiOJvY@BPxL8eMGEJ6_l
z=PIpf$Ccd-6i-3-beE)u&*HAQ!0ha{BPuB2d_Joe8!TG<0xrSFyf7wepC(bK)_
z#XOhTZAaG6Jys^`=JVBh28NT1(i;?^`GNydsI>L?$^!pPgq-DlwD-U;h|>}Kf;
z&GKvB822f>8P#4ZKcnfPB4Amp^E4Hme9T3U+DvJR7tFMn+a>YxkmoVfF2^aL
z`2+jA6pb#kkyABHp1LJUy&p#t;CY%zE&+2IBV)(i(k;!C_B%A#J%2(tTM?oizSEI0
zYjZnVr-dS9^tS={_F$PV|I95B`SnrfN0$ycY)S(X#
zp53@rebG#B{S+eh=_c8#Y0=9vl}^3(hbhs;aM&M{k3DgLG$CetVY^Q|-^XAtr>R@z
zOW{iypls=TmePA1;aTc3j}LY7Md7_`mQ!Add+&G03!ZbaFpF{p2Kz*HQv0*IEN?(a
zCBWsF2aqmJ*D8EyF!d$*z5j;+aY?PWHd^=r2O&}AB_Y|?&1sf$uESPKwNFCYs~xHs
z0(>Kai3@!A502~gWMTO$XxX)*rc?LOgdirrp+^33>`c4#ZX?iEuT1dY=XD$j_F{LJ
z`H~YKsWp>yh0e?oc-Qc9TLPg$A95YbAHJB+2&`}M
zI{>X%hgg-U>YQ%A0;sj(6WLz#`lYkK31NH7Ptux}au+pzCS2a&K};NXhdNR$`95%f
zPJ`Qr%*lOmQZfYMmtAh(KJw*AP_Rb^5Xw5}b=_boym(gA@*^P{wy3@t0u}WW`Ir;J
zb9i%UHo)m#-$yA!y~1w7
z3VNYWVGcv^3_O?XoSq}<>pXU4IRnAD+;-W(Z-M(cB&N%PK1b|><3sL#C_xUvW3_f-
z)S`y#n~_(&5SrC^ZsG#M0)bk^O=&4Uu;KM>(mD5(BhYFfMlFkCggiE{6yz`w%3FMd
zLTs*j8{yA7mFA_SC$w-(Fz>OmfZBtCw>YiSnwtN$zZ*M&W&V~{ZXxF^%I-0%d;sq4pEo1Zgz%%e=Hcr+lJet?g?gB2vjVabu{bwl7
zrw$Sn^fF~7EiprESY1mF0$Kv6tISy!yqOb^0$*K}7FJ;#j1?;8?+<7z!P#(1=e&B9
z;30KWmWbaRG96DRZtkJ?YSnK>O(n5sh$iOH#d05F3q?2vU5qa5KQDY-!xc!#I$%Tg
z5Lxc-aL{kAIJoqO9SJDOZf@G+3hJcCy1CwG$LybMJhGTiZMJ)6v8rNwNzf4DpMV{?(fgL^HyEv>Ig6GB`lT#r{^^NC^f_{dsdNp?z_
z(|2l?@~{D@S%Hgf%%oF3)h>Ud3OB^Q#XO{S+<(&lOrlB1iwb@mkYR*$B(ti0+~;?y=s8r19<>R
z0c!*A&||iHoWo-A4~tp#>2;)!%+#V4UobF|rY3^EUsA}2G21W{CblX-(->Zmq+9Fa
z!1!@VDfE?vB5;Y5h(*GQHAd^@z)~%_sU#1nZdlF=b;02lBXke
zw})KP`hKeA?2>bUtcsDUshG<3cP(WJMFbhhly5s;_vcTX=J0OzQpgVH&9`pMwy@@X0NZGV-r**x2T$o<@7uvNVaRb6NJ{(=+z
z+Z$#TBV~X6$!P=Uf#H(mgWWa0y(&B264JR~4*KG#ro(5O2}ch~^$iuPGf~d6h_6*O
zw1}zma@Yu}NLyUa=BA&NkJr`rrIF*ag}}_)mqEPYSygksRmM!)%><3p
zY0V+!%CCgmH-5{o$~uyjL|C8YIs&$h>V>GeHzmFZa-tI42Tn!@)-jN%$eyUV)$
zkk3@vP$x9wwrH~E+ttBfQ`PN1TRLmO*?NqszA!Pn;_priBV-
z6a@?3yVn&-<|TT5vT?JZC2%~V(#wc4`2NvhX?=sYq*|90Yo~8wZMCuncec6X%hzEs
zg32ZZK6H5#$A=?h?ss{n^zM!uJeNhqE^Fac@z`tU&4d}A(KeR{^VxLwk}9*cKj+W0
zDm}Ywy4|aOb0yfZ{rhUIt@CWvy(y2mk~92js;Py^c0*k;J|Vn*Us$%`qP{0}aeZ!uNfSf?Hb(hwe%Sjuh@^m!nT5
z{eDfIYgaQoAojHkt_ECgd{w%&ot|8W7T-BKgdKiFBY8hJ)zT8
zC#&9eHKQDpTf;KQVR%G2yc^RbODi8W)8AK7zoT?YwQcDgfs^=?60~TT(m|ddOR76Z+w)4KL{z-dl4rBQBwozsP#eE$v+<4<0a`Zs1f%}jqmp1UB8A_X(%
zgKHjBnKbiuJ${*?qV%=Gg6KabR=nHmxOkwTL^eqxP_@y>xM5H(dh~d`On
zn0frowN0FU`5$b~e7cYSAx5pePRdVc^tttO@?;-}+$N7o)v=W5KRPO}C1IlqbZvB+QLx^ms2WGwW<7gJb$yUqb0?l42(m)}v8)Tq
zvv~>|W0oHEO0Ln}J##5F2OS0Xv(d8kQKu@FX-j`;3Uzagm;Ul^v2ReN;YOl+2rWs`j^Aqv<_0Db9zQ
z3JIlAIeM$&4553bC)6y`Ib>M7@s@~agVv{pdpZl|tNes2*Ue03a}r;S7KwtHx6{A1
zSfuNU*bN3m?kv2*6PiOQbF3dchFE4Qlr_Klns|MztGXWKEQ<}=6}qohe)&|A$0f~j
z>awMQdkEDpyyWUg`e~8Zz^7F6@V+^u&1U>z14bj~jl?4xGO79X$CyS;?)Pq+97c264Ez+%K-jJkFT*vV}TQJFnO)N^Jcm`}9Qgo%_FP6Yj0Zg2q>F<4MSH-s~K=+R&daSj==Dzjn6C
zE$*JZFJsc1+a!||y}rV<&1%*k?68>B^U`W6SU-QGGVE-X_zX;;mR)skTzp+xxG|8R
z#?izko;|f0a-$g2AE?xHMbz0jjPI>Cg=t*-gL8Te;~l3ZzV9v>#yw^MW&D7r3}
zH9;7A-DNW2Ocm<>Y?rdRVI`tW@~qldBIWo#p5kejKzHy|apO-8v-B@SMMqcq(CY)w
zfTzs~JE6AujyG{42|;oDF9QzIb>aIjovrKxOz7V9{{3ftV=*^Ab05DS-oW!%9YurX
zY&E@dVKu9MnX)M}eXh}LG_yGK#lvaFGHw6Hcy8|OU#EEH-#?lycZvHxz>Q_B@B7ZL
zonC%&wsN`ApSy98d|JJgz2|UKfjhQoo`*H(6cPa7(@nHNb5uaV=$+`?TvDfYO^14z
z?5TLN%))@H?aN6&uj)FQD#1k0ET&q&swowT?u;VExd6_{0j+e;x?+=<&RY^%f?(i)
z4=0nZ+&ha&!CX`Bl<&P6r1mdloldRgCTm%w#r!E{8XjmX*$X`jncBufSH)7BVl3#i
z)~S1*-N~GOo<4u1sIt0BI`>Sr(mw@9nDphfi@ljY^U|qRwd2^|^D)11`kC)mX3Te$
zsmDYKcZ9(@`uf3itmAB0_I~b_XRvR~QLF=)!nI?{C>iRJpAd!)dU#slzC@>~Ix5yH{2v{a>dMooWk;K(Tr+$*_?q8k#H(!g%k_`p&
zW$kZ@JL~x*D(a
zkyEvo!(v6<*|>#>^WeSGo||eDmHaeN?%{0Lby6`wmmPBP&M(M&9Oatctba4dhf!+c
zA7bC_BWP@%^nGQLhRWYer`@K)rfR2j<1CkRn#>s!BmCdJw;}0ew(w5=4X5rXx`bV=
z)98Nd+R0~BXleMk-|k)T;*WE2?su8q*ucrT|9|`n@^1;Z$_>RVREB_C06`!XMNNeo
IdF!zM14p*&djJ3c
literal 0
HcmV?d00001
diff --git a/examples/src/WebGL2Samples/texture_pixel_store.ts b/examples/src/WebGL2Samples/texture_pixel_store.ts
index f59ba34..62bccbe 100644
--- a/examples/src/WebGL2Samples/texture_pixel_store.ts
+++ b/examples/src/WebGL2Samples/texture_pixel_store.ts
@@ -63,14 +63,11 @@ import { getShaderSource, loadImage } from "./utility";
format: "rgba8unorm",
sources: [{
__type: "TextureDataSource",
- mipLevel: 0, size: [image.width / 2, image.height / 2], data: pixels,
- pixelStore: {
- unpackAlignment: 1,
- unpackRowLength: image.width,
- unpackSkipPixels: image.width / 4,
- unpackSkipRows: image.width / 4,
- unpackFlipY: false,
- },
+ mipLevel: 0,
+ size: [image.width / 2, image.height / 2],
+ data: pixels,
+ dataImageWidth: image.width,
+ dataImageOrigin: [image.width / 4, image.width / 4],
}]
};
const sampler: IGLSampler = {
diff --git a/src/caches/getGLTexture.ts b/src/caches/getGLTexture.ts
index d7a793a..7dce2c6 100644
--- a/src/caches/getGLTexture.ts
+++ b/src/caches/getGLTexture.ts
@@ -129,13 +129,13 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: IGLTexture)
const { image, imageOrigin, flipY, premultipliedAlpha } = imageSource;
//
- const pixelStore1: IGLTexturePixelStore = {};
- pixelStore1.unpackSkipPixels = imageOrigin?.[0] || 0;
- pixelStore1.unpackSkipRows = imageOrigin?.[1] || 0;
- pixelStore1.unpackFlipY = flipY || false;
- pixelStore1.unpackPremulAlpha = premultipliedAlpha || false;
+ const pixelStore: IGLTexturePixelStore = {};
+ pixelStore.unpackSkipPixels = imageOrigin?.[0] || 0;
+ pixelStore.unpackSkipRows = imageOrigin?.[1] || 0;
+ pixelStore.unpackFlipY = flipY || false;
+ pixelStore.unpackPremulAlpha = premultipliedAlpha || false;
- setTexturePixelStore(gl, pixelStore1);
+ setTexturePixelStore(gl, pixelStore);
if (gl instanceof WebGL2RenderingContext)
{
@@ -181,7 +181,15 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: IGLTexture)
// 处理数据资源
const bufferSource = v as IGLTextureDataSource;
- const { data: pixels, pixelsOffset, pixelStore } = bufferSource;
+ const { data, dataImageWidth, dataImageHeight, dataImageOrigin, dataOffset: pixelsOffset } = bufferSource;
+
+ //
+ const pixelStore: IGLTexturePixelStore = {};
+ pixelStore.unpackSkipPixels = dataImageOrigin?.[0] || 0;
+ pixelStore.unpackSkipRows = dataImageOrigin?.[1] || 0;
+ pixelStore.unpackSkipImages = dataImageOrigin?.[2] || 0;
+ pixelStore.unpackRowLength = dataImageWidth;
+ pixelStore.unpackImageHeight = dataImageHeight;
setTexturePixelStore(gl, pixelStore);
@@ -192,11 +200,11 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: IGLTexture)
{
const bindTarget = target === "TEXTURE_CUBE_MAP" ? getTextureCubeMapTarget(depthOrArrayLayers) : target;
- gl.texSubImage2D(gl[bindTarget], mipLevel, xoffset, yoffset, width, height, gl[format], gl[type], pixels, pixelsOffset || 0);
+ gl.texSubImage2D(gl[bindTarget], mipLevel, xoffset, yoffset, width, height, gl[format], gl[type], data, pixelsOffset || 0);
}
else if (target === "TEXTURE_3D" || target === "TEXTURE_2D_ARRAY")
{
- gl.texSubImage3D(gl[target], mipLevel, xoffset, yoffset, zoffset, width, height, depthOrArrayLayers, gl[format], gl[type], pixels, pixelsOffset || 0);
+ gl.texSubImage3D(gl[target], mipLevel, xoffset, yoffset, zoffset, width, height, depthOrArrayLayers, gl[format], gl[type], data, pixelsOffset || 0);
}
else
{
@@ -211,7 +219,7 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: IGLTexture)
{
const bindTarget = target === "TEXTURE_CUBE_MAP" ? getTextureCubeMapTarget(depthOrArrayLayers) : target;
- gl.texSubImage2D(gl[bindTarget], mipLevel, xoffset, yoffset, width, height, gl[format], gl[type], pixels);
+ gl.texSubImage2D(gl[bindTarget], mipLevel, xoffset, yoffset, width, height, gl[format], gl[type], data);
}
else
{
diff --git a/src/data/IGLTexture.ts b/src/data/IGLTexture.ts
index f79734f..6b3cc82 100644
--- a/src/data/IGLTexture.ts
+++ b/src/data/IGLTexture.ts
@@ -46,22 +46,11 @@ export interface IGLTextureImageSource extends ITextureImageSource
*/
export interface IGLTextureDataSource extends ITextureDataSource
{
- /**
- * 像素解包打包时参数。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/pixelStorei
- */
- readonly pixelStore?: IGLTexturePixelStore;
-
- /**
- * 图片数据。
- */
- data: ArrayBufferView;
/**
* 默认为 0。
*/
- pixelsOffset?: number;
+ dataOffset?: number;
}
/**
--
Gitee
From fe227bb24b57ecd58ef33f610d8fc5388a931d93 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 01:06:05 +0800
Subject: [PATCH 082/186] ITextureDataSource.dataLayout
---
examples/src/WebGL2Samples/texture_pixel_store.ts | 2 +-
src/caches/getGLTexture.ts | 15 ++++++++++-----
src/data/IGLTexture.ts | 4 ----
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/examples/src/WebGL2Samples/texture_pixel_store.ts b/examples/src/WebGL2Samples/texture_pixel_store.ts
index 62bccbe..37ffe57 100644
--- a/examples/src/WebGL2Samples/texture_pixel_store.ts
+++ b/examples/src/WebGL2Samples/texture_pixel_store.ts
@@ -66,7 +66,7 @@ import { getShaderSource, loadImage } from "./utility";
mipLevel: 0,
size: [image.width / 2, image.height / 2],
data: pixels,
- dataImageWidth: image.width,
+ dataLayout: { width: image.width },
dataImageOrigin: [image.width / 4, image.width / 4],
}]
};
diff --git a/src/caches/getGLTexture.ts b/src/caches/getGLTexture.ts
index 7dce2c6..15510dc 100644
--- a/src/caches/getGLTexture.ts
+++ b/src/caches/getGLTexture.ts
@@ -181,15 +181,18 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: IGLTexture)
// 处理数据资源
const bufferSource = v as IGLTextureDataSource;
- const { data, dataImageWidth, dataImageHeight, dataImageOrigin, dataOffset: pixelsOffset } = bufferSource;
+ const { data, dataLayout, dataImageOrigin } = bufferSource;
+
+ //
+ const offset = dataLayout?.offset || 0;
//
const pixelStore: IGLTexturePixelStore = {};
pixelStore.unpackSkipPixels = dataImageOrigin?.[0] || 0;
pixelStore.unpackSkipRows = dataImageOrigin?.[1] || 0;
pixelStore.unpackSkipImages = dataImageOrigin?.[2] || 0;
- pixelStore.unpackRowLength = dataImageWidth;
- pixelStore.unpackImageHeight = dataImageHeight;
+ pixelStore.unpackRowLength = dataLayout?.width;
+ pixelStore.unpackImageHeight = dataLayout?.height;
setTexturePixelStore(gl, pixelStore);
@@ -200,11 +203,11 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: IGLTexture)
{
const bindTarget = target === "TEXTURE_CUBE_MAP" ? getTextureCubeMapTarget(depthOrArrayLayers) : target;
- gl.texSubImage2D(gl[bindTarget], mipLevel, xoffset, yoffset, width, height, gl[format], gl[type], data, pixelsOffset || 0);
+ gl.texSubImage2D(gl[bindTarget], mipLevel, xoffset, yoffset, width, height, gl[format], gl[type], data, offset);
}
else if (target === "TEXTURE_3D" || target === "TEXTURE_2D_ARRAY")
{
- gl.texSubImage3D(gl[target], mipLevel, xoffset, yoffset, zoffset, width, height, depthOrArrayLayers, gl[format], gl[type], data, pixelsOffset || 0);
+ gl.texSubImage3D(gl[target], mipLevel, xoffset, yoffset, zoffset, width, height, depthOrArrayLayers, gl[format], gl[type], data, offset);
}
else
{
@@ -220,6 +223,8 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: IGLTexture)
const bindTarget = target === "TEXTURE_CUBE_MAP" ? getTextureCubeMapTarget(depthOrArrayLayers) : target;
gl.texSubImage2D(gl[bindTarget], mipLevel, xoffset, yoffset, width, height, gl[format], gl[type], data);
+
+ console.assert(!offset, `WebGL1 不支持 IGLTextureDataSource.dataLayout.offset !`)
}
else
{
diff --git a/src/data/IGLTexture.ts b/src/data/IGLTexture.ts
index 6b3cc82..1bcab64 100644
--- a/src/data/IGLTexture.ts
+++ b/src/data/IGLTexture.ts
@@ -47,10 +47,6 @@ export interface IGLTextureImageSource extends ITextureImageSource
export interface IGLTextureDataSource extends ITextureDataSource
{
- /**
- * 默认为 0。
- */
- dataOffset?: number;
}
/**
--
Gitee
From 300f4c597e8a3c5de39aa1edbaee5c185e816ba4 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 01:43:26 +0800
Subject: [PATCH 083/186] 1
---
src/caches/getIGLTextureFormats.ts | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/caches/getIGLTextureFormats.ts b/src/caches/getIGLTextureFormats.ts
index e33fe43..995dfae 100644
--- a/src/caches/getIGLTextureFormats.ts
+++ b/src/caches/getIGLTextureFormats.ts
@@ -1,9 +1,8 @@
import { ITextureFormat } from "@feng3d/render-api";
import { IGLTextureFormats } from "../data/IGLTextureFormats";
-export function getIGLTextureFormats(format: ITextureFormat)
+export function getIGLTextureFormats(format: ITextureFormat = "rgba8unorm")
{
- format = format || "rgba8unorm";
const glTextureFormat: IGLTextureFormats = formatMap[format];
console.assert(!!glTextureFormat, `未处理格式 ${format};或者WebGL不支持纹理, 该格式只在WebGPU中支持!`);
--
Gitee
From 79afba67d14be9892e79948229f1c99b2e6667ff Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 13:40:50 +0800
Subject: [PATCH 084/186] 1
---
src/index.ts | 1 +
src/runs/getIGLBuffer.ts | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/index.ts b/src/index.ts
index 9bdee54..9380009 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -53,3 +53,4 @@ export * from "./WebGL";
export * as internal from "./internal";
+export * from "./caches/getGLBuffer";
diff --git a/src/runs/getIGLBuffer.ts b/src/runs/getIGLBuffer.ts
index a9c1a9f..c9d0a68 100644
--- a/src/runs/getIGLBuffer.ts
+++ b/src/runs/getIGLBuffer.ts
@@ -6,7 +6,7 @@ export function getIGLBuffer(data: BufferSource, target?: GLBufferTarget, usage:
{
if (data[_IGLBuffer]) return data[_IGLBuffer];
- console.assert(target, `初始化时不能为空,可能该数据的渲染对象还未被渲染!`);
+ console.assert(!!target, `初始化时不能为空,可能该数据的渲染对象还未被渲染!`);
const indexBuffer: IGLBuffer = data[_IGLBuffer] = {
target: target, usage: usage,
--
Gitee
From acabbb32ea4e2fffde666966efa9da107a58322a Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 13:59:00 +0800
Subject: [PATCH 085/186] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20IGLTextureView=20?=
=?UTF-8?q?=E6=9B=BF=E4=BB=A3=20IGLRenderbuffer?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
examples/src/WebGL2Samples/fbo_blit.ts | 10 +++-------
examples/src/WebGL2Samples/fbo_multisample.ts | 2 +-
examples/src/WebGL2Samples/glsl_centroid.ts | 10 +---------
3 files changed, 5 insertions(+), 17 deletions(-)
diff --git a/examples/src/WebGL2Samples/fbo_blit.ts b/examples/src/WebGL2Samples/fbo_blit.ts
index dde04d4..5dc6c8c 100644
--- a/examples/src/WebGL2Samples/fbo_blit.ts
+++ b/examples/src/WebGL2Samples/fbo_blit.ts
@@ -1,4 +1,4 @@
-import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPassDescriptor, IGLRenderPipeline, IGLRenderbuffer, IGLSampler, IGLTexture, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPassDescriptor, IGLRenderPipeline, IGLSampler, IGLTexture, IGLTextureView, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -71,11 +71,8 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
magFilter: "LINEAR",
};
- const colorRenderbuffer: IGLRenderbuffer = {
- internalformat: "RGBA4",
- width: FRAMEBUFFER_SIZE.x,
- height: FRAMEBUFFER_SIZE.y,
- };
+ // 此处 Renderbuffer 直接使用 IGLTextureView 替代。
+ const colorRenderbuffer: IGLTextureView = { texture: { format: "rgba8unorm", size: [FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y] } };
const vertexArray: { vertices?: IGLVertexAttributes } = {
vertices,
@@ -190,7 +187,6 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
// Delete WebGL resources
webgl.deleteFramebuffer(fboRenderPass.descriptor);
webgl.deleteFramebuffer(framebufferResolve);
- webgl.deleteRenderbuffer(colorRenderbuffer);
webgl.deleteTexture(textureDiffuse);
webgl.deleteTexture(textureColorBuffer);
webgl.deleteProgram(program);
diff --git a/examples/src/WebGL2Samples/fbo_multisample.ts b/examples/src/WebGL2Samples/fbo_multisample.ts
index 8b08e5b..ea4b88d 100644
--- a/examples/src/WebGL2Samples/fbo_multisample.ts
+++ b/examples/src/WebGL2Samples/fbo_multisample.ts
@@ -1,4 +1,4 @@
-import { IGLBlitFramebuffer, IGLRenderPass, IGLRenderPassDescriptor, IGLRenderPipeline, IGLRenderbuffer, IGLCanvasContext, IGLSampler, IGLTexture, IGLVertexAttributes, IGLVertexBuffer, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLRenderPass, IGLRenderPassDescriptor, IGLRenderPipeline, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
diff --git a/examples/src/WebGL2Samples/glsl_centroid.ts b/examples/src/WebGL2Samples/glsl_centroid.ts
index 153b567..7bc492c 100644
--- a/examples/src/WebGL2Samples/glsl_centroid.ts
+++ b/examples/src/WebGL2Samples/glsl_centroid.ts
@@ -1,4 +1,4 @@
-import { IGLCanvasContext, IGLFramebuffer, IGLPassEncoder, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderbuffer, IGLSampler, IGLTexture, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLFramebuffer, IGLPassEncoder, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLTexture, IGLTextureView, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -119,11 +119,6 @@ for (let i = 0; i < VIEWPORTS.MAX; ++i)
// -- Init Frame Buffers
-// non-centroid
-const colorRenderbuffer: IGLRenderbuffer = { internalformat: "RGBA8", width: FRAMEBUFFER_SIZE.x, height: FRAMEBUFFER_SIZE.y };
-// centroid
-const colorRenderbufferCentroid: IGLRenderbuffer = { internalformat: "RGBA8", width: FRAMEBUFFER_SIZE.x, height: FRAMEBUFFER_SIZE.y };
-
const FRAMEBUFFER = {
RENDERBUFFER: 0,
RENDERBUFFER_CENTROID: 1,
@@ -220,9 +215,6 @@ webgl.deleteTexture(textures[PROGRAM.TEXTURE_CENTROID]);
webgl.deleteSampler(samplers[PROGRAM.TEXTURE]);
webgl.deleteSampler(samplers[PROGRAM.TEXTURE_CENTROID]);
-webgl.deleteRenderbuffer(colorRenderbuffer);
-webgl.deleteRenderbuffer(colorRenderbufferCentroid);
-
webgl.deleteFramebuffer(framebuffers[FRAMEBUFFER.RENDERBUFFER]);
webgl.deleteFramebuffer(framebuffers[FRAMEBUFFER.COLORBUFFER]);
--
Gitee
From cf7b4e7c663d76ed6d7ad23bd4f427b57d43bde6 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 14:07:11 +0800
Subject: [PATCH 086/186] 1
---
src/caches/getFramebuffer.ts | 32 ++++++++++++--------------------
1 file changed, 12 insertions(+), 20 deletions(-)
diff --git a/src/caches/getFramebuffer.ts b/src/caches/getFramebuffer.ts
index 8f7a165..55a44cf 100644
--- a/src/caches/getFramebuffer.ts
+++ b/src/caches/getFramebuffer.ts
@@ -82,33 +82,25 @@ export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRen
if (passDescriptor.depthStencilAttachment)
{
const { view } = passDescriptor.depthStencilAttachment;
- if ("texture" in view)
- {
- const { texture, baseMipLevel: level, baseArrayLayer: layer } = { ...defaultTextureView, ...view };
+ const { texture, baseMipLevel: level, baseArrayLayer: layer } = { ...defaultTextureView, ...view };
- const webGLTexture = getGLTexture(gl, texture);
- const textureTarget = webGLTexture.textureTarget;
+ const webGLTexture = getGLTexture(gl, texture);
+ const textureTarget = webGLTexture.textureTarget;
- if (textureTarget === "TEXTURE_2D")
- {
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl[textureTarget], webGLTexture, level);
- }
- else if (textureTarget === "TEXTURE_2D_ARRAY")
- {
- if (gl instanceof WebGL2RenderingContext)
- {
- gl.framebufferTextureLayer(gl.DRAW_FRAMEBUFFER, gl.DEPTH_ATTACHMENT, webGLTexture, level, layer);
- }
- }
- else
+ if (textureTarget === "TEXTURE_2D")
+ {
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl[textureTarget], webGLTexture, level);
+ }
+ else if (textureTarget === "TEXTURE_2D_ARRAY")
+ {
+ if (gl instanceof WebGL2RenderingContext)
{
- console.error(`未处理 ${textureTarget} 的深度模板附件纹理设置!`);
+ gl.framebufferTextureLayer(gl.DRAW_FRAMEBUFFER, gl.DEPTH_ATTACHMENT, webGLTexture, level, layer);
}
}
else
{
- const renderbuffer = getGLRenderbuffer(gl, view as IGLRenderbuffer);
- gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderbuffer);
+ console.error(`未处理 ${textureTarget} 的深度模板附件纹理设置!`);
}
}
--
Gitee
From beef0550a05cd8453242ed734971c42d124fe133 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 14:46:10 +0800
Subject: [PATCH 087/186] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81=20?=
=?UTF-8?q?IRenderPassColorAttachment.view=3F:=20ITextureView?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/caches/getFramebuffer.ts | 29 ++++++++++---------
...tIGLRenderPassDescriptorWithMultisample.ts | 3 +-
src/data/IGLRenderPassColorAttachment.ts | 11 +++----
src/data/IGLRenderPassDescriptor.ts | 2 +-
src/data/IGLRenderbuffer.ts | 4 +--
src/data/IGLTexture.ts | 1 -
src/data/IGLTextureView.ts | 1 -
7 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/src/caches/getFramebuffer.ts b/src/caches/getFramebuffer.ts
index 55a44cf..4ac8642 100644
--- a/src/caches/getFramebuffer.ts
+++ b/src/caches/getFramebuffer.ts
@@ -1,9 +1,9 @@
import { IGLRenderPassDescriptor } from "../data/IGLRenderPassDescriptor";
import { IGLRenderbuffer } from "../data/IGLRenderbuffer";
import { IGLTextureView } from "../data/IGLTextureView";
-import { _IGLRenderPassDescriptorWithMultisample, IGLRenderPassDescriptorWithMultisample } from "./getIGLRenderPassDescriptorWithMultisample";
import { deleteRenderbuffer, getGLRenderbuffer } from "./getGLRenderbuffer";
import { getGLTexture } from "./getGLTexture";
+import { _IGLRenderPassDescriptorWithMultisample, IGLRenderPassDescriptorWithMultisample } from "./getIGLRenderPassDescriptorWithMultisample";
declare global
{
@@ -13,8 +13,6 @@ declare global
}
}
-const defaultTextureView: Partial = { baseMipLevel: 0, baseArrayLayer: 0 };
-
/**
* 获取帧缓冲区
*/
@@ -36,25 +34,27 @@ export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRen
const drawBuffers: number[] = [];
passDescriptor.colorAttachments?.forEach((item, i) =>
{
- const { view } = item;
+ const view = item.view as (IGLTextureView | IGLRenderbuffer);
const attachment = gl[`COLOR_ATTACHMENT${i}`];
drawBuffers.push(attachment);
if ("texture" in view)
{
- const { texture, baseMipLevel: level, baseArrayLayer: layer } = { ...defaultTextureView, ...view };
+ const texture = view.texture;
+ const baseMipLevel = view.baseMipLevel || 0;
+ const baseArrayLayer = view.baseArrayLayer || 0;
const webGLTexture = getGLTexture(gl, texture);
const textureTarget = webGLTexture.textureTarget;
if (textureTarget === "TEXTURE_2D")
{
- gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl[textureTarget], webGLTexture, level);
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl[textureTarget], webGLTexture, baseMipLevel);
}
else if (textureTarget === "TEXTURE_2D_ARRAY")
{
if (gl instanceof WebGL2RenderingContext)
{
- gl.framebufferTextureLayer(gl.DRAW_FRAMEBUFFER, attachment, webGLTexture, level, layer);
+ gl.framebufferTextureLayer(gl.DRAW_FRAMEBUFFER, attachment, webGLTexture, baseMipLevel, baseArrayLayer);
}
}
else
@@ -64,7 +64,7 @@ export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRen
}
else
{
- const renderbuffer = getGLRenderbuffer(gl, view as IGLRenderbuffer, sampleCount);
+ const renderbuffer = getGLRenderbuffer(gl, view, sampleCount);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, renderbuffer);
}
});
@@ -79,23 +79,26 @@ export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRen
}
// 处理深度模板附件
- if (passDescriptor.depthStencilAttachment)
+ if (passDescriptor.depthStencilAttachment?.view)
{
- const { view } = passDescriptor.depthStencilAttachment;
- const { texture, baseMipLevel: level, baseArrayLayer: layer } = { ...defaultTextureView, ...view };
+ const view = passDescriptor.depthStencilAttachment.view;
+
+ const texture = view.texture;
+ const baseMipLevel = view.baseMipLevel || 0;
+ const baseArrayLayer = view.baseArrayLayer || 0;
const webGLTexture = getGLTexture(gl, texture);
const textureTarget = webGLTexture.textureTarget;
if (textureTarget === "TEXTURE_2D")
{
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl[textureTarget], webGLTexture, level);
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl[textureTarget], webGLTexture, baseMipLevel);
}
else if (textureTarget === "TEXTURE_2D_ARRAY")
{
if (gl instanceof WebGL2RenderingContext)
{
- gl.framebufferTextureLayer(gl.DRAW_FRAMEBUFFER, gl.DEPTH_ATTACHMENT, webGLTexture, level, layer);
+ gl.framebufferTextureLayer(gl.DRAW_FRAMEBUFFER, gl.DEPTH_ATTACHMENT, webGLTexture, baseMipLevel, baseArrayLayer);
}
}
else
diff --git a/src/caches/getIGLRenderPassDescriptorWithMultisample.ts b/src/caches/getIGLRenderPassDescriptorWithMultisample.ts
index 91471fa..b608686 100644
--- a/src/caches/getIGLRenderPassDescriptorWithMultisample.ts
+++ b/src/caches/getIGLRenderPassDescriptorWithMultisample.ts
@@ -22,6 +22,7 @@ export function getIGLRenderPassDescriptorWithMultisample(sourcePassDescriptor:
const renderbuffers: IGLRenderbuffer[] = [];
+ // 创建支持 多重采样的 渲染通道
const passDescriptor: IGLRenderPassDescriptor = {
colorAttachments: sourcePassDescriptor.colorAttachments.map((v) =>
{
@@ -34,7 +35,7 @@ export function getIGLRenderPassDescriptorWithMultisample(sourcePassDescriptor:
const colorAttachment: IGLRenderPassColorAttachment = {
...v,
- view: renderbuffer,
+ view: renderbuffer as any,
};
return colorAttachment;
}),
diff --git a/src/data/IGLRenderPassColorAttachment.ts b/src/data/IGLRenderPassColorAttachment.ts
index 2405d41..73e0a4b 100644
--- a/src/data/IGLRenderPassColorAttachment.ts
+++ b/src/data/IGLRenderPassColorAttachment.ts
@@ -1,7 +1,9 @@
import { IRenderPassColorAttachment } from "@feng3d/render-api";
-import { IGLRenderbuffer } from "./IGLRenderbuffer";
import { IGLTextureView } from "./IGLTextureView";
+/**
+ * 渲染通道颜色附件。
+ */
export interface IGLRenderPassColorAttachment extends IRenderPassColorAttachment
{
/**
@@ -11,9 +13,8 @@ export interface IGLRenderPassColorAttachment extends IRenderPassColorAttachment
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/framebufferRenderbuffer
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/framebufferTexture2D
+ *
+ * 注:引擎运行中该属性可能是 IGLRenderbuffer 类型,用于处理多重采样。
*/
- readonly view?: IGLColorAttachmentView;
+ readonly view?: IGLTextureView;
}
-
-export type IGLColorAttachmentView = IGLRenderbuffer | IGLTextureView;
-
diff --git a/src/data/IGLRenderPassDescriptor.ts b/src/data/IGLRenderPassDescriptor.ts
index 06cdb07..b76dab9 100644
--- a/src/data/IGLRenderPassDescriptor.ts
+++ b/src/data/IGLRenderPassDescriptor.ts
@@ -16,4 +16,4 @@ export interface IGLRenderPassDescriptor extends IRenderPassDescriptor
* 深度模板附件。
*/
readonly depthStencilAttachment?: IGLRenderPassDepthStencilAttachment;
-}
\ No newline at end of file
+}
diff --git a/src/data/IGLRenderbuffer.ts b/src/data/IGLRenderbuffer.ts
index d58b173..ddc6f19 100644
--- a/src/data/IGLRenderbuffer.ts
+++ b/src/data/IGLRenderbuffer.ts
@@ -1,12 +1,10 @@
-import { IRenderbuffer } from "@feng3d/render-api";
-
/**
* 渲染缓冲区。
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/renderbufferStorage
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/renderbufferStorageMultisample
*/
-export interface IGLRenderbuffer extends IRenderbuffer
+export interface IGLRenderbuffer
{
/**
* 渲染缓冲区内部格式。
diff --git a/src/data/IGLTexture.ts b/src/data/IGLTexture.ts
index 1bcab64..b0f843c 100644
--- a/src/data/IGLTexture.ts
+++ b/src/data/IGLTexture.ts
@@ -1,6 +1,5 @@
import { ITexture, ITextureDataSource, ITextureImageSource } from "@feng3d/render-api";
import { IGLCanvasTexture } from "./IGLCanvasTexture";
-import { IGLTexturePixelStore } from "./IGLTexturePixelStore";
/**
* 类似纹理,包含画布纹理以及正常纹理。
diff --git a/src/data/IGLTextureView.ts b/src/data/IGLTextureView.ts
index 7399eb0..d2b71bd 100644
--- a/src/data/IGLTextureView.ts
+++ b/src/data/IGLTextureView.ts
@@ -11,4 +11,3 @@ export interface IGLTextureView extends ITextureView
*/
readonly texture: IGLTexture,
}
-
--
Gitee
From 9d52e01e98024d0751d0f7daf9f06359298a6da6 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 15:14:09 +0800
Subject: [PATCH 088/186] =?UTF-8?q?=E5=90=88=E5=B9=B6=20IGLTexture=20?=
=?UTF-8?q?=E4=B8=BA=20ITexture?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/WebGL2Samples/draw_image_space.ts | 5 +-
examples/src/WebGL2Samples/fbo_blit.ts | 7 +--
examples/src/WebGL2Samples/fbo_multisample.ts | 5 +-
.../WebGL2Samples/fbo_new_blend_equation.ts | 5 +-
examples/src/WebGL2Samples/fbo_read_pixels.ts | 5 +-
.../WebGL2Samples/fbo_rtt_depth_texture.ts | 5 +-
.../src/WebGL2Samples/fbo_rtt_draw_buffers.ts | 7 +--
.../WebGL2Samples/fbo_rtt_texture_array.ts | 5 +-
.../src/WebGL2Samples/geo_vertex_format.ts | 5 +-
examples/src/WebGL2Samples/glsl_centroid.ts | 5 +-
.../WebGL2Samples/glsl_non_square_matrix.ts | 5 +-
examples/src/WebGL2Samples/sampler_filter.ts | 5 +-
examples/src/WebGL2Samples/sampler_object.ts | 5 +-
examples/src/WebGL2Samples/sampler_wrap.ts | 5 +-
.../src/WebGL2Samples/texture_2d_array.ts | 5 +-
examples/src/WebGL2Samples/texture_3d.ts | 5 +-
.../src/WebGL2Samples/texture_derivative.ts | 5 +-
examples/src/WebGL2Samples/texture_fetch.ts | 5 +-
examples/src/WebGL2Samples/texture_format.ts | 6 +--
examples/src/WebGL2Samples/texture_grad.ts | 5 +-
.../src/WebGL2Samples/texture_immutable.ts | 7 +--
examples/src/WebGL2Samples/texture_integer.ts | 5 +-
examples/src/WebGL2Samples/texture_lod.ts | 5 +-
examples/src/WebGL2Samples/texture_offset.ts | 5 +-
.../src/WebGL2Samples/texture_pixel_store.ts | 5 +-
examples/src/WebGL2Samples/texture_srgb.ts | 5 +-
examples/src/WebGL2Samples/texture_vertex.ts | 5 +-
examples/src/webgl-examples/sample6.ts | 5 +-
examples/src/webgl-examples/sample7.ts | 5 +-
examples/src/webgl-examples/sample8.ts | 7 +--
src/WebGL.ts | 4 +-
src/caches/getGLTexture.ts | 14 ++---
src/data/IGLCopyTextureToTexture.ts | 4 +-
.../IGLRenderPassDepthStencilAttachment.ts | 3 +-
src/data/IGLSamplerTexture.ts | 7 ++-
src/data/IGLTexture.ts | 54 +------------------
src/data/IGLTextureView.ts | 5 +-
37 files changed, 116 insertions(+), 134 deletions(-)
diff --git a/examples/src/WebGL2Samples/draw_image_space.ts b/examples/src/WebGL2Samples/draw_image_space.ts
index 66acfd6..64b3586 100644
--- a/examples/src/WebGL2Samples/draw_image_space.ts
+++ b/examples/src/WebGL2Samples/draw_image_space.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLTexture, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -12,7 +13,7 @@ const webgl = new WebGL(renderingContext);
loadImage("../../assets/img/Di-3d.png", (img) =>
{
- const texture: IGLTexture = {
+ const texture: ITexture = {
size: [img.width, img.height],
sources: [{ image: img, flipY: false }],
format: "rgba8unorm",
diff --git a/examples/src/WebGL2Samples/fbo_blit.ts b/examples/src/WebGL2Samples/fbo_blit.ts
index 5dc6c8c..dfcbaeb 100644
--- a/examples/src/WebGL2Samples/fbo_blit.ts
+++ b/examples/src/WebGL2Samples/fbo_blit.ts
@@ -1,4 +1,5 @@
-import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPassDescriptor, IGLRenderPipeline, IGLSampler, IGLTexture, IGLTextureView, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPassDescriptor, IGLRenderPipeline, IGLSampler, IGLTextureView, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -50,7 +51,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
y: image.height
};
- const textureDiffuse: IGLTexture = {
+ const textureDiffuse: ITexture = {
size: [image.width, image.height],
format: "rgba8unorm",
sources: [{
@@ -62,7 +63,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
magFilter: "LINEAR",
};
- const textureColorBuffer: IGLTexture = {
+ const textureColorBuffer: ITexture = {
format: "rgba8unorm",
size: [FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y],
};
diff --git a/examples/src/WebGL2Samples/fbo_multisample.ts b/examples/src/WebGL2Samples/fbo_multisample.ts
index ea4b88d..bd7aaa1 100644
--- a/examples/src/WebGL2Samples/fbo_multisample.ts
+++ b/examples/src/WebGL2Samples/fbo_multisample.ts
@@ -1,6 +1,7 @@
-import { IGLCanvasContext, IGLRenderPass, IGLRenderPassDescriptor, IGLRenderPipeline, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLRenderPass, IGLRenderPassDescriptor, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
+import { ITexture } from "@feng3d/render-api";
const canvas = document.createElement("canvas");
canvas.id = "glcanvas";
@@ -69,7 +70,7 @@ const FRAMEBUFFER_SIZE = {
x: canvas.width,
y: canvas.height
};
-const texture: IGLTexture = {
+const texture: ITexture = {
format: "rgba8unorm",
size: [FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y]
};
diff --git a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
index a7d0bf8..8e7399e 100644
--- a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
+++ b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
@@ -1,5 +1,6 @@
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLTexture, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -96,7 +97,7 @@ const sampler: IGLSampler = {
magFilter: "LINEAR"
};
const imageUrl = "../../assets/img/Di-3d.png";
-let texture: IGLTexture;
+let texture: ITexture;
loadImage(imageUrl, function (image)
{
texture = {
diff --git a/examples/src/WebGL2Samples/fbo_read_pixels.ts b/examples/src/WebGL2Samples/fbo_read_pixels.ts
index f2f5358..49cc688 100644
--- a/examples/src/WebGL2Samples/fbo_read_pixels.ts
+++ b/examples/src/WebGL2Samples/fbo_read_pixels.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLFramebuffer, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLFramebuffer, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -101,7 +102,7 @@ const layerVertexArray: { vertices?: IGLVertexAttributes } = {
const w = 16;
const h = 16;
-const texture: IGLTexture = {
+const texture: ITexture = {
dimension: "2d-array",
size: [w, h, 3],
format: "rgba8unorm",
diff --git a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
index 777b92e..179f67b 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLFramebuffer, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLFramebuffer, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -75,7 +76,7 @@ const quadVertexArray: { vertices?: IGLVertexAttributes } = {
// the proper texture format combination can be found here
// https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml
-const depthTexture: IGLTexture = {
+const depthTexture: ITexture = {
size: [windowSize.x, windowSize.y],
format: "depth16unorm",
};
diff --git a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
index aacef2b..7ab3fb7 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLFramebuffer, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLFramebuffer, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -74,13 +75,13 @@ const quadVertexArray: { vertices?: IGLVertexAttributes } = {
// -- Initialize texture targets
-const color1Texture: IGLTexture = {
+const color1Texture: ITexture = {
format: "rgba8unorm",
size: [windowSize.x, windowSize.y],
};
const color1Sampler: IGLSampler = { wrapS: "CLAMP_TO_EDGE", wrapT: "CLAMP_TO_EDGE", minFilter: "NEAREST", magFilter: "NEAREST" };
-const color2Texture: IGLTexture = {
+const color2Texture: ITexture = {
format: "rgba8unorm",
size: [windowSize.x, windowSize.y],
};
diff --git a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
index b74d8b0..d436518 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLFramebuffer, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLFramebuffer, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -101,7 +102,7 @@ const layerVertexArray: { vertices?: IGLVertexAttributes } = {
const w = 16;
const h = 16;
-const texture: IGLTexture = {
+const texture: ITexture = {
dimension: "2d-array",
format: "rgba8unorm",
size: [w, h, 3],
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index 12c8c7a..39f6875 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { HalfFloat } from "./third-party/HalfFloatUtility";
import { getShaderSource, loadImage } from "./utility";
@@ -161,7 +162,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init Texture
const imageUrl = "../../assets/img/Di-3d.png";
- let texture: IGLTexture;
+ let texture: ITexture;
let sampler: IGLSampler;
loadImage(imageUrl, function (image)
{
diff --git a/examples/src/WebGL2Samples/glsl_centroid.ts b/examples/src/WebGL2Samples/glsl_centroid.ts
index 7bc492c..381ed3d 100644
--- a/examples/src/WebGL2Samples/glsl_centroid.ts
+++ b/examples/src/WebGL2Samples/glsl_centroid.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLFramebuffer, IGLPassEncoder, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLTexture, IGLTextureView, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLFramebuffer, IGLPassEncoder, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -105,7 +106,7 @@ const FRAMEBUFFER_SIZE = {
x: canvas.width,
y: canvas.height
};
-const textures: IGLTexture[] = [];
+const textures: ITexture[] = [];
const samplers: IGLSampler[] = [];
for (let i = 0; i < VIEWPORTS.MAX; ++i)
diff --git a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
index 9b251eb..08e0fee 100644
--- a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
+++ b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
@@ -1,4 +1,5 @@
-import { IGLProgram, IGLRenderPass, IGLCanvasContext, IGLSampler, IGLTexture, IGLVertexAttributes, IGLVertexBuffer, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -46,7 +47,7 @@ const vertexArray: { vertices?: IGLVertexAttributes } = {
loadImage("../../assets/img/Di-3d.png", function (image)
{
// -- Init Texture
- const texture: IGLTexture = {
+ const texture: ITexture = {
size: [image.width, image.height],
format: "rgba8unorm",
sources: [{
diff --git a/examples/src/WebGL2Samples/sampler_filter.ts b/examples/src/WebGL2Samples/sampler_filter.ts
index bae3854..1da8a92 100644
--- a/examples/src/WebGL2Samples/sampler_filter.ts
+++ b/examples/src/WebGL2Samples/sampler_filter.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -114,7 +115,7 @@ samplers[Corners.BOTTOM_LEFT].magFilter = "LINEAR";
// -- Load texture then render
const imageUrl = "../../assets/img/Di-3d.png";
-let texture: IGLTexture;
+let texture: ITexture;
loadImage(imageUrl, function (image)
{
texture = {
diff --git a/examples/src/WebGL2Samples/sampler_object.ts b/examples/src/WebGL2Samples/sampler_object.ts
index 5c980ca..425579c 100644
--- a/examples/src/WebGL2Samples/sampler_object.ts
+++ b/examples/src/WebGL2Samples/sampler_object.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLSampler, IGLTexture, IGLVertexAttributes, IGLVertexBuffer, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -64,7 +65,7 @@ const samplerB: IGLSampler = {
// -- Load texture then render
const imageUrl = "../../assets/img/Di-3d.png";
-let texture: IGLTexture;
+let texture: ITexture;
loadImage(imageUrl, function (image)
{
texture = {
diff --git a/examples/src/WebGL2Samples/sampler_wrap.ts b/examples/src/WebGL2Samples/sampler_wrap.ts
index 80541a4..4bbb2e1 100644
--- a/examples/src/WebGL2Samples/sampler_wrap.ts
+++ b/examples/src/WebGL2Samples/sampler_wrap.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -113,7 +114,7 @@ samplers[Corners.BOTTOM_LEFT].wrapT = "CLAMP_TO_EDGE";
// -- Load texture then render
const imageUrl = "../../assets/img/Di-3d.png";
-let texture: IGLTexture;
+let texture: ITexture;
loadImage(imageUrl, function (image)
{
texture = {
diff --git a/examples/src/WebGL2Samples/texture_2d_array.ts b/examples/src/WebGL2Samples/texture_2d_array.ts
index 8a90235..3e7271c 100644
--- a/examples/src/WebGL2Samples/texture_2d_array.ts
+++ b/examples/src/WebGL2Samples/texture_2d_array.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -44,7 +45,7 @@ import { getShaderSource, loadImage } from "./utility";
}
};
- let texture: IGLTexture;
+ let texture: ITexture;
let sampler: IGLSampler;
loadImage("../../assets/img/di-animation-array.jpg", function (image)
{
diff --git a/examples/src/WebGL2Samples/texture_3d.ts b/examples/src/WebGL2Samples/texture_3d.ts
index 7b47c4f..15a53e7 100644
--- a/examples/src/WebGL2Samples/texture_3d.ts
+++ b/examples/src/WebGL2Samples/texture_3d.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource } from "./utility";
@@ -78,7 +79,7 @@ import { getShaderSource } from "./utility";
}
}
- const texture: IGLTexture = {
+ const texture: ITexture = {
size: [SIZE, SIZE, SIZE],
dimension: "3d",
format: "r8unorm",
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index 54c4a4f..85677cb 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -125,7 +126,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init Texture
const imageUrl = "../../assets/img/Di-3d.png";
- let texture: IGLTexture;
+ let texture: ITexture;
let sampler: IGLSampler;
loadImage(imageUrl, function (image)
{
diff --git a/examples/src/WebGL2Samples/texture_fetch.ts b/examples/src/WebGL2Samples/texture_fetch.ts
index 6de97a9..5f19c9c 100644
--- a/examples/src/WebGL2Samples/texture_fetch.ts
+++ b/examples/src/WebGL2Samples/texture_fetch.ts
@@ -1,5 +1,6 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLSampler, IGLTexture, IGLVertexAttributes, IGLVertexBuffer, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
+import { ITexture } from "@feng3d/render-api";
(function ()
{
@@ -45,7 +46,7 @@ import { getShaderSource, loadImage } from "./utility";
loadImage("../../assets/img/Di-3d.png", function (image)
{
// -- Init Texture
- const texture: IGLTexture = {
+ const texture: ITexture = {
size: [image.width, image.height],
format: "rgba8unorm",
sources: [{
diff --git a/examples/src/WebGL2Samples/texture_format.ts b/examples/src/WebGL2Samples/texture_format.ts
index c928d48..f50f0f6 100644
--- a/examples/src/WebGL2Samples/texture_format.ts
+++ b/examples/src/WebGL2Samples/texture_format.ts
@@ -1,5 +1,5 @@
-import { ITextureFormat } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture, ITextureFormat } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -134,7 +134,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init Texture
- const textures: IGLTexture[] = new Array(TextureTypes.MAX);
+ const textures: ITexture[] = new Array(TextureTypes.MAX);
const samplers: IGLSampler[] = new Array(TextureTypes.MAX);
let i = 0;
for (i = 0; i < TextureTypes.MAX; ++i)
diff --git a/examples/src/WebGL2Samples/texture_grad.ts b/examples/src/WebGL2Samples/texture_grad.ts
index d793736..8dd5290 100644
--- a/examples/src/WebGL2Samples/texture_grad.ts
+++ b/examples/src/WebGL2Samples/texture_grad.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -119,7 +120,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init Texture
const imageUrl = "../../assets/img/Di-3d.png";
- let texture: IGLTexture;
+ let texture: ITexture;
let sampler: IGLSampler;
loadImage(imageUrl, function (image)
{
diff --git a/examples/src/WebGL2Samples/texture_immutable.ts b/examples/src/WebGL2Samples/texture_immutable.ts
index 132c0c8..003d457 100644
--- a/examples/src/WebGL2Samples/texture_immutable.ts
+++ b/examples/src/WebGL2Samples/texture_immutable.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource, loadImage } from "./utility";
@@ -81,7 +82,7 @@ import { getShaderSource, loadImage } from "./utility";
]);
// -- Init 2D Texture
- const texture2D: IGLTexture = {
+ const texture2D: ITexture = {
format: "rgba8unorm",
mipLevelCount: 1,
size: [512, 512],
@@ -164,7 +165,7 @@ import { getShaderSource, loadImage } from "./utility";
}
}
- const texture3D: IGLTexture = {
+ const texture3D: ITexture = {
dimension: "3d",
format: "r8uint",
generateMipmap: true,
diff --git a/examples/src/WebGL2Samples/texture_integer.ts b/examples/src/WebGL2Samples/texture_integer.ts
index 7dec9d3..798748e 100644
--- a/examples/src/WebGL2Samples/texture_integer.ts
+++ b/examples/src/WebGL2Samples/texture_integer.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLTexture, IGLVertexAttributes, IGLVertexBuffer, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -47,7 +48,7 @@ import { getShaderSource, loadImage } from "./utility";
loadImage("../../assets/img/Di-3d.png", function (image)
{
// -- Init Texture
- const texture: IGLTexture = {
+ const texture: ITexture = {
size: [image.width, image.height],
format: "rgba8uint",
sources: [{
diff --git a/examples/src/WebGL2Samples/texture_lod.ts b/examples/src/WebGL2Samples/texture_lod.ts
index 62e9b18..7d7745d 100644
--- a/examples/src/WebGL2Samples/texture_lod.ts
+++ b/examples/src/WebGL2Samples/texture_lod.ts
@@ -1,5 +1,6 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
+import { ITexture } from "@feng3d/render-api";
(function ()
{
@@ -118,7 +119,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Load texture then render
const imageUrl = "../../assets/img/Di-3d.png";
- const textures: IGLTexture[] = new Array(Corners.MAX);
+ const textures: ITexture[] = new Array(Corners.MAX);
const samplers: IGLSampler[] = new Array(Corners.MAX);
loadImage(imageUrl, function (image)
{
diff --git a/examples/src/WebGL2Samples/texture_offset.ts b/examples/src/WebGL2Samples/texture_offset.ts
index f8a5cca..193d8a7 100644
--- a/examples/src/WebGL2Samples/texture_offset.ts
+++ b/examples/src/WebGL2Samples/texture_offset.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLTexture, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -71,7 +72,7 @@ import { getShaderSource, loadImage } from "./utility";
loadImage("../../assets/img/Di-3d.png", function (image)
{
// -- Init Texture
- const texture: IGLTexture = {
+ const texture: ITexture = {
size: [image.width, image.height],
format: "rgba8unorm",
sources: [{ mipLevel: 0, image: image, flipY: false, }],
diff --git a/examples/src/WebGL2Samples/texture_pixel_store.ts b/examples/src/WebGL2Samples/texture_pixel_store.ts
index 37ffe57..28d2241 100644
--- a/examples/src/WebGL2Samples/texture_pixel_store.ts
+++ b/examples/src/WebGL2Samples/texture_pixel_store.ts
@@ -1,4 +1,5 @@
-import { getIGLBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLTexture, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { getIGLBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -58,7 +59,7 @@ import { getShaderSource, loadImage } from "./utility";
const pixels = new Uint8Array(imageData.data.buffer);
// -- Init Texture
- const texture: IGLTexture = {
+ const texture: ITexture = {
size: [image.width / 2, image.height / 2],
format: "rgba8unorm",
sources: [{
diff --git a/examples/src/WebGL2Samples/texture_srgb.ts b/examples/src/WebGL2Samples/texture_srgb.ts
index 0c10689..5fe0989 100644
--- a/examples/src/WebGL2Samples/texture_srgb.ts
+++ b/examples/src/WebGL2Samples/texture_srgb.ts
@@ -1,4 +1,5 @@
-import { getIGLBuffer, IGLCanvasContext, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLTexture, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { getIGLBuffer, IGLCanvasContext, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -50,7 +51,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Load texture then render
const imageUrl = "../../assets/img/Di-3d.png";
- let texture: IGLTexture;
+ let texture: ITexture;
let sampler: IGLSampler;
loadImage(imageUrl, function (image)
{
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index c890225..777b7e4 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLTexture, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
import { getShaderSource, loadImage } from "./utility";
@@ -51,7 +52,7 @@ import { getShaderSource, loadImage } from "./utility";
let vertexBuffer: IGLVertexDataTypes;
let indicesBuffer: IGLIndicesDataTypes;
- let texture: IGLTexture;
+ let texture: ITexture;
let sampler: IGLSampler;
const ro: IGLRenderObject = {
diff --git a/examples/src/webgl-examples/sample6.ts b/examples/src/webgl-examples/sample6.ts
index 6a6bceb..ecf5f07 100644
--- a/examples/src/webgl-examples/sample6.ts
+++ b/examples/src/webgl-examples/sample6.ts
@@ -1,4 +1,5 @@
-import { IGLRenderObject, IGLRenderPass, IGLSampler, IGLTexture, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLRenderObject, IGLRenderPass, IGLSampler, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -223,7 +224,7 @@ async function loadTexture(url: string)
const generateMipmap = isPowerOf2(img.width) && isPowerOf2(img.height);
- const texture: IGLTexture = {
+ const texture: ITexture = {
size: [img.width, img.height],
format: "rgba8unorm",
sources: [{ image: img }],
diff --git a/examples/src/webgl-examples/sample7.ts b/examples/src/webgl-examples/sample7.ts
index 609f970..9def8ae 100644
--- a/examples/src/webgl-examples/sample7.ts
+++ b/examples/src/webgl-examples/sample7.ts
@@ -1,4 +1,5 @@
-import { IGLRenderObject, IGLRenderPass, IGLSampler, IGLSamplerTexture, IGLTexture, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLRenderObject, IGLRenderPass, IGLSampler, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -293,7 +294,7 @@ async function loadTexture(url: string)
const generateMipmap = isPowerOf2(img.width) && isPowerOf2(img.height);
- const texture: IGLTexture = {
+ const texture: ITexture = {
size: [img.width, img.height],
format: "rgba8unorm",
sources: [{ image: img }],
diff --git a/examples/src/webgl-examples/sample8.ts b/examples/src/webgl-examples/sample8.ts
index 2d17e5e..1139f36 100644
--- a/examples/src/webgl-examples/sample8.ts
+++ b/examples/src/webgl-examples/sample8.ts
@@ -1,4 +1,5 @@
-import { IGLRenderObject, IGLRenderPass, IGLSampler, IGLSamplerTexture, IGLTexture, WebGL } from "@feng3d/webgl";
+import { ITexture } from "@feng3d/render-api";
+import { IGLRenderObject, IGLRenderPass, IGLSampler, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -325,7 +326,7 @@ function initBuffers()
//
function initTexture(): IGLSamplerTexture
{
- const texture: IGLTexture = {
+ const texture: ITexture = {
size: [1, 1],
format: "rgba8unorm",
sources: [{ __type: "TextureDataSource", size: [1, 1], data: new Uint8Array([0, 0, 255, 255]) }],
@@ -338,7 +339,7 @@ function initTexture(): IGLSamplerTexture
//
// copy the video texture
//
-function updateTexture(texture: IGLTexture, video: HTMLVideoElement)
+function updateTexture(texture: ITexture, video: HTMLVideoElement)
{
// 修改纹理尺寸
if (texture.size[0] !== video.videoWidth || texture.size[1] !== video.videoHeight)
diff --git a/src/WebGL.ts b/src/WebGL.ts
index 1dc28e5..283efb4 100644
--- a/src/WebGL.ts
+++ b/src/WebGL.ts
@@ -15,9 +15,9 @@ import { IGLRenderPipeline } from "./data/IGLRenderPipeline";
import { IGLRenderbuffer } from "./data/IGLRenderbuffer";
import { IGLSampler } from "./data/IGLSampler";
import { IGLSubmit } from "./data/IGLSubmit";
-import { IGLTexture } from "./data/IGLTexture";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
import { runReadPixels } from "./runs/runReadPixels";
+import { ITexture } from "@feng3d/render-api";
/**
* WEBGL 对象。
@@ -67,7 +67,7 @@ export class WebGL
deleteBuffer(this._gl, buffer);
}
- deleteTexture(texture: IGLTexture)
+ deleteTexture(texture: ITexture)
{
deleteTexture(this._gl, texture);
}
diff --git a/src/caches/getGLTexture.ts b/src/caches/getGLTexture.ts
index 15510dc..f6e17b9 100644
--- a/src/caches/getGLTexture.ts
+++ b/src/caches/getGLTexture.ts
@@ -1,6 +1,6 @@
-import { ITextureSize } from "@feng3d/render-api";
+import { ITexture, ITextureDataSource, ITextureImageSource, ITextureSize } from "@feng3d/render-api";
import { watcher } from "@feng3d/watcher";
-import { IGLTexture, IGLTextureDataSource, IGLTextureImageSource, IGLTextureTarget } from "../data/IGLTexture";
+import { IGLTextureTarget } from "../data/IGLTexture";
import { IGLTexturePixelStore } from "../data/IGLTexturePixelStore";
import { getTextureCubeMapTarget } from "../utils/getTextureCubeMapTarget";
import { getIGLTextureFormats } from "./getIGLTextureFormats";
@@ -10,7 +10,7 @@ declare global
{
interface WebGLRenderingContext
{
- _textures: Map
+ _textures: Map
}
interface WebGLTexture
@@ -45,7 +45,7 @@ export const defaultTexturePixelStore: IGLTexturePixelStore = {
unpackSkipImages: 0,
};
-export function getGLTexture(gl: WebGLRenderingContext, texture: IGLTexture)
+export function getGLTexture(gl: WebGLRenderingContext, texture: ITexture)
{
let webGLTexture = gl._textures.get(texture);
if (webGLTexture) return webGLTexture;
@@ -123,7 +123,7 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: IGLTexture)
const zoffset = textureOrigin?.[2];
// 处理图片资源
- const imageSource = v as IGLTextureImageSource;
+ const imageSource = v as ITextureImageSource;
if (imageSource.image)
{
const { image, imageOrigin, flipY, premultipliedAlpha } = imageSource;
@@ -180,7 +180,7 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: IGLTexture)
}
// 处理数据资源
- const bufferSource = v as IGLTextureDataSource;
+ const bufferSource = v as ITextureDataSource;
const { data, dataLayout, dataImageOrigin } = bufferSource;
//
@@ -276,7 +276,7 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: IGLTexture)
return webGLTexture;
}
-export function deleteTexture(gl: WebGLRenderingContext, texture: IGLTexture)
+export function deleteTexture(gl: WebGLRenderingContext, texture: ITexture)
{
const webGLTexture = gl._textures.get(texture);
if (!webGLTexture) return;
diff --git a/src/data/IGLCopyTextureToTexture.ts b/src/data/IGLCopyTextureToTexture.ts
index 00e42d6..d40463b 100644
--- a/src/data/IGLCopyTextureToTexture.ts
+++ b/src/data/IGLCopyTextureToTexture.ts
@@ -1,4 +1,4 @@
-import { IGLTexture } from "./IGLTexture";
+import { ITexture } from "@feng3d/render-api";
/**
* GL中纹理之间拷贝。
@@ -31,7 +31,7 @@ export interface IGLImageCopyTexture
/**
* Texture to copy to/from.
*/
- texture: IGLTexture;
+ texture: ITexture;
/**
* Mip-map level of the {@link GPUImageCopyTexture#texture} to copy to/from.
diff --git a/src/data/IGLRenderPassDepthStencilAttachment.ts b/src/data/IGLRenderPassDepthStencilAttachment.ts
index cae0989..e745c97 100644
--- a/src/data/IGLRenderPassDepthStencilAttachment.ts
+++ b/src/data/IGLRenderPassDepthStencilAttachment.ts
@@ -1,9 +1,10 @@
+import { IRenderPassDepthStencilAttachment } from "@feng3d/render-api";
import { IGLTextureView } from "./IGLTextureView";
/**
* 深度模板附件。
*/
-export interface IGLRenderPassDepthStencilAttachment
+export interface IGLRenderPassDepthStencilAttachment extends IRenderPassDepthStencilAttachment
{
/**
* 深度附件视图。
diff --git a/src/data/IGLSamplerTexture.ts b/src/data/IGLSamplerTexture.ts
index 2536358..2bfdf3a 100644
--- a/src/data/IGLSamplerTexture.ts
+++ b/src/data/IGLSamplerTexture.ts
@@ -1,5 +1,5 @@
+import { ITexture } from "@feng3d/render-api";
import { IGLSampler } from "./IGLSampler";
-import { IGLTexture } from "./IGLTexture";
/**
* 采样纹理。
@@ -8,7 +8,10 @@ import { IGLTexture } from "./IGLTexture";
*/
export interface IGLSamplerTexture
{
- texture: IGLTexture;
+ /**
+ * 纹理。
+ */
+ texture: ITexture;
/**
* 采样器。
diff --git a/src/data/IGLTexture.ts b/src/data/IGLTexture.ts
index b0f843c..bd1c0c2 100644
--- a/src/data/IGLTexture.ts
+++ b/src/data/IGLTexture.ts
@@ -1,60 +1,10 @@
-import { ITexture, ITextureDataSource, ITextureImageSource } from "@feng3d/render-api";
+import { ITexture } from "@feng3d/render-api";
import { IGLCanvasTexture } from "./IGLCanvasTexture";
/**
* 类似纹理,包含画布纹理以及正常纹理。
*/
-export type IGLTextureLike = IGLCanvasTexture | IGLTexture;
-
-/**
- * 纹理
- */
-export interface IGLTexture extends ITexture
-{
- /**
- * 纹理资源。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texSubImage2D
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texSubImage3D
- */
- sources?: readonly IGLTextureSource[];
-}
-
-/**
- * 纹理资源。
- */
-export type IGLTextureSource = IGLTextureImageSource | IGLTextureDataSource;
-
-/**
- * 纹理图片资源。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texSubImage2D
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/texSubImage3D
- *
- * 注:不再支持参数 `border`
- */
-export interface IGLTextureImageSource extends ITextureImageSource
-{
-}
-
-/**
- * 纹理数据资源。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texSubImage2D
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/texSubImage3D
- */
-export interface IGLTextureDataSource extends ITextureDataSource
-{
-
-}
-
-/**
- * 写入纹理。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texSubImage2D
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/texSubImage3D
- */
-export type IGLWriteTexture = IGLTextureImageSource | IGLTextureDataSource;
+export type IGLTextureLike = IGLCanvasTexture | ITexture;
/**
* 纹理绑定点。
diff --git a/src/data/IGLTextureView.ts b/src/data/IGLTextureView.ts
index d2b71bd..8373366 100644
--- a/src/data/IGLTextureView.ts
+++ b/src/data/IGLTextureView.ts
@@ -1,5 +1,4 @@
-import { ITextureView } from "@feng3d/render-api";
-import { IGLTexture } from "./IGLTexture";
+import { ITexture, ITextureView } from "@feng3d/render-api";
/**
* 纹理视图。
@@ -9,5 +8,5 @@ export interface IGLTextureView extends ITextureView
/**
* 纹理。
*/
- readonly texture: IGLTexture,
+ readonly texture: ITexture,
}
--
Gitee
From d19553bced86280a4a59e047f843c3cf04f77df6 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 15:27:24 +0800
Subject: [PATCH 089/186] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/caches/getFramebuffer.ts | 5 +++--
src/caches/getGLTexture.ts | 9 ---------
src/caches/getIGLTextureTarget.ts | 3 +--
src/runs/runSampler.ts | 5 ++---
src/runs/runTexture.ts | 7 +++++--
5 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/src/caches/getFramebuffer.ts b/src/caches/getFramebuffer.ts
index 4ac8642..29e84f3 100644
--- a/src/caches/getFramebuffer.ts
+++ b/src/caches/getFramebuffer.ts
@@ -4,6 +4,7 @@ import { IGLTextureView } from "../data/IGLTextureView";
import { deleteRenderbuffer, getGLRenderbuffer } from "./getGLRenderbuffer";
import { getGLTexture } from "./getGLTexture";
import { _IGLRenderPassDescriptorWithMultisample, IGLRenderPassDescriptorWithMultisample } from "./getIGLRenderPassDescriptorWithMultisample";
+import { getIGLTextureTarget } from "./getIGLTextureTarget";
declare global
{
@@ -44,7 +45,7 @@ export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRen
const baseArrayLayer = view.baseArrayLayer || 0;
const webGLTexture = getGLTexture(gl, texture);
- const textureTarget = webGLTexture.textureTarget;
+ const textureTarget = getIGLTextureTarget(texture.dimension);
if (textureTarget === "TEXTURE_2D")
{
@@ -88,7 +89,7 @@ export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRen
const baseArrayLayer = view.baseArrayLayer || 0;
const webGLTexture = getGLTexture(gl, texture);
- const textureTarget = webGLTexture.textureTarget;
+ const textureTarget = getIGLTextureTarget(texture.dimension);
if (textureTarget === "TEXTURE_2D")
{
diff --git a/src/caches/getGLTexture.ts b/src/caches/getGLTexture.ts
index f6e17b9..b89e115 100644
--- a/src/caches/getGLTexture.ts
+++ b/src/caches/getGLTexture.ts
@@ -15,13 +15,6 @@ declare global
interface WebGLTexture
{
- /**
- * 纹理绑定点。
- *
- * 默认"TEXTURE_2D"。
- */
- textureTarget: IGLTextureTarget;
-
/**
* 销毁WebGL纹理。
*/
@@ -61,8 +54,6 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: ITexture)
gl.bindTexture(gl[target], webGLTexture);
- webGLTexture.textureTarget = target;
-
// 设置纹理尺寸
const [width, height, depth] = texture.size;
const mipLevelCount = texture.mipLevelCount || 1;
diff --git a/src/caches/getIGLTextureTarget.ts b/src/caches/getIGLTextureTarget.ts
index 8ecd4a1..284df9a 100644
--- a/src/caches/getIGLTextureTarget.ts
+++ b/src/caches/getIGLTextureTarget.ts
@@ -1,9 +1,8 @@
import { ITextureDimension } from "@feng3d/render-api";
import { IGLTextureTarget } from "../data/IGLTexture";
-export function getIGLTextureTarget(dimension: ITextureDimension)
+export function getIGLTextureTarget(dimension: ITextureDimension = "2d")
{
- dimension = dimension || "2d";
const target: IGLTextureTarget = dimensionMap[dimension];
console.assert(!!target, `WebGL 不支持纹理维度 ${dimension} , 该维度只在WebGPU中支持!`);
diff --git a/src/runs/runSampler.ts b/src/runs/runSampler.ts
index a2966d9..e45ddb1 100644
--- a/src/runs/runSampler.ts
+++ b/src/runs/runSampler.ts
@@ -1,5 +1,6 @@
import { getGLSampler } from "../caches/getGLSampler";
import { IGLSampler, TextureMagFilter, GLTextureMinFilter, GLTextureWrap } from "../data/IGLSampler";
+import { IGLTextureTarget } from "../data/IGLTexture";
declare global
{
@@ -28,10 +29,8 @@ export const defaultGLSampler: IGLSampler = {
/**
* 设置采样参数
*/
-export function runSampler(gl: WebGLRenderingContext, webGLTexture: WebGLTexture, sampler: IGLSampler, textureID: number)
+export function runSampler(gl: WebGLRenderingContext, textureTarget: IGLTextureTarget, webGLTexture: WebGLTexture, sampler: IGLSampler, textureID: number)
{
- const textureTarget = webGLTexture.textureTarget;
-
if (gl instanceof WebGL2RenderingContext)
{
const webGLSampler = getGLSampler(gl, sampler);
diff --git a/src/runs/runTexture.ts b/src/runs/runTexture.ts
index b81028b..9b8cb05 100644
--- a/src/runs/runTexture.ts
+++ b/src/runs/runTexture.ts
@@ -1,4 +1,5 @@
import { getGLTexture } from "../caches/getGLTexture";
+import { getIGLTextureTarget } from "../caches/getIGLTextureTarget";
import { IGLSamplerTexture } from "../data/IGLSamplerTexture";
import { IUniformItemInfo } from "../data/IGLUniformInfo";
import { runSampler } from "./runSampler";
@@ -8,16 +9,18 @@ export function runSamplerTexture(gl: WebGLRenderingContext, uniformInfo: IUnifo
const { texture, sampler } = samplerTexture;
const { location, textureID } = uniformInfo;
+ const textureTarget = getIGLTextureTarget(texture.dimension);
+
// 设置纹理所在采样编号
gl.uniform1i(location, textureID);
//
const webGLTexture = getGLTexture(gl, texture);
gl.activeTexture(gl[`TEXTURE${textureID}`]);
// 绑定纹理
- gl.bindTexture(gl[webGLTexture.textureTarget], webGLTexture);
+ gl.bindTexture(gl[textureTarget], webGLTexture);
// 运行采样器
- runSampler(gl, webGLTexture, sampler, textureID);
+ runSampler(gl, textureTarget, webGLTexture, sampler, textureID);
return webGLTexture;
}
--
Gitee
From bf7ad1fb72c50dcbe4272c6b923447d5ddfe61c8 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 15:45:13 +0800
Subject: [PATCH 090/186] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/caches/getGLSampler.ts | 15 ++++++++--
src/data/IGLDepthStencilState.ts | 18 ++++++------
src/data/IGLSampler.ts | 48 +++++++++++++++++++++++---------
src/gl/WebGLEnums.ts | 12 ++++----
src/internal.ts | 2 --
src/runs/runSampler.ts | 28 ++++++++-----------
6 files changed, 73 insertions(+), 50 deletions(-)
diff --git a/src/caches/getGLSampler.ts b/src/caches/getGLSampler.ts
index ffd268c..ebf3983 100644
--- a/src/caches/getGLSampler.ts
+++ b/src/caches/getGLSampler.ts
@@ -1,5 +1,5 @@
-import { IGLSampler } from "../data/IGLSampler";
-import { defaultGLSampler } from "../runs/runSampler";
+import { IGLCompareFunction } from "../data/IGLDepthStencilState";
+import { IGLSampler, IGLSamplerCompareMode, IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "../data/IGLSampler";
declare global
{
@@ -19,8 +19,17 @@ export function getGLSampler(gl: WebGLRenderingContext, sampler?: IGLSampler)
webGLSampler = gl.createSampler();
gl._samplers.set(sampler, webGLSampler);
- const { minFilter, magFilter, wrapS, wrapT, wrapR, lodMinClamp, lodMaxClamp, compareMode, compare } = { ...defaultGLSampler, ...sampler };
+ const minFilter: IGLTextureMinFilter = sampler.minFilter || "LINEAR_MIPMAP_LINEAR";
+ const magFilter: IGLTextureMagFilter = sampler.magFilter || "LINEAR";
+ const wrapS: IGLTextureWrap = sampler.wrapS || "REPEAT";
+ const wrapT: IGLTextureWrap = sampler.wrapT || "REPEAT";
+ const wrapR: IGLTextureWrap = sampler.wrapR || "REPEAT";
+ const lodMinClamp = sampler.lodMinClamp || 0;
+ const lodMaxClamp = sampler.lodMaxClamp || 16;
+ const compareMode: IGLSamplerCompareMode = sampler.compareMode || "NONE";
+ const compare: IGLCompareFunction = sampler.compare || "LEQUAL";
+ //
gl.samplerParameteri(webGLSampler, gl.TEXTURE_MIN_FILTER, gl[minFilter]);
gl.samplerParameteri(webGLSampler, gl.TEXTURE_MAG_FILTER, gl[magFilter]);
gl.samplerParameteri(webGLSampler, gl.TEXTURE_WRAP_S, gl[wrapS]);
diff --git a/src/data/IGLDepthStencilState.ts b/src/data/IGLDepthStencilState.ts
index 18f0a9a..6612328 100644
--- a/src/data/IGLDepthStencilState.ts
+++ b/src/data/IGLDepthStencilState.ts
@@ -40,10 +40,10 @@ export interface IGLDepthState
*
* A GLenum specifying the depth comparison function, which sets the conditions under which the pixel will be drawn. The default value is gl.LESS.
*
- * @see GLCompareFunction
+ * @see IGLCompareFunction
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/depthFunc
*/
- depthCompare?: GLCompareFunction;
+ depthCompare?: IGLCompareFunction;
/**
* 深度偏移。
@@ -116,7 +116,7 @@ export interface IStencilFaceState
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilFunc
*/
- stencilFunc?: GLStencilFunc;
+ stencilFunc?: IGLStencilFunc;
/**
* 一个为模板测试指定参考值。这个值被限制在0到2^n -1的范围内,其中n是模板缓冲区中的位数。默认0。
@@ -143,7 +143,7 @@ export interface IStencilFaceState
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilOp
*/
- stencilOpFail?: GLStencilOp;
+ stencilOpFail?: IGLStencilOp;
/**
* 指定在模板测试通过但深度测试失败时使用的函数枚举。默认KEEP,保持当前值。
@@ -152,7 +152,7 @@ export interface IStencilFaceState
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilOp
*/
- stencilOpZFail?: GLStencilOp;
+ stencilOpZFail?: IGLStencilOp;
/**
* 指定在模板测试和深度测试通过时使用的函数枚举,或在模板测试通过且没有深度缓冲或禁用深度测试时使用的函数枚举。默认KEEP,保持当前值。
@@ -161,7 +161,7 @@ export interface IStencilFaceState
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilOp
*/
- stencilOpZPass?: GLStencilOp;
+ stencilOpZPass?: IGLStencilOp;
/**
* 指定位掩码以启用或禁用在模板平面中写入单个位的正整数。默认全为1(0b11111111)。
@@ -189,7 +189,7 @@ export interface IStencilFaceState
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/depthFunc
*/
-export type GLCompareFunction = "NEVER" | "LESS" | "EQUAL" | "LEQUAL" | "GREATER" | "NOTEQUAL" | "GEQUAL" | "ALWAYS";
+export type IGLCompareFunction = "NEVER" | "LESS" | "EQUAL" | "LEQUAL" | "GREATER" | "NOTEQUAL" | "GEQUAL" | "ALWAYS";
/**
* A GLenum specifying the test function. The default function is gl.ALWAYS.
@@ -205,7 +205,7 @@ export type GLCompareFunction = "NEVER" | "LESS" | "EQUAL" | "LEQUAL" | "GREATER
*
* https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilFunc
*/
-export type GLStencilFunc = "NEVER" | "LESS" | "EQUAL" | "LEQUAL" | "GREATER" | "NOTEQUAL" | "GEQUAL" | "ALWAYS";
+export type IGLStencilFunc = "NEVER" | "LESS" | "EQUAL" | "LEQUAL" | "GREATER" | "NOTEQUAL" | "GEQUAL" | "ALWAYS";
/**
* The WebGLRenderingContext.stencilOp() method of the WebGL API sets both the front and back-facing stencil test actions.
@@ -221,4 +221,4 @@ export type GLStencilFunc = "NEVER" | "LESS" | "EQUAL" | "LEQUAL" | "GREATER" |
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilOp
*/
-export type GLStencilOp = "KEEP" | "ZERO" | "REPLACE" | "INCR" | "INCR_WRAP" | "DECR" | "DECR_WRAP" | "INVERT";
+export type IGLStencilOp = "KEEP" | "ZERO" | "REPLACE" | "INCR" | "INCR_WRAP" | "DECR" | "DECR_WRAP" | "INVERT";
diff --git a/src/data/IGLSampler.ts b/src/data/IGLSampler.ts
index 31a080b..b5cb689 100644
--- a/src/data/IGLSampler.ts
+++ b/src/data/IGLSampler.ts
@@ -1,50 +1,72 @@
-import { GLCompareFunction } from "./IGLDepthStencilState";
+import { IGLCompareFunction } from "./IGLDepthStencilState";
export interface IGLSampler
{
+ /**
+ * 默认 "LINEAR_MIPMAP_LINEAR" 。
+ */
+ minFilter?: IGLTextureMinFilter;
- minFilter?: GLTextureMinFilter;
-
- magFilter?: TextureMagFilter;
+ /**
+ * 默认 "LINEAR"。
+ */
+ magFilter?: IGLTextureMagFilter;
/**
* 表示x轴的纹理的回环方式,就是当纹理的宽度小于需要贴图的平面的宽度的时候,平面剩下的部分应该p以何种方式贴图的问题。
+ *
+ * 默认 "REPEAT"。
*/
- wrapS?: GLTextureWrap;
+ wrapS?: IGLTextureWrap;
/**
* 表示y轴的纹理回环方式。 magFilter和minFilter表示过滤的方式。
+ *
+ * 默认 "REPEAT"。
*/
- wrapT?: GLTextureWrap;
+ wrapT?: IGLTextureWrap;
/**
* 表示y轴的纹理回环方式。 magFilter和minFilter表示过滤的方式。
+ *
+ * 默认 "REPEAT"。
*/
- wrapR?: GLTextureWrap;
+ wrapR?: IGLTextureWrap;
/**
* 各向异性过滤。使用各向异性过滤能够使纹理的效果更好,但是会消耗更多的内存、CPU、GPU时间。默认为1。
+ *
+ * 默认 1。
*/
anisotropy?: number;
/**
* 采样时使用的最小Lod等级。
+ *
+ * 默认 0。
*/
lodMinClamp?: number;
/**
* 采样时使用的最大Lod等级。
+ *
+ * 默认 16 。
*/
lodMaxClamp?: number;
- compareMode?: GLSamplerCompareMode;
+ /**
+ * 默认 "NONE"。
+ */
+ compareMode?: IGLSamplerCompareMode;
/**
* 比较函数。
+ *
+ * 默认 "LEQUAL"。
*/
- compare?: GLCompareFunction;
+ compare?: IGLCompareFunction;
}
-export type GLSamplerCompareMode = "NONE" | "COMPARE_REF_TO_TEXTURE";
+export type IGLSamplerCompareMode = "NONE" | "COMPARE_REF_TO_TEXTURE";
/**
* 纹理放大滤波器
@@ -55,7 +77,7 @@ export type GLSamplerCompareMode = "NONE" | "COMPARE_REF_TO_TEXTURE";
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texParameter
*/
-export type TextureMagFilter = "LINEAR" | "NEAREST";
+export type IGLTextureMagFilter = "LINEAR" | "NEAREST";
/**
* 纹理缩小过滤器
@@ -70,7 +92,7 @@ export type TextureMagFilter = "LINEAR" | "NEAREST";
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texParameter
*/
-export type GLTextureMinFilter = "LINEAR" | "NEAREST" | "NEAREST_MIPMAP_NEAREST" | "LINEAR_MIPMAP_NEAREST" | "NEAREST_MIPMAP_LINEAR" | "LINEAR_MIPMAP_LINEAR";
+export type IGLTextureMinFilter = "LINEAR" | "NEAREST" | "NEAREST_MIPMAP_NEAREST" | "LINEAR_MIPMAP_NEAREST" | "NEAREST_MIPMAP_LINEAR" | "LINEAR_MIPMAP_LINEAR";
/**
* 纹理坐标s包装函数枚举
@@ -82,4 +104,4 @@ export type GLTextureMinFilter = "LINEAR" | "NEAREST" | "NEAREST_MIPMAP_NEAREST"
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texParameter
*/
-export type GLTextureWrap = "REPEAT" | "CLAMP_TO_EDGE" | "MIRRORED_REPEAT";
\ No newline at end of file
+export type IGLTextureWrap = "REPEAT" | "CLAMP_TO_EDGE" | "MIRRORED_REPEAT";
\ No newline at end of file
diff --git a/src/gl/WebGLEnums.ts b/src/gl/WebGLEnums.ts
index c48b391..52d9450 100644
--- a/src/gl/WebGLEnums.ts
+++ b/src/gl/WebGLEnums.ts
@@ -1,4 +1,4 @@
-import { TextureMagFilter, GLTextureMinFilter, GLTextureWrap } from "../data/IGLSampler";
+import { IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "../data/IGLSampler";
/**
* A GLenum specifying which WebGL capability to enable. Possible values:
@@ -95,22 +95,22 @@ export interface TexParameteri extends TexParameteri_WebGL2
/**
* Texture magnification filter
*/
- TEXTURE_MAG_FILTER: TextureMagFilter;
+ TEXTURE_MAG_FILTER: IGLTextureMagFilter;
/**
* Texture minification filter
*/
- TEXTURE_MIN_FILTER: GLTextureMinFilter;
+ TEXTURE_MIN_FILTER: IGLTextureMinFilter;
/**
* Wrapping function for texture coordinate s
*/
- TEXTURE_WRAP_S: GLTextureWrap;
+ TEXTURE_WRAP_S: IGLTextureWrap;
/**
* Wrapping function for texture coordinate t
*/
- TEXTURE_WRAP_T: GLTextureWrap;
+ TEXTURE_WRAP_T: IGLTextureWrap;
}
/**
@@ -163,7 +163,7 @@ export interface TexParameteri_WebGL2
/**
* Wrapping function for texture coordinate r
*/
- TEXTURE_WRAP_R: GLTextureWrap;
+ TEXTURE_WRAP_R: IGLTextureWrap;
}
/**
diff --git a/src/internal.ts b/src/internal.ts
index c8e1436..c59cd7d 100644
--- a/src/internal.ts
+++ b/src/internal.ts
@@ -1,4 +1,2 @@
-export { defaultGLSampler } from "./runs/runSampler";
-
export * from "./caches/getGLTexture";
diff --git a/src/runs/runSampler.ts b/src/runs/runSampler.ts
index e45ddb1..c9599da 100644
--- a/src/runs/runSampler.ts
+++ b/src/runs/runSampler.ts
@@ -1,31 +1,22 @@
import { getGLSampler } from "../caches/getGLSampler";
-import { IGLSampler, TextureMagFilter, GLTextureMinFilter, GLTextureWrap } from "../data/IGLSampler";
+import { IGLTextureMinFilter, IGLTextureWrap, IGLSampler, IGLTextureMagFilter } from "../data/IGLSampler";
import { IGLTextureTarget } from "../data/IGLTexture";
declare global
{
interface WebGLTexture
{
- minFilter?: GLTextureMinFilter,
- magFilter?: TextureMagFilter,
- wrapS?: GLTextureWrap,
- wrapT?: GLTextureWrap,
- wrapR?: GLTextureWrap,
+ minFilter?: IGLTextureMinFilter,
+ magFilter?: IGLTextureMagFilter,
+ wrapS?: IGLTextureWrap,
+ wrapT?: IGLTextureWrap,
+ wrapR?: IGLTextureWrap,
anisotropy?: number,
lodMinClamp?: number;
lodMaxClamp?: number;
}
}
-export const defaultGLSampler: IGLSampler = {
- minFilter: "LINEAR_MIPMAP_LINEAR", magFilter: "LINEAR",
- wrapS: "REPEAT", wrapT: "REPEAT", wrapR: "REPEAT",
- lodMinClamp: 0, lodMaxClamp: 16,
- compareMode: "NONE",
- compare: "LEQUAL",
- anisotropy: 1,
-};
-
/**
* 设置采样参数
*/
@@ -38,7 +29,10 @@ export function runSampler(gl: WebGLRenderingContext, textureTarget: IGLTextureT
}
else
{
- const { minFilter, magFilter, wrapS, wrapT } = { ...defaultGLSampler, ...sampler };
+ const minFilter: IGLTextureMinFilter = sampler.minFilter || "LINEAR_MIPMAP_LINEAR";
+ const magFilter: IGLTextureMagFilter = sampler.magFilter || "LINEAR";
+ const wrapS: IGLTextureWrap = sampler.wrapS || "REPEAT";
+ const wrapT: IGLTextureWrap = sampler.wrapT || "REPEAT";
// 设置纹理参数
if (webGLTexture.minFilter !== minFilter)
@@ -64,7 +58,7 @@ export function runSampler(gl: WebGLRenderingContext, textureTarget: IGLTextureT
}
//
- const anisotropy = sampler?.anisotropy || defaultGLSampler.anisotropy;
+ const anisotropy = sampler?.anisotropy || 1;
if (webGLTexture.anisotropy !== anisotropy)
{
const extension = gl.getExtension("EXT_texture_filter_anisotropic");
--
Gitee
From 2b9f674eb20bc93efbd91c63e749934ec965327d Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 16:06:30 +0800
Subject: [PATCH 091/186] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
examples/src/WebGL2Samples/fbo_blit.ts | 8 +--
examples/src/WebGL2Samples/fbo_multisample.ts | 6 +--
examples/src/WebGL2Samples/fbo_read_pixels.ts | 6 +--
.../WebGL2Samples/fbo_rtt_depth_texture.ts | 6 +--
.../src/WebGL2Samples/fbo_rtt_draw_buffers.ts | 6 +--
.../WebGL2Samples/fbo_rtt_texture_array.ts | 6 +--
examples/src/WebGL2Samples/glsl_centroid.ts | 6 +--
src/RunWebGL.ts | 18 +++----
src/WebGL.ts | 5 +-
src/caches/getFramebuffer.ts | 23 +++++---
src/caches/getIGLBlitFramebuffer.ts | 14 +++--
...tIGLRenderPassDescriptorWithMultisample.ts | 31 +++++++----
src/data/IGLBlitFramebuffer.ts | 6 +--
src/data/IGLFramebuffer.ts | 10 ----
src/data/IGLReadPixels.ts | 4 +-
src/data/IGLRenderPass.ts | 6 ---
src/data/IGLRenderPassColorAttachment.ts | 20 -------
.../IGLRenderPassDepthStencilAttachment.ts | 54 -------------------
src/data/IGLRenderPassDescriptor.ts | 19 -------
src/data/IGLTextureStorage.ts | 14 -----
src/data/IGLTextureView.ts | 12 -----
src/index.ts | 6 ---
src/runs/runFramebuffer.ts | 4 +-
23 files changed, 84 insertions(+), 206 deletions(-)
delete mode 100644 src/data/IGLFramebuffer.ts
delete mode 100644 src/data/IGLRenderPassColorAttachment.ts
delete mode 100644 src/data/IGLRenderPassDepthStencilAttachment.ts
delete mode 100644 src/data/IGLRenderPassDescriptor.ts
delete mode 100644 src/data/IGLTextureStorage.ts
delete mode 100644 src/data/IGLTextureView.ts
diff --git a/examples/src/WebGL2Samples/fbo_blit.ts b/examples/src/WebGL2Samples/fbo_blit.ts
index dfcbaeb..ff9bb73 100644
--- a/examples/src/WebGL2Samples/fbo_blit.ts
+++ b/examples/src/WebGL2Samples/fbo_blit.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPassDescriptor, IGLRenderPipeline, IGLSampler, IGLTextureView, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderPassDescriptor, ITexture, ITextureView } from "@feng3d/render-api";
+import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -73,7 +73,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
};
// 此处 Renderbuffer 直接使用 IGLTextureView 替代。
- const colorRenderbuffer: IGLTextureView = { texture: { format: "rgba8unorm", size: [FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y] } };
+ const colorRenderbuffer: ITextureView = { texture: { format: "rgba8unorm", size: [FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y] } };
const vertexArray: { vertices?: IGLVertexAttributes } = {
vertices,
@@ -106,7 +106,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
renderObjects: [viewport, renderObject],
};
- const framebufferResolve: IGLRenderPassDescriptor = {
+ const framebufferResolve: IRenderPassDescriptor = {
colorAttachments: [{
view: { texture: textureColorBuffer, baseMipLevel: 0 },
clearValue: [0.7, 0.0, 0.0, 1.0]
diff --git a/examples/src/WebGL2Samples/fbo_multisample.ts b/examples/src/WebGL2Samples/fbo_multisample.ts
index bd7aaa1..d8bd22a 100644
--- a/examples/src/WebGL2Samples/fbo_multisample.ts
+++ b/examples/src/WebGL2Samples/fbo_multisample.ts
@@ -1,7 +1,7 @@
-import { IGLCanvasContext, IGLRenderPass, IGLRenderPassDescriptor, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
-import { ITexture } from "@feng3d/render-api";
+import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
const canvas = document.createElement("canvas");
canvas.id = "glcanvas";
@@ -77,7 +77,7 @@ const texture: ITexture = {
const sampler: IGLSampler = { minFilter: "NEAREST", magFilter: "NEAREST" };
// -- Init Frame Buffers
-const framebuffer: IGLRenderPassDescriptor = {
+const framebuffer: IRenderPassDescriptor = {
colorAttachments: [{ view: { texture, baseMipLevel: 0 }, clearValue: [0.0, 0.0, 0.0, 1.0] }],
sampleCount: 4 // 多重采样
};
diff --git a/examples/src/WebGL2Samples/fbo_read_pixels.ts b/examples/src/WebGL2Samples/fbo_read_pixels.ts
index 49cc688..cd8443e 100644
--- a/examples/src/WebGL2Samples/fbo_read_pixels.ts
+++ b/examples/src/WebGL2Samples/fbo_read_pixels.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLFramebuffer, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -111,7 +111,7 @@ const sampler: IGLSampler = { lodMinClamp: 0, lodMaxClamp: 0, minFilter: "NEARES
// -- Initialize frame buffer
-const frameBuffer: IGLFramebuffer = {
+const frameBuffer: IRenderPassDescriptor = {
colorAttachments: [
{ view: { texture, baseMipLevel: 0, baseArrayLayer: Textures.RED } },
{ view: { texture, baseMipLevel: 0, baseArrayLayer: Textures.GREEN } },
diff --git a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
index 179f67b..6a7c0fe 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLFramebuffer, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -84,7 +84,7 @@ const depthSampler: IGLSampler = { wrapS: "CLAMP_TO_EDGE", wrapT: "CLAMP_TO_EDGE
// -- Initialize frame buffer
-const frameBuffer: IGLFramebuffer = {
+const frameBuffer: IRenderPassDescriptor = {
colorAttachments: [],
depthStencilAttachment: { view: { texture: depthTexture, baseMipLevel: 0 }, depthLoadOp: "clear" },
};
diff --git a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
index 7ab3fb7..092cef7 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLFramebuffer, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -89,7 +89,7 @@ const color2Sampler: IGLSampler = { wrapS: "CLAMP_TO_EDGE", wrapT: "CLAMP_TO_EDG
// -- Initialize frame buffer
-const frameBuffer: IGLFramebuffer = {
+const frameBuffer: IRenderPassDescriptor = {
colorAttachments: [
{ view: { texture: color1Texture, baseMipLevel: 0 } },
{ view: { texture: color2Texture, baseMipLevel: 0 } },
diff --git a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
index d436518..1d972e7 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLFramebuffer, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -111,7 +111,7 @@ const sampler: IGLSampler = { minFilter: "NEAREST", magFilter: "NEAREST", lodMin
// -- Initialize frame buffer
-const frameBuffer: IGLFramebuffer = {
+const frameBuffer: IRenderPassDescriptor = {
colorAttachments: [
{ view: { texture, baseMipLevel: 0, baseArrayLayer: Textures.RED } },
{ view: { texture, baseMipLevel: 0, baseArrayLayer: Textures.GREEN } },
diff --git a/examples/src/WebGL2Samples/glsl_centroid.ts b/examples/src/WebGL2Samples/glsl_centroid.ts
index 381ed3d..c66037d 100644
--- a/examples/src/WebGL2Samples/glsl_centroid.ts
+++ b/examples/src/WebGL2Samples/glsl_centroid.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLFramebuffer, IGLPassEncoder, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLPassEncoder, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -127,7 +127,7 @@ const FRAMEBUFFER = {
COLORBUFFER_CENTROID: 3
};
-const framebuffers: IGLFramebuffer[] = [
+const framebuffers: IRenderPassDescriptor[] = [
{ colorAttachments: [{ view: { texture: textures[0], baseMipLevel: 0 }, clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }], sampleCount: 4 },
{ colorAttachments: [{ view: { texture: textures[1], baseMipLevel: 0 }, clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }], sampleCount: 4 },
];
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index db07654..5a47ac2 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,19 +1,16 @@
+import { IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, ITextureView } from "@feng3d/render-api";
import { getFramebuffer } from "./caches/getFramebuffer";
+import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLRenderOcclusionQuery } from "./caches/getGLRenderOcclusionQuery";
import { getIGLBlitFramebuffer } from "./caches/getIGLBlitFramebuffer";
import { getIGLRenderPassDescriptorWithMultisample } from "./caches/getIGLRenderPassDescriptorWithMultisample";
-import { getGLBuffer } from "./caches/getGLBuffer";
import { _GL_Submit_Times } from "./const/const";
import { IGLBlitFramebuffer } from "./data/IGLBlitFramebuffer";
import { IGLCommandEncoder } from "./data/IGLCommandEncoder";
import { IGLCopyBufferToBuffer } from "./data/IGLCopyBufferToBuffer";
import { IGLCopyTextureToTexture } from "./data/IGLCopyTextureToTexture";
import { IGLRenderPass, IGLRenderPassObject } from "./data/IGLRenderPass";
-import { IGLRenderPassColorAttachment } from "./data/IGLRenderPassColorAttachment";
-import { IGLRenderPassDepthStencilAttachment } from "./data/IGLRenderPassDepthStencilAttachment";
-import { IGLRenderPassDescriptor } from "./data/IGLRenderPassDescriptor";
import { IGLSubmit } from "./data/IGLSubmit";
-import { IGLTextureView } from "./data/IGLTextureView";
import { runFramebuffer } from "./runs/runFramebuffer";
import { runOcclusionQuery } from "./runs/runOcclusionQuery";
import { runRenderObject } from "./runs/runRenderObject";
@@ -73,7 +70,7 @@ export class RunWebGL
//
occlusionQuery.init();
- if (renderPass.descriptor?.sampleCount && (renderPass.descriptor.colorAttachments[0].view as IGLTextureView).texture)
+ if (renderPass.descriptor?.sampleCount && (renderPass.descriptor.colorAttachments[0].view as ITextureView).texture)
{
const { passDescriptor, blitFramebuffer } = getIGLRenderPassDescriptorWithMultisample(renderPass.descriptor);
@@ -93,7 +90,7 @@ export class RunWebGL
occlusionQuery.resolve(renderPass);
}
- private runPassDescriptor(gl: WebGLRenderingContext, passDescriptor: IGLRenderPassDescriptor)
+ private runPassDescriptor(gl: WebGLRenderingContext, passDescriptor: IRenderPassDescriptor)
{
passDescriptor = passDescriptor || {};
@@ -110,6 +107,9 @@ export class RunWebGL
//
const depthStencilAttachment = Object.assign({}, defaultDepthStencilAttachment, passDescriptor.depthStencilAttachment);
const { depthClearValue, depthLoadOp, stencilClearValue, stencilLoadOp } = depthStencilAttachment;
+
+
+
gl.clearDepth(depthClearValue);
gl.clearStencil(stencilClearValue);
@@ -199,5 +199,5 @@ export class RunWebGL
}
}
-export const defaultRenderPassColorAttachment: IGLRenderPassColorAttachment = { clearValue: [0, 0, 0, 0], loadOp: "clear" };
-export const defaultDepthStencilAttachment: IGLRenderPassDepthStencilAttachment = { depthClearValue: 1, depthLoadOp: "load", stencilClearValue: 0, stencilLoadOp: "load" };
+export const defaultRenderPassColorAttachment: IRenderPassColorAttachment = { clearValue: [0, 0, 0, 0], loadOp: "clear" };
+export const defaultDepthStencilAttachment: IRenderPassDepthStencilAttachment = { depthClearValue: 1, depthLoadOp: "load", stencilClearValue: 0, stencilLoadOp: "load" };
diff --git a/src/WebGL.ts b/src/WebGL.ts
index 283efb4..5585b87 100644
--- a/src/WebGL.ts
+++ b/src/WebGL.ts
@@ -10,14 +10,13 @@ import { deleteTransformFeedback } from "./caches/getGLTransformFeedback";
import { IGLBuffer } from "./data/IGLBuffer";
import { IGLCanvasContext } from "./data/IGLCanvasContext";
import { IGLReadPixels } from "./data/IGLReadPixels";
-import { IGLRenderPassDescriptor } from "./data/IGLRenderPassDescriptor";
import { IGLRenderPipeline } from "./data/IGLRenderPipeline";
import { IGLRenderbuffer } from "./data/IGLRenderbuffer";
import { IGLSampler } from "./data/IGLSampler";
import { IGLSubmit } from "./data/IGLSubmit";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
import { runReadPixels } from "./runs/runReadPixels";
-import { ITexture } from "@feng3d/render-api";
+import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
/**
* WEBGL 对象。
@@ -52,7 +51,7 @@ export class WebGL
runReadPixels(this._gl, readPixels);
}
- deleteFramebuffer(passDescriptor: IGLRenderPassDescriptor)
+ deleteFramebuffer(passDescriptor: IRenderPassDescriptor)
{
deleteFramebuffer(this._gl, passDescriptor);
}
diff --git a/src/caches/getFramebuffer.ts b/src/caches/getFramebuffer.ts
index 29e84f3..c379374 100644
--- a/src/caches/getFramebuffer.ts
+++ b/src/caches/getFramebuffer.ts
@@ -1,6 +1,5 @@
-import { IGLRenderPassDescriptor } from "../data/IGLRenderPassDescriptor";
+import { IRenderPassDescriptor, ITextureView } from "@feng3d/render-api";
import { IGLRenderbuffer } from "../data/IGLRenderbuffer";
-import { IGLTextureView } from "../data/IGLTextureView";
import { deleteRenderbuffer, getGLRenderbuffer } from "./getGLRenderbuffer";
import { getGLTexture } from "./getGLTexture";
import { _IGLRenderPassDescriptorWithMultisample, IGLRenderPassDescriptorWithMultisample } from "./getIGLRenderPassDescriptorWithMultisample";
@@ -10,14 +9,14 @@ declare global
{
interface WebGLRenderingContext
{
- _framebuffers: Map;
+ _framebuffers: Map;
}
}
/**
* 获取帧缓冲区
*/
-export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRenderPassDescriptor)
+export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IRenderPassDescriptor)
{
const view = passDescriptor?.colorAttachments?.[0]?.view || passDescriptor?.depthStencilAttachment?.view;
if (!view) return null;
@@ -35,7 +34,7 @@ export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRen
const drawBuffers: number[] = [];
passDescriptor.colorAttachments?.forEach((item, i) =>
{
- const view = item.view as (IGLTextureView | IGLRenderbuffer);
+ const view = item.view as (ITextureView | IGLRenderbuffer);
const attachment = gl[`COLOR_ATTACHMENT${i}`];
drawBuffers.push(attachment);
if ("texture" in view)
@@ -44,6 +43,12 @@ export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRen
const baseMipLevel = view.baseMipLevel || 0;
const baseArrayLayer = view.baseArrayLayer || 0;
+ if ("context" in texture)
+ {
+ console.error(`WebGL中不支持 ICanvasTexture!`, texture);
+ return;
+ }
+
const webGLTexture = getGLTexture(gl, texture);
const textureTarget = getIGLTextureTarget(texture.dimension);
@@ -88,6 +93,12 @@ export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRen
const baseMipLevel = view.baseMipLevel || 0;
const baseArrayLayer = view.baseArrayLayer || 0;
+ if ("context" in texture)
+ {
+ console.error(`WebGL中不支持 ICanvasTexture!`, texture);
+ return;
+ }
+
const webGLTexture = getGLTexture(gl, texture);
const textureTarget = getIGLTextureTarget(texture.dimension);
@@ -118,7 +129,7 @@ export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRen
* @param handleMultisample 处理存在多重采样的渲染通道描述。
* @returns
*/
-export function deleteFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRenderPassDescriptor, handleMultisample = true)
+export function deleteFramebuffer(gl: WebGLRenderingContext, passDescriptor: IRenderPassDescriptor, handleMultisample = true)
{
if (handleMultisample && passDescriptor?.[_IGLRenderPassDescriptorWithMultisample])
{
diff --git a/src/caches/getIGLBlitFramebuffer.ts b/src/caches/getIGLBlitFramebuffer.ts
index 0bd890d..3dfac82 100644
--- a/src/caches/getIGLBlitFramebuffer.ts
+++ b/src/caches/getIGLBlitFramebuffer.ts
@@ -1,8 +1,6 @@
+import { IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, ITextureView } from "@feng3d/render-api";
import { IGLBlitFramebuffer, IGLBlitFramebufferItem } from "../data/IGLBlitFramebuffer";
import { IGLCopyTextureToTexture, IGLImageCopyTexture } from "../data/IGLCopyTextureToTexture";
-import { IGLRenderPassColorAttachment } from "../data/IGLRenderPassColorAttachment";
-import { IGLRenderPassDepthStencilAttachment } from "../data/IGLRenderPassDepthStencilAttachment";
-import { IGLTextureView } from "../data/IGLTextureView";
/**
* 通过 IGLBlitFramebuffer 实现纹理之间拷贝并不靠谱。
@@ -19,10 +17,10 @@ export function getIGLBlitFramebuffer(copyTextureToTexture: IGLCopyTextureToText
console.assert(sourceAspect === destinationAspect, `拷贝纹理时两个纹理的 aspect 必须相同!`);
- const sourceColorAttachments: IGLRenderPassColorAttachment[] = [];
- let sourceDepthStencilAttachment: IGLRenderPassDepthStencilAttachment;
- const destinationColorAttachments: IGLRenderPassColorAttachment[] = [];
- let destinationDepthStencilAttachment: IGLRenderPassDepthStencilAttachment;
+ const sourceColorAttachments: IRenderPassColorAttachment[] = [];
+ let sourceDepthStencilAttachment: IRenderPassDepthStencilAttachment;
+ const destinationColorAttachments: IRenderPassColorAttachment[] = [];
+ let destinationDepthStencilAttachment: IRenderPassDepthStencilAttachment;
//
let mask: "COLOR_BUFFER_BIT" | "DEPTH_BUFFER_BIT" | "STENCIL_BUFFER_BIT";
@@ -72,7 +70,7 @@ export function getIGLBlitFramebuffer(copyTextureToTexture: IGLCopyTextureToText
function getIGLTextureView(source: IGLImageCopyTexture)
{
- const textureView: IGLTextureView = {
+ const textureView: ITextureView = {
texture: source.texture,
baseMipLevel: source.mipLevel,
baseArrayLayer: source.origin?.[2],
diff --git a/src/caches/getIGLRenderPassDescriptorWithMultisample.ts b/src/caches/getIGLRenderPassDescriptorWithMultisample.ts
index b608686..b4ba137 100644
--- a/src/caches/getIGLRenderPassDescriptorWithMultisample.ts
+++ b/src/caches/getIGLRenderPassDescriptorWithMultisample.ts
@@ -1,9 +1,6 @@
-import { ITextureFormat } from "@feng3d/render-api";
+import { IRenderPassColorAttachment, IRenderPassDescriptor, ITextureFormat, ITextureView } from "@feng3d/render-api";
import { IGLBlitFramebuffer } from "../data/IGLBlitFramebuffer";
import { GLRenderbufferInternalformat, IGLRenderbuffer } from "../data/IGLRenderbuffer";
-import { IGLRenderPassColorAttachment } from "../data/IGLRenderPassColorAttachment";
-import { IGLRenderPassDescriptor } from "../data/IGLRenderPassDescriptor";
-import { IGLTextureView } from "../data/IGLTextureView";
import { getIGLTextureFormats } from "./getIGLTextureFormats";
/**
@@ -14,26 +11,40 @@ import { getIGLTextureFormats } from "./getIGLTextureFormats";
*
* @param sourcePassDescriptor 需要渲染到纹理并且开启多重采样的渲染通道描述。
*/
-export function getIGLRenderPassDescriptorWithMultisample(sourcePassDescriptor: IGLRenderPassDescriptor): IGLRenderPassDescriptorWithMultisample
+export function getIGLRenderPassDescriptorWithMultisample(sourcePassDescriptor: IRenderPassDescriptor): IGLRenderPassDescriptorWithMultisample
{
if (sourcePassDescriptor[_IGLRenderPassDescriptorWithMultisample]) return sourcePassDescriptor[_IGLRenderPassDescriptorWithMultisample];
- const textureSize = (sourcePassDescriptor.colorAttachments[0].view as IGLTextureView).texture.size;
+ const texture = (sourcePassDescriptor.colorAttachments[0].view as ITextureView).texture;
+ if ("context" in texture)
+ {
+ console.error(`WebGL不支持 ICanvasTexture!`, texture);
+ return;
+ }
+
+ const textureSize = texture.size;
const renderbuffers: IGLRenderbuffer[] = [];
// 创建支持 多重采样的 渲染通道
- const passDescriptor: IGLRenderPassDescriptor = {
+ const passDescriptor: IRenderPassDescriptor = {
colorAttachments: sourcePassDescriptor.colorAttachments.map((v) =>
{
+ const texture = v.view.texture;
+ if ("context" in texture)
+ {
+ console.error(`WebGL不支持 ICanvasTexture!`, texture);
+ return;
+ }
+
const renderbuffer: IGLRenderbuffer = {
- internalformat: getGLRenderbufferInternalformat((v.view as IGLTextureView).texture.format),
+ internalformat: getGLRenderbufferInternalformat(texture.format),
width: textureSize[0],
height: textureSize[1],
};
renderbuffers.push(renderbuffer);
- const colorAttachment: IGLRenderPassColorAttachment = {
+ const colorAttachment: IRenderPassColorAttachment = {
...v,
view: renderbuffer as any,
};
@@ -75,7 +86,7 @@ export interface IGLRenderPassDescriptorWithMultisample
/**
* 渲染到渲染缓冲区上。
*/
- passDescriptor: IGLRenderPassDescriptor;
+ passDescriptor: IRenderPassDescriptor;
/**
* 拷贝渲染缓冲区到目标纹理中。
*/
diff --git a/src/data/IGLBlitFramebuffer.ts b/src/data/IGLBlitFramebuffer.ts
index fe8320c..2bd6b55 100644
--- a/src/data/IGLBlitFramebuffer.ts
+++ b/src/data/IGLBlitFramebuffer.ts
@@ -1,4 +1,4 @@
-import { IGLRenderPassDescriptor } from "./IGLRenderPassDescriptor";
+import { IRenderPassDescriptor } from "@feng3d/render-api";
/**
* 拷贝渲染缓冲与纹理直接拷贝数据。
@@ -10,8 +10,8 @@ export interface IGLBlitFramebuffer
*/
readonly __type: "BlitFramebuffer";
- read: IGLRenderPassDescriptor;
- draw: IGLRenderPassDescriptor;
+ read: IRenderPassDescriptor;
+ draw: IRenderPassDescriptor;
blitFramebuffers: IGLBlitFramebufferItem[];
}
diff --git a/src/data/IGLFramebuffer.ts b/src/data/IGLFramebuffer.ts
deleted file mode 100644
index eb248df..0000000
--- a/src/data/IGLFramebuffer.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { IGLRenderPassDescriptor } from "./IGLRenderPassDescriptor";
-
-/**
- * 等价于 IPassDescriptor 。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/framebufferRenderbuffer
- *
- * @deprecated 请使用 IPassDescriptor 。
- */
-export interface IGLFramebuffer extends IGLRenderPassDescriptor { }
diff --git a/src/data/IGLReadPixels.ts b/src/data/IGLReadPixels.ts
index 615dc18..e697deb 100644
--- a/src/data/IGLReadPixels.ts
+++ b/src/data/IGLReadPixels.ts
@@ -1,5 +1,5 @@
+import { IRenderPassDescriptor } from "@feng3d/render-api";
import { GLAttachmentPoint } from "../gl/WebGLEnums";
-import { IGLFramebuffer } from "./IGLFramebuffer";
import { IGLTextureDataType, IGLTextureFormat } from "./IGLTexture";
/**
@@ -9,7 +9,7 @@ import { IGLTextureDataType, IGLTextureFormat } from "./IGLTexture";
*/
export interface IGLReadPixels
{
- frameBuffer: IGLFramebuffer;
+ frameBuffer: IRenderPassDescriptor;
/**
* 读取那个附件。
diff --git a/src/data/IGLRenderPass.ts b/src/data/IGLRenderPass.ts
index ea44470..63a52ef 100644
--- a/src/data/IGLRenderPass.ts
+++ b/src/data/IGLRenderPass.ts
@@ -1,7 +1,6 @@
import { IRenderPass } from "@feng3d/render-api";
import { IGLOcclusionQuery } from "./IGLOcclusionQuery";
import { IGLRenderObject } from "./IGLRenderObject";
-import { IGLRenderPassDescriptor } from "./IGLRenderPassDescriptor";
import { IGLScissorRect } from "./IGLScissorRect";
import { IGLViewport } from "./IGLViewport";
@@ -12,11 +11,6 @@ import { IGLViewport } from "./IGLViewport";
*/
export interface IGLRenderPass extends IRenderPass
{
- /**
- * WebGL渲染通道描述
- */
- readonly descriptor?: IGLRenderPassDescriptor;
-
/**
* 渲染对象列表,默认为 []。
*/
diff --git a/src/data/IGLRenderPassColorAttachment.ts b/src/data/IGLRenderPassColorAttachment.ts
deleted file mode 100644
index 73e0a4b..0000000
--- a/src/data/IGLRenderPassColorAttachment.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { IRenderPassColorAttachment } from "@feng3d/render-api";
-import { IGLTextureView } from "./IGLTextureView";
-
-/**
- * 渲染通道颜色附件。
- */
-export interface IGLRenderPassColorAttachment extends IRenderPassColorAttachment
-{
- /**
- * 颜色附件视图。
- *
- * 如果没有设置,默认为画布;否则使用 帧缓冲 。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/framebufferRenderbuffer
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/framebufferTexture2D
- *
- * 注:引擎运行中该属性可能是 IGLRenderbuffer 类型,用于处理多重采样。
- */
- readonly view?: IGLTextureView;
-}
diff --git a/src/data/IGLRenderPassDepthStencilAttachment.ts b/src/data/IGLRenderPassDepthStencilAttachment.ts
deleted file mode 100644
index e745c97..0000000
--- a/src/data/IGLRenderPassDepthStencilAttachment.ts
+++ /dev/null
@@ -1,54 +0,0 @@
-import { IRenderPassDepthStencilAttachment } from "@feng3d/render-api";
-import { IGLTextureView } from "./IGLTextureView";
-
-/**
- * 深度模板附件。
- */
-export interface IGLRenderPassDepthStencilAttachment extends IRenderPassDepthStencilAttachment
-{
- /**
- * 深度附件视图。
- *
- * 如果没有设置,默认为画布;否则使用 帧缓冲 。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/framebufferRenderbuffer
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/framebufferTexture2D
- */
- readonly view?: IGLTextureView;
-
- /**
- * 清除后填充深度值。
- *
- * 默认为 1。
- *
- * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clearDepth
- */
- readonly depthClearValue?: number;
-
- /**
- * 是否清除深度值。
- *
- * 默认为 "load"。
- *
- * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clear
- */
- readonly depthLoadOp?: "load" | "clear";
-
- /**
- * 清除后填充模板值。
- *
- * 默认为 0。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/clearStencil
- */
- readonly stencilClearValue?: number;
-
- /**
- * 是否清除模板值。
- *
- * 默认为 "load"。
- *
- * @see https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/clear
- */
- readonly stencilLoadOp?: "load" | "clear";
-}
\ No newline at end of file
diff --git a/src/data/IGLRenderPassDescriptor.ts b/src/data/IGLRenderPassDescriptor.ts
deleted file mode 100644
index b76dab9..0000000
--- a/src/data/IGLRenderPassDescriptor.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { IRenderPassDescriptor } from "@feng3d/render-api";
-import { IGLRenderPassColorAttachment } from "./IGLRenderPassColorAttachment";
-import { IGLRenderPassDepthStencilAttachment } from "./IGLRenderPassDepthStencilAttachment";
-
-/**
- * WebGL渲染通道描述
- */
-export interface IGLRenderPassDescriptor extends IRenderPassDescriptor
-{
- /**
- * 颜色附件
- */
- readonly colorAttachments?: readonly IGLRenderPassColorAttachment[];
-
- /**
- * 深度模板附件。
- */
- readonly depthStencilAttachment?: IGLRenderPassDepthStencilAttachment;
-}
diff --git a/src/data/IGLTextureStorage.ts b/src/data/IGLTextureStorage.ts
deleted file mode 100644
index f54990b..0000000
--- a/src/data/IGLTextureStorage.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-/**
- * 初始纹理时指定纹理存储的各个级别。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/texStorage2D
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/texStorage3D
- */
-export interface IGLTextureStorage
-{
- width: number, height: number;
- /**
- * 3D纹理深度。
- */
- depth?: number
-}
\ No newline at end of file
diff --git a/src/data/IGLTextureView.ts b/src/data/IGLTextureView.ts
deleted file mode 100644
index 8373366..0000000
--- a/src/data/IGLTextureView.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { ITexture, ITextureView } from "@feng3d/render-api";
-
-/**
- * 纹理视图。
- */
-export interface IGLTextureView extends ITextureView
-{
- /**
- * 纹理。
- */
- readonly texture: ITexture,
-}
diff --git a/src/index.ts b/src/index.ts
index 9380009..0cb88fa 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -10,7 +10,6 @@ export * from "./data/IGLCullFace";
export * from "./data/IGLDepthStencilState";
export * from "./data/IGLDrawIndexed";
export * from "./data/IGLDrawVertex";
-export * from "./data/IGLFramebuffer";
export * from "./data/IGLIndexBuffer";
export * from "./data/IGLOcclusionQuery";
export * from "./data/IGLPrimitiveState";
@@ -18,9 +17,6 @@ export * from "./data/IGLReadPixels";
export * from "./data/IGLRenderbuffer";
export * from "./data/IGLRenderObject";
export * from "./data/IGLRenderPass";
-export * from "./data/IGLRenderPassColorAttachment";
-export * from "./data/IGLRenderPassDepthStencilAttachment";
-export * from "./data/IGLRenderPassDescriptor";
export * from "./data/IGLRenderPipeline";
export * from "./data/IGLSampler";
export * from "./data/IGLSamplerTexture";
@@ -28,8 +24,6 @@ export * from "./data/IGLScissorRect";
export * from "./data/IGLSubmit";
export * from "./data/IGLTexture";
export * from "./data/IGLTexturePixelStore";
-export * from "./data/IGLTextureStorage";
-export * from "./data/IGLTextureView";
export * from "./data/IGLTransformFeedback";
export * from "./data/IGLUniforms";
export * from "./data/IGLVertexAttributes";
diff --git a/src/runs/runFramebuffer.ts b/src/runs/runFramebuffer.ts
index 999386c..738ca68 100644
--- a/src/runs/runFramebuffer.ts
+++ b/src/runs/runFramebuffer.ts
@@ -1,10 +1,10 @@
+import { IRenderPassDescriptor } from "@feng3d/render-api";
import { getFramebuffer } from "../caches/getFramebuffer";
-import { IGLRenderPassDescriptor } from "../data/IGLRenderPassDescriptor";
/**
* 运行帧缓冲区
*/
-export function runFramebuffer(gl: WebGLRenderingContext, passDescriptor: IGLRenderPassDescriptor)
+export function runFramebuffer(gl: WebGLRenderingContext, passDescriptor: IRenderPassDescriptor)
{
const framebuffer = getFramebuffer(gl, passDescriptor);
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
--
Gitee
From 1b5c51ccc6f35f8c4427788de06f5d596237a06c Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 16:24:37 +0800
Subject: [PATCH 092/186] ITextureLikeMap
---
src/caches/getFramebuffer.ts | 12 ------------
.../getIGLRenderPassDescriptorWithMultisample.ts | 10 ----------
2 files changed, 22 deletions(-)
diff --git a/src/caches/getFramebuffer.ts b/src/caches/getFramebuffer.ts
index c379374..6c8730b 100644
--- a/src/caches/getFramebuffer.ts
+++ b/src/caches/getFramebuffer.ts
@@ -43,12 +43,6 @@ export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IRende
const baseMipLevel = view.baseMipLevel || 0;
const baseArrayLayer = view.baseArrayLayer || 0;
- if ("context" in texture)
- {
- console.error(`WebGL中不支持 ICanvasTexture!`, texture);
- return;
- }
-
const webGLTexture = getGLTexture(gl, texture);
const textureTarget = getIGLTextureTarget(texture.dimension);
@@ -93,12 +87,6 @@ export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IRende
const baseMipLevel = view.baseMipLevel || 0;
const baseArrayLayer = view.baseArrayLayer || 0;
- if ("context" in texture)
- {
- console.error(`WebGL中不支持 ICanvasTexture!`, texture);
- return;
- }
-
const webGLTexture = getGLTexture(gl, texture);
const textureTarget = getIGLTextureTarget(texture.dimension);
diff --git a/src/caches/getIGLRenderPassDescriptorWithMultisample.ts b/src/caches/getIGLRenderPassDescriptorWithMultisample.ts
index b4ba137..326c343 100644
--- a/src/caches/getIGLRenderPassDescriptorWithMultisample.ts
+++ b/src/caches/getIGLRenderPassDescriptorWithMultisample.ts
@@ -16,11 +16,6 @@ export function getIGLRenderPassDescriptorWithMultisample(sourcePassDescriptor:
if (sourcePassDescriptor[_IGLRenderPassDescriptorWithMultisample]) return sourcePassDescriptor[_IGLRenderPassDescriptorWithMultisample];
const texture = (sourcePassDescriptor.colorAttachments[0].view as ITextureView).texture;
- if ("context" in texture)
- {
- console.error(`WebGL不支持 ICanvasTexture!`, texture);
- return;
- }
const textureSize = texture.size;
@@ -31,11 +26,6 @@ export function getIGLRenderPassDescriptorWithMultisample(sourcePassDescriptor:
colorAttachments: sourcePassDescriptor.colorAttachments.map((v) =>
{
const texture = v.view.texture;
- if ("context" in texture)
- {
- console.error(`WebGL不支持 ICanvasTexture!`, texture);
- return;
- }
const renderbuffer: IGLRenderbuffer = {
internalformat: getGLRenderbufferInternalformat(texture.format),
--
Gitee
From 9c044ad5639401cb8a38a13446b289444fb14e13 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 16:38:00 +0800
Subject: [PATCH 093/186] IPassEncoderMap
---
src/data/IGLCommandEncoder.ts | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/data/IGLCommandEncoder.ts b/src/data/IGLCommandEncoder.ts
index 2c00584..cf4c266 100644
--- a/src/data/IGLCommandEncoder.ts
+++ b/src/data/IGLCommandEncoder.ts
@@ -4,6 +4,16 @@ import { IGLCopyBufferToBuffer } from "./IGLCopyBufferToBuffer";
import { IGLCopyTextureToTexture } from "./IGLCopyTextureToTexture";
import { IGLRenderPass } from "./IGLRenderPass";
+declare module "@feng3d/render-api"
+{
+ export interface IPassEncoderMap
+ {
+ IGLBlitFramebuffer: IGLBlitFramebuffer;
+ IGLCopyTextureToTexture: IGLCopyTextureToTexture;
+ IGLCopyBufferToBuffer: IGLCopyBufferToBuffer;
+ }
+}
+
/**
* 命令编码器。
*/
--
Gitee
From dd0c19b8039ac3dfe9bdee7dd0d977ced1ae95ea Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 12 Dec 2024 23:40:50 +0800
Subject: [PATCH 094/186] IGLRenderPass -> IRenderPass
---
examples/src/WebGL2Samples/buffer_copy.ts | 5 ++-
examples/src/WebGL2Samples/buffer_uniform.ts | 7 ++--
.../src/WebGL2Samples/draw_instanced_ubo.ts | 7 ++--
.../src/WebGL2Samples/draw_range_arrays.ts | 5 ++-
examples/src/WebGL2Samples/fbo_blit.ts | 10 ++---
examples/src/WebGL2Samples/fbo_multisample.ts | 8 ++--
.../WebGL2Samples/fbo_new_blend_equation.ts | 8 ++--
examples/src/WebGL2Samples/fbo_read_pixels.ts | 10 ++---
.../WebGL2Samples/fbo_rtt_depth_texture.ts | 8 ++--
.../src/WebGL2Samples/fbo_rtt_draw_buffers.ts | 8 ++--
.../WebGL2Samples/fbo_rtt_texture_array.ts | 10 ++---
.../src/WebGL2Samples/geo_vertex_format.ts | 8 ++--
examples/src/WebGL2Samples/glsl_centroid.ts | 14 +++----
.../glsl_flat_smooth_interpolators.ts | 9 +++--
.../WebGL2Samples/glsl_non_square_matrix.ts | 8 ++--
examples/src/WebGL2Samples/query_occlusion.ts | 9 +++--
examples/src/WebGL2Samples/sampler_filter.ts | 10 ++---
examples/src/WebGL2Samples/sampler_object.ts | 9 +++--
examples/src/WebGL2Samples/sampler_wrap.ts | 10 ++---
.../src/WebGL2Samples/texture_2d_array.ts | 8 ++--
examples/src/WebGL2Samples/texture_3d.ts | 10 ++---
.../src/WebGL2Samples/texture_derivative.ts | 9 +++--
examples/src/WebGL2Samples/texture_fetch.ts | 9 +++--
examples/src/WebGL2Samples/texture_format.ts | 13 ++++---
examples/src/WebGL2Samples/texture_grad.ts | 9 +++--
.../src/WebGL2Samples/texture_immutable.ts | 13 ++++---
examples/src/WebGL2Samples/texture_integer.ts | 9 +++--
examples/src/WebGL2Samples/texture_lod.ts | 11 +++---
examples/src/WebGL2Samples/texture_offset.ts | 12 +++---
.../src/WebGL2Samples/texture_pixel_store.ts | 10 ++---
examples/src/WebGL2Samples/texture_srgb.ts | 11 +++---
examples/src/WebGL2Samples/texture_vertex.ts | 11 +++---
.../transform_feedback_instanced.ts | 9 +++--
.../transform_feedback_interleaved.ts | 11 +++---
.../transform_feedback_separated.ts | 12 +++---
.../transform_feedback_separated_2.ts | 8 ++--
examples/src/webgl-examples/sample1.ts | 5 ++-
examples/src/webgl-examples/sample2.ts | 5 ++-
examples/src/webgl-examples/sample3.ts | 5 ++-
examples/src/webgl-examples/sample4.ts | 5 ++-
examples/src/webgl-examples/sample5.ts | 5 ++-
examples/src/webgl-examples/sample6.ts | 6 +--
examples/src/webgl-examples/sample7.ts | 6 +--
examples/src/webgl-examples/sample8.ts | 6 +--
src/RunWebGL.ts | 19 ++++------
src/WebGL.ts | 10 ++---
src/caches/getGLRenderOcclusionQuery.ts | 8 ++--
src/data/IGLCommandEncoder.ts | 25 +-----------
src/data/IGLRenderPass.ts | 38 ++++++++++---------
src/data/IGLRenderPipeline.ts | 5 ---
src/data/IGLSubmit.ts | 14 -------
src/index.ts | 1 -
52 files changed, 243 insertions(+), 258 deletions(-)
delete mode 100644 src/data/IGLSubmit.ts
diff --git a/examples/src/WebGL2Samples/buffer_copy.ts b/examples/src/WebGL2Samples/buffer_copy.ts
index 2ab0bbe..03a2730 100644
--- a/examples/src/WebGL2Samples/buffer_copy.ts
+++ b/examples/src/WebGL2Samples/buffer_copy.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLCopyBufferToBuffer, IGLRenderPass, IGLRenderPipeline, IGLVertexAttributes, IGLVertexBuffer, WebGL, getIGLBuffer } from "@feng3d/webgl";
+import { IRenderPass } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLCopyBufferToBuffer, IGLRenderPipeline, IGLVertexAttributes, IGLVertexBuffer, WebGL, getIGLBuffer } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -48,7 +49,7 @@ import { getShaderSource } from "./utility";
};
// -- Render
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [{
pipeline: program,
diff --git a/examples/src/WebGL2Samples/buffer_uniform.ts b/examples/src/WebGL2Samples/buffer_uniform.ts
index ab704f9..60af5e8 100644
--- a/examples/src/WebGL2Samples/buffer_uniform.ts
+++ b/examples/src/WebGL2Samples/buffer_uniform.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLUniformBuffer, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLUniformBuffer, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -15,7 +16,7 @@ import { getShaderSource } from "./utility";
const webgl = new WebGL(rc);
// -- Init Program
- const program: IGLProgram = {
+ const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
};
@@ -87,7 +88,7 @@ import { getShaderSource } from "./utility";
drawIndexed: { indexCount: 6, firstIndex: 0 }
};
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [ro],
};
diff --git a/examples/src/WebGL2Samples/draw_instanced_ubo.ts b/examples/src/WebGL2Samples/draw_instanced_ubo.ts
index ac179c1..07c5afa 100644
--- a/examples/src/WebGL2Samples/draw_instanced_ubo.ts
+++ b/examples/src/WebGL2Samples/draw_instanced_ubo.ts
@@ -1,4 +1,5 @@
-import { IGLProgram, IGLRenderPass, IGLCanvasContext, IGLUniformBuffer, IGLVertexBuffer, WebGL } from "@feng3d/webgl";
+import { IRenderPass } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLUniformBuffer, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -11,7 +12,7 @@ const rc: IGLCanvasContext = { canvasId: "glcanvas", contextId: "webgl2" };
const webgl = new WebGL(rc);
// -- Init program
-const program: IGLProgram = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
+const program: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
// -- Init Buffer
const vertices = new Float32Array([
@@ -40,7 +41,7 @@ const materials = new Float32Array([
const uniformMaterialBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", data: materials, usage: "STATIC_DRAW" };
// -- Render
-const rp: IGLRenderPass = {
+const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0, 0, 0, 1], loadOp: "clear" }] },
renderObjects: [{
pipeline: program,
diff --git a/examples/src/WebGL2Samples/draw_range_arrays.ts b/examples/src/WebGL2Samples/draw_range_arrays.ts
index bc64b2c..f0bda54 100644
--- a/examples/src/WebGL2Samples/draw_range_arrays.ts
+++ b/examples/src/WebGL2Samples/draw_range_arrays.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -48,7 +49,7 @@ const renderObject: IGLRenderObject = {
pipeline,
};
-const rp: IGLRenderPass = {
+const rp: IRenderPass = {
descriptor: {
colorAttachments: [{
clearValue: [0.0, 0.0, 0.0, 1.0],
diff --git a/examples/src/WebGL2Samples/fbo_blit.ts b/examples/src/WebGL2Samples/fbo_blit.ts
index ff9bb73..9674196 100644
--- a/examples/src/WebGL2Samples/fbo_blit.ts
+++ b/examples/src/WebGL2Samples/fbo_blit.ts
@@ -1,5 +1,5 @@
-import { IRenderPassDescriptor, ITexture, ITextureView } from "@feng3d/render-api";
-import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, ITexture, ITextureView } from "@feng3d/render-api";
+import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -96,7 +96,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
};
// Render FBO
- const fboRenderPass: IGLRenderPass = {
+ const fboRenderPass: IRenderPass = {
descriptor: {
colorAttachments: [{
view: colorRenderbuffer,
@@ -114,7 +114,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
};
//
- const renderPassResolve: IGLRenderPass = {
+ const renderPassResolve: IRenderPass = {
descriptor: framebufferResolve,
};
@@ -164,7 +164,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
pipeline: program,
};
- const renderPass2: IGLRenderPass = {
+ const renderPass2: IRenderPass = {
descriptor: {
colorAttachments: [{
clearValue: [0.0, 0.0, 0.0, 1.0],
diff --git a/examples/src/WebGL2Samples/fbo_multisample.ts b/examples/src/WebGL2Samples/fbo_multisample.ts
index d8bd22a..f220c5c 100644
--- a/examples/src/WebGL2Samples/fbo_multisample.ts
+++ b/examples/src/WebGL2Samples/fbo_multisample.ts
@@ -1,7 +1,7 @@
-import { IGLCanvasContext, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
-import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
const canvas = document.createElement("canvas");
canvas.id = "glcanvas";
@@ -100,7 +100,7 @@ const IDENTITY = mat4.create();
// -- Render
// Pass 1
-const renderPass1: IGLRenderPass = {
+const renderPass1: IRenderPass = {
descriptor: framebuffer,
renderObjects: [{
pipeline: programs[PROGRAM.TEXTURE],
@@ -117,7 +117,7 @@ vec3.set(scaleVector3, 8.0, 8.0, 8.0);
const mvp = mat4.create();
mat4.scale(mvp, IDENTITY, scaleVector3);
-const renderPass2: IGLRenderPass = {
+const renderPass2: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [
{
diff --git a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
index 8e7399e..882c8ae 100644
--- a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
+++ b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
@@ -1,6 +1,6 @@
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
-import { ITexture } from "@feng3d/render-api";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -126,8 +126,8 @@ function render()
drawVertex: { vertexCount: 6 },
};
- const renderObjects: IGLRenderPassObject[] = [];
- const renderPass: IGLRenderPass = {
+ const renderObjects: IRenderPassObject[] = [];
+ const renderPass: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.5, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderObjects,
};
diff --git a/examples/src/WebGL2Samples/fbo_read_pixels.ts b/examples/src/WebGL2Samples/fbo_read_pixels.ts
index cd8443e..3745965 100644
--- a/examples/src/WebGL2Samples/fbo_read_pixels.ts
+++ b/examples/src/WebGL2Samples/fbo_read_pixels.ts
@@ -1,5 +1,5 @@
-import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -128,7 +128,7 @@ const matrix = new Float32Array([
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
]);
-const rp1: IGLRenderPass = {
+const rp1: IRenderPass = {
descriptor: frameBuffer,
renderObjects: [
{ __type: "Viewport", x: 0, y: 0, width: w, height: h },
@@ -140,9 +140,9 @@ const rp1: IGLRenderPass = {
}],
};
-const renderObjects: IGLRenderPassObject[] = [];
+const renderObjects: IRenderPassObject[] = [];
// Pass 2
-const rp: IGLRenderPass = {
+const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderObjects
};
diff --git a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
index 6a7c0fe..1572cb6 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
@@ -1,5 +1,5 @@
-import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -92,7 +92,7 @@ const frameBuffer: IRenderPassDescriptor = {
// -- Render
// Pass 1: Depth
-const renderPass: IGLRenderPass = {
+const renderPass: IRenderPass = {
descriptor: frameBuffer,
renderObjects: [{
pipeline: depthProgram,
@@ -103,7 +103,7 @@ const renderPass: IGLRenderPass = {
};
// Pass 2: Draw
-const rp2: IGLRenderPass = {
+const rp2: IRenderPass = {
descriptor: {
colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }],
},
diff --git a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
index 092cef7..e6e423a 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
@@ -1,5 +1,5 @@
-import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPass, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -98,7 +98,7 @@ const frameBuffer: IRenderPassDescriptor = {
// -- Render
-const renderPass: IGLRenderPass = {
+const renderPass: IRenderPass = {
descriptor: frameBuffer,
renderObjects: [{
pipeline: drawBufferProgram,
@@ -108,7 +108,7 @@ const renderPass: IGLRenderPass = {
};
// Pass 2: Draw to screen
-const renderPass2: IGLRenderPass = {
+const renderPass2: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [{
pipeline: drawProgram,
diff --git a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
index 1d972e7..590fe63 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
@@ -1,5 +1,5 @@
-import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -130,7 +130,7 @@ const matrix = new Float32Array([
0.0, 0.0, 0.0, 1.0
]);
-const renderPass1: IGLRenderPass = {
+const renderPass1: IRenderPass = {
descriptor: frameBuffer,
renderObjects: [
{ __type: "Viewport", x: 0, y: 0, width: w, height: h },
@@ -143,8 +143,8 @@ const renderPass1: IGLRenderPass = {
};
// Pass 2
-const renderObjects: IGLRenderPassObject[] = [];
-const renderPass: IGLRenderPass = {
+const renderObjects: IRenderPassObject[] = [];
+const renderPass: IRenderPass = {
descriptor: {
colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }],
},
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index 39f6875..5221bf8 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { HalfFloat } from "./third-party/HalfFloatUtility";
import { getShaderSource, loadImage } from "./utility";
@@ -16,7 +16,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLProgram = {
+ const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "TRIANGLES", cullFace: { enableCullFace: true, cullMode: "BACK" } },
depthStencil: { depth: { depthtest: true } },
@@ -215,7 +215,7 @@ import { getShaderSource, loadImage } from "./utility";
drawIndexed: { indexCount: 36 },
};
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [ro],
};
diff --git a/examples/src/WebGL2Samples/glsl_centroid.ts b/examples/src/WebGL2Samples/glsl_centroid.ts
index c66037d..2b17824 100644
--- a/examples/src/WebGL2Samples/glsl_centroid.ts
+++ b/examples/src/WebGL2Samples/glsl_centroid.ts
@@ -1,5 +1,5 @@
-import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLPassEncoder, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IPassEncoder, IRenderPass, IRenderPassDescriptor, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -50,7 +50,7 @@ const PROGRAM = {
MAX: 3
};
-const programs: IGLProgram[] = [
+const programs: IGLRenderPipeline[] = [
{
vertex: { code: getShaderSource("vs-render") }, fragment: { code: getShaderSource("fs-render") },
primitive: { topology: "TRIANGLES" },
@@ -155,14 +155,14 @@ const vertexArrays: { vertices?: IGLVertexAttributes }[] = [
];
// -- Render
-const passEncoders: IGLPassEncoder[] = [];
+const passEncoders: IPassEncoder[] = [];
// Pass 1
const IDENTITY = mat4.create();
for (let i = 0; i < VIEWPORTS.MAX; ++i)
{
// render buffers
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: framebuffers[i],
renderObjects: [{
pipeline: programs[i],
@@ -174,9 +174,9 @@ for (let i = 0; i < VIEWPORTS.MAX; ++i)
passEncoders.push(rp);
}
-const renderObjects: IGLRenderPassObject[] = [];
+const renderObjects: IRenderPassObject[] = [];
// Pass 2
-const rp2: IGLRenderPass = {
+const rp2: IRenderPass = {
renderObjects: renderObjects,
};
const ro: IGLRenderObject = {
diff --git a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
index 664ae93..fea2026 100644
--- a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
+++ b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
import { getShaderSource } from "./utility";
@@ -43,7 +44,7 @@ viewport[VIEWPORTS.RIGHT] = {
};
// -- Initialize program
-const programs: IGLProgram[] = [
+const programs: IGLRenderPipeline[] = [
{
vertex: { code: getShaderSource("vs-flat") }, fragment: { code: getShaderSource("fs-flat") },
primitive: { topology: "TRIANGLES" },
@@ -138,8 +139,8 @@ glTFLoader.loadGLTF(gltfUrl, function (glTF)
// -- Render loop
(function render()
{
- const renderObjects: IGLRenderPassObject[] = [];
- const rp: IGLRenderPass = {
+ const renderObjects: IRenderPassObject[] = [];
+ const rp: IRenderPass = {
descriptor: {
colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }],
depthStencilAttachment: { depthLoadOp: "clear" }
diff --git a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
index 08e0fee..3a05929 100644
--- a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
+++ b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -12,7 +12,7 @@ const rc: IGLCanvasContext = { canvasId: "glcanvas", contextId: "webgl2" };
const webgl = new WebGL(rc);
// -- Init program
-const program: IGLProgram = {
+const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "TRIANGLES" },
};
@@ -64,7 +64,7 @@ loadImage("../../assets/img/Di-3d.png", function (image)
0.2, -0.2, 0.0 //translation
]);
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [{
pipeline: program,
diff --git a/examples/src/WebGL2Samples/query_occlusion.ts b/examples/src/WebGL2Samples/query_occlusion.ts
index 8ef4673..93971e6 100644
--- a/examples/src/WebGL2Samples/query_occlusion.ts
+++ b/examples/src/WebGL2Samples/query_occlusion.ts
@@ -1,5 +1,6 @@
+import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
import { watcher } from "@feng3d/watcher";
-import { IGLCanvasContext, IGLOcclusionQuery, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLOcclusionQuery, IGLRenderObject, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
// -- Init Canvas
@@ -14,7 +15,7 @@ const rc: IGLCanvasContext = { canvasId: "glcanvas", contextId: "webgl2" };
const webgl = new WebGL(rc);
// -- Init Program
-const program: IGLProgram = {
+const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
depthStencil: { depth: { depthtest: true } },
primitive: { topology: "TRIANGLES" },
@@ -38,9 +39,9 @@ const vertexArray: { vertices?: IGLVertexAttributes } = {
}
};
-const renderObjects: IGLRenderPassObject[] = [];
+const renderObjects: IRenderPassObject[] = [];
// -- Render
-const rp: IGLRenderPass = {
+const rp: IRenderPass = {
descriptor: {
colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }],
depthStencilAttachment: { depthLoadOp: "clear" },
diff --git a/examples/src/WebGL2Samples/sampler_filter.ts b/examples/src/WebGL2Samples/sampler_filter.ts
index 1da8a92..e10c119 100644
--- a/examples/src/WebGL2Samples/sampler_filter.ts
+++ b/examples/src/WebGL2Samples/sampler_filter.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -58,7 +58,7 @@ viewport[Corners.TOP_LEFT] = {
// -- Initialize program
-const program: IGLProgram = {
+const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "TRIANGLES" },
};
@@ -138,8 +138,8 @@ function render()
0.0, 0.0, 0.0, 1.0
]);
- const renderObjects: IGLRenderPassObject[] = [];
- const rp: IGLRenderPass = {
+ const renderObjects: IRenderPassObject[] = [];
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderObjects
};
diff --git a/examples/src/WebGL2Samples/sampler_object.ts b/examples/src/WebGL2Samples/sampler_object.ts
index 425579c..05d6b75 100644
--- a/examples/src/WebGL2Samples/sampler_object.ts
+++ b/examples/src/WebGL2Samples/sampler_object.ts
@@ -1,5 +1,6 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -13,7 +14,7 @@ const webgl = new WebGL(rc);
// -- Initialize program
-const program: IGLProgram = {
+const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "TRIANGLES" },
};
@@ -87,7 +88,7 @@ function render()
0.0, 0.0, 0.0, 1.0
]);
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [{
pipeline: program,
diff --git a/examples/src/WebGL2Samples/sampler_wrap.ts b/examples/src/WebGL2Samples/sampler_wrap.ts
index 4bbb2e1..182613b 100644
--- a/examples/src/WebGL2Samples/sampler_wrap.ts
+++ b/examples/src/WebGL2Samples/sampler_wrap.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -58,7 +58,7 @@ viewport[Corners.TOP_LEFT] = {
// -- Initialize program
-const program: IGLProgram = {
+const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "TRIANGLES" },
};
@@ -128,9 +128,9 @@ loadImage(imageUrl, function (image)
function render()
{
- const renderObjects: IGLRenderPassObject[] = [];
+ const renderObjects: IRenderPassObject[] = [];
// Clear color buffer
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderObjects,
};
diff --git a/examples/src/WebGL2Samples/texture_2d_array.ts b/examples/src/WebGL2Samples/texture_2d_array.ts
index 3e7271c..b749c59 100644
--- a/examples/src/WebGL2Samples/texture_2d_array.ts
+++ b/examples/src/WebGL2Samples/texture_2d_array.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -14,7 +14,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLProgram = {
+ const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
};
@@ -92,7 +92,7 @@ import { getShaderSource, loadImage } from "./utility";
drawVertex: { vertexCount: 6 },
};
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [1.0, 1.0, 1.0, 1.0], loadOp: "clear" }] },
renderObjects: [ro],
};
diff --git a/examples/src/WebGL2Samples/texture_3d.ts b/examples/src/WebGL2Samples/texture_3d.ts
index 15a53e7..de36988 100644
--- a/examples/src/WebGL2Samples/texture_3d.ts
+++ b/examples/src/WebGL2Samples/texture_3d.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource } from "./utility";
@@ -94,7 +94,7 @@ import { getShaderSource } from "./utility";
};
// -- Initialize program
- const program: IGLProgram = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
+ const program: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
// -- Initialize buffer
const positions = new Float32Array([
@@ -165,7 +165,7 @@ import { getShaderSource } from "./utility";
drawVertex: { vertexCount: 6 }
};
- const renderPassObjects: IGLRenderPassObject[] = [];
+ const renderPassObjects: IRenderPassObject[] = [];
const renderObjects: IGLRenderObject[] = [];
for (let i = 0; i < Corners.MAX; ++i)
{
@@ -176,7 +176,7 @@ import { getShaderSource } from "./utility";
renderObjects.push(ro);
}
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderPassObjects,
};
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index 85677cb..69bf2ce 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -1,5 +1,6 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -15,7 +16,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLProgram = {
+ const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: {
code: getShaderSource("fs"), targets: [{
@@ -214,7 +215,7 @@ import { getShaderSource, loadImage } from "./utility";
drawIndexed: { indexCount: 36 },
};
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [ro]
};
diff --git a/examples/src/WebGL2Samples/texture_fetch.ts b/examples/src/WebGL2Samples/texture_fetch.ts
index 5f19c9c..aa2d3f3 100644
--- a/examples/src/WebGL2Samples/texture_fetch.ts
+++ b/examples/src/WebGL2Samples/texture_fetch.ts
@@ -1,6 +1,7 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+
import { getShaderSource, loadImage } from "./utility";
-import { ITexture } from "@feng3d/render-api";
(function ()
{
@@ -14,7 +15,7 @@ import { ITexture } from "@feng3d/render-api";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLProgram = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
+ const program: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
// -- Init buffers: vec2 Position, vec2 Texcoord
const positions = new Float32Array([
@@ -67,7 +68,7 @@ import { ITexture } from "@feng3d/render-api";
0.0, 0.0, 0.0, 1.0
]);
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [
{
diff --git a/examples/src/WebGL2Samples/texture_format.ts b/examples/src/WebGL2Samples/texture_format.ts
index f50f0f6..fcc8c9c 100644
--- a/examples/src/WebGL2Samples/texture_format.ts
+++ b/examples/src/WebGL2Samples/texture_format.ts
@@ -1,5 +1,6 @@
-import { ITexture, ITextureFormat } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, ITexture, ITextureFormat } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -48,9 +49,9 @@ import { getShaderSource, loadImage } from "./utility";
}
// -- Init program
- const programUint: IGLProgram = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-uint") } };
+ const programUint: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-uint") } };
- const programNormalized: IGLProgram = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-normalized") } };
+ const programNormalized: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-normalized") } };
// -- Init buffers: vec2 Position, vec2 Texcoord
const positions = new Float32Array([
@@ -162,8 +163,8 @@ import { getShaderSource, loadImage } from "./utility";
0.0, 0.0, 0.0, 1.0
]);
- const renderObjects: IGLRenderPassObject[] = [];
- const rp: IGLRenderPass = {
+ const renderObjects: IRenderPassObject[] = [];
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderObjects
};
diff --git a/examples/src/WebGL2Samples/texture_grad.ts b/examples/src/WebGL2Samples/texture_grad.ts
index 8dd5290..46cc218 100644
--- a/examples/src/WebGL2Samples/texture_grad.ts
+++ b/examples/src/WebGL2Samples/texture_grad.ts
@@ -1,5 +1,6 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -15,7 +16,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLProgram = {
+ const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
depthStencil: { depth: { depthtest: true } },
primitive: { cullFace: { enableCullFace: true, cullMode: "BACK" } },
@@ -204,7 +205,7 @@ import { getShaderSource, loadImage } from "./utility";
drawIndexed: { indexCount: 36 },
};
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [ro],
};
diff --git a/examples/src/WebGL2Samples/texture_immutable.ts b/examples/src/WebGL2Samples/texture_immutable.ts
index 003d457..bb719cc 100644
--- a/examples/src/WebGL2Samples/texture_immutable.ts
+++ b/examples/src/WebGL2Samples/texture_immutable.ts
@@ -1,5 +1,6 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+
import { snoise } from "./third-party/noise3D";
import { getShaderSource, loadImage } from "./utility";
@@ -37,9 +38,9 @@ import { getShaderSource, loadImage } from "./utility";
};
// -- Init program
- const program: IGLProgram = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
+ const program: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
- const program3D: IGLProgram = { vertex: { code: getShaderSource("vs-3d") }, fragment: { code: getShaderSource("fs-3d") } };
+ const program3D: IGLRenderPipeline = { vertex: { code: getShaderSource("vs-3d") }, fragment: { code: getShaderSource("fs-3d") } };
// -- Init buffers: vec2 Position, vec2 Texcoord
const positions = new Float32Array([
@@ -107,8 +108,8 @@ import { getShaderSource, loadImage } from "./utility";
drawVertex: { vertexCount: 6 },
};
- const renderObjects: IGLRenderPassObject[] = [];
- const rp: IGLRenderPass = {
+ const renderObjects: IRenderPassObject[] = [];
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderObjects
};
diff --git a/examples/src/WebGL2Samples/texture_integer.ts b/examples/src/WebGL2Samples/texture_integer.ts
index 798748e..310bbbc 100644
--- a/examples/src/WebGL2Samples/texture_integer.ts
+++ b/examples/src/WebGL2Samples/texture_integer.ts
@@ -1,5 +1,6 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -14,7 +15,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLProgram = {
+ const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
};
@@ -78,7 +79,7 @@ import { getShaderSource, loadImage } from "./utility";
drawVertex: { vertexCount: 6 },
};
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [ro],
};
diff --git a/examples/src/WebGL2Samples/texture_lod.ts b/examples/src/WebGL2Samples/texture_lod.ts
index 7d7745d..15e7d6e 100644
--- a/examples/src/WebGL2Samples/texture_lod.ts
+++ b/examples/src/WebGL2Samples/texture_lod.ts
@@ -1,6 +1,7 @@
-import { IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+
import { getShaderSource, loadImage } from "./utility";
-import { ITexture } from "@feng3d/render-api";
(function ()
{
@@ -86,7 +87,7 @@ import { ITexture } from "@feng3d/render-api";
};
// -- Initialize program
- const program: IGLProgram = {
+ const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
};
@@ -178,9 +179,9 @@ import { ITexture } from "@feng3d/render-api";
function render()
{
- const renderObjects: IGLRenderPassObject[] = [];
+ const renderObjects: IRenderPassObject[] = [];
// Clear color buffer
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderObjects,
};
diff --git a/examples/src/WebGL2Samples/texture_offset.ts b/examples/src/WebGL2Samples/texture_offset.ts
index 193d8a7..7017383 100644
--- a/examples/src/WebGL2Samples/texture_offset.ts
+++ b/examples/src/WebGL2Samples/texture_offset.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -36,9 +36,9 @@ import { getShaderSource, loadImage } from "./utility";
};
// -- Init program
- const programBicubic: IGLProgram = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-bicubic") } };
+ const programBicubic: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-bicubic") } };
- const programOffsetBicubic: IGLProgram = {
+ const programOffsetBicubic: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-offset-bicubic") },
};
@@ -84,9 +84,9 @@ import { getShaderSource, loadImage } from "./utility";
wrapT: "CLAMP_TO_EDGE",
};
- const renderObjects: IGLRenderPassObject[] = [];
+ const renderObjects: IRenderPassObject[] = [];
// -- Render
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderObjects
};
diff --git a/examples/src/WebGL2Samples/texture_pixel_store.ts b/examples/src/WebGL2Samples/texture_pixel_store.ts
index 28d2241..d76bbee 100644
--- a/examples/src/WebGL2Samples/texture_pixel_store.ts
+++ b/examples/src/WebGL2Samples/texture_pixel_store.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { getIGLBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -14,7 +14,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLProgram = {
+ const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
};
@@ -76,9 +76,9 @@ import { getShaderSource, loadImage } from "./utility";
magFilter: "NEAREST",
};
- const renderObjects: IGLRenderPassObject[] = [];
+ const renderObjects: IRenderPassObject[] = [];
// -- Render
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderObjects,
};
diff --git a/examples/src/WebGL2Samples/texture_srgb.ts b/examples/src/WebGL2Samples/texture_srgb.ts
index 5fe0989..406bb0b 100644
--- a/examples/src/WebGL2Samples/texture_srgb.ts
+++ b/examples/src/WebGL2Samples/texture_srgb.ts
@@ -1,5 +1,6 @@
-import { ITexture } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { getIGLBuffer, IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -15,7 +16,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Initialize program
- const program: IGLProgram = {
+ const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
};
@@ -67,9 +68,9 @@ import { getShaderSource, loadImage } from "./utility";
function render()
{
- const renderObjects: IGLRenderPassObject[] = [];
+ const renderObjects: IRenderPassObject[] = [];
// Clear color buffer
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderObjects,
};
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index 777b7e4..ae3775f 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -1,5 +1,6 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLProgram, IGLRenderObject, IGLRenderPass, IGLRenderPassObject, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
import { getShaderSource, loadImage } from "./utility";
@@ -39,7 +40,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLProgram = {
+ const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
depthStencil: { depth: { depthtest: true, depthCompare: "LESS" } },
};
@@ -184,9 +185,9 @@ import { getShaderSource, loadImage } from "./utility";
const localMV = mat4.create();
function render()
{
- const renderObjects: IGLRenderPassObject[] = [];
+ const renderObjects: IRenderPassObject[] = [];
// -- Render
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: {
colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }],
depthStencilAttachment: { depthLoadOp: "clear" }
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index c2847f4..3748e49 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -1,4 +1,5 @@
-import { IGLVertexDataTypes, IGLIndicesDataTypes, IGLCanvasContext, IGLProgram, IGLRenderObject, IGLRenderPass, IGLTransformFeedback, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderPass } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderObject, IGLRenderPipeline, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -120,7 +121,7 @@ import { getShaderSource } from "./utility";
drawVertex: { vertexCount: 3, instanceCount: NUM_INSTANCES },
};
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [transformRO, viewport, renderRO],
};
@@ -129,7 +130,7 @@ import { getShaderSource } from "./utility";
function initPrograms()
{
- const programTransform: IGLProgram = {
+ const programTransform: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs-emit") }, fragment: { code: getShaderSource("fs-emit") },
transformFeedbackVaryings: { varyings: ["v_offset", "v_rotation"], bufferMode: "SEPARATE_ATTRIBS" },
rasterizerDiscard: true,
@@ -137,7 +138,7 @@ import { getShaderSource } from "./utility";
};
// Setup program for draw shader
- const programDraw: IGLProgram = {
+ const programDraw: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs-draw") }, fragment: {
code: getShaderSource("fs-draw"),
targets: [{
diff --git a/examples/src/WebGL2Samples/transform_feedback_interleaved.ts b/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
index 5fc9c7c..0527a2b 100644
--- a/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
@@ -1,5 +1,6 @@
-import { getIGLVertexBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { getIGLVertexBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
+import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
(function ()
{
@@ -20,7 +21,7 @@ import { getShaderSource } from "./utility";
const programTransform = (function (vertexShaderSourceTransform, fragmentShaderSourceTransform)
{
- const programTransform: IGLProgram = {
+ const programTransform: IGLRenderPipeline = {
vertex: { code: vertexShaderSourceTransform },
fragment: { code: fragmentShaderSourceTransform },
transformFeedbackVaryings: { varyings: ["gl_Position", "v_color"], bufferMode: "INTERLEAVED_ATTRIBS" },
@@ -30,7 +31,7 @@ import { getShaderSource } from "./utility";
return programTransform;
})(getShaderSource("vs-transform"), getShaderSource("fs-transform"));
- const programFeedback: IGLProgram = {
+ const programFeedback: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs-feedback") }, fragment: { code: getShaderSource("fs-feedback") },
};
@@ -77,10 +78,10 @@ import { getShaderSource } from "./utility";
]
};
- const renderObjects: IGLRenderPassObject[] = [];
+ const renderObjects: IRenderPassObject[] = [];
// -- Render
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderObjects,
};
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated.ts b/examples/src/WebGL2Samples/transform_feedback_separated.ts
index 9df586a..b98dacc 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated.ts
@@ -1,4 +1,6 @@
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLProgram, IGLRenderPass, IGLRenderPassObject, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+
import { getShaderSource } from "./utility";
(function ()
@@ -17,7 +19,7 @@ import { getShaderSource } from "./utility";
// -- Init Program
const programTransform = (function (vertexShaderSourceTransform, fragmentShaderSourceTransform)
{
- const programTransform: IGLProgram = {
+ const programTransform: IGLRenderPipeline = {
vertex: { code: vertexShaderSourceTransform },
fragment: { code: fragmentShaderSourceTransform },
transformFeedbackVaryings: { varyings: ["gl_Position", "v_color"], bufferMode: "SEPARATE_ATTRIBS" },
@@ -27,7 +29,7 @@ import { getShaderSource } from "./utility";
return programTransform;
})(getShaderSource("vs-transform"), getShaderSource("fs-transform"));
- const programFeedback: IGLProgram = {
+ const programFeedback: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs-feedback") }, fragment: { code: getShaderSource("fs-feedback") },
};
@@ -87,10 +89,10 @@ import { getShaderSource } from "./utility";
]
};
- const renderObjects: IGLRenderPassObject[] = [];
+ const renderObjects: IRenderPassObject[] = [];
// -- Render
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: renderObjects,
};
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
index 485e982..227c17a 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
@@ -1,4 +1,6 @@
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLProgram, IGLRenderObject, IGLRenderPass, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderPass } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLRenderObject, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
+
import { getShaderSource } from "./utility";
(function ()
@@ -101,7 +103,7 @@ import { getShaderSource } from "./utility";
function initProgram()
{
- const program: IGLProgram = {
+ const program: IGLRenderPipeline = {
vertex: { code: getShaderSource("vs-draw") },
fragment: {
code: getShaderSource("fs-draw"),
@@ -129,7 +131,7 @@ import { getShaderSource } from "./utility";
drawVertex: { vertexCount: NUM_PARTICLES },
};
- const rp: IGLRenderPass = {
+ const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
renderObjects: [viewport, ro],
};
diff --git a/examples/src/webgl-examples/sample1.ts b/examples/src/webgl-examples/sample1.ts
index 67406b9..310f00d 100644
--- a/examples/src/webgl-examples/sample1.ts
+++ b/examples/src/webgl-examples/sample1.ts
@@ -1,7 +1,8 @@
// see https://github.com/mdn/dom-examples/blob/main/webgl-examples/tutorial/sample1/webgl-demo.js
// https://mdn.github.io/dom-examples/webgl-examples/tutorial/sample1/
-import { IGLCanvasContext, IGLSubmit, WebGL } from "@feng3d/webgl";
+import { ISubmit } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
async function main()
{
@@ -10,7 +11,7 @@ async function main()
const webgl = new WebGL(renderingContext);
// const webgl = await new WebGPU().init();
- const submit: IGLSubmit = {
+ const submit: ISubmit = {
commandEncoders: [{
passEncoders: [
{
diff --git a/examples/src/webgl-examples/sample2.ts b/examples/src/webgl-examples/sample2.ts
index 5de38fc..3012754 100644
--- a/examples/src/webgl-examples/sample2.ts
+++ b/examples/src/webgl-examples/sample2.ts
@@ -1,4 +1,5 @@
-import { IGLRenderPass, WebGL } from "@feng3d/webgl";
+import { IRenderPass } from "@feng3d/render-api";
+import { WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
main();
@@ -11,7 +12,7 @@ function main()
const webgl = new WebGL({ canvasId: "glcanvas", contextId: "webgl" });
- const renderPass: IGLRenderPass = {
+ const renderPass: IRenderPass = {
descriptor: {
colorAttachments: [{
clearValue: [0, 0, 0, 1],
diff --git a/examples/src/webgl-examples/sample3.ts b/examples/src/webgl-examples/sample3.ts
index acad063..70d7177 100644
--- a/examples/src/webgl-examples/sample3.ts
+++ b/examples/src/webgl-examples/sample3.ts
@@ -1,4 +1,5 @@
-import { IGLRenderPass, WebGL } from "@feng3d/webgl";
+import { IRenderPass } from "@feng3d/render-api";
+import { WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
main();
@@ -15,7 +16,7 @@ function main()
const webgl = new WebGL({ canvasId: "glcanvas", contextId: "webgl" });
- const renderPass: IGLRenderPass = {
+ const renderPass: IRenderPass = {
descriptor: {
colorAttachments: [{
clearValue: [0.0, 0.0, 0.0, 1.0],
diff --git a/examples/src/webgl-examples/sample4.ts b/examples/src/webgl-examples/sample4.ts
index 722a765..29d9e04 100644
--- a/examples/src/webgl-examples/sample4.ts
+++ b/examples/src/webgl-examples/sample4.ts
@@ -1,4 +1,5 @@
-import { IGLRenderObject, IGLRenderPass, WebGL } from "@feng3d/webgl";
+import { IRenderPass } from "@feng3d/render-api";
+import { IGLRenderObject, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let squareRotation = 0.0;
@@ -69,7 +70,7 @@ function main()
drawVertex: { firstVertex: 0, vertexCount: 4 },
};
- const renderPass: IGLRenderPass = {
+ const renderPass: IRenderPass = {
descriptor: {
colorAttachments: [{
clearValue: [0.0, 0.0, 0.0, 1.0],
diff --git a/examples/src/webgl-examples/sample5.ts b/examples/src/webgl-examples/sample5.ts
index 932ffa6..c8248dc 100644
--- a/examples/src/webgl-examples/sample5.ts
+++ b/examples/src/webgl-examples/sample5.ts
@@ -1,4 +1,5 @@
-import { IGLRenderObject, IGLRenderPass, WebGL } from "@feng3d/webgl";
+import { IRenderPass } from "@feng3d/render-api";
+import { IGLRenderObject, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -64,7 +65,7 @@ function main()
drawIndexed: { firstIndex: 0, indexCount: 36 },
};
- const renderPass: IGLRenderPass = {
+ const renderPass: IRenderPass = {
descriptor: {
colorAttachments: [{
clearValue: [0.0, 0.0, 0.0, 1.0],
diff --git a/examples/src/webgl-examples/sample6.ts b/examples/src/webgl-examples/sample6.ts
index ecf5f07..8f963cd 100644
--- a/examples/src/webgl-examples/sample6.ts
+++ b/examples/src/webgl-examples/sample6.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLRenderObject, IGLRenderPass, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLRenderObject, IGLSampler, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -69,7 +69,7 @@ async function main()
drawIndexed: { firstIndex: 0, indexCount: 36 },
};
- const renderPass: IGLRenderPass = {
+ const renderPass: IRenderPass = {
descriptor: {
colorAttachments: [{
clearValue: [0.0, 0.0, 0.0, 1.0],
diff --git a/examples/src/webgl-examples/sample7.ts b/examples/src/webgl-examples/sample7.ts
index 9def8ae..82aff4f 100644
--- a/examples/src/webgl-examples/sample7.ts
+++ b/examples/src/webgl-examples/sample7.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLRenderObject, IGLRenderPass, IGLSampler, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
+import { IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLRenderObject, IGLSampler, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -92,7 +92,7 @@ async function main()
drawIndexed: { firstIndex: 0, indexCount: 36 },
};
- const renderPass: IGLRenderPass = {
+ const renderPass: IRenderPass = {
descriptor: {
colorAttachments: [{
clearValue: [0.0, 0.0, 0.0, 1.0],
diff --git a/examples/src/webgl-examples/sample8.ts b/examples/src/webgl-examples/sample8.ts
index 1139f36..227f8c4 100644
--- a/examples/src/webgl-examples/sample8.ts
+++ b/examples/src/webgl-examples/sample8.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLRenderObject, IGLRenderPass, IGLSampler, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
+import { IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLRenderObject, IGLSampler, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -96,7 +96,7 @@ function main()
drawIndexed: { firstIndex: 0, indexCount: 36 },
};
- const renderPass: IGLRenderPass = {
+ const renderPass: IRenderPass = {
descriptor: {
colorAttachments: [{
clearValue: [0.0, 0.0, 0.0, 1.0],
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 5a47ac2..d430c47 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,4 +1,4 @@
-import { IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, ITextureView } from "@feng3d/render-api";
+import { ICommandEncoder, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, ISubmit, ITextureView } from "@feng3d/render-api";
import { getFramebuffer } from "./caches/getFramebuffer";
import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLRenderOcclusionQuery } from "./caches/getGLRenderOcclusionQuery";
@@ -6,11 +6,8 @@ import { getIGLBlitFramebuffer } from "./caches/getIGLBlitFramebuffer";
import { getIGLRenderPassDescriptorWithMultisample } from "./caches/getIGLRenderPassDescriptorWithMultisample";
import { _GL_Submit_Times } from "./const/const";
import { IGLBlitFramebuffer } from "./data/IGLBlitFramebuffer";
-import { IGLCommandEncoder } from "./data/IGLCommandEncoder";
import { IGLCopyBufferToBuffer } from "./data/IGLCopyBufferToBuffer";
import { IGLCopyTextureToTexture } from "./data/IGLCopyTextureToTexture";
-import { IGLRenderPass, IGLRenderPassObject } from "./data/IGLRenderPass";
-import { IGLSubmit } from "./data/IGLSubmit";
import { runFramebuffer } from "./runs/runFramebuffer";
import { runOcclusionQuery } from "./runs/runOcclusionQuery";
import { runRenderObject } from "./runs/runRenderObject";
@@ -19,7 +16,7 @@ import { runViewPort } from "./runs/runViewPort";
export class RunWebGL
{
- runSubmit(gl: WebGLRenderingContext, submit: IGLSubmit)
+ runSubmit(gl: WebGLRenderingContext, submit: ISubmit)
{
const commandBuffers = submit.commandEncoders.map((v) =>
{
@@ -32,13 +29,13 @@ export class RunWebGL
gl[_GL_Submit_Times] = ~~gl[_GL_Submit_Times] + 1;
}
- protected runCommandEncoder(gl: WebGLRenderingContext, commandEncoder: IGLCommandEncoder)
+ protected runCommandEncoder(gl: WebGLRenderingContext, commandEncoder: ICommandEncoder)
{
commandEncoder.passEncoders.forEach((passEncoder) =>
{
if (!passEncoder.__type)
{
- this.runRenderPass(gl, passEncoder as IGLRenderPass);
+ this.runRenderPass(gl, passEncoder as IRenderPass);
}
else if (passEncoder.__type === "RenderPass")
{
@@ -63,7 +60,7 @@ export class RunWebGL
});
}
- protected runRenderPass(gl: WebGLRenderingContext, renderPass: IGLRenderPass)
+ protected runRenderPass(gl: WebGLRenderingContext, renderPass: IRenderPass)
{
// 处理不被遮挡查询
const occlusionQuery = getGLRenderOcclusionQuery(gl, renderPass.renderObjects);
@@ -108,8 +105,8 @@ export class RunWebGL
const depthStencilAttachment = Object.assign({}, defaultDepthStencilAttachment, passDescriptor.depthStencilAttachment);
const { depthClearValue, depthLoadOp, stencilClearValue, stencilLoadOp } = depthStencilAttachment;
-
-
+
+
gl.clearDepth(depthClearValue);
gl.clearStencil(stencilClearValue);
@@ -120,7 +117,7 @@ export class RunWebGL
);
}
- private runRenderObjects(gl: WebGLRenderingContext, renderObjects?: readonly IGLRenderPassObject[])
+ private runRenderObjects(gl: WebGLRenderingContext, renderObjects?: readonly IRenderPassObject[])
{
renderObjects?.forEach((renderObject) =>
{
diff --git a/src/WebGL.ts b/src/WebGL.ts
index 5585b87..c5202c4 100644
--- a/src/WebGL.ts
+++ b/src/WebGL.ts
@@ -1,11 +1,13 @@
+import { IRenderPassDescriptor, ISubmit, ITexture } from "@feng3d/render-api";
+
import { RunWebGL } from "./RunWebGL";
import { deleteFramebuffer } from "./caches/getFramebuffer";
+import { deleteBuffer } from "./caches/getGLBuffer";
+import { getGLCanvasContext } from "./caches/getGLCanvasContext";
import { deleteProgram } from "./caches/getGLProgram";
import { deleteRenderbuffer } from "./caches/getGLRenderbuffer";
-import { getGLCanvasContext } from "./caches/getGLCanvasContext";
import { deleteSampler } from "./caches/getGLSampler";
import { deleteTexture } from "./caches/getGLTexture";
-import { deleteBuffer } from "./caches/getGLBuffer";
import { deleteTransformFeedback } from "./caches/getGLTransformFeedback";
import { IGLBuffer } from "./data/IGLBuffer";
import { IGLCanvasContext } from "./data/IGLCanvasContext";
@@ -13,10 +15,8 @@ import { IGLReadPixels } from "./data/IGLReadPixels";
import { IGLRenderPipeline } from "./data/IGLRenderPipeline";
import { IGLRenderbuffer } from "./data/IGLRenderbuffer";
import { IGLSampler } from "./data/IGLSampler";
-import { IGLSubmit } from "./data/IGLSubmit";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
import { runReadPixels } from "./runs/runReadPixels";
-import { IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
/**
* WEBGL 对象。
@@ -41,7 +41,7 @@ export class WebGL
* @param submit 一次 GPU 提交内容。
*
*/
- submit(submit: IGLSubmit)
+ submit(submit: ISubmit)
{
this._runWebGL.runSubmit(this._gl, submit);
}
diff --git a/src/caches/getGLRenderOcclusionQuery.ts b/src/caches/getGLRenderOcclusionQuery.ts
index 3e4f1ad..cc8c974 100644
--- a/src/caches/getGLRenderOcclusionQuery.ts
+++ b/src/caches/getGLRenderOcclusionQuery.ts
@@ -1,7 +1,7 @@
+import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
import { IGLOcclusionQuery, IGLQuery } from "../data/IGLOcclusionQuery";
-import { IGLRenderPass, IGLRenderPassObject } from "../data/IGLRenderPass";
-export function getGLRenderOcclusionQuery(gl: WebGLRenderingContext, renderObjects?: readonly IGLRenderPassObject[])
+export function getGLRenderOcclusionQuery(gl: WebGLRenderingContext, renderObjects?: readonly IRenderPassObject[])
{
if (!renderObjects) return defautRenderOcclusionQuery;
if (!(gl instanceof WebGL2RenderingContext)) return defautRenderOcclusionQuery;
@@ -30,7 +30,7 @@ export function getGLRenderOcclusionQuery(gl: WebGLRenderingContext, renderObjec
/**
* 查询结果。
*/
- const resolve = (renderPass: IGLRenderPass) =>
+ const resolve = (renderPass: IRenderPass) =>
{
const results = occlusionQueryObjects.map((v) => v._step.resolve());
@@ -48,7 +48,7 @@ export function getGLRenderOcclusionQuery(gl: WebGLRenderingContext, renderObjec
interface GLRenderOcclusionQuery
{
init: () => void
- resolve: (renderPass: IGLRenderPass) => void
+ resolve: (renderPass: IRenderPass) => void
}
const defautRenderOcclusionQuery = { init: () => { }, resolve: () => { } };
diff --git a/src/data/IGLCommandEncoder.ts b/src/data/IGLCommandEncoder.ts
index cf4c266..1bf9d2e 100644
--- a/src/data/IGLCommandEncoder.ts
+++ b/src/data/IGLCommandEncoder.ts
@@ -1,8 +1,7 @@
-import { ICommandEncoder } from "@feng3d/render-api";
+import { ICommandEncoder, IPassEncoder, IRenderPass } from "@feng3d/render-api";
import { IGLBlitFramebuffer } from "./IGLBlitFramebuffer";
import { IGLCopyBufferToBuffer } from "./IGLCopyBufferToBuffer";
import { IGLCopyTextureToTexture } from "./IGLCopyTextureToTexture";
-import { IGLRenderPass } from "./IGLRenderPass";
declare module "@feng3d/render-api"
{
@@ -13,25 +12,3 @@ declare module "@feng3d/render-api"
IGLCopyBufferToBuffer: IGLCopyBufferToBuffer;
}
}
-
-/**
- * 命令编码器。
- */
-export interface IGLCommandEncoder extends ICommandEncoder
-{
- /**
- * 通道编码器列表。
- *
- * 包括计算通道编码器、渲染通道编码器 以及 GPU中缓存与纹理之间拷贝。
- */
- passEncoders: IGLPassEncoder[];
-}
-
-/**
- * 通道编码器。
- *
- * 包括计算通道编码器、渲染通道编码器 以及 GPU中缓存与纹理之间拷贝。
- *
- * 通道可以理解为源数据通过某种操作到目标数据的映射,该操作可以是计算模块、也可以是渲染模块、也可以是简单的拷贝或者转换。
- */
-export type IGLPassEncoder = IGLRenderPass | IGLBlitFramebuffer | IGLCopyTextureToTexture | IGLCopyBufferToBuffer;
diff --git a/src/data/IGLRenderPass.ts b/src/data/IGLRenderPass.ts
index 63a52ef..543782c 100644
--- a/src/data/IGLRenderPass.ts
+++ b/src/data/IGLRenderPass.ts
@@ -1,27 +1,31 @@
-import { IRenderPass } from "@feng3d/render-api";
+import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
import { IGLOcclusionQuery } from "./IGLOcclusionQuery";
import { IGLRenderObject } from "./IGLRenderObject";
import { IGLScissorRect } from "./IGLScissorRect";
import { IGLViewport } from "./IGLViewport";
-/**
- * WebGL渲染通道
- *
- * 包含渲染通道描述以及需要渲染的对象列表。
- */
-export interface IGLRenderPass extends IRenderPass
+declare module "@feng3d/render-api"
{
/**
- * 渲染对象列表,默认为 []。
- */
- readonly renderObjects?: readonly IGLRenderPassObject[];
-
- /**
- * 渲染不被遮挡查询结果。具体数据保存在各子项的"result"属性中。
+ * WebGL渲染通道
*
- * 当提交WebGL后自动获取结果后填充该属性。
+ * 包含渲染通道描述以及需要渲染的对象列表。
*/
- occlusionQueryResults?: IGLOcclusionQuery[];
-}
+ export interface IRenderPass
+ {
+ /**
+ * 渲染不被遮挡查询结果。具体数据保存在各子项的"result"属性中。
+ *
+ * 当提交WebGL后自动获取结果后填充该属性。
+ */
+ occlusionQueryResults?: IGLOcclusionQuery[];
+ }
-export type IGLRenderPassObject = IGLRenderObject | IGLViewport | IGLScissorRect | IGLOcclusionQuery;
\ No newline at end of file
+ export interface IRenderPassObjectMap
+ {
+ IGLRenderObject:IGLRenderObject,
+ IGLViewport:IGLViewport
+ IGLScissorRect:IGLScissorRect
+ IGLOcclusionQuery:IGLOcclusionQuery
+ }
+}
diff --git a/src/data/IGLRenderPipeline.ts b/src/data/IGLRenderPipeline.ts
index 6b0d4b9..e80daa8 100644
--- a/src/data/IGLRenderPipeline.ts
+++ b/src/data/IGLRenderPipeline.ts
@@ -2,11 +2,6 @@ import { IGLColorTargetState } from "./IGLColorTargetState";
import { IGLDepthStencilState } from "./IGLDepthStencilState";
import { IGLPrimitiveState } from "./IGLPrimitiveState";
-/**
- * @deprecated 请使用 `IRenderPipeline` 。
- */
-export type IGLProgram = IGLRenderPipeline;
-
/**
* 渲染管线。
*/
diff --git a/src/data/IGLSubmit.ts b/src/data/IGLSubmit.ts
deleted file mode 100644
index a950b45..0000000
--- a/src/data/IGLSubmit.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { ISubmit } from "@feng3d/render-api";
-
-import { IGLCommandEncoder } from "./IGLCommandEncoder";
-
-/**
- * 一次 GPU 提交。
- */
-export interface IGLSubmit extends ISubmit
-{
- /**
- * 命令编码器列表。
- */
- commandEncoders: IGLCommandEncoder[];
-}
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index 0cb88fa..89124c1 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -21,7 +21,6 @@ export * from "./data/IGLRenderPipeline";
export * from "./data/IGLSampler";
export * from "./data/IGLSamplerTexture";
export * from "./data/IGLScissorRect";
-export * from "./data/IGLSubmit";
export * from "./data/IGLTexture";
export * from "./data/IGLTexturePixelStore";
export * from "./data/IGLTransformFeedback";
--
Gitee
From 95c0964a95ab3746d2d6d427047c7c92574c1ffd Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 00:04:48 +0800
Subject: [PATCH 095/186] IGLRenderObject -> IRenderObject
---
examples/src/WebGL2Samples/buffer_uniform.ts | 6 +-
.../src/WebGL2Samples/draw_image_space.ts | 6 +-
examples/src/WebGL2Samples/draw_instanced.ts | 5 +-
.../WebGL2Samples/draw_primitive_restart.ts | 5 +-
.../src/WebGL2Samples/draw_range_arrays.ts | 6 +-
examples/src/WebGL2Samples/fbo_blit.ts | 8 +-
.../WebGL2Samples/fbo_new_blend_equation.ts | 6 +-
examples/src/WebGL2Samples/fbo_read_pixels.ts | 6 +-
.../WebGL2Samples/fbo_rtt_texture_array.ts | 6 +-
.../src/WebGL2Samples/geo_vertex_format.ts | 6 +-
examples/src/WebGL2Samples/glsl_centroid.ts | 6 +-
examples/src/WebGL2Samples/query_occlusion.ts | 6 +-
examples/src/WebGL2Samples/sampler_filter.ts | 6 +-
examples/src/WebGL2Samples/sampler_wrap.ts | 6 +-
.../src/WebGL2Samples/texture_2d_array.ts | 6 +-
examples/src/WebGL2Samples/texture_3d.ts | 8 +-
.../src/WebGL2Samples/texture_derivative.ts | 6 +-
examples/src/WebGL2Samples/texture_grad.ts | 6 +-
.../src/WebGL2Samples/texture_immutable.ts | 6 +-
examples/src/WebGL2Samples/texture_integer.ts | 6 +-
examples/src/WebGL2Samples/texture_lod.ts | 6 +-
examples/src/WebGL2Samples/texture_vertex.ts | 6 +-
.../transform_feedback_instanced.ts | 8 +-
.../transform_feedback_separated_2.ts | 6 +-
examples/src/regl-examples/basic.ts | 5 +-
examples/src/regl-examples/batch.ts | 7 +-
examples/src/regl-examples/blur.ts | 7 +-
examples/src/regl-examples/bunny.ts | 5 +-
examples/src/regl-examples/camera.ts | 5 +-
examples/src/regl-examples/cloth.ts | 5 +-
examples/src/regl-examples/cube.ts | 5 +-
examples/src/regl-examples/util/camera.ts | 6 +-
examples/src/webgl-examples/sample4.ts | 6 +-
examples/src/webgl-examples/sample5.ts | 6 +-
examples/src/webgl-examples/sample6.ts | 6 +-
examples/src/webgl-examples/sample7.ts | 6 +-
examples/src/webgl-examples/sample8.ts | 6 +-
src/data/IGLOcclusionQuery.ts | 4 +-
src/data/IGLRenderObject.ts | 94 +++++++++----------
src/data/IGLRenderPass.ts | 9 +-
src/runs/runDrawCall.ts | 4 +-
src/runs/runRenderObject.ts | 4 +-
42 files changed, 173 insertions(+), 165 deletions(-)
diff --git a/examples/src/WebGL2Samples/buffer_uniform.ts b/examples/src/WebGL2Samples/buffer_uniform.ts
index 60af5e8..4a06e89 100644
--- a/examples/src/WebGL2Samples/buffer_uniform.ts
+++ b/examples/src/WebGL2Samples/buffer_uniform.ts
@@ -1,5 +1,5 @@
-import { IRenderPass } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLUniformBuffer, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLUniformBuffer, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -76,7 +76,7 @@ import { getShaderSource } from "./utility";
},
};
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
vertices: vertexArray.vertices,
indices: elementData,
diff --git a/examples/src/WebGL2Samples/draw_image_space.ts b/examples/src/WebGL2Samples/draw_image_space.ts
index 64b3586..fc7a01b 100644
--- a/examples/src/WebGL2Samples/draw_image_space.ts
+++ b/examples/src/WebGL2Samples/draw_image_space.ts
@@ -1,5 +1,5 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -34,7 +34,7 @@ loadImage("../../assets/img/Di-3d.png", (img) =>
}
};
- const renderObject: IGLRenderObject = {
+ const renderObject: IRenderObject = {
uniforms: {
diffuse: { texture, sampler },
u_imageSize: [canvas.width / 2, canvas.height / 2],
diff --git a/examples/src/WebGL2Samples/draw_instanced.ts b/examples/src/WebGL2Samples/draw_instanced.ts
index 3dc732c..2138744 100644
--- a/examples/src/WebGL2Samples/draw_instanced.ts
+++ b/examples/src/WebGL2Samples/draw_instanced.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLVertexAttributes, IGLVertexBuffer, WebGL } from "@feng3d/webgl";
+import { IRenderObject } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -30,7 +31,7 @@ const vertexArray: { vertices?: IGLVertexAttributes } = {
},
};
-const renderObject: IGLRenderObject = {
+const renderObject: IRenderObject = {
vertices: vertexArray.vertices,
uniforms: {},
drawVertex: { instanceCount: 2 },
diff --git a/examples/src/WebGL2Samples/draw_primitive_restart.ts b/examples/src/WebGL2Samples/draw_primitive_restart.ts
index 7313631..2df43f3 100644
--- a/examples/src/WebGL2Samples/draw_primitive_restart.ts
+++ b/examples/src/WebGL2Samples/draw_primitive_restart.ts
@@ -1,4 +1,5 @@
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -42,7 +43,7 @@ const vertexArray: { vertices?: IGLVertexAttributes } = {
},
};
-const renderObject: IGLRenderObject = {
+const renderObject: IRenderObject = {
vertices: vertexArray.vertices,
indices: indices,
uniforms: {},
diff --git a/examples/src/WebGL2Samples/draw_range_arrays.ts b/examples/src/WebGL2Samples/draw_range_arrays.ts
index f0bda54..bb3c062 100644
--- a/examples/src/WebGL2Samples/draw_range_arrays.ts
+++ b/examples/src/WebGL2Samples/draw_range_arrays.ts
@@ -1,5 +1,5 @@
-import { IRenderPass } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -44,7 +44,7 @@ const vertexArray: { vertices?: IGLVertexAttributes } = {
};
const vertexCount = 12;
-const renderObject: IGLRenderObject = {
+const renderObject: IRenderObject = {
vertices: vertexArray.vertices,
pipeline,
};
diff --git a/examples/src/WebGL2Samples/fbo_blit.ts b/examples/src/WebGL2Samples/fbo_blit.ts
index 9674196..8453881 100644
--- a/examples/src/WebGL2Samples/fbo_blit.ts
+++ b/examples/src/WebGL2Samples/fbo_blit.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassDescriptor, ITexture, ITextureView } from "@feng3d/render-api";
-import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, ITexture, ITextureView } from "@feng3d/render-api";
+import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -80,7 +80,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
};
const viewport: IGLViewport = { __type: "Viewport", x: 0, y: 0, width: FRAMEBUFFER_SIZE.x, height: FRAMEBUFFER_SIZE.y };
- const renderObject: IGLRenderObject = {
+ const renderObject: IRenderObject = {
pipeline: program,
vertices: vertexArray.vertices,
uniforms: {
@@ -149,7 +149,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
};
const viewport2: IGLViewport = { __type: "Viewport", x: 0, y: 0, width: canvas.width, height: canvas.height };
- const renderObject2: IGLRenderObject = {
+ const renderObject2: IRenderObject = {
vertices: vertexArray.vertices,
uniforms: {
MVP: new Float32Array([
diff --git a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
index 882c8ae..db9d2a3 100644
--- a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
+++ b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -119,7 +119,7 @@ function render()
0.0, 0.0, 0.0, 1.0
]);
- const renderObject: IGLRenderObject = {
+ const renderObject: IRenderObject = {
pipeline: program,
vertices: vertexArray.vertices,
uniforms: { mvp: matrix, diffuse: { texture, sampler } },
diff --git a/examples/src/WebGL2Samples/fbo_read_pixels.ts b/examples/src/WebGL2Samples/fbo_read_pixels.ts
index 3745965..ab8a632 100644
--- a/examples/src/WebGL2Samples/fbo_read_pixels.ts
+++ b/examples/src/WebGL2Samples/fbo_read_pixels.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassDescriptor, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -147,7 +147,7 @@ const rp: IRenderPass = {
renderObjects: renderObjects
};
-const ro: IGLRenderObject = {
+const ro: IRenderObject = {
pipeline: layerProgram,
uniforms: {
mvp: matrix,
diff --git a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
index 590fe63..55d60a6 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassDescriptor, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -151,7 +151,7 @@ const renderPass: IRenderPass = {
renderObjects: renderObjects,
};
-const renderObject: IGLRenderObject = {
+const renderObject: IRenderObject = {
pipeline: layerProgram,
uniforms: { mvp: matrix, diffuse: { texture, sampler } },
vertices: layerVertexArray.vertices,
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index 5221bf8..8383fee 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { HalfFloat } from "./third-party/HalfFloatUtility";
import { getShaderSource, loadImage } from "./utility";
@@ -202,7 +202,7 @@ import { getShaderSource, loadImage } from "./utility";
const lightPosition = [0.0, 0.0, 5.0];
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
vertices: vertexArray.vertices,
indices: new Uint16Array(cubeVertexIndices),
diff --git a/examples/src/WebGL2Samples/glsl_centroid.ts b/examples/src/WebGL2Samples/glsl_centroid.ts
index 2b17824..fefdaed 100644
--- a/examples/src/WebGL2Samples/glsl_centroid.ts
+++ b/examples/src/WebGL2Samples/glsl_centroid.ts
@@ -1,5 +1,5 @@
-import { IPassEncoder, IRenderPass, IRenderPassDescriptor, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IPassEncoder, IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -179,7 +179,7 @@ const renderObjects: IRenderPassObject[] = [];
const rp2: IRenderPass = {
renderObjects: renderObjects,
};
-const ro: IGLRenderObject = {
+const ro: IRenderObject = {
pipeline: programs[PROGRAM.SPLASH],
vertices: vertexArrays[PROGRAM.SPLASH].vertices,
};
diff --git a/examples/src/WebGL2Samples/query_occlusion.ts b/examples/src/WebGL2Samples/query_occlusion.ts
index 93971e6..5535dfb 100644
--- a/examples/src/WebGL2Samples/query_occlusion.ts
+++ b/examples/src/WebGL2Samples/query_occlusion.ts
@@ -1,6 +1,6 @@
-import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
+import { IRenderObject, IRenderPass, IRenderPassObject } from "@feng3d/render-api";
import { watcher } from "@feng3d/watcher";
-import { IGLCanvasContext, IGLOcclusionQuery, IGLRenderObject, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLOcclusionQuery, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
// -- Init Canvas
@@ -49,7 +49,7 @@ const rp: IRenderPass = {
renderObjects: renderObjects,
};
-const ro: IGLRenderObject = {
+const ro: IRenderObject = {
vertices: vertexArray.vertices,
pipeline: program,
drawVertex: { firstVertex: 0, vertexCount: 3 },
diff --git a/examples/src/WebGL2Samples/sampler_filter.ts b/examples/src/WebGL2Samples/sampler_filter.ts
index e10c119..94fc1e8 100644
--- a/examples/src/WebGL2Samples/sampler_filter.ts
+++ b/examples/src/WebGL2Samples/sampler_filter.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -144,7 +144,7 @@ function render()
renderObjects: renderObjects
};
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
uniforms: { mvp: matrix },
vertices: vertexArray.vertices,
diff --git a/examples/src/WebGL2Samples/sampler_wrap.ts b/examples/src/WebGL2Samples/sampler_wrap.ts
index 182613b..333b735 100644
--- a/examples/src/WebGL2Samples/sampler_wrap.ts
+++ b/examples/src/WebGL2Samples/sampler_wrap.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -142,7 +142,7 @@ function render()
0.0, 0.0, 0.0, 1.0
]);
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
uniforms: { mvp: matrix },
vertices: vertexArray.vertices,
diff --git a/examples/src/WebGL2Samples/texture_2d_array.ts b/examples/src/WebGL2Samples/texture_2d_array.ts
index b749c59..d468ed4 100644
--- a/examples/src/WebGL2Samples/texture_2d_array.ts
+++ b/examples/src/WebGL2Samples/texture_2d_array.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -82,7 +82,7 @@ import { getShaderSource, loadImage } from "./utility";
0.0, 0.0, 0.0, 1.0
]);
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
vertices: vertexArray.vertices,
uniforms: {
diff --git a/examples/src/WebGL2Samples/texture_3d.ts b/examples/src/WebGL2Samples/texture_3d.ts
index de36988..61f981b 100644
--- a/examples/src/WebGL2Samples/texture_3d.ts
+++ b/examples/src/WebGL2Samples/texture_3d.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource } from "./utility";
@@ -156,7 +156,7 @@ import { getShaderSource } from "./utility";
];
}
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
uniforms: {
diffuse: { texture, sampler },
@@ -166,7 +166,7 @@ import { getShaderSource } from "./utility";
};
const renderPassObjects: IRenderPassObject[] = [];
- const renderObjects: IGLRenderObject[] = [];
+ const renderObjects: IRenderObject[] = [];
for (let i = 0; i < Corners.MAX; ++i)
{
renderPassObjects.push(
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index 69bf2ce..aff4306 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -207,7 +207,7 @@ import { getShaderSource, loadImage } from "./utility";
lastMouseY = newY;
};
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
vertices: vertexArray.vertices,
indices: new Uint16Array(cubeVertexIndices),
diff --git a/examples/src/WebGL2Samples/texture_grad.ts b/examples/src/WebGL2Samples/texture_grad.ts
index 46cc218..50ea3dd 100644
--- a/examples/src/WebGL2Samples/texture_grad.ts
+++ b/examples/src/WebGL2Samples/texture_grad.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -197,7 +197,7 @@ import { getShaderSource, loadImage } from "./utility";
lastMouseY = newY;
};
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
vertices: vertexArray.vertices,
indices: new Uint16Array(cubeVertexIndices),
diff --git a/examples/src/WebGL2Samples/texture_immutable.ts b/examples/src/WebGL2Samples/texture_immutable.ts
index bb719cc..f5d7368 100644
--- a/examples/src/WebGL2Samples/texture_immutable.ts
+++ b/examples/src/WebGL2Samples/texture_immutable.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource, loadImage } from "./utility";
@@ -99,7 +99,7 @@ import { getShaderSource, loadImage } from "./utility";
};
// -- Render
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
vertices: vertexArray.vertices,
uniforms: {
diff --git a/examples/src/WebGL2Samples/texture_integer.ts b/examples/src/WebGL2Samples/texture_integer.ts
index 310bbbc..49a0246 100644
--- a/examples/src/WebGL2Samples/texture_integer.ts
+++ b/examples/src/WebGL2Samples/texture_integer.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -69,7 +69,7 @@ import { getShaderSource, loadImage } from "./utility";
0.0, 0.0, 0.0, 1.0
]);
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
uniforms: {
MVP: matrix,
diff --git a/examples/src/WebGL2Samples/texture_lod.ts b/examples/src/WebGL2Samples/texture_lod.ts
index 15e7d6e..2341dad 100644
--- a/examples/src/WebGL2Samples/texture_lod.ts
+++ b/examples/src/WebGL2Samples/texture_lod.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -193,7 +193,7 @@ import { getShaderSource, loadImage } from "./utility";
0.0, 0.0, 0.0, 1.0
]);
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
uniforms: {
mvp: matrix,
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index ae3775f..30cdc2a 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderObject, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
@@ -56,7 +56,7 @@ import { getShaderSource, loadImage } from "./utility";
let texture: ITexture;
let sampler: IGLSampler;
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
};
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index 3748e49..7afc477 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -1,5 +1,5 @@
-import { IRenderPass } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderObject, IGLRenderPipeline, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -105,7 +105,7 @@ import { getShaderSource } from "./utility";
};
}
- const transformRO: IGLRenderObject = {
+ const transformRO: IRenderObject = {
pipeline: programs[PROGRAM_TRANSFORM],
vertices: null,
indices: null,
@@ -115,7 +115,7 @@ import { getShaderSource } from "./utility";
};
const viewport: IGLViewport = { __type: "Viewport", x: 0, y: 0, width: canvas.width, height: canvas.height - 10 };
- const renderRO: IGLRenderObject = {
+ const renderRO: IRenderObject = {
pipeline: programs[PROGRAM_DRAW],
uniforms: {},
drawVertex: { vertexCount: 3, instanceCount: NUM_INSTANCES },
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
index 227c17a..ecb078d 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
@@ -1,5 +1,5 @@
-import { IRenderPass } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLRenderObject, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
@@ -122,7 +122,7 @@ import { getShaderSource } from "./utility";
}
const viewport: IGLViewport = { __type: "Viewport", x: 0, y: 0, width: canvas.width, height: canvas.height - 10 };
- const ro: IGLRenderObject = {
+ const ro: IRenderObject = {
pipeline: program,
uniforms: {
u_color: [0.0, 1.0, 1.0, 1.0],
diff --git a/examples/src/regl-examples/basic.ts b/examples/src/regl-examples/basic.ts
index 6f77082..6e7ea6f 100644
--- a/examples/src/regl-examples/basic.ts
+++ b/examples/src/regl-examples/basic.ts
@@ -1,4 +1,5 @@
-import { IGLRenderObject, WebGL } from "@feng3d/webgl";
+import { IRenderObject } from "@feng3d/render-api";
+import { WebGL } from "@feng3d/webgl";
/**
* 让T中以及所有键值中的所有键都是可选的
@@ -15,7 +16,7 @@ document.body.appendChild(canvas);
const webgl = new WebGL({ canvasId: "glcanvas" });
-const renderObject: IGLRenderObject = {
+const renderObject: IRenderObject = {
vertices: {
position: {
data: new Float32Array([
diff --git a/examples/src/regl-examples/batch.ts b/examples/src/regl-examples/batch.ts
index 1e6305f..c0a6ebb 100644
--- a/examples/src/regl-examples/batch.ts
+++ b/examples/src/regl-examples/batch.ts
@@ -1,4 +1,5 @@
-import { IGLRenderObject, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject } from "@feng3d/render-api";
+import { IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
const canvas = document.createElement("canvas");
canvas.id = "glcanvas";
@@ -55,7 +56,7 @@ const vertexArray: { vertices?: IGLVertexAttributes } = {
function getRenderObject(tick: number, batchId: number)
{
- const renderObject: IGLRenderObject = {
+ const renderObject: IRenderObject = {
vertices: vertexArray.vertices,
uniforms: {
color: () => [
@@ -78,7 +79,7 @@ function draw()
canvas.height = canvas.clientHeight;
tick++;
- const renderObjects: IGLRenderObject[] = [];
+ const renderObjects: IRenderObject[] = [];
for (let i = 0; i < offsets.length; i++)
{
batchId = i;
diff --git a/examples/src/regl-examples/blur.ts b/examples/src/regl-examples/blur.ts
index eaf863f..e9047ae 100644
--- a/examples/src/regl-examples/blur.ts
+++ b/examples/src/regl-examples/blur.ts
@@ -1,4 +1,5 @@
-import { IGLRenderObject, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject } from "@feng3d/render-api";
+import { IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { fit } from "./hughsk/canvas-fit";
import { attachCamera } from "./hughsk/canvas-orbit-camera";
@@ -66,7 +67,7 @@ const pipeline: IGLRenderPipeline = {
function getRenderObject(tick: number, batchId: number)
{
- const renderObject: IGLRenderObject = {
+ const renderObject: IRenderObject = {
vertices: vertexArray.vertices,
uniforms: {
color: () => [
@@ -89,7 +90,7 @@ function draw()
canvas.height = canvas.clientHeight;
tick++;
- const renderObjects: IGLRenderObject[] = [];
+ const renderObjects: IRenderObject[] = [];
for (let i = 0; i < offsets.length; i++)
{
batchId = i;
diff --git a/examples/src/regl-examples/bunny.ts b/examples/src/regl-examples/bunny.ts
index 445c7eb..9885f81 100644
--- a/examples/src/regl-examples/bunny.ts
+++ b/examples/src/regl-examples/bunny.ts
@@ -1,4 +1,5 @@
-import { IGLRenderObject, WebGL } from "@feng3d/webgl";
+import { IRenderObject } from "@feng3d/render-api";
+import { WebGL } from "@feng3d/webgl";
import * as bunny from "./mikolalysenko/bunny";
import * as mat4 from "./stackgl/gl-mat4";
@@ -29,7 +30,7 @@ let tick = 0;
let viewportWidth = canvas.clientWidth;
let viewportHeight = canvas.clientHeight;
-const renderObject: IGLRenderObject = {
+const renderObject: IRenderObject = {
vertices: {
position: { data: new Float32Array(positions), numComponents: 3 },
},
diff --git a/examples/src/regl-examples/camera.ts b/examples/src/regl-examples/camera.ts
index 226263b..5d670c2 100644
--- a/examples/src/regl-examples/camera.ts
+++ b/examples/src/regl-examples/camera.ts
@@ -1,4 +1,5 @@
-import { IGLRenderObject, WebGL } from "@feng3d/webgl";
+import { IRenderObject } from "@feng3d/render-api";
+import { WebGL } from "@feng3d/webgl";
import { angleNormals } from "./mikolalysenko/angle-normals";
import * as bunny from "./mikolalysenko/bunny";
@@ -37,7 +38,7 @@ const normals = angleNormals(bunny.cells, bunny.positions).reduce((pv: number[],
return pv;
}, []);
-const renderObject: IGLRenderObject = {
+const renderObject: IRenderObject = {
vertices: {
position: { data: new Float32Array(positions), numComponents: 3 },
normal: { data: new Float32Array(normals), numComponents: 3 },
diff --git a/examples/src/regl-examples/cloth.ts b/examples/src/regl-examples/cloth.ts
index 1872b09..717c05c 100644
--- a/examples/src/regl-examples/cloth.ts
+++ b/examples/src/regl-examples/cloth.ts
@@ -1,4 +1,5 @@
-import { getIGLVertexBuffer, IGLRenderObject, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
+import { IRenderObject } from "@feng3d/render-api";
+import { getIGLVertexBuffer, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
import { fit } from "./hughsk/canvas-fit";
import { attachCamera } from "./hughsk/canvas-orbit-camera";
@@ -163,7 +164,7 @@ import * as vec3 from "./stackgl/gl-vec3";
let viewportWidth = 1;
let viewportHeight = 1;
- const renderObject: IGLRenderObject = {
+ const renderObject: IRenderObject = {
vertices: {
position: { data: new Float32Array(positions), numComponents: 3 },
normal: { data: new Float32Array(normals), numComponents: 3 },
diff --git a/examples/src/regl-examples/cube.ts b/examples/src/regl-examples/cube.ts
index 0d7f78d..77459f0 100644
--- a/examples/src/regl-examples/cube.ts
+++ b/examples/src/regl-examples/cube.ts
@@ -1,4 +1,5 @@
-import { IGLRenderObject, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
+import { IRenderObject } from "@feng3d/render-api";
+import { IGLSamplerTexture, WebGL } from "@feng3d/webgl";
import * as mat4 from "./stackgl/gl-mat4";
(async () =>
@@ -63,7 +64,7 @@ import * as mat4 from "./stackgl/gl-mat4";
let viewportWidth = 1;
let viewportHeight = 1;
- const renderObject: IGLRenderObject = {
+ const renderObject: IRenderObject = {
vertices: {
position: { data: new Float32Array(positions), numComponents: 3 },
uv: { data: new Float32Array(uvs), numComponents: 2 },
diff --git a/examples/src/regl-examples/util/camera.ts b/examples/src/regl-examples/util/camera.ts
index ac1fdfd..aaa0e23 100644
--- a/examples/src/regl-examples/util/camera.ts
+++ b/examples/src/regl-examples/util/camera.ts
@@ -1,4 +1,4 @@
-import { IGLRenderObject } from "@feng3d/webgl";
+import { IRenderObject } from "@feng3d/render-api";
import { mouseListen as mouseChange } from "../mikolalysenko/mouse-change";
import { mouseWheelListen as mouseWheel } from "../mikolalysenko/mouse-wheel";
@@ -101,7 +101,7 @@ export function createCamera(props)
lookAt(cameraState.view, eye, center, up);
}
- const injectContext = (renderObject: IGLRenderObject, viewportWidth: number, viewportHeight: number) =>
+ const injectContext = (renderObject: IRenderObject, viewportWidth: number, viewportHeight: number) =>
{
Object.keys(cameraState).forEach(function (name)
{
@@ -116,7 +116,7 @@ export function createCamera(props)
1000.0);
};
- function setupCamera(renderObject: IGLRenderObject, viewportWidth: number, viewportHeight: number)
+ function setupCamera(renderObject: IRenderObject, viewportWidth: number, viewportHeight: number)
{
updateCamera();
injectContext(renderObject, viewportWidth, viewportHeight);
diff --git a/examples/src/webgl-examples/sample4.ts b/examples/src/webgl-examples/sample4.ts
index 29d9e04..5de3e9c 100644
--- a/examples/src/webgl-examples/sample4.ts
+++ b/examples/src/webgl-examples/sample4.ts
@@ -1,5 +1,5 @@
-import { IRenderPass } from "@feng3d/render-api";
-import { IGLRenderObject, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass } from "@feng3d/render-api";
+import { WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let squareRotation = 0.0;
@@ -15,7 +15,7 @@ function main()
const webgl = new WebGL({ canvasId: "glcanvas", contextId: "webgl" });
- const renderObject: IGLRenderObject = {
+ const renderObject: IRenderObject = {
pipeline: {
primitive: { topology: "TRIANGLE_STRIP" },
vertex: {
diff --git a/examples/src/webgl-examples/sample5.ts b/examples/src/webgl-examples/sample5.ts
index c8248dc..7d336b2 100644
--- a/examples/src/webgl-examples/sample5.ts
+++ b/examples/src/webgl-examples/sample5.ts
@@ -1,5 +1,5 @@
-import { IRenderPass } from "@feng3d/render-api";
-import { IGLRenderObject, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass } from "@feng3d/render-api";
+import { WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -19,7 +19,7 @@ function main()
// objects we'll be drawing.
const buffers = initBuffers();
- const renderObject: IGLRenderObject = {
+ const renderObject: IRenderObject = {
pipeline: {
primitive: { topology: "TRIANGLES" },
vertex: {
diff --git a/examples/src/webgl-examples/sample6.ts b/examples/src/webgl-examples/sample6.ts
index 8f963cd..7611140 100644
--- a/examples/src/webgl-examples/sample6.ts
+++ b/examples/src/webgl-examples/sample6.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLRenderObject, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLSampler, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -21,7 +21,7 @@ async function main()
const texture = await loadTexture("../../cubetexture.png");
- const renderObject: IGLRenderObject = {
+ const renderObject: IRenderObject = {
pipeline: {
primitive: { topology: "TRIANGLES" },
vertex: {
diff --git a/examples/src/webgl-examples/sample7.ts b/examples/src/webgl-examples/sample7.ts
index 82aff4f..df31557 100644
--- a/examples/src/webgl-examples/sample7.ts
+++ b/examples/src/webgl-examples/sample7.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLRenderObject, IGLSampler, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLSampler, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -21,7 +21,7 @@ async function main()
const texture = await loadTexture("../../cubetexture.png");
- const renderObject: IGLRenderObject = {
+ const renderObject: IRenderObject = {
pipeline: {
primitive: { topology: "TRIANGLES" },
vertex: {
diff --git a/examples/src/webgl-examples/sample8.ts b/examples/src/webgl-examples/sample8.ts
index 227f8c4..deb9f14 100644
--- a/examples/src/webgl-examples/sample8.ts
+++ b/examples/src/webgl-examples/sample8.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLRenderObject, IGLSampler, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
+import { IGLSampler, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -25,7 +25,7 @@ function main()
const video = setupVideo("../../Firefox.mp4");
- const renderObject: IGLRenderObject = {
+ const renderObject: IRenderObject = {
pipeline: {
primitive: { topology: "TRIANGLES" },
vertex: {
diff --git a/src/data/IGLOcclusionQuery.ts b/src/data/IGLOcclusionQuery.ts
index 0f35690..416155e 100644
--- a/src/data/IGLOcclusionQuery.ts
+++ b/src/data/IGLOcclusionQuery.ts
@@ -1,5 +1,5 @@
+import { IRenderObject } from "@feng3d/render-api";
import { IGLOcclusionQueryStep } from "../caches/getGLRenderOcclusionQuery";
-import { IGLRenderObject } from "./IGLRenderObject";
export interface IGLOcclusionQuery
{
@@ -10,7 +10,7 @@ export interface IGLOcclusionQuery
/**
* 渲染对象列表。
*/
- renderObjects: IGLRenderObject[];
+ renderObjects: IRenderObject[];
/**
* 临时变量, 执行过程中由引擎自动填充。
diff --git a/src/data/IGLRenderObject.ts b/src/data/IGLRenderObject.ts
index df1cf72..36888ba 100644
--- a/src/data/IGLRenderObject.ts
+++ b/src/data/IGLRenderObject.ts
@@ -1,3 +1,4 @@
+import { IRenderObject } from "@feng3d/render-api";
import { LazyObject } from "../types";
import { IGLDrawIndexed } from "./IGLDrawIndexed";
import { IGLDrawVertex } from "./IGLDrawVertex";
@@ -7,54 +8,53 @@ import { IGLTransformFeedback } from "./IGLTransformFeedback";
import { IGLUniforms } from "./IGLUniforms";
import { IGLVertexAttributes } from "./IGLVertexAttributes";
-/**
- * 渲染原子(该对象会收集一切渲染所需数据以及参数)
- */
-export interface IGLRenderObject
+declare module "@feng3d/render-api"
{
/**
- * 数据类型。
- */
- readonly __type?: "RenderObject";
-
- /**
- * 渲染程序
- */
- pipeline: IGLRenderPipeline;
+ * 渲染对象,包含一次渲染时包含的所有数据。
+ */
+ export interface IRenderObject
+ {
+ /**
+ * 渲染程序
+ */
+ pipeline: IGLRenderPipeline;
+
+ /**
+ * 顶点属性数据列表
+ */
+ vertices?: IGLVertexAttributes;
+
+ /**
+ * 顶点索引数据
+ */
+ indices?: IGLIndicesDataTypes;
+
+ /**
+ * Uniform渲染数据
+ */
+ uniforms?: LazyObject;
+
+ /**
+ * 绘制一定数量顶点。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawVertex
+ */
+ drawVertex?: IGLDrawVertex;
+
+ /**
+ * 根据索引数据绘制图元。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements
+ */
+ drawIndexed?: IGLDrawIndexed;
+
+ /**
+ * 回写顶点着色器中输出到缓冲区。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/bindTransformFeedback
+ */
+ transformFeedback?: IGLTransformFeedback;
+ }
- /**
- * 顶点属性数据列表
- */
- vertices?: IGLVertexAttributes;
-
- /**
- * 顶点索引数据
- */
- indices?: IGLIndicesDataTypes;
-
- /**
- * Uniform渲染数据
- */
- uniforms?: LazyObject;
-
- /**
- * 绘制一定数量顶点。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawVertex
- */
- drawVertex?: IGLDrawVertex;
-
- /**
- * 根据索引数据绘制图元。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements
- */
- drawIndexed?: IGLDrawIndexed;
-
- /**
- * 回写顶点着色器中输出到缓冲区。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/bindTransformFeedback
- */
- transformFeedback?: IGLTransformFeedback;
}
diff --git a/src/data/IGLRenderPass.ts b/src/data/IGLRenderPass.ts
index 543782c..739ab14 100644
--- a/src/data/IGLRenderPass.ts
+++ b/src/data/IGLRenderPass.ts
@@ -1,6 +1,5 @@
import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
import { IGLOcclusionQuery } from "./IGLOcclusionQuery";
-import { IGLRenderObject } from "./IGLRenderObject";
import { IGLScissorRect } from "./IGLScissorRect";
import { IGLViewport } from "./IGLViewport";
@@ -23,9 +22,9 @@ declare module "@feng3d/render-api"
export interface IRenderPassObjectMap
{
- IGLRenderObject:IGLRenderObject,
- IGLViewport:IGLViewport
- IGLScissorRect:IGLScissorRect
- IGLOcclusionQuery:IGLOcclusionQuery
+ IGLRenderObject: IRenderObject,
+ IGLViewport: IGLViewport
+ IGLScissorRect: IGLScissorRect
+ IGLOcclusionQuery: IGLOcclusionQuery
}
}
diff --git a/src/runs/runDrawCall.ts b/src/runs/runDrawCall.ts
index 52af0f2..9316365 100644
--- a/src/runs/runDrawCall.ts
+++ b/src/runs/runDrawCall.ts
@@ -1,14 +1,14 @@
+import { IRenderObject } from "@feng3d/render-api";
import { getBufferType } from "../caches/getGLBuffer";
import { ElementTypeMap } from "../const/IGLUniformType";
import { IGLDrawIndexed } from "../data/IGLDrawIndexed";
import { IGLDrawVertex } from "../data/IGLDrawVertex";
import { IGLIndicesDataTypes } from "../data/IGLIndexBuffer";
import { IGLDrawMode } from "../data/IGLPrimitiveState";
-import { IGLRenderObject } from "../data/IGLRenderObject";
import { IGLVertexAttributes } from "../data/IGLVertexAttributes";
import { defaultPrimitiveState } from "./runPrimitiveState";
-export function runDrawCall(gl: WebGLRenderingContext, renderObject: IGLRenderObject)
+export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObject)
{
const { pipeline, vertices, indices, drawIndexed, drawVertex } = renderObject;
diff --git a/src/runs/runRenderObject.ts b/src/runs/runRenderObject.ts
index c7aedad..0647fdb 100644
--- a/src/runs/runRenderObject.ts
+++ b/src/runs/runRenderObject.ts
@@ -1,4 +1,4 @@
-import { IGLRenderObject } from "../data/IGLRenderObject";
+import { IRenderObject } from "@feng3d/render-api";
import { runDrawCall } from "./runDrawCall";
import { defaultPrimitiveState } from "./runPrimitiveState";
import { runRenderPipeline } from "./runRenderPipeline";
@@ -6,7 +6,7 @@ import { endTransformFeedback, runTransformFeedback } from "./runTransformFeedba
import { runUniforms } from "./runUniforms";
import { runVertexArray } from "./runVertexArray";
-export function runRenderObject(gl: WebGLRenderingContext, renderObject: IGLRenderObject)
+export function runRenderObject(gl: WebGLRenderingContext, renderObject: IRenderObject)
{
const { pipeline, vertices, indices, uniforms, transformFeedback } = renderObject;
--
Gitee
From b04292ff7811d3e5964fbdd0d119385de5ffe928 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 00:17:20 +0800
Subject: [PATCH 096/186] IGLRenderPipeline -> IRenderPipeline
---
examples/package.json | 1 -
examples/src/WebGL2Samples/buffer_copy.ts | 6 +-
examples/src/WebGL2Samples/buffer_uniform.ts | 6 +-
.../src/WebGL2Samples/draw_image_space.ts | 6 +-
examples/src/WebGL2Samples/draw_instanced.ts | 6 +-
.../src/WebGL2Samples/draw_instanced_ubo.ts | 6 +-
.../WebGL2Samples/draw_primitive_restart.ts | 6 +-
.../src/WebGL2Samples/draw_range_arrays.ts | 6 +-
examples/src/WebGL2Samples/fbo_blit.ts | 6 +-
examples/src/WebGL2Samples/fbo_multisample.ts | 6 +-
.../WebGL2Samples/fbo_new_blend_equation.ts | 6 +-
examples/src/WebGL2Samples/fbo_read_pixels.ts | 8 +--
.../WebGL2Samples/fbo_rtt_depth_texture.ts | 8 +--
.../src/WebGL2Samples/fbo_rtt_draw_buffers.ts | 8 +--
.../WebGL2Samples/fbo_rtt_texture_array.ts | 8 +--
.../src/WebGL2Samples/geo_vertex_format.ts | 6 +-
examples/src/WebGL2Samples/glsl_centroid.ts | 6 +-
.../glsl_flat_smooth_interpolators.ts | 6 +-
.../WebGL2Samples/glsl_non_square_matrix.ts | 6 +-
examples/src/WebGL2Samples/query_occlusion.ts | 8 ++-
examples/src/WebGL2Samples/sampler_filter.ts | 6 +-
examples/src/WebGL2Samples/sampler_object.ts | 6 +-
examples/src/WebGL2Samples/sampler_wrap.ts | 6 +-
.../src/WebGL2Samples/texture_2d_array.ts | 6 +-
examples/src/WebGL2Samples/texture_3d.ts | 6 +-
.../src/WebGL2Samples/texture_derivative.ts | 6 +-
examples/src/WebGL2Samples/texture_fetch.ts | 6 +-
examples/src/WebGL2Samples/texture_format.ts | 8 +--
examples/src/WebGL2Samples/texture_grad.ts | 6 +-
.../src/WebGL2Samples/texture_immutable.ts | 8 +--
examples/src/WebGL2Samples/texture_integer.ts | 6 +-
examples/src/WebGL2Samples/texture_lod.ts | 6 +-
examples/src/WebGL2Samples/texture_offset.ts | 8 +--
.../src/WebGL2Samples/texture_pixel_store.ts | 6 +-
examples/src/WebGL2Samples/texture_srgb.ts | 6 +-
examples/src/WebGL2Samples/texture_vertex.ts | 6 +-
.../transform_feedback_instanced.ts | 8 +--
.../transform_feedback_interleaved.ts | 8 +--
.../transform_feedback_separated.ts | 8 +--
.../transform_feedback_separated_2.ts | 6 +-
examples/src/regl-examples/batch.ts | 6 +-
examples/src/regl-examples/blur.ts | 6 +-
examples/src/webgl-examples/sample1.ts | 1 -
src/WebGL.ts | 5 +-
src/caches/getGLProgram.ts | 9 +--
src/data/IGLRenderObject.ts | 6 --
src/data/IGLRenderPipeline.ts | 65 ++++++++++---------
src/runs/runProgram.ts | 5 +-
src/runs/runRenderPipeline.ts | 6 +-
src/runs/runUniforms.ts | 4 +-
src/runs/runVertexArray.ts | 6 +-
51 files changed, 188 insertions(+), 188 deletions(-)
diff --git a/examples/package.json b/examples/package.json
index 2c00ce4..97ac916 100644
--- a/examples/package.json
+++ b/examples/package.json
@@ -13,7 +13,6 @@
},
"dependencies": {
"gl-matrix": "^3.4.3",
- "@feng3d/webgpu": "0.0.1",
"@feng3d/webgl": "0.0.2"
}
}
\ No newline at end of file
diff --git a/examples/src/WebGL2Samples/buffer_copy.ts b/examples/src/WebGL2Samples/buffer_copy.ts
index 03a2730..92ac7dd 100644
--- a/examples/src/WebGL2Samples/buffer_copy.ts
+++ b/examples/src/WebGL2Samples/buffer_copy.ts
@@ -1,5 +1,5 @@
-import { IRenderPass } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLCopyBufferToBuffer, IGLRenderPipeline, IGLVertexAttributes, IGLVertexBuffer, WebGL, getIGLBuffer } from "@feng3d/webgl";
+import { IRenderPass, IRenderPipeline } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLCopyBufferToBuffer, IGLVertexAttributes, IGLVertexBuffer, WebGL, getIGLBuffer } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -16,7 +16,7 @@ import { getShaderSource } from "./utility";
const webgl = new WebGL(rc);
// -- Init Program
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "TRIANGLES" },
};
diff --git a/examples/src/WebGL2Samples/buffer_uniform.ts b/examples/src/WebGL2Samples/buffer_uniform.ts
index 4a06e89..24c5069 100644
--- a/examples/src/WebGL2Samples/buffer_uniform.ts
+++ b/examples/src/WebGL2Samples/buffer_uniform.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLUniformBuffer, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLUniformBuffer, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -16,7 +16,7 @@ import { getShaderSource } from "./utility";
const webgl = new WebGL(rc);
// -- Init Program
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
};
diff --git a/examples/src/WebGL2Samples/draw_image_space.ts b/examples/src/WebGL2Samples/draw_image_space.ts
index fc7a01b..fb908c1 100644
--- a/examples/src/WebGL2Samples/draw_image_space.ts
+++ b/examples/src/WebGL2Samples/draw_image_space.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -23,7 +23,7 @@ loadImage("../../assets/img/Di-3d.png", (img) =>
magFilter: "LINEAR",
};
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
primitive: { topology: "TRIANGLES" },
vertex: {
code: getShaderSource("vs")
diff --git a/examples/src/WebGL2Samples/draw_instanced.ts b/examples/src/WebGL2Samples/draw_instanced.ts
index 2138744..383da62 100644
--- a/examples/src/WebGL2Samples/draw_instanced.ts
+++ b/examples/src/WebGL2Samples/draw_instanced.ts
@@ -1,5 +1,5 @@
-import { IRenderObject } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPipeline } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -18,7 +18,7 @@ const vertexColorBuffer = new Float32Array([
1.0, 0.5, 0.0,
0.0, 0.5, 1.0]);
-const program: IGLRenderPipeline = {
+const program: IRenderPipeline = {
primitive: { topology: "TRIANGLES" },
vertex: { code: getShaderSource("vs") },
fragment: { code: getShaderSource("fs"), targets: [{ blend: {} }] }
diff --git a/examples/src/WebGL2Samples/draw_instanced_ubo.ts b/examples/src/WebGL2Samples/draw_instanced_ubo.ts
index 07c5afa..47f8835 100644
--- a/examples/src/WebGL2Samples/draw_instanced_ubo.ts
+++ b/examples/src/WebGL2Samples/draw_instanced_ubo.ts
@@ -1,5 +1,5 @@
-import { IRenderPass } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLUniformBuffer, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPipeline } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLUniformBuffer, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -12,7 +12,7 @@ const rc: IGLCanvasContext = { canvasId: "glcanvas", contextId: "webgl2" };
const webgl = new WebGL(rc);
// -- Init program
-const program: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
+const program: IRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
// -- Init Buffer
const vertices = new Float32Array([
diff --git a/examples/src/WebGL2Samples/draw_primitive_restart.ts b/examples/src/WebGL2Samples/draw_primitive_restart.ts
index 2df43f3..6230349 100644
--- a/examples/src/WebGL2Samples/draw_primitive_restart.ts
+++ b/examples/src/WebGL2Samples/draw_primitive_restart.ts
@@ -1,5 +1,5 @@
-import { IRenderObject } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPipeline } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -22,7 +22,7 @@ const vertexPosBuffer = new Float32Array([
1.0, 1.0,
]);
-const program: IGLRenderPipeline = {
+const program: IRenderPipeline = {
primitive: { topology: "TRIANGLE_STRIP" },
vertex: {
code: getShaderSource("vs")
diff --git a/examples/src/WebGL2Samples/draw_range_arrays.ts b/examples/src/WebGL2Samples/draw_range_arrays.ts
index bb3c062..fcf8b45 100644
--- a/examples/src/WebGL2Samples/draw_range_arrays.ts
+++ b/examples/src/WebGL2Samples/draw_range_arrays.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -26,7 +26,7 @@ const vertexPosBuffer = new Float32Array([
-0.5, -0.5,
]);
-const pipeline: IGLRenderPipeline = {
+const pipeline: IRenderPipeline = {
primitive: { topology: "TRIANGLE_STRIP" },
vertex: {
code: getShaderSource("vs")
diff --git a/examples/src/WebGL2Samples/fbo_blit.ts b/examples/src/WebGL2Samples/fbo_blit.ts
index 8453881..4ec85cd 100644
--- a/examples/src/WebGL2Samples/fbo_blit.ts
+++ b/examples/src/WebGL2Samples/fbo_blit.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassDescriptor, ITexture, ITextureView } from "@feng3d/render-api";
-import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, ITextureView } from "@feng3d/render-api";
+import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -11,7 +11,7 @@ document.body.appendChild(canvas);
const renderingContext: IGLCanvasContext = { canvasId: "glcanvas" };
const webgl = new WebGL(renderingContext);
-const program: IGLRenderPipeline = {
+const program: IRenderPipeline = {
primitive: { topology: "TRIANGLES" },
vertex: {
code: getShaderSource("vs")
diff --git a/examples/src/WebGL2Samples/fbo_multisample.ts b/examples/src/WebGL2Samples/fbo_multisample.ts
index f220c5c..f2857fe 100644
--- a/examples/src/WebGL2Samples/fbo_multisample.ts
+++ b/examples/src/WebGL2Samples/fbo_multisample.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -19,7 +19,7 @@ const PROGRAM = {
MAX: 2
};
-const programs: IGLRenderPipeline[] = [
+const programs: IRenderPipeline[] = [
{
vertex: { code: getShaderSource("vs-render") },
fragment: { code: getShaderSource("fs-render") },
diff --git a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
index db9d2a3..bf3142b 100644
--- a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
+++ b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -59,7 +59,7 @@ viewport[Corners.TOP_LEFT] = {
// -- Initialize program
-const program: IGLRenderPipeline = {
+const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") },
fragment: { code: getShaderSource("fs"), targets: [{ blend: {} }] },
};
diff --git a/examples/src/WebGL2Samples/fbo_read_pixels.ts b/examples/src/WebGL2Samples/fbo_read_pixels.ts
index ab8a632..9243899 100644
--- a/examples/src/WebGL2Samples/fbo_read_pixels.ts
+++ b/examples/src/WebGL2Samples/fbo_read_pixels.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -51,13 +51,13 @@ viewport[Textures.BLUE] = {
// -- Initialize program
// Multiple out shaders
-const multipleOutputProgram: IGLRenderPipeline = {
+const multipleOutputProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-multiple-output") }, fragment: { code: getShaderSource("fs-multiple-output") },
primitive: { topology: "TRIANGLES" },
};
// Layer shaders
-const layerProgram: IGLRenderPipeline = {
+const layerProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-layer") }, fragment: { code: getShaderSource("fs-layer") },
primitive: { topology: "TRIANGLES" },
};
diff --git a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
index 1572cb6..7220bb2 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -19,14 +19,14 @@ const windowSize = {
// -- Initialize program
// Depth shaders
-const depthProgram: IGLRenderPipeline = {
+const depthProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-depth") }, fragment: { code: getShaderSource("fs-depth") },
depthStencil: { depth: { depthtest: true } },
primitive: { topology: "TRIANGLES" },
};
// Draw shaders
-const drawProgram: IGLRenderPipeline = {
+const drawProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-draw") }, fragment: { code: getShaderSource("fs-draw") },
primitive: { topology: "TRIANGLES" },
};
diff --git a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
index e6e423a..37b26bf 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassDescriptor, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -19,14 +19,14 @@ const windowSize = {
// -- Initialize program
// Draw buffer shaders
-const drawBufferProgram: IGLRenderPipeline = {
+const drawBufferProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-draw-buffer") },
fragment: { code: getShaderSource("fs-draw-buffer") },
primitive: { topology: "TRIANGLES" },
};
// Draw shaders
-const drawProgram: IGLRenderPipeline = {
+const drawProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-draw") },
fragment: { code: getShaderSource("fs-draw") },
primitive: { topology: "TRIANGLES" },
diff --git a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
index 55d60a6..daf32fe 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -51,13 +51,13 @@ viewport[Textures.BLUE] = {
// -- Initialize program
// Multiple out shaders
-const multipleOutputProgram: IGLRenderPipeline = {
+const multipleOutputProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-multiple-output") }, fragment: { code: getShaderSource("fs-multiple-output") },
primitive: { topology: "TRIANGLES" },
};
// Layer shaders
-const layerProgram: IGLRenderPipeline = {
+const layerProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-layer") }, fragment: { code: getShaderSource("fs-layer") },
primitive: { topology: "TRIANGLES" },
};
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index 8383fee..835bcaf 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { HalfFloat } from "./third-party/HalfFloatUtility";
import { getShaderSource, loadImage } from "./utility";
@@ -16,7 +16,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "TRIANGLES", cullFace: { enableCullFace: true, cullMode: "BACK" } },
depthStencil: { depth: { depthtest: true } },
diff --git a/examples/src/WebGL2Samples/glsl_centroid.ts b/examples/src/WebGL2Samples/glsl_centroid.ts
index fefdaed..95974fc 100644
--- a/examples/src/WebGL2Samples/glsl_centroid.ts
+++ b/examples/src/WebGL2Samples/glsl_centroid.ts
@@ -1,5 +1,5 @@
-import { IPassEncoder, IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IPassEncoder, IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -50,7 +50,7 @@ const PROGRAM = {
MAX: 3
};
-const programs: IGLRenderPipeline[] = [
+const programs: IRenderPipeline[] = [
{
vertex: { code: getShaderSource("vs-render") }, fragment: { code: getShaderSource("fs-render") },
primitive: { topology: "TRIANGLES" },
diff --git a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
index fea2026..243526a 100644
--- a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
+++ b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
import { getShaderSource } from "./utility";
@@ -44,7 +44,7 @@ viewport[VIEWPORTS.RIGHT] = {
};
// -- Initialize program
-const programs: IGLRenderPipeline[] = [
+const programs: IRenderPipeline[] = [
{
vertex: { code: getShaderSource("vs-flat") }, fragment: { code: getShaderSource("fs-flat") },
primitive: { topology: "TRIANGLES" },
diff --git a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
index 3a05929..c6d39fd 100644
--- a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
+++ b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -12,7 +12,7 @@ const rc: IGLCanvasContext = { canvasId: "glcanvas", contextId: "webgl2" };
const webgl = new WebGL(rc);
// -- Init program
-const program: IGLRenderPipeline = {
+const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "TRIANGLES" },
};
diff --git a/examples/src/WebGL2Samples/query_occlusion.ts b/examples/src/WebGL2Samples/query_occlusion.ts
index 5535dfb..88b91e7 100644
--- a/examples/src/WebGL2Samples/query_occlusion.ts
+++ b/examples/src/WebGL2Samples/query_occlusion.ts
@@ -1,6 +1,8 @@
-import { IRenderObject, IRenderPass, IRenderPassObject } from "@feng3d/render-api";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLOcclusionQuery, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+
import { watcher } from "@feng3d/watcher";
-import { IGLCanvasContext, IGLOcclusionQuery, IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+
import { getShaderSource } from "./utility";
// -- Init Canvas
@@ -15,7 +17,7 @@ const rc: IGLCanvasContext = { canvasId: "glcanvas", contextId: "webgl2" };
const webgl = new WebGL(rc);
// -- Init Program
-const program: IGLRenderPipeline = {
+const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
depthStencil: { depth: { depthtest: true } },
primitive: { topology: "TRIANGLES" },
diff --git a/examples/src/WebGL2Samples/sampler_filter.ts b/examples/src/WebGL2Samples/sampler_filter.ts
index 94fc1e8..069b1ed 100644
--- a/examples/src/WebGL2Samples/sampler_filter.ts
+++ b/examples/src/WebGL2Samples/sampler_filter.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -58,7 +58,7 @@ viewport[Corners.TOP_LEFT] = {
// -- Initialize program
-const program: IGLRenderPipeline = {
+const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "TRIANGLES" },
};
diff --git a/examples/src/WebGL2Samples/sampler_object.ts b/examples/src/WebGL2Samples/sampler_object.ts
index 05d6b75..c1a0ad0 100644
--- a/examples/src/WebGL2Samples/sampler_object.ts
+++ b/examples/src/WebGL2Samples/sampler_object.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -14,7 +14,7 @@ const webgl = new WebGL(rc);
// -- Initialize program
-const program: IGLRenderPipeline = {
+const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "TRIANGLES" },
};
diff --git a/examples/src/WebGL2Samples/sampler_wrap.ts b/examples/src/WebGL2Samples/sampler_wrap.ts
index 333b735..25329be 100644
--- a/examples/src/WebGL2Samples/sampler_wrap.ts
+++ b/examples/src/WebGL2Samples/sampler_wrap.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -58,7 +58,7 @@ viewport[Corners.TOP_LEFT] = {
// -- Initialize program
-const program: IGLRenderPipeline = {
+const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "TRIANGLES" },
};
diff --git a/examples/src/WebGL2Samples/texture_2d_array.ts b/examples/src/WebGL2Samples/texture_2d_array.ts
index d468ed4..9d743e5 100644
--- a/examples/src/WebGL2Samples/texture_2d_array.ts
+++ b/examples/src/WebGL2Samples/texture_2d_array.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -14,7 +14,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
};
diff --git a/examples/src/WebGL2Samples/texture_3d.ts b/examples/src/WebGL2Samples/texture_3d.ts
index 61f981b..f31a1b4 100644
--- a/examples/src/WebGL2Samples/texture_3d.ts
+++ b/examples/src/WebGL2Samples/texture_3d.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource } from "./utility";
@@ -94,7 +94,7 @@ import { getShaderSource } from "./utility";
};
// -- Initialize program
- const program: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
+ const program: IRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
// -- Initialize buffer
const positions = new Float32Array([
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index aff4306..983664c 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -16,7 +16,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: {
code: getShaderSource("fs"), targets: [{
diff --git a/examples/src/WebGL2Samples/texture_fetch.ts b/examples/src/WebGL2Samples/texture_fetch.ts
index aa2d3f3..b5ca6a5 100644
--- a/examples/src/WebGL2Samples/texture_fetch.ts
+++ b/examples/src/WebGL2Samples/texture_fetch.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -15,7 +15,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
+ const program: IRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
// -- Init buffers: vec2 Position, vec2 Texcoord
const positions = new Float32Array([
diff --git a/examples/src/WebGL2Samples/texture_format.ts b/examples/src/WebGL2Samples/texture_format.ts
index fcc8c9c..0610fd2 100644
--- a/examples/src/WebGL2Samples/texture_format.ts
+++ b/examples/src/WebGL2Samples/texture_format.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, ITexture, ITextureFormat } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, ITextureFormat } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -49,9 +49,9 @@ import { getShaderSource, loadImage } from "./utility";
}
// -- Init program
- const programUint: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-uint") } };
+ const programUint: IRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-uint") } };
- const programNormalized: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-normalized") } };
+ const programNormalized: IRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-normalized") } };
// -- Init buffers: vec2 Position, vec2 Texcoord
const positions = new Float32Array([
diff --git a/examples/src/WebGL2Samples/texture_grad.ts b/examples/src/WebGL2Samples/texture_grad.ts
index 50ea3dd..71270f7 100644
--- a/examples/src/WebGL2Samples/texture_grad.ts
+++ b/examples/src/WebGL2Samples/texture_grad.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -16,7 +16,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
depthStencil: { depth: { depthtest: true } },
primitive: { cullFace: { enableCullFace: true, cullMode: "BACK" } },
diff --git a/examples/src/WebGL2Samples/texture_immutable.ts b/examples/src/WebGL2Samples/texture_immutable.ts
index f5d7368..cc0d507 100644
--- a/examples/src/WebGL2Samples/texture_immutable.ts
+++ b/examples/src/WebGL2Samples/texture_immutable.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource, loadImage } from "./utility";
@@ -38,9 +38,9 @@ import { getShaderSource, loadImage } from "./utility";
};
// -- Init program
- const program: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
+ const program: IRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") } };
- const program3D: IGLRenderPipeline = { vertex: { code: getShaderSource("vs-3d") }, fragment: { code: getShaderSource("fs-3d") } };
+ const program3D: IRenderPipeline = { vertex: { code: getShaderSource("vs-3d") }, fragment: { code: getShaderSource("fs-3d") } };
// -- Init buffers: vec2 Position, vec2 Texcoord
const positions = new Float32Array([
diff --git a/examples/src/WebGL2Samples/texture_integer.ts b/examples/src/WebGL2Samples/texture_integer.ts
index 49a0246..421a7d0 100644
--- a/examples/src/WebGL2Samples/texture_integer.ts
+++ b/examples/src/WebGL2Samples/texture_integer.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -15,7 +15,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
};
diff --git a/examples/src/WebGL2Samples/texture_lod.ts b/examples/src/WebGL2Samples/texture_lod.ts
index 2341dad..bab9e7f 100644
--- a/examples/src/WebGL2Samples/texture_lod.ts
+++ b/examples/src/WebGL2Samples/texture_lod.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -87,7 +87,7 @@ import { getShaderSource, loadImage } from "./utility";
};
// -- Initialize program
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
};
diff --git a/examples/src/WebGL2Samples/texture_offset.ts b/examples/src/WebGL2Samples/texture_offset.ts
index 7017383..42a59cc 100644
--- a/examples/src/WebGL2Samples/texture_offset.ts
+++ b/examples/src/WebGL2Samples/texture_offset.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -36,9 +36,9 @@ import { getShaderSource, loadImage } from "./utility";
};
// -- Init program
- const programBicubic: IGLRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-bicubic") } };
+ const programBicubic: IRenderPipeline = { vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-bicubic") } };
- const programOffsetBicubic: IGLRenderPipeline = {
+ const programOffsetBicubic: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs-offset-bicubic") },
};
diff --git a/examples/src/WebGL2Samples/texture_pixel_store.ts b/examples/src/WebGL2Samples/texture_pixel_store.ts
index d76bbee..d82f49d 100644
--- a/examples/src/WebGL2Samples/texture_pixel_store.ts
+++ b/examples/src/WebGL2Samples/texture_pixel_store.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { getIGLBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -14,7 +14,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
};
diff --git a/examples/src/WebGL2Samples/texture_srgb.ts b/examples/src/WebGL2Samples/texture_srgb.ts
index 406bb0b..36c7af0 100644
--- a/examples/src/WebGL2Samples/texture_srgb.ts
+++ b/examples/src/WebGL2Samples/texture_srgb.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { getIGLBuffer, IGLCanvasContext, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -16,7 +16,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Initialize program
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
};
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index 30cdc2a..aae39c7 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
@@ -40,7 +40,7 @@ import { getShaderSource, loadImage } from "./utility";
const webgl = new WebGL(rc);
// -- Init program
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
depthStencil: { depth: { depthtest: true, depthCompare: "LESS" } },
};
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index 7afc477..047b3c2 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -130,7 +130,7 @@ import { getShaderSource } from "./utility";
function initPrograms()
{
- const programTransform: IGLRenderPipeline = {
+ const programTransform: IRenderPipeline = {
vertex: { code: getShaderSource("vs-emit") }, fragment: { code: getShaderSource("fs-emit") },
transformFeedbackVaryings: { varyings: ["v_offset", "v_rotation"], bufferMode: "SEPARATE_ATTRIBS" },
rasterizerDiscard: true,
@@ -138,7 +138,7 @@ import { getShaderSource } from "./utility";
};
// Setup program for draw shader
- const programDraw: IGLRenderPipeline = {
+ const programDraw: IRenderPipeline = {
vertex: { code: getShaderSource("vs-draw") }, fragment: {
code: getShaderSource("fs-draw"),
targets: [{
diff --git a/examples/src/WebGL2Samples/transform_feedback_interleaved.ts b/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
index 0527a2b..4e8cb77 100644
--- a/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
@@ -1,6 +1,6 @@
-import { getIGLVertexBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline } from "@feng3d/render-api";
+import { getIGLVertexBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
-import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
(function ()
{
@@ -21,7 +21,7 @@ import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
const programTransform = (function (vertexShaderSourceTransform, fragmentShaderSourceTransform)
{
- const programTransform: IGLRenderPipeline = {
+ const programTransform: IRenderPipeline = {
vertex: { code: vertexShaderSourceTransform },
fragment: { code: fragmentShaderSourceTransform },
transformFeedbackVaryings: { varyings: ["gl_Position", "v_color"], bufferMode: "INTERLEAVED_ATTRIBS" },
@@ -31,7 +31,7 @@ import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
return programTransform;
})(getShaderSource("vs-transform"), getShaderSource("fs-transform"));
- const programFeedback: IGLRenderPipeline = {
+ const programFeedback: IRenderPipeline = {
vertex: { code: getShaderSource("vs-feedback") }, fragment: { code: getShaderSource("fs-feedback") },
};
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated.ts b/examples/src/WebGL2Samples/transform_feedback_separated.ts
index b98dacc..8e6eb02 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
@@ -19,7 +19,7 @@ import { getShaderSource } from "./utility";
// -- Init Program
const programTransform = (function (vertexShaderSourceTransform, fragmentShaderSourceTransform)
{
- const programTransform: IGLRenderPipeline = {
+ const programTransform: IRenderPipeline = {
vertex: { code: vertexShaderSourceTransform },
fragment: { code: fragmentShaderSourceTransform },
transformFeedbackVaryings: { varyings: ["gl_Position", "v_color"], bufferMode: "SEPARATE_ATTRIBS" },
@@ -29,7 +29,7 @@ import { getShaderSource } from "./utility";
return programTransform;
})(getShaderSource("vs-transform"), getShaderSource("fs-transform"));
- const programFeedback: IGLRenderPipeline = {
+ const programFeedback: IRenderPipeline = {
vertex: { code: getShaderSource("vs-feedback") }, fragment: { code: getShaderSource("fs-feedback") },
};
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
index ecb078d..06b3f60 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLRenderPipeline, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
@@ -103,7 +103,7 @@ import { getShaderSource } from "./utility";
function initProgram()
{
- const program: IGLRenderPipeline = {
+ const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs-draw") },
fragment: {
code: getShaderSource("fs-draw"),
diff --git a/examples/src/regl-examples/batch.ts b/examples/src/regl-examples/batch.ts
index c0a6ebb..35fbb5d 100644
--- a/examples/src/regl-examples/batch.ts
+++ b/examples/src/regl-examples/batch.ts
@@ -1,5 +1,5 @@
-import { IRenderObject } from "@feng3d/render-api";
-import { IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPipeline } from "@feng3d/render-api";
+import { IGLVertexAttributes, WebGL } from "@feng3d/webgl";
const canvas = document.createElement("canvas");
canvas.id = "glcanvas";
@@ -21,7 +21,7 @@ const offsets = [{ offset: [-1, -1] },
{ offset: [1, 0] },
{ offset: [1, 1] }];
-const pipeline: IGLRenderPipeline = {
+const pipeline: IRenderPipeline = {
vertex: {
code: `precision mediump float;
attribute vec2 position;
diff --git a/examples/src/regl-examples/blur.ts b/examples/src/regl-examples/blur.ts
index e9047ae..40eb769 100644
--- a/examples/src/regl-examples/blur.ts
+++ b/examples/src/regl-examples/blur.ts
@@ -1,5 +1,5 @@
-import { IRenderObject } from "@feng3d/render-api";
-import { IGLRenderPipeline, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPipeline } from "@feng3d/render-api";
+import { IGLVertexAttributes, WebGL } from "@feng3d/webgl";
import { fit } from "./hughsk/canvas-fit";
import { attachCamera } from "./hughsk/canvas-orbit-camera";
@@ -43,7 +43,7 @@ const vertexArray: { vertices?: IGLVertexAttributes } = {
}
};
-const pipeline: IGLRenderPipeline = {
+const pipeline: IRenderPipeline = {
vertex: {
code: `precision mediump float;
attribute vec2 position;
diff --git a/examples/src/webgl-examples/sample1.ts b/examples/src/webgl-examples/sample1.ts
index 310f00d..e42a861 100644
--- a/examples/src/webgl-examples/sample1.ts
+++ b/examples/src/webgl-examples/sample1.ts
@@ -9,7 +9,6 @@ async function main()
const renderingContext: IGLCanvasContext = { canvasId: "glcanvas", contextId: "webgl" };
const webgl = new WebGL(renderingContext);
- // const webgl = await new WebGPU().init();
const submit: ISubmit = {
commandEncoders: [{
diff --git a/src/WebGL.ts b/src/WebGL.ts
index c5202c4..976b93f 100644
--- a/src/WebGL.ts
+++ b/src/WebGL.ts
@@ -1,4 +1,4 @@
-import { IRenderPassDescriptor, ISubmit, ITexture } from "@feng3d/render-api";
+import { IRenderPassDescriptor, IRenderPipeline, ISubmit, ITexture } from "@feng3d/render-api";
import { RunWebGL } from "./RunWebGL";
import { deleteFramebuffer } from "./caches/getFramebuffer";
@@ -12,7 +12,6 @@ import { deleteTransformFeedback } from "./caches/getGLTransformFeedback";
import { IGLBuffer } from "./data/IGLBuffer";
import { IGLCanvasContext } from "./data/IGLCanvasContext";
import { IGLReadPixels } from "./data/IGLReadPixels";
-import { IGLRenderPipeline } from "./data/IGLRenderPipeline";
import { IGLRenderbuffer } from "./data/IGLRenderbuffer";
import { IGLSampler } from "./data/IGLSampler";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
@@ -76,7 +75,7 @@ export class WebGL
deleteSampler(this._gl, sampler);
}
- deleteProgram(pipeline: IGLRenderPipeline)
+ deleteProgram(pipeline: IRenderPipeline)
{
deleteProgram(this._gl, pipeline);
}
diff --git a/src/caches/getGLProgram.ts b/src/caches/getGLProgram.ts
index dce79da..bbcc2ce 100644
--- a/src/caches/getGLProgram.ts
+++ b/src/caches/getGLProgram.ts
@@ -1,6 +1,7 @@
+import { IRenderPipeline } from "@feng3d/render-api";
import { getWebGLUniformType, isWebGLUniformTextureType } from "../const/IGLUniformType";
import { IGLAttributeInfo } from "../data/IGLAttributeInfo";
-import { IGLRenderPipeline, ITransformFeedbackVaryings } from "../data/IGLRenderPipeline";
+import { ITransformFeedbackVaryings } from "../data/IGLRenderPipeline";
import { IGLUniformInfo, IUniformItemInfo } from "../data/IGLUniformInfo";
import { getIGLAttributeType } from "./getIGLAttributeType";
@@ -37,7 +38,7 @@ declare global
/**
* 激活渲染程序
*/
-export function getGLProgram(gl: WebGLRenderingContext, pipeline: IGLRenderPipeline)
+export function getGLProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeline)
{
const shaderKey = getKey(pipeline);
let result = gl._programs[shaderKey];
@@ -53,7 +54,7 @@ export function getGLProgram(gl: WebGLRenderingContext, pipeline: IGLRenderPipel
return result;
}
-export function deleteProgram(gl: WebGLRenderingContext, pipeline: IGLRenderPipeline)
+export function deleteProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeline)
{
const shaderKey = getKey(pipeline);
const result = gl._programs[shaderKey];
@@ -64,7 +65,7 @@ export function deleteProgram(gl: WebGLRenderingContext, pipeline: IGLRenderPipe
}
}
-function getKey(pipeline: IGLRenderPipeline)
+function getKey(pipeline: IRenderPipeline)
{
const vertex = pipeline.vertex.code;
const fragment = pipeline.fragment.code;
diff --git a/src/data/IGLRenderObject.ts b/src/data/IGLRenderObject.ts
index 36888ba..4d6f528 100644
--- a/src/data/IGLRenderObject.ts
+++ b/src/data/IGLRenderObject.ts
@@ -3,7 +3,6 @@ import { LazyObject } from "../types";
import { IGLDrawIndexed } from "./IGLDrawIndexed";
import { IGLDrawVertex } from "./IGLDrawVertex";
import { IGLIndicesDataTypes } from "./IGLIndexBuffer";
-import { IGLRenderPipeline } from "./IGLRenderPipeline";
import { IGLTransformFeedback } from "./IGLTransformFeedback";
import { IGLUniforms } from "./IGLUniforms";
import { IGLVertexAttributes } from "./IGLVertexAttributes";
@@ -15,11 +14,6 @@ declare module "@feng3d/render-api"
*/
export interface IRenderObject
{
- /**
- * 渲染程序
- */
- pipeline: IGLRenderPipeline;
-
/**
* 顶点属性数据列表
*/
diff --git a/src/data/IGLRenderPipeline.ts b/src/data/IGLRenderPipeline.ts
index e80daa8..a000333 100644
--- a/src/data/IGLRenderPipeline.ts
+++ b/src/data/IGLRenderPipeline.ts
@@ -1,45 +1,50 @@
+import { IRenderPipeline } from "@feng3d/render-api";
import { IGLColorTargetState } from "./IGLColorTargetState";
import { IGLDepthStencilState } from "./IGLDepthStencilState";
import { IGLPrimitiveState } from "./IGLPrimitiveState";
-/**
- * 渲染管线。
- */
-export interface IGLRenderPipeline
+declare module "@feng3d/render-api"
{
/**
- * 顶点着色器代码
+ * 渲染管线。
*/
- vertex: IVertexState;
+ export interface IRenderPipeline
+ {
+ /**
+ * 顶点着色器代码
+ */
+ vertex: IVertexState;
- /**
- * 片段着色器代码
- */
- fragment: IFragmentState;
+ /**
+ * 片段着色器代码
+ */
+ fragment: IFragmentState;
- /**
- * 图元拓扑结构。
- */
- primitive?: IGLPrimitiveState;
+ /**
+ * 图元拓扑结构。
+ */
+ primitive?: IGLPrimitiveState;
- /**
- * 描述可选的深度模板的测试、运算以及偏差。
- */
- depthStencil?: IGLDepthStencilState;
+ /**
+ * 描述可选的深度模板的测试、运算以及偏差。
+ */
+ depthStencil?: IGLDepthStencilState;
- /**
- * 回写变量。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/transformFeedbackVaryings
- */
- transformFeedbackVaryings?: ITransformFeedbackVaryings;
+ /**
+ * 回写变量。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/transformFeedbackVaryings
+ */
+ transformFeedbackVaryings?: ITransformFeedbackVaryings;
+
+ /**
+ * 是否丢弃后续光栅化阶段。
+ *
+ * gl.RASTERIZER_DISCARD
+ */
+ rasterizerDiscard?: boolean;
+ }
- /**
- * 是否丢弃后续光栅化阶段。
- *
- * gl.RASTERIZER_DISCARD
- */
- rasterizerDiscard?: boolean;
}
export interface ITransformFeedbackVaryings
diff --git a/src/runs/runProgram.ts b/src/runs/runProgram.ts
index 2604401..f47c1fb 100644
--- a/src/runs/runProgram.ts
+++ b/src/runs/runProgram.ts
@@ -1,8 +1,9 @@
+import { IRenderPipeline } from "@feng3d/render-api";
import { getGLProgram } from "../caches/getGLProgram";
-import { IFragmentState, IGLRenderPipeline, IVertexState } from "../data/IGLRenderPipeline";
+import { IFragmentState, IVertexState } from "../data/IGLRenderPipeline";
import { defaultColorTargetStates, runColorTargetStates } from "./runColorTargetStates";
-export function runProgram(gl: WebGLRenderingContext, pipeline: IGLRenderPipeline)
+export function runProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeline)
{
const program = getGLProgram(gl, pipeline);
gl.useProgram(program);
diff --git a/src/runs/runRenderPipeline.ts b/src/runs/runRenderPipeline.ts
index 0d09f77..99d6405 100644
--- a/src/runs/runRenderPipeline.ts
+++ b/src/runs/runRenderPipeline.ts
@@ -1,9 +1,9 @@
-import { IGLRenderPipeline } from "../data/IGLRenderPipeline";
+import { IRenderPipeline } from "@feng3d/render-api";
import { defaultDepthStencilState, runDepthStencilState } from "./runDepthStencilState";
import { defaultPrimitiveState, runPrimitiveState } from "./runPrimitiveState";
import { defaultFragmentState, defaultVertexState, runProgram } from "./runProgram";
-export function runRenderPipeline(gl: WebGLRenderingContext, renderPipeline: IGLRenderPipeline)
+export function runRenderPipeline(gl: WebGLRenderingContext, renderPipeline: IRenderPipeline)
{
runProgram(gl, renderPipeline);
@@ -12,7 +12,7 @@ export function runRenderPipeline(gl: WebGLRenderingContext, renderPipeline: IGL
runDepthStencilState(gl, renderPipeline.depthStencil);
}
-export const defaultRenderPipeline: IGLRenderPipeline = Object.freeze({
+export const defaultRenderPipeline: IRenderPipeline = Object.freeze({
vertex: defaultVertexState, fragment: defaultFragmentState, primitive: defaultPrimitiveState,
depthStencil: defaultDepthStencilState
});
\ No newline at end of file
diff --git a/src/runs/runUniforms.ts b/src/runs/runUniforms.ts
index 46b93d5..ac1182e 100644
--- a/src/runs/runUniforms.ts
+++ b/src/runs/runUniforms.ts
@@ -1,8 +1,8 @@
+import { IRenderPipeline } from "@feng3d/render-api";
import { getGLBuffer } from "../caches/getGLBuffer";
import { getGLProgram } from "../caches/getGLProgram";
import { IGLUniformBufferType } from "../const/IGLUniformType";
import { IGLBuffer } from "../data/IGLBuffer";
-import { IGLRenderPipeline } from "../data/IGLRenderPipeline";
import { IGLSamplerTexture } from "../data/IGLSamplerTexture";
import { IUniformItemInfo } from "../data/IGLUniformInfo";
import { IGLUniforms } from "../data/IGLUniforms";
@@ -12,7 +12,7 @@ import { runSamplerTexture } from "./runTexture";
/**
* 激活常量
*/
-export function runUniforms(gl: WebGLRenderingContext, pipeline: IGLRenderPipeline, uniforms: LazyObject)
+export function runUniforms(gl: WebGLRenderingContext, pipeline: IRenderPipeline, uniforms: LazyObject)
{
const webGLProgram = getGLProgram(gl, pipeline);
diff --git a/src/runs/runVertexArray.ts b/src/runs/runVertexArray.ts
index d676538..0b42745 100644
--- a/src/runs/runVertexArray.ts
+++ b/src/runs/runVertexArray.ts
@@ -1,6 +1,6 @@
+import { IRenderPipeline } from "@feng3d/render-api";
import { getGLProgram } from "../caches/getGLProgram";
import { IGLIndicesDataTypes } from "../data/IGLIndexBuffer";
-import { IGLRenderPipeline } from "../data/IGLRenderPipeline";
import { IGLVertexAttributes } from "../data/IGLVertexAttributes";
import { ChainMap } from "../utils/ChainMap";
import { runIndexBuffer } from "./runIndexBuffer";
@@ -10,14 +10,14 @@ declare global
{
interface WebGLRenderingContext
{
- _vertexArrays: ChainMap<[IGLRenderPipeline, IGLVertexAttributes, IGLIndicesDataTypes], WebGLVertexArrayObject>;
+ _vertexArrays: ChainMap<[IRenderPipeline, IGLVertexAttributes, IGLIndicesDataTypes], WebGLVertexArrayObject>;
}
}
/**
* 执行设置或者上传渲染对象的顶点以及索引数据。
*/
-export function runVertexArray(gl: WebGLRenderingContext, pipeline: IGLRenderPipeline, vertices: IGLVertexAttributes, indices: IGLIndicesDataTypes)
+export function runVertexArray(gl: WebGLRenderingContext, pipeline: IRenderPipeline, vertices: IGLVertexAttributes, indices: IGLIndicesDataTypes)
{
if (!vertices && !indices) return;
--
Gitee
From 0c15ae9308bdbf31281afc6e1cc75d04de49943e Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 00:40:35 +0800
Subject: [PATCH 097/186] IGLPrimitiveState -> IPrimitiveState
---
src/data/IGLPrimitiveState.ts | 48 +++++++++++++++++++----------------
src/data/IGLRenderPipeline.ts | 6 -----
src/runs/runPrimitiveState.ts | 4 +--
3 files changed, 28 insertions(+), 30 deletions(-)
diff --git a/src/data/IGLPrimitiveState.ts b/src/data/IGLPrimitiveState.ts
index c909e7d..10bc559 100644
--- a/src/data/IGLPrimitiveState.ts
+++ b/src/data/IGLPrimitiveState.ts
@@ -1,29 +1,33 @@
+import { IPrimitiveState } from "@feng3d/render-api";
import { IGLCullFace } from "./IGLCullFace";
-export interface IGLPrimitiveState
+declare module "@feng3d/render-api"
{
- /**
- * 图形拓扑结构。
- *
- * 默认 TRIANGLES,每三个顶点绘制一个三角形。
- *
- * * POINTS 绘制单个点。
- * * LINE_LOOP 绘制循环连线。
- * * LINE_STRIP 绘制连线
- * * LINES 每两个顶点绘制一条线段。
- * * TRIANGLES 每三个顶点绘制一个三角形。
- * * TRIANGLE_STRIP 绘制三角形条带。
- * * TRIANGLE_FAN 绘制三角扇形。
- *
- * A GLenum specifying the type primitive to render. Possible values are:
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawVertex
- */
- topology?: IGLDrawMode;
+ export interface IPrimitiveState
+ {
+ /**
+ * 图形拓扑结构。
+ *
+ * 默认 TRIANGLES,每三个顶点绘制一个三角形。
+ *
+ * * POINTS 绘制单个点。
+ * * LINE_LOOP 绘制循环连线。
+ * * LINE_STRIP 绘制连线
+ * * LINES 每两个顶点绘制一条线段。
+ * * TRIANGLES 每三个顶点绘制一个三角形。
+ * * TRIANGLE_STRIP 绘制三角形条带。
+ * * TRIANGLE_FAN 绘制三角扇形。
+ *
+ * A GLenum specifying the type primitive to render. Possible values are:
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawVertex
+ */
+ topology?: IGLDrawMode;
- /**
- *
- */
- cullFace?: IGLCullFace;
+ /**
+ *
+ */
+ cullFace?: IGLCullFace;
+ }
}
/**
diff --git a/src/data/IGLRenderPipeline.ts b/src/data/IGLRenderPipeline.ts
index a000333..d639cfe 100644
--- a/src/data/IGLRenderPipeline.ts
+++ b/src/data/IGLRenderPipeline.ts
@@ -1,7 +1,6 @@
import { IRenderPipeline } from "@feng3d/render-api";
import { IGLColorTargetState } from "./IGLColorTargetState";
import { IGLDepthStencilState } from "./IGLDepthStencilState";
-import { IGLPrimitiveState } from "./IGLPrimitiveState";
declare module "@feng3d/render-api"
{
@@ -20,11 +19,6 @@ declare module "@feng3d/render-api"
*/
fragment: IFragmentState;
- /**
- * 图元拓扑结构。
- */
- primitive?: IGLPrimitiveState;
-
/**
* 描述可选的深度模板的测试、运算以及偏差。
*/
diff --git a/src/runs/runPrimitiveState.ts b/src/runs/runPrimitiveState.ts
index 43de634..4343f49 100644
--- a/src/runs/runPrimitiveState.ts
+++ b/src/runs/runPrimitiveState.ts
@@ -1,5 +1,5 @@
+import { IPrimitiveState } from "@feng3d/render-api";
import { IGLCullFace } from "../data/IGLCullFace";
-import { IGLPrimitiveState } from "../data/IGLPrimitiveState";
export function runPrimitiveState(gl: WebGLRenderingContext, cullFace?: IGLCullFace)
{
@@ -18,7 +18,7 @@ export function runPrimitiveState(gl: WebGLRenderingContext, cullFace?: IGLCullF
}
const defaultCullFace: IGLCullFace = { enableCullFace: false, cullMode: "BACK", frontFace: "CCW" };
-export const defaultPrimitiveState: IGLPrimitiveState = { topology: "TRIANGLES", cullFace: defaultCullFace };
+export const defaultPrimitiveState: IPrimitiveState = { topology: "TRIANGLES", cullFace: defaultCullFace };
Object.freeze(defaultCullFace);
Object.freeze(defaultPrimitiveState);
\ No newline at end of file
--
Gitee
From 1bbfaed74dc5f07f4b97114032dbb5c329169e4d Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 01:58:48 +0800
Subject: [PATCH 098/186] IPrimitiveState.topology
---
examples/src/WebGL2Samples/buffer_copy.ts | 2 +-
.../src/WebGL2Samples/draw_image_space.ts | 2 +-
examples/src/WebGL2Samples/draw_instanced.ts | 2 +-
.../WebGL2Samples/draw_primitive_restart.ts | 2 +-
.../src/WebGL2Samples/draw_range_arrays.ts | 2 +-
examples/src/WebGL2Samples/fbo_blit.ts | 2 +-
examples/src/WebGL2Samples/fbo_multisample.ts | 2 +-
examples/src/WebGL2Samples/fbo_read_pixels.ts | 4 +--
.../WebGL2Samples/fbo_rtt_depth_texture.ts | 4 +--
.../src/WebGL2Samples/fbo_rtt_draw_buffers.ts | 4 +--
.../WebGL2Samples/fbo_rtt_texture_array.ts | 4 +--
.../src/WebGL2Samples/geo_vertex_format.ts | 2 +-
examples/src/WebGL2Samples/glsl_centroid.ts | 6 ++--
.../glsl_flat_smooth_interpolators.ts | 4 +--
.../WebGL2Samples/glsl_non_square_matrix.ts | 2 +-
examples/src/WebGL2Samples/query_occlusion.ts | 2 +-
examples/src/WebGL2Samples/sampler_filter.ts | 2 +-
examples/src/WebGL2Samples/sampler_object.ts | 2 +-
examples/src/WebGL2Samples/sampler_wrap.ts | 2 +-
.../src/WebGL2Samples/texture_derivative.ts | 2 +-
examples/src/WebGL2Samples/texture_vertex.ts | 14 +++++-----
.../transform_feedback_instanced.ts | 4 +--
.../transform_feedback_separated_2.ts | 2 +-
examples/src/webgl-examples/sample2.ts | 2 +-
examples/src/webgl-examples/sample3.ts | 2 +-
examples/src/webgl-examples/sample4.ts | 2 +-
examples/src/webgl-examples/sample5.ts | 2 +-
examples/src/webgl-examples/sample6.ts | 2 +-
examples/src/webgl-examples/sample7.ts | 2 +-
examples/src/webgl-examples/sample8.ts | 2 +-
src/caches/getIGLDrawMode.ts | 23 +++++++++++++++
src/data/IGLPrimitiveState.ts | 28 +++++++++++--------
src/runs/runDrawCall.ts | 16 +++++------
src/runs/runPrimitiveState.ts | 2 +-
src/runs/runRenderObject.ts | 6 ++--
35 files changed, 95 insertions(+), 68 deletions(-)
create mode 100644 src/caches/getIGLDrawMode.ts
diff --git a/examples/src/WebGL2Samples/buffer_copy.ts b/examples/src/WebGL2Samples/buffer_copy.ts
index 92ac7dd..cdce4ae 100644
--- a/examples/src/WebGL2Samples/buffer_copy.ts
+++ b/examples/src/WebGL2Samples/buffer_copy.ts
@@ -18,7 +18,7 @@ import { getShaderSource } from "./utility";
// -- Init Program
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// -- Init Buffer
diff --git a/examples/src/WebGL2Samples/draw_image_space.ts b/examples/src/WebGL2Samples/draw_image_space.ts
index fb908c1..732bc3b 100644
--- a/examples/src/WebGL2Samples/draw_image_space.ts
+++ b/examples/src/WebGL2Samples/draw_image_space.ts
@@ -24,7 +24,7 @@ loadImage("../../assets/img/Di-3d.png", (img) =>
};
const program: IRenderPipeline = {
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
vertex: {
code: getShaderSource("vs")
},
diff --git a/examples/src/WebGL2Samples/draw_instanced.ts b/examples/src/WebGL2Samples/draw_instanced.ts
index 383da62..abb1355 100644
--- a/examples/src/WebGL2Samples/draw_instanced.ts
+++ b/examples/src/WebGL2Samples/draw_instanced.ts
@@ -19,7 +19,7 @@ const vertexColorBuffer = new Float32Array([
0.0, 0.5, 1.0]);
const program: IRenderPipeline = {
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
vertex: { code: getShaderSource("vs") },
fragment: { code: getShaderSource("fs"), targets: [{ blend: {} }] }
};
diff --git a/examples/src/WebGL2Samples/draw_primitive_restart.ts b/examples/src/WebGL2Samples/draw_primitive_restart.ts
index 6230349..b1a9b42 100644
--- a/examples/src/WebGL2Samples/draw_primitive_restart.ts
+++ b/examples/src/WebGL2Samples/draw_primitive_restart.ts
@@ -23,7 +23,7 @@ const vertexPosBuffer = new Float32Array([
]);
const program: IRenderPipeline = {
- primitive: { topology: "TRIANGLE_STRIP" },
+ primitive: { topology: "triangle-strip" },
vertex: {
code: getShaderSource("vs")
},
diff --git a/examples/src/WebGL2Samples/draw_range_arrays.ts b/examples/src/WebGL2Samples/draw_range_arrays.ts
index fcf8b45..c75b1a3 100644
--- a/examples/src/WebGL2Samples/draw_range_arrays.ts
+++ b/examples/src/WebGL2Samples/draw_range_arrays.ts
@@ -27,7 +27,7 @@ const vertexPosBuffer = new Float32Array([
]);
const pipeline: IRenderPipeline = {
- primitive: { topology: "TRIANGLE_STRIP" },
+ primitive: { topology: "triangle-strip" },
vertex: {
code: getShaderSource("vs")
},
diff --git a/examples/src/WebGL2Samples/fbo_blit.ts b/examples/src/WebGL2Samples/fbo_blit.ts
index 4ec85cd..e535925 100644
--- a/examples/src/WebGL2Samples/fbo_blit.ts
+++ b/examples/src/WebGL2Samples/fbo_blit.ts
@@ -12,7 +12,7 @@ const renderingContext: IGLCanvasContext = { canvasId: "glcanvas" };
const webgl = new WebGL(renderingContext);
const program: IRenderPipeline = {
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
vertex: {
code: getShaderSource("vs")
},
diff --git a/examples/src/WebGL2Samples/fbo_multisample.ts b/examples/src/WebGL2Samples/fbo_multisample.ts
index f2857fe..c600b62 100644
--- a/examples/src/WebGL2Samples/fbo_multisample.ts
+++ b/examples/src/WebGL2Samples/fbo_multisample.ts
@@ -28,7 +28,7 @@ const programs: IRenderPipeline[] = [
{
vertex: { code: getShaderSource("vs-splash") },
fragment: { code: getShaderSource("fs-splash") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
},
];
diff --git a/examples/src/WebGL2Samples/fbo_read_pixels.ts b/examples/src/WebGL2Samples/fbo_read_pixels.ts
index 9243899..2288325 100644
--- a/examples/src/WebGL2Samples/fbo_read_pixels.ts
+++ b/examples/src/WebGL2Samples/fbo_read_pixels.ts
@@ -53,13 +53,13 @@ viewport[Textures.BLUE] = {
// Multiple out shaders
const multipleOutputProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-multiple-output") }, fragment: { code: getShaderSource("fs-multiple-output") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// Layer shaders
const layerProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-layer") }, fragment: { code: getShaderSource("fs-layer") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// -- Initialize buffer
diff --git a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
index 7220bb2..ff5e2a2 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
@@ -22,13 +22,13 @@ const windowSize = {
const depthProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-depth") }, fragment: { code: getShaderSource("fs-depth") },
depthStencil: { depth: { depthtest: true } },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// Draw shaders
const drawProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-draw") }, fragment: { code: getShaderSource("fs-draw") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// -- Initialize buffer
diff --git a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
index 37b26bf..3885f1d 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
@@ -22,14 +22,14 @@ const windowSize = {
const drawBufferProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-draw-buffer") },
fragment: { code: getShaderSource("fs-draw-buffer") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// Draw shaders
const drawProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-draw") },
fragment: { code: getShaderSource("fs-draw") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// -- Initialize buffer
diff --git a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
index daf32fe..f0575b0 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
@@ -53,13 +53,13 @@ viewport[Textures.BLUE] = {
// Multiple out shaders
const multipleOutputProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-multiple-output") }, fragment: { code: getShaderSource("fs-multiple-output") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// Layer shaders
const layerProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-layer") }, fragment: { code: getShaderSource("fs-layer") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// -- Initialize buffer
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index 835bcaf..665bfbc 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -18,7 +18,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init program
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
- primitive: { topology: "TRIANGLES", cullFace: { enableCullFace: true, cullMode: "BACK" } },
+ primitive: { topology: "triangle-list", cullFace: { enableCullFace: true, cullMode: "BACK" } },
depthStencil: { depth: { depthtest: true } },
};
diff --git a/examples/src/WebGL2Samples/glsl_centroid.ts b/examples/src/WebGL2Samples/glsl_centroid.ts
index 95974fc..0a0f9e5 100644
--- a/examples/src/WebGL2Samples/glsl_centroid.ts
+++ b/examples/src/WebGL2Samples/glsl_centroid.ts
@@ -53,15 +53,15 @@ const PROGRAM = {
const programs: IRenderPipeline[] = [
{
vertex: { code: getShaderSource("vs-render") }, fragment: { code: getShaderSource("fs-render") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
},
{
vertex: { code: getShaderSource("vs-render-centroid") }, fragment: { code: getShaderSource("fs-render-centroid") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
},
{
vertex: { code: getShaderSource("vs-splash") }, fragment: { code: getShaderSource("fs-splash") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
}
];
diff --git a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
index 243526a..d491b69 100644
--- a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
+++ b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
@@ -47,12 +47,12 @@ viewport[VIEWPORTS.RIGHT] = {
const programs: IRenderPipeline[] = [
{
vertex: { code: getShaderSource("vs-flat") }, fragment: { code: getShaderSource("fs-flat") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
depthStencil: { depth: { depthtest: true, depthCompare: "LEQUAL" } },
},
{
vertex: { code: getShaderSource("vs-smooth") }, fragment: { code: getShaderSource("fs-smooth") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
depthStencil: { depth: { depthtest: true, depthCompare: "LEQUAL" } },
}
];
diff --git a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
index c6d39fd..bc4f5be 100644
--- a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
+++ b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
@@ -14,7 +14,7 @@ const webgl = new WebGL(rc);
// -- Init program
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology:"triangle-list" },
};
// -- Init buffers: vec2 Position, vec2 Texcoord
diff --git a/examples/src/WebGL2Samples/query_occlusion.ts b/examples/src/WebGL2Samples/query_occlusion.ts
index 88b91e7..8cb9efa 100644
--- a/examples/src/WebGL2Samples/query_occlusion.ts
+++ b/examples/src/WebGL2Samples/query_occlusion.ts
@@ -20,7 +20,7 @@ const webgl = new WebGL(rc);
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
depthStencil: { depth: { depthtest: true } },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// -- Init Buffer
diff --git a/examples/src/WebGL2Samples/sampler_filter.ts b/examples/src/WebGL2Samples/sampler_filter.ts
index 069b1ed..da36507 100644
--- a/examples/src/WebGL2Samples/sampler_filter.ts
+++ b/examples/src/WebGL2Samples/sampler_filter.ts
@@ -60,7 +60,7 @@ viewport[Corners.TOP_LEFT] = {
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// -- Initialize buffer
diff --git a/examples/src/WebGL2Samples/sampler_object.ts b/examples/src/WebGL2Samples/sampler_object.ts
index c1a0ad0..244058a 100644
--- a/examples/src/WebGL2Samples/sampler_object.ts
+++ b/examples/src/WebGL2Samples/sampler_object.ts
@@ -16,7 +16,7 @@ const webgl = new WebGL(rc);
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// -- Initialize buffer
diff --git a/examples/src/WebGL2Samples/sampler_wrap.ts b/examples/src/WebGL2Samples/sampler_wrap.ts
index 25329be..d76e819 100644
--- a/examples/src/WebGL2Samples/sampler_wrap.ts
+++ b/examples/src/WebGL2Samples/sampler_wrap.ts
@@ -60,7 +60,7 @@ viewport[Corners.TOP_LEFT] = {
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
// -- Initialize buffer
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index 983664c..f7ae044 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -23,7 +23,7 @@ import { getShaderSource, loadImage } from "./utility";
}]
},
depthStencil: { depth: { depthtest: true } },
- primitive: { topology: "TRIANGLES", cullFace: { enableCullFace: true, cullMode: "BACK" } }
+ primitive: { topology: "triangle-list", cullFace: { enableCullFace: true, cullMode: "BACK" } }
};
// -- Init buffers
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index aae39c7..4a9eb3f 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -1,4 +1,4 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
+import { IPrimitiveTopology, IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
import { IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
@@ -7,14 +7,14 @@ import { getShaderSource, loadImage } from "./utility";
(function ()
{
- const IDrawMode2Name = {
- 0: "POINTS",
- 3: "LINE_STRIP",
+ const IDrawMode2Name: { [key: string]: IPrimitiveTopology } = {
+ 0: "point-list",
+ 3: "line-strip",
2: "LINE_LOOP",
- 1: "LINES",
- 5: "TRIANGLE_STRIP",
+ 1: "line-list",
+ 5: "triangle-strip",
6: "TRIANGLE_FAN",
- 4: "TRIANGLES",
+ 4: "triangle-list",
};
const VertexAttributeType2Name = {
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index 047b3c2..e745a77 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -134,7 +134,7 @@ import { getShaderSource } from "./utility";
vertex: { code: getShaderSource("vs-emit") }, fragment: { code: getShaderSource("fs-emit") },
transformFeedbackVaryings: { varyings: ["v_offset", "v_rotation"], bufferMode: "SEPARATE_ATTRIBS" },
rasterizerDiscard: true,
- primitive: { topology: "POINTS" },
+ primitive: { topology: "point-list" },
};
// Setup program for draw shader
@@ -148,7 +148,7 @@ import { getShaderSource } from "./utility";
}
}]
},
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
};
const programs = [programTransform, programDraw];
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
index 06b3f60..fc683d3 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
@@ -115,7 +115,7 @@ import { getShaderSource } from "./utility";
}]
},
transformFeedbackVaryings: { varyings: ["v_position", "v_velocity", "v_spawntime", "v_lifetime"], bufferMode: "SEPARATE_ATTRIBS" },
- primitive: { topology: "POINTS" },
+ primitive: { topology: "point-list" },
};
return program;
diff --git a/examples/src/webgl-examples/sample2.ts b/examples/src/webgl-examples/sample2.ts
index 3012754..2d9310d 100644
--- a/examples/src/webgl-examples/sample2.ts
+++ b/examples/src/webgl-examples/sample2.ts
@@ -25,7 +25,7 @@ function main()
},
renderObjects: [{
pipeline: {
- primitive: { topology: "TRIANGLE_STRIP" },
+ primitive: { topology: "triangle-strip" },
vertex: {
code: `
attribute vec4 aVertexPosition;
diff --git a/examples/src/webgl-examples/sample3.ts b/examples/src/webgl-examples/sample3.ts
index 70d7177..14ce55c 100644
--- a/examples/src/webgl-examples/sample3.ts
+++ b/examples/src/webgl-examples/sample3.ts
@@ -29,7 +29,7 @@ function main()
},
renderObjects: [{
pipeline: {
- primitive: { topology: "TRIANGLE_STRIP" },
+ primitive: { topology: "triangle-strip" },
vertex: {
code: `
attribute vec4 aVertexPosition;
diff --git a/examples/src/webgl-examples/sample4.ts b/examples/src/webgl-examples/sample4.ts
index 5de3e9c..465ddd4 100644
--- a/examples/src/webgl-examples/sample4.ts
+++ b/examples/src/webgl-examples/sample4.ts
@@ -17,7 +17,7 @@ function main()
const renderObject: IRenderObject = {
pipeline: {
- primitive: { topology: "TRIANGLE_STRIP" },
+ primitive: { topology: "triangle-strip" },
vertex: {
code: `
attribute vec4 aVertexPosition;
diff --git a/examples/src/webgl-examples/sample5.ts b/examples/src/webgl-examples/sample5.ts
index 7d336b2..771a418 100644
--- a/examples/src/webgl-examples/sample5.ts
+++ b/examples/src/webgl-examples/sample5.ts
@@ -21,7 +21,7 @@ function main()
const renderObject: IRenderObject = {
pipeline: {
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
vertex: {
code: `
attribute vec4 aVertexPosition;
diff --git a/examples/src/webgl-examples/sample6.ts b/examples/src/webgl-examples/sample6.ts
index 7611140..f2bfb3a 100644
--- a/examples/src/webgl-examples/sample6.ts
+++ b/examples/src/webgl-examples/sample6.ts
@@ -23,7 +23,7 @@ async function main()
const renderObject: IRenderObject = {
pipeline: {
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
vertex: {
code: `
attribute vec4 aVertexPosition;
diff --git a/examples/src/webgl-examples/sample7.ts b/examples/src/webgl-examples/sample7.ts
index df31557..75f921a 100644
--- a/examples/src/webgl-examples/sample7.ts
+++ b/examples/src/webgl-examples/sample7.ts
@@ -23,7 +23,7 @@ async function main()
const renderObject: IRenderObject = {
pipeline: {
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
vertex: {
code: `
attribute vec4 aVertexPosition;
diff --git a/examples/src/webgl-examples/sample8.ts b/examples/src/webgl-examples/sample8.ts
index deb9f14..db7ab9f 100644
--- a/examples/src/webgl-examples/sample8.ts
+++ b/examples/src/webgl-examples/sample8.ts
@@ -27,7 +27,7 @@ function main()
const renderObject: IRenderObject = {
pipeline: {
- primitive: { topology: "TRIANGLES" },
+ primitive: { topology: "triangle-list" },
vertex: {
code: `
attribute vec4 aVertexPosition;
diff --git a/src/caches/getIGLDrawMode.ts b/src/caches/getIGLDrawMode.ts
new file mode 100644
index 0000000..b92d265
--- /dev/null
+++ b/src/caches/getIGLDrawMode.ts
@@ -0,0 +1,23 @@
+import { IPrimitiveTopology } from "@feng3d/render-api";
+import { IGLDrawMode } from "../data/IGLPrimitiveState";
+
+export function getIGLDrawMode(topology: IPrimitiveTopology): IGLDrawMode
+{
+ let drawMode = drawModeMap[topology];
+
+ console.assert(!!drawMode, `WebGL 不支持参数 IPrimitiveTopology ${topology} !`);
+
+ drawMode = drawMode || topology as any;
+
+ return drawMode;
+}
+
+const drawModeMap: { [key: string]: IGLDrawMode } = {
+ "point-list": "POINTS",
+ "line-list": "LINES",
+ "line-strip": "LINE_STRIP",
+ "triangle-list": "TRIANGLES",
+ "triangle-strip": "TRIANGLE_STRIP",
+ "LINE_LOOP": "LINE_LOOP",
+ "TRIANGLE_FAN": "TRIANGLE_FAN",
+};
\ No newline at end of file
diff --git a/src/data/IGLPrimitiveState.ts b/src/data/IGLPrimitiveState.ts
index 10bc559..a62fc62 100644
--- a/src/data/IGLPrimitiveState.ts
+++ b/src/data/IGLPrimitiveState.ts
@@ -1,27 +1,31 @@
-import { IPrimitiveState } from "@feng3d/render-api";
+import { IPrimitiveTopology } from "@feng3d/render-api";
import { IGLCullFace } from "./IGLCullFace";
declare module "@feng3d/render-api"
{
+ export interface IPrimitiveTopologyMap
+ {
+ /**
+ * 绘制循环连线。
+ */
+ "LINE_LOOP": "LINE_LOOP",
+
+ /**
+ * 绘制三角扇形。
+ */
+ "TRIANGLE_FAN": "TRIANGLE_FAN",
+ }
+
export interface IPrimitiveState
{
/**
* 图形拓扑结构。
*
- * 默认 TRIANGLES,每三个顶点绘制一个三角形。
- *
- * * POINTS 绘制单个点。
+ * 以下仅在WebGL生效
* * LINE_LOOP 绘制循环连线。
- * * LINE_STRIP 绘制连线
- * * LINES 每两个顶点绘制一条线段。
- * * TRIANGLES 每三个顶点绘制一个三角形。
- * * TRIANGLE_STRIP 绘制三角形条带。
* * TRIANGLE_FAN 绘制三角扇形。
- *
- * A GLenum specifying the type primitive to render. Possible values are:
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawVertex
*/
- topology?: IGLDrawMode;
+ readonly topology?: IPrimitiveTopology;
/**
*
diff --git a/src/runs/runDrawCall.ts b/src/runs/runDrawCall.ts
index 9316365..3a0f5e1 100644
--- a/src/runs/runDrawCall.ts
+++ b/src/runs/runDrawCall.ts
@@ -1,4 +1,5 @@
import { IRenderObject } from "@feng3d/render-api";
+
import { getBufferType } from "../caches/getGLBuffer";
import { ElementTypeMap } from "../const/IGLUniformType";
import { IGLDrawIndexed } from "../data/IGLDrawIndexed";
@@ -6,29 +7,26 @@ import { IGLDrawVertex } from "../data/IGLDrawVertex";
import { IGLIndicesDataTypes } from "../data/IGLIndexBuffer";
import { IGLDrawMode } from "../data/IGLPrimitiveState";
import { IGLVertexAttributes } from "../data/IGLVertexAttributes";
-import { defaultPrimitiveState } from "./runPrimitiveState";
-export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObject)
+export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObject, drawMode: IGLDrawMode)
{
- const { pipeline, vertices, indices, drawIndexed, drawVertex } = renderObject;
-
- const topology = pipeline.primitive?.topology || defaultPrimitiveState.topology;
+ const { vertices, indices, drawIndexed, drawVertex } = renderObject;
if (drawVertex)
{
- _runDrawVertex(gl, topology, vertices, drawVertex);
+ _runDrawVertex(gl, drawMode, vertices, drawVertex);
}
else if (drawIndexed)
{
- _runDrawIndexed(gl, topology, indices, drawIndexed);
+ _runDrawIndexed(gl, drawMode, indices, drawIndexed);
}
else if (indices)
{
- _runDrawIndexed(gl, topology, indices, drawIndexed);
+ _runDrawIndexed(gl, drawMode, indices, drawIndexed);
}
else
{
- _runDrawVertex(gl, topology, vertices, drawVertex);
+ _runDrawVertex(gl, drawMode, vertices, drawVertex);
}
}
diff --git a/src/runs/runPrimitiveState.ts b/src/runs/runPrimitiveState.ts
index 4343f49..0ff7ac5 100644
--- a/src/runs/runPrimitiveState.ts
+++ b/src/runs/runPrimitiveState.ts
@@ -18,7 +18,7 @@ export function runPrimitiveState(gl: WebGLRenderingContext, cullFace?: IGLCullF
}
const defaultCullFace: IGLCullFace = { enableCullFace: false, cullMode: "BACK", frontFace: "CCW" };
-export const defaultPrimitiveState: IPrimitiveState = { topology: "TRIANGLES", cullFace: defaultCullFace };
+export const defaultPrimitiveState: IPrimitiveState = { topology: "triangle-list", cullFace: defaultCullFace };
Object.freeze(defaultCullFace);
Object.freeze(defaultPrimitiveState);
\ No newline at end of file
diff --git a/src/runs/runRenderObject.ts b/src/runs/runRenderObject.ts
index 0647fdb..12a4328 100644
--- a/src/runs/runRenderObject.ts
+++ b/src/runs/runRenderObject.ts
@@ -5,22 +5,24 @@ import { runRenderPipeline } from "./runRenderPipeline";
import { endTransformFeedback, runTransformFeedback } from "./runTransformFeedback";
import { runUniforms } from "./runUniforms";
import { runVertexArray } from "./runVertexArray";
+import { getIGLDrawMode } from "../caches/getIGLDrawMode";
export function runRenderObject(gl: WebGLRenderingContext, renderObject: IRenderObject)
{
const { pipeline, vertices, indices, uniforms, transformFeedback } = renderObject;
const topology = pipeline.primitive?.topology || defaultPrimitiveState.topology;
+ const drawMode = getIGLDrawMode(topology);
runRenderPipeline(gl, pipeline);
- runTransformFeedback(gl, transformFeedback, topology);
+ runTransformFeedback(gl, transformFeedback, drawMode);
runVertexArray(gl, pipeline, vertices, indices);
runUniforms(gl, pipeline, uniforms);
- runDrawCall(gl, renderObject);
+ runDrawCall(gl, renderObject, drawMode);
endTransformFeedback(gl, transformFeedback);
}
--
Gitee
From f972ff5f4f8aec98da94ab5825f0bef920ab20be Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 03:34:28 +0800
Subject: [PATCH 099/186] IPrimitiveState.cullFace IPrimitiveState.frontFace
---
.../src/WebGL2Samples/geo_vertex_format.ts | 2 +-
.../src/WebGL2Samples/texture_derivative.ts | 2 +-
examples/src/WebGL2Samples/texture_grad.ts | 2 +-
src/data/IGLCullFace.ts | 45 ++++------------
src/data/IGLPrimitiveState.ts | 12 +++--
src/runs/runPrimitiveState.ts | 52 ++++++++++++++-----
src/runs/runRenderObject.ts | 5 +-
src/runs/runRenderPipeline.ts | 13 ++---
8 files changed, 67 insertions(+), 66 deletions(-)
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index 665bfbc..15fc61e 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -18,7 +18,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init program
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
- primitive: { topology: "triangle-list", cullFace: { enableCullFace: true, cullMode: "BACK" } },
+ primitive: { topology: "triangle-list", cullFace: "back" },
depthStencil: { depth: { depthtest: true } },
};
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index f7ae044..7f3409f 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -23,7 +23,7 @@ import { getShaderSource, loadImage } from "./utility";
}]
},
depthStencil: { depth: { depthtest: true } },
- primitive: { topology: "triangle-list", cullFace: { enableCullFace: true, cullMode: "BACK" } }
+ primitive: { topology: "triangle-list", cullFace: "back" }
};
// -- Init buffers
diff --git a/examples/src/WebGL2Samples/texture_grad.ts b/examples/src/WebGL2Samples/texture_grad.ts
index 71270f7..e5808b3 100644
--- a/examples/src/WebGL2Samples/texture_grad.ts
+++ b/examples/src/WebGL2Samples/texture_grad.ts
@@ -19,7 +19,7 @@ import { getShaderSource, loadImage } from "./utility";
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
depthStencil: { depth: { depthtest: true } },
- primitive: { cullFace: { enableCullFace: true, cullMode: "BACK" } },
+ primitive: { cullFace: "back" },
};
// -- Init buffers
diff --git a/src/data/IGLCullFace.ts b/src/data/IGLCullFace.ts
index 4ffee6e..17c90e3 100644
--- a/src/data/IGLCullFace.ts
+++ b/src/data/IGLCullFace.ts
@@ -1,38 +1,11 @@
-/**
- * 面剔除。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/cullFace
- */
-export interface IGLCullFace
-{
- /**
- * 是否开启面剔除。
- *
- * 默认为 false。
- */
- enableCullFace?: boolean;
-
- /**
- * 剔除面,默认 BACK,剔除背面。
- *
- * 默认情况下,逆时针的顶点连接顺序被定义为三角形的正面。
- * 使用gl.frontFace(gl.CW);调整顺时针为正面
- *
- * * NONE 关闭裁剪面
- * * FRONT 正面
- * * BACK 背面
- * * FRONT_AND_BACK 正面与背面
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/cullFace
- */
- cullMode?: GLCullFace;
+import { ICullFace } from "@feng3d/render-api";
- /**
- * 正向方向,默认 CCW。三角形逆时针方向为正面。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/frontFace
- */
- frontFace?: GLFrontFace;
+declare module "@feng3d/render-api"
+{
+ export interface ICullFaceMap
+ {
+ "FRONT_AND_BACK": "FRONT_AND_BACK";
+ }
}
/**
@@ -43,7 +16,7 @@ export interface IGLCullFace
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/frontFace
*/
-export type GLFrontFace = "CW" | "CCW";
+export type IGLFrontFace = "CW" | "CCW";
/**
* 剔除面,默认 BACK,剔除背面。
@@ -58,4 +31,4 @@ export type GLFrontFace = "CW" | "CCW";
* @see http://www.jianshu.com/p/ee04165f2a02
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/cullFace
*/
-export type GLCullFace = "FRONT" | "BACK" | "FRONT_AND_BACK";
\ No newline at end of file
+export type IGLCullFace = "FRONT" | "BACK" | "FRONT_AND_BACK";
\ No newline at end of file
diff --git a/src/data/IGLPrimitiveState.ts b/src/data/IGLPrimitiveState.ts
index a62fc62..379044c 100644
--- a/src/data/IGLPrimitiveState.ts
+++ b/src/data/IGLPrimitiveState.ts
@@ -1,5 +1,4 @@
-import { IPrimitiveTopology } from "@feng3d/render-api";
-import { IGLCullFace } from "./IGLCullFace";
+import { ICullFace, IFrontFace, IPrimitiveTopology } from "@feng3d/render-api";
declare module "@feng3d/render-api"
{
@@ -28,9 +27,16 @@ declare module "@feng3d/render-api"
readonly topology?: IPrimitiveTopology;
/**
+ * * `FRONT_AND_BACK` 剔除正面与背面,仅在WebGL中生效!
*
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/cullFace
*/
- cullFace?: IGLCullFace;
+ readonly cullFace?: ICullFace;
+
+ /**
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/frontFace
+ */
+ readonly frontFace?: IFrontFace;
}
}
diff --git a/src/runs/runPrimitiveState.ts b/src/runs/runPrimitiveState.ts
index 0ff7ac5..f458900 100644
--- a/src/runs/runPrimitiveState.ts
+++ b/src/runs/runPrimitiveState.ts
@@ -1,15 +1,20 @@
-import { IPrimitiveState } from "@feng3d/render-api";
-import { IGLCullFace } from "../data/IGLCullFace";
+import { ICullFace, IFrontFace, IPrimitiveState } from "@feng3d/render-api";
+import { IGLCullFace, IGLFrontFace } from "../data/IGLCullFace";
-export function runPrimitiveState(gl: WebGLRenderingContext, cullFace?: IGLCullFace)
+export function runPrimitiveState(gl: WebGLRenderingContext, primitive?: IPrimitiveState)
{
- //
- const { enableCullFace: enableCullMode, cullMode, frontFace } = { ...defaultCullFace, ...cullFace };
- if (enableCullMode)
+ const cullFace: ICullFace = primitive?.cullFace || "none";
+ const frontFace: IFrontFace = primitive?.frontFace || "ccw";
+
+ const enableCullFace = cullFace !== "none";
+ const glCullMode: IGLCullFace = getIGLCullFace(cullFace);
+ const glFrontFace: IGLFrontFace = getIGLFrontFace(frontFace);
+
+ if (enableCullFace)
{
gl.enable(gl.CULL_FACE);
- gl.cullFace(gl[cullMode]);
- gl.frontFace(gl[frontFace]);
+ gl.cullFace(gl[glCullMode]);
+ gl.frontFace(gl[glFrontFace]);
}
else
{
@@ -17,8 +22,31 @@ export function runPrimitiveState(gl: WebGLRenderingContext, cullFace?: IGLCullF
}
}
-const defaultCullFace: IGLCullFace = { enableCullFace: false, cullMode: "BACK", frontFace: "CCW" };
-export const defaultPrimitiveState: IPrimitiveState = { topology: "triangle-list", cullFace: defaultCullFace };
+function getIGLCullFace(cullFace: ICullFace)
+{
+ const glCullMode: IGLCullFace = cullFaceMap[cullFace];
+
+ console.assert(!!glCullMode, `接收到错误值,请从 ${Object.keys(cullFaceMap).toString()} 中取值!`);
+
+ return glCullMode;
+}
-Object.freeze(defaultCullFace);
-Object.freeze(defaultPrimitiveState);
\ No newline at end of file
+const cullFaceMap: { [key: string]: IGLCullFace } = {
+ "FRONT_AND_BACK": "FRONT_AND_BACK",
+ "none": "BACK", // 不会开启剔除面功能,什么值无所谓。
+ "front": "FRONT",
+ "back": "BACK",
+};
+
+function getIGLFrontFace(frontFace: IFrontFace)
+{
+ const glFrontFace: IGLFrontFace = frontFaceMap[frontFace];
+
+ console.assert(!!glFrontFace, `接收到错误 IFrontFace 值,请从 ${Object.keys(cullFaceMap).toString()} 中取值!`);
+
+ return glFrontFace;
+}
+const frontFaceMap: { [key: string]: IGLFrontFace } = {
+ "ccw": "CCW",
+ "cw": "CW",
+};
\ No newline at end of file
diff --git a/src/runs/runRenderObject.ts b/src/runs/runRenderObject.ts
index 12a4328..60ca557 100644
--- a/src/runs/runRenderObject.ts
+++ b/src/runs/runRenderObject.ts
@@ -1,17 +1,16 @@
import { IRenderObject } from "@feng3d/render-api";
+import { getIGLDrawMode } from "../caches/getIGLDrawMode";
import { runDrawCall } from "./runDrawCall";
-import { defaultPrimitiveState } from "./runPrimitiveState";
import { runRenderPipeline } from "./runRenderPipeline";
import { endTransformFeedback, runTransformFeedback } from "./runTransformFeedback";
import { runUniforms } from "./runUniforms";
import { runVertexArray } from "./runVertexArray";
-import { getIGLDrawMode } from "../caches/getIGLDrawMode";
export function runRenderObject(gl: WebGLRenderingContext, renderObject: IRenderObject)
{
const { pipeline, vertices, indices, uniforms, transformFeedback } = renderObject;
- const topology = pipeline.primitive?.topology || defaultPrimitiveState.topology;
+ const topology = pipeline.primitive?.topology || "triangle-list";
const drawMode = getIGLDrawMode(topology);
runRenderPipeline(gl, pipeline);
diff --git a/src/runs/runRenderPipeline.ts b/src/runs/runRenderPipeline.ts
index 99d6405..58cd1b7 100644
--- a/src/runs/runRenderPipeline.ts
+++ b/src/runs/runRenderPipeline.ts
@@ -1,18 +1,13 @@
import { IRenderPipeline } from "@feng3d/render-api";
-import { defaultDepthStencilState, runDepthStencilState } from "./runDepthStencilState";
-import { defaultPrimitiveState, runPrimitiveState } from "./runPrimitiveState";
-import { defaultFragmentState, defaultVertexState, runProgram } from "./runProgram";
+import { runDepthStencilState } from "./runDepthStencilState";
+import { runPrimitiveState } from "./runPrimitiveState";
+import { runProgram } from "./runProgram";
export function runRenderPipeline(gl: WebGLRenderingContext, renderPipeline: IRenderPipeline)
{
runProgram(gl, renderPipeline);
- runPrimitiveState(gl, renderPipeline?.primitive?.cullFace);
+ runPrimitiveState(gl, renderPipeline?.primitive);
runDepthStencilState(gl, renderPipeline.depthStencil);
}
-
-export const defaultRenderPipeline: IRenderPipeline = Object.freeze({
- vertex: defaultVertexState, fragment: defaultFragmentState, primitive: defaultPrimitiveState,
- depthStencil: defaultDepthStencilState
-});
\ No newline at end of file
--
Gitee
From 1d7acfc6e9c83df56a7c45b448ed8e910cda9240 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 03:43:32 +0800
Subject: [PATCH 100/186] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/caches/getIGLDrawMode.ts | 28 ++++++++++++++--
src/data/IGLPrimitiveState.ts | 30 +++--------------
src/index.ts | 1 -
src/runs/runDrawCall.ts | 2 +-
src/runs/runPrimitiveState.ts | 32 ++-----------------
src/runs/runTransformFeedback.ts | 2 +-
.../getIGLCullFace.ts} | 26 +++++++--------
src/utils/getIGLFrontFace.ts | 24 ++++++++++++++
8 files changed, 71 insertions(+), 74 deletions(-)
rename src/{data/IGLCullFace.ts => utils/getIGLCullFace.ts} (52%)
create mode 100644 src/utils/getIGLFrontFace.ts
diff --git a/src/caches/getIGLDrawMode.ts b/src/caches/getIGLDrawMode.ts
index b92d265..529e35b 100644
--- a/src/caches/getIGLDrawMode.ts
+++ b/src/caches/getIGLDrawMode.ts
@@ -1,5 +1,4 @@
import { IPrimitiveTopology } from "@feng3d/render-api";
-import { IGLDrawMode } from "../data/IGLPrimitiveState";
export function getIGLDrawMode(topology: IPrimitiveTopology): IGLDrawMode
{
@@ -20,4 +19,29 @@ const drawModeMap: { [key: string]: IGLDrawMode } = {
"triangle-strip": "TRIANGLE_STRIP",
"LINE_LOOP": "LINE_LOOP",
"TRIANGLE_FAN": "TRIANGLE_FAN",
-};
\ No newline at end of file
+};
+
+/**
+ * 渲染模式,默认 TRIANGLES,每三个顶点绘制一个三角形。
+ *
+ * * POINTS 绘制单个点。
+ * * LINE_LOOP 绘制循环连线。
+ * * LINE_STRIP 绘制连线
+ * * LINES 每两个顶点绘制一条线段。
+ * * TRIANGLES 每三个顶点绘制一个三角形。
+ * * TRIANGLE_STRIP 绘制三角形条带。
+ * * TRIANGLE_FAN 绘制三角扇形。
+ *
+ * A GLenum specifying the type primitive to render. Possible values are:
+ *
+ * * gl.POINTS: Draws a single dot.
+ * * gl.LINE_STRIP: Draws a straight line to the next vertex.
+ * * gl.LINE_LOOP: Draws a straight line to the next vertex, and connects the last vertex back to the first.
+ * * gl.LINES: Draws a line between a pair of vertices.
+ * * gl.TRIANGLE_STRIP
+ * * gl.TRIANGLE_FAN
+ * * gl.TRIANGLES: Draws a triangle for a group of three vertices.
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements
+ */
+export type IGLDrawMode = "POINTS" | "LINE_STRIP" | "LINE_LOOP" | "LINES" | "TRIANGLE_STRIP" | "TRIANGLE_FAN" | "TRIANGLES";
diff --git a/src/data/IGLPrimitiveState.ts b/src/data/IGLPrimitiveState.ts
index 379044c..e1e876e 100644
--- a/src/data/IGLPrimitiveState.ts
+++ b/src/data/IGLPrimitiveState.ts
@@ -15,6 +15,11 @@ declare module "@feng3d/render-api"
"TRIANGLE_FAN": "TRIANGLE_FAN",
}
+ export interface ICullFaceMap
+ {
+ "FRONT_AND_BACK": "FRONT_AND_BACK";
+ }
+
export interface IPrimitiveState
{
/**
@@ -39,28 +44,3 @@ declare module "@feng3d/render-api"
readonly frontFace?: IFrontFace;
}
}
-
-/**
- * 渲染模式,默认 TRIANGLES,每三个顶点绘制一个三角形。
- *
- * * POINTS 绘制单个点。
- * * LINE_LOOP 绘制循环连线。
- * * LINE_STRIP 绘制连线
- * * LINES 每两个顶点绘制一条线段。
- * * TRIANGLES 每三个顶点绘制一个三角形。
- * * TRIANGLE_STRIP 绘制三角形条带。
- * * TRIANGLE_FAN 绘制三角扇形。
- *
- * A GLenum specifying the type primitive to render. Possible values are:
- *
- * * gl.POINTS: Draws a single dot.
- * * gl.LINE_STRIP: Draws a straight line to the next vertex.
- * * gl.LINE_LOOP: Draws a straight line to the next vertex, and connects the last vertex back to the first.
- * * gl.LINES: Draws a line between a pair of vertices.
- * * gl.TRIANGLE_STRIP
- * * gl.TRIANGLE_FAN
- * * gl.TRIANGLES: Draws a triangle for a group of three vertices.
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements
- */
-export type IGLDrawMode = "POINTS" | "LINE_STRIP" | "LINE_LOOP" | "LINES" | "TRIANGLE_STRIP" | "TRIANGLE_FAN" | "TRIANGLES";
diff --git a/src/index.ts b/src/index.ts
index 89124c1..2e9077f 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -6,7 +6,6 @@ export * from "./data/IGLCapabilities";
export * from "./data/IGLColorTargetState";
export * from "./data/IGLCommandEncoder";
export * from "./data/IGLCopyBufferToBuffer";
-export * from "./data/IGLCullFace";
export * from "./data/IGLDepthStencilState";
export * from "./data/IGLDrawIndexed";
export * from "./data/IGLDrawVertex";
diff --git a/src/runs/runDrawCall.ts b/src/runs/runDrawCall.ts
index 3a0f5e1..65938d7 100644
--- a/src/runs/runDrawCall.ts
+++ b/src/runs/runDrawCall.ts
@@ -1,11 +1,11 @@
import { IRenderObject } from "@feng3d/render-api";
import { getBufferType } from "../caches/getGLBuffer";
+import { IGLDrawMode } from "../caches/getIGLDrawMode";
import { ElementTypeMap } from "../const/IGLUniformType";
import { IGLDrawIndexed } from "../data/IGLDrawIndexed";
import { IGLDrawVertex } from "../data/IGLDrawVertex";
import { IGLIndicesDataTypes } from "../data/IGLIndexBuffer";
-import { IGLDrawMode } from "../data/IGLPrimitiveState";
import { IGLVertexAttributes } from "../data/IGLVertexAttributes";
export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObject, drawMode: IGLDrawMode)
diff --git a/src/runs/runPrimitiveState.ts b/src/runs/runPrimitiveState.ts
index f458900..58fb9de 100644
--- a/src/runs/runPrimitiveState.ts
+++ b/src/runs/runPrimitiveState.ts
@@ -1,5 +1,6 @@
import { ICullFace, IFrontFace, IPrimitiveState } from "@feng3d/render-api";
-import { IGLCullFace, IGLFrontFace } from "../data/IGLCullFace";
+import { getIGLCullFace, IGLCullFace } from "../utils/getIGLCullFace";
+import { getIGLFrontFace, IGLFrontFace } from "../utils/getIGLFrontFace";
export function runPrimitiveState(gl: WebGLRenderingContext, primitive?: IPrimitiveState)
{
@@ -21,32 +22,3 @@ export function runPrimitiveState(gl: WebGLRenderingContext, primitive?: IPrimit
gl.disable(gl.CULL_FACE);
}
}
-
-function getIGLCullFace(cullFace: ICullFace)
-{
- const glCullMode: IGLCullFace = cullFaceMap[cullFace];
-
- console.assert(!!glCullMode, `接收到错误值,请从 ${Object.keys(cullFaceMap).toString()} 中取值!`);
-
- return glCullMode;
-}
-
-const cullFaceMap: { [key: string]: IGLCullFace } = {
- "FRONT_AND_BACK": "FRONT_AND_BACK",
- "none": "BACK", // 不会开启剔除面功能,什么值无所谓。
- "front": "FRONT",
- "back": "BACK",
-};
-
-function getIGLFrontFace(frontFace: IFrontFace)
-{
- const glFrontFace: IGLFrontFace = frontFaceMap[frontFace];
-
- console.assert(!!glFrontFace, `接收到错误 IFrontFace 值,请从 ${Object.keys(cullFaceMap).toString()} 中取值!`);
-
- return glFrontFace;
-}
-const frontFaceMap: { [key: string]: IGLFrontFace } = {
- "ccw": "CCW",
- "cw": "CW",
-};
\ No newline at end of file
diff --git a/src/runs/runTransformFeedback.ts b/src/runs/runTransformFeedback.ts
index 21d5955..214704f 100644
--- a/src/runs/runTransformFeedback.ts
+++ b/src/runs/runTransformFeedback.ts
@@ -1,5 +1,5 @@
import { getGLTransformFeedback } from "../caches/getGLTransformFeedback";
-import { IGLDrawMode } from "../data/IGLPrimitiveState";
+import { IGLDrawMode } from "../caches/getIGLDrawMode";
import { IGLTransformFeedback } from "../data/IGLTransformFeedback";
export function runTransformFeedback(gl: WebGLRenderingContext, transformFeedback: IGLTransformFeedback, topology: IGLDrawMode)
diff --git a/src/data/IGLCullFace.ts b/src/utils/getIGLCullFace.ts
similarity index 52%
rename from src/data/IGLCullFace.ts
rename to src/utils/getIGLCullFace.ts
index 17c90e3..eaff698 100644
--- a/src/data/IGLCullFace.ts
+++ b/src/utils/getIGLCullFace.ts
@@ -1,22 +1,20 @@
import { ICullFace } from "@feng3d/render-api";
-declare module "@feng3d/render-api"
+export function getIGLCullFace(cullFace: ICullFace)
{
- export interface ICullFaceMap
- {
- "FRONT_AND_BACK": "FRONT_AND_BACK";
- }
+ const glCullMode: IGLCullFace = cullFaceMap[cullFace];
+
+ console.assert(!!glCullMode, `接收到错误值,请从 ${Object.keys(cullFaceMap).toString()} 中取值!`);
+
+ return glCullMode;
}
-/**
- * 正面方向枚举
- *
- * * CW 顺时钟方向
- * * CCW 逆时钟方向
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/frontFace
- */
-export type IGLFrontFace = "CW" | "CCW";
+const cullFaceMap: { [key: string]: IGLCullFace } = {
+ "FRONT_AND_BACK": "FRONT_AND_BACK",
+ "none": "BACK", // 不会开启剔除面功能,什么值无所谓。
+ "front": "FRONT",
+ "back": "BACK",
+};
/**
* 剔除面,默认 BACK,剔除背面。
diff --git a/src/utils/getIGLFrontFace.ts b/src/utils/getIGLFrontFace.ts
new file mode 100644
index 0000000..144f380
--- /dev/null
+++ b/src/utils/getIGLFrontFace.ts
@@ -0,0 +1,24 @@
+import { IFrontFace } from "@feng3d/render-api";
+
+export function getIGLFrontFace(frontFace: IFrontFace)
+{
+ const glFrontFace: IGLFrontFace = frontFaceMap[frontFace];
+
+ console.assert(!!glFrontFace, `接收到错误 IFrontFace 值,请从 ${Object.keys(frontFaceMap).toString()} 中取值!`);
+
+ return glFrontFace;
+}
+const frontFaceMap: { [key: string]: IGLFrontFace } = {
+ "ccw": "CCW",
+ "cw": "CW",
+};
+
+/**
+ * 正面方向枚举
+ *
+ * * CW 顺时钟方向
+ * * CCW 逆时钟方向
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/frontFace
+ */
+export type IGLFrontFace = "CW" | "CCW";
--
Gitee
From 6ffac79c14759882d66c192a95dbfc0013545f87 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 12:46:44 +0800
Subject: [PATCH 101/186] IRenderPipeline.vertex
---
src/data/IGLRenderPipeline.ts | 13 -------------
src/runs/runProgram.ts | 3 +--
2 files changed, 1 insertion(+), 15 deletions(-)
diff --git a/src/data/IGLRenderPipeline.ts b/src/data/IGLRenderPipeline.ts
index d639cfe..a22d6d8 100644
--- a/src/data/IGLRenderPipeline.ts
+++ b/src/data/IGLRenderPipeline.ts
@@ -9,11 +9,6 @@ declare module "@feng3d/render-api"
*/
export interface IRenderPipeline
{
- /**
- * 顶点着色器代码
- */
- vertex: IVertexState;
-
/**
* 片段着色器代码
*/
@@ -54,14 +49,6 @@ export interface ITransformFeedbackVaryings
bufferMode: "INTERLEAVED_ATTRIBS" | "SEPARATE_ATTRIBS";
}
-/**
- * 顶点程序阶段。
- */
-export interface IVertexState
-{
- code: string;
-}
-
/**
* GPU片元程序阶段。
*/
diff --git a/src/runs/runProgram.ts b/src/runs/runProgram.ts
index f47c1fb..1e559f2 100644
--- a/src/runs/runProgram.ts
+++ b/src/runs/runProgram.ts
@@ -1,6 +1,6 @@
import { IRenderPipeline } from "@feng3d/render-api";
import { getGLProgram } from "../caches/getGLProgram";
-import { IFragmentState, IVertexState } from "../data/IGLRenderPipeline";
+import { IFragmentState } from "../data/IGLRenderPipeline";
import { defaultColorTargetStates, runColorTargetStates } from "./runColorTargetStates";
export function runProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeline)
@@ -25,5 +25,4 @@ export function runProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeline)
runColorTargetStates(gl, pipeline.fragment.targets);
}
-export const defaultVertexState: IVertexState = Object.freeze({ code: "" });
export const defaultFragmentState: IFragmentState = Object.freeze({ code: "", targets: defaultColorTargetStates });
\ No newline at end of file
--
Gitee
From 294f2b1289b3bbc4dcbd4bda24e4c5fc9ddb317c Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 13:16:14 +0800
Subject: [PATCH 102/186] IFragmentState
---
src/data/IGLRenderPipeline.ts | 28 +++++++---------------------
src/runs/runProgram.ts | 5 +----
2 files changed, 8 insertions(+), 25 deletions(-)
diff --git a/src/data/IGLRenderPipeline.ts b/src/data/IGLRenderPipeline.ts
index a22d6d8..1145609 100644
--- a/src/data/IGLRenderPipeline.ts
+++ b/src/data/IGLRenderPipeline.ts
@@ -9,11 +9,6 @@ declare module "@feng3d/render-api"
*/
export interface IRenderPipeline
{
- /**
- * 片段着色器代码
- */
- fragment: IFragmentState;
-
/**
* 描述可选的深度模板的测试、运算以及偏差。
*/
@@ -34,6 +29,13 @@ declare module "@feng3d/render-api"
rasterizerDiscard?: boolean;
}
+ export interface IFragmentState
+ {
+ /**
+ * 定义了该管道写入的颜色目标的格式和行为。
+ */
+ targets?: IGLColorTargetState[]
+ }
}
export interface ITransformFeedbackVaryings
@@ -48,19 +50,3 @@ export interface ITransformFeedbackVaryings
*/
bufferMode: "INTERLEAVED_ATTRIBS" | "SEPARATE_ATTRIBS";
}
-
-/**
- * GPU片元程序阶段。
- */
-export interface IFragmentState
-{
- /**
- * 着色器源码。
- */
- code: string,
-
- /**
- * 定义了该管道写入的颜色目标的格式和行为。
- */
- targets?: IGLColorTargetState[]
-}
\ No newline at end of file
diff --git a/src/runs/runProgram.ts b/src/runs/runProgram.ts
index 1e559f2..2cd30c6 100644
--- a/src/runs/runProgram.ts
+++ b/src/runs/runProgram.ts
@@ -1,7 +1,6 @@
import { IRenderPipeline } from "@feng3d/render-api";
import { getGLProgram } from "../caches/getGLProgram";
-import { IFragmentState } from "../data/IGLRenderPipeline";
-import { defaultColorTargetStates, runColorTargetStates } from "./runColorTargetStates";
+import { runColorTargetStates } from "./runColorTargetStates";
export function runProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeline)
{
@@ -24,5 +23,3 @@ export function runProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeline)
//
runColorTargetStates(gl, pipeline.fragment.targets);
}
-
-export const defaultFragmentState: IFragmentState = Object.freeze({ code: "", targets: defaultColorTargetStates });
\ No newline at end of file
--
Gitee
From d7859f9e24055d4fca22db1664b83ff70a609639 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 13:33:45 +0800
Subject: [PATCH 103/186] IColorTargetState
---
src/data/IGLBlendState.ts | 100 ------------------------
src/data/IGLColorTargetState.ts | 20 -----
src/data/IGLRenderPipeline.ts | 129 ++++++++++++++++++++++++++++++-
src/index.ts | 2 -
src/runs/runColorTargetStates.ts | 14 ++--
5 files changed, 132 insertions(+), 133 deletions(-)
delete mode 100644 src/data/IGLBlendState.ts
delete mode 100644 src/data/IGLColorTargetState.ts
diff --git a/src/data/IGLBlendState.ts b/src/data/IGLBlendState.ts
deleted file mode 100644
index 928f35b..0000000
--- a/src/data/IGLBlendState.ts
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * 混合状态。
- */
-export interface IGLBlendState
-{
- /**
- * 为颜色通道定义相应渲染目标的混合行为。
- */
- color?: IGLBlendComponent;
-
- /**
- * 为alpha通道定义相应渲染目标的混合行为。
- */
- alpha?: IGLBlendComponent;
-}
-
-/**
- * 为颜色或alpha通道定义相应渲染目标的混合行为。
- */
-export interface IGLBlendComponent
-{
- /**
- * 混合方式,默认 FUNC_ADD,源 + 目标。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendEquation
- */
- operation?: GLBlendEquation;
-
- /**
- * 源混合因子,默认 SRC_ALPHA,将所有颜色乘以源alpha值。
- *
- * @see GLBlendFactor
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
- */
- srcFactor?: GLBlendFactor;
-
- /**
- * 目标混合因子,默认 ONE_MINUS_SRC_ALPHA,将所有颜色乘以1减去源alpha值。
- *
- * @see GLBlendFactor
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
- */
- dstFactor?: GLBlendFactor;
-}
-
-/**
- * 混合因子(R分量系数,G分量系数,B分量系数)
- *
- * 混合颜色的公式可以这样描述:color(RGBA) = (sourceColor * sfactor) + (destinationColor * dfactor)。这里的 RGBA 值均在0与1之间。
- *
- * The formula for the blending color can be described like this: color(RGBA) = (sourceColor * sfactor) + (destinationColor * dfactor). The RBGA values are between 0 and 1.
- *
- * * `ZERO` Factor: (0,0,0,0); 把所有颜色都乘以0。
- * * `ONE` Factor: (1,1,1,1); 把所有颜色都乘以1。
- * * `SRC_COLOR` Factor: (Rs, Gs, Bs, As); 将所有颜色乘以源颜色。
- * * `ONE_MINUS_SRC_COLOR` Factor: (1-Rs, 1-Gs, 1-Bs, 1-As); 将所有颜色乘以1减去每个源颜色。
- * * `DST_COLOR` Factor: (Rd, Gd, Bd, Ad); 将所有颜色乘以目标颜色。
- * * `ONE_MINUS_DST_COLOR` Factor: (1-Rd, 1-Gd, 1-Bd, 1-Ad); 将所有颜色乘以1减去每个目标颜色。
- * * `SRC_ALPHA` Factor: (As, As, As, As); 将所有颜色乘以源alpha值。
- * * `ONE_MINUS_SRC_ALPHA` Factor: (1-As, 1-As, 1-As, 1-As); 将所有颜色乘以1减去源alpha值。
- * * `DST_ALPHA` Factor: (Ad, Ad, Ad, Ad); 将所有颜色乘以目标alpha值。
- * * `ONE_MINUS_DST_ALPHA` Factor: (1-Ad, 1-Ad, 1-Ad, 1-Ad); 将所有颜色乘以1减去目标alpha值。
- * * `CONSTANT_COLOR` Factor: (Rc, Gc, Bc, Ac); 将所有颜色乘以一个常数颜色。
- * * `ONE_MINUS_CONSTANT_COLOR` Factor: (1-Rc, 1-Gc, 1-Bc, 1-Ac); 所有颜色乘以1减去一个常数颜色。
- * * `CONSTANT_ALPHA` Factor: (Ac, Ac, Ac, Ac); 将所有颜色乘以一个常量alpha值。
- * * `ONE_MINUS_CONSTANT_ALPHA` Factor: (1-Ac, 1-Ac, 1-Ac, 1-Ac); 将所有颜色乘以1减去一个常数alpha值。
- * * `SRC_ALPHA_SATURATE` Factor: (min(As, 1 - Ad), min(As, 1 - Ad), min(As, 1 - Ad), 1); 将RGB颜色乘以源alpha值与1减去目标alpha值的较小值。alpha值乘以1。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
- */
-export type GLBlendFactor = "ZERO" | "ONE" | "SRC_COLOR" | "ONE_MINUS_SRC_COLOR" | "DST_COLOR" | "ONE_MINUS_DST_COLOR" | "SRC_ALPHA" | "ONE_MINUS_SRC_ALPHA" | "DST_ALPHA" | "ONE_MINUS_DST_ALPHA" | "SRC_ALPHA_SATURATE" | "CONSTANT_COLOR" | "ONE_MINUS_CONSTANT_COLOR" | "CONSTANT_ALPHA" | "ONE_MINUS_CONSTANT_ALPHA";
-
-/**
- * 混合方法
- *
- * * FUNC_ADD 源 + 目标
- * * FUNC_SUBTRACT 源 - 目标
- * * FUNC_REVERSE_SUBTRACT 目标 - 源
- * * MIN 源与目标的最小值,在 WebGL 2 中可使用。在 WebGL 1 时,自动使用 EXT_blend_minmax 扩展中 MIN_EXT 值。
- * * MAX 源与目标的最大值,在 WebGL 2 中可使用。在 WebGL 1 时,自动使用 EXT_blend_minmax 扩展中 MAX_EXT 值。
- *
- * A GLenum specifying how source and destination colors are combined. Must be either:
- *
- * * gl.FUNC_ADD: source + destination (default value)
- * * gl.FUNC_SUBTRACT: source - destination
- * * gl.FUNC_REVERSE_SUBTRACT: destination - source
- *
- * When using the EXT_blend_minmax extension:
- *
- * * ext.MIN_EXT: Minimum of source and destination
- * * ext.MAX_EXT: Maximum of source and destination
- *
- * When using a WebGL 2 context, the following values are available additionally:
- *
- * * gl.MIN: Minimum of source and destination
- * * gl.MAX: Maximum of source and destination
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendEquation
- */
-export type GLBlendEquation = "FUNC_ADD" | "FUNC_SUBTRACT" | "FUNC_REVERSE_SUBTRACT" | "MIN" | "MAX";
diff --git a/src/data/IGLColorTargetState.ts b/src/data/IGLColorTargetState.ts
deleted file mode 100644
index cfab0e7..0000000
--- a/src/data/IGLColorTargetState.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { IGLBlendState } from "./IGLBlendState";
-
-export interface IGLColorTargetState
-{
- /**
- * 混合状态。
- */
- blend?: IGLBlendState;
-
- /**
- * 控制那些颜色分量是否可以被写入到帧缓冲器。
- *
- * [red: boolean, green: boolean, blue: boolean, alpha: boolean]
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/colorMask
- */
- writeMask?: IGLWriteMask;
-}
-
-export type IGLWriteMask = [red: boolean, green: boolean, blue: boolean, alpha: boolean];
\ No newline at end of file
diff --git a/src/data/IGLRenderPipeline.ts b/src/data/IGLRenderPipeline.ts
index 1145609..2afad78 100644
--- a/src/data/IGLRenderPipeline.ts
+++ b/src/data/IGLRenderPipeline.ts
@@ -1,5 +1,4 @@
import { IRenderPipeline } from "@feng3d/render-api";
-import { IGLColorTargetState } from "./IGLColorTargetState";
import { IGLDepthStencilState } from "./IGLDepthStencilState";
declare module "@feng3d/render-api"
@@ -34,19 +33,141 @@ declare module "@feng3d/render-api"
/**
* 定义了该管道写入的颜色目标的格式和行为。
*/
- targets?: IGLColorTargetState[]
+ readonly targets?: readonly IColorTargetState[]
}
+
+ export interface IColorTargetState
+ {
+ /**
+ * 混合状态。
+ */
+ readonly blend?: IBlendState;
+
+ /**
+ * 控制那些颜色分量是否可以被写入到帧缓冲器。
+ *
+ * [red: boolean, green: boolean, blue: boolean, alpha: boolean]
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/colorMask
+ */
+ readonly writeMask?: IGLWriteMask;
+ }
+
+ /**
+ * 混合状态。
+ */
+ export interface IBlendState
+ {
+ /**
+ * 为颜色通道定义相应渲染目标的混合行为。
+ */
+ readonly color?: IBlendComponent;
+
+ /**
+ * 为alpha通道定义相应渲染目标的混合行为。
+ */
+ readonly alpha?: IBlendComponent;
+ }
+
+ /**
+ * 为颜色或alpha通道定义相应渲染目标的混合行为。
+ */
+ export interface IBlendComponent
+ {
+ /**
+ * 混合方式,默认 FUNC_ADD,源 + 目标。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendEquation
+ */
+ operation?: GLBlendEquation;
+
+ /**
+ * 源混合因子,默认 SRC_ALPHA,将所有颜色乘以源alpha值。
+ *
+ * @see GLBlendFactor
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
+ */
+ srcFactor?: GLBlendFactor;
+
+ /**
+ * 目标混合因子,默认 ONE_MINUS_SRC_ALPHA,将所有颜色乘以1减去源alpha值。
+ *
+ * @see GLBlendFactor
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
+ */
+ dstFactor?: GLBlendFactor;
+ }
+
}
export interface ITransformFeedbackVaryings
{
/**
* 回写变量列表。
- */
+ */
varyings: string[];
/**
* 交叉或者分离。
- */
+ */
bufferMode: "INTERLEAVED_ATTRIBS" | "SEPARATE_ATTRIBS";
}
+
+export type IGLWriteMask = [red: boolean, green: boolean, blue: boolean, alpha: boolean];
+
+
+/**
+ * 混合因子(R分量系数,G分量系数,B分量系数)
+ *
+ * 混合颜色的公式可以这样描述:color(RGBA) = (sourceColor * sfactor) + (destinationColor * dfactor)。这里的 RGBA 值均在0与1之间。
+ *
+ * The formula for the blending color can be described like this: color(RGBA) = (sourceColor * sfactor) + (destinationColor * dfactor). The RBGA values are between 0 and 1.
+ *
+ * * `ZERO` Factor: (0,0,0,0); 把所有颜色都乘以0。
+ * * `ONE` Factor: (1,1,1,1); 把所有颜色都乘以1。
+ * * `SRC_COLOR` Factor: (Rs, Gs, Bs, As); 将所有颜色乘以源颜色。
+ * * `ONE_MINUS_SRC_COLOR` Factor: (1-Rs, 1-Gs, 1-Bs, 1-As); 将所有颜色乘以1减去每个源颜色。
+ * * `DST_COLOR` Factor: (Rd, Gd, Bd, Ad); 将所有颜色乘以目标颜色。
+ * * `ONE_MINUS_DST_COLOR` Factor: (1-Rd, 1-Gd, 1-Bd, 1-Ad); 将所有颜色乘以1减去每个目标颜色。
+ * * `SRC_ALPHA` Factor: (As, As, As, As); 将所有颜色乘以源alpha值。
+ * * `ONE_MINUS_SRC_ALPHA` Factor: (1-As, 1-As, 1-As, 1-As); 将所有颜色乘以1减去源alpha值。
+ * * `DST_ALPHA` Factor: (Ad, Ad, Ad, Ad); 将所有颜色乘以目标alpha值。
+ * * `ONE_MINUS_DST_ALPHA` Factor: (1-Ad, 1-Ad, 1-Ad, 1-Ad); 将所有颜色乘以1减去目标alpha值。
+ * * `CONSTANT_COLOR` Factor: (Rc, Gc, Bc, Ac); 将所有颜色乘以一个常数颜色。
+ * * `ONE_MINUS_CONSTANT_COLOR` Factor: (1-Rc, 1-Gc, 1-Bc, 1-Ac); 所有颜色乘以1减去一个常数颜色。
+ * * `CONSTANT_ALPHA` Factor: (Ac, Ac, Ac, Ac); 将所有颜色乘以一个常量alpha值。
+ * * `ONE_MINUS_CONSTANT_ALPHA` Factor: (1-Ac, 1-Ac, 1-Ac, 1-Ac); 将所有颜色乘以1减去一个常数alpha值。
+ * * `SRC_ALPHA_SATURATE` Factor: (min(As, 1 - Ad), min(As, 1 - Ad), min(As, 1 - Ad), 1); 将RGB颜色乘以源alpha值与1减去目标alpha值的较小值。alpha值乘以1。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
+ */
+export type GLBlendFactor = "ZERO" | "ONE" | "SRC_COLOR" | "ONE_MINUS_SRC_COLOR" | "DST_COLOR" | "ONE_MINUS_DST_COLOR" | "SRC_ALPHA" | "ONE_MINUS_SRC_ALPHA" | "DST_ALPHA" | "ONE_MINUS_DST_ALPHA" | "SRC_ALPHA_SATURATE" | "CONSTANT_COLOR" | "ONE_MINUS_CONSTANT_COLOR" | "CONSTANT_ALPHA" | "ONE_MINUS_CONSTANT_ALPHA";
+
+/**
+ * 混合方法
+ *
+ * * FUNC_ADD 源 + 目标
+ * * FUNC_SUBTRACT 源 - 目标
+ * * FUNC_REVERSE_SUBTRACT 目标 - 源
+ * * MIN 源与目标的最小值,在 WebGL 2 中可使用。在 WebGL 1 时,自动使用 EXT_blend_minmax 扩展中 MIN_EXT 值。
+ * * MAX 源与目标的最大值,在 WebGL 2 中可使用。在 WebGL 1 时,自动使用 EXT_blend_minmax 扩展中 MAX_EXT 值。
+ *
+ * A GLenum specifying how source and destination colors are combined. Must be either:
+ *
+ * * gl.FUNC_ADD: source + destination (default value)
+ * * gl.FUNC_SUBTRACT: source - destination
+ * * gl.FUNC_REVERSE_SUBTRACT: destination - source
+ *
+ * When using the EXT_blend_minmax extension:
+ *
+ * * ext.MIN_EXT: Minimum of source and destination
+ * * ext.MAX_EXT: Maximum of source and destination
+ *
+ * When using a WebGL 2 context, the following values are available additionally:
+ *
+ * * gl.MIN: Minimum of source and destination
+ * * gl.MAX: Maximum of source and destination
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendEquation
+ */
+export type GLBlendEquation = "FUNC_ADD" | "FUNC_SUBTRACT" | "FUNC_REVERSE_SUBTRACT" | "MIN" | "MAX";
diff --git a/src/index.ts b/src/index.ts
index 2e9077f..7259379 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,9 +1,7 @@
-export * from "./data/IGLBlendState";
export * from "./data/IGLBlitFramebuffer";
export * from "./data/IGLBuffer";
export * from "./data/IGLCanvasContext";
export * from "./data/IGLCapabilities";
-export * from "./data/IGLColorTargetState";
export * from "./data/IGLCommandEncoder";
export * from "./data/IGLCopyBufferToBuffer";
export * from "./data/IGLDepthStencilState";
diff --git a/src/runs/runColorTargetStates.ts b/src/runs/runColorTargetStates.ts
index 0aaa0d2..9460630 100644
--- a/src/runs/runColorTargetStates.ts
+++ b/src/runs/runColorTargetStates.ts
@@ -1,7 +1,7 @@
-import { IGLBlendComponent, IGLBlendState } from "../data/IGLBlendState";
-import { IGLColorTargetState, IGLWriteMask } from "../data/IGLColorTargetState";
+import { IBlendComponent, IBlendState, IColorTargetState } from "@feng3d/render-api";
+import { IGLWriteMask } from "../data/IGLRenderPipeline";
-export function runColorTargetStates(gl: WebGLRenderingContext, targets?: IGLColorTargetState[])
+export function runColorTargetStates(gl: WebGLRenderingContext, targets?: readonly IColorTargetState[])
{
//
const colorMask = targets?.[0]?.writeMask || defaultWriteMask;
@@ -27,7 +27,7 @@ export function runColorTargetStates(gl: WebGLRenderingContext, targets?: IGLCol
}
const defaultWriteMask: IGLWriteMask = Object.freeze([true, true, true, true]) as any;
-const defaultBlendComponent: IGLBlendComponent = Object.freeze({ operation: "FUNC_ADD", srcFactor: "SRC_ALPHA", dstFactor: "ONE_MINUS_SRC_ALPHA" });
-export const defaultBlendState: IGLBlendState = Object.freeze({ color: defaultBlendComponent, alpha: defaultBlendComponent });
-const defaultColorTargetState: IGLColorTargetState = Object.freeze({ writeMask: defaultWriteMask, blend: defaultBlendState });
-export const defaultColorTargetStates: IGLColorTargetState[] = Object.freeze([defaultColorTargetState]) as any;
\ No newline at end of file
+const defaultBlendComponent: IBlendComponent = Object.freeze({ operation: "FUNC_ADD", srcFactor: "SRC_ALPHA", dstFactor: "ONE_MINUS_SRC_ALPHA" });
+export const defaultBlendState: IBlendState = Object.freeze({ color: defaultBlendComponent, alpha: defaultBlendComponent });
+const defaultColorTargetState: IColorTargetState = Object.freeze({ writeMask: defaultWriteMask, blend: defaultBlendState });
+export const defaultColorTargetStates: IColorTargetState[] = Object.freeze([defaultColorTargetState]) as any;
\ No newline at end of file
--
Gitee
From 5d14d386ace30002c1fe9938af84f1580b9318ba Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 13:43:02 +0800
Subject: [PATCH 104/186] runColorTargetStates
---
src/data/IGLRenderPipeline.ts | 14 +++++++-------
src/runs/runColorTargetStates.ts | 28 +++++++++++++---------------
2 files changed, 20 insertions(+), 22 deletions(-)
diff --git a/src/data/IGLRenderPipeline.ts b/src/data/IGLRenderPipeline.ts
index 2afad78..dba6aae 100644
--- a/src/data/IGLRenderPipeline.ts
+++ b/src/data/IGLRenderPipeline.ts
@@ -79,23 +79,23 @@ declare module "@feng3d/render-api"
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendEquation
*/
- operation?: GLBlendEquation;
+ operation?: IGLBlendEquation;
/**
* 源混合因子,默认 SRC_ALPHA,将所有颜色乘以源alpha值。
*
- * @see GLBlendFactor
+ * @see IGLBlendFactor
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
*/
- srcFactor?: GLBlendFactor;
+ srcFactor?: IGLBlendFactor;
/**
* 目标混合因子,默认 ONE_MINUS_SRC_ALPHA,将所有颜色乘以1减去源alpha值。
*
- * @see GLBlendFactor
+ * @see IGLBlendFactor
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
*/
- dstFactor?: GLBlendFactor;
+ dstFactor?: IGLBlendFactor;
}
}
@@ -141,7 +141,7 @@ export type IGLWriteMask = [red: boolean, green: boolean, blue: boolean, alpha:
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
*/
-export type GLBlendFactor = "ZERO" | "ONE" | "SRC_COLOR" | "ONE_MINUS_SRC_COLOR" | "DST_COLOR" | "ONE_MINUS_DST_COLOR" | "SRC_ALPHA" | "ONE_MINUS_SRC_ALPHA" | "DST_ALPHA" | "ONE_MINUS_DST_ALPHA" | "SRC_ALPHA_SATURATE" | "CONSTANT_COLOR" | "ONE_MINUS_CONSTANT_COLOR" | "CONSTANT_ALPHA" | "ONE_MINUS_CONSTANT_ALPHA";
+export type IGLBlendFactor = "ZERO" | "ONE" | "SRC_COLOR" | "ONE_MINUS_SRC_COLOR" | "DST_COLOR" | "ONE_MINUS_DST_COLOR" | "SRC_ALPHA" | "ONE_MINUS_SRC_ALPHA" | "DST_ALPHA" | "ONE_MINUS_DST_ALPHA" | "SRC_ALPHA_SATURATE" | "CONSTANT_COLOR" | "ONE_MINUS_CONSTANT_COLOR" | "CONSTANT_ALPHA" | "ONE_MINUS_CONSTANT_ALPHA";
/**
* 混合方法
@@ -170,4 +170,4 @@ export type GLBlendFactor = "ZERO" | "ONE" | "SRC_COLOR" | "ONE_MINUS_SRC_COLOR"
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendEquation
*/
-export type GLBlendEquation = "FUNC_ADD" | "FUNC_SUBTRACT" | "FUNC_REVERSE_SUBTRACT" | "MIN" | "MAX";
+export type IGLBlendEquation = "FUNC_ADD" | "FUNC_SUBTRACT" | "FUNC_REVERSE_SUBTRACT" | "MIN" | "MAX";
diff --git a/src/runs/runColorTargetStates.ts b/src/runs/runColorTargetStates.ts
index 9460630..3dfd2da 100644
--- a/src/runs/runColorTargetStates.ts
+++ b/src/runs/runColorTargetStates.ts
@@ -1,33 +1,31 @@
-import { IBlendComponent, IBlendState, IColorTargetState } from "@feng3d/render-api";
-import { IGLWriteMask } from "../data/IGLRenderPipeline";
+import { IColorTargetState } from "@feng3d/render-api";
+import { IGLBlendEquation, IGLBlendFactor } from "../data/IGLRenderPipeline";
export function runColorTargetStates(gl: WebGLRenderingContext, targets?: readonly IColorTargetState[])
{
//
- const colorMask = targets?.[0]?.writeMask || defaultWriteMask;
+ const colorMask = targets?.[0]?.writeMask || [true, true, true, true];
gl.colorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
//
let blend = targets?.[0]?.blend;
if (blend)
{
- blend = {
- color: { ...defaultBlendState.color, ...blend?.color },
- alpha: { ...defaultBlendState.alpha, ...blend?.color, ...blend?.alpha },
- };
+ const colorOperation: IGLBlendEquation = blend?.color?.operation || "FUNC_ADD";
+ const colorSrcFactor: IGLBlendFactor = blend?.color?.srcFactor || "SRC_ALPHA";
+ const colorDstFactor: IGLBlendFactor = blend?.color?.dstFactor || "ONE_MINUS_SRC_ALPHA";
+ //
+ const alphaOperation: IGLBlendEquation = blend?.alpha?.operation || colorOperation || "FUNC_ADD";
+ const alphaSrcFactor: IGLBlendFactor = blend?.alpha?.srcFactor || colorSrcFactor || "SRC_ALPHA";
+ const alphaDstFactor: IGLBlendFactor = blend?.alpha?.dstFactor || colorDstFactor || "ONE_MINUS_SRC_ALPHA";
+
//
gl.enable(gl.BLEND);
- gl.blendEquationSeparate(gl[blend.color.operation], gl[blend.alpha.operation]);
- gl.blendFuncSeparate(gl[blend.color.srcFactor], gl[blend.color.dstFactor], gl[blend.alpha.srcFactor], gl[blend.alpha.dstFactor]);
+ gl.blendEquationSeparate(gl[colorOperation], gl[alphaOperation]);
+ gl.blendFuncSeparate(gl[colorSrcFactor], gl[colorDstFactor], gl[alphaSrcFactor], gl[alphaDstFactor]);
}
else
{
gl.disable(gl.BLEND);
}
}
-
-const defaultWriteMask: IGLWriteMask = Object.freeze([true, true, true, true]) as any;
-const defaultBlendComponent: IBlendComponent = Object.freeze({ operation: "FUNC_ADD", srcFactor: "SRC_ALPHA", dstFactor: "ONE_MINUS_SRC_ALPHA" });
-export const defaultBlendState: IBlendState = Object.freeze({ color: defaultBlendComponent, alpha: defaultBlendComponent });
-const defaultColorTargetState: IColorTargetState = Object.freeze({ writeMask: defaultWriteMask, blend: defaultBlendState });
-export const defaultColorTargetStates: IColorTargetState[] = Object.freeze([defaultColorTargetState]) as any;
\ No newline at end of file
--
Gitee
From de5c010c3f1e508436e41cd2c0df2bc3bfa76056 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 13:45:05 +0800
Subject: [PATCH 105/186] runColorTargetStates
---
src/runs/runColorTargetStates.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/runs/runColorTargetStates.ts b/src/runs/runColorTargetStates.ts
index 3dfd2da..42e8f07 100644
--- a/src/runs/runColorTargetStates.ts
+++ b/src/runs/runColorTargetStates.ts
@@ -1,10 +1,10 @@
import { IColorTargetState } from "@feng3d/render-api";
-import { IGLBlendEquation, IGLBlendFactor } from "../data/IGLRenderPipeline";
+import { IGLBlendEquation, IGLBlendFactor, IGLWriteMask } from "../data/IGLRenderPipeline";
export function runColorTargetStates(gl: WebGLRenderingContext, targets?: readonly IColorTargetState[])
{
//
- const colorMask = targets?.[0]?.writeMask || [true, true, true, true];
+ const colorMask: IGLWriteMask = targets?.[0]?.writeMask || [true, true, true, true];
gl.colorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
//
--
Gitee
From 5215933843e9b65c64496b43aa5ab4e77ae95f0a Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 17:31:15 +0800
Subject: [PATCH 106/186] IFragmentState runColorTargetStates
---
.../WebGL2Samples/fbo_new_blend_equation.ts | 8 +-
.../transform_feedback_instanced.ts | 4 +-
.../transform_feedback_separated_2.ts | 4 +-
src/data/IGLRenderPipeline.ts | 131 +-----------------
src/runs/runColorTargetStates.ts | 122 ++++++++++++++--
5 files changed, 122 insertions(+), 147 deletions(-)
diff --git a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
index bf3142b..9f9e9d3 100644
--- a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
+++ b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
@@ -161,8 +161,8 @@ function render()
...program.fragment.targets[0],
blend: {
...program.fragment.targets[0].blend,
- color: { ...program.fragment.targets[0].blend.color, operation: "MIN" },
- alpha: { ...program.fragment.targets[0].blend.alpha, operation: "MIN" },
+ color: { ...program.fragment.targets[0].blend.color, operation: "min" },
+ alpha: { ...program.fragment.targets[0].blend.alpha, operation: "min" },
},
}]
}
@@ -182,8 +182,8 @@ function render()
...program.fragment.targets[0],
blend: {
...program.fragment.targets[0].blend,
- color: { ...program.fragment.targets[0].blend.color, operation: "MAX" },
- alpha: { ...program.fragment.targets[0].blend.alpha, operation: "MAX" },
+ color: { ...program.fragment.targets[0].blend.color, operation: "max" },
+ alpha: { ...program.fragment.targets[0].blend.alpha, operation: "max" },
},
}]
}
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index e745a77..1b723e7 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -143,8 +143,8 @@ import { getShaderSource } from "./utility";
code: getShaderSource("fs-draw"),
targets: [{
blend: {
- color: { srcFactor: "SRC_ALPHA", dstFactor: "ONE" },
- alpha: { srcFactor: "SRC_ALPHA", dstFactor: "ONE" },
+ color: { srcFactor: "src-alpha", dstFactor: "one" },
+ alpha: { srcFactor: "src-alpha", dstFactor: "one" },
}
}]
},
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
index fc683d3..29ce1bf 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
@@ -109,8 +109,8 @@ import { getShaderSource } from "./utility";
code: getShaderSource("fs-draw"),
targets: [{
blend: {
- color: { srcFactor: "SRC_ALPHA", dstFactor: "ONE" },
- alpha: { srcFactor: "SRC_ALPHA", dstFactor: "ONE" },
+ color: { srcFactor: "src-alpha", dstFactor: "one" },
+ alpha: { srcFactor: "src-alpha", dstFactor: "one" },
}
}]
},
diff --git a/src/data/IGLRenderPipeline.ts b/src/data/IGLRenderPipeline.ts
index dba6aae..598aaeb 100644
--- a/src/data/IGLRenderPipeline.ts
+++ b/src/data/IGLRenderPipeline.ts
@@ -1,4 +1,4 @@
-import { IRenderPipeline } from "@feng3d/render-api";
+import { IBlendComponent, IBlendState, IColorTargetState, IRenderPipeline } from "@feng3d/render-api";
import { IGLDepthStencilState } from "./IGLDepthStencilState";
declare module "@feng3d/render-api"
@@ -27,77 +27,6 @@ declare module "@feng3d/render-api"
*/
rasterizerDiscard?: boolean;
}
-
- export interface IFragmentState
- {
- /**
- * 定义了该管道写入的颜色目标的格式和行为。
- */
- readonly targets?: readonly IColorTargetState[]
- }
-
- export interface IColorTargetState
- {
- /**
- * 混合状态。
- */
- readonly blend?: IBlendState;
-
- /**
- * 控制那些颜色分量是否可以被写入到帧缓冲器。
- *
- * [red: boolean, green: boolean, blue: boolean, alpha: boolean]
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/colorMask
- */
- readonly writeMask?: IGLWriteMask;
- }
-
- /**
- * 混合状态。
- */
- export interface IBlendState
- {
- /**
- * 为颜色通道定义相应渲染目标的混合行为。
- */
- readonly color?: IBlendComponent;
-
- /**
- * 为alpha通道定义相应渲染目标的混合行为。
- */
- readonly alpha?: IBlendComponent;
- }
-
- /**
- * 为颜色或alpha通道定义相应渲染目标的混合行为。
- */
- export interface IBlendComponent
- {
- /**
- * 混合方式,默认 FUNC_ADD,源 + 目标。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendEquation
- */
- operation?: IGLBlendEquation;
-
- /**
- * 源混合因子,默认 SRC_ALPHA,将所有颜色乘以源alpha值。
- *
- * @see IGLBlendFactor
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
- */
- srcFactor?: IGLBlendFactor;
-
- /**
- * 目标混合因子,默认 ONE_MINUS_SRC_ALPHA,将所有颜色乘以1减去源alpha值。
- *
- * @see IGLBlendFactor
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
- */
- dstFactor?: IGLBlendFactor;
- }
-
}
export interface ITransformFeedbackVaryings
@@ -113,61 +42,3 @@ export interface ITransformFeedbackVaryings
bufferMode: "INTERLEAVED_ATTRIBS" | "SEPARATE_ATTRIBS";
}
-export type IGLWriteMask = [red: boolean, green: boolean, blue: boolean, alpha: boolean];
-
-
-/**
- * 混合因子(R分量系数,G分量系数,B分量系数)
- *
- * 混合颜色的公式可以这样描述:color(RGBA) = (sourceColor * sfactor) + (destinationColor * dfactor)。这里的 RGBA 值均在0与1之间。
- *
- * The formula for the blending color can be described like this: color(RGBA) = (sourceColor * sfactor) + (destinationColor * dfactor). The RBGA values are between 0 and 1.
- *
- * * `ZERO` Factor: (0,0,0,0); 把所有颜色都乘以0。
- * * `ONE` Factor: (1,1,1,1); 把所有颜色都乘以1。
- * * `SRC_COLOR` Factor: (Rs, Gs, Bs, As); 将所有颜色乘以源颜色。
- * * `ONE_MINUS_SRC_COLOR` Factor: (1-Rs, 1-Gs, 1-Bs, 1-As); 将所有颜色乘以1减去每个源颜色。
- * * `DST_COLOR` Factor: (Rd, Gd, Bd, Ad); 将所有颜色乘以目标颜色。
- * * `ONE_MINUS_DST_COLOR` Factor: (1-Rd, 1-Gd, 1-Bd, 1-Ad); 将所有颜色乘以1减去每个目标颜色。
- * * `SRC_ALPHA` Factor: (As, As, As, As); 将所有颜色乘以源alpha值。
- * * `ONE_MINUS_SRC_ALPHA` Factor: (1-As, 1-As, 1-As, 1-As); 将所有颜色乘以1减去源alpha值。
- * * `DST_ALPHA` Factor: (Ad, Ad, Ad, Ad); 将所有颜色乘以目标alpha值。
- * * `ONE_MINUS_DST_ALPHA` Factor: (1-Ad, 1-Ad, 1-Ad, 1-Ad); 将所有颜色乘以1减去目标alpha值。
- * * `CONSTANT_COLOR` Factor: (Rc, Gc, Bc, Ac); 将所有颜色乘以一个常数颜色。
- * * `ONE_MINUS_CONSTANT_COLOR` Factor: (1-Rc, 1-Gc, 1-Bc, 1-Ac); 所有颜色乘以1减去一个常数颜色。
- * * `CONSTANT_ALPHA` Factor: (Ac, Ac, Ac, Ac); 将所有颜色乘以一个常量alpha值。
- * * `ONE_MINUS_CONSTANT_ALPHA` Factor: (1-Ac, 1-Ac, 1-Ac, 1-Ac); 将所有颜色乘以1减去一个常数alpha值。
- * * `SRC_ALPHA_SATURATE` Factor: (min(As, 1 - Ad), min(As, 1 - Ad), min(As, 1 - Ad), 1); 将RGB颜色乘以源alpha值与1减去目标alpha值的较小值。alpha值乘以1。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
- */
-export type IGLBlendFactor = "ZERO" | "ONE" | "SRC_COLOR" | "ONE_MINUS_SRC_COLOR" | "DST_COLOR" | "ONE_MINUS_DST_COLOR" | "SRC_ALPHA" | "ONE_MINUS_SRC_ALPHA" | "DST_ALPHA" | "ONE_MINUS_DST_ALPHA" | "SRC_ALPHA_SATURATE" | "CONSTANT_COLOR" | "ONE_MINUS_CONSTANT_COLOR" | "CONSTANT_ALPHA" | "ONE_MINUS_CONSTANT_ALPHA";
-
-/**
- * 混合方法
- *
- * * FUNC_ADD 源 + 目标
- * * FUNC_SUBTRACT 源 - 目标
- * * FUNC_REVERSE_SUBTRACT 目标 - 源
- * * MIN 源与目标的最小值,在 WebGL 2 中可使用。在 WebGL 1 时,自动使用 EXT_blend_minmax 扩展中 MIN_EXT 值。
- * * MAX 源与目标的最大值,在 WebGL 2 中可使用。在 WebGL 1 时,自动使用 EXT_blend_minmax 扩展中 MAX_EXT 值。
- *
- * A GLenum specifying how source and destination colors are combined. Must be either:
- *
- * * gl.FUNC_ADD: source + destination (default value)
- * * gl.FUNC_SUBTRACT: source - destination
- * * gl.FUNC_REVERSE_SUBTRACT: destination - source
- *
- * When using the EXT_blend_minmax extension:
- *
- * * ext.MIN_EXT: Minimum of source and destination
- * * ext.MAX_EXT: Maximum of source and destination
- *
- * When using a WebGL 2 context, the following values are available additionally:
- *
- * * gl.MIN: Minimum of source and destination
- * * gl.MAX: Maximum of source and destination
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendEquation
- */
-export type IGLBlendEquation = "FUNC_ADD" | "FUNC_SUBTRACT" | "FUNC_REVERSE_SUBTRACT" | "MIN" | "MAX";
diff --git a/src/runs/runColorTargetStates.ts b/src/runs/runColorTargetStates.ts
index 42e8f07..86524e3 100644
--- a/src/runs/runColorTargetStates.ts
+++ b/src/runs/runColorTargetStates.ts
@@ -1,23 +1,25 @@
-import { IColorTargetState } from "@feng3d/render-api";
-import { IGLBlendEquation, IGLBlendFactor, IGLWriteMask } from "../data/IGLRenderPipeline";
+import { IBlendComponent, IBlendFactor, IBlendOperation, IColorTargetState } from "@feng3d/render-api";
export function runColorTargetStates(gl: WebGLRenderingContext, targets?: readonly IColorTargetState[])
{
//
- const colorMask: IGLWriteMask = targets?.[0]?.writeMask || [true, true, true, true];
+ const colorMask = targets?.[0]?.writeMask || [true, true, true, true];
gl.colorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
//
let blend = targets?.[0]?.blend;
if (blend)
{
- const colorOperation: IGLBlendEquation = blend?.color?.operation || "FUNC_ADD";
- const colorSrcFactor: IGLBlendFactor = blend?.color?.srcFactor || "SRC_ALPHA";
- const colorDstFactor: IGLBlendFactor = blend?.color?.dstFactor || "ONE_MINUS_SRC_ALPHA";
+ const color: IBlendComponent = blend.color;
+ const alpha: IBlendComponent = blend.alpha;
+
+ const colorOperation: IGLBlendEquation = getIGLBlendEquation(color?.operation) || "FUNC_ADD";
+ const colorSrcFactor: IGLBlendFactor = getIGLBlendFactor(color?.srcFactor) || "SRC_ALPHA";
+ const colorDstFactor: IGLBlendFactor = getIGLBlendFactor(color?.dstFactor) || "ONE_MINUS_SRC_ALPHA";
//
- const alphaOperation: IGLBlendEquation = blend?.alpha?.operation || colorOperation || "FUNC_ADD";
- const alphaSrcFactor: IGLBlendFactor = blend?.alpha?.srcFactor || colorSrcFactor || "SRC_ALPHA";
- const alphaDstFactor: IGLBlendFactor = blend?.alpha?.dstFactor || colorDstFactor || "ONE_MINUS_SRC_ALPHA";
+ const alphaOperation: IGLBlendEquation = getIGLBlendEquation(alpha?.operation) || colorOperation;
+ const alphaSrcFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.srcFactor) || colorSrcFactor;
+ const alphaDstFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.dstFactor) || colorDstFactor;
//
gl.enable(gl.BLEND);
@@ -29,3 +31,105 @@ export function runColorTargetStates(gl: WebGLRenderingContext, targets?: readon
gl.disable(gl.BLEND);
}
}
+
+function getIGLBlendEquation(operation?: IBlendOperation)
+{
+ if (!operation) return undefined;
+
+ const glBlendEquation: IGLBlendEquation = operationMap[operation];
+
+ console.assert(!!glBlendEquation, `接收到错误值,请从 ${Object.keys(operationMap).toString()} 中取值!`);
+
+ return glBlendEquation;
+}
+
+const operationMap: { [key: string]: IGLBlendEquation } = {
+ "add": "FUNC_ADD",
+ "subtract": "FUNC_SUBTRACT",
+ "reverse-subtract": "FUNC_REVERSE_SUBTRACT",
+ "min": "MIN",
+ "max": "MAX",
+};
+
+function getIGLBlendFactor(blendFactor?: IBlendFactor)
+{
+ if (!blendFactor) return undefined;
+
+ const glBlendFactor: IGLBlendFactor = blendFactorMap[blendFactor];
+
+ console.assert(!!glBlendFactor, `接收到错误值,请从 ${Object.keys(blendFactorMap).toString()} 中取值!`);
+
+ return glBlendFactor;
+}
+
+const blendFactorMap: { [key: string]: IGLBlendFactor } = {
+ "zero": "ZERO",
+ "one": "ONE",
+ "src": "SRC_COLOR",
+ "one-minus-src": "ONE_MINUS_SRC_COLOR",
+ "src-alpha": "SRC_ALPHA",
+ "one-minus-src-alpha": "ONE_MINUS_SRC_ALPHA",
+ "dst": "DST_COLOR",
+ "one-minus-dst": "ONE_MINUS_DST_COLOR",
+ "dst-alpha": "DST_ALPHA",
+ "one-minus-dst-alpha": "ONE_MINUS_DST_ALPHA",
+ "src-alpha-saturated": "SRC_ALPHA_SATURATE",
+ "constant": "CONSTANT_COLOR",
+ "one-minus-constant": "ONE_MINUS_CONSTANT_COLOR",
+};
+
+/**
+ * 混合因子(R分量系数,G分量系数,B分量系数)
+ *
+ * 混合颜色的公式可以这样描述:color(RGBA) = (sourceColor * sfactor) + (destinationColor * dfactor)。这里的 RGBA 值均在0与1之间。
+ *
+ * The formula for the blending color can be described like this: color(RGBA) = (sourceColor * sfactor) + (destinationColor * dfactor). The RBGA values are between 0 and 1.
+ *
+ * * `ZERO` Factor: (0,0,0,0); 把所有颜色都乘以0。
+ * * `ONE` Factor: (1,1,1,1); 把所有颜色都乘以1。
+ * * `SRC_COLOR` Factor: (Rs, Gs, Bs, As); 将所有颜色乘以源颜色。
+ * * `ONE_MINUS_SRC_COLOR` Factor: (1-Rs, 1-Gs, 1-Bs, 1-As); 将所有颜色乘以1减去每个源颜色。
+ * * `DST_COLOR` Factor: (Rd, Gd, Bd, Ad); 将所有颜色乘以目标颜色。
+ * * `ONE_MINUS_DST_COLOR` Factor: (1-Rd, 1-Gd, 1-Bd, 1-Ad); 将所有颜色乘以1减去每个目标颜色。
+ * * `SRC_ALPHA` Factor: (As, As, As, As); 将所有颜色乘以源alpha值。
+ * * `ONE_MINUS_SRC_ALPHA` Factor: (1-As, 1-As, 1-As, 1-As); 将所有颜色乘以1减去源alpha值。
+ * * `DST_ALPHA` Factor: (Ad, Ad, Ad, Ad); 将所有颜色乘以目标alpha值。
+ * * `ONE_MINUS_DST_ALPHA` Factor: (1-Ad, 1-Ad, 1-Ad, 1-Ad); 将所有颜色乘以1减去目标alpha值。
+ * * `CONSTANT_COLOR` Factor: (Rc, Gc, Bc, Ac); 将所有颜色乘以一个常数颜色。
+ * * `ONE_MINUS_CONSTANT_COLOR` Factor: (1-Rc, 1-Gc, 1-Bc, 1-Ac); 所有颜色乘以1减去一个常数颜色。
+ * * `CONSTANT_ALPHA` Factor: (Ac, Ac, Ac, Ac); 将所有颜色乘以一个常量alpha值。
+ * * `ONE_MINUS_CONSTANT_ALPHA` Factor: (1-Ac, 1-Ac, 1-Ac, 1-Ac); 将所有颜色乘以1减去一个常数alpha值。
+ * * `SRC_ALPHA_SATURATE` Factor: (min(As, 1 - Ad), min(As, 1 - Ad), min(As, 1 - Ad), 1); 将RGB颜色乘以源alpha值与1减去目标alpha值的较小值。alpha值乘以1。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc
+ */
+export type IGLBlendFactor = "ZERO" | "ONE" | "SRC_COLOR" | "ONE_MINUS_SRC_COLOR" | "DST_COLOR" | "ONE_MINUS_DST_COLOR" | "SRC_ALPHA" | "ONE_MINUS_SRC_ALPHA" | "DST_ALPHA" | "ONE_MINUS_DST_ALPHA" | "SRC_ALPHA_SATURATE" | "CONSTANT_COLOR" | "ONE_MINUS_CONSTANT_COLOR" | "CONSTANT_ALPHA" | "ONE_MINUS_CONSTANT_ALPHA";
+
+/**
+ * 混合方法
+ *
+ * * FUNC_ADD 源 + 目标
+ * * FUNC_SUBTRACT 源 - 目标
+ * * FUNC_REVERSE_SUBTRACT 目标 - 源
+ * * MIN 源与目标的最小值,在 WebGL 2 中可使用。在 WebGL 1 时,自动使用 EXT_blend_minmax 扩展中 MIN_EXT 值。
+ * * MAX 源与目标的最大值,在 WebGL 2 中可使用。在 WebGL 1 时,自动使用 EXT_blend_minmax 扩展中 MAX_EXT 值。
+ *
+ * A GLenum specifying how source and destination colors are combined. Must be either:
+ *
+ * * gl.FUNC_ADD: source + destination (default value)
+ * * gl.FUNC_SUBTRACT: source - destination
+ * * gl.FUNC_REVERSE_SUBTRACT: destination - source
+ *
+ * When using the EXT_blend_minmax extension:
+ *
+ * * ext.MIN_EXT: Minimum of source and destination
+ * * ext.MAX_EXT: Maximum of source and destination
+ *
+ * When using a WebGL 2 context, the following values are available additionally:
+ *
+ * * gl.MIN: Minimum of source and destination
+ * * gl.MAX: Maximum of source and destination
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendEquation
+ */
+export type IGLBlendEquation = "FUNC_ADD" | "FUNC_SUBTRACT" | "FUNC_REVERSE_SUBTRACT" | "MIN" | "MAX";
--
Gitee
From 973ae7b7a2216a3330c22d6160eb2dedb4004dc3 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 13 Dec 2024 20:05:49 +0800
Subject: [PATCH 107/186] IRenderPipeline.depthStencil
---
src/data/IGLDepthStencilState.ts | 15 ---------------
src/data/IGLRenderPipeline.ts | 20 ++++++++++++++++++--
src/runs/runDepthStencilState.ts | 6 +++---
3 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/src/data/IGLDepthStencilState.ts b/src/data/IGLDepthStencilState.ts
index 6612328..b779f1d 100644
--- a/src/data/IGLDepthStencilState.ts
+++ b/src/data/IGLDepthStencilState.ts
@@ -1,18 +1,3 @@
-/**
- * 深度模板状态。
- */
-export interface IGLDepthStencilState
-{
- /**
- * 深度状态。
- */
- depth?: IGLDepthState;
-
- /**
- * 模板状态。
- */
- stencil?: IGLStencilState;
-}
/**
* 深度状态。
diff --git a/src/data/IGLRenderPipeline.ts b/src/data/IGLRenderPipeline.ts
index 598aaeb..a48ed81 100644
--- a/src/data/IGLRenderPipeline.ts
+++ b/src/data/IGLRenderPipeline.ts
@@ -1,5 +1,5 @@
import { IBlendComponent, IBlendState, IColorTargetState, IRenderPipeline } from "@feng3d/render-api";
-import { IGLDepthStencilState } from "./IGLDepthStencilState";
+import { IGLDepthState, IGLStencilState } from "./IGLDepthStencilState";
declare module "@feng3d/render-api"
{
@@ -11,7 +11,7 @@ declare module "@feng3d/render-api"
/**
* 描述可选的深度模板的测试、运算以及偏差。
*/
- depthStencil?: IGLDepthStencilState;
+ readonly depthStencil?: IDepthStencilState;
/**
* 回写变量。
@@ -27,6 +27,22 @@ declare module "@feng3d/render-api"
*/
rasterizerDiscard?: boolean;
}
+
+ /**
+ * 深度模板状态。
+ */
+ export interface IDepthStencilState
+ {
+ /**
+ * 深度状态。
+ */
+ depth?: IGLDepthState;
+
+ /**
+ * 模板状态。
+ */
+ stencil?: IGLStencilState;
+ }
}
export interface ITransformFeedbackVaryings
diff --git a/src/runs/runDepthStencilState.ts b/src/runs/runDepthStencilState.ts
index 33f9669..132c259 100644
--- a/src/runs/runDepthStencilState.ts
+++ b/src/runs/runDepthStencilState.ts
@@ -1,10 +1,10 @@
-import { IGLDepthStencilState } from "../data/IGLDepthStencilState";
+import { IDepthStencilState } from "@feng3d/render-api";
import { defaultDepthState, runDepthState } from "./runDepthState";
import { defaultStencilState, runStencilState } from "./runStencilState";
-export const defaultDepthStencilState: IGLDepthStencilState = Object.freeze({ depth: defaultDepthState, stencil: defaultStencilState });
+export const defaultDepthStencilState: IDepthStencilState = Object.freeze({ depth: defaultDepthState, stencil: defaultStencilState });
-export function runDepthStencilState(gl: WebGLRenderingContext, depthStencil?: IGLDepthStencilState)
+export function runDepthStencilState(gl: WebGLRenderingContext, depthStencil?: IDepthStencilState)
{
runDepthState(gl, depthStencil?.depth || defaultDepthStencilState.depth);
runStencilState(gl, depthStencil?.stencil || defaultDepthStencilState.stencil);
--
Gitee
From 9808a5128a00ab936af27e14ca48b1658ef3d4d0 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 14 Dec 2024 00:16:09 +0800
Subject: [PATCH 108/186] IStencilFaceState
---
src/data/IGLDepthStencilState.ts | 36 ++++++++++++++++----------------
src/runs/runDepthStencilState.ts | 2 +-
src/runs/runStencilState.ts | 2 +-
3 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/src/data/IGLDepthStencilState.ts b/src/data/IGLDepthStencilState.ts
index b779f1d..dc5f101 100644
--- a/src/data/IGLDepthStencilState.ts
+++ b/src/data/IGLDepthStencilState.ts
@@ -95,31 +95,40 @@ export interface IGLStencilState
export interface IStencilFaceState
{
/**
- * 描述模板测试的方法。默认ALWAYS,总是通过。
+ * 一个为模板测试指定参考值。这个值被限制在0到2^n -1的范围内,其中n是模板缓冲区中的位数。默认0。
*
- * A GLenum specifying the test function. The default function is gl.ALWAYS.
+ * A GLint specifying the reference value for the stencil test. This value is clamped to the range 0 to 2^n -1 where n is the number of bitplanes in the stencil buffer. The default value is 0.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilFunc
*/
- stencilFunc?: IGLStencilFunc;
+ stencilFuncRef?: number;
/**
- * 一个为模板测试指定参考值。这个值被限制在0到2^n -1的范围内,其中n是模板缓冲区中的位数。默认0。
+ * 模板测试时使用的mask值,默认全为1(0xFFFFFFFF)。
*
- * A GLint specifying the reference value for the stencil test. This value is clamped to the range 0 to 2^n -1 where n is the number of bitplanes in the stencil buffer. The default value is 0.
+ * A GLuint specifying a bit-wise mask that is used to AND the reference value and the stored stencil value when the test is done. The default value is all 1.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilFunc
*/
- stencilFuncRef?: number;
+ stencilFuncMask?: number;
/**
- * 模板测试时使用的mask值,默认全为1(0b11111111)。
+ * 指定位掩码以启用或禁用在模板平面中写入单个位的正整数。默认全为1(0xFFFFFFFF)。
*
- * A GLuint specifying a bit-wise mask that is used to AND the reference value and the stored stencil value when the test is done. The default value is all 1.
+ * A GLuint specifying a bit mask to enable or disable writing of individual bits in the stencil planes. By default, the mask is all 1.
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilMask
+ */
+ stencilMask?: number;
+
+ /**
+ * 描述模板测试的方法。默认ALWAYS,总是通过。
+ *
+ * A GLenum specifying the test function. The default function is gl.ALWAYS.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilFunc
*/
- stencilFuncMask?: number;
+ stencilFunc?: IGLStencilFunc;
/**
* 指定模板测试失败时使用的函数的枚举。默认KEEP,保持当前值。
@@ -147,15 +156,6 @@ export interface IStencilFaceState
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilOp
*/
stencilOpZPass?: IGLStencilOp;
-
- /**
- * 指定位掩码以启用或禁用在模板平面中写入单个位的正整数。默认全为1(0b11111111)。
- *
- * A GLuint specifying a bit mask to enable or disable writing of individual bits in the stencil planes. By default, the mask is all 1.
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilMask
- */
- stencilMask?: number;
}
/**
diff --git a/src/runs/runDepthStencilState.ts b/src/runs/runDepthStencilState.ts
index 132c259..f9fd1d5 100644
--- a/src/runs/runDepthStencilState.ts
+++ b/src/runs/runDepthStencilState.ts
@@ -6,6 +6,6 @@ export const defaultDepthStencilState: IDepthStencilState = Object.freeze({ dept
export function runDepthStencilState(gl: WebGLRenderingContext, depthStencil?: IDepthStencilState)
{
- runDepthState(gl, depthStencil?.depth || defaultDepthStencilState.depth);
+ runDepthState(gl, depthStencil?.depth);
runStencilState(gl, depthStencil?.stencil || defaultDepthStencilState.stencil);
}
diff --git a/src/runs/runStencilState.ts b/src/runs/runStencilState.ts
index a570907..f2a9e4a 100644
--- a/src/runs/runStencilState.ts
+++ b/src/runs/runStencilState.ts
@@ -1,6 +1,6 @@
import { IStencilFaceState, IGLStencilState } from "../data/IGLDepthStencilState";
-const defaultStencilFaceState: IStencilFaceState = { stencilFunc: "ALWAYS", stencilFuncRef: 0, stencilFuncMask: 0b11111111, stencilOpFail: "KEEP", stencilOpZFail: "KEEP", stencilOpZPass: "KEEP", stencilMask: 0b11111111 };
+const defaultStencilFaceState: IStencilFaceState = { stencilFunc: "ALWAYS", stencilFuncRef: 0, stencilFuncMask: 0xFFFFFFFF, stencilOpFail: "KEEP", stencilOpZFail: "KEEP", stencilOpZPass: "KEEP", stencilMask: 0xFFFFFFFF };
export const defaultStencilState: IGLStencilState = { useStencil: false, stencilFront: defaultStencilFaceState, stencilBack: defaultStencilFaceState };
export function runStencilState(gl: WebGLRenderingContext, stencil: IGLStencilState)
--
Gitee
From d3f3a2a70fd573d9b698b88b008a1ce04bb19285 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 14 Dec 2024 02:12:06 +0800
Subject: [PATCH 109/186] runDepthState runStencilState
---
.../WebGL2Samples/fbo_rtt_depth_texture.ts | 2 +-
.../src/WebGL2Samples/geo_vertex_format.ts | 2 +-
.../glsl_flat_smooth_interpolators.ts | 4 +-
examples/src/WebGL2Samples/query_occlusion.ts | 2 +-
.../src/WebGL2Samples/texture_derivative.ts | 2 +-
examples/src/WebGL2Samples/texture_grad.ts | 2 +-
examples/src/WebGL2Samples/texture_vertex.ts | 2 +-
examples/src/regl-examples/basic.ts | 2 +-
examples/src/regl-examples/batch.ts | 2 +-
examples/src/regl-examples/blur.ts | 2 +-
examples/src/regl-examples/bunny.ts | 2 +-
examples/src/regl-examples/camera.ts | 2 +-
examples/src/regl-examples/cloth.ts | 2 +-
examples/src/regl-examples/cube.ts | 2 +-
examples/src/webgl-examples/sample2.ts | 2 +-
examples/src/webgl-examples/sample3.ts | 2 +-
examples/src/webgl-examples/sample4.ts | 2 +-
examples/src/webgl-examples/sample5.ts | 2 +-
examples/src/webgl-examples/sample6.ts | 2 +-
examples/src/webgl-examples/sample7.ts | 2 +-
examples/src/webgl-examples/sample8.ts | 2 +-
src/data/IGLRenderPipeline.ts | 22 -----
src/runs/runDepthState.ts | 38 ++++++---
src/runs/runDepthStencilState.ts | 10 +--
src/runs/runStencilState.ts | 82 ++++++++++++++-----
25 files changed, 117 insertions(+), 79 deletions(-)
diff --git a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
index ff5e2a2..74e0cb2 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
@@ -21,7 +21,7 @@ const windowSize = {
// Depth shaders
const depthProgram: IRenderPipeline = {
vertex: { code: getShaderSource("vs-depth") }, fragment: { code: getShaderSource("fs-depth") },
- depthStencil: { depth: { depthtest: true } },
+ depthStencil: {},
primitive: { topology: "triangle-list" },
};
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index 15fc61e..de4fdba 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -19,7 +19,7 @@ import { getShaderSource, loadImage } from "./utility";
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "triangle-list", cullFace: "back" },
- depthStencil: { depth: { depthtest: true } },
+ depthStencil: { },
};
// -- Init geometries
diff --git a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
index d491b69..c28ae53 100644
--- a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
+++ b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
@@ -48,12 +48,12 @@ const programs: IRenderPipeline[] = [
{
vertex: { code: getShaderSource("vs-flat") }, fragment: { code: getShaderSource("fs-flat") },
primitive: { topology: "triangle-list" },
- depthStencil: { depth: { depthtest: true, depthCompare: "LEQUAL" } },
+ depthStencil: { depthCompare: "less-equal" },
},
{
vertex: { code: getShaderSource("vs-smooth") }, fragment: { code: getShaderSource("fs-smooth") },
primitive: { topology: "triangle-list" },
- depthStencil: { depth: { depthtest: true, depthCompare: "LEQUAL" } },
+ depthStencil: { depthCompare: "less-equal" },
}
];
// -- Load gltf then render
diff --git a/examples/src/WebGL2Samples/query_occlusion.ts b/examples/src/WebGL2Samples/query_occlusion.ts
index 8cb9efa..d0a484e 100644
--- a/examples/src/WebGL2Samples/query_occlusion.ts
+++ b/examples/src/WebGL2Samples/query_occlusion.ts
@@ -19,7 +19,7 @@ const webgl = new WebGL(rc);
// -- Init Program
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
- depthStencil: { depth: { depthtest: true } },
+ depthStencil: {},
primitive: { topology: "triangle-list" },
};
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index 7f3409f..ef788f2 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -22,7 +22,7 @@ import { getShaderSource, loadImage } from "./utility";
}]
},
- depthStencil: { depth: { depthtest: true } },
+ depthStencil: {},
primitive: { topology: "triangle-list", cullFace: "back" }
};
diff --git a/examples/src/WebGL2Samples/texture_grad.ts b/examples/src/WebGL2Samples/texture_grad.ts
index e5808b3..e32dfdf 100644
--- a/examples/src/WebGL2Samples/texture_grad.ts
+++ b/examples/src/WebGL2Samples/texture_grad.ts
@@ -18,7 +18,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init program
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
- depthStencil: { depth: { depthtest: true } },
+ depthStencil: {},
primitive: { cullFace: "back" },
};
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index 4a9eb3f..092d9fc 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -42,7 +42,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init program
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
- depthStencil: { depth: { depthtest: true, depthCompare: "LESS" } },
+ depthStencil: { depthCompare:"less" },
};
const vertexArrayMaps: { [key: string]: { vertices?: IGLVertexAttributes, indices: IGLIndicesDataTypes }[] } = {};
diff --git a/examples/src/regl-examples/basic.ts b/examples/src/regl-examples/basic.ts
index 6e7ea6f..99d9c48 100644
--- a/examples/src/regl-examples/basic.ts
+++ b/examples/src/regl-examples/basic.ts
@@ -47,7 +47,7 @@ const renderObject: IRenderObject = {
`,
targets: [{ blend: {} }],
},
- depthStencil: { depth: { depthtest: true } },
+ depthStencil: {},
}
};
diff --git a/examples/src/regl-examples/batch.ts b/examples/src/regl-examples/batch.ts
index 35fbb5d..49547aa 100644
--- a/examples/src/regl-examples/batch.ts
+++ b/examples/src/regl-examples/batch.ts
@@ -38,7 +38,7 @@ const pipeline: IRenderPipeline = {
void main() {
gl_FragColor = color;
}` },
- depthStencil: { depth: { depthtest: true } },
+ depthStencil: {},
};
const vertexArray: { vertices?: IGLVertexAttributes } = {
diff --git a/examples/src/regl-examples/blur.ts b/examples/src/regl-examples/blur.ts
index 40eb769..19bad40 100644
--- a/examples/src/regl-examples/blur.ts
+++ b/examples/src/regl-examples/blur.ts
@@ -62,7 +62,7 @@ const pipeline: IRenderPipeline = {
}`,
targets: [{ blend: {} }],
},
- depthStencil: { depth: { depthtest: true } },
+ depthStencil: {},
};
function getRenderObject(tick: number, batchId: number)
diff --git a/examples/src/regl-examples/bunny.ts b/examples/src/regl-examples/bunny.ts
index 9885f81..6d5c155 100644
--- a/examples/src/regl-examples/bunny.ts
+++ b/examples/src/regl-examples/bunny.ts
@@ -68,7 +68,7 @@ const renderObject: IRenderObject = {
}`,
targets: [{ blend: {} }],
},
- depthStencil: { depth: { depthtest: true } },
+ depthStencil: {},
}
};
diff --git a/examples/src/regl-examples/camera.ts b/examples/src/regl-examples/camera.ts
index 5d670c2..035226c 100644
--- a/examples/src/regl-examples/camera.ts
+++ b/examples/src/regl-examples/camera.ts
@@ -63,7 +63,7 @@ const renderObject: IRenderObject = {
}`,
targets: [{ blend: {} }],
},
- depthStencil: { depth: { depthtest: true } },
+ depthStencil: {},
}
};
diff --git a/examples/src/regl-examples/cloth.ts b/examples/src/regl-examples/cloth.ts
index 717c05c..3b8bef7 100644
--- a/examples/src/regl-examples/cloth.ts
+++ b/examples/src/regl-examples/cloth.ts
@@ -225,7 +225,7 @@ import * as vec3 from "./stackgl/gl-vec3";
}`,
targets: [{ blend: {} }],
},
- depthStencil: { depth: { depthtest: true } },
+ depthStencil: {},
}
};
diff --git a/examples/src/regl-examples/cube.ts b/examples/src/regl-examples/cube.ts
index 77459f0..f0fff39 100644
--- a/examples/src/regl-examples/cube.ts
+++ b/examples/src/regl-examples/cube.ts
@@ -108,7 +108,7 @@ import * as mat4 from "./stackgl/gl-mat4";
}`,
targets: [{ blend: {} }],
},
- depthStencil: { depth: { depthtest: true } },
+ depthStencil: {},
}
};
diff --git a/examples/src/webgl-examples/sample2.ts b/examples/src/webgl-examples/sample2.ts
index 2d9310d..6756148 100644
--- a/examples/src/webgl-examples/sample2.ts
+++ b/examples/src/webgl-examples/sample2.ts
@@ -40,7 +40,7 @@ function main()
void main() {
gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);
}` },
- depthStencil: { depth: { depthCompare: "LEQUAL" } }
+ depthStencil: { depthCompare: "less-equal" }
},
vertices: {
aVertexPosition: {
diff --git a/examples/src/webgl-examples/sample3.ts b/examples/src/webgl-examples/sample3.ts
index 14ce55c..0377ec6 100644
--- a/examples/src/webgl-examples/sample3.ts
+++ b/examples/src/webgl-examples/sample3.ts
@@ -52,7 +52,7 @@ function main()
gl_FragColor = vColor;
}
` },
- depthStencil: { depth: { depthtest: true, depthCompare: "LEQUAL" } }
+ depthStencil: { depthCompare: "less-equal" }
},
vertices: {
aVertexPosition: {
diff --git a/examples/src/webgl-examples/sample4.ts b/examples/src/webgl-examples/sample4.ts
index 465ddd4..ed46460 100644
--- a/examples/src/webgl-examples/sample4.ts
+++ b/examples/src/webgl-examples/sample4.ts
@@ -40,7 +40,7 @@ function main()
gl_FragColor = vColor;
}
` },
- depthStencil: { depth: { depthtest: true, depthCompare: "LEQUAL" } }
+ depthStencil: { depthCompare: "less-equal" }
},
vertices: {
aVertexPosition: {
diff --git a/examples/src/webgl-examples/sample5.ts b/examples/src/webgl-examples/sample5.ts
index 771a418..f240259 100644
--- a/examples/src/webgl-examples/sample5.ts
+++ b/examples/src/webgl-examples/sample5.ts
@@ -44,7 +44,7 @@ function main()
gl_FragColor = vColor;
}
` },
- depthStencil: { depth: { depthtest: true, depthCompare: "LEQUAL" } }
+ depthStencil: { depthCompare: "less-equal" }
},
vertices: {
aVertexPosition: {
diff --git a/examples/src/webgl-examples/sample6.ts b/examples/src/webgl-examples/sample6.ts
index f2bfb3a..377f369 100644
--- a/examples/src/webgl-examples/sample6.ts
+++ b/examples/src/webgl-examples/sample6.ts
@@ -48,7 +48,7 @@ async function main()
gl_FragColor = texture2D(uSampler, vTextureCoord);
}
` },
- depthStencil: { depth: { depthtest: true, depthCompare: "LEQUAL" } }
+ depthStencil: { depthCompare: "less-equal" }
},
vertices: {
aVertexPosition: {
diff --git a/examples/src/webgl-examples/sample7.ts b/examples/src/webgl-examples/sample7.ts
index 75f921a..42839b8 100644
--- a/examples/src/webgl-examples/sample7.ts
+++ b/examples/src/webgl-examples/sample7.ts
@@ -65,7 +65,7 @@ async function main()
gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);
}
` },
- depthStencil: { depth: { depthtest: true, depthCompare: "LEQUAL" } }
+ depthStencil: { depthCompare: "less-equal" }
},
vertices: {
aVertexPosition: {
diff --git a/examples/src/webgl-examples/sample8.ts b/examples/src/webgl-examples/sample8.ts
index db7ab9f..fe04324 100644
--- a/examples/src/webgl-examples/sample8.ts
+++ b/examples/src/webgl-examples/sample8.ts
@@ -69,7 +69,7 @@ function main()
gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);
}
` },
- depthStencil: { depth: { depthtest: true, depthCompare: "LEQUAL" } }
+ depthStencil: { depthCompare: "less-equal" }
},
vertices: {
aVertexPosition: {
diff --git a/src/data/IGLRenderPipeline.ts b/src/data/IGLRenderPipeline.ts
index a48ed81..e7d5bc2 100644
--- a/src/data/IGLRenderPipeline.ts
+++ b/src/data/IGLRenderPipeline.ts
@@ -1,5 +1,4 @@
import { IBlendComponent, IBlendState, IColorTargetState, IRenderPipeline } from "@feng3d/render-api";
-import { IGLDepthState, IGLStencilState } from "./IGLDepthStencilState";
declare module "@feng3d/render-api"
{
@@ -8,11 +7,6 @@ declare module "@feng3d/render-api"
*/
export interface IRenderPipeline
{
- /**
- * 描述可选的深度模板的测试、运算以及偏差。
- */
- readonly depthStencil?: IDepthStencilState;
-
/**
* 回写变量。
*
@@ -27,22 +21,6 @@ declare module "@feng3d/render-api"
*/
rasterizerDiscard?: boolean;
}
-
- /**
- * 深度模板状态。
- */
- export interface IDepthStencilState
- {
- /**
- * 深度状态。
- */
- depth?: IGLDepthState;
-
- /**
- * 模板状态。
- */
- stencil?: IGLStencilState;
- }
}
export interface ITransformFeedbackVaryings
diff --git a/src/runs/runDepthState.ts b/src/runs/runDepthState.ts
index 0cf91f1..442e34e 100644
--- a/src/runs/runDepthState.ts
+++ b/src/runs/runDepthState.ts
@@ -1,21 +1,24 @@
-import { IGLDepthState } from "../data/IGLDepthStencilState";
+import { ICompareFunction, IDepthStencilState } from "@feng3d/render-api";
+import { IGLCompareFunction } from "../data/IGLDepthStencilState";
-export function runDepthState(gl: WebGLRenderingContext, depth: IGLDepthState)
+export function runDepthState(gl: WebGLRenderingContext, depthStencil?: IDepthStencilState)
{
- const { depthtest, depthCompare, depthWriteEnabled, depthBias } = { ...defaultDepthState, ...depth };
-
- if (depthtest)
+ if (depthStencil && (depthStencil.depthWriteEnabled || depthStencil.depthCompare !== "always"))
{
+ const depthCompare: IGLCompareFunction = getIGLCompareFunction(depthStencil.depthCompare ?? 'less');
+ const depthWriteEnabled = depthStencil.depthWriteEnabled ?? true;
+ //
gl.enable(gl.DEPTH_TEST);
//
gl.depthFunc(gl[depthCompare]);
gl.depthMask(depthWriteEnabled);
//
- if (depthBias)
+ if (depthStencil.depthBias || depthStencil.depthBiasSlopeScale)
{
- const { factor, units } = depthBias;
-
+ const factor = depthStencil.depthBiasSlopeScale ?? 0;
+ const units = depthStencil.depthBias ?? 0;
+ //
gl.enable(gl.POLYGON_OFFSET_FILL);
gl.polygonOffset(factor, units);
}
@@ -30,5 +33,20 @@ export function runDepthState(gl: WebGLRenderingContext, depth: IGLDepthState)
}
}
-export const defaultDepthState: IGLDepthState = { depthtest: false, depthWriteEnabled: true, depthCompare: "LESS" };
-Object.freeze(defaultDepthState);
\ No newline at end of file
+function getIGLCompareFunction(depthCompare: ICompareFunction)
+{
+ const glDepthCompare: IGLCompareFunction = depthCompareMap[depthCompare];
+
+ return glDepthCompare;
+}
+
+const depthCompareMap: { [key: string]: IGLCompareFunction } = {
+ "never": "NEVER",
+ "less": "LESS",
+ "equal": "EQUAL",
+ "less-equal": "LEQUAL",
+ "greater": "GREATER",
+ "not-equal": "NOTEQUAL",
+ "greater-equal": "GEQUAL",
+ "always": "ALWAYS",
+};
\ No newline at end of file
diff --git a/src/runs/runDepthStencilState.ts b/src/runs/runDepthStencilState.ts
index f9fd1d5..52bc43b 100644
--- a/src/runs/runDepthStencilState.ts
+++ b/src/runs/runDepthStencilState.ts
@@ -1,11 +1,9 @@
import { IDepthStencilState } from "@feng3d/render-api";
-import { defaultDepthState, runDepthState } from "./runDepthState";
-import { defaultStencilState, runStencilState } from "./runStencilState";
-
-export const defaultDepthStencilState: IDepthStencilState = Object.freeze({ depth: defaultDepthState, stencil: defaultStencilState });
+import { runDepthState } from "./runDepthState";
+import { runStencilState } from "./runStencilState";
export function runDepthStencilState(gl: WebGLRenderingContext, depthStencil?: IDepthStencilState)
{
- runDepthState(gl, depthStencil?.depth);
- runStencilState(gl, depthStencil?.stencil || defaultDepthStencilState.stencil);
+ runDepthState(gl, depthStencil);
+ runStencilState(gl, depthStencil);
}
diff --git a/src/runs/runStencilState.ts b/src/runs/runStencilState.ts
index f2a9e4a..b2c8f74 100644
--- a/src/runs/runStencilState.ts
+++ b/src/runs/runStencilState.ts
@@ -1,33 +1,77 @@
-import { IStencilFaceState, IGLStencilState } from "../data/IGLDepthStencilState";
+import { ICompareFunction, IDepthStencilState, IStencilOperation } from "@feng3d/render-api";
+import { IGLStencilFunc, IGLStencilOp } from "../data/IGLDepthStencilState";
-const defaultStencilFaceState: IStencilFaceState = { stencilFunc: "ALWAYS", stencilFuncRef: 0, stencilFuncMask: 0xFFFFFFFF, stencilOpFail: "KEEP", stencilOpZFail: "KEEP", stencilOpZPass: "KEEP", stencilMask: 0xFFFFFFFF };
-export const defaultStencilState: IGLStencilState = { useStencil: false, stencilFront: defaultStencilFaceState, stencilBack: defaultStencilFaceState };
-
-export function runStencilState(gl: WebGLRenderingContext, stencil: IGLStencilState)
+export function runStencilState(gl: WebGLRenderingContext, depthStencil?: IDepthStencilState)
{
+ const { stencilFront, stencilBack } = { ...depthStencil };
//
- const {
- useStencil, stencilFront, stencilBack,
- } = { ...defaultStencilState, ...stencil };
-
- if (useStencil)
+ if (stencilFront || stencilBack)
{
+ const ref: number = depthStencil.stencilReference ?? 0;
+ const readMask = depthStencil.stencilReadMask ?? 0xFFFFFFFF;
+ const writeMask = depthStencil.stencilWriteMask ?? 0xFFFFFFFF;
+
gl.enable(gl.STENCIL_TEST);
+
+ if (stencilFront)
{
- const { stencilFunc, stencilFuncRef, stencilFuncMask, stencilOpFail, stencilOpZFail, stencilOpZPass, stencilMask } = { ...defaultStencilFaceState, ...stencilFront };
- gl.stencilFuncSeparate(gl.FRONT, gl[stencilFunc], stencilFuncRef, stencilFuncMask);
- gl.stencilOpSeparate(gl.FRONT, gl[stencilOpFail], gl[stencilOpZFail], gl[stencilOpZPass]);
- gl.stencilMaskSeparate(gl.FRONT, stencilMask);
+ const func: IGLStencilFunc = getIGLStencilFunc(stencilFront.compare ?? "always");
+ const fail: IGLStencilOp = getIGLStencilOp(stencilFront.failOp);
+ const zfail: IGLStencilOp = getIGLStencilOp(stencilFront.depthFailOp);
+ const zpass: IGLStencilOp = getIGLStencilOp(stencilFront.passOp);
+ //
+ gl.stencilFuncSeparate(gl.FRONT, gl[func], ref, readMask);
+ gl.stencilOpSeparate(gl.FRONT, gl[fail], gl[zfail], gl[zpass]);
+ gl.stencilMaskSeparate(gl.FRONT, writeMask);
}
+ if (stencilBack)
{
- const { stencilFunc, stencilFuncRef, stencilFuncMask, stencilOpFail, stencilOpZFail, stencilOpZPass, stencilMask } = { ...defaultStencilFaceState, ...stencilBack };
- gl.stencilFuncSeparate(gl.BACK, gl[stencilFunc], stencilFuncRef, stencilFuncMask);
- gl.stencilOpSeparate(gl.BACK, gl[stencilOpFail], gl[stencilOpZFail], gl[stencilOpZPass]);
- gl.stencilMaskSeparate(gl.BACK, stencilMask);
+ const func: IGLStencilFunc = getIGLStencilFunc(stencilBack.compare ?? "always");
+ const fail: IGLStencilOp = getIGLStencilOp(stencilBack.failOp);
+ const zfail: IGLStencilOp = getIGLStencilOp(stencilBack.depthFailOp);
+ const zpass: IGLStencilOp = getIGLStencilOp(stencilBack.passOp);
+ //
+ gl.stencilFuncSeparate(gl.BACK, gl[func], ref, readMask);
+ gl.stencilOpSeparate(gl.BACK, gl[fail], gl[zfail], gl[zpass]);
+ gl.stencilMaskSeparate(gl.BACK, writeMask);
}
}
else
{
gl.disable(gl.STENCIL_TEST);
}
-}
\ No newline at end of file
+}
+
+function getIGLStencilFunc(compare: ICompareFunction)
+{
+ const stencilFunc: IGLStencilFunc = compareMap[compare];
+
+ return stencilFunc;
+}
+const compareMap: { [key: string]: IGLStencilFunc } = {
+ "never": "NEVER",
+ "less": "LESS",
+ "equal": "EQUAL",
+ "less-equal": "LEQUAL",
+ "greater": "GREATER",
+ "not-equal": "NOTEQUAL",
+ "greater-equal": "GEQUAL",
+ "always": "ALWAYS",
+};
+
+function getIGLStencilOp(stencilOperation?: IStencilOperation)
+{
+ const glStencilOp: IGLStencilOp = stencilOperationMap[stencilOperation];
+
+ return glStencilOp;
+}
+const stencilOperationMap: { [key: string]: IGLStencilOp } = {
+ "keep": "KEEP",
+ "zero": "ZERO",
+ "replace": "REPLACE",
+ "invert": "INVERT",
+ "increment-clamp": "INCR",
+ "decrement-clamp": "DECR",
+ "increment-wrap": "INCR_WRAP",
+ "decrement-wrap": "DECR_WRAP",
+};
\ No newline at end of file
--
Gitee
From 6c98fdf6958bf479f727b53d4d89fd4072759e24 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 14 Dec 2024 17:26:59 +0800
Subject: [PATCH 110/186] =?UTF-8?q?=E5=BD=93=E6=B7=B7=E5=90=88=E7=B3=BB?=
=?UTF-8?q?=E6=95=B0=E7=94=A8=E5=88=B0=E4=BA=86=E6=B7=B7=E5=90=88=E5=B8=B8?=
=?UTF-8?q?=E9=87=8F=E5=80=BC=E6=97=B6=E8=AE=BE=E7=BD=AE=E6=B7=B7=E5=90=88?=
=?UTF-8?q?=E5=B8=B8=E9=87=8F=E5=80=BC=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/runs/runColorTargetStates.ts | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/runs/runColorTargetStates.ts b/src/runs/runColorTargetStates.ts
index 86524e3..08024c2 100644
--- a/src/runs/runColorTargetStates.ts
+++ b/src/runs/runColorTargetStates.ts
@@ -21,6 +21,18 @@ export function runColorTargetStates(gl: WebGLRenderingContext, targets?: readon
const alphaSrcFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.srcFactor) || colorSrcFactor;
const alphaDstFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.dstFactor) || colorDstFactor;
+ // 当混合系数用到了混合常量值时设置混合常量值。
+ if (0
+ || colorSrcFactor === "CONSTANT_COLOR"
+ || colorSrcFactor === "ONE_MINUS_CONSTANT_COLOR"
+ || alphaSrcFactor === "CONSTANT_COLOR"
+ || alphaSrcFactor === "ONE_MINUS_CONSTANT_COLOR"
+ )
+ {
+ const blendColor = blend.constantColor ?? [0, 0, 0, 0];
+ gl.blendColor(blendColor[0], blendColor[1], blendColor[2], blendColor[3]);
+ }
+
//
gl.enable(gl.BLEND);
gl.blendEquationSeparate(gl[colorOperation], gl[alphaOperation]);
--
Gitee
From 9e6070fe4590bd2c3bd0eb86cf77a74cac0d745b Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 14 Dec 2024 17:35:51 +0800
Subject: [PATCH 111/186] getBlendConstantColor
---
src/runs/runColorTargetStates.ts | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/src/runs/runColorTargetStates.ts b/src/runs/runColorTargetStates.ts
index 08024c2..c4e7bb2 100644
--- a/src/runs/runColorTargetStates.ts
+++ b/src/runs/runColorTargetStates.ts
@@ -1,4 +1,4 @@
-import { IBlendComponent, IBlendFactor, IBlendOperation, IColorTargetState } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IBlendFactor, IBlendOperation, IColorTargetState } from "@feng3d/render-api";
export function runColorTargetStates(gl: WebGLRenderingContext, targets?: readonly IColorTargetState[])
{
@@ -22,15 +22,11 @@ export function runColorTargetStates(gl: WebGLRenderingContext, targets?: readon
const alphaDstFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.dstFactor) || colorDstFactor;
// 当混合系数用到了混合常量值时设置混合常量值。
- if (0
- || colorSrcFactor === "CONSTANT_COLOR"
- || colorSrcFactor === "ONE_MINUS_CONSTANT_COLOR"
- || alphaSrcFactor === "CONSTANT_COLOR"
- || alphaSrcFactor === "ONE_MINUS_CONSTANT_COLOR"
- )
+ const constantColor = getBlendConstantColor(blend);
+ if (constantColor)
{
- const blendColor = blend.constantColor ?? [0, 0, 0, 0];
- gl.blendColor(blendColor[0], blendColor[1], blendColor[2], blendColor[3]);
+ const constantColor = blend.constantColor ?? [0, 0, 0, 0];
+ gl.blendColor(constantColor[0], constantColor[1], constantColor[2], constantColor[3]);
}
//
--
Gitee
From d306bf8aab8036f699dc60ca6c728e160bb4dd5c Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 14 Dec 2024 18:43:45 +0800
Subject: [PATCH 112/186] getBlendConstantColor
---
src/runs/runColorTargetStates.ts | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/runs/runColorTargetStates.ts b/src/runs/runColorTargetStates.ts
index c4e7bb2..c698073 100644
--- a/src/runs/runColorTargetStates.ts
+++ b/src/runs/runColorTargetStates.ts
@@ -14,12 +14,12 @@ export function runColorTargetStates(gl: WebGLRenderingContext, targets?: readon
const alpha: IBlendComponent = blend.alpha;
const colorOperation: IGLBlendEquation = getIGLBlendEquation(color?.operation) || "FUNC_ADD";
- const colorSrcFactor: IGLBlendFactor = getIGLBlendFactor(color?.srcFactor) || "SRC_ALPHA";
- const colorDstFactor: IGLBlendFactor = getIGLBlendFactor(color?.dstFactor) || "ONE_MINUS_SRC_ALPHA";
+ const colorSrcFactor: IGLBlendFactor = getIGLBlendFactor(color?.srcFactor, color?.operation) || "SRC_ALPHA";
+ const colorDstFactor: IGLBlendFactor = getIGLBlendFactor(color?.dstFactor, color?.operation) || "ONE_MINUS_SRC_ALPHA";
//
const alphaOperation: IGLBlendEquation = getIGLBlendEquation(alpha?.operation) || colorOperation;
- const alphaSrcFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.srcFactor) || colorSrcFactor;
- const alphaDstFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.dstFactor) || colorDstFactor;
+ const alphaSrcFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.srcFactor, color?.operation) || colorSrcFactor;
+ const alphaDstFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.dstFactor, color?.operation) || colorDstFactor;
// 当混合系数用到了混合常量值时设置混合常量值。
const constantColor = getBlendConstantColor(blend);
@@ -59,10 +59,12 @@ const operationMap: { [key: string]: IGLBlendEquation } = {
"max": "MAX",
};
-function getIGLBlendFactor(blendFactor?: IBlendFactor)
+function getIGLBlendFactor(blendFactor: IBlendFactor, operation: IBlendOperation)
{
if (!blendFactor) return undefined;
+ if (operation === "max" || operation === "min") blendFactor = "one";
+
const glBlendFactor: IGLBlendFactor = blendFactorMap[blendFactor];
console.assert(!!glBlendFactor, `接收到错误值,请从 ${Object.keys(blendFactorMap).toString()} 中取值!`);
--
Gitee
From 1c904465c2fd43d697b4952ebe14446d66b4a0dd Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 14 Dec 2024 20:23:59 +0800
Subject: [PATCH 113/186] IRenderObject.vertices
---
examples/src/WebGL2Samples/buffer_copy.ts | 4 +-
examples/src/WebGL2Samples/buffer_uniform.ts | 4 +-
examples/src/WebGL2Samples/draw_instanced.ts | 4 +-
.../WebGL2Samples/draw_primitive_restart.ts | 4 +-
.../src/WebGL2Samples/draw_range_arrays.ts | 4 +-
examples/src/WebGL2Samples/fbo_blit.ts | 6 +-
examples/src/WebGL2Samples/fbo_multisample.ts | 4 +-
.../WebGL2Samples/fbo_new_blend_equation.ts | 4 +-
examples/src/WebGL2Samples/fbo_read_pixels.ts | 6 +-
.../WebGL2Samples/fbo_rtt_depth_texture.ts | 6 +-
.../src/WebGL2Samples/fbo_rtt_draw_buffers.ts | 6 +-
.../WebGL2Samples/fbo_rtt_texture_array.ts | 6 +-
.../src/WebGL2Samples/geo_vertex_format.ts | 4 +-
examples/src/WebGL2Samples/glsl_centroid.ts | 4 +-
.../glsl_flat_smooth_interpolators.ts | 6 +-
.../WebGL2Samples/glsl_non_square_matrix.ts | 4 +-
examples/src/WebGL2Samples/query_occlusion.ts | 4 +-
examples/src/WebGL2Samples/sampler_filter.ts | 4 +-
examples/src/WebGL2Samples/sampler_object.ts | 4 +-
examples/src/WebGL2Samples/sampler_wrap.ts | 4 +-
.../src/WebGL2Samples/texture_2d_array.ts | 4 +-
examples/src/WebGL2Samples/texture_3d.ts | 4 +-
.../src/WebGL2Samples/texture_derivative.ts | 4 +-
examples/src/WebGL2Samples/texture_fetch.ts | 4 +-
examples/src/WebGL2Samples/texture_format.ts | 4 +-
examples/src/WebGL2Samples/texture_grad.ts | 4 +-
.../src/WebGL2Samples/texture_immutable.ts | 4 +-
examples/src/WebGL2Samples/texture_integer.ts | 4 +-
examples/src/WebGL2Samples/texture_lod.ts | 4 +-
examples/src/WebGL2Samples/texture_offset.ts | 4 +-
.../src/WebGL2Samples/texture_pixel_store.ts | 8 +-
examples/src/WebGL2Samples/texture_srgb.ts | 8 +-
examples/src/WebGL2Samples/texture_vertex.ts | 6 +-
.../WebGL2Samples/third-party/gltf-loader.ts | 4 +-
.../transform_feedback_instanced.ts | 20 +--
.../transform_feedback_interleaved.ts | 14 +-
.../transform_feedback_separated.ts | 16 +--
.../transform_feedback_separated_2.ts | 18 +--
examples/src/regl-examples/batch.ts | 4 +-
examples/src/regl-examples/blur.ts | 4 +-
examples/src/webgl-examples/sample2.ts | 3 +-
src/caches/getGLBuffer.ts | 4 +-
src/data/IGLAttributeInfo.ts | 4 +-
src/data/IGLRenderObject.ts | 6 -
src/data/IGLTransformFeedback.ts | 4 +-
src/data/IGLVertexAttributes.ts | 54 +-------
src/index.ts | 1 -
src/runs/getIGLBuffer.ts | 5 +-
src/runs/runDepthState.ts | 2 +
src/runs/runDrawCall.ts | 7 +-
src/runs/runVertexArray.ts | 7 +-
src/runs/runVertexAttribute.ts | 131 ++++++++++++++++--
52 files changed, 257 insertions(+), 205 deletions(-)
diff --git a/examples/src/WebGL2Samples/buffer_copy.ts b/examples/src/WebGL2Samples/buffer_copy.ts
index cdce4ae..c08e0f0 100644
--- a/examples/src/WebGL2Samples/buffer_copy.ts
+++ b/examples/src/WebGL2Samples/buffer_copy.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLCopyBufferToBuffer, IGLVertexAttributes, IGLVertexBuffer, WebGL, getIGLBuffer } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLCopyBufferToBuffer, IVertexAttributes, IGLVertexBuffer, WebGL, getIGLBuffer } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -42,7 +42,7 @@ import { getShaderSource } from "./utility";
};
// -- Init Vertex Array
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
pos: { data: vertexPosBufferDst, numComponents: 2 },
}
diff --git a/examples/src/WebGL2Samples/buffer_uniform.ts b/examples/src/WebGL2Samples/buffer_uniform.ts
index 24c5069..4b6d6e7 100644
--- a/examples/src/WebGL2Samples/buffer_uniform.ts
+++ b/examples/src/WebGL2Samples/buffer_uniform.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLUniformBuffer, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLUniformBuffer, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -68,7 +68,7 @@ import { getShaderSource } from "./utility";
const uniformPerSceneBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", data: material, usage: "STATIC_DRAW" };
// -- Init Vertex Array
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: vertices, numComponents: 3, vertexSize: 40, offset: 0 },
normal: { data: vertices, numComponents: 3, vertexSize: 40, offset: 12 },
diff --git a/examples/src/WebGL2Samples/draw_instanced.ts b/examples/src/WebGL2Samples/draw_instanced.ts
index abb1355..13ba06e 100644
--- a/examples/src/WebGL2Samples/draw_instanced.ts
+++ b/examples/src/WebGL2Samples/draw_instanced.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -24,7 +24,7 @@ const program: IRenderPipeline = {
fragment: { code: getShaderSource("fs"), targets: [{ blend: {} }] }
};
-const vertexArray: { vertices?: IGLVertexAttributes } = {
+const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
pos: { data: vertexPosBuffer, numComponents: 2 },
color: { data: vertexColorBuffer, numComponents: 3, divisor: 1 },
diff --git a/examples/src/WebGL2Samples/draw_primitive_restart.ts b/examples/src/WebGL2Samples/draw_primitive_restart.ts
index b1a9b42..d11fe39 100644
--- a/examples/src/WebGL2Samples/draw_primitive_restart.ts
+++ b/examples/src/WebGL2Samples/draw_primitive_restart.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -37,7 +37,7 @@ const indices = new Uint16Array([
0, 1, 2, MAX_UNSIGNED_SHORT, 2, 3, 1
]);
-const vertexArray: { vertices?: IGLVertexAttributes } = {
+const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
pos: { data: vertexPosBuffer, numComponents: 2 },
},
diff --git a/examples/src/WebGL2Samples/draw_range_arrays.ts b/examples/src/WebGL2Samples/draw_range_arrays.ts
index c75b1a3..4edd8d2 100644
--- a/examples/src/WebGL2Samples/draw_range_arrays.ts
+++ b/examples/src/WebGL2Samples/draw_range_arrays.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -37,7 +37,7 @@ const pipeline: IRenderPipeline = {
}
};
-const vertexArray: { vertices?: IGLVertexAttributes } = {
+const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: vertexPosBuffer, numComponents: 2 },
}
diff --git a/examples/src/WebGL2Samples/fbo_blit.ts b/examples/src/WebGL2Samples/fbo_blit.ts
index e535925..ebe02ac 100644
--- a/examples/src/WebGL2Samples/fbo_blit.ts
+++ b/examples/src/WebGL2Samples/fbo_blit.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, ITextureView } from "@feng3d/render-api";
-import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLSampler, IVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -39,7 +39,7 @@ const vertexTexBuffer = new Float32Array([
0.0, 1.0
]);
-const vertices: IGLVertexAttributes = {
+const vertices: IVertexAttributes = {
position: { data: vertexPosBuffer, numComponents: 2 },
texcoord: { data: vertexTexBuffer, numComponents: 2 },
};
@@ -75,7 +75,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
// 此处 Renderbuffer 直接使用 IGLTextureView 替代。
const colorRenderbuffer: ITextureView = { texture: { format: "rgba8unorm", size: [FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y] } };
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices,
};
diff --git a/examples/src/WebGL2Samples/fbo_multisample.ts b/examples/src/WebGL2Samples/fbo_multisample.ts
index c600b62..d1fcbfe 100644
--- a/examples/src/WebGL2Samples/fbo_multisample.ts
+++ b/examples/src/WebGL2Samples/fbo_multisample.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -83,7 +83,7 @@ const framebuffer: IRenderPassDescriptor = {
};
// -- Init VertexArray
-const vertexArrays: { vertices?: IGLVertexAttributes }[] = [
+const vertexArrays: { vertices?: IVertexAttributes }[] = [
{
vertices: { position: { data: data, numComponents: 2 } }
},
diff --git a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
index 9f9e9d3..7af9071 100644
--- a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
+++ b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -84,7 +84,7 @@ const texcoords = new Float32Array([
]);
// -- Initilize vertex array
-const vertexArray: { vertices?: IGLVertexAttributes } = {
+const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
textureCoordinates: { data: texcoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/fbo_read_pixels.ts b/examples/src/WebGL2Samples/fbo_read_pixels.ts
index 2288325..40c7ede 100644
--- a/examples/src/WebGL2Samples/fbo_read_pixels.ts
+++ b/examples/src/WebGL2Samples/fbo_read_pixels.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -84,13 +84,13 @@ const texcoords = new Float32Array([
// -- Initialize vertex array
-const multipleOutputVertexArray: { vertices?: IGLVertexAttributes } = {
+const multipleOutputVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
}
};
-const layerVertexArray: { vertices?: IGLVertexAttributes } = {
+const layerVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
textureCoordinates: { data: texcoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
index 74e0cb2..04131c0 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -59,13 +59,13 @@ const quadTexcoords = new Float32Array([
// -- Initialize vertex array
-const triVertexArray: { vertices?: IGLVertexAttributes } = {
+const triVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: triPositions, numComponents: 3 },
}
};
-const quadVertexArray: { vertices?: IGLVertexAttributes } = {
+const quadVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: quadPositions, numComponents: 2 },
textureCoordinates: { data: quadTexcoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
index 3885f1d..81f4275 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -60,13 +60,13 @@ const quadTexcoords = new Float32Array([
// -- Initialize vertex array
-const triVertexArray: { vertices?: IGLVertexAttributes } = {
+const triVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: triPositions, numComponents: 3 }
}
};
-const quadVertexArray: { vertices?: IGLVertexAttributes } = {
+const quadVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: quadPositions, numComponents: 2 },
textureCoordinates: { data: quadTexcoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
index f0575b0..593955b 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -84,13 +84,13 @@ const texcoords = new Float32Array([
// -- Initialize vertex array
-const multipleOutputVertexArray: { vertices?: IGLVertexAttributes } = {
+const multipleOutputVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
}
};
-const layerVertexArray: { vertices?: IGLVertexAttributes } = {
+const layerVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
textureCoordinates: { data: texcoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index de4fdba..14042d3 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { HalfFloat } from "./third-party/HalfFloatUtility";
import { getShaderSource, loadImage } from "./utility";
@@ -151,7 +151,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init VertexArray
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
a_position: { type: "FLOAT", data: positions, numComponents: 3 },
a_normal: { type: "HALF_FLOAT", data: normals, numComponents: 3 },
diff --git a/examples/src/WebGL2Samples/glsl_centroid.ts b/examples/src/WebGL2Samples/glsl_centroid.ts
index 0a0f9e5..a3547c8 100644
--- a/examples/src/WebGL2Samples/glsl_centroid.ts
+++ b/examples/src/WebGL2Samples/glsl_centroid.ts
@@ -1,5 +1,5 @@
import { IPassEncoder, IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -133,7 +133,7 @@ const framebuffers: IRenderPassDescriptor[] = [
];
// -- Init VertexArray
-const vertexArrays: { vertices?: IGLVertexAttributes }[] = [
+const vertexArrays: { vertices?: IVertexAttributes }[] = [
{
vertices: {
position: { data: positions, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
index c28ae53..5cb17dd 100644
--- a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
+++ b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPassObject, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLIndicesDataTypes, IVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
import { getShaderSource } from "./utility";
@@ -66,7 +66,7 @@ glTFLoader.loadGLTF(gltfUrl, function (glTF)
// -- Initialize vertex array
const vertexArrayMaps: {
- [key: string]: { vertexArray: { vertices?: IGLVertexAttributes }, indices: IGLIndicesDataTypes }[]
+ [key: string]: { vertexArray: { vertices?: IVertexAttributes }, indices: IGLIndicesDataTypes }[]
} = {};
// var in loop
@@ -75,7 +75,7 @@ glTFLoader.loadGLTF(gltfUrl, function (glTF)
};
let primitive: Primitive;
// { matrix: mat4, attributes: { [key: string]: { size: number, type: number, stride: number, offset: number } }, vertexBuffer, indices };
- let vertexArray: { vertices?: IGLVertexAttributes };
+ let vertexArray: { vertices?: IVertexAttributes };
let i: number; let len: number;
diff --git a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
index bc4f5be..28ae13f 100644
--- a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
+++ b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -37,7 +37,7 @@ const texCoords = new Float32Array([
]);
// -- Init VertexArray
-const vertexArray: { vertices?: IGLVertexAttributes } = {
+const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
texcoord: { data: texCoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/query_occlusion.ts b/examples/src/WebGL2Samples/query_occlusion.ts
index d0a484e..4d8798c 100644
--- a/examples/src/WebGL2Samples/query_occlusion.ts
+++ b/examples/src/WebGL2Samples/query_occlusion.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLOcclusionQuery, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLOcclusionQuery, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { watcher } from "@feng3d/watcher";
@@ -35,7 +35,7 @@ const vertices = new Float32Array([
]);
// -- Init Vertex Array
-const vertexArray: { vertices?: IGLVertexAttributes } = {
+const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
pos: { data: vertices, numComponents: 3, normalized: false, vertexSize: 0, offset: 0 },
}
diff --git a/examples/src/WebGL2Samples/sampler_filter.ts b/examples/src/WebGL2Samples/sampler_filter.ts
index da36507..7a63f52 100644
--- a/examples/src/WebGL2Samples/sampler_filter.ts
+++ b/examples/src/WebGL2Samples/sampler_filter.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -85,7 +85,7 @@ const texcoords = new Float32Array([
// -- Initialize vertex array
-const vertexArray: { vertices?: IGLVertexAttributes } = {
+const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
textureCoordinates: { data: texcoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/sampler_object.ts b/examples/src/WebGL2Samples/sampler_object.ts
index 244058a..1af4279 100644
--- a/examples/src/WebGL2Samples/sampler_object.ts
+++ b/examples/src/WebGL2Samples/sampler_object.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -41,7 +41,7 @@ const texcoords = new Float32Array([
// -- Initialize vertex array
-const vertexArray: { vertices?: IGLVertexAttributes } = {
+const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
textureCoordinates: { data: texcoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/sampler_wrap.ts b/examples/src/WebGL2Samples/sampler_wrap.ts
index d76e819..074fdac 100644
--- a/examples/src/WebGL2Samples/sampler_wrap.ts
+++ b/examples/src/WebGL2Samples/sampler_wrap.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -85,7 +85,7 @@ const texcoords = new Float32Array([
// -- Initilize vertex array
-const vertexArray: { vertices?: IGLVertexAttributes } = {
+const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
textureCoordinates: { data: texcoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/texture_2d_array.ts b/examples/src/WebGL2Samples/texture_2d_array.ts
index 9d743e5..3583905 100644
--- a/examples/src/WebGL2Samples/texture_2d_array.ts
+++ b/examples/src/WebGL2Samples/texture_2d_array.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -38,7 +38,7 @@ import { getShaderSource, loadImage } from "./utility";
]);
// -- Init VertexArray
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
texcoord: { data: texCoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/texture_3d.ts b/examples/src/WebGL2Samples/texture_3d.ts
index f31a1b4..864ca62 100644
--- a/examples/src/WebGL2Samples/texture_3d.ts
+++ b/examples/src/WebGL2Samples/texture_3d.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource } from "./utility";
@@ -117,7 +117,7 @@ import { getShaderSource } from "./utility";
// -- Initilize vertex array
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
in_texcoord: { data: texCoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index ef788f2..c983760 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -117,7 +117,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init VertexArray
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 3 },
texcoord: { data: texCoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/texture_fetch.ts b/examples/src/WebGL2Samples/texture_fetch.ts
index b5ca6a5..a6f748c 100644
--- a/examples/src/WebGL2Samples/texture_fetch.ts
+++ b/examples/src/WebGL2Samples/texture_fetch.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -37,7 +37,7 @@ import { getShaderSource, loadImage } from "./utility";
]);
// -- Init VertexArray
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
texcoord: { data: texCoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/texture_format.ts b/examples/src/WebGL2Samples/texture_format.ts
index 0610fd2..e669d24 100644
--- a/examples/src/WebGL2Samples/texture_format.ts
+++ b/examples/src/WebGL2Samples/texture_format.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, ITextureFormat } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -73,7 +73,7 @@ import { getShaderSource, loadImage } from "./utility";
]);
// -- Init VertexArray
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
texcoord: { data: texCoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/texture_grad.ts b/examples/src/WebGL2Samples/texture_grad.ts
index e32dfdf..dc3386d 100644
--- a/examples/src/WebGL2Samples/texture_grad.ts
+++ b/examples/src/WebGL2Samples/texture_grad.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -111,7 +111,7 @@ import { getShaderSource, loadImage } from "./utility";
];
// -- Init VertexArray
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 3 },
texcoord: { data: texCoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/texture_immutable.ts b/examples/src/WebGL2Samples/texture_immutable.ts
index cc0d507..97e26ed 100644
--- a/examples/src/WebGL2Samples/texture_immutable.ts
+++ b/examples/src/WebGL2Samples/texture_immutable.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource, loadImage } from "./utility";
@@ -62,7 +62,7 @@ import { getShaderSource, loadImage } from "./utility";
]);
// -- Init VertexArray
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
in_texcoord: { data: texCoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/texture_integer.ts b/examples/src/WebGL2Samples/texture_integer.ts
index 421a7d0..347d0ae 100644
--- a/examples/src/WebGL2Samples/texture_integer.ts
+++ b/examples/src/WebGL2Samples/texture_integer.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -39,7 +39,7 @@ import { getShaderSource, loadImage } from "./utility";
]);
// -- Init VertexArray
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
texcoord: { data: texCoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/texture_lod.ts b/examples/src/WebGL2Samples/texture_lod.ts
index bab9e7f..479c69e 100644
--- a/examples/src/WebGL2Samples/texture_lod.ts
+++ b/examples/src/WebGL2Samples/texture_lod.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -111,7 +111,7 @@ import { getShaderSource, loadImage } from "./utility";
]);
// -- Initialize vertex array
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
textureCoordinates: { data: texcoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/texture_offset.ts b/examples/src/WebGL2Samples/texture_offset.ts
index 42a59cc..1f5490d 100644
--- a/examples/src/WebGL2Samples/texture_offset.ts
+++ b/examples/src/WebGL2Samples/texture_offset.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -62,7 +62,7 @@ import { getShaderSource, loadImage } from "./utility";
]);
// -- Init VertexArray
- const vertexArray: { vertices?: IGLVertexAttributes } = {
+ const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: { data: positions, numComponents: 2 },
texcoord: { data: texCoords, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/texture_pixel_store.ts b/examples/src/WebGL2Samples/texture_pixel_store.ts
index d82f49d..a93722c 100644
--- a/examples/src/WebGL2Samples/texture_pixel_store.ts
+++ b/examples/src/WebGL2Samples/texture_pixel_store.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { getIGLBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, IVertexAttributes, IVertexDataTypes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -27,7 +27,7 @@ import { getShaderSource, loadImage } from "./utility";
-1.0, 1.0,
-1.0, -1.0
]);
- const vertexPosBuffer: IGLVertexDataTypes = positions;
+ const vertexPosBuffer: IVertexDataTypes = positions;
const texCoords = new Float32Array([
0.0, 1.0,
@@ -37,10 +37,10 @@ import { getShaderSource, loadImage } from "./utility";
0.0, 0.0,
0.0, 1.0
]);
- const vertexTexBuffer: IGLVertexDataTypes = texCoords;
+ const vertexTexBuffer: IVertexDataTypes = texCoords;
// -- Init VertexArray
- const vertexArray: { vertices?: IGLVertexAttributes, indices?: IGLIndicesDataTypes } = {
+ const vertexArray: { vertices?: IVertexAttributes, indices?: IGLIndicesDataTypes } = {
vertices: {
position: { data: vertexPosBuffer, numComponents: 2 },
texcoord: { data: vertexTexBuffer, numComponents: 2 },
diff --git a/examples/src/WebGL2Samples/texture_srgb.ts b/examples/src/WebGL2Samples/texture_srgb.ts
index 36c7af0..d3c99bd 100644
--- a/examples/src/WebGL2Samples/texture_srgb.ts
+++ b/examples/src/WebGL2Samples/texture_srgb.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { getIGLBuffer, IGLCanvasContext, IGLSampler, IVertexAttributes, IVertexDataTypes, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -30,7 +30,7 @@ import { getShaderSource, loadImage } from "./utility";
-1.0, 1.0,
-1.0, -1.0
]);
- const vertexPosBuffer: IGLVertexDataTypes = positions;
+ const vertexPosBuffer: IVertexDataTypes = positions;
const texcoords = new Float32Array([
0.0, 1.0,
@@ -40,11 +40,11 @@ import { getShaderSource, loadImage } from "./utility";
0.0, 0.0,
0.0, 1.0
]);
- const vertexTexBuffer: IGLVertexDataTypes = texcoords;
+ const vertexTexBuffer: IVertexDataTypes = texcoords;
// -- Initialize vertex array
- const vertices: IGLVertexAttributes = {
+ const vertices: IVertexAttributes = {
position: { data: vertexPosBuffer, numComponents: 2 },
textureCoordinates: { data: vertexTexBuffer, numComponents: 2 },
}
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index 092d9fc..8c11ea3 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -1,5 +1,5 @@
import { IPrimitiveTopology, IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, IVertexAttributes, IVertexDataTypes, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
@@ -45,12 +45,12 @@ import { getShaderSource, loadImage } from "./utility";
depthStencil: { depthCompare:"less" },
};
- const vertexArrayMaps: { [key: string]: { vertices?: IGLVertexAttributes, indices: IGLIndicesDataTypes }[] } = {};
+ const vertexArrayMaps: { [key: string]: { vertices?: IVertexAttributes, indices: IGLIndicesDataTypes }[] } = {};
// var in loop
let mesh;
let primitive: Primitive;
- let vertexBuffer: IGLVertexDataTypes;
+ let vertexBuffer: IVertexDataTypes;
let indicesBuffer: IGLIndicesDataTypes;
let texture: ITexture;
diff --git a/examples/src/WebGL2Samples/third-party/gltf-loader.ts b/examples/src/WebGL2Samples/third-party/gltf-loader.ts
index 0c5433e..32f31af 100644
--- a/examples/src/WebGL2Samples/third-party/gltf-loader.ts
+++ b/examples/src/WebGL2Samples/third-party/gltf-loader.ts
@@ -1,6 +1,6 @@
import { mat4, quat, vec3 } from "gl-matrix";
-type IGLVertexDataTypes =
+type IVertexDataTypes =
| Float32Array
| Uint32Array
| Int32Array
@@ -43,7 +43,7 @@ export class Primitive
mode: number;
indices: IGLIndicesDataTypes;
indicesComponentType: number;
- vertexBuffer: IGLVertexDataTypes;
+ vertexBuffer: IVertexDataTypes;
matrix: mat4;
attributes: {
[key: string]: { size: 1 | 2 | 3 | 4, type?: number, stride: number, offset: number },
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index 1b723e7..6430128 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -65,12 +65,12 @@ import { getShaderSource } from "./utility";
const COLOR_LOCATION = 3;
const NUM_LOCATIONS = 4;
- const vertexArrays: { vertices?: IGLVertexAttributes, indices?: IGLIndicesDataTypes }[][] = [];
+ const vertexArrays: { vertices?: IVertexAttributes, indices?: IGLIndicesDataTypes }[][] = [];
// Transform feedback objects track output buffer state
const transformFeedbacks: IGLTransformFeedback[] = [];
- const vertexBuffers: IGLVertexDataTypes[][] = new Array(vertexArrays.length);
+ const vertexBuffers: IVertexDataTypes[][] = new Array(vertexArrays.length);
for (let va = 0; va < 2; ++va)
{
@@ -84,16 +84,16 @@ import { getShaderSource } from "./utility";
vertexArrays[va] = [];
vertexArrays[va][0] = {
vertices: {
- a_offset: { data: vertexBuffers[va][OFFSET_LOCATION], numComponents: 2 },
- a_rotation: { data: vertexBuffers[va][ROTATION_LOCATION], numComponents: 1 },
+ a_offset: { data: vertexBuffers[va][OFFSET_LOCATION], format: "float32x2" },
+ a_rotation: { data: vertexBuffers[va][ROTATION_LOCATION], format: "float32" },
}
};
vertexArrays[va][1] = {
vertices: {
- a_offset: { data: vertexBuffers[va][OFFSET_LOCATION], numComponents: 2, divisor: 1 },
- a_rotation: { data: vertexBuffers[va][ROTATION_LOCATION], numComponents: 1, divisor: 1 },
- a_position: { data: vertexBuffers[va][POSITION_LOCATION], numComponents: 2 },
- a_color: { data: vertexBuffers[va][COLOR_LOCATION], numComponents: 3, divisor: 1 },
+ a_offset: { data: vertexBuffers[va][OFFSET_LOCATION], format: "float32x2", stepMode: "instance" },
+ a_rotation: { data: vertexBuffers[va][ROTATION_LOCATION], format: "float32", stepMode: "instance" },
+ a_position: { data: vertexBuffers[va][POSITION_LOCATION], format: "float32x2" },
+ a_color: { data: vertexBuffers[va][COLOR_LOCATION], format: "float32x3", stepMode: "instance" },
}
};
diff --git a/examples/src/WebGL2Samples/transform_feedback_interleaved.ts b/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
index 4e8cb77..dddc0b4 100644
--- a/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline } from "@feng3d/render-api";
-import { getIGLVertexBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { getIGLVertexBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -49,7 +49,7 @@ import { getShaderSource } from "./utility";
-1.0, -1.0, 0.0, 1.0
]);
- const buffers: IGLVertexDataTypes[] = [
+ const buffers: IVertexDataTypes[] = [
// Transform buffer
vertices,
// Feedback empty buffer
@@ -57,16 +57,16 @@ import { getShaderSource } from "./utility";
];
// -- Init Vertex Array
- const vertexArrays: { vertices?: IGLVertexAttributes, indices?: IGLIndicesDataTypes }[] = [
+ const vertexArrays: { vertices?: IVertexAttributes, indices?: IGLIndicesDataTypes }[] = [
{
vertices: {
- position: { data: buffers[PROGRAM_TRANSFORM], numComponents: 4 },
+ position: { data: buffers[PROGRAM_TRANSFORM], format: "float32x4" },
}
},
{
vertices: {
- position: { data: buffers[PROGRAM_FEEDBACK], numComponents: 4, vertexSize: SIZE_V4C4, offset: 0 },
- color: { data: buffers[PROGRAM_FEEDBACK], numComponents: 4, vertexSize: SIZE_V4C4, offset: SIZE_V4C4 / 2 },
+ position: { data: buffers[PROGRAM_FEEDBACK], format: "float32x4", arrayStride: SIZE_V4C4, offset: 0 },
+ color: { data: buffers[PROGRAM_FEEDBACK], format: "float32x4", arrayStride: SIZE_V4C4, offset: SIZE_V4C4 / 2 },
}
},
];
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated.ts b/examples/src/WebGL2Samples/transform_feedback_separated.ts
index 8e6eb02..11daceb 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
@@ -56,7 +56,7 @@ import { getShaderSource } from "./utility";
MAX: 3
};
- const buffers: IGLVertexDataTypes[] = [
+ const buffers: IVertexDataTypes[] = [
// Transform buffer
positions,
// Feedback empty buffers
@@ -67,16 +67,16 @@ import { getShaderSource } from "./utility";
];
// -- Init Transform Vertex Array
- const vertexArrays: { vertices?: IGLVertexAttributes, indices?: IGLIndicesDataTypes }[] = [
+ const vertexArrays: { vertices?: IVertexAttributes, indices?: IGLIndicesDataTypes }[] = [
{
vertices: {
- position: { data: buffers[BufferType.VERTEX], numComponents: 4 },
+ position: { data: buffers[BufferType.VERTEX], format: "float32x4" },
}
},
{
vertices: {
- position: { data: buffers[BufferType.POSITION], numComponents: 4 },
- color: { data: buffers[BufferType.COLOR], numComponents: 4 },
+ position: { data: buffers[BufferType.POSITION], format: "float32x4" },
+ color: { data: buffers[BufferType.COLOR], format: "float32x4" },
}
},
];
@@ -90,7 +90,7 @@ import { getShaderSource } from "./utility";
};
const renderObjects: IRenderPassObject[] = [];
-
+
// -- Render
const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
index 29ce1bf..932ff64 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, IGLVertexAttributes, IGLVertexDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
@@ -58,12 +58,12 @@ import { getShaderSource } from "./utility";
}
// -- Init Vertex Arrays and Buffers
- const particleVAOs: { vertices?: IGLVertexAttributes, indices?: IGLIndicesDataTypes }[] = [];
+ const particleVAOs: { vertices?: IVertexAttributes, indices?: IGLIndicesDataTypes }[] = [];
// Transform feedback objects track output buffer state
const particleTransformFeedbacks: IGLTransformFeedback[] = [];
- const particleVBOs: IGLVertexDataTypes[][] = new Array(particleVAOs.length);
+ const particleVBOs: IVertexDataTypes[][] = new Array(particleVAOs.length);
for (let i = 0; i < 2; ++i)
{
@@ -82,11 +82,11 @@ import { getShaderSource } from "./utility";
particleVAOs[i] = {
vertices: {
- a_position: { data: particleVBOs[i][POSITION_LOCATION], numComponents: 2 },
- a_velocity: { data: particleVBOs[i][VELOCITY_LOCATION], numComponents: 2 },
- a_spawntime: { data: particleVBOs[i][SPAWNTIME_LOCATION], numComponents: 1 },
- a_lifetime: { data: particleVBOs[i][LIFETIME_LOCATION], numComponents: 1 },
- a_ID: { data: particleVBOs[i][ID_LOCATION], numComponents: 1 },
+ a_position: { data: particleVBOs[i][POSITION_LOCATION], format:"float32x2" },
+ a_velocity: { data: particleVBOs[i][VELOCITY_LOCATION], format:"float32x2" },
+ a_spawntime: { data: particleVBOs[i][SPAWNTIME_LOCATION], format:"float32" },
+ a_lifetime: { data: particleVBOs[i][LIFETIME_LOCATION], format:"float32" },
+ a_ID: { data: particleVBOs[i][ID_LOCATION], format:"float32" },
}
};
diff --git a/examples/src/regl-examples/batch.ts b/examples/src/regl-examples/batch.ts
index 49547aa..6b10562 100644
--- a/examples/src/regl-examples/batch.ts
+++ b/examples/src/regl-examples/batch.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPipeline } from "@feng3d/render-api";
-import { IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IVertexAttributes, WebGL } from "@feng3d/webgl";
const canvas = document.createElement("canvas");
canvas.id = "glcanvas";
@@ -41,7 +41,7 @@ const pipeline: IRenderPipeline = {
depthStencil: {},
};
-const vertexArray: { vertices?: IGLVertexAttributes } = {
+const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: {
data: new Float32Array([
diff --git a/examples/src/regl-examples/blur.ts b/examples/src/regl-examples/blur.ts
index 19bad40..a393609 100644
--- a/examples/src/regl-examples/blur.ts
+++ b/examples/src/regl-examples/blur.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPipeline } from "@feng3d/render-api";
-import { IGLVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IVertexAttributes, WebGL } from "@feng3d/webgl";
import { fit } from "./hughsk/canvas-fit";
import { attachCamera } from "./hughsk/canvas-orbit-camera";
@@ -31,7 +31,7 @@ const offsets = [{ offset: [-1, -1] },
{ offset: [1, 0] },
{ offset: [1, 1] }];
-const vertexArray: { vertices?: IGLVertexAttributes } = {
+const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: {
data: new Float32Array([
diff --git a/examples/src/webgl-examples/sample2.ts b/examples/src/webgl-examples/sample2.ts
index 6756148..d24120b 100644
--- a/examples/src/webgl-examples/sample2.ts
+++ b/examples/src/webgl-examples/sample2.ts
@@ -44,14 +44,13 @@ function main()
},
vertices: {
aVertexPosition: {
- type: "FLOAT",
+ format:"float32x2",
data: new Float32Array([
1.0, 1.0,
-1.0, 1.0,
1.0, -1.0,
-1.0, -1.0,
]),
- numComponents: 2,
}
},
uniforms: {
diff --git a/src/caches/getGLBuffer.ts b/src/caches/getGLBuffer.ts
index 86e0255..b7bfb52 100644
--- a/src/caches/getGLBuffer.ts
+++ b/src/caches/getGLBuffer.ts
@@ -1,6 +1,6 @@
import { watcher } from "@feng3d/watcher";
import { IGLBuffer } from "../data/IGLBuffer";
-import { IGLVertexDataTypes } from "../data/IGLVertexAttributes";
+import { IVertexDataTypes } from "@feng3d/render-api";
declare global
{
@@ -106,7 +106,7 @@ export function deleteBuffer(gl: WebGLRenderingContext, buffer: IGLBuffer)
}
}
-export function getBufferType(data?: IGLVertexDataTypes)
+export function getBufferType(data?: IVertexDataTypes)
{
return bufferTypeMap[data?.constructor.name];
}
diff --git a/src/data/IGLAttributeInfo.ts b/src/data/IGLAttributeInfo.ts
index 9e34fe9..4024982 100644
--- a/src/data/IGLAttributeInfo.ts
+++ b/src/data/IGLAttributeInfo.ts
@@ -1,4 +1,4 @@
-import { VertexAttributeTypes } from "./IGLVertexAttributes";
+import { IGLVertexAttributeTypes } from "../runs/runVertexAttribute";
export interface IGLAttributeInfo
{
@@ -15,7 +15,7 @@ export interface IGLAttributeInfo
/**
* 属性缓冲数据类型
*/
- type?: VertexAttributeTypes;
+ type?: IGLVertexAttributeTypes;
/**
* 属性地址
diff --git a/src/data/IGLRenderObject.ts b/src/data/IGLRenderObject.ts
index 4d6f528..0a35c3b 100644
--- a/src/data/IGLRenderObject.ts
+++ b/src/data/IGLRenderObject.ts
@@ -5,7 +5,6 @@ import { IGLDrawVertex } from "./IGLDrawVertex";
import { IGLIndicesDataTypes } from "./IGLIndexBuffer";
import { IGLTransformFeedback } from "./IGLTransformFeedback";
import { IGLUniforms } from "./IGLUniforms";
-import { IGLVertexAttributes } from "./IGLVertexAttributes";
declare module "@feng3d/render-api"
{
@@ -14,11 +13,6 @@ declare module "@feng3d/render-api"
*/
export interface IRenderObject
{
- /**
- * 顶点属性数据列表
- */
- vertices?: IGLVertexAttributes;
-
/**
* 顶点索引数据
*/
diff --git a/src/data/IGLTransformFeedback.ts b/src/data/IGLTransformFeedback.ts
index fd93665..8ad7504 100644
--- a/src/data/IGLTransformFeedback.ts
+++ b/src/data/IGLTransformFeedback.ts
@@ -1,4 +1,4 @@
-import { IGLVertexDataTypes } from "./IGLVertexAttributes";
+import { IVertexDataTypes } from "@feng3d/render-api";
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/createTransformFeedback
@@ -15,5 +15,5 @@ export interface IGLTransformFeedbacBindBuffer
{
index: number;
- data: IGLVertexDataTypes;
+ data: IVertexDataTypes;
}
\ No newline at end of file
diff --git a/src/data/IGLVertexAttributes.ts b/src/data/IGLVertexAttributes.ts
index 5116b95..82b3cb0 100644
--- a/src/data/IGLVertexAttributes.ts
+++ b/src/data/IGLVertexAttributes.ts
@@ -1,13 +1,6 @@
+import { IGLVertexAttributeTypes } from "../runs/runVertexAttribute";
import { IGLBuffer } from "./IGLBuffer";
-/**
- * 顶点属性数据映射。
- */
-export interface IGLVertexAttributes
-{
- [name: string]: IGLVertexAttribute;
-}
-
/**
* 顶点属性数据。
*
@@ -19,7 +12,7 @@ export interface IGLVertexAttribute
/**
* 顶点属性数据。
*/
- data: IGLVertexDataTypes;
+ data: IVertexDataTypes;
/**
* 顶点数据元素数量。
@@ -31,7 +24,7 @@ export interface IGLVertexAttribute
*
* 默认从Buffer数据中获取,如果未取到则默认为 "FLOAT" 。
*/
- type?: VertexAttributeTypes;
+ type?: IGLVertexAttributeTypes;
/**
* 是否标准化。
@@ -64,13 +57,13 @@ export interface IGLVertexBuffer extends IGLBuffer
/**
* 缓冲区数据。
*/
- data?: IGLVertexDataTypes;
+ data?: IVertexDataTypes;
}
/**
* 顶点属性数据类型。
*/
-export type IGLVertexDataTypes =
+export type IVertexDataTypes =
| Float32Array
| Uint32Array
| Int32Array
@@ -79,40 +72,3 @@ export type IGLVertexDataTypes =
| Uint8Array
| Int8Array;
-
-/**
- * 属性缓冲数据类型
- *
- * A GLenum specifying the data type of each component in the array. Possible values:
- *
- * * gl.BYTE: signed 8-bit integer, with values in [-128, 127]
- * * gl.SHORT: signed 16-bit integer, with values in [-32768, 32767]
- * * gl.UNSIGNED_BYTE: unsigned 8-bit integer, with values in [0, 255]
- * * gl.UNSIGNED_SHORT: unsigned 16-bit integer, with values in [0,65535]
- * * gl.FLOAT: 32-bit IEEE floating point number
- *
- * When using a WebGL 2 context, the following values are available additionally:
- *
- * * gl.HALF_FLOAT: 16-bit IEEE floating point number
- * * gl.INT: 32-bit signed binary integer
- * * gl.UNSIGNED_INT: 32-bit unsigned binary integer
- * * gl.INT_2_10_10_10_REV: 32-bit signed integer with values in [-512, 511]
- * * gl.UNSIGNED_INT_2_10_10_10_REV: 32-bit unsigned integer with values in [0, 1023]
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer
- */
-export type VertexAttributeTypes = "FLOAT" | "BYTE" | "SHORT" | "UNSIGNED_BYTE" | "UNSIGNED_SHORT" // WebGL1
- | "HALF_FLOAT" | "INT" | "UNSIGNED_INT" | "INT_2_10_10_10_REV" | "UNSIGNED_INT_2_10_10_10_REV"; // WebGL2
-
-/**
- * A GLenum specifying the data type of each component in the array. Must be one of:
- * * gl.BYTE
- * * gl.UNSIGNED_BYTE
- * * gl.SHORT
- * * gl.UNSIGNED_SHORT
- * * gl.INT
- * * gl.UNSIGNED_INT.
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/vertexAttribIPointer
- */
-export type VertexAttributeIntegerTypes = "BYTE" | "UNSIGNED_BYTE" | "SHORT" | "UNSIGNED_SHORT" | "INT" | "UNSIGNED_INT";
diff --git a/src/index.ts b/src/index.ts
index 7259379..9564a8b 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -22,7 +22,6 @@ export * from "./data/IGLTexture";
export * from "./data/IGLTexturePixelStore";
export * from "./data/IGLTransformFeedback";
export * from "./data/IGLUniforms";
-export * from "./data/IGLVertexAttributes";
export * from "./data/IGLViewport";
export * from "./runs/getIGLBuffer";
diff --git a/src/runs/getIGLBuffer.ts b/src/runs/getIGLBuffer.ts
index c9d0a68..3719f0e 100644
--- a/src/runs/getIGLBuffer.ts
+++ b/src/runs/getIGLBuffer.ts
@@ -1,6 +1,7 @@
+import { IVertexDataTypes } from "@feng3d/render-api";
import { GLBufferTarget, GLBufferUsage, IGLBuffer } from "../data/IGLBuffer";
import { IGLIndexBuffer, IGLIndicesDataTypes } from "../data/IGLIndexBuffer";
-import { IGLVertexBuffer, IGLVertexDataTypes } from "../data/IGLVertexAttributes";
+import { IGLVertexBuffer } from "../data/IGLVertexAttributes";
export function getIGLBuffer(data: BufferSource, target?: GLBufferTarget, usage: GLBufferUsage = "STATIC_DRAW")
{
@@ -16,7 +17,7 @@ export function getIGLBuffer(data: BufferSource, target?: GLBufferTarget, usage:
return indexBuffer;
}
-export function getIGLVertexBuffer(data: IGLVertexDataTypes, usage?: "STREAM_COPY")
+export function getIGLVertexBuffer(data: IVertexDataTypes, usage?: "STREAM_COPY")
{
const vertexBuffer: IGLVertexBuffer = data[_IGLBuffer] = data[_IGLBuffer] || getIGLBuffer(data, "ARRAY_BUFFER", usage);
diff --git a/src/runs/runDepthState.ts b/src/runs/runDepthState.ts
index 442e34e..b8d8275 100644
--- a/src/runs/runDepthState.ts
+++ b/src/runs/runDepthState.ts
@@ -37,6 +37,8 @@ function getIGLCompareFunction(depthCompare: ICompareFunction)
{
const glDepthCompare: IGLCompareFunction = depthCompareMap[depthCompare];
+ console.assert(!!glDepthCompare, `接收到错误值,请从 ${Object.keys(depthCompareMap).toString()} 中取值!`);
+
return glDepthCompare;
}
diff --git a/src/runs/runDrawCall.ts b/src/runs/runDrawCall.ts
index 65938d7..51520d5 100644
--- a/src/runs/runDrawCall.ts
+++ b/src/runs/runDrawCall.ts
@@ -1,4 +1,4 @@
-import { IRenderObject } from "@feng3d/render-api";
+import { IRenderObject, IVertexAttributes } from "@feng3d/render-api";
import { getBufferType } from "../caches/getGLBuffer";
import { IGLDrawMode } from "../caches/getIGLDrawMode";
@@ -6,7 +6,6 @@ import { ElementTypeMap } from "../const/IGLUniformType";
import { IGLDrawIndexed } from "../data/IGLDrawIndexed";
import { IGLDrawVertex } from "../data/IGLDrawVertex";
import { IGLIndicesDataTypes } from "../data/IGLIndexBuffer";
-import { IGLVertexAttributes } from "../data/IGLVertexAttributes";
export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObject, drawMode: IGLDrawMode)
{
@@ -63,7 +62,7 @@ function _runDrawIndexed(gl: WebGLRenderingContext, drawMode: IGLDrawMode, indic
export const defaultDrawVertex: IGLDrawVertex = Object.freeze({ vertexCount: 6, instanceCount: 1, firstVertex: 0 });
-function _runDrawVertex(gl: WebGLRenderingContext, drawMode: IGLDrawMode, vertices: IGLVertexAttributes, drawArrays: IGLDrawVertex)
+function _runDrawVertex(gl: WebGLRenderingContext, drawMode: IGLDrawMode, vertices: IVertexAttributes, drawArrays: IGLDrawVertex)
{
//
let { firstVertex, vertexCount, instanceCount } = drawArrays || {};
@@ -93,7 +92,7 @@ function _runDrawVertex(gl: WebGLRenderingContext, drawMode: IGLDrawMode, vertic
/**
* 获取属性顶点属性。
*/
-export function getAttributeVertexNum(vertices: IGLVertexAttributes)
+export function getAttributeVertexNum(vertices: IVertexAttributes)
{
const vertexNum = ((vertices) =>
{
diff --git a/src/runs/runVertexArray.ts b/src/runs/runVertexArray.ts
index 0b42745..67bd1ee 100644
--- a/src/runs/runVertexArray.ts
+++ b/src/runs/runVertexArray.ts
@@ -1,7 +1,6 @@
-import { IRenderPipeline } from "@feng3d/render-api";
+import { IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
import { getGLProgram } from "../caches/getGLProgram";
import { IGLIndicesDataTypes } from "../data/IGLIndexBuffer";
-import { IGLVertexAttributes } from "../data/IGLVertexAttributes";
import { ChainMap } from "../utils/ChainMap";
import { runIndexBuffer } from "./runIndexBuffer";
import { runVertexAttribute } from "./runVertexAttribute";
@@ -10,14 +9,14 @@ declare global
{
interface WebGLRenderingContext
{
- _vertexArrays: ChainMap<[IRenderPipeline, IGLVertexAttributes, IGLIndicesDataTypes], WebGLVertexArrayObject>;
+ _vertexArrays: ChainMap<[IRenderPipeline, IVertexAttributes, IGLIndicesDataTypes], WebGLVertexArrayObject>;
}
}
/**
* 执行设置或者上传渲染对象的顶点以及索引数据。
*/
-export function runVertexArray(gl: WebGLRenderingContext, pipeline: IRenderPipeline, vertices: IGLVertexAttributes, indices: IGLIndicesDataTypes)
+export function runVertexArray(gl: WebGLRenderingContext, pipeline: IRenderPipeline, vertices: IVertexAttributes, indices: IGLIndicesDataTypes)
{
if (!vertices && !indices) return;
diff --git a/src/runs/runVertexAttribute.ts b/src/runs/runVertexAttribute.ts
index 5069ab8..6617308 100644
--- a/src/runs/runVertexAttribute.ts
+++ b/src/runs/runVertexAttribute.ts
@@ -1,32 +1,32 @@
-import { getBufferType, getGLBuffer } from "../caches/getGLBuffer";
-import { IGLVertexAttribute } from "../data/IGLVertexAttributes";
+import { IVertexAttribute, IVertexFormat } from "@feng3d/render-api";
+import { getGLBuffer } from "../caches/getGLBuffer";
import { getIGLVertexBuffer } from "./getIGLBuffer";
-export function runVertexAttribute(gl: WebGLRenderingContext, location: number, attribute: IGLVertexAttribute)
+export function runVertexAttribute(gl: WebGLRenderingContext, location: number, attribute: IVertexAttribute)
{
- const { numComponents, normalized, divisor } = attribute;
- let { vertexSize, offset } = attribute;
+ const { stepMode, format } = attribute;
+ let { arrayStride, offset } = attribute;
+
+ const glVertexFormat = getIGLVertexFormat(format);
+ const { numComponents, normalized, type } = glVertexFormat;
gl.enableVertexAttribArray(location);
- if (divisor !== undefined)
+ if (stepMode === "instance")
{
if (gl instanceof WebGL2RenderingContext)
{
- gl.vertexAttribDivisor(location, divisor);
+ gl.vertexAttribDivisor(location, 1);
}
else
{
const extension = gl.getExtension("ANGLE_instanced_arrays");
- extension.vertexAttribDivisorANGLE(location, divisor);
+ extension.vertexAttribDivisorANGLE(location, 1);
}
}
//
- const type = attribute.type || getBufferType(attribute.data) || "FLOAT";
-
- //
- vertexSize = vertexSize || 0;
+ arrayStride = arrayStride || 0;
offset = offset || 0;
//
@@ -37,10 +37,113 @@ export function runVertexAttribute(gl: WebGLRenderingContext, location: number,
//
if (gl instanceof WebGL2RenderingContext && (type === "INT" || type === "UNSIGNED_INT"))
{
- gl.vertexAttribIPointer(location, numComponents, gl[type], vertexSize, offset);
+ gl.vertexAttribIPointer(location, numComponents, gl[type], arrayStride, offset);
}
else
{
- gl.vertexAttribPointer(location, numComponents, gl[type], normalized, vertexSize, offset);
+ gl.vertexAttribPointer(location, numComponents, gl[type], normalized, arrayStride, offset);
}
}
+
+function getIGLVertexFormat(format: IVertexFormat): IGLVertexFormat
+{
+ const glVertexFormat = formatMap[format];
+
+ console.assert(!!glVertexFormat, `接收到错误值,请从 ${Object.keys(formatMap).toString()} 中取值!`);
+
+ return glVertexFormat;
+}
+
+const formatMap: { [key: string]: IGLVertexFormat } = {
+
+ "uint8x2": { numComponents: 2, type: "UNSIGNED_BYTE", normalized: false },
+ "uint8x4": { numComponents: 4, type: "UNSIGNED_BYTE", normalized: false },
+ "sint8x2": { numComponents: 2, type: "BYTE", normalized: false },
+ "sint8x4": { numComponents: 4, type: "BYTE", normalized: false },
+ "unorm8x2": { numComponents: 2, type: "UNSIGNED_BYTE", normalized: true },
+ "unorm8x4": { numComponents: 4, type: "UNSIGNED_BYTE", normalized: true },
+ "snorm8x2": { numComponents: 2, type: "BYTE", normalized: true },
+ "snorm8x4": { numComponents: 4, type: "BYTE", normalized: true },
+ "uint16x2": { numComponents: 2, type: "UNSIGNED_SHORT", normalized: false },
+ "uint16x4": { numComponents: 4, type: "UNSIGNED_SHORT", normalized: false },
+ "sint16x2": { numComponents: 2, type: "SHORT", normalized: false },
+ "sint16x4": { numComponents: 4, type: "SHORT", normalized: false },
+ "unorm16x2": { numComponents: 2, type: "UNSIGNED_SHORT", normalized: true },
+ "unorm16x4": { numComponents: 4, type: "UNSIGNED_SHORT", normalized: true },
+ "snorm16x2": { numComponents: 2, type: "SHORT", normalized: true },
+ "snorm16x4": { numComponents: 4, type: "SHORT", normalized: true },
+ "float16x2": { numComponents: 2, type: "HALF_FLOAT", normalized: false },
+ "float16x4": { numComponents: 4, type: "HALF_FLOAT", normalized: false },
+ "float32": { numComponents: 1, type: "FLOAT", normalized: false },
+ "float32x2": { numComponents: 2, type: "FLOAT", normalized: false },
+ "float32x3": { numComponents: 3, type: "FLOAT", normalized: false },
+ "float32x4": { numComponents: 4, type: "FLOAT", normalized: false },
+ "uint32": { numComponents: 1, type: "UNSIGNED_INT", normalized: false },
+ "uint32x2": { numComponents: 2, type: "UNSIGNED_INT", normalized: false },
+ "uint32x3": { numComponents: 3, type: "UNSIGNED_INT", normalized: false },
+ "uint32x4": { numComponents: 4, type: "UNSIGNED_INT", normalized: false },
+ "sint32": { numComponents: 1, type: "INT", normalized: false },
+ "sint32x2": { numComponents: 2, type: "INT", normalized: false },
+ "sint32x3": { numComponents: 3, type: "INT", normalized: false },
+ "sint32x4": { numComponents: 4, type: "INT", normalized: false },
+ "unorm10-10-10-2": { numComponents: 4, type: "UNSIGNED_INT_2_10_10_10_REV", normalized: true },
+};
+
+
+interface IGLVertexFormat
+{
+ /**
+ * 顶点数据元素数量。
+ */
+ numComponents: 1 | 2 | 3 | 4;
+
+ /**
+ * 属性缓冲数据类型
+ *
+ * 默认从Buffer数据中获取,如果未取到则默认为 "FLOAT" 。
+ */
+ type: IGLVertexAttributeTypes;
+
+ /**
+ * 是否标准化。
+ */
+ normalized: boolean;
+}
+
+/**
+ * 属性缓冲数据类型
+ *
+ * A GLenum specifying the data type of each component in the array. Possible values:
+ *
+ * * gl.BYTE: signed 8-bit integer, with values in [-128, 127]
+ * * gl.SHORT: signed 16-bit integer, with values in [-32768, 32767]
+ * * gl.UNSIGNED_BYTE: unsigned 8-bit integer, with values in [0, 255]
+ * * gl.UNSIGNED_SHORT: unsigned 16-bit integer, with values in [0,65535]
+ * * gl.FLOAT: 32-bit IEEE floating point number
+ *
+ * When using a WebGL 2 context, the following values are available additionally:
+ *
+ * * gl.HALF_FLOAT: 16-bit IEEE floating point number
+ * * gl.INT: 32-bit signed binary integer
+ * * gl.UNSIGNED_INT: 32-bit unsigned binary integer
+ * * gl.INT_2_10_10_10_REV: 32-bit signed integer with values in [-512, 511]
+ * * gl.UNSIGNED_INT_2_10_10_10_REV: 32-bit unsigned integer with values in [0, 1023]
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer
+ */
+export type IGLVertexAttributeTypes = "FLOAT" | "BYTE" | "SHORT" | "UNSIGNED_BYTE" | "UNSIGNED_SHORT" // WebGL1
+ | "HALF_FLOAT" | "INT" | "UNSIGNED_INT" | "INT_2_10_10_10_REV" | "UNSIGNED_INT_2_10_10_10_REV"; // WebGL2
+
+
+/**
+ * A GLenum specifying the data type of each component in the array. Must be one of:
+ * * gl.BYTE
+ * * gl.UNSIGNED_BYTE
+ * * gl.SHORT
+ * * gl.UNSIGNED_SHORT
+ * * gl.INT
+ * * gl.UNSIGNED_INT.
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/vertexAttribIPointer
+ */
+export type IGLVertexAttributeIntegerTypes = "BYTE" | "UNSIGNED_BYTE" | "SHORT" | "UNSIGNED_SHORT" | "INT" | "UNSIGNED_INT";
\ No newline at end of file
--
Gitee
From a4d4be6901b747ffb0181a8f66a900563b314bea Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 14 Dec 2024 22:12:54 +0800
Subject: [PATCH 114/186] IVertexAttribute.format
---
examples/src/WebGL2Samples/buffer_copy.ts | 6 +-
examples/src/WebGL2Samples/buffer_uniform.ts | 10 +-
examples/src/WebGL2Samples/draw_instanced.ts | 8 +-
.../src/WebGL2Samples/draw_instanced_ubo.ts | 2 +-
.../WebGL2Samples/draw_primitive_restart.ts | 6 +-
.../src/WebGL2Samples/draw_range_arrays.ts | 6 +-
examples/src/WebGL2Samples/fbo_blit.ts | 8 +-
examples/src/WebGL2Samples/fbo_multisample.ts | 10 +-
.../WebGL2Samples/fbo_new_blend_equation.ts | 8 +-
examples/src/WebGL2Samples/fbo_read_pixels.ts | 10 +-
.../WebGL2Samples/fbo_rtt_depth_texture.ts | 10 +-
.../src/WebGL2Samples/fbo_rtt_draw_buffers.ts | 10 +-
.../WebGL2Samples/fbo_rtt_texture_array.ts | 10 +-
.../src/WebGL2Samples/geo_vertex_format.ts | 12 +-
examples/src/WebGL2Samples/glsl_centroid.ts | 16 +--
.../glsl_flat_smooth_interpolators.ts | 12 +-
.../WebGL2Samples/glsl_non_square_matrix.ts | 10 +-
examples/src/WebGL2Samples/query_occlusion.ts | 6 +-
examples/src/WebGL2Samples/sampler_filter.ts | 8 +-
examples/src/WebGL2Samples/sampler_object.ts | 8 +-
examples/src/WebGL2Samples/sampler_wrap.ts | 8 +-
.../src/WebGL2Samples/texture_2d_array.ts | 8 +-
examples/src/WebGL2Samples/texture_3d.ts | 8 +-
.../src/WebGL2Samples/texture_derivative.ts | 8 +-
examples/src/WebGL2Samples/texture_fetch.ts | 8 +-
examples/src/WebGL2Samples/texture_format.ts | 8 +-
examples/src/WebGL2Samples/texture_grad.ts | 8 +-
.../src/WebGL2Samples/texture_immutable.ts | 10 +-
examples/src/WebGL2Samples/texture_integer.ts | 8 +-
examples/src/WebGL2Samples/texture_lod.ts | 8 +-
examples/src/WebGL2Samples/texture_offset.ts | 8 +-
.../src/WebGL2Samples/texture_pixel_store.ts | 8 +-
examples/src/WebGL2Samples/texture_srgb.ts | 8 +-
examples/src/WebGL2Samples/texture_vertex.ts | 16 +--
examples/src/regl-examples/basic.ts | 2 +-
examples/src/regl-examples/batch.ts | 6 +-
examples/src/regl-examples/blur.ts | 7 +-
examples/src/regl-examples/bunny.ts | 2 +-
examples/src/regl-examples/camera.ts | 4 +-
examples/src/regl-examples/cloth.ts | 6 +-
examples/src/regl-examples/cube.ts | 4 +-
examples/src/webgl-examples/sample3.ts | 8 +-
examples/src/webgl-examples/sample4.ts | 8 +-
examples/src/webgl-examples/sample5.ts | 8 +-
examples/src/webgl-examples/sample6.ts | 8 +-
examples/src/webgl-examples/sample7.ts | 12 +-
examples/src/webgl-examples/sample8.ts | 12 +-
src/data/IGLAttributeInfo.ts | 2 +-
src/data/IGLBuffer.ts | 12 ++
src/data/IGLVertexAttributes.ts | 74 -----------
src/index.ts | 2 +
src/runs/getIGLBuffer.ts | 3 +-
src/runs/runVertexAttribute.ts | 103 +--------------
src/utils/getIVertexFormat.ts | 123 ++++++++++++++++++
54 files changed, 319 insertions(+), 385 deletions(-)
delete mode 100644 src/data/IGLVertexAttributes.ts
create mode 100644 src/utils/getIVertexFormat.ts
diff --git a/examples/src/WebGL2Samples/buffer_copy.ts b/examples/src/WebGL2Samples/buffer_copy.ts
index c08e0f0..b30d141 100644
--- a/examples/src/WebGL2Samples/buffer_copy.ts
+++ b/examples/src/WebGL2Samples/buffer_copy.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLCopyBufferToBuffer, IVertexAttributes, IGLVertexBuffer, WebGL, getIGLBuffer } from "@feng3d/webgl";
+import { IRenderPass, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLCopyBufferToBuffer, IGLVertexBuffer, WebGL, getIGLBuffer } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -44,7 +44,7 @@ import { getShaderSource } from "./utility";
// -- Init Vertex Array
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- pos: { data: vertexPosBufferDst, numComponents: 2 },
+ pos: { data: vertexPosBufferDst, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/buffer_uniform.ts b/examples/src/WebGL2Samples/buffer_uniform.ts
index 4b6d6e7..349eeec 100644
--- a/examples/src/WebGL2Samples/buffer_uniform.ts
+++ b/examples/src/WebGL2Samples/buffer_uniform.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLUniformBuffer, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLUniformBuffer, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -70,9 +70,9 @@ import { getShaderSource } from "./utility";
// -- Init Vertex Array
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: vertices, numComponents: 3, vertexSize: 40, offset: 0 },
- normal: { data: vertices, numComponents: 3, vertexSize: 40, offset: 12 },
- color: { data: vertices, numComponents: 4, vertexSize: 40, offset: 24 },
+ position: { data: vertices, format: "float32x3", arrayStride: 40, offset: 0 },
+ normal: { data: vertices, format: "float32x3", arrayStride: 40, offset: 12 },
+ color: { data: vertices, format: "float32x4", arrayStride: 40, offset: 24 },
},
};
diff --git a/examples/src/WebGL2Samples/draw_instanced.ts b/examples/src/WebGL2Samples/draw_instanced.ts
index 13ba06e..96954c0 100644
--- a/examples/src/WebGL2Samples/draw_instanced.ts
+++ b/examples/src/WebGL2Samples/draw_instanced.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -26,8 +26,8 @@ const program: IRenderPipeline = {
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- pos: { data: vertexPosBuffer, numComponents: 2 },
- color: { data: vertexColorBuffer, numComponents: 3, divisor: 1 },
+ pos: { data: vertexPosBuffer, format: "float32x2" },
+ color: { data: vertexColorBuffer, format: "float32x3", stepMode: "instance" },
},
};
diff --git a/examples/src/WebGL2Samples/draw_instanced_ubo.ts b/examples/src/WebGL2Samples/draw_instanced_ubo.ts
index 47f8835..c2da5c0 100644
--- a/examples/src/WebGL2Samples/draw_instanced_ubo.ts
+++ b/examples/src/WebGL2Samples/draw_instanced_ubo.ts
@@ -46,7 +46,7 @@ const rp: IRenderPass = {
renderObjects: [{
pipeline: program,
vertices: {
- pos: { data: vertices, numComponents: 2 },
+ pos: { data: vertices, format: "float32x2" },
},
uniforms: {
Transform: uniformTransformBuffer,
diff --git a/examples/src/WebGL2Samples/draw_primitive_restart.ts b/examples/src/WebGL2Samples/draw_primitive_restart.ts
index d11fe39..8f0d179 100644
--- a/examples/src/WebGL2Samples/draw_primitive_restart.ts
+++ b/examples/src/WebGL2Samples/draw_primitive_restart.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -39,7 +39,7 @@ const indices = new Uint16Array([
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- pos: { data: vertexPosBuffer, numComponents: 2 },
+ pos: { data: vertexPosBuffer, format: "float32x2" },
},
};
diff --git a/examples/src/WebGL2Samples/draw_range_arrays.ts b/examples/src/WebGL2Samples/draw_range_arrays.ts
index 4edd8d2..809cdfe 100644
--- a/examples/src/WebGL2Samples/draw_range_arrays.ts
+++ b/examples/src/WebGL2Samples/draw_range_arrays.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -39,7 +39,7 @@ const pipeline: IRenderPipeline = {
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: vertexPosBuffer, numComponents: 2 },
+ position: { data: vertexPosBuffer, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/fbo_blit.ts b/examples/src/WebGL2Samples/fbo_blit.ts
index ebe02ac..3f91c35 100644
--- a/examples/src/WebGL2Samples/fbo_blit.ts
+++ b/examples/src/WebGL2Samples/fbo_blit.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, ITextureView } from "@feng3d/render-api";
-import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLSampler, IVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, ITextureView, IVertexAttributes } from "@feng3d/render-api";
+import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLSampler, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -40,8 +40,8 @@ const vertexTexBuffer = new Float32Array([
]);
const vertices: IVertexAttributes = {
- position: { data: vertexPosBuffer, numComponents: 2 },
- texcoord: { data: vertexTexBuffer, numComponents: 2 },
+ position: { data: vertexPosBuffer, format: "float32x2" },
+ texcoord: { data: vertexTexBuffer, format: "float32x2" },
};
loadImage("../../assets/img/Di-3d.png", (image) =>
diff --git a/examples/src/WebGL2Samples/fbo_multisample.ts b/examples/src/WebGL2Samples/fbo_multisample.ts
index d1fcbfe..ad7d930 100644
--- a/examples/src/WebGL2Samples/fbo_multisample.ts
+++ b/examples/src/WebGL2Samples/fbo_multisample.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -85,12 +85,12 @@ const framebuffer: IRenderPassDescriptor = {
// -- Init VertexArray
const vertexArrays: { vertices?: IVertexAttributes }[] = [
{
- vertices: { position: { data: data, numComponents: 2 } }
+ vertices: { position: { data: data, format: "float32x2" } }
},
{
vertices: {
- position: { data: positions, numComponents: 2 },
- texcoord: { data: texCoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ texcoord: { data: texCoords, format: "float32x2" },
}
},
];
diff --git a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
index 7af9071..52826a1 100644
--- a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
+++ b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -86,8 +86,8 @@ const texcoords = new Float32Array([
// -- Initilize vertex array
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- textureCoordinates: { data: texcoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ textureCoordinates: { data: texcoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/fbo_read_pixels.ts b/examples/src/WebGL2Samples/fbo_read_pixels.ts
index 40c7ede..ada1f72 100644
--- a/examples/src/WebGL2Samples/fbo_read_pixels.ts
+++ b/examples/src/WebGL2Samples/fbo_read_pixels.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -86,14 +86,14 @@ const texcoords = new Float32Array([
const multipleOutputVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
}
};
const layerVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- textureCoordinates: { data: texcoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ textureCoordinates: { data: texcoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
index 04131c0..8deb449 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -61,14 +61,14 @@ const quadTexcoords = new Float32Array([
const triVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: triPositions, numComponents: 3 },
+ position: { data: triPositions, format: "float32x3" },
}
};
const quadVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: quadPositions, numComponents: 2 },
- textureCoordinates: { data: quadTexcoords, numComponents: 2 },
+ position: { data: quadPositions, format: "float32x2" },
+ textureCoordinates: { data: quadTexcoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
index 81f4275..8296479 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -62,14 +62,14 @@ const quadTexcoords = new Float32Array([
const triVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: triPositions, numComponents: 3 }
+ position: { data: triPositions, format: "float32x3" }
}
};
const quadVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: quadPositions, numComponents: 2 },
- textureCoordinates: { data: quadTexcoords, numComponents: 2 },
+ position: { data: quadPositions, format: "float32x2" },
+ textureCoordinates: { data: quadTexcoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
index 593955b..a89e620 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -86,14 +86,14 @@ const texcoords = new Float32Array([
const multipleOutputVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
}
};
const layerVertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- textureCoordinates: { data: texcoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ textureCoordinates: { data: texcoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index 14042d3..328b71c 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { HalfFloat } from "./third-party/HalfFloatUtility";
import { getShaderSource, loadImage } from "./utility";
@@ -19,7 +19,7 @@ import { getShaderSource, loadImage } from "./utility";
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
primitive: { topology: "triangle-list", cullFace: "back" },
- depthStencil: { },
+ depthStencil: {},
};
// -- Init geometries
@@ -153,9 +153,9 @@ import { getShaderSource, loadImage } from "./utility";
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- a_position: { type: "FLOAT", data: positions, numComponents: 3 },
- a_normal: { type: "HALF_FLOAT", data: normals, numComponents: 3 },
- a_texCoord: { type: "HALF_FLOAT", data: texCoords, numComponents: 2 },
+ a_position: { data: positions, format: "float32x3" },
+ a_normal: { data: normals, format: "float16x4", arrayStride: 6 }, // 由于不支持类型 "float16x3",则需要设置 arrayStride 为6,表示每次间隔3个半浮点数。
+ a_texCoord: { data: texCoords, format: "float16x2" },
},
};
diff --git a/examples/src/WebGL2Samples/glsl_centroid.ts b/examples/src/WebGL2Samples/glsl_centroid.ts
index a3547c8..b30b554 100644
--- a/examples/src/WebGL2Samples/glsl_centroid.ts
+++ b/examples/src/WebGL2Samples/glsl_centroid.ts
@@ -1,5 +1,5 @@
-import { IPassEncoder, IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IPassEncoder, IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -136,20 +136,20 @@ const framebuffers: IRenderPassDescriptor[] = [
const vertexArrays: { vertices?: IVertexAttributes }[] = [
{
vertices: {
- position: { data: positions, numComponents: 2 },
- data: { data: data, numComponents: 1 },
+ position: { data: positions, format: "float32x2" },
+ data: { data: data, format: "float32" },
}
},
{
vertices: {
- position: { data: positions, numComponents: 2 },
- data: { data: data, numComponents: 1 },
+ position: { data: positions, format: "float32x2" },
+ data: { data: data, format: "float32" },
}
},
{
vertices: {
- position: { data: textureVertexPositions, numComponents: 2 },
- texcoord: { data: textureVertexTexCoords, numComponents: 2 },
+ position: { data: textureVertexPositions, format: "float32x2" },
+ texcoord: { data: textureVertexTexCoords, format: "float32x2" },
}
},
];
diff --git a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
index 5cb17dd..8109231 100644
--- a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
+++ b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IVertexAttributes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { getIVertexFormat, IGLCanvasContext, IGLIndicesDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
import { getShaderSource } from "./utility";
@@ -104,12 +104,12 @@ glTFLoader.loadGLTF(gltfUrl, function (glTF)
vertexArray = {
vertices: {
position: {
- data: vertices, numComponents: positionInfo.size, normalized: false,
- vertexSize: positionInfo.stride, offset: positionInfo.offset
+ data: vertices, format: getIVertexFormat(positionInfo.size),
+ arrayStride: positionInfo.stride, offset: positionInfo.offset
},
normal: {
- data: vertices, numComponents: normalInfo.size, normalized: false,
- vertexSize: normalInfo.stride, offset: normalInfo.offset
+ data: vertices, format: getIVertexFormat(normalInfo.size),
+ arrayStride: normalInfo.stride, offset: normalInfo.offset
},
},
};
diff --git a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
index 28ae13f..fb42a36 100644
--- a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
+++ b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -14,7 +14,7 @@ const webgl = new WebGL(rc);
// -- Init program
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
- primitive: { topology:"triangle-list" },
+ primitive: { topology: "triangle-list" },
};
// -- Init buffers: vec2 Position, vec2 Texcoord
@@ -39,8 +39,8 @@ const texCoords = new Float32Array([
// -- Init VertexArray
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- texcoord: { data: texCoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ texcoord: { data: texCoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/query_occlusion.ts b/examples/src/WebGL2Samples/query_occlusion.ts
index 4d8798c..f76b58f 100644
--- a/examples/src/WebGL2Samples/query_occlusion.ts
+++ b/examples/src/WebGL2Samples/query_occlusion.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLOcclusionQuery, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLOcclusionQuery, WebGL } from "@feng3d/webgl";
import { watcher } from "@feng3d/watcher";
@@ -37,7 +37,7 @@ const vertices = new Float32Array([
// -- Init Vertex Array
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- pos: { data: vertices, numComponents: 3, normalized: false, vertexSize: 0, offset: 0 },
+ pos: { data: vertices, format: "float32x3", arrayStride: 0, offset: 0 },
}
};
diff --git a/examples/src/WebGL2Samples/sampler_filter.ts b/examples/src/WebGL2Samples/sampler_filter.ts
index 7a63f52..f4c9cc4 100644
--- a/examples/src/WebGL2Samples/sampler_filter.ts
+++ b/examples/src/WebGL2Samples/sampler_filter.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -87,8 +87,8 @@ const texcoords = new Float32Array([
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- textureCoordinates: { data: texcoords, numComponents: 2 },
+ position: { data: positions, format:"float32x2" },
+ textureCoordinates: { data: texcoords, format:"float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/sampler_object.ts b/examples/src/WebGL2Samples/sampler_object.ts
index 1af4279..03a5021 100644
--- a/examples/src/WebGL2Samples/sampler_object.ts
+++ b/examples/src/WebGL2Samples/sampler_object.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -43,8 +43,8 @@ const texcoords = new Float32Array([
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- textureCoordinates: { data: texcoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ textureCoordinates: { data: texcoords, format: "float32x2" },
},
};
diff --git a/examples/src/WebGL2Samples/sampler_wrap.ts b/examples/src/WebGL2Samples/sampler_wrap.ts
index 074fdac..a771036 100644
--- a/examples/src/WebGL2Samples/sampler_wrap.ts
+++ b/examples/src/WebGL2Samples/sampler_wrap.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -87,8 +87,8 @@ const texcoords = new Float32Array([
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- textureCoordinates: { data: texcoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ textureCoordinates: { data: texcoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/texture_2d_array.ts b/examples/src/WebGL2Samples/texture_2d_array.ts
index 3583905..3116f35 100644
--- a/examples/src/WebGL2Samples/texture_2d_array.ts
+++ b/examples/src/WebGL2Samples/texture_2d_array.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -40,8 +40,8 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init VertexArray
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- texcoord: { data: texCoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ texcoord: { data: texCoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/texture_3d.ts b/examples/src/WebGL2Samples/texture_3d.ts
index 864ca62..4799c02 100644
--- a/examples/src/WebGL2Samples/texture_3d.ts
+++ b/examples/src/WebGL2Samples/texture_3d.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource } from "./utility";
@@ -119,8 +119,8 @@ import { getShaderSource } from "./utility";
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- in_texcoord: { data: texCoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ in_texcoord: { data: texCoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index c983760..f786ee1 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -119,8 +119,8 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init VertexArray
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 3 },
- texcoord: { data: texCoords, numComponents: 2 },
+ position: { data: positions, format: "float32x3" },
+ texcoord: { data: texCoords, format: "float32x2" },
},
};
diff --git a/examples/src/WebGL2Samples/texture_fetch.ts b/examples/src/WebGL2Samples/texture_fetch.ts
index a6f748c..b8ade41 100644
--- a/examples/src/WebGL2Samples/texture_fetch.ts
+++ b/examples/src/WebGL2Samples/texture_fetch.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -39,8 +39,8 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init VertexArray
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- texcoord: { data: texCoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ texcoord: { data: texCoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/texture_format.ts b/examples/src/WebGL2Samples/texture_format.ts
index e669d24..1be3901 100644
--- a/examples/src/WebGL2Samples/texture_format.ts
+++ b/examples/src/WebGL2Samples/texture_format.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, ITextureFormat } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, ITextureFormat, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -75,8 +75,8 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init VertexArray
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- texcoord: { data: texCoords, numComponents: 2 },
+ position: { data: positions, format:"float32x2" },
+ texcoord: { data: texCoords, format:"float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/texture_grad.ts b/examples/src/WebGL2Samples/texture_grad.ts
index dc3386d..e6c9a88 100644
--- a/examples/src/WebGL2Samples/texture_grad.ts
+++ b/examples/src/WebGL2Samples/texture_grad.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -113,8 +113,8 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init VertexArray
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 3 },
- texcoord: { data: texCoords, numComponents: 2 },
+ position: { data: positions, format: "float32x3" },
+ texcoord: { data: texCoords, format: "float32x2" },
},
};
diff --git a/examples/src/WebGL2Samples/texture_immutable.ts b/examples/src/WebGL2Samples/texture_immutable.ts
index 97e26ed..0043c56 100644
--- a/examples/src/WebGL2Samples/texture_immutable.ts
+++ b/examples/src/WebGL2Samples/texture_immutable.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource, loadImage } from "./utility";
@@ -64,9 +64,9 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init VertexArray
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- in_texcoord: { data: texCoords, numComponents: 2 },
- texcoord: { data: texCoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ in_texcoord: { data: texCoords, format: "float32x2" },
+ texcoord: { data: texCoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/texture_integer.ts b/examples/src/WebGL2Samples/texture_integer.ts
index 347d0ae..70db3fe 100644
--- a/examples/src/WebGL2Samples/texture_integer.ts
+++ b/examples/src/WebGL2Samples/texture_integer.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -41,8 +41,8 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init VertexArray
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- texcoord: { data: texCoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ texcoord: { data: texCoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/texture_lod.ts b/examples/src/WebGL2Samples/texture_lod.ts
index 479c69e..beeb780 100644
--- a/examples/src/WebGL2Samples/texture_lod.ts
+++ b/examples/src/WebGL2Samples/texture_lod.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -113,8 +113,8 @@ import { getShaderSource, loadImage } from "./utility";
// -- Initialize vertex array
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- textureCoordinates: { data: texcoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ textureCoordinates: { data: texcoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/texture_offset.ts b/examples/src/WebGL2Samples/texture_offset.ts
index 1f5490d..83cec49 100644
--- a/examples/src/WebGL2Samples/texture_offset.ts
+++ b/examples/src/WebGL2Samples/texture_offset.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -64,8 +64,8 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init VertexArray
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, numComponents: 2 },
- texcoord: { data: texCoords, numComponents: 2 },
+ position: { data: positions, format: "float32x2" },
+ texcoord: { data: texCoords, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/texture_pixel_store.ts b/examples/src/WebGL2Samples/texture_pixel_store.ts
index a93722c..a3455e4 100644
--- a/examples/src/WebGL2Samples/texture_pixel_store.ts
+++ b/examples/src/WebGL2Samples/texture_pixel_store.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, IVertexAttributes, IVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { getIGLBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -42,8 +42,8 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init VertexArray
const vertexArray: { vertices?: IVertexAttributes, indices?: IGLIndicesDataTypes } = {
vertices: {
- position: { data: vertexPosBuffer, numComponents: 2 },
- texcoord: { data: vertexTexBuffer, numComponents: 2 },
+ position: { data: vertexPosBuffer, format: "float32x2" },
+ texcoord: { data: vertexTexBuffer, format: "float32x2" },
}
};
diff --git a/examples/src/WebGL2Samples/texture_srgb.ts b/examples/src/WebGL2Samples/texture_srgb.ts
index d3c99bd..32a9eac 100644
--- a/examples/src/WebGL2Samples/texture_srgb.ts
+++ b/examples/src/WebGL2Samples/texture_srgb.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, IGLSampler, IVertexAttributes, IVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { getIGLBuffer, IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -45,8 +45,8 @@ import { getShaderSource, loadImage } from "./utility";
// -- Initialize vertex array
const vertices: IVertexAttributes = {
- position: { data: vertexPosBuffer, numComponents: 2 },
- textureCoordinates: { data: vertexTexBuffer, numComponents: 2 },
+ position: { data: vertexPosBuffer, format: "float32x2" },
+ textureCoordinates: { data: vertexTexBuffer, format: "float32x2" },
}
// -- Load texture then render
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index 8c11ea3..94afad7 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -1,5 +1,5 @@
-import { IPrimitiveTopology, IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, IVertexAttributes, IVertexDataTypes, WebGL } from "@feng3d/webgl";
+import { IPrimitiveTopology, IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { getIVertexFormat, IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
@@ -17,7 +17,7 @@ import { getShaderSource, loadImage } from "./utility";
4: "triangle-list",
};
- const VertexAttributeType2Name = {
+ const VertexAttributeType2Name = Object.freeze({
5126: "FLOAT",
5120: "BYTE",
5122: "SHORT",
@@ -28,7 +28,7 @@ import { getShaderSource, loadImage } from "./utility";
5125: "UNSIGNED_INT",
36255: "INT_2_10_10_10_REV",
33640: "UNSIGNED_INT_2_10_10_10_REV"
- };
+ });
const canvas = document.createElement("canvas");
canvas.id = "glcanvas";
@@ -42,7 +42,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init program
const program: IRenderPipeline = {
vertex: { code: getShaderSource("vs") }, fragment: { code: getShaderSource("fs") },
- depthStencil: { depthCompare:"less" },
+ depthStencil: { depthCompare: "less" },
};
const vertexArrayMaps: { [key: string]: { vertices?: IVertexAttributes, indices: IGLIndicesDataTypes }[] } = {};
@@ -94,9 +94,9 @@ import { getShaderSource, loadImage } from "./utility";
//
vertexArrayMaps[mid].push({
vertices: {
- position: { data: vertexBuffer, numComponents: positionInfo.size, type: VertexAttributeType2Name[positionInfo.type], vertexSize: positionInfo.stride, offset: positionInfo.offset },
- normal: { data: vertexBuffer, numComponents: normalInfo.size, type: VertexAttributeType2Name[normalInfo.type], vertexSize: normalInfo.stride, offset: normalInfo.offset },
- texcoord: { data: vertexBuffer, numComponents: texcoordInfo.size, type: VertexAttributeType2Name[texcoordInfo.type], vertexSize: texcoordInfo.stride, offset: texcoordInfo.offset },
+ position: { data: vertexBuffer, format: getIVertexFormat(positionInfo.size, VertexAttributeType2Name[positionInfo.type]), arrayStride: positionInfo.stride, offset: positionInfo.offset },
+ normal: { data: vertexBuffer, format: getIVertexFormat(normalInfo.size, VertexAttributeType2Name[normalInfo.type]), arrayStride: normalInfo.stride, offset: normalInfo.offset },
+ texcoord: { data: vertexBuffer, format: getIVertexFormat(texcoordInfo.size, VertexAttributeType2Name[texcoordInfo.type]), arrayStride: texcoordInfo.stride, offset: texcoordInfo.offset },
}, indices: indicesBuffer
});
}
diff --git a/examples/src/regl-examples/basic.ts b/examples/src/regl-examples/basic.ts
index 99d9c48..9c5fb5f 100644
--- a/examples/src/regl-examples/basic.ts
+++ b/examples/src/regl-examples/basic.ts
@@ -24,7 +24,7 @@ const renderObject: IRenderObject = {
0, -1,
1, 1
]),
- numComponents: 2
+ format: "float32x2",
},
},
uniforms: { color: [1, 0, 0, 1] },
diff --git a/examples/src/regl-examples/batch.ts b/examples/src/regl-examples/batch.ts
index 6b10562..0ea7d2d 100644
--- a/examples/src/regl-examples/batch.ts
+++ b/examples/src/regl-examples/batch.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPipeline } from "@feng3d/render-api";
-import { IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { WebGL } from "@feng3d/webgl";
const canvas = document.createElement("canvas");
canvas.id = "glcanvas";
@@ -49,7 +49,7 @@ const vertexArray: { vertices?: IVertexAttributes } = {
0, 0.5,
1, 1
]),
- numComponents: 2
+ format: "float32x2",
},
}
};
diff --git a/examples/src/regl-examples/blur.ts b/examples/src/regl-examples/blur.ts
index a393609..021dd1c 100644
--- a/examples/src/regl-examples/blur.ts
+++ b/examples/src/regl-examples/blur.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPipeline } from "@feng3d/render-api";
-import { IVertexAttributes, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { WebGL } from "@feng3d/webgl";
import { fit } from "./hughsk/canvas-fit";
import { attachCamera } from "./hughsk/canvas-orbit-camera";
@@ -34,11 +34,12 @@ const offsets = [{ offset: [-1, -1] },
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
position: {
+ format: "float32x2",
data: new Float32Array([
0.5, 0,
0, 0.5,
1, 1
- ]), numComponents: 2
+ ]),
},
}
};
diff --git a/examples/src/regl-examples/bunny.ts b/examples/src/regl-examples/bunny.ts
index 6d5c155..b66abc5 100644
--- a/examples/src/regl-examples/bunny.ts
+++ b/examples/src/regl-examples/bunny.ts
@@ -32,7 +32,7 @@ let viewportHeight = canvas.clientHeight;
const renderObject: IRenderObject = {
vertices: {
- position: { data: new Float32Array(positions), numComponents: 3 },
+ position: { data: new Float32Array(positions),format:"float32x3" },
},
indices: new Uint16Array(indices),
uniforms: {
diff --git a/examples/src/regl-examples/camera.ts b/examples/src/regl-examples/camera.ts
index 035226c..ff7075c 100644
--- a/examples/src/regl-examples/camera.ts
+++ b/examples/src/regl-examples/camera.ts
@@ -40,8 +40,8 @@ const normals = angleNormals(bunny.cells, bunny.positions).reduce((pv: number[],
const renderObject: IRenderObject = {
vertices: {
- position: { data: new Float32Array(positions), numComponents: 3 },
- normal: { data: new Float32Array(normals), numComponents: 3 },
+ position: { data: new Float32Array(positions), format: "float32x3" },
+ normal: { data: new Float32Array(normals), format: "float32x3" },
},
indices: new Uint16Array(indices),
uniforms: {},
diff --git a/examples/src/regl-examples/cloth.ts b/examples/src/regl-examples/cloth.ts
index 3b8bef7..5499d22 100644
--- a/examples/src/regl-examples/cloth.ts
+++ b/examples/src/regl-examples/cloth.ts
@@ -166,9 +166,9 @@ import * as vec3 from "./stackgl/gl-vec3";
const renderObject: IRenderObject = {
vertices: {
- position: { data: new Float32Array(positions), numComponents: 3 },
- normal: { data: new Float32Array(normals), numComponents: 3 },
- uv: { data: new Float32Array(uvs), numComponents: 2 },
+ position: { data: new Float32Array(positions), format: "float32x3" },
+ normal: { data: new Float32Array(normals), format: "float32x3" },
+ uv: { data: new Float32Array(uvs), format: "float32x2" },
},
indices: new Uint16Array(indices),
uniforms: {
diff --git a/examples/src/regl-examples/cube.ts b/examples/src/regl-examples/cube.ts
index f0fff39..53e33a1 100644
--- a/examples/src/regl-examples/cube.ts
+++ b/examples/src/regl-examples/cube.ts
@@ -66,8 +66,8 @@ import * as mat4 from "./stackgl/gl-mat4";
const renderObject: IRenderObject = {
vertices: {
- position: { data: new Float32Array(positions), numComponents: 3 },
- uv: { data: new Float32Array(uvs), numComponents: 2 },
+ position: { data: new Float32Array(positions), format: "float32x3" },
+ uv: { data: new Float32Array(uvs), format: "float32x2" },
},
indices: new Uint16Array(indices),
uniforms: {
diff --git a/examples/src/webgl-examples/sample3.ts b/examples/src/webgl-examples/sample3.ts
index 0377ec6..b666ea9 100644
--- a/examples/src/webgl-examples/sample3.ts
+++ b/examples/src/webgl-examples/sample3.ts
@@ -56,26 +56,22 @@ function main()
},
vertices: {
aVertexPosition: {
- type: "FLOAT",
+ format: "float32x2",
data: new Float32Array([
1.0, 1.0,
-1.0, 1.0,
1.0, -1.0,
-1.0, -1.0,
]),
- numComponents: 2,
- normalized: false,
},
aVertexColor: {
- type: "FLOAT",
+ format: "float32x4",
data: new Float32Array([
1.0, 1.0, 1.0, 1.0, // white
1.0, 0.0, 0.0, 1.0, // red
0.0, 1.0, 0.0, 1.0, // green
0.0, 0.0, 1.0, 1.0, // blue
]),
- numComponents: 4,
- normalized: false,
},
},
uniforms: {
diff --git a/examples/src/webgl-examples/sample4.ts b/examples/src/webgl-examples/sample4.ts
index ed46460..bf89c1f 100644
--- a/examples/src/webgl-examples/sample4.ts
+++ b/examples/src/webgl-examples/sample4.ts
@@ -44,26 +44,22 @@ function main()
},
vertices: {
aVertexPosition: {
- type: "FLOAT",
+ format: "float32x2",
data: new Float32Array([
1.0, 1.0,
-1.0, 1.0,
1.0, -1.0,
-1.0, -1.0,
]),
- numComponents: 2,
- normalized: false,
},
aVertexColor: {
- type: "FLOAT",
+ format: "float32x4",
data: new Float32Array([
1.0, 1.0, 1.0, 1.0, // white
1.0, 0.0, 0.0, 1.0, // red
0.0, 1.0, 0.0, 1.0, // green
0.0, 0.0, 1.0, 1.0, // blue
]),
- numComponents: 4,
- normalized: false,
},
},
uniforms: {},
diff --git a/examples/src/webgl-examples/sample5.ts b/examples/src/webgl-examples/sample5.ts
index f240259..b05b586 100644
--- a/examples/src/webgl-examples/sample5.ts
+++ b/examples/src/webgl-examples/sample5.ts
@@ -48,16 +48,12 @@ function main()
},
vertices: {
aVertexPosition: {
- type: "FLOAT",
+ format: "float32x3",
data: buffers.position,
- numComponents: 3,
- normalized: false,
},
aVertexColor: {
- type: "FLOAT",
+ format: "float32x4",
data: buffers.color,
- numComponents: 4,
- normalized: false,
},
},
indices: buffers.indices,
diff --git a/examples/src/webgl-examples/sample6.ts b/examples/src/webgl-examples/sample6.ts
index 377f369..1a2ab35 100644
--- a/examples/src/webgl-examples/sample6.ts
+++ b/examples/src/webgl-examples/sample6.ts
@@ -52,16 +52,12 @@ async function main()
},
vertices: {
aVertexPosition: {
- type: "FLOAT",
+ format: "float32x3",
data: buffers.position,
- numComponents: 3,
- normalized: false,
},
aTextureCoord: {
- type: "FLOAT",
+ format: "float32x2",
data: buffers.textureCoord,
- numComponents: 2,
- normalized: false,
},
},
indices: buffers.indices,
diff --git a/examples/src/webgl-examples/sample7.ts b/examples/src/webgl-examples/sample7.ts
index 42839b8..f38b9fd 100644
--- a/examples/src/webgl-examples/sample7.ts
+++ b/examples/src/webgl-examples/sample7.ts
@@ -69,22 +69,16 @@ async function main()
},
vertices: {
aVertexPosition: {
- type: "FLOAT",
+ format: "float32x3",
data: buffers.position,
- numComponents: 3,
- normalized: false,
},
aVertexNormal: {
- type: "FLOAT",
+ format: "float32x3",
data: buffers.normal,
- numComponents: 3,
- normalized: false,
},
aTextureCoord: {
- type: "FLOAT",
+ format: "float32x2",
data: buffers.textureCoord,
- numComponents: 2,
- normalized: false,
},
},
indices: buffers.indices,
diff --git a/examples/src/webgl-examples/sample8.ts b/examples/src/webgl-examples/sample8.ts
index fe04324..ad5d1d3 100644
--- a/examples/src/webgl-examples/sample8.ts
+++ b/examples/src/webgl-examples/sample8.ts
@@ -73,22 +73,16 @@ function main()
},
vertices: {
aVertexPosition: {
- type: "FLOAT",
+ format: "float32x3",
data: buffers.position,
- numComponents: 3,
- normalized: false,
},
aVertexNormal: {
- type: "FLOAT",
+ format: "float32x3",
data: buffers.normal,
- numComponents: 3,
- normalized: false,
},
aTextureCoord: {
- type: "FLOAT",
+ format: "float32x2",
data: buffers.textureCoord,
- numComponents: 2,
- normalized: false,
},
},
indices: buffers.indices,
diff --git a/src/data/IGLAttributeInfo.ts b/src/data/IGLAttributeInfo.ts
index 4024982..38fc6c3 100644
--- a/src/data/IGLAttributeInfo.ts
+++ b/src/data/IGLAttributeInfo.ts
@@ -1,4 +1,4 @@
-import { IGLVertexAttributeTypes } from "../runs/runVertexAttribute";
+import { IGLVertexAttributeTypes } from "../utils/getIVertexFormat";
export interface IGLAttributeInfo
{
diff --git a/src/data/IGLBuffer.ts b/src/data/IGLBuffer.ts
index 0e75ffa..8499454 100644
--- a/src/data/IGLBuffer.ts
+++ b/src/data/IGLBuffer.ts
@@ -1,3 +1,5 @@
+import { IVertexDataTypes } from "@feng3d/render-api";
+
/**
* WebGL缓冲区
*
@@ -37,6 +39,16 @@ export interface IGLBuffer
writeBuffers?: IGLWriteBuffer[];
}
+export interface IGLVertexBuffer extends IGLBuffer
+{
+ target: "ARRAY_BUFFER";
+
+ /**
+ * 缓冲区数据。
+ */
+ data?: IVertexDataTypes;
+}
+
export interface IGLWriteBuffer
{
bufferOffset?: number;
diff --git a/src/data/IGLVertexAttributes.ts b/src/data/IGLVertexAttributes.ts
deleted file mode 100644
index 82b3cb0..0000000
--- a/src/data/IGLVertexAttributes.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-import { IGLVertexAttributeTypes } from "../runs/runVertexAttribute";
-import { IGLBuffer } from "./IGLBuffer";
-
-/**
- * 顶点属性数据。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/vertexAttribIPointer
- */
-export interface IGLVertexAttribute
-{
- /**
- * 顶点属性数据。
- */
- data: IVertexDataTypes;
-
- /**
- * 顶点数据元素数量。
- */
- numComponents: 1 | 2 | 3 | 4;
-
- /**
- * 属性缓冲数据类型
- *
- * 默认从Buffer数据中获取,如果未取到则默认为 "FLOAT" 。
- */
- type?: IGLVertexAttributeTypes;
-
- /**
- * 是否标准化。
- */
- normalized?: boolean;
-
- /**
- * drawElementsInstanced时将会用到的因子,表示divisor个geometry共用一个数据
- *
- * A GLuint specifying the number of instances that will pass between updates of the generic attribute.
- * @see https://developer.mozilla.org/en-US/docs/Web/API/ANGLE_instanced_arrays/vertexAttribDivisorANGLE
- */
- divisor?: number;
-
- /**
- * 所在顶点数据中的偏移字节数。
- */
- offset?: number;
-
- /**
- * 单个顶点数据尺寸。比如单个数据包含position与uv那么值可能为(3+2)*4=20。
- */
- vertexSize?: number;
-}
-
-export interface IGLVertexBuffer extends IGLBuffer
-{
- target: "ARRAY_BUFFER";
-
- /**
- * 缓冲区数据。
- */
- data?: IVertexDataTypes;
-}
-
-/**
- * 顶点属性数据类型。
- */
-export type IVertexDataTypes =
- | Float32Array
- | Uint32Array
- | Int32Array
- | Uint16Array
- | Int16Array | Uint8ClampedArray
- | Uint8Array
- | Int8Array;
-
diff --git a/src/index.ts b/src/index.ts
index 9564a8b..9d1f8f7 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -43,3 +43,5 @@ export * from "./WebGL";
export * as internal from "./internal";
export * from "./caches/getGLBuffer";
+
+export * from "./utils/getIVertexFormat";
diff --git a/src/runs/getIGLBuffer.ts b/src/runs/getIGLBuffer.ts
index 3719f0e..c4e0c6e 100644
--- a/src/runs/getIGLBuffer.ts
+++ b/src/runs/getIGLBuffer.ts
@@ -1,7 +1,6 @@
import { IVertexDataTypes } from "@feng3d/render-api";
-import { GLBufferTarget, GLBufferUsage, IGLBuffer } from "../data/IGLBuffer";
+import { GLBufferTarget, GLBufferUsage, IGLBuffer, IGLVertexBuffer } from "../data/IGLBuffer";
import { IGLIndexBuffer, IGLIndicesDataTypes } from "../data/IGLIndexBuffer";
-import { IGLVertexBuffer } from "../data/IGLVertexAttributes";
export function getIGLBuffer(data: BufferSource, target?: GLBufferTarget, usage: GLBufferUsage = "STATIC_DRAW")
{
diff --git a/src/runs/runVertexAttribute.ts b/src/runs/runVertexAttribute.ts
index 6617308..091f99f 100644
--- a/src/runs/runVertexAttribute.ts
+++ b/src/runs/runVertexAttribute.ts
@@ -1,6 +1,7 @@
import { IVertexAttribute, IVertexFormat } from "@feng3d/render-api";
import { getGLBuffer } from "../caches/getGLBuffer";
import { getIGLVertexBuffer } from "./getIGLBuffer";
+import { getIGLVertexFormat } from "../utils/getIVertexFormat";
export function runVertexAttribute(gl: WebGLRenderingContext, location: number, attribute: IVertexAttribute)
{
@@ -45,105 +46,3 @@ export function runVertexAttribute(gl: WebGLRenderingContext, location: number,
}
}
-function getIGLVertexFormat(format: IVertexFormat): IGLVertexFormat
-{
- const glVertexFormat = formatMap[format];
-
- console.assert(!!glVertexFormat, `接收到错误值,请从 ${Object.keys(formatMap).toString()} 中取值!`);
-
- return glVertexFormat;
-}
-
-const formatMap: { [key: string]: IGLVertexFormat } = {
-
- "uint8x2": { numComponents: 2, type: "UNSIGNED_BYTE", normalized: false },
- "uint8x4": { numComponents: 4, type: "UNSIGNED_BYTE", normalized: false },
- "sint8x2": { numComponents: 2, type: "BYTE", normalized: false },
- "sint8x4": { numComponents: 4, type: "BYTE", normalized: false },
- "unorm8x2": { numComponents: 2, type: "UNSIGNED_BYTE", normalized: true },
- "unorm8x4": { numComponents: 4, type: "UNSIGNED_BYTE", normalized: true },
- "snorm8x2": { numComponents: 2, type: "BYTE", normalized: true },
- "snorm8x4": { numComponents: 4, type: "BYTE", normalized: true },
- "uint16x2": { numComponents: 2, type: "UNSIGNED_SHORT", normalized: false },
- "uint16x4": { numComponents: 4, type: "UNSIGNED_SHORT", normalized: false },
- "sint16x2": { numComponents: 2, type: "SHORT", normalized: false },
- "sint16x4": { numComponents: 4, type: "SHORT", normalized: false },
- "unorm16x2": { numComponents: 2, type: "UNSIGNED_SHORT", normalized: true },
- "unorm16x4": { numComponents: 4, type: "UNSIGNED_SHORT", normalized: true },
- "snorm16x2": { numComponents: 2, type: "SHORT", normalized: true },
- "snorm16x4": { numComponents: 4, type: "SHORT", normalized: true },
- "float16x2": { numComponents: 2, type: "HALF_FLOAT", normalized: false },
- "float16x4": { numComponents: 4, type: "HALF_FLOAT", normalized: false },
- "float32": { numComponents: 1, type: "FLOAT", normalized: false },
- "float32x2": { numComponents: 2, type: "FLOAT", normalized: false },
- "float32x3": { numComponents: 3, type: "FLOAT", normalized: false },
- "float32x4": { numComponents: 4, type: "FLOAT", normalized: false },
- "uint32": { numComponents: 1, type: "UNSIGNED_INT", normalized: false },
- "uint32x2": { numComponents: 2, type: "UNSIGNED_INT", normalized: false },
- "uint32x3": { numComponents: 3, type: "UNSIGNED_INT", normalized: false },
- "uint32x4": { numComponents: 4, type: "UNSIGNED_INT", normalized: false },
- "sint32": { numComponents: 1, type: "INT", normalized: false },
- "sint32x2": { numComponents: 2, type: "INT", normalized: false },
- "sint32x3": { numComponents: 3, type: "INT", normalized: false },
- "sint32x4": { numComponents: 4, type: "INT", normalized: false },
- "unorm10-10-10-2": { numComponents: 4, type: "UNSIGNED_INT_2_10_10_10_REV", normalized: true },
-};
-
-
-interface IGLVertexFormat
-{
- /**
- * 顶点数据元素数量。
- */
- numComponents: 1 | 2 | 3 | 4;
-
- /**
- * 属性缓冲数据类型
- *
- * 默认从Buffer数据中获取,如果未取到则默认为 "FLOAT" 。
- */
- type: IGLVertexAttributeTypes;
-
- /**
- * 是否标准化。
- */
- normalized: boolean;
-}
-
-/**
- * 属性缓冲数据类型
- *
- * A GLenum specifying the data type of each component in the array. Possible values:
- *
- * * gl.BYTE: signed 8-bit integer, with values in [-128, 127]
- * * gl.SHORT: signed 16-bit integer, with values in [-32768, 32767]
- * * gl.UNSIGNED_BYTE: unsigned 8-bit integer, with values in [0, 255]
- * * gl.UNSIGNED_SHORT: unsigned 16-bit integer, with values in [0,65535]
- * * gl.FLOAT: 32-bit IEEE floating point number
- *
- * When using a WebGL 2 context, the following values are available additionally:
- *
- * * gl.HALF_FLOAT: 16-bit IEEE floating point number
- * * gl.INT: 32-bit signed binary integer
- * * gl.UNSIGNED_INT: 32-bit unsigned binary integer
- * * gl.INT_2_10_10_10_REV: 32-bit signed integer with values in [-512, 511]
- * * gl.UNSIGNED_INT_2_10_10_10_REV: 32-bit unsigned integer with values in [0, 1023]
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer
- */
-export type IGLVertexAttributeTypes = "FLOAT" | "BYTE" | "SHORT" | "UNSIGNED_BYTE" | "UNSIGNED_SHORT" // WebGL1
- | "HALF_FLOAT" | "INT" | "UNSIGNED_INT" | "INT_2_10_10_10_REV" | "UNSIGNED_INT_2_10_10_10_REV"; // WebGL2
-
-
-/**
- * A GLenum specifying the data type of each component in the array. Must be one of:
- * * gl.BYTE
- * * gl.UNSIGNED_BYTE
- * * gl.SHORT
- * * gl.UNSIGNED_SHORT
- * * gl.INT
- * * gl.UNSIGNED_INT.
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/vertexAttribIPointer
- */
-export type IGLVertexAttributeIntegerTypes = "BYTE" | "UNSIGNED_BYTE" | "SHORT" | "UNSIGNED_SHORT" | "INT" | "UNSIGNED_INT";
\ No newline at end of file
diff --git a/src/utils/getIVertexFormat.ts b/src/utils/getIVertexFormat.ts
new file mode 100644
index 0000000..1474fa1
--- /dev/null
+++ b/src/utils/getIVertexFormat.ts
@@ -0,0 +1,123 @@
+import { IVertexFormat } from "@feng3d/render-api";
+
+export function getIVertexFormat(numComponents: 1 | 2 | 3 | 4, type: IGLVertexAttributeTypes = "FLOAT", normalized = false): IVertexFormat
+{
+ for (const key in formatMap)
+ {
+ const element = formatMap[key];
+ if (
+ element.numComponents === numComponents &&
+ element.type === type &&
+ !element.normalized === !normalized
+ )
+ {
+ return key as IVertexFormat;
+ }
+ }
+
+ console.error(`没有找到与 ${JSON.stringify({ numComponents, type, normalized })} 对应的顶点数据格式!`);
+
+ return undefined;
+}
+
+export function getIGLVertexFormat(format: IVertexFormat): IGLVertexFormat
+{
+ const glVertexFormat = formatMap[format];
+
+ console.assert(!!glVertexFormat, `接收到错误值,请从 ${Object.keys(formatMap).toString()} 中取值!`);
+
+ return glVertexFormat;
+}
+
+export const formatMap: { [key: string]: IGLVertexFormat } = {
+
+ "uint8x2": { numComponents: 2, type: "UNSIGNED_BYTE", normalized: false },
+ "uint8x4": { numComponents: 4, type: "UNSIGNED_BYTE", normalized: false },
+ "sint8x2": { numComponents: 2, type: "BYTE", normalized: false },
+ "sint8x4": { numComponents: 4, type: "BYTE", normalized: false },
+ "unorm8x2": { numComponents: 2, type: "UNSIGNED_BYTE", normalized: true },
+ "unorm8x4": { numComponents: 4, type: "UNSIGNED_BYTE", normalized: true },
+ "snorm8x2": { numComponents: 2, type: "BYTE", normalized: true },
+ "snorm8x4": { numComponents: 4, type: "BYTE", normalized: true },
+ "uint16x2": { numComponents: 2, type: "UNSIGNED_SHORT", normalized: false },
+ "uint16x4": { numComponents: 4, type: "UNSIGNED_SHORT", normalized: false },
+ "sint16x2": { numComponents: 2, type: "SHORT", normalized: false },
+ "sint16x4": { numComponents: 4, type: "SHORT", normalized: false },
+ "unorm16x2": { numComponents: 2, type: "UNSIGNED_SHORT", normalized: true },
+ "unorm16x4": { numComponents: 4, type: "UNSIGNED_SHORT", normalized: true },
+ "snorm16x2": { numComponents: 2, type: "SHORT", normalized: true },
+ "snorm16x4": { numComponents: 4, type: "SHORT", normalized: true },
+ "float16x2": { numComponents: 2, type: "HALF_FLOAT", normalized: false },
+ "float16x4": { numComponents: 4, type: "HALF_FLOAT", normalized: false },
+ "float32": { numComponents: 1, type: "FLOAT", normalized: false },
+ "float32x2": { numComponents: 2, type: "FLOAT", normalized: false },
+ "float32x3": { numComponents: 3, type: "FLOAT", normalized: false },
+ "float32x4": { numComponents: 4, type: "FLOAT", normalized: false },
+ "uint32": { numComponents: 1, type: "UNSIGNED_INT", normalized: false },
+ "uint32x2": { numComponents: 2, type: "UNSIGNED_INT", normalized: false },
+ "uint32x3": { numComponents: 3, type: "UNSIGNED_INT", normalized: false },
+ "uint32x4": { numComponents: 4, type: "UNSIGNED_INT", normalized: false },
+ "sint32": { numComponents: 1, type: "INT", normalized: false },
+ "sint32x2": { numComponents: 2, type: "INT", normalized: false },
+ "sint32x3": { numComponents: 3, type: "INT", normalized: false },
+ "sint32x4": { numComponents: 4, type: "INT", normalized: false },
+ "unorm10-10-10-2": { numComponents: 4, type: "UNSIGNED_INT_2_10_10_10_REV", normalized: true },
+};
+
+
+interface IGLVertexFormat
+{
+ /**
+ * 顶点数据元素数量。
+ */
+ numComponents: 1 | 2 | 3 | 4;
+
+ /**
+ * 属性缓冲数据类型
+ *
+ * 默认从Buffer数据中获取,如果未取到则默认为 "FLOAT" 。
+ */
+ type: IGLVertexAttributeTypes;
+
+ /**
+ * 是否标准化。
+ */
+ normalized: boolean;
+}
+
+/**
+ * 属性缓冲数据类型
+ *
+ * A GLenum specifying the data type of each component in the array. Possible values:
+ *
+ * * gl.BYTE: signed 8-bit integer, with values in [-128, 127]
+ * * gl.SHORT: signed 16-bit integer, with values in [-32768, 32767]
+ * * gl.UNSIGNED_BYTE: unsigned 8-bit integer, with values in [0, 255]
+ * * gl.UNSIGNED_SHORT: unsigned 16-bit integer, with values in [0,65535]
+ * * gl.FLOAT: 32-bit IEEE floating point number
+ *
+ * When using a WebGL 2 context, the following values are available additionally:
+ *
+ * * gl.HALF_FLOAT: 16-bit IEEE floating point number
+ * * gl.INT: 32-bit signed binary integer
+ * * gl.UNSIGNED_INT: 32-bit unsigned binary integer
+ * * gl.INT_2_10_10_10_REV: 32-bit signed integer with values in [-512, 511]
+ * * gl.UNSIGNED_INT_2_10_10_10_REV: 32-bit unsigned integer with values in [0, 1023]
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer
+ */
+export type IGLVertexAttributeTypes = "FLOAT" | "BYTE" | "SHORT" | "UNSIGNED_BYTE" | "UNSIGNED_SHORT" // WebGL1
+ | "HALF_FLOAT" | "INT" | "UNSIGNED_INT" | "INT_2_10_10_10_REV" | "UNSIGNED_INT_2_10_10_10_REV"; // WebGL2
+
+/**
+ * A GLenum specifying the data type of each component in the array. Must be one of:
+ * * gl.BYTE
+ * * gl.UNSIGNED_BYTE
+ * * gl.SHORT
+ * * gl.UNSIGNED_SHORT
+ * * gl.INT
+ * * gl.UNSIGNED_INT.
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/vertexAttribIPointer
+ */
+export type IGLVertexAttributeIntegerTypes = "BYTE" | "UNSIGNED_BYTE" | "SHORT" | "UNSIGNED_SHORT" | "INT" | "UNSIGNED_INT";
\ No newline at end of file
--
Gitee
From 56ce22c2ab25ae825bb109f5e0f80a649e69a938 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sun, 15 Dec 2024 17:06:36 +0800
Subject: [PATCH 115/186] IRenderObject.indices
---
.../src/WebGL2Samples/glsl_flat_smooth_interpolators.ts | 6 +++---
examples/src/WebGL2Samples/texture_pixel_store.ts | 6 +++---
examples/src/WebGL2Samples/texture_vertex.ts | 8 ++++----
examples/src/WebGL2Samples/third-party/gltf-loader.ts | 4 ++--
.../src/WebGL2Samples/transform_feedback_instanced.ts | 6 +++---
.../src/WebGL2Samples/transform_feedback_interleaved.ts | 6 +++---
.../src/WebGL2Samples/transform_feedback_separated.ts | 6 +++---
.../src/WebGL2Samples/transform_feedback_separated_2.ts | 6 +++---
src/data/IGLIndexBuffer.ts | 8 ++------
src/data/IGLRenderObject.ts | 6 ------
src/runs/getIGLBuffer.ts | 6 +++---
src/runs/runDrawCall.ts | 5 ++---
src/runs/runIndexBuffer.ts | 4 ++--
src/runs/runVertexArray.ts | 7 +++----
14 files changed, 36 insertions(+), 48 deletions(-)
diff --git a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
index 8109231..6ede06d 100644
--- a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
+++ b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
-import { getIVertexFormat, IGLCanvasContext, IGLIndicesDataTypes, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { getIVertexFormat, IGLCanvasContext, IGLViewport, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
import { getShaderSource } from "./utility";
@@ -66,7 +66,7 @@ glTFLoader.loadGLTF(gltfUrl, function (glTF)
// -- Initialize vertex array
const vertexArrayMaps: {
- [key: string]: { vertexArray: { vertices?: IVertexAttributes }, indices: IGLIndicesDataTypes }[]
+ [key: string]: { vertexArray: { vertices?: IVertexAttributes }, indices: IIndicesDataTypes }[]
} = {};
// var in loop
diff --git a/examples/src/WebGL2Samples/texture_pixel_store.ts b/examples/src/WebGL2Samples/texture_pixel_store.ts
index a3455e4..eb77430 100644
--- a/examples/src/WebGL2Samples/texture_pixel_store.ts
+++ b/examples/src/WebGL2Samples/texture_pixel_store.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { getIGLBuffer, IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -40,7 +40,7 @@ import { getShaderSource, loadImage } from "./utility";
const vertexTexBuffer: IVertexDataTypes = texCoords;
// -- Init VertexArray
- const vertexArray: { vertices?: IVertexAttributes, indices?: IGLIndicesDataTypes } = {
+ const vertexArray: { vertices?: IVertexAttributes, indices?: IIndicesDataTypes } = {
vertices: {
position: { data: vertexPosBuffer, format: "float32x2" },
texcoord: { data: vertexTexBuffer, format: "float32x2" },
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index 94afad7..ffd3ed7 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -1,5 +1,5 @@
-import { IPrimitiveTopology, IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { getIVertexFormat, IGLCanvasContext, IGLIndicesDataTypes, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IPrimitiveTopology, IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { getIVertexFormat, IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
@@ -45,13 +45,13 @@ import { getShaderSource, loadImage } from "./utility";
depthStencil: { depthCompare: "less" },
};
- const vertexArrayMaps: { [key: string]: { vertices?: IVertexAttributes, indices: IGLIndicesDataTypes }[] } = {};
+ const vertexArrayMaps: { [key: string]: { vertices?: IVertexAttributes, indices: IIndicesDataTypes }[] } = {};
// var in loop
let mesh;
let primitive: Primitive;
let vertexBuffer: IVertexDataTypes;
- let indicesBuffer: IGLIndicesDataTypes;
+ let indicesBuffer: IIndicesDataTypes;
let texture: ITexture;
let sampler: IGLSampler;
diff --git a/examples/src/WebGL2Samples/third-party/gltf-loader.ts b/examples/src/WebGL2Samples/third-party/gltf-loader.ts
index 32f31af..fd2be0a 100644
--- a/examples/src/WebGL2Samples/third-party/gltf-loader.ts
+++ b/examples/src/WebGL2Samples/third-party/gltf-loader.ts
@@ -9,7 +9,7 @@ type IVertexDataTypes =
| Uint8Array
| Int8Array;
-type IGLIndicesDataTypes = Uint16Array | Uint32Array | Uint8Array;
+type IIndicesDataTypes = Uint16Array | Uint32Array;
// Data classes
class Scene
@@ -41,7 +41,7 @@ class Mesh
export class Primitive
{
mode: number;
- indices: IGLIndicesDataTypes;
+ indices: IIndicesDataTypes;
indicesComponentType: number;
vertexBuffer: IVertexDataTypes;
matrix: mat4;
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index 6430128..d919856 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLTransformFeedback, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -65,7 +65,7 @@ import { getShaderSource } from "./utility";
const COLOR_LOCATION = 3;
const NUM_LOCATIONS = 4;
- const vertexArrays: { vertices?: IVertexAttributes, indices?: IGLIndicesDataTypes }[][] = [];
+ const vertexArrays: { vertices?: IVertexAttributes, indices?: IIndicesDataTypes }[][] = [];
// Transform feedback objects track output buffer state
const transformFeedbacks: IGLTransformFeedback[] = [];
diff --git a/examples/src/WebGL2Samples/transform_feedback_interleaved.ts b/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
index dddc0b4..67cf48b 100644
--- a/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { getIGLVertexBuffer, IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { getIGLVertexBuffer, IGLCanvasContext, IGLTransformFeedback, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -57,7 +57,7 @@ import { getShaderSource } from "./utility";
];
// -- Init Vertex Array
- const vertexArrays: { vertices?: IVertexAttributes, indices?: IGLIndicesDataTypes }[] = [
+ const vertexArrays: { vertices?: IVertexAttributes, indices?: IIndicesDataTypes }[] = [
{
vertices: {
position: { data: buffers[PROGRAM_TRANSFORM], format: "float32x4" },
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated.ts b/examples/src/WebGL2Samples/transform_feedback_separated.ts
index 11daceb..9fb79bc 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLTransformFeedback, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
@@ -67,7 +67,7 @@ import { getShaderSource } from "./utility";
];
// -- Init Transform Vertex Array
- const vertexArrays: { vertices?: IVertexAttributes, indices?: IGLIndicesDataTypes }[] = [
+ const vertexArrays: { vertices?: IVertexAttributes, indices?: IIndicesDataTypes }[] = [
{
vertices: {
position: { data: buffers[BufferType.VERTEX], format: "float32x4" },
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
index 932ff64..614ae6c 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLIndicesDataTypes, IGLTransformFeedback, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLTransformFeedback, IGLViewport, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
@@ -58,7 +58,7 @@ import { getShaderSource } from "./utility";
}
// -- Init Vertex Arrays and Buffers
- const particleVAOs: { vertices?: IVertexAttributes, indices?: IGLIndicesDataTypes }[] = [];
+ const particleVAOs: { vertices?: IVertexAttributes, indices?: IIndicesDataTypes }[] = [];
// Transform feedback objects track output buffer state
const particleTransformFeedbacks: IGLTransformFeedback[] = [];
diff --git a/src/data/IGLIndexBuffer.ts b/src/data/IGLIndexBuffer.ts
index e51cf95..6d9acf4 100644
--- a/src/data/IGLIndexBuffer.ts
+++ b/src/data/IGLIndexBuffer.ts
@@ -1,3 +1,4 @@
+import { IIndicesDataTypes } from "@feng3d/render-api";
import { IGLBuffer } from "./IGLBuffer";
/**
@@ -15,14 +16,9 @@ export interface IGLIndexBuffer extends IGLBuffer
/**
* 顶点索引数据。
*/
- data: IGLIndicesDataTypes;
+ data: IIndicesDataTypes;
}
-/**
- * 顶点索引数据类型
- */
-export type IGLIndicesDataTypes = Uint16Array | Uint32Array | Uint8Array;
-
/**
* 元素缓冲数据类型。
*
diff --git a/src/data/IGLRenderObject.ts b/src/data/IGLRenderObject.ts
index 0a35c3b..80afcc3 100644
--- a/src/data/IGLRenderObject.ts
+++ b/src/data/IGLRenderObject.ts
@@ -2,7 +2,6 @@ import { IRenderObject } from "@feng3d/render-api";
import { LazyObject } from "../types";
import { IGLDrawIndexed } from "./IGLDrawIndexed";
import { IGLDrawVertex } from "./IGLDrawVertex";
-import { IGLIndicesDataTypes } from "./IGLIndexBuffer";
import { IGLTransformFeedback } from "./IGLTransformFeedback";
import { IGLUniforms } from "./IGLUniforms";
@@ -13,11 +12,6 @@ declare module "@feng3d/render-api"
*/
export interface IRenderObject
{
- /**
- * 顶点索引数据
- */
- indices?: IGLIndicesDataTypes;
-
/**
* Uniform渲染数据
*/
diff --git a/src/runs/getIGLBuffer.ts b/src/runs/getIGLBuffer.ts
index c4e0c6e..abda1cc 100644
--- a/src/runs/getIGLBuffer.ts
+++ b/src/runs/getIGLBuffer.ts
@@ -1,6 +1,6 @@
-import { IVertexDataTypes } from "@feng3d/render-api";
+import { IIndicesDataTypes, IVertexDataTypes } from "@feng3d/render-api";
import { GLBufferTarget, GLBufferUsage, IGLBuffer, IGLVertexBuffer } from "../data/IGLBuffer";
-import { IGLIndexBuffer, IGLIndicesDataTypes } from "../data/IGLIndexBuffer";
+import { IGLIndexBuffer } from "../data/IGLIndexBuffer";
export function getIGLBuffer(data: BufferSource, target?: GLBufferTarget, usage: GLBufferUsage = "STATIC_DRAW")
{
@@ -23,7 +23,7 @@ export function getIGLVertexBuffer(data: IVertexDataTypes, usage?: "STREAM_COPY"
return vertexBuffer;
}
-export function getIGLIndexBuffer(indices: IGLIndicesDataTypes)
+export function getIGLIndexBuffer(indices: IIndicesDataTypes)
{
const indexBuffer: IGLIndexBuffer = indices[_IGLBuffer] = indices[_IGLBuffer] || getIGLBuffer(indices, "ELEMENT_ARRAY_BUFFER");
diff --git a/src/runs/runDrawCall.ts b/src/runs/runDrawCall.ts
index 51520d5..9539ff3 100644
--- a/src/runs/runDrawCall.ts
+++ b/src/runs/runDrawCall.ts
@@ -1,11 +1,10 @@
-import { IRenderObject, IVertexAttributes } from "@feng3d/render-api";
+import { IIndicesDataTypes, IRenderObject, IVertexAttributes } from "@feng3d/render-api";
import { getBufferType } from "../caches/getGLBuffer";
import { IGLDrawMode } from "../caches/getIGLDrawMode";
import { ElementTypeMap } from "../const/IGLUniformType";
import { IGLDrawIndexed } from "../data/IGLDrawIndexed";
import { IGLDrawVertex } from "../data/IGLDrawVertex";
-import { IGLIndicesDataTypes } from "../data/IGLIndexBuffer";
export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObject, drawMode: IGLDrawMode)
{
@@ -31,7 +30,7 @@ export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObje
export const defaultDrawIndexed: IGLDrawIndexed = Object.freeze({ firstIndex: 0, instanceCount: 1 });
-function _runDrawIndexed(gl: WebGLRenderingContext, drawMode: IGLDrawMode, indices: IGLIndicesDataTypes, drawIndexed: IGLDrawIndexed)
+function _runDrawIndexed(gl: WebGLRenderingContext, drawMode: IGLDrawMode, indices: IIndicesDataTypes, drawIndexed: IGLDrawIndexed)
{
const type = getBufferType(indices);
const dataLength = indices.length;
diff --git a/src/runs/runIndexBuffer.ts b/src/runs/runIndexBuffer.ts
index 1feaad4..707596f 100644
--- a/src/runs/runIndexBuffer.ts
+++ b/src/runs/runIndexBuffer.ts
@@ -1,8 +1,8 @@
+import { IIndicesDataTypes } from "@feng3d/render-api";
import { getGLBuffer } from "../caches/getGLBuffer";
-import { IGLIndicesDataTypes } from "../data/IGLIndexBuffer";
import { getIGLIndexBuffer } from "./getIGLBuffer";
-export function runIndexBuffer(gl: WebGLRenderingContext, indices?: IGLIndicesDataTypes)
+export function runIndexBuffer(gl: WebGLRenderingContext, indices?: IIndicesDataTypes)
{
if (!indices) return;
diff --git a/src/runs/runVertexArray.ts b/src/runs/runVertexArray.ts
index 67bd1ee..bfaa12f 100644
--- a/src/runs/runVertexArray.ts
+++ b/src/runs/runVertexArray.ts
@@ -1,6 +1,5 @@
-import { IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { IIndicesDataTypes, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
import { getGLProgram } from "../caches/getGLProgram";
-import { IGLIndicesDataTypes } from "../data/IGLIndexBuffer";
import { ChainMap } from "../utils/ChainMap";
import { runIndexBuffer } from "./runIndexBuffer";
import { runVertexAttribute } from "./runVertexAttribute";
@@ -9,14 +8,14 @@ declare global
{
interface WebGLRenderingContext
{
- _vertexArrays: ChainMap<[IRenderPipeline, IVertexAttributes, IGLIndicesDataTypes], WebGLVertexArrayObject>;
+ _vertexArrays: ChainMap<[IRenderPipeline, IVertexAttributes, IIndicesDataTypes], WebGLVertexArrayObject>;
}
}
/**
* 执行设置或者上传渲染对象的顶点以及索引数据。
*/
-export function runVertexArray(gl: WebGLRenderingContext, pipeline: IRenderPipeline, vertices: IVertexAttributes, indices: IGLIndicesDataTypes)
+export function runVertexArray(gl: WebGLRenderingContext, pipeline: IRenderPipeline, vertices: IVertexAttributes, indices: IIndicesDataTypes)
{
if (!vertices && !indices) return;
--
Gitee
From 8bafb67c78fb4d750ccc6096590dd97a2d818b80 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sun, 15 Dec 2024 17:53:05 +0800
Subject: [PATCH 116/186] IRenderObject.drawVertex
---
examples/src/WebGL2Samples/draw_instanced.ts | 2 +-
src/caches/getGLBuffer.ts | 7 ++--
src/data/IGLDrawVertex.ts | 20 ----------
src/data/IGLRenderObject.ts | 8 ----
src/index.ts | 2 +-
src/runs/runDrawCall.ts | 39 +++-----------------
6 files changed, 12 insertions(+), 66 deletions(-)
delete mode 100644 src/data/IGLDrawVertex.ts
diff --git a/examples/src/WebGL2Samples/draw_instanced.ts b/examples/src/WebGL2Samples/draw_instanced.ts
index 96954c0..b6f822e 100644
--- a/examples/src/WebGL2Samples/draw_instanced.ts
+++ b/examples/src/WebGL2Samples/draw_instanced.ts
@@ -34,7 +34,7 @@ const vertexArray: { vertices?: IVertexAttributes } = {
const renderObject: IRenderObject = {
vertices: vertexArray.vertices,
uniforms: {},
- drawVertex: { instanceCount: 2 },
+ drawVertex: { vertexCount: 3, instanceCount: 2 },
pipeline: program
};
diff --git a/src/caches/getGLBuffer.ts b/src/caches/getGLBuffer.ts
index b7bfb52..1c2e2f5 100644
--- a/src/caches/getGLBuffer.ts
+++ b/src/caches/getGLBuffer.ts
@@ -1,6 +1,7 @@
+import { IVertexDataTypes } from "@feng3d/render-api";
import { watcher } from "@feng3d/watcher";
import { IGLBuffer } from "../data/IGLBuffer";
-import { IVertexDataTypes } from "@feng3d/render-api";
+import { IGLVertexAttributeTypes } from "../utils/getIVertexFormat";
declare global
{
@@ -111,7 +112,7 @@ export function getBufferType(data?: IVertexDataTypes)
return bufferTypeMap[data?.constructor.name];
}
-const bufferTypeMap = {
+const bufferTypeMap: { [key: string]: IGLVertexAttributeTypes } = {
Float32Array: "FLOAT",
Uint32Array: "UNSIGNED_INT",
Int32Array: "INT",
@@ -119,5 +120,5 @@ const bufferTypeMap = {
Int16Array: "SHORT",
Uint8Array: "UNSIGNED_BYTE",
Int8Array: "BYTE",
- Uint8ClampedArray: "BYTE",
+ Uint8ClampedArray: "UNSIGNED_BYTE",
};
diff --git a/src/data/IGLDrawVertex.ts b/src/data/IGLDrawVertex.ts
deleted file mode 100644
index e2c5a62..0000000
--- a/src/data/IGLDrawVertex.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * 根据顶点数据绘制图元。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawVertex
- */
-export interface IGLDrawVertex
-{
- /**
- * 绘制顶点数量。
- */
- vertexCount?: number;
- /**
- * 渲染实例数量
- */
- instanceCount?: number;
- /**
- * 第一个顶点索引。
- */
- firstVertex?: number;
-}
diff --git a/src/data/IGLRenderObject.ts b/src/data/IGLRenderObject.ts
index 80afcc3..d3bac6a 100644
--- a/src/data/IGLRenderObject.ts
+++ b/src/data/IGLRenderObject.ts
@@ -1,7 +1,6 @@
import { IRenderObject } from "@feng3d/render-api";
import { LazyObject } from "../types";
import { IGLDrawIndexed } from "./IGLDrawIndexed";
-import { IGLDrawVertex } from "./IGLDrawVertex";
import { IGLTransformFeedback } from "./IGLTransformFeedback";
import { IGLUniforms } from "./IGLUniforms";
@@ -17,13 +16,6 @@ declare module "@feng3d/render-api"
*/
uniforms?: LazyObject;
- /**
- * 绘制一定数量顶点。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawVertex
- */
- drawVertex?: IGLDrawVertex;
-
/**
* 根据索引数据绘制图元。
*
diff --git a/src/index.ts b/src/index.ts
index 9d1f8f7..41e5423 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -6,7 +6,6 @@ export * from "./data/IGLCommandEncoder";
export * from "./data/IGLCopyBufferToBuffer";
export * from "./data/IGLDepthStencilState";
export * from "./data/IGLDrawIndexed";
-export * from "./data/IGLDrawVertex";
export * from "./data/IGLIndexBuffer";
export * from "./data/IGLOcclusionQuery";
export * from "./data/IGLPrimitiveState";
@@ -45,3 +44,4 @@ export * as internal from "./internal";
export * from "./caches/getGLBuffer";
export * from "./utils/getIVertexFormat";
+
diff --git a/src/runs/runDrawCall.ts b/src/runs/runDrawCall.ts
index 9539ff3..3d4fccf 100644
--- a/src/runs/runDrawCall.ts
+++ b/src/runs/runDrawCall.ts
@@ -1,10 +1,9 @@
-import { IIndicesDataTypes, IRenderObject, IVertexAttributes } from "@feng3d/render-api";
+import { IDrawVertex, IIndicesDataTypes, IRenderObject, IVertexAttributes } from "@feng3d/render-api";
import { getBufferType } from "../caches/getGLBuffer";
import { IGLDrawMode } from "../caches/getIGLDrawMode";
import { ElementTypeMap } from "../const/IGLUniformType";
import { IGLDrawIndexed } from "../data/IGLDrawIndexed";
-import { IGLDrawVertex } from "../data/IGLDrawVertex";
export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObject, drawMode: IGLDrawMode)
{
@@ -28,16 +27,14 @@ export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObje
}
}
-export const defaultDrawIndexed: IGLDrawIndexed = Object.freeze({ firstIndex: 0, instanceCount: 1 });
-
function _runDrawIndexed(gl: WebGLRenderingContext, drawMode: IGLDrawMode, indices: IIndicesDataTypes, drawIndexed: IGLDrawIndexed)
{
const type = getBufferType(indices);
const dataLength = indices.length;
//
let { indexCount, instanceCount, firstIndex } = drawIndexed || {};
- firstIndex = firstIndex || defaultDrawIndexed.firstIndex;
- instanceCount = instanceCount || defaultDrawIndexed.instanceCount;
+ firstIndex = firstIndex || 0;
+ instanceCount = instanceCount || 1;
indexCount = indexCount || (dataLength - firstIndex);
//
@@ -59,16 +56,13 @@ function _runDrawIndexed(gl: WebGLRenderingContext, drawMode: IGLDrawMode, indic
}
}
-export const defaultDrawVertex: IGLDrawVertex = Object.freeze({ vertexCount: 6, instanceCount: 1, firstVertex: 0 });
-
-function _runDrawVertex(gl: WebGLRenderingContext, drawMode: IGLDrawMode, vertices: IVertexAttributes, drawArrays: IGLDrawVertex)
+function _runDrawVertex(gl: WebGLRenderingContext, drawMode: IGLDrawMode, vertices: IVertexAttributes, drawArrays: IDrawVertex)
{
//
let { firstVertex, vertexCount, instanceCount } = drawArrays || {};
//
- firstVertex = firstVertex || defaultDrawVertex.firstVertex;
- vertexCount = vertexCount || getAttributeVertexNum(vertices) || defaultDrawVertex.vertexCount;
- instanceCount = instanceCount || defaultDrawVertex.instanceCount;
+ firstVertex = firstVertex || 0;
+ instanceCount = instanceCount || 1;
if (instanceCount > 1)
{
@@ -87,24 +81,3 @@ function _runDrawVertex(gl: WebGLRenderingContext, drawMode: IGLDrawMode, vertic
gl.drawArrays(gl[drawMode], firstVertex, vertexCount);
}
}
-
-/**
- * 获取属性顶点属性。
- */
-export function getAttributeVertexNum(vertices: IVertexAttributes)
-{
- const vertexNum = ((vertices) =>
- {
- for (const attr in vertices)
- {
- if (vertices.hasOwnProperty(attr))
- {
- return vertices[attr].data.length;
- }
- }
-
- return 0;
- })(vertices);
-
- return vertexNum;
-}
\ No newline at end of file
--
Gitee
From 6d97933ac87c5c31d03cf9cd502b990c15b65191 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Mon, 16 Dec 2024 08:36:11 +0800
Subject: [PATCH 117/186] IRenderObject.drawIndexed
---
src/data/IGLDrawIndexed.ts | 12 ------------
src/data/IGLRenderObject.ts | 8 --------
src/index.ts | 1 -
src/runs/runDrawCall.ts | 5 ++---
4 files changed, 2 insertions(+), 24 deletions(-)
delete mode 100644 src/data/IGLDrawIndexed.ts
diff --git a/src/data/IGLDrawIndexed.ts b/src/data/IGLDrawIndexed.ts
deleted file mode 100644
index 4e65b78..0000000
--- a/src/data/IGLDrawIndexed.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- * 根据索引数据绘制图元。
- */
-export interface IGLDrawIndexed
-{
- /**
- * 默认渲染所有顶点索引。
- */
- indexCount?: number;
- instanceCount?: number;
- firstIndex?: number;
-}
\ No newline at end of file
diff --git a/src/data/IGLRenderObject.ts b/src/data/IGLRenderObject.ts
index d3bac6a..a6713b7 100644
--- a/src/data/IGLRenderObject.ts
+++ b/src/data/IGLRenderObject.ts
@@ -1,6 +1,5 @@
import { IRenderObject } from "@feng3d/render-api";
import { LazyObject } from "../types";
-import { IGLDrawIndexed } from "./IGLDrawIndexed";
import { IGLTransformFeedback } from "./IGLTransformFeedback";
import { IGLUniforms } from "./IGLUniforms";
@@ -16,13 +15,6 @@ declare module "@feng3d/render-api"
*/
uniforms?: LazyObject;
- /**
- * 根据索引数据绘制图元。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements
- */
- drawIndexed?: IGLDrawIndexed;
-
/**
* 回写顶点着色器中输出到缓冲区。
*
diff --git a/src/index.ts b/src/index.ts
index 41e5423..c7bdc38 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -5,7 +5,6 @@ export * from "./data/IGLCapabilities";
export * from "./data/IGLCommandEncoder";
export * from "./data/IGLCopyBufferToBuffer";
export * from "./data/IGLDepthStencilState";
-export * from "./data/IGLDrawIndexed";
export * from "./data/IGLIndexBuffer";
export * from "./data/IGLOcclusionQuery";
export * from "./data/IGLPrimitiveState";
diff --git a/src/runs/runDrawCall.ts b/src/runs/runDrawCall.ts
index 3d4fccf..268d1e9 100644
--- a/src/runs/runDrawCall.ts
+++ b/src/runs/runDrawCall.ts
@@ -1,9 +1,8 @@
-import { IDrawVertex, IIndicesDataTypes, IRenderObject, IVertexAttributes } from "@feng3d/render-api";
+import { IDrawIndexed, IDrawVertex, IIndicesDataTypes, IRenderObject, IVertexAttributes } from "@feng3d/render-api";
import { getBufferType } from "../caches/getGLBuffer";
import { IGLDrawMode } from "../caches/getIGLDrawMode";
import { ElementTypeMap } from "../const/IGLUniformType";
-import { IGLDrawIndexed } from "../data/IGLDrawIndexed";
export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObject, drawMode: IGLDrawMode)
{
@@ -27,7 +26,7 @@ export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObje
}
}
-function _runDrawIndexed(gl: WebGLRenderingContext, drawMode: IGLDrawMode, indices: IIndicesDataTypes, drawIndexed: IGLDrawIndexed)
+function _runDrawIndexed(gl: WebGLRenderingContext, drawMode: IGLDrawMode, indices: IIndicesDataTypes, drawIndexed: IDrawIndexed)
{
const type = getBufferType(indices);
const dataLength = indices.length;
--
Gitee
From eff72b505a86878413fffc51df1c93277b9fe2cf Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Mon, 16 Dec 2024 16:30:26 +0800
Subject: [PATCH 118/186] 1
---
examples/src/WebGL2Samples/draw_primitive_restart.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/src/WebGL2Samples/draw_primitive_restart.ts b/examples/src/WebGL2Samples/draw_primitive_restart.ts
index 8f0d179..85def9d 100644
--- a/examples/src/WebGL2Samples/draw_primitive_restart.ts
+++ b/examples/src/WebGL2Samples/draw_primitive_restart.ts
@@ -47,7 +47,7 @@ const renderObject: IRenderObject = {
vertices: vertexArray.vertices,
indices: indices,
uniforms: {},
- drawIndexed: { instanceCount: 2 },
+ drawIndexed: { indexCount: 7, instanceCount: 2 },
pipeline: program,
};
--
Gitee
From c681a2eb224cf1326b090d8f43d3aed89809e86f Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Mon, 16 Dec 2024 16:40:35 +0800
Subject: [PATCH 119/186] runDrawCall
---
src/const/IGLUniformType.ts | 9 ---------
src/runs/runDrawCall.ts | 40 ++++++++++++++-----------------------
2 files changed, 15 insertions(+), 34 deletions(-)
diff --git a/src/const/IGLUniformType.ts b/src/const/IGLUniformType.ts
index da831af..95c2c70 100644
--- a/src/const/IGLUniformType.ts
+++ b/src/const/IGLUniformType.ts
@@ -80,12 +80,3 @@ const webGLUniformValueType = Object.keys(webGLUniformTypeValue).reduce((pv, cv)
return pv;
}, {});
-
-/**
- * 顶点索引数据类型对应的字节数量。
- */
-export const ElementTypeMap = {
- UNSIGNED_BYTE: 1,
- UNSIGNED_SHORT: 2,
- UNSIGNED_INT: 4,
-};
\ No newline at end of file
diff --git a/src/runs/runDrawCall.ts b/src/runs/runDrawCall.ts
index 268d1e9..4d0227c 100644
--- a/src/runs/runDrawCall.ts
+++ b/src/runs/runDrawCall.ts
@@ -1,67 +1,57 @@
-import { IDrawIndexed, IDrawVertex, IIndicesDataTypes, IRenderObject, IVertexAttributes } from "@feng3d/render-api";
+import { IDrawIndexed, IDrawVertex, IIndicesDataTypes, IRenderObject } from "@feng3d/render-api";
import { getBufferType } from "../caches/getGLBuffer";
import { IGLDrawMode } from "../caches/getIGLDrawMode";
-import { ElementTypeMap } from "../const/IGLUniformType";
export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObject, drawMode: IGLDrawMode)
{
- const { vertices, indices, drawIndexed, drawVertex } = renderObject;
+ const { indices, drawIndexed, drawVertex } = renderObject;
if (drawVertex)
{
- _runDrawVertex(gl, drawMode, vertices, drawVertex);
+ _runDrawVertex(gl, drawMode, drawVertex);
}
else if (drawIndexed)
{
_runDrawIndexed(gl, drawMode, indices, drawIndexed);
}
- else if (indices)
- {
- _runDrawIndexed(gl, drawMode, indices, drawIndexed);
- }
- else
- {
- _runDrawVertex(gl, drawMode, vertices, drawVertex);
- }
}
function _runDrawIndexed(gl: WebGLRenderingContext, drawMode: IGLDrawMode, indices: IIndicesDataTypes, drawIndexed: IDrawIndexed)
{
const type = getBufferType(indices);
- const dataLength = indices.length;
//
- let { indexCount, instanceCount, firstIndex } = drawIndexed || {};
- firstIndex = firstIndex || 0;
- instanceCount = instanceCount || 1;
- indexCount = indexCount || (dataLength - firstIndex);
+ const indexCount = drawIndexed.indexCount;
+ const firstIndex = drawIndexed.firstIndex || 0;
+ const instanceCount = drawIndexed.instanceCount || 1;
+ //
+ const offset = firstIndex * indices.BYTES_PER_ELEMENT;
//
if (instanceCount > 1)
{
if (gl instanceof WebGL2RenderingContext)
{
- gl.drawElementsInstanced(gl[drawMode], indexCount, gl[type], firstIndex * ElementTypeMap[type], instanceCount);
+ gl.drawElementsInstanced(gl[drawMode], indexCount, gl[type], offset, instanceCount);
}
else
{
const extension = gl.getExtension("ANGLE_instanced_arrays");
- extension.drawElementsInstancedANGLE(gl[drawMode], indexCount, gl[type], firstIndex * ElementTypeMap[type], instanceCount);
+ extension.drawElementsInstancedANGLE(gl[drawMode], indexCount, gl[type], offset, instanceCount);
}
}
else
{
- gl.drawElements(gl[drawMode], indexCount, gl[type], firstIndex * ElementTypeMap[type]);
+ gl.drawElements(gl[drawMode], indexCount, gl[type], offset);
}
}
-function _runDrawVertex(gl: WebGLRenderingContext, drawMode: IGLDrawMode, vertices: IVertexAttributes, drawArrays: IDrawVertex)
+function _runDrawVertex(gl: WebGLRenderingContext, drawMode: IGLDrawMode, drawArrays: IDrawVertex)
{
//
- let { firstVertex, vertexCount, instanceCount } = drawArrays || {};
- //
- firstVertex = firstVertex || 0;
- instanceCount = instanceCount || 1;
+ const vertexCount = drawArrays.vertexCount;
+ const firstVertex = drawArrays.firstVertex || 0;
+ const instanceCount = drawArrays.instanceCount || 1;
if (instanceCount > 1)
{
--
Gitee
From 8adbe6ffdcb58081363a9f533524d2eab3512671 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Mon, 16 Dec 2024 21:24:02 +0800
Subject: [PATCH 120/186] 1
---
examples/index.ts | 1 -
examples/src/regl-examples/basic.ts | 4 +-
examples/src/regl-examples/batch.ts | 4 +-
examples/src/regl-examples/blur.html | 35 ---------
examples/src/regl-examples/blur.ts | 113 ---------------------------
examples/src/regl-examples/bunny.ts | 4 +-
examples/src/regl-examples/camera.ts | 27 ++-----
examples/src/regl-examples/cloth.ts | 1 +
examples/src/regl-examples/cube.ts | 3 +-
src/runs/runDepthState.ts | 2 +-
10 files changed, 19 insertions(+), 175 deletions(-)
delete mode 100644 examples/src/regl-examples/blur.html
delete mode 100644 examples/src/regl-examples/blur.ts
diff --git a/examples/index.ts b/examples/index.ts
index a153d0a..09a3489 100644
--- a/examples/index.ts
+++ b/examples/index.ts
@@ -12,7 +12,6 @@ const files = {
"regl-examples": [
"basic",
"batch",
- "blur",
"bunny",
"camera",
"cloth",
diff --git a/examples/src/regl-examples/basic.ts b/examples/src/regl-examples/basic.ts
index 9c5fb5f..0e8551c 100644
--- a/examples/src/regl-examples/basic.ts
+++ b/examples/src/regl-examples/basic.ts
@@ -48,7 +48,8 @@ const renderObject: IRenderObject = {
targets: [{ blend: {} }],
},
depthStencil: {},
- }
+ },
+ drawVertex: { vertexCount: 3 },
};
function draw()
@@ -60,6 +61,7 @@ function draw()
commandEncoders: [{
passEncoders: [
{
+ descriptor: { colorAttachments: [{ clearValue: [0, 0, 0, 1] }], depthStencilAttachment: { depthClearValue: 1 } },
renderObjects: [renderObject]
}
]
diff --git a/examples/src/regl-examples/batch.ts b/examples/src/regl-examples/batch.ts
index 0ea7d2d..44c4bb5 100644
--- a/examples/src/regl-examples/batch.ts
+++ b/examples/src/regl-examples/batch.ts
@@ -38,7 +38,7 @@ const pipeline: IRenderPipeline = {
void main() {
gl_FragColor = color;
}` },
- depthStencil: {},
+ depthStencil: { depthWriteEnabled: false },
};
const vertexArray: { vertices?: IVertexAttributes } = {
@@ -68,6 +68,7 @@ function getRenderObject(tick: number, batchId: number)
offset: () => offsets[batchId].offset,
},
pipeline,
+ drawVertex: { vertexCount: 3 }
};
return renderObject;
@@ -90,6 +91,7 @@ function draw()
commandEncoders: [{
passEncoders: [
{
+ descriptor: { colorAttachments: [{ clearValue: [0, 0, 0, 1] }] },
renderObjects
}
]
diff --git a/examples/src/regl-examples/blur.html b/examples/src/regl-examples/blur.html
deleted file mode 100644
index a02dea9..0000000
--- a/examples/src/regl-examples/blur.html
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-
-
- feng3d examples
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/examples/src/regl-examples/blur.ts b/examples/src/regl-examples/blur.ts
deleted file mode 100644
index 021dd1c..0000000
--- a/examples/src/regl-examples/blur.ts
+++ /dev/null
@@ -1,113 +0,0 @@
-import { IRenderObject, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
-import { WebGL } from "@feng3d/webgl";
-
-import { fit } from "./hughsk/canvas-fit";
-import { attachCamera } from "./hughsk/canvas-orbit-camera";
-
-const canvas = document.body.appendChild(document.createElement("canvas"));
-canvas.id = "glcanvas";
-window.addEventListener("resize", fit(canvas), false);
-
-const webgl = new WebGL({ canvasId: "glcanvas" });
-
-const camera = attachCamera(canvas);
-
-// increase and decrease the blur amount by modifying this value.
-const FILTER_RADIUS = 1;
-
-// configure intial camera view.
-camera.rotate([0.0, 0.0], [0.0, -0.4]);
-camera.zoom(300.0);
-
-let batchId = 0;
-let tick = 0;
-const offsets = [{ offset: [-1, -1] },
-{ offset: [-1, 0] },
-{ offset: [-1, 1] },
-{ offset: [0, -1] },
-{ offset: [0, 0] },
-{ offset: [0, 1] },
-{ offset: [1, -1] },
-{ offset: [1, 0] },
-{ offset: [1, 1] }];
-
-const vertexArray: { vertices?: IVertexAttributes } = {
- vertices: {
- position: {
- format: "float32x2",
- data: new Float32Array([
- 0.5, 0,
- 0, 0.5,
- 1, 1
- ]),
- },
- }
-};
-
-const pipeline: IRenderPipeline = {
- vertex: {
- code: `precision mediump float;
- attribute vec2 position;
- uniform float angle;
- uniform vec2 offset;
- void main() {
- gl_Position = vec4(
- cos(angle) * position.x + sin(angle) * position.y + offset.x,
- -sin(angle) * position.x + cos(angle) * position.y + offset.y, 0, 1);
- }` },
- fragment: {
- code: `precision mediump float;
- uniform vec4 color;
- void main() {
- gl_FragColor = color;
- }`,
- targets: [{ blend: {} }],
- },
- depthStencil: {},
-};
-
-function getRenderObject(tick: number, batchId: number)
-{
- const renderObject: IRenderObject = {
- vertices: vertexArray.vertices,
- uniforms: {
- color: () => [
- Math.sin(0.02 * ((0.1 + Math.sin(batchId)) * tick + 3.0 * batchId)),
- Math.cos(0.02 * (0.02 * tick + 0.1 * batchId)),
- Math.sin(0.02 * ((0.3 + Math.cos(2.0 * batchId)) * tick + 0.8 * batchId)),
- 1],
- angle: () => 0.01 * tick,
- offset: () => offsets[batchId].offset,
- },
- pipeline,
- };
-
- return renderObject;
-}
-
-function draw()
-{
- canvas.width = canvas.clientWidth;
- canvas.height = canvas.clientHeight;
-
- tick++;
- const renderObjects: IRenderObject[] = [];
- for (let i = 0; i < offsets.length; i++)
- {
- batchId = i;
- renderObjects.push(getRenderObject(tick, batchId));
- }
-
- webgl.submit({
- commandEncoders: [{
- passEncoders: [
- {
- renderObjects
- }
- ]
- }]
- });
-
- requestAnimationFrame(draw);
-}
-draw();
diff --git a/examples/src/regl-examples/bunny.ts b/examples/src/regl-examples/bunny.ts
index b66abc5..7399886 100644
--- a/examples/src/regl-examples/bunny.ts
+++ b/examples/src/regl-examples/bunny.ts
@@ -32,9 +32,10 @@ let viewportHeight = canvas.clientHeight;
const renderObject: IRenderObject = {
vertices: {
- position: { data: new Float32Array(positions),format:"float32x3" },
+ position: { data: new Float32Array(positions), format: "float32x3" },
},
indices: new Uint16Array(indices),
+ drawIndexed: { indexCount: indices.length },
uniforms: {
model: mat4.identity([]),
view: () =>
@@ -82,6 +83,7 @@ function draw()
commandEncoders: [{
passEncoders: [
{
+ descriptor: { colorAttachments: [{ clearValue: [0, 0, 0, 1] }], depthStencilAttachment: { depthClearValue: 1 } },
renderObjects: [renderObject]
}
]
diff --git a/examples/src/regl-examples/camera.ts b/examples/src/regl-examples/camera.ts
index ff7075c..ae5f99a 100644
--- a/examples/src/regl-examples/camera.ts
+++ b/examples/src/regl-examples/camera.ts
@@ -17,26 +17,9 @@ const camera = createCamera({
center: [0, 2.5, 0]
});
-const positions = bunny.positions.reduce((pv: number[], cv: number[]) =>
-{
- cv.forEach((v) => { pv.push(v); });
-
- return pv;
-}, []);
-
-const indices = bunny.cells.reduce((pv: number[], cv: number[]) =>
-{
- cv.forEach((v) => { pv.push(v); });
-
- return pv;
-}, []);
-
-const normals = angleNormals(bunny.cells, bunny.positions).reduce((pv: number[], cv: number[]) =>
-{
- cv.forEach((v) => { pv.push(v); });
-
- return pv;
-}, []);
+const positions = bunny.positions.flat();
+const indices = bunny.cells.flat();
+const normals = angleNormals(bunny.cells, bunny.positions).flat();
const renderObject: IRenderObject = {
vertices: {
@@ -44,6 +27,7 @@ const renderObject: IRenderObject = {
normal: { data: new Float32Array(normals), format: "float32x3" },
},
indices: new Uint16Array(indices),
+ drawIndexed: { indexCount: indices.length },
uniforms: {},
pipeline: {
vertex: {
@@ -63,7 +47,7 @@ const renderObject: IRenderObject = {
}`,
targets: [{ blend: {} }],
},
- depthStencil: {},
+ depthStencil: { depthWriteEnabled: true },
}
};
@@ -78,6 +62,7 @@ function draw()
commandEncoders: [{
passEncoders: [
{
+ descriptor: { colorAttachments: [{ clearValue: [0, 0, 0, 1] }] },
renderObjects: [renderObject]
}
]
diff --git a/examples/src/regl-examples/cloth.ts b/examples/src/regl-examples/cloth.ts
index 5499d22..8b41c24 100644
--- a/examples/src/regl-examples/cloth.ts
+++ b/examples/src/regl-examples/cloth.ts
@@ -171,6 +171,7 @@ import * as vec3 from "./stackgl/gl-vec3";
uv: { data: new Float32Array(uvs), format: "float32x2" },
},
indices: new Uint16Array(indices),
+ drawIndexed: { indexCount: indices.length },
uniforms: {
view: () => camera.view(),
projection: () =>
diff --git a/examples/src/regl-examples/cube.ts b/examples/src/regl-examples/cube.ts
index 53e33a1..7700281 100644
--- a/examples/src/regl-examples/cube.ts
+++ b/examples/src/regl-examples/cube.ts
@@ -70,6 +70,7 @@ import * as mat4 from "./stackgl/gl-mat4";
uv: { data: new Float32Array(uvs), format: "float32x2" },
},
indices: new Uint16Array(indices),
+ drawIndexed: { indexCount: indices.length },
uniforms: {
view: () =>
{
@@ -108,7 +109,7 @@ import * as mat4 from "./stackgl/gl-mat4";
}`,
targets: [{ blend: {} }],
},
- depthStencil: {},
+ depthStencil: { depthWriteEnabled: true },
}
};
diff --git a/src/runs/runDepthState.ts b/src/runs/runDepthState.ts
index b8d8275..432dccf 100644
--- a/src/runs/runDepthState.ts
+++ b/src/runs/runDepthState.ts
@@ -6,7 +6,7 @@ export function runDepthState(gl: WebGLRenderingContext, depthStencil?: IDepthSt
if (depthStencil && (depthStencil.depthWriteEnabled || depthStencil.depthCompare !== "always"))
{
const depthCompare: IGLCompareFunction = getIGLCompareFunction(depthStencil.depthCompare ?? 'less');
- const depthWriteEnabled = depthStencil.depthWriteEnabled ?? true;
+ const depthWriteEnabled = depthStencil.depthWriteEnabled ?? false;
//
gl.enable(gl.DEPTH_TEST);
//
--
Gitee
From 07b658c7f030d00e8c3017ec65cb27f25cf0cb74 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Mon, 16 Dec 2024 21:50:38 +0800
Subject: [PATCH 121/186] =?UTF-8?q?IDepthStencilState.depthWriteEnabled=20?=
=?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=B8=BAtrue?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/runs/runDepthState.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/runs/runDepthState.ts b/src/runs/runDepthState.ts
index 432dccf..b8d8275 100644
--- a/src/runs/runDepthState.ts
+++ b/src/runs/runDepthState.ts
@@ -6,7 +6,7 @@ export function runDepthState(gl: WebGLRenderingContext, depthStencil?: IDepthSt
if (depthStencil && (depthStencil.depthWriteEnabled || depthStencil.depthCompare !== "always"))
{
const depthCompare: IGLCompareFunction = getIGLCompareFunction(depthStencil.depthCompare ?? 'less');
- const depthWriteEnabled = depthStencil.depthWriteEnabled ?? false;
+ const depthWriteEnabled = depthStencil.depthWriteEnabled ?? true;
//
gl.enable(gl.DEPTH_TEST);
//
--
Gitee
From 0955de502723c50d279d8a881d14da7d3dc6258f Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Mon, 16 Dec 2024 23:14:59 +0800
Subject: [PATCH 122/186] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/RunWebGL.ts | 711 ++++++++++++++++++++++++++++++-
src/WebGL.ts | 6 +-
src/index.ts | 2 -
src/runs/runColorTargetStates.ts | 46 +-
src/runs/runDepthState.ts | 34 +-
src/runs/runDepthStencilState.ts | 9 -
src/runs/runDrawCall.ts | 72 ----
src/runs/runFramebuffer.ts | 11 -
src/runs/runIndexBuffer.ts | 14 -
src/runs/runOcclusionQuery.ts | 17 -
src/runs/runPrimitiveState.ts | 24 --
src/runs/runProgram.ts | 25 --
src/runs/runReadPixels.ts | 2 +-
src/runs/runRenderObject.ts | 27 --
src/runs/runRenderPipeline.ts | 13 -
src/runs/runSampler.ts | 71 ---
src/runs/runScissor.ts | 14 -
src/runs/runStencilState.ts | 45 +-
src/runs/runTexture.ts | 26 --
src/runs/runTransformFeedback.ts | 39 --
src/runs/runUniforms.ts | 153 -------
src/runs/runVertexArray.ts | 57 ---
src/runs/runVertexAttribute.ts | 48 ---
src/runs/runViewPort.ts | 13 -
24 files changed, 707 insertions(+), 772 deletions(-)
delete mode 100644 src/runs/runDepthStencilState.ts
delete mode 100644 src/runs/runDrawCall.ts
delete mode 100644 src/runs/runFramebuffer.ts
delete mode 100644 src/runs/runIndexBuffer.ts
delete mode 100644 src/runs/runOcclusionQuery.ts
delete mode 100644 src/runs/runPrimitiveState.ts
delete mode 100644 src/runs/runProgram.ts
delete mode 100644 src/runs/runRenderObject.ts
delete mode 100644 src/runs/runRenderPipeline.ts
delete mode 100644 src/runs/runSampler.ts
delete mode 100644 src/runs/runScissor.ts
delete mode 100644 src/runs/runTexture.ts
delete mode 100644 src/runs/runTransformFeedback.ts
delete mode 100644 src/runs/runUniforms.ts
delete mode 100644 src/runs/runVertexArray.ts
delete mode 100644 src/runs/runVertexAttribute.ts
delete mode 100644 src/runs/runViewPort.ts
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index d430c47..96890aa 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,18 +1,63 @@
-import { ICommandEncoder, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, ISubmit, ITextureView } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes } from "@feng3d/render-api";
import { getFramebuffer } from "./caches/getFramebuffer";
-import { getGLBuffer } from "./caches/getGLBuffer";
+import { getBufferType, getGLBuffer } from "./caches/getGLBuffer";
+import { getGLProgram } from "./caches/getGLProgram";
import { getGLRenderOcclusionQuery } from "./caches/getGLRenderOcclusionQuery";
+import { getGLSampler } from "./caches/getGLSampler";
+import { getGLTransformFeedback } from "./caches/getGLTransformFeedback";
import { getIGLBlitFramebuffer } from "./caches/getIGLBlitFramebuffer";
+import { getIGLDrawMode, IGLDrawMode } from "./caches/getIGLDrawMode";
import { getIGLRenderPassDescriptorWithMultisample } from "./caches/getIGLRenderPassDescriptorWithMultisample";
+import { getIGLTextureTarget } from "./caches/getIGLTextureTarget";
import { _GL_Submit_Times } from "./const/const";
+import { IGLUniformBufferType } from "./const/IGLUniformType";
import { IGLBlitFramebuffer } from "./data/IGLBlitFramebuffer";
+import { IGLBuffer } from "./data/IGLBuffer";
import { IGLCopyBufferToBuffer } from "./data/IGLCopyBufferToBuffer";
import { IGLCopyTextureToTexture } from "./data/IGLCopyTextureToTexture";
-import { runFramebuffer } from "./runs/runFramebuffer";
-import { runOcclusionQuery } from "./runs/runOcclusionQuery";
-import { runRenderObject } from "./runs/runRenderObject";
-import { runScissor } from "./runs/runScissor";
-import { runViewPort } from "./runs/runViewPort";
+import { IGLCompareFunction, IGLStencilFunc, IGLStencilOp } from "./data/IGLDepthStencilState";
+import { IGLOcclusionQuery } from "./data/IGLOcclusionQuery";
+import { IGLSampler, IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "./data/IGLSampler";
+import { IGLSamplerTexture } from "./data/IGLSamplerTexture";
+import { IGLScissorRect } from "./data/IGLScissorRect";
+import { IGLTextureTarget } from "./data/IGLTexture";
+import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
+import { IUniformItemInfo } from "./data/IGLUniformInfo";
+import { IGLUniforms } from "./data/IGLUniforms";
+import { IGLViewport } from "./data/IGLViewport";
+import { getGLTexture } from "./internal";
+import { getIGLIndexBuffer, getIGLVertexBuffer } from "./runs/getIGLBuffer";
+import { getIGLBlendEquation, getIGLBlendFactor, IGLBlendEquation, IGLBlendFactor } from "./runs/runColorTargetStates";
+import { getIGLCompareFunction } from "./runs/runDepthState";
+import { getIGLStencilFunc, getIGLStencilOp } from "./runs/runStencilState";
+import { lazy, LazyObject } from "./types";
+import { ChainMap } from "./utils/ChainMap";
+import { getIGLCullFace, IGLCullFace } from "./utils/getIGLCullFace";
+import { getIGLFrontFace, IGLFrontFace } from "./utils/getIGLFrontFace";
+import { getIGLVertexFormat } from "./utils/getIVertexFormat";
+
+declare global
+{
+ interface WebGLRenderingContext
+ {
+ _vertexArrays: ChainMap<[IRenderPipeline, IVertexAttributes, IIndicesDataTypes], WebGLVertexArrayObject>;
+ }
+}
+
+declare global
+{
+ interface WebGLTexture
+ {
+ minFilter?: IGLTextureMinFilter,
+ magFilter?: IGLTextureMagFilter,
+ wrapS?: IGLTextureWrap,
+ wrapT?: IGLTextureWrap,
+ wrapR?: IGLTextureWrap,
+ anisotropy?: number,
+ lodMinClamp?: number;
+ lodMaxClamp?: number;
+ }
+}
export class RunWebGL
{
@@ -95,7 +140,8 @@ export class RunWebGL
const colorAttachment = Object.assign({}, defaultRenderPassColorAttachment, passDescriptor.colorAttachments?.[0]);
//
- runFramebuffer(gl, passDescriptor);
+ const framebuffer = getFramebuffer(gl, passDescriptor);
+ gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
//
const { clearValue, loadOp } = colorAttachment;
@@ -105,8 +151,6 @@ export class RunWebGL
const depthStencilAttachment = Object.assign({}, defaultDepthStencilAttachment, passDescriptor.depthStencilAttachment);
const { depthClearValue, depthLoadOp, stencilClearValue, stencilLoadOp } = depthStencilAttachment;
-
-
gl.clearDepth(depthClearValue);
gl.clearStencil(stencilClearValue);
@@ -123,21 +167,660 @@ export class RunWebGL
{
if (renderObject.__type === "Viewport")
{
- runViewPort(gl, renderObject);
+ this.runViewPort(gl, renderObject);
}
else if (renderObject.__type === "ScissorRect")
{
- runScissor(gl, renderObject);
+ this.runScissor(gl, renderObject);
}
else if (renderObject.__type === "OcclusionQuery")
{
- runOcclusionQuery(gl, renderObject);
+ this.runOcclusionQuery(gl, renderObject);
+ }
+ else
+ {
+ this.runRenderObject(gl, renderObject);
+ }
+ });
+ }
+
+ private runRenderObject(gl: WebGLRenderingContext, renderObject: IRenderObject)
+ {
+ const { pipeline, vertices, indices, uniforms, transformFeedback, drawIndexed, drawVertex } = renderObject;
+
+ const topology = pipeline.primitive?.topology || "triangle-list";
+ const drawMode = getIGLDrawMode(topology);
+
+ this.runRenderPipeline(gl, pipeline);
+
+ this.runTransformFeedback(gl, transformFeedback, drawMode);
+
+ this.runVertexArray(gl, pipeline, vertices, indices);
+
+ this.runUniforms(gl, pipeline, uniforms);
+
+ if (drawVertex)
+ {
+ this.runDrawVertex(gl, drawMode, drawVertex);
+ }
+ if (drawIndexed)
+ {
+ this.runDrawIndexed(gl, drawMode, indices, drawIndexed);
+ }
+
+ this.endTransformFeedback(gl, transformFeedback);
+ }
+
+ private endTransformFeedback(gl: WebGLRenderingContext, transformFeedback: IGLTransformFeedback)
+ {
+ //
+ if (transformFeedback)
+ {
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ gl.endTransformFeedback();
+ gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
+ }
+ }
+ }
+
+ private runDrawIndexed(gl: WebGLRenderingContext, drawMode: IGLDrawMode, indices: IIndicesDataTypes, drawIndexed: IDrawIndexed)
+ {
+ const type = getBufferType(indices);
+ //
+ const indexCount = drawIndexed.indexCount;
+ const firstIndex = drawIndexed.firstIndex || 0;
+ const instanceCount = drawIndexed.instanceCount || 1;
+ //
+ const offset = firstIndex * indices.BYTES_PER_ELEMENT;
+
+ //
+ if (instanceCount > 1)
+ {
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ gl.drawElementsInstanced(gl[drawMode], indexCount, gl[type], offset, instanceCount);
+ }
+ else
+ {
+ const extension = gl.getExtension("ANGLE_instanced_arrays");
+ extension.drawElementsInstancedANGLE(gl[drawMode], indexCount, gl[type], offset, instanceCount);
+ }
+ }
+ else
+ {
+ gl.drawElements(gl[drawMode], indexCount, gl[type], offset);
+ }
+ }
+
+ private runDrawVertex(gl: WebGLRenderingContext, drawMode: IGLDrawMode, drawArrays: IDrawVertex)
+ {
+ //
+ const vertexCount = drawArrays.vertexCount;
+ const firstVertex = drawArrays.firstVertex || 0;
+ const instanceCount = drawArrays.instanceCount || 1;
+
+ if (instanceCount > 1)
+ {
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ gl.drawArraysInstanced(gl[drawMode], firstVertex, vertexCount, instanceCount);
+ }
+ else
+ {
+ const extension = gl.getExtension("ANGLE_instanced_arrays");
+ extension.drawArraysInstancedANGLE(gl[drawMode], firstVertex, vertexCount, instanceCount);
+ }
+ }
+ else
+ {
+ gl.drawArrays(gl[drawMode], firstVertex, vertexCount);
+ }
+ }
+
+
+ /**
+ * 激活常量
+ */
+ private runUniforms(gl: WebGLRenderingContext, pipeline: IRenderPipeline, uniforms: LazyObject)
+ {
+ const webGLProgram = getGLProgram(gl, pipeline);
+
+ webGLProgram.uniforms.forEach((uniformInfo) =>
+ {
+ const { name, type, items, isTexture, inBlock } = uniformInfo;
+ if (inBlock) return;
+
+ items.forEach((v) =>
+ {
+ const { paths } = v;
+
+ let uniformData = lazy.getValue(uniforms[paths[0]], uniforms);
+ for (let i = 1; i < paths.length; i++)
+ {
+ uniformData = uniformData[paths[i]];
+ }
+ if (uniformData === undefined)
+ {
+ console.error(`沒有找到Uniform ${name} 數據!`);
+ }
+
+ if (isTexture)
+ {
+ this.runSamplerTexture(gl, v, uniformData as IGLSamplerTexture);
+ }
+ else
+ {
+ this.runUniform(gl, type as IGLUniformBufferType, v, uniformData);
+ }
+ });
+ });
+
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ webGLProgram.uniformBlocks.forEach((uniformBlock) =>
+ {
+ const { name, index } = uniformBlock;
+ const uniformData = lazy.getValue(uniforms[name], uniforms);
+
+ //
+ const webGLBuffer = getGLBuffer(gl, uniformData as IGLBuffer);
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, index, webGLBuffer);
+ });
+ }
+ }
+
+ private runSamplerTexture(gl: WebGLRenderingContext, uniformInfo: IUniformItemInfo, samplerTexture: IGLSamplerTexture)
+ {
+ const { texture, sampler } = samplerTexture;
+ const { location, textureID } = uniformInfo;
+
+ const textureTarget = getIGLTextureTarget(texture.dimension);
+
+ // 设置纹理所在采样编号
+ gl.uniform1i(location, textureID);
+ //
+ const webGLTexture = getGLTexture(gl, texture);
+ gl.activeTexture(gl[`TEXTURE${textureID}`]);
+ // 绑定纹理
+ gl.bindTexture(gl[textureTarget], webGLTexture);
+
+ // 运行采样器
+ this.runSampler(gl, textureTarget, webGLTexture, sampler, textureID);
+
+ return webGLTexture;
+ }
+
+ /**
+ * 设置采样参数
+ */
+ private runSampler(gl: WebGLRenderingContext, textureTarget: IGLTextureTarget, webGLTexture: WebGLTexture, sampler: IGLSampler, textureID: number)
+ {
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ const webGLSampler = getGLSampler(gl, sampler);
+ gl.bindSampler(textureID, webGLSampler);
+ }
+ else
+ {
+ const minFilter: IGLTextureMinFilter = sampler.minFilter || "LINEAR_MIPMAP_LINEAR";
+ const magFilter: IGLTextureMagFilter = sampler.magFilter || "LINEAR";
+ const wrapS: IGLTextureWrap = sampler.wrapS || "REPEAT";
+ const wrapT: IGLTextureWrap = sampler.wrapT || "REPEAT";
+
+ // 设置纹理参数
+ if (webGLTexture.minFilter !== minFilter)
+ {
+ gl.texParameteri(gl[textureTarget], gl.TEXTURE_MIN_FILTER, gl[minFilter]);
+ webGLTexture.minFilter = minFilter;
+ }
+ if (webGLTexture.magFilter !== magFilter)
+ {
+ gl.texParameteri(gl[textureTarget], gl.TEXTURE_MAG_FILTER, gl[magFilter]);
+ webGLTexture.magFilter = magFilter;
+ }
+ if (webGLTexture.wrapS !== wrapS)
+ {
+ gl.texParameteri(gl[textureTarget], gl.TEXTURE_WRAP_S, gl[wrapS]);
+ webGLTexture.wrapS = wrapS;
+ }
+ if (webGLTexture.wrapT !== wrapT)
+ {
+ gl.texParameteri(gl[textureTarget], gl.TEXTURE_WRAP_T, gl[wrapT]);
+ webGLTexture.wrapT = wrapT;
+ }
+ }
+
+ //
+ const anisotropy = sampler?.anisotropy || 1;
+ if (webGLTexture.anisotropy !== anisotropy)
+ {
+ const extension = gl.getExtension("EXT_texture_filter_anisotropic");
+ if (extension)
+ {
+ gl.texParameterf(gl[textureTarget], extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(anisotropy, gl._capabilities.maxAnisotropy));
+ }
+ webGLTexture.anisotropy = anisotropy;
+ }
+ }
+
+ /**
+ * 设置环境Uniform数据
+ */
+ private runUniform(gl: WebGLRenderingContext, type: IGLUniformBufferType, uniformInfo: IUniformItemInfo, data: any)
+ {
+ const location = uniformInfo.location;
+ switch (type)
+ {
+ case "BOOL":
+ case "INT":
+ // gl.uniform1i(location, data);
+ gl.uniform1iv(location, [data]);
+ break;
+ case "BOOL_VEC2":
+ case "INT_VEC2":
+ // gl.uniform2i(location, data[0], data[1]);
+ gl.uniform2iv(location, data);
+ break;
+ case "BOOL_VEC3":
+ case "INT_VEC3":
+ // gl.uniform3i(location, data[0], data[1], data[2]);
+ gl.uniform3iv(location, data);
+ break;
+ case "BOOL_VEC4":
+ case "INT_VEC4":
+ // gl.uniform4i(location, data[0], data[1], data[2], data[3]);
+ gl.uniform4iv(location, data);
+ break;
+ case "FLOAT":
+ // gl.uniform1f(location, data);
+ gl.uniform1fv(location, [data]);
+ break;
+ case "FLOAT_VEC2":
+ // gl.uniform2f(location, data[0], data[1]);
+ gl.uniform2fv(location, data);
+ break;
+ case "FLOAT_VEC3":
+ // gl.uniform3f(location, data[0], data[1], data[2]);
+ gl.uniform3fv(location, data);
+ break;
+ case "FLOAT_VEC4":
+ // gl.uniform4f(location, data[0], data[1], data[2], data[3]);
+ gl.uniform4fv(location, data);
+ break;
+ case "FLOAT_MAT2":
+ gl.uniformMatrix2fv(location, false, data);
+ break;
+ case "FLOAT_MAT3":
+ gl.uniformMatrix3fv(location, false, data);
+ break;
+ case "FLOAT_MAT4":
+ gl.uniformMatrix4fv(location, false, data);
+ break;
+ case "UNSIGNED_INT":
+ (gl as any as WebGL2RenderingContext).uniform1ui(location, data);
+ (gl as any as WebGL2RenderingContext).uniform1uiv(location, [data]);
+ break;
+ case "UNSIGNED_INT_VEC2":
+ // (gl as any as WebGL2RenderingContext).uniform2ui(location, data[0], data[1]);
+ (gl as any as WebGL2RenderingContext).uniform2uiv(location, data);
+ break;
+ case "UNSIGNED_INT_VEC3":
+ // (gl as any as WebGL2RenderingContext).uniform3ui(location, data[0], data[1], data[2]);
+ (gl as any as WebGL2RenderingContext).uniform3uiv(location, data);
+ break;
+ case "UNSIGNED_INT_VEC4":
+ // (gl as any as WebGL2RenderingContext).uniform4ui(location, data[0], data[1], data[2], data[3]);
+ (gl as any as WebGL2RenderingContext).uniform4uiv(location, data);
+ break;
+ case "FLOAT_MAT2x3":
+ (gl as any as WebGL2RenderingContext).uniformMatrix2x3fv(location, false, data);
+ break;
+ case "FLOAT_MAT2x4":
+ (gl as any as WebGL2RenderingContext).uniformMatrix2x4fv(location, false, data);
+ break;
+ case "FLOAT_MAT3x2":
+ (gl as any as WebGL2RenderingContext).uniformMatrix3x2fv(location, false, data);
+ break;
+ case "FLOAT_MAT3x4":
+ (gl as any as WebGL2RenderingContext).uniformMatrix3x4fv(location, false, data);
+ break;
+ case "FLOAT_MAT4x2":
+ (gl as any as WebGL2RenderingContext).uniformMatrix4x2fv(location, false, data);
+ break;
+ case "FLOAT_MAT4x3":
+ (gl as any as WebGL2RenderingContext).uniformMatrix4x3fv(location, false, data);
+ break;
+ default:
+ console.error(`无法识别的uniform类型 ${uniformInfo.paths} ${type}`);
+ }
+ }
+
+
+ /**
+ * 执行设置或者上传渲染对象的顶点以及索引数据。
+ */
+ private runVertexArray(gl: WebGLRenderingContext, pipeline: IRenderPipeline, vertices: IVertexAttributes, indices: IIndicesDataTypes)
+ {
+ if (!vertices && !indices) return;
+
+ let webGLVertexArrayObject: WebGLVertexArrayObject;
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ webGLVertexArrayObject = gl._vertexArrays.get([pipeline, vertices, indices]);
+ if (webGLVertexArrayObject)
+ {
+ gl.bindVertexArray(webGLVertexArrayObject);
+
+ return;
+ }
+
+ webGLVertexArrayObject = gl.createVertexArray();
+ gl.bindVertexArray(webGLVertexArrayObject);
+ gl._vertexArrays.set([pipeline, vertices, indices], webGLVertexArrayObject);
+ }
+
+ const shaderResult = getGLProgram(gl, pipeline);
+
+ //
+ shaderResult.attributes.forEach((activeInfo) =>
+ {
+ const { name, location } = activeInfo;
+ // 处理 WebGL 内置属性 gl_VertexID 等
+ if (location < 0) return;
+
+ const attribute = vertices[name];
+ if (!attribute)
+ {
+ console.error(`缺少顶点 ${name} 数据!`);
+ }
+
+ this.runVertexAttribute(gl, location, attribute);
+ });
+
+ this.runIndexBuffer(gl, indices);
+ }
+
+ private runIndexBuffer(gl: WebGLRenderingContext, indices?: IIndicesDataTypes)
+ {
+ if (!indices) return;
+
+ const indexBuffer = getIGLIndexBuffer(indices);
+
+ const buffer = getGLBuffer(gl, indexBuffer);
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer);
+ }
+
+ private runVertexAttribute(gl: WebGLRenderingContext, location: number, attribute: IVertexAttribute)
+ {
+ const { stepMode, format } = attribute;
+ let { arrayStride, offset } = attribute;
+
+ const glVertexFormat = getIGLVertexFormat(format);
+ const { numComponents, normalized, type } = glVertexFormat;
+
+ gl.enableVertexAttribArray(location);
+
+ if (stepMode === "instance")
+ {
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ gl.vertexAttribDivisor(location, 1);
}
else
{
- runRenderObject(gl, renderObject);
+ const extension = gl.getExtension("ANGLE_instanced_arrays");
+ extension.vertexAttribDivisorANGLE(location, 1);
}
+ }
+
+ //
+ arrayStride = arrayStride || 0;
+ offset = offset || 0;
+
+ //
+ const buffer = getIGLVertexBuffer(attribute.data);
+ const webGLBuffer = getGLBuffer(gl, buffer);
+ gl.bindBuffer(gl.ARRAY_BUFFER, webGLBuffer);
+
+ //
+ if (gl instanceof WebGL2RenderingContext && (type === "INT" || type === "UNSIGNED_INT"))
+ {
+ gl.vertexAttribIPointer(location, numComponents, gl[type], arrayStride, offset);
+ }
+ else
+ {
+ gl.vertexAttribPointer(location, numComponents, gl[type], normalized, arrayStride, offset);
+ }
+ }
+
+ private runTransformFeedback(gl: WebGLRenderingContext, transformFeedback: IGLTransformFeedback, topology: IGLDrawMode)
+ {
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ if (transformFeedback)
+ {
+ const webGLTransformFeedback = getGLTransformFeedback(gl, transformFeedback);
+
+ gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, webGLTransformFeedback);
+
+ gl.beginTransformFeedback(gl[topology]);
+ }
+ else
+ {
+ gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
+ }
+ }
+ else if (transformFeedback)
+ {
+ console.log(`WebGL1 不支持顶点着色器回写数据功能!`);
+ }
+ }
+
+ private runRenderPipeline(gl: WebGLRenderingContext, renderPipeline: IRenderPipeline)
+ {
+ this.runProgram(gl, renderPipeline);
+
+ this.runPrimitiveState(gl, renderPipeline?.primitive);
+
+ this.runDepthState(gl, renderPipeline.depthStencil);
+ this.runStencilState(gl, renderPipeline.depthStencil);
+ }
+
+ private runStencilState(gl: WebGLRenderingContext, depthStencil?: IDepthStencilState)
+ {
+ const { stencilFront, stencilBack } = { ...depthStencil };
+ //
+ if (stencilFront || stencilBack)
+ {
+ const ref: number = depthStencil.stencilReference ?? 0;
+ const readMask = depthStencil.stencilReadMask ?? 0xFFFFFFFF;
+ const writeMask = depthStencil.stencilWriteMask ?? 0xFFFFFFFF;
+
+ gl.enable(gl.STENCIL_TEST);
+
+ if (stencilFront)
+ {
+ const func: IGLStencilFunc = getIGLStencilFunc(stencilFront.compare ?? "always");
+ const fail: IGLStencilOp = getIGLStencilOp(stencilFront.failOp);
+ const zfail: IGLStencilOp = getIGLStencilOp(stencilFront.depthFailOp);
+ const zpass: IGLStencilOp = getIGLStencilOp(stencilFront.passOp);
+ //
+ gl.stencilFuncSeparate(gl.FRONT, gl[func], ref, readMask);
+ gl.stencilOpSeparate(gl.FRONT, gl[fail], gl[zfail], gl[zpass]);
+ gl.stencilMaskSeparate(gl.FRONT, writeMask);
+ }
+ if (stencilBack)
+ {
+ const func: IGLStencilFunc = getIGLStencilFunc(stencilBack.compare ?? "always");
+ const fail: IGLStencilOp = getIGLStencilOp(stencilBack.failOp);
+ const zfail: IGLStencilOp = getIGLStencilOp(stencilBack.depthFailOp);
+ const zpass: IGLStencilOp = getIGLStencilOp(stencilBack.passOp);
+ //
+ gl.stencilFuncSeparate(gl.BACK, gl[func], ref, readMask);
+ gl.stencilOpSeparate(gl.BACK, gl[fail], gl[zfail], gl[zpass]);
+ gl.stencilMaskSeparate(gl.BACK, writeMask);
+ }
+ }
+ else
+ {
+ gl.disable(gl.STENCIL_TEST);
+ }
+ }
+
+ private runDepthState(gl: WebGLRenderingContext, depthStencil?: IDepthStencilState)
+ {
+ if (depthStencil && (depthStencil.depthWriteEnabled || depthStencil.depthCompare !== "always"))
+ {
+ const depthCompare: IGLCompareFunction = getIGLCompareFunction(depthStencil.depthCompare ?? 'less');
+ const depthWriteEnabled = depthStencil.depthWriteEnabled ?? true;
+ //
+ gl.enable(gl.DEPTH_TEST);
+ //
+ gl.depthFunc(gl[depthCompare]);
+ gl.depthMask(depthWriteEnabled);
+
+ //
+ if (depthStencil.depthBias || depthStencil.depthBiasSlopeScale)
+ {
+ const factor = depthStencil.depthBiasSlopeScale ?? 0;
+ const units = depthStencil.depthBias ?? 0;
+ //
+ gl.enable(gl.POLYGON_OFFSET_FILL);
+ gl.polygonOffset(factor, units);
+ }
+ else
+ {
+ gl.disable(gl.POLYGON_OFFSET_FILL);
+ }
+ }
+ else
+ {
+ gl.disable(gl.DEPTH_TEST);
+ }
+ }
+
+ private runPrimitiveState(gl: WebGLRenderingContext, primitive?: IPrimitiveState)
+ {
+ const cullFace: ICullFace = primitive?.cullFace || "none";
+ const frontFace: IFrontFace = primitive?.frontFace || "ccw";
+
+ const enableCullFace = cullFace !== "none";
+ const glCullMode: IGLCullFace = getIGLCullFace(cullFace);
+ const glFrontFace: IGLFrontFace = getIGLFrontFace(frontFace);
+
+ if (enableCullFace)
+ {
+ gl.enable(gl.CULL_FACE);
+ gl.cullFace(gl[glCullMode]);
+ gl.frontFace(gl[glFrontFace]);
+ }
+ else
+ {
+ gl.disable(gl.CULL_FACE);
+ }
+ }
+
+ private runProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeline)
+ {
+ const program = getGLProgram(gl, pipeline);
+ gl.useProgram(program);
+
+ //
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ if (pipeline.rasterizerDiscard)
+ {
+ gl.enable(gl.RASTERIZER_DISCARD);
+ }
+ else
+ {
+ gl.disable(gl.RASTERIZER_DISCARD);
+ }
+ }
+
+ //
+ this.runColorTargetStates(gl, pipeline.fragment.targets);
+ }
+
+ private runColorTargetStates(gl: WebGLRenderingContext, targets?: readonly IColorTargetState[])
+ {
+ //
+ const colorMask = targets?.[0]?.writeMask || [true, true, true, true];
+ gl.colorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
+
+ //
+ let blend = targets?.[0]?.blend;
+ if (blend)
+ {
+ const color: IBlendComponent = blend.color;
+ const alpha: IBlendComponent = blend.alpha;
+
+ const colorOperation: IGLBlendEquation = getIGLBlendEquation(color?.operation) || "FUNC_ADD";
+ const colorSrcFactor: IGLBlendFactor = getIGLBlendFactor(color?.srcFactor, color?.operation) || "SRC_ALPHA";
+ const colorDstFactor: IGLBlendFactor = getIGLBlendFactor(color?.dstFactor, color?.operation) || "ONE_MINUS_SRC_ALPHA";
+ //
+ const alphaOperation: IGLBlendEquation = getIGLBlendEquation(alpha?.operation) || colorOperation;
+ const alphaSrcFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.srcFactor, color?.operation) || colorSrcFactor;
+ const alphaDstFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.dstFactor, color?.operation) || colorDstFactor;
+
+ // 当混合系数用到了混合常量值时设置混合常量值。
+ const constantColor = getBlendConstantColor(blend);
+ if (constantColor)
+ {
+ const constantColor = blend.constantColor ?? [0, 0, 0, 0];
+ gl.blendColor(constantColor[0], constantColor[1], constantColor[2], constantColor[3]);
+ }
+
+ //
+ gl.enable(gl.BLEND);
+ gl.blendEquationSeparate(gl[colorOperation], gl[alphaOperation]);
+ gl.blendFuncSeparate(gl[colorSrcFactor], gl[colorDstFactor], gl[alphaSrcFactor], gl[alphaDstFactor]);
+ }
+ else
+ {
+ gl.disable(gl.BLEND);
+ }
+ }
+
+ private runOcclusionQuery(gl: WebGLRenderingContext, occlusionQuery: IGLOcclusionQuery)
+ {
+ // 开始查询
+ occlusionQuery._step.begin();
+
+ // 正常渲染对象列表
+ occlusionQuery.renderObjects.forEach((renderObject) =>
+ {
+ this.runRenderObject(gl, renderObject);
});
+
+ // 结束查询
+ occlusionQuery._step.end();
+ }
+
+ private runViewPort(gl: WebGLRenderingContext, viewport?: IGLViewport)
+ {
+ if (viewport)
+ {
+ gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
+ }
+ else
+ {
+ gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
+ }
+ }
+
+ private runScissor(gl: WebGLRenderingContext, scissor?: IGLScissorRect)
+ {
+ if (scissor)
+ {
+ gl.enable(gl.SCISSOR_TEST);
+ gl.scissor(scissor.x, scissor.y, scissor.width, scissor.height);
+ }
+ else
+ {
+ gl.disable(gl.SCISSOR_TEST);
+ }
}
private runCopyTextureToTexture(gl: WebGLRenderingContext, copyTextureToTexture: IGLCopyTextureToTexture)
diff --git a/src/WebGL.ts b/src/WebGL.ts
index 976b93f..75a28a9 100644
--- a/src/WebGL.ts
+++ b/src/WebGL.ts
@@ -15,7 +15,7 @@ import { IGLReadPixels } from "./data/IGLReadPixels";
import { IGLRenderbuffer } from "./data/IGLRenderbuffer";
import { IGLSampler } from "./data/IGLSampler";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
-import { runReadPixels } from "./runs/runReadPixels";
+import { readPixels } from "./runs/runReadPixels";
/**
* WEBGL 对象。
@@ -45,9 +45,9 @@ export class WebGL
this._runWebGL.runSubmit(this._gl, submit);
}
- runReadPixels(readPixels: IGLReadPixels)
+ runReadPixels(glReadPixels: IGLReadPixels)
{
- runReadPixels(this._gl, readPixels);
+ readPixels(this._gl, glReadPixels);
}
deleteFramebuffer(passDescriptor: IRenderPassDescriptor)
diff --git a/src/index.ts b/src/index.ts
index c7bdc38..f56ae1d 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -24,8 +24,6 @@ export * from "./data/IGLViewport";
export * from "./runs/getIGLBuffer";
export * from "./runs/runColorTargetStates";
-export * from "./runs/runDrawCall";
-export * from "./runs/runVertexAttribute";
export * from "./RunWebGL";
export * from "./defaults/defaults";
diff --git a/src/runs/runColorTargetStates.ts b/src/runs/runColorTargetStates.ts
index c698073..e46060a 100644
--- a/src/runs/runColorTargetStates.ts
+++ b/src/runs/runColorTargetStates.ts
@@ -1,46 +1,6 @@
-import { getBlendConstantColor, IBlendComponent, IBlendFactor, IBlendOperation, IColorTargetState } from "@feng3d/render-api";
+import { IBlendFactor, IBlendOperation } from "@feng3d/render-api";
-export function runColorTargetStates(gl: WebGLRenderingContext, targets?: readonly IColorTargetState[])
-{
- //
- const colorMask = targets?.[0]?.writeMask || [true, true, true, true];
- gl.colorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
-
- //
- let blend = targets?.[0]?.blend;
- if (blend)
- {
- const color: IBlendComponent = blend.color;
- const alpha: IBlendComponent = blend.alpha;
-
- const colorOperation: IGLBlendEquation = getIGLBlendEquation(color?.operation) || "FUNC_ADD";
- const colorSrcFactor: IGLBlendFactor = getIGLBlendFactor(color?.srcFactor, color?.operation) || "SRC_ALPHA";
- const colorDstFactor: IGLBlendFactor = getIGLBlendFactor(color?.dstFactor, color?.operation) || "ONE_MINUS_SRC_ALPHA";
- //
- const alphaOperation: IGLBlendEquation = getIGLBlendEquation(alpha?.operation) || colorOperation;
- const alphaSrcFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.srcFactor, color?.operation) || colorSrcFactor;
- const alphaDstFactor: IGLBlendFactor = getIGLBlendFactor(alpha?.dstFactor, color?.operation) || colorDstFactor;
-
- // 当混合系数用到了混合常量值时设置混合常量值。
- const constantColor = getBlendConstantColor(blend);
- if (constantColor)
- {
- const constantColor = blend.constantColor ?? [0, 0, 0, 0];
- gl.blendColor(constantColor[0], constantColor[1], constantColor[2], constantColor[3]);
- }
-
- //
- gl.enable(gl.BLEND);
- gl.blendEquationSeparate(gl[colorOperation], gl[alphaOperation]);
- gl.blendFuncSeparate(gl[colorSrcFactor], gl[colorDstFactor], gl[alphaSrcFactor], gl[alphaDstFactor]);
- }
- else
- {
- gl.disable(gl.BLEND);
- }
-}
-
-function getIGLBlendEquation(operation?: IBlendOperation)
+export function getIGLBlendEquation(operation?: IBlendOperation)
{
if (!operation) return undefined;
@@ -59,7 +19,7 @@ const operationMap: { [key: string]: IGLBlendEquation } = {
"max": "MAX",
};
-function getIGLBlendFactor(blendFactor: IBlendFactor, operation: IBlendOperation)
+export function getIGLBlendFactor(blendFactor: IBlendFactor, operation: IBlendOperation)
{
if (!blendFactor) return undefined;
diff --git a/src/runs/runDepthState.ts b/src/runs/runDepthState.ts
index b8d8275..9d99e8b 100644
--- a/src/runs/runDepthState.ts
+++ b/src/runs/runDepthState.ts
@@ -1,39 +1,7 @@
import { ICompareFunction, IDepthStencilState } from "@feng3d/render-api";
import { IGLCompareFunction } from "../data/IGLDepthStencilState";
-export function runDepthState(gl: WebGLRenderingContext, depthStencil?: IDepthStencilState)
-{
- if (depthStencil && (depthStencil.depthWriteEnabled || depthStencil.depthCompare !== "always"))
- {
- const depthCompare: IGLCompareFunction = getIGLCompareFunction(depthStencil.depthCompare ?? 'less');
- const depthWriteEnabled = depthStencil.depthWriteEnabled ?? true;
- //
- gl.enable(gl.DEPTH_TEST);
- //
- gl.depthFunc(gl[depthCompare]);
- gl.depthMask(depthWriteEnabled);
-
- //
- if (depthStencil.depthBias || depthStencil.depthBiasSlopeScale)
- {
- const factor = depthStencil.depthBiasSlopeScale ?? 0;
- const units = depthStencil.depthBias ?? 0;
- //
- gl.enable(gl.POLYGON_OFFSET_FILL);
- gl.polygonOffset(factor, units);
- }
- else
- {
- gl.disable(gl.POLYGON_OFFSET_FILL);
- }
- }
- else
- {
- gl.disable(gl.DEPTH_TEST);
- }
-}
-
-function getIGLCompareFunction(depthCompare: ICompareFunction)
+export function getIGLCompareFunction(depthCompare: ICompareFunction)
{
const glDepthCompare: IGLCompareFunction = depthCompareMap[depthCompare];
diff --git a/src/runs/runDepthStencilState.ts b/src/runs/runDepthStencilState.ts
deleted file mode 100644
index 52bc43b..0000000
--- a/src/runs/runDepthStencilState.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { IDepthStencilState } from "@feng3d/render-api";
-import { runDepthState } from "./runDepthState";
-import { runStencilState } from "./runStencilState";
-
-export function runDepthStencilState(gl: WebGLRenderingContext, depthStencil?: IDepthStencilState)
-{
- runDepthState(gl, depthStencil);
- runStencilState(gl, depthStencil);
-}
diff --git a/src/runs/runDrawCall.ts b/src/runs/runDrawCall.ts
deleted file mode 100644
index 4d0227c..0000000
--- a/src/runs/runDrawCall.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-import { IDrawIndexed, IDrawVertex, IIndicesDataTypes, IRenderObject } from "@feng3d/render-api";
-
-import { getBufferType } from "../caches/getGLBuffer";
-import { IGLDrawMode } from "../caches/getIGLDrawMode";
-
-export function runDrawCall(gl: WebGLRenderingContext, renderObject: IRenderObject, drawMode: IGLDrawMode)
-{
- const { indices, drawIndexed, drawVertex } = renderObject;
-
- if (drawVertex)
- {
- _runDrawVertex(gl, drawMode, drawVertex);
- }
- else if (drawIndexed)
- {
- _runDrawIndexed(gl, drawMode, indices, drawIndexed);
- }
-}
-
-function _runDrawIndexed(gl: WebGLRenderingContext, drawMode: IGLDrawMode, indices: IIndicesDataTypes, drawIndexed: IDrawIndexed)
-{
- const type = getBufferType(indices);
- //
- const indexCount = drawIndexed.indexCount;
- const firstIndex = drawIndexed.firstIndex || 0;
- const instanceCount = drawIndexed.instanceCount || 1;
- //
- const offset = firstIndex * indices.BYTES_PER_ELEMENT;
-
- //
- if (instanceCount > 1)
- {
- if (gl instanceof WebGL2RenderingContext)
- {
- gl.drawElementsInstanced(gl[drawMode], indexCount, gl[type], offset, instanceCount);
- }
- else
- {
- const extension = gl.getExtension("ANGLE_instanced_arrays");
- extension.drawElementsInstancedANGLE(gl[drawMode], indexCount, gl[type], offset, instanceCount);
- }
- }
- else
- {
- gl.drawElements(gl[drawMode], indexCount, gl[type], offset);
- }
-}
-
-function _runDrawVertex(gl: WebGLRenderingContext, drawMode: IGLDrawMode, drawArrays: IDrawVertex)
-{
- //
- const vertexCount = drawArrays.vertexCount;
- const firstVertex = drawArrays.firstVertex || 0;
- const instanceCount = drawArrays.instanceCount || 1;
-
- if (instanceCount > 1)
- {
- if (gl instanceof WebGL2RenderingContext)
- {
- gl.drawArraysInstanced(gl[drawMode], firstVertex, vertexCount, instanceCount);
- }
- else
- {
- const extension = gl.getExtension("ANGLE_instanced_arrays");
- extension.drawArraysInstancedANGLE(gl[drawMode], firstVertex, vertexCount, instanceCount);
- }
- }
- else
- {
- gl.drawArrays(gl[drawMode], firstVertex, vertexCount);
- }
-}
diff --git a/src/runs/runFramebuffer.ts b/src/runs/runFramebuffer.ts
deleted file mode 100644
index 738ca68..0000000
--- a/src/runs/runFramebuffer.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import { IRenderPassDescriptor } from "@feng3d/render-api";
-import { getFramebuffer } from "../caches/getFramebuffer";
-
-/**
- * 运行帧缓冲区
- */
-export function runFramebuffer(gl: WebGLRenderingContext, passDescriptor: IRenderPassDescriptor)
-{
- const framebuffer = getFramebuffer(gl, passDescriptor);
- gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
-}
\ No newline at end of file
diff --git a/src/runs/runIndexBuffer.ts b/src/runs/runIndexBuffer.ts
deleted file mode 100644
index 707596f..0000000
--- a/src/runs/runIndexBuffer.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { IIndicesDataTypes } from "@feng3d/render-api";
-import { getGLBuffer } from "../caches/getGLBuffer";
-import { getIGLIndexBuffer } from "./getIGLBuffer";
-
-export function runIndexBuffer(gl: WebGLRenderingContext, indices?: IIndicesDataTypes)
-{
- if (!indices) return;
-
- const indexBuffer = getIGLIndexBuffer(indices);
-
- const buffer = getGLBuffer(gl, indexBuffer);
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer);
-}
-
diff --git a/src/runs/runOcclusionQuery.ts b/src/runs/runOcclusionQuery.ts
deleted file mode 100644
index e6c4afd..0000000
--- a/src/runs/runOcclusionQuery.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import { IGLOcclusionQuery } from "../data/IGLOcclusionQuery";
-import { runRenderObject } from "./runRenderObject";
-
-export function runOcclusionQuery(gl: WebGLRenderingContext, occlusionQuery: IGLOcclusionQuery)
-{
- // 开始查询
- occlusionQuery._step.begin();
-
- // 正常渲染对象列表
- occlusionQuery.renderObjects.forEach((renderObject) =>
- {
- runRenderObject(gl, renderObject);
- });
-
- // 结束查询
- occlusionQuery._step.end();
-}
diff --git a/src/runs/runPrimitiveState.ts b/src/runs/runPrimitiveState.ts
deleted file mode 100644
index 58fb9de..0000000
--- a/src/runs/runPrimitiveState.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { ICullFace, IFrontFace, IPrimitiveState } from "@feng3d/render-api";
-import { getIGLCullFace, IGLCullFace } from "../utils/getIGLCullFace";
-import { getIGLFrontFace, IGLFrontFace } from "../utils/getIGLFrontFace";
-
-export function runPrimitiveState(gl: WebGLRenderingContext, primitive?: IPrimitiveState)
-{
- const cullFace: ICullFace = primitive?.cullFace || "none";
- const frontFace: IFrontFace = primitive?.frontFace || "ccw";
-
- const enableCullFace = cullFace !== "none";
- const glCullMode: IGLCullFace = getIGLCullFace(cullFace);
- const glFrontFace: IGLFrontFace = getIGLFrontFace(frontFace);
-
- if (enableCullFace)
- {
- gl.enable(gl.CULL_FACE);
- gl.cullFace(gl[glCullMode]);
- gl.frontFace(gl[glFrontFace]);
- }
- else
- {
- gl.disable(gl.CULL_FACE);
- }
-}
diff --git a/src/runs/runProgram.ts b/src/runs/runProgram.ts
deleted file mode 100644
index 2cd30c6..0000000
--- a/src/runs/runProgram.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { IRenderPipeline } from "@feng3d/render-api";
-import { getGLProgram } from "../caches/getGLProgram";
-import { runColorTargetStates } from "./runColorTargetStates";
-
-export function runProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeline)
-{
- const program = getGLProgram(gl, pipeline);
- gl.useProgram(program);
-
- //
- if (gl instanceof WebGL2RenderingContext)
- {
- if (pipeline.rasterizerDiscard)
- {
- gl.enable(gl.RASTERIZER_DISCARD);
- }
- else
- {
- gl.disable(gl.RASTERIZER_DISCARD);
- }
- }
-
- //
- runColorTargetStates(gl, pipeline.fragment.targets);
-}
diff --git a/src/runs/runReadPixels.ts b/src/runs/runReadPixels.ts
index 213fab6..e82ba1e 100644
--- a/src/runs/runReadPixels.ts
+++ b/src/runs/runReadPixels.ts
@@ -1,7 +1,7 @@
import { getFramebuffer } from "../caches/getFramebuffer";
import { IGLReadPixels } from "../data/IGLReadPixels";
-export function runReadPixels(gl: WebGLRenderingContext, readPixels: IGLReadPixels)
+export function readPixels(gl: WebGLRenderingContext, readPixels: IGLReadPixels)
{
if (gl instanceof WebGL2RenderingContext)
{
diff --git a/src/runs/runRenderObject.ts b/src/runs/runRenderObject.ts
deleted file mode 100644
index 60ca557..0000000
--- a/src/runs/runRenderObject.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { IRenderObject } from "@feng3d/render-api";
-import { getIGLDrawMode } from "../caches/getIGLDrawMode";
-import { runDrawCall } from "./runDrawCall";
-import { runRenderPipeline } from "./runRenderPipeline";
-import { endTransformFeedback, runTransformFeedback } from "./runTransformFeedback";
-import { runUniforms } from "./runUniforms";
-import { runVertexArray } from "./runVertexArray";
-
-export function runRenderObject(gl: WebGLRenderingContext, renderObject: IRenderObject)
-{
- const { pipeline, vertices, indices, uniforms, transformFeedback } = renderObject;
-
- const topology = pipeline.primitive?.topology || "triangle-list";
- const drawMode = getIGLDrawMode(topology);
-
- runRenderPipeline(gl, pipeline);
-
- runTransformFeedback(gl, transformFeedback, drawMode);
-
- runVertexArray(gl, pipeline, vertices, indices);
-
- runUniforms(gl, pipeline, uniforms);
-
- runDrawCall(gl, renderObject, drawMode);
-
- endTransformFeedback(gl, transformFeedback);
-}
diff --git a/src/runs/runRenderPipeline.ts b/src/runs/runRenderPipeline.ts
deleted file mode 100644
index 58cd1b7..0000000
--- a/src/runs/runRenderPipeline.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { IRenderPipeline } from "@feng3d/render-api";
-import { runDepthStencilState } from "./runDepthStencilState";
-import { runPrimitiveState } from "./runPrimitiveState";
-import { runProgram } from "./runProgram";
-
-export function runRenderPipeline(gl: WebGLRenderingContext, renderPipeline: IRenderPipeline)
-{
- runProgram(gl, renderPipeline);
-
- runPrimitiveState(gl, renderPipeline?.primitive);
-
- runDepthStencilState(gl, renderPipeline.depthStencil);
-}
diff --git a/src/runs/runSampler.ts b/src/runs/runSampler.ts
deleted file mode 100644
index c9599da..0000000
--- a/src/runs/runSampler.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-import { getGLSampler } from "../caches/getGLSampler";
-import { IGLTextureMinFilter, IGLTextureWrap, IGLSampler, IGLTextureMagFilter } from "../data/IGLSampler";
-import { IGLTextureTarget } from "../data/IGLTexture";
-
-declare global
-{
- interface WebGLTexture
- {
- minFilter?: IGLTextureMinFilter,
- magFilter?: IGLTextureMagFilter,
- wrapS?: IGLTextureWrap,
- wrapT?: IGLTextureWrap,
- wrapR?: IGLTextureWrap,
- anisotropy?: number,
- lodMinClamp?: number;
- lodMaxClamp?: number;
- }
-}
-
-/**
- * 设置采样参数
- */
-export function runSampler(gl: WebGLRenderingContext, textureTarget: IGLTextureTarget, webGLTexture: WebGLTexture, sampler: IGLSampler, textureID: number)
-{
- if (gl instanceof WebGL2RenderingContext)
- {
- const webGLSampler = getGLSampler(gl, sampler);
- gl.bindSampler(textureID, webGLSampler);
- }
- else
- {
- const minFilter: IGLTextureMinFilter = sampler.minFilter || "LINEAR_MIPMAP_LINEAR";
- const magFilter: IGLTextureMagFilter = sampler.magFilter || "LINEAR";
- const wrapS: IGLTextureWrap = sampler.wrapS || "REPEAT";
- const wrapT: IGLTextureWrap = sampler.wrapT || "REPEAT";
-
- // 设置纹理参数
- if (webGLTexture.minFilter !== minFilter)
- {
- gl.texParameteri(gl[textureTarget], gl.TEXTURE_MIN_FILTER, gl[minFilter]);
- webGLTexture.minFilter = minFilter;
- }
- if (webGLTexture.magFilter !== magFilter)
- {
- gl.texParameteri(gl[textureTarget], gl.TEXTURE_MAG_FILTER, gl[magFilter]);
- webGLTexture.magFilter = magFilter;
- }
- if (webGLTexture.wrapS !== wrapS)
- {
- gl.texParameteri(gl[textureTarget], gl.TEXTURE_WRAP_S, gl[wrapS]);
- webGLTexture.wrapS = wrapS;
- }
- if (webGLTexture.wrapT !== wrapT)
- {
- gl.texParameteri(gl[textureTarget], gl.TEXTURE_WRAP_T, gl[wrapT]);
- webGLTexture.wrapT = wrapT;
- }
- }
-
- //
- const anisotropy = sampler?.anisotropy || 1;
- if (webGLTexture.anisotropy !== anisotropy)
- {
- const extension = gl.getExtension("EXT_texture_filter_anisotropic");
- if (extension)
- {
- gl.texParameterf(gl[textureTarget], extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(anisotropy, gl._capabilities.maxAnisotropy));
- }
- webGLTexture.anisotropy = anisotropy;
- }
-}
diff --git a/src/runs/runScissor.ts b/src/runs/runScissor.ts
deleted file mode 100644
index 0e0dd02..0000000
--- a/src/runs/runScissor.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { IGLScissorRect } from "../data/IGLScissorRect";
-
-export function runScissor(gl: WebGLRenderingContext, scissor?: IGLScissorRect)
-{
- if (scissor)
- {
- gl.enable(gl.SCISSOR_TEST);
- gl.scissor(scissor.x, scissor.y, scissor.width, scissor.height);
- }
- else
- {
- gl.disable(gl.SCISSOR_TEST);
- }
-}
\ No newline at end of file
diff --git a/src/runs/runStencilState.ts b/src/runs/runStencilState.ts
index b2c8f74..39ab879 100644
--- a/src/runs/runStencilState.ts
+++ b/src/runs/runStencilState.ts
@@ -1,48 +1,7 @@
import { ICompareFunction, IDepthStencilState, IStencilOperation } from "@feng3d/render-api";
import { IGLStencilFunc, IGLStencilOp } from "../data/IGLDepthStencilState";
-export function runStencilState(gl: WebGLRenderingContext, depthStencil?: IDepthStencilState)
-{
- const { stencilFront, stencilBack } = { ...depthStencil };
- //
- if (stencilFront || stencilBack)
- {
- const ref: number = depthStencil.stencilReference ?? 0;
- const readMask = depthStencil.stencilReadMask ?? 0xFFFFFFFF;
- const writeMask = depthStencil.stencilWriteMask ?? 0xFFFFFFFF;
-
- gl.enable(gl.STENCIL_TEST);
-
- if (stencilFront)
- {
- const func: IGLStencilFunc = getIGLStencilFunc(stencilFront.compare ?? "always");
- const fail: IGLStencilOp = getIGLStencilOp(stencilFront.failOp);
- const zfail: IGLStencilOp = getIGLStencilOp(stencilFront.depthFailOp);
- const zpass: IGLStencilOp = getIGLStencilOp(stencilFront.passOp);
- //
- gl.stencilFuncSeparate(gl.FRONT, gl[func], ref, readMask);
- gl.stencilOpSeparate(gl.FRONT, gl[fail], gl[zfail], gl[zpass]);
- gl.stencilMaskSeparate(gl.FRONT, writeMask);
- }
- if (stencilBack)
- {
- const func: IGLStencilFunc = getIGLStencilFunc(stencilBack.compare ?? "always");
- const fail: IGLStencilOp = getIGLStencilOp(stencilBack.failOp);
- const zfail: IGLStencilOp = getIGLStencilOp(stencilBack.depthFailOp);
- const zpass: IGLStencilOp = getIGLStencilOp(stencilBack.passOp);
- //
- gl.stencilFuncSeparate(gl.BACK, gl[func], ref, readMask);
- gl.stencilOpSeparate(gl.BACK, gl[fail], gl[zfail], gl[zpass]);
- gl.stencilMaskSeparate(gl.BACK, writeMask);
- }
- }
- else
- {
- gl.disable(gl.STENCIL_TEST);
- }
-}
-
-function getIGLStencilFunc(compare: ICompareFunction)
+export function getIGLStencilFunc(compare: ICompareFunction)
{
const stencilFunc: IGLStencilFunc = compareMap[compare];
@@ -59,7 +18,7 @@ const compareMap: { [key: string]: IGLStencilFunc } = {
"always": "ALWAYS",
};
-function getIGLStencilOp(stencilOperation?: IStencilOperation)
+export function getIGLStencilOp(stencilOperation?: IStencilOperation)
{
const glStencilOp: IGLStencilOp = stencilOperationMap[stencilOperation];
diff --git a/src/runs/runTexture.ts b/src/runs/runTexture.ts
deleted file mode 100644
index 9b8cb05..0000000
--- a/src/runs/runTexture.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { getGLTexture } from "../caches/getGLTexture";
-import { getIGLTextureTarget } from "../caches/getIGLTextureTarget";
-import { IGLSamplerTexture } from "../data/IGLSamplerTexture";
-import { IUniformItemInfo } from "../data/IGLUniformInfo";
-import { runSampler } from "./runSampler";
-
-export function runSamplerTexture(gl: WebGLRenderingContext, uniformInfo: IUniformItemInfo, samplerTexture: IGLSamplerTexture)
-{
- const { texture, sampler } = samplerTexture;
- const { location, textureID } = uniformInfo;
-
- const textureTarget = getIGLTextureTarget(texture.dimension);
-
- // 设置纹理所在采样编号
- gl.uniform1i(location, textureID);
- //
- const webGLTexture = getGLTexture(gl, texture);
- gl.activeTexture(gl[`TEXTURE${textureID}`]);
- // 绑定纹理
- gl.bindTexture(gl[textureTarget], webGLTexture);
-
- // 运行采样器
- runSampler(gl, textureTarget, webGLTexture, sampler, textureID);
-
- return webGLTexture;
-}
diff --git a/src/runs/runTransformFeedback.ts b/src/runs/runTransformFeedback.ts
deleted file mode 100644
index 214704f..0000000
--- a/src/runs/runTransformFeedback.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-import { getGLTransformFeedback } from "../caches/getGLTransformFeedback";
-import { IGLDrawMode } from "../caches/getIGLDrawMode";
-import { IGLTransformFeedback } from "../data/IGLTransformFeedback";
-
-export function runTransformFeedback(gl: WebGLRenderingContext, transformFeedback: IGLTransformFeedback, topology: IGLDrawMode)
-{
- if (gl instanceof WebGL2RenderingContext)
- {
- if (transformFeedback)
- {
- const webGLTransformFeedback = getGLTransformFeedback(gl, transformFeedback);
-
- gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, webGLTransformFeedback);
-
- gl.beginTransformFeedback(gl[topology]);
- }
- else
- {
- gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
- }
- }
- else if (transformFeedback)
- {
- console.log(`WebGL1 不支持顶点着色器回写数据功能!`);
- }
-}
-
-export function endTransformFeedback(gl: WebGLRenderingContext, transformFeedback: IGLTransformFeedback)
-{
- //
- if (transformFeedback)
- {
- if (gl instanceof WebGL2RenderingContext)
- {
- gl.endTransformFeedback();
- gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
- }
- }
-}
diff --git a/src/runs/runUniforms.ts b/src/runs/runUniforms.ts
deleted file mode 100644
index ac1182e..0000000
--- a/src/runs/runUniforms.ts
+++ /dev/null
@@ -1,153 +0,0 @@
-import { IRenderPipeline } from "@feng3d/render-api";
-import { getGLBuffer } from "../caches/getGLBuffer";
-import { getGLProgram } from "../caches/getGLProgram";
-import { IGLUniformBufferType } from "../const/IGLUniformType";
-import { IGLBuffer } from "../data/IGLBuffer";
-import { IGLSamplerTexture } from "../data/IGLSamplerTexture";
-import { IUniformItemInfo } from "../data/IGLUniformInfo";
-import { IGLUniforms } from "../data/IGLUniforms";
-import { LazyObject, lazy } from "../types";
-import { runSamplerTexture } from "./runTexture";
-
-/**
- * 激活常量
- */
-export function runUniforms(gl: WebGLRenderingContext, pipeline: IRenderPipeline, uniforms: LazyObject)
-{
- const webGLProgram = getGLProgram(gl, pipeline);
-
- webGLProgram.uniforms.forEach((uniformInfo) =>
- {
- const { name, type, items, isTexture, inBlock } = uniformInfo;
- if (inBlock) return;
-
- items.forEach((v) =>
- {
- const { paths } = v;
-
- let uniformData = lazy.getValue(uniforms[paths[0]], uniforms);
- for (let i = 1; i < paths.length; i++)
- {
- uniformData = uniformData[paths[i]];
- }
- if (uniformData === undefined)
- {
- console.error(`沒有找到Uniform ${name} 數據!`);
- }
-
- if (isTexture)
- {
- runSamplerTexture(gl, v, uniformData as IGLSamplerTexture);
- }
- else
- {
- runUniform(gl, type as IGLUniformBufferType, v, uniformData);
- }
- });
- });
-
- if (gl instanceof WebGL2RenderingContext)
- {
- webGLProgram.uniformBlocks.forEach((uniformBlock) =>
- {
- const { name, index } = uniformBlock;
- const uniformData = lazy.getValue(uniforms[name], uniforms);
-
- //
- const webGLBuffer = getGLBuffer(gl, uniformData as IGLBuffer);
- gl.bindBufferBase(gl.UNIFORM_BUFFER, index, webGLBuffer);
- });
- }
-}
-
-/**
- * 设置环境Uniform数据
- */
-function runUniform(gl: WebGLRenderingContext, type: IGLUniformBufferType, uniformInfo: IUniformItemInfo, data: any)
-{
- const location = uniformInfo.location;
- switch (type)
- {
- case "BOOL":
- case "INT":
- // gl.uniform1i(location, data);
- gl.uniform1iv(location, [data]);
- break;
- case "BOOL_VEC2":
- case "INT_VEC2":
- // gl.uniform2i(location, data[0], data[1]);
- gl.uniform2iv(location, data);
- break;
- case "BOOL_VEC3":
- case "INT_VEC3":
- // gl.uniform3i(location, data[0], data[1], data[2]);
- gl.uniform3iv(location, data);
- break;
- case "BOOL_VEC4":
- case "INT_VEC4":
- // gl.uniform4i(location, data[0], data[1], data[2], data[3]);
- gl.uniform4iv(location, data);
- break;
- case "FLOAT":
- // gl.uniform1f(location, data);
- gl.uniform1fv(location, [data]);
- break;
- case "FLOAT_VEC2":
- // gl.uniform2f(location, data[0], data[1]);
- gl.uniform2fv(location, data);
- break;
- case "FLOAT_VEC3":
- // gl.uniform3f(location, data[0], data[1], data[2]);
- gl.uniform3fv(location, data);
- break;
- case "FLOAT_VEC4":
- // gl.uniform4f(location, data[0], data[1], data[2], data[3]);
- gl.uniform4fv(location, data);
- break;
- case "FLOAT_MAT2":
- gl.uniformMatrix2fv(location, false, data);
- break;
- case "FLOAT_MAT3":
- gl.uniformMatrix3fv(location, false, data);
- break;
- case "FLOAT_MAT4":
- gl.uniformMatrix4fv(location, false, data);
- break;
- case "UNSIGNED_INT":
- (gl as any as WebGL2RenderingContext).uniform1ui(location, data);
- (gl as any as WebGL2RenderingContext).uniform1uiv(location, [data]);
- break;
- case "UNSIGNED_INT_VEC2":
- // (gl as any as WebGL2RenderingContext).uniform2ui(location, data[0], data[1]);
- (gl as any as WebGL2RenderingContext).uniform2uiv(location, data);
- break;
- case "UNSIGNED_INT_VEC3":
- // (gl as any as WebGL2RenderingContext).uniform3ui(location, data[0], data[1], data[2]);
- (gl as any as WebGL2RenderingContext).uniform3uiv(location, data);
- break;
- case "UNSIGNED_INT_VEC4":
- // (gl as any as WebGL2RenderingContext).uniform4ui(location, data[0], data[1], data[2], data[3]);
- (gl as any as WebGL2RenderingContext).uniform4uiv(location, data);
- break;
- case "FLOAT_MAT2x3":
- (gl as any as WebGL2RenderingContext).uniformMatrix2x3fv(location, false, data);
- break;
- case "FLOAT_MAT2x4":
- (gl as any as WebGL2RenderingContext).uniformMatrix2x4fv(location, false, data);
- break;
- case "FLOAT_MAT3x2":
- (gl as any as WebGL2RenderingContext).uniformMatrix3x2fv(location, false, data);
- break;
- case "FLOAT_MAT3x4":
- (gl as any as WebGL2RenderingContext).uniformMatrix3x4fv(location, false, data);
- break;
- case "FLOAT_MAT4x2":
- (gl as any as WebGL2RenderingContext).uniformMatrix4x2fv(location, false, data);
- break;
- case "FLOAT_MAT4x3":
- (gl as any as WebGL2RenderingContext).uniformMatrix4x3fv(location, false, data);
- break;
- default:
- console.error(`无法识别的uniform类型 ${uniformInfo.paths} ${type}`);
- }
-}
diff --git a/src/runs/runVertexArray.ts b/src/runs/runVertexArray.ts
deleted file mode 100644
index bfaa12f..0000000
--- a/src/runs/runVertexArray.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-import { IIndicesDataTypes, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
-import { getGLProgram } from "../caches/getGLProgram";
-import { ChainMap } from "../utils/ChainMap";
-import { runIndexBuffer } from "./runIndexBuffer";
-import { runVertexAttribute } from "./runVertexAttribute";
-
-declare global
-{
- interface WebGLRenderingContext
- {
- _vertexArrays: ChainMap<[IRenderPipeline, IVertexAttributes, IIndicesDataTypes], WebGLVertexArrayObject>;
- }
-}
-
-/**
- * 执行设置或者上传渲染对象的顶点以及索引数据。
- */
-export function runVertexArray(gl: WebGLRenderingContext, pipeline: IRenderPipeline, vertices: IVertexAttributes, indices: IIndicesDataTypes)
-{
- if (!vertices && !indices) return;
-
- let webGLVertexArrayObject: WebGLVertexArrayObject;
- if (gl instanceof WebGL2RenderingContext)
- {
- webGLVertexArrayObject = gl._vertexArrays.get([pipeline, vertices, indices]);
- if (webGLVertexArrayObject)
- {
- gl.bindVertexArray(webGLVertexArrayObject);
-
- return;
- }
-
- webGLVertexArrayObject = gl.createVertexArray();
- gl.bindVertexArray(webGLVertexArrayObject);
- gl._vertexArrays.set([pipeline, vertices, indices], webGLVertexArrayObject);
- }
-
- const shaderResult = getGLProgram(gl, pipeline);
-
- //
- shaderResult.attributes.forEach((activeInfo) =>
- {
- const { name, location } = activeInfo;
- // 处理 WebGL 内置属性 gl_VertexID 等
- if (location < 0) return;
-
- const attribute = vertices[name];
- if (!attribute)
- {
- console.error(`缺少顶点 ${name} 数据!`);
- }
-
- runVertexAttribute(gl, location, attribute);
- });
-
- runIndexBuffer(gl, indices);
-}
diff --git a/src/runs/runVertexAttribute.ts b/src/runs/runVertexAttribute.ts
deleted file mode 100644
index 091f99f..0000000
--- a/src/runs/runVertexAttribute.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import { IVertexAttribute, IVertexFormat } from "@feng3d/render-api";
-import { getGLBuffer } from "../caches/getGLBuffer";
-import { getIGLVertexBuffer } from "./getIGLBuffer";
-import { getIGLVertexFormat } from "../utils/getIVertexFormat";
-
-export function runVertexAttribute(gl: WebGLRenderingContext, location: number, attribute: IVertexAttribute)
-{
- const { stepMode, format } = attribute;
- let { arrayStride, offset } = attribute;
-
- const glVertexFormat = getIGLVertexFormat(format);
- const { numComponents, normalized, type } = glVertexFormat;
-
- gl.enableVertexAttribArray(location);
-
- if (stepMode === "instance")
- {
- if (gl instanceof WebGL2RenderingContext)
- {
- gl.vertexAttribDivisor(location, 1);
- }
- else
- {
- const extension = gl.getExtension("ANGLE_instanced_arrays");
- extension.vertexAttribDivisorANGLE(location, 1);
- }
- }
-
- //
- arrayStride = arrayStride || 0;
- offset = offset || 0;
-
- //
- const buffer = getIGLVertexBuffer(attribute.data);
- const webGLBuffer = getGLBuffer(gl, buffer);
- gl.bindBuffer(gl.ARRAY_BUFFER, webGLBuffer);
-
- //
- if (gl instanceof WebGL2RenderingContext && (type === "INT" || type === "UNSIGNED_INT"))
- {
- gl.vertexAttribIPointer(location, numComponents, gl[type], arrayStride, offset);
- }
- else
- {
- gl.vertexAttribPointer(location, numComponents, gl[type], normalized, arrayStride, offset);
- }
-}
-
diff --git a/src/runs/runViewPort.ts b/src/runs/runViewPort.ts
deleted file mode 100644
index 1c1d6f9..0000000
--- a/src/runs/runViewPort.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { IGLViewport } from "../data/IGLViewport";
-
-export function runViewPort(gl: WebGLRenderingContext, viewport?: IGLViewport)
-{
- if (viewport)
- {
- gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
- }
- else
- {
- gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
- }
-}
--
Gitee
From b586d96ca67f62dd137a5ed9c54cf674f0f755ac Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Mon, 16 Dec 2024 23:20:11 +0800
Subject: [PATCH 123/186] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/WebGL.ts | 2 +-
src/shader/ShaderLib.ts | 1 -
src/utils/getTextureCubeMapTarget.ts | 6 +++---
src/{runs/runReadPixels.ts => utils/readPixels.ts} | 2 +-
4 files changed, 5 insertions(+), 6 deletions(-)
rename src/{runs/runReadPixels.ts => utils/readPixels.ts} (99%)
diff --git a/src/WebGL.ts b/src/WebGL.ts
index 75a28a9..adf9a7c 100644
--- a/src/WebGL.ts
+++ b/src/WebGL.ts
@@ -15,7 +15,7 @@ import { IGLReadPixels } from "./data/IGLReadPixels";
import { IGLRenderbuffer } from "./data/IGLRenderbuffer";
import { IGLSampler } from "./data/IGLSampler";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
-import { readPixels } from "./runs/runReadPixels";
+import { readPixels } from "./utils/readPixels";
/**
* WEBGL 对象。
diff --git a/src/shader/ShaderLib.ts b/src/shader/ShaderLib.ts
index 27526d1..84ba3af 100644
--- a/src/shader/ShaderLib.ts
+++ b/src/shader/ShaderLib.ts
@@ -30,7 +30,6 @@ export interface ShaderConfig
/**
* 渲染代码库
-
*/
export class ShaderLib
{
diff --git a/src/utils/getTextureCubeMapTarget.ts b/src/utils/getTextureCubeMapTarget.ts
index c1fc14e..fbdd306 100644
--- a/src/utils/getTextureCubeMapTarget.ts
+++ b/src/utils/getTextureCubeMapTarget.ts
@@ -1,13 +1,13 @@
export function getTextureCubeMapTarget(depthOrArrayLayers: number)
{
- const textureCubeMapTarget: TextureCubeMapTarget = textureCubeMapTargetMap[depthOrArrayLayers];
+ const textureCubeMapTarget: IGLTextureCubeMapTarget = textureCubeMapTargetMap[depthOrArrayLayers];
console.assert(!!textureCubeMapTarget, `CubeMap的depthOrArrayLayers值应在[0-5]之间!`);
return textureCubeMapTarget;
}
-const textureCubeMapTargetMap: TextureCubeMapTarget[] = [
+const textureCubeMapTargetMap: IGLTextureCubeMapTarget[] = [
"TEXTURE_CUBE_MAP_POSITIVE_X",
"TEXTURE_CUBE_MAP_NEGATIVE_X",
"TEXTURE_CUBE_MAP_POSITIVE_Y",
@@ -28,7 +28,7 @@ const textureCubeMapTargetMap: TextureCubeMapTarget[] = [
*
* https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texImage2D
*/
-export type TextureCubeMapTarget =
+export type IGLTextureCubeMapTarget =
| "TEXTURE_CUBE_MAP_POSITIVE_X"
| "TEXTURE_CUBE_MAP_NEGATIVE_X"
| "TEXTURE_CUBE_MAP_POSITIVE_Y"
diff --git a/src/runs/runReadPixels.ts b/src/utils/readPixels.ts
similarity index 99%
rename from src/runs/runReadPixels.ts
rename to src/utils/readPixels.ts
index e82ba1e..4be4b30 100644
--- a/src/runs/runReadPixels.ts
+++ b/src/utils/readPixels.ts
@@ -17,4 +17,4 @@ export function readPixels(gl: WebGLRenderingContext, readPixels: IGLReadPixels)
{
console.error(`WebGL1 不支持 readBuffer/readPixels !`);
}
-}
\ No newline at end of file
+}
--
Gitee
From 2174f6a0401f25b9baa70957993dea0ac2f9ddb2 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Tue, 17 Dec 2024 10:16:13 +0800
Subject: [PATCH 124/186] RunWebGL.runDrawIndexed
---
src/RunWebGL.ts | 5 +++--
src/caches/getGLBuffer.ts | 18 ------------------
src/data/IGLBuffer.ts | 7 -------
3 files changed, 3 insertions(+), 27 deletions(-)
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 96890aa..5ddf17a 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,6 +1,6 @@
import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes } from "@feng3d/render-api";
import { getFramebuffer } from "./caches/getFramebuffer";
-import { getBufferType, getGLBuffer } from "./caches/getGLBuffer";
+import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLProgram } from "./caches/getGLProgram";
import { getGLRenderOcclusionQuery } from "./caches/getGLRenderOcclusionQuery";
import { getGLSampler } from "./caches/getGLSampler";
@@ -16,6 +16,7 @@ import { IGLBuffer } from "./data/IGLBuffer";
import { IGLCopyBufferToBuffer } from "./data/IGLCopyBufferToBuffer";
import { IGLCopyTextureToTexture } from "./data/IGLCopyTextureToTexture";
import { IGLCompareFunction, IGLStencilFunc, IGLStencilOp } from "./data/IGLDepthStencilState";
+import { IGLDrawElementType } from "./data/IGLIndexBuffer";
import { IGLOcclusionQuery } from "./data/IGLOcclusionQuery";
import { IGLSampler, IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "./data/IGLSampler";
import { IGLSamplerTexture } from "./data/IGLSamplerTexture";
@@ -226,7 +227,7 @@ export class RunWebGL
private runDrawIndexed(gl: WebGLRenderingContext, drawMode: IGLDrawMode, indices: IIndicesDataTypes, drawIndexed: IDrawIndexed)
{
- const type = getBufferType(indices);
+ const type: IGLDrawElementType = indices.BYTES_PER_ELEMENT === 2 ? "UNSIGNED_SHORT" : "UNSIGNED_INT";
//
const indexCount = drawIndexed.indexCount;
const firstIndex = drawIndexed.firstIndex || 0;
diff --git a/src/caches/getGLBuffer.ts b/src/caches/getGLBuffer.ts
index 1c2e2f5..e7124f9 100644
--- a/src/caches/getGLBuffer.ts
+++ b/src/caches/getGLBuffer.ts
@@ -1,7 +1,5 @@
-import { IVertexDataTypes } from "@feng3d/render-api";
import { watcher } from "@feng3d/watcher";
import { IGLBuffer } from "../data/IGLBuffer";
-import { IGLVertexAttributeTypes } from "../utils/getIVertexFormat";
declare global
{
@@ -106,19 +104,3 @@ export function deleteBuffer(gl: WebGLRenderingContext, buffer: IGLBuffer)
gl.deleteBuffer(webGLBuffer);
}
}
-
-export function getBufferType(data?: IVertexDataTypes)
-{
- return bufferTypeMap[data?.constructor.name];
-}
-
-const bufferTypeMap: { [key: string]: IGLVertexAttributeTypes } = {
- Float32Array: "FLOAT",
- Uint32Array: "UNSIGNED_INT",
- Int32Array: "INT",
- Uint16Array: "UNSIGNED_SHORT",
- Int16Array: "SHORT",
- Uint8Array: "UNSIGNED_BYTE",
- Int8Array: "BYTE",
- Uint8ClampedArray: "UNSIGNED_BYTE",
-};
diff --git a/src/data/IGLBuffer.ts b/src/data/IGLBuffer.ts
index 8499454..a1b5066 100644
--- a/src/data/IGLBuffer.ts
+++ b/src/data/IGLBuffer.ts
@@ -9,13 +9,6 @@ export interface IGLBuffer
{
target: GLBufferTarget;
- /**
- * 被bindBuffer多次绑定到不同位置时,需要填入多个值。
- *
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/bindBuffer)
- */
- targets?: GLBufferTarget[];
-
/**
* 缓冲区数据。
*/
--
Gitee
From ca167d01b6964e3d4bca3b3703932ea1c90893c7 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 18 Dec 2024 10:50:03 +0800
Subject: [PATCH 125/186] IRenderObject.viewport
---
.../src/WebGL2Samples/draw_range_arrays.ts | 4 +--
examples/src/WebGL2Samples/fbo_blit.ts | 12 ++++----
.../WebGL2Samples/fbo_new_blend_equation.ts | 12 ++++----
examples/src/WebGL2Samples/fbo_read_pixels.ts | 4 +--
.../WebGL2Samples/fbo_rtt_texture_array.ts | 4 +--
examples/src/WebGL2Samples/glsl_centroid.ts | 10 +++----
.../glsl_flat_smooth_interpolators.ts | 10 +++----
examples/src/WebGL2Samples/sampler_filter.ts | 6 ++--
examples/src/WebGL2Samples/sampler_wrap.ts | 2 +-
examples/src/WebGL2Samples/texture_3d.ts | 16 +++++-----
examples/src/WebGL2Samples/texture_format.ts | 8 ++---
.../src/WebGL2Samples/texture_immutable.ts | 4 +--
examples/src/WebGL2Samples/texture_lod.ts | 2 +-
examples/src/WebGL2Samples/texture_offset.ts | 4 +--
.../transform_feedback_instanced.ts | 6 ++--
.../transform_feedback_separated_2.ts | 16 +++++-----
src/RunWebGL.ts | 16 +++++-----
src/data/IGLRenderPass.ts | 2 --
src/data/IGLViewport.ts | 30 -------------------
src/index.ts | 1 -
20 files changed, 64 insertions(+), 105 deletions(-)
delete mode 100644 src/data/IGLViewport.ts
diff --git a/examples/src/WebGL2Samples/draw_range_arrays.ts b/examples/src/WebGL2Samples/draw_range_arrays.ts
index 809cdfe..5cf681b 100644
--- a/examples/src/WebGL2Samples/draw_range_arrays.ts
+++ b/examples/src/WebGL2Samples/draw_range_arrays.ts
@@ -57,14 +57,14 @@ const rp: IRenderPass = {
}],
},
renderObjects: [
- { __type: "Viewport", x: 0, y: 0, width: canvas.width / 2, height: canvas.height },
{
...renderObject,
+ viewport: { x: 0, y: 0, width: canvas.width / 2, height: canvas.height },
drawVertex: { firstVertex: 0, vertexCount: vertexCount / 2 },
},
- { __type: "Viewport", x: canvas.width / 2, y: 0, width: canvas.width / 2, height: canvas.height },
{
...renderObject,
+ viewport: { x: canvas.width / 2, y: 0, width: canvas.width / 2, height: canvas.height },
drawVertex: { firstVertex: 6, vertexCount: vertexCount / 2 },
},
],
diff --git a/examples/src/WebGL2Samples/fbo_blit.ts b/examples/src/WebGL2Samples/fbo_blit.ts
index 3f91c35..33dbcf3 100644
--- a/examples/src/WebGL2Samples/fbo_blit.ts
+++ b/examples/src/WebGL2Samples/fbo_blit.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, ITextureView, IVertexAttributes } from "@feng3d/render-api";
-import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLSampler, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, ITextureView, IVertexAttributes, IViewport } from "@feng3d/render-api";
+import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -79,8 +79,8 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
vertices,
};
- const viewport: IGLViewport = { __type: "Viewport", x: 0, y: 0, width: FRAMEBUFFER_SIZE.x, height: FRAMEBUFFER_SIZE.y };
const renderObject: IRenderObject = {
+ viewport: { x: 0, y: 0, width: FRAMEBUFFER_SIZE.x, height: FRAMEBUFFER_SIZE.y },
pipeline: program,
vertices: vertexArray.vertices,
uniforms: {
@@ -103,7 +103,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
clearValue: [0.3, 0.3, 0.3, 1.0]
}]
},
- renderObjects: [viewport, renderObject],
+ renderObjects: [renderObject],
};
const framebufferResolve: IRenderPassDescriptor = {
@@ -148,8 +148,8 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
blitFramebuffers,
};
- const viewport2: IGLViewport = { __type: "Viewport", x: 0, y: 0, width: canvas.width, height: canvas.height };
const renderObject2: IRenderObject = {
+ viewport: { x: 0, y: 0, width: canvas.width, height: canvas.height },
vertices: vertexArray.vertices,
uniforms: {
MVP: new Float32Array([
@@ -171,7 +171,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
loadOp: "clear",
}],
},
- renderObjects: [viewport2, renderObject2]
+ renderObjects: [renderObject2]
};
// 执行
diff --git a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
index 52826a1..1d97117 100644
--- a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
+++ b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IViewport } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -134,7 +134,7 @@ function render()
for (let i = 0; i < Corners.MAX; ++i)
{
- const viewport0: IGLViewport = { __type: "Viewport", x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w };
+ const viewport0: IViewport = { x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w };
if (i === Corners.TOP_LEFT)
{
@@ -143,17 +143,17 @@ function render()
else if (i === Corners.TOP_RIGHT)
{
renderObjects.push(
- viewport0,
{
...renderObject,
+ viewport: viewport0,
});
}
else if (i === Corners.BOTTOM_RIGHT)
{
renderObjects.push(
- viewport0,
{
...renderObject,
+ viewport: viewport0,
pipeline: {
...program, fragment: {
...program.fragment,
@@ -172,9 +172,9 @@ function render()
else if (i === Corners.BOTTOM_LEFT)
{
renderObjects.push(
- viewport0,
{
...renderObject,
+ viewport: viewport0,
pipeline: {
...program, fragment: {
...program.fragment,
diff --git a/examples/src/WebGL2Samples/fbo_read_pixels.ts b/examples/src/WebGL2Samples/fbo_read_pixels.ts
index ada1f72..4c541ef 100644
--- a/examples/src/WebGL2Samples/fbo_read_pixels.ts
+++ b/examples/src/WebGL2Samples/fbo_read_pixels.ts
@@ -131,8 +131,8 @@ const matrix = new Float32Array([
const rp1: IRenderPass = {
descriptor: frameBuffer,
renderObjects: [
- { __type: "Viewport", x: 0, y: 0, width: w, height: h },
{
+ viewport: { x: 0, y: 0, width: w, height: h },
pipeline: multipleOutputProgram,
uniforms: { mvp: matrix },
vertices: multipleOutputVertexArray.vertices,
@@ -161,9 +161,9 @@ const ro: IRenderObject = {
for (let i = 0; i < Textures.MAX; ++i)
{
renderObjects.push(
- { __type: "Viewport", x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
{
...ro,
+ viewport: { x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
uniforms: { ...ro.uniforms, layer: i },
});
}
diff --git a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
index a89e620..9aabf49 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
@@ -133,8 +133,8 @@ const matrix = new Float32Array([
const renderPass1: IRenderPass = {
descriptor: frameBuffer,
renderObjects: [
- { __type: "Viewport", x: 0, y: 0, width: w, height: h },
{
+ viewport: { x: 0, y: 0, width: w, height: h },
pipeline: multipleOutputProgram,
uniforms: { mvp: matrix },
vertices: multipleOutputVertexArray.vertices,
@@ -162,8 +162,8 @@ const renderObject: IRenderObject = {
for (let i = 0; i < Textures.MAX; ++i)
{
renderObjects.push(
- { __type: "Viewport", x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
{
+ viewport: { x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
...renderObject,
uniforms: { ...renderObject.uniforms, layer: i },
drawVertex: { vertexCount: 6 },
diff --git a/examples/src/WebGL2Samples/glsl_centroid.ts b/examples/src/WebGL2Samples/glsl_centroid.ts
index b30b554..5c1f076 100644
--- a/examples/src/WebGL2Samples/glsl_centroid.ts
+++ b/examples/src/WebGL2Samples/glsl_centroid.ts
@@ -1,5 +1,5 @@
-import { IPassEncoder, IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IPassEncoder, IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IViewport } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -24,10 +24,9 @@ const VIEWPORTS = {
MAX: 2
};
-const viewport: IGLViewport[] = new Array(VIEWPORTS.MAX);
+const viewport: IViewport[] = new Array(VIEWPORTS.MAX);
viewport[VIEWPORTS.LEFT] = {
- __type: "Viewport",
x: 0,
y: canvasSize.y - canvasSize.x / 2 - 50,
width: canvasSize.x / 2,
@@ -35,7 +34,6 @@ viewport[VIEWPORTS.LEFT] = {
};
viewport[VIEWPORTS.RIGHT] = {
- __type: "Viewport",
x: canvasSize.x / 2,
y: canvasSize.y - canvasSize.x / 2 - 50,
width: canvasSize.x / 2,
@@ -193,9 +191,9 @@ mat4.scale(mvp, IDENTITY, scaleVector3);
for (let i = 0; i < VIEWPORTS.MAX; ++i)
{
renderObjects.push(
- viewport[i],
{
...ro,
+ viewport: viewport[i],
uniforms: {
MVP: mvp,
diffuse: { texture: textures[i], sampler: samplers[i] },
diff --git a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
index 6ede06d..c345e47 100644
--- a/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
+++ b/examples/src/WebGL2Samples/glsl_flat_smooth_interpolators.ts
@@ -1,5 +1,5 @@
-import { IIndicesDataTypes, IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
-import { getIVertexFormat, IGLCanvasContext, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes, IViewport } from "@feng3d/render-api";
+import { getIVertexFormat, IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
import { getShaderSource } from "./utility";
@@ -25,10 +25,9 @@ const VIEWPORTS = {
MAX: 2
};
-const viewport: IGLViewport[] = new Array(VIEWPORTS.MAX);
+const viewport: IViewport[] = new Array(VIEWPORTS.MAX);
viewport[VIEWPORTS.LEFT] = {
- __type: "Viewport",
x: 0,
y: canvasSize.y - canvasSize.x / 2 - 50,
width: canvasSize.x / 2,
@@ -36,7 +35,6 @@ viewport[VIEWPORTS.LEFT] = {
};
viewport[VIEWPORTS.RIGHT] = {
- __type: "Viewport",
x: canvasSize.x / 2,
y: canvasSize.y - canvasSize.x / 2 - 50,
width: canvasSize.x / 2,
@@ -170,8 +168,8 @@ glTFLoader.loadGLTF(gltfUrl, function (glTF)
for (i = 0; i < VIEWPORTS.MAX; ++i)
{
renderObjects.push(
- viewport[i],
{
+ viewport: viewport[i],
pipeline: programs[i],
vertices: vertexArray.vertices,
indices,
diff --git a/examples/src/WebGL2Samples/sampler_filter.ts b/examples/src/WebGL2Samples/sampler_filter.ts
index f4c9cc4..ae51f13 100644
--- a/examples/src/WebGL2Samples/sampler_filter.ts
+++ b/examples/src/WebGL2Samples/sampler_filter.ts
@@ -87,8 +87,8 @@ const texcoords = new Float32Array([
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, format:"float32x2" },
- textureCoordinates: { data: texcoords, format:"float32x2" },
+ position: { data: positions, format: "float32x2" },
+ textureCoordinates: { data: texcoords, format: "float32x2" },
}
};
@@ -155,9 +155,9 @@ function render()
for (let i = 0; i < Corners.MAX; ++i)
{
renderObjects.push(
- { __type: "Viewport", x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
{
...ro,
+ viewport: { x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
uniforms: {
...ro.uniforms,
diffuse: {
diff --git a/examples/src/WebGL2Samples/sampler_wrap.ts b/examples/src/WebGL2Samples/sampler_wrap.ts
index a771036..6ffa101 100644
--- a/examples/src/WebGL2Samples/sampler_wrap.ts
+++ b/examples/src/WebGL2Samples/sampler_wrap.ts
@@ -151,9 +151,9 @@ function render()
for (let i = 0; i < Corners.MAX; ++i)
{
renderObjects.push(
- { __type: "Viewport", x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
{
...ro,
+ viewport: { x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
uniforms: {
...ro.uniforms,
diffuse: { texture, sampler: samplers[i] },
diff --git a/examples/src/WebGL2Samples/texture_3d.ts b/examples/src/WebGL2Samples/texture_3d.ts
index 4799c02..980b9a4 100644
--- a/examples/src/WebGL2Samples/texture_3d.ts
+++ b/examples/src/WebGL2Samples/texture_3d.ts
@@ -1,4 +1,4 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IRenderObject, IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource } from "./utility";
@@ -165,15 +165,13 @@ import { getShaderSource } from "./utility";
drawVertex: { vertexCount: 6 }
};
- const renderPassObjects: IRenderPassObject[] = [];
- const renderObjects: IRenderObject[] = [];
+ const renderPassObjects: IRenderObject[] = [];
for (let i = 0; i < Corners.MAX; ++i)
{
- renderPassObjects.push(
- { __type: "Viewport", x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
- ro,
- );
- renderObjects.push(ro);
+ renderPassObjects.push({
+ ...ro,
+ viewport: { x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
+ });
}
const rp: IRenderPass = {
@@ -195,7 +193,7 @@ import { getShaderSource } from "./utility";
for (let i = 0; i < Corners.MAX; ++i)
{
- renderObjects[i].uniforms.orientation = matrices[i];
+ renderPassObjects[i].uniforms.orientation = matrices[i];
}
webgl.submit({ commandEncoders: [{ passEncoders: [rp] }] });
diff --git a/examples/src/WebGL2Samples/texture_format.ts b/examples/src/WebGL2Samples/texture_format.ts
index 1be3901..ddf635c 100644
--- a/examples/src/WebGL2Samples/texture_format.ts
+++ b/examples/src/WebGL2Samples/texture_format.ts
@@ -75,8 +75,8 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init VertexArray
const vertexArray: { vertices?: IVertexAttributes } = {
vertices: {
- position: { data: positions, format:"float32x2" },
- texcoord: { data: texCoords, format:"float32x2" },
+ position: { data: positions, format: "float32x2" },
+ texcoord: { data: texCoords, format: "float32x2" },
}
};
@@ -172,8 +172,8 @@ import { getShaderSource, loadImage } from "./utility";
for (i = 0; i < TextureTypes.RGB8UI; ++i)
{
renderObjects.push(
- { __type: "Viewport", x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
{
+ viewport: { x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
vertices: vertexArray.vertices,
pipeline: programNormalized,
uniforms: {
@@ -188,8 +188,8 @@ import { getShaderSource, loadImage } from "./utility";
for (i = TextureTypes.RGB8UI; i < TextureTypes.MAX; ++i)
{
renderObjects.push(
- { __type: "Viewport", x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
{
+ viewport: { x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
vertices: vertexArray.vertices,
pipeline: programUint,
uniforms: {
diff --git a/examples/src/WebGL2Samples/texture_immutable.ts b/examples/src/WebGL2Samples/texture_immutable.ts
index 0043c56..f02f0d6 100644
--- a/examples/src/WebGL2Samples/texture_immutable.ts
+++ b/examples/src/WebGL2Samples/texture_immutable.ts
@@ -115,8 +115,8 @@ import { getShaderSource, loadImage } from "./utility";
};
renderObjects.push(
- { __type: "Viewport", x: viewports[Corners.LEFT].x, y: viewports[Corners.LEFT].y, width: viewports[Corners.LEFT].z, height: viewports[Corners.LEFT].w },
{
+ viewport: { x: viewports[Corners.LEFT].x, y: viewports[Corners.LEFT].y, width: viewports[Corners.LEFT].z, height: viewports[Corners.LEFT].w },
...ro,
pipeline: program,
uniforms: {
@@ -127,8 +127,8 @@ import { getShaderSource, loadImage } from "./utility";
// Immutable 3D texture
renderObjects.push(
- { __type: "Viewport", x: viewports[Corners.RIGHT].x, y: viewports[Corners.RIGHT].y, width: viewports[Corners.RIGHT].z, height: viewports[Corners.RIGHT].w },
{
+ viewport: { x: viewports[Corners.RIGHT].x, y: viewports[Corners.RIGHT].y, width: viewports[Corners.RIGHT].z, height: viewports[Corners.RIGHT].w },
...ro,
pipeline: program3D,
uniforms: {
diff --git a/examples/src/WebGL2Samples/texture_lod.ts b/examples/src/WebGL2Samples/texture_lod.ts
index beeb780..e5e2c35 100644
--- a/examples/src/WebGL2Samples/texture_lod.ts
+++ b/examples/src/WebGL2Samples/texture_lod.ts
@@ -208,8 +208,8 @@ import { getShaderSource, loadImage } from "./utility";
for (let i = 0; i < Corners.MAX; ++i)
{
renderObjects.push(
- { __type: "Viewport", x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
{
+ viewport: { x: viewport[i].x, y: viewport[i].y, width: viewport[i].z, height: viewport[i].w },
...ro,
uniforms: {
mvp: matrix,
diff --git a/examples/src/WebGL2Samples/texture_offset.ts b/examples/src/WebGL2Samples/texture_offset.ts
index 83cec49..238c6d0 100644
--- a/examples/src/WebGL2Samples/texture_offset.ts
+++ b/examples/src/WebGL2Samples/texture_offset.ts
@@ -100,8 +100,8 @@ import { getShaderSource, loadImage } from "./utility";
// No offset
renderObjects.push(
- { __type: "Viewport", x: viewports[Corners.RIGHT].x, y: viewports[Corners.RIGHT].y, width: viewports[Corners.RIGHT].z, height: viewports[Corners.RIGHT].w },
{
+ viewport: { x: viewports[Corners.RIGHT].x, y: viewports[Corners.RIGHT].y, width: viewports[Corners.RIGHT].z, height: viewports[Corners.RIGHT].w },
vertices: vertexArray.vertices,
pipeline: programBicubic,
uniforms: {
@@ -115,8 +115,8 @@ import { getShaderSource, loadImage } from "./utility";
const offset = new Int32Array([100, -80]);
renderObjects.push(
- { __type: "Viewport", x: viewports[Corners.LEFT].x, y: viewports[Corners.LEFT].y, width: viewports[Corners.LEFT].z, height: viewports[Corners.LEFT].w },
{
+ viewport: { x: viewports[Corners.LEFT].x, y: viewports[Corners.LEFT].y, width: viewports[Corners.LEFT].z, height: viewports[Corners.LEFT].w },
vertices: vertexArray.vertices,
pipeline: programOffsetBicubic,
uniforms: {
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index d919856..e1c5955 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -1,5 +1,5 @@
import { IIndicesDataTypes, IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLTransformFeedback, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLTransformFeedback, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -114,8 +114,8 @@ import { getShaderSource } from "./utility";
drawVertex: { vertexCount: NUM_INSTANCES },
};
- const viewport: IGLViewport = { __type: "Viewport", x: 0, y: 0, width: canvas.width, height: canvas.height - 10 };
const renderRO: IRenderObject = {
+ viewport: { x: 0, y: 0, width: canvas.width, height: canvas.height - 10 },
pipeline: programs[PROGRAM_DRAW],
uniforms: {},
drawVertex: { vertexCount: 3, instanceCount: NUM_INSTANCES },
@@ -123,7 +123,7 @@ import { getShaderSource } from "./utility";
const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
- renderObjects: [transformRO, viewport, renderRO],
+ renderObjects: [transformRO, renderRO],
};
render();
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
index 614ae6c..3d92e2d 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
@@ -1,5 +1,5 @@
import { IIndicesDataTypes, IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLTransformFeedback, IGLViewport, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, IGLTransformFeedback, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
@@ -82,11 +82,11 @@ import { getShaderSource } from "./utility";
particleVAOs[i] = {
vertices: {
- a_position: { data: particleVBOs[i][POSITION_LOCATION], format:"float32x2" },
- a_velocity: { data: particleVBOs[i][VELOCITY_LOCATION], format:"float32x2" },
- a_spawntime: { data: particleVBOs[i][SPAWNTIME_LOCATION], format:"float32" },
- a_lifetime: { data: particleVBOs[i][LIFETIME_LOCATION], format:"float32" },
- a_ID: { data: particleVBOs[i][ID_LOCATION], format:"float32" },
+ a_position: { data: particleVBOs[i][POSITION_LOCATION], format: "float32x2" },
+ a_velocity: { data: particleVBOs[i][VELOCITY_LOCATION], format: "float32x2" },
+ a_spawntime: { data: particleVBOs[i][SPAWNTIME_LOCATION], format: "float32" },
+ a_lifetime: { data: particleVBOs[i][LIFETIME_LOCATION], format: "float32" },
+ a_ID: { data: particleVBOs[i][ID_LOCATION], format: "float32" },
}
};
@@ -121,8 +121,8 @@ import { getShaderSource } from "./utility";
return program;
}
- const viewport: IGLViewport = { __type: "Viewport", x: 0, y: 0, width: canvas.width, height: canvas.height - 10 };
const ro: IRenderObject = {
+ viewport: { x: 0, y: 0, width: canvas.width, height: canvas.height - 10 },
pipeline: program,
uniforms: {
u_color: [0.0, 1.0, 1.0, 1.0],
@@ -133,7 +133,7 @@ import { getShaderSource } from "./utility";
const rp: IRenderPass = {
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
- renderObjects: [viewport, ro],
+ renderObjects: [ro],
};
function render()
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 5ddf17a..9ccb5e7 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,4 +1,5 @@
-import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport } from "@feng3d/render-api";
+
import { getFramebuffer } from "./caches/getFramebuffer";
import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLProgram } from "./caches/getGLProgram";
@@ -25,7 +26,6 @@ import { IGLTextureTarget } from "./data/IGLTexture";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
import { IUniformItemInfo } from "./data/IGLUniformInfo";
import { IGLUniforms } from "./data/IGLUniforms";
-import { IGLViewport } from "./data/IGLViewport";
import { getGLTexture } from "./internal";
import { getIGLIndexBuffer, getIGLVertexBuffer } from "./runs/getIGLBuffer";
import { getIGLBlendEquation, getIGLBlendFactor, IGLBlendEquation, IGLBlendFactor } from "./runs/runColorTargetStates";
@@ -166,11 +166,7 @@ export class RunWebGL
{
renderObjects?.forEach((renderObject) =>
{
- if (renderObject.__type === "Viewport")
- {
- this.runViewPort(gl, renderObject);
- }
- else if (renderObject.__type === "ScissorRect")
+ if (renderObject.__type === "ScissorRect")
{
this.runScissor(gl, renderObject);
}
@@ -187,11 +183,13 @@ export class RunWebGL
private runRenderObject(gl: WebGLRenderingContext, renderObject: IRenderObject)
{
- const { pipeline, vertices, indices, uniforms, transformFeedback, drawIndexed, drawVertex } = renderObject;
+ const { viewport, pipeline, vertices, indices, uniforms, transformFeedback, drawIndexed, drawVertex } = renderObject;
const topology = pipeline.primitive?.topology || "triangle-list";
const drawMode = getIGLDrawMode(topology);
+ this.runViewPort(gl, viewport);
+
this.runRenderPipeline(gl, pipeline);
this.runTransformFeedback(gl, transformFeedback, drawMode);
@@ -799,7 +797,7 @@ export class RunWebGL
occlusionQuery._step.end();
}
- private runViewPort(gl: WebGLRenderingContext, viewport?: IGLViewport)
+ private runViewPort(gl: WebGLRenderingContext, viewport?: IViewport)
{
if (viewport)
{
diff --git a/src/data/IGLRenderPass.ts b/src/data/IGLRenderPass.ts
index 739ab14..bfff835 100644
--- a/src/data/IGLRenderPass.ts
+++ b/src/data/IGLRenderPass.ts
@@ -1,7 +1,6 @@
import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
import { IGLOcclusionQuery } from "./IGLOcclusionQuery";
import { IGLScissorRect } from "./IGLScissorRect";
-import { IGLViewport } from "./IGLViewport";
declare module "@feng3d/render-api"
{
@@ -23,7 +22,6 @@ declare module "@feng3d/render-api"
export interface IRenderPassObjectMap
{
IGLRenderObject: IRenderObject,
- IGLViewport: IGLViewport
IGLScissorRect: IGLScissorRect
IGLOcclusionQuery: IGLOcclusionQuery
}
diff --git a/src/data/IGLViewport.ts b/src/data/IGLViewport.ts
deleted file mode 100644
index ff3f6cf..0000000
--- a/src/data/IGLViewport.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * 视窗。
- */
-export interface IGLViewport
-{
- /**
- * 数据类型。
- */
- readonly __type: "Viewport";
-
- /**
- * 视窗X轴最小值(像素)。
- */
- x: number,
-
- /**
- * 视窗Y轴最小值(像素)。
- */
- y: number,
-
- /**
- * 视窗宽度(像素)。
- */
- width: number,
-
- /**
- * 视窗高度(像素)。
- */
- height: number,
-}
diff --git a/src/index.ts b/src/index.ts
index f56ae1d..2f48508 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -20,7 +20,6 @@ export * from "./data/IGLTexture";
export * from "./data/IGLTexturePixelStore";
export * from "./data/IGLTransformFeedback";
export * from "./data/IGLUniforms";
-export * from "./data/IGLViewport";
export * from "./runs/getIGLBuffer";
export * from "./runs/runColorTargetStates";
--
Gitee
From ccc4a0db63218d62f046937e8f4f6772956e58ec Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 18 Dec 2024 16:51:30 +0800
Subject: [PATCH 126/186] IRenderObject.scissorRect
---
src/RunWebGL.ts | 15 ++++++--------
src/data/IGLRenderObject.ts | 14 +++++++++++++
src/data/IGLRenderPass.ts | 2 --
src/data/IGLScissorRect.ts | 39 -------------------------------------
src/index.ts | 1 -
5 files changed, 20 insertions(+), 51 deletions(-)
delete mode 100644 src/data/IGLScissorRect.ts
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 9ccb5e7..66c955d 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,4 +1,4 @@
-import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, IScissorRect, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport } from "@feng3d/render-api";
import { getFramebuffer } from "./caches/getFramebuffer";
import { getGLBuffer } from "./caches/getGLBuffer";
@@ -21,7 +21,6 @@ import { IGLDrawElementType } from "./data/IGLIndexBuffer";
import { IGLOcclusionQuery } from "./data/IGLOcclusionQuery";
import { IGLSampler, IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "./data/IGLSampler";
import { IGLSamplerTexture } from "./data/IGLSamplerTexture";
-import { IGLScissorRect } from "./data/IGLScissorRect";
import { IGLTextureTarget } from "./data/IGLTexture";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
import { IUniformItemInfo } from "./data/IGLUniformInfo";
@@ -166,11 +165,7 @@ export class RunWebGL
{
renderObjects?.forEach((renderObject) =>
{
- if (renderObject.__type === "ScissorRect")
- {
- this.runScissor(gl, renderObject);
- }
- else if (renderObject.__type === "OcclusionQuery")
+ if (renderObject.__type === "OcclusionQuery")
{
this.runOcclusionQuery(gl, renderObject);
}
@@ -183,13 +178,15 @@ export class RunWebGL
private runRenderObject(gl: WebGLRenderingContext, renderObject: IRenderObject)
{
- const { viewport, pipeline, vertices, indices, uniforms, transformFeedback, drawIndexed, drawVertex } = renderObject;
+ const { viewport, scissorRect, pipeline, vertices, indices, uniforms, transformFeedback, drawIndexed, drawVertex } = renderObject;
const topology = pipeline.primitive?.topology || "triangle-list";
const drawMode = getIGLDrawMode(topology);
this.runViewPort(gl, viewport);
+ this.runScissor(gl, scissorRect);
+
this.runRenderPipeline(gl, pipeline);
this.runTransformFeedback(gl, transformFeedback, drawMode);
@@ -809,7 +806,7 @@ export class RunWebGL
}
}
- private runScissor(gl: WebGLRenderingContext, scissor?: IGLScissorRect)
+ private runScissor(gl: WebGLRenderingContext, scissor?: IScissorRect)
{
if (scissor)
{
diff --git a/src/data/IGLRenderObject.ts b/src/data/IGLRenderObject.ts
index a6713b7..0e430f0 100644
--- a/src/data/IGLRenderObject.ts
+++ b/src/data/IGLRenderObject.ts
@@ -23,4 +23,18 @@ declare module "@feng3d/render-api"
transformFeedback?: IGLTransformFeedback;
}
+ /**
+ * 剪刀盒。
+ *
+ * 设置了一个剪刀盒,它将绘图限制为一个指定的矩形。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/scissor
+ */
+ export interface IScissorRect
+ {
+ /**
+ * 数据类型。
+ */
+ readonly __type: "ScissorRect";
+ }
}
diff --git a/src/data/IGLRenderPass.ts b/src/data/IGLRenderPass.ts
index bfff835..746fa73 100644
--- a/src/data/IGLRenderPass.ts
+++ b/src/data/IGLRenderPass.ts
@@ -1,6 +1,5 @@
import { IRenderPass, IRenderPassObject } from "@feng3d/render-api";
import { IGLOcclusionQuery } from "./IGLOcclusionQuery";
-import { IGLScissorRect } from "./IGLScissorRect";
declare module "@feng3d/render-api"
{
@@ -22,7 +21,6 @@ declare module "@feng3d/render-api"
export interface IRenderPassObjectMap
{
IGLRenderObject: IRenderObject,
- IGLScissorRect: IGLScissorRect
IGLOcclusionQuery: IGLOcclusionQuery
}
}
diff --git a/src/data/IGLScissorRect.ts b/src/data/IGLScissorRect.ts
deleted file mode 100644
index 13f5267..0000000
--- a/src/data/IGLScissorRect.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 剪刀盒。
- *
- * 设置了一个剪刀盒,它将绘图限制为一个指定的矩形。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/scissor
- */
-export interface IGLScissorRect
-{
- /**
- * 数据类型。
- */
- readonly __type: "ScissorRect";
-
- /**
- * 是否开启
- */
- enable?: boolean;
-
- /**
- * 剪刀盒X轴最小值(像素)。
- */
- x: number,
-
- /**
- * 剪刀盒Y轴最小值(像素)。
- */
- y: number,
-
- /**
- * 剪刀盒宽度(像素)。
- */
- width: number,
-
- /**
- * 剪刀盒高度(像素)。
- */
- height: number,
-}
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index 2f48508..ef22e93 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -15,7 +15,6 @@ export * from "./data/IGLRenderPass";
export * from "./data/IGLRenderPipeline";
export * from "./data/IGLSampler";
export * from "./data/IGLSamplerTexture";
-export * from "./data/IGLScissorRect";
export * from "./data/IGLTexture";
export * from "./data/IGLTexturePixelStore";
export * from "./data/IGLTransformFeedback";
--
Gitee
From 6c03024202e64987c8891cb004c410102dc58f06 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 18 Dec 2024 18:09:22 +0800
Subject: [PATCH 127/186] IViewport.isYup
---
src/RunWebGL.ts | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 66c955d..b9ce433 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -798,7 +798,18 @@ export class RunWebGL
{
if (viewport)
{
- gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
+ const isYup = viewport.isYup ?? true;
+ const x = viewport.x ?? 0;
+ let y = viewport.y ?? 0;
+ const width = viewport.width ?? gl.canvas.width;
+ const height = viewport.height ?? gl.canvas.height;
+
+ if (!isYup)
+ {
+ y = gl.canvas.height - y - height;
+ }
+
+ gl.viewport(x, y, width, height);
}
else
{
--
Gitee
From 0524130c22bed7267370e939b41f35c1e3629195 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 18 Dec 2024 20:13:20 +0800
Subject: [PATCH 128/186] getGLRenderPassAttachmentSize
---
src/RunWebGL.ts | 49 ++++++++++++++--------
src/utils/getGLRenderPassAttachmentSize.ts | 45 ++++++++++++++++++++
2 files changed, 77 insertions(+), 17 deletions(-)
create mode 100644 src/utils/getGLRenderPassAttachmentSize.ts
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index b9ce433..50b6a73 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -35,6 +35,7 @@ import { ChainMap } from "./utils/ChainMap";
import { getIGLCullFace, IGLCullFace } from "./utils/getIGLCullFace";
import { getIGLFrontFace, IGLFrontFace } from "./utils/getIGLFrontFace";
import { getIGLVertexFormat } from "./utils/getIVertexFormat";
+import { getGLRenderPassAttachmentSize } from "./utils/getGLRenderPassAttachmentSize";
declare global
{
@@ -107,6 +108,9 @@ export class RunWebGL
protected runRenderPass(gl: WebGLRenderingContext, renderPass: IRenderPass)
{
+ // 获取附件尺寸
+ const attachmentSize = getGLRenderPassAttachmentSize(gl, renderPass.descriptor);
+
// 处理不被遮挡查询
const occlusionQuery = getGLRenderOcclusionQuery(gl, renderPass.renderObjects);
//
@@ -118,7 +122,7 @@ export class RunWebGL
this.runPassDescriptor(gl, passDescriptor);
- this.runRenderObjects(gl, renderPass.renderObjects);
+ this.runRenderObjects(gl, attachmentSize, renderPass.renderObjects);
this.runBlitFramebuffer(gl, blitFramebuffer);
}
@@ -126,7 +130,7 @@ export class RunWebGL
{
this.runPassDescriptor(gl, renderPass.descriptor);
- this.runRenderObjects(gl, renderPass.renderObjects);
+ this.runRenderObjects(gl, attachmentSize, renderPass.renderObjects);
}
occlusionQuery.resolve(renderPass);
@@ -161,31 +165,31 @@ export class RunWebGL
);
}
- private runRenderObjects(gl: WebGLRenderingContext, renderObjects?: readonly IRenderPassObject[])
+ private runRenderObjects(gl: WebGLRenderingContext, attachmentSize: { width: number, height: number }, renderObjects?: readonly IRenderPassObject[])
{
renderObjects?.forEach((renderObject) =>
{
if (renderObject.__type === "OcclusionQuery")
{
- this.runOcclusionQuery(gl, renderObject);
+ this.runOcclusionQuery(gl, attachmentSize, renderObject);
}
else
{
- this.runRenderObject(gl, renderObject);
+ this.runRenderObject(gl, attachmentSize, renderObject);
}
});
}
- private runRenderObject(gl: WebGLRenderingContext, renderObject: IRenderObject)
+ private runRenderObject(gl: WebGLRenderingContext, attachmentSize: { width: number, height: number }, renderObject: IRenderObject)
{
const { viewport, scissorRect, pipeline, vertices, indices, uniforms, transformFeedback, drawIndexed, drawVertex } = renderObject;
const topology = pipeline.primitive?.topology || "triangle-list";
const drawMode = getIGLDrawMode(topology);
- this.runViewPort(gl, viewport);
+ this.runViewPort(gl, attachmentSize, viewport);
- this.runScissor(gl, scissorRect);
+ this.runScissor(gl, attachmentSize, scissorRect);
this.runRenderPipeline(gl, pipeline);
@@ -779,7 +783,7 @@ export class RunWebGL
}
}
- private runOcclusionQuery(gl: WebGLRenderingContext, occlusionQuery: IGLOcclusionQuery)
+ private runOcclusionQuery(gl: WebGLRenderingContext, attachmentSize: { width: number, height: number }, occlusionQuery: IGLOcclusionQuery)
{
// 开始查询
occlusionQuery._step.begin();
@@ -787,42 +791,53 @@ export class RunWebGL
// 正常渲染对象列表
occlusionQuery.renderObjects.forEach((renderObject) =>
{
- this.runRenderObject(gl, renderObject);
+ this.runRenderObject(gl, attachmentSize, renderObject);
});
// 结束查询
occlusionQuery._step.end();
}
- private runViewPort(gl: WebGLRenderingContext, viewport?: IViewport)
+ private runViewPort(gl: WebGLRenderingContext, attachmentSize: { width: number, height: number }, viewport: IViewport)
{
if (viewport)
{
const isYup = viewport.isYup ?? true;
const x = viewport.x ?? 0;
let y = viewport.y ?? 0;
- const width = viewport.width ?? gl.canvas.width;
- const height = viewport.height ?? gl.canvas.height;
+ const width = viewport.width ?? attachmentSize.width;
+ const height = viewport.height ?? attachmentSize.height;
if (!isYup)
{
- y = gl.canvas.height - y - height;
+ y = attachmentSize.height - y - height;
}
gl.viewport(x, y, width, height);
}
else
{
- gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
+ gl.viewport(0, 0, attachmentSize.width, attachmentSize.height);
}
}
- private runScissor(gl: WebGLRenderingContext, scissor?: IScissorRect)
+ private runScissor(gl: WebGLRenderingContext, attachmentSize: { width: number, height: number }, scissor: IScissorRect)
{
if (scissor)
{
+ const isYup = scissor.isYup ?? true;
+ const x = scissor.x ?? 0;
+ let y = scissor.y ?? 0;
+ const width = scissor.width ?? attachmentSize.width;
+ const height = scissor.height ?? attachmentSize.height;
+
+ if (!isYup)
+ {
+ y = attachmentSize.height - y - height;
+ }
+
gl.enable(gl.SCISSOR_TEST);
- gl.scissor(scissor.x, scissor.y, scissor.width, scissor.height);
+ gl.scissor(x, y, width, height);
}
else
{
diff --git a/src/utils/getGLRenderPassAttachmentSize.ts b/src/utils/getGLRenderPassAttachmentSize.ts
new file mode 100644
index 0000000..2e0988c
--- /dev/null
+++ b/src/utils/getGLRenderPassAttachmentSize.ts
@@ -0,0 +1,45 @@
+import { IRenderPassDescriptor } from "@feng3d/render-api";
+
+/**
+ * 获取渲染通道附件尺寸。
+ *
+ * @param gl
+ * @param descriptor
+ */
+export function getGLRenderPassAttachmentSize(gl: WebGLRenderingContext, descriptor: IRenderPassDescriptor): { width: number; height: number; }
+{
+ if (!descriptor) return { width: gl.drawingBufferWidth, height: gl.drawingBufferHeight };
+
+ const colorAttachments = descriptor.colorAttachments;
+ if (colorAttachments)
+ {
+ for (let i = 0; i < colorAttachments.length; i++)
+ {
+ const view = colorAttachments[i].view;
+ if (view)
+ {
+ return { width: view.texture.size[0], height: view.texture.size[1] };
+ }
+ else
+ {
+ return { width: gl.drawingBufferWidth, height: gl.drawingBufferHeight };
+ }
+ }
+ }
+
+ const depthStencilAttachment = descriptor.depthStencilAttachment;
+ if (depthStencilAttachment)
+ {
+ const view = depthStencilAttachment.view;
+ if (view)
+ {
+ return { width: view.texture.size[0], height: view.texture.size[1] };
+ }
+ else
+ {
+ return { width: gl.drawingBufferWidth, height: gl.drawingBufferHeight };
+ }
+ }
+
+ return { width: gl.drawingBufferWidth, height: gl.drawingBufferHeight };
+}
\ No newline at end of file
--
Gitee
From 63862dde67fce2ee79783c6c176e16dbe7217cdd Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 18 Dec 2024 21:05:57 +0800
Subject: [PATCH 129/186] 1
---
src/utils/getGLRenderPassAttachmentSize.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/utils/getGLRenderPassAttachmentSize.ts b/src/utils/getGLRenderPassAttachmentSize.ts
index 2e0988c..94e52b1 100644
--- a/src/utils/getGLRenderPassAttachmentSize.ts
+++ b/src/utils/getGLRenderPassAttachmentSize.ts
@@ -6,7 +6,7 @@ import { IRenderPassDescriptor } from "@feng3d/render-api";
* @param gl
* @param descriptor
*/
-export function getGLRenderPassAttachmentSize(gl: WebGLRenderingContext, descriptor: IRenderPassDescriptor): { width: number; height: number; }
+export function getGLRenderPassAttachmentSize(gl: WebGLRenderingContext, descriptor: IRenderPassDescriptor): { readonly width: number; readonly height: number; }
{
if (!descriptor) return { width: gl.drawingBufferWidth, height: gl.drawingBufferHeight };
--
Gitee
From b4199e7697a0b3525f7d0381ee782ca4dbb936f6 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 18 Dec 2024 22:01:19 +0800
Subject: [PATCH 130/186] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20IGLTransformFeedba?=
=?UTF-8?q?ckPass?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/RunWebGL.ts | 3 +-
src/data/IGLRenderPipeline.ts | 2 +-
src/data/IGLTransformFeedbackPass.ts | 80 ++++++++++++++++++++++++++++
3 files changed, 83 insertions(+), 2 deletions(-)
create mode 100644 src/data/IGLTransformFeedbackPass.ts
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 50b6a73..86172d6 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -32,10 +32,10 @@ import { getIGLCompareFunction } from "./runs/runDepthState";
import { getIGLStencilFunc, getIGLStencilOp } from "./runs/runStencilState";
import { lazy, LazyObject } from "./types";
import { ChainMap } from "./utils/ChainMap";
+import { getGLRenderPassAttachmentSize } from "./utils/getGLRenderPassAttachmentSize";
import { getIGLCullFace, IGLCullFace } from "./utils/getIGLCullFace";
import { getIGLFrontFace, IGLFrontFace } from "./utils/getIGLFrontFace";
import { getIGLVertexFormat } from "./utils/getIVertexFormat";
-import { getGLRenderPassAttachmentSize } from "./utils/getGLRenderPassAttachmentSize";
declare global
{
@@ -732,6 +732,7 @@ export class RunWebGL
if (pipeline.rasterizerDiscard)
{
gl.enable(gl.RASTERIZER_DISCARD);
+ return;
}
else
{
diff --git a/src/data/IGLRenderPipeline.ts b/src/data/IGLRenderPipeline.ts
index e7d5bc2..1b2f701 100644
--- a/src/data/IGLRenderPipeline.ts
+++ b/src/data/IGLRenderPipeline.ts
@@ -32,7 +32,7 @@ export interface ITransformFeedbackVaryings
/**
* 交叉或者分离。
- */
+ */
bufferMode: "INTERLEAVED_ATTRIBS" | "SEPARATE_ATTRIBS";
}
diff --git a/src/data/IGLTransformFeedbackPass.ts b/src/data/IGLTransformFeedbackPass.ts
new file mode 100644
index 0000000..9244771
--- /dev/null
+++ b/src/data/IGLTransformFeedbackPass.ts
@@ -0,0 +1,80 @@
+import { IDrawVertex, IVertexAttributes, IVertexState } from "@feng3d/render-api";
+import { LazyObject } from "../types";
+import { ITransformFeedbackVaryings } from "./IGLRenderPipeline";
+import { IGLTransformFeedback } from "./IGLTransformFeedback";
+import { IGLUniforms } from "./IGLUniforms";
+
+declare module "@feng3d/render-api"
+{
+ export interface IPassEncoderMap
+ {
+ IGLTransformFeedbackPass: IGLTransformFeedbackPass,
+ }
+}
+
+export interface IGLTransformFeedbackPass
+{
+ /**
+ * 数据类型。
+ */
+ readonly __type: "TransformFeedbackPass";
+
+ /**
+ * 计算对象列表。
+ */
+ computeObjects: IGLTransformFeedbackObject[];
+}
+
+export interface IGLTransformFeedbackObject
+{
+ /**
+ * 渲染管线描述。
+ */
+ readonly pipeline: ITransformFeedbackPipeline;
+
+ /**
+ * 顶点属性数据映射。
+ */
+ vertices?: IVertexAttributes;
+
+ /**
+ * 根据顶点数据绘制图元。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawVertex
+ */
+ readonly drawVertex?: IDrawVertex;
+
+ /**
+ * Uniform渲染数据
+ */
+ uniforms?: LazyObject;
+
+ /**
+ * 回写顶点着色器中输出到缓冲区。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/bindTransformFeedback
+ */
+ transformFeedback?: IGLTransformFeedback;
+}
+
+export interface ITransformFeedbackPipeline
+{
+ /**
+ * 顶点着色器阶段描述。
+ */
+ readonly vertex: IVertexState;
+
+ /**
+ * 回写变量。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/transformFeedbackVaryings
+ */
+ transformFeedbackVaryings?: ITransformFeedbackVaryings;
+
+ /**
+ * 是否丢弃后续光栅化阶段。
+ *
+ * gl.RASTERIZER_DISCARD
+ */
+ rasterizerDiscard?: boolean;
+}
\ No newline at end of file
--
Gitee
From b3ed65fdb2cdff39c4e842d6b5724a7b42bb6abe Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 18 Dec 2024 22:26:45 +0800
Subject: [PATCH 131/186] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20IGLTransformFeedba?=
=?UTF-8?q?ckPass?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/RunWebGL.ts | 47 +++++++++++++++++++++++++++-
src/caches/getGLProgram.ts | 36 +++++++++++++++++++++
src/data/IGLTransformFeedbackPass.ts | 6 ++--
3 files changed, 85 insertions(+), 4 deletions(-)
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 86172d6..277b376 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -2,7 +2,7 @@ import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEnco
import { getFramebuffer } from "./caches/getFramebuffer";
import { getGLBuffer } from "./caches/getGLBuffer";
-import { getGLProgram } from "./caches/getGLProgram";
+import { getGLProgram, getGLTransformFeedbackProgram } from "./caches/getGLProgram";
import { getGLRenderOcclusionQuery } from "./caches/getGLRenderOcclusionQuery";
import { getGLSampler } from "./caches/getGLSampler";
import { getGLTransformFeedback } from "./caches/getGLTransformFeedback";
@@ -23,6 +23,7 @@ import { IGLSampler, IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap }
import { IGLSamplerTexture } from "./data/IGLSamplerTexture";
import { IGLTextureTarget } from "./data/IGLTexture";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
+import { IGLTransformFeedbackObject, IGLTransformFeedbackPass, ITransformFeedbackPipeline } from "./data/IGLTransformFeedbackPass";
import { IUniformItemInfo } from "./data/IGLUniformInfo";
import { IGLUniforms } from "./data/IGLUniforms";
import { getGLTexture } from "./internal";
@@ -87,6 +88,10 @@ export class RunWebGL
{
this.runRenderPass(gl, passEncoder);
}
+ else if (passEncoder.__type === "TransformFeedbackPass")
+ {
+ this.runTransformFeedbackPass(gl, passEncoder);
+ }
else if (passEncoder.__type === "BlitFramebuffer")
{
this.runBlitFramebuffer(gl, passEncoder);
@@ -106,6 +111,14 @@ export class RunWebGL
});
}
+ protected runTransformFeedbackPass(gl: WebGLRenderingContext, transformFeedbackPass: IGLTransformFeedbackPass)
+ {
+ transformFeedbackPass.transformFeedbackObjects.forEach((transformFeedbackObject) =>
+ {
+ this.runTransformFeedbackObject(gl, transformFeedbackObject);
+ });
+ }
+
protected runRenderPass(gl: WebGLRenderingContext, renderPass: IRenderPass)
{
// 获取附件尺寸
@@ -211,6 +224,25 @@ export class RunWebGL
this.endTransformFeedback(gl, transformFeedback);
}
+ private runTransformFeedbackObject(gl: WebGLRenderingContext, renderObject: IGLTransformFeedbackObject)
+ {
+ const { pipeline, vertices, uniforms, transformFeedback, drawVertex } = renderObject;
+
+ const drawMode = getIGLDrawMode("point-list");
+
+ this.runTransformFeedbackPipeline(gl, pipeline);
+
+ this.runTransformFeedback(gl, transformFeedback, drawMode);
+
+ this.runVertexArray(gl, pipeline, vertices, undefined);
+
+ this.runUniforms(gl, pipeline, uniforms);
+
+ this.runDrawVertex(gl, drawMode, drawVertex);
+
+ this.endTransformFeedback(gl, transformFeedback);
+ }
+
private endTransformFeedback(gl: WebGLRenderingContext, transformFeedback: IGLTransformFeedback)
{
//
@@ -617,6 +649,19 @@ export class RunWebGL
}
}
+ private runTransformFeedbackPipeline(gl: WebGLRenderingContext, renderPipeline: ITransformFeedbackPipeline)
+ {
+ const program = getGLTransformFeedbackProgram(gl, renderPipeline);
+ gl.useProgram(program);
+
+ //
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ gl.enable(gl.RASTERIZER_DISCARD);
+ return;
+ }
+ }
+
private runRenderPipeline(gl: WebGLRenderingContext, renderPipeline: IRenderPipeline)
{
this.runProgram(gl, renderPipeline);
diff --git a/src/caches/getGLProgram.ts b/src/caches/getGLProgram.ts
index bbcc2ce..b28014d 100644
--- a/src/caches/getGLProgram.ts
+++ b/src/caches/getGLProgram.ts
@@ -2,6 +2,7 @@ import { IRenderPipeline } from "@feng3d/render-api";
import { getWebGLUniformType, isWebGLUniformTextureType } from "../const/IGLUniformType";
import { IGLAttributeInfo } from "../data/IGLAttributeInfo";
import { ITransformFeedbackVaryings } from "../data/IGLRenderPipeline";
+import { ITransformFeedbackPipeline } from "../data/IGLTransformFeedbackPass";
import { IGLUniformInfo, IUniformItemInfo } from "../data/IGLUniformInfo";
import { getIGLAttributeType } from "./getIGLAttributeType";
@@ -35,6 +36,33 @@ declare global
}
}
+/**
+ * 激活渲染程序
+ */
+export function getGLTransformFeedbackProgram(gl: WebGLRenderingContext, pipeline: ITransformFeedbackPipeline)
+{
+ const shaderKey = getTransformFeedbackKey(pipeline);
+ let result = gl._programs[shaderKey];
+ if (result) return result;
+
+ const vertex = pipeline.vertex.code;
+ const fragment = `
+ #version 300 es
+ precision highp float;
+ precision highp int;
+
+ void main()
+ {
+ }
+ `;
+ const transformFeedbackVaryings = pipeline.transformFeedbackVaryings;
+
+ result = getWebGLProgram(gl, vertex, fragment, transformFeedbackVaryings);
+ gl._programs[shaderKey] = result;
+
+ return result;
+}
+
/**
* 激活渲染程序
*/
@@ -65,6 +93,14 @@ export function deleteProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeli
}
}
+function getTransformFeedbackKey(pipeline: ITransformFeedbackPipeline)
+{
+ const vertex = pipeline.vertex.code;
+ const transformFeedbackVaryings = pipeline.transformFeedbackVaryings;
+
+ return `---vertexShader---\n${vertex}\n---fragment---\n---feedback---${transformFeedbackVaryings?.varyings.toString()} ${transformFeedbackVaryings?.bufferMode}`;
+}
+
function getKey(pipeline: IRenderPipeline)
{
const vertex = pipeline.vertex.code;
diff --git a/src/data/IGLTransformFeedbackPass.ts b/src/data/IGLTransformFeedbackPass.ts
index 9244771..01703aa 100644
--- a/src/data/IGLTransformFeedbackPass.ts
+++ b/src/data/IGLTransformFeedbackPass.ts
@@ -20,9 +20,9 @@ export interface IGLTransformFeedbackPass
readonly __type: "TransformFeedbackPass";
/**
- * 计算对象列表。
+ * 变换反馈对象列表。
*/
- computeObjects: IGLTransformFeedbackObject[];
+ transformFeedbackObjects: IGLTransformFeedbackObject[];
}
export interface IGLTransformFeedbackObject
@@ -42,7 +42,7 @@ export interface IGLTransformFeedbackObject
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawVertex
*/
- readonly drawVertex?: IDrawVertex;
+ readonly drawVertex: IDrawVertex;
/**
* Uniform渲染数据
--
Gitee
From 576d38f53c6ad6a58c6aee5f4ab3ba00247a37aa Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 18 Dec 2024 22:45:13 +0800
Subject: [PATCH 132/186] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20IGLTransformFeedba?=
=?UTF-8?q?ckPass?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../transform_feedback_instanced.ts | 33 +++++++-------
src/RunWebGL.ts | 24 ++++++-----
src/caches/getGLProgram.ts | 43 +++----------------
src/data/IGLRenderPipeline.ts | 4 +-
src/data/IGLTransformFeedbackPass.ts | 19 +++-----
src/index.ts | 1 +
6 files changed, 47 insertions(+), 77 deletions(-)
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index e1c5955..d66d6e8 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -1,5 +1,5 @@
-import { IIndicesDataTypes, IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLTransformFeedback, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IRenderObject, IRenderPipeline, ISubmit, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLTransformFeedback, IGLTransformFeedbackObject, IGLTransformFeedbackPipeline, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -105,10 +105,9 @@ import { getShaderSource } from "./utility";
};
}
- const transformRO: IRenderObject = {
+ const transformRO: IGLTransformFeedbackObject = {
pipeline: programs[PROGRAM_TRANSFORM],
vertices: null,
- indices: null,
transformFeedback: null,
uniforms: {},
drawVertex: { vertexCount: NUM_INSTANCES },
@@ -121,20 +120,25 @@ import { getShaderSource } from "./utility";
drawVertex: { vertexCount: 3, instanceCount: NUM_INSTANCES },
};
- const rp: IRenderPass = {
- descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
- renderObjects: [transformRO, renderRO],
- };
+ const submit: ISubmit = {
+ commandEncoders: [{
+ passEncoders: [{
+ __type: "TransformFeedbackPass",
+ transformFeedbackObjects: [transformRO],
+ }, {
+ descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
+ renderObjects: [renderRO],
+ }]
+ }]
+ }
render();
function initPrograms()
{
- const programTransform: IRenderPipeline = {
- vertex: { code: getShaderSource("vs-emit") }, fragment: { code: getShaderSource("fs-emit") },
+ const programTransform: IGLTransformFeedbackPipeline = {
+ vertex: { code: getShaderSource("vs-emit") },
transformFeedbackVaryings: { varyings: ["v_offset", "v_rotation"], bufferMode: "SEPARATE_ATTRIBS" },
- rasterizerDiscard: true,
- primitive: { topology: "point-list" },
};
// Setup program for draw shader
@@ -151,7 +155,7 @@ import { getShaderSource } from "./utility";
primitive: { topology: "triangle-list" },
};
- const programs = [programTransform, programDraw];
+ const programs: [IGLTransformFeedbackPipeline, IRenderPipeline] = [programTransform, programDraw];
return programs;
}
@@ -167,7 +171,6 @@ import { getShaderSource } from "./utility";
const destinationTransformFeedback = transformFeedbacks[destinationIdx];
transformRO.vertices = sourceVAO.vertices;
- transformRO.indices = sourceVAO.indices;
transformRO.transformFeedback = destinationTransformFeedback;
transformRO.uniforms.u_time = time;
@@ -184,7 +187,7 @@ import { getShaderSource } from "./utility";
renderRO.vertices = vertexArrays[currentSourceIdx][1].vertices;
renderRO.indices = vertexArrays[currentSourceIdx][1].indices;
- webgl.submit({ commandEncoders: [{ passEncoders: [rp] }] });
+ webgl.submit(submit);
requestAnimationFrame(render);
}
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 277b376..f36be5c 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -2,7 +2,7 @@ import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEnco
import { getFramebuffer } from "./caches/getFramebuffer";
import { getGLBuffer } from "./caches/getGLBuffer";
-import { getGLProgram, getGLTransformFeedbackProgram } from "./caches/getGLProgram";
+import { getGLProgram } from "./caches/getGLProgram";
import { getGLRenderOcclusionQuery } from "./caches/getGLRenderOcclusionQuery";
import { getGLSampler } from "./caches/getGLSampler";
import { getGLTransformFeedback } from "./caches/getGLTransformFeedback";
@@ -23,7 +23,7 @@ import { IGLSampler, IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap }
import { IGLSamplerTexture } from "./data/IGLSamplerTexture";
import { IGLTextureTarget } from "./data/IGLTexture";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
-import { IGLTransformFeedbackObject, IGLTransformFeedbackPass, ITransformFeedbackPipeline } from "./data/IGLTransformFeedbackPass";
+import { IGLTransformFeedbackObject, IGLTransformFeedbackPass, IGLTransformFeedbackPipeline } from "./data/IGLTransformFeedbackPass";
import { IUniformItemInfo } from "./data/IGLUniformInfo";
import { IGLUniforms } from "./data/IGLUniforms";
import { getGLTexture } from "./internal";
@@ -113,10 +113,19 @@ export class RunWebGL
protected runTransformFeedbackPass(gl: WebGLRenderingContext, transformFeedbackPass: IGLTransformFeedbackPass)
{
+ // 执行变换反馈通道时关闭光栅化功能
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ gl.enable(gl.RASTERIZER_DISCARD);
+ }
transformFeedbackPass.transformFeedbackObjects.forEach((transformFeedbackObject) =>
{
this.runTransformFeedbackObject(gl, transformFeedbackObject);
});
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ gl.disable(gl.RASTERIZER_DISCARD);
+ }
}
protected runRenderPass(gl: WebGLRenderingContext, renderPass: IRenderPass)
@@ -649,17 +658,10 @@ export class RunWebGL
}
}
- private runTransformFeedbackPipeline(gl: WebGLRenderingContext, renderPipeline: ITransformFeedbackPipeline)
+ private runTransformFeedbackPipeline(gl: WebGLRenderingContext, renderPipeline: IGLTransformFeedbackPipeline)
{
- const program = getGLTransformFeedbackProgram(gl, renderPipeline);
+ const program = getGLProgram(gl, renderPipeline);
gl.useProgram(program);
-
- //
- if (gl instanceof WebGL2RenderingContext)
- {
- gl.enable(gl.RASTERIZER_DISCARD);
- return;
- }
}
private runRenderPipeline(gl: WebGLRenderingContext, renderPipeline: IRenderPipeline)
diff --git a/src/caches/getGLProgram.ts b/src/caches/getGLProgram.ts
index b28014d..463ce07 100644
--- a/src/caches/getGLProgram.ts
+++ b/src/caches/getGLProgram.ts
@@ -1,8 +1,7 @@
import { IRenderPipeline } from "@feng3d/render-api";
import { getWebGLUniformType, isWebGLUniformTextureType } from "../const/IGLUniformType";
import { IGLAttributeInfo } from "../data/IGLAttributeInfo";
-import { ITransformFeedbackVaryings } from "../data/IGLRenderPipeline";
-import { ITransformFeedbackPipeline } from "../data/IGLTransformFeedbackPass";
+import { IGLTransformFeedbackVaryings } from "../data/IGLRenderPipeline";
import { IGLUniformInfo, IUniformItemInfo } from "../data/IGLUniformInfo";
import { getIGLAttributeType } from "./getIGLAttributeType";
@@ -39,15 +38,14 @@ declare global
/**
* 激活渲染程序
*/
-export function getGLTransformFeedbackProgram(gl: WebGLRenderingContext, pipeline: ITransformFeedbackPipeline)
+export function getGLProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeline)
{
- const shaderKey = getTransformFeedbackKey(pipeline);
+ const shaderKey = getKey(pipeline);
let result = gl._programs[shaderKey];
if (result) return result;
const vertex = pipeline.vertex.code;
- const fragment = `
- #version 300 es
+ const fragment = pipeline.fragment?.code || `#version 300 es
precision highp float;
precision highp int;
@@ -63,25 +61,6 @@ export function getGLTransformFeedbackProgram(gl: WebGLRenderingContext, pipelin
return result;
}
-/**
- * 激活渲染程序
- */
-export function getGLProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeline)
-{
- const shaderKey = getKey(pipeline);
- let result = gl._programs[shaderKey];
- if (result) return result;
-
- const vertex = pipeline.vertex.code;
- const fragment = pipeline.fragment.code;
- const transformFeedbackVaryings = pipeline.transformFeedbackVaryings;
-
- result = getWebGLProgram(gl, vertex, fragment, transformFeedbackVaryings);
- gl._programs[shaderKey] = result;
-
- return result;
-}
-
export function deleteProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeline)
{
const shaderKey = getKey(pipeline);
@@ -93,24 +72,16 @@ export function deleteProgram(gl: WebGLRenderingContext, pipeline: IRenderPipeli
}
}
-function getTransformFeedbackKey(pipeline: ITransformFeedbackPipeline)
-{
- const vertex = pipeline.vertex.code;
- const transformFeedbackVaryings = pipeline.transformFeedbackVaryings;
-
- return `---vertexShader---\n${vertex}\n---fragment---\n---feedback---${transformFeedbackVaryings?.varyings.toString()} ${transformFeedbackVaryings?.bufferMode}`;
-}
-
function getKey(pipeline: IRenderPipeline)
{
const vertex = pipeline.vertex.code;
- const fragment = pipeline.fragment.code;
+ const fragment = pipeline.fragment?.code;
const transformFeedbackVaryings = pipeline.transformFeedbackVaryings;
return `---vertexShader---\n${vertex}\n---fragment---\n${fragment}\n---feedback---${transformFeedbackVaryings?.varyings.toString()} ${transformFeedbackVaryings?.bufferMode}`;
}
-function getWebGLProgram(gl: WebGLRenderingContext, vshader: string, fshader: string, transformFeedbackVaryings: ITransformFeedbackVaryings)
+function getWebGLProgram(gl: WebGLRenderingContext, vshader: string, fshader: string, transformFeedbackVaryings: IGLTransformFeedbackVaryings)
{
// 编译顶点着色器
const vertexShader = getWebGLShader(gl, "VERTEX_SHADER", vshader);
@@ -276,7 +247,7 @@ function getWebGLShader(gl: WebGLRenderingContext, type: ShaderType, code: strin
return shader;
}
-function createLinkProgram(gl: WebGLRenderingContext, vertexShader: WebGLShader, fragmentShader: WebGLShader, transformFeedbackVaryings: ITransformFeedbackVaryings)
+function createLinkProgram(gl: WebGLRenderingContext, vertexShader: WebGLShader, fragmentShader: WebGLShader, transformFeedbackVaryings: IGLTransformFeedbackVaryings)
{
// 创建程序对象
const program = gl.createProgram();
diff --git a/src/data/IGLRenderPipeline.ts b/src/data/IGLRenderPipeline.ts
index 1b2f701..1b05c7c 100644
--- a/src/data/IGLRenderPipeline.ts
+++ b/src/data/IGLRenderPipeline.ts
@@ -12,7 +12,7 @@ declare module "@feng3d/render-api"
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/transformFeedbackVaryings
*/
- transformFeedbackVaryings?: ITransformFeedbackVaryings;
+ transformFeedbackVaryings?: IGLTransformFeedbackVaryings;
/**
* 是否丢弃后续光栅化阶段。
@@ -23,7 +23,7 @@ declare module "@feng3d/render-api"
}
}
-export interface ITransformFeedbackVaryings
+export interface IGLTransformFeedbackVaryings
{
/**
* 回写变量列表。
diff --git a/src/data/IGLTransformFeedbackPass.ts b/src/data/IGLTransformFeedbackPass.ts
index 01703aa..8dbceb2 100644
--- a/src/data/IGLTransformFeedbackPass.ts
+++ b/src/data/IGLTransformFeedbackPass.ts
@@ -1,6 +1,6 @@
import { IDrawVertex, IVertexAttributes, IVertexState } from "@feng3d/render-api";
import { LazyObject } from "../types";
-import { ITransformFeedbackVaryings } from "./IGLRenderPipeline";
+import { IGLTransformFeedbackVaryings } from "./IGLRenderPipeline";
import { IGLTransformFeedback } from "./IGLTransformFeedback";
import { IGLUniforms } from "./IGLUniforms";
@@ -30,12 +30,12 @@ export interface IGLTransformFeedbackObject
/**
* 渲染管线描述。
*/
- readonly pipeline: ITransformFeedbackPipeline;
+ readonly pipeline: IGLTransformFeedbackPipeline;
/**
* 顶点属性数据映射。
*/
- vertices?: IVertexAttributes;
+ vertices: IVertexAttributes;
/**
* 根据顶点数据绘制图元。
@@ -54,10 +54,10 @@ export interface IGLTransformFeedbackObject
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/bindTransformFeedback
*/
- transformFeedback?: IGLTransformFeedback;
+ transformFeedback: IGLTransformFeedback;
}
-export interface ITransformFeedbackPipeline
+export interface IGLTransformFeedbackPipeline
{
/**
* 顶点着色器阶段描述。
@@ -69,12 +69,5 @@ export interface ITransformFeedbackPipeline
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/transformFeedbackVaryings
*/
- transformFeedbackVaryings?: ITransformFeedbackVaryings;
-
- /**
- * 是否丢弃后续光栅化阶段。
- *
- * gl.RASTERIZER_DISCARD
- */
- rasterizerDiscard?: boolean;
+ transformFeedbackVaryings: IGLTransformFeedbackVaryings;
}
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index ef22e93..e275021 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -18,6 +18,7 @@ export * from "./data/IGLSamplerTexture";
export * from "./data/IGLTexture";
export * from "./data/IGLTexturePixelStore";
export * from "./data/IGLTransformFeedback";
+export * from "./data/IGLTransformFeedbackPass";
export * from "./data/IGLUniforms";
export * from "./runs/getIGLBuffer";
--
Gitee
From 5a9a0a090b36d6aefaf9f332eed37cdea9ea74c1 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 18 Dec 2024 23:41:23 +0800
Subject: [PATCH 133/186] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20IGLTransformFeedba?=
=?UTF-8?q?ckPass?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../transform_feedback_instanced.ts | 36 +++---
.../transform_feedback_separated_2.html | 23 +++-
.../transform_feedback_separated_2.ts | 110 ++++++++++++------
src/RunWebGL.ts | 20 +---
src/caches/getGLProgram.ts | 14 +--
src/data/IGLRenderObject.ts | 23 ----
src/data/IGLRenderPipeline.ts | 38 ------
src/data/IGLTransformFeedbackPass.ts | 16 ++-
src/index.ts | 1 -
9 files changed, 134 insertions(+), 147 deletions(-)
delete mode 100644 src/data/IGLRenderPipeline.ts
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index d66d6e8..9148a94 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -72,35 +72,35 @@ import { getShaderSource } from "./utility";
const vertexBuffers: IVertexDataTypes[][] = new Array(vertexArrays.length);
- for (let va = 0; va < 2; ++va)
+ for (let i = 0; i < 2; ++i)
{
- vertexBuffers[va] = new Array(NUM_LOCATIONS);
+ vertexBuffers[i] = new Array(NUM_LOCATIONS);
- vertexBuffers[va][OFFSET_LOCATION] = instanceOffsets.slice();
- vertexBuffers[va][ROTATION_LOCATION] = instanceRotations.slice();
- vertexBuffers[va][POSITION_LOCATION] = trianglePositions.slice();
- vertexBuffers[va][COLOR_LOCATION] = instanceColors.slice();
+ vertexBuffers[i][OFFSET_LOCATION] = instanceOffsets.slice();
+ vertexBuffers[i][ROTATION_LOCATION] = instanceRotations.slice();
+ vertexBuffers[i][POSITION_LOCATION] = trianglePositions.slice();
+ vertexBuffers[i][COLOR_LOCATION] = instanceColors.slice();
- vertexArrays[va] = [];
- vertexArrays[va][0] = {
+ vertexArrays[i] = [];
+ vertexArrays[i][0] = {
vertices: {
- a_offset: { data: vertexBuffers[va][OFFSET_LOCATION], format: "float32x2" },
- a_rotation: { data: vertexBuffers[va][ROTATION_LOCATION], format: "float32" },
+ a_offset: { data: vertexBuffers[i][OFFSET_LOCATION], format: "float32x2" },
+ a_rotation: { data: vertexBuffers[i][ROTATION_LOCATION], format: "float32" },
}
};
- vertexArrays[va][1] = {
+ vertexArrays[i][1] = {
vertices: {
- a_offset: { data: vertexBuffers[va][OFFSET_LOCATION], format: "float32x2", stepMode: "instance" },
- a_rotation: { data: vertexBuffers[va][ROTATION_LOCATION], format: "float32", stepMode: "instance" },
- a_position: { data: vertexBuffers[va][POSITION_LOCATION], format: "float32x2" },
- a_color: { data: vertexBuffers[va][COLOR_LOCATION], format: "float32x3", stepMode: "instance" },
+ a_offset: { data: vertexBuffers[i][OFFSET_LOCATION], format: "float32x2", stepMode: "instance" },
+ a_rotation: { data: vertexBuffers[i][ROTATION_LOCATION], format: "float32", stepMode: "instance" },
+ a_position: { data: vertexBuffers[i][POSITION_LOCATION], format: "float32x2" },
+ a_color: { data: vertexBuffers[i][COLOR_LOCATION], format: "float32x3", stepMode: "instance" },
}
};
- transformFeedbacks[va] = {
+ transformFeedbacks[i] = {
bindBuffers: [
- { index: 0, data: vertexBuffers[va][OFFSET_LOCATION] },
- { index: 1, data: vertexBuffers[va][ROTATION_LOCATION] },
+ { index: 0, data: vertexBuffers[i][OFFSET_LOCATION] },
+ { index: 1, data: vertexBuffers[i][ROTATION_LOCATION] },
]
};
}
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.html b/examples/src/WebGL2Samples/transform_feedback_separated_2.html
index 8b43dd5..8b6c758 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.html
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.html
@@ -15,7 +15,7 @@
Using transform feedback in a simple particle system
-
+
+
-
-
-
@@ -75,10 +74,6 @@
layout(location = POSITION_LOCATION) in vec2 a_position;
- float rand(vec2 co){
- return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
- }
-
void main()
{
gl_Position = vec4(a_position, 0.0, 1.0);
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
index 4c6dbd2..f05e96d 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
@@ -58,7 +58,7 @@ import { getShaderSource } from "./utility";
}
// -- Init Vertex Arrays and Buffers
- const vertexArrays: { vertices?: IVertexAttributes, indices?: IIndicesDataTypes }[] = [];
+ const vertexArrays: { vertices?: IVertexAttributes, indices?: IIndicesDataTypes }[][] = [];
// Transform feedback objects track output buffer state
const transformFeedbacks: IGLTransformFeedback[] = [];
@@ -80,7 +80,8 @@ import { getShaderSource } from "./utility";
vertexBuffers[i][ID_LOCATION] = particleIDs;
- vertexArrays[i] = {
+ vertexArrays[i] = [];
+ vertexArrays[i][0] = {
vertices: {
a_position: { data: vertexBuffers[i][POSITION_LOCATION], format: "float32x2" },
a_velocity: { data: vertexBuffers[i][VELOCITY_LOCATION], format: "float32x2" },
@@ -90,6 +91,12 @@ import { getShaderSource } from "./utility";
}
};
+ vertexArrays[i][1] = {
+ vertices: {
+ a_position: { data: vertexBuffers[i][POSITION_LOCATION], format: "float32x2" },
+ }
+ };
+
// Set up output
transformFeedbacks[i] = {
bindBuffers: [
@@ -125,7 +132,7 @@ import { getShaderSource } from "./utility";
return [transformFeedbackPipeline, program];
}
- const transformFeedbackObject: IGLTransformFeedbackObject = {
+ const transformRO: IGLTransformFeedbackObject = {
vertices: undefined,
transformFeedback: undefined,
pipeline: transformFeedbackPipeline,
@@ -136,7 +143,7 @@ import { getShaderSource } from "./utility";
drawVertex: { vertexCount: NUM_PARTICLES },
};
- const ro: IRenderObject = {
+ const renderRO: IRenderObject = {
viewport: { x: 0, y: 0, width: canvas.width, height: canvas.height - 10 },
pipeline: program,
uniforms: {
@@ -151,11 +158,11 @@ import { getShaderSource } from "./utility";
passEncoders: [
{
__type: "TransformFeedbackPass",
- transformFeedbackObjects: [transformFeedbackObject],
+ transformFeedbackObjects: [transformRO],
},
{
descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
- renderObjects: [ro],
+ renderObjects: [renderRO],
}
]
}]
@@ -167,14 +174,14 @@ import { getShaderSource } from "./utility";
const destinationIdx = (currentSourceIdx + 1) % 2;
// Toggle source and destination VBO
- const sourceVAO = vertexArrays[currentSourceIdx];
+ const sourceVAO = vertexArrays[currentSourceIdx][0];
const destinationTransformFeedback = transformFeedbacks[destinationIdx];
//
- transformFeedbackObject.vertices = sourceVAO.vertices;
- transformFeedbackObject.transformFeedback = destinationTransformFeedback;
+ transformRO.vertices = sourceVAO.vertices;
+ transformRO.transformFeedback = destinationTransformFeedback;
- transformFeedbackObject.uniforms.u_time = time;
+ transformRO.uniforms.u_time = time;
// Ping pong the buffers
currentSourceIdx = (currentSourceIdx + 1) % 2;
@@ -185,8 +192,8 @@ import { getShaderSource } from "./utility";
transform();
//
- ro.vertices = vertexArrays[currentSourceIdx].vertices;
- ro.indices = vertexArrays[currentSourceIdx].indices;
+ renderRO.vertices = vertexArrays[currentSourceIdx][1].vertices;
+ renderRO.indices = vertexArrays[currentSourceIdx][1].indices;
webgl.submit(submit);
--
Gitee
From e0e394e7a8bfcbb098a23a6cc6530eb85c5e7506 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 00:18:07 +0800
Subject: [PATCH 135/186] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20IGLTransformFeedba?=
=?UTF-8?q?ckPass?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../transform_feedback_instanced.ts | 56 +++++++++----------
.../transform_feedback_separated_2.ts | 39 ++++++-------
2 files changed, 45 insertions(+), 50 deletions(-)
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index 6805115..65c2acc 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -105,6 +105,32 @@ import { getShaderSource } from "./utility";
};
}
+ function initPrograms()
+ {
+ const programTransform: IGLTransformFeedbackPipeline = {
+ vertex: { code: getShaderSource("vs-emit") },
+ transformFeedbackVaryings: { varyings: ["v_offset", "v_rotation"], bufferMode: "SEPARATE_ATTRIBS" },
+ };
+
+ // Setup program for draw shader
+ const programDraw: IRenderPipeline = {
+ vertex: { code: getShaderSource("vs-draw") }, fragment: {
+ code: getShaderSource("fs-draw"),
+ targets: [{
+ blend: {
+ color: { srcFactor: "src-alpha", dstFactor: "one" },
+ alpha: { srcFactor: "src-alpha", dstFactor: "one" },
+ }
+ }]
+ },
+ primitive: { topology: "triangle-list" },
+ };
+
+ const programs: [IGLTransformFeedbackPipeline, IRenderPipeline] = [programTransform, programDraw];
+
+ return programs;
+ }
+
const transformRO: IGLTransformFeedbackObject = {
pipeline: programs[PROGRAM_TRANSFORM],
vertices: null,
@@ -132,34 +158,6 @@ import { getShaderSource } from "./utility";
}]
}
- render();
-
- function initPrograms()
- {
- const programTransform: IGLTransformFeedbackPipeline = {
- vertex: { code: getShaderSource("vs-emit") },
- transformFeedbackVaryings: { varyings: ["v_offset", "v_rotation"], bufferMode: "SEPARATE_ATTRIBS" },
- };
-
- // Setup program for draw shader
- const programDraw: IRenderPipeline = {
- vertex: { code: getShaderSource("vs-draw") }, fragment: {
- code: getShaderSource("fs-draw"),
- targets: [{
- blend: {
- color: { srcFactor: "src-alpha", dstFactor: "one" },
- alpha: { srcFactor: "src-alpha", dstFactor: "one" },
- }
- }]
- },
- primitive: { topology: "triangle-list" },
- };
-
- const programs: [IGLTransformFeedbackPipeline, IRenderPipeline] = [programTransform, programDraw];
-
- return programs;
- }
-
function transform()
{
const time = Date.now();
@@ -192,6 +190,8 @@ import { getShaderSource } from "./utility";
requestAnimationFrame(render);
}
+ requestAnimationFrame(render);
+
// If you have a long-running page, and need to delete WebGL resources, use:
//
// gl.deleteProgram(programs[PROGRAM_TRANSFORM]);
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
index f05e96d..15b54df 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
@@ -39,13 +39,6 @@ import { getShaderSource } from "./utility";
const particleLifetime = new Float32Array(NUM_PARTICLES);
const particleIDs = new Float32Array(NUM_PARTICLES);
- const POSITION_LOCATION = 0;
- const VELOCITY_LOCATION = 1;
- const SPAWNTIME_LOCATION = 2;
- const LIFETIME_LOCATION = 3;
- const ID_LOCATION = 4;
- const NUM_LOCATIONS = 5;
-
for (let p = 0; p < NUM_PARTICLES; ++p)
{
particlePositions[p * 2] = 0.0;
@@ -57,6 +50,13 @@ import { getShaderSource } from "./utility";
particleIDs[p] = p;
}
+ const POSITION_LOCATION = 0;
+ const VELOCITY_LOCATION = 1;
+ const SPAWNTIME_LOCATION = 2;
+ const LIFETIME_LOCATION = 3;
+ const ID_LOCATION = 4;
+ const NUM_LOCATIONS = 5;
+
// -- Init Vertex Arrays and Buffers
const vertexArrays: { vertices?: IVertexAttributes, indices?: IIndicesDataTypes }[][] = [];
@@ -133,11 +133,10 @@ import { getShaderSource } from "./utility";
}
const transformRO: IGLTransformFeedbackObject = {
- vertices: undefined,
- transformFeedback: undefined,
pipeline: transformFeedbackPipeline,
+ vertices: null,
+ transformFeedback: null,
uniforms: {
- u_color: [0.0, 1.0, 1.0, 1.0],
u_acceleration: [0.0, ACCELERATION],
},
drawVertex: { vertexCount: NUM_PARTICLES },
@@ -148,25 +147,21 @@ import { getShaderSource } from "./utility";
pipeline: program,
uniforms: {
u_color: [0.0, 1.0, 1.0, 1.0],
- u_acceleration: [0.0, ACCELERATION],
},
drawVertex: { vertexCount: NUM_PARTICLES },
};
const submit: ISubmit = {
commandEncoders: [{
- passEncoders: [
- {
- __type: "TransformFeedbackPass",
- transformFeedbackObjects: [transformRO],
- },
- {
- descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
- renderObjects: [renderRO],
- }
- ]
+ passEncoders: [{
+ __type: "TransformFeedbackPass",
+ transformFeedbackObjects: [transformRO],
+ }, {
+ descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
+ renderObjects: [renderRO],
+ }]
}]
- };
+ }
function transform()
{
--
Gitee
From d6f2645dff4bfbf10589bc11f081392c990ac808 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 00:23:38 +0800
Subject: [PATCH 136/186] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20IGLTransformFeedba?=
=?UTF-8?q?ckPass?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../transform_feedback_instanced.ts | 17 ++++++++++-------
.../transform_feedback_separated_2.ts | 17 ++++++++++-------
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index 65c2acc..86f71a3 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -148,13 +148,16 @@ import { getShaderSource } from "./utility";
const submit: ISubmit = {
commandEncoders: [{
- passEncoders: [{
- __type: "TransformFeedbackPass",
- transformFeedbackObjects: [transformRO],
- }, {
- descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
- renderObjects: [renderRO],
- }]
+ passEncoders: [
+ {
+ __type: "TransformFeedbackPass",
+ transformFeedbackObjects: [transformRO],
+ },
+ {
+ descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
+ renderObjects: [renderRO],
+ }
+ ]
}]
}
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
index 15b54df..457e77b 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
@@ -153,13 +153,16 @@ import { getShaderSource } from "./utility";
const submit: ISubmit = {
commandEncoders: [{
- passEncoders: [{
- __type: "TransformFeedbackPass",
- transformFeedbackObjects: [transformRO],
- }, {
- descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
- renderObjects: [renderRO],
- }]
+ passEncoders: [
+ {
+ __type: "TransformFeedbackPass",
+ transformFeedbackObjects: [transformRO],
+ },
+ {
+ descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
+ renderObjects: [renderRO],
+ }
+ ]
}]
}
--
Gitee
From c723026742ea6db1855e9a85e344cfafb2f867f1 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 00:25:10 +0800
Subject: [PATCH 137/186] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20IGLTransformFeedba?=
=?UTF-8?q?ckPass?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/WebGL2Samples/transform_feedback_instanced.ts | 8 ++------
.../src/WebGL2Samples/transform_feedback_separated_2.ts | 8 ++------
2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/examples/src/WebGL2Samples/transform_feedback_instanced.ts b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
index 86f71a3..28907b7 100644
--- a/examples/src/WebGL2Samples/transform_feedback_instanced.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_instanced.ts
@@ -167,12 +167,8 @@ import { getShaderSource } from "./utility";
const destinationIdx = (currentSourceIdx + 1) % 2;
// Toggle source and destination VBO
- const sourceVAO = vertexArrays[currentSourceIdx][0];
-
- const destinationTransformFeedback = transformFeedbacks[destinationIdx];
-
- transformRO.vertices = sourceVAO.vertices;
- transformRO.transformFeedback = destinationTransformFeedback;
+ transformRO.vertices = vertexArrays[currentSourceIdx][0].vertices;
+ transformRO.transformFeedback = transformFeedbacks[destinationIdx];
transformRO.uniforms.u_time = time;
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
index 457e77b..6dae627 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated_2.ts
@@ -172,12 +172,8 @@ import { getShaderSource } from "./utility";
const destinationIdx = (currentSourceIdx + 1) % 2;
// Toggle source and destination VBO
- const sourceVAO = vertexArrays[currentSourceIdx][0];
- const destinationTransformFeedback = transformFeedbacks[destinationIdx];
-
- //
- transformRO.vertices = sourceVAO.vertices;
- transformRO.transformFeedback = destinationTransformFeedback;
+ transformRO.vertices = vertexArrays[currentSourceIdx][0].vertices;
+ transformRO.transformFeedback = transformFeedbacks[destinationIdx];
transformRO.uniforms.u_time = time;
--
Gitee
From 8c27eb021d0ffd9aea5bcfc762136073e2ce396a Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 10:55:35 +0800
Subject: [PATCH 138/186] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20bug=20=20A=20trans?=
=?UTF-8?q?form=20feedback=20buffer=20that=20would=20be=20written=20to=20i?=
=?UTF-8?q?s=20also=20bound=20to=20a=20non-transform-feedback=20target,=20?=
=?UTF-8?q?which=20would=20cause=20undefined=20behavior.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/RunWebGL.ts | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 4220a93..12207f2 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -257,6 +257,8 @@ export class RunWebGL
{
gl.endTransformFeedback();
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
+ gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, null);
}
}
}
--
Gitee
From 5c3236e9198b26fc53baeabca20144bd82e0cd39 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 11:12:30 +0800
Subject: [PATCH 139/186] 1
---
src/RunWebGL.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 12207f2..9dd3448 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -237,12 +237,12 @@ export class RunWebGL
this.runTransformFeedbackPipeline(gl, pipeline);
- this.runTransformFeedback(gl, transformFeedback, drawMode);
-
this.runVertexArray(gl, pipeline, vertices, undefined);
this.runUniforms(gl, pipeline, uniforms);
+ this.runTransformFeedback(gl, transformFeedback, drawMode);
+
this.runDrawVertex(gl, drawMode, drawVertex);
this.endTransformFeedback(gl, transformFeedback);
--
Gitee
From 49aaea4ec6e115091e24c4724ff24074101c0c93 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 11:31:39 +0800
Subject: [PATCH 140/186] 1
---
src/RunWebGL.ts | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 9dd3448..85ccfad 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -535,7 +535,6 @@ export class RunWebGL
}
}
-
/**
* 执行设置或者上传渲染对象的顶点以及索引数据。
*/
@@ -925,6 +924,10 @@ export class RunWebGL
gl.bindBuffer(gl.COPY_READ_BUFFER, rb);
gl.bindBuffer(gl.COPY_WRITE_BUFFER, wb);
gl.copyBufferSubData(gl.COPY_READ_BUFFER, gl.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
+
+ //
+ gl.bindBuffer(gl.COPY_READ_BUFFER, null);
+ gl.bindBuffer(gl.COPY_WRITE_BUFFER, null);
}
else
{
--
Gitee
From c5e9b2b48212d9dfca865817c2fccb15268a5896 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 11:41:01 +0800
Subject: [PATCH 141/186] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20IGLTransformFeedba?=
=?UTF-8?q?ckPass=20=E5=AE=9E=E7=8E=B0=E7=A4=BA=E4=BE=8B=20transform=5Ffee?=
=?UTF-8?q?dback=5Fseparated?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../transform_feedback_separated.ts | 70 ++++++++++---------
1 file changed, 36 insertions(+), 34 deletions(-)
diff --git a/examples/src/WebGL2Samples/transform_feedback_separated.ts b/examples/src/WebGL2Samples/transform_feedback_separated.ts
index 9fb79bc..d6126ec 100644
--- a/examples/src/WebGL2Samples/transform_feedback_separated.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_separated.ts
@@ -1,5 +1,5 @@
-import { IIndicesDataTypes, IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLTransformFeedback, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IRenderPass, IRenderPassObject, IRenderPipeline, ISubmit, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLTransformFeedback, IGLTransformFeedbackPipeline, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
@@ -19,14 +19,12 @@ import { getShaderSource } from "./utility";
// -- Init Program
const programTransform = (function (vertexShaderSourceTransform, fragmentShaderSourceTransform)
{
- const programTransform: IRenderPipeline = {
+ const transformFeedbackPipeline: IGLTransformFeedbackPipeline = {
vertex: { code: vertexShaderSourceTransform },
- fragment: { code: fragmentShaderSourceTransform },
transformFeedbackVaryings: { varyings: ["gl_Position", "v_color"], bufferMode: "SEPARATE_ATTRIBS" },
- rasterizerDiscard: true,
};
- return programTransform;
+ return transformFeedbackPipeline;
})(getShaderSource("vs-transform"), getShaderSource("fs-transform"));
const programFeedback: IRenderPipeline = {
@@ -60,8 +58,6 @@ import { getShaderSource } from "./utility";
// Transform buffer
positions,
// Feedback empty buffers
- // { target: "ARRAY_BUFFER", data: positions, usage: "STATIC_DRAW" },
- // { target: "ARRAY_BUFFER", data: positions, usage: "STATIC_DRAW" },
positions.slice(),
positions.slice(),
];
@@ -89,14 +85,6 @@ import { getShaderSource } from "./utility";
]
};
- const renderObjects: IRenderPassObject[] = [];
-
- // -- Render
- const rp: IRenderPass = {
- descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
- renderObjects: renderObjects,
- };
-
// First draw, capture the attributes
// Disable rasterization, vertices processing only
@@ -107,24 +95,38 @@ import { getShaderSource } from "./utility";
0.0, 0.0, 0.0, 1.0
]);
- renderObjects.push({
- pipeline: programs[PROGRAM_TRANSFORM],
- vertices: vertexArrays[PROGRAM_TRANSFORM].vertices,
- indices: vertexArrays[PROGRAM_TRANSFORM].indices,
- uniforms: { MVP: matrix },
- transformFeedback,
- drawVertex: { vertexCount: VERTEX_COUNT },
- });
-
- // Second draw, reuse captured attributes
- renderObjects.push({
- pipeline: programs[PROGRAM_FEEDBACK],
- vertices: vertexArrays[PROGRAM_FEEDBACK].vertices,
- indices: vertexArrays[PROGRAM_FEEDBACK].indices,
- drawVertex: { vertexCount: VERTEX_COUNT },
- });
-
- webgl.submit({ commandEncoders: [{ passEncoders: [rp] }] });
+ const submit: ISubmit = {
+ commandEncoders: [{
+ passEncoders: [
+ {
+ __type: "TransformFeedbackPass",
+ transformFeedbackObjects: [
+ {
+ pipeline: programTransform,
+ vertices: vertexArrays[PROGRAM_TRANSFORM].vertices,
+ uniforms: { MVP: matrix },
+ transformFeedback,
+ drawVertex: { vertexCount: VERTEX_COUNT },
+ }
+ ]
+ },
+ {
+ descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
+ renderObjects: [
+ // Second draw, reuse captured attributes
+ {
+ pipeline: programs[PROGRAM_FEEDBACK],
+ vertices: vertexArrays[PROGRAM_FEEDBACK].vertices,
+ indices: vertexArrays[PROGRAM_FEEDBACK].indices,
+ drawVertex: { vertexCount: VERTEX_COUNT },
+ }
+ ],
+ }
+ ]
+ }]
+ };
+
+ webgl.submit(submit);
// -- Delete WebGL resources
// gl.deleteTransformFeedback(transformFeedback);
--
Gitee
From 731309de52b147818019b21d5f27d1c0f4260b97 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 11:49:02 +0800
Subject: [PATCH 142/186] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20IGLTransformFeedba?=
=?UTF-8?q?ckPass=20=E5=AE=9E=E7=8E=B0=E7=A4=BA=E4=BE=8B=20transform=5Ffee?=
=?UTF-8?q?dback=5Finterleaved?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../transform_feedback_interleaved.ts | 67 +++++++++----------
1 file changed, 33 insertions(+), 34 deletions(-)
diff --git a/examples/src/WebGL2Samples/transform_feedback_interleaved.ts b/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
index 67cf48b..769a2c3 100644
--- a/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
+++ b/examples/src/WebGL2Samples/transform_feedback_interleaved.ts
@@ -1,5 +1,5 @@
-import { IIndicesDataTypes, IRenderPass, IRenderPassObject, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { getIGLVertexBuffer, IGLCanvasContext, IGLTransformFeedback, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IRenderPipeline, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { getIGLVertexBuffer, IGLCanvasContext, IGLTransformFeedback, IGLTransformFeedbackPipeline, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -21,11 +21,9 @@ import { getShaderSource } from "./utility";
const programTransform = (function (vertexShaderSourceTransform, fragmentShaderSourceTransform)
{
- const programTransform: IRenderPipeline = {
+ const programTransform: IGLTransformFeedbackPipeline = {
vertex: { code: vertexShaderSourceTransform },
- fragment: { code: fragmentShaderSourceTransform },
transformFeedbackVaryings: { varyings: ["gl_Position", "v_color"], bufferMode: "INTERLEAVED_ATTRIBS" },
- rasterizerDiscard: true,
};
return programTransform;
@@ -35,8 +33,6 @@ import { getShaderSource } from "./utility";
vertex: { code: getShaderSource("vs-feedback") }, fragment: { code: getShaderSource("fs-feedback") },
};
- const programs = [programTransform, programFeedback];
-
// -- Init Buffer
const SIZE_V4C4 = 32;
const VERTEX_COUNT = 6;
@@ -78,14 +74,6 @@ import { getShaderSource } from "./utility";
]
};
- const renderObjects: IRenderPassObject[] = [];
-
- // -- Render
- const rp: IRenderPass = {
- descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
- renderObjects: renderObjects,
- };
-
// First draw, capture the attributes
// Disable rasterization, vertices processing only
@@ -96,29 +84,40 @@ import { getShaderSource } from "./utility";
0.0, 0.0, 0.0, 1.0
]);
- renderObjects.push({
- pipeline: programs[PROGRAM_TRANSFORM],
- vertices: vertexArrays[PROGRAM_TRANSFORM].vertices,
- indices: vertexArrays[PROGRAM_TRANSFORM].indices,
- uniforms: { MVP: matrix },
- transformFeedback,
- drawVertex: { vertexCount: VERTEX_COUNT },
+ webgl.submit({
+ commandEncoders: [{
+ passEncoders: [
+ {
+ __type: "TransformFeedbackPass",
+ transformFeedbackObjects: [
+ {
+ pipeline: programTransform,
+ vertices: vertexArrays[PROGRAM_TRANSFORM].vertices,
+ uniforms: { MVP: matrix },
+ transformFeedback,
+ drawVertex: { vertexCount: VERTEX_COUNT },
+ }
+ ],
+ },
+ {
+ descriptor: { colorAttachments: [{ clearValue: [0.0, 0.0, 0.0, 1.0], loadOp: "clear" }] },
+ renderObjects: [
+ // Second draw, reuse captured attributes
+ {
+ pipeline: programFeedback,
+ vertices: vertexArrays[PROGRAM_FEEDBACK].vertices,
+ indices: vertexArrays[PROGRAM_FEEDBACK].indices,
+ drawVertex: { vertexCount: VERTEX_COUNT },
+ }
+ ],
+ }]
+ }]
});
- // Second draw, reuse captured attributes
- renderObjects.push({
- pipeline: programs[PROGRAM_FEEDBACK],
- vertices: vertexArrays[PROGRAM_FEEDBACK].vertices,
- indices: vertexArrays[PROGRAM_FEEDBACK].indices,
- drawVertex: { vertexCount: VERTEX_COUNT },
- });
-
- webgl.submit({ commandEncoders: [{ passEncoders: [rp] }] });
-
// -- Delete WebGL resources
webgl.deleteTransformFeedback(transformFeedback);
webgl.deleteBuffer(getIGLVertexBuffer(buffers[PROGRAM_TRANSFORM]));
webgl.deleteBuffer(getIGLVertexBuffer(buffers[PROGRAM_FEEDBACK]));
- webgl.deleteProgram(programs[PROGRAM_TRANSFORM]);
- webgl.deleteProgram(programs[PROGRAM_FEEDBACK]);
+ webgl.deleteProgram(programTransform);
+ webgl.deleteProgram(programFeedback);
})();
--
Gitee
From ed35a7043a1d92fdc7708f8e039206c64a120af8 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 14:29:54 +0800
Subject: [PATCH 143/186] ICopyTextureToTexture
---
src/RunWebGL.ts | 5 ++-
src/caches/getIGLBlitFramebuffer.ts | 7 ++--
src/data/IGLCommandEncoder.ts | 2 --
src/data/IGLCopyTextureToTexture.ts | 55 -----------------------------
4 files changed, 5 insertions(+), 64 deletions(-)
delete mode 100644 src/data/IGLCopyTextureToTexture.ts
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 85ccfad..573b8b9 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,4 +1,4 @@
-import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, IScissorRect, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, IScissorRect, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport } from "@feng3d/render-api";
import { getFramebuffer } from "./caches/getFramebuffer";
import { getGLBuffer } from "./caches/getGLBuffer";
@@ -15,7 +15,6 @@ import { IGLUniformBufferType } from "./const/IGLUniformType";
import { IGLBlitFramebuffer } from "./data/IGLBlitFramebuffer";
import { IGLBuffer } from "./data/IGLBuffer";
import { IGLCopyBufferToBuffer } from "./data/IGLCopyBufferToBuffer";
-import { IGLCopyTextureToTexture } from "./data/IGLCopyTextureToTexture";
import { IGLCompareFunction, IGLStencilFunc, IGLStencilOp } from "./data/IGLDepthStencilState";
import { IGLDrawElementType } from "./data/IGLIndexBuffer";
import { IGLOcclusionQuery } from "./data/IGLOcclusionQuery";
@@ -876,7 +875,7 @@ export class RunWebGL
}
}
- private runCopyTextureToTexture(gl: WebGLRenderingContext, copyTextureToTexture: IGLCopyTextureToTexture)
+ private runCopyTextureToTexture(gl: WebGLRenderingContext, copyTextureToTexture: ICopyTextureToTexture)
{
const blitFramebuffer = getIGLBlitFramebuffer(copyTextureToTexture);
this.runBlitFramebuffer(gl, blitFramebuffer);
diff --git a/src/caches/getIGLBlitFramebuffer.ts b/src/caches/getIGLBlitFramebuffer.ts
index 3dfac82..23f8720 100644
--- a/src/caches/getIGLBlitFramebuffer.ts
+++ b/src/caches/getIGLBlitFramebuffer.ts
@@ -1,6 +1,5 @@
-import { IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, ITextureView } from "@feng3d/render-api";
+import { ICopyTextureToTexture, IImageCopyTexture, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, ITextureView } from "@feng3d/render-api";
import { IGLBlitFramebuffer, IGLBlitFramebufferItem } from "../data/IGLBlitFramebuffer";
-import { IGLCopyTextureToTexture, IGLImageCopyTexture } from "../data/IGLCopyTextureToTexture";
/**
* 通过 IGLBlitFramebuffer 实现纹理之间拷贝并不靠谱。
@@ -8,7 +7,7 @@ import { IGLCopyTextureToTexture, IGLImageCopyTexture } from "../data/IGLCopyTex
* @param copyTextureToTexture GL纹理之间拷贝。
* @returns
*/
-export function getIGLBlitFramebuffer(copyTextureToTexture: IGLCopyTextureToTexture)
+export function getIGLBlitFramebuffer(copyTextureToTexture: ICopyTextureToTexture)
{
const { source, destination, copySize } = copyTextureToTexture;
@@ -68,7 +67,7 @@ export function getIGLBlitFramebuffer(copyTextureToTexture: IGLCopyTextureToText
return blitFramebuffer;
}
-function getIGLTextureView(source: IGLImageCopyTexture)
+function getIGLTextureView(source: IImageCopyTexture)
{
const textureView: ITextureView = {
texture: source.texture,
diff --git a/src/data/IGLCommandEncoder.ts b/src/data/IGLCommandEncoder.ts
index 1bf9d2e..8b0b602 100644
--- a/src/data/IGLCommandEncoder.ts
+++ b/src/data/IGLCommandEncoder.ts
@@ -1,14 +1,12 @@
import { ICommandEncoder, IPassEncoder, IRenderPass } from "@feng3d/render-api";
import { IGLBlitFramebuffer } from "./IGLBlitFramebuffer";
import { IGLCopyBufferToBuffer } from "./IGLCopyBufferToBuffer";
-import { IGLCopyTextureToTexture } from "./IGLCopyTextureToTexture";
declare module "@feng3d/render-api"
{
export interface IPassEncoderMap
{
IGLBlitFramebuffer: IGLBlitFramebuffer;
- IGLCopyTextureToTexture: IGLCopyTextureToTexture;
IGLCopyBufferToBuffer: IGLCopyBufferToBuffer;
}
}
diff --git a/src/data/IGLCopyTextureToTexture.ts b/src/data/IGLCopyTextureToTexture.ts
deleted file mode 100644
index d40463b..0000000
--- a/src/data/IGLCopyTextureToTexture.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-import { ITexture } from "@feng3d/render-api";
-
-/**
- * GL中纹理之间拷贝。
- */
-export interface IGLCopyTextureToTexture
-{
- /**
- * 数据类型。
- */
- readonly __type: "CopyTextureToTexture";
-
- /**
- * Combined with `copySize`, defines the region of the source texture subresources.
- */
- source: IGLImageCopyTexture,
-
- /**
- * Combined with `copySize`, defines the region of the destination texture subresources.
- */
- destination: IGLImageCopyTexture,
-
- /**
- * 拷贝的尺寸。
- */
- copySize: IGLExtent3DStrict;
-}
-
-export interface IGLImageCopyTexture
-{
- /**
- * Texture to copy to/from.
- */
- texture: ITexture;
-
- /**
- * Mip-map level of the {@link GPUImageCopyTexture#texture} to copy to/from.
- */
- mipLevel?: number;
-
- /**
- * Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from.
- * Together with `copySize`, defines the full copy sub-region.
- */
- origin?: [width: number, height: number, depth?: number];
-
- /**
- * Defines which aspects of the {@link GPUImageCopyTexture#texture} to copy to/from.
- */
- aspect?: GLTextureAspect;
-}
-
-export type GLTextureAspect = "all" | "stencil-only" | "depth-only";
-
-export type IGLExtent3DStrict = [width: number, height: number, depthOrArrayLayers?: number];
\ No newline at end of file
--
Gitee
From d127a83b19ac52ce277c2c2cb27f8ae1efe25905 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 15:34:35 +0800
Subject: [PATCH 144/186] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=A4=BA=E4=BE=8B=20?=
=?UTF-8?q?fractalCube?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
examples/index.ts | 3 +
examples/src/test/fractalCube.html | 17 ++
examples/src/test/fractalCube.ts | 277 +++++++++++++++++++++++++++++
src/RunWebGL.ts | 6 +-
src/caches/getFramebuffer.ts | 2 +-
src/data/IGLCommandEncoder.ts | 17 +-
6 files changed, 317 insertions(+), 5 deletions(-)
create mode 100644 examples/src/test/fractalCube.html
create mode 100644 examples/src/test/fractalCube.ts
diff --git a/examples/index.ts b/examples/index.ts
index 09a3489..541c556 100644
--- a/examples/index.ts
+++ b/examples/index.ts
@@ -9,6 +9,9 @@ const files = {
"sample7",
"sample8",
],
+ "test":[
+ "fractalCube"
+ ],
"regl-examples": [
"basic",
"batch",
diff --git a/examples/src/test/fractalCube.html b/examples/src/test/fractalCube.html
new file mode 100644
index 0000000..6693a17
--- /dev/null
+++ b/examples/src/test/fractalCube.html
@@ -0,0 +1,17 @@
+
+
+
+
+
+ 分形立方体-测试纹理拷贝
+
+
+
+
+
+ 测试纹理之间拷贝,把前一帧的渲染结果作为纹理渲染到下一帧中。
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/src/test/fractalCube.ts b/examples/src/test/fractalCube.ts
new file mode 100644
index 0000000..a7da320
--- /dev/null
+++ b/examples/src/test/fractalCube.ts
@@ -0,0 +1,277 @@
+import { IRenderObject, ISubmit, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { mat4 } from "gl-matrix";
+
+let cubeRotation = 0.0;
+
+main();
+
+//
+// Start here
+//
+async function main()
+{
+ const canvas = document.querySelector("#glcanvas") as HTMLCanvasElement;
+
+ const renderingContext: IGLCanvasContext = { canvasId: "glcanvas", contextId: "webgl2" };
+
+ const webgl = new WebGL(renderingContext);
+
+ // Here's where we call the routine that builds all the
+ // objects we'll be drawing.
+ const buffers = initBuffers();
+
+ const texture: {
+ texture: ITexture;
+ sampler: IGLSampler;
+ } = { texture: { size: [canvas.width, canvas.height] }, sampler: {} };
+
+ const renderObject: IRenderObject = {
+ pipeline: {
+ primitive: { topology: "triangle-list" },
+ vertex: {
+ code: `
+ attribute vec4 aVertexPosition;
+ attribute vec2 aTextureCoord;
+
+ uniform mat4 uModelViewMatrix;
+ uniform mat4 uProjectionMatrix;
+
+ varying highp vec2 vTextureCoord;
+ varying highp vec4 v_fragPosition;
+
+ void main(void) {
+ gl_Position = uProjectionMatrix * uModelViewMatrix * aVertexPosition;
+ vTextureCoord = aTextureCoord;
+ v_fragPosition = 0.5 * (aVertexPosition + vec4(1.0, 1.0, 1.0, 1.0));
+ }
+ ` }, fragment: {
+ code: `
+ precision highp float;
+ precision highp int;
+
+ varying highp vec2 vTextureCoord;
+ varying highp vec4 v_fragPosition;
+
+ uniform sampler2D uSampler;
+
+ void main(void) {
+ vec4 color = texture2D(uSampler, vTextureCoord) * v_fragPosition;
+ gl_FragColor = color;
+ }
+ ` },
+ depthStencil: { depthCompare: "less-equal" }
+ },
+ vertices: {
+ aVertexPosition: {
+ format: "float32x3",
+ data: buffers.position,
+ },
+ aTextureCoord: {
+ format: "float32x2",
+ data: buffers.textureCoord,
+ },
+ },
+ indices: buffers.indices,
+ uniforms: { uSampler: texture },
+ drawIndexed: { firstIndex: 0, indexCount: 36 },
+ };
+
+ const submit: ISubmit = {
+ commandEncoders: [{
+ passEncoders: [
+ // 绘制
+ {
+ descriptor: {
+ colorAttachments: [{ clearValue: [0.5, 0.5, 0.5, 1.0], loadOp: "clear" }],
+ depthStencilAttachment: { depthClearValue: 1.0, depthLoadOp: "clear" },
+ },
+ renderObjects: [renderObject],
+ },
+ // 从画布中拷贝到纹理。
+ {
+ __type: "CopyTextureToTexture",
+ source: { texture: null }, // 当值设置为 null或者undefined时表示当前画布。
+ destination: { texture: texture.texture },
+ copySize: [canvas.width, canvas.height],
+ },
+ ]
+ }]
+ }
+
+ let then = 0;
+
+ // Draw the scene repeatedly
+ function render()
+ {
+ let now = Date.now();
+ now *= 0.001; // convert to seconds
+ const deltaTime = now - then;
+ then = now;
+
+ const { projectionMatrix, modelViewMatrix } = drawScene(canvas, deltaTime);
+
+ renderObject.uniforms.uProjectionMatrix = projectionMatrix;
+ renderObject.uniforms.uModelViewMatrix = modelViewMatrix;
+
+ webgl.submit(submit);
+
+ requestAnimationFrame(render);
+ }
+ requestAnimationFrame(render);
+}
+
+//
+// initBuffers
+//
+// Initialize the buffers we'll need. For this demo, we just
+// have one object -- a simple three-dimensional cube.
+//
+function initBuffers()
+{
+ // Now create an array of positions for the cube.
+
+ const positions = [
+ // Front face
+ -1.0, -1.0, 1.0,
+ 1.0, -1.0, 1.0,
+ 1.0, 1.0, 1.0,
+ -1.0, 1.0, 1.0,
+
+ // Back face
+ -1.0, -1.0, -1.0,
+ -1.0, 1.0, -1.0,
+ 1.0, 1.0, -1.0,
+ 1.0, -1.0, -1.0,
+
+ // Top face
+ -1.0, 1.0, -1.0,
+ -1.0, 1.0, 1.0,
+ 1.0, 1.0, 1.0,
+ 1.0, 1.0, -1.0,
+
+ // Bottom face
+ -1.0, -1.0, -1.0,
+ 1.0, -1.0, -1.0,
+ 1.0, -1.0, 1.0,
+ -1.0, -1.0, 1.0,
+
+ // Right face
+ 1.0, -1.0, -1.0,
+ 1.0, 1.0, -1.0,
+ 1.0, 1.0, 1.0,
+ 1.0, -1.0, 1.0,
+
+ // Left face
+ -1.0, -1.0, -1.0,
+ -1.0, -1.0, 1.0,
+ -1.0, 1.0, 1.0,
+ -1.0, 1.0, -1.0,
+ ];
+
+ // Now set up the texture coordinates for the faces.
+
+ const textureCoordinates = [
+ // Front
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ // Back
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ // Top
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ // Bottom
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ // Right
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ // Left
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ ];
+
+ // This array defines each face as two triangles, using the
+ // indices into the vertex array to specify each triangle's
+ // position.
+
+ const indices = [
+ 0, 1, 2, 0, 2, 3, // front
+ 4, 5, 6, 4, 6, 7, // back
+ 8, 9, 10, 8, 10, 11, // top
+ 12, 13, 14, 12, 14, 15, // bottom
+ 16, 17, 18, 16, 18, 19, // right
+ 20, 21, 22, 20, 22, 23, // left
+ ];
+
+ return {
+ position: new Float32Array(positions),
+ textureCoord: new Float32Array(textureCoordinates),
+ indices: new Uint16Array(indices),
+ };
+}
+
+//
+// Draw the scene.
+//
+function drawScene(canvas: HTMLCanvasElement, deltaTime: number)
+{
+ // Create a perspective matrix, a special matrix that is
+ // used to simulate the distortion of perspective in a camera.
+ // Our field of view is 45 degrees, with a width/height
+ // ratio that matches the display size of the canvas
+ // and we only want to see objects between 0.1 units
+ // and 100 units away from the camera.
+
+ const fieldOfView = 45 * Math.PI / 180; // in radians
+ const aspect = canvas.clientWidth / canvas.clientHeight;
+ const zNear = 0.1;
+ const zFar = 100.0;
+ const projectionMatrix = mat4.create();
+
+ // note: glmatrix.js always has the first argument
+ // as the destination to receive the result.
+ mat4.perspective(projectionMatrix,
+ fieldOfView,
+ aspect,
+ zNear,
+ zFar);
+
+ // Set the drawing position to the "identity" point, which is
+ // the center of the scene.
+ const modelViewMatrix = mat4.create();
+
+ // Now move the drawing position a bit to where we want to
+ // start drawing the square.
+
+ mat4.translate(modelViewMatrix, // destination matrix
+ modelViewMatrix, // matrix to translate
+ [-0.0, 0.0, -6.0]); // amount to translate
+ mat4.rotate(modelViewMatrix, // destination matrix
+ modelViewMatrix, // matrix to rotate
+ cubeRotation, // amount to rotate in radians
+ [0, 0, 1]); // axis to rotate around (Z)
+ mat4.rotate(modelViewMatrix, // destination matrix
+ modelViewMatrix, // matrix to rotate
+ cubeRotation * 0.7, // amount to rotate in radians
+ [0, 1, 0]); // axis to rotate around (X)
+
+ // Update the rotation for the next draw
+
+ cubeRotation += deltaTime;
+
+ return { projectionMatrix, modelViewMatrix };
+}
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 573b8b9..9595bef 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -141,7 +141,7 @@ export class RunWebGL
{
const { passDescriptor, blitFramebuffer } = getIGLRenderPassDescriptorWithMultisample(renderPass.descriptor);
- this.runPassDescriptor(gl, passDescriptor);
+ this.runRenderPassDescriptor(gl, passDescriptor);
this.runRenderObjects(gl, attachmentSize, renderPass.renderObjects);
@@ -149,7 +149,7 @@ export class RunWebGL
}
else
{
- this.runPassDescriptor(gl, renderPass.descriptor);
+ this.runRenderPassDescriptor(gl, renderPass.descriptor);
this.runRenderObjects(gl, attachmentSize, renderPass.renderObjects);
}
@@ -157,7 +157,7 @@ export class RunWebGL
occlusionQuery.resolve(renderPass);
}
- private runPassDescriptor(gl: WebGLRenderingContext, passDescriptor: IRenderPassDescriptor)
+ private runRenderPassDescriptor(gl: WebGLRenderingContext, passDescriptor: IRenderPassDescriptor)
{
passDescriptor = passDescriptor || {};
diff --git a/src/caches/getFramebuffer.ts b/src/caches/getFramebuffer.ts
index 6c8730b..5ef1b80 100644
--- a/src/caches/getFramebuffer.ts
+++ b/src/caches/getFramebuffer.ts
@@ -19,7 +19,7 @@ declare global
export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IRenderPassDescriptor)
{
const view = passDescriptor?.colorAttachments?.[0]?.view || passDescriptor?.depthStencilAttachment?.view;
- if (!view) return null;
+ if (!view || !view.texture) return null;
let webGLFramebuffer = gl._framebuffers.get(passDescriptor);
if (webGLFramebuffer) return webGLFramebuffer;
diff --git a/src/data/IGLCommandEncoder.ts b/src/data/IGLCommandEncoder.ts
index 8b0b602..a11c8e6 100644
--- a/src/data/IGLCommandEncoder.ts
+++ b/src/data/IGLCommandEncoder.ts
@@ -1,4 +1,4 @@
-import { ICommandEncoder, IPassEncoder, IRenderPass } from "@feng3d/render-api";
+import { ICommandEncoder, IPassEncoder, IRenderPass, ITextureLike } from "@feng3d/render-api";
import { IGLBlitFramebuffer } from "./IGLBlitFramebuffer";
import { IGLCopyBufferToBuffer } from "./IGLCopyBufferToBuffer";
@@ -9,4 +9,19 @@ declare module "@feng3d/render-api"
IGLBlitFramebuffer: IGLBlitFramebuffer;
IGLCopyBufferToBuffer: IGLCopyBufferToBuffer;
}
+
+ /**
+ * 被操作的纹理相关信息。
+ *
+ * {@link GPUCommandEncoder.copyTextureToTexture}
+ * {@link GPUImageCopyTexture}
+ */
+ export interface IImageCopyTexture
+ {
+ /**
+ *
+ * 注:当值设置为 null或者undefined时表示当前画布。
+ */
+ texture: ITextureLike;
+ }
}
--
Gitee
From 03737f575f70b1ca2fa2415257cd92a029da63a6 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 16:28:09 +0800
Subject: [PATCH 145/186] writeBuffer
---
src/caches/getGLBuffer.ts | 13 +++++++++++--
src/data/IGLBuffer.ts | 8 ++++----
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/caches/getGLBuffer.ts b/src/caches/getGLBuffer.ts
index e7124f9..8776fc7 100644
--- a/src/caches/getGLBuffer.ts
+++ b/src/caches/getGLBuffer.ts
@@ -62,8 +62,17 @@ export function getGLBuffer(gl: WebGLRenderingContext, buffer: IGLBuffer)
{
const bufferOffset = writeBuffer.bufferOffset || 0;
const data = writeBuffer.data;
-
- gl.bufferSubData(gl[target], bufferOffset, data);
+ const dataOffset = writeBuffer.dataOffset || 0;
+ const size = writeBuffer.size || 0;
+
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ gl.bufferSubData(gl[target], bufferOffset, data, dataOffset, size);
+ }
+ else
+ {
+ gl.bufferSubData(gl[target], bufferOffset, data);
+ }
});
buffer.writeBuffers = null;
}
diff --git a/src/data/IGLBuffer.ts b/src/data/IGLBuffer.ts
index a1b5066..de4f872 100644
--- a/src/data/IGLBuffer.ts
+++ b/src/data/IGLBuffer.ts
@@ -1,18 +1,18 @@
-import { IVertexDataTypes } from "@feng3d/render-api";
+import { IBuffer, IVertexDataTypes } from "@feng3d/render-api";
/**
* WebGL缓冲区
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData
*/
-export interface IGLBuffer
+export interface IGLBuffer extends IBuffer
{
target: GLBufferTarget;
/**
* 缓冲区数据。
*/
- data?: BufferSource;
+ data?: ArrayBufferView;
/**
* 创建指定尺寸的空缓冲区。
@@ -49,7 +49,7 @@ export interface IGLWriteBuffer
/**
* 写入缓冲区数据。
*/
- data: BufferSource;
+ data: ArrayBufferView;
dataOffset?: number
--
Gitee
From adaf9bc702f53154d3e9c18e64844b72112a0bf4 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 16:43:32 +0800
Subject: [PATCH 146/186] IBuffer
---
src/data/IGLBuffer.ts | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/src/data/IGLBuffer.ts b/src/data/IGLBuffer.ts
index de4f872..fe7aac6 100644
--- a/src/data/IGLBuffer.ts
+++ b/src/data/IGLBuffer.ts
@@ -9,16 +9,6 @@ export interface IGLBuffer extends IBuffer
{
target: GLBufferTarget;
- /**
- * 缓冲区数据。
- */
- data?: ArrayBufferView;
-
- /**
- * 创建指定尺寸的空缓冲区。
- */
- size?: number;
-
/**
* 为优化目的指定数据存储的预期使用模式的GLenum。
*
--
Gitee
From 3b6f25303f752d535ead0ab0938ebde3792b7dac Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 18:58:59 +0800
Subject: [PATCH 147/186] =?UTF-8?q?IBuffer.size=20=E5=BF=85=E9=A1=BB?=
=?UTF-8?q?=E6=8F=90=E4=BE=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
examples/src/WebGL2Samples/buffer_copy.ts | 2 +-
examples/src/WebGL2Samples/buffer_uniform.ts | 6 +++---
examples/src/WebGL2Samples/draw_instanced_ubo.ts | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/examples/src/WebGL2Samples/buffer_copy.ts b/examples/src/WebGL2Samples/buffer_copy.ts
index b30d141..734739a 100644
--- a/examples/src/WebGL2Samples/buffer_copy.ts
+++ b/examples/src/WebGL2Samples/buffer_copy.ts
@@ -30,7 +30,7 @@ import { getShaderSource } from "./utility";
-1.0, 1.0,
-1.0, -1.0
]);
- const vertexPosBufferSrc: IGLVertexBuffer = { target: "ARRAY_BUFFER", data: vertices, usage: "STATIC_DRAW" };
+ const vertexPosBufferSrc: IGLVertexBuffer = { target: "ARRAY_BUFFER", size: vertices.byteLength, data: vertices, usage: "STATIC_DRAW" };
const vertexPosBufferDst = new Float32Array(vertices.length);
diff --git a/examples/src/WebGL2Samples/buffer_uniform.ts b/examples/src/WebGL2Samples/buffer_uniform.ts
index 349eeec..5fd98d0 100644
--- a/examples/src/WebGL2Samples/buffer_uniform.ts
+++ b/examples/src/WebGL2Samples/buffer_uniform.ts
@@ -52,12 +52,12 @@ import { getShaderSource } from "./utility";
0.0, 0.0, 0.0, 1.0
]);
- const uniformPerDrawBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", data: transforms, usage: "DYNAMIC_DRAW" };
+ const uniformPerDrawBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", size: transforms.byteLength, data: transforms, usage: "DYNAMIC_DRAW" };
const lightPos = new Float32Array([
0.0, 0.0, 0.0, 0.0,
]);
- const uniformPerPassBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", data: lightPos, usage: "DYNAMIC_DRAW" };
+ const uniformPerPassBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", size: lightPos.byteLength, data: lightPos, usage: "DYNAMIC_DRAW" };
//vec3 ambient, diffuse, specular, float shininess
const material = new Float32Array([
@@ -65,7 +65,7 @@ import { getShaderSource } from "./utility";
0.5, 0.0, 0.0, 0.0,
1.0, 1.0, 1.0, 4.0,
]);
- const uniformPerSceneBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", data: material, usage: "STATIC_DRAW" };
+ const uniformPerSceneBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", size: material.byteLength, data: material, usage: "STATIC_DRAW" };
// -- Init Vertex Array
const vertexArray: { vertices?: IVertexAttributes } = {
diff --git a/examples/src/WebGL2Samples/draw_instanced_ubo.ts b/examples/src/WebGL2Samples/draw_instanced_ubo.ts
index c2da5c0..9ac0f40 100644
--- a/examples/src/WebGL2Samples/draw_instanced_ubo.ts
+++ b/examples/src/WebGL2Samples/draw_instanced_ubo.ts
@@ -32,13 +32,13 @@ const transforms = new Float32Array([
0.0, 0.0, 1.0, 0.0,
0.5, 0.0, 0.0, 1.0
]);
-const uniformTransformBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", data: transforms, usage: "DYNAMIC_DRAW" };
+const uniformTransformBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", size: transforms.byteLength, data: transforms, usage: "DYNAMIC_DRAW" };
const materials = new Float32Array([
1.0, 0.5, 0.0, 1.0,
0.0, 0.5, 1.0, 1.0
]);
-const uniformMaterialBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", data: materials, usage: "STATIC_DRAW" };
+const uniformMaterialBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", size: materials.byteLength, data: materials, usage: "STATIC_DRAW" };
// -- Render
const rp: IRenderPass = {
--
Gitee
From dc23678982bf7fd56f780c2e9b8114d1f191eb38 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 19:13:15 +0800
Subject: [PATCH 148/186] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/RunWebGL.ts | 3 +--
src/data/IGLBuffer.ts | 55 ++++++++++++++++++++++++++++++++------
src/data/IGLIndexBuffer.ts | 36 -------------------------
src/data/IGLUniforms.ts | 7 +----
src/index.ts | 1 -
src/runs/getIGLBuffer.ts | 3 +--
6 files changed, 50 insertions(+), 55 deletions(-)
delete mode 100644 src/data/IGLIndexBuffer.ts
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 9595bef..131be2e 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -13,10 +13,9 @@ import { getIGLTextureTarget } from "./caches/getIGLTextureTarget";
import { _GL_Submit_Times } from "./const/const";
import { IGLUniformBufferType } from "./const/IGLUniformType";
import { IGLBlitFramebuffer } from "./data/IGLBlitFramebuffer";
-import { IGLBuffer } from "./data/IGLBuffer";
+import { IGLBuffer, IGLDrawElementType } from "./data/IGLBuffer";
import { IGLCopyBufferToBuffer } from "./data/IGLCopyBufferToBuffer";
import { IGLCompareFunction, IGLStencilFunc, IGLStencilOp } from "./data/IGLDepthStencilState";
-import { IGLDrawElementType } from "./data/IGLIndexBuffer";
import { IGLOcclusionQuery } from "./data/IGLOcclusionQuery";
import { IGLSampler, IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "./data/IGLSampler";
import { IGLSamplerTexture } from "./data/IGLSamplerTexture";
diff --git a/src/data/IGLBuffer.ts b/src/data/IGLBuffer.ts
index fe7aac6..93e03bc 100644
--- a/src/data/IGLBuffer.ts
+++ b/src/data/IGLBuffer.ts
@@ -1,4 +1,4 @@
-import { IBuffer, IVertexDataTypes } from "@feng3d/render-api";
+import { IBuffer, IIndicesDataTypes, IVertexDataTypes } from "@feng3d/render-api";
/**
* WebGL缓冲区
@@ -22,6 +22,20 @@ export interface IGLBuffer extends IBuffer
writeBuffers?: IGLWriteBuffer[];
}
+export interface IGLWriteBuffer
+{
+ bufferOffset?: number;
+
+ /**
+ * 写入缓冲区数据。
+ */
+ data: ArrayBufferView;
+
+ dataOffset?: number
+
+ size?: number
+}
+
export interface IGLVertexBuffer extends IGLBuffer
{
target: "ARRAY_BUFFER";
@@ -32,20 +46,45 @@ export interface IGLVertexBuffer extends IGLBuffer
data?: IVertexDataTypes;
}
-export interface IGLWriteBuffer
+/**
+ * WebGL元素缓冲,顶点索引缓冲。
+ *
+ * 使用 gl.ELEMENT_ARRAY_BUFFER 进行绑定数据。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bindBuffer
+ *
+ */
+export interface IGLIndexBuffer extends IGLBuffer
{
- bufferOffset?: number;
+ target: "ELEMENT_ARRAY_BUFFER";
/**
- * 写入缓冲区数据。
+ * 顶点索引数据。
*/
- data: ArrayBufferView;
-
- dataOffset?: number
+ data: IIndicesDataTypes;
+}
- size?: number
+export interface IGLUniformBuffer extends IGLBuffer
+{
+ target: "UNIFORM_BUFFER";
}
+/**
+ * 元素缓冲数据类型。
+ *
+ * A GLenum specifying the type of the values in the element array buffer. Possible values are:
+ *
+ * * gl.UNSIGNED_BYTE
+ * * gl.UNSIGNED_SHORT
+ *
+ * When using the OES_element_index_uint extension:
+ *
+ * * gl.UNSIGNED_INT
+ *
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/drawElements
+ */
+export type IGLDrawElementType = "UNSIGNED_BYTE" | "UNSIGNED_SHORT" | "UNSIGNED_INT";
+
/**
* A GLenum specifying the intended usage pattern of the data store for optimization purposes. Possible values:
*
diff --git a/src/data/IGLIndexBuffer.ts b/src/data/IGLIndexBuffer.ts
deleted file mode 100644
index 6d9acf4..0000000
--- a/src/data/IGLIndexBuffer.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import { IIndicesDataTypes } from "@feng3d/render-api";
-import { IGLBuffer } from "./IGLBuffer";
-
-/**
- * WebGL元素缓冲,顶点索引缓冲。
- *
- * 使用 gl.ELEMENT_ARRAY_BUFFER 进行绑定数据。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bindBuffer
- *
- */
-export interface IGLIndexBuffer extends IGLBuffer
-{
- target: "ELEMENT_ARRAY_BUFFER";
-
- /**
- * 顶点索引数据。
- */
- data: IIndicesDataTypes;
-}
-
-/**
- * 元素缓冲数据类型。
- *
- * A GLenum specifying the type of the values in the element array buffer. Possible values are:
- *
- * * gl.UNSIGNED_BYTE
- * * gl.UNSIGNED_SHORT
- *
- * When using the OES_element_index_uint extension:
- *
- * * gl.UNSIGNED_INT
- *
- * @see https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/drawElements
- */
-export type IGLDrawElementType = "UNSIGNED_BYTE" | "UNSIGNED_SHORT" | "UNSIGNED_INT";
diff --git a/src/data/IGLUniforms.ts b/src/data/IGLUniforms.ts
index ff2cac4..878a22b 100644
--- a/src/data/IGLUniforms.ts
+++ b/src/data/IGLUniforms.ts
@@ -1,4 +1,4 @@
-import { IGLBuffer } from "./IGLBuffer";
+import { IGLUniformBuffer } from "./IGLBuffer";
import { IGLSamplerTexture } from "./IGLSamplerTexture";
/**
@@ -6,11 +6,6 @@ import { IGLSamplerTexture } from "./IGLSamplerTexture";
*/
export type IGLUniformType = IGLSamplerTexture | IGLSamplerTexture[] | number | number[] | Float32Array | (number[] | Float32Array)[] | Int32Array | IGLUniformBuffer | IGLUniforms;
-export interface IGLUniformBuffer extends IGLBuffer
-{
- target: "UNIFORM_BUFFER";
-}
-
/**
* Uniform 数据
*/
diff --git a/src/index.ts b/src/index.ts
index c572262..040492f 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -5,7 +5,6 @@ export * from "./data/IGLCapabilities";
export * from "./data/IGLCommandEncoder";
export * from "./data/IGLCopyBufferToBuffer";
export * from "./data/IGLDepthStencilState";
-export * from "./data/IGLIndexBuffer";
export * from "./data/IGLOcclusionQuery";
export * from "./data/IGLPrimitiveState";
export * from "./data/IGLReadPixels";
diff --git a/src/runs/getIGLBuffer.ts b/src/runs/getIGLBuffer.ts
index abda1cc..75654e6 100644
--- a/src/runs/getIGLBuffer.ts
+++ b/src/runs/getIGLBuffer.ts
@@ -1,6 +1,5 @@
import { IIndicesDataTypes, IVertexDataTypes } from "@feng3d/render-api";
-import { GLBufferTarget, GLBufferUsage, IGLBuffer, IGLVertexBuffer } from "../data/IGLBuffer";
-import { IGLIndexBuffer } from "../data/IGLIndexBuffer";
+import { GLBufferTarget, GLBufferUsage, IGLBuffer, IGLIndexBuffer, IGLVertexBuffer } from "../data/IGLBuffer";
export function getIGLBuffer(data: BufferSource, target?: GLBufferTarget, usage: GLBufferUsage = "STATIC_DRAW")
{
--
Gitee
From b4c246fc7f6d02ef1339f4ac614262710242ad92 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 20:34:37 +0800
Subject: [PATCH 149/186] IWriteBuffer
---
src/caches/getGLBuffer.ts | 13 +++++++------
src/data/IGLBuffer.ts | 28 ++++------------------------
src/runs/getIGLBuffer.ts | 4 ++--
3 files changed, 13 insertions(+), 32 deletions(-)
diff --git a/src/caches/getGLBuffer.ts b/src/caches/getGLBuffer.ts
index 8776fc7..9b0aabf 100644
--- a/src/caches/getGLBuffer.ts
+++ b/src/caches/getGLBuffer.ts
@@ -62,17 +62,18 @@ export function getGLBuffer(gl: WebGLRenderingContext, buffer: IGLBuffer)
{
const bufferOffset = writeBuffer.bufferOffset || 0;
const data = writeBuffer.data;
- const dataOffset = writeBuffer.dataOffset || 0;
- const size = writeBuffer.size || 0;
-
- if (gl instanceof WebGL2RenderingContext)
+ const dataOffset = writeBuffer.dataOffset ?? 0;
+ //
+ let arrayBufferView: Uint8Array;
+ if ("buffer" in data)
{
- gl.bufferSubData(gl[target], bufferOffset, data, dataOffset, size);
+ arrayBufferView = new Uint8Array(data.buffer, data.byteOffset + dataOffset * data.BYTES_PER_ELEMENT, (data.length - dataOffset) * data.BYTES_PER_ELEMENT);
}
else
{
- gl.bufferSubData(gl[target], bufferOffset, data);
+ arrayBufferView = new Uint8Array(data, dataOffset, data.byteLength - dataOffset);
}
+ gl.bufferSubData(gl[target], bufferOffset, arrayBufferView);
});
buffer.writeBuffers = null;
}
diff --git a/src/data/IGLBuffer.ts b/src/data/IGLBuffer.ts
index 93e03bc..e8b1738 100644
--- a/src/data/IGLBuffer.ts
+++ b/src/data/IGLBuffer.ts
@@ -7,33 +7,14 @@ import { IBuffer, IIndicesDataTypes, IVertexDataTypes } from "@feng3d/render-api
*/
export interface IGLBuffer extends IBuffer
{
- target: GLBufferTarget;
+ target: IGLBufferTarget;
/**
* 为优化目的指定数据存储的预期使用模式的GLenum。
*
* 默认为 "STATIC_DRAW"。
*/
- usage?: GLBufferUsage;
-
- /**
- * 写缓冲区。
- */
- writeBuffers?: IGLWriteBuffer[];
-}
-
-export interface IGLWriteBuffer
-{
- bufferOffset?: number;
-
- /**
- * 写入缓冲区数据。
- */
- data: ArrayBufferView;
-
- dataOffset?: number
-
- size?: number
+ usage?: IGLBufferUsage;
}
export interface IGLVertexBuffer extends IGLBuffer
@@ -103,7 +84,7 @@ export type IGLDrawElementType = "UNSIGNED_BYTE" | "UNSIGNED_SHORT" | "UNSIGNED_
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData
*/
-export type GLBufferUsage = "STATIC_DRAW" | "DYNAMIC_DRAW" | "STREAM_DRAW" // WebGL1
+export type IGLBufferUsage = "STATIC_DRAW" | "DYNAMIC_DRAW" | "STREAM_DRAW" // WebGL1
| "STATIC_READ" | "DYNAMIC_READ" | "STREAM_READ" | "STATIC_COPY" | "DYNAMIC_COPY" | "STREAM_COPY" // WebGL2
;
@@ -122,7 +103,6 @@ export type GLBufferUsage = "STATIC_DRAW" | "DYNAMIC_DRAW" | "STREAM_DRAW" // We
* * gl.PIXEL_UNPACK_BUFFER: Buffer used for pixel transfer operations.
*
*/
-export type GLBufferTarget = "ARRAY_BUFFER" | "ELEMENT_ARRAY_BUFFER" // WebGL1
+export type IGLBufferTarget = "ARRAY_BUFFER" | "ELEMENT_ARRAY_BUFFER" // WebGL1
| "COPY_READ_BUFFER" | "COPY_WRITE_BUFFER" | "TRANSFORM_FEEDBACK_BUFFER"// WebGL2
| "UNIFORM_BUFFER" | "PIXEL_PACK_BUFFER" | "PIXEL_UNPACK_BUFFER"; // WebGL2
-// export type GLBufferTarget = "ARRAY_BUFFER" | "ELEMENT_ARRAY_BUFFER" | "UNIFORM_BUFFER";
\ No newline at end of file
diff --git a/src/runs/getIGLBuffer.ts b/src/runs/getIGLBuffer.ts
index 75654e6..a167709 100644
--- a/src/runs/getIGLBuffer.ts
+++ b/src/runs/getIGLBuffer.ts
@@ -1,7 +1,7 @@
import { IIndicesDataTypes, IVertexDataTypes } from "@feng3d/render-api";
-import { GLBufferTarget, GLBufferUsage, IGLBuffer, IGLIndexBuffer, IGLVertexBuffer } from "../data/IGLBuffer";
+import { IGLBufferTarget, IGLBufferUsage, IGLBuffer, IGLIndexBuffer, IGLVertexBuffer } from "../data/IGLBuffer";
-export function getIGLBuffer(data: BufferSource, target?: GLBufferTarget, usage: GLBufferUsage = "STATIC_DRAW")
+export function getIGLBuffer(data: BufferSource, target?: IGLBufferTarget, usage: IGLBufferUsage = "STATIC_DRAW")
{
if (data[_IGLBuffer]) return data[_IGLBuffer];
--
Gitee
From b093e9d29ad5c83b5b6a2aca0951eb19a9960e16 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 20:36:31 +0800
Subject: [PATCH 150/186] getFramebuffer ->getGLFramebuffer
---
src/RunWebGL.ts | 8 ++++----
src/WebGL.ts | 2 +-
src/caches/{getFramebuffer.ts => getGLFramebuffer.ts} | 2 +-
src/utils/readPixels.ts | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)
rename src/caches/{getFramebuffer.ts => getGLFramebuffer.ts} (98%)
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 131be2e..d70f91e 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,6 +1,6 @@
import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, IScissorRect, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport } from "@feng3d/render-api";
-import { getFramebuffer } from "./caches/getFramebuffer";
+import { getGLFramebuffer } from "./caches/getGLFramebuffer";
import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLProgram } from "./caches/getGLProgram";
import { getGLRenderOcclusionQuery } from "./caches/getGLRenderOcclusionQuery";
@@ -164,7 +164,7 @@ export class RunWebGL
const colorAttachment = Object.assign({}, defaultRenderPassColorAttachment, passDescriptor.colorAttachments?.[0]);
//
- const framebuffer = getFramebuffer(gl, passDescriptor);
+ const framebuffer = getGLFramebuffer(gl, passDescriptor);
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
//
@@ -884,8 +884,8 @@ export class RunWebGL
{
const { read, draw, blitFramebuffers } = blitFramebuffer;
- const readFramebuffer = getFramebuffer(gl, read);
- const drawFramebuffer = getFramebuffer(gl, draw);
+ const readFramebuffer = getGLFramebuffer(gl, read);
+ const drawFramebuffer = getGLFramebuffer(gl, draw);
if (gl instanceof WebGL2RenderingContext)
{
diff --git a/src/WebGL.ts b/src/WebGL.ts
index adf9a7c..9186350 100644
--- a/src/WebGL.ts
+++ b/src/WebGL.ts
@@ -1,9 +1,9 @@
import { IRenderPassDescriptor, IRenderPipeline, ISubmit, ITexture } from "@feng3d/render-api";
import { RunWebGL } from "./RunWebGL";
-import { deleteFramebuffer } from "./caches/getFramebuffer";
import { deleteBuffer } from "./caches/getGLBuffer";
import { getGLCanvasContext } from "./caches/getGLCanvasContext";
+import { deleteFramebuffer } from "./caches/getGLFramebuffer";
import { deleteProgram } from "./caches/getGLProgram";
import { deleteRenderbuffer } from "./caches/getGLRenderbuffer";
import { deleteSampler } from "./caches/getGLSampler";
diff --git a/src/caches/getFramebuffer.ts b/src/caches/getGLFramebuffer.ts
similarity index 98%
rename from src/caches/getFramebuffer.ts
rename to src/caches/getGLFramebuffer.ts
index 5ef1b80..39e1891 100644
--- a/src/caches/getFramebuffer.ts
+++ b/src/caches/getGLFramebuffer.ts
@@ -16,7 +16,7 @@ declare global
/**
* 获取帧缓冲区
*/
-export function getFramebuffer(gl: WebGLRenderingContext, passDescriptor: IRenderPassDescriptor)
+export function getGLFramebuffer(gl: WebGLRenderingContext, passDescriptor: IRenderPassDescriptor)
{
const view = passDescriptor?.colorAttachments?.[0]?.view || passDescriptor?.depthStencilAttachment?.view;
if (!view || !view.texture) return null;
diff --git a/src/utils/readPixels.ts b/src/utils/readPixels.ts
index 4be4b30..058272d 100644
--- a/src/utils/readPixels.ts
+++ b/src/utils/readPixels.ts
@@ -1,4 +1,4 @@
-import { getFramebuffer } from "../caches/getFramebuffer";
+import { getGLFramebuffer } from "../caches/getGLFramebuffer";
import { IGLReadPixels } from "../data/IGLReadPixels";
export function readPixels(gl: WebGLRenderingContext, readPixels: IGLReadPixels)
@@ -7,7 +7,7 @@ export function readPixels(gl: WebGLRenderingContext, readPixels: IGLReadPixels)
{
const { frameBuffer, attachmentPoint, x, y, width, height, format, type, dstData, dstOffset } = readPixels;
- const webGLFramebuffer = getFramebuffer(gl, frameBuffer);
+ const webGLFramebuffer = getGLFramebuffer(gl, frameBuffer);
gl.bindFramebuffer(gl.FRAMEBUFFER, webGLFramebuffer);
gl.readBuffer(gl[attachmentPoint]);
--
Gitee
From 4f251c9621e9ce0d98ce00bee480ba45746eb4e1 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 20:47:10 +0800
Subject: [PATCH 151/186] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/caches/getGLFramebuffer.ts | 2 +-
src/caches/getIGLBlitFramebuffer.ts | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/caches/getGLFramebuffer.ts b/src/caches/getGLFramebuffer.ts
index 39e1891..7c31e00 100644
--- a/src/caches/getGLFramebuffer.ts
+++ b/src/caches/getGLFramebuffer.ts
@@ -19,7 +19,7 @@ declare global
export function getGLFramebuffer(gl: WebGLRenderingContext, passDescriptor: IRenderPassDescriptor)
{
const view = passDescriptor?.colorAttachments?.[0]?.view || passDescriptor?.depthStencilAttachment?.view;
- if (!view || !view.texture) return null;
+ if (!view) return null;
let webGLFramebuffer = gl._framebuffers.get(passDescriptor);
if (webGLFramebuffer) return webGLFramebuffer;
diff --git a/src/caches/getIGLBlitFramebuffer.ts b/src/caches/getIGLBlitFramebuffer.ts
index 23f8720..42755ab 100644
--- a/src/caches/getIGLBlitFramebuffer.ts
+++ b/src/caches/getIGLBlitFramebuffer.ts
@@ -69,6 +69,8 @@ export function getIGLBlitFramebuffer(copyTextureToTexture: ICopyTextureToTextur
function getIGLTextureView(source: IImageCopyTexture)
{
+ if (!source.texture) return undefined;
+
const textureView: ITextureView = {
texture: source.texture,
baseMipLevel: source.mipLevel,
--
Gitee
From 9f7e197d9f060106154bc55209f02c518a346b4b Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 21:09:47 +0800
Subject: [PATCH 152/186] getIGLBuffer
---
src/runs/getIGLBuffer.ts | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/runs/getIGLBuffer.ts b/src/runs/getIGLBuffer.ts
index a167709..d6237e2 100644
--- a/src/runs/getIGLBuffer.ts
+++ b/src/runs/getIGLBuffer.ts
@@ -1,16 +1,19 @@
-import { IIndicesDataTypes, IVertexDataTypes } from "@feng3d/render-api";
-import { IGLBufferTarget, IGLBufferUsage, IGLBuffer, IGLIndexBuffer, IGLVertexBuffer } from "../data/IGLBuffer";
+import { IIndicesDataTypes, IVertexDataTypes, TypedArray } from "@feng3d/render-api";
+import { IGLBuffer, IGLBufferTarget, IGLBufferUsage, IGLIndexBuffer, IGLVertexBuffer } from "../data/IGLBuffer";
-export function getIGLBuffer(data: BufferSource, target?: IGLBufferTarget, usage: IGLBufferUsage = "STATIC_DRAW")
+export function getIGLBuffer(data: TypedArray, target?: IGLBufferTarget, usage: IGLBufferUsage = "STATIC_DRAW")
{
if (data[_IGLBuffer]) return data[_IGLBuffer];
console.assert(!!target, `初始化时不能为空,可能该数据的渲染对象还未被渲染!`);
- const indexBuffer: IGLBuffer = data[_IGLBuffer] = {
- target: target, usage: usage,
+ const indexBuffer: IGLBuffer = {
+ size: data.byteLength,
+ target: target,
+ usage: usage,
data: data,
- } as IGLBuffer;
+ };
+ data[_IGLBuffer] = indexBuffer;
return indexBuffer;
}
--
Gitee
From 820033735130e21f97332ad5f19e6e3999daa4a2 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 21:35:17 +0800
Subject: [PATCH 153/186] getGLBuffer
---
src/caches/getGLBuffer.ts | 79 ++++++++++++++++++---------------------
1 file changed, 36 insertions(+), 43 deletions(-)
diff --git a/src/caches/getGLBuffer.ts b/src/caches/getGLBuffer.ts
index 9b0aabf..55f2a26 100644
--- a/src/caches/getGLBuffer.ts
+++ b/src/caches/getGLBuffer.ts
@@ -27,66 +27,59 @@ export function getGLBuffer(gl: WebGLRenderingContext, buffer: IGLBuffer)
const target = buffer.target;
- const updateBuffer = () =>
- {
- // 获取
- const data = buffer.data;
- const size = buffer.size;
- const usage = buffer.usage || "STATIC_DRAW";
+ const size = buffer.size;
+ const usage = buffer.usage || "STATIC_DRAW";
- // 上传数据到WebGL
- gl.bindBuffer(gl[target], webGLBuffer);
-
- if (data)
- {
- gl.bufferData(gl[target], data, gl[usage]);
- }
- else if (size)
- {
- gl.bufferData(gl[target], size, gl[usage]);
- }
- else
- {
- console.log(`初始化缓冲区时必须提供数据或者尺寸!`);
- }
- };
+ // 上传数据到WebGL
+ gl.bindBuffer(gl[target], webGLBuffer);
+ gl.bufferData(gl[target], size, gl[usage]);
const writeBuffer = () =>
{
const writeBuffers = buffer.writeBuffers;
- if (writeBuffers)
+ if (!writeBuffers) return;
+
+ gl.bindBuffer(gl[target], webGLBuffer);
+ writeBuffers.forEach((writeBuffer) =>
{
- gl.bindBuffer(gl[target], webGLBuffer);
- writeBuffers.forEach((writeBuffer) =>
+ const bufferOffset = writeBuffer.bufferOffset ?? 0;
+ const data = writeBuffer.data;
+ const dataOffset = writeBuffer.dataOffset ?? 0;
+ //
+ let arrayBufferView: Uint8Array;
+ if ("buffer" in data)
{
- const bufferOffset = writeBuffer.bufferOffset || 0;
- const data = writeBuffer.data;
- const dataOffset = writeBuffer.dataOffset ?? 0;
- //
- let arrayBufferView: Uint8Array;
- if ("buffer" in data)
- {
- arrayBufferView = new Uint8Array(data.buffer, data.byteOffset + dataOffset * data.BYTES_PER_ELEMENT, (data.length - dataOffset) * data.BYTES_PER_ELEMENT);
- }
- else
- {
- arrayBufferView = new Uint8Array(data, dataOffset, data.byteLength - dataOffset);
- }
- gl.bufferSubData(gl[target], bufferOffset, arrayBufferView);
- });
- buffer.writeBuffers = null;
- }
+ arrayBufferView = new Uint8Array(
+ data.buffer,
+ data.byteOffset + dataOffset * data.BYTES_PER_ELEMENT,
+ (data.length - dataOffset) * data.BYTES_PER_ELEMENT
+ );
+ }
+ else
+ {
+ arrayBufferView = new Uint8Array(
+ data,
+ dataOffset,
+ data.byteLength - dataOffset
+ );
+ }
+ gl.bufferSubData(gl[target], bufferOffset, arrayBufferView);
+ });
+ buffer.writeBuffers = null;
};
const dataChange = () =>
{
+ if (!buffer.data) return;
+
const writeBuffers = buffer.writeBuffers || [];
writeBuffers.push({ data: buffer.data });
buffer.writeBuffers = writeBuffers;
};
- updateBuffer();
+ dataChange();
+ writeBuffer();
//
watcher.watch(buffer, "data", dataChange);
--
Gitee
From 07042a1c38a054e1c520cd2fd67edf2c3b19451e Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 19 Dec 2024 21:57:06 +0800
Subject: [PATCH 154/186] IGLBuffer -> IBuffer
---
src/RunWebGL.ts | 8 ++++----
src/WebGL.ts | 5 ++---
src/caches/getGLBuffer.ts | 8 ++++----
src/data/IGLBuffer.ts | 31 +++++++++++++++++--------------
src/data/IGLCopyBufferToBuffer.ts | 6 +++---
src/runs/getIGLBuffer.ts | 6 +++---
6 files changed, 33 insertions(+), 31 deletions(-)
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index d70f91e..39019b6 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,7 +1,7 @@
-import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, IScissorRect, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IBuffer, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, IScissorRect, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport } from "@feng3d/render-api";
-import { getGLFramebuffer } from "./caches/getGLFramebuffer";
import { getGLBuffer } from "./caches/getGLBuffer";
+import { getGLFramebuffer } from "./caches/getGLFramebuffer";
import { getGLProgram } from "./caches/getGLProgram";
import { getGLRenderOcclusionQuery } from "./caches/getGLRenderOcclusionQuery";
import { getGLSampler } from "./caches/getGLSampler";
@@ -13,7 +13,7 @@ import { getIGLTextureTarget } from "./caches/getIGLTextureTarget";
import { _GL_Submit_Times } from "./const/const";
import { IGLUniformBufferType } from "./const/IGLUniformType";
import { IGLBlitFramebuffer } from "./data/IGLBlitFramebuffer";
-import { IGLBuffer, IGLDrawElementType } from "./data/IGLBuffer";
+import { IGLDrawElementType } from "./data/IGLBuffer";
import { IGLCopyBufferToBuffer } from "./data/IGLCopyBufferToBuffer";
import { IGLCompareFunction, IGLStencilFunc, IGLStencilOp } from "./data/IGLDepthStencilState";
import { IGLOcclusionQuery } from "./data/IGLOcclusionQuery";
@@ -361,7 +361,7 @@ export class RunWebGL
const uniformData = lazy.getValue(uniforms[name], uniforms);
//
- const webGLBuffer = getGLBuffer(gl, uniformData as IGLBuffer);
+ const webGLBuffer = getGLBuffer(gl, uniformData as IBuffer);
gl.bindBufferBase(gl.UNIFORM_BUFFER, index, webGLBuffer);
});
}
diff --git a/src/WebGL.ts b/src/WebGL.ts
index 9186350..caef269 100644
--- a/src/WebGL.ts
+++ b/src/WebGL.ts
@@ -1,4 +1,4 @@
-import { IRenderPassDescriptor, IRenderPipeline, ISubmit, ITexture } from "@feng3d/render-api";
+import { IBuffer, IRenderPassDescriptor, IRenderPipeline, ISubmit, ITexture } from "@feng3d/render-api";
import { RunWebGL } from "./RunWebGL";
import { deleteBuffer } from "./caches/getGLBuffer";
@@ -9,7 +9,6 @@ import { deleteRenderbuffer } from "./caches/getGLRenderbuffer";
import { deleteSampler } from "./caches/getGLSampler";
import { deleteTexture } from "./caches/getGLTexture";
import { deleteTransformFeedback } from "./caches/getGLTransformFeedback";
-import { IGLBuffer } from "./data/IGLBuffer";
import { IGLCanvasContext } from "./data/IGLCanvasContext";
import { IGLReadPixels } from "./data/IGLReadPixels";
import { IGLRenderbuffer } from "./data/IGLRenderbuffer";
@@ -60,7 +59,7 @@ export class WebGL
deleteRenderbuffer(this._gl, renderbuffer);
}
- deleteBuffer(buffer: IGLBuffer)
+ deleteBuffer(buffer: IBuffer)
{
deleteBuffer(this._gl, buffer);
}
diff --git a/src/caches/getGLBuffer.ts b/src/caches/getGLBuffer.ts
index 55f2a26..7eadd51 100644
--- a/src/caches/getGLBuffer.ts
+++ b/src/caches/getGLBuffer.ts
@@ -1,11 +1,11 @@
+import { IBuffer } from "@feng3d/render-api";
import { watcher } from "@feng3d/watcher";
-import { IGLBuffer } from "../data/IGLBuffer";
declare global
{
interface WebGLRenderingContext
{
- _buffers: Map
+ _buffers: Map
}
interface WebGLBuffer
@@ -17,7 +17,7 @@ declare global
}
}
-export function getGLBuffer(gl: WebGLRenderingContext, buffer: IGLBuffer)
+export function getGLBuffer(gl: WebGLRenderingContext, buffer: IBuffer)
{
let webGLBuffer = gl._buffers.get(buffer);
if (webGLBuffer) return webGLBuffer;
@@ -95,7 +95,7 @@ export function getGLBuffer(gl: WebGLRenderingContext, buffer: IGLBuffer)
return webGLBuffer;
}
-export function deleteBuffer(gl: WebGLRenderingContext, buffer: IGLBuffer)
+export function deleteBuffer(gl: WebGLRenderingContext, buffer: IBuffer)
{
const webGLBuffer = gl._buffers.get(buffer);
if (webGLBuffer)
diff --git a/src/data/IGLBuffer.ts b/src/data/IGLBuffer.ts
index e8b1738..46a9336 100644
--- a/src/data/IGLBuffer.ts
+++ b/src/data/IGLBuffer.ts
@@ -1,23 +1,26 @@
import { IBuffer, IIndicesDataTypes, IVertexDataTypes } from "@feng3d/render-api";
-/**
- * WebGL缓冲区
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData
- */
-export interface IGLBuffer extends IBuffer
+declare module "@feng3d/render-api"
{
- target: IGLBufferTarget;
-
/**
- * 为优化目的指定数据存储的预期使用模式的GLenum。
+ * WebGL缓冲区
*
- * 默认为 "STATIC_DRAW"。
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData
*/
- usage?: IGLBufferUsage;
+ export interface IBuffer
+ {
+ target: IGLBufferTarget;
+
+ /**
+ * 为优化目的指定数据存储的预期使用模式的GLenum。
+ *
+ * 默认为 "STATIC_DRAW"。
+ */
+ usage?: IGLBufferUsage;
+ }
}
-export interface IGLVertexBuffer extends IGLBuffer
+export interface IGLVertexBuffer extends IBuffer
{
target: "ARRAY_BUFFER";
@@ -35,7 +38,7 @@ export interface IGLVertexBuffer extends IGLBuffer
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bindBuffer
*
*/
-export interface IGLIndexBuffer extends IGLBuffer
+export interface IGLIndexBuffer extends IBuffer
{
target: "ELEMENT_ARRAY_BUFFER";
@@ -45,7 +48,7 @@ export interface IGLIndexBuffer extends IGLBuffer
data: IIndicesDataTypes;
}
-export interface IGLUniformBuffer extends IGLBuffer
+export interface IGLUniformBuffer extends IBuffer
{
target: "UNIFORM_BUFFER";
}
diff --git a/src/data/IGLCopyBufferToBuffer.ts b/src/data/IGLCopyBufferToBuffer.ts
index e18edf8..c321676 100644
--- a/src/data/IGLCopyBufferToBuffer.ts
+++ b/src/data/IGLCopyBufferToBuffer.ts
@@ -1,4 +1,4 @@
-import { IGLBuffer } from "./IGLBuffer";
+import { IBuffer } from "@feng3d/render-api";
/**
* GL缓冲区之间拷贝。
@@ -14,7 +14,7 @@ export interface IGLCopyBufferToBuffer
/**
* 源缓冲区。
*/
- source: IGLBuffer,
+ source: IBuffer,
/**
* 默认为0。
*/
@@ -22,7 +22,7 @@ export interface IGLCopyBufferToBuffer
/**
* 目标缓冲区。
*/
- destination: IGLBuffer,
+ destination: IBuffer,
/**
* 默认为0。
*/
diff --git a/src/runs/getIGLBuffer.ts b/src/runs/getIGLBuffer.ts
index d6237e2..b580730 100644
--- a/src/runs/getIGLBuffer.ts
+++ b/src/runs/getIGLBuffer.ts
@@ -1,5 +1,5 @@
-import { IIndicesDataTypes, IVertexDataTypes, TypedArray } from "@feng3d/render-api";
-import { IGLBuffer, IGLBufferTarget, IGLBufferUsage, IGLIndexBuffer, IGLVertexBuffer } from "../data/IGLBuffer";
+import { IBuffer, IIndicesDataTypes, IVertexDataTypes, TypedArray } from "@feng3d/render-api";
+import { IGLBufferTarget, IGLBufferUsage, IGLIndexBuffer, IGLVertexBuffer } from "../data/IGLBuffer";
export function getIGLBuffer(data: TypedArray, target?: IGLBufferTarget, usage: IGLBufferUsage = "STATIC_DRAW")
{
@@ -7,7 +7,7 @@ export function getIGLBuffer(data: TypedArray, target?: IGLBufferTarget, usage:
console.assert(!!target, `初始化时不能为空,可能该数据的渲染对象还未被渲染!`);
- const indexBuffer: IGLBuffer = {
+ const indexBuffer: IBuffer = {
size: data.byteLength,
target: target,
usage: usage,
--
Gitee
From 277bc2221adaca23c1af8961570ed3ec91ef37f5 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 20 Dec 2024 20:49:49 +0800
Subject: [PATCH 155/186] =?UTF-8?q?IBuffer.size=20=E5=B0=BA=E5=AF=B8?=
=?UTF-8?q?=E5=BF=85=E9=A1=BB=E4=B8=BA4=E7=9A=84=E5=80=8D=E6=95=B0?=
=?UTF-8?q?=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/runs/getIGLBuffer.ts | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/runs/getIGLBuffer.ts b/src/runs/getIGLBuffer.ts
index b580730..b830f5e 100644
--- a/src/runs/getIGLBuffer.ts
+++ b/src/runs/getIGLBuffer.ts
@@ -7,15 +7,15 @@ export function getIGLBuffer(data: TypedArray, target?: IGLBufferTarget, usage:
console.assert(!!target, `初始化时不能为空,可能该数据的渲染对象还未被渲染!`);
- const indexBuffer: IBuffer = {
- size: data.byteLength,
+ const buffer: IBuffer = {
+ size: Math.ceil(data.byteLength / 4) * 4,
target: target,
usage: usage,
data: data,
};
- data[_IGLBuffer] = indexBuffer;
+ data[_IGLBuffer] = buffer;
- return indexBuffer;
+ return buffer;
}
export function getIGLVertexBuffer(data: IVertexDataTypes, usage?: "STREAM_COPY")
--
Gitee
From 2c66f8bc8f7c67cf54bcc381c6798ee3005555a0 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 2 Jan 2025 12:00:52 +0800
Subject: [PATCH 156/186] ISampler
---
src/data/IGLSampler.ts | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/data/IGLSampler.ts b/src/data/IGLSampler.ts
index b5cb689..fb8717c 100644
--- a/src/data/IGLSampler.ts
+++ b/src/data/IGLSampler.ts
@@ -1,6 +1,7 @@
+import { ISampler } from "@feng3d/render-api";
import { IGLCompareFunction } from "./IGLDepthStencilState";
-export interface IGLSampler
+export interface IGLSampler extends ISampler
{
/**
* 默认 "LINEAR_MIPMAP_LINEAR" 。
@@ -13,21 +14,23 @@ export interface IGLSampler
magFilter?: IGLTextureMagFilter;
/**
- * 表示x轴的纹理的回环方式,就是当纹理的宽度小于需要贴图的平面的宽度的时候,平面剩下的部分应该p以何种方式贴图的问题。
+ * 用于指定纹理在S轴(即水平方向或U坐标轴)上的环绕方式。
*
* 默认 "REPEAT"。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_wrap_s
*/
wrapS?: IGLTextureWrap;
/**
- * 表示y轴的纹理回环方式。 magFilter和minFilter表示过滤的方式。
+ * 用于指定纹理在T轴(即垂直方向或V坐标轴)上的环绕方式。
*
* 默认 "REPEAT"。
*/
wrapT?: IGLTextureWrap;
/**
- * 表示y轴的纹理回环方式。 magFilter和minFilter表示过滤的方式。
+ * 用于指定纹理在R轴(即深度方向或W坐标轴)上的环绕方式。用于3D纹理或者纹理数组。
*
* 默认 "REPEAT"。
*/
@@ -58,6 +61,7 @@ export interface IGLSampler
* 默认 "NONE"。
*/
compareMode?: IGLSamplerCompareMode;
+
/**
* 比较函数。
*
--
Gitee
From 8f4197d04a4908440df29897aff997205c318a57 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 2 Jan 2025 12:08:59 +0800
Subject: [PATCH 157/186] IGLSampler.wrapU wrapV wrapW
---
.../src/WebGL2Samples/fbo_rtt_depth_texture.ts | 2 +-
.../src/WebGL2Samples/fbo_rtt_draw_buffers.ts | 4 ++--
.../src/WebGL2Samples/geo_vertex_format.ts | 4 ++--
examples/src/WebGL2Samples/sampler_filter.ts | 2 +-
examples/src/WebGL2Samples/sampler_object.ts | 4 ++--
examples/src/WebGL2Samples/sampler_wrap.ts | 18 +++++++++---------
.../src/WebGL2Samples/texture_derivative.ts | 4 ++--
examples/src/WebGL2Samples/texture_grad.ts | 4 ++--
.../src/WebGL2Samples/texture_immutable.ts | 4 ++--
examples/src/WebGL2Samples/texture_offset.ts | 4 ++--
examples/src/WebGL2Samples/texture_vertex.ts | 4 ++--
examples/src/regl-examples/cloth.ts | 2 +-
examples/src/webgl-examples/sample6.ts | 2 +-
examples/src/webgl-examples/sample7.ts | 2 +-
examples/src/webgl-examples/sample8.ts | 2 +-
src/RunWebGL.ts | 4 ++--
src/caches/getGLSampler.ts | 6 +++---
src/data/IGLSampler.ts | 10 +++++++---
18 files changed, 43 insertions(+), 39 deletions(-)
diff --git a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
index 8deb449..815c0da 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
@@ -80,7 +80,7 @@ const depthTexture: ITexture = {
size: [windowSize.x, windowSize.y],
format: "depth16unorm",
};
-const depthSampler: IGLSampler = { wrapS: "CLAMP_TO_EDGE", wrapT: "CLAMP_TO_EDGE", minFilter: "NEAREST", magFilter: "NEAREST" };
+const depthSampler: IGLSampler = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", minFilter: "NEAREST", magFilter: "NEAREST" };
// -- Initialize frame buffer
diff --git a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
index 8296479..42b03aa 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
@@ -79,13 +79,13 @@ const color1Texture: ITexture = {
format: "rgba8unorm",
size: [windowSize.x, windowSize.y],
};
-const color1Sampler: IGLSampler = { wrapS: "CLAMP_TO_EDGE", wrapT: "CLAMP_TO_EDGE", minFilter: "NEAREST", magFilter: "NEAREST" };
+const color1Sampler: IGLSampler = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", minFilter: "NEAREST", magFilter: "NEAREST" };
const color2Texture: ITexture = {
format: "rgba8unorm",
size: [windowSize.x, windowSize.y],
};
-const color2Sampler: IGLSampler = { wrapS: "CLAMP_TO_EDGE", wrapT: "CLAMP_TO_EDGE", minFilter: "NEAREST", magFilter: "NEAREST" };
+const color2Sampler: IGLSampler = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", minFilter: "NEAREST", magFilter: "NEAREST" };
// -- Initialize frame buffer
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index 328b71c..488aa93 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -176,8 +176,8 @@ import { getShaderSource, loadImage } from "./utility";
sampler = {
minFilter: "NEAREST",
magFilter: "NEAREST",
- wrapS: "CLAMP_TO_EDGE",
- wrapT: "CLAMP_TO_EDGE",
+ wrapU: "CLAMP_TO_EDGE",
+ wrapV: "CLAMP_TO_EDGE",
};
requestAnimationFrame(render);
diff --git a/examples/src/WebGL2Samples/sampler_filter.ts b/examples/src/WebGL2Samples/sampler_filter.ts
index ae51f13..7c8b851 100644
--- a/examples/src/WebGL2Samples/sampler_filter.ts
+++ b/examples/src/WebGL2Samples/sampler_filter.ts
@@ -97,7 +97,7 @@ const vertexArray: { vertices?: IVertexAttributes } = {
const samplers: IGLSampler[] = new Array(Corners.MAX);
for (let i = 0; i < Corners.MAX; ++i)
{
- samplers[i] = { wrapS: "CLAMP_TO_EDGE", wrapT: "CLAMP_TO_EDGE", wrapR: "CLAMP_TO_EDGE" };
+ samplers[i] = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", wrapW: "CLAMP_TO_EDGE" };
}
// Min filter
diff --git a/examples/src/WebGL2Samples/sampler_object.ts b/examples/src/WebGL2Samples/sampler_object.ts
index 03a5021..111bc36 100644
--- a/examples/src/WebGL2Samples/sampler_object.ts
+++ b/examples/src/WebGL2Samples/sampler_object.ts
@@ -52,13 +52,13 @@ const vertexArray: { vertices?: IVertexAttributes } = {
const samplerA: IGLSampler = {
minFilter: "NEAREST_MIPMAP_NEAREST", magFilter: "NEAREST",
- wrapS: "CLAMP_TO_EDGE", wrapT: "CLAMP_TO_EDGE", wrapR: "CLAMP_TO_EDGE",
+ wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", wrapW: "CLAMP_TO_EDGE",
lodMinClamp: -1000.0, lodMaxClamp: 1000.0,
compareMode: "NONE", compare: "LEQUAL",
};
const samplerB: IGLSampler = {
minFilter: "LINEAR_MIPMAP_LINEAR", magFilter: "LINEAR",
- wrapS: "CLAMP_TO_EDGE", wrapT: "CLAMP_TO_EDGE", wrapR: "CLAMP_TO_EDGE",
+ wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", wrapW: "CLAMP_TO_EDGE",
lodMinClamp: -1000.0, lodMaxClamp: 1000.0,
compareMode: "NONE", compare: "LEQUAL",
};
diff --git a/examples/src/WebGL2Samples/sampler_wrap.ts b/examples/src/WebGL2Samples/sampler_wrap.ts
index 6ffa101..725237b 100644
--- a/examples/src/WebGL2Samples/sampler_wrap.ts
+++ b/examples/src/WebGL2Samples/sampler_wrap.ts
@@ -101,15 +101,15 @@ for (let i = 0; i < Corners.MAX; ++i)
samplers[i] = { minFilter: "LINEAR_MIPMAP_LINEAR", magFilter: "LINEAR" };
}
-samplers[Corners.TOP_LEFT].wrapS = "MIRRORED_REPEAT";
-samplers[Corners.TOP_RIGHT].wrapS = "CLAMP_TO_EDGE";
-samplers[Corners.BOTTOM_RIGHT].wrapS = "REPEAT";
-samplers[Corners.BOTTOM_LEFT].wrapS = "CLAMP_TO_EDGE";
-
-samplers[Corners.TOP_LEFT].wrapT = "MIRRORED_REPEAT";
-samplers[Corners.TOP_RIGHT].wrapT = "MIRRORED_REPEAT";
-samplers[Corners.BOTTOM_RIGHT].wrapT = "REPEAT";
-samplers[Corners.BOTTOM_LEFT].wrapT = "CLAMP_TO_EDGE";
+samplers[Corners.TOP_LEFT].wrapU = "MIRRORED_REPEAT";
+samplers[Corners.TOP_RIGHT].wrapU = "CLAMP_TO_EDGE";
+samplers[Corners.BOTTOM_RIGHT].wrapU = "REPEAT";
+samplers[Corners.BOTTOM_LEFT].wrapU = "CLAMP_TO_EDGE";
+
+samplers[Corners.TOP_LEFT].wrapV = "MIRRORED_REPEAT";
+samplers[Corners.TOP_RIGHT].wrapV = "MIRRORED_REPEAT";
+samplers[Corners.BOTTOM_RIGHT].wrapV = "REPEAT";
+samplers[Corners.BOTTOM_LEFT].wrapV = "CLAMP_TO_EDGE";
// -- Load texture then render
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index f786ee1..639fa49 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -143,8 +143,8 @@ import { getShaderSource, loadImage } from "./utility";
sampler = {
minFilter: "NEAREST",
magFilter: "NEAREST",
- wrapS: "CLAMP_TO_EDGE",
- wrapT: "CLAMP_TO_EDGE",
+ wrapU: "CLAMP_TO_EDGE",
+ wrapV: "CLAMP_TO_EDGE",
};
// // -- Allocate storage for the texture
diff --git a/examples/src/WebGL2Samples/texture_grad.ts b/examples/src/WebGL2Samples/texture_grad.ts
index e6c9a88..d4f190e 100644
--- a/examples/src/WebGL2Samples/texture_grad.ts
+++ b/examples/src/WebGL2Samples/texture_grad.ts
@@ -137,8 +137,8 @@ import { getShaderSource, loadImage } from "./utility";
sampler = {
minFilter: "NEAREST",
magFilter: "NEAREST",
- wrapS: "CLAMP_TO_EDGE",
- wrapT: "CLAMP_TO_EDGE",
+ wrapU: "CLAMP_TO_EDGE",
+ wrapV: "CLAMP_TO_EDGE",
};
requestAnimationFrame(render);
diff --git a/examples/src/WebGL2Samples/texture_immutable.ts b/examples/src/WebGL2Samples/texture_immutable.ts
index f02f0d6..e096eae 100644
--- a/examples/src/WebGL2Samples/texture_immutable.ts
+++ b/examples/src/WebGL2Samples/texture_immutable.ts
@@ -94,8 +94,8 @@ import { getShaderSource, loadImage } from "./utility";
const sampler2D: IGLSampler = {
minFilter: "NEAREST",
magFilter: "LINEAR",
- wrapS: "CLAMP_TO_EDGE",
- wrapT: "CLAMP_TO_EDGE",
+ wrapU: "CLAMP_TO_EDGE",
+ wrapV: "CLAMP_TO_EDGE",
};
// -- Render
diff --git a/examples/src/WebGL2Samples/texture_offset.ts b/examples/src/WebGL2Samples/texture_offset.ts
index 238c6d0..223f027 100644
--- a/examples/src/WebGL2Samples/texture_offset.ts
+++ b/examples/src/WebGL2Samples/texture_offset.ts
@@ -80,8 +80,8 @@ import { getShaderSource, loadImage } from "./utility";
const sampler: IGLSampler = {
minFilter: "NEAREST",
magFilter: "NEAREST",
- wrapS: "CLAMP_TO_EDGE",
- wrapT: "CLAMP_TO_EDGE",
+ wrapU: "CLAMP_TO_EDGE",
+ wrapV: "CLAMP_TO_EDGE",
};
const renderObjects: IRenderPassObject[] = [];
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index ffd3ed7..4a455ea 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -116,8 +116,8 @@ import { getShaderSource, loadImage } from "./utility";
sampler = {
minFilter: "NEAREST",
magFilter: "NEAREST",
- wrapS: "CLAMP_TO_EDGE",
- wrapT: "CLAMP_TO_EDGE",
+ wrapU: "CLAMP_TO_EDGE",
+ wrapV: "CLAMP_TO_EDGE",
};
requestAnimationFrame(render);
diff --git a/examples/src/regl-examples/cloth.ts b/examples/src/regl-examples/cloth.ts
index 8b41c24..2cdcb86 100644
--- a/examples/src/regl-examples/cloth.ts
+++ b/examples/src/regl-examples/cloth.ts
@@ -390,7 +390,7 @@ import * as vec3 from "./stackgl/gl-vec3";
size: [img.width, img.height],
generateMipmap: true,
sources: [{ image: img }]
- }, sampler: { minFilter: "LINEAR_MIPMAP_LINEAR", wrapS: "REPEAT", wrapT: "REPEAT" }
+ }, sampler: { minFilter: "LINEAR_MIPMAP_LINEAR", wrapU: "REPEAT", wrapV: "REPEAT" }
};
draw();
diff --git a/examples/src/webgl-examples/sample6.ts b/examples/src/webgl-examples/sample6.ts
index 1a2ab35..9655a0e 100644
--- a/examples/src/webgl-examples/sample6.ts
+++ b/examples/src/webgl-examples/sample6.ts
@@ -230,7 +230,7 @@ async function loadTexture(url: string)
let sampler: IGLSampler = {};
if (generateMipmap)
{
- sampler = { wrapS: "CLAMP_TO_EDGE", wrapT: "CLAMP_TO_EDGE", minFilter: "LINEAR" };
+ sampler = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", minFilter: "LINEAR" };
}
return { texture, sampler };
diff --git a/examples/src/webgl-examples/sample7.ts b/examples/src/webgl-examples/sample7.ts
index f38b9fd..21e22f7 100644
--- a/examples/src/webgl-examples/sample7.ts
+++ b/examples/src/webgl-examples/sample7.ts
@@ -299,7 +299,7 @@ async function loadTexture(url: string)
if (!generateMipmap)
{
- sampler = { wrapS: "CLAMP_TO_EDGE", wrapT: "CLAMP_TO_EDGE", minFilter: "LINEAR" };
+ sampler = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", minFilter: "LINEAR" };
}
return { texture, sampler } as IGLSamplerTexture;
diff --git a/examples/src/webgl-examples/sample8.ts b/examples/src/webgl-examples/sample8.ts
index ad5d1d3..b835fbb 100644
--- a/examples/src/webgl-examples/sample8.ts
+++ b/examples/src/webgl-examples/sample8.ts
@@ -325,7 +325,7 @@ function initTexture(): IGLSamplerTexture
format: "rgba8unorm",
sources: [{ __type: "TextureDataSource", size: [1, 1], data: new Uint8Array([0, 0, 255, 255]) }],
};
- const sampler: IGLSampler = { wrapS: "CLAMP_TO_EDGE", wrapT: "CLAMP_TO_EDGE", minFilter: "LINEAR" };
+ const sampler: IGLSampler = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", minFilter: "LINEAR" };
return { texture, sampler };
}
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 39019b6..a2ea057 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -402,8 +402,8 @@ export class RunWebGL
{
const minFilter: IGLTextureMinFilter = sampler.minFilter || "LINEAR_MIPMAP_LINEAR";
const magFilter: IGLTextureMagFilter = sampler.magFilter || "LINEAR";
- const wrapS: IGLTextureWrap = sampler.wrapS || "REPEAT";
- const wrapT: IGLTextureWrap = sampler.wrapT || "REPEAT";
+ const wrapS: IGLTextureWrap = sampler.wrapU || "REPEAT";
+ const wrapT: IGLTextureWrap = sampler.wrapV || "REPEAT";
// 设置纹理参数
if (webGLTexture.minFilter !== minFilter)
diff --git a/src/caches/getGLSampler.ts b/src/caches/getGLSampler.ts
index ebf3983..24d04c0 100644
--- a/src/caches/getGLSampler.ts
+++ b/src/caches/getGLSampler.ts
@@ -21,9 +21,9 @@ export function getGLSampler(gl: WebGLRenderingContext, sampler?: IGLSampler)
const minFilter: IGLTextureMinFilter = sampler.minFilter || "LINEAR_MIPMAP_LINEAR";
const magFilter: IGLTextureMagFilter = sampler.magFilter || "LINEAR";
- const wrapS: IGLTextureWrap = sampler.wrapS || "REPEAT";
- const wrapT: IGLTextureWrap = sampler.wrapT || "REPEAT";
- const wrapR: IGLTextureWrap = sampler.wrapR || "REPEAT";
+ const wrapS: IGLTextureWrap = sampler.wrapU || "REPEAT";
+ const wrapT: IGLTextureWrap = sampler.wrapV || "REPEAT";
+ const wrapR: IGLTextureWrap = sampler.wrapW || "REPEAT";
const lodMinClamp = sampler.lodMinClamp || 0;
const lodMaxClamp = sampler.lodMaxClamp || 16;
const compareMode: IGLSamplerCompareMode = sampler.compareMode || "NONE";
diff --git a/src/data/IGLSampler.ts b/src/data/IGLSampler.ts
index fb8717c..90eb7a9 100644
--- a/src/data/IGLSampler.ts
+++ b/src/data/IGLSampler.ts
@@ -20,21 +20,25 @@ export interface IGLSampler extends ISampler
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_wrap_s
*/
- wrapS?: IGLTextureWrap;
+ wrapU?: IGLTextureWrap;
/**
* 用于指定纹理在T轴(即垂直方向或V坐标轴)上的环绕方式。
*
* 默认 "REPEAT"。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_wrap_t
*/
- wrapT?: IGLTextureWrap;
+ wrapV?: IGLTextureWrap;
/**
* 用于指定纹理在R轴(即深度方向或W坐标轴)上的环绕方式。用于3D纹理或者纹理数组。
*
* 默认 "REPEAT"。
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_wrap_r
*/
- wrapR?: IGLTextureWrap;
+ wrapW?: IGLTextureWrap;
/**
* 各向异性过滤。使用各向异性过滤能够使纹理的效果更好,但是会消耗更多的内存、CPU、GPU时间。默认为1。
--
Gitee
From 7e50e6bf23174fa4381425f7089471a9c4ccfe02 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 2 Jan 2025 12:35:07 +0800
Subject: [PATCH 158/186] ISampler.addressModeU addressModeV addressModeW
---
.../WebGL2Samples/fbo_rtt_depth_texture.ts | 2 +-
.../src/WebGL2Samples/fbo_rtt_draw_buffers.ts | 4 +--
.../src/WebGL2Samples/geo_vertex_format.ts | 4 +--
examples/src/WebGL2Samples/sampler_filter.ts | 2 +-
examples/src/WebGL2Samples/sampler_object.ts | 4 +--
examples/src/WebGL2Samples/sampler_wrap.ts | 18 ++++++------
.../src/WebGL2Samples/texture_derivative.ts | 4 +--
examples/src/WebGL2Samples/texture_grad.ts | 4 +--
.../src/WebGL2Samples/texture_immutable.ts | 4 +--
examples/src/WebGL2Samples/texture_offset.ts | 4 +--
examples/src/WebGL2Samples/texture_vertex.ts | 4 +--
examples/src/regl-examples/cloth.ts | 2 +-
examples/src/webgl-examples/sample6.ts | 2 +-
examples/src/webgl-examples/sample7.ts | 2 +-
examples/src/webgl-examples/sample8.ts | 2 +-
src/RunWebGL.ts | 6 ++--
src/caches/getGLSampler.ts | 24 ++++++++++++---
src/data/IGLSampler.ts | 29 +------------------
18 files changed, 55 insertions(+), 66 deletions(-)
diff --git a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
index 815c0da..dc0373c 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
@@ -80,7 +80,7 @@ const depthTexture: ITexture = {
size: [windowSize.x, windowSize.y],
format: "depth16unorm",
};
-const depthSampler: IGLSampler = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", minFilter: "NEAREST", magFilter: "NEAREST" };
+const depthSampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "NEAREST", magFilter: "NEAREST" };
// -- Initialize frame buffer
diff --git a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
index 42b03aa..5f5c366 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
@@ -79,13 +79,13 @@ const color1Texture: ITexture = {
format: "rgba8unorm",
size: [windowSize.x, windowSize.y],
};
-const color1Sampler: IGLSampler = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", minFilter: "NEAREST", magFilter: "NEAREST" };
+const color1Sampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "NEAREST", magFilter: "NEAREST" };
const color2Texture: ITexture = {
format: "rgba8unorm",
size: [windowSize.x, windowSize.y],
};
-const color2Sampler: IGLSampler = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", minFilter: "NEAREST", magFilter: "NEAREST" };
+const color2Sampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "NEAREST", magFilter: "NEAREST" };
// -- Initialize frame buffer
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index 488aa93..fe1dd31 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -176,8 +176,8 @@ import { getShaderSource, loadImage } from "./utility";
sampler = {
minFilter: "NEAREST",
magFilter: "NEAREST",
- wrapU: "CLAMP_TO_EDGE",
- wrapV: "CLAMP_TO_EDGE",
+ addressModeU: "clamp-to-edge",
+ addressModeV: "clamp-to-edge",
};
requestAnimationFrame(render);
diff --git a/examples/src/WebGL2Samples/sampler_filter.ts b/examples/src/WebGL2Samples/sampler_filter.ts
index 7c8b851..4db8bc5 100644
--- a/examples/src/WebGL2Samples/sampler_filter.ts
+++ b/examples/src/WebGL2Samples/sampler_filter.ts
@@ -97,7 +97,7 @@ const vertexArray: { vertices?: IVertexAttributes } = {
const samplers: IGLSampler[] = new Array(Corners.MAX);
for (let i = 0; i < Corners.MAX; ++i)
{
- samplers[i] = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", wrapW: "CLAMP_TO_EDGE" };
+ samplers[i] = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", addressModeW: "clamp-to-edge" };
}
// Min filter
diff --git a/examples/src/WebGL2Samples/sampler_object.ts b/examples/src/WebGL2Samples/sampler_object.ts
index 111bc36..72e0503 100644
--- a/examples/src/WebGL2Samples/sampler_object.ts
+++ b/examples/src/WebGL2Samples/sampler_object.ts
@@ -52,13 +52,13 @@ const vertexArray: { vertices?: IVertexAttributes } = {
const samplerA: IGLSampler = {
minFilter: "NEAREST_MIPMAP_NEAREST", magFilter: "NEAREST",
- wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", wrapW: "CLAMP_TO_EDGE",
+ addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", addressModeW: "clamp-to-edge",
lodMinClamp: -1000.0, lodMaxClamp: 1000.0,
compareMode: "NONE", compare: "LEQUAL",
};
const samplerB: IGLSampler = {
minFilter: "LINEAR_MIPMAP_LINEAR", magFilter: "LINEAR",
- wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", wrapW: "CLAMP_TO_EDGE",
+ addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", addressModeW: "clamp-to-edge",
lodMinClamp: -1000.0, lodMaxClamp: 1000.0,
compareMode: "NONE", compare: "LEQUAL",
};
diff --git a/examples/src/WebGL2Samples/sampler_wrap.ts b/examples/src/WebGL2Samples/sampler_wrap.ts
index 725237b..f21fdf4 100644
--- a/examples/src/WebGL2Samples/sampler_wrap.ts
+++ b/examples/src/WebGL2Samples/sampler_wrap.ts
@@ -101,15 +101,15 @@ for (let i = 0; i < Corners.MAX; ++i)
samplers[i] = { minFilter: "LINEAR_MIPMAP_LINEAR", magFilter: "LINEAR" };
}
-samplers[Corners.TOP_LEFT].wrapU = "MIRRORED_REPEAT";
-samplers[Corners.TOP_RIGHT].wrapU = "CLAMP_TO_EDGE";
-samplers[Corners.BOTTOM_RIGHT].wrapU = "REPEAT";
-samplers[Corners.BOTTOM_LEFT].wrapU = "CLAMP_TO_EDGE";
-
-samplers[Corners.TOP_LEFT].wrapV = "MIRRORED_REPEAT";
-samplers[Corners.TOP_RIGHT].wrapV = "MIRRORED_REPEAT";
-samplers[Corners.BOTTOM_RIGHT].wrapV = "REPEAT";
-samplers[Corners.BOTTOM_LEFT].wrapV = "CLAMP_TO_EDGE";
+samplers[Corners.TOP_LEFT].addressModeU = "mirror-repeat";
+samplers[Corners.TOP_RIGHT].addressModeU = "clamp-to-edge";
+samplers[Corners.BOTTOM_RIGHT].addressModeU = "repeat";
+samplers[Corners.BOTTOM_LEFT].addressModeU = "clamp-to-edge";
+
+samplers[Corners.TOP_LEFT].addressModeV = "mirror-repeat";
+samplers[Corners.TOP_RIGHT].addressModeV = "mirror-repeat";
+samplers[Corners.BOTTOM_RIGHT].addressModeV = "repeat";
+samplers[Corners.BOTTOM_LEFT].addressModeV = "clamp-to-edge";
// -- Load texture then render
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index 639fa49..e2ff164 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -143,8 +143,8 @@ import { getShaderSource, loadImage } from "./utility";
sampler = {
minFilter: "NEAREST",
magFilter: "NEAREST",
- wrapU: "CLAMP_TO_EDGE",
- wrapV: "CLAMP_TO_EDGE",
+ addressModeU: "clamp-to-edge",
+ addressModeV: "clamp-to-edge",
};
// // -- Allocate storage for the texture
diff --git a/examples/src/WebGL2Samples/texture_grad.ts b/examples/src/WebGL2Samples/texture_grad.ts
index d4f190e..20f36c5 100644
--- a/examples/src/WebGL2Samples/texture_grad.ts
+++ b/examples/src/WebGL2Samples/texture_grad.ts
@@ -137,8 +137,8 @@ import { getShaderSource, loadImage } from "./utility";
sampler = {
minFilter: "NEAREST",
magFilter: "NEAREST",
- wrapU: "CLAMP_TO_EDGE",
- wrapV: "CLAMP_TO_EDGE",
+ addressModeU: "clamp-to-edge",
+ addressModeV: "clamp-to-edge",
};
requestAnimationFrame(render);
diff --git a/examples/src/WebGL2Samples/texture_immutable.ts b/examples/src/WebGL2Samples/texture_immutable.ts
index e096eae..371d92f 100644
--- a/examples/src/WebGL2Samples/texture_immutable.ts
+++ b/examples/src/WebGL2Samples/texture_immutable.ts
@@ -94,8 +94,8 @@ import { getShaderSource, loadImage } from "./utility";
const sampler2D: IGLSampler = {
minFilter: "NEAREST",
magFilter: "LINEAR",
- wrapU: "CLAMP_TO_EDGE",
- wrapV: "CLAMP_TO_EDGE",
+ addressModeU: "clamp-to-edge",
+ addressModeV: "clamp-to-edge",
};
// -- Render
diff --git a/examples/src/WebGL2Samples/texture_offset.ts b/examples/src/WebGL2Samples/texture_offset.ts
index 223f027..f28748f 100644
--- a/examples/src/WebGL2Samples/texture_offset.ts
+++ b/examples/src/WebGL2Samples/texture_offset.ts
@@ -80,8 +80,8 @@ import { getShaderSource, loadImage } from "./utility";
const sampler: IGLSampler = {
minFilter: "NEAREST",
magFilter: "NEAREST",
- wrapU: "CLAMP_TO_EDGE",
- wrapV: "CLAMP_TO_EDGE",
+ addressModeU: "clamp-to-edge",
+ addressModeV: "clamp-to-edge",
};
const renderObjects: IRenderPassObject[] = [];
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index 4a455ea..63664fb 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -116,8 +116,8 @@ import { getShaderSource, loadImage } from "./utility";
sampler = {
minFilter: "NEAREST",
magFilter: "NEAREST",
- wrapU: "CLAMP_TO_EDGE",
- wrapV: "CLAMP_TO_EDGE",
+ addressModeU: "clamp-to-edge",
+ addressModeV: "clamp-to-edge",
};
requestAnimationFrame(render);
diff --git a/examples/src/regl-examples/cloth.ts b/examples/src/regl-examples/cloth.ts
index 2cdcb86..8fe35fb 100644
--- a/examples/src/regl-examples/cloth.ts
+++ b/examples/src/regl-examples/cloth.ts
@@ -390,7 +390,7 @@ import * as vec3 from "./stackgl/gl-vec3";
size: [img.width, img.height],
generateMipmap: true,
sources: [{ image: img }]
- }, sampler: { minFilter: "LINEAR_MIPMAP_LINEAR", wrapU: "REPEAT", wrapV: "REPEAT" }
+ }, sampler: { minFilter: "LINEAR_MIPMAP_LINEAR", addressModeU: "repeat", addressModeV: "repeat" }
};
draw();
diff --git a/examples/src/webgl-examples/sample6.ts b/examples/src/webgl-examples/sample6.ts
index 9655a0e..d2943be 100644
--- a/examples/src/webgl-examples/sample6.ts
+++ b/examples/src/webgl-examples/sample6.ts
@@ -230,7 +230,7 @@ async function loadTexture(url: string)
let sampler: IGLSampler = {};
if (generateMipmap)
{
- sampler = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", minFilter: "LINEAR" };
+ sampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "LINEAR" };
}
return { texture, sampler };
diff --git a/examples/src/webgl-examples/sample7.ts b/examples/src/webgl-examples/sample7.ts
index 21e22f7..d8ddd91 100644
--- a/examples/src/webgl-examples/sample7.ts
+++ b/examples/src/webgl-examples/sample7.ts
@@ -299,7 +299,7 @@ async function loadTexture(url: string)
if (!generateMipmap)
{
- sampler = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", minFilter: "LINEAR" };
+ sampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "LINEAR" };
}
return { texture, sampler } as IGLSamplerTexture;
diff --git a/examples/src/webgl-examples/sample8.ts b/examples/src/webgl-examples/sample8.ts
index b835fbb..ada6af1 100644
--- a/examples/src/webgl-examples/sample8.ts
+++ b/examples/src/webgl-examples/sample8.ts
@@ -325,7 +325,7 @@ function initTexture(): IGLSamplerTexture
format: "rgba8unorm",
sources: [{ __type: "TextureDataSource", size: [1, 1], data: new Uint8Array([0, 0, 255, 255]) }],
};
- const sampler: IGLSampler = { wrapU: "CLAMP_TO_EDGE", wrapV: "CLAMP_TO_EDGE", minFilter: "LINEAR" };
+ const sampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "LINEAR" };
return { texture, sampler };
}
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index a2ea057..7d00ab9 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -4,7 +4,7 @@ import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLFramebuffer } from "./caches/getGLFramebuffer";
import { getGLProgram } from "./caches/getGLProgram";
import { getGLRenderOcclusionQuery } from "./caches/getGLRenderOcclusionQuery";
-import { getGLSampler } from "./caches/getGLSampler";
+import { getGLSampler, getIGLTextureWrap } from "./caches/getGLSampler";
import { getGLTransformFeedback } from "./caches/getGLTransformFeedback";
import { getIGLBlitFramebuffer } from "./caches/getIGLBlitFramebuffer";
import { getIGLDrawMode, IGLDrawMode } from "./caches/getIGLDrawMode";
@@ -402,8 +402,8 @@ export class RunWebGL
{
const minFilter: IGLTextureMinFilter = sampler.minFilter || "LINEAR_MIPMAP_LINEAR";
const magFilter: IGLTextureMagFilter = sampler.magFilter || "LINEAR";
- const wrapS: IGLTextureWrap = sampler.wrapU || "REPEAT";
- const wrapT: IGLTextureWrap = sampler.wrapV || "REPEAT";
+ const wrapS: IGLTextureWrap = getIGLTextureWrap(sampler.addressModeU);
+ const wrapT: IGLTextureWrap = getIGLTextureWrap(sampler.addressModeV);
// 设置纹理参数
if (webGLTexture.minFilter !== minFilter)
diff --git a/src/caches/getGLSampler.ts b/src/caches/getGLSampler.ts
index 24d04c0..d1bc85e 100644
--- a/src/caches/getGLSampler.ts
+++ b/src/caches/getGLSampler.ts
@@ -1,3 +1,4 @@
+import { IAddressMode } from "@feng3d/render-api";
import { IGLCompareFunction } from "../data/IGLDepthStencilState";
import { IGLSampler, IGLSamplerCompareMode, IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "../data/IGLSampler";
@@ -21,9 +22,9 @@ export function getGLSampler(gl: WebGLRenderingContext, sampler?: IGLSampler)
const minFilter: IGLTextureMinFilter = sampler.minFilter || "LINEAR_MIPMAP_LINEAR";
const magFilter: IGLTextureMagFilter = sampler.magFilter || "LINEAR";
- const wrapS: IGLTextureWrap = sampler.wrapU || "REPEAT";
- const wrapT: IGLTextureWrap = sampler.wrapV || "REPEAT";
- const wrapR: IGLTextureWrap = sampler.wrapW || "REPEAT";
+ const wrapS: IGLTextureWrap = getIGLTextureWrap(sampler.addressModeU);
+ const wrapT: IGLTextureWrap = getIGLTextureWrap(sampler.addressModeV);
+ const wrapR: IGLTextureWrap = getIGLTextureWrap(sampler.addressModeW);
const lodMinClamp = sampler.lodMinClamp || 0;
const lodMaxClamp = sampler.lodMaxClamp || 16;
const compareMode: IGLSamplerCompareMode = sampler.compareMode || "NONE";
@@ -52,4 +53,19 @@ export function deleteSampler(gl: WebGLRenderingContext, sampler?: IGLSampler)
gl._samplers.delete(sampler);
gl.deleteSampler(webGLSampler);
}
-}
\ No newline at end of file
+}
+
+export function getIGLTextureWrap(addressMode: IAddressMode = "repeat")
+{
+ const textureWrap: IGLTextureWrap = addressModeMap[addressMode];
+
+ console.assert(!!textureWrap, `接收到错误值,请从 ${Object.keys(addressModeMap).toString()} 中取值!`);
+
+ return textureWrap;
+}
+
+const addressModeMap: { [key: string]: IGLTextureWrap } = {
+ "clamp-to-edge": "clamp-to-edge",
+ "repeat": "repeat",
+ "mirror-repeat": "mirror-repeat",
+};
\ No newline at end of file
diff --git a/src/data/IGLSampler.ts b/src/data/IGLSampler.ts
index 90eb7a9..343cb68 100644
--- a/src/data/IGLSampler.ts
+++ b/src/data/IGLSampler.ts
@@ -13,33 +13,6 @@ export interface IGLSampler extends ISampler
*/
magFilter?: IGLTextureMagFilter;
- /**
- * 用于指定纹理在S轴(即水平方向或U坐标轴)上的环绕方式。
- *
- * 默认 "REPEAT"。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_wrap_s
- */
- wrapU?: IGLTextureWrap;
-
- /**
- * 用于指定纹理在T轴(即垂直方向或V坐标轴)上的环绕方式。
- *
- * 默认 "REPEAT"。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_wrap_t
- */
- wrapV?: IGLTextureWrap;
-
- /**
- * 用于指定纹理在R轴(即深度方向或W坐标轴)上的环绕方式。用于3D纹理或者纹理数组。
- *
- * 默认 "REPEAT"。
- *
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter#gl.texture_wrap_r
- */
- wrapW?: IGLTextureWrap;
-
/**
* 各向异性过滤。使用各向异性过滤能够使纹理的效果更好,但是会消耗更多的内存、CPU、GPU时间。默认为1。
*
@@ -112,4 +85,4 @@ export type IGLTextureMinFilter = "LINEAR" | "NEAREST" | "NEAREST_MIPMAP_NEAREST
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texParameter
*/
-export type IGLTextureWrap = "REPEAT" | "CLAMP_TO_EDGE" | "MIRRORED_REPEAT";
\ No newline at end of file
+export type IGLTextureWrap = "repeat" | "clamp-to-edge" | "mirror-repeat";
\ No newline at end of file
--
Gitee
From 4142311b1581b8ed8b79d2ad9b65531996e1f83b Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 2 Jan 2025 12:40:37 +0800
Subject: [PATCH 159/186] ISampler.addressModeU addressModeV addressModeW
---
src/caches/getGLSampler.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/caches/getGLSampler.ts b/src/caches/getGLSampler.ts
index d1bc85e..bad3074 100644
--- a/src/caches/getGLSampler.ts
+++ b/src/caches/getGLSampler.ts
@@ -55,7 +55,7 @@ export function deleteSampler(gl: WebGLRenderingContext, sampler?: IGLSampler)
}
}
-export function getIGLTextureWrap(addressMode: IAddressMode = "repeat")
+export function getIGLTextureWrap(addressMode: IAddressMode = "clamp-to-edge")
{
const textureWrap: IGLTextureWrap = addressModeMap[addressMode];
--
Gitee
From d61f3165dcd3524a62526f93ed99996479eccac0 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 2 Jan 2025 13:28:39 +0800
Subject: [PATCH 160/186] ISampler.magFilter minFilter mipmapFilter
---
.../src/WebGL2Samples/draw_image_space.ts | 4 +-
examples/src/WebGL2Samples/fbo_blit.ts | 8 +--
examples/src/WebGL2Samples/fbo_multisample.ts | 2 +-
.../WebGL2Samples/fbo_new_blend_equation.ts | 4 +-
examples/src/WebGL2Samples/fbo_read_pixels.ts | 2 +-
.../WebGL2Samples/fbo_rtt_depth_texture.ts | 2 +-
.../src/WebGL2Samples/fbo_rtt_draw_buffers.ts | 4 +-
.../WebGL2Samples/fbo_rtt_texture_array.ts | 2 +-
.../src/WebGL2Samples/geo_vertex_format.ts | 4 +-
examples/src/WebGL2Samples/glsl_centroid.ts | 2 +-
.../WebGL2Samples/glsl_non_square_matrix.ts | 2 +-
examples/src/WebGL2Samples/sampler_filter.ts | 21 ++++---
examples/src/WebGL2Samples/sampler_object.ts | 4 +-
examples/src/WebGL2Samples/sampler_wrap.ts | 6 +-
.../src/WebGL2Samples/texture_2d_array.ts | 4 +-
examples/src/WebGL2Samples/texture_3d.ts | 5 +-
.../src/WebGL2Samples/texture_derivative.ts | 4 +-
examples/src/WebGL2Samples/texture_fetch.ts | 4 +-
examples/src/WebGL2Samples/texture_format.ts | 4 +-
examples/src/WebGL2Samples/texture_grad.ts | 4 +-
.../src/WebGL2Samples/texture_immutable.ts | 9 +--
examples/src/WebGL2Samples/texture_integer.ts | 4 +-
examples/src/WebGL2Samples/texture_lod.ts | 20 ++++---
examples/src/WebGL2Samples/texture_offset.ts | 4 +-
.../src/WebGL2Samples/texture_pixel_store.ts | 4 +-
examples/src/WebGL2Samples/texture_srgb.ts | 2 +-
examples/src/WebGL2Samples/texture_vertex.ts | 4 +-
examples/src/regl-examples/cloth.ts | 2 +-
examples/src/regl-examples/cube.ts | 2 +-
examples/src/webgl-examples/sample6.ts | 2 +-
examples/src/webgl-examples/sample7.ts | 2 +-
examples/src/webgl-examples/sample8.ts | 2 +-
src/RunWebGL.ts | 6 +-
src/caches/getGLSampler.ts | 55 +++++++++++++++++--
src/data/IGLSampler.ts | 12 +---
35 files changed, 135 insertions(+), 87 deletions(-)
diff --git a/examples/src/WebGL2Samples/draw_image_space.ts b/examples/src/WebGL2Samples/draw_image_space.ts
index 732bc3b..21314b3 100644
--- a/examples/src/WebGL2Samples/draw_image_space.ts
+++ b/examples/src/WebGL2Samples/draw_image_space.ts
@@ -19,8 +19,8 @@ loadImage("../../assets/img/Di-3d.png", (img) =>
format: "rgba8unorm",
};
const sampler: IGLSampler = {
- minFilter: "LINEAR",
- magFilter: "LINEAR",
+ minFilter: "linear",
+ magFilter: "linear",
};
const program: IRenderPipeline = {
diff --git a/examples/src/WebGL2Samples/fbo_blit.ts b/examples/src/WebGL2Samples/fbo_blit.ts
index 33dbcf3..984ef35 100644
--- a/examples/src/WebGL2Samples/fbo_blit.ts
+++ b/examples/src/WebGL2Samples/fbo_blit.ts
@@ -59,8 +59,8 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
}],
};
const samplerDiffuse: IGLSampler = {
- minFilter: "LINEAR",
- magFilter: "LINEAR",
+ minFilter: "linear",
+ magFilter: "linear",
};
const textureColorBuffer: ITexture = {
@@ -68,8 +68,8 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
size: [FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y],
};
const samplerColorBuffer: IGLSampler = {
- minFilter: "LINEAR",
- magFilter: "LINEAR",
+ minFilter: "linear",
+ magFilter: "linear",
};
// 此处 Renderbuffer 直接使用 IGLTextureView 替代。
diff --git a/examples/src/WebGL2Samples/fbo_multisample.ts b/examples/src/WebGL2Samples/fbo_multisample.ts
index ad7d930..0c454e4 100644
--- a/examples/src/WebGL2Samples/fbo_multisample.ts
+++ b/examples/src/WebGL2Samples/fbo_multisample.ts
@@ -74,7 +74,7 @@ const texture: ITexture = {
format: "rgba8unorm",
size: [FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y]
};
-const sampler: IGLSampler = { minFilter: "NEAREST", magFilter: "NEAREST" };
+const sampler: IGLSampler = { minFilter: "nearest", magFilter: "nearest" };
// -- Init Frame Buffers
const framebuffer: IRenderPassDescriptor = {
diff --git a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
index 1d97117..24a57f4 100644
--- a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
+++ b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
@@ -93,8 +93,8 @@ const vertexArray: { vertices?: IVertexAttributes } = {
// -- Load texture then render
const sampler: IGLSampler = {
- minFilter: "LINEAR",
- magFilter: "LINEAR"
+ minFilter: "linear",
+ magFilter: "linear"
};
const imageUrl = "../../assets/img/Di-3d.png";
let texture: ITexture;
diff --git a/examples/src/WebGL2Samples/fbo_read_pixels.ts b/examples/src/WebGL2Samples/fbo_read_pixels.ts
index 4c541ef..4427874 100644
--- a/examples/src/WebGL2Samples/fbo_read_pixels.ts
+++ b/examples/src/WebGL2Samples/fbo_read_pixels.ts
@@ -107,7 +107,7 @@ const texture: ITexture = {
size: [w, h, 3],
format: "rgba8unorm",
};
-const sampler: IGLSampler = { lodMinClamp: 0, lodMaxClamp: 0, minFilter: "NEAREST", magFilter: "NEAREST" };
+const sampler: IGLSampler = { lodMinClamp: 0, lodMaxClamp: 0, minFilter: "nearest", magFilter: "nearest" };
// -- Initialize frame buffer
diff --git a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
index dc0373c..e6e0ebd 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
@@ -80,7 +80,7 @@ const depthTexture: ITexture = {
size: [windowSize.x, windowSize.y],
format: "depth16unorm",
};
-const depthSampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "NEAREST", magFilter: "NEAREST" };
+const depthSampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "nearest", magFilter: "nearest" };
// -- Initialize frame buffer
diff --git a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
index 5f5c366..576c51f 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
@@ -79,13 +79,13 @@ const color1Texture: ITexture = {
format: "rgba8unorm",
size: [windowSize.x, windowSize.y],
};
-const color1Sampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "NEAREST", magFilter: "NEAREST" };
+const color1Sampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "nearest", magFilter: "nearest" };
const color2Texture: ITexture = {
format: "rgba8unorm",
size: [windowSize.x, windowSize.y],
};
-const color2Sampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "NEAREST", magFilter: "NEAREST" };
+const color2Sampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "nearest", magFilter: "nearest" };
// -- Initialize frame buffer
diff --git a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
index 9aabf49..239dfc4 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
@@ -107,7 +107,7 @@ const texture: ITexture = {
format: "rgba8unorm",
size: [w, h, 3],
};
-const sampler: IGLSampler = { minFilter: "NEAREST", magFilter: "NEAREST", lodMinClamp: 0, lodMaxClamp: 0 };
+const sampler: IGLSampler = { minFilter: "nearest", magFilter: "nearest", lodMinClamp: 0, lodMaxClamp: 0 };
// -- Initialize frame buffer
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index fe1dd31..595c0ec 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -174,8 +174,8 @@ import { getShaderSource, loadImage } from "./utility";
sources: [{ image: image, flipY: false }],
};
sampler = {
- minFilter: "NEAREST",
- magFilter: "NEAREST",
+ minFilter: "nearest",
+ magFilter: "nearest",
addressModeU: "clamp-to-edge",
addressModeV: "clamp-to-edge",
};
diff --git a/examples/src/WebGL2Samples/glsl_centroid.ts b/examples/src/WebGL2Samples/glsl_centroid.ts
index 5c1f076..4d103bf 100644
--- a/examples/src/WebGL2Samples/glsl_centroid.ts
+++ b/examples/src/WebGL2Samples/glsl_centroid.ts
@@ -113,7 +113,7 @@ for (let i = 0; i < VIEWPORTS.MAX; ++i)
format: "rgba8unorm",
size: [FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y],
};
- samplers[i] = { minFilter: "NEAREST", magFilter: "NEAREST" };
+ samplers[i] = { minFilter: "nearest", magFilter: "nearest" };
}
// -- Init Frame Buffers
diff --git a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
index fb42a36..8a113e5 100644
--- a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
+++ b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
@@ -54,7 +54,7 @@ loadImage("../../assets/img/Di-3d.png", function (image)
image: image, flipY: false,
}]
};
- const sampler: IGLSampler = { minFilter: "NEAREST", magFilter: "NEAREST" };
+ const sampler: IGLSampler = { minFilter: "nearest", magFilter: "nearest" };
// -- Render
const matrix = new Float32Array([
diff --git a/examples/src/WebGL2Samples/sampler_filter.ts b/examples/src/WebGL2Samples/sampler_filter.ts
index 4db8bc5..73571f6 100644
--- a/examples/src/WebGL2Samples/sampler_filter.ts
+++ b/examples/src/WebGL2Samples/sampler_filter.ts
@@ -101,16 +101,21 @@ for (let i = 0; i < Corners.MAX; ++i)
}
// Min filter
-samplers[Corners.TOP_LEFT].minFilter = "NEAREST";
-samplers[Corners.TOP_RIGHT].minFilter = "LINEAR";
-samplers[Corners.BOTTOM_RIGHT].minFilter = "LINEAR_MIPMAP_NEAREST";
-samplers[Corners.BOTTOM_LEFT].minFilter = "LINEAR_MIPMAP_LINEAR";
+samplers[Corners.TOP_LEFT].minFilter = "nearest";
+samplers[Corners.TOP_RIGHT].minFilter = "linear";
+samplers[Corners.BOTTOM_RIGHT].minFilter = "linear";
+samplers[Corners.BOTTOM_LEFT].minFilter = "linear";
+
// Mag filter
-samplers[Corners.TOP_LEFT].magFilter = "NEAREST";
-samplers[Corners.TOP_RIGHT].magFilter = "LINEAR";
-samplers[Corners.BOTTOM_RIGHT].magFilter = "LINEAR";
-samplers[Corners.BOTTOM_LEFT].magFilter = "LINEAR";
+samplers[Corners.TOP_LEFT].magFilter = "nearest";
+samplers[Corners.TOP_RIGHT].magFilter = "linear";
+samplers[Corners.BOTTOM_RIGHT].magFilter = "linear";
+samplers[Corners.BOTTOM_LEFT].magFilter = "linear";
+
+//
+samplers[Corners.BOTTOM_RIGHT].mipmapFilter = "nearest";
+samplers[Corners.BOTTOM_LEFT].mipmapFilter = "linear";
// -- Load texture then render
diff --git a/examples/src/WebGL2Samples/sampler_object.ts b/examples/src/WebGL2Samples/sampler_object.ts
index 72e0503..681000d 100644
--- a/examples/src/WebGL2Samples/sampler_object.ts
+++ b/examples/src/WebGL2Samples/sampler_object.ts
@@ -51,13 +51,13 @@ const vertexArray: { vertices?: IVertexAttributes } = {
// -- Initialize samplers
const samplerA: IGLSampler = {
- minFilter: "NEAREST_MIPMAP_NEAREST", magFilter: "NEAREST",
+ minFilter: "nearest", magFilter: "nearest", mipmapFilter: "nearest",
addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", addressModeW: "clamp-to-edge",
lodMinClamp: -1000.0, lodMaxClamp: 1000.0,
compareMode: "NONE", compare: "LEQUAL",
};
const samplerB: IGLSampler = {
- minFilter: "LINEAR_MIPMAP_LINEAR", magFilter: "LINEAR",
+ minFilter: "linear", magFilter: "linear", mipmapFilter: "linear",
addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", addressModeW: "clamp-to-edge",
lodMinClamp: -1000.0, lodMaxClamp: 1000.0,
compareMode: "NONE", compare: "LEQUAL",
diff --git a/examples/src/WebGL2Samples/sampler_wrap.ts b/examples/src/WebGL2Samples/sampler_wrap.ts
index f21fdf4..f05bc25 100644
--- a/examples/src/WebGL2Samples/sampler_wrap.ts
+++ b/examples/src/WebGL2Samples/sampler_wrap.ts
@@ -98,7 +98,11 @@ const samplers: IGLSampler[] = new Array(Corners.MAX);
for (let i = 0; i < Corners.MAX; ++i)
{
- samplers[i] = { minFilter: "LINEAR_MIPMAP_LINEAR", magFilter: "LINEAR" };
+ samplers[i] = {
+ minFilter: "linear",
+ magFilter: "linear",
+ mipmapFilter:"linear",
+ };
}
samplers[Corners.TOP_LEFT].addressModeU = "mirror-repeat";
diff --git a/examples/src/WebGL2Samples/texture_2d_array.ts b/examples/src/WebGL2Samples/texture_2d_array.ts
index 3116f35..54ada88 100644
--- a/examples/src/WebGL2Samples/texture_2d_array.ts
+++ b/examples/src/WebGL2Samples/texture_2d_array.ts
@@ -71,8 +71,8 @@ import { getShaderSource, loadImage } from "./utility";
sources: [{ __type: "TextureDataSource", size: [IMAGE_SIZE.width, IMAGE_SIZE.height, NUM_IMAGES], data: pixels }],
};
sampler = {
- minFilter: "LINEAR",
- magFilter: "LINEAR",
+ minFilter: "linear",
+ magFilter: "linear",
};
const matrix = new Float32Array([
diff --git a/examples/src/WebGL2Samples/texture_3d.ts b/examples/src/WebGL2Samples/texture_3d.ts
index 980b9a4..91e04fc 100644
--- a/examples/src/WebGL2Samples/texture_3d.ts
+++ b/examples/src/WebGL2Samples/texture_3d.ts
@@ -89,8 +89,9 @@ import { getShaderSource } from "./utility";
const sampler: IGLSampler = {
lodMinClamp: 0,
lodMaxClamp: Math.log2(SIZE),
- minFilter: "LINEAR_MIPMAP_LINEAR",
- magFilter: "LINEAR",
+ minFilter: "linear",
+ magFilter: "linear",
+ mipmapFilter: "linear",
};
// -- Initialize program
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index e2ff164..bf093d2 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -141,8 +141,8 @@ import { getShaderSource, loadImage } from "./utility";
}]
};
sampler = {
- minFilter: "NEAREST",
- magFilter: "NEAREST",
+ minFilter: "nearest",
+ magFilter: "nearest",
addressModeU: "clamp-to-edge",
addressModeV: "clamp-to-edge",
};
diff --git a/examples/src/WebGL2Samples/texture_fetch.ts b/examples/src/WebGL2Samples/texture_fetch.ts
index b8ade41..fffa8ed 100644
--- a/examples/src/WebGL2Samples/texture_fetch.ts
+++ b/examples/src/WebGL2Samples/texture_fetch.ts
@@ -55,8 +55,8 @@ import { getShaderSource, loadImage } from "./utility";
}],
};
const sampler: IGLSampler = {
- minFilter: "NEAREST",
- magFilter: "NEAREST",
+ minFilter: "nearest",
+ magFilter: "nearest",
};
// -- Render
diff --git a/examples/src/WebGL2Samples/texture_format.ts b/examples/src/WebGL2Samples/texture_format.ts
index ddf635c..1b42d55 100644
--- a/examples/src/WebGL2Samples/texture_format.ts
+++ b/examples/src/WebGL2Samples/texture_format.ts
@@ -148,8 +148,8 @@ import { getShaderSource, loadImage } from "./utility";
}],
};
samplers[i] = {
- minFilter: "NEAREST",
- magFilter: "NEAREST",
+ minFilter: "nearest",
+ magFilter: "nearest",
lodMinClamp: 0,
lodMaxClamp: 0,
};
diff --git a/examples/src/WebGL2Samples/texture_grad.ts b/examples/src/WebGL2Samples/texture_grad.ts
index 20f36c5..1a2e44a 100644
--- a/examples/src/WebGL2Samples/texture_grad.ts
+++ b/examples/src/WebGL2Samples/texture_grad.ts
@@ -135,8 +135,8 @@ import { getShaderSource, loadImage } from "./utility";
}]
};
sampler = {
- minFilter: "NEAREST",
- magFilter: "NEAREST",
+ minFilter: "nearest",
+ magFilter: "nearest",
addressModeU: "clamp-to-edge",
addressModeV: "clamp-to-edge",
};
diff --git a/examples/src/WebGL2Samples/texture_immutable.ts b/examples/src/WebGL2Samples/texture_immutable.ts
index 371d92f..6ceff38 100644
--- a/examples/src/WebGL2Samples/texture_immutable.ts
+++ b/examples/src/WebGL2Samples/texture_immutable.ts
@@ -92,8 +92,8 @@ import { getShaderSource, loadImage } from "./utility";
}],
};
const sampler2D: IGLSampler = {
- minFilter: "NEAREST",
- magFilter: "LINEAR",
+ minFilter: "nearest",
+ magFilter: "linear",
addressModeU: "clamp-to-edge",
addressModeV: "clamp-to-edge",
};
@@ -177,8 +177,9 @@ import { getShaderSource, loadImage } from "./utility";
const sampler3D: IGLSampler = {
lodMinClamp: 0,
lodMaxClamp: Math.log2(SIZE),
- minFilter: "LINEAR_MIPMAP_LINEAR",
- magFilter: "LINEAR",
+ minFilter: "linear",
+ magFilter: "linear",
+ mipmapFilter: "linear",
};
return { texture3D, sampler3D };
diff --git a/examples/src/WebGL2Samples/texture_integer.ts b/examples/src/WebGL2Samples/texture_integer.ts
index 70db3fe..76ec47b 100644
--- a/examples/src/WebGL2Samples/texture_integer.ts
+++ b/examples/src/WebGL2Samples/texture_integer.ts
@@ -57,8 +57,8 @@ import { getShaderSource, loadImage } from "./utility";
}],
};
const sampler: IGLSampler = {
- minFilter: "NEAREST",
- magFilter: "NEAREST",
+ minFilter: "nearest",
+ magFilter: "nearest",
};
// -- Render
diff --git a/examples/src/WebGL2Samples/texture_lod.ts b/examples/src/WebGL2Samples/texture_lod.ts
index e5e2c35..ddfd8bc 100644
--- a/examples/src/WebGL2Samples/texture_lod.ts
+++ b/examples/src/WebGL2Samples/texture_lod.ts
@@ -131,8 +131,9 @@ import { getShaderSource, loadImage } from "./utility";
sources: [{ mipLevel: 0, image: image }],
};
samplers[Corners.TOP_LEFT] = {
- minFilter: "LINEAR_MIPMAP_LINEAR",
- magFilter: "LINEAR",
+ minFilter: "linear",
+ magFilter: "linear",
+ mipmapFilter: "linear",
};
textures[Corners.TOP_RIGHT] = {
@@ -142,8 +143,9 @@ import { getShaderSource, loadImage } from "./utility";
sources: [{ mipLevel: 0, image: image }],
};
samplers[Corners.TOP_RIGHT] = {
- minFilter: "LINEAR_MIPMAP_LINEAR",
- magFilter: "LINEAR",
+ minFilter: "linear",
+ magFilter: "linear",
+ mipmapFilter: "linear",
lodMinClamp: 3.0,
lodMaxClamp: 3.0,
};
@@ -155,8 +157,9 @@ import { getShaderSource, loadImage } from "./utility";
sources: [{ mipLevel: 0, image: image }],
};
samplers[Corners.BOTTOM_LEFT] = {
- minFilter: "LINEAR_MIPMAP_LINEAR",
- magFilter: "LINEAR",
+ minFilter: "linear",
+ magFilter: "linear",
+ mipmapFilter: "linear",
lodMinClamp: 0.0,
lodMaxClamp: 10.0,
};
@@ -168,8 +171,9 @@ import { getShaderSource, loadImage } from "./utility";
sources: [{ mipLevel: 0, image: image }],
};
samplers[Corners.BOTTOM_RIGHT] = {
- minFilter: "LINEAR_MIPMAP_LINEAR",
- magFilter: "LINEAR",
+ minFilter: "linear",
+ magFilter: "linear",
+ mipmapFilter: "linear",
lodMinClamp: 0.0,
lodMaxClamp: 10.0,
};
diff --git a/examples/src/WebGL2Samples/texture_offset.ts b/examples/src/WebGL2Samples/texture_offset.ts
index f28748f..17e75f9 100644
--- a/examples/src/WebGL2Samples/texture_offset.ts
+++ b/examples/src/WebGL2Samples/texture_offset.ts
@@ -78,8 +78,8 @@ import { getShaderSource, loadImage } from "./utility";
sources: [{ mipLevel: 0, image: image, flipY: false, }],
};
const sampler: IGLSampler = {
- minFilter: "NEAREST",
- magFilter: "NEAREST",
+ minFilter: "nearest",
+ magFilter: "nearest",
addressModeU: "clamp-to-edge",
addressModeV: "clamp-to-edge",
};
diff --git a/examples/src/WebGL2Samples/texture_pixel_store.ts b/examples/src/WebGL2Samples/texture_pixel_store.ts
index eb77430..ea1046d 100644
--- a/examples/src/WebGL2Samples/texture_pixel_store.ts
+++ b/examples/src/WebGL2Samples/texture_pixel_store.ts
@@ -72,8 +72,8 @@ import { getShaderSource, loadImage } from "./utility";
}]
};
const sampler: IGLSampler = {
- minFilter: "NEAREST",
- magFilter: "NEAREST",
+ minFilter: "nearest",
+ magFilter: "nearest",
};
const renderObjects: IRenderPassObject[] = [];
diff --git a/examples/src/WebGL2Samples/texture_srgb.ts b/examples/src/WebGL2Samples/texture_srgb.ts
index 32a9eac..e7de6a2 100644
--- a/examples/src/WebGL2Samples/texture_srgb.ts
+++ b/examples/src/WebGL2Samples/texture_srgb.ts
@@ -61,7 +61,7 @@ import { getShaderSource, loadImage } from "./utility";
format: "rgba8unorm-srgb",
sources: [{ mipLevel: 0, image: image }],
};
- sampler = { minFilter: "NEAREST", magFilter: "NEAREST" };
+ sampler = { minFilter: "nearest", magFilter: "nearest" };
render();
});
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index 63664fb..d3d985e 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -114,8 +114,8 @@ import { getShaderSource, loadImage } from "./utility";
sources: [{ image: image, flipY: false, }],
};
sampler = {
- minFilter: "NEAREST",
- magFilter: "NEAREST",
+ minFilter: "nearest",
+ magFilter: "nearest",
addressModeU: "clamp-to-edge",
addressModeV: "clamp-to-edge",
};
diff --git a/examples/src/regl-examples/cloth.ts b/examples/src/regl-examples/cloth.ts
index 8fe35fb..2088b81 100644
--- a/examples/src/regl-examples/cloth.ts
+++ b/examples/src/regl-examples/cloth.ts
@@ -390,7 +390,7 @@ import * as vec3 from "./stackgl/gl-vec3";
size: [img.width, img.height],
generateMipmap: true,
sources: [{ image: img }]
- }, sampler: { minFilter: "LINEAR_MIPMAP_LINEAR", addressModeU: "repeat", addressModeV: "repeat" }
+ }, sampler: { minFilter: "linear", mipmapFilter: "linear", addressModeU: "repeat", addressModeV: "repeat" }
};
draw();
diff --git a/examples/src/regl-examples/cube.ts b/examples/src/regl-examples/cube.ts
index 7700281..ce19f4e 100644
--- a/examples/src/regl-examples/cube.ts
+++ b/examples/src/regl-examples/cube.ts
@@ -141,7 +141,7 @@ import * as mat4 from "./stackgl/gl-mat4";
texture: {
size: [img.width, img.height],
sources: [{ image: img }]
- }, sampler: { minFilter: "LINEAR" }
+ }, sampler: { minFilter: "linear" }
};
draw();
diff --git a/examples/src/webgl-examples/sample6.ts b/examples/src/webgl-examples/sample6.ts
index d2943be..a122d5e 100644
--- a/examples/src/webgl-examples/sample6.ts
+++ b/examples/src/webgl-examples/sample6.ts
@@ -230,7 +230,7 @@ async function loadTexture(url: string)
let sampler: IGLSampler = {};
if (generateMipmap)
{
- sampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "LINEAR" };
+ sampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "linear" };
}
return { texture, sampler };
diff --git a/examples/src/webgl-examples/sample7.ts b/examples/src/webgl-examples/sample7.ts
index d8ddd91..4181ce0 100644
--- a/examples/src/webgl-examples/sample7.ts
+++ b/examples/src/webgl-examples/sample7.ts
@@ -299,7 +299,7 @@ async function loadTexture(url: string)
if (!generateMipmap)
{
- sampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "LINEAR" };
+ sampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "linear" };
}
return { texture, sampler } as IGLSamplerTexture;
diff --git a/examples/src/webgl-examples/sample8.ts b/examples/src/webgl-examples/sample8.ts
index ada6af1..f2a5f92 100644
--- a/examples/src/webgl-examples/sample8.ts
+++ b/examples/src/webgl-examples/sample8.ts
@@ -325,7 +325,7 @@ function initTexture(): IGLSamplerTexture
format: "rgba8unorm",
sources: [{ __type: "TextureDataSource", size: [1, 1], data: new Uint8Array([0, 0, 255, 255]) }],
};
- const sampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "LINEAR" };
+ const sampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "linear" };
return { texture, sampler };
}
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 7d00ab9..bb26455 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -4,7 +4,7 @@ import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLFramebuffer } from "./caches/getGLFramebuffer";
import { getGLProgram } from "./caches/getGLProgram";
import { getGLRenderOcclusionQuery } from "./caches/getGLRenderOcclusionQuery";
-import { getGLSampler, getIGLTextureWrap } from "./caches/getGLSampler";
+import { getGLSampler, getIGLTextureMagFilter, getIGLTextureMinFilter, getIGLTextureWrap } from "./caches/getGLSampler";
import { getGLTransformFeedback } from "./caches/getGLTransformFeedback";
import { getIGLBlitFramebuffer } from "./caches/getIGLBlitFramebuffer";
import { getIGLDrawMode, IGLDrawMode } from "./caches/getIGLDrawMode";
@@ -400,8 +400,8 @@ export class RunWebGL
}
else
{
- const minFilter: IGLTextureMinFilter = sampler.minFilter || "LINEAR_MIPMAP_LINEAR";
- const magFilter: IGLTextureMagFilter = sampler.magFilter || "LINEAR";
+ const minFilter: IGLTextureMinFilter = getIGLTextureMinFilter(sampler.minFilter, sampler.mipmapFilter);
+ const magFilter: IGLTextureMagFilter = getIGLTextureMagFilter(sampler.magFilter);
const wrapS: IGLTextureWrap = getIGLTextureWrap(sampler.addressModeU);
const wrapT: IGLTextureWrap = getIGLTextureWrap(sampler.addressModeV);
diff --git a/src/caches/getGLSampler.ts b/src/caches/getGLSampler.ts
index bad3074..dc013d8 100644
--- a/src/caches/getGLSampler.ts
+++ b/src/caches/getGLSampler.ts
@@ -1,4 +1,4 @@
-import { IAddressMode } from "@feng3d/render-api";
+import { IAddressMode, IFilterMode } from "@feng3d/render-api";
import { IGLCompareFunction } from "../data/IGLDepthStencilState";
import { IGLSampler, IGLSamplerCompareMode, IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "../data/IGLSampler";
@@ -20,8 +20,8 @@ export function getGLSampler(gl: WebGLRenderingContext, sampler?: IGLSampler)
webGLSampler = gl.createSampler();
gl._samplers.set(sampler, webGLSampler);
- const minFilter: IGLTextureMinFilter = sampler.minFilter || "LINEAR_MIPMAP_LINEAR";
- const magFilter: IGLTextureMagFilter = sampler.magFilter || "LINEAR";
+ const minFilter: IGLTextureMinFilter = getIGLTextureMinFilter(sampler.minFilter, sampler.mipmapFilter);
+ const magFilter: IGLTextureMagFilter = getIGLTextureMagFilter(sampler.magFilter);
const wrapS: IGLTextureWrap = getIGLTextureWrap(sampler.addressModeU);
const wrapT: IGLTextureWrap = getIGLTextureWrap(sampler.addressModeV);
const wrapR: IGLTextureWrap = getIGLTextureWrap(sampler.addressModeW);
@@ -65,7 +65,50 @@ export function getIGLTextureWrap(addressMode: IAddressMode = "clamp-to-edge")
}
const addressModeMap: { [key: string]: IGLTextureWrap } = {
- "clamp-to-edge": "clamp-to-edge",
- "repeat": "repeat",
- "mirror-repeat": "mirror-repeat",
+ "clamp-to-edge": "CLAMP_TO_EDGE",
+ "repeat": "REPEAT",
+ "mirror-repeat": "MIRRORED_REPEAT",
+};
+
+export function getIGLTextureMinFilter(minFilter: IFilterMode = "nearest", mipmapFilter: IFilterMode = "nearest"): IGLTextureMinFilter
+{
+ let glMinFilter: IGLTextureMinFilter;
+ if (minFilter === "linear")
+ {
+ if (mipmapFilter === "linear")
+ {
+ glMinFilter = "LINEAR_MIPMAP_LINEAR";
+ }
+ else
+ {
+ glMinFilter = "LINEAR_MIPMAP_NEAREST";
+ }
+ }
+ else
+ {
+ if (mipmapFilter === "linear")
+ {
+ glMinFilter = "NEAREST_MIPMAP_LINEAR";
+ }
+ else
+ {
+ glMinFilter = "NEAREST_MIPMAP_NEAREST";
+ }
+ }
+
+ return glMinFilter;
+}
+
+export function getIGLTextureMagFilter(magFilter: IFilterMode = "nearest")
+{
+ const glMagFilter: IGLTextureMagFilter = magFilterMap[magFilter];
+
+ console.assert(!!glMagFilter, `接收到错误值,请从 ${Object.keys(magFilterMap).toString()} 中取值!`);
+
+ return glMagFilter;
+}
+
+const magFilterMap: { [key: string]: IGLTextureMagFilter } = {
+ "nearest": "NEAREST",
+ "linear": "LINEAR",
};
\ No newline at end of file
diff --git a/src/data/IGLSampler.ts b/src/data/IGLSampler.ts
index 343cb68..b952168 100644
--- a/src/data/IGLSampler.ts
+++ b/src/data/IGLSampler.ts
@@ -3,16 +3,6 @@ import { IGLCompareFunction } from "./IGLDepthStencilState";
export interface IGLSampler extends ISampler
{
- /**
- * 默认 "LINEAR_MIPMAP_LINEAR" 。
- */
- minFilter?: IGLTextureMinFilter;
-
- /**
- * 默认 "LINEAR"。
- */
- magFilter?: IGLTextureMagFilter;
-
/**
* 各向异性过滤。使用各向异性过滤能够使纹理的效果更好,但是会消耗更多的内存、CPU、GPU时间。默认为1。
*
@@ -85,4 +75,4 @@ export type IGLTextureMinFilter = "LINEAR" | "NEAREST" | "NEAREST_MIPMAP_NEAREST
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texParameter
*/
-export type IGLTextureWrap = "repeat" | "clamp-to-edge" | "mirror-repeat";
\ No newline at end of file
+export type IGLTextureWrap = "REPEAT" | "CLAMP_TO_EDGE" | "MIRRORED_REPEAT";
\ No newline at end of file
--
Gitee
From 836970a81d25743ade8b48ad3ae0922dccb49f58 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 2 Jan 2025 15:33:23 +0800
Subject: [PATCH 161/186] ITexture.writeTextures
---
src/caches/getGLTexture.ts | 191 ++++++++++++++++++++++++++++++++-----
1 file changed, 169 insertions(+), 22 deletions(-)
diff --git a/src/caches/getGLTexture.ts b/src/caches/getGLTexture.ts
index b89e115..d839d3d 100644
--- a/src/caches/getGLTexture.ts
+++ b/src/caches/getGLTexture.ts
@@ -1,6 +1,5 @@
import { ITexture, ITextureDataSource, ITextureImageSource, ITextureSize } from "@feng3d/render-api";
import { watcher } from "@feng3d/watcher";
-import { IGLTextureTarget } from "../data/IGLTexture";
import { IGLTexturePixelStore } from "../data/IGLTexturePixelStore";
import { getTextureCubeMapTarget } from "../utils/getTextureCubeMapTarget";
import { getIGLTextureFormats } from "./getIGLTextureFormats";
@@ -54,36 +53,190 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: ITexture)
gl.bindTexture(gl[target], webGLTexture);
+ //
+ const { sources, generateMipmap } = texture;
+
// 设置纹理尺寸
const [width, height, depth] = texture.size;
const mipLevelCount = texture.mipLevelCount || 1;
- if (gl instanceof WebGL2RenderingContext)
+
+ if (sources)
{
- if (target === "TEXTURE_2D" || target === "TEXTURE_CUBE_MAP")
+ sources.forEach((v) =>
{
- gl.texStorage2D(gl[target], mipLevelCount, gl[internalformat], width, height);
- }
- else if (target === "TEXTURE_3D" || target === "TEXTURE_2D_ARRAY")
- {
- gl.texStorage3D(gl[target], mipLevelCount, gl[internalformat], width, height, depth);
- }
- else
+ const { textureOrigin, size } = v;
+ //
+ const mipLevel = v.mipLevel ?? 0;
+ const width = size?.[0];
+ const height = size?.[1];
+ const depthOrArrayLayers = size?.[2];
+ const xoffset = textureOrigin?.[0];
+ const yoffset = textureOrigin?.[1];
+ const zoffset = textureOrigin?.[2];
+ if (gl instanceof WebGL2RenderingContext)
+ {
+ const imageSource = v as ITextureImageSource;
+ if (imageSource.image)
+ {
+ const { image, imageOrigin, flipY, premultipliedAlpha } = imageSource;
+
+ //
+ const pixelStore: IGLTexturePixelStore = {};
+ pixelStore.unpackSkipPixels = imageOrigin?.[0] || 0;
+ pixelStore.unpackSkipRows = imageOrigin?.[1] || 0;
+ pixelStore.unpackFlipY = flipY || false;
+ pixelStore.unpackPremulAlpha = premultipliedAlpha || false;
+
+ setTexturePixelStore(gl, pixelStore);
+
+ if (target === "TEXTURE_2D" || target === "TEXTURE_CUBE_MAP")
+ {
+ const bindTarget = target === "TEXTURE_CUBE_MAP" ? getTextureCubeMapTarget(depthOrArrayLayers) : target;
+ if (width && height)
+ {
+ gl.texImage2D(gl[bindTarget], mipLevel, gl[internalformat], width, height, 0, gl[format], gl[type], image);
+ }
+ else
+ {
+ gl.texImage2D(gl[bindTarget], mipLevel, gl[internalformat], gl[format], gl[type], image);
+ }
+ }
+ else if (target === "TEXTURE_3D" || target === "TEXTURE_2D_ARRAY")
+ {
+ gl.texImage3D(gl[target], mipLevel, gl[internalformat], width, height, depth, 0, gl[format], gl[type], image);
+ }
+ else
+ {
+ console.error(`未处理 ${target} 纹理初始化存储!`);
+ }
+ }
+ else
+ {
+ const bufferSource = v as ITextureDataSource;
+ const { data, dataLayout, dataImageOrigin } = bufferSource;
+
+ //
+ const offset = dataLayout?.offset || 0;
+
+ //
+ const pixelStore: IGLTexturePixelStore = {};
+ pixelStore.unpackSkipPixels = dataImageOrigin?.[0] || 0;
+ pixelStore.unpackSkipRows = dataImageOrigin?.[1] || 0;
+ pixelStore.unpackSkipImages = dataImageOrigin?.[2] || 0;
+ pixelStore.unpackRowLength = dataLayout?.width;
+ pixelStore.unpackImageHeight = dataLayout?.height;
+
+ setTexturePixelStore(gl, pixelStore);
+
+ if (target === "TEXTURE_2D" || target === "TEXTURE_CUBE_MAP")
+ {
+ const bindTarget = target === "TEXTURE_CUBE_MAP" ? getTextureCubeMapTarget(depthOrArrayLayers) : target;
+ gl.texImage2D(gl[bindTarget], mipLevel, gl[internalformat], width, height, 0, gl[format], gl[type], data, offset);
+ }
+ else if (target === "TEXTURE_3D" || target === "TEXTURE_2D_ARRAY")
+ {
+ gl.texImage3D(gl[target], mipLevel, gl[internalformat], width, height, depth, 0, gl[format], gl[type], data, offset);
+ }
+ else
+ {
+ console.error(`未处理 ${target} 纹理初始化存储!`);
+ }
+ }
+ }
+ else
+ {
+ const imageSource = v as ITextureImageSource;
+ if (imageSource.image)
+ {
+ const { image, imageOrigin, flipY, premultipliedAlpha } = imageSource;
+
+ //
+ const pixelStore: IGLTexturePixelStore = {};
+ pixelStore.unpackSkipPixels = imageOrigin?.[0] || 0;
+ pixelStore.unpackSkipRows = imageOrigin?.[1] || 0;
+ pixelStore.unpackFlipY = flipY || false;
+ pixelStore.unpackPremulAlpha = premultipliedAlpha || false;
+
+ setTexturePixelStore(gl, pixelStore);
+
+ if (target === "TEXTURE_2D" || target === "TEXTURE_CUBE_MAP")
+ {
+ const bindTarget = target === "TEXTURE_CUBE_MAP" ? getTextureCubeMapTarget(depthOrArrayLayers) : target;
+ gl.texImage2D(gl[bindTarget], mipLevel, gl[internalformat], gl[format], gl[type], image);
+ }
+ else
+ {
+ console.error(`未处理 ${target} 纹理初始化存储!`);
+ }
+ }
+ else
+ {
+ const bufferSource = v as ITextureDataSource;
+ const { data, dataLayout, dataImageOrigin } = bufferSource;
+
+ //
+ const offset = dataLayout?.offset || 0;
+
+ //
+ const pixelStore: IGLTexturePixelStore = {};
+ pixelStore.unpackSkipPixels = dataImageOrigin?.[0] || 0;
+ pixelStore.unpackSkipRows = dataImageOrigin?.[1] || 0;
+ pixelStore.unpackSkipImages = dataImageOrigin?.[2] || 0;
+ pixelStore.unpackRowLength = dataLayout?.width;
+ pixelStore.unpackImageHeight = dataLayout?.height;
+
+ setTexturePixelStore(gl, pixelStore);
+
+ if (target === "TEXTURE_2D" || target === "TEXTURE_CUBE_MAP")
+ {
+ const bindTarget = target === "TEXTURE_CUBE_MAP" ? getTextureCubeMapTarget(depthOrArrayLayers) : target;
+ console.assert(offset === 0, `WebGL1中ITextureDataLayout.offset必须为0`);
+ gl.texImage2D(gl[bindTarget], mipLevel, gl[internalformat], width, height, 0, gl[format], gl[type], data);
+ }
+ else
+ {
+ console.error(`未处理 ${target} 纹理初始化存储!`);
+ }
+ }
+ }
+ });
+
+ //
+ if (generateMipmap)
{
- console.error(`未处理 ${target} 纹理初始化存储!`);
+ gl.generateMipmap(gl[target]);
}
}
else
{
- if (target === "TEXTURE_2D" || target === "TEXTURE_CUBE_MAP")
+ if (gl instanceof WebGL2RenderingContext)
{
- for (let i = 0; i < mipLevelCount; i++)
+ if (target === "TEXTURE_2D" || target === "TEXTURE_CUBE_MAP")
+ {
+ gl.texStorage2D(gl[target], mipLevelCount, gl[internalformat], width, height);
+ }
+ else if (target === "TEXTURE_3D" || target === "TEXTURE_2D_ARRAY")
{
- gl.texImage2D(gl[target], i, gl[format], width, height, 0, gl[format], gl[type], null)
+ gl.texStorage3D(gl[target], mipLevelCount, gl[internalformat], width, height, depth);
+ }
+ else
+ {
+ console.error(`未处理 ${target} 纹理初始化存储!`);
}
}
else
{
- console.error(`未处理 ${target} 纹理初始化存储!`);
+ if (target === "TEXTURE_2D" || target === "TEXTURE_CUBE_MAP")
+ {
+ for (let i = 0; i < mipLevelCount; i++)
+ {
+ gl.texImage2D(gl[target], i, gl[format], width, height, 0, gl[format], gl[type], null)
+ }
+ }
+ else
+ {
+ console.error(`未处理 ${target} 纹理初始化存储!`);
+ }
}
}
}
@@ -92,11 +245,9 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: ITexture)
// 更新纹理
const updateTexture = () =>
{
- const { sources: writeTextures } = texture;
+ const { writeTextures } = texture;
if (!writeTextures || writeTextures.length === 0) return;
- const { generateMipmap } = texture;
-
const target = getIGLTextureTarget(texture.dimension);
const { format, type } = getIGLTextureFormats(texture.format);
@@ -223,10 +374,6 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: ITexture)
}
}
});
- if (generateMipmap)
- {
- gl.generateMipmap(gl[target]);
- }
};
updateTexture();
--
Gitee
From 6f3fa9b56013515b35107d1725141ff989ff4f8a Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 2 Jan 2025 16:23:49 +0800
Subject: [PATCH 162/186] ITexture.writeTextures
---
src/caches/getGLTexture.ts | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/caches/getGLTexture.ts b/src/caches/getGLTexture.ts
index d839d3d..126b568 100644
--- a/src/caches/getGLTexture.ts
+++ b/src/caches/getGLTexture.ts
@@ -162,7 +162,7 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: ITexture)
if (target === "TEXTURE_2D" || target === "TEXTURE_CUBE_MAP")
{
const bindTarget = target === "TEXTURE_CUBE_MAP" ? getTextureCubeMapTarget(depthOrArrayLayers) : target;
- gl.texImage2D(gl[bindTarget], mipLevel, gl[internalformat], gl[format], gl[type], image);
+ gl.texImage2D(gl[bindTarget], mipLevel, gl[format], gl[format], gl[type], image);
}
else
{
@@ -191,7 +191,7 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: ITexture)
{
const bindTarget = target === "TEXTURE_CUBE_MAP" ? getTextureCubeMapTarget(depthOrArrayLayers) : target;
console.assert(offset === 0, `WebGL1中ITextureDataLayout.offset必须为0`);
- gl.texImage2D(gl[bindTarget], mipLevel, gl[internalformat], width, height, 0, gl[format], gl[type], data);
+ gl.texImage2D(gl[bindTarget], mipLevel, gl[format], width, height, 0, gl[format], gl[type], data);
}
else
{
@@ -242,6 +242,13 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: ITexture)
}
createTexture();
+ const updateSources = () =>
+ {
+ webGLTexture.destroy();
+ };
+
+ watcher.watch(texture, "sources", updateSources);
+
// 更新纹理
const updateTexture = () =>
{
@@ -378,7 +385,7 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: ITexture)
updateTexture();
watcher.watchs(texture, ["generateMipmap"], updateTexture);
- watcher.watch(texture, "sources", updateTexture);
+ watcher.watch(texture, "writeTextures", updateTexture);
// 监听纹理尺寸发生变化
const resize = (newValue: ITextureSize, oldValue: ITextureSize) =>
@@ -405,7 +412,8 @@ export function getGLTexture(gl: WebGLRenderingContext, texture: ITexture)
gl._textures.delete(texture);
//
watcher.unwatchs(texture, ["generateMipmap"], updateTexture);
- watcher.unwatch(texture, "sources", updateTexture);
+ watcher.unwatch(texture, "sources", updateSources);
+ watcher.unwatch(texture, "writeTextures", updateTexture);
watcher.unwatch(texture, "size", resize);
//
delete webGLTexture.destroy;
--
Gitee
From 178636fb761123b97e3aa045b9a7c4c66197728e Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 2 Jan 2025 16:37:33 +0800
Subject: [PATCH 163/186] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20getIGLTextureMinFi?=
=?UTF-8?q?lter=20=E5=AF=BC=E8=87=B4=E7=BA=B9=E7=90=86=E6=97=A0=E6=B3=95?=
=?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/caches/getGLSampler.ts | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/caches/getGLSampler.ts b/src/caches/getGLSampler.ts
index dc013d8..b252432 100644
--- a/src/caches/getGLSampler.ts
+++ b/src/caches/getGLSampler.ts
@@ -70,7 +70,7 @@ const addressModeMap: { [key: string]: IGLTextureWrap } = {
"mirror-repeat": "MIRRORED_REPEAT",
};
-export function getIGLTextureMinFilter(minFilter: IFilterMode = "nearest", mipmapFilter: IFilterMode = "nearest"): IGLTextureMinFilter
+export function getIGLTextureMinFilter(minFilter: IFilterMode = "nearest", mipmapFilter?: IFilterMode): IGLTextureMinFilter
{
let glMinFilter: IGLTextureMinFilter;
if (minFilter === "linear")
@@ -79,10 +79,14 @@ export function getIGLTextureMinFilter(minFilter: IFilterMode = "nearest", mipma
{
glMinFilter = "LINEAR_MIPMAP_LINEAR";
}
- else
+ else if (mipmapFilter === "nearest")
{
glMinFilter = "LINEAR_MIPMAP_NEAREST";
}
+ else
+ {
+ glMinFilter = "LINEAR";
+ }
}
else
{
@@ -90,10 +94,14 @@ export function getIGLTextureMinFilter(minFilter: IFilterMode = "nearest", mipma
{
glMinFilter = "NEAREST_MIPMAP_LINEAR";
}
- else
+ else if (mipmapFilter === "nearest")
{
glMinFilter = "NEAREST_MIPMAP_NEAREST";
}
+ else
+ {
+ glMinFilter = "NEAREST";
+ }
}
return glMinFilter;
--
Gitee
From 6eb9fc5651507b76681e78a09e6ba291b2ec572e Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 2 Jan 2025 16:56:04 +0800
Subject: [PATCH 164/186] =?UTF-8?q?ISampler.addressModeU=20addressModeV=20?=
=?UTF-8?q?addressModeW=20=E9=BB=98=E8=AE=A4=E4=B8=BA=20"repeat"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/caches/getGLSampler.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/caches/getGLSampler.ts b/src/caches/getGLSampler.ts
index b252432..20617d6 100644
--- a/src/caches/getGLSampler.ts
+++ b/src/caches/getGLSampler.ts
@@ -55,7 +55,7 @@ export function deleteSampler(gl: WebGLRenderingContext, sampler?: IGLSampler)
}
}
-export function getIGLTextureWrap(addressMode: IAddressMode = "clamp-to-edge")
+export function getIGLTextureWrap(addressMode: IAddressMode = "repeat")
{
const textureWrap: IGLTextureWrap = addressModeMap[addressMode];
--
Gitee
From 725a00c52cc8867e6ed592827a395f125d586cc5 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 3 Jan 2025 22:02:13 +0800
Subject: [PATCH 165/186] IGLSampler -> ISampler
---
.../src/WebGL2Samples/draw_image_space.ts | 6 +--
examples/src/WebGL2Samples/fbo_blit.ts | 8 ++--
examples/src/WebGL2Samples/fbo_multisample.ts | 6 +--
.../WebGL2Samples/fbo_new_blend_equation.ts | 6 +--
examples/src/WebGL2Samples/fbo_read_pixels.ts | 6 +--
.../WebGL2Samples/fbo_rtt_depth_texture.ts | 6 +--
.../src/WebGL2Samples/fbo_rtt_draw_buffers.ts | 8 ++--
.../WebGL2Samples/fbo_rtt_texture_array.ts | 6 +--
.../src/WebGL2Samples/geo_vertex_format.ts | 6 +--
examples/src/WebGL2Samples/glsl_centroid.ts | 6 +--
.../WebGL2Samples/glsl_non_square_matrix.ts | 6 +--
examples/src/WebGL2Samples/sampler_filter.ts | 6 +--
examples/src/WebGL2Samples/sampler_object.ts | 10 ++---
examples/src/WebGL2Samples/sampler_wrap.ts | 6 +--
.../src/WebGL2Samples/texture_2d_array.ts | 6 +--
examples/src/WebGL2Samples/texture_3d.ts | 6 +--
.../src/WebGL2Samples/texture_derivative.ts | 6 +--
examples/src/WebGL2Samples/texture_fetch.ts | 6 +--
examples/src/WebGL2Samples/texture_format.ts | 6 +--
examples/src/WebGL2Samples/texture_grad.ts | 6 +--
.../src/WebGL2Samples/texture_immutable.ts | 8 ++--
examples/src/WebGL2Samples/texture_integer.ts | 6 +--
examples/src/WebGL2Samples/texture_lod.ts | 6 +--
examples/src/WebGL2Samples/texture_offset.ts | 6 +--
.../src/WebGL2Samples/texture_pixel_store.ts | 6 +--
examples/src/WebGL2Samples/texture_srgb.ts | 6 +--
examples/src/WebGL2Samples/texture_vertex.ts | 6 +--
examples/src/test/fractalCube.ts | 4 +-
examples/src/webgl-examples/sample6.ts | 6 +--
examples/src/webgl-examples/sample7.ts | 6 +--
examples/src/webgl-examples/sample8.ts | 6 +--
src/RunWebGL.ts | 16 ++++----
src/WebGL.ts | 5 +--
src/caches/getGLSampler.ts | 15 +++----
src/data/IGLSampler.ts | 39 -------------------
src/data/IGLSamplerTexture.ts | 7 ++--
36 files changed, 117 insertions(+), 159 deletions(-)
diff --git a/examples/src/WebGL2Samples/draw_image_space.ts b/examples/src/WebGL2Samples/draw_image_space.ts
index 21314b3..9751293 100644
--- a/examples/src/WebGL2Samples/draw_image_space.ts
+++ b/examples/src/WebGL2Samples/draw_image_space.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPipeline, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPipeline, ISampler, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -18,7 +18,7 @@ loadImage("../../assets/img/Di-3d.png", (img) =>
sources: [{ image: img, flipY: false }],
format: "rgba8unorm",
};
- const sampler: IGLSampler = {
+ const sampler: ISampler = {
minFilter: "linear",
magFilter: "linear",
};
diff --git a/examples/src/WebGL2Samples/fbo_blit.ts b/examples/src/WebGL2Samples/fbo_blit.ts
index 984ef35..127c5e1 100644
--- a/examples/src/WebGL2Samples/fbo_blit.ts
+++ b/examples/src/WebGL2Samples/fbo_blit.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, ITextureView, IVertexAttributes, IViewport } from "@feng3d/render-api";
-import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPipeline, ISampler, ITexture, ITextureView, IVertexAttributes } from "@feng3d/render-api";
+import { IGLBlitFramebuffer, IGLBlitFramebufferItem, IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -58,7 +58,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
image: image, flipY: true
}],
};
- const samplerDiffuse: IGLSampler = {
+ const samplerDiffuse: ISampler = {
minFilter: "linear",
magFilter: "linear",
};
@@ -67,7 +67,7 @@ loadImage("../../assets/img/Di-3d.png", (image) =>
format: "rgba8unorm",
size: [FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y],
};
- const samplerColorBuffer: IGLSampler = {
+ const samplerColorBuffer: ISampler = {
minFilter: "linear",
magFilter: "linear",
};
diff --git a/examples/src/WebGL2Samples/fbo_multisample.ts b/examples/src/WebGL2Samples/fbo_multisample.ts
index 0c454e4..8b4b972 100644
--- a/examples/src/WebGL2Samples/fbo_multisample.ts
+++ b/examples/src/WebGL2Samples/fbo_multisample.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -74,7 +74,7 @@ const texture: ITexture = {
format: "rgba8unorm",
size: [FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y]
};
-const sampler: IGLSampler = { minFilter: "nearest", magFilter: "nearest" };
+const sampler: ISampler = { minFilter: "nearest", magFilter: "nearest" };
// -- Init Frame Buffers
const framebuffer: IRenderPassDescriptor = {
diff --git a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
index 24a57f4..211e340 100644
--- a/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
+++ b/examples/src/WebGL2Samples/fbo_new_blend_equation.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IViewport } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ISampler, ITexture, IVertexAttributes, IViewport } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -92,7 +92,7 @@ const vertexArray: { vertices?: IVertexAttributes } = {
};
// -- Load texture then render
-const sampler: IGLSampler = {
+const sampler: ISampler = {
minFilter: "linear",
magFilter: "linear"
};
diff --git a/examples/src/WebGL2Samples/fbo_read_pixels.ts b/examples/src/WebGL2Samples/fbo_read_pixels.ts
index 4427874..beb7eb6 100644
--- a/examples/src/WebGL2Samples/fbo_read_pixels.ts
+++ b/examples/src/WebGL2Samples/fbo_read_pixels.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -107,7 +107,7 @@ const texture: ITexture = {
size: [w, h, 3],
format: "rgba8unorm",
};
-const sampler: IGLSampler = { lodMinClamp: 0, lodMaxClamp: 0, minFilter: "nearest", magFilter: "nearest" };
+const sampler: ISampler = { lodMinClamp: 0, lodMaxClamp: 0, minFilter: "nearest", magFilter: "nearest" };
// -- Initialize frame buffer
diff --git a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
index e6e0ebd..75f628d 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_depth_texture.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -80,7 +80,7 @@ const depthTexture: ITexture = {
size: [windowSize.x, windowSize.y],
format: "depth16unorm",
};
-const depthSampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "nearest", magFilter: "nearest" };
+const depthSampler: ISampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "nearest", magFilter: "nearest" };
// -- Initialize frame buffer
diff --git a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
index 576c51f..70b60f8 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_draw_buffers.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassDescriptor, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -79,13 +79,13 @@ const color1Texture: ITexture = {
format: "rgba8unorm",
size: [windowSize.x, windowSize.y],
};
-const color1Sampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "nearest", magFilter: "nearest" };
+const color1Sampler: ISampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "nearest", magFilter: "nearest" };
const color2Texture: ITexture = {
format: "rgba8unorm",
size: [windowSize.x, windowSize.y],
};
-const color2Sampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "nearest", magFilter: "nearest" };
+const color2Sampler: ISampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "nearest", magFilter: "nearest" };
// -- Initialize frame buffer
diff --git a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
index 239dfc4..1380527 100644
--- a/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
+++ b/examples/src/WebGL2Samples/fbo_rtt_texture_array.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -107,7 +107,7 @@ const texture: ITexture = {
format: "rgba8unorm",
size: [w, h, 3],
};
-const sampler: IGLSampler = { minFilter: "nearest", magFilter: "nearest", lodMinClamp: 0, lodMaxClamp: 0 };
+const sampler: ISampler = { minFilter: "nearest", magFilter: "nearest", lodMinClamp: 0, lodMaxClamp: 0 };
// -- Initialize frame buffer
diff --git a/examples/src/WebGL2Samples/geo_vertex_format.ts b/examples/src/WebGL2Samples/geo_vertex_format.ts
index 595c0ec..3314559 100644
--- a/examples/src/WebGL2Samples/geo_vertex_format.ts
+++ b/examples/src/WebGL2Samples/geo_vertex_format.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { HalfFloat } from "./third-party/HalfFloatUtility";
import { getShaderSource, loadImage } from "./utility";
@@ -163,7 +163,7 @@ import { getShaderSource, loadImage } from "./utility";
const imageUrl = "../../assets/img/Di-3d.png";
let texture: ITexture;
- let sampler: IGLSampler;
+ let sampler: ISampler;
loadImage(imageUrl, function (image)
{
// -- Init 2D Texture
diff --git a/examples/src/WebGL2Samples/glsl_centroid.ts b/examples/src/WebGL2Samples/glsl_centroid.ts
index 4d103bf..84c2610 100644
--- a/examples/src/WebGL2Samples/glsl_centroid.ts
+++ b/examples/src/WebGL2Samples/glsl_centroid.ts
@@ -1,5 +1,5 @@
-import { IPassEncoder, IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IViewport } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IPassEncoder, IRenderObject, IRenderPass, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, ITexture, IVertexAttributes, IViewport } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource } from "./utility";
@@ -105,7 +105,7 @@ const FRAMEBUFFER_SIZE = {
y: canvas.height
};
const textures: ITexture[] = [];
-const samplers: IGLSampler[] = [];
+const samplers: ISampler[] = [];
for (let i = 0; i < VIEWPORTS.MAX; ++i)
{
diff --git a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
index 8a113e5..b0971f8 100644
--- a/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
+++ b/examples/src/WebGL2Samples/glsl_non_square_matrix.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -54,7 +54,7 @@ loadImage("../../assets/img/Di-3d.png", function (image)
image: image, flipY: false,
}]
};
- const sampler: IGLSampler = { minFilter: "nearest", magFilter: "nearest" };
+ const sampler: ISampler = { minFilter: "nearest", magFilter: "nearest" };
// -- Render
const matrix = new Float32Array([
diff --git a/examples/src/WebGL2Samples/sampler_filter.ts b/examples/src/WebGL2Samples/sampler_filter.ts
index 73571f6..b34d8bd 100644
--- a/examples/src/WebGL2Samples/sampler_filter.ts
+++ b/examples/src/WebGL2Samples/sampler_filter.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -94,7 +94,7 @@ const vertexArray: { vertices?: IVertexAttributes } = {
// -- Initialize samplers
-const samplers: IGLSampler[] = new Array(Corners.MAX);
+const samplers: ISampler[] = new Array(Corners.MAX);
for (let i = 0; i < Corners.MAX; ++i)
{
samplers[i] = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", addressModeW: "clamp-to-edge" };
diff --git a/examples/src/WebGL2Samples/sampler_object.ts b/examples/src/WebGL2Samples/sampler_object.ts
index 681000d..1825af9 100644
--- a/examples/src/WebGL2Samples/sampler_object.ts
+++ b/examples/src/WebGL2Samples/sampler_object.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -50,17 +50,15 @@ const vertexArray: { vertices?: IVertexAttributes } = {
// -- Initialize samplers
-const samplerA: IGLSampler = {
+const samplerA: ISampler = {
minFilter: "nearest", magFilter: "nearest", mipmapFilter: "nearest",
addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", addressModeW: "clamp-to-edge",
lodMinClamp: -1000.0, lodMaxClamp: 1000.0,
- compareMode: "NONE", compare: "LEQUAL",
};
-const samplerB: IGLSampler = {
+const samplerB: ISampler = {
minFilter: "linear", magFilter: "linear", mipmapFilter: "linear",
addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", addressModeW: "clamp-to-edge",
lodMinClamp: -1000.0, lodMaxClamp: 1000.0,
- compareMode: "NONE", compare: "LEQUAL",
};
// -- Load texture then render
diff --git a/examples/src/WebGL2Samples/sampler_wrap.ts b/examples/src/WebGL2Samples/sampler_wrap.ts
index f05bc25..df7eacc 100644
--- a/examples/src/WebGL2Samples/sampler_wrap.ts
+++ b/examples/src/WebGL2Samples/sampler_wrap.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
const canvas = document.createElement("canvas");
@@ -94,7 +94,7 @@ const vertexArray: { vertices?: IVertexAttributes } = {
// -- Initialize samplers
-const samplers: IGLSampler[] = new Array(Corners.MAX);
+const samplers: ISampler[] = new Array(Corners.MAX);
for (let i = 0; i < Corners.MAX; ++i)
{
diff --git a/examples/src/WebGL2Samples/texture_2d_array.ts b/examples/src/WebGL2Samples/texture_2d_array.ts
index 54ada88..c69e0cb 100644
--- a/examples/src/WebGL2Samples/texture_2d_array.ts
+++ b/examples/src/WebGL2Samples/texture_2d_array.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -46,7 +46,7 @@ import { getShaderSource, loadImage } from "./utility";
};
let texture: ITexture;
- let sampler: IGLSampler;
+ let sampler: ISampler;
loadImage("../../assets/img/di-animation-array.jpg", function (image)
{
const NUM_IMAGES = 3;
diff --git a/examples/src/WebGL2Samples/texture_3d.ts b/examples/src/WebGL2Samples/texture_3d.ts
index 91e04fc..3bf11f3 100644
--- a/examples/src/WebGL2Samples/texture_3d.ts
+++ b/examples/src/WebGL2Samples/texture_3d.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource } from "./utility";
@@ -86,7 +86,7 @@ import { getShaderSource } from "./utility";
generateMipmap: true,
sources: [{ __type: "TextureDataSource", mipLevel: 0, size: [SIZE, SIZE, SIZE], data: data }],
};
- const sampler: IGLSampler = {
+ const sampler: ISampler = {
lodMinClamp: 0,
lodMaxClamp: Math.log2(SIZE),
minFilter: "linear",
diff --git a/examples/src/WebGL2Samples/texture_derivative.ts b/examples/src/WebGL2Samples/texture_derivative.ts
index bf093d2..26fcca6 100644
--- a/examples/src/WebGL2Samples/texture_derivative.ts
+++ b/examples/src/WebGL2Samples/texture_derivative.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -128,7 +128,7 @@ import { getShaderSource, loadImage } from "./utility";
const imageUrl = "../../assets/img/Di-3d.png";
let texture: ITexture;
- let sampler: IGLSampler;
+ let sampler: ISampler;
loadImage(imageUrl, function (image)
{
// -- Init 2D Texture
diff --git a/examples/src/WebGL2Samples/texture_fetch.ts b/examples/src/WebGL2Samples/texture_fetch.ts
index fffa8ed..03762c8 100644
--- a/examples/src/WebGL2Samples/texture_fetch.ts
+++ b/examples/src/WebGL2Samples/texture_fetch.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -54,7 +54,7 @@ import { getShaderSource, loadImage } from "./utility";
mipLevel: 0, image: image, flipY: false,
}],
};
- const sampler: IGLSampler = {
+ const sampler: ISampler = {
minFilter: "nearest",
magFilter: "nearest",
};
diff --git a/examples/src/WebGL2Samples/texture_format.ts b/examples/src/WebGL2Samples/texture_format.ts
index 1b42d55..0630d44 100644
--- a/examples/src/WebGL2Samples/texture_format.ts
+++ b/examples/src/WebGL2Samples/texture_format.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, ITextureFormat, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, ISampler, ITexture, ITextureFormat, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -136,7 +136,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Init Texture
const textures: ITexture[] = new Array(TextureTypes.MAX);
- const samplers: IGLSampler[] = new Array(TextureTypes.MAX);
+ const samplers: ISampler[] = new Array(TextureTypes.MAX);
let i = 0;
for (i = 0; i < TextureTypes.MAX; ++i)
{
diff --git a/examples/src/WebGL2Samples/texture_grad.ts b/examples/src/WebGL2Samples/texture_grad.ts
index 1a2e44a..f2bf9a6 100644
--- a/examples/src/WebGL2Samples/texture_grad.ts
+++ b/examples/src/WebGL2Samples/texture_grad.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { getShaderSource, loadImage } from "./utility";
@@ -122,7 +122,7 @@ import { getShaderSource, loadImage } from "./utility";
const imageUrl = "../../assets/img/Di-3d.png";
let texture: ITexture;
- let sampler: IGLSampler;
+ let sampler: ISampler;
loadImage(imageUrl, function (image)
{
// -- Init 2D Texture
diff --git a/examples/src/WebGL2Samples/texture_immutable.ts b/examples/src/WebGL2Samples/texture_immutable.ts
index 6ceff38..e8a9981 100644
--- a/examples/src/WebGL2Samples/texture_immutable.ts
+++ b/examples/src/WebGL2Samples/texture_immutable.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { snoise } from "./third-party/noise3D";
import { getShaderSource, loadImage } from "./utility";
@@ -91,7 +91,7 @@ import { getShaderSource, loadImage } from "./utility";
image: image, flipY: false,
}],
};
- const sampler2D: IGLSampler = {
+ const sampler2D: ISampler = {
minFilter: "nearest",
magFilter: "linear",
addressModeU: "clamp-to-edge",
@@ -174,7 +174,7 @@ import { getShaderSource, loadImage } from "./utility";
size: [SIZE, SIZE, SIZE],
sources: [{ __type: "TextureDataSource", size: [SIZE, SIZE, SIZE], data: data }],
};
- const sampler3D: IGLSampler = {
+ const sampler3D: ISampler = {
lodMinClamp: 0,
lodMaxClamp: Math.log2(SIZE),
minFilter: "linear",
diff --git a/examples/src/WebGL2Samples/texture_integer.ts b/examples/src/WebGL2Samples/texture_integer.ts
index 76ec47b..c3c4e4a 100644
--- a/examples/src/WebGL2Samples/texture_integer.ts
+++ b/examples/src/WebGL2Samples/texture_integer.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -56,7 +56,7 @@ import { getShaderSource, loadImage } from "./utility";
mipLevel: 0, image: image, flipY: false,
}],
};
- const sampler: IGLSampler = {
+ const sampler: ISampler = {
minFilter: "nearest",
magFilter: "nearest",
};
diff --git a/examples/src/WebGL2Samples/texture_lod.ts b/examples/src/WebGL2Samples/texture_lod.ts
index ddfd8bc..2720e97 100644
--- a/examples/src/WebGL2Samples/texture_lod.ts
+++ b/examples/src/WebGL2Samples/texture_lod.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -121,7 +121,7 @@ import { getShaderSource, loadImage } from "./utility";
// -- Load texture then render
const imageUrl = "../../assets/img/Di-3d.png";
const textures: ITexture[] = new Array(Corners.MAX);
- const samplers: IGLSampler[] = new Array(Corners.MAX);
+ const samplers: ISampler[] = new Array(Corners.MAX);
loadImage(imageUrl, function (image)
{
textures[Corners.TOP_LEFT] = {
diff --git a/examples/src/WebGL2Samples/texture_offset.ts b/examples/src/WebGL2Samples/texture_offset.ts
index 17e75f9..dd59350 100644
--- a/examples/src/WebGL2Samples/texture_offset.ts
+++ b/examples/src/WebGL2Samples/texture_offset.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, ISampler, ITexture, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -77,7 +77,7 @@ import { getShaderSource, loadImage } from "./utility";
format: "rgba8unorm",
sources: [{ mipLevel: 0, image: image, flipY: false, }],
};
- const sampler: IGLSampler = {
+ const sampler: ISampler = {
minFilter: "nearest",
magFilter: "nearest",
addressModeU: "clamp-to-edge",
diff --git a/examples/src/WebGL2Samples/texture_pixel_store.ts b/examples/src/WebGL2Samples/texture_pixel_store.ts
index ea1046d..cfe63ca 100644
--- a/examples/src/WebGL2Samples/texture_pixel_store.ts
+++ b/examples/src/WebGL2Samples/texture_pixel_store.ts
@@ -1,5 +1,5 @@
-import { IIndicesDataTypes, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IRenderPass, IRenderPassObject, IRenderPipeline, ISampler, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { getIGLBuffer, IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
(function ()
@@ -71,7 +71,7 @@ import { getShaderSource, loadImage } from "./utility";
dataImageOrigin: [image.width / 4, image.width / 4],
}]
};
- const sampler: IGLSampler = {
+ const sampler: ISampler = {
minFilter: "nearest",
magFilter: "nearest",
};
diff --git a/examples/src/WebGL2Samples/texture_srgb.ts b/examples/src/WebGL2Samples/texture_srgb.ts
index e7de6a2..773b906 100644
--- a/examples/src/WebGL2Samples/texture_srgb.ts
+++ b/examples/src/WebGL2Samples/texture_srgb.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderPass, IRenderPassObject, IRenderPipeline, ISampler, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { getIGLBuffer, IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource, loadImage } from "./utility";
@@ -53,7 +53,7 @@ import { getShaderSource, loadImage } from "./utility";
const imageUrl = "../../assets/img/Di-3d.png";
let texture: ITexture;
- let sampler: IGLSampler;
+ let sampler: ISampler;
loadImage(imageUrl, function (image)
{
texture = {
diff --git a/examples/src/WebGL2Samples/texture_vertex.ts b/examples/src/WebGL2Samples/texture_vertex.ts
index d3d985e..152a8ca 100644
--- a/examples/src/WebGL2Samples/texture_vertex.ts
+++ b/examples/src/WebGL2Samples/texture_vertex.ts
@@ -1,5 +1,5 @@
-import { IIndicesDataTypes, IPrimitiveTopology, IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
-import { getIVertexFormat, IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IIndicesDataTypes, IPrimitiveTopology, IRenderObject, IRenderPass, IRenderPassObject, IRenderPipeline, ISampler, ITexture, IVertexAttributes, IVertexDataTypes } from "@feng3d/render-api";
+import { getIVertexFormat, IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { mat4, vec3 } from "gl-matrix";
import { GlTFLoader, Primitive } from "./third-party/gltf-loader";
@@ -54,7 +54,7 @@ import { getShaderSource, loadImage } from "./utility";
let indicesBuffer: IIndicesDataTypes;
let texture: ITexture;
- let sampler: IGLSampler;
+ let sampler: ISampler;
const ro: IRenderObject = {
pipeline: program,
diff --git a/examples/src/test/fractalCube.ts b/examples/src/test/fractalCube.ts
index a7da320..32440d3 100644
--- a/examples/src/test/fractalCube.ts
+++ b/examples/src/test/fractalCube.ts
@@ -1,5 +1,5 @@
import { IRenderObject, ISubmit, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLSampler, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, ISampler, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -23,7 +23,7 @@ async function main()
const texture: {
texture: ITexture;
- sampler: IGLSampler;
+ sampler: ISampler;
} = { texture: { size: [canvas.width, canvas.height] }, sampler: {} };
const renderObject: IRenderObject = {
diff --git a/examples/src/webgl-examples/sample6.ts b/examples/src/webgl-examples/sample6.ts
index a122d5e..847c71c 100644
--- a/examples/src/webgl-examples/sample6.ts
+++ b/examples/src/webgl-examples/sample6.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLSampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, ISampler, ITexture } from "@feng3d/render-api";
+import { WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -227,7 +227,7 @@ async function loadTexture(url: string)
generateMipmap,
};
- let sampler: IGLSampler = {};
+ let sampler: ISampler = {};
if (generateMipmap)
{
sampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "linear" };
diff --git a/examples/src/webgl-examples/sample7.ts b/examples/src/webgl-examples/sample7.ts
index 4181ce0..a171f9c 100644
--- a/examples/src/webgl-examples/sample7.ts
+++ b/examples/src/webgl-examples/sample7.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLSampler, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, ISampler, ITexture } from "@feng3d/render-api";
+import { IGLSamplerTexture, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -295,7 +295,7 @@ async function loadTexture(url: string)
generateMipmap,
};
- let sampler: IGLSampler = {};
+ let sampler: ISampler = {};
if (!generateMipmap)
{
diff --git a/examples/src/webgl-examples/sample8.ts b/examples/src/webgl-examples/sample8.ts
index f2a5f92..4369f56 100644
--- a/examples/src/webgl-examples/sample8.ts
+++ b/examples/src/webgl-examples/sample8.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, ITexture } from "@feng3d/render-api";
-import { IGLSampler, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, ISampler, ITexture } from "@feng3d/render-api";
+import { IGLSamplerTexture, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
@@ -325,7 +325,7 @@ function initTexture(): IGLSamplerTexture
format: "rgba8unorm",
sources: [{ __type: "TextureDataSource", size: [1, 1], data: new Uint8Array([0, 0, 255, 255]) }],
};
- const sampler: IGLSampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "linear" };
+ const sampler: ISampler = { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", minFilter: "linear" };
return { texture, sampler };
}
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index bb26455..d1e100e 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,4 +1,4 @@
-import { getBlendConstantColor, IBlendComponent, IBuffer, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, IScissorRect, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IBuffer, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport } from "@feng3d/render-api";
import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLFramebuffer } from "./caches/getGLFramebuffer";
@@ -17,7 +17,7 @@ import { IGLDrawElementType } from "./data/IGLBuffer";
import { IGLCopyBufferToBuffer } from "./data/IGLCopyBufferToBuffer";
import { IGLCompareFunction, IGLStencilFunc, IGLStencilOp } from "./data/IGLDepthStencilState";
import { IGLOcclusionQuery } from "./data/IGLOcclusionQuery";
-import { IGLSampler, IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "./data/IGLSampler";
+import { IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "./data/IGLSampler";
import { IGLSamplerTexture } from "./data/IGLSamplerTexture";
import { IGLTextureTarget } from "./data/IGLTexture";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
@@ -53,7 +53,7 @@ declare global
wrapS?: IGLTextureWrap,
wrapT?: IGLTextureWrap,
wrapR?: IGLTextureWrap,
- anisotropy?: number,
+ maxAnisotropy?: number,
lodMinClamp?: number;
lodMaxClamp?: number;
}
@@ -391,7 +391,7 @@ export class RunWebGL
/**
* 设置采样参数
*/
- private runSampler(gl: WebGLRenderingContext, textureTarget: IGLTextureTarget, webGLTexture: WebGLTexture, sampler: IGLSampler, textureID: number)
+ private runSampler(gl: WebGLRenderingContext, textureTarget: IGLTextureTarget, webGLTexture: WebGLTexture, sampler: ISampler, textureID: number)
{
if (gl instanceof WebGL2RenderingContext)
{
@@ -429,15 +429,15 @@ export class RunWebGL
}
//
- const anisotropy = sampler?.anisotropy || 1;
- if (webGLTexture.anisotropy !== anisotropy)
+ const maxAnisotropy = sampler?.maxAnisotropy || 1;
+ if (webGLTexture.maxAnisotropy !== maxAnisotropy)
{
const extension = gl.getExtension("EXT_texture_filter_anisotropic");
if (extension)
{
- gl.texParameterf(gl[textureTarget], extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(anisotropy, gl._capabilities.maxAnisotropy));
+ gl.texParameterf(gl[textureTarget], extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(maxAnisotropy, gl._capabilities.maxAnisotropy));
}
- webGLTexture.anisotropy = anisotropy;
+ webGLTexture.maxAnisotropy = maxAnisotropy;
}
}
diff --git a/src/WebGL.ts b/src/WebGL.ts
index caef269..00cceef 100644
--- a/src/WebGL.ts
+++ b/src/WebGL.ts
@@ -1,4 +1,4 @@
-import { IBuffer, IRenderPassDescriptor, IRenderPipeline, ISubmit, ITexture } from "@feng3d/render-api";
+import { IBuffer, IRenderPassDescriptor, IRenderPipeline, ISampler, ISubmit, ITexture } from "@feng3d/render-api";
import { RunWebGL } from "./RunWebGL";
import { deleteBuffer } from "./caches/getGLBuffer";
@@ -12,7 +12,6 @@ import { deleteTransformFeedback } from "./caches/getGLTransformFeedback";
import { IGLCanvasContext } from "./data/IGLCanvasContext";
import { IGLReadPixels } from "./data/IGLReadPixels";
import { IGLRenderbuffer } from "./data/IGLRenderbuffer";
-import { IGLSampler } from "./data/IGLSampler";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
import { readPixels } from "./utils/readPixels";
@@ -69,7 +68,7 @@ export class WebGL
deleteTexture(this._gl, texture);
}
- deleteSampler(sampler: IGLSampler)
+ deleteSampler(sampler: ISampler)
{
deleteSampler(this._gl, sampler);
}
diff --git a/src/caches/getGLSampler.ts b/src/caches/getGLSampler.ts
index 20617d6..dca0041 100644
--- a/src/caches/getGLSampler.ts
+++ b/src/caches/getGLSampler.ts
@@ -1,16 +1,17 @@
-import { IAddressMode, IFilterMode } from "@feng3d/render-api";
+import { IAddressMode, IFilterMode, ISampler } from "@feng3d/render-api";
import { IGLCompareFunction } from "../data/IGLDepthStencilState";
-import { IGLSampler, IGLSamplerCompareMode, IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "../data/IGLSampler";
+import { IGLSamplerCompareMode, IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "../data/IGLSampler";
+import { getIGLCompareFunction } from "../runs/runDepthState";
declare global
{
interface WebGLRenderingContext
{
- _samplers: Map;
+ _samplers: Map;
}
}
-export function getGLSampler(gl: WebGLRenderingContext, sampler?: IGLSampler)
+export function getGLSampler(gl: WebGLRenderingContext, sampler?: ISampler)
{
let webGLSampler = gl._samplers.get(sampler);
if (webGLSampler) return webGLSampler;
@@ -27,8 +28,8 @@ export function getGLSampler(gl: WebGLRenderingContext, sampler?: IGLSampler)
const wrapR: IGLTextureWrap = getIGLTextureWrap(sampler.addressModeW);
const lodMinClamp = sampler.lodMinClamp || 0;
const lodMaxClamp = sampler.lodMaxClamp || 16;
- const compareMode: IGLSamplerCompareMode = sampler.compareMode || "NONE";
- const compare: IGLCompareFunction = sampler.compare || "LEQUAL";
+ const compareMode: IGLSamplerCompareMode = sampler.compare ? "COMPARE_REF_TO_TEXTURE" : "NONE";
+ const compare: IGLCompareFunction = getIGLCompareFunction(sampler.compare ?? "less-equal");
//
gl.samplerParameteri(webGLSampler, gl.TEXTURE_MIN_FILTER, gl[minFilter]);
@@ -45,7 +46,7 @@ export function getGLSampler(gl: WebGLRenderingContext, sampler?: IGLSampler)
return webGLSampler;
}
-export function deleteSampler(gl: WebGLRenderingContext, sampler?: IGLSampler)
+export function deleteSampler(gl: WebGLRenderingContext, sampler?: ISampler)
{
if (gl instanceof WebGL2RenderingContext)
{
diff --git a/src/data/IGLSampler.ts b/src/data/IGLSampler.ts
index b952168..681070d 100644
--- a/src/data/IGLSampler.ts
+++ b/src/data/IGLSampler.ts
@@ -1,42 +1,3 @@
-import { ISampler } from "@feng3d/render-api";
-import { IGLCompareFunction } from "./IGLDepthStencilState";
-
-export interface IGLSampler extends ISampler
-{
- /**
- * 各向异性过滤。使用各向异性过滤能够使纹理的效果更好,但是会消耗更多的内存、CPU、GPU时间。默认为1。
- *
- * 默认 1。
- */
- anisotropy?: number;
-
- /**
- * 采样时使用的最小Lod等级。
- *
- * 默认 0。
- */
- lodMinClamp?: number;
-
- /**
- * 采样时使用的最大Lod等级。
- *
- * 默认 16 。
- */
- lodMaxClamp?: number;
-
- /**
- * 默认 "NONE"。
- */
- compareMode?: IGLSamplerCompareMode;
-
- /**
- * 比较函数。
- *
- * 默认 "LEQUAL"。
- */
- compare?: IGLCompareFunction;
-}
-
export type IGLSamplerCompareMode = "NONE" | "COMPARE_REF_TO_TEXTURE";
/**
diff --git a/src/data/IGLSamplerTexture.ts b/src/data/IGLSamplerTexture.ts
index 2bfdf3a..2a1bb57 100644
--- a/src/data/IGLSamplerTexture.ts
+++ b/src/data/IGLSamplerTexture.ts
@@ -1,5 +1,4 @@
-import { ITexture } from "@feng3d/render-api";
-import { IGLSampler } from "./IGLSampler";
+import { ISampler, ITexture } from "@feng3d/render-api";
/**
* 采样纹理。
@@ -16,5 +15,5 @@ export interface IGLSamplerTexture
/**
* 采样器。
*/
- sampler?: IGLSampler;
-}
\ No newline at end of file
+ sampler?: ISampler;
+}
--
Gitee
From 656462633eab0fe01db530eb5e201f3cae808fc7 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 4 Jan 2025 12:56:10 +0800
Subject: [PATCH 166/186] IGLSampler -> ISampler
---
examples/src/test/fractalCube.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/examples/src/test/fractalCube.ts b/examples/src/test/fractalCube.ts
index 32440d3..c9841d9 100644
--- a/examples/src/test/fractalCube.ts
+++ b/examples/src/test/fractalCube.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, ISubmit, ITexture } from "@feng3d/render-api";
-import { IGLCanvasContext, ISampler, WebGL } from "@feng3d/webgl";
+import { IRenderObject, ISampler, ISubmit, ITexture } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { mat4 } from "gl-matrix";
let cubeRotation = 0.0;
--
Gitee
From 82ee62bce809ac3345d7cb36e725d5ab52203afb Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 4 Jan 2025 14:15:18 +0800
Subject: [PATCH 167/186] =?UTF-8?q?=E4=B8=BA=E4=BA=86=E5=85=BC=E5=AE=B9Web?=
=?UTF-8?q?GPU=EF=BC=8CGLSL=E7=9D=80=E8=89=B2=E5=99=A8=E4=B8=AD=E6=95=B0?=
=?UTF-8?q?=E6=8D=AE=E7=BB=93=E6=9E=84=E4=B8=8D=E5=86=8D=E6=94=AF=E6=8C=81?=
=?UTF-8?q?=E7=BA=B9=E7=90=86=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 18 ++++++++++++++++++
examples/src/WebGL2Samples/sampler_object.html | 12 ++++--------
examples/src/WebGL2Samples/sampler_object.ts | 8 ++------
src/data/IGLUniforms.ts | 2 +-
4 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/README.md b/README.md
index f1ae9e0..4836671 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,19 @@
# @feng3d/renderer
+
+
+## 不再支持内容
+1. 为了兼容WebGPU,GLSL着色器中数据结构不再支持纹理。
+ 如下GLSL着色器中struct中包含sampler2D
+ ```
+ struct Material
+ {
+ sampler2D diffuse[2];
+ };
+
+ uniform Material material;
+ ```
+ 需要修改为
+ ```
+ uniform sampler2D materialDiffuse0;
+ uniform sampler2D materialDiffuse1;
+ ```
diff --git a/examples/src/WebGL2Samples/sampler_object.html b/examples/src/WebGL2Samples/sampler_object.html
index d2f1fe1..1315f59 100644
--- a/examples/src/WebGL2Samples/sampler_object.html
+++ b/examples/src/WebGL2Samples/sampler_object.html
@@ -47,12 +47,8 @@
precision highp float;
precision highp int;
- struct Material
- {
- sampler2D diffuse[2];
- };
-
- uniform Material material;
+ uniform sampler2D materialDiffuse0;
+ uniform sampler2D materialDiffuse1;
in vec2 v_st;
@@ -61,9 +57,9 @@
void main()
{
if (v_st.y / v_st.x < 1.0) {
- color = texture(material.diffuse[0], v_st);
+ color = texture(materialDiffuse0, v_st);
} else {
- color = texture(material.diffuse[1], v_st) * 0.77;
+ color = texture(materialDiffuse1, v_st) * 0.77;
}
}
diff --git a/examples/src/WebGL2Samples/sampler_object.ts b/examples/src/WebGL2Samples/sampler_object.ts
index 1825af9..05bf4ea 100644
--- a/examples/src/WebGL2Samples/sampler_object.ts
+++ b/examples/src/WebGL2Samples/sampler_object.ts
@@ -93,12 +93,8 @@ function render()
vertices: vertexArray.vertices,
uniforms: {
mvp: matrix,
- material: {
- diffuse: [
- { texture, sampler: samplerA },
- { texture, sampler: samplerB },
- ]
- },
+ materialDiffuse0: { texture, sampler: samplerA },
+ materialDiffuse1: { texture, sampler: samplerB },
},
drawVertex: { vertexCount: 6, instanceCount: 1 },
}],
diff --git a/src/data/IGLUniforms.ts b/src/data/IGLUniforms.ts
index 878a22b..e1dd948 100644
--- a/src/data/IGLUniforms.ts
+++ b/src/data/IGLUniforms.ts
@@ -4,7 +4,7 @@ import { IGLSamplerTexture } from "./IGLSamplerTexture";
/**
* Uniform 类型
*/
-export type IGLUniformType = IGLSamplerTexture | IGLSamplerTexture[] | number | number[] | Float32Array | (number[] | Float32Array)[] | Int32Array | IGLUniformBuffer | IGLUniforms;
+export type IGLUniformType = IGLSamplerTexture | number | number[] | Float32Array | (number[] | Float32Array)[] | Int32Array | IGLUniformBuffer | IGLUniforms;
/**
* Uniform 数据
--
Gitee
From 8d340776516553892367ea9cd49a8cbed8ce25c0 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 4 Jan 2025 14:18:50 +0800
Subject: [PATCH 168/186] =?UTF-8?q?=E4=B8=BA=E4=BA=86=E5=85=BC=E5=AE=B9Web?=
=?UTF-8?q?GPU=EF=BC=8CGLSL=E7=9D=80=E8=89=B2=E5=99=A8=E4=B8=AD=E6=95=B0?=
=?UTF-8?q?=E6=8D=AE=E7=BB=93=E6=9E=84=E4=B8=8D=E5=86=8D=E6=94=AF=E6=8C=81?=
=?UTF-8?q?=E7=BA=B9=E7=90=86=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
examples/src/WebGL2Samples/texture_srgb.html | 67 +++++++++-----------
examples/src/WebGL2Samples/texture_srgb.ts | 2 +-
src/data/IGLUniforms.ts | 2 +-
3 files changed, 33 insertions(+), 38 deletions(-)
diff --git a/examples/src/WebGL2Samples/texture_srgb.html b/examples/src/WebGL2Samples/texture_srgb.html
index b9e6f30..2dd23cc 100644
--- a/examples/src/WebGL2Samples/texture_srgb.html
+++ b/examples/src/WebGL2Samples/texture_srgb.html
@@ -82,12 +82,7 @@
precision highp float;
precision highp int;
- struct Material
- {
- sampler2D diffuse;
- };
-
- uniform Material material;
+ uniform sampler2D materialDiffuse;
in vec2 v_blurTexCoords[14];
in vec2 h_blurTexCoords[14];
@@ -127,36 +122,36 @@
// This is useful since then we could work with the filtering math in linear space,
// then convert back to sRGB space for the color output.
// In this example, we will use a Gaussian filter for blurring.
- vec4 colorRgb = vec4(texture(material.diffuse, v_st).rgb, 1.0);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[ 0]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[ 1]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[ 2]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[ 3]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[ 4]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[ 5]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[ 6]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[ 7]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[ 8]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[ 9]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[10]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[11]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[12]), sampleCoord.y);
- colorRgb = mix(colorRgb, texture(material.diffuse, v_blurTexCoords[13]), sampleCoord.y);
-
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[ 0]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[ 1]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[ 2]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[ 3]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[ 4]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[ 5]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[ 6]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[ 7]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[ 8]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[ 9]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[10]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[11]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[12]), sampleCoord.x);
- colorRgb = mix(colorRgb, texture(material.diffuse, h_blurTexCoords[13]), sampleCoord.x);
+ vec4 colorRgb = vec4(texture(materialDiffuse, v_st).rgb, 1.0);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[ 0]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[ 1]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[ 2]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[ 3]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[ 4]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[ 5]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[ 6]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[ 7]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[ 8]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[ 9]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[10]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[11]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[12]), sampleCoord.y);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, v_blurTexCoords[13]), sampleCoord.y);
+
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[ 0]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[ 1]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[ 2]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[ 3]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[ 4]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[ 5]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[ 6]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[ 7]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[ 8]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[ 9]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[10]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[11]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[12]), sampleCoord.x);
+ colorRgb = mix(colorRgb, texture(materialDiffuse, h_blurTexCoords[13]), sampleCoord.x);
float brightness = 1.0;
float saturation = 0.5;
diff --git a/examples/src/WebGL2Samples/texture_srgb.ts b/examples/src/WebGL2Samples/texture_srgb.ts
index 773b906..4aca404 100644
--- a/examples/src/WebGL2Samples/texture_srgb.ts
+++ b/examples/src/WebGL2Samples/texture_srgb.ts
@@ -86,7 +86,7 @@ import { getShaderSource, loadImage } from "./utility";
vertices,
uniforms: {
mvp: matrix,
- material: { diffuse: { texture, sampler } },
+ materialDiffuse: { texture, sampler },
},
drawVertex: { vertexCount: 6 },
});
diff --git a/src/data/IGLUniforms.ts b/src/data/IGLUniforms.ts
index e1dd948..e44c6dd 100644
--- a/src/data/IGLUniforms.ts
+++ b/src/data/IGLUniforms.ts
@@ -4,7 +4,7 @@ import { IGLSamplerTexture } from "./IGLSamplerTexture";
/**
* Uniform 类型
*/
-export type IGLUniformType = IGLSamplerTexture | number | number[] | Float32Array | (number[] | Float32Array)[] | Int32Array | IGLUniformBuffer | IGLUniforms;
+export type IGLUniformType = IGLSamplerTexture | number | number[] | Float32Array | (number[] | Float32Array)[] | Int32Array | IGLUniformBuffer;
/**
* Uniform 数据
--
Gitee
From c55b9431cf2b8c603bc437daab059a9c65558b7b Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 4 Jan 2025 15:44:14 +0800
Subject: [PATCH 169/186] 1
---
src/data/IGLUniforms.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/data/IGLUniforms.ts b/src/data/IGLUniforms.ts
index e44c6dd..9e2b88f 100644
--- a/src/data/IGLUniforms.ts
+++ b/src/data/IGLUniforms.ts
@@ -4,7 +4,7 @@ import { IGLSamplerTexture } from "./IGLSamplerTexture";
/**
* Uniform 类型
*/
-export type IGLUniformType = IGLSamplerTexture | number | number[] | Float32Array | (number[] | Float32Array)[] | Int32Array | IGLUniformBuffer;
+export type IGLUniformType = IGLSamplerTexture | number | number[] | Float32Array | Int32Array | IGLUniformBuffer;
/**
* Uniform 数据
--
Gitee
From 9ffb6217d763aae86507a57fdffb5d5519b59278 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 4 Jan 2025 16:10:44 +0800
Subject: [PATCH 170/186] IGLUniforms
---
src/data/IGLRenderObject.ts | 3 +--
src/data/IGLUniforms.ts | 7 +++++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/data/IGLRenderObject.ts b/src/data/IGLRenderObject.ts
index a64191a..c8998e6 100644
--- a/src/data/IGLRenderObject.ts
+++ b/src/data/IGLRenderObject.ts
@@ -1,5 +1,4 @@
import { IRenderObject } from "@feng3d/render-api";
-import { LazyObject } from "../types";
import { IGLUniforms } from "./IGLUniforms";
declare module "@feng3d/render-api"
@@ -12,6 +11,6 @@ declare module "@feng3d/render-api"
/**
* Uniform渲染数据
*/
- uniforms?: LazyObject;
+ uniforms?: IGLUniforms;
}
}
diff --git a/src/data/IGLUniforms.ts b/src/data/IGLUniforms.ts
index 9e2b88f..03da7bf 100644
--- a/src/data/IGLUniforms.ts
+++ b/src/data/IGLUniforms.ts
@@ -1,15 +1,18 @@
+import { Lazy } from "../types";
import { IGLUniformBuffer } from "./IGLBuffer";
import { IGLSamplerTexture } from "./IGLSamplerTexture";
/**
* Uniform 类型
*/
-export type IGLUniformType = IGLSamplerTexture | number | number[] | Float32Array | Int32Array | IGLUniformBuffer;
+export type IGLUniformType = IGLSamplerTexture | IGLUniformDataItem | IGLUniformBuffer;
/**
* Uniform 数据
*/
export interface IGLUniforms
{
- [key: string]: IGLUniformType;
+ [key: string]: Lazy;
}
+
+export type IGLUniformDataItem = number | number[] | Float32Array | Int32Array;
--
Gitee
From 53f0351f7760076316cc54753577d50561c748ee Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 4 Jan 2025 16:32:50 +0800
Subject: [PATCH 171/186] IGLUniformTypeMap
---
src/RunWebGL.ts | 5 ++--
src/data/IGLTransformFeedbackPass.ts | 3 +-
src/data/IGLUniforms.ts | 11 +++++--
src/types.ts | 43 ----------------------------
4 files changed, 12 insertions(+), 50 deletions(-)
delete mode 100644 src/types.ts
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index d1e100e..76e5e32 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,4 +1,4 @@
-import { getBlendConstantColor, IBlendComponent, IBuffer, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IBuffer, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport, lazy } from "@feng3d/render-api";
import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLFramebuffer } from "./caches/getGLFramebuffer";
@@ -29,7 +29,6 @@ import { getIGLIndexBuffer, getIGLVertexBuffer } from "./runs/getIGLBuffer";
import { getIGLBlendEquation, getIGLBlendFactor, IGLBlendEquation, IGLBlendFactor } from "./runs/runColorTargetStates";
import { getIGLCompareFunction } from "./runs/runDepthState";
import { getIGLStencilFunc, getIGLStencilOp } from "./runs/runStencilState";
-import { lazy, LazyObject } from "./types";
import { ChainMap } from "./utils/ChainMap";
import { getGLRenderPassAttachmentSize } from "./utils/getGLRenderPassAttachmentSize";
import { getIGLCullFace, IGLCullFace } from "./utils/getIGLCullFace";
@@ -319,7 +318,7 @@ export class RunWebGL
/**
* 激活常量
*/
- private runUniforms(gl: WebGLRenderingContext, pipeline: IRenderPipeline, uniforms: LazyObject)
+ private runUniforms(gl: WebGLRenderingContext, pipeline: IRenderPipeline, uniforms: IGLUniforms)
{
const webGLProgram = getGLProgram(gl, pipeline);
diff --git a/src/data/IGLTransformFeedbackPass.ts b/src/data/IGLTransformFeedbackPass.ts
index d2a96ef..cdd0b88 100644
--- a/src/data/IGLTransformFeedbackPass.ts
+++ b/src/data/IGLTransformFeedbackPass.ts
@@ -1,5 +1,4 @@
import { IDrawVertex, IVertexAttributes, IVertexState } from "@feng3d/render-api";
-import { LazyObject } from "../types";
import { IGLTransformFeedback } from "./IGLTransformFeedback";
import { IGLUniforms } from "./IGLUniforms";
@@ -46,7 +45,7 @@ export interface IGLTransformFeedbackObject
/**
* Uniform渲染数据
*/
- uniforms?: LazyObject;
+ uniforms?: IGLUniforms;
/**
* 回写顶点着色器中输出到缓冲区。
diff --git a/src/data/IGLUniforms.ts b/src/data/IGLUniforms.ts
index 03da7bf..45f36f2 100644
--- a/src/data/IGLUniforms.ts
+++ b/src/data/IGLUniforms.ts
@@ -1,11 +1,11 @@
-import { Lazy } from "../types";
+import { Lazy } from "@feng3d/render-api";
import { IGLUniformBuffer } from "./IGLBuffer";
import { IGLSamplerTexture } from "./IGLSamplerTexture";
/**
* Uniform 类型
*/
-export type IGLUniformType = IGLSamplerTexture | IGLUniformDataItem | IGLUniformBuffer;
+export type IGLUniformType = IGLUniformTypeMap[keyof IGLUniformTypeMap];
/**
* Uniform 数据
@@ -16,3 +16,10 @@ export interface IGLUniforms
}
export type IGLUniformDataItem = number | number[] | Float32Array | Int32Array;
+
+export interface IGLUniformTypeMap
+{
+ IGLSamplerTexture: IGLSamplerTexture;
+ IGLUniformDataItem: IGLUniformDataItem;
+ IGLUniformBuffer: IGLUniformBuffer;
+}
\ No newline at end of file
diff --git a/src/types.ts b/src/types.ts
deleted file mode 100644
index e0bde5c..0000000
--- a/src/types.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 构造函数
- *
- * @example
- * ```
- * const Vector2Constructor: Constructor = Vector2;
- * ```
- */
-export type Constructor = (new (...args: any[]) => T);
-
-/**
- * 映射每个属性的类定义
- *
- * @example
- * ```
- * const classmap: ConstructorOf<{ Vector2: Vector2 }> = { Vector2: Vector2 };
- * ```
- */
-export type ConstructorOf = { [P in keyof T]: Constructor; };
-
-/**
- * 让T中以及所有键值中的所有键都是可选的
- */
-export type gPartial = {
- [P in keyof T]?: T[P] | gPartial;
-};
-
-export type Lazy = T | ((...args: any[]) => T);
-
-export type LazyObject = { [P in keyof T]: Lazy; };
-
-export const lazy = {
- getValue(lazyItem: Lazy, ...args: any[]): T
- {
- if (typeof lazyItem === "function")
- {
- // eslint-disable-next-line prefer-spread
- return (lazyItem as Function).apply(undefined, args);
- }
-
- return lazyItem;
- }
-};
--
Gitee
From fc0046c3959430e4dd2d9f37ec03719539dd7a81 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Sat, 4 Jan 2025 16:39:23 +0800
Subject: [PATCH 172/186] IRenderObject.uniforms
---
src/RunWebGL.ts | 5 ++---
src/data/IGLRenderObject.ts | 16 ----------------
src/data/IGLRenderPass.ts | 1 -
src/data/IGLTransformFeedbackPass.ts | 5 ++---
src/data/IGLUniforms.ts | 26 ++++++++------------------
src/index.ts | 1 -
6 files changed, 12 insertions(+), 42 deletions(-)
delete mode 100644 src/data/IGLRenderObject.ts
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 76e5e32..cdd9333 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,4 +1,4 @@
-import { getBlendConstantColor, IBlendComponent, IBuffer, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IVertexAttribute, IVertexAttributes, IViewport, lazy } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IBuffer, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IUniforms, IVertexAttribute, IVertexAttributes, IViewport, lazy } from "@feng3d/render-api";
import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLFramebuffer } from "./caches/getGLFramebuffer";
@@ -23,7 +23,6 @@ import { IGLTextureTarget } from "./data/IGLTexture";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
import { IGLTransformFeedbackObject, IGLTransformFeedbackPass, IGLTransformFeedbackPipeline } from "./data/IGLTransformFeedbackPass";
import { IUniformItemInfo } from "./data/IGLUniformInfo";
-import { IGLUniforms } from "./data/IGLUniforms";
import { getGLTexture } from "./internal";
import { getIGLIndexBuffer, getIGLVertexBuffer } from "./runs/getIGLBuffer";
import { getIGLBlendEquation, getIGLBlendFactor, IGLBlendEquation, IGLBlendFactor } from "./runs/runColorTargetStates";
@@ -318,7 +317,7 @@ export class RunWebGL
/**
* 激活常量
*/
- private runUniforms(gl: WebGLRenderingContext, pipeline: IRenderPipeline, uniforms: IGLUniforms)
+ private runUniforms(gl: WebGLRenderingContext, pipeline: IRenderPipeline, uniforms: IUniforms)
{
const webGLProgram = getGLProgram(gl, pipeline);
diff --git a/src/data/IGLRenderObject.ts b/src/data/IGLRenderObject.ts
deleted file mode 100644
index c8998e6..0000000
--- a/src/data/IGLRenderObject.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { IRenderObject } from "@feng3d/render-api";
-import { IGLUniforms } from "./IGLUniforms";
-
-declare module "@feng3d/render-api"
-{
- /**
- * 渲染对象,包含一次渲染时包含的所有数据。
- */
- export interface IRenderObject
- {
- /**
- * Uniform渲染数据
- */
- uniforms?: IGLUniforms;
- }
-}
diff --git a/src/data/IGLRenderPass.ts b/src/data/IGLRenderPass.ts
index 746fa73..f115ef8 100644
--- a/src/data/IGLRenderPass.ts
+++ b/src/data/IGLRenderPass.ts
@@ -20,7 +20,6 @@ declare module "@feng3d/render-api"
export interface IRenderPassObjectMap
{
- IGLRenderObject: IRenderObject,
IGLOcclusionQuery: IGLOcclusionQuery
}
}
diff --git a/src/data/IGLTransformFeedbackPass.ts b/src/data/IGLTransformFeedbackPass.ts
index cdd0b88..413eb17 100644
--- a/src/data/IGLTransformFeedbackPass.ts
+++ b/src/data/IGLTransformFeedbackPass.ts
@@ -1,6 +1,5 @@
-import { IDrawVertex, IVertexAttributes, IVertexState } from "@feng3d/render-api";
+import { IDrawVertex, IUniforms, IVertexAttributes, IVertexState } from "@feng3d/render-api";
import { IGLTransformFeedback } from "./IGLTransformFeedback";
-import { IGLUniforms } from "./IGLUniforms";
declare module "@feng3d/render-api"
{
@@ -45,7 +44,7 @@ export interface IGLTransformFeedbackObject
/**
* Uniform渲染数据
*/
- uniforms?: IGLUniforms;
+ uniforms?: IUniforms;
/**
* 回写顶点着色器中输出到缓冲区。
diff --git a/src/data/IGLUniforms.ts b/src/data/IGLUniforms.ts
index 45f36f2..a7a8188 100644
--- a/src/data/IGLUniforms.ts
+++ b/src/data/IGLUniforms.ts
@@ -2,24 +2,14 @@ import { Lazy } from "@feng3d/render-api";
import { IGLUniformBuffer } from "./IGLBuffer";
import { IGLSamplerTexture } from "./IGLSamplerTexture";
-/**
- * Uniform 类型
- */
-export type IGLUniformType = IGLUniformTypeMap[keyof IGLUniformTypeMap];
-
-/**
- * Uniform 数据
- */
-export interface IGLUniforms
+declare module "@feng3d/render-api"
{
- [key: string]: Lazy;
+ export interface IUniformTypeMap
+ {
+ IGLSamplerTexture: IGLSamplerTexture;
+ IGLUniformDataItem: IGLUniformDataItem;
+ IGLUniformBuffer: IGLUniformBuffer;
+ }
}
-export type IGLUniformDataItem = number | number[] | Float32Array | Int32Array;
-
-export interface IGLUniformTypeMap
-{
- IGLSamplerTexture: IGLSamplerTexture;
- IGLUniformDataItem: IGLUniformDataItem;
- IGLUniformBuffer: IGLUniformBuffer;
-}
\ No newline at end of file
+export type IGLUniformDataItem = number | number[] | Float32Array | Int32Array;
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index 040492f..2c8c50f 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -9,7 +9,6 @@ export * from "./data/IGLOcclusionQuery";
export * from "./data/IGLPrimitiveState";
export * from "./data/IGLReadPixels";
export * from "./data/IGLRenderbuffer";
-export * from "./data/IGLRenderObject";
export * from "./data/IGLRenderPass";
export * from "./data/IGLSampler";
export * from "./data/IGLSamplerTexture";
--
Gitee
From 7d2508e6d2e836b7f3fc0c72241da779bcf26b28 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Mon, 6 Jan 2025 16:24:03 +0800
Subject: [PATCH 173/186] getIGLUniformBuffer
---
examples/src/WebGL2Samples/buffer_uniform.ts | 16 ++++++----------
examples/src/WebGL2Samples/draw_instanced_ubo.ts | 12 +++++-------
src/RunWebGL.ts | 9 +++++----
src/data/IGLUniforms.ts | 4 +---
src/runs/getIGLBuffer.ts | 14 ++++++++++----
5 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/examples/src/WebGL2Samples/buffer_uniform.ts b/examples/src/WebGL2Samples/buffer_uniform.ts
index 5fd98d0..eec9965 100644
--- a/examples/src/WebGL2Samples/buffer_uniform.ts
+++ b/examples/src/WebGL2Samples/buffer_uniform.ts
@@ -1,5 +1,5 @@
import { IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLUniformBuffer, WebGL } from "@feng3d/webgl";
+import { getIGLBuffer, IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -52,12 +52,9 @@ import { getShaderSource } from "./utility";
0.0, 0.0, 0.0, 1.0
]);
- const uniformPerDrawBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", size: transforms.byteLength, data: transforms, usage: "DYNAMIC_DRAW" };
-
const lightPos = new Float32Array([
0.0, 0.0, 0.0, 0.0,
]);
- const uniformPerPassBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", size: lightPos.byteLength, data: lightPos, usage: "DYNAMIC_DRAW" };
//vec3 ambient, diffuse, specular, float shininess
const material = new Float32Array([
@@ -65,7 +62,6 @@ import { getShaderSource } from "./utility";
0.5, 0.0, 0.0, 0.0,
1.0, 1.0, 1.0, 4.0,
]);
- const uniformPerSceneBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", size: material.byteLength, data: material, usage: "STATIC_DRAW" };
// -- Init Vertex Array
const vertexArray: { vertices?: IVertexAttributes } = {
@@ -81,9 +77,9 @@ import { getShaderSource } from "./utility";
vertices: vertexArray.vertices,
indices: elementData,
uniforms: {
- PerDraw: uniformPerDrawBuffer,
- PerPass: uniformPerPassBuffer,
- PerScene: uniformPerSceneBuffer,
+ PerDraw: transforms,
+ PerPass: lightPos,
+ PerScene: material,
},
drawIndexed: { indexCount: 6, firstIndex: 0 }
};
@@ -100,11 +96,11 @@ import { getShaderSource } from "./utility";
// -- update uniform buffer
transforms[16] = 0.1 * Math.cos(uTime) + 0.4;
- uniformPerDrawBuffer.writeBuffers = [{ bufferOffset: 0, data: transforms }];
+ getIGLBuffer(transforms).writeBuffers = [{ bufferOffset: 0, data: transforms }];
lightPos[0] = Math.cos(3 * uTime);
lightPos[1] = Math.sin(6 * uTime);
- uniformPerPassBuffer.writeBuffers = [{ bufferOffset: 0, data: lightPos }];
+ getIGLBuffer(lightPos).writeBuffers = [{ bufferOffset: 0, data: lightPos }];
webgl.submit({ commandEncoders: [{ passEncoders: [rp] }] });
diff --git a/examples/src/WebGL2Samples/draw_instanced_ubo.ts b/examples/src/WebGL2Samples/draw_instanced_ubo.ts
index 9ac0f40..018d2a4 100644
--- a/examples/src/WebGL2Samples/draw_instanced_ubo.ts
+++ b/examples/src/WebGL2Samples/draw_instanced_ubo.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPipeline } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLUniformBuffer, WebGL } from "@feng3d/webgl";
+import { getIGLBuffer, IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -32,13 +32,11 @@ const transforms = new Float32Array([
0.0, 0.0, 1.0, 0.0,
0.5, 0.0, 0.0, 1.0
]);
-const uniformTransformBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", size: transforms.byteLength, data: transforms, usage: "DYNAMIC_DRAW" };
const materials = new Float32Array([
1.0, 0.5, 0.0, 1.0,
0.0, 0.5, 1.0, 1.0
]);
-const uniformMaterialBuffer: IGLUniformBuffer = { target: "UNIFORM_BUFFER", size: materials.byteLength, data: materials, usage: "STATIC_DRAW" };
// -- Render
const rp: IRenderPass = {
@@ -49,8 +47,8 @@ const rp: IRenderPass = {
pos: { data: vertices, format: "float32x2" },
},
uniforms: {
- Transform: uniformTransformBuffer,
- Material: uniformMaterialBuffer,
+ Transform: transforms,
+ Material: materials,
},
drawVertex: { vertexCount: 3, instanceCount: 2 },
}]
@@ -59,6 +57,6 @@ const rp: IRenderPass = {
webgl.submit({ commandEncoders: [{ passEncoders: [rp] }] });
// -- Delete WebGL resources
-webgl.deleteBuffer(uniformTransformBuffer);
-webgl.deleteBuffer(uniformMaterialBuffer);
+webgl.deleteBuffer(getIGLBuffer(transforms));
+webgl.deleteBuffer(getIGLBuffer(materials));
webgl.deleteProgram(program);
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index cdd9333..b430908 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,4 +1,4 @@
-import { getBlendConstantColor, IBlendComponent, IBuffer, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IUniforms, IVertexAttribute, IVertexAttributes, IViewport, lazy } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IUniforms, IVertexAttribute, IVertexAttributes, IViewport, lazy, TypedArray } from "@feng3d/render-api";
import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLFramebuffer } from "./caches/getGLFramebuffer";
@@ -24,7 +24,7 @@ import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
import { IGLTransformFeedbackObject, IGLTransformFeedbackPass, IGLTransformFeedbackPipeline } from "./data/IGLTransformFeedbackPass";
import { IUniformItemInfo } from "./data/IGLUniformInfo";
import { getGLTexture } from "./internal";
-import { getIGLIndexBuffer, getIGLVertexBuffer } from "./runs/getIGLBuffer";
+import { getIGLIndexBuffer, getIGLUniformBuffer, getIGLVertexBuffer } from "./runs/getIGLBuffer";
import { getIGLBlendEquation, getIGLBlendFactor, IGLBlendEquation, IGLBlendFactor } from "./runs/runColorTargetStates";
import { getIGLCompareFunction } from "./runs/runDepthState";
import { getIGLStencilFunc, getIGLStencilOp } from "./runs/runStencilState";
@@ -313,7 +313,6 @@ export class RunWebGL
}
}
-
/**
* 激活常量
*/
@@ -358,8 +357,10 @@ export class RunWebGL
const { name, index } = uniformBlock;
const uniformData = lazy.getValue(uniforms[name], uniforms);
+ const buffer = getIGLUniformBuffer(uniformData as TypedArray);
+
//
- const webGLBuffer = getGLBuffer(gl, uniformData as IBuffer);
+ const webGLBuffer = getGLBuffer(gl, buffer);
gl.bindBufferBase(gl.UNIFORM_BUFFER, index, webGLBuffer);
});
}
diff --git a/src/data/IGLUniforms.ts b/src/data/IGLUniforms.ts
index a7a8188..e4d0d93 100644
--- a/src/data/IGLUniforms.ts
+++ b/src/data/IGLUniforms.ts
@@ -1,5 +1,4 @@
import { Lazy } from "@feng3d/render-api";
-import { IGLUniformBuffer } from "./IGLBuffer";
import { IGLSamplerTexture } from "./IGLSamplerTexture";
declare module "@feng3d/render-api"
@@ -8,8 +7,7 @@ declare module "@feng3d/render-api"
{
IGLSamplerTexture: IGLSamplerTexture;
IGLUniformDataItem: IGLUniformDataItem;
- IGLUniformBuffer: IGLUniformBuffer;
}
}
-export type IGLUniformDataItem = number | number[] | Float32Array | Int32Array;
\ No newline at end of file
+export type IGLUniformDataItem = number | number[] | Float32Array | Int32Array;
diff --git a/src/runs/getIGLBuffer.ts b/src/runs/getIGLBuffer.ts
index b830f5e..646fc32 100644
--- a/src/runs/getIGLBuffer.ts
+++ b/src/runs/getIGLBuffer.ts
@@ -1,12 +1,10 @@
import { IBuffer, IIndicesDataTypes, IVertexDataTypes, TypedArray } from "@feng3d/render-api";
-import { IGLBufferTarget, IGLBufferUsage, IGLIndexBuffer, IGLVertexBuffer } from "../data/IGLBuffer";
+import { IGLBufferTarget, IGLBufferUsage, IGLIndexBuffer, IGLUniformBuffer, IGLVertexBuffer } from "../data/IGLBuffer";
-export function getIGLBuffer(data: TypedArray, target?: IGLBufferTarget, usage: IGLBufferUsage = "STATIC_DRAW")
+export function getIGLBuffer(data: TypedArray, target?: IGLBufferTarget, usage: IGLBufferUsage = "STATIC_DRAW"): IBuffer
{
if (data[_IGLBuffer]) return data[_IGLBuffer];
- console.assert(!!target, `初始化时不能为空,可能该数据的渲染对象还未被渲染!`);
-
const buffer: IBuffer = {
size: Math.ceil(data.byteLength / 4) * 4,
target: target,
@@ -18,6 +16,14 @@ export function getIGLBuffer(data: TypedArray, target?: IGLBufferTarget, usage:
return buffer;
}
+export function getIGLUniformBuffer(data: TypedArray, usage?: "DYNAMIC_DRAW")
+{
+ const vertexBuffer: IGLUniformBuffer = data[_IGLBuffer] = data[_IGLBuffer] || getIGLBuffer(data, "UNIFORM_BUFFER", usage);
+ vertexBuffer.target = vertexBuffer.target || "UNIFORM_BUFFER";
+
+ return vertexBuffer;
+}
+
export function getIGLVertexBuffer(data: IVertexDataTypes, usage?: "STREAM_COPY")
{
const vertexBuffer: IGLVertexBuffer = data[_IGLBuffer] = data[_IGLBuffer] || getIGLBuffer(data, "ARRAY_BUFFER", usage);
--
Gitee
From ac33a5e705960e77cd3faba47b1b4afc919f76ab Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Mon, 6 Jan 2025 16:50:18 +0800
Subject: [PATCH 174/186] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20Lazy?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
examples/src/regl-examples/batch.ts | 51 ++++++++++++---------
examples/src/regl-examples/bunny.ts | 53 +++++++++++-----------
examples/src/regl-examples/cloth.ts | 42 +++++++++---------
examples/src/regl-examples/cube.ts | 54 +++++++++++------------
examples/src/regl-examples/util/camera.ts | 13 +++---
src/RunWebGL.ts | 6 +--
src/data/IGLUniforms.ts | 2 +-
7 files changed, 115 insertions(+), 106 deletions(-)
diff --git a/examples/src/regl-examples/batch.ts b/examples/src/regl-examples/batch.ts
index 44c4bb5..aa974ad 100644
--- a/examples/src/regl-examples/batch.ts
+++ b/examples/src/regl-examples/batch.ts
@@ -1,4 +1,4 @@
-import { IRenderObject, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { IRenderObject, IRenderPipeline, ISubmit, IVertexAttributes } from "@feng3d/render-api";
import { WebGL } from "@feng3d/webgl";
const canvas = document.createElement("canvas");
@@ -54,18 +54,12 @@ const vertexArray: { vertices?: IVertexAttributes } = {
}
};
-function getRenderObject(tick: number, batchId: number)
+function getRenderObject(batchId: number)
{
const renderObject: IRenderObject = {
vertices: vertexArray.vertices,
uniforms: {
- color: () => [
- Math.sin(0.02 * ((0.1 + Math.sin(batchId)) * tick + 3.0 * batchId)),
- Math.cos(0.02 * (0.02 * tick + 0.1 * batchId)),
- Math.sin(0.02 * ((0.3 + Math.cos(2.0 * batchId)) * tick + 0.8 * batchId)),
- 1],
- angle: () => 0.01 * tick,
- offset: () => offsets[batchId].offset,
+ offset: offsets[batchId].offset,
},
pipeline,
drawVertex: { vertexCount: 3 }
@@ -74,29 +68,44 @@ function getRenderObject(tick: number, batchId: number)
return renderObject;
}
+const renderObjects: IRenderObject[] = [];
+for (let i = 0; i < offsets.length; i++)
+{
+ renderObjects.push(getRenderObject(i));
+}
+
+const submit: ISubmit = {
+ commandEncoders: [{
+ passEncoders: [
+ {
+ descriptor: { colorAttachments: [{ clearValue: [0, 0, 0, 1] }] },
+ renderObjects
+ }
+ ]
+ }]
+};
+
function draw()
{
canvas.width = canvas.clientWidth;
canvas.height = canvas.clientHeight;
tick++;
- const renderObjects: IRenderObject[] = [];
+
for (let i = 0; i < offsets.length; i++)
{
batchId = i;
- renderObjects.push(getRenderObject(tick, batchId));
+ //
+ const ro = renderObjects[i];
+ ro.uniforms.color = [
+ Math.sin(0.02 * ((0.1 + Math.sin(batchId)) * tick + 3.0 * batchId)),
+ Math.cos(0.02 * (0.02 * tick + 0.1 * batchId)),
+ Math.sin(0.02 * ((0.3 + Math.cos(2.0 * batchId)) * tick + 0.8 * batchId)),
+ 1];
+ ro.uniforms.angle = 0.01 * tick;
}
- webgl.submit({
- commandEncoders: [{
- passEncoders: [
- {
- descriptor: { colorAttachments: [{ clearValue: [0, 0, 0, 1] }] },
- renderObjects
- }
- ]
- }]
- });
+ webgl.submit(submit);
requestAnimationFrame(draw);
}
diff --git a/examples/src/regl-examples/bunny.ts b/examples/src/regl-examples/bunny.ts
index 7399886..2fb76c8 100644
--- a/examples/src/regl-examples/bunny.ts
+++ b/examples/src/regl-examples/bunny.ts
@@ -1,4 +1,4 @@
-import { IRenderObject } from "@feng3d/render-api";
+import { IRenderObject, ISubmit } from "@feng3d/render-api";
import { WebGL } from "@feng3d/webgl";
import * as bunny from "./mikolalysenko/bunny";
@@ -38,21 +38,6 @@ const renderObject: IRenderObject = {
drawIndexed: { indexCount: indices.length },
uniforms: {
model: mat4.identity([]),
- view: () =>
- {
- const t = 0.01 * tick;
-
- return mat4.lookAt([],
- [30 * Math.cos(t), 2.5, 30 * Math.sin(t)],
- [0, 2.5, 0],
- [0, 1, 0]);
- },
- projection: () =>
- mat4.perspective([],
- Math.PI / 4,
- viewportWidth / viewportHeight,
- 0.01,
- 1000),
},
pipeline: {
vertex: {
@@ -73,22 +58,38 @@ const renderObject: IRenderObject = {
}
};
+const submit: ISubmit = {
+ commandEncoders: [{
+ passEncoders: [
+ {
+ descriptor: { colorAttachments: [{ clearValue: [0, 0, 0, 1] }], depthStencilAttachment: { depthClearValue: 1 } },
+ renderObjects: [renderObject]
+ }
+ ]
+ }]
+};
+
function draw()
{
viewportWidth = canvas.width = canvas.clientWidth;
viewportHeight = canvas.height = canvas.clientHeight;
tick++;
- webgl.submit({
- commandEncoders: [{
- passEncoders: [
- {
- descriptor: { colorAttachments: [{ clearValue: [0, 0, 0, 1] }], depthStencilAttachment: { depthClearValue: 1 } },
- renderObjects: [renderObject]
- }
- ]
- }]
- });
+ const t = 0.01 * tick;
+
+ renderObject.uniforms.view = mat4.lookAt([],
+ [30 * Math.cos(t), 2.5, 30 * Math.sin(t)],
+ [0, 2.5, 0],
+ [0, 1, 0]);
+
+ renderObject.uniforms.projection =
+ mat4.perspective([],
+ Math.PI / 4,
+ viewportWidth / viewportHeight,
+ 0.01,
+ 1000);
+
+ webgl.submit(submit);
requestAnimationFrame(draw);
}
diff --git a/examples/src/regl-examples/cloth.ts b/examples/src/regl-examples/cloth.ts
index 2088b81..e4cf4d7 100644
--- a/examples/src/regl-examples/cloth.ts
+++ b/examples/src/regl-examples/cloth.ts
@@ -1,4 +1,4 @@
-import { IRenderObject } from "@feng3d/render-api";
+import { IRenderObject, ISubmit } from "@feng3d/render-api";
import { getIGLVertexBuffer, IGLSamplerTexture, WebGL } from "@feng3d/webgl";
import { fit } from "./hughsk/canvas-fit";
@@ -172,16 +172,7 @@ import * as vec3 from "./stackgl/gl-vec3";
},
indices: new Uint16Array(indices),
drawIndexed: { indexCount: indices.length },
- uniforms: {
- view: () => camera.view(),
- projection: () =>
- mat4.perspective([],
- Math.PI / 4,
- viewportWidth / viewportHeight,
- 0.01,
- 1000),
- texture: () => diffuse,
- },
+ uniforms: {},
pipeline: {
vertex: {
code: `precision mediump float;
@@ -230,6 +221,16 @@ import * as vec3 from "./stackgl/gl-vec3";
}
};
+ const submit: ISubmit = {
+ commandEncoders: [{
+ passEncoders: [
+ {
+ renderObjects: [renderObject]
+ }
+ ]
+ }]
+ };
+
function draw()
{
const deltaTime = 0.017;
@@ -368,15 +369,15 @@ import * as vec3 from "./stackgl/gl-vec3";
camera.tick();
- webgl.submit({
- commandEncoders: [{
- passEncoders: [
- {
- renderObjects: [renderObject]
- }
- ]
- }]
- });
+ renderObject.uniforms.view = camera.view();
+ renderObject.uniforms.projection =
+ mat4.perspective([],
+ Math.PI / 4,
+ viewportWidth / viewportHeight,
+ 0.01,
+ 1000);
+
+ webgl.submit(submit);
requestAnimationFrame(draw);
}
@@ -392,6 +393,7 @@ import * as vec3 from "./stackgl/gl-vec3";
sources: [{ image: img }]
}, sampler: { minFilter: "linear", mipmapFilter: "linear", addressModeU: "repeat", addressModeV: "repeat" }
};
+ renderObject.uniforms.texture = diffuse;
draw();
})();
\ No newline at end of file
diff --git a/examples/src/regl-examples/cube.ts b/examples/src/regl-examples/cube.ts
index ce19f4e..7c53d43 100644
--- a/examples/src/regl-examples/cube.ts
+++ b/examples/src/regl-examples/cube.ts
@@ -1,4 +1,4 @@
-import { IRenderObject } from "@feng3d/render-api";
+import { IRenderObject, ISubmit } from "@feng3d/render-api";
import { IGLSamplerTexture, WebGL } from "@feng3d/webgl";
import * as mat4 from "./stackgl/gl-mat4";
@@ -71,24 +71,7 @@ import * as mat4 from "./stackgl/gl-mat4";
},
indices: new Uint16Array(indices),
drawIndexed: { indexCount: indices.length },
- uniforms: {
- view: () =>
- {
- const t = 0.01 * tick;
-
- return mat4.lookAt([],
- [5 * Math.cos(t), 2.5 * Math.sin(t), 5 * Math.sin(t)],
- [0, 0.0, 0],
- [0, 1, 0]);
- },
- projection: () =>
- mat4.perspective([],
- Math.PI / 4,
- viewportWidth / viewportHeight,
- 0.01,
- 10),
- tex: () => diffuse,
- },
+ uniforms: {},
pipeline: {
vertex: {
code: `precision mediump float;
@@ -113,6 +96,16 @@ import * as mat4 from "./stackgl/gl-mat4";
}
};
+ const submit: ISubmit = {
+ commandEncoders: [{
+ passEncoders: [
+ {
+ renderObjects: [renderObject]
+ }
+ ]
+ }]
+ };
+
function draw()
{
tick++;
@@ -120,15 +113,19 @@ import * as mat4 from "./stackgl/gl-mat4";
viewportWidth = canvas.width = canvas.clientWidth;
viewportHeight = canvas.height = canvas.clientHeight;
- webgl.submit({
- commandEncoders: [{
- passEncoders: [
- {
- renderObjects: [renderObject]
- }
- ]
- }]
- });
+ const t = 0.01 * tick;
+ renderObject.uniforms.view = mat4.lookAt([],
+ [5 * Math.cos(t), 2.5 * Math.sin(t), 5 * Math.sin(t)],
+ [0, 0.0, 0],
+ [0, 1, 0]);
+ renderObject.uniforms.projection =
+ mat4.perspective([],
+ Math.PI / 4,
+ viewportWidth / viewportHeight,
+ 0.01,
+ 10);
+
+ webgl.submit(submit);
requestAnimationFrame(draw);
}
@@ -143,6 +140,7 @@ import * as mat4 from "./stackgl/gl-mat4";
sources: [{ image: img }]
}, sampler: { minFilter: "linear" }
};
+ renderObject.uniforms.tex = diffuse;
draw();
})();
\ No newline at end of file
diff --git a/examples/src/regl-examples/util/camera.ts b/examples/src/regl-examples/util/camera.ts
index aaa0e23..c477f79 100644
--- a/examples/src/regl-examples/util/camera.ts
+++ b/examples/src/regl-examples/util/camera.ts
@@ -105,15 +105,14 @@ export function createCamera(props)
{
Object.keys(cameraState).forEach(function (name)
{
- renderObject.uniforms[name] = () => setupCamera[name];
+ renderObject.uniforms[name] = setupCamera[name];
});
- renderObject.uniforms["projection"] = () =>
- perspective(cameraState.projection,
- Math.PI / 4.0,
- viewportWidth / viewportHeight,
- 0.01,
- 1000.0);
+ renderObject.uniforms["projection"] = perspective(cameraState.projection,
+ Math.PI / 4.0,
+ viewportWidth / viewportHeight,
+ 0.01,
+ 1000.0);
};
function setupCamera(renderObject: IRenderObject, viewportWidth: number, viewportHeight: number)
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index b430908..8205ee3 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,4 +1,4 @@
-import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IUniforms, IVertexAttribute, IVertexAttributes, IViewport, lazy, TypedArray } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IUniforms, IVertexAttribute, IVertexAttributes, IViewport, TypedArray } from "@feng3d/render-api";
import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLFramebuffer } from "./caches/getGLFramebuffer";
@@ -329,7 +329,7 @@ export class RunWebGL
{
const { paths } = v;
- let uniformData = lazy.getValue(uniforms[paths[0]], uniforms);
+ let uniformData = uniforms[paths[0]];
for (let i = 1; i < paths.length; i++)
{
uniformData = uniformData[paths[i]];
@@ -355,7 +355,7 @@ export class RunWebGL
webGLProgram.uniformBlocks.forEach((uniformBlock) =>
{
const { name, index } = uniformBlock;
- const uniformData = lazy.getValue(uniforms[name], uniforms);
+ const uniformData = uniforms[name];
const buffer = getIGLUniformBuffer(uniformData as TypedArray);
diff --git a/src/data/IGLUniforms.ts b/src/data/IGLUniforms.ts
index e4d0d93..1797209 100644
--- a/src/data/IGLUniforms.ts
+++ b/src/data/IGLUniforms.ts
@@ -1,4 +1,4 @@
-import { Lazy } from "@feng3d/render-api";
+import { } from "@feng3d/render-api";
import { IGLSamplerTexture } from "./IGLSamplerTexture";
declare module "@feng3d/render-api"
--
Gitee
From 48f3530af8a9e0db236a570bb69fa82fe1ca5be4 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Tue, 7 Jan 2025 11:53:22 +0800
Subject: [PATCH 175/186] updateBufferBinding
---
src/RunWebGL.ts | 6 ++++--
src/utils/updateBufferBinding.ts | 34 ++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 2 deletions(-)
create mode 100644 src/utils/updateBufferBinding.ts
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 8205ee3..4d4dd0b 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -33,6 +33,7 @@ import { getGLRenderPassAttachmentSize } from "./utils/getGLRenderPassAttachment
import { getIGLCullFace, IGLCullFace } from "./utils/getIGLCullFace";
import { getIGLFrontFace, IGLFrontFace } from "./utils/getIGLFrontFace";
import { getIGLVertexFormat } from "./utils/getIVertexFormat";
+import { updateBufferBinding } from "./utils/updateBufferBinding";
declare global
{
@@ -355,9 +356,10 @@ export class RunWebGL
webGLProgram.uniformBlocks.forEach((uniformBlock) =>
{
const { name, index } = uniformBlock;
- const uniformData = uniforms[name];
+ const uniformData = uniforms[name] as TypedArray;
- const buffer = getIGLUniformBuffer(uniformData as TypedArray);
+ const buffer = getIGLUniformBuffer(uniformData);
+ updateBufferBinding(uniformBlock, { bufferView: uniformData });
//
const webGLBuffer = getGLBuffer(gl, buffer);
diff --git a/src/utils/updateBufferBinding.ts b/src/utils/updateBufferBinding.ts
new file mode 100644
index 0000000..af2ee24
--- /dev/null
+++ b/src/utils/updateBufferBinding.ts
@@ -0,0 +1,34 @@
+import { UnReadonly } from "@feng3d/render-api";
+import { IUniformBlockInfo } from "../caches/getGLProgram";
+import { getGLBuffer } from "../caches/getGLBuffer";
+import { getIGLBuffer } from "../runs/getIGLBuffer";
+
+export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData: IBufferBinding)
+{
+ const size = uniformBlock.dataSize;
+ // 是否存在默认值。
+ const hasDefautValue = !!uniformData.bufferView;
+ if (!hasDefautValue)
+ {
+ (uniformData as UnReadonly).bufferView = new Uint8Array(size);
+ }
+
+ // const buffer = getIGLBuffer(uniformData.bufferView);
+ // (buffer as any).label = buffer.label || (`BufferBinding ${variableInfo.name}`);
+ // const offset = uniformData.bufferView.byteOffset;
+
+
+}
+
+/**
+ * 缓冲区绑定。
+ */
+export interface IBufferBinding
+{
+ [name: string]: ArrayBufferView | ArrayLike | number;
+
+ /**
+ * 如果未设置引擎将自动生成。
+ */
+ readonly bufferView?: ArrayBufferView;
+}
--
Gitee
From 646fb66506484d360e453dab0adb8514e61b12ca Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Tue, 7 Jan 2025 12:40:52 +0800
Subject: [PATCH 176/186] 1
---
src/utils/updateBufferBinding.ts | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/utils/updateBufferBinding.ts b/src/utils/updateBufferBinding.ts
index af2ee24..3daed89 100644
--- a/src/utils/updateBufferBinding.ts
+++ b/src/utils/updateBufferBinding.ts
@@ -1,7 +1,5 @@
-import { UnReadonly } from "@feng3d/render-api";
+import { TypedArray, UnReadonly } from "@feng3d/render-api";
import { IUniformBlockInfo } from "../caches/getGLProgram";
-import { getGLBuffer } from "../caches/getGLBuffer";
-import { getIGLBuffer } from "../runs/getIGLBuffer";
export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData: IBufferBinding)
{
@@ -16,7 +14,7 @@ export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData
// const buffer = getIGLBuffer(uniformData.bufferView);
// (buffer as any).label = buffer.label || (`BufferBinding ${variableInfo.name}`);
// const offset = uniformData.bufferView.byteOffset;
-
+
}
@@ -25,10 +23,10 @@ export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData
*/
export interface IBufferBinding
{
- [name: string]: ArrayBufferView | ArrayLike | number;
+ [name: string]: TypedArray | ArrayLike | number;
/**
* 如果未设置引擎将自动生成。
*/
- readonly bufferView?: ArrayBufferView;
+ readonly bufferView?: TypedArray;
}
--
Gitee
From 76ba04200dadeba13aba10675a6c9d4959534414 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Tue, 7 Jan 2025 17:43:00 +0800
Subject: [PATCH 177/186] IGLCopyBufferToBuffer -> ICopyBufferToBuffer
---
examples/src/WebGL2Samples/buffer_copy.ts | 6 ++--
src/RunWebGL.ts | 5 ++--
src/data/IGLCommandEncoder.ts | 4 +--
src/data/IGLCopyBufferToBuffer.ts | 34 -----------------------
src/index.ts | 1 -
5 files changed, 6 insertions(+), 44 deletions(-)
delete mode 100644 src/data/IGLCopyBufferToBuffer.ts
diff --git a/examples/src/WebGL2Samples/buffer_copy.ts b/examples/src/WebGL2Samples/buffer_copy.ts
index 734739a..541e386 100644
--- a/examples/src/WebGL2Samples/buffer_copy.ts
+++ b/examples/src/WebGL2Samples/buffer_copy.ts
@@ -1,5 +1,5 @@
-import { IRenderPass, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
-import { IGLCanvasContext, IGLCopyBufferToBuffer, IGLVertexBuffer, WebGL, getIGLBuffer } from "@feng3d/webgl";
+import { ICopyBufferToBuffer, IRenderPass, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, IGLVertexBuffer, WebGL, getIGLBuffer } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -34,7 +34,7 @@ import { getShaderSource } from "./utility";
const vertexPosBufferDst = new Float32Array(vertices.length);
- const cb: IGLCopyBufferToBuffer = {
+ const cb: ICopyBufferToBuffer = {
__type: "CopyBufferToBuffer",
source: vertexPosBufferSrc,
destination: getIGLBuffer(vertexPosBufferDst, "ARRAY_BUFFER"),
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 4d4dd0b..e0bef0b 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,4 +1,4 @@
-import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IUniforms, IVertexAttribute, IVertexAttributes, IViewport, TypedArray } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICopyBufferToBuffer, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IUniforms, IVertexAttribute, IVertexAttributes, IViewport, TypedArray } from "@feng3d/render-api";
import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLFramebuffer } from "./caches/getGLFramebuffer";
@@ -14,7 +14,6 @@ import { _GL_Submit_Times } from "./const/const";
import { IGLUniformBufferType } from "./const/IGLUniformType";
import { IGLBlitFramebuffer } from "./data/IGLBlitFramebuffer";
import { IGLDrawElementType } from "./data/IGLBuffer";
-import { IGLCopyBufferToBuffer } from "./data/IGLCopyBufferToBuffer";
import { IGLCompareFunction, IGLStencilFunc, IGLStencilOp } from "./data/IGLDepthStencilState";
import { IGLOcclusionQuery } from "./data/IGLOcclusionQuery";
import { IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "./data/IGLSampler";
@@ -911,7 +910,7 @@ export class RunWebGL
}
}
- private runCopyBuffer(gl: WebGLRenderingContext, copyBuffer: IGLCopyBufferToBuffer)
+ private runCopyBuffer(gl: WebGLRenderingContext, copyBuffer: ICopyBufferToBuffer)
{
if (gl instanceof WebGL2RenderingContext)
{
diff --git a/src/data/IGLCommandEncoder.ts b/src/data/IGLCommandEncoder.ts
index a11c8e6..bbcfa7b 100644
--- a/src/data/IGLCommandEncoder.ts
+++ b/src/data/IGLCommandEncoder.ts
@@ -1,13 +1,11 @@
-import { ICommandEncoder, IPassEncoder, IRenderPass, ITextureLike } from "@feng3d/render-api";
+import { ITextureLike } from "@feng3d/render-api";
import { IGLBlitFramebuffer } from "./IGLBlitFramebuffer";
-import { IGLCopyBufferToBuffer } from "./IGLCopyBufferToBuffer";
declare module "@feng3d/render-api"
{
export interface IPassEncoderMap
{
IGLBlitFramebuffer: IGLBlitFramebuffer;
- IGLCopyBufferToBuffer: IGLCopyBufferToBuffer;
}
/**
diff --git a/src/data/IGLCopyBufferToBuffer.ts b/src/data/IGLCopyBufferToBuffer.ts
deleted file mode 100644
index c321676..0000000
--- a/src/data/IGLCopyBufferToBuffer.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { IBuffer } from "@feng3d/render-api";
-
-/**
- * GL缓冲区之间拷贝。
- *
- * {@link WebGL2RenderingContextBase.copyBufferSubData}
- */
-export interface IGLCopyBufferToBuffer
-{
- /**
- * 数据类型。
- */
- readonly __type: "CopyBufferToBuffer";
- /**
- * 源缓冲区。
- */
- source: IBuffer,
- /**
- * 默认为0。
- */
- sourceOffset: number
- /**
- * 目标缓冲区。
- */
- destination: IBuffer,
- /**
- * 默认为0。
- */
- destinationOffset: number
- /**
- * 默认为源缓冲区尺寸。
- */
- size: number
-}
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index 2c8c50f..fc06b9c 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -3,7 +3,6 @@ export * from "./data/IGLBuffer";
export * from "./data/IGLCanvasContext";
export * from "./data/IGLCapabilities";
export * from "./data/IGLCommandEncoder";
-export * from "./data/IGLCopyBufferToBuffer";
export * from "./data/IGLDepthStencilState";
export * from "./data/IGLOcclusionQuery";
export * from "./data/IGLPrimitiveState";
--
Gitee
From 9359d14dd2f7fc815f120e9ca35ba0ff5f80c67f Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 8 Jan 2025 16:52:21 +0800
Subject: [PATCH 178/186] updateBufferBinding
---
src/const/IGLUniformType.ts | 2 +-
src/utils/updateBufferBinding.ts | 85 ++++++++++++++++++++++++++++++--
2 files changed, 83 insertions(+), 4 deletions(-)
diff --git a/src/const/IGLUniformType.ts b/src/const/IGLUniformType.ts
index 95c2c70..488c4a9 100644
--- a/src/const/IGLUniformType.ts
+++ b/src/const/IGLUniformType.ts
@@ -67,7 +67,7 @@ const webGLUniformTypeValue = { ...webGL1UniformBufferTypeValue, ...webGL1Unifor
const webGLUniformTextureTypeValue = { ...webGL1UniformTextureTypeValue, ...webGL2OnlyUniformTextureTypeValue };
/**
- * WebGL Uniform 纹理类型与值的映射。
+ * WebGL Uniform 缓冲区数据与值的映射。
*/
const webGLUniformBufferTypeValue = { ...webGL1UniformBufferTypeValue, ...webGL2OnlyUniformBufferTypeValue };
diff --git a/src/utils/updateBufferBinding.ts b/src/utils/updateBufferBinding.ts
index 3daed89..d8014b2 100644
--- a/src/utils/updateBufferBinding.ts
+++ b/src/utils/updateBufferBinding.ts
@@ -1,6 +1,16 @@
import { TypedArray, UnReadonly } from "@feng3d/render-api";
+import { watcher } from "@feng3d/watcher";
import { IUniformBlockInfo } from "../caches/getGLProgram";
+import { IGLUniformBufferType } from "../const/IGLUniformType";
+import { getIGLBuffer } from "../runs/getIGLBuffer";
+/**
+ *
+ * @param uniformBlock
+ * @param uniformData
+ *
+ * @see https://learnopengl-cn.readthedocs.io/zh/latest/04%20Advanced%20OpenGL/08%20Advanced%20GLSL/#uniform_1
+ */
export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData: IBufferBinding)
{
const size = uniformBlock.dataSize;
@@ -11,11 +21,47 @@ export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData
(uniformData as UnReadonly).bufferView = new Uint8Array(size);
}
- // const buffer = getIGLBuffer(uniformData.bufferView);
- // (buffer as any).label = buffer.label || (`BufferBinding ${variableInfo.name}`);
- // const offset = uniformData.bufferView.byteOffset;
+ const buffer = getIGLBuffer(uniformData.bufferView);
+ (buffer as any).label = buffer.label || (`BufferBinding ${uniformBlock.name}`);
+ const offset = uniformData.bufferView.byteOffset;
+ let currentSize = 0;
+
+ uniformBlock.uniforms.forEach((uniformInfo) =>
+ {
+ const uniformBufferType = uniformInfo.type as IGLUniformBufferType;
+ const alignSize = uniformBufferTypeAlignSizeMap[uniformBufferType];
+ console.assert(alignSize, `没有找到 ${uniformBufferType} 统一缓冲类型对应的对齐与尺寸。`);
+
+ uniformInfo.items.forEach((itemInfo) =>
+ {
+ currentSize = roundUp(alignSize.align, currentSize); // 单项对齐
+ itemInfo.offset = currentSize;
+ itemInfo.size = alignSize.size;
+ //
+ currentSize += alignSize.size;
+ //
+ const paths = itemInfo.paths;
+ const update = () =>
+ {
+ let value: any;
+ for (let i = 0; i < paths.length; i++)
+ {
+ value = uniformData[paths[i]];
+ if (value === undefined) return;
+ }
+ }
+ update();
+ watcher.watchchain(uniformData, itemInfo.paths.join("."), update, undefined, false);
+ });
+ });
+ currentSize = roundUp(4, currentSize); // 整个数据对齐
+}
+
+function roundUp(k: number, n: number): number
+{
+ return Math.ceil(n / k) * k;
}
/**
@@ -30,3 +76,36 @@ export interface IBufferBinding
*/
readonly bufferView?: TypedArray;
}
+
+/**
+ *
+ * @see https://github.com/brendan-duncan/wgsl_reflect/blob/main/src/wgsl_reflect.ts#L1206
+ * @see https://www.orillusion.com/zh/wgsl.html#memory-layouts
+ */
+const uniformBufferTypeAlignSizeMap: { [key: string]: { align: number, size: number } } = {
+ "FLOAT": { align: 4, size: 4 },
+ "FLOAT_VEC2": { align: 8, size: 8 },
+ "FLOAT_VEC3": { align: 16, size: 12 },
+ "FLOAT_VEC4": { align: 16, size: 16 },
+ "INT": { align: 4, size: 4 },
+ "INT_VEC2": { align: 8, size: 8 },
+ "INT_VEC3": { align: 16, size: 12 },
+ "INT_VEC4": { align: 16, size: 16 },
+ "BOOL": { align: 4, size: 4 },
+ "BOOL_VEC2": { align: 8, size: 8 },
+ "BOOL_VEC3": { align: 16, size: 12 },
+ "BOOL_VEC4": { align: 16, size: 16 },
+ "FLOAT_MAT2": { align: 8, size: 16 },
+ "FLOAT_MAT3": { align: 16, size: 48 },
+ "FLOAT_MAT4": { align: 16, size: 64 },
+ "UNSIGNED_INT": { align: 4, size: 4 },
+ "UNSIGNED_INT_VEC2": { align: 8, size: 8 },
+ "UNSIGNED_INT_VEC3": { align: 16, size: 12 },
+ "UNSIGNED_INT_VEC4": { align: 16, size: 16 },
+ "FLOAT_MAT2x3": { align: 16, size: 32 },
+ "FLOAT_MAT2x4": { align: 16, size: 32 },
+ "FLOAT_MAT3x2": { align: 8, size: 24 },
+ "FLOAT_MAT3x4": { align: 16, size: 48 },
+ "FLOAT_MAT4x2": { align: 8, size: 32 },
+ "FLOAT_MAT4x3": { align: 16, size: 64 },
+};
\ No newline at end of file
--
Gitee
From 7dea704a68618348d2c0d262d79830089ecd4938 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 8 Jan 2025 17:53:05 +0800
Subject: [PATCH 179/186] updateBufferBinding
---
src/utils/updateBufferBinding.ts | 88 +++++++++++++++++++++-----------
1 file changed, 57 insertions(+), 31 deletions(-)
diff --git a/src/utils/updateBufferBinding.ts b/src/utils/updateBufferBinding.ts
index d8014b2..7368a33 100644
--- a/src/utils/updateBufferBinding.ts
+++ b/src/utils/updateBufferBinding.ts
@@ -35,28 +35,48 @@ export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData
uniformInfo.items.forEach((itemInfo) =>
{
currentSize = roundUp(alignSize.align, currentSize); // 单项对齐
- itemInfo.offset = currentSize;
- itemInfo.size = alignSize.size;
+ const itemInfoOffset = currentSize;
+ const itemInfoSize = alignSize.size;
//
currentSize += alignSize.size;
+ const Cls = alignSize.clsType;
//
const paths = itemInfo.paths;
const update = () =>
{
- let value: any;
+ let value: any = uniformData;
for (let i = 0; i < paths.length; i++)
{
- value = uniformData[paths[i]];
+ value = value[paths[i]];
if (value === undefined) return;
}
+ let data: Float32Array | Int32Array | Uint32Array;
+ if (typeof value === "number")
+ {
+ data = new Cls([value]);
+ }
+ else if (value.constructor.name !== Cls.name)
+ {
+ data = new Cls(value as ArrayLike);
+ }
+ else
+ {
+ data = value as any;
+ }
+
+ const writeBuffers = buffer.writeBuffers ?? [];
+ writeBuffers.push({ data: data.buffer, bufferOffset: offset + itemInfoOffset, size: Math.min(itemInfoSize, data.byteLength) });
+ buffer.writeBuffers = writeBuffers;
}
update();
watcher.watchchain(uniformData, itemInfo.paths.join("."), update, undefined, false);
});
});
- currentSize = roundUp(4, currentSize); // 整个数据对齐
+ currentSize = roundUp(16, currentSize); // 整个数据对齐
+
+ console.assert(size === currentSize, `uniformBlock映射尺寸出现错误( ${size} ${currentSize} )!`);
}
function roundUp(k: number, n: number): number
@@ -82,30 +102,36 @@ export interface IBufferBinding
* @see https://github.com/brendan-duncan/wgsl_reflect/blob/main/src/wgsl_reflect.ts#L1206
* @see https://www.orillusion.com/zh/wgsl.html#memory-layouts
*/
-const uniformBufferTypeAlignSizeMap: { [key: string]: { align: number, size: number } } = {
- "FLOAT": { align: 4, size: 4 },
- "FLOAT_VEC2": { align: 8, size: 8 },
- "FLOAT_VEC3": { align: 16, size: 12 },
- "FLOAT_VEC4": { align: 16, size: 16 },
- "INT": { align: 4, size: 4 },
- "INT_VEC2": { align: 8, size: 8 },
- "INT_VEC3": { align: 16, size: 12 },
- "INT_VEC4": { align: 16, size: 16 },
- "BOOL": { align: 4, size: 4 },
- "BOOL_VEC2": { align: 8, size: 8 },
- "BOOL_VEC3": { align: 16, size: 12 },
- "BOOL_VEC4": { align: 16, size: 16 },
- "FLOAT_MAT2": { align: 8, size: 16 },
- "FLOAT_MAT3": { align: 16, size: 48 },
- "FLOAT_MAT4": { align: 16, size: 64 },
- "UNSIGNED_INT": { align: 4, size: 4 },
- "UNSIGNED_INT_VEC2": { align: 8, size: 8 },
- "UNSIGNED_INT_VEC3": { align: 16, size: 12 },
- "UNSIGNED_INT_VEC4": { align: 16, size: 16 },
- "FLOAT_MAT2x3": { align: 16, size: 32 },
- "FLOAT_MAT2x4": { align: 16, size: 32 },
- "FLOAT_MAT3x2": { align: 8, size: 24 },
- "FLOAT_MAT3x4": { align: 16, size: 48 },
- "FLOAT_MAT4x2": { align: 8, size: 32 },
- "FLOAT_MAT4x3": { align: 16, size: 64 },
+const uniformBufferTypeAlignSizeMap: {
+ [key: string]: {
+ align: number,
+ size: number,
+ clsType: Float32ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor,
+ }
+} = {
+ "FLOAT": { align: 4, size: 4, clsType: Float32Array },
+ "FLOAT_VEC2": { align: 8, size: 8, clsType: Float32Array },
+ "FLOAT_VEC3": { align: 16, size: 12, clsType: Float32Array },
+ "FLOAT_VEC4": { align: 16, size: 16, clsType: Float32Array },
+ "INT": { align: 4, size: 4, clsType: Int32Array },
+ "INT_VEC2": { align: 8, size: 8, clsType: Int32Array },
+ "INT_VEC3": { align: 16, size: 12, clsType: Int32Array },
+ "INT_VEC4": { align: 16, size: 16, clsType: Int32Array },
+ "BOOL": { align: 4, size: 4, clsType: Int32Array },
+ "BOOL_VEC2": { align: 8, size: 8, clsType: Int32Array },
+ "BOOL_VEC3": { align: 16, size: 12, clsType: Int32Array },
+ "BOOL_VEC4": { align: 16, size: 16, clsType: Int32Array },
+ "FLOAT_MAT2": { align: 8, size: 16, clsType: Float32Array },
+ "FLOAT_MAT3": { align: 16, size: 48, clsType: Float32Array },
+ "FLOAT_MAT4": { align: 16, size: 64, clsType: Float32Array },
+ "UNSIGNED_INT": { align: 4, size: 4, clsType: Uint32Array },
+ "UNSIGNED_INT_VEC2": { align: 8, size: 8, clsType: Uint32Array },
+ "UNSIGNED_INT_VEC3": { align: 16, size: 12, clsType: Uint32Array },
+ "UNSIGNED_INT_VEC4": { align: 16, size: 16, clsType: Uint32Array },
+ "FLOAT_MAT2x3": { align: 16, size: 32, clsType: Float32Array },
+ "FLOAT_MAT2x4": { align: 16, size: 32, clsType: Float32Array },
+ "FLOAT_MAT3x2": { align: 8, size: 24, clsType: Float32Array },
+ "FLOAT_MAT3x4": { align: 16, size: 48, clsType: Float32Array },
+ "FLOAT_MAT4x2": { align: 8, size: 32, clsType: Float32Array },
+ "FLOAT_MAT4x3": { align: 16, size: 64, clsType: Float32Array },
};
\ No newline at end of file
--
Gitee
From aa5989d44ad35399d2adfc77872f538ab70a0201 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 8 Jan 2025 20:56:28 +0800
Subject: [PATCH 180/186] =?UTF-8?q?=E5=8F=8D=E5=B0=84=20GLUniformBuffer=20?=
=?UTF-8?q?=E5=B1=9E=E6=80=A7=E6=95=B0=E6=8D=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
examples/src/WebGL2Samples/buffer_uniform.ts | 75 +++++++++++--------
.../src/WebGL2Samples/draw_instanced_ubo.ts | 43 ++++++-----
src/RunWebGL.ts | 40 +++++-----
src/caches/getGLBuffer.ts | 2 +-
src/data/IGLUniforms.ts | 24 +++++-
src/utils/updateBufferBinding.ts | 48 +++++++-----
6 files changed, 144 insertions(+), 88 deletions(-)
diff --git a/examples/src/WebGL2Samples/buffer_uniform.ts b/examples/src/WebGL2Samples/buffer_uniform.ts
index eec9965..6e110e7 100644
--- a/examples/src/WebGL2Samples/buffer_uniform.ts
+++ b/examples/src/WebGL2Samples/buffer_uniform.ts
@@ -1,5 +1,5 @@
-import { IRenderObject, IRenderPass, IRenderPipeline, IVertexAttributes } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, WebGL } from "@feng3d/webgl";
+import { IRenderObject, IRenderPass, IRenderPipeline, ISubmit, IVertexAttributes } from "@feng3d/render-api";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
(function ()
@@ -35,33 +35,42 @@ import { getShaderSource } from "./utility";
]);
//mat4 P, mat4 MV, mat3 Mnormal
- const transforms = new Float32Array([
- 1.0, 0.0, 0.0, 0.0,
- 0.0, 1.0, 0.0, 0.0,
- 0.0, 0.0, 1.0, 0.0,
- 0.0, 0.0, 0.0, 1.0,
-
- 0.5, 0.0, 0.0, 0.0,
- 0.0, 0.5, 0.0, 0.0,
- 0.0, 0.0, 0.5, 0.0,
- 0.0, 0.0, 0.0, 1.0,
-
- 1.0, 0.0, 0.0, 0.0,
- 0.0, 1.0, 0.0, 0.0,
- 0.0, 0.0, 1.0, 0.0,
- 0.0, 0.0, 0.0, 1.0
- ]);
+ const transforms = {
+ transform: {
+ P: [1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0,
+ ],
+ MV: [0.5, 0.0, 0.0, 0.0,
+ 0.0, 0.5, 0.0, 0.0,
+ 0.0, 0.0, 0.5, 0.0,
+ 0.0, 0.0, 0.0, 1.0,
+ ],
+ Mnormal: [
+ 1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0,
+ ],
+ }
+ };
- const lightPos = new Float32Array([
- 0.0, 0.0, 0.0, 0.0,
- ]);
+ const lightPos = {
+ light: {
+ position: [0.0, 0.0, 0.0]
+ }
+ };
//vec3 ambient, diffuse, specular, float shininess
- const material = new Float32Array([
- 0.1, 0.0, 0.0, 0.0,
- 0.5, 0.0, 0.0, 0.0,
- 1.0, 1.0, 1.0, 4.0,
- ]);
+ const material = {
+ material: {
+ ambient: [0.1, 0.0, 0.0],
+ diffuse: [0.5, 0.0, 0.0],
+ specular: [1.0, 1.0, 1.0],
+ shininess: 4.0,
+ }
+ };
// -- Init Vertex Array
const vertexArray: { vertices?: IVertexAttributes } = {
@@ -89,20 +98,22 @@ import { getShaderSource } from "./utility";
renderObjects: [ro],
};
+ const submit: ISubmit = { commandEncoders: [{ passEncoders: [rp] }] };
+
let uTime = 0;
function render()
{
uTime += 0.01;
// -- update uniform buffer
- transforms[16] = 0.1 * Math.cos(uTime) + 0.4;
- getIGLBuffer(transforms).writeBuffers = [{ bufferOffset: 0, data: transforms }];
+ transforms.transform.MV[0] = 0.1 * Math.cos(uTime) + 0.4;
+ transforms.transform.MV = transforms.transform.MV;
- lightPos[0] = Math.cos(3 * uTime);
- lightPos[1] = Math.sin(6 * uTime);
- getIGLBuffer(lightPos).writeBuffers = [{ bufferOffset: 0, data: lightPos }];
+ lightPos.light.position[0] = Math.cos(3 * uTime);
+ lightPos.light.position[1] = Math.sin(6 * uTime);
+ lightPos.light.position = lightPos.light.position;
- webgl.submit({ commandEncoders: [{ passEncoders: [rp] }] });
+ webgl.submit(submit);
requestAnimationFrame(render);
}
diff --git a/examples/src/WebGL2Samples/draw_instanced_ubo.ts b/examples/src/WebGL2Samples/draw_instanced_ubo.ts
index 018d2a4..339fe65 100644
--- a/examples/src/WebGL2Samples/draw_instanced_ubo.ts
+++ b/examples/src/WebGL2Samples/draw_instanced_ubo.ts
@@ -1,5 +1,5 @@
import { IRenderPass, IRenderPipeline } from "@feng3d/render-api";
-import { getIGLBuffer, IGLCanvasContext, WebGL } from "@feng3d/webgl";
+import { IGLCanvasContext, WebGL } from "@feng3d/webgl";
import { getShaderSource } from "./utility";
const canvas = document.createElement("canvas");
@@ -21,22 +21,29 @@ const vertices = new Float32Array([
0.0, 0.5
]);
-const transforms = new Float32Array([
- 1.0, 0.0, 0.0, 0.0,
- 0.0, 1.0, 0.0, 0.0,
- 0.0, 0.0, 1.0, 0.0,
- -0.5, 0.0, 0.0, 1.0,
-
- 1.0, 0.0, 0.0, 0.0,
- 0.0, 1.0, 0.0, 0.0,
- 0.0, 0.0, 1.0, 0.0,
- 0.5, 0.0, 0.0, 1.0
-]);
+const transforms = {
+ MVP: [
+ new Float32Array([
+ 1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ -0.5, 0.0, 0.0, 1.0,
+ ]),
+ new Float32Array([
+ 1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.5, 0.0, 0.0, 1.0
+ ]),
+ ]
+};
-const materials = new Float32Array([
- 1.0, 0.5, 0.0, 1.0,
- 0.0, 0.5, 1.0, 1.0
-]);
+const materials = {
+ Diffuse: [
+ [1.0, 0.5, 0.0, 1.0,],
+ [0.0, 0.5, 1.0, 1.0],
+ ]
+};
// -- Render
const rp: IRenderPass = {
@@ -57,6 +64,6 @@ const rp: IRenderPass = {
webgl.submit({ commandEncoders: [{ passEncoders: [rp] }] });
// -- Delete WebGL resources
-webgl.deleteBuffer(getIGLBuffer(transforms));
-webgl.deleteBuffer(getIGLBuffer(materials));
+// webgl.deleteBuffer(getIGLBuffer(transforms));
+// webgl.deleteBuffer(getIGLBuffer(materials));
webgl.deleteProgram(program);
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index e0bef0b..6a2be39 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -13,7 +13,7 @@ import { getIGLTextureTarget } from "./caches/getIGLTextureTarget";
import { _GL_Submit_Times } from "./const/const";
import { IGLUniformBufferType } from "./const/IGLUniformType";
import { IGLBlitFramebuffer } from "./data/IGLBlitFramebuffer";
-import { IGLDrawElementType } from "./data/IGLBuffer";
+import { IGLDrawElementType, IGLUniformBuffer } from "./data/IGLBuffer";
import { IGLCompareFunction, IGLStencilFunc, IGLStencilOp } from "./data/IGLDepthStencilState";
import { IGLOcclusionQuery } from "./data/IGLOcclusionQuery";
import { IGLTextureMagFilter, IGLTextureMinFilter, IGLTextureWrap } from "./data/IGLSampler";
@@ -22,6 +22,7 @@ import { IGLTextureTarget } from "./data/IGLTexture";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
import { IGLTransformFeedbackObject, IGLTransformFeedbackPass, IGLTransformFeedbackPipeline } from "./data/IGLTransformFeedbackPass";
import { IUniformItemInfo } from "./data/IGLUniformInfo";
+import { IBufferBinding } from "./data/IGLUniforms";
import { getGLTexture } from "./internal";
import { getIGLIndexBuffer, getIGLUniformBuffer, getIGLVertexBuffer } from "./runs/getIGLBuffer";
import { getIGLBlendEquation, getIGLBlendFactor, IGLBlendEquation, IGLBlendFactor } from "./runs/runColorTargetStates";
@@ -355,10 +356,21 @@ export class RunWebGL
webGLProgram.uniformBlocks.forEach((uniformBlock) =>
{
const { name, index } = uniformBlock;
- const uniformData = uniforms[name] as TypedArray;
+ const uniformData = uniforms[name] as TypedArray | IBufferBinding;
- const buffer = getIGLUniformBuffer(uniformData);
- updateBufferBinding(uniformBlock, { bufferView: uniformData });
+ //
+ let buffer: IGLUniformBuffer;
+ const typedArray = uniformData as TypedArray;
+ if (typedArray.buffer && typedArray.BYTES_PER_ELEMENT)
+ {
+ buffer = getIGLUniformBuffer(typedArray);
+ }
+ else
+ {
+ const bufferBinding = uniforms[name] as IBufferBinding;
+ updateBufferBinding(uniformBlock, bufferBinding);
+ buffer = getIGLUniformBuffer(bufferBinding.bufferView);
+ }
//
const webGLBuffer = getGLBuffer(gl, buffer);
@@ -446,43 +458,39 @@ export class RunWebGL
*/
private runUniform(gl: WebGLRenderingContext, type: IGLUniformBufferType, uniformInfo: IUniformItemInfo, data: any)
{
+ if (typeof data === 'number')
+ {
+ data = [data];
+ }
const location = uniformInfo.location;
switch (type)
{
case "BOOL":
case "INT":
- // gl.uniform1i(location, data);
- gl.uniform1iv(location, [data]);
+ gl.uniform1iv(location, data);
break;
case "BOOL_VEC2":
case "INT_VEC2":
- // gl.uniform2i(location, data[0], data[1]);
gl.uniform2iv(location, data);
break;
case "BOOL_VEC3":
case "INT_VEC3":
- // gl.uniform3i(location, data[0], data[1], data[2]);
gl.uniform3iv(location, data);
break;
case "BOOL_VEC4":
case "INT_VEC4":
- // gl.uniform4i(location, data[0], data[1], data[2], data[3]);
gl.uniform4iv(location, data);
break;
case "FLOAT":
- // gl.uniform1f(location, data);
gl.uniform1fv(location, [data]);
break;
case "FLOAT_VEC2":
- // gl.uniform2f(location, data[0], data[1]);
gl.uniform2fv(location, data);
break;
case "FLOAT_VEC3":
- // gl.uniform3f(location, data[0], data[1], data[2]);
gl.uniform3fv(location, data);
break;
case "FLOAT_VEC4":
- // gl.uniform4f(location, data[0], data[1], data[2], data[3]);
gl.uniform4fv(location, data);
break;
case "FLOAT_MAT2":
@@ -495,19 +503,15 @@ export class RunWebGL
gl.uniformMatrix4fv(location, false, data);
break;
case "UNSIGNED_INT":
- (gl as any as WebGL2RenderingContext).uniform1ui(location, data);
- (gl as any as WebGL2RenderingContext).uniform1uiv(location, [data]);
+ (gl as any as WebGL2RenderingContext).uniform1uiv(location, data);
break;
case "UNSIGNED_INT_VEC2":
- // (gl as any as WebGL2RenderingContext).uniform2ui(location, data[0], data[1]);
(gl as any as WebGL2RenderingContext).uniform2uiv(location, data);
break;
case "UNSIGNED_INT_VEC3":
- // (gl as any as WebGL2RenderingContext).uniform3ui(location, data[0], data[1], data[2]);
(gl as any as WebGL2RenderingContext).uniform3uiv(location, data);
break;
case "UNSIGNED_INT_VEC4":
- // (gl as any as WebGL2RenderingContext).uniform4ui(location, data[0], data[1], data[2], data[3]);
(gl as any as WebGL2RenderingContext).uniform4uiv(location, data);
break;
case "FLOAT_MAT2x3":
diff --git a/src/caches/getGLBuffer.ts b/src/caches/getGLBuffer.ts
index 7eadd51..1cfd4da 100644
--- a/src/caches/getGLBuffer.ts
+++ b/src/caches/getGLBuffer.ts
@@ -74,7 +74,7 @@ export function getGLBuffer(gl: WebGLRenderingContext, buffer: IBuffer)
if (!buffer.data) return;
const writeBuffers = buffer.writeBuffers || [];
- writeBuffers.push({ data: buffer.data });
+ writeBuffers.unshift({ data: buffer.data });
buffer.writeBuffers = writeBuffers;
};
diff --git a/src/data/IGLUniforms.ts b/src/data/IGLUniforms.ts
index 1797209..de04cf0 100644
--- a/src/data/IGLUniforms.ts
+++ b/src/data/IGLUniforms.ts
@@ -1,13 +1,33 @@
-import { } from "@feng3d/render-api";
+import { TypedArray } from "@feng3d/render-api";
import { IGLSamplerTexture } from "./IGLSamplerTexture";
declare module "@feng3d/render-api"
{
export interface IUniformTypeMap
{
+ /**
+ * Uniform Block 数据
+ * 统一块数据
+ */
+ IBufferBinding: IBufferBinding;
IGLSamplerTexture: IGLSamplerTexture;
IGLUniformDataItem: IGLUniformDataItem;
}
}
-export type IGLUniformDataItem = number | number[] | Float32Array | Int32Array;
+export type IGLUniformDataItem = number | number[] | number[][] | TypedArray | TypedArray[];
+
+/**
+ * 缓冲区绑定。
+ */
+export interface IBufferBinding
+{
+ [name: string]: IBufferBindingItem;
+
+ /**
+ * 如果未设置引擎将自动生成。
+ */
+ readonly bufferView?: TypedArray;
+}
+
+export type IBufferBindingItem = IGLUniformDataItem | { [key: string]: IBufferBindingItem };
\ No newline at end of file
diff --git a/src/utils/updateBufferBinding.ts b/src/utils/updateBufferBinding.ts
index 7368a33..cf7a659 100644
--- a/src/utils/updateBufferBinding.ts
+++ b/src/utils/updateBufferBinding.ts
@@ -1,7 +1,8 @@
-import { TypedArray, UnReadonly } from "@feng3d/render-api";
+import { UnReadonly } from "@feng3d/render-api";
import { watcher } from "@feng3d/watcher";
import { IUniformBlockInfo } from "../caches/getGLProgram";
import { IGLUniformBufferType } from "../const/IGLUniformType";
+import { IBufferBinding } from "../data/IGLUniforms";
import { getIGLBuffer } from "../runs/getIGLBuffer";
/**
@@ -13,6 +14,21 @@ import { getIGLBuffer } from "../runs/getIGLBuffer";
*/
export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData: IBufferBinding)
{
+ if (uniformData["_uniformBlock"] !== undefined)
+ {
+ const preVariableInfo = uniformData["_uniformBlock"] as any as IUniformBlockInfo;
+ if (preVariableInfo.name !== uniformBlock.name
+ || preVariableInfo.dataSize !== uniformBlock.dataSize
+ )
+ {
+ console.warn(`updateBufferBinding 出现一份数据对应多个 variableInfo`, { uniformData, uniformBlock, preVariableInfo });
+ }
+
+ return;
+ }
+
+ uniformData["_uniformBlock"] = uniformBlock as any;
+
const size = uniformBlock.dataSize;
// 是否存在默认值。
const hasDefautValue = !!uniformData.bufferView;
@@ -20,6 +36,10 @@ export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData
{
(uniformData as UnReadonly).bufferView = new Uint8Array(size);
}
+ else
+ {
+ console.assert(uniformData.bufferView.byteLength === size, `uniformData.bufferView 统一块数据提供数据尺寸不对!`);
+ }
const buffer = getIGLBuffer(uniformData.bufferView);
(buffer as any).label = buffer.label || (`BufferBinding ${uniformBlock.name}`);
@@ -41,14 +61,21 @@ export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData
currentSize += alignSize.size;
const Cls = alignSize.clsType;
//
- const paths = itemInfo.paths;
+ const paths = itemInfo.paths.slice(1);
const update = () =>
{
let value: any = uniformData;
for (let i = 0; i < paths.length; i++)
{
value = value[paths[i]];
- if (value === undefined) return;
+ if (value === undefined)
+ {
+ if (!hasDefautValue)
+ {
+ console.warn(`没有找到 统一块变量属性 ${paths.join(".")} 的值!`);
+ }
+ return;
+ }
}
let data: Float32Array | Int32Array | Uint32Array;
@@ -71,7 +98,7 @@ export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData
}
update();
- watcher.watchchain(uniformData, itemInfo.paths.join("."), update, undefined, false);
+ watcher.watchchain(uniformData, paths.join("."), update, undefined, false);
});
});
currentSize = roundUp(16, currentSize); // 整个数据对齐
@@ -84,19 +111,6 @@ function roundUp(k: number, n: number): number
return Math.ceil(n / k) * k;
}
-/**
- * 缓冲区绑定。
- */
-export interface IBufferBinding
-{
- [name: string]: TypedArray | ArrayLike | number;
-
- /**
- * 如果未设置引擎将自动生成。
- */
- readonly bufferView?: TypedArray;
-}
-
/**
*
* @see https://github.com/brendan-duncan/wgsl_reflect/blob/main/src/wgsl_reflect.ts#L1206
--
Gitee
From 9a5de28c798f3e1c8cec324c195774731d4a4f46 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 8 Jan 2025 22:00:55 +0800
Subject: [PATCH 181/186] =?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BD=93=E4=B9=8B?=
=?UTF-8?q?=E9=97=B4=E5=AF=B9=E9=BD=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/utils/updateBufferBinding.ts | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/utils/updateBufferBinding.ts b/src/utils/updateBufferBinding.ts
index cf7a659..aacd1d2 100644
--- a/src/utils/updateBufferBinding.ts
+++ b/src/utils/updateBufferBinding.ts
@@ -45,6 +45,7 @@ export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData
(buffer as any).label = buffer.label || (`BufferBinding ${uniformBlock.name}`);
const offset = uniformData.bufferView.byteOffset;
let currentSize = 0;
+ let structName: string;
uniformBlock.uniforms.forEach((uniformInfo) =>
{
@@ -52,9 +53,18 @@ export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData
const alignSize = uniformBufferTypeAlignSizeMap[uniformBufferType];
console.assert(alignSize, `没有找到 ${uniformBufferType} 统一缓冲类型对应的对齐与尺寸。`);
+ //
+ const currentstructName = uniformInfo.name.substring(0, uniformInfo.name.lastIndexOf("."));
+ if (structName !== currentstructName)
+ {
+ currentSize = roundUp(16, currentSize); // 结构体之间对齐
+ structName = currentstructName;
+ }
+
+ //
uniformInfo.items.forEach((itemInfo) =>
{
- currentSize = roundUp(alignSize.align, currentSize); // 单项对齐
+ currentSize = roundUp(alignSize.align, currentSize); // 结构体成员对齐
const itemInfoOffset = currentSize;
const itemInfoSize = alignSize.size;
//
@@ -101,7 +111,7 @@ export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData
watcher.watchchain(uniformData, paths.join("."), update, undefined, false);
});
});
- currentSize = roundUp(16, currentSize); // 整个数据对齐
+ currentSize = roundUp(16, currentSize); // 整个统一块数据对齐
console.assert(size === currentSize, `uniformBlock映射尺寸出现错误( ${size} ${currentSize} )!`);
}
--
Gitee
From bca904a20a3f9e1673cf8bf6971049b03b435816 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 8 Jan 2025 22:44:33 +0800
Subject: [PATCH 182/186] updateBufferBinding
IUniformBlockInfo.bufferBindingInfo
---
src/RunWebGL.ts | 2 +-
src/caches/getGLProgram.ts | 120 +++++++++++++++++++++++-
src/utils/updateBufferBinding.ts | 155 +++++++++----------------------
3 files changed, 162 insertions(+), 115 deletions(-)
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 6a2be39..9e3c651 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -368,7 +368,7 @@ export class RunWebGL
else
{
const bufferBinding = uniforms[name] as IBufferBinding;
- updateBufferBinding(uniformBlock, bufferBinding);
+ updateBufferBinding(uniformBlock.bufferBindingInfo, bufferBinding);
buffer = getIGLUniformBuffer(bufferBinding.bufferView);
}
diff --git a/src/caches/getGLProgram.ts b/src/caches/getGLProgram.ts
index 207e125..7df5592 100644
--- a/src/caches/getGLProgram.ts
+++ b/src/caches/getGLProgram.ts
@@ -1,5 +1,5 @@
import { IRenderPipeline } from "@feng3d/render-api";
-import { getWebGLUniformType, isWebGLUniformTextureType } from "../const/IGLUniformType";
+import { getWebGLUniformType, IGLUniformBufferType, isWebGLUniformTextureType } from "../const/IGLUniformType";
import { IGLAttributeInfo } from "../data/IGLAttributeInfo";
import { IGLTransformFeedbackPipeline, IGLTransformFeedbackVaryings } from "../data/IGLTransformFeedbackPass";
import { IGLUniformInfo, IUniformItemInfo } from "../data/IGLUniformInfo";
@@ -175,8 +175,12 @@ function getWebGLProgram(gl: WebGLRenderingContext, vshader: string, fshader: st
index: i,
dataSize: gl.getActiveUniformBlockParameter(program, i, gl.UNIFORM_BLOCK_DATA_SIZE),
uniforms: uniformList,
+ bufferBindingInfo: undefined,
};
+ //
+ info.bufferBindingInfo = getBufferBindingInfo(info);
+
return info;
});
program.uniformBlocks = uniformBlockActiveInfos;
@@ -215,6 +219,11 @@ export interface IUniformBlockInfo
* 包含的统一变量列表。
*/
uniforms: IGLUniformInfo[];
+
+ /**
+ * 缓冲区绑定信息。
+ */
+ bufferBindingInfo: IBufferBindingInfo;
}
/**
@@ -291,3 +300,112 @@ function createLinkProgram(gl: WebGLRenderingContext, vertexShader: WebGLShader,
* Either a gl.FRAGMENT_SHADER or a gl.VERTEX_SHADER.
*/
export type ShaderType = "FRAGMENT_SHADER" | "VERTEX_SHADER";
+
+/**
+ * 缓冲区绑定信息。
+ */
+export interface IBufferBindingInfo
+{
+ name: string;
+ size: number;
+ items: {
+ paths: string[];
+ offset: number;
+ size: number;
+ Cls: Float32ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor;
+ }[]
+}
+
+function getBufferBindingInfo(uniformBlock: IUniformBlockInfo): IBufferBindingInfo
+{
+ const size = uniformBlock.dataSize;
+ //
+ let currentSize = 0;
+ let structName: string;
+
+ const items: { paths: string[], offset: number, size: number, Cls: Float32ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor }[] = [];
+ uniformBlock.uniforms.forEach((uniformInfo) =>
+ {
+ const uniformBufferType = uniformInfo.type as IGLUniformBufferType;
+ const alignSize = uniformBufferTypeAlignSizeMap[uniformBufferType];
+ console.assert(alignSize, `没有找到 ${uniformBufferType} 统一缓冲类型对应的对齐与尺寸。`);
+
+ //
+ const currentstructName = uniformInfo.name.substring(0, uniformInfo.name.lastIndexOf("."));
+ if (structName !== currentstructName)
+ {
+ currentSize = roundUp(16, currentSize); // 结构体之间对齐
+ structName = currentstructName;
+ }
+
+ //
+ uniformInfo.items.forEach((itemInfo) =>
+ {
+ currentSize = roundUp(alignSize.align, currentSize); // 结构体成员对齐
+ const itemInfoOffset = currentSize;
+ const itemInfoSize = alignSize.size;
+ //
+ currentSize += alignSize.size;
+ const Cls = alignSize.clsType;
+ //
+ const paths = itemInfo.paths.slice(1);
+ //
+ items.push({ paths, offset: itemInfoOffset, size: itemInfoSize, Cls: Cls });
+ });
+ });
+ currentSize = roundUp(16, currentSize); // 整个统一块数据对齐
+
+ console.assert(size === currentSize, `uniformBlock映射尺寸出现错误( ${size} ${currentSize} )!`);
+
+ const bufferBindingInfo: IBufferBindingInfo = {
+ size: uniformBlock.dataSize,
+ name: uniformBlock.name,
+ items,
+ };
+
+ return bufferBindingInfo;
+}
+
+function roundUp(k: number, n: number): number
+{
+ return Math.ceil(n / k) * k;
+}
+
+/**
+ *
+ * @see https://github.com/brendan-duncan/wgsl_reflect/blob/main/src/wgsl_reflect.ts#L1206
+ * @see https://www.orillusion.com/zh/wgsl.html#memory-layouts
+ */
+const uniformBufferTypeAlignSizeMap: {
+ [key: string]: {
+ align: number,
+ size: number,
+ clsType: Float32ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor,
+ }
+} = {
+ "FLOAT": { align: 4, size: 4, clsType: Float32Array },
+ "FLOAT_VEC2": { align: 8, size: 8, clsType: Float32Array },
+ "FLOAT_VEC3": { align: 16, size: 12, clsType: Float32Array },
+ "FLOAT_VEC4": { align: 16, size: 16, clsType: Float32Array },
+ "INT": { align: 4, size: 4, clsType: Int32Array },
+ "INT_VEC2": { align: 8, size: 8, clsType: Int32Array },
+ "INT_VEC3": { align: 16, size: 12, clsType: Int32Array },
+ "INT_VEC4": { align: 16, size: 16, clsType: Int32Array },
+ "BOOL": { align: 4, size: 4, clsType: Int32Array },
+ "BOOL_VEC2": { align: 8, size: 8, clsType: Int32Array },
+ "BOOL_VEC3": { align: 16, size: 12, clsType: Int32Array },
+ "BOOL_VEC4": { align: 16, size: 16, clsType: Int32Array },
+ "FLOAT_MAT2": { align: 8, size: 16, clsType: Float32Array },
+ "FLOAT_MAT3": { align: 16, size: 48, clsType: Float32Array },
+ "FLOAT_MAT4": { align: 16, size: 64, clsType: Float32Array },
+ "UNSIGNED_INT": { align: 4, size: 4, clsType: Uint32Array },
+ "UNSIGNED_INT_VEC2": { align: 8, size: 8, clsType: Uint32Array },
+ "UNSIGNED_INT_VEC3": { align: 16, size: 12, clsType: Uint32Array },
+ "UNSIGNED_INT_VEC4": { align: 16, size: 16, clsType: Uint32Array },
+ "FLOAT_MAT2x3": { align: 16, size: 32, clsType: Float32Array },
+ "FLOAT_MAT2x4": { align: 16, size: 32, clsType: Float32Array },
+ "FLOAT_MAT3x2": { align: 8, size: 24, clsType: Float32Array },
+ "FLOAT_MAT3x4": { align: 16, size: 48, clsType: Float32Array },
+ "FLOAT_MAT4x2": { align: 8, size: 32, clsType: Float32Array },
+ "FLOAT_MAT4x3": { align: 16, size: 64, clsType: Float32Array },
+};
\ No newline at end of file
diff --git a/src/utils/updateBufferBinding.ts b/src/utils/updateBufferBinding.ts
index aacd1d2..94d30b8 100644
--- a/src/utils/updateBufferBinding.ts
+++ b/src/utils/updateBufferBinding.ts
@@ -1,7 +1,6 @@
import { UnReadonly } from "@feng3d/render-api";
import { watcher } from "@feng3d/watcher";
-import { IUniformBlockInfo } from "../caches/getGLProgram";
-import { IGLUniformBufferType } from "../const/IGLUniformType";
+import { IBufferBindingInfo } from "../caches/getGLProgram";
import { IBufferBinding } from "../data/IGLUniforms";
import { getIGLBuffer } from "../runs/getIGLBuffer";
@@ -12,24 +11,24 @@ import { getIGLBuffer } from "../runs/getIGLBuffer";
*
* @see https://learnopengl-cn.readthedocs.io/zh/latest/04%20Advanced%20OpenGL/08%20Advanced%20GLSL/#uniform_1
*/
-export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData: IBufferBinding)
+export function updateBufferBinding(bufferBindingInfo: IBufferBindingInfo, uniformData: IBufferBinding)
{
- if (uniformData["_uniformBlock"] !== undefined)
+ if (uniformData["_bufferBindingInfo"] !== undefined)
{
- const preVariableInfo = uniformData["_uniformBlock"] as any as IUniformBlockInfo;
- if (preVariableInfo.name !== uniformBlock.name
- || preVariableInfo.dataSize !== uniformBlock.dataSize
+ const preVariableInfo = uniformData["_bufferBindingInfo"] as any as IBufferBindingInfo;
+ if (preVariableInfo.name !== bufferBindingInfo.name
+ || preVariableInfo.size !== bufferBindingInfo.size
)
{
- console.warn(`updateBufferBinding 出现一份数据对应多个 variableInfo`, { uniformData, uniformBlock, preVariableInfo });
+ console.warn(`updateBufferBinding 出现一份数据对应多个 variableInfo`, { uniformData, bufferBindingInfo, preVariableInfo });
}
return;
}
- uniformData["_uniformBlock"] = uniformBlock as any;
+ uniformData["_bufferBindingInfo"] = bufferBindingInfo as any;
- const size = uniformBlock.dataSize;
+ const size = bufferBindingInfo.size;
// 是否存在默认值。
const hasDefautValue = !!uniformData.bufferView;
if (!hasDefautValue)
@@ -41,121 +40,51 @@ export function updateBufferBinding(uniformBlock: IUniformBlockInfo, uniformData
console.assert(uniformData.bufferView.byteLength === size, `uniformData.bufferView 统一块数据提供数据尺寸不对!`);
}
+ //
const buffer = getIGLBuffer(uniformData.bufferView);
- (buffer as any).label = buffer.label || (`BufferBinding ${uniformBlock.name}`);
+ (buffer as any).label = buffer.label || (`BufferBinding ${bufferBindingInfo.name}`);
const offset = uniformData.bufferView.byteOffset;
- let currentSize = 0;
- let structName: string;
- uniformBlock.uniforms.forEach((uniformInfo) =>
+ //
+ bufferBindingInfo.items.forEach((v) =>
{
- const uniformBufferType = uniformInfo.type as IGLUniformBufferType;
- const alignSize = uniformBufferTypeAlignSizeMap[uniformBufferType];
- console.assert(alignSize, `没有找到 ${uniformBufferType} 统一缓冲类型对应的对齐与尺寸。`);
-
- //
- const currentstructName = uniformInfo.name.substring(0, uniformInfo.name.lastIndexOf("."));
- if (structName !== currentstructName)
- {
- currentSize = roundUp(16, currentSize); // 结构体之间对齐
- structName = currentstructName;
- }
-
- //
- uniformInfo.items.forEach((itemInfo) =>
+ const { paths, offset: itemInfoOffset, size: itemInfoSize, Cls } = v;
+ const update = () =>
{
- currentSize = roundUp(alignSize.align, currentSize); // 结构体成员对齐
- const itemInfoOffset = currentSize;
- const itemInfoSize = alignSize.size;
- //
- currentSize += alignSize.size;
- const Cls = alignSize.clsType;
- //
- const paths = itemInfo.paths.slice(1);
- const update = () =>
+ let value: any = uniformData;
+ for (let i = 0; i < paths.length; i++)
{
- let value: any = uniformData;
- for (let i = 0; i < paths.length; i++)
+ value = value[paths[i]];
+ if (value === undefined)
{
- value = value[paths[i]];
- if (value === undefined)
+ if (!hasDefautValue)
{
- if (!hasDefautValue)
- {
- console.warn(`没有找到 统一块变量属性 ${paths.join(".")} 的值!`);
- }
- return;
+ console.warn(`没有找到 统一块变量属性 ${paths.join(".")} 的值!`);
}
+ return;
}
-
- let data: Float32Array | Int32Array | Uint32Array;
- if (typeof value === "number")
- {
- data = new Cls([value]);
- }
- else if (value.constructor.name !== Cls.name)
- {
- data = new Cls(value as ArrayLike);
- }
- else
- {
- data = value as any;
- }
-
- const writeBuffers = buffer.writeBuffers ?? [];
- writeBuffers.push({ data: data.buffer, bufferOffset: offset + itemInfoOffset, size: Math.min(itemInfoSize, data.byteLength) });
- buffer.writeBuffers = writeBuffers;
}
- update();
- watcher.watchchain(uniformData, paths.join("."), update, undefined, false);
- });
- });
- currentSize = roundUp(16, currentSize); // 整个统一块数据对齐
+ let data: Float32Array | Int32Array | Uint32Array;
+ if (typeof value === "number")
+ {
+ data = new Cls([value]);
+ }
+ else if (value.constructor.name !== Cls.name)
+ {
+ data = new Cls(value as ArrayLike);
+ }
+ else
+ {
+ data = value as any;
+ }
- console.assert(size === currentSize, `uniformBlock映射尺寸出现错误( ${size} ${currentSize} )!`);
-}
+ const writeBuffers = buffer.writeBuffers ?? [];
+ writeBuffers.push({ data: data.buffer, bufferOffset: offset + itemInfoOffset, size: Math.min(itemInfoSize, data.byteLength) });
+ buffer.writeBuffers = writeBuffers;
+ }
-function roundUp(k: number, n: number): number
-{
- return Math.ceil(n / k) * k;
+ update();
+ watcher.watchchain(uniformData, paths.join("."), update, undefined, false);
+ });
}
-
-/**
- *
- * @see https://github.com/brendan-duncan/wgsl_reflect/blob/main/src/wgsl_reflect.ts#L1206
- * @see https://www.orillusion.com/zh/wgsl.html#memory-layouts
- */
-const uniformBufferTypeAlignSizeMap: {
- [key: string]: {
- align: number,
- size: number,
- clsType: Float32ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor,
- }
-} = {
- "FLOAT": { align: 4, size: 4, clsType: Float32Array },
- "FLOAT_VEC2": { align: 8, size: 8, clsType: Float32Array },
- "FLOAT_VEC3": { align: 16, size: 12, clsType: Float32Array },
- "FLOAT_VEC4": { align: 16, size: 16, clsType: Float32Array },
- "INT": { align: 4, size: 4, clsType: Int32Array },
- "INT_VEC2": { align: 8, size: 8, clsType: Int32Array },
- "INT_VEC3": { align: 16, size: 12, clsType: Int32Array },
- "INT_VEC4": { align: 16, size: 16, clsType: Int32Array },
- "BOOL": { align: 4, size: 4, clsType: Int32Array },
- "BOOL_VEC2": { align: 8, size: 8, clsType: Int32Array },
- "BOOL_VEC3": { align: 16, size: 12, clsType: Int32Array },
- "BOOL_VEC4": { align: 16, size: 16, clsType: Int32Array },
- "FLOAT_MAT2": { align: 8, size: 16, clsType: Float32Array },
- "FLOAT_MAT3": { align: 16, size: 48, clsType: Float32Array },
- "FLOAT_MAT4": { align: 16, size: 64, clsType: Float32Array },
- "UNSIGNED_INT": { align: 4, size: 4, clsType: Uint32Array },
- "UNSIGNED_INT_VEC2": { align: 8, size: 8, clsType: Uint32Array },
- "UNSIGNED_INT_VEC3": { align: 16, size: 12, clsType: Uint32Array },
- "UNSIGNED_INT_VEC4": { align: 16, size: 16, clsType: Uint32Array },
- "FLOAT_MAT2x3": { align: 16, size: 32, clsType: Float32Array },
- "FLOAT_MAT2x4": { align: 16, size: 32, clsType: Float32Array },
- "FLOAT_MAT3x2": { align: 8, size: 24, clsType: Float32Array },
- "FLOAT_MAT3x4": { align: 16, size: 48, clsType: Float32Array },
- "FLOAT_MAT4x2": { align: 8, size: 32, clsType: Float32Array },
- "FLOAT_MAT4x3": { align: 16, size: 64, clsType: Float32Array },
-};
\ No newline at end of file
--
Gitee
From 802b58f565e08c1cf1439f91c38ee88b6797ea28 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Wed, 8 Jan 2025 23:02:11 +0800
Subject: [PATCH 183/186] updateBufferBinding
IUniformBlockInfo.bufferBindingInfo
---
src/RunWebGL.ts | 3 ++-
src/caches/getGLProgram.ts | 2 --
src/utils/updateBufferBinding.ts | 4 +---
3 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 9e3c651..3c3a566 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,4 +1,4 @@
-import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICopyBufferToBuffer, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IUniforms, IVertexAttribute, IVertexAttributes, IViewport, TypedArray } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICopyBufferToBuffer, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IUniforms, IVertexAttribute, IVertexAttributes, IViewport, TypedArray, UnReadonly } from "@feng3d/render-api";
import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLFramebuffer } from "./caches/getGLFramebuffer";
@@ -371,6 +371,7 @@ export class RunWebGL
updateBufferBinding(uniformBlock.bufferBindingInfo, bufferBinding);
buffer = getIGLUniformBuffer(bufferBinding.bufferView);
}
+ (buffer as UnReadonly).label = buffer.label || (`UniformBuffer ${name}`);
//
const webGLBuffer = getGLBuffer(gl, buffer);
diff --git a/src/caches/getGLProgram.ts b/src/caches/getGLProgram.ts
index 7df5592..d15247b 100644
--- a/src/caches/getGLProgram.ts
+++ b/src/caches/getGLProgram.ts
@@ -306,7 +306,6 @@ export type ShaderType = "FRAGMENT_SHADER" | "VERTEX_SHADER";
*/
export interface IBufferBindingInfo
{
- name: string;
size: number;
items: {
paths: string[];
@@ -359,7 +358,6 @@ function getBufferBindingInfo(uniformBlock: IUniformBlockInfo): IBufferBindingIn
const bufferBindingInfo: IBufferBindingInfo = {
size: uniformBlock.dataSize,
- name: uniformBlock.name,
items,
};
diff --git a/src/utils/updateBufferBinding.ts b/src/utils/updateBufferBinding.ts
index 94d30b8..48b7a1f 100644
--- a/src/utils/updateBufferBinding.ts
+++ b/src/utils/updateBufferBinding.ts
@@ -16,8 +16,7 @@ export function updateBufferBinding(bufferBindingInfo: IBufferBindingInfo, unifo
if (uniformData["_bufferBindingInfo"] !== undefined)
{
const preVariableInfo = uniformData["_bufferBindingInfo"] as any as IBufferBindingInfo;
- if (preVariableInfo.name !== bufferBindingInfo.name
- || preVariableInfo.size !== bufferBindingInfo.size
+ if (preVariableInfo.size !== bufferBindingInfo.size
)
{
console.warn(`updateBufferBinding 出现一份数据对应多个 variableInfo`, { uniformData, bufferBindingInfo, preVariableInfo });
@@ -42,7 +41,6 @@ export function updateBufferBinding(bufferBindingInfo: IBufferBindingInfo, unifo
//
const buffer = getIGLBuffer(uniformData.bufferView);
- (buffer as any).label = buffer.label || (`BufferBinding ${bufferBindingInfo.name}`);
const offset = uniformData.bufferView.byteOffset;
//
--
Gitee
From 02375996d527e2e31915596de8f5079fdea27778 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Thu, 9 Jan 2025 23:12:42 +0800
Subject: [PATCH 184/186] "@feng3d/watcher": "^0.8.7"
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 7669550..8e7a922 100644
--- a/package.json
+++ b/package.json
@@ -62,6 +62,6 @@
"dependencies": {
"@feng3d/render-api": "0.0.1",
"@feng3d/serialization": "^0.8.1",
- "@feng3d/watcher": "^0.8.3"
+ "@feng3d/watcher": "^0.8.7"
}
}
\ No newline at end of file
--
Gitee
From 4373cbef82e308708bda8a24aab1d38c4bb7dd13 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 10 Jan 2025 14:55:53 +0800
Subject: [PATCH 185/186] 1
---
src/utils/updateBufferBinding.ts | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/utils/updateBufferBinding.ts b/src/utils/updateBufferBinding.ts
index 48b7a1f..f6f5cfb 100644
--- a/src/utils/updateBufferBinding.ts
+++ b/src/utils/updateBufferBinding.ts
@@ -16,8 +16,7 @@ export function updateBufferBinding(bufferBindingInfo: IBufferBindingInfo, unifo
if (uniformData["_bufferBindingInfo"] !== undefined)
{
const preVariableInfo = uniformData["_bufferBindingInfo"] as any as IBufferBindingInfo;
- if (preVariableInfo.size !== bufferBindingInfo.size
- )
+ if (preVariableInfo.size !== bufferBindingInfo.size)
{
console.warn(`updateBufferBinding 出现一份数据对应多个 variableInfo`, { uniformData, bufferBindingInfo, preVariableInfo });
}
--
Gitee
From bd3f5adcf085573b97530cb167123955cce6add3 Mon Sep 17 00:00:00 2001
From: feng <908087098@qq.com>
Date: Fri, 10 Jan 2025 15:43:55 +0800
Subject: [PATCH 186/186] IBufferBinding
---
src/RunWebGL.ts | 3 +--
src/data/IGLUniforms.ts | 26 ++------------------------
src/utils/updateBufferBinding.ts | 3 +--
3 files changed, 4 insertions(+), 28 deletions(-)
diff --git a/src/RunWebGL.ts b/src/RunWebGL.ts
index 3c3a566..051166b 100644
--- a/src/RunWebGL.ts
+++ b/src/RunWebGL.ts
@@ -1,4 +1,4 @@
-import { getBlendConstantColor, IBlendComponent, IColorTargetState, ICommandEncoder, ICopyBufferToBuffer, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IUniforms, IVertexAttribute, IVertexAttributes, IViewport, TypedArray, UnReadonly } from "@feng3d/render-api";
+import { getBlendConstantColor, IBlendComponent, IBufferBinding, IColorTargetState, ICommandEncoder, ICopyBufferToBuffer, ICopyTextureToTexture, ICullFace, IDepthStencilState, IDrawIndexed, IDrawVertex, IFrontFace, IIndicesDataTypes, IPrimitiveState, IRenderObject, IRenderPass, IRenderPassColorAttachment, IRenderPassDepthStencilAttachment, IRenderPassDescriptor, IRenderPassObject, IRenderPipeline, ISampler, IScissorRect, ISubmit, ITextureView, IUniforms, IVertexAttribute, IVertexAttributes, IViewport, TypedArray, UnReadonly } from "@feng3d/render-api";
import { getGLBuffer } from "./caches/getGLBuffer";
import { getGLFramebuffer } from "./caches/getGLFramebuffer";
@@ -22,7 +22,6 @@ import { IGLTextureTarget } from "./data/IGLTexture";
import { IGLTransformFeedback } from "./data/IGLTransformFeedback";
import { IGLTransformFeedbackObject, IGLTransformFeedbackPass, IGLTransformFeedbackPipeline } from "./data/IGLTransformFeedbackPass";
import { IUniformItemInfo } from "./data/IGLUniformInfo";
-import { IBufferBinding } from "./data/IGLUniforms";
import { getGLTexture } from "./internal";
import { getIGLIndexBuffer, getIGLUniformBuffer, getIGLVertexBuffer } from "./runs/getIGLBuffer";
import { getIGLBlendEquation, getIGLBlendFactor, IGLBlendEquation, IGLBlendFactor } from "./runs/runColorTargetStates";
diff --git a/src/data/IGLUniforms.ts b/src/data/IGLUniforms.ts
index de04cf0..a1bf151 100644
--- a/src/data/IGLUniforms.ts
+++ b/src/data/IGLUniforms.ts
@@ -1,33 +1,11 @@
-import { TypedArray } from "@feng3d/render-api";
+import { IUniformDataItem } from "@feng3d/render-api";
import { IGLSamplerTexture } from "./IGLSamplerTexture";
declare module "@feng3d/render-api"
{
export interface IUniformTypeMap
{
- /**
- * Uniform Block 数据
- * 统一块数据
- */
- IBufferBinding: IBufferBinding;
IGLSamplerTexture: IGLSamplerTexture;
- IGLUniformDataItem: IGLUniformDataItem;
+ IUniformDataItem: IUniformDataItem;
}
}
-
-export type IGLUniformDataItem = number | number[] | number[][] | TypedArray | TypedArray[];
-
-/**
- * 缓冲区绑定。
- */
-export interface IBufferBinding
-{
- [name: string]: IBufferBindingItem;
-
- /**
- * 如果未设置引擎将自动生成。
- */
- readonly bufferView?: TypedArray;
-}
-
-export type IBufferBindingItem = IGLUniformDataItem | { [key: string]: IBufferBindingItem };
\ No newline at end of file
diff --git a/src/utils/updateBufferBinding.ts b/src/utils/updateBufferBinding.ts
index f6f5cfb..f7cb79a 100644
--- a/src/utils/updateBufferBinding.ts
+++ b/src/utils/updateBufferBinding.ts
@@ -1,7 +1,6 @@
-import { UnReadonly } from "@feng3d/render-api";
+import { IBufferBinding, UnReadonly } from "@feng3d/render-api";
import { watcher } from "@feng3d/watcher";
import { IBufferBindingInfo } from "../caches/getGLProgram";
-import { IBufferBinding } from "../data/IGLUniforms";
import { getIGLBuffer } from "../runs/getIGLBuffer";
/**
--
Gitee