Printbed textures generated from svg files

This commit is contained in:
Enrico Turri committed 2019-02-20 15:23:23 +01:00
1 parent 0b0457186b
commit 11fc849b1a
16 files changed
+5124 -33

No files matched your search

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="710.08" height="596.69" viewBox="0 0 710.08 596.69"><title>MK2_bottom</title><line x1="0.71" y1="0.71" x2="0.71" y2="595.98" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="142.44" y1="0.71" x2="142.44" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="284.17" y1="0.71" x2="284.17" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="709.37" y1="581.81" x2="709.37" y2="0.71" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="14.25" y1="581.81" x2="709.37" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="0.71" y1="595.98" x2="709.37" y2="595.98" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="14.25" y1="440.08" x2="709.37" y2="440.08" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="14.25" y1="298.35" x2="709.37" y2="298.35" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="14.25" y1="156.61" x2="709.37" y2="156.61" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="14.25" y1="14.88" x2="709.37" y2="14.88" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="709.37" y1="0.71" x2="0.71" y2="0.71" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="425.91" y1="0.71" x2="425.91" y2="499.35" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="425.91" y1="522.54" x2="425.91" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="567.64" y1="0.71" x2="567.64" y2="499.35" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="567.64" y1="522.54" x2="567.64" y2="527.69" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="567.64" y1="548.31" x2="567.64" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="85.75" y1="0.71" x2="85.75" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="114.09" y1="0.71" x2="114.09" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="170.79" y1="0.71" x2="170.79" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="199.13" y1="0.71" x2="199.13" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="227.48" y1="0.71" x2="227.48" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="255.83" y1="0.71" x2="255.83" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="312.52" y1="0.71" x2="312.52" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="340.87" y1="0.71" x2="340.87" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="681.02" y1="0.71" x2="681.02" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="29.06" y1="0.71" x2="29.06" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="57.4" y1="0.71" x2="57.4" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="468.43" x2="709.37" y2="468.43" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="496.77" x2="709.37" y2="496.77" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="525.12" x2="709.37" y2="525.12" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="553.46" x2="709.37" y2="553.46" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="411.73" x2="709.37" y2="411.73" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="383.39" x2="709.37" y2="383.39" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="355.04" x2="709.37" y2="355.04" fill=Line truncated

After

Width:  |  Height:  |  Size: 61 KiB

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="710.08" height="596.69" viewBox="0 0 710.08 596.69"><title>MK3_bottom</title><line x1="0.71" y1="0.71" x2="0.71" y2="595.98" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="142.44" y1="0.71" x2="142.44" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="284.17" y1="0.71" x2="284.17" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="709.37" y1="581.81" x2="709.37" y2="0.71" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="14.25" y1="581.81" x2="709.37" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="0.71" y1="595.98" x2="709.37" y2="595.98" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="14.25" y1="440.08" x2="709.37" y2="440.08" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="14.25" y1="298.35" x2="709.37" y2="298.35" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="14.25" y1="156.61" x2="709.37" y2="156.61" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="14.25" y1="14.88" x2="709.37" y2="14.88" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="709.37" y1="0.71" x2="0.71" y2="0.71" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="425.91" y1="0.71" x2="425.91" y2="499.35" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="425.91" y1="522.54" x2="425.91" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="567.64" y1="0.71" x2="567.64" y2="499.35" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="567.64" y1="522.54" x2="567.64" y2="527.69" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="567.64" y1="548.31" x2="567.64" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.42"/><line x1="85.75" y1="0.71" x2="85.75" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="114.09" y1="0.71" x2="114.09" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="170.79" y1="0.71" x2="170.79" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="199.13" y1="0.71" x2="199.13" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="227.48" y1="0.71" x2="227.48" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="255.83" y1="0.71" x2="255.83" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="312.52" y1="0.71" x2="312.52" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="340.87" y1="0.71" x2="340.87" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="681.02" y1="0.71" x2="681.02" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="29.06" y1="0.71" x2="29.06" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="57.4" y1="0.71" x2="57.4" y2="581.81" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="468.43" x2="709.37" y2="468.43" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="496.77" x2="709.37" y2="496.77" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="525.12" x2="709.37" y2="525.12" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="553.46" x2="709.37" y2="553.46" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="411.73" x2="709.37" y2="411.73" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="383.39" x2="709.37" y2="383.39" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.37"/><line x1="14.25" y1="355.04" x2="709.37" y2="355.04" fill=Line truncated

After

Width:  |  Height:  |  Size: 61 KiB

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="337.32" height="187.09" viewBox="0 0 337.32 187.09"><title>SL1_Bottom</title><path d="M207.57,151.83h5.59a5.32,5.32,0,0,1,2.2.39,3.45,3.45,0,0,1,1.31,1,3.26,3.26,0,0,1,.63,1.28,5.57,5.57,0,0,1,.17,1.28,5.49,5.49,0,0,1-.17,1.27,3.25,3.25,0,0,1-.63,1.26,3.35,3.35,0,0,1-1.31,1,5.33,5.33,0,0,1-2.2.38h-3.37v4.86h-2.22Zm2.22,6H213a2.94,2.94,0,0,0,.76-.1,2.19,2.19,0,0,0,.72-.35,1.88,1.88,0,0,0,.53-.64,2.25,2.25,0,0,0,.2-1,2.57,2.57,0,0,0-.18-1,1.59,1.59,0,0,0-.47-.65,1.79,1.79,0,0,0-.7-.32,3.64,3.64,0,0,0-.83-.09h-3.28Z" transform="translate(0 0)" fill="#fff"/><path d="M219.4,151.83h6a4.72,4.72,0,0,1,3.14.9,3.17,3.17,0,0,1,1,2.52,3.66,3.66,0,0,1-.27,1.5,3.39,3.39,0,0,1-.62,1,2.58,2.58,0,0,1-.7.52,3.46,3.46,0,0,1-.51.21v0a1.91,1.91,0,0,1,.61.18,1.72,1.72,0,0,1,.62.45,2.62,2.62,0,0,1,.47.81,3.65,3.65,0,0,1,.18,1.24,11.48,11.48,0,0,0,.17,2,2.69,2.69,0,0,0,.52,1.3h-2.37a2,2,0,0,1-.3-.9c0-.33,0-.65,0-1a8.21,8.21,0,0,0-.11-1.5,2.61,2.61,0,0,0-.39-1,1.62,1.62,0,0,0-.77-.61,3.39,3.39,0,0,0-1.25-.19h-3.26v5.21H219.4Zm2.22,5.76h3.63a2.36,2.36,0,0,0,1.62-.5,2,2,0,0,0,.55-1.52,2.29,2.29,0,0,0-.18-1,1.4,1.4,0,0,0-.49-.6,1.79,1.79,0,0,0-.71-.28,4.39,4.39,0,0,0-.82-.07h-3.6Z" transform="translate(0 0)" fill="#fff"/><path d="M231.75,151.83H234v7.38q0,.63.06,1.29a3,3,0,0,0,.36,1.18,2.17,2.17,0,0,0,.89.86,3.44,3.44,0,0,0,1.67.34,3.51,3.51,0,0,0,1.68-.34,2.21,2.21,0,0,0,.88-.86,2.86,2.86,0,0,0,.36-1.18q.06-.66.06-1.29v-7.38h2.22v8.1a5.71,5.71,0,0,1-.37,2.13,4.13,4.13,0,0,1-1.06,1.52,4.3,4.3,0,0,1-1.64.91,7.71,7.71,0,0,1-4.26,0,4.45,4.45,0,0,1-1.64-.91,4.22,4.22,0,0,1-1-1.52,5.52,5.52,0,0,1-.37-2.13Z" transform="translate(0 0)" fill="#fff"/><path d="M246.15,160.27a2.89,2.89,0,0,0,.24,1.24,2.21,2.21,0,0,0,.7.84,2.83,2.83,0,0,0,1,.48,4.92,4.92,0,0,0,1.25.15,4.15,4.15,0,0,0,1.24-.16,2.59,2.59,0,0,0,.83-.44,1.57,1.57,0,0,0,.46-.61,1.72,1.72,0,0,0,.14-.7,1.54,1.54,0,0,0-.32-1.07,1.75,1.75,0,0,0-.72-.49,15.05,15.05,0,0,0-1.57-.47l-2.21-.58a4.76,4.76,0,0,1-1.36-.56,3.24,3.24,0,0,1-.86-.77,2.72,2.72,0,0,1-.45-.9,3.62,3.62,0,0,1-.13-1,3.27,3.27,0,0,1,.4-1.66,3.64,3.64,0,0,1,1.05-1.16,4.71,4.71,0,0,1,1.49-.68,6.48,6.48,0,0,1,1.69-.22,6.7,6.7,0,0,1,1.87.25,4.66,4.66,0,0,1,1.54.78,3.62,3.62,0,0,1,1.45,3h-2.22a2.17,2.17,0,0,0-.83-1.73,3.3,3.3,0,0,0-1.9-.5,3.68,3.68,0,0,0-.8.08,2.5,2.5,0,0,0-.74.26,1.53,1.53,0,0,0-.56.51A1.52,1.52,0,0,0,247,156a2.64,2.64,0,0,0,1.09.58l.56.15,1.09.29,1.18.31.83.22a3.88,3.88,0,0,1,1.08.53,3.55,3.55,0,0,1,.77.78,3.11,3.11,0,0,1,.46.93,3.4,3.4,0,0,1,.15,1,3.58,3.58,0,0,1-.43,1.82,3.76,3.76,0,0,1-1.15,1.23,5,5,0,0,1-1.61.7,7.62,7.62,0,0,1-1.85.22,7.92,7.92,0,0,1-2-.26,4.78,4.78,0,0,1-1.66-.82,3.88,3.88,0,0,1-1.14-1.41,4.71,4.71,0,0,1-.44-2Z" transform="translate(0 0)" fill="#fff"/><path d="M259.57,151.83h2.36l4.88,12.66h-2.38l-1.19-3.35h-5.05L257,164.49h-2.29Zm-.78,7.62h3.87l-1.9-5.44h-.05Z" transform="translate(0 0)" fill="#fff"/><path d="M274.4,160.27a2.74,2.74,0,0,0,.25,1.24,2.1,2.1,0,0,0,.69.84,2.83,2.83,0,0,0,1,.48,4.92,4.92,0,0,0,1.25.15,4.1,4.1,0,0,0,1.24-.16,2.59,2.59,0,0,0,.83-.44,1.48,1.48,0,0,0,.46-.61,1.73,1.73,0,0,0,.15-.7A1.49,1.49,0,0,0,280,160a1.75,1.75,0,0,0-.72-.49,14.35,14.35,0,0,0-1.57-.47l-2.21-.58a4.88,4.88,0,0,1-1.36-.56,3,3,0,0,1-.85-.77,2.57,2.57,0,0,1-.46-.9,3.62,3.62,0,0,1-.13-1,3.27,3.27,0,0,1,.4-1.66,3.64,3.64,0,0,1,1.05-1.16,4.71,4.71,0,0,1,1.49-.68,6.48,6.48,0,0,1,1.69-.22,6.7,6.7,0,0,1,1.87.25,4.57,4.57,0,0,1,1.54.78,3.68,3.68,0,0,1,1.06,1.26,3.79,3.79,0,0,1,.39,1.75h-2.22a2.17,2.17,0,0,0-.83-1.73,3.3,3.3,0,0,0-1.9-.5,3.68,3.68,0,0,0-.8.08,2.5,2.5,0,0,0-.74.26,1.61,1.61,0,0,0-.56.51,1.35,1.35,0,0,0-.22.8,1.38,1.38,0,0,0,.41,1,2.64,2.64,0,0,0,1.09.58l.56.15,1.09.29,1.18.31.83.22a3.88,3.88,0,0,1,1.08.53,3.55,3.55,0,0,1,.77.78,3.11,3.11,0,0,1,.46.93,3.4,3.4,0,0,1,.15,1,3.58,3.58,0,0,1-.43,1.82,3.66,3.66,0,0,1-1.15,1.23,5,5,0,0,1-1.61.7,7.59,7.59,0,0,1-1.84.22,7.8,7.8,0,0,1-2-.26,4.74,4.74,0,0,1-1.67-.82,4,4,0,0,1-1.14-1.41,4.71,4.71,0,0,1-.44-2Z" transform="translate(0 0)" fill="#fff"/><path d="M284.43,151.83h2.22v10.75h6.44v1.91h-8.66Z" transform="translate(0 0)" fill="#fff"/><path d="M294.21,154.13a7.24,7.24,0,0,0,1.24-.1,3.78,3.78,0,0,0,1.09-.36,2.6,2.6,0,0,0,.83-.64,2,2,0,0,0,.46-.95h1.64v12.41h-2.21v-8.76h-3.05Z" transform="translate(0 0)" fill="#fff"/><path d="M211.49,140.53a4,4,0,0,1,3.14,1.38,4.72,4.72,0,0,1,.84,1.49,5.55,5.55,0,0,1,.29,1.79,5.63,5.63,0,0,1-.29,1.81,4.72,4.72,0,0,1-.84,1.49,4,4,0,0,1-1.35,1,4.09,4.09,0,0,1-1.79.37,4.15,4.15,0,0,1-1.79-.37,4,4,0,0,1-1.34-1,4.72,4.72,0,0,1-.84-1.49,5.63,5.63,0,0,1-.29-1.81,5.55,5.55,0,0,1,.29-1.79,4.72,4.72,0,0,1,.84-1.49,4,4,0,0,1,3.13-1.38Zm0,1.27a2.54,2.54,0,0,0-1.23.29,2.45,2.45,0,0,0-.84.76,3.9,3.9,0,0,0-.48,1.1,5.13,5.13,0,0,0-.15,1.24,5.22,5.22,0,0,0,.15,1.25,3.72,3.72,0,0,0,.48,1.09,2.48,2.48,0,0,0,.84.77,2.54,2.54,0,0,0,1.23.29,2.49,2.49,0,0,0,1.23-.29,2.31,2.31,0,0,0,.84-.77,3.49,3.49,0,0,0,.49-1.09,5.22,5.22,0,0,0,.15-1.25,5.13,5.13,0,0,0-.15-1.24,3.66,3.66,0,0,0-.49-1.1,2.28,Line truncated

After

Width:  |  Height:  |  Size: 9.2 KiB

+20
View File
@@ -0,0 +1,20 @@
#version 110
const vec3 back_color_dark = vec3(0.235, 0.235, 0.235);
const vec3 back_color_light = vec3(0.365, 0.365, 0.365);
uniform sampler2D texture;
uniform bool transparent_background;
varying vec2 tex_coords;
void main()
{
// calculates radial gradient
vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coords.xy) - vec2(0.5)))));
vec4 fore_color = texture2D(texture, tex_coords);
// blends foreground with background
gl_FragColor = vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0);
}
+11
View File
@@ -0,0 +1,11 @@
#version 110
attribute vec2 v_tex_coords;
varying vec2 tex_coords;
void main()
{
gl_Position = ftransform();
tex_coords = v_tex_coords;
}
+8
View File
@@ -51,4 +51,12 @@
#define ENABLE_MODE_AWARE_TOOLBAR_ITEMS (1 && ENABLE_1_42_0_ALPHA5)
//====================
// 1.42.0.alpha7 techs
//====================
#define ENABLE_1_42_0_ALPHA7 1
// Printbed textures generated from svg files
#define ENABLE_TEXTURES_FROM_SVG (1 && ENABLE_1_42_0_ALPHA7)
#endif // _technologies_h_
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+287 -2
View File
@@ -20,6 +20,67 @@ namespace GUI {
bool GeometryBuffer::set_from_triangles(const Polygons& triangles, float z, bool generate_tex_coords)
{
#if ENABLE_TEXTURES_FROM_SVG
m_vertices.clear();
unsigned int v_size = 3 * (unsigned int)triangles.size();
if (v_size == 0)
return false;
m_vertices = std::vector<Vertex>(v_size, Vertex());
float min_x = unscale<float>(triangles[0].points[0](0));
float min_y = unscale<float>(triangles[0].points[0](1));
float max_x = min_x;
float max_y = min_y;
unsigned int v_count = 0;
for (const Polygon& t : triangles)
{
for (unsigned int i = 0; i < 3; ++i)
{
Vertex& v = m_vertices[v_count];
const Point& p = t.points[i];
float x = unscale<float>(p(0));
float y = unscale<float>(p(1));
v.position[0] = x;
v.position[1] = y;
v.position[2] = z;
if (generate_tex_coords)
{
v.tex_coords[0] = x;
v.tex_coords[1] = y;
min_x = std::min(min_x, x);
max_x = std::max(max_x, x);
min_y = std::min(min_y, y);
max_y = std::max(max_y, y);
}
++v_count;
}
}
if (generate_tex_coords)
{
float size_x = max_x - min_x;
float size_y = max_y - min_y;
if ((size_x != 0.0f) && (size_y != 0.0f))
{
float inv_size_x = 1.0f / size_x;
float inv_size_y = -1.0f / size_y;
for (Vertex& v : m_vertices)
{
v.tex_coords[0] = (v.tex_coords[0] - min_x) * inv_size_x;
v.tex_coords[1] = (v.tex_coords[1] - min_y) * inv_size_y;
}
}
}
#else
m_vertices.clear();
m_tex_coords.clear();
@@ -80,12 +141,38 @@ bool GeometryBuffer::set_from_triangles(const Polygons& triangles, float z, bool
}
}
}
#endif // ENABLE_TEXTURES_FROM_SVG
return true;
}
bool GeometryBuffer::set_from_lines(const Lines& lines, float z)
{
#if ENABLE_TEXTURES_FROM_SVG
m_vertices.clear();
unsigned int v_size = 2 * (unsigned int)lines.size();
if (v_size == 0)
return false;
m_vertices = std::vector<Vertex>(v_size, Vertex());
unsigned int v_count = 0;
for (const Line& l : lines)
{
Vertex& v1 = m_vertices[v_count];
v1.position[0] = unscale<float>(l.a(0));
v1.position[1] = unscale<float>(l.a(1));
v1.position[2] = z;
++v_count;
Vertex& v2 = m_vertices[v_count];
v2.position[0] = unscale<float>(l.b(0));
v2.position[1] = unscale<float>(l.b(1));
v2.position[2] = z;
++v_count;
}
#else
m_vertices.clear();
m_tex_coords.clear();
@@ -105,10 +192,18 @@ bool GeometryBuffer::set_from_lines(const Lines& lines, float z)
m_vertices[coord++] = unscale<float>(l.b(1));
m_vertices[coord++] = z;
}
#endif // ENABLE_TEXTURES_FROM_SVG
return true;
}
#if ENABLE_TEXTURES_FROM_SVG
const float* GeometryBuffer::get_vertices_data() const
{
return (m_vertices.size() > 0) ? (const float*)m_vertices.data() : nullptr;
}
#endif // ENABLE_TEXTURES_FROM_SVG
const double Bed3D::Axes::Radius = 0.5;
const double Bed3D::Axes::ArrowBaseRadius = 2.5 * Bed3D::Axes::Radius;
const double Bed3D::Axes::ArrowLength = 5.0;
@@ -176,8 +271,11 @@ void Bed3D::Axes::render_axis(double length) const
}
Bed3D::Bed3D()
: m_type(Custom)
, m_scale_factor(1.0f)
: m_type(Custom)
#if ENABLE_TEXTURES_FROM_SVG
, m_vbo_id(0)
#endif // ENABLE_TEXTURES_FROM_SVG
, m_scale_factor(1.0f)
{
}
@@ -206,6 +304,10 @@ bool Bed3D::set_shape(const Pointfs& shape)
m_polygon = offset_ex(poly.contour, (float)bed_bbox.radius() * 1.7f, jtRound, scale_(0.5))[0].contour;
#if ENABLE_TEXTURES_FROM_SVG
reset();
#endif // ENABLE_TEXTURES_FROM_SVG
// Set the origin and size for painting of the coordinate system axes.
m_axes.origin = Vec3d(0.0, 0.0, (double)GROUND_Z);
m_axes.length = 0.1 * get_bounding_box().max_size() * Vec3d::Ones();
@@ -224,6 +326,39 @@ Point Bed3D::point_projection(const Point& point) const
return m_polygon.point_projection(point);
}
#if ENABLE_TEXTURES_FROM_SVG
void Bed3D::render(float theta, bool useVBOs, float scale_factor) const
{
m_scale_factor = scale_factor;
EType type = useVBOs ? m_type : Custom;
switch (type)
{
case MK2:
{
render_prusa("mk2", theta > 90.0f);
break;
}
case MK3:
{
render_prusa("mk3", theta > 90.0f);
break;
}
case SL1:
{
render_prusa("sl1", theta > 90.0f);
break;
}
default:
case Custom:
{
render_custom();
break;
}
}
}
#else
void Bed3D::render(float theta, bool useVBOs, float scale_factor) const
{
m_scale_factor = scale_factor;
@@ -256,6 +391,7 @@ void Bed3D::render(float theta, bool useVBOs, float scale_factor) const
}
}
}
#endif // ENABLE_TEXTURES_FROM_SVG
void Bed3D::render_axes() const
{
@@ -349,6 +485,131 @@ Bed3D::EType Bed3D::detect_type(const Pointfs& shape) const
return type;
}
#if ENABLE_TEXTURES_FROM_SVG
void Bed3D::render_prusa(const std::string &key, bool bottom) const
{
std::string tex_path = resources_dir() + "/icons/bed/" + key;
std::string model_path = resources_dir() + "/models/" + key;
// use anisotropic filter if graphic card allows
GLfloat max_anisotropy = 0.0f;
if (glewIsSupported("GL_EXT_texture_filter_anisotropic"))
::glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy);
// use higher resolution images if graphic card allows
GLint max_tex_size;
::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size);
// clamp or the texture generation becomes too slow
max_tex_size = std::min(max_tex_size, 8192);
std::string filename = tex_path + ".svg";
if ((m_texture.get_id() == 0) || (m_texture.get_source() != filename))
{
if (!m_texture.load_from_svg_file(filename, true, max_tex_size))
{
render_custom();
return;
}
if (max_anisotropy > 0.0f)
{
::glBindTexture(GL_TEXTURE_2D, m_texture.get_id());
::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
::glBindTexture(GL_TEXTURE_2D, 0);
}
}
if (!bottom)
{
filename = model_path + "_bed.stl";
if ((m_model.get_filename() != filename) && m_model.init_from_file(filename, true)) {
Vec3d offset = m_bounding_box.center() - Vec3d(0.0, 0.0, 0.5 * m_model.get_bounding_box().size()(2));
if (key == "mk2")
// hardcoded value to match the stl model
offset += Vec3d(0.0, 7.5, -0.03);
else if (key == "mk3")
// hardcoded value to match the stl model
offset += Vec3d(0.0, 5.5, 2.43);
else if (key == "sl1")
// hardcoded value to match the stl model
offset += Vec3d(0.0, 0.0, -0.03);
m_model.center_around(offset);
}
if (!m_model.get_filename().empty())
{
::glEnable(GL_LIGHTING);
m_model.render();
::glDisable(GL_LIGHTING);
}
}
unsigned int triangles_vcount = m_triangles.get_vertices_count();
if (triangles_vcount > 0)
{
if (m_vbo_id == 0)
{
::glGenBuffers(1, &m_vbo_id);
::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id);
::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)m_triangles.get_vertices_data_size(), (const GLvoid*)m_triangles.get_vertices_data(), GL_STATIC_DRAW);
::glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_position_offset());
::glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_tex_coords_offset());
::glBindBuffer(GL_ARRAY_BUFFER, 0);
}
::glEnable(GL_DEPTH_TEST);
::glDepthMask(GL_FALSE);
::glEnable(GL_BLEND);
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
::glEnable(GL_TEXTURE_2D);
::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
if (bottom)
::glFrontFace(GL_CW);
render_prusa_shader(triangles_vcount, bottom);
if (bottom)
::glFrontFace(GL_CCW);
::glDisable(GL_TEXTURE_2D);
::glDisable(GL_BLEND);
::glDepthMask(GL_TRUE);
}
}
void Bed3D::render_prusa_shader(unsigned int vertices_count, bool transparent) const
{
if (m_shader.get_shader_program_id() == 0)
m_shader.init("printbed.vs", "printbed.fs");
if (m_shader.is_initialized())
{
m_shader.start_using();
m_shader.set_uniform("transparent_background", transparent);
::glBindTexture(GL_TEXTURE_2D, (GLuint)m_texture.get_id());
::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id);
::glEnableVertexAttribArray(0);
::glEnableVertexAttribArray(1);
::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices_count);
::glDisableVertexAttribArray(1);
::glDisableVertexAttribArray(0);
::glBindBuffer(GL_ARRAY_BUFFER, 0);
::glBindTexture(GL_TEXTURE_2D, 0);
m_shader.stop_using();
}
}
#else
void Bed3D::render_prusa(const std::string &key, float theta, bool useVBOs) const
{
std::string tex_path = resources_dir() + "/icons/bed/" + key;
@@ -468,11 +729,16 @@ void Bed3D::render_prusa(const std::string &key, float theta, bool useVBOs) cons
glsafe(::glDepthMask(GL_TRUE));
}
}
#endif // ENABLE_TEXTURES_FROM_SVG
void Bed3D::render_custom() const
{
#if ENABLE_TEXTURES_FROM_SVG
m_texture.reset();
#else
m_top_texture.reset();
m_bottom_texture.reset();
#endif // ENABLE_TEXTURES_FROM_SVG
unsigned int triangles_vcount = m_triangles.get_vertices_count();
if (triangles_vcount > 0)
@@ -487,7 +753,11 @@ void Bed3D::render_custom() const
glsafe(::glColor4f(0.35f, 0.35f, 0.35f, 0.4f));
glsafe(::glNormal3d(0.0f, 0.0f, 1.0f));
#if ENABLE_TEXTURES_FROM_SVG
::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_vertices_data());
#else
glsafe(::glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)m_triangles.get_vertices()));
#endif // ENABLE_TEXTURES_FROM_SVG
glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount));
// draw grid
@@ -497,7 +767,11 @@ void Bed3D::render_custom() const
glsafe(::glEnable(GL_DEPTH_TEST));
glsafe(::glLineWidth(3.0f * m_scale_factor));
glsafe(::glColor4f(0.2f, 0.2f, 0.2f, 0.4f));
#if ENABLE_TEXTURES_FROM_SVG
::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data());
#else
glsafe(::glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)m_gridlines.get_vertices()));
#endif // ENABLE_TEXTURES_FROM_SVG
glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)gridlines_vcount));
glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
@@ -507,5 +781,16 @@ void Bed3D::render_custom() const
}
}
#if ENABLE_TEXTURES_FROM_SVG
void Bed3D::reset()
{
if (m_vbo_id > 0)
{
::glDeleteBuffers(1, &m_vbo_id);
m_vbo_id = 0;
}
}
#endif // ENABLE_TEXTURES_FROM_SVG
} // GUI
} // Slic3r
+45 -1
View File
@@ -3,6 +3,9 @@
#include "GLTexture.hpp"
#include "3DScene.hpp"
#if ENABLE_TEXTURES_FROM_SVG
#include "GLShader.hpp"
#endif // ENABLE_TEXTURES_FROM_SVG
class GLUquadric;
typedef class GLUquadric GLUquadricObj;
@@ -12,17 +15,41 @@ namespace GUI {
class GeometryBuffer
{
#if ENABLE_TEXTURES_FROM_SVG
struct Vertex
{
float position[3];
float tex_coords[2];
Vertex()
{
position[0] = 0.0f; position[1] = 0.0f; position[2] = 0.0f;
tex_coords[0] = 0.0f; tex_coords[1] = 0.0f;
}
};
std::vector<Vertex> m_vertices;
#else
std::vector<float> m_vertices;
std::vector<float> m_tex_coords;
#endif // ENABLE_TEXTURES_FROM_SVG
public:
bool set_from_triangles(const Polygons& triangles, float z, bool generate_tex_coords);
bool set_from_lines(const Lines& lines, float z);
#if ENABLE_TEXTURES_FROM_SVG
const float* get_vertices_data() const;
unsigned int get_vertices_data_size() const { return (unsigned int)m_vertices.size() * get_vertex_data_size(); }
unsigned int get_vertex_data_size() const { return (unsigned int)(5 * sizeof(float)); }
unsigned int get_position_offset() const { return 0; }
unsigned int get_tex_coords_offset() const { return (unsigned int)(3 * sizeof(float)); }
unsigned int get_vertices_count() const { return (unsigned int)m_vertices.size(); }
#else
const float* get_vertices() const { return m_vertices.data(); }
const float* get_tex_coords() const { return m_tex_coords.data(); }
unsigned int get_vertices_count() const { return (unsigned int)m_vertices.size() / 3; }
#endif // ENABLE_TEXTURES_FROM_SVG
};
class Bed3D
@@ -62,8 +89,14 @@ private:
Polygon m_polygon;
GeometryBuffer m_triangles;
GeometryBuffer m_gridlines;
#if ENABLE_TEXTURES_FROM_SVG
mutable GLTexture m_texture;
mutable Shader m_shader;
mutable unsigned int m_vbo_id;
#else
mutable GLTexture m_top_texture;
mutable GLTexture m_bottom_texture;
#endif // ENABLE_TEXTURES_FROM_SVG
mutable GLBed m_model;
Axes m_axes;
@@ -71,6 +104,9 @@ private:
public:
Bed3D();
#if ENABLE_TEXTURES_FROM_SVG
~Bed3D() { reset(); }
#endif // ENABLE_TEXTURES_FROM_SVG
EType get_type() const { return m_type; }
@@ -93,8 +129,16 @@ private:
void calc_triangles(const ExPolygon& poly);
void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox);
EType detect_type(const Pointfs& shape) const;
#if ENABLE_TEXTURES_FROM_SVG
void render_prusa(const std::string& key, bool bottom) const;
void render_prusa_shader(unsigned int vertices_count, bool transparent) const;
#else
void render_prusa(const std::string &key, float theta, bool useVBOs) const;
#endif // ENABLE_TEXTURES_FROM_SVG
void render_custom() const;
#if ENABLE_TEXTURES_FROM_SVG
void reset();
#endif // ENABLE_TEXTURES_FROM_SVG
};
} // GUI
+2
View File
@@ -238,6 +238,7 @@ void GLCanvas3D::Camera::set_scene_box(const BoundingBoxf3& box, GLCanvas3D& can
}
}
#if !ENABLE_TEXTURES_FROM_SVG
GLCanvas3D::Shader::Shader()
: m_shader(nullptr)
{
@@ -316,6 +317,7 @@ void GLCanvas3D::Shader::_reset()
m_shader = nullptr;
}
}
#endif // !ENABLE_TEXTURES_FROM_SVG
GLCanvas3D::LayersEditing::LayersEditing()
: m_use_legacy_opengl(false)
+2
View File
@@ -192,6 +192,7 @@ class GLCanvas3D
void set_scene_box(const BoundingBoxf3& box, GLCanvas3D& canvas);
};
#if !ENABLE_TEXTURES_FROM_SVG
class Shader
{
GLShader* m_shader;
@@ -215,6 +216,7 @@ class GLCanvas3D
private:
void _reset();
};
#endif // !ENABLE_TEXTURES_FROM_SVG
class LayersEditing
{
+87
View File
@@ -253,4 +253,91 @@ sub SetMatrix
}
*/
#if ENABLE_TEXTURES_FROM_SVG
Shader::Shader()
: m_shader(nullptr)
{
}
Shader::~Shader()
{
reset();
}
bool Shader::init(const std::string& vertex_shader_filename, const std::string& fragment_shader_filename)
{
if (is_initialized())
return true;
m_shader = new GLShader();
if (m_shader != nullptr)
{
if (!m_shader->load_from_file(fragment_shader_filename.c_str(), vertex_shader_filename.c_str()))
{
std::cout << "Compilaton of shader failed:" << std::endl;
std::cout << m_shader->last_error << std::endl;
reset();
return false;
}
}
return true;
}
bool Shader::is_initialized() const
{
return (m_shader != nullptr);
}
bool Shader::start_using() const
{
if (is_initialized())
{
m_shader->enable();
return true;
}
else
return false;
}
void Shader::stop_using() const
{
if (m_shader != nullptr)
m_shader->disable();
}
void Shader::set_uniform(const std::string& name, float value) const
{
if (m_shader != nullptr)
m_shader->set_uniform(name.c_str(), value);
}
void Shader::set_uniform(const std::string& name, const float* matrix) const
{
if (m_shader != nullptr)
m_shader->set_uniform(name.c_str(), matrix);
}
void Shader::set_uniform(const std::string& name, bool value) const
{
if (m_shader != nullptr)
m_shader->set_uniform(name.c_str(), value);
}
unsigned int Shader::get_shader_program_id() const
{
return (m_shader != nullptr) ? m_shader->shader_program_id : 0;
}
void Shader::reset()
{
if (m_shader != nullptr)
{
m_shader->release();
delete m_shader;
m_shader = nullptr;
}
}
#endif // ENABLE_TEXTURES_FROM_SVG
} // namespace Slic3r
+28
View File
@@ -36,6 +36,34 @@ public:
std::string last_error;
};
#if ENABLE_TEXTURES_FROM_SVG
class Shader
{
GLShader* m_shader;
public:
Shader();
~Shader();
bool init(const std::string& vertex_shader_filename, const std::string& fragment_shader_filename);
bool is_initialized() const;
bool start_using() const;
void stop_using() const;
void set_uniform(const std::string& name, float value) const;
void set_uniform(const std::string& name, const float* matrix) const;
void set_uniform(const std::string& name, bool value) const;
const GLShader* get_shader() const { return m_shader; }
unsigned int get_shader_program_id() const;
private:
void reset();
};
#endif // ENABLE_TEXTURES_FROM_SVG
}
#endif /* slic3r_GLShader_hpp_ */
+190 -24
View File
@@ -1,3 +1,4 @@
#include "libslic3r/libslic3r.h"
#include "GLTexture.hpp"
#include <GL/glew.h>
@@ -5,10 +6,20 @@
#include <wx/image.h>
#include <boost/filesystem.hpp>
#if ENABLE_TEXTURES_FROM_SVG
#include <boost/algorithm/string/predicate.hpp>
#endif // ENABLE_TEXTURES_FROM_SVG
#include <vector>
#include <algorithm>
#if ENABLE_TEXTURES_FROM_SVG
#define NANOSVG_IMPLEMENTATION
#include "nanosvg/nanosvg.h"
#define NANOSVGRAST_IMPLEMENTATION
#include "nanosvg/nanosvgrast.h"
#endif // ENABLE_TEXTURES_FROM_SVG
namespace Slic3r {
namespace GUI {
@@ -27,7 +38,34 @@ GLTexture::~GLTexture()
reset();
}
bool GLTexture::load_from_file(const std::string& filename, bool generate_mipmaps)
#if ENABLE_TEXTURES_FROM_SVG
bool GLTexture::load_from_file(const std::string& filename, bool use_mipmaps)
{
reset();
if (!boost::filesystem::exists(filename))
return false;
if (boost::algorithm::iends_with(filename, ".png"))
return load_from_png(filename, use_mipmaps);
else
return false;
}
bool GLTexture::load_from_svg_file(const std::string& filename, bool use_mipmaps, unsigned int max_size_px)
{
reset();
if (!boost::filesystem::exists(filename))
return false;
if (boost::algorithm::iends_with(filename, ".svg"))
return load_from_svg(filename, use_mipmaps, max_size_px);
else
return false;
}
#else
bool GLTexture::load_from_file(const std::string& filename, bool use_mipmaps)
{
reset();
@@ -78,10 +116,10 @@ bool GLTexture::load_from_file(const std::string& filename, bool generate_mipmap
::glGenTextures(1, &m_id);
::glBindTexture(GL_TEXTURE_2D, m_id);
::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data());
if (generate_mipmaps)
if (use_mipmaps)
{
// we manually generate mipmaps because glGenerateMipmap() function is not reliable on all graphics cards
unsigned int levels_count = _generate_mipmaps(image);
unsigned int levels_count = generate_mipmaps(image);
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1 + levels_count);
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}
@@ -97,6 +135,7 @@ bool GLTexture::load_from_file(const std::string& filename, bool generate_mipmap
m_source = filename;
return true;
}
#endif // ENABLE_TEXTURES_FROM_SVG
void GLTexture::reset()
{
@@ -109,26 +148,6 @@ void GLTexture::reset()
m_source = "";
}
unsigned int GLTexture::get_id() const
{
return m_id;
}
int GLTexture::get_width() const
{
return m_width;
}
int GLTexture::get_height() const
{
return m_height;
}
const std::string& GLTexture::get_source() const
{
return m_source;
}
void GLTexture::render_texture(unsigned int tex_id, float left, float right, float bottom, float top)
{
render_sub_texture(tex_id, left, right, bottom, top, FullTextureUVs);
@@ -157,7 +176,7 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right,
::glDisable(GL_BLEND);
}
unsigned int GLTexture::_generate_mipmaps(wxImage& image)
unsigned int GLTexture::generate_mipmaps(wxImage& image)
{
int w = image.GetWidth();
int h = image.GetHeight();
@@ -195,5 +214,152 @@ unsigned int GLTexture::_generate_mipmaps(wxImage& image)
return (unsigned int)level;
}
#if ENABLE_TEXTURES_FROM_SVG
bool GLTexture::load_from_png(const std::string& filename, bool use_mipmaps)
{
// Load a PNG with an alpha channel.
wxImage image;
if (!image.LoadFile(wxString::FromUTF8(filename.c_str()), wxBITMAP_TYPE_PNG))
{
reset();
return false;
}
m_width = image.GetWidth();
m_height = image.GetHeight();
int n_pixels = m_width * m_height;
if (n_pixels <= 0)
{
reset();
return false;
}
// Get RGB & alpha raw data from wxImage, pack them into an array.
unsigned char* img_rgb = image.GetData();
if (img_rgb == nullptr)
{
reset();
return false;
}
unsigned char* img_alpha = image.GetAlpha();
std::vector<unsigned char> data(n_pixels * 4, 0);
for (int i = 0; i < n_pixels; ++i)
{
int data_id = i * 4;
int img_id = i * 3;
data[data_id + 0] = img_rgb[img_id + 0];
data[data_id + 1] = img_rgb[img_id + 1];
data[data_id + 2] = img_rgb[img_id + 2];
data[data_id + 3] = (img_alpha != nullptr) ? img_alpha[i] : 255;
}
// sends data to gpu
::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
::glGenTextures(1, &m_id);
::glBindTexture(GL_TEXTURE_2D, m_id);
::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data());
if (use_mipmaps)
{
// we manually generate mipmaps because glGenerateMipmap() function is not reliable on all graphics cards
unsigned int levels_count = generate_mipmaps(image);
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1 + levels_count);
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}
else
{
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
}
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
::glBindTexture(GL_TEXTURE_2D, 0);
m_source = filename;
return true;
}
bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, unsigned int max_size_px)
{
NSVGimage* image = nsvgParseFromFile(filename.c_str(), "px", 96.0f);
if (image == nullptr)
{
// printf("Could not open SVG image.\n");
reset();
return false;
}
float scale = (float)max_size_px / std::max(image->width, image->height);
m_width = (int)(scale * image->width);
m_height = (int)(scale * image->height);
int n_pixels = m_width * m_height;
if (n_pixels <= 0)
{
reset();
return false;
}
NSVGrasterizer* rast = nsvgCreateRasterizer();
if (rast == nullptr)
{
// printf("Could not init rasterizer.\n");
nsvgDelete(image);
reset();
return false;
}
// creates the temporary buffer only once, with max size, and reuse it for all the levels, if generating mipmaps
std::vector<unsigned char> data(n_pixels * 4, 0);
nsvgRasterize(rast, image, 0, 0, scale, data.data(), m_width, m_height, m_width * 4);
// sends data to gpu
::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
::glGenTextures(1, &m_id);
::glBindTexture(GL_TEXTURE_2D, m_id);
::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data());
if (use_mipmaps)
{
// we manually generate mipmaps because glGenerateMipmap() function is not reliable on all graphics cards
int lod_w = m_width;
int lod_h = m_height;
GLint level = 0;
while ((lod_w > 1) || (lod_h > 1))
{
++level;
lod_w = std::max(lod_w / 2, 1);
lod_h = std::max(lod_h / 2, 1);
scale /= 2.0f;
nsvgRasterize(rast, image, 0, 0, scale, data.data(), lod_w, lod_h, lod_w * 4);
::glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, (GLsizei)lod_w, (GLsizei)lod_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data());
}
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1 + level);
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}
else
{
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
}
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
::glBindTexture(GL_TEXTURE_2D, 0);
m_source = filename;
nsvgDeleteRasterizer(rast);
nsvgDelete(image);
return true;
}
#endif // ENABLE_TEXTURES_FROM_SVG
} // namespace GUI
} // namespace Slic3r
+14 -6
View File
@@ -37,20 +37,28 @@ namespace GUI {
GLTexture();
virtual ~GLTexture();
bool load_from_file(const std::string& filename, bool generate_mipmaps);
bool load_from_file(const std::string& filename, bool use_mipmaps);
#if ENABLE_TEXTURES_FROM_SVG
bool load_from_svg_file(const std::string& filename, bool use_mipmaps, unsigned int max_size_px);
#endif // ENABLE_TEXTURES_FROM_SVG
void reset();
unsigned int get_id() const;
int get_width() const;
int get_height() const;
unsigned int get_id() const { return m_id; }
int get_width() const { return m_width; }
int get_height() const { return m_height; }
const std::string& get_source() const;
const std::string& get_source() const { return m_source; }
static void render_texture(unsigned int tex_id, float left, float right, float bottom, float top);
static void render_sub_texture(unsigned int tex_id, float left, float right, float bottom, float top, const Quad_UVs& uvs);
protected:
unsigned int _generate_mipmaps(wxImage& image);
unsigned int generate_mipmaps(wxImage& image);
#if ENABLE_TEXTURES_FROM_SVG
private:
bool load_from_png(const std::string& filename, bool use_mipmaps);
bool load_from_svg(const std::string& filename, bool use_mipmaps, unsigned int max_size_px);
#endif // ENABLE_TEXTURES_FROM_SVG
};
} // namespace GUI