Merge remote-tracking branch 'origin/master' into ys_cut

This commit is contained in:
YuSanka 2022-03-11 15:58:14 +01:00
commit e5b10ae289
85 changed files with 5320 additions and 1851 deletions

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 25.2.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="50 0 228 330" style="enable-background:new 50 0 228 330;" xml:space="preserve">
<style type="text/css">
.st0{display:none;}
.st1{fill:none;stroke:#ED6B21;stroke-width:17.0079;stroke-linecap:round;stroke-miterlimit:10;}
</style>
<path id="XMLID_28_" class="st0" d="M180,315V51.2l49.4,49.4c5.9,5.9,15.4,5.9,21.2,0c5.9-5.9,5.9-15.4,0-21.2l-75-75
c-5.9-5.9-15.4-5.9-21.2,0l-75,75C76.5,82.3,75,86.2,75,90s1.5,7.7,4.4,10.6c5.9,5.9,15.4,5.9,21.2,0L150,51.2V315
c0,8.3,6.7,15,15,15S180,323.3,180,315z"
style="fill:#ed6b21;"/>
<g id="XMLID_1_">
<g>
</g>
<g>
<polyline class="st1" points="113.3,84.5 164,18.3 164,18.3 "/>
<polyline class="st1" points="216.1,84.5 164,18.3 164,18.3 "/>
</g>
</g>
<line class="st1" x1="164" y1="263.3" x2="164" y2="18.3"/>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-02-09 09:04+0100\n" "POT-Creation-Date: 2022-02-09 09:04+0100\n"
"PO-Revision-Date: 2021-12-16 18:50+0100\n" "PO-Revision-Date: 2022-03-04 17:01+0100\n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"Language: ca\n" "Language: ca\n"
@ -90,7 +90,7 @@ msgstr ""
#: src/slic3r/GUI/BackgroundSlicingProcess.cpp:84 #: src/slic3r/GUI/BackgroundSlicingProcess.cpp:84
#, boost-format #, boost-format
msgid "PrusaSlicer has encountered a fatal error: \"%1%\"" msgid "PrusaSlicer has encountered a fatal error: \"%1%\""
msgstr "" msgstr "PrusaSlicer ha trobat un error crític: \"%1%\""
#: src/slic3r/GUI/BackgroundSlicingProcess.cpp:85 #: src/slic3r/GUI/BackgroundSlicingProcess.cpp:85
msgid "" msgid ""
@ -1887,7 +1887,7 @@ msgstr "Imatge del firmware:"
#: src/slic3r/GUI/FirmwareDialog.cpp:813 #: src/slic3r/GUI/FirmwareDialog.cpp:813
msgid "Select a file" msgid "Select a file"
msgstr "" msgstr "Seleccioneu un fitxer"
#: src/slic3r/GUI/FirmwareDialog.cpp:815 #: src/slic3r/GUI/FirmwareDialog.cpp:815
#: src/slic3r/GUI/PhysicalPrinterDialog.cpp:297 #: src/slic3r/GUI/PhysicalPrinterDialog.cpp:297
@ -3495,11 +3495,11 @@ msgstr "Preparant pestanyes de configuració"
#: src/slic3r/GUI/GUI_App.cpp:1334 src/slic3r/GUI/Preferences.cpp:287 #: src/slic3r/GUI/GUI_App.cpp:1334 src/slic3r/GUI/Preferences.cpp:287
msgid "Restore window position on start" msgid "Restore window position on start"
msgstr "" msgstr "Restaura la posició de la finestra a l'inici"
#: src/slic3r/GUI/GUI_App.cpp:1336 #: src/slic3r/GUI/GUI_App.cpp:1336
msgid "PrusaSlicer started after a crash" msgid "PrusaSlicer started after a crash"
msgstr "" msgstr "PrusaSlicer s'ha reiniciat després d'una fallada"
#: src/slic3r/GUI/GUI_App.cpp:1337 #: src/slic3r/GUI/GUI_App.cpp:1337
#, boost-format #, boost-format
@ -3513,16 +3513,27 @@ msgid ""
"To avoid this problem, consider disabling \"%4%\" in \"Preferences\". " "To avoid this problem, consider disabling \"%4%\" in \"Preferences\". "
"Otherwise, the application will most likely crash again next time." "Otherwise, the application will most likely crash again next time."
msgstr "" msgstr ""
"PrusaSlicer va crashejar la darrera vegada en intentar establir la posició "
"de la finestra.\n"
"Lamentem les molèsties, malauradament passa amb certes configuracions de "
"monitor múltiple.\n"
"El motiu més precís de l'accident: \"%1%\".\n"
"Per obtenir més informació, consulteu el nostre rastrejador d'incidències de "
"GitHub: \"%2%\" i \"%3%\"\n"
"\n"
"Per evitar aquest problema, considereu desactivar \"%4%\" a \"Preferències"
"\". En cas contrari, és probable que l'aplicació es torni a crashejar la "
"propera vegada."
#: src/slic3r/GUI/GUI_App.cpp:1349 #: src/slic3r/GUI/GUI_App.cpp:1349
#, boost-format #, boost-format
msgid "Disable \"%1%\"" msgid "Disable \"%1%\""
msgstr "" msgstr "Deshabilitar \"%1%\""
#: src/slic3r/GUI/GUI_App.cpp:1350 #: src/slic3r/GUI/GUI_App.cpp:1350
#, boost-format #, boost-format
msgid "Leave \"%1%\" enabled" msgid "Leave \"%1%\" enabled"
msgstr "" msgstr "Deixa \"%1%\" habilitat"
#: src/slic3r/GUI/GUI_App.cpp:1677 #: src/slic3r/GUI/GUI_App.cpp:1677
msgid "" msgid ""
@ -3805,6 +3816,7 @@ msgstr "PrusaSlicer recordarà la vostra elecció."
#: src/slic3r/GUI/GUI_App.cpp:3101 #: src/slic3r/GUI/GUI_App.cpp:3101
msgid "You will not be asked about it again on hyperlinks hovering." msgid "You will not be asked about it again on hyperlinks hovering."
msgstr "" msgstr ""
"No se us tornarà a preguntar al respecte quan passis per sobre de l'enllaç."
#: src/slic3r/GUI/GUI_App.cpp:3102 src/slic3r/GUI/Plater.cpp:1738 #: src/slic3r/GUI/GUI_App.cpp:3102 src/slic3r/GUI/Plater.cpp:1738
#, boost-format #, boost-format
@ -5008,15 +5020,16 @@ msgstr "S'ha produït un error inesperat"
#: src/slic3r/GUI/Jobs/RotoptimizeJob.hpp:21 #: src/slic3r/GUI/Jobs/RotoptimizeJob.hpp:21
msgid "Best surface quality" msgid "Best surface quality"
msgstr "" msgstr "Màxima qualitat de superfície"
#: src/slic3r/GUI/Jobs/RotoptimizeJob.hpp:23 #: src/slic3r/GUI/Jobs/RotoptimizeJob.hpp:23
msgid "Optimize object rotation for best surface quality." msgid "Optimize object rotation for best surface quality."
msgstr "" msgstr ""
"Optimitzar la rotació de l'objecte per a la màxima qualitat de superfície."
#: src/slic3r/GUI/Jobs/RotoptimizeJob.hpp:24 #: src/slic3r/GUI/Jobs/RotoptimizeJob.hpp:24
msgid "Reduced overhang slopes" msgid "Reduced overhang slopes"
msgstr "" msgstr "Pendents de voladís reduïts"
#: src/slic3r/GUI/Jobs/RotoptimizeJob.hpp:26 #: src/slic3r/GUI/Jobs/RotoptimizeJob.hpp:26
msgid "" msgid ""
@ -5025,14 +5038,20 @@ msgid ""
"Note that this method will try to find the best surface of the object for " "Note that this method will try to find the best surface of the object for "
"touching the print bed if no elevation is set." "touching the print bed if no elevation is set."
msgstr "" msgstr ""
"Optimitza la rotació d'objectes per tenir una quantitat mínima de voladissos "
"que necessiten estructures de suport.\n"
"Tingueu en compte que aquest mètode intentarà trobar la millor superfície de "
"l'objecte per tocar el llit d'impressió si no s'estableix cap elevació."
#: src/slic3r/GUI/Jobs/RotoptimizeJob.hpp:30 #: src/slic3r/GUI/Jobs/RotoptimizeJob.hpp:30
msgid "Lowest Z height" msgid "Lowest Z height"
msgstr "" msgstr "Mínima alçada Z"
#: src/slic3r/GUI/Jobs/RotoptimizeJob.hpp:32 #: src/slic3r/GUI/Jobs/RotoptimizeJob.hpp:32
msgid "Rotate the model to have the lowest z height for faster print time." msgid "Rotate the model to have the lowest z height for faster print time."
msgstr "" msgstr ""
"Rota el model per tenir l'alçada z més baixa i un temps d'impressió més "
"ràpid."
#: src/slic3r/GUI/Jobs/RotoptimizeJob.cpp:59 #: src/slic3r/GUI/Jobs/RotoptimizeJob.cpp:59
msgid "Searching for optimal orientation" msgid "Searching for optimal orientation"
@ -6985,7 +7004,7 @@ msgstr "Voleu desar els canvis a \"%1%\"?"
#: src/slic3r/GUI/Plater.cpp:1732 src/slic3r/GUI/Preferences.cpp:222 #: src/slic3r/GUI/Plater.cpp:1732 src/slic3r/GUI/Preferences.cpp:222
msgid "Ask for unsaved changes in project" msgid "Ask for unsaved changes in project"
msgstr "" msgstr "Preguntar pels canvis no desats al projecte"
#: src/slic3r/GUI/Plater.cpp:1735 #: src/slic3r/GUI/Plater.cpp:1735
msgid "" msgid ""
@ -6993,6 +7012,9 @@ msgid ""
"- Closing PrusaSlicer,\n" "- Closing PrusaSlicer,\n"
"- Loading or creating a new project" "- Loading or creating a new project"
msgstr "" msgstr ""
"No et preguntarà pels canvis no guardats la propera vegada que: \n"
"- Tanquis PrusaSlicer,\n"
"- Carreguis o creis un nou projecte"
#: src/slic3r/GUI/Plater.cpp:2197 #: src/slic3r/GUI/Plater.cpp:2197
#, c-format, boost-format #, c-format, boost-format
@ -7622,6 +7644,9 @@ msgid ""
"- Closing PrusaSlicer,\n" "- Closing PrusaSlicer,\n"
"- Loading or creating a new project" "- Loading or creating a new project"
msgstr "" msgstr ""
"Sol·licita sempre canvis no desats en el projecte, quan: \n"
"- Tancament PrusaSlicer,\n"
"- Càrrega o creació d'un nou projecte"
#: src/slic3r/GUI/Preferences.cpp:233 #: src/slic3r/GUI/Preferences.cpp:233
#: src/slic3r/GUI/UnsavedChangesDialog.cpp:897 #: src/slic3r/GUI/UnsavedChangesDialog.cpp:897
@ -7629,6 +7654,8 @@ msgid ""
"Ask to save unsaved changes in presets when closing the application or when " "Ask to save unsaved changes in presets when closing the application or when "
"loading a new project" "loading a new project"
msgstr "" msgstr ""
"Demana desar els canvis no desats en els predefinits en tancar l'aplicació o "
"en carregar un projecte nou"
#: src/slic3r/GUI/Preferences.cpp:235 #: src/slic3r/GUI/Preferences.cpp:235
msgid "" msgid ""
@ -7636,6 +7663,9 @@ msgid ""
"- Closing PrusaSlicer while some presets are modified,\n" "- Closing PrusaSlicer while some presets are modified,\n"
"- Loading a new project while some presets are modified" "- Loading a new project while some presets are modified"
msgstr "" msgstr ""
"Preguntar sempre pels canvis no guardats en els predefinits, quan:\n"
"- En tancar PrusaSlicer mentre es modifiquen alguns ajustaments,\n"
"- En carregar un nou projecte mentre es modifiquen alguns ajustaments"
#: src/slic3r/GUI/Preferences.cpp:242 #: src/slic3r/GUI/Preferences.cpp:242
#: src/slic3r/GUI/UnsavedChangesDialog.cpp:896 #: src/slic3r/GUI/UnsavedChangesDialog.cpp:896
@ -7647,15 +7677,20 @@ msgid ""
"Always ask for unsaved changes in presets when selecting new preset or " "Always ask for unsaved changes in presets when selecting new preset or "
"resetting a preset" "resetting a preset"
msgstr "" msgstr ""
"Preguntar sempre pels canvis no guardats en predefinits en seleccionar un "
"nou ajustament o en restablir un ajustament"
#: src/slic3r/GUI/Preferences.cpp:249 #: src/slic3r/GUI/Preferences.cpp:249
#: src/slic3r/GUI/UnsavedChangesDialog.cpp:895 #: src/slic3r/GUI/UnsavedChangesDialog.cpp:895
msgid "Ask for unsaved changes in presets when creating new project" msgid "Ask for unsaved changes in presets when creating new project"
msgstr "" msgstr ""
"Preguntar pels canvis no desats en predefinits en crear un nou projecte"
#: src/slic3r/GUI/Preferences.cpp:251 #: src/slic3r/GUI/Preferences.cpp:251
msgid "Always ask for unsaved changes in presets when creating new project" msgid "Always ask for unsaved changes in presets when creating new project"
msgstr "" msgstr ""
"Preguntar sempre pels canvis no guardats en predefinits en crear un nou "
"projecte"
#: src/slic3r/GUI/Preferences.cpp:258 #: src/slic3r/GUI/Preferences.cpp:258
msgid "Associate .gcode files to PrusaSlicer G-code Viewer" msgid "Associate .gcode files to PrusaSlicer G-code Viewer"
@ -7688,6 +7723,7 @@ msgstr "Mostra la pantalla de presentació"
#: src/slic3r/GUI/Preferences.cpp:289 #: src/slic3r/GUI/Preferences.cpp:289
msgid "If enabled, PrusaSlicer will be open at the position it was closed" msgid "If enabled, PrusaSlicer will be open at the position it was closed"
msgstr "" msgstr ""
"Si està habilitat, PrusaSlicer s'obrirà en la posició en què s'ha tancat"
#: src/slic3r/GUI/Preferences.cpp:295 #: src/slic3r/GUI/Preferences.cpp:295
msgid "Clear Undo / Redo stack on new project" msgid "Clear Undo / Redo stack on new project"
@ -7779,7 +7815,7 @@ msgstr ""
#: src/slic3r/GUI/Preferences.cpp:384 #: src/slic3r/GUI/Preferences.cpp:384
msgid "If enabled, PrusaSlicer will not open hyperlinks in your browser." msgid "If enabled, PrusaSlicer will not open hyperlinks in your browser."
msgstr "" msgstr "Si està habilitat, PrusaSlicer no obrirà hipervincles al navegador."
#: src/slic3r/GUI/Preferences.cpp:391 #: src/slic3r/GUI/Preferences.cpp:391
msgid "Use colors for axes values in Manipulation panel" msgid "Use colors for axes values in Manipulation panel"
@ -9224,19 +9260,19 @@ msgstr "Ajust"
#: src/slic3r/GUI/Tab.cpp:3938 #: src/slic3r/GUI/Tab.cpp:3938
msgid "Find" msgid "Find"
msgstr "Cerca" msgstr "Cercar"
#: src/slic3r/GUI/Tab.cpp:3939 #: src/slic3r/GUI/Tab.cpp:3939
msgid "Replace with" msgid "Replace with"
msgstr "" msgstr "Substitueix-ho per"
#: src/slic3r/GUI/Tab.cpp:4028 #: src/slic3r/GUI/Tab.cpp:4028
msgid "Regular expression" msgid "Regular expression"
msgstr "" msgstr "Expressió normal"
#: src/slic3r/GUI/Tab.cpp:4032 #: src/slic3r/GUI/Tab.cpp:4032
msgid "Case insensitive" msgid "Case insensitive"
msgstr "" msgstr "No distingeix minúscules/majúscules"
#: src/slic3r/GUI/Tab.cpp:4036 #: src/slic3r/GUI/Tab.cpp:4036
msgid "Whole word" msgid "Whole word"
@ -9244,11 +9280,11 @@ msgstr "Paraula sencera"
#: src/slic3r/GUI/Tab.cpp:4040 #: src/slic3r/GUI/Tab.cpp:4040
msgid "Match single line" msgid "Match single line"
msgstr "" msgstr "Coincideix amb una sola línia"
#: src/slic3r/GUI/Tab.cpp:4143 #: src/slic3r/GUI/Tab.cpp:4143
msgid "Are you sure you want to delete all substitutions?" msgid "Are you sure you want to delete all substitutions?"
msgstr "" msgstr "Esteu segur que voleu suprimir totes les substitucions?"
#: src/slic3r/GUI/Tab.cpp:4275 #: src/slic3r/GUI/Tab.cpp:4275
msgid "" msgid ""
@ -9512,12 +9548,16 @@ msgid ""
"You will not be asked about the unsaved changes in presets the next time you " "You will not be asked about the unsaved changes in presets the next time you "
"create new project" "create new project"
msgstr "" msgstr ""
"No et preguntarà pels canvis no guardats en predefinits la propera vegada "
"que creis un nou projecte"
#: src/slic3r/GUI/UnsavedChangesDialog.cpp:899 #: src/slic3r/GUI/UnsavedChangesDialog.cpp:899
msgid "" msgid ""
"You will not be asked about the unsaved changes in presets the next time you " "You will not be asked about the unsaved changes in presets the next time you "
"switch a preset" "switch a preset"
msgstr "" msgstr ""
"No et preguntarà pels canvis no guardats en predefinits la propera vegada "
"que canvíis d'ajust"
#: src/slic3r/GUI/UnsavedChangesDialog.cpp:900 #: src/slic3r/GUI/UnsavedChangesDialog.cpp:900
msgid "" msgid ""
@ -9526,6 +9566,10 @@ msgid ""
"- Closing PrusaSlicer while some presets are modified,\n" "- Closing PrusaSlicer while some presets are modified,\n"
"- Loading a new project while some presets are modified" "- Loading a new project while some presets are modified"
msgstr "" msgstr ""
"Preguntar sempre pels canvis no guardats en predefinits la propera vegada "
"que::\n"
"- Tanquis PrusaSlicer mentre es modifiquen alguns ajustaments,\n"
"- Carreguis un nou projecte mentre es modifiquen alguns ajustaments"
#: src/slic3r/GUI/UnsavedChangesDialog.cpp:903 #: src/slic3r/GUI/UnsavedChangesDialog.cpp:903
msgid "PrusaSlicer will remember your action." msgid "PrusaSlicer will remember your action."
@ -9617,7 +9661,7 @@ msgstr "Comptador d'extrusors"
#: src/slic3r/GUI/UnsavedChangesDialog.cpp:1454 #: src/slic3r/GUI/UnsavedChangesDialog.cpp:1454
msgid "Select presets to compare" msgid "Select presets to compare"
msgstr "" msgstr "Seleccioneu els predefinits per comparar"
#: src/slic3r/GUI/UnsavedChangesDialog.cpp:1503 #: src/slic3r/GUI/UnsavedChangesDialog.cpp:1503
msgid "Show all presets (including incompatible)" msgid "Show all presets (including incompatible)"
@ -10245,24 +10289,26 @@ msgstr ""
#: src/slic3r/Config/Snapshot.cpp:584 #: src/slic3r/Config/Snapshot.cpp:584
msgid "Taking a configuration snapshot failed." msgid "Taking a configuration snapshot failed."
msgstr "" msgstr "No s'ha pogut prendre una instantània de configuració."
#: src/slic3r/Config/Snapshot.cpp:598 #: src/slic3r/Config/Snapshot.cpp:598
msgid "" msgid ""
"PrusaSlicer has encountered an error while taking a configuration snapshot." "PrusaSlicer has encountered an error while taking a configuration snapshot."
msgstr "" msgstr ""
"El PrusaSlicer ha trobat un error mentre feia una instantània de "
"configuració."
#: src/slic3r/Config/Snapshot.cpp:599 #: src/slic3r/Config/Snapshot.cpp:599
msgid "PrusaSlicer error" msgid "PrusaSlicer error"
msgstr "" msgstr "Error de PrusaSlicer"
#: src/slic3r/Config/Snapshot.cpp:601 #: src/slic3r/Config/Snapshot.cpp:601
msgid "Continue" msgid "Continue"
msgstr "" msgstr "Continuar"
#: src/slic3r/Config/Snapshot.cpp:601 #: src/slic3r/Config/Snapshot.cpp:601
msgid "Abort" msgid "Abort"
msgstr "" msgstr "Avortar"
#: src/libslic3r/GCode.cpp:539 #: src/libslic3r/GCode.cpp:539
msgid "There is an object with no extrusions in the first layer." msgid "There is an object with no extrusions in the first layer."
@ -10313,7 +10359,7 @@ msgstr ""
#: src/libslic3r/GCode.cpp:1236 src/libslic3r/GCode.cpp:1247 #: src/libslic3r/GCode.cpp:1236 src/libslic3r/GCode.cpp:1247
msgid "No extrusions were generated for objects." msgid "No extrusions were generated for objects."
msgstr "" msgstr "No s'han generat extrusions per als objectes."
#: src/libslic3r/GCode.cpp:1445 #: src/libslic3r/GCode.cpp:1445
msgid "" msgid ""
@ -10706,18 +10752,25 @@ msgid ""
"each layer to prevent loss of floating point accuracy. Add \"G92 E0\" to " "each layer to prevent loss of floating point accuracy. Add \"G92 E0\" to "
"layer_gcode." "layer_gcode."
msgstr "" msgstr ""
"L'adreçament relatiu de l'extrusor requereix restablir la posició de "
"l'extrusor a cada capa per evitar la pèrdua de precisió de coma flotant. "
"Afegiu \"G92 E0\" a layer_gcode."
#: src/libslic3r/Print.cpp:665 #: src/libslic3r/Print.cpp:665
msgid "" msgid ""
"\"G92 E0\" was found in before_layer_gcode, which is incompatible with " "\"G92 E0\" was found in before_layer_gcode, which is incompatible with "
"absolute extruder addressing." "absolute extruder addressing."
msgstr "" msgstr ""
"\"G92 E0\" s'ha trobat a before_layer_gcode, el qual és incompatible amb "
"l'adreçament absolut d'extrusor."
#: src/libslic3r/Print.cpp:667 #: src/libslic3r/Print.cpp:667
msgid "" msgid ""
"\"G92 E0\" was found in layer_gcode, which is incompatible with absolute " "\"G92 E0\" was found in layer_gcode, which is incompatible with absolute "
"extruder addressing." "extruder addressing."
msgstr "" msgstr ""
"\"G92 E0\" s'ha trobat a layer_gcode, el qual és incompatible amb "
"l'adreçament absolut d'extrusor."
#: src/libslic3r/Print.cpp:809 #: src/libslic3r/Print.cpp:809
msgid "Infilling layers" msgid "Infilling layers"
@ -12309,11 +12362,11 @@ msgstr ""
#: src/libslic3r/PrintConfig.cpp:1361 #: src/libslic3r/PrintConfig.cpp:1361
msgid "G-code substitutions" msgid "G-code substitutions"
msgstr "" msgstr "Substitucions de codi G"
#: src/libslic3r/PrintConfig.cpp:1362 #: src/libslic3r/PrintConfig.cpp:1362
msgid "Find / replace patterns in G-code lines and substitute them." msgid "Find / replace patterns in G-code lines and substitute them."
msgstr "" msgstr "Cerca / substitueix patrons en línies de codi G i els substitueix."
#: src/libslic3r/PrintConfig.cpp:1367 #: src/libslic3r/PrintConfig.cpp:1367
msgid "High extruder current on filament swap" msgid "High extruder current on filament swap"
@ -15587,7 +15640,7 @@ msgid ""
"the<a>Variable layer height tool</a>. (Not available for SLA printers.)" "the<a>Variable layer height tool</a>. (Not available for SLA printers.)"
msgstr "" msgstr ""
"Alçada de capa variable\n" "Alçada de capa variable\n"
"Sabies que pot imprimir diferents regions del teu model amb una alçada de " "Sabies que pots imprimir diferents regions del teu model amb una alçada de "
"capa diferent i suavitzar les transicions entre elles? Proveu " "capa diferent i suavitzar les transicions entre elles? Proveu "
"l'eina<a>Alçada de capa variable</a>. (No disponible per a impressores SLA.)" "l'eina<a>Alçada de capa variable</a>. (No disponible per a impressores SLA.)"
@ -15624,7 +15677,7 @@ msgid ""
"threshold area</a>. (Expert mode only.)" "threshold area</a>. (Expert mode only.)"
msgstr "" msgstr ""
"Àrea llindar de farciment sòlid\n" "Àrea llindar de farciment sòlid\n"
"Sabies que pot fer que les parts del seu model amb una secció transversal " "Sabies que pots fer que les parts del teu model amb una secció transversal "
"petita s'emplenin amb farciment sòlid automàticament? Ajusta el<a>Àrea " "petita s'emplenin amb farciment sòlid automàticament? Ajusta el<a>Àrea "
"llindar de farciment sòlid</a>. (Només en mode Expert.)" "llindar de farciment sòlid</a>. (Només en mode Expert.)"
@ -15837,13 +15890,44 @@ msgstr ""
"Sabies que pots posar el PrusaSlicer en mode de pantalla completa? Utilitzeu " "Sabies que pots posar el PrusaSlicer en mode de pantalla completa? Utilitzeu "
"la tecla d'accés ràpid <b>F11</b>." "la tecla d'accés ràpid <b>F11</b>."
#: ../src/common/debugrpt.cpp:586 #~ msgid ""
msgid "" #~ "If enabled, the descriptions of configuration parameters in settings tabs "
"\n" #~ "wouldn't work as hyperlinks. If disabled, the descriptions of "
"Please send this report to the program maintainer, thank you!\n" #~ "configuration parameters in settings tabs will work as hyperlinks."
msgstr "" #~ msgstr ""
"\n" #~ "Si està habilitat, les descripcions dels paràmetres de configuració a les "
"Envieu aquest informe al mantenidor del programa. Gràcies!\n" #~ "pestanyes de configuració no funcionaran com a hiperenllaços. Si està "
#~ "deshabilitat, les descripcions dels paràmetres de configuració a les "
#~ "pestanyes de configuració funcionaran com a hiperenllaços."
#, c-format, boost-format
#~ msgid ""
#~ "PrusaSlicer detected another configuration folder at %s.\n"
#~ "Its version is %s.\n"
#~ "Last version you used in current configuration folder is %s.\n"
#~ "Please note that PrusaSlicer uses different folders to save configuration "
#~ "of alpha, beta and full release versions.\n"
#~ "Would you like to copy found configuration to your current configuration "
#~ "folder?\n"
#~ "\n"
#~ "If you select yes, PrusaSlicer will copy all profiles and other files "
#~ "from found folder to the current one. Overwriting any existing file with "
#~ "matching name.\n"
#~ "If you select no, you will continue with current configuration."
#~ msgstr ""
#~ "PrusaSlicer ha detectat una altra carpeta de configuració a %s.\n"
#~ "La vostra versió és %s.\n"
#~ "La darrera versió que heu utilitzat a la carpeta de configuració actual "
#~ "és %s.\n"
#~ "Si us plau, tingueu en compte que PrusaSlicer utilitza diferents carpetes "
#~ "per desar la configuració de les versions alfa, beta i final.\n"
#~ "Voleu copiar la configuració trobada a la vostra carpeta de configuració "
#~ "actual?\n"
#~ "\n"
#~ "Si seleccioneu sí, PrusaSlicer copiarà tots els perfils i altres fitxers "
#~ "de la carpeta trobada a l'actual, sobreescrivint qualsevol fitxer "
#~ "existent amb el mateix nom.\n"
#~ "Si seleccioneu no, continuareu amb la configuració actual."
#: ../src/richtext/richtextstyledlg.cpp:210 #: ../src/richtext/richtextstyledlg.cpp:210
#: ../src/richtext/richtextstyledlg.cpp:222 #: ../src/richtext/richtextstyledlg.cpp:222

View File

@ -1,3 +1,5 @@
min_slic3r_version = 2.4.1-rc1
0.1.0 Added Anycubic 4Max Pro 2.0
min_slic3r_version = 2.3.2-alpha0 min_slic3r_version = 2.3.2-alpha0
0.0.12 Updated Anycubic i3 MEGA(S) profiles. 0.0.12 Updated Anycubic i3 MEGA(S) profiles.
0.0.11 Added bed model and texture for i3 Mega, i3 Mega S. 0.0.11 Added bed model and texture for i3 Mega, i3 Mega S.

View File

@ -5,7 +5,7 @@
name = Anycubic name = Anycubic
# Configuration version of this file. Config file will only be installed, if the config_version differs. # Configuration version of this file. Config file will only be installed, if the config_version differs.
# This means, the server may force the PrusaSlicer configuration to be downgraded. # This means, the server may force the PrusaSlicer configuration to be downgraded.
config_version = 0.0.12 config_version = 0.1.0
# Where to get the updates from? # Where to get the updates from?
config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/Anycubic/ config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/Anycubic/
# changelog_url = https://files.prusa3d.com/?latest=slicer-profiles&lng=%1% # changelog_url = https://files.prusa3d.com/?latest=slicer-profiles&lng=%1%
@ -57,6 +57,15 @@ family = MEGA
bed_model = i3megas_bed.stl bed_model = i3megas_bed.stl
bed_texture = i3megas.svg bed_texture = i3megas.svg
[printer_model:4MAXPRO20]
name = Anycubic 4Max Pro 2.0
variants = 0.4
technology = FFF
family = 4Max
bed_model = 4MAXPRO20_bed.stl
bed_texture = 4MAXPRO20_texture.svg
default_materials = Generic PLA @4Max Pro 2.0; Generic TPU @4Max Pro 2.0; Generic ABS @4Max Pro 2.0
[printer_model:PREDATOR] [printer_model:PREDATOR]
name = Anycubic Predator name = Anycubic Predator
variants = 0.4; 0.6; 0.8 variants = 0.4; 0.6; 0.8
@ -1902,17 +1911,339 @@ min_layer_height = 0.16
max_layer_height = 0.48 max_layer_height = 0.48
default_print_profile = 0.24mm 0.8 nozzle DETAILED QUALITY @PREDATOR default_print_profile = 0.24mm 0.8 nozzle DETAILED QUALITY @PREDATOR
######################################### ## Anycubic 4MAX Pro 2.0
########## end printer presets ########## ## based on https://hartrusion.com/en/prusaslicer-config-for-anycubic-4max-pro-2-0/
#########################################
[print:*common_4max*]
avoid_crossing_perimeters = 0
avoid_crossing_perimeters_max_detour = 0
bottom_fill_pattern = monotonic
bottom_solid_layers = 4
bridge_acceleration = 300
bridge_angle = 0
bridge_flow_ratio = 0.65
bridge_speed = 30
brim_separation = 0
brim_type = outer_only
brim_width = 0
clip_multipart_objects = 1
compatible_printers_condition = printer_model=="4MAXPRO20" and nozzle_diameter[0]==0.4
complete_objects = 0
default_acceleration = 900
dont_support_bridges = 1
draft_shield = disabled
elefant_foot_compensation = 0.2
ensure_vertical_shell_thickness = 1
external_perimeter_extrusion_width = 0
external_perimeter_speed = 35
external_perimeters_first = 0
extra_perimeters = 0
extruder_clearance_height = 20
extruder_clearance_radius = 20
extrusion_width = 0.45
fill_angle = 45
fill_density = 20%
fill_pattern = gyroid
first_layer_acceleration = 300
first_layer_acceleration_over_raft = 0
first_layer_extrusion_width = 0.65
first_layer_height = 0.3
first_layer_speed = 20
first_layer_speed_over_raft = 30
fuzzy_skin = none
fuzzy_skin_point_dist = 0.8
fuzzy_skin_thickness = 0.3
gap_fill_enabled = 1
gap_fill_speed = 40
gcode_comments = 0
gcode_label_objects = 0
gcode_resolution = 0.0125
infill_acceleration = 600
infill_anchor = 400%
infill_anchor_max = 50
infill_every_layers = 1
infill_extruder = 1
infill_extrusion_width = 0
infill_first = 0
infill_only_where_needed = 0
infill_overlap = 23%
infill_speed = 45
inherits =
interface_shells = 0
ironing = 0
ironing_flowrate = 15%
ironing_spacing = 0.1
ironing_speed = 15
ironing_type = top
layer_height = 0.2
max_print_speed = 50
max_volumetric_speed = 0
min_skirt_length = 0
only_retract_when_crossing_perimeters = 0
ooze_prevention = 0
output_filename_format = {input_filename_base}_{layer_height}mm_{filament_type[0]}_{print_time}.gcode
overhangs = 1
perimeter_acceleration = 500
perimeter_extruder = 1
perimeter_extrusion_width = 0
perimeter_speed = 45
perimeters = 3
post_process =
print_settings_id =
raft_contact_distance = 0.1
raft_expansion = 1.5
raft_first_layer_density = 90%
raft_first_layer_expansion = 3
raft_layers = 0
resolution = 0
seam_position = aligned
single_extruder_multi_material_priming = 1
skirt_distance = 5
skirt_height = 1
skirts = 2
slicing_mode = regular
small_perimeter_speed = 20
solid_infill_below_area = 0
solid_infill_every_layers = 0
solid_infill_extruder = 1
solid_infill_extrusion_width = 0
solid_infill_speed = 45
spiral_vase = 0
standby_temperature_delta = -5
support_material = 0
support_material_angle = 0
support_material_auto = 1
support_material_bottom_contact_distance = 0
support_material_bottom_interface_layers = -1
support_material_buildplate_only = 1
support_material_closing_radius = 2
support_material_contact_distance = 0.2
support_material_enforce_layers = 0
support_material_extruder = 1
support_material_extrusion_width = 0.4
support_material_interface_contact_loops = 0
support_material_interface_extruder = 1
support_material_interface_layers = 2
support_material_interface_pattern = rectilinear
support_material_interface_spacing = 0.2
support_material_interface_speed = 30
support_material_pattern = rectilinear-grid
support_material_spacing = 2.5
support_material_speed = 45
support_material_style = grid
support_material_synchronize_layers = 0
support_material_threshold = 45
support_material_with_sheath = 1
support_material_xy_spacing = 60%
thick_bridges = 1
thin_walls = 0
top_fill_pattern = monotonic
top_infill_extrusion_width = 0.4
top_solid_infill_speed = 30
top_solid_layers = 5
travel_speed = 60
travel_speed_z = 0
wipe_tower = 0
wipe_tower_bridging = 10
wipe_tower_brim_width = 2
wipe_tower_no_sparse_layers = 0
wipe_tower_rotation_angle = 0
wipe_tower_width = 60
wipe_tower_x = 180
wipe_tower_y = 140
xy_size_compensation = 0
[print:0.15mm Detail @4Max Pro 2.0]
inherits = *common_4max*
layer_height = 0.15
bottom_solid_layers = 5
top_solid_layers = 7
perimeter_speed = 40
external_perimeter_speed = 25
[print:0.20mm Quality @4Max Pro 2.0]
inherits = *common_4max*
external_perimeter_speed = 25
[print:0.30mm Draft @4Max Pro 2.0]
inherits = *common_4max*
layer_height = 0.3
bottom_solid_layers = 3
top_solid_layers = 3
[filament:*common_4max*]
bed_temperature = 60
bridge_fan_speed = 100
compatible_printers_condition = printer_model=="4MAXPRO20"
cooling = 1
disable_fan_first_layers = 1
extrusion_multiplier = 1
fan_always_on = 1
fan_below_layer_time = 30
filament_density = 1.24
filament_diameter = 1.75
filament_max_volumetric_speed = 0
filament_type = PLA
first_layer_bed_temperature = 60
first_layer_temperature = 210
full_fan_speed_layer = 5
max_fan_speed = 100
min_fan_speed = 80
min_print_speed = 10
slowdown_below_layer_time = 15
temperature = 205
[filament:*PLA_4max*]
inherits = *common_4max*
[filament:Generic PLA @4Max Pro 2.0]
inherits = *PLA_4max*
filament_vendor = Generic
[filament:Anycubic PLA @4Max Pro 2.0]
inherits = *PLA_4max*
first_layer_temperature = 215
temperature = 207
filament_vendor = Anycubic
[filament:Generic ABS @4Max Pro 2.0]
filament_vendor = Generic
compatible_printers_condition = printer_model=="4MAXPRO20"
bed_temperature = 100
first_layer_bed_temperature = 100
temperature = 245
first_layer_temperature = 245
bridge_fan_speed = 15
cooling = 1
disable_fan_first_layers = 3
extrusion_multiplier = 1
fan_always_on = 0
fan_below_layer_time = 60
filament_colour = #800000
filament_density = 1.04
filament_diameter = 1.75
filament_type = ABS
full_fan_speed_layer = 0
max_fan_speed = 0
min_fan_speed = 0
min_print_speed = 10
slowdown_below_layer_time = 25
[filament:Generic TPU @4Max Pro 2.0]
filament_vendor = Generic
bed_temperature = 60
bridge_fan_speed = 0
compatible_printers_condition = printer_model=="4MAXPRO20"
cooling = 1
disable_fan_first_layers = 3
extrusion_multiplier = 1
fan_always_on = 0
fan_below_layer_time = 60
filament_colour = #211AB5
filament_density = 1.19
filament_deretract_speed = 20
filament_diameter = 1.75
filament_retract_speed = 30
filament_type = FLEX
filament_max_volumetric_speed = 1.65
first_layer_bed_temperature = 60
first_layer_temperature = 215
full_fan_speed_layer = 0
max_fan_speed = 0
min_fan_speed = 0
min_print_speed = 10
slowdown_below_layer_time = 20
temperature = 215
[filament:Polymaker PolyFlex TPU95 @4Max Pro 2.0]
filament_vendor = Polymaker
bed_temperature = 45
bridge_fan_speed = 80
compatible_printers_condition = printer_model=="4MAXPRO20"
cooling = 1
disable_fan_first_layers = 5
extrusion_multiplier = 1.04
fan_always_on = 1
fan_below_layer_time = 45
filament_colour = #FD7D2F
filament_density = 1.22
filament_deretract_speed = 25
filament_diameter = 1.75
filament_max_volumetric_speed = 1.65
filament_retract_length = 4
filament_retract_restart_extra = 0.1
filament_retract_speed = 60
filament_type = FLEX
first_layer_bed_temperature = 55
first_layer_temperature = 215
full_fan_speed_layer = 8
max_fan_speed = 50
min_fan_speed = 25
min_print_speed = 10
slowdown_below_layer_time = 10
temperature = 217
[printer:Anycubic 4Max Pro 2.0]
printer_model = 4MAXPRO20
printer_variant = 0.4
printer_technology = FFF
bed_shape = 0x0,270x0,270x210,0x210
color_change_gcode = M600
default_filament_profile = Generic PLA @4Max Pro 2.0
default_print_profile = 0.20mm Quality @4Max Pro 2.0
deretract_speed = 25
end_gcode = M104 S0 ; turn off extruder heating\nM140 S0 ; turn off bed heating\nM107 ; turn off fans\nG91 ; relative positioning\nG0 Z+0.5 ; move Z up a tiny bit\nG90 ; absolute positioning\nG0 X135 Y105 F{machine_max_feedrate_x[0]*60} ; move extruder to center position\nG0 Z190.5 F{machine_max_feedrate_z[0]*60} ; lower the plattform to Z min\nM84 ; steppers off\nG90 ; absolute positioning\n
extruder_offset = 0x0
gcode_flavor = marlin
machine_limits_usage = time_estimate_only
machine_max_acceleration_e = 5000
machine_max_acceleration_extruding = 1250
machine_max_acceleration_retracting = 1250
machine_max_acceleration_travel = 1500
machine_max_acceleration_x = 900
machine_max_acceleration_y = 900
machine_max_acceleration_z = 100
machine_max_feedrate_e = 120
machine_max_feedrate_x = 200
machine_max_feedrate_y = 200
machine_max_feedrate_z = 16
machine_max_jerk_e = 5
machine_max_jerk_x = 6
machine_max_jerk_y = 6
machine_max_jerk_z = 0.2
machine_min_extruding_rate = 0
machine_min_travel_rate = 0
max_layer_height = 0.3
max_print_height = 190
min_layer_height = 0.07
nozzle_diameter = 0.4
pause_print_gcode = M601
remaining_times = 0
retract_before_travel = 2
retract_before_wipe = 0%
retract_layer_change = 1
retract_length = 2.5
retract_length_toolchange = 10
retract_lift = 0
retract_lift_above = 0
retract_lift_below = 0
retract_restart_extra = 0
retract_restart_extra_toolchange = 0
retract_speed = 35
silent_mode = 0
single_extruder_multi_material = 0
start_gcode = G21 ; metric values\nG90 ; absolute positioning\nM82 ; set extruder to absolute mode\nM140 S[first_layer_bed_temperature] ; set bed temp\nG28 X0 Y0 ; home X and Y\nG28 Z0 ; home Z\nG1 Z30 F{machine_max_feedrate_z[0]*60} ; move Z a bit down to not blow on the bed edge while heating\nG1 X10 F3900 ; let some space on x to prevent the filament cooling exhaust from beeing blocked by the servo motor\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM104 S[first_layer_temperature] ; set extruder temp\nM106 S80 ; turn on fan to prevent air nozzle melt while heating up\nM109 S[first_layer_temperature] ; wait for extruder temp\nM107 ; start with the fan off\nG28 X0 ; goto X home again\nG92 E0 ; zero the extruded length\nG1 Z0.2 F360 ; move plattform upwards\n; extrude material next to the plattform (comment or remove following lines to disable)\nG1 F180 E20 ; extrude some material next to the plattform\nG92 E0 ; zero the extruded length\nG1 E-[retract_length] F{retract_speed[0]*60} ; do a filament retract\nG92 E0 ; zero the extruded length again\nG1 X5 F3900 ; move sideways to get rid of that string\nG1 E[retract_length] F{retract_speed[0]*60} ; do a filament deretract with retract parameters\nG92 E0 ; zero the extruded length again\n; draw intro line (comment or remove following lines to disable)\nG1 X30 E5 F700 ; draw intro line\nG92 E0 ; zero the extruded length\nG1 E-[retract_length] F{retract_speed[0]*60} ; do a filament retract\nG1 X40 Z2.0 ; move away from the introline\nG92 E0 ; zero the extruded length again\nG1 E[retract_length] F{retract_speed[0]*60} ; do a filament deretract with retract parameters\n; end of intro line code\nM117 Printing...\nG5
use_firmware_retraction = 0
use_relative_e_distances = 0
use_volumetric_e = 0
variable_layer_height = 1
wipe = 0
z_offset = 0
#########################################
########## SLA printer presets ########## ########## SLA printer presets ##########
#########################################
[sla_print:*common print ANYCUBIC SLA*] [sla_print:*common print ANYCUBIC SLA*]
compatible_printers_condition = family=="PHOTON MONO" compatible_printers_condition = printer_notes=~/.*PHOTONMONOX.*/
layer_height = 0.05 layer_height = 0.05
output_filename_format = [input_filename_base].pwmx output_filename_format = [input_filename_base].pwmx
pad_edge_radius = 0.5 pad_edge_radius = 0.5

Binary file not shown.

View File

@ -0,0 +1,259 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="270mm"
height="210mm"
viewBox="0 0 270 210"
version="1.1"
id="svg8"
inkscape:version="1.0.2-2 (e86c870879, 2021-01-15)"
sodipodi:docname="4MAXPRO20_texture.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.98994949"
inkscape:cx="246.42197"
inkscape:cy="156.15646"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
inkscape:document-rotation="0"
showgrid="true"
inkscape:window-width="2560"
inkscape:window-height="1377"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1">
<inkscape:grid
type="xygrid"
id="grid1404" />
</sodipodi:namedview>
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-34.773811,-90.714287)">
<rect
style="fill:none;stroke-width:0.264583"
id="rect1402"
width="270"
height="210"
x="34.773811"
y="90.714287" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773811,100.71429 H 304.7738 v 0"
id="path1410" />
<path
style="fill:none;stroke:#000000;stroke-width:0.5;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="m 304.7738,100.71429 v 0"
id="path1412" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,110.71429 H 304.77381 v 0"
id="path1410-7" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,120.71429 H 304.77381 v 0"
id="path1410-4" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,130.71429 H 304.77381 v 0"
id="path1410-9" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,140.71429 H 304.77381 v 0"
id="path1410-1" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,150.71429 H 304.77381 v 0"
id="path1410-5" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,160.71429 H 304.77381 v 0"
id="path1410-8" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,170.71429 H 304.77381 v 0"
id="path1410-56" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,180.71429 H 304.77381 v 0"
id="path1410-569" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,190.71429 H 304.77381 v 0"
id="path1410-85" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,200.71429 H 304.77381 v 0"
id="path1410-0" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,210.71429 H 304.77381 v 0"
id="path1410-43" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,220.71429 H 304.77381 v 0"
id="path1410-55" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,230.71429 H 304.77381 v 0"
id="path1410-45" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,240.71429 H 304.77381 v 0"
id="path1410-58" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,250.71429 H 304.77381 v 0"
id="path1410-3" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,260.71429 H 304.77381 v 0"
id="path1410-53" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,270.71429 H 304.77381 v 0"
id="path1410-97" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,280.71429 H 304.77381 v 0"
id="path1410-38" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 34.773822,290.71429 H 304.77381 v 0"
id="path1410-75" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 44.773811,90.714287 V 300.71429 270.71428"
id="path1618" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 44.773811,270.71428 v 0"
id="path1620" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 54.773811,90.714287 V 300.71429 270.71428"
id="path1618-5" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 64.773811,90.714287 V 300.71429 270.71428"
id="path1618-2" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 74.773811,90.714287 V 300.71429 270.71428"
id="path1618-3" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 84.773811,90.714287 V 300.71429 270.71428"
id="path1618-6" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 94.773811,90.714287 V 300.71429 270.71428"
id="path1618-9" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 104.77381,90.714287 V 300.71429 270.71428"
id="path1618-0" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 114.77381,90.714287 V 300.71429 270.71428"
id="path1618-95" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 124.77381,90.714287 V 300.71429 270.71428"
id="path1618-1" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 134.77381,90.714287 V 300.71429 270.71428"
id="path1618-57" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 144.77381,90.714287 V 300.71429 270.71428"
id="path1618-54" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 154.77381,90.714287 V 300.71429 270.71428"
id="path1618-958" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 164.77381,90.714287 V 300.71429 270.71428"
id="path1618-4" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 174.77381,90.714287 V 300.71429 270.71428"
id="path1618-17" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 184.77381,90.714287 V 300.71429 270.71428"
id="path1618-27" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 194.77381,90.714287 V 300.71429 270.71428"
id="path1618-8" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 204.77381,90.714287 V 300.71429 270.71428"
id="path1618-88" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 214.77381,90.714287 V 300.71429 270.71428"
id="path1618-98" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 224.77381,90.714287 V 300.71429 270.71428"
id="path1618-16" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 234.77381,90.714287 V 300.71429 270.71428"
id="path1618-7" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 244.77381,90.714287 V 300.71429 270.71428"
id="path1618-175" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 254.77381,90.714287 V 300.71429 270.71428"
id="path1618-00" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 264.77381,90.714287 V 300.71429 270.71428"
id="path1618-28" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 274.77381,90.714287 V 300.71429 270.71428"
id="path1618-39" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 284.77381,90.714287 V 300.71429 270.71428"
id="path1618-70" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 294.77381,90.714287 V 300.71429 270.71428"
id="path1618-33" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -1,3 +1,5 @@
min_slic3r_version = 2.4.1
0.1.4 Added Ender-3 Pro. Added M25 support for some printers.
min_slic3r_version = 2.4.0-rc min_slic3r_version = 2.4.0-rc
0.1.3 Ender-3 S1 improvements. 0.1.3 Ender-3 S1 improvements.
0.1.2 Added alpha Ender 3 S1 profiles. 0.1.2 Added alpha Ender 3 S1 profiles.

View File

@ -5,7 +5,7 @@
name = Creality name = Creality
# Configuration version of this file. Config file will only be installed, if the config_version differs. # Configuration version of this file. Config file will only be installed, if the config_version differs.
# This means, the server may force the PrusaSlicer configuration to be downgraded. # This means, the server may force the PrusaSlicer configuration to be downgraded.
config_version = 0.1.3 config_version = 0.1.4
# Where to get the updates from? # Where to get the updates from?
config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/Creality/ config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/Creality/
# changelog_url = https://files.prusa3d.com/?latest=slicer-profiles&lng=%1% # changelog_url = https://files.prusa3d.com/?latest=slicer-profiles&lng=%1%
@ -32,6 +32,15 @@ bed_model = ender3_bed.stl
bed_texture = ender3.svg bed_texture = ender3.svg
default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Matt @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Matt @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY
[printer_model:ENDER3PRO]
name = Creality Ender-3 Pro
variants = 0.4
technology = FFF
family = ENDER
bed_model = ender3_bed.stl
bed_texture = ender3.svg
default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Matt @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY
[printer_model:ENDER3V2] [printer_model:ENDER3V2]
name = Creality Ender-3 V2 name = Creality Ender-3 V2
variants = 0.4 variants = 0.4
@ -960,8 +969,16 @@ inherits = Creality Ender-3; *fastabl*
renamed_from = "Creality ENDER-3 BLTouch" renamed_from = "Creality ENDER-3 BLTouch"
printer_model = ENDER3BLTOUCH printer_model = ENDER3BLTOUCH
[printer:Creality Ender-3 Pro]
inherits = *common*; *pauseprint*
renamed_from = "Creality Ender-3 Pro"
bed_shape = 5x0,215x0,215x220,5x220
max_print_height = 250
printer_model = ENDER3PRO
printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3PRO\nPRINTER_HAS_BOWDEN
[printer:Creality Ender-3 V2] [printer:Creality Ender-3 V2]
inherits = *common* inherits = *common*; *pauseprint*
renamed_from = "Creality Ender-3V2" renamed_from = "Creality Ender-3V2"
bed_shape = 5x0,215x0,215x220,5x220 bed_shape = 5x0,215x0,215x220,5x220
max_print_height = 250 max_print_height = 250
@ -969,14 +986,14 @@ printer_model = ENDER3V2
printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3V2\nPRINTER_HAS_BOWDEN printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3V2\nPRINTER_HAS_BOWDEN
[printer:Creality Ender-3 S1] [printer:Creality Ender-3 S1]
inherits = *common*; *spriteextruder* inherits = *common*; *pauseprint*; *spriteextruder*
bed_shape = 5x0,215x0,215x220,5x220 bed_shape = 5x0,215x0,215x220,5x220
max_print_height = 270 max_print_height = 270
printer_model = ENDER3S1 printer_model = ENDER3S1
printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3S1 printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3S1
[printer:Creality Ender-3 Max] [printer:Creality Ender-3 Max]
inherits = *common* inherits = *common*; *pauseprint*
retract_length = 6 retract_length = 6
bed_shape = 5x5,295x5,295x295,5x295 bed_shape = 5x5,295x5,295x295,5x295
max_print_height = 340 max_print_height = 340

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -0,0 +1,12 @@
#version 110
attribute vec3 v_position;
attribute vec2 v_tex_coord;
varying vec2 tex_coord;
void main()
{
tex_coord = v_tex_coord;
gl_Position = vec4(v_position, 1.0);
}

View File

@ -0,0 +1,11 @@
#version 110
attribute vec3 v_position;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
void main()
{
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
}

View File

@ -0,0 +1,15 @@
#version 110
attribute vec3 v_position;
attribute vec2 v_tex_coord;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
varying vec2 tex_coord;
void main()
{
tex_coord = v_tex_coord;
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
}

View File

@ -40,7 +40,6 @@ varying vec2 intensity;
uniform PrintVolumeDetection print_volume; uniform PrintVolumeDetection print_volume;
varying vec4 model_pos;
varying vec4 world_pos; varying vec4 world_pos;
varying float world_normal_z; varying float world_normal_z;
varying vec3 eye_normal; varying vec3 eye_normal;

View File

@ -38,7 +38,6 @@ varying vec2 intensity;
varying vec3 clipping_planes_dots; varying vec3 clipping_planes_dots;
varying vec4 model_pos;
varying vec4 world_pos; varying vec4 world_pos;
varying float world_normal_z; varying float world_normal_z;
varying vec3 eye_normal; varying vec3 eye_normal;
@ -60,7 +59,6 @@ void main()
NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0); NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0);
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
model_pos = gl_Vertex;
// Point in homogenous coordinates. // Point in homogenous coordinates.
world_pos = volume_world_matrix * gl_Vertex; world_pos = volume_world_matrix * gl_Vertex;

View File

@ -0,0 +1,77 @@
#version 110
#define INTENSITY_CORRECTION 0.6
// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31)
const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929);
#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION)
#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION)
#define LIGHT_TOP_SHININESS 20.0
// normalized values for (1./1.43, 0.2/1.43, 1./1.43)
const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074);
#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION)
//#define LIGHT_FRONT_SPECULAR (0.0 * INTENSITY_CORRECTION)
//#define LIGHT_FRONT_SHININESS 5.0
#define INTENSITY_AMBIENT 0.3
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
struct SlopeDetection
{
bool actived;
float normal_z;
mat3 volume_world_normal_matrix;
};
attribute vec3 v_position;
attribute vec3 v_normal;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat3 normal_matrix;
uniform mat4 volume_world_matrix;
uniform SlopeDetection slope;
// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane.
uniform vec2 z_range;
// Clipping plane - general orientation. Used by the SLA gizmo.
uniform vec4 clipping_plane;
// x = diffuse, y = specular;
varying vec2 intensity;
varying vec3 clipping_planes_dots;
varying vec4 world_pos;
varying float world_normal_z;
varying vec3 eye_normal;
void main()
{
// First transform the normal into camera space and normalize the result.
eye_normal = normalize(normal_matrix * v_normal);
// Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex.
// Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range.
float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0);
intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
vec4 position = view_model_matrix * vec4(v_position, 1.0);
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS);
// Perform the same lighting calculation for the 2nd light source (no specular applied).
NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0);
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
// Point in homogenous coordinates.
world_pos = volume_world_matrix * vec4(v_position, 1.0);
// z component of normal vector in world coordinate used for slope shading
world_normal_z = slope.actived ? (normalize(slope.volume_world_normal_matrix * v_normal)).z : 0.0;
gl_Position = projection_matrix * position;
// Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded.
clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z);
}

View File

@ -0,0 +1,45 @@
#version 110
#define INTENSITY_CORRECTION 0.6
// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31)
const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929);
#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION)
#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION)
#define LIGHT_TOP_SHININESS 20.0
// normalized values for (1./1.43, 0.2/1.43, 1./1.43)
const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074);
#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION)
#define INTENSITY_AMBIENT 0.3
attribute vec3 v_position;
attribute vec3 v_normal;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat3 normal_matrix;
// x = tainted, y = specular;
varying vec2 intensity;
void main()
{
// First transform the normal into camera space and normalize the result.
vec3 normal = normalize(normal_matrix * v_normal);
// Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex.
// Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range.
float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0);
intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
vec4 position = view_model_matrix * vec4(v_position, 1.0);
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS);
// Perform the same lighting calculation for the 2nd light source (no specular applied).
NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0);
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
gl_Position = projection_matrix * position;
}

View File

@ -0,0 +1,50 @@
#version 110
#define INTENSITY_CORRECTION 0.6
// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31)
const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929);
#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION)
#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION)
#define LIGHT_TOP_SHININESS 20.0
// normalized values for (1./1.43, 0.2/1.43, 1./1.43)
const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074);
#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION)
#define INTENSITY_AMBIENT 0.3
// vertex attributes
attribute vec3 v_position;
attribute vec3 v_normal;
// instance attributes
attribute vec3 i_offset;
attribute vec2 i_scales;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat3 normal_matrix;
// x = tainted, y = specular;
varying vec2 intensity;
void main()
{
// First transform the normal into camera space and normalize the result.
vec3 eye_normal = normalize(normal_matrix * v_normal);
// Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex.
// Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range.
float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0);
intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
vec4 world_position = vec4(v_position * vec3(vec2(1.5 * i_scales.x), 1.5 * i_scales.y) + i_offset - vec3(0.0, 0.0, 0.5 * i_scales.y), 1.0);
vec4 eye_position = view_model_matrix * world_position;
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(eye_position.xyz), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS);
// Perform the same lighting calculation for the 2nd light source (no specular applied).
NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0);
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
gl_Position = projection_matrix * eye_position;
}

View File

@ -0,0 +1,13 @@
#version 110
const float EPSILON = 0.0001;
uniform vec4 uniform_color;
void main()
{
gl_FragColor = uniform_color;
// Values inside depth buffer for fragments of the contour of a selected area are offset
// by small epsilon to solve z-fighting between painted triangles and contour lines.
gl_FragDepth = gl_FragCoord.z - EPSILON;
}

View File

@ -0,0 +1,11 @@
#version 110
attribute vec3 v_position;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
void main()
{
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
}

View File

@ -0,0 +1,63 @@
#version 110
#define INTENSITY_CORRECTION 0.6
// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31)
const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929);
#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION)
#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION)
#define LIGHT_TOP_SHININESS 20.0
// normalized values for (1./1.43, 0.2/1.43, 1./1.43)
const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074);
#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION)
#define INTENSITY_AMBIENT 0.3
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
const float EPSILON = 0.0001;
uniform vec4 uniform_color;
uniform bool volume_mirrored;
uniform mat4 view_model_matrix;
uniform mat3 normal_matrix;
varying vec3 clipping_planes_dots;
varying vec4 model_pos;
void main()
{
if (any(lessThan(clipping_planes_dots, ZERO)))
discard;
vec3 color = uniform_color.rgb;
float alpha = uniform_color.a;
vec3 triangle_normal = normalize(cross(dFdx(model_pos.xyz), dFdy(model_pos.xyz)));
#ifdef FLIP_TRIANGLE_NORMALS
triangle_normal = -triangle_normal;
#endif
if (volume_mirrored)
triangle_normal = -triangle_normal;
// First transform the normal into camera space and normalize the result.
vec3 eye_normal = normalize(normal_matrix * triangle_normal);
// Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex.
// Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range.
float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0);
// x = diffuse, y = specular;
vec2 intensity = vec2(0.0);
intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
vec3 position = (view_model_matrix * model_pos).xyz;
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS);
// Perform the same lighting calculation for the 2nd light source (no specular applied).
NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0);
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha);
}

View File

@ -0,0 +1,28 @@
#version 110
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
attribute vec3 v_position;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat4 volume_world_matrix;
// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane.
uniform vec2 z_range;
// Clipping plane - general orientation. Used by the SLA gizmo.
uniform vec4 clipping_plane;
varying vec3 clipping_planes_dots;
varying vec4 model_pos;
void main()
{
model_pos = vec4(v_position, 1.0);
// Point in homogenous coordinates.
vec4 world_pos = volume_world_matrix * model_pos;
gl_Position = projection_matrix * view_model_matrix * model_pos;
// Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded.
clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z);
}

View File

@ -1,8 +0,0 @@
#version 110
uniform vec4 uniform_color;
void main()
{
gl_FragColor = uniform_color;
}

View File

@ -1,22 +0,0 @@
#version 110
uniform bool use_fixed_screen_size;
uniform float zoom;
uniform float point_size;
uniform float near_plane_height;
float fixed_screen_size()
{
return point_size;
}
float fixed_world_size()
{
return (gl_Position.w == 1.0) ? zoom * near_plane_height * point_size : near_plane_height * point_size / gl_Position.w;
}
void main()
{
gl_Position = ftransform();
gl_PointSize = use_fixed_screen_size ? fixed_screen_size() : fixed_world_size();
}

View File

@ -1,22 +0,0 @@
// version 120 is needed for gl_PointCoord
#version 120
uniform vec4 uniform_color;
uniform float percent_outline_radius;
uniform float percent_center_radius;
vec4 calc_color(float radius, vec4 color)
{
return ((radius < percent_center_radius) || (radius > 1.0 - percent_outline_radius)) ?
vec4(0.5 * color.rgb, color.a) : color;
}
void main()
{
vec2 pos = (gl_PointCoord - 0.5) * 2.0;
float radius = length(pos);
if (radius > 1.0)
discard;
gl_FragColor = calc_color(radius, uniform_color);
}

View File

@ -1,22 +0,0 @@
#version 120
uniform bool use_fixed_screen_size;
uniform float zoom;
uniform float point_size;
uniform float near_plane_height;
float fixed_screen_size()
{
return point_size;
}
float fixed_world_size()
{
return (gl_Position.w == 1.0) ? zoom * near_plane_height * point_size : near_plane_height * point_size / gl_Position.w;
}
void main()
{
gl_Position = ftransform();
gl_PointSize = use_fixed_screen_size ? fixed_screen_size() : fixed_world_size();
}

View File

@ -7,15 +7,15 @@ uniform sampler2D texture;
uniform bool transparent_background; uniform bool transparent_background;
uniform bool svg_source; uniform bool svg_source;
varying vec2 tex_coords; varying vec2 tex_coord;
vec4 svg_color() vec4 svg_color()
{ {
// takes foreground from texture // takes foreground from texture
vec4 fore_color = texture2D(texture, tex_coords); vec4 fore_color = texture2D(texture, tex_coord);
// calculates radial gradient // 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))))); vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coord.xy) - vec2(0.5)))));
// blends foreground with background // blends foreground with background
return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0); return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0);
@ -24,7 +24,7 @@ vec4 svg_color()
vec4 non_svg_color() vec4 non_svg_color()
{ {
// takes foreground from texture // takes foreground from texture
vec4 color = texture2D(texture, tex_coords); vec4 color = texture2D(texture, tex_coord);
return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a); return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a);
} }

View File

@ -1,9 +1,9 @@
#version 110 #version 110
varying vec2 tex_coords; varying vec2 tex_coord;
void main() void main()
{ {
gl_Position = ftransform(); gl_Position = ftransform();
tex_coords = gl_MultiTexCoord0.xy; tex_coord = gl_MultiTexCoord0.xy;
} }

View File

@ -0,0 +1,15 @@
#version 110
attribute vec3 v_position;
attribute vec2 v_tex_coord;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
varying vec2 tex_coord;
void main()
{
tex_coord = v_tex_coord;
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
}

View File

@ -0,0 +1,47 @@
#version 110
#define INTENSITY_CORRECTION 0.6
// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31)
const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929);
#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION)
#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION)
#define LIGHT_TOP_SHININESS 20.0
// normalized values for (1./1.43, 0.2/1.43, 1./1.43)
const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074);
#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION)
#define INTENSITY_AMBIENT 0.3
attribute vec3 v_position;
attribute vec3 v_normal;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat3 normal_matrix;
// x = tainted, y = specular;
varying vec2 intensity;
varying vec3 world_position;
void main()
{
// First transform the normal into camera space and normalize the result.
vec3 normal = normalize(normal_matrix * v_normal);
// Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex.
// Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range.
float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0);
intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
vec4 position = view_model_matrix * vec4(v_position, 1.0);
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS);
// Perform the same lighting calculation for the 2nd light source (no specular applied).
NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0);
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
world_position = v_position;
gl_Position = projection_matrix * position;
}

View File

@ -0,0 +1,60 @@
#version 110
#define INTENSITY_CORRECTION 0.6
const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929);
#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION)
#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION)
#define LIGHT_TOP_SHININESS 20.0
const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074);
#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION)
//#define LIGHT_FRONT_SPECULAR (0.0 * INTENSITY_CORRECTION)
//#define LIGHT_FRONT_SHININESS 5.0
#define INTENSITY_AMBIENT 0.3
attribute vec3 v_position;
attribute vec3 v_normal;
attribute vec2 v_tex_coord;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat3 normal_matrix;
uniform mat4 volume_world_matrix;
uniform float object_max_z;
// x = tainted, y = specular;
varying vec2 intensity;
varying float object_z;
void main()
{
// =====================================================
// NOTE:
// when object_max_z > 0.0 we are rendering the overlay
// when object_max_z == 0.0 we are rendering the volumes
// =====================================================
// First transform the normal into camera space and normalize the result.
vec3 normal = (object_max_z > 0.0) ? vec3(0.0, 0.0, 1.0) : normalize(normal_matrix * v_normal);
// Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex.
// Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range.
float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0);
intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
vec4 position = view_model_matrix * vec4(v_position, 1.0);
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS);
// Perform the same lighting calculation for the 2nd light source (no specular)
NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0);
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
// Scaled to widths of the Z texture.
object_z = (object_max_z > 0.0) ? object_max_z * v_tex_coord.y : (volume_world_matrix * vec4(v_position, 1.0)).z;
gl_Position = projection_matrix * position;
}

View File

@ -95,10 +95,10 @@ public:
bool all_paths_inside_vertices_and_normals_interleaved(const std::vector<float>& paths, const Eigen::AlignedBox<float, 3>& bbox, bool ignore_bottom = true) const; bool all_paths_inside_vertices_and_normals_interleaved(const std::vector<float>& paths, const Eigen::AlignedBox<float, 3>& bbox, bool ignore_bottom = true) const;
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
const std::pair<std::vector<Vec2d>, std::vector<Vec2d>>& top_bottom_convex_hull_decomposition_scene() const { return m_top_bottom_convex_hull_decomposition_scene; } const std::pair<std::vector<Vec2d>, std::vector<Vec2d>>& top_bottom_convex_hull_decomposition_scene() const { return m_top_bottom_convex_hull_decomposition_scene; }
const std::pair<std::vector<Vec2d>, std::vector<Vec2d>>& top_bottom_convex_hull_decomposition_bed() const { return m_top_bottom_convex_hull_decomposition_bed; } const std::pair<std::vector<Vec2d>, std::vector<Vec2d>>& top_bottom_convex_hull_decomposition_bed() const { return m_top_bottom_convex_hull_decomposition_bed; }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
private: private:
// Source definition of the print bed geometry (PrintConfig::bed_shape) // Source definition of the print bed geometry (PrintConfig::bed_shape)

View File

@ -1155,13 +1155,13 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
} }
print.throw_if_canceled(); print.throw_if_canceled();
// Starting now, the G-code find / replace post-processor will be enabled.
file.find_replace_enable();
// adds tags for time estimators // adds tags for time estimators
if (print.config().remaining_times.value) if (print.config().remaining_times.value)
file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::First_Line_M73_Placeholder).c_str()); file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::First_Line_M73_Placeholder).c_str());
// Starting now, the G-code find / replace post-processor will be enabled.
file.find_replace_enable();
// Prepare the helper object for replacing placeholders in custom G-code and output filename. // Prepare the helper object for replacing placeholders in custom G-code and output filename.
m_placeholder_parser = print.placeholder_parser(); m_placeholder_parser = print.placeholder_parser();
m_placeholder_parser.update_timestamp(); m_placeholder_parser.update_timestamp();
@ -1442,6 +1442,10 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
file.write(m_writer.update_progress(m_layer_count, m_layer_count, true)); // 100% file.write(m_writer.update_progress(m_layer_count, m_layer_count, true)); // 100%
file.write(m_writer.postamble()); file.write(m_writer.postamble());
// From now to the end of G-code, the G-code find / replace post-processor will be disabled.
// Thus the PrusaSlicer generated config will NOT be processed by the G-code post-processor, see GH issue #7952.
file.find_replace_supress();
// adds tags for time estimators // adds tags for time estimators
if (print.config().remaining_times.value) if (print.config().remaining_times.value)
file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Last_Line_M73_Placeholder).c_str()); file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Last_Line_M73_Placeholder).c_str());
@ -1464,10 +1468,6 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
file.write_format("; total toolchanges = %i\n", print.m_print_statistics.total_toolchanges); file.write_format("; total toolchanges = %i\n", print.m_print_statistics.total_toolchanges);
file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Estimated_Printing_Time_Placeholder).c_str()); file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Estimated_Printing_Time_Placeholder).c_str());
// From now to the end of G-code, the G-code find / replace post-processor will be disabled.
// Thus the PrusaSlicer generated config will NOT be processed by the G-code post-processor, see GH issue #7952.
file.find_replace_supress();
// Append full config, delimited by two 'phony' configuration keys prusaslicer_config = begin and prusaslicer_config = end. // Append full config, delimited by two 'phony' configuration keys prusaslicer_config = begin and prusaslicer_config = end.
// The delimiters are structured as configuration key / value pairs to be parsable by older versions of PrusaSlicer G-code viewer. // The delimiters are structured as configuration key / value pairs to be parsable by older versions of PrusaSlicer G-code viewer.
{ {

View File

@ -13,6 +13,8 @@
#include <unordered_set> #include <unordered_set>
#include <boost/range/adaptor/reversed.hpp> #include <boost/range/adaptor/reversed.hpp>
//#define AVOID_CROSSING_PERIMETERS_DEBUG_OUTPUT
namespace Slic3r { namespace Slic3r {
struct TravelPoint struct TravelPoint
@ -354,8 +356,6 @@ static Polyline to_polyline(const std::vector<TravelPoint> &travel)
return result; return result;
} }
// #define AVOID_CROSSING_PERIMETERS_DEBUG_OUTPUT
#ifdef AVOID_CROSSING_PERIMETERS_DEBUG_OUTPUT #ifdef AVOID_CROSSING_PERIMETERS_DEBUG_OUTPUT
static void export_travel_to_svg(const Polygons &boundary, static void export_travel_to_svg(const Polygons &boundary,
const Line &original_travel, const Line &original_travel,
@ -521,6 +521,25 @@ static float get_perimeter_spacing_external(const Layer &layer)
return perimeter_spacing; return perimeter_spacing;
} }
// Returns average perimeter width calculated from all LayerRegion within the layer.
static float get_external_perimeter_width(const Layer &layer)
{
size_t regions_count = 0;
float perimeter_width = 0.f;
for (const LayerRegion *layer_region : layer.regions())
if (layer_region != nullptr && !layer_region->slices.empty()) {
perimeter_width += float(layer_region->flow(frExternalPerimeter).scaled_width());
++regions_count;
}
assert(perimeter_width >= 0.f);
if (regions_count != 0)
perimeter_width /= float(regions_count);
else
perimeter_width = get_default_perimeter_spacing(*layer.object());
return perimeter_width;
}
// Called by avoid_perimeters() and by simplify_travel_heuristics(). // Called by avoid_perimeters() and by simplify_travel_heuristics().
static size_t avoid_perimeters_inner(const AvoidCrossingPerimeters::Boundary &boundary, static size_t avoid_perimeters_inner(const AvoidCrossingPerimeters::Boundary &boundary,
const Point &start, const Point &start,
@ -659,22 +678,22 @@ static size_t avoid_perimeters(const AvoidCrossingPerimeters::Boundary &boundary
// Check if anyone of ExPolygons contains whole travel. // Check if anyone of ExPolygons contains whole travel.
// called by need_wipe() and AvoidCrossingPerimeters::travel_to() // called by need_wipe() and AvoidCrossingPerimeters::travel_to()
// FIXME Lukas H.: Maybe similar approach could also be used for ExPolygon::contains() // FIXME Lukas H.: Maybe similar approach could also be used for ExPolygon::contains()
static bool any_expolygon_contains(const ExPolygons &ex_polygons, static bool any_expolygon_contains(const ExPolygons &lslices_offset,
const std::vector<BoundingBox> &ex_polygons_bboxes, const std::vector<BoundingBox> &lslices_offset_bboxes,
const EdgeGrid::Grid &grid_lslice, const EdgeGrid::Grid &grid_lslices_offset,
const Line &travel) const Line &travel)
{ {
assert(ex_polygons.size() == ex_polygons_bboxes.size()); assert(lslices_offset.size() == lslices_offset_bboxes.size());
if(!grid_lslice.bbox().contains(travel.a) || !grid_lslice.bbox().contains(travel.b)) if(!grid_lslices_offset.bbox().contains(travel.a) || !grid_lslices_offset.bbox().contains(travel.b))
return false; return false;
FirstIntersectionVisitor visitor(grid_lslice); FirstIntersectionVisitor visitor(grid_lslices_offset);
visitor.pt_current = &travel.a; visitor.pt_current = &travel.a;
visitor.pt_next = &travel.b; visitor.pt_next = &travel.b;
grid_lslice.visit_cells_intersecting_line(*visitor.pt_current, *visitor.pt_next, visitor); grid_lslices_offset.visit_cells_intersecting_line(*visitor.pt_current, *visitor.pt_next, visitor);
if (!visitor.intersect) { if (!visitor.intersect) {
for (const ExPolygon &ex_polygon : ex_polygons) { for (const ExPolygon &ex_polygon : lslices_offset) {
const BoundingBox &bbox = ex_polygons_bboxes[&ex_polygon - &ex_polygons.front()]; const BoundingBox &bbox = lslices_offset_bboxes[&ex_polygon - &lslices_offset.front()];
if (bbox.contains(travel.a) && bbox.contains(travel.b) && ex_polygon.contains(travel.a)) if (bbox.contains(travel.a) && bbox.contains(travel.b) && ex_polygon.contains(travel.a))
return true; return true;
} }
@ -684,18 +703,18 @@ static bool any_expolygon_contains(const ExPolygons &ex_polygons,
// Check if anyone of ExPolygons contains whole travel. // Check if anyone of ExPolygons contains whole travel.
// called by need_wipe() // called by need_wipe()
static bool any_expolygon_contains(const ExPolygons &ex_polygons, const std::vector<BoundingBox> &ex_polygons_bboxes, const EdgeGrid::Grid &grid_lslice, const Polyline &travel) static bool any_expolygon_contains(const ExPolygons &ex_polygons, const std::vector<BoundingBox> &ex_polygons_bboxes, const EdgeGrid::Grid &grid_lslice_offset, const Polyline &travel)
{ {
assert(ex_polygons.size() == ex_polygons_bboxes.size()); assert(ex_polygons.size() == ex_polygons_bboxes.size());
if(std::any_of(travel.points.begin(), travel.points.end(), [&grid_lslice](const Point &point) { return !grid_lslice.bbox().contains(point); })) if(std::any_of(travel.points.begin(), travel.points.end(), [&grid_lslice_offset](const Point &point) { return !grid_lslice_offset.bbox().contains(point); }))
return false; return false;
FirstIntersectionVisitor visitor(grid_lslice); FirstIntersectionVisitor visitor(grid_lslice_offset);
bool any_intersection = false; bool any_intersection = false;
for (size_t line_idx = 1; line_idx < travel.size(); ++line_idx) { for (size_t line_idx = 1; line_idx < travel.size(); ++line_idx) {
visitor.pt_current = &travel.points[line_idx - 1]; visitor.pt_current = &travel.points[line_idx - 1];
visitor.pt_next = &travel.points[line_idx]; visitor.pt_next = &travel.points[line_idx];
grid_lslice.visit_cells_intersecting_line(*visitor.pt_current, *visitor.pt_next, visitor); grid_lslice_offset.visit_cells_intersecting_line(*visitor.pt_current, *visitor.pt_next, visitor);
any_intersection = visitor.intersect; any_intersection = visitor.intersect;
if (any_intersection) break; if (any_intersection) break;
} }
@ -712,13 +731,13 @@ static bool any_expolygon_contains(const ExPolygons &ex_polygons, const std::vec
} }
static bool need_wipe(const GCode &gcodegen, static bool need_wipe(const GCode &gcodegen,
const EdgeGrid::Grid &grid_lslice, const ExPolygons &lslices_offset,
const std::vector<BoundingBox> &lslices_offset_bboxes,
const EdgeGrid::Grid &grid_lslices_offset,
const Line &original_travel, const Line &original_travel,
const Polyline &result_travel, const Polyline &result_travel,
const size_t intersection_count) const size_t intersection_count)
{ {
const ExPolygons &lslices = gcodegen.layer()->lslices;
const std::vector<BoundingBox> &lslices_bboxes = gcodegen.layer()->lslices_bboxes;
bool z_lift_enabled = gcodegen.config().retract_lift.get_at(gcodegen.writer().extruder()->id()) > 0.; bool z_lift_enabled = gcodegen.config().retract_lift.get_at(gcodegen.writer().extruder()->id()) > 0.;
bool wipe_needed = false; bool wipe_needed = false;
@ -728,16 +747,16 @@ static bool need_wipe(const GCode &gcodegen,
// The original layer is intersected with defined boundaries. Then it is necessary to make a detailed test. // The original layer is intersected with defined boundaries. Then it is necessary to make a detailed test.
// If the z-lift is enabled, then a wipe is needed when the original travel leads above the holes. // If the z-lift is enabled, then a wipe is needed when the original travel leads above the holes.
if (z_lift_enabled) { if (z_lift_enabled) {
if (any_expolygon_contains(lslices, lslices_bboxes, grid_lslice, original_travel)) { if (any_expolygon_contains(lslices_offset, lslices_offset_bboxes, grid_lslices_offset, original_travel)) {
// Check if original_travel and result_travel are not same. // Check if original_travel and result_travel are not same.
// If both are the same, then it is possible to skip testing of result_travel // If both are the same, then it is possible to skip testing of result_travel
wipe_needed = !(result_travel.size() > 2 && result_travel.first_point() == original_travel.a && result_travel.last_point() == original_travel.b) && wipe_needed = !(result_travel.size() > 2 && result_travel.first_point() == original_travel.a && result_travel.last_point() == original_travel.b) &&
!any_expolygon_contains(lslices, lslices_bboxes, grid_lslice, result_travel); !any_expolygon_contains(lslices_offset, lslices_offset_bboxes, grid_lslices_offset, result_travel);
} else { } else {
wipe_needed = true; wipe_needed = true;
} }
} else { } else {
wipe_needed = !any_expolygon_contains(lslices, lslices_bboxes, grid_lslice, result_travel); wipe_needed = !any_expolygon_contains(lslices_offset, lslices_offset_bboxes, grid_lslices_offset, result_travel);
} }
} }
@ -1163,10 +1182,8 @@ Polyline AvoidCrossingPerimeters::travel_to(const GCode &gcodegen, const Point &
Vec2d startf = start.cast<double>(); Vec2d startf = start.cast<double>();
Vec2d endf = end .cast<double>(); Vec2d endf = end .cast<double>();
const ExPolygons &lslices = gcodegen.layer()->lslices;
const std::vector<BoundingBox> &lslices_bboxes = gcodegen.layer()->lslices_bboxes;
bool is_support_layer = dynamic_cast<const SupportLayer *>(gcodegen.layer()) != nullptr; bool is_support_layer = dynamic_cast<const SupportLayer *>(gcodegen.layer()) != nullptr;
if (!use_external && (is_support_layer || (!lslices.empty() && !any_expolygon_contains(lslices, lslices_bboxes, m_grid_lslice, travel)))) { if (!use_external && (is_support_layer || (!m_lslices_offset.empty() && !any_expolygon_contains(m_lslices_offset, m_lslices_offset_bboxes, m_grid_lslices_offset, travel)))) {
// Initialize m_internal only when it is necessary. // Initialize m_internal only when it is necessary.
if (m_internal.boundaries.empty()) if (m_internal.boundaries.empty())
init_boundary(&m_internal, to_polygons(get_boundary(*gcodegen.layer()))); init_boundary(&m_internal, to_polygons(get_boundary(*gcodegen.layer())));
@ -1216,7 +1233,7 @@ Polyline AvoidCrossingPerimeters::travel_to(const GCode &gcodegen, const Point &
} else if (max_detour_length_exceeded) { } else if (max_detour_length_exceeded) {
*could_be_wipe_disabled = false; *could_be_wipe_disabled = false;
} else } else
*could_be_wipe_disabled = !need_wipe(gcodegen, m_grid_lslice, travel, result_pl, travel_intersection_count); *could_be_wipe_disabled = !need_wipe(gcodegen, m_lslices_offset, m_lslices_offset_bboxes, m_grid_lslices_offset, travel, result_pl, travel_intersection_count);
return result_pl; return result_pl;
} }
@ -1227,13 +1244,21 @@ void AvoidCrossingPerimeters::init_layer(const Layer &layer)
{ {
m_internal.clear(); m_internal.clear();
m_external.clear(); m_external.clear();
m_lslices_offset.clear();
m_lslices_offset_bboxes.clear();
float perimeter_offset = -get_external_perimeter_width(layer) / float(2.);
m_lslices_offset = offset_ex(layer.lslices, perimeter_offset);
m_lslices_offset_bboxes.reserve(m_lslices_offset.size());
for (const ExPolygon &ex_poly : m_lslices_offset)
m_lslices_offset_bboxes.emplace_back(get_extents(ex_poly));
BoundingBox bbox_slice(get_extents(layer.lslices)); BoundingBox bbox_slice(get_extents(layer.lslices));
bbox_slice.offset(SCALED_EPSILON); bbox_slice.offset(SCALED_EPSILON);
m_grid_lslice.set_bbox(bbox_slice); m_grid_lslices_offset.set_bbox(bbox_slice);
//FIXME 1mm grid? m_grid_lslices_offset.create(m_lslices_offset, coord_t(scale_(1.)));
m_grid_lslice.create(layer.lslices, coord_t(scale_(1.)));
} }
#if 0 #if 0

View File

@ -58,8 +58,11 @@ private:
// we enable it by default for the first travel move in print // we enable it by default for the first travel move in print
bool m_disabled_once { true }; bool m_disabled_once { true };
// Lslices offseted by half an external perimeter width. Used for detection if line or polyline is inside of any polygon.
ExPolygons m_lslices_offset;
std::vector<BoundingBox> m_lslices_offset_bboxes;
// Used for detection of line or polyline is inside of any polygon. // Used for detection of line or polyline is inside of any polygon.
EdgeGrid::Grid m_grid_lslice; EdgeGrid::Grid m_grid_lslices_offset;
// Store all needed data for travels inside object // Store all needed data for travels inside object
Boundary m_internal; Boundary m_internal;
// Store all needed data for travels outside object // Store all needed data for travels outside object

View File

@ -66,10 +66,12 @@
#define ENABLE_OBJECT_MANIPULATOR_FOCUS (1 && ENABLE_2_5_0_ALPHA1) #define ENABLE_OBJECT_MANIPULATOR_FOCUS (1 && ENABLE_2_5_0_ALPHA1)
// Enable removal of wipe tower magic object_id equal to 1000 // Enable removal of wipe tower magic object_id equal to 1000
#define ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL (1 && ENABLE_2_5_0_ALPHA1) #define ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL (1 && ENABLE_2_5_0_ALPHA1)
// Enable removal of old OpenGL render calls // Enable removal of legacy OpenGL calls
#define ENABLE_GLBEGIN_GLEND_REMOVAL (1 && ENABLE_2_5_0_ALPHA1) #define ENABLE_LEGACY_OPENGL_REMOVAL (1 && ENABLE_2_5_0_ALPHA1)
// Enable replace GLIndexedVertexArray with GLModel // Enable using vertex attributes and matrices in shaders
#define ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL (1 && ENABLE_GLBEGIN_GLEND_REMOVAL) #define ENABLE_GL_SHADERS_ATTRIBUTES (1 && ENABLE_LEGACY_OPENGL_REMOVAL)
// Shows an imgui dialog with GLModel statistics data
#define ENABLE_GLMODEL_STATISTICS (0 && ENABLE_LEGACY_OPENGL_REMOVAL)
// Enable show non-manifold edges // Enable show non-manifold edges
#define ENABLE_SHOW_NON_MANIFOLD_EDGES (1 && ENABLE_2_5_0_ALPHA1) #define ENABLE_SHOW_NON_MANIFOLD_EDGES (1 && ENABLE_2_5_0_ALPHA1)
// Enable rework of Reload from disk command // Enable rework of Reload from disk command

View File

@ -11,6 +11,10 @@
#include "GUI_App.hpp" #include "GUI_App.hpp"
#include "GLCanvas3D.hpp" #include "GLCanvas3D.hpp"
#if ENABLE_GL_SHADERS_ATTRIBUTES
#include "Plater.hpp"
#include "Camera.hpp"
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#include <GL/glew.h> #include <GL/glew.h>
@ -27,7 +31,7 @@ static const Slic3r::ColorRGBA DEFAULT_TRANSPARENT_GRID_COLOR = { 0.9f, 0.9f, 0
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
bool GeometryBuffer::set_from_triangles(const std::vector<Vec2f> &triangles, float z) bool GeometryBuffer::set_from_triangles(const std::vector<Vec2f> &triangles, float z)
{ {
if (triangles.empty()) { if (triangles.empty()) {
@ -96,7 +100,7 @@ const float* GeometryBuffer::get_vertices_data() const
{ {
return (m_vertices.size() > 0) ? (const float*)m_vertices.data() : nullptr; return (m_vertices.size() > 0) ? (const float*)m_vertices.data() : nullptr;
} }
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
const float Bed3D::Axes::DefaultStemRadius = 0.5f; const float Bed3D::Axes::DefaultStemRadius = 0.5f;
const float Bed3D::Axes::DefaultStemLength = 25.0f; const float Bed3D::Axes::DefaultStemLength = 25.0f;
@ -105,17 +109,32 @@ const float Bed3D::Axes::DefaultTipLength = 5.0f;
void Bed3D::Axes::render() void Bed3D::Axes::render()
{ {
#if ENABLE_GL_SHADERS_ATTRIBUTES
auto render_axis = [this](GLShaderProgram* shader, const Transform3d& transform) {
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d matrix = camera.get_view_matrix() * transform;
shader->set_uniform("view_model_matrix", matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
shader->set_uniform("normal_matrix", (Matrix3d)matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
auto render_axis = [this](const Transform3f& transform) { auto render_axis = [this](const Transform3f& transform) {
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glMultMatrixf(transform.data())); glsafe(::glMultMatrixf(transform.data()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_arrow.render(); m_arrow.render();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
}; };
if (!m_arrow.is_initialized()) if (!m_arrow.is_initialized())
m_arrow.init_from(stilized_arrow(16, DefaultTipRadius, DefaultTipLength, DefaultStemRadius, m_stem_length)); m_arrow.init_from(stilized_arrow(16, DefaultTipRadius, DefaultTipLength, DefaultStemRadius, m_stem_length));
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
@ -125,28 +144,40 @@ void Bed3D::Axes::render()
shader->set_uniform("emission_factor", 0.0f); shader->set_uniform("emission_factor", 0.0f);
// x axis // x axis
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_arrow.set_color(ColorRGBA::X()); m_arrow.set_color(ColorRGBA::X());
#else #else
m_arrow.set_color(-1, ColorRGBA::X()); m_arrow.set_color(-1, ColorRGBA::X());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_axis(shader, Geometry::assemble_transform(m_origin, { 0.0, 0.5 * M_PI, 0.0 }));
#else
render_axis(Geometry::assemble_transform(m_origin, { 0.0, 0.5 * M_PI, 0.0 }).cast<float>()); render_axis(Geometry::assemble_transform(m_origin, { 0.0, 0.5 * M_PI, 0.0 }).cast<float>());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
// y axis // y axis
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_arrow.set_color(ColorRGBA::Y()); m_arrow.set_color(ColorRGBA::Y());
#else #else
m_arrow.set_color(-1, ColorRGBA::Y()); m_arrow.set_color(-1, ColorRGBA::Y());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_axis(shader, Geometry::assemble_transform(m_origin, { -0.5 * M_PI, 0.0, 0.0 }));
#else
render_axis(Geometry::assemble_transform(m_origin, { -0.5 * M_PI, 0.0, 0.0 }).cast<float>()); render_axis(Geometry::assemble_transform(m_origin, { -0.5 * M_PI, 0.0, 0.0 }).cast<float>());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
// z axis // z axis
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_arrow.set_color(ColorRGBA::Z()); m_arrow.set_color(ColorRGBA::Z());
#else #else
m_arrow.set_color(-1, ColorRGBA::Z()); m_arrow.set_color(-1, ColorRGBA::Z());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_axis(shader, Geometry::assemble_transform(m_origin));
#else
render_axis(Geometry::assemble_transform(m_origin).cast<float>()); render_axis(Geometry::assemble_transform(m_origin).cast<float>());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
shader->stop_using(); shader->stop_using();
@ -200,7 +231,7 @@ bool Bed3D::set_shape(const Pointfs& bed_shape, const double max_print_height, c
m_model_filename = model_filename; m_model_filename = model_filename;
m_extended_bounding_box = this->calc_extended_bounding_box(); m_extended_bounding_box = this->calc_extended_bounding_box();
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_contour = ExPolygon(Polygon::new_scale(bed_shape)); m_contour = ExPolygon(Polygon::new_scale(bed_shape));
m_polygon = offset(m_contour.contour, (float)m_contour.contour.bounding_box().radius() * 1.7f, jtRound, scale_(0.5)).front(); m_polygon = offset(m_contour.contour, (float)m_contour.contour.bounding_box().radius() * 1.7f, jtRound, scale_(0.5)).front();
@ -217,7 +248,7 @@ bool Bed3D::set_shape(const Pointfs& bed_shape, const double max_print_height, c
m_polygon = offset(poly.contour, (float)bed_bbox.radius() * 1.7f, jtRound, scale_(0.5)).front(); m_polygon = offset(poly.contour, (float)bed_bbox.radius() * 1.7f, jtRound, scale_(0.5)).front();
this->release_VBOs(); this->release_VBOs();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
m_texture.reset(); m_texture.reset();
m_model.reset(); m_model.reset();
@ -239,6 +270,17 @@ Point Bed3D::point_projection(const Point& point) const
return m_polygon.point_projection(point); return m_polygon.point_projection(point);
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void Bed3D::render(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture)
{
render_internal(canvas, view_matrix, projection_matrix, bottom, scale_factor, show_axes, show_texture, false);
}
void Bed3D::render_for_picking(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor)
{
render_internal(canvas, view_matrix, projection_matrix, bottom, scale_factor, false, false, true);
}
#else
void Bed3D::render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture) void Bed3D::render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture)
{ {
render_internal(canvas, bottom, scale_factor, show_axes, show_texture, false); render_internal(canvas, bottom, scale_factor, show_axes, show_texture, false);
@ -248,9 +290,15 @@ void Bed3D::render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_fact
{ {
render_internal(canvas, bottom, scale_factor, false, false, true); render_internal(canvas, bottom, scale_factor, false, false, true);
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_GL_SHADERS_ATTRIBUTES
void Bed3D::render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor,
bool show_axes, bool show_texture, bool picking)
#else
void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor, void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor,
bool show_axes, bool show_texture, bool picking) bool show_axes, bool show_texture, bool picking)
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
{ {
m_scale_factor = scale_factor; m_scale_factor = scale_factor;
@ -259,17 +307,23 @@ void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor,
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_model.set_color(picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR); m_model.set_color(picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR);
#else #else
m_model.set_color(-1, picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR); m_model.set_color(-1, picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
switch (m_type) switch (m_type)
{ {
#if ENABLE_GL_SHADERS_ATTRIBUTES
case Type::System: { render_system(canvas, view_matrix, projection_matrix, bottom, show_texture); break; }
default:
case Type::Custom: { render_custom(canvas, view_matrix, projection_matrix, bottom, show_texture, picking); break; }
#else
case Type::System: { render_system(canvas, bottom, show_texture); break; } case Type::System: { render_system(canvas, bottom, show_texture); break; }
default: default:
case Type::Custom: { render_custom(canvas, bottom, show_texture, picking); break; } case Type::Custom: { render_custom(canvas, bottom, show_texture, picking); break; }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
} }
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
@ -298,7 +352,7 @@ BoundingBoxf3 Bed3D::calc_extended_bounding_box() const
return out; return out;
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void Bed3D::init_triangles() void Bed3D::init_triangles()
{ {
if (m_triangles.is_initialized()) if (m_triangles.is_initialized())
@ -312,7 +366,7 @@ void Bed3D::init_triangles()
return; return;
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3T2, GLModel::Geometry::index_type(triangles.size()) }; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3T2 };
init_data.reserve_vertices(triangles.size()); init_data.reserve_vertices(triangles.size());
init_data.reserve_indices(triangles.size() / 3); init_data.reserve_indices(triangles.size() / 3);
@ -336,12 +390,8 @@ void Bed3D::init_triangles()
const Vec3f p = { v.x(), v.y(), GROUND_Z }; const Vec3f p = { v.x(), v.y(), GROUND_Z };
init_data.add_vertex(p, (Vec2f)(v - min).cwiseProduct(inv_size).eval()); init_data.add_vertex(p, (Vec2f)(v - min).cwiseProduct(inv_size).eval());
++vertices_counter; ++vertices_counter;
if (vertices_counter % 3 == 0) { if (vertices_counter % 3 == 0)
if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) init_data.add_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1);
init_data.add_ushort_triangle((unsigned short)vertices_counter - 3, (unsigned short)vertices_counter - 2, (unsigned short)vertices_counter - 1);
else
init_data.add_uint_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1);
}
} }
m_triangles.init_from(std::move(init_data)); m_triangles.init_from(std::move(init_data));
@ -380,18 +430,15 @@ void Bed3D::init_gridlines()
std::copy(contour_lines.begin(), contour_lines.end(), std::back_inserter(gridlines)); std::copy(contour_lines.begin(), contour_lines.end(), std::back_inserter(gridlines));
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::index_type(2 * gridlines.size()) }; init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(2 * gridlines.size()); init_data.reserve_vertices(2 * gridlines.size());
init_data.reserve_indices(2 * gridlines.size()); init_data.reserve_indices(2 * gridlines.size());
for (const Line& l : gridlines) { for (const Slic3r::Line& l : gridlines) {
init_data.add_vertex(Vec3f(unscale<float>(l.a.x()), unscale<float>(l.a.y()), GROUND_Z)); init_data.add_vertex(Vec3f(unscale<float>(l.a.x()), unscale<float>(l.a.y()), GROUND_Z));
init_data.add_vertex(Vec3f(unscale<float>(l.b.x()), unscale<float>(l.b.y()), GROUND_Z)); init_data.add_vertex(Vec3f(unscale<float>(l.b.x()), unscale<float>(l.b.y()), GROUND_Z));
const unsigned int vertices_counter = (unsigned int)init_data.vertices_count(); const unsigned int vertices_counter = (unsigned int)init_data.vertices_count();
if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) init_data.add_line(vertices_counter - 2, vertices_counter - 1);
init_data.add_ushort_line((unsigned short)vertices_counter - 2, (unsigned short)vertices_counter - 1);
else
init_data.add_uint_line(vertices_counter - 2, vertices_counter - 1);
} }
m_gridlines.init_from(std::move(init_data)); m_gridlines.init_from(std::move(init_data));
@ -429,7 +476,7 @@ void Bed3D::calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox)
if (!m_gridlines.set_from_lines(gridlines, GROUND_Z)) if (!m_gridlines.set_from_lines(gridlines, GROUND_Z))
BOOST_LOG_TRIVIAL(error) << "Unable to create bed grid lines\n"; BOOST_LOG_TRIVIAL(error) << "Unable to create bed grid lines\n";
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// Try to match the print bed shape with the shape of an active profile. If such a match exists, // Try to match the print bed shape with the shape of an active profile. If such a match exists,
// return the print bed model. // return the print bed model.
@ -461,6 +508,16 @@ void Bed3D::render_axes()
m_axes.render(); m_axes.render();
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void Bed3D::render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture)
{
if (!bottom)
render_model(view_matrix, projection_matrix);
if (show_texture)
render_texture(bottom, canvas);
}
#else
void Bed3D::render_system(GLCanvas3D& canvas, bool bottom, bool show_texture) void Bed3D::render_system(GLCanvas3D& canvas, bool bottom, bool show_texture)
{ {
if (!bottom) if (!bottom)
@ -469,6 +526,7 @@ void Bed3D::render_system(GLCanvas3D& canvas, bool bottom, bool show_texture)
if (show_texture) if (show_texture)
render_texture(bottom, canvas); render_texture(bottom, canvas);
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas)
{ {
@ -531,12 +589,21 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas)
canvas.request_extra_frame(); canvas.request_extra_frame();
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
init_triangles(); init_triangles();
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("printbed_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("printbed"); GLShaderProgram* shader = wxGetApp().get_shader("printbed");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
shader->set_uniform("transparent_background", bottom); shader->set_uniform("transparent_background", bottom);
shader->set_uniform("svg_source", boost::algorithm::iends_with(m_texture.get_source(), ".svg")); shader->set_uniform("svg_source", boost::algorithm::iends_with(m_texture.get_source(), ".svg"));
@ -627,20 +694,24 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas)
shader->stop_using(); shader->stop_using();
} }
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void Bed3D::render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix)
#else
void Bed3D::render_model() void Bed3D::render_model()
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
{ {
if (m_model_filename.empty()) if (m_model_filename.empty())
return; return;
if (m_model.get_filename() != m_model_filename && m_model.init_from_file(m_model_filename)) { if (m_model.get_filename() != m_model_filename && m_model.init_from_file(m_model_filename)) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_model.set_color(DEFAULT_MODEL_COLOR); m_model.set_color(DEFAULT_MODEL_COLOR);
#else #else
m_model.set_color(-1, DEFAULT_MODEL_COLOR); m_model.set_color(-1, DEFAULT_MODEL_COLOR);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// move the model so that its origin (0.0, 0.0, 0.0) goes into the bed shape center and a bit down to avoid z-fighting with the texture quad // move the model so that its origin (0.0, 0.0, 0.0) goes into the bed shape center and a bit down to avoid z-fighting with the texture quad
m_model_offset = to_3d(m_build_volume.bounding_volume2d().center(), -0.03); m_model_offset = to_3d(m_build_volume.bounding_volume2d().center(), -0.03);
@ -650,20 +721,37 @@ void Bed3D::render_model()
} }
if (!m_model.get_filename().empty()) { if (!m_model.get_filename().empty()) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
shader->set_uniform("emission_factor", 0.0f); shader->set_uniform("emission_factor", 0.0f);
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d matrix = view_matrix * Geometry::assemble_transform(m_model_offset);
shader->set_uniform("view_model_matrix", matrix);
shader->set_uniform("projection_matrix", projection_matrix);
shader->set_uniform("normal_matrix", (Matrix3d)matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(m_model_offset.x(), m_model_offset.y(), m_model_offset.z())); glsafe(::glTranslated(m_model_offset.x(), m_model_offset.y(), m_model_offset.z()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_model.render(); m_model.render();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
shader->stop_using(); shader->stop_using();
} }
} }
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void Bed3D::render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking)
#else
void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking) void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking)
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
{ {
if (m_texture_filename.empty() && m_model_filename.empty()) { if (m_texture_filename.empty() && m_model_filename.empty()) {
render_default(bottom, picking); render_default(bottom, picking);
@ -671,7 +759,11 @@ void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bo
} }
if (!bottom) if (!bottom)
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_model(view_matrix, projection_matrix);
#else
render_model(); render_model();
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (show_texture) if (show_texture)
render_texture(bottom, canvas); render_texture(bottom, canvas);
@ -681,14 +773,24 @@ void Bed3D::render_default(bool bottom, bool picking)
{ {
m_texture.reset(); m_texture.reset();
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
init_gridlines(); init_gridlines();
init_triangles(); init_triangles();
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
@ -747,10 +849,10 @@ void Bed3D::render_default(bool bottom, bool picking)
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
void Bed3D::release_VBOs() void Bed3D::release_VBOs()
{ {
if (m_vbo_id > 0) { if (m_vbo_id > 0) {
@ -758,7 +860,7 @@ void Bed3D::release_VBOs()
m_vbo_id = 0; m_vbo_id = 0;
} }
} }
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
} // GUI } // GUI
} // Slic3r } // Slic3r

View File

@ -6,9 +6,9 @@
#include "GLModel.hpp" #include "GLModel.hpp"
#include "libslic3r/BuildVolume.hpp" #include "libslic3r/BuildVolume.hpp"
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#include "libslic3r/ExPolygon.hpp" #include "libslic3r/ExPolygon.hpp"
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#include <tuple> #include <tuple>
#include <array> #include <array>
@ -18,7 +18,7 @@ namespace GUI {
class GLCanvas3D; class GLCanvas3D;
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
class GeometryBuffer class GeometryBuffer
{ {
struct Vertex struct Vertex
@ -40,7 +40,7 @@ public:
size_t get_tex_coords_offset() const { return (size_t)(3 * sizeof(float)); } size_t get_tex_coords_offset() const { return (size_t)(3 * sizeof(float)); }
unsigned int get_vertices_count() const { return (unsigned int)m_vertices.size(); } unsigned int get_vertices_count() const { return (unsigned int)m_vertices.size(); }
}; };
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
class Bed3D class Bed3D
{ {
@ -84,38 +84,38 @@ private:
std::string m_model_filename; std::string m_model_filename;
// Print volume bounding box exteded with axes and model. // Print volume bounding box exteded with axes and model.
BoundingBoxf3 m_extended_bounding_box; BoundingBoxf3 m_extended_bounding_box;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// Print bed polygon // Print bed polygon
ExPolygon m_contour; ExPolygon m_contour;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// Slightly expanded print bed polygon, for collision detection. // Slightly expanded print bed polygon, for collision detection.
Polygon m_polygon; Polygon m_polygon;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel m_triangles; GLModel m_triangles;
GLModel m_gridlines; GLModel m_gridlines;
#else #else
GeometryBuffer m_triangles; GeometryBuffer m_triangles;
GeometryBuffer m_gridlines; GeometryBuffer m_gridlines;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
GLTexture m_texture; GLTexture m_texture;
// temporary texture shown until the main texture has still no levels compressed // temporary texture shown until the main texture has still no levels compressed
GLTexture m_temp_texture; GLTexture m_temp_texture;
GLModel m_model; GLModel m_model;
Vec3d m_model_offset{ Vec3d::Zero() }; Vec3d m_model_offset{ Vec3d::Zero() };
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
unsigned int m_vbo_id{ 0 }; unsigned int m_vbo_id{ 0 };
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
Axes m_axes; Axes m_axes;
float m_scale_factor{ 1.0f }; float m_scale_factor{ 1.0f };
public: public:
Bed3D() = default; Bed3D() = default;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
~Bed3D() = default; ~Bed3D() = default;
#else #else
~Bed3D() { release_VBOs(); } ~Bed3D() { release_VBOs(); }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// Update print bed model from configuration. // Update print bed model from configuration.
// Return true if the bed shape changed, so the calee will update the UI. // Return true if the bed shape changed, so the calee will update the UI.
@ -139,31 +139,50 @@ public:
bool contains(const Point& point) const; bool contains(const Point& point) const;
Point point_projection(const Point& point) const; Point point_projection(const Point& point) const;
#if ENABLE_GL_SHADERS_ATTRIBUTES
void render(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture);
void render_for_picking(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor);
#else
void render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture); void render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture);
void render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_factor); void render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_factor);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
private: private:
// Calculate an extended bounding box from axes and current model for visualization purposes. // Calculate an extended bounding box from axes and current model for visualization purposes.
BoundingBoxf3 calc_extended_bounding_box() const; BoundingBoxf3 calc_extended_bounding_box() const;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void init_triangles(); void init_triangles();
void init_gridlines(); void init_gridlines();
#else #else
void calc_triangles(const ExPolygon& poly); void calc_triangles(const ExPolygon& poly);
void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox); void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
static std::tuple<Type, std::string, std::string> detect_type(const Pointfs& shape); static std::tuple<Type, std::string, std::string> detect_type(const Pointfs& shape);
#if ENABLE_GL_SHADERS_ATTRIBUTES
void render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor,
bool show_axes, bool show_texture, bool picking);
#else
void render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor, void render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor,
bool show_axes, bool show_texture, bool picking); bool show_axes, bool show_texture, bool picking);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void render_axes(); void render_axes();
#if ENABLE_GL_SHADERS_ATTRIBUTES
void render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture);
#else
void render_system(GLCanvas3D& canvas, bool bottom, bool show_texture); void render_system(GLCanvas3D& canvas, bool bottom, bool show_texture);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void render_texture(bool bottom, GLCanvas3D& canvas); void render_texture(bool bottom, GLCanvas3D& canvas);
#if ENABLE_GL_SHADERS_ATTRIBUTES
void render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix);
void render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking);
#else
void render_model(); void render_model();
void render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking); void render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void render_default(bool bottom, bool picking); void render_default(bool bottom, bool picking);
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
void release_VBOs(); void release_VBOs();
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
}; };
} // GUI } // GUI

View File

@ -1,18 +1,21 @@
#include <GL/glew.h> #include <GL/glew.h>
#if !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_SMOOTH_NORMALS #if ENABLE_SMOOTH_NORMALS
#include <igl/per_face_normals.h> #include <igl/per_face_normals.h>
#include <igl/per_corner_normals.h> #include <igl/per_corner_normals.h>
#include <igl/per_vertex_normals.h> #include <igl/per_vertex_normals.h>
#endif // ENABLE_SMOOTH_NORMALS #endif // ENABLE_SMOOTH_NORMALS
#endif // !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
#include "3DScene.hpp" #include "3DScene.hpp"
#include "GLShader.hpp" #include "GLShader.hpp"
#include "GUI_App.hpp" #include "GUI_App.hpp"
#include "Plater.hpp" #include "Plater.hpp"
#include "BitmapCache.hpp" #include "BitmapCache.hpp"
#if ENABLE_GL_SHADERS_ATTRIBUTES
#include "Camera.hpp"
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#include "libslic3r/BuildVolume.hpp" #include "libslic3r/BuildVolume.hpp"
#include "libslic3r/ExtrusionEntity.hpp" #include "libslic3r/ExtrusionEntity.hpp"
@ -71,7 +74,7 @@ void glAssertRecentCallImpl(const char* file_name, unsigned int line, const char
namespace Slic3r { namespace Slic3r {
#if !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_SMOOTH_NORMALS #if ENABLE_SMOOTH_NORMALS
static void smooth_normals_corner(TriangleMesh& mesh, std::vector<stl_normal>& normals) static void smooth_normals_corner(TriangleMesh& mesh, std::vector<stl_normal>& normals)
{ {
@ -290,7 +293,7 @@ void GLIndexedVertexArray::render(
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
} }
#endif // !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
const float GLVolume::SinkingContours::HalfWidth = 0.25f; const float GLVolume::SinkingContours::HalfWidth = 0.25f;
@ -298,10 +301,22 @@ void GLVolume::SinkingContours::render()
{ {
update(); update();
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = GUI::wxGetApp().get_current_shader();
if (shader == nullptr)
return;
const GUI::Camera& camera = GUI::wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix() * Geometry::assemble_transform(m_shift));
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(m_shift.x(), m_shift.y(), m_shift.z())); glsafe(::glTranslated(m_shift.x(), m_shift.y(), m_shift.z()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_model.render(); m_model.render();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
void GLVolume::SinkingContours::update() void GLVolume::SinkingContours::update()
@ -319,16 +334,16 @@ void GLVolume::SinkingContours::update()
m_model.reset(); m_model.reset();
GUI::GLModel::Geometry init_data; GUI::GLModel::Geometry init_data;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Triangles, GUI::GLModel::Geometry::EVertexLayout::P3, GUI::GLModel::Geometry::EIndexType::UINT }; init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Triangles, GUI::GLModel::Geometry::EVertexLayout::P3 };
init_data.color = ColorRGBA::WHITE(); init_data.color = ColorRGBA::WHITE();
unsigned int vertices_counter = 0; unsigned int vertices_counter = 0;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
MeshSlicingParams slicing_params; MeshSlicingParams slicing_params;
slicing_params.trafo = m_parent.world_matrix(); slicing_params.trafo = m_parent.world_matrix();
const Polygons polygons = union_(slice_mesh(mesh.its, 0.0f, slicing_params)); const Polygons polygons = union_(slice_mesh(mesh.its, 0.0f, slicing_params));
for (const ExPolygon& expoly : diff_ex(expand(polygons, float(scale_(HalfWidth))), shrink(polygons, float(scale_(HalfWidth))))) { for (const ExPolygon& expoly : diff_ex(expand(polygons, float(scale_(HalfWidth))), shrink(polygons, float(scale_(HalfWidth))))) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
const std::vector<Vec3d> triangulation = triangulate_expolygon_3d(expoly); const std::vector<Vec3d> triangulation = triangulate_expolygon_3d(expoly);
init_data.reserve_vertices(init_data.vertices_count() + triangulation.size()); init_data.reserve_vertices(init_data.vertices_count() + triangulation.size());
init_data.reserve_indices(init_data.indices_count() + triangulation.size()); init_data.reserve_indices(init_data.indices_count() + triangulation.size());
@ -336,7 +351,7 @@ void GLVolume::SinkingContours::update()
init_data.add_vertex((Vec3f)(v.cast<float>() + 0.015f * Vec3f::UnitZ())); // add a small positive z to avoid z-fighting init_data.add_vertex((Vec3f)(v.cast<float>() + 0.015f * Vec3f::UnitZ())); // add a small positive z to avoid z-fighting
++vertices_counter; ++vertices_counter;
if (vertices_counter % 3 == 0) if (vertices_counter % 3 == 0)
init_data.add_uint_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1); init_data.add_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1);
} }
} }
m_model.init_from(std::move(init_data)); m_model.init_from(std::move(init_data));
@ -360,7 +375,7 @@ void GLVolume::SinkingContours::update()
init_data.entities.emplace_back(entity); init_data.entities.emplace_back(entity);
} }
m_model.init_from(init_data); m_model.init_from(init_data);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
else else
m_shift = box.center() - m_old_box.center(); m_shift = box.center() - m_old_box.center();
@ -375,15 +390,27 @@ void GLVolume::NonManifoldEdges::render()
update(); update();
glsafe(::glLineWidth(2.0f)); glsafe(::glLineWidth(2.0f));
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = GUI::wxGetApp().get_current_shader();
if (shader == nullptr)
return;
const GUI::Camera& camera = GUI::wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix() * m_parent.world_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glMultMatrixd(m_parent.world_matrix().data())); glsafe(::glMultMatrixd(m_parent.world_matrix().data()));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_LEGACY_OPENGL_REMOVAL
m_model.set_color(complementary(m_parent.render_color)); m_model.set_color(complementary(m_parent.render_color));
#else #else
m_model.set_color(-1, complementary(m_parent.render_color)); m_model.set_color(-1, complementary(m_parent.render_color));
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
m_model.render(); m_model.render();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
void GLVolume::NonManifoldEdges::update() void GLVolume::NonManifoldEdges::update()
@ -403,8 +430,8 @@ void GLVolume::NonManifoldEdges::update()
const std::vector<std::pair<int, int>> edges = its_get_open_edges(mesh.its); const std::vector<std::pair<int, int>> edges = its_get_open_edges(mesh.its);
if (!edges.empty()) { if (!edges.empty()) {
GUI::GLModel::Geometry init_data; GUI::GLModel::Geometry init_data;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Lines, GUI::GLModel::Geometry::EVertexLayout::P3, GUI::GLModel::Geometry::index_type(2 * edges.size()) }; init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Lines, GUI::GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(2 * edges.size()); init_data.reserve_vertices(2 * edges.size());
init_data.reserve_indices(2 * edges.size()); init_data.reserve_indices(2 * edges.size());
@ -414,10 +441,7 @@ void GLVolume::NonManifoldEdges::update()
init_data.add_vertex((Vec3f)mesh.its.vertices[edge.first].cast<float>()); init_data.add_vertex((Vec3f)mesh.its.vertices[edge.first].cast<float>());
init_data.add_vertex((Vec3f)mesh.its.vertices[edge.second].cast<float>()); init_data.add_vertex((Vec3f)mesh.its.vertices[edge.second].cast<float>());
vertices_count += 2; vertices_count += 2;
if (init_data.format.index_type == GUI::GLModel::Geometry::EIndexType::USHORT) init_data.add_line(vertices_count - 2, vertices_count - 1);
init_data.add_ushort_line((unsigned short)vertices_count - 2, (unsigned short)vertices_count - 1);
else
init_data.add_uint_line(vertices_count - 2, vertices_count - 1);
} }
m_model.init_from(std::move(init_data)); m_model.init_from(std::move(init_data));
#else #else
@ -438,7 +462,7 @@ void GLVolume::NonManifoldEdges::update()
init_data.entities.emplace_back(entity); init_data.entities.emplace_back(entity);
m_model.init_from(init_data); m_model.init_from(init_data);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
} }
} }
@ -487,9 +511,9 @@ GLVolume::GLVolume(float r, float g, float b, float a)
, force_neutral_color(false) , force_neutral_color(false)
, force_sinking_contours(false) , force_sinking_contours(false)
, tverts_range(0, size_t(-1)) , tverts_range(0, size_t(-1))
#if !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
, qverts_range(0, size_t(-1)) , qverts_range(0, size_t(-1))
#endif // !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
{ {
color = { r, g, b, a }; color = { r, g, b, a };
set_render_color(color); set_render_color(color);
@ -605,7 +629,7 @@ const BoundingBoxf3& GLVolume::transformed_non_sinking_bounding_box() const
return *m_transformed_non_sinking_bounding_box; return *m_transformed_non_sinking_bounding_box;
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void GLVolume::set_range(double min_z, double max_z) void GLVolume::set_range(double min_z, double max_z)
{ {
this->tverts_range.first = 0; this->tverts_range.first = 0;
@ -671,29 +695,40 @@ void GLVolume::set_range(double min_z, double max_z)
} }
} }
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
void GLVolume::render() void GLVolume::render()
{ {
if (!is_active) if (!is_active)
return; return;
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = GUI::wxGetApp().get_current_shader();
if (shader == nullptr)
return;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (this->is_left_handed()) if (this->is_left_handed())
glFrontFace(GL_CW); glFrontFace(GL_CW);
glsafe(::glCullFace(GL_BACK)); glsafe(::glCullFace(GL_BACK));
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glMultMatrixd(world_matrix().data())); glsafe(::glMultMatrixd(world_matrix().data()));
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
if (tverts_range == std::make_pair<size_t, size_t>(0, -1)) if (tverts_range == std::make_pair<size_t, size_t>(0, -1))
model.render(); model.render();
else else
model.render(this->tverts_range); model.render(this->tverts_range);
#else #else
this->indexed_vertex_array.render(this->tverts_range, this->qverts_range); this->indexed_vertex_array.render(this->tverts_range, this->qverts_range);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
if (this->is_left_handed()) if (this->is_left_handed())
glFrontFace(GL_CCW); glFrontFace(GL_CCW);
} }
@ -726,7 +761,7 @@ void GLVolume::render_non_manifold_edges()
} }
#endif // ENABLE_SHOW_NON_MANIFOLD_EDGES #endif // ENABLE_SHOW_NON_MANIFOLD_EDGES
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
std::vector<int> GLVolumeCollection::load_object( std::vector<int> GLVolumeCollection::load_object(
const ModelObject* model_object, const ModelObject* model_object,
int obj_idx, int obj_idx,
@ -737,20 +772,20 @@ std::vector<int> GLVolumeCollection::load_object(
int obj_idx, int obj_idx,
const std::vector<int> &instance_idxs, const std::vector<int> &instance_idxs,
bool opengl_initialized) bool opengl_initialized)
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
{ {
std::vector<int> volumes_idx; std::vector<int> volumes_idx;
for (int volume_idx = 0; volume_idx < int(model_object->volumes.size()); ++volume_idx) for (int volume_idx = 0; volume_idx < int(model_object->volumes.size()); ++volume_idx)
for (int instance_idx : instance_idxs) for (int instance_idx : instance_idxs)
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx)); volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx));
#else #else
volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx, opengl_initialized)); volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx, opengl_initialized));
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
return volumes_idx; return volumes_idx;
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
int GLVolumeCollection::load_object_volume( int GLVolumeCollection::load_object_volume(
const ModelObject* model_object, const ModelObject* model_object,
int obj_idx, int obj_idx,
@ -763,7 +798,7 @@ int GLVolumeCollection::load_object_volume(
int volume_idx, int volume_idx,
int instance_idx, int instance_idx,
bool opengl_initialized) bool opengl_initialized)
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
{ {
const ModelVolume *model_volume = model_object->volumes[volume_idx]; const ModelVolume *model_volume = model_object->volumes[volume_idx];
const int extruder_id = model_volume->extruder_id(); const int extruder_id = model_volume->extruder_id();
@ -772,7 +807,7 @@ int GLVolumeCollection::load_object_volume(
this->volumes.emplace_back(new GLVolume()); this->volumes.emplace_back(new GLVolume());
GLVolume& v = *this->volumes.back(); GLVolume& v = *this->volumes.back();
v.set_color(color_from_model_volume(*model_volume)); v.set_color(color_from_model_volume(*model_volume));
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_SMOOTH_NORMALS #if ENABLE_SMOOTH_NORMALS
v.model.init_from(mesh, true); v.model.init_from(mesh, true);
#else #else
@ -785,7 +820,7 @@ int GLVolumeCollection::load_object_volume(
v.indexed_vertex_array.load_mesh(mesh); v.indexed_vertex_array.load_mesh(mesh);
#endif // ENABLE_SMOOTH_NORMALS #endif // ENABLE_SMOOTH_NORMALS
v.indexed_vertex_array.finalize_geometry(opengl_initialized); v.indexed_vertex_array.finalize_geometry(opengl_initialized);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
v.composite_id = GLVolume::CompositeID(obj_idx, volume_idx, instance_idx); v.composite_id = GLVolume::CompositeID(obj_idx, volume_idx, instance_idx);
if (model_volume->is_model_part()) { if (model_volume->is_model_part()) {
// GLVolume will reference a convex hull from model_volume! // GLVolume will reference a convex hull from model_volume!
@ -804,7 +839,7 @@ int GLVolumeCollection::load_object_volume(
// Load SLA auxiliary GLVolumes (for support trees or pad). // Load SLA auxiliary GLVolumes (for support trees or pad).
// This function produces volumes for multiple instances in a single shot, // This function produces volumes for multiple instances in a single shot,
// as some object specific mesh conversions may be expensive. // as some object specific mesh conversions may be expensive.
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void GLVolumeCollection::load_object_auxiliary( void GLVolumeCollection::load_object_auxiliary(
const SLAPrintObject* print_object, const SLAPrintObject* print_object,
int obj_idx, int obj_idx,
@ -823,7 +858,7 @@ void GLVolumeCollection::load_object_auxiliary(
// Timestamp of the last change of the milestone // Timestamp of the last change of the milestone
size_t timestamp, size_t timestamp,
bool opengl_initialized) bool opengl_initialized)
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
{ {
assert(print_object->is_step_done(milestone)); assert(print_object->is_step_done(milestone));
Transform3d mesh_trafo_inv = print_object->trafo().inverse(); Transform3d mesh_trafo_inv = print_object->trafo().inverse();
@ -836,7 +871,7 @@ void GLVolumeCollection::load_object_auxiliary(
const ModelInstance& model_instance = *print_object->model_object()->instances[instance_idx.first]; const ModelInstance& model_instance = *print_object->model_object()->instances[instance_idx.first];
this->volumes.emplace_back(new GLVolume((milestone == slaposPad) ? GLVolume::SLA_PAD_COLOR : GLVolume::SLA_SUPPORT_COLOR)); this->volumes.emplace_back(new GLVolume((milestone == slaposPad) ? GLVolume::SLA_PAD_COLOR : GLVolume::SLA_SUPPORT_COLOR));
GLVolume& v = *this->volumes.back(); GLVolume& v = *this->volumes.back();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_SMOOTH_NORMALS #if ENABLE_SMOOTH_NORMALS
v.model.init_from(mesh, true); v.model.init_from(mesh, true);
#else #else
@ -850,7 +885,7 @@ void GLVolumeCollection::load_object_auxiliary(
v.indexed_vertex_array.load_mesh(mesh); v.indexed_vertex_array.load_mesh(mesh);
#endif // ENABLE_SMOOTH_NORMALS #endif // ENABLE_SMOOTH_NORMALS
v.indexed_vertex_array.finalize_geometry(opengl_initialized); v.indexed_vertex_array.finalize_geometry(opengl_initialized);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
v.composite_id = GLVolume::CompositeID(obj_idx, -int(milestone), (int)instance_idx.first); v.composite_id = GLVolume::CompositeID(obj_idx, -int(milestone), (int)instance_idx.first);
v.geometry_id = std::pair<size_t, size_t>(timestamp, model_instance.id().id); v.geometry_id = std::pair<size_t, size_t>(timestamp, model_instance.id().id);
// Create a copy of the convex hull mesh for each instance. Use a move operator on the last instance. // Create a copy of the convex hull mesh for each instance. Use a move operator on the last instance.
@ -866,7 +901,7 @@ void GLVolumeCollection::load_object_auxiliary(
} }
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL #if ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL
int GLVolumeCollection::load_wipe_tower_preview( int GLVolumeCollection::load_wipe_tower_preview(
float pos_x, float pos_y, float width, float depth, float height, float pos_x, float pos_y, float width, float depth, float height,
@ -886,7 +921,7 @@ int GLVolumeCollection::load_wipe_tower_preview(
int obj_idx, float pos_x, float pos_y, float width, float depth, float height, int obj_idx, float pos_x, float pos_y, float width, float depth, float height,
float rotation_angle, bool size_unknown, float brim_width, bool opengl_initialized) float rotation_angle, bool size_unknown, float brim_width, bool opengl_initialized)
#endif // ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL #endif // ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
{ {
if (depth < 0.01f) if (depth < 0.01f)
return int(this->volumes.size() - 1); return int(this->volumes.size() - 1);
@ -943,16 +978,16 @@ int GLVolumeCollection::load_wipe_tower_preview(
volumes.emplace_back(new GLVolume(color)); volumes.emplace_back(new GLVolume(color));
GLVolume& v = *volumes.back(); GLVolume& v = *volumes.back();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
v.model.init_from(mesh); v.model.init_from(mesh);
v.model.set_color(color); v.model.set_color(color);
#else #else
v.indexed_vertex_array.load_mesh(mesh); v.indexed_vertex_array.load_mesh(mesh);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
v.set_convex_hull(mesh.convex_hull_3d()); v.set_convex_hull(mesh.convex_hull_3d());
#if !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
v.indexed_vertex_array.finalize_geometry(opengl_initialized); v.indexed_vertex_array.finalize_geometry(opengl_initialized);
#endif // !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
v.set_volume_offset(Vec3d(pos_x, pos_y, 0.0)); v.set_volume_offset(Vec3d(pos_x, pos_y, 0.0));
v.set_volume_rotation(Vec3d(0., 0., (M_PI / 180.) * rotation_angle)); v.set_volume_rotation(Vec3d(0., 0., (M_PI / 180.) * rotation_angle));
#if ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL #if ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL
@ -967,7 +1002,7 @@ int GLVolumeCollection::load_wipe_tower_preview(
return int(volumes.size() - 1); return int(volumes.size() - 1);
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLVolume* GLVolumeCollection::new_toolpath_volume(const ColorRGBA& rgba) GLVolume* GLVolumeCollection::new_toolpath_volume(const ColorRGBA& rgba)
{ {
GLVolume* out = new_nontoolpath_volume(rgba); GLVolume* out = new_nontoolpath_volume(rgba);
@ -999,7 +1034,7 @@ GLVolume* GLVolumeCollection::new_nontoolpath_volume(const ColorRGBA& rgba, size
this->volumes.emplace_back(out); this->volumes.emplace_back(out);
return out; return out;
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCollection::ERenderType type, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func) GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCollection::ERenderType type, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func)
{ {
@ -1034,7 +1069,12 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo
return list; return list;
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, const Transform3d& projection_matrix,
std::function<bool(const GLVolume&)> filter_func) const
#else
void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func) const void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func) const
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
{ {
GLVolumeWithIdAndZList to_render = volumes_to_render(volumes, type, view_matrix, filter_func); GLVolumeWithIdAndZList to_render = volumes_to_render(volumes, type, view_matrix, filter_func);
if (to_render.empty()) if (to_render.empty())
@ -1044,10 +1084,16 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab
if (shader == nullptr) if (shader == nullptr)
return; return;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* sink_shader = GUI::wxGetApp().get_shader("flat_attr");
GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("flat_attr");
assert(boost::algorithm::iends_with(shader->get_name(), "_attr"));
#else
GLShaderProgram* sink_shader = GUI::wxGetApp().get_shader("flat"); GLShaderProgram* sink_shader = GUI::wxGetApp().get_shader("flat");
GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("flat"); GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("flat");
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GL_SHADERS_ATTRIBUTES
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (type == ERenderType::Transparent) { if (type == ERenderType::Transparent) {
glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_BLEND));
@ -1062,36 +1108,34 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab
volume.first->set_render_color(true); volume.first->set_render_color(true);
// render sinking contours of non-hovered volumes // render sinking contours of non-hovered volumes
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
if (sink_shader != nullptr) { if (sink_shader != nullptr) {
sink_shader->start_using(); sink_shader->start_using();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (m_show_sinking_contours) { if (m_show_sinking_contours) {
if (volume.first->is_sinking() && !volume.first->is_below_printbed() && if (volume.first->is_sinking() && !volume.first->is_below_printbed() &&
volume.first->hover == GLVolume::HS_None && !volume.first->force_sinking_contours) { volume.first->hover == GLVolume::HS_None && !volume.first->force_sinking_contours) {
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
volume.first->render_sinking_contours(); volume.first->render_sinking_contours();
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
shader->start_using(); shader->start_using();
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
} }
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
sink_shader->stop_using(); sink_shader->stop_using();
} }
shader->start_using(); shader->start_using();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); glsafe(::glEnableClientState(GL_NORMAL_ARRAY));
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
if (!volume.first->model.is_initialized())
#endif // !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
shader->set_uniform("uniform_color", volume.first->render_color);
shader->set_uniform("z_range", m_z_range, 2); shader->set_uniform("z_range", m_z_range, 2);
shader->set_uniform("clipping_plane", m_clipping_plane, 4); shader->set_uniform("clipping_plane", m_clipping_plane, 4);
shader->set_uniform("print_volume.type", static_cast<int>(m_print_volume.type)); shader->set_uniform("print_volume.type", static_cast<int>(m_print_volume.type));
@ -1111,9 +1155,17 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab
#endif // ENABLE_ENVIRONMENT_MAP #endif // ENABLE_ENVIRONMENT_MAP
glcheck(); glcheck();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
volume.first->model.set_color(volume.first->render_color); volume.first->model.set_color(volume.first->render_color);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #else
shader->set_uniform("uniform_color", volume.first->render_color);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d matrix = view_matrix * volume.first->world_matrix();
shader->set_uniform("view_model_matrix", matrix);
shader->set_uniform("projection_matrix", projection_matrix);
shader->set_uniform("normal_matrix", (Matrix3d)matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
volume.first->render(); volume.first->render();
#if ENABLE_ENVIRONMENT_MAP #if ENABLE_ENVIRONMENT_MAP
@ -1124,54 +1176,56 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); glsafe(::glDisableClientState(GL_NORMAL_ARRAY));
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
if (m_show_sinking_contours) { if (m_show_sinking_contours) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
if (sink_shader != nullptr) { if (sink_shader != nullptr) {
sink_shader->start_using(); sink_shader->start_using();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
for (GLVolumeWithIdAndZ& volume : to_render) { for (GLVolumeWithIdAndZ& volume : to_render) {
// render sinking contours of hovered/displaced volumes // render sinking contours of hovered/displaced volumes
if (volume.first->is_sinking() && !volume.first->is_below_printbed() && if (volume.first->is_sinking() && !volume.first->is_below_printbed() &&
(volume.first->hover != GLVolume::HS_None || volume.first->force_sinking_contours)) { (volume.first->hover != GLVolume::HS_None || volume.first->force_sinking_contours)) {
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glDepthFunc(GL_ALWAYS)); glsafe(::glDepthFunc(GL_ALWAYS));
volume.first->render_sinking_contours(); volume.first->render_sinking_contours();
glsafe(::glDepthFunc(GL_LESS)); glsafe(::glDepthFunc(GL_LESS));
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
shader->start_using(); shader->start_using();
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
} }
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
sink_shader->start_using(); sink_shader->start_using();
} }
shader->start_using(); shader->start_using();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_SHOW_NON_MANIFOLD_EDGES #if ENABLE_SHOW_NON_MANIFOLD_EDGES
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
if (edges_shader != nullptr) { if (edges_shader != nullptr) {
edges_shader->start_using(); edges_shader->start_using();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (m_show_non_manifold_edges && GUI::wxGetApp().app_config->get("non_manifold_edges") == "1") { if (m_show_non_manifold_edges && GUI::wxGetApp().app_config->get("non_manifold_edges") == "1") {
for (GLVolumeWithIdAndZ& volume : to_render) { for (GLVolumeWithIdAndZ& volume : to_render) {
volume.first->render_non_manifold_edges(); volume.first->render_non_manifold_edges();
} }
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
edges_shader->stop_using(); edges_shader->stop_using();
} }
shader->start_using(); shader->start_using();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#endif // ENABLE_SHOW_NON_MANIFOLD_EDGES #endif // ENABLE_SHOW_NON_MANIFOLD_EDGES
if (disable_cullface) if (disable_cullface)
@ -1349,7 +1403,7 @@ std::string GLVolumeCollection::log_memory_info() const
return " (GLVolumeCollection RAM: " + format_memsize_MB(this->cpu_memory_used()) + " GPU: " + format_memsize_MB(this->gpu_memory_used()) + " Both: " + format_memsize_MB(this->gpu_memory_used()) + ")"; return " (GLVolumeCollection RAM: " + format_memsize_MB(this->cpu_memory_used()) + " GPU: " + format_memsize_MB(this->gpu_memory_used()) + " Both: " + format_memsize_MB(this->gpu_memory_used()) + ")";
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
static void thick_lines_to_geometry( static void thick_lines_to_geometry(
const Lines& lines, const Lines& lines,
const std::vector<double>& widths, const std::vector<double>& widths,
@ -1425,8 +1479,8 @@ static void thick_lines_to_geometry(
if (!is_first && bottom_z_different) { if (!is_first && bottom_z_different) {
// Found a change of the layer thickness -> Add a cap at the end of the previous segment. // Found a change of the layer thickness -> Add a cap at the end of the previous segment.
geometry.add_uint_triangle(idx_b[Bottom], idx_b[Left], idx_b[Top]); geometry.add_triangle(idx_b[Bottom], idx_b[Left], idx_b[Top]);
geometry.add_uint_triangle(idx_b[Bottom], idx_b[Top], idx_b[Right]); geometry.add_triangle(idx_b[Bottom], idx_b[Top], idx_b[Right]);
} }
// Share top / bottom vertices if possible. // Share top / bottom vertices if possible.
@ -1476,13 +1530,13 @@ static void thick_lines_to_geometry(
geometry.add_vertex(Vec3f(a2.x(), a2.y(), middle_z), Vec3f(-xy_right_normal.x(), -xy_right_normal.y(), 0.0f)); geometry.add_vertex(Vec3f(a2.x(), a2.y(), middle_z), Vec3f(-xy_right_normal.x(), -xy_right_normal.y(), 0.0f));
if (cross2(v_prev, v) > 0.0) { if (cross2(v_prev, v) > 0.0) {
// Right turn. Fill in the right turn wedge. // Right turn. Fill in the right turn wedge.
geometry.add_uint_triangle(idx_prev[Right], idx_a[Right], idx_prev[Top]); geometry.add_triangle(idx_prev[Right], idx_a[Right], idx_prev[Top]);
geometry.add_uint_triangle(idx_prev[Right], idx_prev[Bottom], idx_a[Right]); geometry.add_triangle(idx_prev[Right], idx_prev[Bottom], idx_a[Right]);
} }
else { else {
// Left turn. Fill in the left turn wedge. // Left turn. Fill in the left turn wedge.
geometry.add_uint_triangle(idx_prev[Left], idx_prev[Top], idx_a[Left]); geometry.add_triangle(idx_prev[Left], idx_prev[Top], idx_a[Left]);
geometry.add_uint_triangle(idx_prev[Left], idx_a[Left], idx_prev[Bottom]); geometry.add_triangle(idx_prev[Left], idx_a[Left], idx_prev[Bottom]);
} }
} }
} }
@ -1504,11 +1558,11 @@ static void thick_lines_to_geometry(
// Replace the left / right vertex indices to point to the start of the loop. // Replace the left / right vertex indices to point to the start of the loop.
const size_t indices_count = geometry.indices_count(); const size_t indices_count = geometry.indices_count();
for (size_t u = indices_count - 24; u < indices_count; ++u) { for (size_t u = indices_count - 24; u < indices_count; ++u) {
const unsigned int id = geometry.extract_uint_index(u); const unsigned int id = geometry.extract_index(u);
if (id == (unsigned int)idx_prev[Left]) if (id == (unsigned int)idx_prev[Left])
geometry.set_uint_index(u, (unsigned int)idx_initial[Left]); geometry.set_index(u, (unsigned int)idx_initial[Left]);
else if (id == (unsigned int)idx_prev[Right]) else if (id == (unsigned int)idx_prev[Right])
geometry.set_uint_index(u, (unsigned int)idx_initial[Right]); geometry.set_index(u, (unsigned int)idx_initial[Right]);
} }
} }
} }
@ -1545,36 +1599,36 @@ static void thick_lines_to_geometry(
if (bottom_z_different && (closed || (!is_first && !is_last))) { if (bottom_z_different && (closed || (!is_first && !is_last))) {
// Found a change of the layer thickness -> Add a cap at the beginning of this segment. // Found a change of the layer thickness -> Add a cap at the beginning of this segment.
geometry.add_uint_triangle(idx_a[Bottom], idx_a[Right], idx_a[Top]); geometry.add_triangle(idx_a[Bottom], idx_a[Right], idx_a[Top]);
geometry.add_uint_triangle(idx_a[Bottom], idx_a[Top], idx_a[Left]); geometry.add_triangle(idx_a[Bottom], idx_a[Top], idx_a[Left]);
} }
if (!closed) { if (!closed) {
// Terminate open paths with caps. // Terminate open paths with caps.
if (is_first) { if (is_first) {
geometry.add_uint_triangle(idx_a[Bottom], idx_a[Right], idx_a[Top]); geometry.add_triangle(idx_a[Bottom], idx_a[Right], idx_a[Top]);
geometry.add_uint_triangle(idx_a[Bottom], idx_a[Top], idx_a[Left]); geometry.add_triangle(idx_a[Bottom], idx_a[Top], idx_a[Left]);
} }
// We don't use 'else' because both cases are true if we have only one line. // We don't use 'else' because both cases are true if we have only one line.
if (is_last) { if (is_last) {
geometry.add_uint_triangle(idx_b[Bottom], idx_b[Left], idx_b[Top]); geometry.add_triangle(idx_b[Bottom], idx_b[Left], idx_b[Top]);
geometry.add_uint_triangle(idx_b[Bottom], idx_b[Top], idx_b[Right]); geometry.add_triangle(idx_b[Bottom], idx_b[Top], idx_b[Right]);
} }
} }
// Add quads for a straight hollow tube-like segment. // Add quads for a straight hollow tube-like segment.
// bottom-right face // bottom-right face
geometry.add_uint_triangle(idx_a[Bottom], idx_b[Bottom], idx_b[Right]); geometry.add_triangle(idx_a[Bottom], idx_b[Bottom], idx_b[Right]);
geometry.add_uint_triangle(idx_a[Bottom], idx_b[Right], idx_a[Right]); geometry.add_triangle(idx_a[Bottom], idx_b[Right], idx_a[Right]);
// top-right face // top-right face
geometry.add_uint_triangle(idx_a[Right], idx_b[Right], idx_b[Top]); geometry.add_triangle(idx_a[Right], idx_b[Right], idx_b[Top]);
geometry.add_uint_triangle(idx_a[Right], idx_b[Top], idx_a[Top]); geometry.add_triangle(idx_a[Right], idx_b[Top], idx_a[Top]);
// top-left face // top-left face
geometry.add_uint_triangle(idx_a[Top], idx_b[Top], idx_b[Left]); geometry.add_triangle(idx_a[Top], idx_b[Top], idx_b[Left]);
geometry.add_uint_triangle(idx_a[Top], idx_b[Left], idx_a[Left]); geometry.add_triangle(idx_a[Top], idx_b[Left], idx_a[Left]);
// bottom-left face // bottom-left face
geometry.add_uint_triangle(idx_a[Left], idx_b[Left], idx_b[Bottom]); geometry.add_triangle(idx_a[Left], idx_b[Left], idx_b[Bottom]);
geometry.add_uint_triangle(idx_a[Left], idx_b[Bottom], idx_a[Bottom]); geometry.add_triangle(idx_a[Left], idx_b[Bottom], idx_a[Bottom]);
} }
} }
@ -1714,13 +1768,13 @@ static void thick_lines_to_geometry(
if (is_right_turn) { if (is_right_turn) {
// Right turn. Fill in the right turn wedge. // Right turn. Fill in the right turn wedge.
geometry.add_uint_triangle(idx_prev[Right], idx_a[Right], idx_prev[Top]); geometry.add_triangle(idx_prev[Right], idx_a[Right], idx_prev[Top]);
geometry.add_uint_triangle(idx_prev[Right], idx_prev[Bottom], idx_a[Right]); geometry.add_triangle(idx_prev[Right], idx_prev[Bottom], idx_a[Right]);
} }
else { else {
// Left turn. Fill in the left turn wedge. // Left turn. Fill in the left turn wedge.
geometry.add_uint_triangle(idx_prev[Left], idx_prev[Top], idx_a[Left]); geometry.add_triangle(idx_prev[Left], idx_prev[Top], idx_a[Left]);
geometry.add_uint_triangle(idx_prev[Left], idx_a[Left], idx_prev[Bottom]); geometry.add_triangle(idx_prev[Left], idx_a[Left], idx_prev[Bottom]);
} }
} }
else { else {
@ -1739,11 +1793,11 @@ static void thick_lines_to_geometry(
// Replace the left / right vertex indices to point to the start of the loop. // Replace the left / right vertex indices to point to the start of the loop.
const size_t indices_count = geometry.indices_count(); const size_t indices_count = geometry.indices_count();
for (size_t u = indices_count - 24; u < indices_count; ++u) { for (size_t u = indices_count - 24; u < indices_count; ++u) {
const unsigned int id = geometry.extract_uint_index(u); const unsigned int id = geometry.extract_index(u);
if (id == (unsigned int)idx_prev[Left]) if (id == (unsigned int)idx_prev[Left])
geometry.set_uint_index(u, (unsigned int)idx_initial[Left]); geometry.set_index(u, (unsigned int)idx_initial[Left]);
else if (id == (unsigned int)idx_prev[Right]) else if (id == (unsigned int)idx_prev[Right])
geometry.set_uint_index(u, (unsigned int)idx_initial[Right]); geometry.set_index(u, (unsigned int)idx_initial[Right]);
} }
} }
@ -1782,30 +1836,30 @@ static void thick_lines_to_geometry(
if (!closed) { if (!closed) {
// Terminate open paths with caps. // Terminate open paths with caps.
if (i == 0) { if (i == 0) {
geometry.add_uint_triangle(idx_a[Bottom], idx_a[Right], idx_a[Top]); geometry.add_triangle(idx_a[Bottom], idx_a[Right], idx_a[Top]);
geometry.add_uint_triangle(idx_a[Bottom], idx_a[Top], idx_a[Left]); geometry.add_triangle(idx_a[Bottom], idx_a[Top], idx_a[Left]);
} }
// We don't use 'else' because both cases are true if we have only one line. // We don't use 'else' because both cases are true if we have only one line.
if (i + 1 == lines.size()) { if (i + 1 == lines.size()) {
geometry.add_uint_triangle(idx_b[Bottom], idx_b[Left], idx_b[Top]); geometry.add_triangle(idx_b[Bottom], idx_b[Left], idx_b[Top]);
geometry.add_uint_triangle(idx_b[Bottom], idx_b[Top], idx_b[Right]); geometry.add_triangle(idx_b[Bottom], idx_b[Top], idx_b[Right]);
} }
} }
// Add quads for a straight hollow tube-like segment. // Add quads for a straight hollow tube-like segment.
// bottom-right face // bottom-right face
geometry.add_uint_triangle(idx_a[Bottom], idx_b[Bottom], idx_b[Right]); geometry.add_triangle(idx_a[Bottom], idx_b[Bottom], idx_b[Right]);
geometry.add_uint_triangle(idx_a[Bottom], idx_b[Right], idx_a[Right]); geometry.add_triangle(idx_a[Bottom], idx_b[Right], idx_a[Right]);
// top-right face // top-right face
geometry.add_uint_triangle(idx_a[Right], idx_b[Right], idx_b[Top]); geometry.add_triangle(idx_a[Right], idx_b[Right], idx_b[Top]);
geometry.add_uint_triangle(idx_a[Right], idx_b[Top], idx_a[Top]); geometry.add_triangle(idx_a[Right], idx_b[Top], idx_a[Top]);
// top-left face // top-left face
geometry.add_uint_triangle(idx_a[Top], idx_b[Top], idx_b[Left]); geometry.add_triangle(idx_a[Top], idx_b[Top], idx_b[Left]);
geometry.add_uint_triangle(idx_a[Top], idx_b[Left], idx_a[Left]); geometry.add_triangle(idx_a[Top], idx_b[Left], idx_a[Left]);
// bottom-left face // bottom-left face
geometry.add_uint_triangle(idx_a[Left], idx_b[Left], idx_b[Bottom]); geometry.add_triangle(idx_a[Left], idx_b[Left], idx_b[Bottom]);
geometry.add_uint_triangle(idx_a[Left], idx_b[Bottom], idx_a[Bottom]); geometry.add_triangle(idx_a[Left], idx_b[Bottom], idx_a[Bottom]);
} }
} }
#else #else
@ -2318,9 +2372,9 @@ static void point_to_indexed_vertex_array(const Vec3crd& point,
volume.push_triangle(idxs[3], idxs[1], idxs[4]); volume.push_triangle(idxs[3], idxs[1], idxs[4]);
volume.push_triangle(idxs[0], idxs[3], idxs[4]); volume.push_triangle(idxs[0], idxs[3], idxs[4]);
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void _3DScene::thick_lines_to_verts( void _3DScene::thick_lines_to_verts(
const Lines& lines, const Lines& lines,
const std::vector<double>& widths, const std::vector<double>& widths,
@ -2383,10 +2437,10 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionPath &extrusion_path, flo
{ {
extrusionentity_to_verts(extrusion_path.polyline, extrusion_path.width, extrusion_path.height, print_z, volume); extrusionentity_to_verts(extrusion_path.polyline, extrusion_path.width, extrusion_path.height, print_z, volume);
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// Fill in the qverts and tverts with quads and triangles for the extrusion_path. // Fill in the qverts and tverts with quads and triangles for the extrusion_path.
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void _3DScene::extrusionentity_to_verts(const ExtrusionPath& extrusion_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) void _3DScene::extrusionentity_to_verts(const ExtrusionPath& extrusion_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry)
{ {
Polyline polyline = extrusion_path.polyline; Polyline polyline = extrusion_path.polyline;
@ -2408,10 +2462,10 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionPath &extrusion_path, flo
std::vector<double> heights(lines.size(), extrusion_path.height); std::vector<double> heights(lines.size(), extrusion_path.height);
thick_lines_to_verts(lines, widths, heights, false, print_z, volume); thick_lines_to_verts(lines, widths, heights, false, print_z, volume);
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// Fill in the qverts and tverts with quads and triangles for the extrusion_loop. // Fill in the qverts and tverts with quads and triangles for the extrusion_loop.
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void _3DScene::extrusionentity_to_verts(const ExtrusionLoop& extrusion_loop, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) void _3DScene::extrusionentity_to_verts(const ExtrusionLoop& extrusion_loop, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry)
{ {
Lines lines; Lines lines;
@ -2445,10 +2499,10 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionLoop &extrusion_loop, flo
} }
thick_lines_to_verts(lines, widths, heights, true, print_z, volume); thick_lines_to_verts(lines, widths, heights, true, print_z, volume);
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// Fill in the qverts and tverts with quads and triangles for the extrusion_multi_path. // Fill in the qverts and tverts with quads and triangles for the extrusion_multi_path.
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void _3DScene::extrusionentity_to_verts(const ExtrusionMultiPath& extrusion_multi_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) void _3DScene::extrusionentity_to_verts(const ExtrusionMultiPath& extrusion_multi_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry)
{ {
Lines lines; Lines lines;
@ -2482,9 +2536,9 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionMultiPath &extrusion_mult
} }
thick_lines_to_verts(lines, widths, heights, false, print_z, volume); thick_lines_to_verts(lines, widths, heights, false, print_z, volume);
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void _3DScene::extrusionentity_to_verts(const ExtrusionEntityCollection& extrusion_entity_collection, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) void _3DScene::extrusionentity_to_verts(const ExtrusionEntityCollection& extrusion_entity_collection, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry)
{ {
for (const ExtrusionEntity* extrusion_entity : extrusion_entity_collection.entities) for (const ExtrusionEntity* extrusion_entity : extrusion_entity_collection.entities)
@ -2496,9 +2550,9 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionEntityCollection &extrusi
for (const ExtrusionEntity *extrusion_entity : extrusion_entity_collection.entities) for (const ExtrusionEntity *extrusion_entity : extrusion_entity_collection.entities)
extrusionentity_to_verts(extrusion_entity, print_z, copy, volume); extrusionentity_to_verts(extrusion_entity, print_z, copy, volume);
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void _3DScene::extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) void _3DScene::extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry)
{ {
if (extrusion_entity != nullptr) { if (extrusion_entity != nullptr) {
@ -2563,6 +2617,6 @@ void _3DScene::point3_to_verts(const Vec3crd& point, double width, double height
{ {
thick_point_to_verts(point, width, height, volume); thick_point_to_verts(point, width, height, volume);
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} // namespace Slic3r } // namespace Slic3r

View File

@ -46,7 +46,7 @@ enum ModelInstanceEPrintVolumeState : unsigned char;
// Return appropriate color based on the ModelVolume. // Return appropriate color based on the ModelVolume.
extern ColorRGBA color_from_model_volume(const ModelVolume& model_volume); extern ColorRGBA color_from_model_volume(const ModelVolume& model_volume);
#if !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
// A container for interleaved arrays of 3D vertices and normals, // A container for interleaved arrays of 3D vertices and normals,
// possibly indexed by triangles and / or quads. // possibly indexed by triangles and / or quads.
class GLIndexedVertexArray { class GLIndexedVertexArray {
@ -247,7 +247,7 @@ public:
private: private:
BoundingBox m_bounding_box; BoundingBox m_bounding_box;
}; };
#endif // !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
class GLVolume { class GLVolume {
public: public:
@ -390,17 +390,17 @@ public:
// Is mouse or rectangle selection over this object to select/deselect it ? // Is mouse or rectangle selection over this object to select/deselect it ?
EHoverState hover; EHoverState hover;
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GUI::GLModel model; GUI::GLModel model;
#else #else
// Interleaved triangles & normals with indexed triangles & quads. // Interleaved triangles & normals with indexed triangles & quads.
GLIndexedVertexArray indexed_vertex_array; GLIndexedVertexArray indexed_vertex_array;
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// Ranges of triangle and quad indices to be rendered. // Ranges of triangle and quad indices to be rendered.
std::pair<size_t, size_t> tverts_range; std::pair<size_t, size_t> tverts_range;
#if !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
std::pair<size_t, size_t> qverts_range; std::pair<size_t, size_t> qverts_range;
#endif // !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
// If the qverts or tverts contain thick extrusions, then offsets keeps pointers of the starts // If the qverts or tverts contain thick extrusions, then offsets keeps pointers of the starts
// of the extrusions per layer. // of the extrusions per layer.
@ -410,7 +410,7 @@ public:
// Bounding box of this volume, in unscaled coordinates. // Bounding box of this volume, in unscaled coordinates.
BoundingBoxf3 bounding_box() const { BoundingBoxf3 bounding_box() const {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
return this->model.get_bounding_box(); return this->model.get_bounding_box();
#else #else
BoundingBoxf3 out; BoundingBoxf3 out;
@ -420,7 +420,7 @@ public:
out.defined = true; out.defined = true;
} }
return out; return out;
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
void set_color(const ColorRGBA& rgba) { color = rgba; } void set_color(const ColorRGBA& rgba) { color = rgba; }
@ -510,20 +510,20 @@ public:
// convex hull // convex hull
const TriangleMesh* convex_hull() const { return m_convex_hull.get(); } const TriangleMesh* convex_hull() const { return m_convex_hull.get(); }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
bool empty() const { return this->model.is_empty(); } bool empty() const { return this->model.is_empty(); }
#else #else
bool empty() const { return this->indexed_vertex_array.empty(); } bool empty() const { return this->indexed_vertex_array.empty(); }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
void set_range(double low, double high); void set_range(double low, double high);
void render(); void render();
#if !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
void finalize_geometry(bool opengl_initialized) { this->indexed_vertex_array.finalize_geometry(opengl_initialized); } void finalize_geometry(bool opengl_initialized) { this->indexed_vertex_array.finalize_geometry(opengl_initialized); }
void release_geometry() { this->indexed_vertex_array.release_geometry(); } void release_geometry() { this->indexed_vertex_array.release_geometry(); }
#endif // !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
void set_bounding_boxes_as_dirty() { void set_bounding_boxes_as_dirty() {
m_transformed_bounding_box.reset(); m_transformed_bounding_box.reset();
@ -543,7 +543,7 @@ public:
// Return an estimate of the memory consumed by this class. // Return an estimate of the memory consumed by this class.
size_t cpu_memory_used() const { size_t cpu_memory_used() const {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
return sizeof(*this) + this->model.cpu_memory_used() + this->print_zs.capacity() * sizeof(coordf_t) + return sizeof(*this) + this->model.cpu_memory_used() + this->print_zs.capacity() * sizeof(coordf_t) +
this->offsets.capacity() * sizeof(size_t); this->offsets.capacity() * sizeof(size_t);
} }
@ -555,7 +555,7 @@ public:
} }
// Return an estimate of the memory held by GPU vertex buffers. // Return an estimate of the memory held by GPU vertex buffers.
size_t gpu_memory_used() const { return this->indexed_vertex_array.gpu_memory_used(); } size_t gpu_memory_used() const { return this->indexed_vertex_array.gpu_memory_used(); }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
size_t total_memory_used() const { return this->cpu_memory_used() + this->gpu_memory_used(); } size_t total_memory_used() const { return this->cpu_memory_used() + this->gpu_memory_used(); }
}; };
@ -615,7 +615,7 @@ public:
GLVolumeCollection() { set_default_slope_normal_z(); } GLVolumeCollection() { set_default_slope_normal_z(); }
~GLVolumeCollection() { clear(); } ~GLVolumeCollection() { clear(); }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
std::vector<int> load_object( std::vector<int> load_object(
const ModelObject* model_object, const ModelObject* model_object,
int obj_idx, int obj_idx,
@ -676,20 +676,25 @@ public:
int load_wipe_tower_preview( int load_wipe_tower_preview(
int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width, bool opengl_initialized); int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width, bool opengl_initialized);
#endif // ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL #endif // ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLVolume* new_toolpath_volume(const ColorRGBA& rgba); GLVolume* new_toolpath_volume(const ColorRGBA& rgba);
GLVolume* new_nontoolpath_volume(const ColorRGBA& rgba); GLVolume* new_nontoolpath_volume(const ColorRGBA& rgba);
#else #else
GLVolume* new_toolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats = 0); GLVolume* new_toolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats = 0);
GLVolume* new_nontoolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats = 0); GLVolume* new_nontoolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats = 0);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// Render the volumes by OpenGL. // Render the volumes by OpenGL.
#if ENABLE_GL_SHADERS_ATTRIBUTES
void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, const Transform3d& projection_matrix,
std::function<bool(const GLVolume&)> filter_func = std::function<bool(const GLVolume&)>()) const;
#else
void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func = std::function<bool(const GLVolume&)>()) const; void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func = std::function<bool(const GLVolume&)>()) const;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
// Finalize the initialization of the geometry & indices, // Finalize the initialization of the geometry & indices,
// upload the geometry and indices to OpenGL VBO objects // upload the geometry and indices to OpenGL VBO objects
// and shrink the allocated data, possibly relasing it if it has been loaded into the VBOs. // and shrink the allocated data, possibly relasing it if it has been loaded into the VBOs.
@ -697,7 +702,7 @@ public:
// Release the geometry data assigned to the volumes. // Release the geometry data assigned to the volumes.
// If OpenGL VBOs were allocated, an OpenGL context has to be active to release them. // If OpenGL VBOs were allocated, an OpenGL context has to be active to release them.
void release_geometry() { for (auto *v : volumes) v->release_geometry(); } void release_geometry() { for (auto *v : volumes) v->release_geometry(); }
#endif // !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
// Clear the geometry // Clear the geometry
void clear() { for (auto *v : volumes) delete v; volumes.clear(); } void clear() { for (auto *v : volumes) delete v; volumes.clear(); }
@ -747,7 +752,7 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo
struct _3DScene struct _3DScene
{ {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
static void thick_lines_to_verts(const Lines& lines, const std::vector<double>& widths, const std::vector<double>& heights, bool closed, double top_z, GUI::GLModel::Geometry& geometry); static void thick_lines_to_verts(const Lines& lines, const std::vector<double>& widths, const std::vector<double>& heights, bool closed, double top_z, GUI::GLModel::Geometry& geometry);
static void thick_lines_to_verts(const Lines3& lines, const std::vector<double>& widths, const std::vector<double>& heights, bool closed, GUI::GLModel::Geometry& geometry); static void thick_lines_to_verts(const Lines3& lines, const std::vector<double>& widths, const std::vector<double>& heights, bool closed, GUI::GLModel::Geometry& geometry);
static void extrusionentity_to_verts(const ExtrusionPath& extrusion_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry); static void extrusionentity_to_verts(const ExtrusionPath& extrusion_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry);
@ -767,7 +772,7 @@ struct _3DScene
static void extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, float print_z, const Point& copy, GLVolume& volume); static void extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, float print_z, const Point& copy, GLVolume& volume);
static void polyline3_to_verts(const Polyline3& polyline, double width, double height, GLVolume& volume); static void polyline3_to_verts(const Polyline3& polyline, double width, double height, GLVolume& volume);
static void point3_to_verts(const Vec3crd& point, double width, double height, GLVolume& volume); static void point3_to_verts(const Vec3crd& point, double width, double height, GLVolume& volume);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
}; };
} }

View File

@ -184,7 +184,11 @@ void GCodeViewer::COG::render()
init(); init();
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("toolpaths_cog_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("toolpaths_cog"); GLShaderProgram* shader = wxGetApp().get_shader("toolpaths_cog");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
@ -192,6 +196,18 @@ void GCodeViewer::COG::render()
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
Transform3d matrix = camera.get_view_matrix() * Geometry::assemble_transform(cog());
if (m_fixed_size) {
const double inv_zoom = wxGetApp().plater()->get_camera().get_inv_zoom();
matrix = matrix * Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), inv_zoom * Vec3d::Ones());
}
shader->set_uniform("view_model_matrix", matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
shader->set_uniform("normal_matrix", (Matrix3d)matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
m_model.render();
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
const Vec3d position = cog(); const Vec3d position = cog();
glsafe(::glTranslated(position.x(), position.y(), position.z())); glsafe(::glTranslated(position.x(), position.y(), position.z()));
@ -200,8 +216,8 @@ void GCodeViewer::COG::render()
glsafe(::glScaled(inv_zoom, inv_zoom, inv_zoom)); glsafe(::glScaled(inv_zoom, inv_zoom, inv_zoom));
} }
m_model.render(); m_model.render();
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
shader->stop_using(); shader->stop_using();
@ -297,11 +313,11 @@ void GCodeViewer::SequentialRangeCap::reset() {
void GCodeViewer::SequentialView::Marker::init() void GCodeViewer::SequentialView::Marker::init()
{ {
m_model.init_from(stilized_arrow(16, 2.0f, 4.0f, 1.0f, 8.0f)); m_model.init_from(stilized_arrow(16, 2.0f, 4.0f, 1.0f, 8.0f));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_model.set_color({ 1.0f, 1.0f, 1.0f, 0.5f }); m_model.set_color({ 1.0f, 1.0f, 1.0f, 0.5f });
#else #else
m_model.set_color(-1, { 1.0f, 1.0f, 1.0f, 0.5f }); m_model.set_color(-1, { 1.0f, 1.0f, 1.0f, 0.5f });
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
void GCodeViewer::SequentialView::Marker::set_world_position(const Vec3f& position) void GCodeViewer::SequentialView::Marker::set_world_position(const Vec3f& position)
@ -315,7 +331,11 @@ void GCodeViewer::SequentialView::Marker::render()
if (!m_visible) if (!m_visible)
return; return;
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
@ -324,13 +344,22 @@ void GCodeViewer::SequentialView::Marker::render()
shader->start_using(); shader->start_using();
shader->set_uniform("emission_factor", 0.0f); shader->set_uniform("emission_factor", 0.0f);
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d matrix = camera.get_view_matrix() * m_world_transform.cast<double>();
shader->set_uniform("view_model_matrix", matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
shader->set_uniform("normal_matrix", (Matrix3d)matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glMultMatrixf(m_world_transform.data())); glsafe(::glMultMatrixf(m_world_transform.data()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_model.render(); m_model.render();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
shader->stop_using(); shader->stop_using();
@ -663,7 +692,11 @@ void GCodeViewer::init()
#if !DISABLE_GCODEVIEWER_INSTANCED_MODELS #if !DISABLE_GCODEVIEWER_INSTANCED_MODELS
if (wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) { if (wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) {
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::InstancedModel; buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::InstancedModel;
#if ENABLE_GL_SHADERS_ATTRIBUTES
buffer.shader = "gouraud_light_instanced_attr";
#else
buffer.shader = "gouraud_light_instanced"; buffer.shader = "gouraud_light_instanced";
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
buffer.model.model.init_from(diamond(16)); buffer.model.model.init_from(diamond(16));
buffer.model.color = option_color(type); buffer.model.color = option_color(type);
buffer.model.instances.format = InstanceVBuffer::EFormat::InstancedModel; buffer.model.instances.format = InstanceVBuffer::EFormat::InstancedModel;
@ -672,7 +705,11 @@ void GCodeViewer::init()
#endif // !DISABLE_GCODEVIEWER_INSTANCED_MODELS #endif // !DISABLE_GCODEVIEWER_INSTANCED_MODELS
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::BatchedModel; buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::BatchedModel;
buffer.vertices.format = VBuffer::EFormat::PositionNormal3; buffer.vertices.format = VBuffer::EFormat::PositionNormal3;
#if ENABLE_GL_SHADERS_ATTRIBUTES
buffer.shader = "gouraud_light_attr";
#else
buffer.shader = "gouraud_light"; buffer.shader = "gouraud_light";
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
buffer.model.data = diamond(16); buffer.model.data = diamond(16);
buffer.model.color = option_color(type); buffer.model.color = option_color(type);
@ -686,13 +723,22 @@ void GCodeViewer::init()
case EMoveType::Extrude: { case EMoveType::Extrude: {
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle; buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle;
buffer.vertices.format = VBuffer::EFormat::PositionNormal3; buffer.vertices.format = VBuffer::EFormat::PositionNormal3;
#if ENABLE_GL_SHADERS_ATTRIBUTES
buffer.shader = "gouraud_light_attr";
#else
buffer.shader = "gouraud_light"; buffer.shader = "gouraud_light";
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
break; break;
} }
case EMoveType::Travel: { case EMoveType::Travel: {
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line; buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line;
#if ENABLE_GL_SHADERS_ATTRIBUTES
buffer.vertices.format = VBuffer::EFormat::Position;
buffer.shader = "flat_attr";
#else
buffer.vertices.format = VBuffer::EFormat::PositionNormal3; buffer.vertices.format = VBuffer::EFormat::PositionNormal3;
buffer.shader = "toolpaths_lines"; buffer.shader = "toolpaths_lines";
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
break; break;
} }
} }
@ -711,11 +757,11 @@ void GCodeViewer::init()
m_gl_data_initialized = true; m_gl_data_initialized = true;
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& print) void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& print)
#else #else
void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& print, bool initialized) void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& print, bool initialized)
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
{ {
// avoid processing if called with the same gcode_result // avoid processing if called with the same gcode_result
#if ENABLE_VOLUMETRIC_RATE_TOOLPATHS_RECALC #if ENABLE_VOLUMETRIC_RATE_TOOLPATHS_RECALC
@ -754,11 +800,11 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr
m_filament_densities = gcode_result.filament_densities; m_filament_densities = gcode_result.filament_densities;
if (wxGetApp().is_editor()) if (wxGetApp().is_editor())
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
load_shells(print); load_shells(print);
#else #else
load_shells(print, initialized); load_shells(print, initialized);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
else { else {
Pointfs bed_shape; Pointfs bed_shape;
std::string texture; std::string texture;
@ -1278,11 +1324,21 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
// format data into the buffers to be rendered as lines // format data into the buffers to be rendered as lines
auto add_vertices_as_line = [](const GCodeProcessorResult::MoveVertex& prev, const GCodeProcessorResult::MoveVertex& curr, VertexBuffer& vertices) { auto add_vertices_as_line = [](const GCodeProcessorResult::MoveVertex& prev, const GCodeProcessorResult::MoveVertex& curr, VertexBuffer& vertices) {
#if !ENABLE_GL_SHADERS_ATTRIBUTES
// x component of the normal to the current segment (the normal is parallel to the XY plane) // x component of the normal to the current segment (the normal is parallel to the XY plane)
const Vec3f dir = (curr.position - prev.position).normalized(); const Vec3f dir = (curr.position - prev.position).normalized();
Vec3f normal(dir.y(), -dir.x(), 0.0); Vec3f normal(dir.y(), -dir.x(), 0.0);
normal.normalize(); normal.normalize();
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_GL_SHADERS_ATTRIBUTES
auto add_vertex = [&vertices](const GCodeProcessorResult::MoveVertex& vertex) {
// add position
vertices.push_back(vertex.position.x());
vertices.push_back(vertex.position.y());
vertices.push_back(vertex.position.z());
};
#else
auto add_vertex = [&vertices, &normal](const GCodeProcessorResult::MoveVertex& vertex) { auto add_vertex = [&vertices, &normal](const GCodeProcessorResult::MoveVertex& vertex) {
// add position // add position
vertices.push_back(vertex.position.x()); vertices.push_back(vertex.position.x());
@ -1293,6 +1349,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
vertices.push_back(normal.y()); vertices.push_back(normal.y());
vertices.push_back(normal.z()); vertices.push_back(normal.z());
}; };
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
// add previous vertex // add previous vertex
add_vertex(prev); add_vertex(prev);
@ -1571,7 +1628,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
const Transform3d trafo = Geometry::assemble_transform((curr.position - 0.5f * curr.height * Vec3f::UnitZ()).cast<double>(), Vec3d::Zero(), { width, width, height }); const Transform3d trafo = Geometry::assemble_transform((curr.position - 0.5f * curr.height * Vec3f::UnitZ()).cast<double>(), Vec3d::Zero(), { width, width, height });
const Eigen::Matrix<double, 3, 3, Eigen::DontAlign> normal_matrix = trafo.matrix().template block<3, 3>(0, 0).inverse().transpose(); const Eigen::Matrix<double, 3, 3, Eigen::DontAlign> normal_matrix = trafo.matrix().template block<3, 3>(0, 0).inverse().transpose();
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// append vertices // append vertices
const size_t vertices_count = data.vertices_count(); const size_t vertices_count = data.vertices_count();
for (size_t i = 0; i < vertices_count; ++i) { for (size_t i = 0; i < vertices_count; ++i) {
@ -1604,7 +1661,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
vertices.push_back(static_cast<float>(normal.z())); vertices.push_back(static_cast<float>(normal.z()));
} }
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// append instance position // append instance position
instances.push_back(curr.position.x()); instances.push_back(curr.position.x());
@ -1615,10 +1672,10 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
}; };
auto add_indices_as_model_batch = [](const GLModel::Geometry& data, IndexBuffer& indices, IBufferType base_index) { auto add_indices_as_model_batch = [](const GLModel::Geometry& data, IndexBuffer& indices, IBufferType base_index) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
const size_t indices_count = data.indices_count(); const size_t indices_count = data.indices_count();
for (size_t i = 0; i < indices_count; ++i) { for (size_t i = 0; i < indices_count; ++i) {
indices.push_back(static_cast<IBufferType>(data.extract_ushort_index(i) + base_index)); indices.push_back(static_cast<IBufferType>(data.extract_index(i) + base_index));
} }
#else #else
for (const auto& entity : data.entities) { for (const auto& entity : data.entities) {
@ -1626,7 +1683,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
indices.push_back(static_cast<IBufferType>(entity.indices[i] + base_index)); indices.push_back(static_cast<IBufferType>(entity.indices[i] + base_index));
} }
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
}; };
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
@ -2297,11 +2354,11 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
progress_dialog->Destroy(); progress_dialog->Destroy();
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void GCodeViewer::load_shells(const Print& print) void GCodeViewer::load_shells(const Print& print)
#else #else
void GCodeViewer::load_shells(const Print& print, bool initialized) void GCodeViewer::load_shells(const Print& print, bool initialized)
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
{ {
if (print.objects().empty()) if (print.objects().empty())
// no shells, return // no shells, return
@ -2318,11 +2375,11 @@ void GCodeViewer::load_shells(const Print& print, bool initialized)
} }
size_t current_volumes_count = m_shells.volumes.volumes.size(); size_t current_volumes_count = m_shells.volumes.volumes.size();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_shells.volumes.load_object(model_obj, object_id, instance_ids); m_shells.volumes.load_object(model_obj, object_id, instance_ids);
#else #else
m_shells.volumes.load_object(model_obj, object_id, instance_ids, initialized); m_shells.volumes.load_object(model_obj, object_id, instance_ids, initialized);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// adjust shells' z if raft is present // adjust shells' z if raft is present
const SlicingParameters& slicing_parameters = obj->slicing_parameters(); const SlicingParameters& slicing_parameters = obj->slicing_parameters();
@ -2346,7 +2403,7 @@ void GCodeViewer::load_shells(const Print& print, bool initialized)
const float depth = print.wipe_tower_data(extruders_count).depth; const float depth = print.wipe_tower_data(extruders_count).depth;
const float brim_width = print.wipe_tower_data(extruders_count).brim_width; const float brim_width = print.wipe_tower_data(extruders_count).brim_width;
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL #if ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL
m_shells.volumes.load_wipe_tower_preview(config.wipe_tower_x, config.wipe_tower_y, config.wipe_tower_width, depth, max_z, config.wipe_tower_rotation_angle, m_shells.volumes.load_wipe_tower_preview(config.wipe_tower_x, config.wipe_tower_y, config.wipe_tower_width, depth, max_z, config.wipe_tower_rotation_angle,
!print.is_step_done(psWipeTower), brim_width); !print.is_step_done(psWipeTower), brim_width);
@ -2362,7 +2419,7 @@ void GCodeViewer::load_shells(const Print& print, bool initialized)
m_shells.volumes.load_wipe_tower_preview(1000, config.wipe_tower_x, config.wipe_tower_y, config.wipe_tower_width, depth, max_z, config.wipe_tower_rotation_angle, m_shells.volumes.load_wipe_tower_preview(1000, config.wipe_tower_x, config.wipe_tower_y, config.wipe_tower_width, depth, max_z, config.wipe_tower_rotation_angle,
!print.is_step_done(psWipeTower), brim_width, initialized); !print.is_step_done(psWipeTower), brim_width, initialized);
#endif // ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL #endif // ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
} }
@ -2912,15 +2969,17 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
void GCodeViewer::render_toolpaths() void GCodeViewer::render_toolpaths()
{ {
#if ENABLE_FIXED_SCREEN_SIZE_POINT_MARKERS #if ENABLE_FIXED_SCREEN_SIZE_POINT_MARKERS
float point_size = 20.0f; const float point_size = 20.0f;
#else #else
float point_size = 0.8f; const float point_size = 0.8f;
#endif // ENABLE_FIXED_SCREEN_SIZE_POINT_MARKERS #endif // ENABLE_FIXED_SCREEN_SIZE_POINT_MARKERS
std::array<float, 4> light_intensity = { 0.25f, 0.70f, 0.75f, 0.75f }; #if !ENABLE_GL_SHADERS_ATTRIBUTES
const std::array<float, 4> light_intensity = { 0.25f, 0.70f, 0.75f, 0.75f };
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera(); const Camera& camera = wxGetApp().plater()->get_camera();
double zoom = camera.get_zoom(); const double zoom = camera.get_zoom();
const std::array<int, 4>& viewport = camera.get_viewport(); const std::array<int, 4>& viewport = camera.get_viewport();
float near_plane_height = camera.get_type() == Camera::EType::Perspective ? static_cast<float>(viewport[3]) / (2.0f * static_cast<float>(2.0 * std::tan(0.5 * Geometry::deg2rad(camera.get_fov())))) : const float near_plane_height = camera.get_type() == Camera::EType::Perspective ? static_cast<float>(viewport[3]) / (2.0f * static_cast<float>(2.0 * std::tan(0.5 * Geometry::deg2rad(camera.get_fov())))) :
static_cast<float>(viewport[3]) * 0.0005; static_cast<float>(viewport[3]) * 0.0005;
auto shader_init_as_points = [zoom, point_size, near_plane_height](GLShaderProgram& shader) { auto shader_init_as_points = [zoom, point_size, near_plane_height](GLShaderProgram& shader) {
@ -2960,9 +3019,11 @@ void GCodeViewer::render_toolpaths()
glsafe(::glDisable(GL_VERTEX_PROGRAM_POINT_SIZE)); glsafe(::glDisable(GL_VERTEX_PROGRAM_POINT_SIZE));
}; };
#if !ENABLE_GL_SHADERS_ATTRIBUTES
auto shader_init_as_lines = [light_intensity](GLShaderProgram &shader) { auto shader_init_as_lines = [light_intensity](GLShaderProgram &shader) {
shader.set_uniform("light_intensity", light_intensity); shader.set_uniform("light_intensity", light_intensity);
}; };
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
auto render_as_lines = [ auto render_as_lines = [
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
this this
@ -3013,11 +3074,11 @@ void GCodeViewer::render_toolpaths()
} }
if (range.vbo > 0) { if (range.vbo > 0) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
buffer.model.model.set_color(range.color); buffer.model.model.set_color(range.color);
#else #else
buffer.model.model.set_color(-1, range.color); buffer.model.model.set_color(-1, range.color);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
buffer.model.model.render_instanced(range.vbo, range.count); buffer.model.model.render_instanced(range.vbo, range.count);
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
++m_statistics.gl_instanced_models_calls_count; ++m_statistics.gl_instanced_models_calls_count;
@ -3027,11 +3088,19 @@ void GCodeViewer::render_toolpaths()
} }
}; };
#if ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_GCODE_VIEWER_STATISTICS
auto render_as_batched_model = [this](TBuffer& buffer, GLShaderProgram& shader, int position_id, int normal_id) {
#else
auto render_as_batched_model = [](TBuffer& buffer, GLShaderProgram& shader, int position_id, int normal_id) {
#endif // ENABLE_GCODE_VIEWER_STATISTICS
#else
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
auto render_as_batched_model = [this](TBuffer& buffer, GLShaderProgram& shader) { auto render_as_batched_model = [this](TBuffer& buffer, GLShaderProgram& shader) {
#else #else
auto render_as_batched_model = [](TBuffer& buffer, GLShaderProgram& shader) { auto render_as_batched_model = [](TBuffer& buffer, GLShaderProgram& shader) {
#endif // ENABLE_GCODE_VIEWER_STATISTICS #endif // ENABLE_GCODE_VIEWER_STATISTICS
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
struct Range struct Range
{ {
@ -3040,30 +3109,44 @@ void GCodeViewer::render_toolpaths()
bool intersects(const Range& other) const { return (other.last < first || other.first > last) ? false : true; } bool intersects(const Range& other) const { return (other.last < first || other.first > last) ? false : true; }
}; };
Range buffer_range = { 0, 0 }; Range buffer_range = { 0, 0 };
size_t indices_per_instance = buffer.model.data.indices_count(); const size_t indices_per_instance = buffer.model.data.indices_count();
for (size_t j = 0; j < buffer.indices.size(); ++j) { for (size_t j = 0; j < buffer.indices.size(); ++j) {
const IBuffer& i_buffer = buffer.indices[j]; const IBuffer& i_buffer = buffer.indices[j];
buffer_range.last = buffer_range.first + i_buffer.count / indices_per_instance; buffer_range.last = buffer_range.first + i_buffer.count / indices_per_instance;
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo));
#if ENABLE_GL_SHADERS_ATTRIBUTES
if (position_id != -1) {
glsafe(::glVertexAttribPointer(position_id, buffer.vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes()));
glsafe(::glEnableVertexAttribArray(position_id));
}
#else
glsafe(::glVertexPointer(buffer.vertices.position_size_floats(), GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); glsafe(::glVertexPointer(buffer.vertices.position_size_floats(), GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes()));
glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
bool has_normals = buffer.vertices.normal_size_floats() > 0; #endif // ENABLE_GL_SHADERS_ATTRIBUTES
const bool has_normals = buffer.vertices.normal_size_floats() > 0;
if (has_normals) { if (has_normals) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
if (normal_id != -1) {
glsafe(::glVertexAttribPointer(normal_id, buffer.vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes()));
glsafe(::glEnableVertexAttribArray(normal_id));
}
#else
glsafe(::glNormalPointer(GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); glsafe(::glNormalPointer(GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes()));
glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); glsafe(::glEnableClientState(GL_NORMAL_ARRAY));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
} }
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo));
for (auto& range : buffer.model.instances.render_ranges.ranges) { for (auto& range : buffer.model.instances.render_ranges.ranges) {
Range range_range = { range.offset, range.offset + range.count }; const Range range_range = { range.offset, range.offset + range.count };
if (range_range.intersects(buffer_range)) { if (range_range.intersects(buffer_range)) {
shader.set_uniform("uniform_color", range.color); shader.set_uniform("uniform_color", range.color);
unsigned int offset = (range_range.first > buffer_range.first) ? range_range.first - buffer_range.first : 0; const unsigned int offset = (range_range.first > buffer_range.first) ? range_range.first - buffer_range.first : 0;
size_t offset_bytes = static_cast<size_t>(offset) * indices_per_instance * sizeof(IBufferType); const size_t offset_bytes = static_cast<size_t>(offset) * indices_per_instance * sizeof(IBufferType);
Range render_range = { std::max(range_range.first, buffer_range.first), std::min(range_range.last, buffer_range.last) }; const Range render_range = { std::max(range_range.first, buffer_range.first), std::min(range_range.last, buffer_range.last) };
size_t count = static_cast<size_t>(render_range.last - render_range.first) * indices_per_instance; const size_t count = static_cast<size_t>(render_range.last - render_range.first) * indices_per_instance;
if (count > 0) { if (count > 0) {
glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)count, GL_UNSIGNED_SHORT, (const void*)offset_bytes)); glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)count, GL_UNSIGNED_SHORT, (const void*)offset_bytes));
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
@ -3075,10 +3158,17 @@ void GCodeViewer::render_toolpaths()
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
#if ENABLE_GL_SHADERS_ATTRIBUTES
if (normal_id != -1)
glsafe(::glDisableVertexAttribArray(normal_id));
if (position_id != -1)
glsafe(::glDisableVertexAttribArray(position_id));
#else
if (has_normals) if (has_normals)
glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); glsafe(::glDisableClientState(GL_NORMAL_ARRAY));
glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
buffer_range.first = buffer_range.last; buffer_range.first = buffer_range.last;
@ -3089,8 +3179,8 @@ void GCodeViewer::render_toolpaths()
return (zoom < 5.0) ? 1.0 : (1.0 + 5.0 * (zoom - 5.0) / (100.0 - 5.0)); return (zoom < 5.0) ? 1.0 : (1.0 + 5.0 * (zoom - 5.0) / (100.0 - 5.0));
}; };
unsigned char begin_id = buffer_id(EMoveType::Retract); const unsigned char begin_id = buffer_id(EMoveType::Retract);
unsigned char end_id = buffer_id(EMoveType::Count); const unsigned char end_id = buffer_id(EMoveType::Count);
for (unsigned char i = begin_id; i < end_id; ++i) { for (unsigned char i = begin_id; i < end_id; ++i) {
TBuffer& buffer = m_buffers[i]; TBuffer& buffer = m_buffers[i];
@ -3098,9 +3188,23 @@ void GCodeViewer::render_toolpaths()
continue; continue;
GLShaderProgram* shader = wxGetApp().get_shader(buffer.shader.c_str()); GLShaderProgram* shader = wxGetApp().get_shader(buffer.shader.c_str());
if (shader != nullptr) { if (shader == nullptr)
continue;
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
int position_id = -1;
int normal_id = -1;
const Transform3d& view_matrix = camera.get_view_matrix();
shader->set_uniform("view_model_matrix", view_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
shader->set_uniform("normal_matrix", (Matrix3d)view_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
position_id = shader->get_attrib_location("v_position");
normal_id = shader->get_attrib_location("v_normal");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::InstancedModel) { if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::InstancedModel) {
shader->set_uniform("emission_factor", 0.25f); shader->set_uniform("emission_factor", 0.25f);
render_as_instanced_model(buffer, *shader); render_as_instanced_model(buffer, *shader);
@ -3108,32 +3212,56 @@ void GCodeViewer::render_toolpaths()
} }
else if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::BatchedModel) { else if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::BatchedModel) {
shader->set_uniform("emission_factor", 0.25f); shader->set_uniform("emission_factor", 0.25f);
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_as_batched_model(buffer, *shader, position_id, normal_id);
#else
render_as_batched_model(buffer, *shader); render_as_batched_model(buffer, *shader);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
shader->set_uniform("emission_factor", 0.0f); shader->set_uniform("emission_factor", 0.0f);
} }
else { else {
#if ENABLE_GL_SHADERS_ATTRIBUTES
if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::Point)
shader_init_as_points(*shader);
#else
switch (buffer.render_primitive_type) { switch (buffer.render_primitive_type) {
case TBuffer::ERenderPrimitiveType::Point: shader_init_as_points(*shader); break; case TBuffer::ERenderPrimitiveType::Point: shader_init_as_points(*shader); break;
case TBuffer::ERenderPrimitiveType::Line: shader_init_as_lines(*shader); break; case TBuffer::ERenderPrimitiveType::Line: shader_init_as_lines(*shader); break;
default: break; default: break;
} }
int uniform_color = shader->get_uniform_location("uniform_color"); #endif // ENABLE_GL_SHADERS_ATTRIBUTES
const int uniform_color = shader->get_uniform_location("uniform_color");
auto it_path = buffer.render_paths.begin(); auto it_path = buffer.render_paths.begin();
for (unsigned int ibuffer_id = 0; ibuffer_id < static_cast<unsigned int>(buffer.indices.size()); ++ibuffer_id) { for (unsigned int ibuffer_id = 0; ibuffer_id < static_cast<unsigned int>(buffer.indices.size()); ++ibuffer_id) {
const IBuffer& i_buffer = buffer.indices[ibuffer_id]; const IBuffer& i_buffer = buffer.indices[ibuffer_id];
// Skip all paths with ibuffer_id < ibuffer_id. // Skip all paths with ibuffer_id < ibuffer_id.
for (; it_path != buffer.render_paths.end() && it_path->ibuffer_id < ibuffer_id; ++ it_path) ; for (; it_path != buffer.render_paths.end() && it_path->ibuffer_id < ibuffer_id; ++it_path);
if (it_path == buffer.render_paths.end() || it_path->ibuffer_id > ibuffer_id) if (it_path == buffer.render_paths.end() || it_path->ibuffer_id > ibuffer_id)
// Not found. This shall not happen. // Not found. This shall not happen.
continue; continue;
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo));
#if ENABLE_GL_SHADERS_ATTRIBUTES
if (position_id != -1) {
glsafe(::glVertexAttribPointer(position_id, buffer.vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes()));
glsafe(::glEnableVertexAttribArray(position_id));
}
#else
glsafe(::glVertexPointer(buffer.vertices.position_size_floats(), GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); glsafe(::glVertexPointer(buffer.vertices.position_size_floats(), GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes()));
glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
bool has_normals = buffer.vertices.normal_size_floats() > 0; #endif // ENABLE_GL_SHADERS_ATTRIBUTES
const bool has_normals = buffer.vertices.normal_size_floats() > 0;
if (has_normals) { if (has_normals) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
if (normal_id != -1) {
glsafe(::glVertexAttribPointer(normal_id, buffer.vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes()));
glsafe(::glEnableVertexAttribArray(normal_id));
}
#else
glsafe(::glNormalPointer(GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); glsafe(::glNormalPointer(GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes()));
glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); glsafe(::glEnableClientState(GL_NORMAL_ARRAY));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
} }
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo));
@ -3159,17 +3287,23 @@ void GCodeViewer::render_toolpaths()
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
#if ENABLE_GL_SHADERS_ATTRIBUTES
if (normal_id != -1)
glsafe(::glDisableVertexAttribArray(normal_id));
if (position_id != -1)
glsafe(::glDisableVertexAttribArray(position_id));
#else
if (has_normals) if (has_normals)
glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); glsafe(::glDisableClientState(GL_NORMAL_ARRAY));
glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
} }
} }
shader->stop_using(); shader->stop_using();
} }
}
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
auto render_sequential_range_cap = [this] auto render_sequential_range_cap = [this]
@ -3177,17 +3311,47 @@ void GCodeViewer::render_toolpaths()
auto render_sequential_range_cap = [] auto render_sequential_range_cap = []
#endif // ENABLE_GCODE_VIEWER_STATISTICS #endif // ENABLE_GCODE_VIEWER_STATISTICS
(const SequentialRangeCap& cap) { (const SequentialRangeCap& cap) {
GLShaderProgram* shader = wxGetApp().get_shader(cap.buffer->shader.c_str()); const TBuffer* buffer = cap.buffer;
if (shader != nullptr) { GLShaderProgram* shader = wxGetApp().get_shader(buffer->shader.c_str());
if (shader == nullptr)
return;
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
int position_id = -1;
int normal_id = -1;
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d& view_matrix = camera.get_view_matrix();
shader->set_uniform("view_model_matrix", view_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
shader->set_uniform("normal_matrix", (Matrix3d)view_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
position_id = shader->get_attrib_location("v_position");
normal_id = shader->get_attrib_location("v_normal");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, cap.vbo)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, cap.vbo));
glsafe(::glVertexPointer(cap.buffer->vertices.position_size_floats(), GL_FLOAT, cap.buffer->vertices.vertex_size_bytes(), (const void*)cap.buffer->vertices.position_offset_bytes())); #if ENABLE_GL_SHADERS_ATTRIBUTES
if (position_id != -1) {
glsafe(::glVertexAttribPointer(position_id, buffer->vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.position_offset_bytes()));
glsafe(::glEnableVertexAttribArray(position_id));
}
#else
glsafe(::glVertexPointer(buffer->vertices.position_size_floats(), GL_FLOAT, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.position_offset_bytes()));
glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
bool has_normals = cap.buffer->vertices.normal_size_floats() > 0; #endif // ENABLE_GL_SHADERS_ATTRIBUTES
const bool has_normals = buffer->vertices.normal_size_floats() > 0;
if (has_normals) { if (has_normals) {
glsafe(::glNormalPointer(GL_FLOAT, cap.buffer->vertices.vertex_size_bytes(), (const void*)cap.buffer->vertices.normal_offset_bytes())); #if ENABLE_GL_SHADERS_ATTRIBUTES
if (normal_id != -1) {
glsafe(::glVertexAttribPointer(normal_id, buffer->vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.normal_offset_bytes()));
glsafe(::glEnableVertexAttribArray(normal_id));
}
#else
glsafe(::glNormalPointer(GL_FLOAT, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.normal_offset_bytes()));
glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); glsafe(::glEnableClientState(GL_NORMAL_ARRAY));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
} }
shader->set_uniform("uniform_color", cap.color); shader->set_uniform("uniform_color", cap.color);
@ -3200,14 +3364,21 @@ void GCodeViewer::render_toolpaths()
++m_statistics.gl_triangles_calls_count; ++m_statistics.gl_triangles_calls_count;
#endif // ENABLE_GCODE_VIEWER_STATISTICS #endif // ENABLE_GCODE_VIEWER_STATISTICS
#if ENABLE_GL_SHADERS_ATTRIBUTES
if (normal_id != -1)
glsafe(::glDisableVertexAttribArray(normal_id));
if (position_id != -1)
glsafe(::glDisableVertexAttribArray(position_id));
#else
if (has_normals) if (has_normals)
glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); glsafe(::glDisableClientState(GL_NORMAL_ARRAY));
glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
shader->stop_using(); shader->stop_using();
}
}; };
for (unsigned int i = 0; i < 2; ++i) { for (unsigned int i = 0; i < 2; ++i) {
@ -3221,11 +3392,15 @@ void GCodeViewer::render_shells()
if (!m_shells.visible || m_shells.volumes.empty()) if (!m_shells.visible || m_shells.volumes.empty())
return; return;
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
#if !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
// when the background processing is enabled, it may happen that the shells data have been loaded // when the background processing is enabled, it may happen that the shells data have been loaded
// before opengl has been initialized for the preview canvas. // before opengl has been initialized for the preview canvas.
// when this happens, the volumes' data have not been sent to gpu yet. // when this happens, the volumes' data have not been sent to gpu yet.
@ -3233,12 +3408,17 @@ void GCodeViewer::render_shells()
if (!v->indexed_vertex_array.has_VBOs()) if (!v->indexed_vertex_array.has_VBOs())
v->finalize_geometry(true); v->finalize_geometry(true);
} }
#endif // !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
// glsafe(::glDepthMask(GL_FALSE)); // glsafe(::glDepthMask(GL_FALSE));
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
m_shells.volumes.render(GLVolumeCollection::ERenderType::Transparent, true, camera.get_view_matrix(), camera.get_projection_matrix());
#else
m_shells.volumes.render(GLVolumeCollection::ERenderType::Transparent, true, wxGetApp().plater()->get_camera().get_view_matrix()); m_shells.volumes.render(GLVolumeCollection::ERenderType::Transparent, true, wxGetApp().plater()->get_camera().get_view_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
shader->stop_using(); shader->stop_using();
// glsafe(::glDepthMask(GL_TRUE)); // glsafe(::glDepthMask(GL_TRUE));
@ -4449,13 +4629,13 @@ void GCodeViewer::render_statistics()
ImGuiWrapper& imgui = *wxGetApp().imgui(); ImGuiWrapper& imgui = *wxGetApp().imgui();
auto add_time = [this, &imgui](const std::string& label, int64_t time) { auto add_time = [&imgui](const std::string& label, int64_t time) {
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label); imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label);
ImGui::SameLine(offset); ImGui::SameLine(offset);
imgui.text(std::to_string(time) + " ms (" + get_time_dhms(static_cast<float>(time) * 0.001f) + ")"); imgui.text(std::to_string(time) + " ms (" + get_time_dhms(static_cast<float>(time) * 0.001f) + ")");
}; };
auto add_memory = [this, &imgui](const std::string& label, int64_t memory) { auto add_memory = [&imgui](const std::string& label, int64_t memory) {
auto format_string = [memory](const std::string& units, float value) { auto format_string = [memory](const std::string& units, float value) {
return std::to_string(memory) + " bytes (" + return std::to_string(memory) + " bytes (" +
Slic3r::float_to_string_decimal_point(float(memory) * value, 3) Slic3r::float_to_string_decimal_point(float(memory) * value, 3)
@ -4478,7 +4658,7 @@ void GCodeViewer::render_statistics()
imgui.text(format_string("GB", inv_gb)); imgui.text(format_string("GB", inv_gb));
}; };
auto add_counter = [this, &imgui](const std::string& label, int64_t counter) { auto add_counter = [&imgui](const std::string& label, int64_t counter) {
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label); imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label);
ImGui::SameLine(offset); ImGui::SameLine(offset);
imgui.text(std::to_string(counter)); imgui.text(std::to_string(counter));

View File

@ -365,11 +365,11 @@ class GCodeViewer
} }
case ERenderPrimitiveType::InstancedModel: { return model.model.is_initialized() && !model.instances.buffer.empty(); } case ERenderPrimitiveType::InstancedModel: { return model.model.is_initialized() && !model.instances.buffer.empty(); }
case ERenderPrimitiveType::BatchedModel: { case ERenderPrimitiveType::BatchedModel: {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
return !model.data.vertices.empty() && !model.data.indices.empty() && return !model.data.vertices.empty() && !model.data.indices.empty() &&
#else #else
return model.data.vertices_count() > 0 && model.data.indices_count() && return model.data.vertices_count() > 0 && model.data.indices_count() &&
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
!vertices.vbos.empty() && vertices.vbos.front() != 0 && !indices.empty() && indices.front().ibo != 0; !vertices.vbos.empty() && vertices.vbos.front() != 0 && !indices.empty() && indices.front().ibo != 0;
} }
default: { return false; } default: { return false; }
@ -421,11 +421,11 @@ class GCodeViewer
const float radius = m_fixed_size ? 10.0f : 1.0f; const float radius = m_fixed_size ? 10.0f : 1.0f;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_model.init_from(smooth_sphere(32, radius)); m_model.init_from(smooth_sphere(32, radius));
#else #else
m_model.init_from(its_make_sphere(radius, PI / 32.0)); m_model.init_from(its_make_sphere(radius, PI / 32.0));
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
}; };
#endif // ENABLE_SHOW_TOOLPATHS_COG #endif // ENABLE_SHOW_TOOLPATHS_COG
@ -823,11 +823,11 @@ public:
void init(); void init();
// extract rendering data from the given parameters // extract rendering data from the given parameters
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void load(const GCodeProcessorResult& gcode_result, const Print& print); void load(const GCodeProcessorResult& gcode_result, const Print& print);
#else #else
void load(const GCodeProcessorResult& gcode_result, const Print& print, bool initialized); void load(const GCodeProcessorResult& gcode_result, const Print& print, bool initialized);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// recalculate ranges in dependence of what is visible and sets tool/print colors // recalculate ranges in dependence of what is visible and sets tool/print colors
void refresh(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors); void refresh(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors);
#if ENABLE_PREVIEW_LAYOUT #if ENABLE_PREVIEW_LAYOUT
@ -887,11 +887,11 @@ public:
private: private:
void load_toolpaths(const GCodeProcessorResult& gcode_result); void load_toolpaths(const GCodeProcessorResult& gcode_result);
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void load_shells(const Print& print); void load_shells(const Print& print);
#else #else
void load_shells(const Print& print, bool initialized); void load_shells(const Print& print, bool initialized);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if !ENABLE_PREVIEW_LAYOUT #if !ENABLE_PREVIEW_LAYOUT
void refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const; void refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const;
#endif // !ENABLE_PREVIEW_LAYOUT #endif // !ENABLE_PREVIEW_LAYOUT

File diff suppressed because it is too large Load Diff

View File

@ -239,18 +239,24 @@ class GLCanvas3D
int last_object_id{ -1 }; int last_object_id{ -1 };
float last_z{ 0.0f }; float last_z{ 0.0f };
LayerHeightEditActionType last_action{ LAYER_HEIGHT_EDIT_ACTION_INCREASE }; LayerHeightEditActionType last_action{ LAYER_HEIGHT_EDIT_ACTION_INCREASE };
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
struct Profile struct Profile
{ {
GLModel baseline; GLModel baseline;
GLModel profile; GLModel profile;
GLModel background; GLModel background;
#if ENABLE_GL_SHADERS_ATTRIBUTES
float old_canvas_width{ 0.0f };
#else
Rect old_bar_rect; Rect old_bar_rect;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
std::vector<double> old_layer_height_profile; std::vector<double> old_layer_height_profile;
#if !ENABLE_GL_SHADERS_ATTRIBUTES
bool dirty{ false }; bool dirty{ false };
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
}; };
Profile m_profile; Profile m_profile;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
LayersEditing() = default; LayersEditing() = default;
~LayersEditing(); ~LayersEditing();
@ -277,7 +283,9 @@ class GLCanvas3D
static float get_cursor_z_relative(const GLCanvas3D& canvas); static float get_cursor_z_relative(const GLCanvas3D& canvas);
static bool bar_rect_contains(const GLCanvas3D& canvas, float x, float y); static bool bar_rect_contains(const GLCanvas3D& canvas, float x, float y);
static Rect get_bar_rect_screen(const GLCanvas3D& canvas); static Rect get_bar_rect_screen(const GLCanvas3D& canvas);
#if !ENABLE_GL_SHADERS_ATTRIBUTES
static Rect get_bar_rect_viewport(const GLCanvas3D& canvas); static Rect get_bar_rect_viewport(const GLCanvas3D& canvas);
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
static float get_overlay_window_width() { return LayersEditing::s_overlay_window_width; } static float get_overlay_window_width() { return LayersEditing::s_overlay_window_width; }
float object_max_z() const { return m_object_max_z; } float object_max_z() const { return m_object_max_z; }
@ -287,8 +295,13 @@ class GLCanvas3D
private: private:
bool is_initialized() const; bool is_initialized() const;
void generate_layer_height_texture(); void generate_layer_height_texture();
#if ENABLE_GL_SHADERS_ATTRIBUTES
void render_active_object_annotations(const GLCanvas3D& canvas);
void render_profile(const GLCanvas3D& canvas);
#else
void render_active_object_annotations(const GLCanvas3D& canvas, const Rect& bar_rect); void render_active_object_annotations(const GLCanvas3D& canvas, const Rect& bar_rect);
void render_profile(const Rect& bar_rect); void render_profile(const Rect& bar_rect);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void update_slicing_parameters(); void update_slicing_parameters();
static float thickness_bar_width(const GLCanvas3D &canvas); static float thickness_bar_width(const GLCanvas3D &canvas);
@ -335,7 +348,7 @@ class GLCanvas3D
struct SlaCap struct SlaCap
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
struct Triangles struct Triangles
{ {
GLModel object; GLModel object;
@ -353,7 +366,7 @@ class GLCanvas3D
typedef std::map<unsigned int, Triangles> ObjectIdToTrianglesMap; typedef std::map<unsigned int, Triangles> ObjectIdToTrianglesMap;
double z; double z;
ObjectIdToTrianglesMap triangles; ObjectIdToTrianglesMap triangles;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
SlaCap() { reset(); } SlaCap() { reset(); }
void reset() { z = DBL_MAX; triangles.clear(); } void reset() { z = DBL_MAX; triangles.clear(); }
@ -620,7 +633,7 @@ private:
} }
m_gizmo_highlighter; m_gizmo_highlighter;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_SHOW_CAMERA_TARGET #if ENABLE_SHOW_CAMERA_TARGET
struct CameraTarget struct CameraTarget
{ {
@ -631,7 +644,7 @@ private:
CameraTarget m_camera_target; CameraTarget m_camera_target;
#endif // ENABLE_SHOW_CAMERA_TARGET #endif // ENABLE_SHOW_CAMERA_TARGET
GLModel m_background; GLModel m_background;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
public: public:
explicit GLCanvas3D(wxGLCanvas* canvas, Bed3D &bed); explicit GLCanvas3D(wxGLCanvas* canvas, Bed3D &bed);
@ -940,8 +953,13 @@ private:
void _picking_pass(); void _picking_pass();
void _rectangular_selection_picking_pass(); void _rectangular_selection_picking_pass();
void _render_background(); void _render_background();
#if ENABLE_GL_SHADERS_ATTRIBUTES
void _render_bed(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_axes);
void _render_bed_for_picking(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom);
#else
void _render_bed(bool bottom, bool show_axes); void _render_bed(bool bottom, bool show_axes);
void _render_bed_for_picking(bool bottom); void _render_bed_for_picking(bool bottom);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void _render_objects(GLVolumeCollection::ERenderType type); void _render_objects(GLVolumeCollection::ERenderType type);
void _render_gcode(); void _render_gcode();
#if ENABLE_SHOW_TOOLPATHS_COG #if ENABLE_SHOW_TOOLPATHS_COG

File diff suppressed because it is too large Load Diff

View File

@ -14,16 +14,16 @@ namespace Slic3r {
class TriangleMesh; class TriangleMesh;
class Polygon; class Polygon;
using Polygons = std::vector<Polygon>; using Polygons = std::vector<Polygon>;
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
class BuildVolume; class BuildVolume;
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
namespace GUI { namespace GUI {
class GLModel class GLModel
{ {
public: public:
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
enum class EPrimitiveType : unsigned char enum class EPrimitiveType : unsigned char
{ {
Triangles, Triangles,
@ -40,11 +40,11 @@ namespace GUI {
size_t indices_count{ 0 }; size_t indices_count{ 0 };
ColorRGBA color; ColorRGBA color;
}; };
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
struct Geometry struct Geometry
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
enum class EPrimitiveType : unsigned char enum class EPrimitiveType : unsigned char
{ {
Points, Points,
@ -68,23 +68,25 @@ namespace GUI {
enum class EIndexType : unsigned char enum class EIndexType : unsigned char
{ {
UINT, // unsigned int UINT, // unsigned int
USHORT // unsigned short USHORT, // unsigned short
UBYTE // unsigned byte
}; };
struct Format struct Format
{ {
EPrimitiveType type{ EPrimitiveType::Triangles }; EPrimitiveType type{ EPrimitiveType::Triangles };
EVertexLayout vertex_layout{ EVertexLayout::P3N3 }; EVertexLayout vertex_layout{ EVertexLayout::P3N3 };
EIndexType index_type{ EIndexType::UINT };
}; };
Format format; Format format;
std::vector<float> vertices; std::vector<float> vertices;
std::vector<unsigned char> indices; std::vector<unsigned int> indices;
EIndexType index_type{ EIndexType::UINT };
ColorRGBA color{ ColorRGBA::BLACK() }; ColorRGBA color{ ColorRGBA::BLACK() };
void reserve_vertices(size_t vertices_count); void reserve_vertices(size_t vertices_count) { vertices.reserve(vertices_count * vertex_stride_floats(format)); }
void reserve_indices(size_t indices_count); void reserve_indices(size_t indices_count) { indices.reserve(indices_count * index_stride_bytes(*this)); }
void add_vertex(const Vec2f& position); // EVertexLayout::P2 void add_vertex(const Vec2f& position); // EVertexLayout::P2
void add_vertex(const Vec2f& position, const Vec2f& tex_coord); // EVertexLayout::P2T2 void add_vertex(const Vec2f& position, const Vec2f& tex_coord); // EVertexLayout::P2T2
@ -92,42 +94,31 @@ namespace GUI {
void add_vertex(const Vec3f& position, const Vec2f& tex_coord); // EVertexLayout::P3T2 void add_vertex(const Vec3f& position, const Vec2f& tex_coord); // EVertexLayout::P3T2
void add_vertex(const Vec3f& position, const Vec3f& normal); // EVertexLayout::P3N3 void add_vertex(const Vec3f& position, const Vec3f& normal); // EVertexLayout::P3N3
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
void set_vertex(size_t id, const Vec3f& position, const Vec3f& normal); // EVertexLayout::P3N3 void set_vertex(size_t id, const Vec3f& position, const Vec3f& normal); // EVertexLayout::P3N3
void set_ushort_index(size_t id, unsigned short index); void set_index(size_t id, unsigned int index);
void set_uint_index(size_t id, unsigned int index);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
void add_ushort_index(unsigned short id); void add_index(unsigned int id);
void add_uint_index(unsigned int id); void add_line(unsigned int id1, unsigned int id2);
void add_triangle(unsigned int id1, unsigned int id2, unsigned int id3);
void add_ushort_line(unsigned short id1, unsigned short id2);
void add_uint_line(unsigned int id1, unsigned int id2);
void add_ushort_triangle(unsigned short id1, unsigned short id2, unsigned short id3);
void add_uint_triangle(unsigned int id1, unsigned int id2, unsigned int id3);
Vec2f extract_position_2(size_t id) const; Vec2f extract_position_2(size_t id) const;
Vec3f extract_position_3(size_t id) const; Vec3f extract_position_3(size_t id) const;
Vec3f extract_normal_3(size_t id) const; Vec3f extract_normal_3(size_t id) const;
Vec2f extract_tex_coord_2(size_t id) const; Vec2f extract_tex_coord_2(size_t id) const;
unsigned int extract_uint_index(size_t id) const; unsigned int extract_index(size_t id) const;
unsigned short extract_ushort_index(size_t id) const;
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
void remove_vertex(size_t id); void remove_vertex(size_t id);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
bool is_empty() const { return vertices_count() == 0 || indices_count() == 0; } bool is_empty() const { return vertices_count() == 0 || indices_count() == 0; }
size_t vertices_count() const { return vertices.size() / vertex_stride_floats(format); } size_t vertices_count() const { return vertices.size() / vertex_stride_floats(format); }
size_t indices_count() const { return indices.size() / index_stride_bytes(format); } size_t indices_count() const { return indices.size(); }
size_t vertices_size_floats() const { return vertices.size(); } size_t vertices_size_floats() const { return vertices.size(); }
size_t vertices_size_bytes() const { return vertices_size_floats() * sizeof(float); } size_t vertices_size_bytes() const { return vertices_size_floats() * sizeof(float); }
size_t indices_size_bytes() const { return indices.size(); } size_t indices_size_bytes() const { return indices.size() * index_stride_bytes(*this); }
static size_t vertex_stride_floats(const Format& format); static size_t vertex_stride_floats(const Format& format);
static size_t vertex_stride_bytes(const Format& format) { return vertex_stride_floats(format) * sizeof(float); } static size_t vertex_stride_bytes(const Format& format) { return vertex_stride_floats(format) * sizeof(float); }
@ -147,9 +138,7 @@ namespace GUI {
static size_t tex_coord_offset_floats(const Format& format); static size_t tex_coord_offset_floats(const Format& format);
static size_t tex_coord_offset_bytes(const Format& format) { return tex_coord_offset_floats(format) * sizeof(float); } static size_t tex_coord_offset_bytes(const Format& format) { return tex_coord_offset_floats(format) * sizeof(float); }
static size_t index_stride_bytes(const Format& format); static size_t index_stride_bytes(const Geometry& data);
static EIndexType index_type(size_t vertices_count);
static bool has_position(const Format& format); static bool has_position(const Format& format);
static bool has_normal(const Format& format); static bool has_normal(const Format& format);
@ -172,10 +161,10 @@ namespace GUI {
size_t indices_count() const; size_t indices_count() const;
size_t indices_size_bytes() const { return indices_count() * sizeof(unsigned int); } size_t indices_size_bytes() const { return indices_count() * sizeof(unsigned int); }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
}; };
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
struct RenderData struct RenderData
{ {
Geometry geometry; Geometry geometry;
@ -184,16 +173,35 @@ namespace GUI {
size_t vertices_count{ 0 }; size_t vertices_count{ 0 };
size_t indices_count{ 0 }; size_t indices_count{ 0 };
}; };
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
private: private:
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
RenderData m_render_data; #if ENABLE_GLMODEL_STATISTICS
#else struct Statistics
std::vector<RenderData> m_render_data; {
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL struct Buffers
{
struct Data
{
size_t current{ 0 };
size_t max{ 0 };
};
Data indices;
Data vertices;
};
Buffers gpu_memory;
int64_t render_calls{ 0 };
int64_t render_instanced_calls{ 0 };
};
static Statistics s_statistics;
#endif // ENABLE_GLMODEL_STATISTICS
RenderData m_render_data;
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
// By default the vertex and index buffers data are sent to gpu at the first call to render() method. // By default the vertex and index buffers data are sent to gpu at the first call to render() method.
// If you need to initialize a model from outside the main thread, so that a call to render() may happen // If you need to initialize a model from outside the main thread, so that a call to render() may happen
// before the initialization is complete, use the methods: // before the initialization is complete, use the methods:
@ -202,7 +210,9 @@ namespace GUI {
// enable_render() // enable_render()
// to keep the data on cpu side until needed. // to keep the data on cpu side until needed.
bool m_render_disabled{ false }; bool m_render_disabled{ false };
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #else
std::vector<RenderData> m_render_data;
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
BoundingBoxf3 m_bounding_box; BoundingBoxf3 m_bounding_box;
std::string m_filename; std::string m_filename;
@ -210,7 +220,7 @@ namespace GUI {
GLModel() = default; GLModel() = default;
virtual ~GLModel() { reset(); } virtual ~GLModel() { reset(); }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
size_t vertices_count() const { return m_render_data.vertices_count > 0 ? size_t vertices_count() const { return m_render_data.vertices_count > 0 ?
m_render_data.vertices_count : m_render_data.geometry.vertices_count(); } m_render_data.vertices_count : m_render_data.geometry.vertices_count(); }
size_t indices_count() const { return m_render_data.indices_count > 0 ? size_t indices_count() const { return m_render_data.indices_count > 0 ?
@ -219,11 +229,9 @@ namespace GUI {
size_t vertices_size_floats() const { return vertices_count() * Geometry::vertex_stride_floats(m_render_data.geometry.format); } size_t vertices_size_floats() const { return vertices_count() * Geometry::vertex_stride_floats(m_render_data.geometry.format); }
size_t vertices_size_bytes() const { return vertices_size_floats() * sizeof(float); } size_t vertices_size_bytes() const { return vertices_size_floats() * sizeof(float); }
size_t indices_size_bytes() const { return indices_count() * Geometry::index_stride_bytes(m_render_data.geometry.format); } size_t indices_size_bytes() const { return indices_count() * Geometry::index_stride_bytes(m_render_data.geometry); }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
const Geometry& get_geometry() const { return m_render_data.geometry; } const Geometry& get_geometry() const { return m_render_data.geometry; }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
void init_from(Geometry&& data); void init_from(Geometry&& data);
#if ENABLE_SMOOTH_NORMALS #if ENABLE_SMOOTH_NORMALS
@ -234,43 +242,39 @@ namespace GUI {
#else #else
void init_from(const Geometry& data); void init_from(const Geometry& data);
void init_from(const indexed_triangle_set& its, const BoundingBoxf3& bbox); void init_from(const indexed_triangle_set& its, const BoundingBoxf3& bbox);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
void init_from(const indexed_triangle_set& its); void init_from(const indexed_triangle_set& its);
void init_from(const Polygons& polygons, float z); void init_from(const Polygons& polygons, float z);
bool init_from_file(const std::string& filename); bool init_from_file(const std::string& filename);
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void set_color(const ColorRGBA& color) { m_render_data.geometry.color = color; } void set_color(const ColorRGBA& color) { m_render_data.geometry.color = color; }
const ColorRGBA& get_color() const { return m_render_data.geometry.color; } const ColorRGBA& get_color() const { return m_render_data.geometry.color; }
#else #else
// if entity_id == -1 set the color of all entities // if entity_id == -1 set the color of all entities
void set_color(int entity_id, const ColorRGBA& color); void set_color(int entity_id, const ColorRGBA& color);
ColorRGBA get_color(size_t entity_id = 0U) const; ColorRGBA get_color(size_t entity_id = 0U) const;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
void reset(); void reset();
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void render(); void render();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
void render(const std::pair<size_t, size_t>& range); void render(const std::pair<size_t, size_t>& range);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
void render_instanced(unsigned int instances_vbo, unsigned int instances_count); void render_instanced(unsigned int instances_vbo, unsigned int instances_count);
bool is_initialized() const { return vertices_count() > 0 && indices_count() > 0; } bool is_initialized() const { return vertices_count() > 0 && indices_count() > 0; }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
bool is_empty() const { return m_render_data.geometry.is_empty(); } bool is_empty() const { return m_render_data.geometry.is_empty(); }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
#else #else
void render() const; void render() const;
void render_instanced(unsigned int instances_vbo, unsigned int instances_count) const; void render_instanced(unsigned int instances_vbo, unsigned int instances_count) const;
bool is_initialized() const { return !m_render_data.empty(); } bool is_initialized() const { return !m_render_data.empty(); }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
const BoundingBoxf3& get_bounding_box() const { return m_bounding_box; } const BoundingBoxf3& get_bounding_box() const { return m_bounding_box; }
const std::string& get_filename() const { return m_filename; } const std::string& get_filename() const { return m_filename; }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
bool is_render_disabled() const { return m_render_disabled; } bool is_render_disabled() const { return m_render_disabled; }
void enable_render() { m_render_disabled = false; } void enable_render() { m_render_disabled = false; }
void disable_render() { m_render_disabled = true; } void disable_render() { m_render_disabled = true; }
@ -291,31 +295,39 @@ namespace GUI {
ret += indices_size_bytes(); ret += indices_size_bytes();
return ret; return ret;
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
#if ENABLE_GLMODEL_STATISTICS
static void render_statistics();
static void reset_statistics_counters() {
s_statistics.render_calls = 0;
s_statistics.render_instanced_calls = 0;
}
#endif // ENABLE_GLMODEL_STATISTICS
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
private: private:
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
bool send_to_gpu(); bool send_to_gpu();
#else #else
void send_to_gpu(RenderData& data, const std::vector<float>& vertices, const std::vector<unsigned int>& indices); void send_to_gpu(RenderData& data, const std::vector<float>& vertices, const std::vector<unsigned int>& indices);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
}; };
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
bool contains(const BuildVolume& volume, const GLModel& model, bool ignore_bottom = true); bool contains(const BuildVolume& volume, const GLModel& model, bool ignore_bottom = true);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// create an arrow with cylindrical stem and conical tip, with the given dimensions and resolution // create an arrow with cylindrical stem and conical tip, with the given dimensions and resolution
// the origin of the arrow is in the center of the stem cap // the origin of the arrow is in the center of the stem cap
// the arrow has its axis of symmetry along the Z axis and is pointing upward // the arrow has its axis of symmetry along the Z axis and is pointing upward
// used to render bed axes and sequential marker // used to render bed axes and sequential marker
GLModel::Geometry stilized_arrow(unsigned short resolution, float tip_radius, float tip_height, float stem_radius, float stem_height); GLModel::Geometry stilized_arrow(unsigned int resolution, float tip_radius, float tip_height, float stem_radius, float stem_height);
// create an arrow whose stem is a quarter of circle, with the given dimensions and resolution // create an arrow whose stem is a quarter of circle, with the given dimensions and resolution
// the origin of the arrow is in the center of the circle // the origin of the arrow is in the center of the circle
// the arrow is contained in the 1st quadrant of the XY plane and is pointing counterclockwise // the arrow is contained in the 1st quadrant of the XY plane and is pointing counterclockwise
// used to render sidebar hints for rotations // used to render sidebar hints for rotations
GLModel::Geometry circular_arrow(unsigned short resolution, float radius, float tip_height, float tip_width, float stem_width, float thickness); GLModel::Geometry circular_arrow(unsigned int resolution, float radius, float tip_height, float tip_width, float stem_width, float thickness);
// create an arrow with the given dimensions // create an arrow with the given dimensions
// the origin of the arrow is in the center of the stem cap // the origin of the arrow is in the center of the stem cap
@ -326,15 +338,15 @@ namespace GUI {
// create a diamond with the given resolution // create a diamond with the given resolution
// the origin of the diamond is in its center // the origin of the diamond is in its center
// the diamond is contained into a box with size [1, 1, 1] // the diamond is contained into a box with size [1, 1, 1]
GLModel::Geometry diamond(unsigned short resolution); GLModel::Geometry diamond(unsigned int resolution);
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_SHOW_TOOLPATHS_COG #if ENABLE_SHOW_TOOLPATHS_COG
// create a sphere with the given resolution and smooth normals // create a sphere with the given resolution and smooth normals
// the origin of the sphere is in its center // the origin of the sphere is in its center
GLModel::Geometry smooth_sphere(unsigned short resolution, float radius); GLModel::Geometry smooth_sphere(unsigned int resolution, float radius);
#endif // ENABLE_SHOW_TOOLPATHS_COG #endif // ENABLE_SHOW_TOOLPATHS_COG
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} // namespace GUI } // namespace GUI
} // namespace Slic3r } // namespace Slic3r

View File

@ -74,34 +74,49 @@ namespace GUI {
if (!is_dragging()) if (!is_dragging())
return; return;
const Camera& camera = wxGetApp().plater()->get_camera(); const Size cnv_size = canvas.get_canvas_size();
float inv_zoom = (float)camera.get_inv_zoom(); #if ENABLE_GL_SHADERS_ATTRIBUTES
const float cnv_width = (float)cnv_size.get_width();
const float cnv_height = (float)cnv_size.get_height();
if (cnv_width == 0.0f || cnv_height == 0.0f)
return;
Size cnv_size = canvas.get_canvas_size(); const float cnv_inv_width = 1.0f / cnv_width;
float cnv_half_width = 0.5f * (float)cnv_size.get_width(); const float cnv_inv_height = 1.0f / cnv_height;
float cnv_half_height = 0.5f * (float)cnv_size.get_height(); const float left = 2.0f * (get_left() * cnv_inv_width - 0.5f);
const float right = 2.0f * (get_right() * cnv_inv_width - 0.5f);
const float top = -2.0f * (get_top() * cnv_inv_height - 0.5f);
const float bottom = -2.0f * (get_bottom() * cnv_inv_height - 0.5f);
#else
const Camera& camera = wxGetApp().plater()->get_camera();
const float inv_zoom = (float)camera.get_inv_zoom();
const float cnv_half_width = 0.5f * (float)cnv_size.get_width();
const float cnv_half_height = 0.5f * (float)cnv_size.get_height();
if (cnv_half_width == 0.0f || cnv_half_height == 0.0f) if (cnv_half_width == 0.0f || cnv_half_height == 0.0f)
return; return;
Vec2d start(m_start_corner(0) - cnv_half_width, cnv_half_height - m_start_corner(1)); const Vec2d start(m_start_corner.x() - cnv_half_width, cnv_half_height - m_start_corner.y());
Vec2d end(m_end_corner(0) - cnv_half_width, cnv_half_height - m_end_corner(1)); const Vec2d end(m_end_corner.x() - cnv_half_width, cnv_half_height - m_end_corner.y());
const float left = (float)std::min(start(0), end(0)) * inv_zoom; const float left = (float)std::min(start.x(), end.x()) * inv_zoom;
const float top = (float)std::max(start(1), end(1)) * inv_zoom; const float top = (float)std::max(start.y(), end.y()) * inv_zoom;
const float right = (float)std::max(start(0), end(0)) * inv_zoom; const float right = (float)std::max(start.x(), end.x()) * inv_zoom;
const float bottom = (float)std::min(start(1), end(1)) * inv_zoom; const float bottom = (float)std::min(start.y(), end.y()) * inv_zoom;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glLineWidth(1.5f)); glsafe(::glLineWidth(1.5f));
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
float color[3]; float color[3];
color[0] = (m_state == Select) ? 0.3f : 1.0f; color[0] = (m_state == Select) ? 0.3f : 1.0f;
color[1] = (m_state == Select) ? 1.0f : 0.3f; color[1] = (m_state == Select) ? 1.0f : 0.3f;
color[2] = 0.3f; color[2] = 0.3f;
glsafe(::glColor3fv(color)); glsafe(::glColor3fv(color));
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glLoadIdentity()); glsafe(::glLoadIdentity());
// ensure that the rectangle is renderered inside the frustrum // ensure that the rectangle is renderered inside the frustrum
@ -109,13 +124,18 @@ namespace GUI {
// ensure that the overlay fits the frustrum near z plane // ensure that the overlay fits the frustrum near z plane
const double gui_scale = camera.get_gui_scale(); const double gui_scale = camera.get_gui_scale();
glsafe(::glScaled(gui_scale, gui_scale, 1.0)); glsafe(::glScaled(gui_scale, gui_scale, 1.0));
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPushAttrib(GL_ENABLE_BIT)); glsafe(::glPushAttrib(GL_ENABLE_BIT));
glsafe(::glLineStipple(4, 0xAAAA)); glsafe(::glLineStipple(4, 0xAAAA));
glsafe(::glEnable(GL_LINE_STIPPLE)); glsafe(::glEnable(GL_LINE_STIPPLE));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
@ -125,7 +145,7 @@ namespace GUI {
m_rectangle.reset(); m_rectangle.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2 };
init_data.reserve_vertices(4); init_data.reserve_vertices(4);
init_data.reserve_indices(4); init_data.reserve_indices(4);
@ -136,19 +156,20 @@ namespace GUI {
init_data.add_vertex(Vec2f(left, top)); init_data.add_vertex(Vec2f(left, top));
// indices // indices
init_data.add_ushort_index(0); init_data.add_index(0);
init_data.add_ushort_index(1); init_data.add_index(1);
init_data.add_ushort_index(2); init_data.add_index(2);
init_data.add_ushort_index(3); init_data.add_index(3);
m_rectangle.init_from(std::move(init_data)); m_rectangle.init_from(std::move(init_data));
} }
const ColorRGBA color( #if ENABLE_GL_SHADERS_ATTRIBUTES
(m_state == Select) ? 0.3f : 1.0f, shader->set_uniform("view_model_matrix", Transform3d::Identity());
(m_state == Select) ? 1.0f : 0.3f, shader->set_uniform("projection_matrix", Transform3d::Identity());
0.3f, 1.0f); #endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_rectangle.set_color(color);
m_rectangle.set_color(ColorRGBA((m_state == Select) ? 0.3f : 1.0f, (m_state == Select) ? 1.0f : 0.3f, 0.3f, 1.0f));
m_rectangle.render(); m_rectangle.render();
shader->stop_using(); shader->stop_using();
} }
@ -159,11 +180,13 @@ namespace GUI {
::glVertex2f((GLfloat)right, (GLfloat)top); ::glVertex2f((GLfloat)right, (GLfloat)top);
::glVertex2f((GLfloat)left, (GLfloat)top); ::glVertex2f((GLfloat)left, (GLfloat)top);
glsafe(::glEnd()); glsafe(::glEnd());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glPopAttrib()); glsafe(::glPopAttrib());
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
} // namespace GUI } // namespace GUI

View File

@ -2,9 +2,9 @@
#define slic3r_GLSelectionRectangle_hpp_ #define slic3r_GLSelectionRectangle_hpp_
#include "libslic3r/Point.hpp" #include "libslic3r/Point.hpp"
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#include "GLModel.hpp" #include "GLModel.hpp"
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
@ -38,22 +38,22 @@ public:
bool is_dragging() const { return m_state != Off; } bool is_dragging() const { return m_state != Off; }
EState get_state() const { return m_state; } EState get_state() const { return m_state; }
float get_width() const { return std::abs(m_start_corner(0) - m_end_corner(0)); } float get_width() const { return std::abs(m_start_corner.x() - m_end_corner.x()); }
float get_height() const { return std::abs(m_start_corner(1) - m_end_corner(1)); } float get_height() const { return std::abs(m_start_corner.y() - m_end_corner.y()); }
float get_left() const { return std::min(m_start_corner(0), m_end_corner(0)); } float get_left() const { return std::min(m_start_corner.x(), m_end_corner.x()); }
float get_right() const { return std::max(m_start_corner(0), m_end_corner(0)); } float get_right() const { return std::max(m_start_corner.x(), m_end_corner.x()); }
float get_top() const { return std::max(m_start_corner(1), m_end_corner(1)); } float get_top() const { return std::max(m_start_corner.y(), m_end_corner.y()); }
float get_bottom() const { return std::min(m_start_corner(1), m_end_corner(1)); } float get_bottom() const { return std::min(m_start_corner.y(), m_end_corner.y()); }
private: private:
EState m_state{ Off }; EState m_state{ Off };
Vec2d m_start_corner{ Vec2d::Zero() }; Vec2d m_start_corner{ Vec2d::Zero() };
Vec2d m_end_corner{ Vec2d::Zero() }; Vec2d m_end_corner{ Vec2d::Zero() };
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel m_rectangle; GLModel m_rectangle;
Vec2d m_old_start_corner{ Vec2d::Zero() }; Vec2d m_old_start_corner{ Vec2d::Zero() };
Vec2d m_old_end_corner{ Vec2d::Zero() }; Vec2d m_old_end_corner{ Vec2d::Zero() };
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
}; };

View File

@ -296,6 +296,13 @@ void GLShaderProgram::set_uniform(int id, const Matrix3f& value) const
glsafe(::glUniformMatrix3fv(id, 1, GL_FALSE, static_cast<const GLfloat*>(value.data()))); glsafe(::glUniformMatrix3fv(id, 1, GL_FALSE, static_cast<const GLfloat*>(value.data())));
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void GLShaderProgram::set_uniform(int id, const Matrix3d& value) const
{
set_uniform(id, (Matrix3f)value.cast<float>());
}
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void GLShaderProgram::set_uniform(int id, const Vec3f& value) const void GLShaderProgram::set_uniform(int id, const Vec3f& value) const
{ {
if (id >= 0) if (id >= 0)

View File

@ -61,6 +61,9 @@ public:
void set_uniform(const char* name, const Transform3f& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const Transform3f& value) const { set_uniform(get_uniform_location(name), value); }
void set_uniform(const char* name, const Transform3d& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const Transform3d& value) const { set_uniform(get_uniform_location(name), value); }
void set_uniform(const char* name, const Matrix3f& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const Matrix3f& value) const { set_uniform(get_uniform_location(name), value); }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void set_uniform(const char* name, const Matrix3d& value) const { set_uniform(get_uniform_location(name), value); }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void set_uniform(const char* name, const Vec3f& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const Vec3f& value) const { set_uniform(get_uniform_location(name), value); }
void set_uniform(const char* name, const Vec3d& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const Vec3d& value) const { set_uniform(get_uniform_location(name), value); }
void set_uniform(const char* name, const ColorRGB& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const ColorRGB& value) const { set_uniform(get_uniform_location(name), value); }
@ -80,6 +83,9 @@ public:
void set_uniform(int id, const Transform3f& value) const; void set_uniform(int id, const Transform3f& value) const;
void set_uniform(int id, const Transform3d& value) const; void set_uniform(int id, const Transform3d& value) const;
void set_uniform(int id, const Matrix3f& value) const; void set_uniform(int id, const Matrix3f& value) const;
#if ENABLE_GL_SHADERS_ATTRIBUTES
void set_uniform(int id, const Matrix3d& value) const;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void set_uniform(int id, const Vec3f& value) const; void set_uniform(int id, const Vec3f& value) const;
void set_uniform(int id, const Vec3d& value) const; void set_uniform(int id, const Vec3d& value) const;
void set_uniform(int id, const ColorRGB& value) const; void set_uniform(int id, const ColorRGB& value) const;

View File

@ -33,47 +33,91 @@ std::pair<bool, std::string> GLShadersManager::init()
bool valid = true; bool valid = true;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
// basic shader, used to render all what was previously rendered using the immediate mode
valid &= append_shader("flat_attr", { "flat_attr.vs", "flat.fs" });
// basic shader for textures, used to render textures
valid &= append_shader("flat_texture_attr", { "flat_texture_attr.vs", "flat_texture.fs" });
// used to render 3D scene background
valid &= append_shader("background_attr", { "background_attr.vs", "background.fs" });
#else
// basic shader, used to render all what was previously rendered using the immediate mode // basic shader, used to render all what was previously rendered using the immediate mode
valid &= append_shader("flat", { "flat.vs", "flat.fs" }); valid &= append_shader("flat", { "flat.vs", "flat.fs" });
// basic shader for textures, used to render textures // basic shader for textures, used to render textures
valid &= append_shader("flat_texture", { "flat_texture.vs", "flat_texture.fs" }); valid &= append_shader("flat_texture", { "flat_texture.vs", "flat_texture.fs" });
// used to render 3D scene background // used to render 3D scene background
valid &= append_shader("background", { "background.vs", "background.fs" }); valid &= append_shader("background", { "background.vs", "background.fs" });
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GL_SHADERS_ATTRIBUTES
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_SHOW_TOOLPATHS_COG #if ENABLE_SHOW_TOOLPATHS_COG
// used to render toolpaths center of gravity // used to render toolpaths center of gravity
#if ENABLE_GL_SHADERS_ATTRIBUTES
valid &= append_shader("toolpaths_cog_attr", { "toolpaths_cog_attr.vs", "toolpaths_cog.fs" });
#else
valid &= append_shader("toolpaths_cog", { "toolpaths_cog.vs", "toolpaths_cog.fs" }); valid &= append_shader("toolpaths_cog", { "toolpaths_cog.vs", "toolpaths_cog.fs" });
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#endif // ENABLE_SHOW_TOOLPATHS_COG #endif // ENABLE_SHOW_TOOLPATHS_COG
#if ENABLE_GL_SHADERS_ATTRIBUTES
// used to render bed axes and model, selection hints, gcode sequential view marker model, preview shells, options in gcode preview
valid &= append_shader("gouraud_light_attr", { "gouraud_light_attr.vs", "gouraud_light.fs" });
// used to render printbed
valid &= append_shader("printbed_attr", { "printbed_attr.vs", "printbed.fs" });
#else
// used to render bed axes and model, selection hints, gcode sequential view marker model, preview shells, options in gcode preview // used to render bed axes and model, selection hints, gcode sequential view marker model, preview shells, options in gcode preview
valid &= append_shader("gouraud_light", { "gouraud_light.vs", "gouraud_light.fs" }); valid &= append_shader("gouraud_light", { "gouraud_light.vs", "gouraud_light.fs" });
// used to render printbed // used to render printbed
valid &= append_shader("printbed", { "printbed.vs", "printbed.fs" }); valid &= append_shader("printbed", { "printbed.vs", "printbed.fs" });
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
// used to render options in gcode preview // used to render options in gcode preview
if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
valid &= append_shader("gouraud_light_instanced_attr", { "gouraud_light_instanced_attr.vs", "gouraud_light_instanced.fs" });
#else
valid &= append_shader("gouraud_light_instanced", { "gouraud_light_instanced.vs", "gouraud_light_instanced.fs" }); valid &= append_shader("gouraud_light_instanced", { "gouraud_light_instanced.vs", "gouraud_light_instanced.fs" });
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
}
#if ENABLE_GL_SHADERS_ATTRIBUTES
// used to render objects in 3d editor
valid &= append_shader("gouraud_attr", { "gouraud_attr.vs", "gouraud.fs" }
#else
// used to render extrusion and travel paths as lines in gcode preview // used to render extrusion and travel paths as lines in gcode preview
valid &= append_shader("toolpaths_lines", { "toolpaths_lines.vs", "toolpaths_lines.fs" }); valid &= append_shader("toolpaths_lines", { "toolpaths_lines.vs", "toolpaths_lines.fs" });
// used to render objects in 3d editor // used to render objects in 3d editor
valid &= append_shader("gouraud", { "gouraud.vs", "gouraud.fs" } valid &= append_shader("gouraud", { "gouraud.vs", "gouraud.fs" }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_ENVIRONMENT_MAP #if ENABLE_ENVIRONMENT_MAP
, { "ENABLE_ENVIRONMENT_MAP"sv } , { "ENABLE_ENVIRONMENT_MAP"sv }
#endif // ENABLE_ENVIRONMENT_MAP #endif // ENABLE_ENVIRONMENT_MAP
); );
#if ENABLE_GL_SHADERS_ATTRIBUTES
// used to render variable layers heights in 3d editor
valid &= append_shader("variable_layer_height_attr", { "variable_layer_height_attr.vs", "variable_layer_height.fs" });
// used to render highlight contour around selected triangles inside the multi-material gizmo
valid &= append_shader("mm_contour_attr", { "mm_contour_attr.vs", "mm_contour_attr.fs" });
#else
// used to render variable layers heights in 3d editor // used to render variable layers heights in 3d editor
valid &= append_shader("variable_layer_height", { "variable_layer_height.vs", "variable_layer_height.fs" }); valid &= append_shader("variable_layer_height", { "variable_layer_height.vs", "variable_layer_height.fs" });
// used to render highlight contour around selected triangles inside the multi-material gizmo // used to render highlight contour around selected triangles inside the multi-material gizmo
valid &= append_shader("mm_contour", { "mm_contour.vs", "mm_contour.fs" }); valid &= append_shader("mm_contour", { "mm_contour.vs", "mm_contour.fs" });
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
// Used to render painted triangles inside the multi-material gizmo. Triangle normals are computed inside fragment shader. // Used to render painted triangles inside the multi-material gizmo. Triangle normals are computed inside fragment shader.
// For Apple's on Arm CPU computed triangle normals inside fragment shader using dFdx and dFdy has the opposite direction. // For Apple's on Arm CPU computed triangle normals inside fragment shader using dFdx and dFdy has the opposite direction.
// Because of this, objects had darker colors inside the multi-material gizmo. // Because of this, objects had darker colors inside the multi-material gizmo.
// Based on https://stackoverflow.com/a/66206648, the similar behavior was also spotted on some other devices with Arm CPU. // Based on https://stackoverflow.com/a/66206648, the similar behavior was also spotted on some other devices with Arm CPU.
// Since macOS 12 (Monterey), this issue with the opposite direction on Apple's Arm CPU seems to be fixed, and computed // Since macOS 12 (Monterey), this issue with the opposite direction on Apple's Arm CPU seems to be fixed, and computed
// triangle normals inside fragment shader have the right direction. // triangle normals inside fragment shader have the right direction.
#if ENABLE_GL_SHADERS_ATTRIBUTES
if (platform_flavor() == PlatformFlavor::OSXOnArm && wxPlatformInfo::Get().GetOSMajorVersion() < 12)
valid &= append_shader("mm_gouraud_attr", { "mm_gouraud_attr.vs", "mm_gouraud_attr.fs" }, { "FLIP_TRIANGLE_NORMALS"sv });
else
valid &= append_shader("mm_gouraud_attr", { "mm_gouraud_attr.vs", "mm_gouraud_attr.fs" });
#else
if (platform_flavor() == PlatformFlavor::OSXOnArm && wxPlatformInfo::Get().GetOSMajorVersion() < 12) if (platform_flavor() == PlatformFlavor::OSXOnArm && wxPlatformInfo::Get().GetOSMajorVersion() < 12)
valid &= append_shader("mm_gouraud", {"mm_gouraud.vs", "mm_gouraud.fs"}, {"FLIP_TRIANGLE_NORMALS"sv}); valid &= append_shader("mm_gouraud", {"mm_gouraud.vs", "mm_gouraud.fs"}, {"FLIP_TRIANGLE_NORMALS"sv});
else else
valid &= append_shader("mm_gouraud", {"mm_gouraud.vs", "mm_gouraud.fs"}); valid &= append_shader("mm_gouraud", {"mm_gouraud.vs", "mm_gouraud.fs"});
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
return { valid, error }; return { valid, error };
} }

View File

@ -3,10 +3,10 @@
#include "3DScene.hpp" #include "3DScene.hpp"
#include "OpenGLManager.hpp" #include "OpenGLManager.hpp"
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#include "GUI_App.hpp" #include "GUI_App.hpp"
#include "GLModel.hpp" #include "GLModel.hpp"
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#include <GL/glew.h> #include <GL/glew.h>
@ -339,9 +339,9 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right,
glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)tex_id)); glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)tex_id));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P2T2, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P2T2 };
init_data.reserve_vertices(4); init_data.reserve_vertices(4);
init_data.reserve_indices(6); init_data.reserve_indices(6);
@ -352,15 +352,23 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right,
init_data.add_vertex(Vec2f(left, top), Vec2f(uvs.left_top.u, uvs.left_top.v)); init_data.add_vertex(Vec2f(left, top), Vec2f(uvs.left_top.u, uvs.left_top.v));
// indices // indices
init_data.add_ushort_triangle(0, 1, 2); init_data.add_triangle(0, 1, 2);
init_data.add_ushort_triangle(2, 3, 0); init_data.add_triangle(2, 3, 0);
GLModel model; GLModel model;
model.init_from(std::move(init_data)); model.init_from(std::move(init_data));
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_texture_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat_texture"); GLShaderProgram* shader = wxGetApp().get_shader("flat_texture");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
shader->set_uniform("view_model_matrix", Transform3d::Identity());
shader->set_uniform("projection_matrix", Transform3d::Identity());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
model.render(); model.render();
shader->stop_using(); shader->stop_using();
} }
@ -371,7 +379,7 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right,
::glTexCoord2f(uvs.right_top.u, uvs.right_top.v); ::glVertex2f(right, top); ::glTexCoord2f(uvs.right_top.u, uvs.right_top.v); ::glVertex2f(right, top);
::glTexCoord2f(uvs.left_top.u, uvs.left_top.v); ::glVertex2f(left, top); ::glTexCoord2f(uvs.left_top.u, uvs.left_top.v); ::glVertex2f(left, top);
glsafe(::glEnd()); glsafe(::glEnd());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); glsafe(::glBindTexture(GL_TEXTURE_2D, 0));

View File

@ -85,26 +85,29 @@ bool GLToolbarItem::update_enabled_state()
return ret; return ret;
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void GLToolbarItem::render(const GLCanvas3D& parent, unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const
#else
void GLToolbarItem::render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const void GLToolbarItem::render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
{ {
auto uvs = [this](unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) -> GLTexture::Quad_UVs auto uvs = [this](unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) -> GLTexture::Quad_UVs {
{ assert(tex_width != 0 && tex_height != 0);
assert((tex_width != 0) && (tex_height != 0));
GLTexture::Quad_UVs ret; GLTexture::Quad_UVs ret;
// tiles in the texture are spaced by 1 pixel // tiles in the texture are spaced by 1 pixel
float icon_size_px = (float)(tex_width - 1) / ((float)Num_States + (float)Num_Rendered_Highlight_States); const float icon_size_px = (float)(tex_width - 1) / ((float)Num_States + (float)Num_Rendered_Highlight_States);
char render_state = (m_highlight_state == NotHighlighted ? m_state : Num_States + m_highlight_state); const char render_state = (m_highlight_state == NotHighlighted ? m_state : Num_States + m_highlight_state);
float inv_tex_width = 1.0f / (float)tex_width; const float inv_tex_width = 1.0f / (float)tex_width;
float inv_tex_height = 1.0f / (float)tex_height; const float inv_tex_height = 1.0f / (float)tex_height;
// tiles in the texture are spaced by 1 pixel // tiles in the texture are spaced by 1 pixel
float u_offset = 1.0f * inv_tex_width; const float u_offset = 1.0f * inv_tex_width;
float v_offset = 1.0f * inv_tex_height; const float v_offset = 1.0f * inv_tex_height;
float du = icon_size_px * inv_tex_width; const float du = icon_size_px * inv_tex_width;
float dv = icon_size_px * inv_tex_height; const float dv = icon_size_px * inv_tex_height;
float left = u_offset + (float)render_state * du; const float left = u_offset + (float)render_state * du;
float right = left + du - u_offset; const float right = left + du - u_offset;
float top = v_offset + (float)m_data.sprite_id * dv; const float top = v_offset + (float)m_data.sprite_id * dv;
float bottom = top + dv - v_offset; const float bottom = top + dv - v_offset;
ret.left_top = { left, top }; ret.left_top = { left, top };
ret.left_bottom = { left, bottom }; ret.left_bottom = { left, bottom };
ret.right_bottom = { right, bottom }; ret.right_bottom = { right, bottom };
@ -114,12 +117,26 @@ void GLToolbarItem::render(unsigned int tex_id, float left, float right, float b
GLTexture::render_sub_texture(tex_id, left, right, bottom, top, uvs(tex_width, tex_height, icon_size)); GLTexture::render_sub_texture(tex_id, left, right, bottom, top, uvs(tex_width, tex_height, icon_size));
if (is_pressed()) if (is_pressed()) {
{ #if ENABLE_GL_SHADERS_ATTRIBUTES
if ((m_last_action_type == Left) && m_data.left.can_render()) const Size cnv_size = parent.get_canvas_size();
const float cnv_w = (float)cnv_size.get_width();
const float cnv_h = (float)cnv_size.get_height();
const float out_left = (0.5f * left + 0.5f) * cnv_w;
const float out_right = (0.5f * right + 0.5f) * cnv_w;
const float out_top = (0.5f * top + 0.5f) * cnv_h;
const float out_bottom = (0.5f * bottom + 0.5f) * cnv_h;
if (m_last_action_type == Left && m_data.left.can_render())
m_data.left.render_callback(out_left, out_right, out_bottom, out_top);
else if (m_last_action_type == Right && m_data.right.can_render())
m_data.right.render_callback(out_left, out_right, out_bottom, out_top);
#else
if (m_last_action_type == Left && m_data.left.can_render())
m_data.left.render_callback(left, right, bottom, top); m_data.left.render_callback(left, right, bottom, top);
else if ((m_last_action_type == Right) && m_data.right.can_render()) else if (m_last_action_type == Right && m_data.right.can_render())
m_data.right.render_callback(left, right, bottom, top); m_data.right.render_callback(left, right, bottom, top);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
} }
} }
@ -185,6 +202,16 @@ bool GLToolbar::init(const BackgroundTexture::Metadata& background_texture)
return res; return res;
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
bool GLToolbar::init_arrow(const std::string& filename)
{
if (m_arrow_texture.get_id() != 0)
return true;
const std::string path = resources_dir() + "/icons/";
return (!filename.empty()) ? m_arrow_texture.load_from_svg_file(path + filename, false, false, false, 512) : false;
}
#else
bool GLToolbar::init_arrow(const BackgroundTexture::Metadata& arrow_texture) bool GLToolbar::init_arrow(const BackgroundTexture::Metadata& arrow_texture)
{ {
if (m_arrow_texture.texture.get_id() != 0) if (m_arrow_texture.texture.get_id() != 0)
@ -193,14 +220,15 @@ bool GLToolbar::init_arrow(const BackgroundTexture::Metadata& arrow_texture)
std::string path = resources_dir() + "/icons/"; std::string path = resources_dir() + "/icons/";
bool res = false; bool res = false;
if (!arrow_texture.filename.empty()) { if (!arrow_texture.filename.empty())
res = m_arrow_texture.texture.load_from_svg_file(path + arrow_texture.filename, false, false, false, 1000); res = m_arrow_texture.texture.load_from_svg_file(path + arrow_texture.filename, false, false, false, 1000);
}
if (res) if (res)
m_arrow_texture.metadata = arrow_texture; m_arrow_texture.metadata = arrow_texture;
return res; return res;
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
GLToolbar::Layout::EType GLToolbar::get_layout_type() const GLToolbar::Layout::EType GLToolbar::get_layout_type() const
{ {
@ -438,14 +466,12 @@ void GLToolbar::render(const GLCanvas3D& parent)
} }
} }
bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent) bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
{ {
if (!m_enabled) if (!m_enabled)
return false; return false;
Vec2d mouse_pos((double)evt.GetX(), (double)evt.GetY()); const Vec2d mouse_pos((double)evt.GetX(), (double)evt.GetY());
bool processed = false; bool processed = false;
// mouse anywhere // mouse anywhere
@ -493,7 +519,7 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
return false; return false;
} }
int item_id = contains_mouse(mouse_pos, parent); const int item_id = contains_mouse(mouse_pos, parent);
if (item_id != -1) { if (item_id != -1) {
// mouse inside toolbar // mouse inside toolbar
if (evt.LeftDown() || evt.LeftDClick()) { if (evt.LeftDown() || evt.LeftDClick()) {
@ -601,16 +627,12 @@ int GLToolbar::get_visible_items_cnt() const
void GLToolbar::do_action(GLToolbarItem::EActionType type, int item_id, GLCanvas3D& parent, bool check_hover) void GLToolbar::do_action(GLToolbarItem::EActionType type, int item_id, GLCanvas3D& parent, bool check_hover)
{ {
if ((m_pressed_toggable_id == -1) || (m_pressed_toggable_id == item_id)) if (m_pressed_toggable_id == -1 || m_pressed_toggable_id == item_id) {
{ if (0 <= item_id && item_id < (int)m_items.size()) {
if ((0 <= item_id) && (item_id < (int)m_items.size()))
{
GLToolbarItem* item = m_items[item_id]; GLToolbarItem* item = m_items[item_id];
if ((item != nullptr) && !item->is_separator() && !item->is_disabled() && (!check_hover || item->is_hovered())) if (item != nullptr && !item->is_separator() && !item->is_disabled() && (!check_hover || item->is_hovered())) {
{ if ((type == GLToolbarItem::Right && item->is_right_toggable()) ||
if (((type == GLToolbarItem::Right) && item->is_right_toggable()) || (type == GLToolbarItem::Left && item->is_left_toggable())) {
((type == GLToolbarItem::Left) && item->is_left_toggable()))
{
GLToolbarItem::EState state = item->get_state(); GLToolbarItem::EState state = item->get_state();
if (state == GLToolbarItem::Hover) if (state == GLToolbarItem::Hover)
item->set_state(GLToolbarItem::HoverPressed); item->set_state(GLToolbarItem::HoverPressed);
@ -632,8 +654,7 @@ void GLToolbar::do_action(GLToolbarItem::EActionType type, int item_id, GLCanvas
case GLToolbarItem::Right: { item->do_right_action(); break; } case GLToolbarItem::Right: { item->do_right_action(); break; }
} }
} }
else else {
{
if (m_type == Radio) if (m_type == Radio)
select_item(item->get_name()); select_item(item->get_name());
else else
@ -648,8 +669,7 @@ void GLToolbar::do_action(GLToolbarItem::EActionType type, int item_id, GLCanvas
case GLToolbarItem::Right: { item->do_right_action(); break; } case GLToolbarItem::Right: { item->do_right_action(); break; }
} }
if ((m_type == Normal) && (item->get_state() != GLToolbarItem::Disabled)) if (m_type == Normal && item->get_state() != GLToolbarItem::Disabled) {
{
// the item may get disabled during the action, if not, set it back to hover state // the item may get disabled during the action, if not, set it back to hover state
item->set_state(GLToolbarItem::Hover); item->set_state(GLToolbarItem::Hover);
parent.render(); parent.render();
@ -673,6 +693,205 @@ void GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent)
} }
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent)
{
const Size cnv_size = parent.get_canvas_size();
const Vec2d scaled_mouse_pos((mouse_pos.x() - 0.5 * (double)cnv_size.get_width()), (0.5 * (double)cnv_size.get_height() - mouse_pos.y()));
const float icons_size = m_layout.icons_size * m_layout.scale;
const float separator_size = m_layout.separator_size * m_layout.scale;
const float gap_size = m_layout.gap_size * m_layout.scale;
const float border = m_layout.border * m_layout.scale;
const float separator_stride = separator_size + gap_size;
const float icon_stride = icons_size + gap_size;
float left = m_layout.left + border;
float top = m_layout.top - border;
for (GLToolbarItem* item : m_items) {
if (!item->is_visible())
continue;
if (item->is_separator())
left += separator_stride;
else {
const float right = left + icons_size;
const float bottom = top - icons_size;
const GLToolbarItem::EState state = item->get_state();
bool inside = (left <= (float)scaled_mouse_pos.x()) &&
((float)scaled_mouse_pos.x() <= right) &&
(bottom <= (float)scaled_mouse_pos.y()) &&
((float)scaled_mouse_pos.y() <= top);
switch (state)
{
case GLToolbarItem::Normal:
{
if (inside) {
item->set_state(GLToolbarItem::Hover);
parent.set_as_dirty();
}
break;
}
case GLToolbarItem::Hover:
{
if (!inside) {
item->set_state(GLToolbarItem::Normal);
parent.set_as_dirty();
}
break;
}
case GLToolbarItem::Pressed:
{
if (inside) {
item->set_state(GLToolbarItem::HoverPressed);
parent.set_as_dirty();
}
break;
}
case GLToolbarItem::HoverPressed:
{
if (!inside) {
item->set_state(GLToolbarItem::Pressed);
parent.set_as_dirty();
}
break;
}
case GLToolbarItem::Disabled:
{
if (inside) {
item->set_state(GLToolbarItem::HoverDisabled);
parent.set_as_dirty();
}
break;
}
case GLToolbarItem::HoverDisabled:
{
if (!inside) {
item->set_state(GLToolbarItem::Disabled);
parent.set_as_dirty();
}
break;
}
default:
{
break;
}
}
left += icon_stride;
}
}
}
void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent)
{
const Size cnv_size = parent.get_canvas_size();
const Vec2d scaled_mouse_pos((mouse_pos.x() - 0.5 * (double)cnv_size.get_width()), (0.5 * (double)cnv_size.get_height() - mouse_pos.y()));
const float icons_size = m_layout.icons_size * m_layout.scale;
const float separator_size = m_layout.separator_size * m_layout.scale;
const float gap_size = m_layout.gap_size * m_layout.scale;
const float border = m_layout.border * m_layout.scale;
const float separator_stride = separator_size + gap_size;
const float icon_stride = icons_size + gap_size;
float left = m_layout.left + border;
float top = m_layout.top - border;
for (GLToolbarItem* item : m_items) {
if (!item->is_visible())
continue;
if (item->is_separator())
top -= separator_stride;
else {
const float right = left + icons_size;
const float bottom = top - icons_size;
GLToolbarItem::EState state = item->get_state();
const bool inside = (left <= (float)scaled_mouse_pos.x()) &&
((float)scaled_mouse_pos.x() <= right) &&
(bottom <= (float)scaled_mouse_pos.y()) &&
((float)scaled_mouse_pos.y() <= top);
switch (state)
{
case GLToolbarItem::Normal:
{
if (inside) {
item->set_state(GLToolbarItem::Hover);
parent.set_as_dirty();
}
break;
}
case GLToolbarItem::Hover:
{
if (!inside) {
item->set_state(GLToolbarItem::Normal);
parent.set_as_dirty();
}
break;
}
case GLToolbarItem::Pressed:
{
if (inside) {
item->set_state(GLToolbarItem::HoverPressed);
parent.set_as_dirty();
}
break;
}
case GLToolbarItem::HoverPressed:
{
if (!inside) {
item->set_state(GLToolbarItem::Pressed);
parent.set_as_dirty();
}
break;
}
case GLToolbarItem::Disabled:
{
if (inside) {
item->set_state(GLToolbarItem::HoverDisabled);
parent.set_as_dirty();
}
break;
}
case GLToolbarItem::HoverDisabled:
{
if (!inside) {
item->set_state(GLToolbarItem::Disabled);
parent.set_as_dirty();
}
break;
}
default:
{
break;
}
}
top -= icon_stride;
}
}
}
#else
void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent) void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent)
{ {
// NB: mouse_pos is already scaled appropriately // NB: mouse_pos is already scaled appropriately
@ -889,19 +1108,17 @@ void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D&
} }
} }
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
GLToolbarItem* GLToolbar::get_item(const std::string& item_name) GLToolbarItem* GLToolbar::get_item(const std::string& item_name)
{ {
if (!m_enabled) if (!m_enabled)
return nullptr; return nullptr;
for (GLToolbarItem* item : m_items) for (GLToolbarItem* item : m_items) {
{
if (item->get_name() == item_name) if (item->get_name() == item_name)
{
return item; return item;
} }
}
return nullptr; return nullptr;
} }
@ -918,6 +1135,155 @@ int GLToolbar::contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent)
} }
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const
{
const Size cnv_size = parent.get_canvas_size();
const Vec2d scaled_mouse_pos((mouse_pos.x() - 0.5 * (double)cnv_size.get_width()), (0.5 * (double)cnv_size.get_height() - mouse_pos.y()));
const float icons_size = m_layout.icons_size * m_layout.scale;
const float separator_size = m_layout.separator_size * m_layout.scale;
const float gap_size = m_layout.gap_size * m_layout.scale;
const float border = m_layout.border * m_layout.scale;
float left = m_layout.left + border;
const float top = m_layout.top - border;
for (size_t id = 0; id < m_items.size(); ++id) {
GLToolbarItem* item = m_items[id];
if (!item->is_visible())
continue;
if (item->is_separator()) {
float right = left + separator_size;
const float bottom = top - icons_size;
// mouse inside the separator
if (left <= (float)scaled_mouse_pos.x() &&
(float)scaled_mouse_pos.x() <= right &&
bottom <= (float)scaled_mouse_pos.y() &&
(float)scaled_mouse_pos.y() <= top)
return id;
left = right;
right += gap_size;
if (id < m_items.size() - 1) {
// mouse inside the gap
if (left <= (float)scaled_mouse_pos.x() &&
(float)scaled_mouse_pos.x() <= right &&
bottom <= (float)scaled_mouse_pos.y() &&
(float)scaled_mouse_pos.y() <= top)
return -2;
}
left = right;
}
else {
float right = left + icons_size;
const float bottom = top - icons_size;
// mouse inside the icon
if (left <= (float)scaled_mouse_pos.x() &&
(float)scaled_mouse_pos.x() <= right &&
bottom <= (float)scaled_mouse_pos.y() &&
(float)scaled_mouse_pos.y() <= top)
return id;
left = right;
right += gap_size;
if (id < m_items.size() - 1) {
// mouse inside the gap
if (left <= (float)scaled_mouse_pos.x() &&
(float)scaled_mouse_pos.x() <= right &&
bottom <= (float)scaled_mouse_pos.y() &&
(float)scaled_mouse_pos.y() <= top)
return -2;
}
left = right;
}
}
return -1;
}
int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& parent) const
{
const Size cnv_size = parent.get_canvas_size();
const Vec2d scaled_mouse_pos((mouse_pos.x() - 0.5 * (double)cnv_size.get_width()), (0.5 * (double)cnv_size.get_height() - mouse_pos.y()));
const float icons_size = m_layout.icons_size * m_layout.scale;
const float separator_size = m_layout.separator_size * m_layout.scale;
const float gap_size = m_layout.gap_size * m_layout.scale;
const float border = m_layout.border * m_layout.scale;
const float left = m_layout.left + border;
float top = m_layout.top - border;
for (size_t id = 0; id < m_items.size(); ++id) {
GLToolbarItem* item = m_items[id];
if (!item->is_visible())
continue;
if (item->is_separator()) {
const float right = left + icons_size;
float bottom = top - separator_size;
// mouse inside the separator
if (left <= (float)scaled_mouse_pos.x() &&
(float)scaled_mouse_pos.x() <= right &&
bottom <= (float)scaled_mouse_pos.y() &&
(float)scaled_mouse_pos.y() <= top)
return id;
top = bottom;
bottom -= gap_size;
if (id < m_items.size() - 1) {
// mouse inside the gap
if (left <= (float)scaled_mouse_pos.x() &&
(float)scaled_mouse_pos.x() <= right &&
bottom <= (float)scaled_mouse_pos.y() &&
(float)scaled_mouse_pos.y() <= top)
return -2;
}
top = bottom;
}
else {
const float right = left + icons_size;
float bottom = top - icons_size;
// mouse inside the icon
if (left <= (float)scaled_mouse_pos.x() &&
(float)scaled_mouse_pos.x() <= right &&
bottom <= (float)scaled_mouse_pos.y() &&
(float)scaled_mouse_pos.y() <= top)
return id;
top = bottom;
bottom -= gap_size;
if (id < m_items.size() - 1) {
// mouse inside the gap
if (left <= (float)scaled_mouse_pos.x() &&
(float)scaled_mouse_pos.x() <= right &&
bottom <= (float)scaled_mouse_pos.y() &&
(float)scaled_mouse_pos.y() <= top)
return -2;
}
top = bottom;
}
}
return -1;
}
#else
int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const
{ {
// NB: mouse_pos is already scaled appropriately // NB: mouse_pos is already scaled appropriately
@ -1062,14 +1428,92 @@ int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D&
return -1; return -1;
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_GL_SHADERS_ATTRIBUTES
void GLToolbar::render_background(float left, float top, float right, float bottom, float border_w, float border_h) const
{
const unsigned int tex_id = m_background_texture.texture.get_id();
const float tex_width = (float)m_background_texture.texture.get_width();
const float tex_height = (float)m_background_texture.texture.get_height();
if (tex_id != 0 && tex_width > 0.0f && tex_height > 0.0f) {
const float inv_tex_width = 1.0f / tex_width;
const float inv_tex_height = 1.0f / tex_height;
const float internal_left = left + border_w;
const float internal_right = right - border_w;
const float internal_top = top - border_h;
const float internal_bottom = bottom + border_w;
const float left_uv = 0.0f;
const float right_uv = 1.0f;
const float top_uv = 1.0f;
const float bottom_uv = 0.0f;
const float internal_left_uv = (float)m_background_texture.metadata.left * inv_tex_width;
const float internal_right_uv = 1.0f - (float)m_background_texture.metadata.right * inv_tex_width;
const float internal_top_uv = 1.0f - (float)m_background_texture.metadata.top * inv_tex_height;
const float internal_bottom_uv = (float)m_background_texture.metadata.bottom * inv_tex_height;
// top-left corner
if (m_layout.horizontal_orientation == Layout::HO_Left || m_layout.vertical_orientation == Layout::VO_Top)
GLTexture::render_sub_texture(tex_id, left, internal_left, internal_top, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
else
GLTexture::render_sub_texture(tex_id, left, internal_left, internal_top, top, { { left_uv, internal_top_uv }, { internal_left_uv, internal_top_uv }, { internal_left_uv, top_uv }, { left_uv, top_uv } });
// top edge
if (m_layout.vertical_orientation == Layout::VO_Top)
GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_top, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
else
GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_top, top, { { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, top_uv }, { internal_left_uv, top_uv } });
// top-right corner
if (m_layout.horizontal_orientation == Layout::HO_Right || m_layout.vertical_orientation == Layout::VO_Top)
GLTexture::render_sub_texture(tex_id, internal_right, right, internal_top, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
else
GLTexture::render_sub_texture(tex_id, internal_right, right, internal_top, top, { { internal_right_uv, internal_top_uv }, { right_uv, internal_top_uv }, { right_uv, top_uv }, { internal_right_uv, top_uv } });
// center-left edge
if (m_layout.horizontal_orientation == Layout::HO_Left)
GLTexture::render_sub_texture(tex_id, left, internal_left, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
else
GLTexture::render_sub_texture(tex_id, left, internal_left, internal_bottom, internal_top, { { left_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv }, { internal_left_uv, internal_top_uv }, { left_uv, internal_top_uv } });
// center
GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
// center-right edge
if (m_layout.horizontal_orientation == Layout::HO_Right)
GLTexture::render_sub_texture(tex_id, internal_right, right, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
else
GLTexture::render_sub_texture(tex_id, internal_right, right, internal_bottom, internal_top, { { internal_right_uv, internal_bottom_uv }, { right_uv, internal_bottom_uv }, { right_uv, internal_top_uv }, { internal_right_uv, internal_top_uv } });
// bottom-left corner
if (m_layout.horizontal_orientation == Layout::HO_Left || m_layout.vertical_orientation == Layout::VO_Bottom)
GLTexture::render_sub_texture(tex_id, left, internal_left, bottom, internal_bottom, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
else
GLTexture::render_sub_texture(tex_id, left, internal_left, bottom, internal_bottom, { { left_uv, bottom_uv }, { internal_left_uv, bottom_uv }, { internal_left_uv, internal_bottom_uv }, { left_uv, internal_bottom_uv } });
// bottom edge
if (m_layout.vertical_orientation == Layout::VO_Bottom)
GLTexture::render_sub_texture(tex_id, internal_left, internal_right, bottom, internal_bottom, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
else
GLTexture::render_sub_texture(tex_id, internal_left, internal_right, bottom, internal_bottom, { { internal_left_uv, bottom_uv }, { internal_right_uv, bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv } });
// bottom-right corner
if (m_layout.horizontal_orientation == Layout::HO_Right || m_layout.vertical_orientation == Layout::VO_Bottom)
GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
else
GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } });
}
}
#else
void GLToolbar::render_background(float left, float top, float right, float bottom, float border) const void GLToolbar::render_background(float left, float top, float right, float bottom, float border) const
{ {
unsigned int tex_id = m_background_texture.texture.get_id(); unsigned int tex_id = m_background_texture.texture.get_id();
float tex_width = (float)m_background_texture.texture.get_width(); float tex_width = (float)m_background_texture.texture.get_width();
float tex_height = (float)m_background_texture.texture.get_height(); float tex_height = (float)m_background_texture.texture.get_height();
if ((tex_id != 0) && (tex_width > 0) && (tex_height > 0)) if (tex_id != 0 && tex_width > 0 && tex_height > 0) {
{
float inv_tex_width = (tex_width != 0.0f) ? 1.0f / tex_width : 0.0f; float inv_tex_width = (tex_width != 0.0f) ? 1.0f / tex_width : 0.0f;
float inv_tex_height = (tex_height != 0.0f) ? 1.0f / tex_height : 0.0f; float inv_tex_height = (tex_height != 0.0f) ? 1.0f / tex_height : 0.0f;
@ -1140,7 +1584,78 @@ void GLToolbar::render_background(float left, float top, float right, float bott
GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } }); GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } });
} }
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_GL_SHADERS_ATTRIBUTES
void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighted_item)
{
// arrow texture not initialized
if (m_arrow_texture.get_id() == 0)
return;
const Size cnv_size = parent.get_canvas_size();
const float cnv_w = (float)cnv_size.get_width();
const float cnv_h = (float)cnv_size.get_height();
if (cnv_w == 0 || cnv_h == 0)
return;
const float inv_cnv_w = 1.0f / cnv_w;
const float inv_cnv_h = 1.0f / cnv_h;
const float icons_size_x = 2.0f * m_layout.icons_size * m_layout.scale * inv_cnv_w;
const float icons_size_y = 2.0f * m_layout.icons_size * m_layout.scale * inv_cnv_h;
const float separator_size = 2.0f * m_layout.separator_size * m_layout.scale * inv_cnv_w;
const float gap_size = 2.0f * m_layout.gap_size * m_layout.scale * inv_cnv_w;
const float border_x = 2.0f * m_layout.border * m_layout.scale * inv_cnv_w;
const float border_y = 2.0f * m_layout.border * m_layout.scale * inv_cnv_h;
const float separator_stride = separator_size + gap_size;
const float icon_stride = icons_size_x + gap_size;
float left = 2.0f * m_layout.left * inv_cnv_w + border_x;
float top = 2.0f * m_layout.top * inv_cnv_h - 2.0f * border_y - icons_size_y;
bool found = false;
for (const GLToolbarItem* item : m_items) {
if (!item->is_visible())
continue;
if (item->is_separator())
left += separator_stride;
else {
if (item->get_name() == highlighted_item->get_name()) {
found = true;
break;
}
left += icon_stride;
}
}
if (!found)
return;
const float right = left + icons_size_x;
const unsigned int tex_id = m_arrow_texture.get_id();
// arrow width and height
const float arr_tex_width = (float)m_arrow_texture.get_width();
const float arr_tex_height = (float)m_arrow_texture.get_height();
if (tex_id != 0 && arr_tex_width > 0.0f && arr_tex_height > 0.0f) {
const float arrow_size_x = 2.0f * m_layout.scale * arr_tex_width * inv_cnv_w;
const float arrow_size_y = 2.0f * m_layout.scale * arr_tex_height * inv_cnv_h;
const float left_uv = 0.0f;
const float right_uv = 1.0f;
const float top_uv = 1.0f;
const float bottom_uv = 0.0f;
top -= border_y;
const float bottom = top - arrow_size_y * icons_size_x / arrow_size_x;
GLTexture::render_sub_texture(tex_id, left, right, bottom, top, { { left_uv, top_uv }, { right_uv, top_uv }, { right_uv, bottom_uv }, { left_uv, bottom_uv } });
}
}
#else
void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighted_item) void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighted_item)
{ {
// arrow texture not initialized // arrow texture not initialized
@ -1206,7 +1721,119 @@ void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighte
GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_bottom, internal_top, { { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv } }); GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_bottom, internal_top, { { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv } });
} }
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_GL_SHADERS_ATTRIBUTES
void GLToolbar::render_horizontal(const GLCanvas3D& parent)
{
const Size cnv_size = parent.get_canvas_size();
const float cnv_w = (float)cnv_size.get_width();
const float cnv_h = (float)cnv_size.get_height();
if (cnv_w == 0 || cnv_h == 0)
return;
const unsigned int tex_id = m_icons_texture.get_id();
const int tex_width = m_icons_texture.get_width();
const int tex_height = m_icons_texture.get_height();
if (tex_id == 0 || tex_width <= 0 || tex_height <= 0)
return;
const float inv_cnv_w = 1.0f / cnv_w;
const float inv_cnv_h = 1.0f / cnv_h;
const float icons_size_x = 2.0f * m_layout.icons_size * m_layout.scale * inv_cnv_w;
const float icons_size_y = 2.0f * m_layout.icons_size * m_layout.scale * inv_cnv_h;
const float separator_size = 2.0f * m_layout.separator_size * m_layout.scale * inv_cnv_w;
const float gap_size = 2.0f * m_layout.gap_size * m_layout.scale * inv_cnv_w;
const float border_w = 2.0f * m_layout.border * m_layout.scale * inv_cnv_w;
const float border_h = 2.0f * m_layout.border * m_layout.scale * inv_cnv_h;
const float width = 2.0f * get_width() * inv_cnv_w;
const float height = 2.0f * get_height() * inv_cnv_h;
const float separator_stride = separator_size + gap_size;
const float icon_stride = icons_size_x + gap_size;
float left = 2.0f * m_layout.left * inv_cnv_w;
float top = 2.0f * m_layout.top * inv_cnv_h;
const float right = left + width;
const float bottom = top - height;
render_background(left, top, right, bottom, border_w, border_h);
left += border_w;
top -= border_h;
// renders icons
for (const GLToolbarItem* item : m_items) {
if (!item->is_visible())
continue;
if (item->is_separator())
left += separator_stride;
else {
item->render(parent, tex_id, left, left + icons_size_x, top - icons_size_y, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale));
left += icon_stride;
}
}
}
void GLToolbar::render_vertical(const GLCanvas3D& parent)
{
const Size cnv_size = parent.get_canvas_size();
const float cnv_w = (float)cnv_size.get_width();
const float cnv_h = (float)cnv_size.get_height();
if (cnv_w == 0 || cnv_h == 0)
return;
const unsigned int tex_id = m_icons_texture.get_id();
const int tex_width = m_icons_texture.get_width();
const int tex_height = m_icons_texture.get_height();
if (tex_id == 0 || tex_width <= 0 || tex_height <= 0)
return;
const float inv_cnv_w = 1.0f / cnv_w;
const float inv_cnv_h = 1.0f / cnv_h;
const float icons_size_x = 2.0f * m_layout.icons_size * m_layout.scale * inv_cnv_w;
const float icons_size_y = 2.0f * m_layout.icons_size * m_layout.scale * inv_cnv_h;
const float separator_size = 2.0f * m_layout.separator_size * m_layout.scale * inv_cnv_h;
const float gap_size = 2.0f * m_layout.gap_size * m_layout.scale * inv_cnv_h;
const float border_w = 2.0f * m_layout.border * m_layout.scale * inv_cnv_w;
const float border_h = 2.0f * m_layout.border * m_layout.scale * inv_cnv_h;
const float width = 2.0f * get_width() * inv_cnv_w;
const float height = 2.0f * get_height() * inv_cnv_h;
const float separator_stride = separator_size + gap_size;
const float icon_stride = icons_size_y + gap_size;
float left = 2.0f * m_layout.left * inv_cnv_w;
float top = 2.0f * m_layout.top * inv_cnv_h;
const float right = left + width;
const float bottom = top - height;
render_background(left, top, right, bottom, border_w, border_h);
left += border_w;
top -= border_h;
// renders icons
for (const GLToolbarItem* item : m_items) {
if (!item->is_visible())
continue;
if (item->is_separator())
top -= separator_stride;
else {
item->render(parent, tex_id, left, left + icons_size_x, top - icons_size_y, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale));
top -= icon_stride;
}
}
}
#else
void GLToolbar::render_horizontal(const GLCanvas3D& parent) void GLToolbar::render_horizontal(const GLCanvas3D& parent)
{ {
unsigned int tex_id = m_icons_texture.get_id(); unsigned int tex_id = m_icons_texture.get_id();
@ -1300,6 +1927,7 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent)
} }
} }
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
bool GLToolbar::generate_icons_texture() bool GLToolbar::generate_icons_texture()
{ {

View File

@ -153,7 +153,12 @@ public:
// returns true if the state changes // returns true if the state changes
bool update_enabled_state(); bool update_enabled_state();
#if ENABLE_GL_SHADERS_ATTRIBUTES
void render(const GLCanvas3D& parent, unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const;
#else
void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const; void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
private: private:
void set_visible(bool visible) { m_data.visible = visible; } void set_visible(bool visible) { m_data.visible = visible; }
@ -246,7 +251,11 @@ private:
GLTexture m_icons_texture; GLTexture m_icons_texture;
bool m_icons_texture_dirty; bool m_icons_texture_dirty;
BackgroundTexture m_background_texture; BackgroundTexture m_background_texture;
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLTexture m_arrow_texture;
#else
BackgroundTexture m_arrow_texture; BackgroundTexture m_arrow_texture;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
Layout m_layout; Layout m_layout;
ItemsList m_items; ItemsList m_items;
@ -273,7 +282,11 @@ public:
bool init(const BackgroundTexture::Metadata& background_texture); bool init(const BackgroundTexture::Metadata& background_texture);
#if ENABLE_GL_SHADERS_ATTRIBUTES
bool init_arrow(const std::string& filename);
#else
bool init_arrow(const BackgroundTexture::Metadata& arrow_texture); bool init_arrow(const BackgroundTexture::Metadata& arrow_texture);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
Layout::EType get_layout_type() const; Layout::EType get_layout_type() const;
void set_layout_type(Layout::EType type); void set_layout_type(Layout::EType type);
@ -344,7 +357,11 @@ private:
int contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const; int contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const;
int contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& parent) const; int contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& parent) const;
#if ENABLE_GL_SHADERS_ATTRIBUTES
void render_background(float left, float top, float right, float bottom, float border_w, float border_h) const;
#else
void render_background(float left, float top, float right, float bottom, float border) const; void render_background(float left, float top, float right, float bottom, float border) const;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void render_horizontal(const GLCanvas3D& parent); void render_horizontal(const GLCanvas3D& parent);
void render_vertical(const GLCanvas3D& parent); void render_vertical(const GLCanvas3D& parent);

View File

@ -873,6 +873,8 @@ void GUI_App::init_app_config()
// SetAppName(SLIC3R_APP_KEY); // SetAppName(SLIC3R_APP_KEY);
SetAppName(SLIC3R_APP_KEY "-alpha"); SetAppName(SLIC3R_APP_KEY "-alpha");
// SetAppName(SLIC3R_APP_KEY "-beta"); // SetAppName(SLIC3R_APP_KEY "-beta");
// SetAppDisplayName(SLIC3R_APP_NAME); // SetAppDisplayName(SLIC3R_APP_NAME);
// Set the Slic3r data directory at the Slic3r XS module. // Set the Slic3r data directory at the Slic3r XS module.

View File

@ -275,12 +275,12 @@ static void generate_thumbnail_from_model(const std::string& filename)
GLVolumeCollection volumes; GLVolumeCollection volumes;
volumes.volumes.push_back(new GLVolume()); volumes.volumes.push_back(new GLVolume());
GLVolume* volume = volumes.volumes.back(); GLVolume* volume = volumes.volumes.back();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
volume->model.init_from(model.mesh()); volume->model.init_from(model.mesh());
#else #else
volume->indexed_vertex_array.load_mesh(model.mesh()); volume->indexed_vertex_array.load_mesh(model.mesh());
volume->indexed_vertex_array.finalize_geometry(true); volume->indexed_vertex_array.finalize_geometry(true);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
volume->set_instance_transformation(model.objects[0]->instances[0]->get_transformation()); volume->set_instance_transformation(model.objects[0]->instances[0]->get_transformation());
volume->set_volume_transformation(model.objects[0]->volumes[0]->get_transformation()); volume->set_volume_transformation(model.objects[0]->volumes[0]->get_transformation());

View File

@ -4,8 +4,10 @@
#include <GL/glew.h> #include <GL/glew.h>
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/GUI_ObjectManipulation.hpp" #include "slic3r/GUI/GUI_ObjectManipulation.hpp"
#if ENABLE_GL_SHADERS_ATTRIBUTES
#include "slic3r/GUI/Plater.hpp"
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
// TODO: Display tooltips quicker on Linux // TODO: Display tooltips quicker on Linux
@ -33,34 +35,52 @@ float GLGizmoBase::Grabber::get_dragging_half_size(float size) const
void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, bool picking) void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, bool picking)
{ {
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_current_shader();
if (shader == nullptr)
return;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (!m_cube.is_initialized()) { if (!m_cube.is_initialized()) {
// This cannot be done in constructor, OpenGL is not yet // This cannot be done in constructor, OpenGL is not yet
// initialized at that point (on Linux at least). // initialized at that point (on Linux at least).
indexed_triangle_set its = its_make_cube(1., 1., 1.); indexed_triangle_set its = its_make_cube(1., 1., 1.);
its_translate(its, Vec3f(-0.5, -0.5, -0.5)); its_translate(its, -0.5f * Vec3f::Ones());
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_cube.init_from(its); m_cube.init_from(its);
#else #else
m_cube.init_from(its, BoundingBoxf3{ { -0.5, -0.5, -0.5 }, { 0.5, 0.5, 0.5 } }); m_cube.init_from(its, BoundingBoxf3{ { -0.5, -0.5, -0.5 }, { 0.5, 0.5, 0.5 } });
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
const float fullsize = 2.0f * (dragging ? get_dragging_half_size(size) : get_half_size(size)); const float fullsize = 2.0f * (dragging ? get_dragging_half_size(size) : get_half_size(size));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_cube.set_color(render_color); m_cube.set_color(render_color);
#else #else
m_cube.set_color(-1, render_color); m_cube.set_color(-1, render_color);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d view_model_matrix = camera.get_view_matrix() * matrix * Geometry::assemble_transform(center, angles, fullsize * Vec3d::Ones());
const Transform3d& projection_matrix = camera.get_projection_matrix();
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("projection_matrix", projection_matrix);
shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(center.x(), center.y(), center.z())); glsafe(::glTranslated(center.x(), center.y(), center.z()));
glsafe(::glRotated(Geometry::rad2deg(angles.z()), 0.0, 0.0, 1.0)); glsafe(::glRotated(Geometry::rad2deg(angles.z()), 0.0, 0.0, 1.0));
glsafe(::glRotated(Geometry::rad2deg(angles.y()), 0.0, 1.0, 0.0)); glsafe(::glRotated(Geometry::rad2deg(angles.y()), 0.0, 1.0, 0.0));
glsafe(::glRotated(Geometry::rad2deg(angles.x()), 1.0, 0.0, 0.0)); glsafe(::glRotated(Geometry::rad2deg(angles.x()), 1.0, 0.0, 0.0));
glsafe(::glScaled(fullsize, fullsize, fullsize)); glsafe(::glScaled(fullsize, fullsize, fullsize));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_cube.render(); m_cube.render();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id)
@ -114,7 +134,11 @@ void GLGizmoBase::render_grabbers(const BoundingBoxf3& box) const
void GLGizmoBase::render_grabbers(float size) const void GLGizmoBase::render_grabbers(float size) const
{ {
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
shader->start_using(); shader->start_using();
@ -128,11 +152,15 @@ void GLGizmoBase::render_grabbers(float size) const
void GLGizmoBase::render_grabbers_for_picking(const BoundingBoxf3& box) const void GLGizmoBase::render_grabbers_for_picking(const BoundingBoxf3& box) const
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
const float mean_size = float((box.size().x() + box.size().y() + box.size().z()) / 3.0); const float mean_size = float((box.size().x() + box.size().y() + box.size().z()) / 3.0);
for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i) { for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i) {
@ -141,10 +169,10 @@ void GLGizmoBase::render_grabbers_for_picking(const BoundingBoxf3& box) const
m_grabbers[i].render_for_picking(mean_size); m_grabbers[i].render_for_picking(mean_size);
} }
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
// help function to process grabbers // help function to process grabbers

View File

@ -49,6 +49,9 @@ protected:
bool dragging{ false }; bool dragging{ false };
Vec3d center{ Vec3d::Zero() }; Vec3d center{ Vec3d::Zero() };
Vec3d angles{ Vec3d::Zero() }; Vec3d angles{ Vec3d::Zero() };
#if ENABLE_GL_SHADERS_ATTRIBUTES
Transform3d matrix{ Transform3d::Identity() };
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
ColorRGBA color{ ColorRGBA::WHITE() }; ColorRGBA color{ ColorRGBA::WHITE() };
Grabber() = default; Grabber() = default;

View File

@ -351,14 +351,31 @@ void GLGizmoCut3D::render_cut_plane()
glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
shader->start_using(); shader->start_using();
/* const Vec3d diff = plane_center - m_old_center;
// Z changed when move with cut plane
// X and Y changed when move with cutted object
bool is_changed = std::abs(diff.x()) > EPSILON ||
std::abs(diff.y()) > EPSILON ||
std::abs(diff.z()) > EPSILON;
m_old_center = plane_center;
*/
const Vec3d& angles = m_rotation_gizmo.get_rotation(); const Vec3d& angles = m_rotation_gizmo.get_rotation();
GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 };
init_data.color = { 0.8f, 0.8f, 0.8f, 0.5f };
init_data.reserve_vertices(4);
init_data.reserve_indices(6);
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(m_plane_center.x(), m_plane_center.y(), m_plane_center.z())); glsafe(::glTranslated(m_plane_center.x(), m_plane_center.y(), m_plane_center.z()));
glsafe(::glRotated(Geometry::rad2deg(angles.z()), 0.0, 0.0, 1.0)); glsafe(::glRotated(Geometry::rad2deg(angles.z()), 0.0, 0.0, 1.0));
@ -368,11 +385,9 @@ void GLGizmoCut3D::render_cut_plane()
if (!m_plane.is_initialized()) { if (!m_plane.is_initialized()) {
m_plane.reset(); m_plane.reset();
GLModel::Geometry init_data; // indices
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.add_triangle(0, 1, 2);
init_data.color = { 0.8f, 0.8f, 0.8f, 0.5f }; init_data.add_triangle(2, 3, 0);
init_data.reserve_vertices(4);
init_data.reserve_indices(6);
// vertices // vertices
init_data.add_vertex(Vec3f(min_x, min_y, 0.0)); init_data.add_vertex(Vec3f(min_x, min_y, 0.0));
@ -380,12 +395,11 @@ void GLGizmoCut3D::render_cut_plane()
init_data.add_vertex(Vec3f(max_x, max_y, 0.0)); init_data.add_vertex(Vec3f(max_x, max_y, 0.0));
init_data.add_vertex(Vec3f(min_x, max_y, 0.0)); init_data.add_vertex(Vec3f(min_x, max_y, 0.0));
// indices #if ENABLE_GL_SHADERS_ATTRIBUTES
init_data.add_ushort_triangle(0, 1, 2); const Camera& camera = wxGetApp().plater()->get_camera();
init_data.add_ushort_triangle(2, 3, 0); shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
m_plane.init_from(std::move(init_data)); #endif // ENABLE_GL_SHADERS_ATTRIBUTES
}
m_plane.render(); m_plane.render();
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
@ -398,7 +412,7 @@ void GLGizmoCut3D::render_cut_plane()
::glVertex3f(max_x, max_y, plane_center.z()); ::glVertex3f(max_x, max_y, plane_center.z());
::glVertex3f(min_x, max_y, plane_center.z()); ::glVertex3f(min_x, max_y, plane_center.z());
glsafe(::glEnd()); glsafe(::glEnd());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glEnable(GL_CULL_FACE)); glsafe(::glEnable(GL_CULL_FACE));
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));
@ -431,7 +445,7 @@ void GLGizmoCut3D::render_cut_center_graber()
m_grabber_connection.reset(); m_grabber_connection.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 };
init_data.color = ColorRGBA::YELLOW(); init_data.color = ColorRGBA::YELLOW();
init_data.reserve_vertices(2); init_data.reserve_vertices(2);
init_data.reserve_indices(2); init_data.reserve_indices(2);
@ -441,7 +455,7 @@ void GLGizmoCut3D::render_cut_center_graber()
init_data.add_vertex((Vec3f)m_grabbers[0].center.cast<float>()); init_data.add_vertex((Vec3f)m_grabbers[0].center.cast<float>());
// indices // indices
init_data.add_ushort_line(0, 1); init_data.add_line(0, 1);
m_grabber_connection.init_from(std::move(init_data)); m_grabber_connection.init_from(std::move(init_data));
} }
@ -450,7 +464,20 @@ void GLGizmoCut3D::render_cut_center_graber()
shader->stop_using(); shader->stop_using();
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
shader = wxGetApp().get_shader("gouraud_light_attr");
#else
shader = wxGetApp().get_shader("gouraud_light"); shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#else
glsafe(::glColor3f(1.0, 1.0, 0.0));
::glBegin(GL_LINES);
::glVertex3dv(plane_center.data());
::glVertex3dv(m_grabbers[0].center.data());
glsafe(::glEnd());
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
shader->set_uniform("emission_factor", 0.1f); shader->set_uniform("emission_factor", 0.1f);
@ -538,6 +565,7 @@ void GLGizmoCut3D::on_dragging(const UpdateData& data)
for (auto& connector : connectors) for (auto& connector : connectors)
connector.pos += shift; connector.pos += shift;
} }
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
else if (m_hover_id > m_group_id) else if (m_hover_id > m_group_id)
{ {
std::pair<Vec3f, Vec3f> pos_and_normal; std::pair<Vec3f, Vec3f> pos_and_normal;
@ -665,7 +693,7 @@ void GLGizmoCut3D::on_render_input_window(float x, float y, float bottom_limit)
revert_rotation = render_revert_button("rotation"); revert_rotation = render_revert_button("rotation");
for (Axis axis : {X, Y, Z}) for (Axis axis : {X, Y, Z})
render_rotation_input(axis); render_rotation_input(axis);
m_imgui->text(_L("°")); m_imgui->text(_L("°"));
} }
else { else {
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();

View File

@ -29,11 +29,11 @@ class GLGizmoCut3D : public GLGizmoBase
GLModel m_connector_shape; GLModel m_connector_shape;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel m_plane; GLModel m_plane;
GLModel m_grabber_connection; GLModel m_grabber_connection;
Vec3d m_old_center; Vec3d m_old_center;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
bool m_keep_upper{ true }; bool m_keep_upper{ true };
bool m_keep_lower{ true }; bool m_keep_lower{ true };

View File

@ -1,9 +1,13 @@
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. // Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
#include "GLGizmoFlatten.hpp" #include "GLGizmoFlatten.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/GLCanvas3D.hpp"
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
#include "slic3r/GUI/Plater.hpp"
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" #include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp"
#include "libslic3r/Geometry/ConvexHull.hpp" #include "libslic3r/Geometry/ConvexHull.hpp"
@ -100,13 +104,17 @@ void GLGizmoFlatten::on_render()
{ {
const Selection& selection = m_parent.get_selection(); const Selection& selection = m_parent.get_selection();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
shader->start_using(); shader->start_using();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
@ -115,70 +123,96 @@ void GLGizmoFlatten::on_render()
if (selection.is_single_full_instance()) { if (selection.is_single_full_instance()) {
const Transform3d& m = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(); const Transform3d& m = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d view_model_matrix = camera.get_view_matrix() *
Geometry::assemble_transform(selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z() * Vec3d::UnitZ()) * m;
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslatef(0.f, 0.f, selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z())); glsafe(::glTranslatef(0.f, 0.f, selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z()));
glsafe(::glMultMatrixd(m.data())); glsafe(::glMultMatrixd(m.data()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (this->is_plane_update_necessary()) if (this->is_plane_update_necessary())
update_planes(); update_planes();
for (int i = 0; i < (int)m_planes.size(); ++i) { for (int i = 0; i < (int)m_planes.size(); ++i) {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_planes[i].vbo.set_color(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR : DEFAULT_PLANE_COLOR); m_planes[i].vbo.set_color(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR : DEFAULT_PLANE_COLOR);
m_planes[i].vbo.render(); m_planes[i].vbo.render();
#else #else
glsafe(::glColor4fv(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR.data() : DEFAULT_PLANE_COLOR.data())); glsafe(::glColor4fv(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR.data() : DEFAULT_PLANE_COLOR.data()));
if (m_planes[i].vbo.has_VBOs()) if (m_planes[i].vbo.has_VBOs())
m_planes[i].vbo.render(); m_planes[i].vbo.render();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
glsafe(::glEnable(GL_CULL_FACE)); glsafe(::glEnable(GL_CULL_FACE));
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
void GLGizmoFlatten::on_render_for_picking() void GLGizmoFlatten::on_render_for_picking()
{ {
const Selection& selection = m_parent.get_selection(); const Selection& selection = m_parent.get_selection();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
shader->start_using(); shader->start_using();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));
if (selection.is_single_full_instance() && !wxGetKeyState(WXK_CONTROL)) { if (selection.is_single_full_instance() && !wxGetKeyState(WXK_CONTROL)) {
const Transform3d& m = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(); const Transform3d& m = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d view_model_matrix = camera.get_view_matrix() *
Geometry::assemble_transform(selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z() * Vec3d::UnitZ()) * m;
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslatef(0.f, 0.f, selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z())); glsafe(::glTranslatef(0.f, 0.f, selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z()));
glsafe(::glMultMatrixd(m.data())); glsafe(::glMultMatrixd(m.data()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (this->is_plane_update_necessary()) if (this->is_plane_update_necessary())
update_planes(); update_planes();
for (int i = 0; i < (int)m_planes.size(); ++i) { for (int i = 0; i < (int)m_planes.size(); ++i) {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_planes[i].vbo.set_color(picking_color_component(i)); m_planes[i].vbo.set_color(picking_color_component(i));
#else #else
glsafe(::glColor4fv(picking_color_component(i).data())); glsafe(::glColor4fv(picking_color_component(i).data()));
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
m_planes[i].vbo.render(); m_planes[i].vbo.render();
} }
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
glsafe(::glEnable(GL_CULL_FACE)); glsafe(::glEnable(GL_CULL_FACE));
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object) void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
@ -393,18 +427,15 @@ void GLGizmoFlatten::update_planes()
// And finally create respective VBOs. The polygon is convex with // And finally create respective VBOs. The polygon is convex with
// the vertices in order, so triangulation is trivial. // the vertices in order, so triangulation is trivial.
for (auto& plane : m_planes) { for (auto& plane : m_planes) {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::TriangleFan, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::index_type(plane.vertices.size()) }; init_data.format = { GLModel::Geometry::EPrimitiveType::TriangleFan, GLModel::Geometry::EVertexLayout::P3N3 };
init_data.reserve_vertices(plane.vertices.size()); init_data.reserve_vertices(plane.vertices.size());
init_data.reserve_indices(plane.vertices.size()); init_data.reserve_indices(plane.vertices.size());
// vertices + indices // vertices + indices
for (size_t i = 0; i < plane.vertices.size(); ++i) { for (size_t i = 0; i < plane.vertices.size(); ++i) {
init_data.add_vertex((Vec3f)plane.vertices[i].cast<float>(), (Vec3f)plane.normal.cast<float>()); init_data.add_vertex((Vec3f)plane.vertices[i].cast<float>(), (Vec3f)plane.normal.cast<float>());
if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) init_data.add_index((unsigned int)i);
init_data.add_ushort_index((unsigned short)i);
else
init_data.add_uint_index((unsigned int)i);
} }
plane.vbo.init_from(std::move(init_data)); plane.vbo.init_from(std::move(init_data));
#else #else
@ -414,7 +445,7 @@ void GLGizmoFlatten::update_planes()
for (size_t i=1; i<plane.vertices.size()-1; ++i) for (size_t i=1; i<plane.vertices.size()-1; ++i)
plane.vbo.push_triangle(0, i, i+1); // triangle fan plane.vbo.push_triangle(0, i, i+1); // triangle fan
plane.vbo.finalize_geometry(true); plane.vbo.finalize_geometry(true);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// FIXME: vertices should really be local, they need not // FIXME: vertices should really be local, they need not
// persist now when we use VBOs // persist now when we use VBOs
plane.vertices.clear(); plane.vertices.clear();

View File

@ -2,11 +2,11 @@
#define slic3r_GLGizmoFlatten_hpp_ #define slic3r_GLGizmoFlatten_hpp_
#include "GLGizmoBase.hpp" #include "GLGizmoBase.hpp"
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#include "slic3r/GUI/GLModel.hpp" #include "slic3r/GUI/GLModel.hpp"
#else #else
#include "slic3r/GUI/3DScene.hpp" #include "slic3r/GUI/3DScene.hpp"
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
namespace Slic3r { namespace Slic3r {
@ -25,11 +25,11 @@ private:
struct PlaneData { struct PlaneData {
std::vector<Vec3d> vertices; // should be in fact local in update_planes() std::vector<Vec3d> vertices; // should be in fact local in update_planes()
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel vbo; GLModel vbo;
#else #else
GLIndexedVertexArray vbo; GLIndexedVertexArray vbo;
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
Vec3d normal; Vec3d normal;
float area; float area;
}; };

View File

@ -103,8 +103,12 @@ void GLGizmoHollow::on_render_for_picking()
void GLGizmoHollow::render_points(const Selection& selection, bool picking) void GLGizmoHollow::render_points(const Selection& selection, bool picking)
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat_attr") : wxGetApp().get_shader("gouraud_light_attr");
#else
GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat") : wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat") : wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
@ -115,23 +119,34 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking)
if (shader) if (shader)
shader->start_using(); shader->start_using();
ScopeGuard guard([shader]() { if (shader) shader->stop_using(); }); ScopeGuard guard([shader]() { if (shader) shader->stop_using(); });
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin());
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse();
const Transform3d instance_matrix = Geometry::assemble_transform(m_c->selection_info()->get_sla_shift() * Vec3d::UnitZ()) * vol->get_instance_transformation().get_matrix();
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d& view_matrix = camera.get_view_matrix();
const Transform3d& projection_matrix = camera.get_projection_matrix();
shader->set_uniform("projection_matrix", projection_matrix);
#else
const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse(); const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse();
const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix(); const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix();
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(0.0, 0.0, m_c->selection_info()->get_sla_shift())); glsafe(::glTranslated(0.0, 0.0, m_c->selection_info()->get_sla_shift()));
glsafe(::glMultMatrixd(instance_matrix.data())); glsafe(::glMultMatrixd(instance_matrix.data()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
ColorRGBA render_color; ColorRGBA render_color;
const sla::DrainHoles& drain_holes = m_c->selection_info()->model_object()->sla_drain_holes; const sla::DrainHoles& drain_holes = m_c->selection_info()->model_object()->sla_drain_holes;
size_t cache_size = drain_holes.size(); const size_t cache_size = drain_holes.size();
for (size_t i = 0; i < cache_size; ++i) { for (size_t i = 0; i < cache_size; ++i) {
const sla::DrainHole& drain_hole = drain_holes[i]; const sla::DrainHole& drain_hole = drain_holes[i];
const bool& point_selected = m_selected[i]; const bool point_selected = m_selected[i];
if (is_mesh_point_clipped(drain_hole.pos.cast<double>())) if (is_mesh_point_clipped(drain_hole.pos.cast<double>()))
continue; continue;
@ -151,16 +166,20 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking)
render_color = point_selected ? ColorRGBA(1.0f, 0.3f, 0.3f, 0.5f) : ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f); render_color = point_selected ? ColorRGBA(1.0f, 0.3f, 0.3f, 0.5f) : ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f);
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_cylinder.set_color(render_color); m_cylinder.set_color(render_color);
#else #else
const_cast<GLModel*>(&m_cylinder)->set_color(-1, render_color); const_cast<GLModel*>(&m_cylinder)->set_color(-1, render_color);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object.
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d hole_matrix = Geometry::assemble_transform(drain_hole.pos.cast<double>()) * instance_scaling_matrix_inverse;
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslatef(drain_hole.pos.x(), drain_hole.pos.y(), drain_hole.pos.z())); glsafe(::glTranslatef(drain_hole.pos.x(), drain_hole.pos.y(), drain_hole.pos.z()));
glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data())); glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (vol->is_left_handed()) if (vol->is_left_handed())
glFrontFace(GL_CW); glFrontFace(GL_CW);
@ -168,18 +187,31 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking)
// Matrices set, we can render the point mark now. // Matrices set, we can render the point mark now.
Eigen::Quaterniond q; Eigen::Quaterniond q;
q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-drain_hole.normal).cast<double>()); q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-drain_hole.normal).cast<double>());
Eigen::AngleAxisd aa(q); const Eigen::AngleAxisd aa(q);
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d view_model_matrix = view_matrix * instance_matrix * hole_matrix * Transform3d(aa.toRotationMatrix()) *
Geometry::assemble_transform(-drain_hole.height * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength));
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z())); glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z()));
glsafe(::glTranslated(0., 0., -drain_hole.height)); glsafe(::glTranslated(0., 0., -drain_hole.height));
glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_cylinder.render(); m_cylinder.render();
if (vol->is_left_handed()) if (vol->is_left_handed())
glFrontFace(GL_CCW); glFrontFace(GL_CCW);
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
bool GLGizmoHollow::is_mesh_point_clipped(const Vec3d& point) const bool GLGizmoHollow::is_mesh_point_clipped(const Vec3d& point) const

View File

@ -170,7 +170,11 @@ void GLGizmoMmuSegmentation::data_changed()
void GLGizmoMmuSegmentation::render_triangles(const Selection &selection) const void GLGizmoMmuSegmentation::render_triangles(const Selection &selection) const
{ {
ClippingPlaneDataWrapper clp_data = this->get_clipping_plane_data(); ClippingPlaneDataWrapper clp_data = this->get_clipping_plane_data();
#if ENABLE_GL_SHADERS_ATTRIBUTES
auto* shader = wxGetApp().get_shader("mm_gouraud_attr");
#else
auto *shader = wxGetApp().get_shader("mm_gouraud"); auto *shader = wxGetApp().get_shader("mm_gouraud");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (!shader) if (!shader)
return; return;
shader->start_using(); shader->start_using();
@ -188,18 +192,32 @@ void GLGizmoMmuSegmentation::render_triangles(const Selection &selection) const
const Transform3d trafo_matrix = mo->instances[selection.get_instance_idx()]->get_transformation().get_matrix() * mv->get_matrix(); const Transform3d trafo_matrix = mo->instances[selection.get_instance_idx()]->get_transformation().get_matrix() * mv->get_matrix();
bool is_left_handed = trafo_matrix.matrix().determinant() < 0.; const bool is_left_handed = trafo_matrix.matrix().determinant() < 0.0;
if (is_left_handed) if (is_left_handed)
glsafe(::glFrontFace(GL_CW)); glsafe(::glFrontFace(GL_CW));
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d matrix = camera.get_view_matrix() * trafo_matrix;
shader->set_uniform("view_model_matrix", matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
shader->set_uniform("normal_matrix", (Matrix3d)matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glMultMatrixd(trafo_matrix.data())); glsafe(::glMultMatrixd(trafo_matrix.data()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
shader->set_uniform("volume_world_matrix", trafo_matrix); shader->set_uniform("volume_world_matrix", trafo_matrix);
shader->set_uniform("volume_mirrored", is_left_handed); shader->set_uniform("volume_mirrored", is_left_handed);
#if ENABLE_GL_SHADERS_ATTRIBUTES
m_triangle_selectors[mesh_id]->render(m_imgui, trafo_matrix);
#else
m_triangle_selectors[mesh_id]->render(m_imgui); m_triangle_selectors[mesh_id]->render(m_imgui);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
if (is_left_handed) if (is_left_handed)
glsafe(::glFrontFace(GL_CCW)); glsafe(::glFrontFace(GL_CCW));
} }
@ -568,7 +586,11 @@ ColorRGBA GLGizmoMmuSegmentation::get_cursor_sphere_right_button_color() const
return color; return color;
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void TriangleSelectorMmGui::render(ImGuiWrapper* imgui, const Transform3d& matrix)
#else
void TriangleSelectorMmGui::render(ImGuiWrapper *imgui) void TriangleSelectorMmGui::render(ImGuiWrapper *imgui)
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
{ {
if (m_update_render_data) if (m_update_render_data)
update_render_data(); update_render_data();
@ -576,7 +598,11 @@ void TriangleSelectorMmGui::render(ImGuiWrapper *imgui)
auto *shader = wxGetApp().get_current_shader(); auto *shader = wxGetApp().get_current_shader();
if (!shader) if (!shader)
return; return;
#if ENABLE_GL_SHADERS_ATTRIBUTES
assert(shader->get_name() == "mm_gouraud_attr");
#else
assert(shader->get_name() == "mm_gouraud"); assert(shader->get_name() == "mm_gouraud");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
for (size_t color_idx = 0; color_idx < m_gizmo_scene.triangle_indices.size(); ++color_idx) for (size_t color_idx = 0; color_idx < m_gizmo_scene.triangle_indices.size(); ++color_idx)
if (m_gizmo_scene.has_VBOs(color_idx)) { if (m_gizmo_scene.has_VBOs(color_idx)) {
@ -588,8 +614,12 @@ void TriangleSelectorMmGui::render(ImGuiWrapper *imgui)
m_gizmo_scene.render(color_idx); m_gizmo_scene.render(color_idx);
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_paint_contour(matrix);
#else
render_paint_contour(); render_paint_contour();
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#else #else
if (m_paint_contour.has_VBO()) { if (m_paint_contour.has_VBO()) {
ScopeGuard guard_mm_gouraud([shader]() { shader->start_using(); }); ScopeGuard guard_mm_gouraud([shader]() { shader->start_using(); });
@ -604,7 +634,7 @@ void TriangleSelectorMmGui::render(ImGuiWrapper *imgui)
contour_shader->stop_using(); contour_shader->stop_using();
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
m_update_render_data = false; m_update_render_data = false;
} }
@ -639,7 +669,7 @@ void TriangleSelectorMmGui::update_render_data()
m_gizmo_scene.finalize_triangle_indices(); m_gizmo_scene.finalize_triangle_indices();
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
update_paint_contour(); update_paint_contour();
#else #else
m_paint_contour.release_geometry(); m_paint_contour.release_geometry();
@ -660,7 +690,7 @@ void TriangleSelectorMmGui::update_render_data()
m_paint_contour.contour_indices_size = m_paint_contour.contour_indices.size(); m_paint_contour.contour_indices_size = m_paint_contour.contour_indices.size();
m_paint_contour.finalize_geometry(); m_paint_contour.finalize_geometry();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
wxString GLGizmoMmuSegmentation::handle_snapshot_action_name(bool shift_down, GLGizmoPainterBase::Button button_down) const wxString GLGizmoMmuSegmentation::handle_snapshot_action_name(bool shift_down, GLGizmoPainterBase::Button button_down) const

View File

@ -66,9 +66,13 @@ public:
: TriangleSelectorGUI(mesh), m_colors(colors), m_default_volume_color(default_volume_color), m_gizmo_scene(2 * (colors.size() + 1)) {} : TriangleSelectorGUI(mesh), m_colors(colors), m_default_volume_color(default_volume_color), m_gizmo_scene(2 * (colors.size() + 1)) {}
~TriangleSelectorMmGui() override = default; ~TriangleSelectorMmGui() override = default;
#if ENABLE_GL_SHADERS_ATTRIBUTES
void render(ImGuiWrapper* imgui, const Transform3d& matrix) override;
#else
// Render current selection. Transformation matrices are supposed // Render current selection. Transformation matrices are supposed
// to be already set. // to be already set.
void render(ImGuiWrapper* imgui) override; void render(ImGuiWrapper* imgui) override;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
private: private:
void update_render_data(); void update_render_data();

View File

@ -2,6 +2,9 @@
#include "GLGizmoMove.hpp" #include "GLGizmoMove.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/GLCanvas3D.hpp"
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#if ENABLE_GL_SHADERS_ATTRIBUTES
#include "slic3r/GUI/Plater.hpp"
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#include <GL/glew.h> #include <GL/glew.h>
@ -121,7 +124,7 @@ void GLGizmoMove3D::on_render()
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
auto render_grabber_connection = [this, &center](unsigned int id) { auto render_grabber_connection = [this, &center](unsigned int id) {
if (m_grabbers[id].enabled) { if (m_grabbers[id].enabled) {
if (!m_grabber_connections[id].model.is_initialized() || !m_grabber_connections[id].old_center.isApprox(center)) { if (!m_grabber_connections[id].model.is_initialized() || !m_grabber_connections[id].old_center.isApprox(center)) {
@ -129,7 +132,7 @@ void GLGizmoMove3D::on_render()
m_grabber_connections[id].model.reset(); m_grabber_connections[id].model.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 };
init_data.color = AXES_COLOR[id]; init_data.color = AXES_COLOR[id];
init_data.reserve_vertices(2); init_data.reserve_vertices(2);
init_data.reserve_indices(2); init_data.reserve_indices(2);
@ -139,7 +142,7 @@ void GLGizmoMove3D::on_render()
init_data.add_vertex((Vec3f)m_grabbers[id].center.cast<float>()); init_data.add_vertex((Vec3f)m_grabbers[id].center.cast<float>());
// indices // indices
init_data.add_ushort_line(0, 1); init_data.add_line(0, 1);
m_grabber_connections[id].model.init_from(std::move(init_data)); m_grabber_connections[id].model.init_from(std::move(init_data));
} }
@ -147,18 +150,28 @@ void GLGizmoMove3D::on_render()
m_grabber_connections[id].model.render(); m_grabber_connections[id].model.render();
} }
}; };
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (m_hover_id == -1) { if (m_hover_id == -1) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
// draw axes // draw axes
for (unsigned int i = 0; i < 3; ++i) { for (unsigned int i = 0; i < 3; ++i) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
render_grabber_connection(i); render_grabber_connection(i);
#else #else
if (m_grabbers[i].enabled) { if (m_grabbers[i].enabled) {
@ -168,13 +181,13 @@ void GLGizmoMove3D::on_render()
::glVertex3dv(m_grabbers[i].center.data()); ::glVertex3dv(m_grabbers[i].center.data());
glsafe(::glEnd()); glsafe(::glEnd());
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// draw grabbers // draw grabbers
render_grabbers(box); render_grabbers(box);
@ -185,15 +198,30 @@ void GLGizmoMove3D::on_render()
} }
else { else {
// draw axis // draw axis
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
render_grabber_connection(m_hover_id); render_grabber_connection(m_hover_id);
shader->stop_using(); shader->stop_using();
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
shader = wxGetApp().get_shader("gouraud_light_attr");
#else
shader = wxGetApp().get_shader("gouraud_light"); shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#else #else
glsafe(::glColor4fv(AXES_COLOR[m_hover_id].data())); glsafe(::glColor4fv(AXES_COLOR[m_hover_id].data()));
::glBegin(GL_LINES); ::glBegin(GL_LINES);
@ -202,12 +230,12 @@ void GLGizmoMove3D::on_render()
glsafe(::glEnd()); glsafe(::glEnd());
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
shader->set_uniform("emission_factor", 0.1f); shader->set_uniform("emission_factor", 0.1f);
// draw grabber // draw grabber
float mean_size = (float)((box.size().x() + box.size().y() + box.size().z()) / 3.0); const float mean_size = (float)((box.size().x() + box.size().y() + box.size().z()) / 3.0);
m_grabbers[m_hover_id].render(true, mean_size); m_grabbers[m_hover_id].render(true, mean_size);
shader->stop_using(); shader->stop_using();
} }
@ -254,18 +282,22 @@ double GLGizmoMove3D::calc_projection(const UpdateData& data) const
void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box, bool picking) void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box, bool picking)
{ {
float mean_size = float((box.size().x() + box.size().y() + box.size().z()) / 3.0); const float mean_size = float((box.size().x() + box.size().y() + box.size().z()) / 3.0);
double size = m_dragging ? double(m_grabbers[axis].get_dragging_half_size(mean_size)) : double(m_grabbers[axis].get_half_size(mean_size)); const double size = m_dragging ? double(m_grabbers[axis].get_dragging_half_size(mean_size)) : double(m_grabbers[axis].get_half_size(mean_size));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat_attr" : "gouraud_light_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat" : "gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat" : "gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#else #else
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (shader == nullptr) if (shader == nullptr)
return; return;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_cone.set_color((!picking && m_hover_id != -1) ? complementary(m_grabbers[axis].color) : m_grabbers[axis].color); m_cone.set_color((!picking && m_hover_id != -1) ? complementary(m_grabbers[axis].color) : m_grabbers[axis].color);
shader->start_using(); shader->start_using();
shader->set_uniform("emission_factor", 0.1f); shader->set_uniform("emission_factor", 0.1f);
@ -275,8 +307,21 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box
shader->start_using(); shader->start_using();
shader->set_uniform("emission_factor", 0.1f); shader->set_uniform("emission_factor", 0.1f);
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
Transform3d view_model_matrix = camera.get_view_matrix() * Geometry::assemble_transform(m_grabbers[axis].center);
if (axis == X)
view_model_matrix = view_model_matrix * Geometry::assemble_transform(Vec3d::Zero(), 0.5 * PI * Vec3d::UnitY());
else if (axis == Y)
view_model_matrix = view_model_matrix * Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitX());
view_model_matrix = view_model_matrix * Geometry::assemble_transform(2.0 * size * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(0.75 * size, 0.75 * size, 3.0 * size));
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(m_grabbers[axis].center.x(), m_grabbers[axis].center.y(), m_grabbers[axis].center.z())); glsafe(::glTranslated(m_grabbers[axis].center.x(), m_grabbers[axis].center.y(), m_grabbers[axis].center.z()));
if (axis == X) if (axis == X)
@ -286,12 +331,15 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box
glsafe(::glTranslated(0.0, 0.0, 2.0 * size)); glsafe(::glTranslated(0.0, 0.0, 2.0 * size));
glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size)); glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_cone.render(); m_cone.render();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
if (! picking) if (! picking)
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
} }

View File

@ -18,14 +18,14 @@ class GLGizmoMove3D : public GLGizmoBase
Vec3d m_starting_box_bottom_center{ Vec3d::Zero() }; Vec3d m_starting_box_bottom_center{ Vec3d::Zero() };
GLModel m_cone; GLModel m_cone;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
struct GrabberConnection struct GrabberConnection
{ {
GLModel model; GLModel model;
Vec3d old_center{ Vec3d::Zero() }; Vec3d old_center{ Vec3d::Zero() };
}; };
std::array<GrabberConnection, 3> m_grabber_connections; std::array<GrabberConnection, 3> m_grabber_connections;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
public: public:
GLGizmoMove3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); GLGizmoMove3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);

View File

@ -18,11 +18,11 @@
namespace Slic3r::GUI { namespace Slic3r::GUI {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
std::shared_ptr<GLModel> GLGizmoPainterBase::s_sphere = nullptr; std::shared_ptr<GLModel> GLGizmoPainterBase::s_sphere = nullptr;
#else #else
std::shared_ptr<GLIndexedVertexArray> GLGizmoPainterBase::s_sphere = nullptr; std::shared_ptr<GLIndexedVertexArray> GLGizmoPainterBase::s_sphere = nullptr;
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
GLGizmoPainterBase::GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) GLGizmoPainterBase::GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id)
: GLGizmoBase(parent, icon_filename, sprite_id) : GLGizmoBase(parent, icon_filename, sprite_id)
@ -31,13 +31,13 @@ GLGizmoPainterBase::GLGizmoPainterBase(GLCanvas3D& parent, const std::string& ic
GLGizmoPainterBase::~GLGizmoPainterBase() GLGizmoPainterBase::~GLGizmoPainterBase()
{ {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
if (s_sphere != nullptr) if (s_sphere != nullptr)
s_sphere.reset(); s_sphere.reset();
#else #else
if (s_sphere != nullptr && s_sphere->has_VBOs()) if (s_sphere != nullptr && s_sphere->has_VBOs())
s_sphere->release_geometry(); s_sphere->release_geometry();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
void GLGizmoPainterBase::data_changed() void GLGizmoPainterBase::data_changed()
@ -80,7 +80,11 @@ GLGizmoPainterBase::ClippingPlaneDataWrapper GLGizmoPainterBase::get_clipping_pl
void GLGizmoPainterBase::render_triangles(const Selection& selection) const void GLGizmoPainterBase::render_triangles(const Selection& selection) const
{ {
#if ENABLE_GL_SHADERS_ATTRIBUTES
auto* shader = wxGetApp().get_shader("gouraud_attr");
#else
auto* shader = wxGetApp().get_shader("gouraud"); auto* shader = wxGetApp().get_shader("gouraud");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (! shader) if (! shader)
return; return;
shader->start_using(); shader->start_using();
@ -105,8 +109,16 @@ void GLGizmoPainterBase::render_triangles(const Selection& selection) const
if (is_left_handed) if (is_left_handed)
glsafe(::glFrontFace(GL_CW)); glsafe(::glFrontFace(GL_CW));
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d matrix = camera.get_view_matrix() * trafo_matrix;
shader->set_uniform("view_model_matrix", matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
shader->set_uniform("normal_matrix", (Matrix3d)matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glMultMatrixd(trafo_matrix.data())); glsafe(::glMultMatrixd(trafo_matrix.data()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
// For printers with multiple extruders, it is necessary to pass trafo_matrix // For printers with multiple extruders, it is necessary to pass trafo_matrix
// to the shader input variable print_box.volume_world_matrix before // to the shader input variable print_box.volume_world_matrix before
@ -114,9 +126,13 @@ void GLGizmoPainterBase::render_triangles(const Selection& selection) const
// wrong transformation matrix is used for "Clipping of view". // wrong transformation matrix is used for "Clipping of view".
shader->set_uniform("volume_world_matrix", trafo_matrix); shader->set_uniform("volume_world_matrix", trafo_matrix);
#if ENABLE_GL_SHADERS_ATTRIBUTES
m_triangle_selectors[mesh_id]->render(m_imgui, trafo_matrix);
#else
m_triangle_selectors[mesh_id]->render(m_imgui); m_triangle_selectors[mesh_id]->render(m_imgui);
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (is_left_handed) if (is_left_handed)
glsafe(::glFrontFace(GL_CCW)); glsafe(::glFrontFace(GL_CCW));
} }
@ -151,11 +167,25 @@ void GLGizmoPainterBase::render_cursor()
void GLGizmoPainterBase::render_cursor_circle() void GLGizmoPainterBase::render_cursor_circle()
{ {
#if !ENABLE_GL_SHADERS_ATTRIBUTES
const Camera &camera = wxGetApp().plater()->get_camera(); const Camera &camera = wxGetApp().plater()->get_camera();
const float zoom = float(camera.get_zoom()); const float zoom = float(camera.get_zoom());
const float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; const float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
const Size cnv_size = m_parent.get_canvas_size(); const Size cnv_size = m_parent.get_canvas_size();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const float cnv_width = float(cnv_size.get_width());
const float cnv_height = float(cnv_size.get_height());
if (cnv_width == 0.0f || cnv_height == 0.0f)
return;
const float cnv_inv_width = 1.0f / cnv_width;
const float cnv_inv_height = 1.0f / cnv_height;
const Vec2d center = m_parent.get_local_mouse_position();
const float radius = m_cursor_radius * float(wxGetApp().plater()->get_camera().get_zoom());
#else
const float cnv_half_width = 0.5f * float(cnv_size.get_width()); const float cnv_half_width = 0.5f * float(cnv_size.get_width());
const float cnv_half_height = 0.5f * float(cnv_size.get_height()); const float cnv_half_height = 0.5f * float(cnv_size.get_height());
if (cnv_half_width == 0.0f || cnv_half_height == 0.0f) if (cnv_half_width == 0.0f || cnv_half_height == 0.0f)
@ -163,14 +193,16 @@ void GLGizmoPainterBase::render_cursor_circle()
const Vec2d mouse_pos(m_parent.get_local_mouse_position().x(), m_parent.get_local_mouse_position().y()); const Vec2d mouse_pos(m_parent.get_local_mouse_position().x(), m_parent.get_local_mouse_position().y());
Vec2d center(mouse_pos.x() - cnv_half_width, cnv_half_height - mouse_pos.y()); Vec2d center(mouse_pos.x() - cnv_half_width, cnv_half_height - mouse_pos.y());
center = center * inv_zoom; center = center * inv_zoom;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glLineWidth(1.5f)); glsafe(::glLineWidth(1.5f));
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
static const std::array<float, 3> color = { 0.f, 1.f, 0.3f }; static const std::array<float, 3> color = { 0.f, 1.f, 0.3f };
glsafe(::glColor3fv(color.data())); glsafe(::glColor3fv(color.data()));
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glLoadIdentity()); glsafe(::glLoadIdentity());
// ensure that the circle is renderered inside the frustrum // ensure that the circle is renderered inside the frustrum
@ -178,38 +210,57 @@ void GLGizmoPainterBase::render_cursor_circle()
// ensure that the overlay fits the frustrum near z plane // ensure that the overlay fits the frustrum near z plane
const double gui_scale = camera.get_gui_scale(); const double gui_scale = camera.get_gui_scale();
glsafe(::glScaled(gui_scale, gui_scale, 1.0)); glsafe(::glScaled(gui_scale, gui_scale, 1.0));
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPushAttrib(GL_ENABLE_BIT)); glsafe(::glPushAttrib(GL_ENABLE_BIT));
glsafe(::glLineStipple(4, 0xAAAA)); glsafe(::glLineStipple(4, 0xAAAA));
glsafe(::glEnable(GL_LINE_STIPPLE)); glsafe(::glEnable(GL_LINE_STIPPLE));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
if (!m_circle.is_initialized() || !m_old_center.isApprox(center) || std::abs(m_old_cursor_radius - radius) > EPSILON) {
m_old_cursor_radius = radius;
#else
if (!m_circle.is_initialized() || !m_old_center.isApprox(center) || std::abs(m_old_cursor_radius - m_cursor_radius) > EPSILON) { if (!m_circle.is_initialized() || !m_old_center.isApprox(center) || std::abs(m_old_cursor_radius - m_cursor_radius) > EPSILON) {
m_old_center = center;
m_old_cursor_radius = m_cursor_radius; m_old_cursor_radius = m_cursor_radius;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_old_center = center;
m_circle.reset(); m_circle.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
static const unsigned int StepsCount = 32; static const unsigned int StepsCount = 32;
static const float StepSize = 2.0f * float(PI) / float(StepsCount); static const float StepSize = 2.0f * float(PI) / float(StepsCount);
init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2 };
init_data.color = { 0.0f, 1.0f, 0.3f, 1.0f }; init_data.color = { 0.0f, 1.0f, 0.3f, 1.0f };
init_data.reserve_vertices(StepsCount); init_data.reserve_vertices(StepsCount);
init_data.reserve_indices(StepsCount); init_data.reserve_indices(StepsCount);
// vertices + indices // vertices + indices
for (unsigned short i = 0; i < StepsCount; ++i) { for (unsigned int i = 0; i < StepsCount; ++i) {
const float angle = float(i * StepSize); const float angle = float(i) * StepSize;
#if ENABLE_GL_SHADERS_ATTRIBUTES
init_data.add_vertex(Vec2f(2.0f * ((center.x() + ::cos(angle) * radius) * cnv_inv_width - 0.5f),
-2.0f * ((center.y() + ::sin(angle) * radius) * cnv_inv_height - 0.5f)));
#else
init_data.add_vertex(Vec2f(center.x() + ::cos(angle) * m_cursor_radius, center.y() + ::sin(angle) * m_cursor_radius)); init_data.add_vertex(Vec2f(center.x() + ::cos(angle) * m_cursor_radius, center.y() + ::sin(angle) * m_cursor_radius));
init_data.add_ushort_index(i); #endif // ENABLE_GL_SHADERS_ATTRIBUTES
init_data.add_index(i);
} }
m_circle.init_from(std::move(init_data)); m_circle.init_from(std::move(init_data));
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = GUI::wxGetApp().get_shader("flat"); GLShaderProgram* shader = GUI::wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
shader->set_uniform("view_model_matrix", Transform3d::Identity());
shader->set_uniform("projection_matrix", Transform3d::Identity());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_circle.render(); m_circle.render();
shader->stop_using(); shader->stop_using();
} }
@ -218,10 +269,12 @@ void GLGizmoPainterBase::render_cursor_circle()
for (double angle=0; angle<2*M_PI; angle+=M_PI/20.) for (double angle=0; angle<2*M_PI; angle+=M_PI/20.)
::glVertex2f(GLfloat(center.x()+m_cursor_radius*cos(angle)), GLfloat(center.y()+m_cursor_radius*sin(angle))); ::glVertex2f(GLfloat(center.x()+m_cursor_radius*cos(angle)), GLfloat(center.y()+m_cursor_radius*sin(angle)));
glsafe(::glEnd()); glsafe(::glEnd());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glPopAttrib()); glsafe(::glPopAttrib());
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
} }
@ -229,29 +282,35 @@ void GLGizmoPainterBase::render_cursor_circle()
void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const
{ {
if (s_sphere == nullptr) { if (s_sphere == nullptr) {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
s_sphere = std::make_shared<GLModel>(); s_sphere = std::make_shared<GLModel>();
s_sphere->init_from(its_make_sphere(1.0, double(PI) / 12.0)); s_sphere->init_from(its_make_sphere(1.0, double(PI) / 12.0));
#else #else
s_sphere = std::make_shared<GLIndexedVertexArray>(); s_sphere = std::make_shared<GLIndexedVertexArray>();
s_sphere->load_its_flat_shading(its_make_sphere(1.0, double(PI) / 12.0)); s_sphere->load_its_flat_shading(its_make_sphere(1.0, double(PI) / 12.0));
s_sphere->finalize_geometry(true); s_sphere->finalize_geometry(true);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
const Transform3d complete_scaling_matrix_inverse = Geometry::Transformation(trafo).get_matrix(true, true, false, true).inverse(); const Transform3d complete_scaling_matrix_inverse = Geometry::Transformation(trafo).get_matrix(true, true, false, true).inverse();
const bool is_left_handed = Geometry::Transformation(trafo).is_left_handed(); const bool is_left_handed = Geometry::Transformation(trafo).is_left_handed();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glMultMatrixd(trafo.data())); glsafe(::glMultMatrixd(trafo.data()));
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object.
glsafe(::glTranslatef(m_rr.hit.x(), m_rr.hit.y(), m_rr.hit.z())); glsafe(::glTranslatef(m_rr.hit.x(), m_rr.hit.y(), m_rr.hit.z()));
glsafe(::glMultMatrixd(complete_scaling_matrix_inverse.data())); glsafe(::glMultMatrixd(complete_scaling_matrix_inverse.data()));
glsafe(::glScaled(m_cursor_radius, m_cursor_radius, m_cursor_radius)); glsafe(::glScaled(m_cursor_radius, m_cursor_radius, m_cursor_radius));
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
if (is_left_handed) if (is_left_handed)
glFrontFace(GL_CW); glFrontFace(GL_CW);
@ -261,26 +320,38 @@ void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const
render_color = this->get_cursor_sphere_left_button_color(); render_color = this->get_cursor_sphere_left_button_color();
else if (m_button_down == Button::Right) else if (m_button_down == Button::Right)
render_color = this->get_cursor_sphere_right_button_color(); render_color = this->get_cursor_sphere_right_button_color();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
Transform3d view_model_matrix = camera.get_view_matrix() * trafo *
Geometry::assemble_transform(m_rr.hit.cast<double>()) * complete_scaling_matrix_inverse *
Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), m_cursor_radius * Vec3d::Ones());
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
assert(s_sphere != nullptr); assert(s_sphere != nullptr);
s_sphere->set_color(render_color); s_sphere->set_color(render_color);
#else #else
glsafe(::glColor4fv(render_color.data())); glsafe(::glColor4fv(render_color.data()));
assert(s_sphere != nullptr); assert(s_sphere != nullptr);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
s_sphere->render(); s_sphere->render();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (is_left_handed) if (is_left_handed)
glFrontFace(GL_CCW); glFrontFace(GL_CCW);
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
@ -839,7 +910,11 @@ ColorRGBA TriangleSelectorGUI::get_seed_fill_color(const ColorRGBA& base_color)
return saturate(base_color, 0.75f); return saturate(base_color, 0.75f);
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void TriangleSelectorGUI::render(ImGuiWrapper* imgui, const Transform3d& matrix)
#else
void TriangleSelectorGUI::render(ImGuiWrapper* imgui) void TriangleSelectorGUI::render(ImGuiWrapper* imgui)
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
{ {
static const ColorRGBA enforcers_color = { 0.47f, 0.47f, 1.0f, 1.0f }; static const ColorRGBA enforcers_color = { 0.47f, 0.47f, 1.0f, 1.0f };
static const ColorRGBA blockers_color = { 1.0f, 0.44f, 0.44f, 1.0f }; static const ColorRGBA blockers_color = { 1.0f, 0.44f, 0.44f, 1.0f };
@ -852,12 +927,16 @@ void TriangleSelectorGUI::render(ImGuiWrapper* imgui)
auto* shader = wxGetApp().get_current_shader(); auto* shader = wxGetApp().get_current_shader();
if (! shader) if (! shader)
return; return;
#if ENABLE_GL_SHADERS_ATTRIBUTES
assert(shader->get_name() == "gouraud_attr");
#else
assert(shader->get_name() == "gouraud"); assert(shader->get_name() == "gouraud");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
ScopeGuard guard([shader]() { if (shader) shader->set_uniform("offset_depth_buffer", false);}); ScopeGuard guard([shader]() { if (shader) shader->set_uniform("offset_depth_buffer", false);});
shader->set_uniform("offset_depth_buffer", true); shader->set_uniform("offset_depth_buffer", true);
for (auto iva : {std::make_pair(&m_iva_enforcers, enforcers_color), for (auto iva : {std::make_pair(&m_iva_enforcers, enforcers_color),
std::make_pair(&m_iva_blockers, blockers_color)}) { std::make_pair(&m_iva_blockers, blockers_color)}) {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
iva.first->set_color(iva.second); iva.first->set_color(iva.second);
iva.first->render(); iva.first->render();
#else #else
@ -865,10 +944,10 @@ void TriangleSelectorGUI::render(ImGuiWrapper* imgui)
shader->set_uniform("uniform_color", iva.second); shader->set_uniform("uniform_color", iva.second);
iva.first->render(); iva.first->render();
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
for (auto& iva : m_iva_seed_fills) { for (auto& iva : m_iva_seed_fills) {
size_t color_idx = &iva - &m_iva_seed_fills.front(); size_t color_idx = &iva - &m_iva_seed_fills.front();
const ColorRGBA& color = TriangleSelectorGUI::get_seed_fill_color(color_idx == 1 ? enforcers_color : const ColorRGBA& color = TriangleSelectorGUI::get_seed_fill_color(color_idx == 1 ? enforcers_color :
@ -887,10 +966,14 @@ void TriangleSelectorGUI::render(ImGuiWrapper* imgui)
shader->set_uniform("uniform_color", color); shader->set_uniform("uniform_color", color);
iva.render(); iva.render();
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_paint_contour(matrix);
#else
render_paint_contour(); render_paint_contour();
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#else #else
if (m_paint_contour.has_VBO()) { if (m_paint_contour.has_VBO()) {
ScopeGuard guard_gouraud([shader]() { shader->start_using(); }); ScopeGuard guard_gouraud([shader]() { shader->start_using(); });
@ -905,7 +988,7 @@ void TriangleSelectorGUI::render(ImGuiWrapper* imgui)
contour_shader->stop_using(); contour_shader->stop_using();
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#ifdef PRUSASLICER_TRIANGLE_SELECTOR_DEBUG #ifdef PRUSASLICER_TRIANGLE_SELECTOR_DEBUG
if (imgui) if (imgui)
@ -921,7 +1004,7 @@ void TriangleSelectorGUI::update_render_data()
int blc_cnt = 0; int blc_cnt = 0;
std::vector<int> seed_fill_cnt(m_iva_seed_fills.size(), 0); std::vector<int> seed_fill_cnt(m_iva_seed_fills.size(), 0);
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
for (auto* iva : { &m_iva_enforcers, &m_iva_blockers }) { for (auto* iva : { &m_iva_enforcers, &m_iva_blockers }) {
iva->reset(); iva->reset();
} }
@ -931,26 +1014,26 @@ void TriangleSelectorGUI::update_render_data()
} }
GLModel::Geometry iva_enforcers_data; GLModel::Geometry iva_enforcers_data;
iva_enforcers_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT }; iva_enforcers_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 };
GLModel::Geometry iva_blockers_data; GLModel::Geometry iva_blockers_data;
iva_blockers_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT }; iva_blockers_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 };
std::array<GLModel::Geometry, 3> iva_seed_fills_data; std::array<GLModel::Geometry, 3> iva_seed_fills_data;
for (auto& data : iva_seed_fills_data) for (auto& data : iva_seed_fills_data)
data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT }; data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 };
#else #else
for (auto *iva : {&m_iva_enforcers, &m_iva_blockers}) for (auto *iva : {&m_iva_enforcers, &m_iva_blockers})
iva->release_geometry(); iva->release_geometry();
for (auto &iva : m_iva_seed_fills) for (auto &iva : m_iva_seed_fills)
iva.release_geometry(); iva.release_geometry();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
for (const Triangle &tr : m_triangles) { for (const Triangle &tr : m_triangles) {
if (!tr.valid() || tr.is_split() || (tr.get_state() == EnforcerBlockerType::NONE && !tr.is_selected_by_seed_fill())) if (!tr.valid() || tr.is_split() || (tr.get_state() == EnforcerBlockerType::NONE && !tr.is_selected_by_seed_fill()))
continue; continue;
int tr_state = int(tr.get_state()); int tr_state = int(tr.get_state());
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel::Geometry &iva = tr.is_selected_by_seed_fill() ? iva_seed_fills_data[tr_state] : GLModel::Geometry &iva = tr.is_selected_by_seed_fill() ? iva_seed_fills_data[tr_state] :
tr.get_state() == EnforcerBlockerType::ENFORCER ? iva_enforcers_data : tr.get_state() == EnforcerBlockerType::ENFORCER ? iva_enforcers_data :
iva_blockers_data; iva_blockers_data;
@ -958,7 +1041,7 @@ void TriangleSelectorGUI::update_render_data()
GLIndexedVertexArray &iva = tr.is_selected_by_seed_fill() ? m_iva_seed_fills[tr_state] : GLIndexedVertexArray &iva = tr.is_selected_by_seed_fill() ? m_iva_seed_fills[tr_state] :
tr.get_state() == EnforcerBlockerType::ENFORCER ? m_iva_enforcers : tr.get_state() == EnforcerBlockerType::ENFORCER ? m_iva_enforcers :
m_iva_blockers; m_iva_blockers;
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
int &cnt = tr.is_selected_by_seed_fill() ? seed_fill_cnt[tr_state] : int &cnt = tr.is_selected_by_seed_fill() ? seed_fill_cnt[tr_state] :
tr.get_state() == EnforcerBlockerType::ENFORCER ? enf_cnt : tr.get_state() == EnforcerBlockerType::ENFORCER ? enf_cnt :
blc_cnt; blc_cnt;
@ -968,21 +1051,21 @@ void TriangleSelectorGUI::update_render_data()
//FIXME the normal may likely be pulled from m_triangle_selectors, but it may not be worth the effort //FIXME the normal may likely be pulled from m_triangle_selectors, but it may not be worth the effort
// or the current implementation may be more cache friendly. // or the current implementation may be more cache friendly.
const Vec3f n = (v1 - v0).cross(v2 - v1).normalized(); const Vec3f n = (v1 - v0).cross(v2 - v1).normalized();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
iva.add_vertex(v0, n); iva.add_vertex(v0, n);
iva.add_vertex(v1, n); iva.add_vertex(v1, n);
iva.add_vertex(v2, n); iva.add_vertex(v2, n);
iva.add_uint_triangle((unsigned int)cnt, (unsigned int)cnt + 1, (unsigned int)cnt + 2); iva.add_triangle((unsigned int)cnt, (unsigned int)cnt + 1, (unsigned int)cnt + 2);
#else #else
iva.push_geometry(v0, n); iva.push_geometry(v0, n);
iva.push_geometry(v1, n); iva.push_geometry(v1, n);
iva.push_geometry(v2, n); iva.push_geometry(v2, n);
iva.push_triangle(cnt, cnt + 1, cnt + 2); iva.push_triangle(cnt, cnt + 1, cnt + 2);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
cnt += 3; cnt += 3;
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
if (!iva_enforcers_data.is_empty()) if (!iva_enforcers_data.is_empty())
m_iva_enforcers.init_from(std::move(iva_enforcers_data)); m_iva_enforcers.init_from(std::move(iva_enforcers_data));
if (!iva_blockers_data.is_empty()) if (!iva_blockers_data.is_empty())
@ -991,17 +1074,15 @@ void TriangleSelectorGUI::update_render_data()
if (!iva_seed_fills_data[i].is_empty()) if (!iva_seed_fills_data[i].is_empty())
m_iva_seed_fills[i].init_from(std::move(iva_seed_fills_data[i])); m_iva_seed_fills[i].init_from(std::move(iva_seed_fills_data[i]));
} }
update_paint_contour();
#else #else
for (auto *iva : {&m_iva_enforcers, &m_iva_blockers}) for (auto *iva : {&m_iva_enforcers, &m_iva_blockers})
iva->finalize_geometry(true); iva->finalize_geometry(true);
for (auto &iva : m_iva_seed_fills) for (auto &iva : m_iva_seed_fills)
iva.finalize_geometry(true); iva.finalize_geometry(true);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
#if ENABLE_GLBEGIN_GLEND_REMOVAL
update_paint_contour();
#else
m_paint_contour.release_geometry(); m_paint_contour.release_geometry();
std::vector<Vec2i> contour_edges = this->get_seed_fill_contour(); std::vector<Vec2i> contour_edges = this->get_seed_fill_contour();
m_paint_contour.contour_vertices.reserve(contour_edges.size() * 6); m_paint_contour.contour_vertices.reserve(contour_edges.size() * 6);
@ -1020,10 +1101,10 @@ void TriangleSelectorGUI::update_render_data()
m_paint_contour.contour_indices_size = m_paint_contour.contour_indices.size(); m_paint_contour.contour_indices_size = m_paint_contour.contour_indices.size();
m_paint_contour.finalize_geometry(); m_paint_contour.finalize_geometry();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
void GLPaintContour::render() const void GLPaintContour::render() const
{ {
assert(this->m_contour_VBO_id != 0); assert(this->m_contour_VBO_id != 0);
@ -1081,7 +1162,7 @@ void GLPaintContour::release_geometry()
} }
this->clear(); this->clear();
} }
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
#ifdef PRUSASLICER_TRIANGLE_SELECTOR_DEBUG #ifdef PRUSASLICER_TRIANGLE_SELECTOR_DEBUG
void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui) void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui)
@ -1118,60 +1199,60 @@ void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui)
INVALID INVALID
}; };
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
for (auto& va : m_varrays) for (auto& va : m_varrays)
va.reset(); va.reset();
#else #else
for (auto& va : m_varrays) for (auto& va : m_varrays)
va.release_geometry(); va.release_geometry();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
std::array<int, 3> cnts; std::array<int, 3> cnts;
::glScalef(1.01f, 1.01f, 1.01f); ::glScalef(1.01f, 1.01f, 1.01f);
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
std::array<GLModel::Geometry, 3> varrays_data; std::array<GLModel::Geometry, 3> varrays_data;
for (auto& data : varrays_data) for (auto& data : varrays_data)
data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT }; data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT };
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
for (int tr_id=0; tr_id<int(m_triangles.size()); ++tr_id) { for (int tr_id=0; tr_id<int(m_triangles.size()); ++tr_id) {
const Triangle& tr = m_triangles[tr_id]; const Triangle& tr = m_triangles[tr_id];
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel::Geometry* va = nullptr; GLModel::Geometry* va = nullptr;
#else #else
GLIndexedVertexArray* va = nullptr; GLIndexedVertexArray* va = nullptr;
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
int* cnt = nullptr; int* cnt = nullptr;
if (tr_id < m_orig_size_indices) { if (tr_id < m_orig_size_indices) {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
va = &varrays_data[ORIGINAL]; va = &varrays_data[ORIGINAL];
#else #else
va = &m_varrays[ORIGINAL]; va = &m_varrays[ORIGINAL];
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
cnt = &cnts[ORIGINAL]; cnt = &cnts[ORIGINAL];
} }
else if (tr.valid()) { else if (tr.valid()) {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
va = &varrays_data[SPLIT]; va = &varrays_data[SPLIT];
#else #else
va = &m_varrays[SPLIT]; va = &m_varrays[SPLIT];
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
cnt = &cnts[SPLIT]; cnt = &cnts[SPLIT];
} }
else { else {
if (! m_show_invalid) if (! m_show_invalid)
continue; continue;
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
va = &varrays_data[INVALID]; va = &varrays_data[INVALID];
#else #else
va = &m_varrays[INVALID]; va = &m_varrays[INVALID];
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
cnt = &cnts[INVALID]; cnt = &cnts[INVALID];
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
va->add_vertex(m_vertices[tr.verts_idxs[i]].v, Vec3f(0.0f, 0.0f, 1.0f)); va->add_vertex(m_vertices[tr.verts_idxs[i]].v, Vec3f(0.0f, 0.0f, 1.0f));
} }
@ -1185,11 +1266,11 @@ void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui)
va->push_triangle(*cnt, va->push_triangle(*cnt,
*cnt + 1, *cnt + 1,
*cnt + 2); *cnt + 2);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
*cnt += 3; *cnt += 3;
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
if (!varrays_data[i].is_empty()) if (!varrays_data[i].is_empty())
m_varrays[i].init_from(std::move(varrays_data[i])); m_varrays[i].init_from(std::move(varrays_data[i]));
@ -1200,21 +1281,31 @@ void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui)
// //
// for (auto& iva : m_iva_seed_fills) // for (auto& iva : m_iva_seed_fills)
// iva.finalize_geometry(true); // iva.finalize_geometry(true);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); GLShaderProgram* curr_shader = wxGetApp().get_current_shader();
if (curr_shader != nullptr) if (curr_shader != nullptr)
curr_shader->stop_using(); curr_shader->stop_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
::glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); ::glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
for (vtype i : {ORIGINAL, SPLIT, INVALID}) { for (vtype i : {ORIGINAL, SPLIT, INVALID}) {
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel& va = m_varrays[i]; GLModel& va = m_varrays[i];
switch (i) { switch (i) {
case ORIGINAL: va.set_color({ 0.0f, 0.0f, 1.0f, 1.0f }); break; case ORIGINAL: va.set_color({ 0.0f, 0.0f, 1.0f, 1.0f }); break;
@ -1233,56 +1324,71 @@ void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui)
} }
va.render(); va.render();
} }
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
::glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); ::glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
} }
if (curr_shader != nullptr) if (curr_shader != nullptr)
curr_shader->start_using(); curr_shader->start_using();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#endif // PRUSASLICER_TRIANGLE_SELECTOR_DEBUG #endif // PRUSASLICER_TRIANGLE_SELECTOR_DEBUG
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void TriangleSelectorGUI::update_paint_contour() void TriangleSelectorGUI::update_paint_contour()
{ {
m_paint_contour.reset(); m_paint_contour.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
const std::vector<Vec2i> contour_edges = this->get_seed_fill_contour(); const std::vector<Vec2i> contour_edges = this->get_seed_fill_contour();
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::index_type(2 * contour_edges.size()) }; init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(2 * contour_edges.size()); init_data.reserve_vertices(2 * contour_edges.size());
init_data.reserve_indices(2 * contour_edges.size()); init_data.reserve_indices(2 * contour_edges.size());
#if ENABLE_GL_SHADERS_ATTRIBUTES
init_data.color = ColorRGBA::WHITE();
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
//
// vertices + indices // vertices + indices
unsigned int vertices_count = 0; unsigned int vertices_count = 0;
for (const Vec2i& edge : contour_edges) { for (const Vec2i& edge : contour_edges) {
init_data.add_vertex(m_vertices[edge(0)].v); init_data.add_vertex(m_vertices[edge(0)].v);
init_data.add_vertex(m_vertices[edge(1)].v); init_data.add_vertex(m_vertices[edge(1)].v);
vertices_count += 2; vertices_count += 2;
if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) init_data.add_line(vertices_count - 2, vertices_count - 1);
init_data.add_ushort_line((unsigned short)vertices_count - 2, (unsigned short)vertices_count - 1);
else
init_data.add_uint_line(vertices_count - 2, vertices_count - 1);
} }
if (!init_data.is_empty()) if (!init_data.is_empty())
m_paint_contour.init_from(std::move(init_data)); m_paint_contour.init_from(std::move(init_data));
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void TriangleSelectorGUI::render_paint_contour(const Transform3d& matrix)
#else
void TriangleSelectorGUI::render_paint_contour() void TriangleSelectorGUI::render_paint_contour()
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
{ {
auto* curr_shader = wxGetApp().get_current_shader(); auto* curr_shader = wxGetApp().get_current_shader();
if (curr_shader != nullptr) if (curr_shader != nullptr)
curr_shader->stop_using(); curr_shader->stop_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
auto* contour_shader = wxGetApp().get_shader("mm_contour_attr");
#else
auto* contour_shader = wxGetApp().get_shader("mm_contour"); auto* contour_shader = wxGetApp().get_shader("mm_contour");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (contour_shader != nullptr) { if (contour_shader != nullptr) {
contour_shader->start_using(); contour_shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
contour_shader->set_uniform("view_model_matrix", camera.get_view_matrix() * matrix);
contour_shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glDepthFunc(GL_LEQUAL)); glsafe(::glDepthFunc(GL_LEQUAL));
m_paint_contour.render(); m_paint_contour.render();
glsafe(::glDepthFunc(GL_LESS)); glsafe(::glDepthFunc(GL_LESS));
@ -1293,6 +1399,6 @@ void TriangleSelectorGUI::render_paint_contour()
if (curr_shader != nullptr) if (curr_shader != nullptr)
curr_shader->start_using(); curr_shader->start_using();
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} // namespace Slic3r::GUI } // namespace Slic3r::GUI

View File

@ -3,11 +3,11 @@
#include "GLGizmoBase.hpp" #include "GLGizmoBase.hpp"
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#include "slic3r/GUI/GLModel.hpp" #include "slic3r/GUI/GLModel.hpp"
#else #else
#include "slic3r/GUI/3DScene.hpp" #include "slic3r/GUI/3DScene.hpp"
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#include "libslic3r/ObjectID.hpp" #include "libslic3r/ObjectID.hpp"
#include "libslic3r/TriangleSelector.hpp" #include "libslic3r/TriangleSelector.hpp"
@ -33,7 +33,7 @@ enum class PainterGizmoType {
MMU_SEGMENTATION MMU_SEGMENTATION
}; };
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
class GLPaintContour class GLPaintContour
{ {
public: public:
@ -69,7 +69,7 @@ public:
GLuint m_contour_VBO_id{0}; GLuint m_contour_VBO_id{0};
GLuint m_contour_EBO_id{0}; GLuint m_contour_EBO_id{0};
}; };
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
class TriangleSelectorGUI : public TriangleSelector { class TriangleSelectorGUI : public TriangleSelector {
public: public:
@ -77,10 +77,15 @@ public:
: TriangleSelector(mesh) {} : TriangleSelector(mesh) {}
virtual ~TriangleSelectorGUI() = default; virtual ~TriangleSelectorGUI() = default;
#if ENABLE_GL_SHADERS_ATTRIBUTES
virtual void render(ImGuiWrapper* imgui, const Transform3d& matrix);
void render(const Transform3d& matrix) { this->render(nullptr, matrix); }
#else
// Render current selection. Transformation matrices are supposed // Render current selection. Transformation matrices are supposed
// to be already set. // to be already set.
virtual void render(ImGuiWrapper *imgui); virtual void render(ImGuiWrapper *imgui);
void render() { this->render(nullptr); } void render() { this->render(nullptr); }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void request_update_render_data() { m_update_render_data = true; } void request_update_render_data() { m_update_render_data = true; }
@ -98,7 +103,7 @@ protected:
private: private:
void update_render_data(); void update_render_data();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel m_iva_enforcers; GLModel m_iva_enforcers;
GLModel m_iva_blockers; GLModel m_iva_blockers;
std::array<GLModel, 3> m_iva_seed_fills; std::array<GLModel, 3> m_iva_seed_fills;
@ -110,17 +115,21 @@ private:
GLIndexedVertexArray m_iva_blockers; GLIndexedVertexArray m_iva_blockers;
std::array<GLIndexedVertexArray, 3> m_iva_seed_fills; std::array<GLIndexedVertexArray, 3> m_iva_seed_fills;
std::array<GLIndexedVertexArray, 3> m_varrays; std::array<GLIndexedVertexArray, 3> m_varrays;
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
protected: protected:
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel m_paint_contour; GLModel m_paint_contour;
void update_paint_contour(); void update_paint_contour();
#if ENABLE_GL_SHADERS_ATTRIBUTES
void render_paint_contour(const Transform3d& matrix);
#else
void render_paint_contour(); void render_paint_contour();
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#else #else
GLPaintContour m_paint_contour; GLPaintContour m_paint_contour;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
}; };
@ -203,11 +212,11 @@ protected:
bool m_paint_on_overhangs_only = false; bool m_paint_on_overhangs_only = false;
float m_highlight_by_angle_threshold_deg = 0.f; float m_highlight_by_angle_threshold_deg = 0.f;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel m_circle; GLModel m_circle;
Vec2d m_old_center{ Vec2d::Zero() }; Vec2d m_old_center{ Vec2d::Zero() };
float m_old_cursor_radius{ 0.0f }; float m_old_cursor_radius{ 0.0f };
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
static constexpr float SmartFillAngleMin = 0.0f; static constexpr float SmartFillAngleMin = 0.0f;
static constexpr float SmartFillAngleMax = 90.f; static constexpr float SmartFillAngleMax = 90.f;
@ -241,11 +250,11 @@ private:
const Camera& camera, const Camera& camera,
const std::vector<Transform3d>& trafo_matrices) const; const std::vector<Transform3d>& trafo_matrices) const;
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
static std::shared_ptr<GLModel> s_sphere; static std::shared_ptr<GLModel> s_sphere;
#else #else
static std::shared_ptr<GLIndexedVertexArray> s_sphere; static std::shared_ptr<GLIndexedVertexArray> s_sphere;
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
bool m_internal_stack_active = false; bool m_internal_stack_active = false;
bool m_schedule_update = false; bool m_schedule_update = false;

View File

@ -169,15 +169,30 @@ void GLGizmoRotate::on_render()
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
#if ENABLE_GL_SHADERS_ATTRIBUTES
m_grabbers.front().matrix = local_transform(selection);
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
transform_to_local(selection); transform_to_local(selection);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d view_model_matrix = camera.get_view_matrix() * m_grabbers.front().matrix;
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
const bool radius_changed = std::abs(m_old_radius - m_radius) > EPSILON; const bool radius_changed = std::abs(m_old_radius - m_radius) > EPSILON;
m_old_radius = m_radius; m_old_radius = m_radius;
@ -211,12 +226,14 @@ void GLGizmoRotate::on_render()
if (m_hover_id != -1) if (m_hover_id != -1)
render_angle(); render_angle();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
render_grabber(box); render_grabber(box);
render_grabber_extension(box, false); render_grabber_extension(box, false);
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
void GLGizmoRotate::on_render_for_picking() void GLGizmoRotate::on_render_for_picking()
@ -225,15 +242,20 @@ void GLGizmoRotate::on_render_for_picking()
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
#if ENABLE_GL_SHADERS_ATTRIBUTES
m_grabbers.front().matrix = local_transform(selection);
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
transform_to_local(selection); transform_to_local(selection);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
const BoundingBoxf3& box = selection.get_bounding_box(); const BoundingBoxf3& box = selection.get_bounding_box();
render_grabbers_for_picking(box); render_grabbers_for_picking(box);
render_grabber_extension(box, true); render_grabber_extension(box, true);
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
void GLGizmoRotate3D::on_render_input_window(float x, float y, float bottom_limit) void GLGizmoRotate3D::on_render_input_window(float x, float y, float bottom_limit)
@ -266,26 +288,26 @@ void GLGizmoRotate3D::load_rotoptimize_state()
} }
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void GLGizmoRotate::render_circle(const ColorRGBA& color, bool radius_changed) void GLGizmoRotate::render_circle(const ColorRGBA& color, bool radius_changed)
#else #else
void GLGizmoRotate::render_circle() const void GLGizmoRotate::render_circle() const
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
if (!m_circle.is_initialized() || radius_changed) { if (!m_circle.is_initialized() || radius_changed) {
m_circle.reset(); m_circle.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(ScaleStepsCount); init_data.reserve_vertices(ScaleStepsCount);
init_data.reserve_indices(ScaleStepsCount); init_data.reserve_indices(ScaleStepsCount);
// vertices + indices // vertices + indices
for (unsigned short i = 0; i < ScaleStepsCount; ++i) { for (unsigned int i = 0; i < ScaleStepsCount; ++i) {
const float angle = float(i * ScaleStepRad); const float angle = float(i * ScaleStepRad);
init_data.add_vertex(Vec3f(::cos(angle) * m_radius, ::sin(angle) * m_radius, 0.0f)); init_data.add_vertex(Vec3f(::cos(angle) * m_radius, ::sin(angle) * m_radius, 0.0f));
init_data.add_ushort_index(i); init_data.add_index(i);
} }
m_circle.init_from(std::move(init_data)); m_circle.init_from(std::move(init_data));
@ -303,29 +325,29 @@ void GLGizmoRotate::render_circle() const
::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z); ::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z);
} }
glsafe(::glEnd()); glsafe(::glEnd());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void GLGizmoRotate::render_scale(const ColorRGBA& color, bool radius_changed) void GLGizmoRotate::render_scale(const ColorRGBA& color, bool radius_changed)
#else #else
void GLGizmoRotate::render_scale() const void GLGizmoRotate::render_scale() const
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
{ {
const float out_radius_long = m_snap_fine_out_radius; const float out_radius_long = m_snap_fine_out_radius;
const float out_radius_short = m_radius * (1.0f + 0.5f * ScaleLongTooth); const float out_radius_short = m_radius * (1.0f + 0.5f * ScaleLongTooth);
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
if (!m_scale.is_initialized() || radius_changed) { if (!m_scale.is_initialized() || radius_changed) {
m_scale.reset(); m_scale.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(2 * ScaleStepsCount); init_data.reserve_vertices(2 * ScaleStepsCount);
init_data.reserve_indices(2 * ScaleStepsCount); init_data.reserve_indices(2 * ScaleStepsCount);
// vertices + indices // vertices + indices
for (unsigned short i = 0; i < ScaleStepsCount; ++i) { for (unsigned int i = 0; i < ScaleStepsCount; ++i) {
const float angle = float(i * ScaleStepRad); const float angle = float(i * ScaleStepRad);
const float cosa = ::cos(angle); const float cosa = ::cos(angle);
const float sina = ::sin(angle); const float sina = ::sin(angle);
@ -334,10 +356,12 @@ void GLGizmoRotate::render_scale() const
const float out_x = (i % ScaleLongEvery == 0) ? cosa * out_radius_long : cosa * out_radius_short; const float out_x = (i % ScaleLongEvery == 0) ? cosa * out_radius_long : cosa * out_radius_short;
const float out_y = (i % ScaleLongEvery == 0) ? sina * out_radius_long : sina * out_radius_short; const float out_y = (i % ScaleLongEvery == 0) ? sina * out_radius_long : sina * out_radius_short;
// vertices
init_data.add_vertex(Vec3f(in_x, in_y, 0.0f)); init_data.add_vertex(Vec3f(in_x, in_y, 0.0f));
init_data.add_vertex(Vec3f(out_x, out_y, 0.0f)); init_data.add_vertex(Vec3f(out_x, out_y, 0.0f));
init_data.add_ushort_index(i * 2);
init_data.add_ushort_index(i * 2 + 1); // indices
init_data.add_line(i * 2, i * 2 + 1);
} }
m_scale.init_from(std::move(init_data)); m_scale.init_from(std::move(init_data));
@ -361,30 +385,30 @@ void GLGizmoRotate::render_scale() const
::glVertex3f((GLfloat)out_x, (GLfloat)out_y, (GLfloat)out_z); ::glVertex3f((GLfloat)out_x, (GLfloat)out_y, (GLfloat)out_z);
} }
glsafe(::glEnd()); glsafe(::glEnd());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void GLGizmoRotate::render_snap_radii(const ColorRGBA& color, bool radius_changed) void GLGizmoRotate::render_snap_radii(const ColorRGBA& color, bool radius_changed)
#else #else
void GLGizmoRotate::render_snap_radii() const void GLGizmoRotate::render_snap_radii() const
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
{ {
const float step = 2.0f * float(PI) / float(SnapRegionsCount); const float step = 2.0f * float(PI) / float(SnapRegionsCount);
const float in_radius = m_radius / 3.0f; const float in_radius = m_radius / 3.0f;
const float out_radius = 2.0f * in_radius; const float out_radius = 2.0f * in_radius;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
if (!m_snap_radii.is_initialized() || radius_changed) { if (!m_snap_radii.is_initialized() || radius_changed) {
m_snap_radii.reset(); m_snap_radii.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(2 * ScaleStepsCount); init_data.reserve_vertices(2 * ScaleStepsCount);
init_data.reserve_indices(2 * ScaleStepsCount); init_data.reserve_indices(2 * ScaleStepsCount);
// vertices + indices // vertices + indices
for (unsigned short i = 0; i < ScaleStepsCount; ++i) { for (unsigned int i = 0; i < ScaleStepsCount; ++i) {
const float angle = float(i * step); const float angle = float(i * step);
const float cosa = ::cos(angle); const float cosa = ::cos(angle);
const float sina = ::sin(angle); const float sina = ::sin(angle);
@ -393,10 +417,12 @@ void GLGizmoRotate::render_snap_radii() const
const float out_x = cosa * out_radius; const float out_x = cosa * out_radius;
const float out_y = sina * out_radius; const float out_y = sina * out_radius;
// vertices
init_data.add_vertex(Vec3f(in_x, in_y, 0.0f)); init_data.add_vertex(Vec3f(in_x, in_y, 0.0f));
init_data.add_vertex(Vec3f(out_x, out_y, 0.0f)); init_data.add_vertex(Vec3f(out_x, out_y, 0.0f));
init_data.add_ushort_index(i * 2);
init_data.add_ushort_index(i * 2 + 1); // indices
init_data.add_line(i * 2, i * 2 + 1);
} }
m_snap_radii.init_from(std::move(init_data)); m_snap_radii.init_from(std::move(init_data));
@ -420,17 +446,17 @@ void GLGizmoRotate::render_snap_radii() const
::glVertex3f((GLfloat)out_x, (GLfloat)out_y, (GLfloat)out_z); ::glVertex3f((GLfloat)out_x, (GLfloat)out_y, (GLfloat)out_z);
} }
glsafe(::glEnd()); glsafe(::glEnd());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void GLGizmoRotate::render_reference_radius(const ColorRGBA& color, bool radius_changed) void GLGizmoRotate::render_reference_radius(const ColorRGBA& color, bool radius_changed)
{ {
if (!m_reference_radius.is_initialized() || radius_changed) { if (!m_reference_radius.is_initialized() || radius_changed) {
m_reference_radius.reset(); m_reference_radius.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(2); init_data.reserve_vertices(2);
init_data.reserve_indices(2); init_data.reserve_indices(2);
@ -439,7 +465,7 @@ void GLGizmoRotate::render_reference_radius(const ColorRGBA& color, bool radius_
init_data.add_vertex(Vec3f(m_radius * (1.0f + GrabberOffset), 0.0f, 0.0f)); init_data.add_vertex(Vec3f(m_radius * (1.0f + GrabberOffset), 0.0f, 0.0f));
// indices // indices
init_data.add_ushort_line(0, 1); init_data.add_line(0, 1);
m_reference_radius.init_from(std::move(init_data)); m_reference_radius.init_from(std::move(init_data));
} }
@ -455,18 +481,18 @@ void GLGizmoRotate::render_reference_radius() const
::glVertex3f((GLfloat)(m_radius * (1.0f + GrabberOffset)), 0.0f, 0.0f); ::glVertex3f((GLfloat)(m_radius * (1.0f + GrabberOffset)), 0.0f, 0.0f);
glsafe(::glEnd()); glsafe(::glEnd());
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void GLGizmoRotate::render_angle_arc(const ColorRGBA& color, bool radius_changed) void GLGizmoRotate::render_angle_arc(const ColorRGBA& color, bool radius_changed)
#else #else
void GLGizmoRotate::render_angle() const void GLGizmoRotate::render_angle() const
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
{ {
const float step_angle = float(m_angle) / float(AngleResolution); const float step_angle = float(m_angle) / float(AngleResolution);
const float ex_radius = m_radius * (1.0f + GrabberOffset); const float ex_radius = m_radius * (1.0f + GrabberOffset);
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
const bool angle_changed = std::abs(m_old_angle - m_angle) > EPSILON; const bool angle_changed = std::abs(m_old_angle - m_angle) > EPSILON;
m_old_angle = m_angle; m_old_angle = m_angle;
@ -474,15 +500,15 @@ void GLGizmoRotate::render_angle() const
m_angle_arc.reset(); m_angle_arc.reset();
if (m_angle > 0.0f) { if (m_angle > 0.0f) {
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::LineStrip, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::LineStrip, GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(1 + AngleResolution); init_data.reserve_vertices(1 + AngleResolution);
init_data.reserve_indices(1 + AngleResolution); init_data.reserve_indices(1 + AngleResolution);
// vertices + indices // vertices + indices
for (unsigned short i = 0; i <= AngleResolution; ++i) { for (unsigned int i = 0; i <= AngleResolution; ++i) {
const float angle = float(i) * step_angle; const float angle = float(i) * step_angle;
init_data.add_vertex(Vec3f(::cos(angle) * ex_radius, ::sin(angle) * ex_radius, 0.0f)); init_data.add_vertex(Vec3f(::cos(angle) * ex_radius, ::sin(angle) * ex_radius, 0.0f));
init_data.add_ushort_index(i); init_data.add_index(i);
} }
m_angle_arc.init_from(std::move(init_data)); m_angle_arc.init_from(std::move(init_data));
@ -501,10 +527,10 @@ void GLGizmoRotate::render_angle() const
::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z); ::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z);
} }
glsafe(::glEnd()); glsafe(::glEnd());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radius_changed) void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radius_changed)
{ {
if (!m_grabber_connection.model.is_initialized() || radius_changed || !m_grabber_connection.old_center.isApprox(m_grabbers.front().center)) { if (!m_grabber_connection.model.is_initialized() || radius_changed || !m_grabber_connection.old_center.isApprox(m_grabbers.front().center)) {
@ -512,7 +538,7 @@ void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radiu
m_grabber_connection.old_center = m_grabbers.front().center; m_grabber_connection.old_center = m_grabbers.front().center;
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(2); init_data.reserve_vertices(2);
init_data.reserve_indices(2); init_data.reserve_indices(2);
@ -521,7 +547,7 @@ void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radiu
init_data.add_vertex((Vec3f)m_grabbers.front().center.cast<float>()); init_data.add_vertex((Vec3f)m_grabbers.front().center.cast<float>());
// indices // indices
init_data.add_ushort_line(0, 1); init_data.add_line(0, 1);
m_grabber_connection.model.init_from(std::move(init_data)); m_grabber_connection.model.init_from(std::move(init_data));
} }
@ -529,11 +555,11 @@ void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radiu
m_grabber_connection.model.set_color(color); m_grabber_connection.model.set_color(color);
m_grabber_connection.model.render(); m_grabber_connection.model.render();
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) void GLGizmoRotate::render_grabber(const BoundingBoxf3& box)
{ {
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
const double grabber_radius = double(m_radius) * (1.0 + double(GrabberOffset)); const double grabber_radius = double(m_radius) * (1.0 + double(GrabberOffset));
m_grabbers[0].center = Vec3d(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0); m_grabbers[0].center = Vec3d(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0);
m_grabbers[0].angles.z() = m_angle; m_grabbers[0].angles.z() = m_angle;
@ -544,7 +570,7 @@ void GLGizmoRotate::render_grabber(const BoundingBoxf3& box)
::glVertex3f(0.0f, 0.0f, 0.0f); ::glVertex3f(0.0f, 0.0f, 0.0f);
::glVertex3dv(m_grabbers[0].center.data()); ::glVertex3dv(m_grabbers[0].center.data());
glsafe(::glEnd()); glsafe(::glEnd());
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
m_grabbers.front().color = m_highlight_color; m_grabbers.front().color = m_highlight_color;
render_grabbers(box); render_grabbers(box);
@ -555,8 +581,12 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
const float mean_size = float((box.size().x() + box.size().y() + box.size().z()) / 3.0); const float mean_size = float((box.size().x() + box.size().y() + box.size().z()) / 3.0);
const double size = m_dragging ? double(m_grabbers.front().get_dragging_half_size(mean_size)) : double(m_grabbers.front().get_half_size(mean_size)); const double size = m_dragging ? double(m_grabbers.front().get_dragging_half_size(mean_size)) : double(m_grabbers.front().get_half_size(mean_size));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat_attr" : "gouraud_light_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat" : "gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat" : "gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
@ -574,17 +604,38 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
shader->start_using(); shader->start_using();
shader->set_uniform("emission_factor", 0.1f); shader->set_uniform("emission_factor", 0.1f);
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
const Vec3d& center = m_grabbers.front().center; const Vec3d& center = m_grabbers.front().center;
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d& view_matrix = camera.get_view_matrix();
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
Transform3d view_model_matrix = view_matrix * m_grabbers.front().matrix *
Geometry::assemble_transform(center, Vec3d(0.5 * PI, 0.0, m_angle)) *
Geometry::assemble_transform(2.0 * size * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(0.75 * size, 0.75 * size, 3.0 * size));
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(center.x(), center.y(), center.z())); glsafe(::glTranslated(center.x(), center.y(), center.z()));
glsafe(::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0)); glsafe(::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0));
glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); glsafe(::glRotated(90.0, 1.0, 0.0, 0.0));
glsafe(::glTranslated(0.0, 0.0, 2.0 * size)); glsafe(::glTranslated(0.0, 0.0, 2.0 * size));
glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size)); glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_cone.render(); m_cone.render();
#if ENABLE_GL_SHADERS_ATTRIBUTES
view_model_matrix = view_matrix * m_grabbers.front().matrix *
Geometry::assemble_transform(center, Vec3d(-0.5 * PI, 0.0, m_angle)) *
Geometry::assemble_transform(2.0 * size * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(0.75 * size, 0.75 * size, 3.0 * size));
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(center.x(), center.y(), center.z())); glsafe(::glTranslated(center.x(), center.y(), center.z()));
@ -592,15 +643,49 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0));
glsafe(::glTranslated(0.0, 0.0, 2.0 * size)); glsafe(::glTranslated(0.0, 0.0, 2.0 * size));
glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size)); glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_cone.render(); m_cone.render();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
if (! picking) if (! picking)
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
Transform3d GLGizmoRotate::local_transform(const Selection& selection) const
{
Transform3d ret;
switch (m_axis)
{
case X:
{
ret = Geometry::assemble_transform(Vec3d::Zero(), Vec3d(0.0, 0.5 * PI, 0.0)) * Geometry::assemble_transform(Vec3d::Zero(), Vec3d(0.0, 0.0, -0.5 * PI));
break;
}
case Y:
{
ret = Geometry::assemble_transform(Vec3d::Zero(), Vec3d(0.0, 0.0, -0.5 * PI)) * Geometry::assemble_transform(Vec3d::Zero(), Vec3d(0.0, -0.5 * PI, 0.0));
break;
}
default:
case Z:
{
ret = Transform3d::Identity();
break;
}
}
if (selection.is_single_volume() || selection.is_single_modifier() || selection.requires_local_axes())
ret = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(true, false, true, true) * ret;
return Geometry::assemble_transform(m_center) * ret;
}
#else
void GLGizmoRotate::transform_to_local(const Selection& selection) const void GLGizmoRotate::transform_to_local(const Selection& selection) const
{ {
glsafe(::glTranslated(m_center.x(), m_center.y(), m_center.z())); glsafe(::glTranslated(m_center.x(), m_center.y(), m_center.z()));
@ -632,6 +717,7 @@ void GLGizmoRotate::transform_to_local(const Selection& selection) const
} }
} }
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const
{ {

View File

@ -38,7 +38,7 @@ private:
Vec3d m_forced_center{ Vec3d::Zero() }; Vec3d m_forced_center{ Vec3d::Zero() };
GLModel m_cone; GLModel m_cone;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel m_circle; GLModel m_circle;
GLModel m_scale; GLModel m_scale;
GLModel m_snap_radii; GLModel m_snap_radii;
@ -53,7 +53,7 @@ private:
float m_old_radius{ 0.0f }; float m_old_radius{ 0.0f };
float m_old_hover_radius{ 0.0f }; float m_old_hover_radius{ 0.0f };
float m_old_angle{ 0.0f }; float m_old_angle{ 0.0f };
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
ColorRGBA m_drag_color; ColorRGBA m_drag_color;
ColorRGBA m_highlight_color; ColorRGBA m_highlight_color;
@ -92,7 +92,7 @@ protected:
void on_render_for_picking() override; void on_render_for_picking() override;
private: private:
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void render_circle(const ColorRGBA& color, bool radius_changed); void render_circle(const ColorRGBA& color, bool radius_changed);
void render_scale(const ColorRGBA& color, bool radius_changed); void render_scale(const ColorRGBA& color, bool radius_changed);
void render_snap_radii(const ColorRGBA& color, bool radius_changed); void render_snap_radii(const ColorRGBA& color, bool radius_changed);
@ -105,11 +105,16 @@ private:
void render_snap_radii() const; void render_snap_radii() const;
void render_reference_radius() const; void render_reference_radius() const;
void render_angle() const; void render_angle() const;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
void render_grabber(const BoundingBoxf3& box); void render_grabber(const BoundingBoxf3& box);
void render_grabber_extension(const BoundingBoxf3& box, bool picking); void render_grabber_extension(const BoundingBoxf3& box, bool picking);
#if ENABLE_GL_SHADERS_ATTRIBUTES
Transform3d local_transform(const Selection& selection) const;
#else
void transform_to_local(const Selection& selection) const; void transform_to_local(const Selection& selection) const;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
// returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate // returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate
Vec3d mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const; Vec3d mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const;
}; };

View File

@ -2,6 +2,9 @@
#include "GLGizmoScale.hpp" #include "GLGizmoScale.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/GLCanvas3D.hpp"
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#if ENABLE_GL_SHADERS_ATTRIBUTES
#include "slic3r/GUI/Plater.hpp"
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#include <GL/glew.h> #include <GL/glew.h>
@ -22,7 +25,7 @@ GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent, const std::string& icon_filen
, m_drag_color(DEFAULT_DRAG_COLOR) , m_drag_color(DEFAULT_DRAG_COLOR)
, m_highlight_color(DEFAULT_HIGHLIGHT_COLOR) , m_highlight_color(DEFAULT_HIGHLIGHT_COLOR)
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_grabber_connections[0].grabber_indices = { 0, 1 }; m_grabber_connections[0].grabber_indices = { 0, 1 };
m_grabber_connections[1].grabber_indices = { 2, 3 }; m_grabber_connections[1].grabber_indices = { 2, 3 };
m_grabber_connections[2].grabber_indices = { 4, 5 }; m_grabber_connections[2].grabber_indices = { 4, 5 };
@ -30,7 +33,7 @@ GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent, const std::string& icon_filen
m_grabber_connections[4].grabber_indices = { 7, 8 }; m_grabber_connections[4].grabber_indices = { 7, 8 };
m_grabber_connections[5].grabber_indices = { 8, 9 }; m_grabber_connections[5].grabber_indices = { 8, 9 };
m_grabber_connections[6].grabber_indices = { 9, 6 }; m_grabber_connections[6].grabber_indices = { 9, 6 };
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
std::string GLGizmoScale3D::get_tooltip() const std::string GLGizmoScale3D::get_tooltip() const
@ -215,11 +218,11 @@ void GLGizmoScale3D::on_render()
m_box = selection.get_bounding_box(); m_box = selection.get_bounding_box();
const Vec3d& center = m_box.center(); const Vec3d& center = m_box.center();
Vec3d offset_x = offsets_transform * Vec3d((double)Offset, 0.0, 0.0); const Vec3d offset_x = offsets_transform * Vec3d((double)Offset, 0.0, 0.0);
Vec3d offset_y = offsets_transform * Vec3d(0.0, (double)Offset, 0.0); const Vec3d offset_y = offsets_transform * Vec3d(0.0, (double)Offset, 0.0);
Vec3d offset_z = offsets_transform * Vec3d(0.0, 0.0, (double)Offset); const Vec3d offset_z = offsets_transform * Vec3d(0.0, 0.0, (double)Offset);
bool ctrl_down = (m_dragging && m_starting.ctrl_down) || (!m_dragging && wxGetKeyState(WXK_CONTROL)); const bool ctrl_down = (m_dragging && m_starting.ctrl_down) || (!m_dragging && wxGetKeyState(WXK_CONTROL));
// x axis // x axis
m_grabbers[0].center = m_transform * Vec3d(m_box.min.x(), center.y(), center.z()) - offset_x; m_grabbers[0].center = m_transform * Vec3d(m_box.min.x(), center.y(), center.z()) - offset_x;
@ -257,14 +260,23 @@ void GLGizmoScale3D::on_render()
const BoundingBoxf3& selection_box = selection.get_bounding_box(); const BoundingBoxf3& selection_box = selection.get_bounding_box();
float grabber_mean_size = (float)((selection_box.size().x() + selection_box.size().y() + selection_box.size().z()) / 3.0); const float grabber_mean_size = (float)((selection_box.size().x() + selection_box.size().y() + selection_box.size().z()) / 3.0);
if (m_hover_id == -1) { if (m_hover_id == -1) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// draw connections // draw connections
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (m_grabbers[0].enabled && m_grabbers[1].enabled) if (m_grabbers[0].enabled && m_grabbers[1].enabled)
render_grabbers_connection(0, 1, m_grabbers[0].color); render_grabbers_connection(0, 1, m_grabbers[0].color);
if (m_grabbers[2].enabled && m_grabbers[3].enabled) if (m_grabbers[2].enabled && m_grabbers[3].enabled)
@ -296,23 +308,36 @@ void GLGizmoScale3D::on_render()
render_grabbers_connection(7, 8); render_grabbers_connection(7, 8);
render_grabbers_connection(8, 9); render_grabbers_connection(8, 9);
render_grabbers_connection(9, 6); render_grabbers_connection(9, 6);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// draw grabbers // draw grabbers
render_grabbers(grabber_mean_size); render_grabbers(grabber_mean_size);
} }
else if (m_hover_id == 0 || m_hover_id == 1) { else if (m_hover_id == 0 || m_hover_id == 1) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// draw connections // draw connections
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
render_grabbers_connection(0, 1, m_grabbers[0].color); render_grabbers_connection(0, 1, m_grabbers[0].color);
shader->stop_using(); shader->stop_using();
} }
// draw grabbers // draw grabbers
#if ENABLE_GL_SHADERS_ATTRIBUTES
shader = wxGetApp().get_shader("gouraud_light_attr");
#else
shader = wxGetApp().get_shader("gouraud_light"); shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#else #else
// draw connection // draw connection
glsafe(::glColor4fv(m_grabbers[0].color.data())); glsafe(::glColor4fv(m_grabbers[0].color.data()));
@ -320,7 +345,7 @@ void GLGizmoScale3D::on_render()
// draw grabbers // draw grabbers
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
shader->set_uniform("emission_factor", 0.1f); shader->set_uniform("emission_factor", 0.1f);
@ -330,17 +355,30 @@ void GLGizmoScale3D::on_render()
} }
} }
else if (m_hover_id == 2 || m_hover_id == 3) { else if (m_hover_id == 2 || m_hover_id == 3) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// draw connections // draw connections
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
render_grabbers_connection(2, 3, m_grabbers[2].color); render_grabbers_connection(2, 3, m_grabbers[2].color);
shader->stop_using(); shader->stop_using();
} }
// draw grabbers // draw grabbers
#if ENABLE_GL_SHADERS_ATTRIBUTES
shader = wxGetApp().get_shader("gouraud_light_attr");
#else
shader = wxGetApp().get_shader("gouraud_light"); shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#else #else
// draw connection // draw connection
glsafe(::glColor4fv(m_grabbers[2].color.data())); glsafe(::glColor4fv(m_grabbers[2].color.data()));
@ -348,7 +386,7 @@ void GLGizmoScale3D::on_render()
// draw grabbers // draw grabbers
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
shader->set_uniform("emission_factor", 0.1f); shader->set_uniform("emission_factor", 0.1f);
@ -358,17 +396,30 @@ void GLGizmoScale3D::on_render()
} }
} }
else if (m_hover_id == 4 || m_hover_id == 5) { else if (m_hover_id == 4 || m_hover_id == 5) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// draw connections // draw connections
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
render_grabbers_connection(4, 5, m_grabbers[4].color); render_grabbers_connection(4, 5, m_grabbers[4].color);
shader->stop_using(); shader->stop_using();
} }
// draw grabbers // draw grabbers
#if ENABLE_GL_SHADERS_ATTRIBUTES
shader = wxGetApp().get_shader("gouraud_light_attr");
#else
shader = wxGetApp().get_shader("gouraud_light"); shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#else #else
// draw connection // draw connection
glsafe(::glColor4fv(m_grabbers[4].color.data())); glsafe(::glColor4fv(m_grabbers[4].color.data()));
@ -376,7 +427,7 @@ void GLGizmoScale3D::on_render()
// draw grabbers // draw grabbers
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
shader->set_uniform("emission_factor", 0.1f); shader->set_uniform("emission_factor", 0.1f);
@ -386,11 +437,20 @@ void GLGizmoScale3D::on_render()
} }
} }
else if (m_hover_id >= 6) { else if (m_hover_id >= 6) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// draw connections // draw connections
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
render_grabbers_connection(6, 7, m_drag_color); render_grabbers_connection(6, 7, m_drag_color);
render_grabbers_connection(7, 8, m_drag_color); render_grabbers_connection(7, 8, m_drag_color);
render_grabbers_connection(8, 9, m_drag_color); render_grabbers_connection(8, 9, m_drag_color);
@ -399,7 +459,11 @@ void GLGizmoScale3D::on_render()
} }
// draw grabbers // draw grabbers
#if ENABLE_GL_SHADERS_ATTRIBUTES
shader = wxGetApp().get_shader("gouraud_light_attr");
#else
shader = wxGetApp().get_shader("gouraud_light"); shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#else #else
// draw connection // draw connection
glsafe(::glColor4fv(m_drag_color.data())); glsafe(::glColor4fv(m_drag_color.data()));
@ -410,7 +474,7 @@ void GLGizmoScale3D::on_render()
// draw grabbers // draw grabbers
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
shader->set_uniform("emission_factor", 0.1f); shader->set_uniform("emission_factor", 0.1f);
@ -428,7 +492,7 @@ void GLGizmoScale3D::on_render_for_picking()
render_grabbers_for_picking(m_parent.get_selection().get_bounding_box()); render_grabbers_for_picking(m_parent.get_selection().get_bounding_box());
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2, const ColorRGBA& color) void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2, const ColorRGBA& color)
{ {
auto grabber_connection = [this](unsigned int id_1, unsigned int id_2) { auto grabber_connection = [this](unsigned int id_1, unsigned int id_2) {
@ -451,7 +515,7 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int
m_grabber_connections[id].model.reset(); m_grabber_connections[id].model.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(2); init_data.reserve_vertices(2);
init_data.reserve_indices(2); init_data.reserve_indices(2);
@ -460,7 +524,7 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int
init_data.add_vertex((Vec3f)m_grabbers[id_2].center.cast<float>()); init_data.add_vertex((Vec3f)m_grabbers[id_2].center.cast<float>());
// indices // indices
init_data.add_ushort_line(0, 1); init_data.add_line(0, 1);
m_grabber_connections[id].model.init_from(std::move(init_data)); m_grabber_connections[id].model.init_from(std::move(init_data));
} }
@ -479,7 +543,7 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int
glsafe(::glEnd()); glsafe(::glEnd());
} }
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
void GLGizmoScale3D::do_scale_along_axis(Axis axis, const UpdateData& data) void GLGizmoScale3D::do_scale_along_axis(Axis axis, const UpdateData& data)
{ {

View File

@ -33,7 +33,7 @@ class GLGizmoScale3D : public GLGizmoBase
double m_snap_step{ 0.05 }; double m_snap_step{ 0.05 };
StartingData m_starting; StartingData m_starting;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
struct GrabberConnection struct GrabberConnection
{ {
GLModel model; GLModel model;
@ -42,7 +42,7 @@ class GLGizmoScale3D : public GLGizmoBase
Vec3d old_v2{ Vec3d::Zero() }; Vec3d old_v2{ Vec3d::Zero() };
}; };
std::array<GrabberConnection, 7> m_grabber_connections; std::array<GrabberConnection, 7> m_grabber_connections;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
ColorRGBA m_base_color; ColorRGBA m_base_color;
ColorRGBA m_drag_color; ColorRGBA m_drag_color;
@ -77,11 +77,11 @@ protected:
virtual void on_render_for_picking() override; virtual void on_render_for_picking() override;
private: private:
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void render_grabbers_connection(unsigned int id_1, unsigned int id_2, const ColorRGBA& color); void render_grabbers_connection(unsigned int id_1, unsigned int id_2, const ColorRGBA& color);
#else #else
void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const; void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
void do_scale_along_axis(Axis axis, const UpdateData& data); void do_scale_along_axis(Axis axis, const UpdateData& data);
void do_scale_uniform(const UpdateData& data); void do_scale_uniform(const UpdateData& data);

View File

@ -651,7 +651,7 @@ void GLGizmoSimplify::init_model()
} }
assert(volume != nullptr); assert(volume != nullptr);
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// set actual triangle count // set actual triangle count
m_triangle_count += volume->mesh().its.indices.size(); m_triangle_count += volume->mesh().its.indices.size();
#else #else
@ -659,17 +659,17 @@ void GLGizmoSimplify::init_model()
// set actual triangle count // set actual triangle count
m_triangle_count += its.indices.size(); m_triangle_count += its.indices.size();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
assert(m_glmodels.find(id) == m_glmodels.end()); assert(m_glmodels.find(id) == m_glmodels.end());
GLModel &glmodel = m_glmodels[id]; // create new glmodel GLModel &glmodel = m_glmodels[id]; // create new glmodel
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
glmodel.init_from(volume->mesh()); glmodel.init_from(volume->mesh());
glmodel.set_color(selected_volume->color); glmodel.set_color(selected_volume->color);
#else #else
glmodel.init_from(its); glmodel.init_from(its);
glmodel.set_color(-1,selected_volume->color); glmodel.set_color(-1,selected_volume->color);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
m_parent.toggle_model_objects_visibility(false, info->model_object(), m_parent.toggle_model_objects_visibility(false, info->model_object(),
info->get_active_instance(), info->get_active_instance(),
@ -698,11 +698,11 @@ void GLGizmoSimplify::update_model(const State::Data &data)
// when not reset it keeps old shape // when not reset it keeps old shape
glmodel.reset(); glmodel.reset();
glmodel.init_from(its); glmodel.init_from(its);
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
glmodel.set_color(color); glmodel.set_color(color);
#else #else
glmodel.set_color(-1, color); glmodel.set_color(-1, color);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
m_triangle_count += its.indices.size(); m_triangle_count += its.indices.size();
} }
@ -737,27 +737,53 @@ void GLGizmoSimplify::on_render()
GLModel &glmodel = it->second; GLModel &glmodel = it->second;
const Transform3d trafo_matrix = selected_volume->world_matrix(); const Transform3d trafo_matrix = selected_volume->world_matrix();
#if ENABLE_GL_SHADERS_ATTRIBUTES
auto* gouraud_shader = wxGetApp().get_shader("gouraud_light_attr");
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glMultMatrixd(trafo_matrix.data())); glsafe(::glMultMatrixd(trafo_matrix.data()));
auto *gouraud_shader = wxGetApp().get_shader("gouraud_light"); auto *gouraud_shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPushAttrib(GL_DEPTH_TEST)); glsafe(::glPushAttrib(GL_DEPTH_TEST));
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
gouraud_shader->start_using(); gouraud_shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d view_model_matrix = camera.get_view_matrix() * trafo_matrix;
gouraud_shader->set_uniform("view_model_matrix", view_model_matrix);
gouraud_shader->set_uniform("projection_matrix", camera.get_projection_matrix());
gouraud_shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
glmodel.render(); glmodel.render();
gouraud_shader->stop_using(); gouraud_shader->stop_using();
if (m_show_wireframe) { if (m_show_wireframe) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
auto* contour_shader = wxGetApp().get_shader("mm_contour_attr");
#else
auto *contour_shader = wxGetApp().get_shader("mm_contour"); auto *contour_shader = wxGetApp().get_shader("mm_contour");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
contour_shader->start_using(); contour_shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
contour_shader->set_uniform("view_model_matrix", view_model_matrix);
contour_shader->set_uniform("projection_matrix", camera.get_projection_matrix());
const ColorRGBA color = glmodel.get_color();
glmodel.set_color(ColorRGBA::WHITE());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glLineWidth(1.0f)); glsafe(::glLineWidth(1.0f));
glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)); glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_LINE));
glmodel.render(); glmodel.render();
glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)); glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL));
#if ENABLE_GL_SHADERS_ATTRIBUTES
glmodel.set_color(color);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
contour_shader->stop_using(); contour_shader->stop_using();
} }
glsafe(::glPopAttrib()); glsafe(::glPopAttrib());
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
} }

View File

@ -129,8 +129,12 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
if (! has_points && ! has_holes) if (! has_points && ! has_holes)
return; return;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat_attr") : wxGetApp().get_shader("gouraud_light_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat" : "gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat" : "gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
@ -144,16 +148,26 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
if (shader != nullptr) if (shader != nullptr)
shader->stop_using(); shader->stop_using();
}); });
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin());
const Transform3d instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse(); const Transform3d instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse();
const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix(); #if ENABLE_GL_SHADERS_ATTRIBUTES
const float z_shift = m_c->selection_info()->get_sla_shift(); const Transform3d instance_matrix = Geometry::assemble_transform(m_c->selection_info()->get_sla_shift() * Vec3d::UnitZ()) * vol->get_instance_transformation().get_matrix();
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d& view_matrix = camera.get_view_matrix();
const Transform3d& projection_matrix = camera.get_projection_matrix();
shader->set_uniform("projection_matrix", projection_matrix);
#else
const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix();
const float z_shift = m_c->selection_info()->get_sla_shift();
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(0.0, 0.0, z_shift)); glsafe(::glTranslated(0.0, 0.0, z_shift));
glsafe(::glMultMatrixd(instance_matrix.data())); glsafe(::glMultMatrixd(instance_matrix.data()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
ColorRGBA render_color; ColorRGBA render_color;
for (size_t i = 0; i < cache_size; ++i) { for (size_t i = 0; i < cache_size; ++i) {
@ -185,7 +199,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
} }
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_cone.set_color(render_color); m_cone.set_color(render_color);
m_sphere.set_color(render_color); m_sphere.set_color(render_color);
if (!picking) if (!picking)
@ -193,13 +207,17 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
m_cone.set_color(-1, render_color); m_cone.set_color(-1, render_color);
m_sphere.set_color(-1, render_color); m_sphere.set_color(-1, render_color);
if (shader && !picking) if (shader && !picking)
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
shader->set_uniform("emission_factor", 0.5f); shader->set_uniform("emission_factor", 0.5f);
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object.
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d support_matrix = Geometry::assemble_transform(support_point.pos.cast<double>()) * instance_scaling_matrix_inverse;
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslatef(support_point.pos.x(), support_point.pos.y(), support_point.pos.z())); glsafe(::glTranslatef(support_point.pos.x(), support_point.pos.y(), support_point.pos.z()));
glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data())); glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (vol->is_left_handed()) if (vol->is_left_handed())
glFrontFace(GL_CW); glFrontFace(GL_CW);
@ -212,68 +230,108 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
m_c->raycaster()->raycaster()->get_closest_point(m_editing_cache[i].support_point.pos, &m_editing_cache[i].normal); m_c->raycaster()->raycaster()->get_closest_point(m_editing_cache[i].support_point.pos, &m_editing_cache[i].normal);
Eigen::Quaterniond q; Eigen::Quaterniond q;
q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast<double>()); q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast<double>());
const Eigen::AngleAxisd aa(q); const Eigen::AngleAxisd aa(q);
glsafe(::glPushMatrix());
glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z()));
const double cone_radius = 0.25; // mm const double cone_radius = 0.25; // mm
const double cone_height = 0.75; const double cone_height = 0.75;
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d view_model_matrix = view_matrix * instance_matrix * support_matrix * Transform3d(aa.toRotationMatrix()) *
Geometry::assemble_transform((cone_height + support_point.head_front_radius * RenderPointScale) * Vec3d::UnitZ(),
Vec3d(PI, 0.0, 0.0), Vec3d(cone_radius, cone_radius, cone_height));
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glPushMatrix());
glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z()));
glsafe(::glTranslatef(0.f, 0.f, cone_height + support_point.head_front_radius * RenderPointScale)); glsafe(::glTranslatef(0.f, 0.f, cone_height + support_point.head_front_radius * RenderPointScale));
glsafe(::glRotated(180., 1., 0., 0.)); glsafe(::glRotated(180., 1., 0., 0.));
glsafe(::glScaled(cone_radius, cone_radius, cone_height)); glsafe(::glScaled(cone_radius, cone_radius, cone_height));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_cone.render(); m_cone.render();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
const double radius = (double)support_point.head_front_radius * RenderPointScale; const double radius = (double)support_point.head_front_radius * RenderPointScale;
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d view_model_matrix = view_matrix * instance_matrix * support_matrix *
Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), radius * Vec3d::Ones());
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glPushMatrix());
glsafe(::glScaled(radius, radius, radius)); glsafe(::glScaled(radius, radius, radius));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_sphere.render(); m_sphere.render();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
if (vol->is_left_handed()) if (vol->is_left_handed())
glFrontFace(GL_CCW); glFrontFace(GL_CCW);
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
// Now render the drain holes: // Now render the drain holes:
if (has_holes && ! picking) { if (has_holes && ! picking) {
render_color = { 0.7f, 0.7f, 0.7f, 0.7f }; render_color = { 0.7f, 0.7f, 0.7f, 0.7f };
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_cylinder.set_color(render_color); m_cylinder.set_color(render_color);
#else #else
m_cylinder.set_color(-1, render_color); m_cylinder.set_color(-1, render_color);
if (shader != nullptr) if (shader != nullptr)
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
shader->set_uniform("emission_factor", 0.5f); shader->set_uniform("emission_factor", 0.5f);
for (const sla::DrainHole& drain_hole : m_c->selection_info()->model_object()->sla_drain_holes) { for (const sla::DrainHole& drain_hole : m_c->selection_info()->model_object()->sla_drain_holes) {
if (is_mesh_point_clipped(drain_hole.pos.cast<double>())) if (is_mesh_point_clipped(drain_hole.pos.cast<double>()))
continue; continue;
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d hole_matrix = Geometry::assemble_transform(drain_hole.pos.cast<double>()) * instance_scaling_matrix_inverse;
#else
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object.
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslatef(drain_hole.pos.x(), drain_hole.pos.y(), drain_hole.pos.z())); glsafe(::glTranslatef(drain_hole.pos.x(), drain_hole.pos.y(), drain_hole.pos.z()));
glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data())); glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (vol->is_left_handed()) if (vol->is_left_handed())
glFrontFace(GL_CW); glFrontFace(GL_CW);
// Matrices set, we can render the point mark now. // Matrices set, we can render the point mark now.
Eigen::Quaterniond q; Eigen::Quaterniond q;
q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * (-drain_hole.normal).cast<double>()); q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-drain_hole.normal).cast<double>());
const Eigen::AngleAxisd aa(q); const Eigen::AngleAxisd aa(q);
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d view_model_matrix = view_matrix * instance_matrix * hole_matrix * Transform3d(aa.toRotationMatrix()) *
Geometry::assemble_transform(-drain_hole.height * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength));
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z())); glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z()));
glsafe(::glTranslated(0., 0., -drain_hole.height)); glsafe(::glTranslated(0., 0., -drain_hole.height));
glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_cylinder.render(); m_cylinder.render();
if (vol->is_left_handed()) if (vol->is_left_handed())
glFrontFace(GL_CCW); glFrontFace(GL_CCW);
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
} }
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }

View File

@ -209,27 +209,32 @@ void InstancesHider::render_cut() const
ClippingPlane clp = *get_pool()->object_clipper()->get_clipping_plane(); ClippingPlane clp = *get_pool()->object_clipper()->get_clipping_plane();
clp.set_normal(-clp.get_normal()); clp.set_normal(-clp.get_normal());
clipper->set_limiting_plane(clp); clipper->set_limiting_plane(clp);
} else }
else
clipper->set_limiting_plane(ClippingPlane::ClipsNothing()); clipper->set_limiting_plane(ClippingPlane::ClipsNothing());
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
#if !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_GL_SHADERS_ATTRIBUTES
#if !ENABLE_LEGACY_OPENGL_REMOVAL
if (mv->is_model_part()) if (mv->is_model_part())
glsafe(::glColor3f(0.8f, 0.3f, 0.0f)); glsafe(::glColor3f(0.8f, 0.3f, 0.0f));
else { else {
const ColorRGBA color = color_from_model_volume(*mv); const ColorRGBA color = color_from_model_volume(*mv);
glsafe(::glColor4fv(color.data())); glsafe(::glColor4fv(color.data()));
} }
#endif // !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glPushAttrib(GL_DEPTH_TEST)); glsafe(::glPushAttrib(GL_DEPTH_TEST));
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
clipper->render_cut(mv->is_model_part() ? ColorRGBA(0.8f, 0.3f, 0.0f, 1.0f) : color_from_model_volume(*mv)); clipper->render_cut(mv->is_model_part() ? ColorRGBA(0.8f, 0.3f, 0.0f, 1.0f) : color_from_model_volume(*mv));
#else #else
clipper->render_cut(); clipper->render_cut();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glPopAttrib()); glsafe(::glPopAttrib());
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
++clipper_id; ++clipper_id;
} }
@ -410,11 +415,11 @@ void ObjectClipper::render_cut() const
return; return;
const SelectionInfo* sel_info = get_pool()->selection_info(); const SelectionInfo* sel_info = get_pool()->selection_info();
const ModelObject* mo = sel_info->model_object(); const ModelObject* mo = sel_info->model_object();
Geometry::Transformation inst_trafo = mo->instances[sel_info->get_active_instance()]->get_transformation(); const Geometry::Transformation inst_trafo = mo->instances[sel_info->get_active_instance()]->get_transformation();
size_t clipper_id = 0; size_t clipper_id = 0;
for (const ModelVolume* mv : mo->volumes) { for (const ModelVolume* mv : mo->volumes) {
Geometry::Transformation vol_trafo = mv->get_transformation(); const Geometry::Transformation vol_trafo = mv->get_transformation();
Geometry::Transformation trafo = inst_trafo * vol_trafo; Geometry::Transformation trafo = inst_trafo * vol_trafo;
trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., sel_info->get_sla_shift())); trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., sel_info->get_sla_shift()));
@ -422,8 +427,10 @@ void ObjectClipper::render_cut() const
clipper->set_plane(*m_clp); clipper->set_plane(*m_clp);
clipper->set_transformation(trafo); clipper->set_transformation(trafo);
clipper->set_limiting_plane(ClippingPlane(Vec3d::UnitZ(), -SINKING_Z_THRESHOLD)); clipper->set_limiting_plane(ClippingPlane(Vec3d::UnitZ(), -SINKING_Z_THRESHOLD));
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_LEGACY_OPENGL_REMOVAL
clipper->render_cut({ 1.0f, 0.37f, 0.0f, 1.0f }); clipper->render_cut({ 1.0f, 0.37f, 0.0f, 1.0f });
clipper->render_contour({ 1.f, 1.f, 1.f, 1.f}); clipper->render_contour({ 1.f, 1.f, 1.f, 1.f});
#else #else
@ -431,8 +438,10 @@ void ObjectClipper::render_cut() const
clipper->render_cut(); clipper->render_cut();
glsafe(::glColor3f(1.f, 1.f, 1.f)); glsafe(::glColor3f(1.f, 1.f, 1.f));
clipper->render_contour(); clipper->render_contour();
#endif #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
++clipper_id; ++clipper_id;
} }
@ -545,7 +554,7 @@ void SupportsClipper::render_cut() const
const SelectionInfo* sel_info = get_pool()->selection_info(); const SelectionInfo* sel_info = get_pool()->selection_info();
const ModelObject* mo = sel_info->model_object(); const ModelObject* mo = sel_info->model_object();
Geometry::Transformation inst_trafo = mo->instances[sel_info->get_active_instance()]->get_transformation(); const Geometry::Transformation inst_trafo = mo->instances[sel_info->get_active_instance()]->get_transformation();
//Geometry::Transformation vol_trafo = mo->volumes.front()->get_transformation(); //Geometry::Transformation vol_trafo = mo->volumes.front()->get_transformation();
Geometry::Transformation trafo = inst_trafo;// * vol_trafo; Geometry::Transformation trafo = inst_trafo;// * vol_trafo;
trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., sel_info->get_sla_shift())); trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., sel_info->get_sla_shift()));
@ -564,8 +573,10 @@ void SupportsClipper::render_cut() const
m_clipper->set_plane(*ocl->get_clipping_plane()); m_clipper->set_plane(*ocl->get_clipping_plane());
m_clipper->set_transformation(supports_trafo); m_clipper->set_transformation(supports_trafo);
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // !ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_LEGACY_OPENGL_REMOVAL
m_clipper->render_cut({ 1.0f, 0.f, 0.37f, 1.0f }); m_clipper->render_cut({ 1.0f, 0.f, 0.37f, 1.0f });
m_clipper->render_contour({ 1.f, 1.f, 1.f, 1.f }); m_clipper->render_contour({ 1.f, 1.f, 1.f, 1.f });
#else #else
@ -573,8 +584,10 @@ void SupportsClipper::render_cut() const
m_clipper->render_cut(); m_clipper->render_cut();
glsafe(::glColor3f(1.0f, 1.f, 1.f)); glsafe(::glColor3f(1.0f, 1.f, 1.f));
m_clipper->render_contour(); m_clipper->render_contour();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }

View File

@ -124,7 +124,17 @@ bool GLGizmosManager::init()
return true; return true;
} }
bool GLGizmosManager::init_arrow(const BackgroundTexture::Metadata& arrow_texture) #if ENABLE_GL_SHADERS_ATTRIBUTES
bool GLGizmosManager::init_arrow(const std::string& filename)
{
if (m_arrow_texture.get_id() != 0)
return true;
const std::string path = resources_dir() + "/icons/";
return (!filename.empty()) ? m_arrow_texture.load_from_svg_file(path + filename, false, false, false, 512) : false;
}
#else
bool GLGizmosManager::init_arrow(const BackgroundTexture::Metadata & arrow_texture)
{ {
if (m_arrow_texture.texture.get_id() != 0) if (m_arrow_texture.texture.get_id() != 0)
return true; return true;
@ -139,6 +149,7 @@ bool GLGizmosManager::init_arrow(const BackgroundTexture::Metadata& arrow_textur
return res; return res;
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void GLGizmosManager::set_overlay_icon_size(float size) void GLGizmosManager::set_overlay_icon_size(float size)
{ {
@ -331,7 +342,7 @@ void GLGizmosManager::render_current_gizmo_for_picking_pass() const
m_gizmos[m_current]->render_for_picking(); m_gizmos[m_current]->render_for_picking();
} }
void GLGizmosManager::render_overlay() const void GLGizmosManager::render_overlay()
{ {
if (!m_enabled) if (!m_enabled)
return; return;
@ -667,6 +678,60 @@ void GLGizmosManager::update_after_undo_redo(const UndoRedo::Snapshot& snapshot)
dynamic_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports].get())->reslice_SLA_supports(true); dynamic_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports].get())->reslice_SLA_supports(true);
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void GLGizmosManager::render_background(float left, float top, float right, float bottom, float border_w, float border_h) const
{
const unsigned int tex_id = m_background_texture.texture.get_id();
const float tex_width = float(m_background_texture.texture.get_width());
const float tex_height = float(m_background_texture.texture.get_height());
if (tex_id != 0 && tex_width > 0 && tex_height > 0) {
const float inv_tex_width = (tex_width != 0.0f) ? 1.0f / tex_width : 0.0f;
const float inv_tex_height = (tex_height != 0.0f) ? 1.0f / tex_height : 0.0f;
const float internal_left = left + border_w;
const float internal_right = right - border_w;
const float internal_top = top - border_h;
const float internal_bottom = bottom + border_h;
// float left_uv = 0.0f;
const float right_uv = 1.0f;
const float top_uv = 1.0f;
const float bottom_uv = 0.0f;
const float internal_left_uv = float(m_background_texture.metadata.left) * inv_tex_width;
const float internal_right_uv = 1.0f - float(m_background_texture.metadata.right) * inv_tex_width;
const float internal_top_uv = 1.0f - float(m_background_texture.metadata.top) * inv_tex_height;
const float internal_bottom_uv = float(m_background_texture.metadata.bottom) * inv_tex_height;
// top-left corner
GLTexture::render_sub_texture(tex_id, left, internal_left, internal_top, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
// top edge
GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_top, top, { { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, top_uv }, { internal_left_uv, top_uv } });
// top-right corner
GLTexture::render_sub_texture(tex_id, internal_right, right, internal_top, top, { { internal_right_uv, internal_top_uv }, { right_uv, internal_top_uv }, { right_uv, top_uv }, { internal_right_uv, top_uv } });
// center-left edge
GLTexture::render_sub_texture(tex_id, left, internal_left, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
// center
GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
// center-right edge
GLTexture::render_sub_texture(tex_id, internal_right, right, internal_bottom, internal_top, { { internal_right_uv, internal_bottom_uv }, { right_uv, internal_bottom_uv }, { right_uv, internal_top_uv }, { internal_right_uv, internal_top_uv } });
// bottom-left corner
GLTexture::render_sub_texture(tex_id, left, internal_left, bottom, internal_bottom, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
// bottom edge
GLTexture::render_sub_texture(tex_id, internal_left, internal_right, bottom, internal_bottom, { { internal_left_uv, bottom_uv }, { internal_right_uv, bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv } });
// bottom-right corner
GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } });
}
}
#else
void GLGizmosManager::render_background(float left, float top, float right, float bottom, float border) const void GLGizmosManager::render_background(float left, float top, float right, float bottom, float border) const
{ {
const unsigned int tex_id = m_background_texture.texture.get_id(); const unsigned int tex_id = m_background_texture.texture.get_id();
@ -719,7 +784,56 @@ void GLGizmosManager::render_background(float left, float top, float right, floa
GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } }); GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } });
} }
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_GL_SHADERS_ATTRIBUTES
void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_type) const
{
const std::vector<size_t> selectable_idxs = get_selectable_idxs();
if (selectable_idxs.empty())
return;
const Size cnv_size = m_parent.get_canvas_size();
const float cnv_w = (float)cnv_size.get_width();
const float cnv_h = (float)cnv_size.get_height();
if (cnv_w == 0 || cnv_h == 0)
return;
const float inv_cnv_w = 1.0f / cnv_w;
const float inv_cnv_h = 1.0f / cnv_h;
const float top_x = -1.0f;
float top_y = get_scaled_total_height() * inv_cnv_h;
const float icons_size_x = 2.0f * m_layout.scaled_icons_size() * inv_cnv_w;
const float icons_size_y = 2.0f * m_layout.scaled_icons_size() * inv_cnv_h;
const float stride_y = 2.0f * m_layout.scaled_stride_y() * inv_cnv_h;
for (size_t idx : selectable_idxs) {
if (idx == highlighted_type) {
const int tex_width = m_arrow_texture.get_width();
const int tex_height = m_arrow_texture.get_height();
const unsigned int tex_id = m_arrow_texture.get_id();
const float arrow_size_x = 2.0f * m_layout.scale * float(tex_height) * inv_cnv_w;
const float arrow_size_y = 2.0f * m_layout.scale * float(tex_width) * inv_cnv_h;
const float left_uv = 0.0f;
const float right_uv = 1.0f;
const float top_uv = 1.0f;
const float bottom_uv = 0.0f;
const float left = top_x + icons_size_x + 6.0f * m_layout.scaled_border() * inv_cnv_w;
const float right = left + arrow_size_x * icons_size_y / arrow_size_y;
GLTexture::render_sub_texture(tex_id, left, right, top_y, top_y + icons_size_y, { { left_uv, bottom_uv }, { left_uv, top_uv }, { right_uv, top_uv }, { right_uv, bottom_uv } });
break;
}
top_y -= stride_y;
}
}
#else
void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_type) const void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_type) const
{ {
std::vector<size_t> selectable_idxs = get_selectable_idxs(); std::vector<size_t> selectable_idxs = get_selectable_idxs();
@ -758,21 +872,95 @@ void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_t
zoomed_top_y -= zoomed_stride_y; zoomed_top_y -= zoomed_stride_y;
} }
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_GL_SHADERS_ATTRIBUTES
void GLGizmosManager::do_render_overlay() const
{
const std::vector<size_t> selectable_idxs = get_selectable_idxs();
if (selectable_idxs.empty())
return;
const Size cnv_size = m_parent.get_canvas_size();
const float cnv_w = (float)cnv_size.get_width();
const float cnv_h = (float)cnv_size.get_height();
if (cnv_w == 0 || cnv_h == 0)
return;
const float inv_cnv_w = 1.0f / cnv_w;
const float inv_cnv_h = 1.0f / cnv_h;
const float height = 2.0f * get_scaled_total_height() * inv_cnv_h;
const float width = 2.0f * get_scaled_total_width() * inv_cnv_w;
const float border_h = 2.0f * m_layout.scaled_border() * inv_cnv_h;
const float border_w = 2.0f * m_layout.scaled_border() * inv_cnv_w;
float top_x = -1.0f;
float top_y = 0.5f * height;
render_background(top_x, top_y, top_x + width, top_y - height, border_w, border_h);
top_x += border_w;
top_y -= border_h;
const float icons_size_x = 2.0f * m_layout.scaled_icons_size() * inv_cnv_w;
const float icons_size_y = 2.0f * m_layout.scaled_icons_size() * inv_cnv_h;
const float stride_y = 2.0f * m_layout.scaled_stride_y() * inv_cnv_h;
const unsigned int icons_texture_id = m_icons_texture.get_id();
const int tex_width = m_icons_texture.get_width();
const int tex_height = m_icons_texture.get_height();
if (icons_texture_id == 0 || tex_width <= 1 || tex_height <= 1)
return;
const float du = (float)(tex_width - 1) / (6.0f * (float)tex_width); // 6 is the number of possible states if the icons
const float dv = (float)(tex_height - 1) / (float)(m_gizmos.size() * tex_height);
// tiles in the texture are spaced by 1 pixel
const float u_offset = 1.0f / (float)tex_width;
const float v_offset = 1.0f / (float)tex_height;
float current_y = FLT_MAX;
for (size_t idx : selectable_idxs) {
GLGizmoBase* gizmo = m_gizmos[idx].get();
const unsigned int sprite_id = gizmo->get_sprite_id();
// higlighted state needs to be decided first so its highlighting in every other state
const int icon_idx = (m_highlight.first == idx ? (m_highlight.second ? 4 : 5) : (m_current == idx) ? 2 : ((m_hover == idx) ? 1 : (gizmo->is_activable() ? 0 : 3)));
const float u_left = u_offset + icon_idx * du;
const float u_right = u_left + du - u_offset;
const float v_top = v_offset + sprite_id * dv;
const float v_bottom = v_top + dv - v_offset;
GLTexture::render_sub_texture(icons_texture_id, top_x, top_x + icons_size_x, top_y - icons_size_y, top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } });
if (idx == m_current || current_y == FLT_MAX) {
// The FLT_MAX trick is here so that even non-selectable but activable
// gizmos are passed some meaningful value.
current_y = 0.5f * cnv_h - 0.5f * top_y * cnv_h;
}
top_y -= stride_y;
}
if (m_current != Undefined)
m_gizmos[m_current]->render_input_window(get_scaled_total_width(), current_y, cnv_h - wxGetApp().plater()->get_view_toolbar().get_height());
}
#else
void GLGizmosManager::do_render_overlay() const void GLGizmosManager::do_render_overlay() const
{ {
std::vector<size_t> selectable_idxs = get_selectable_idxs(); std::vector<size_t> selectable_idxs = get_selectable_idxs();
if (selectable_idxs.empty()) if (selectable_idxs.empty())
return; return;
float cnv_w = (float)m_parent.get_canvas_size().get_width(); const float cnv_w = (float)m_parent.get_canvas_size().get_width();
float cnv_h = (float)m_parent.get_canvas_size().get_height(); const float cnv_h = (float)m_parent.get_canvas_size().get_height();
float zoom = (float)wxGetApp().plater()->get_camera().get_zoom(); const float zoom = (float)wxGetApp().plater()->get_camera().get_zoom();
float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); const float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom();
float height = get_scaled_total_height(); const float height = get_scaled_total_height();
float width = get_scaled_total_width(); const float width = get_scaled_total_width();
float zoomed_border = m_layout.scaled_border() * inv_zoom; const float zoomed_border = m_layout.scaled_border() * inv_zoom;
float zoomed_top_x = (-0.5f * cnv_w) * inv_zoom; float zoomed_top_x = (-0.5f * cnv_w) * inv_zoom;
float zoomed_top_y = (0.5f * height) * inv_zoom; float zoomed_top_y = (0.5f * height) * inv_zoom;
@ -787,36 +975,35 @@ void GLGizmosManager::do_render_overlay() const
zoomed_top_x += zoomed_border; zoomed_top_x += zoomed_border;
zoomed_top_y -= zoomed_border; zoomed_top_y -= zoomed_border;
float icons_size = m_layout.scaled_icons_size(); const float icons_size = m_layout.scaled_icons_size();
float zoomed_icons_size = icons_size * inv_zoom; const float zoomed_icons_size = icons_size * inv_zoom;
float zoomed_stride_y = m_layout.scaled_stride_y() * inv_zoom; const float zoomed_stride_y = m_layout.scaled_stride_y() * inv_zoom;
unsigned int icons_texture_id = m_icons_texture.get_id(); const unsigned int icons_texture_id = m_icons_texture.get_id();
int tex_width = m_icons_texture.get_width(); const int tex_width = m_icons_texture.get_width();
int tex_height = m_icons_texture.get_height(); const int tex_height = m_icons_texture.get_height();
if ((icons_texture_id == 0) || (tex_width <= 1) || (tex_height <= 1)) if (icons_texture_id == 0 || tex_width <= 1 || tex_height <= 1)
return; return;
float du = (float)(tex_width - 1) / (6.0f * (float)tex_width); // 6 is the number of possible states if the icons const float du = (float)(tex_width - 1) / (6.0f * (float)tex_width); // 6 is the number of possible states if the icons
float dv = (float)(tex_height - 1) / (float)(m_gizmos.size() * tex_height); const float dv = (float)(tex_height - 1) / (float)(m_gizmos.size() * tex_height);
// tiles in the texture are spaced by 1 pixel // tiles in the texture are spaced by 1 pixel
float u_offset = 1.0f / (float)tex_width; const float u_offset = 1.0f / (float)tex_width;
float v_offset = 1.0f / (float)tex_height; const float v_offset = 1.0f / (float)tex_height;
float current_y = FLT_MAX; float current_y = FLT_MAX;
for (size_t idx : selectable_idxs) for (size_t idx : selectable_idxs) {
{
GLGizmoBase* gizmo = m_gizmos[idx].get(); GLGizmoBase* gizmo = m_gizmos[idx].get();
unsigned int sprite_id = gizmo->get_sprite_id(); const unsigned int sprite_id = gizmo->get_sprite_id();
// higlighted state needs to be decided first so its highlighting in every other state // higlighted state needs to be decided first so its highlighting in every other state
int icon_idx = (m_highlight.first == idx ? (m_highlight.second ? 4 : 5) : (m_current == idx) ? 2 : ((m_hover == idx) ? 1 : (gizmo->is_activable()? 0 : 3))); const int icon_idx = (m_highlight.first == idx ? (m_highlight.second ? 4 : 5) : (m_current == idx) ? 2 : ((m_hover == idx) ? 1 : (gizmo->is_activable()? 0 : 3)));
float v_top = v_offset + sprite_id * dv; const float u_left = u_offset + icon_idx * du;
float u_left = u_offset + icon_idx * du; const float u_right = u_left + du - u_offset;
float v_bottom = v_top + dv - v_offset; const float v_top = v_offset + sprite_id * dv;
float u_right = u_left + du - u_offset; const float v_bottom = v_top + dv - v_offset;
GLTexture::render_sub_texture(icons_texture_id, zoomed_top_x, zoomed_top_x + zoomed_icons_size, zoomed_top_y - zoomed_icons_size, zoomed_top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } }); GLTexture::render_sub_texture(icons_texture_id, zoomed_top_x, zoomed_top_x + zoomed_icons_size, zoomed_top_y - zoomed_icons_size, zoomed_top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } });
if (idx == m_current || current_y == FLT_MAX) { if (idx == m_current || current_y == FLT_MAX) {
@ -828,10 +1015,11 @@ void GLGizmosManager::do_render_overlay() const
} }
if (m_current != Undefined) { if (m_current != Undefined) {
float toolbar_top = cnv_h - wxGetApp().plater()->get_view_toolbar().get_height(); const float toolbar_top = cnv_h - wxGetApp().plater()->get_view_toolbar().get_height();
m_gizmos[m_current]->render_input_window(width, current_y, toolbar_top); m_gizmos[m_current]->render_input_window(width, current_y, toolbar_top);
} }
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
float GLGizmosManager::get_scaled_total_height() const float GLGizmosManager::get_scaled_total_height() const
{ {
@ -861,14 +1049,12 @@ GLGizmosManager::EType GLGizmosManager::get_gizmo_from_name(const std::string& g
return GLGizmosManager::EType::Undefined; return GLGizmosManager::EType::Undefined;
} }
bool GLGizmosManager::generate_icons_texture() const bool GLGizmosManager::generate_icons_texture()
{ {
std::string path = resources_dir() + "/icons/"; std::string path = resources_dir() + "/icons/";
std::vector<std::string> filenames; std::vector<std::string> filenames;
for (size_t idx=0; idx<m_gizmos.size(); ++idx) for (size_t idx = 0; idx<m_gizmos.size(); ++idx) {
{ if (m_gizmos[idx] != nullptr) {
if (m_gizmos[idx] != nullptr)
{
const std::string& icon_filename = m_gizmos[idx]->get_icon_filename(); const std::string& icon_filename = m_gizmos[idx]->get_icon_filename();
if (!icon_filename.empty()) if (!icon_filename.empty())
filenames.push_back(path + icon_filename); filenames.push_back(path + icon_filename);

View File

@ -34,7 +34,7 @@ public:
Rect() = default; Rect() = default;
Rect(float left, float top, float right, float bottom) : m_left(left) , m_top(top) , m_right(right) , m_bottom(bottom) {} Rect(float left, float top, float right, float bottom) : m_left(left) , m_top(top) , m_right(right) , m_bottom(bottom) {}
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
bool operator == (const Rect& other) const { bool operator == (const Rect& other) const {
if (std::abs(m_left - other.m_left) > EPSILON) return false; if (std::abs(m_left - other.m_left) > EPSILON) return false;
if (std::abs(m_top - other.m_top) > EPSILON) return false; if (std::abs(m_top - other.m_top) > EPSILON) return false;
@ -43,7 +43,7 @@ public:
return true; return true;
} }
bool operator != (const Rect& other) const { return !operator==(other); } bool operator != (const Rect& other) const { return !operator==(other); }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
float get_left() const { return m_left; } float get_left() const { return m_left; }
void set_left(float left) { m_left = left; } void set_left(float left) { m_left = left; }
@ -102,10 +102,14 @@ private:
GLCanvas3D& m_parent; GLCanvas3D& m_parent;
bool m_enabled; bool m_enabled;
std::vector<std::unique_ptr<GLGizmoBase>> m_gizmos; std::vector<std::unique_ptr<GLGizmoBase>> m_gizmos;
mutable GLTexture m_icons_texture; GLTexture m_icons_texture;
mutable bool m_icons_texture_dirty; bool m_icons_texture_dirty;
BackgroundTexture m_background_texture; BackgroundTexture m_background_texture;
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLTexture m_arrow_texture;
#else
BackgroundTexture m_arrow_texture; BackgroundTexture m_arrow_texture;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
Layout m_layout; Layout m_layout;
EType m_current; EType m_current;
EType m_hover; EType m_hover;
@ -133,7 +137,11 @@ public:
bool init(); bool init();
#if ENABLE_GL_SHADERS_ATTRIBUTES
bool init_arrow(const std::string& filename);
#else
bool init_arrow(const BackgroundTexture::Metadata& arrow_texture); bool init_arrow(const BackgroundTexture::Metadata& arrow_texture);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
template<class Archive> template<class Archive>
void load(Archive& ar) void load(Archive& ar)
@ -208,7 +216,7 @@ public:
void render_current_gizmo_for_picking_pass() const; void render_current_gizmo_for_picking_pass() const;
void render_painter_gizmo(); void render_painter_gizmo();
void render_overlay() const; void render_overlay();
void render_arrow(const GLCanvas3D& parent, EType highlighted_type) const; void render_arrow(const GLCanvas3D& parent, EType highlighted_type) const;
@ -234,14 +242,18 @@ private:
bool alt_down = false, bool alt_down = false,
bool control_down = false); bool control_down = false);
#if ENABLE_GL_SHADERS_ATTRIBUTES
void render_background(float left, float top, float right, float bottom, float border_w, float border_h) const;
#else
void render_background(float left, float top, float right, float bottom, float border) const; void render_background(float left, float top, float right, float bottom, float border) const;
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
void do_render_overlay() const; void do_render_overlay() const;
float get_scaled_total_height() const; float get_scaled_total_height() const;
float get_scaled_total_width() const; float get_scaled_total_width() const;
bool generate_icons_texture() const; bool generate_icons_texture();
void update_hover_state(const EType &type); void update_hover_state(const EType &type);
bool grabber_contains_mouse() const; bool grabber_contains_mouse() const;

View File

@ -6,10 +6,13 @@
#include "libslic3r/ClipperUtils.hpp" #include "libslic3r/ClipperUtils.hpp"
#include "libslic3r/Model.hpp" #include "libslic3r/Model.hpp"
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#include "slic3r/GUI/Camera.hpp" #include "slic3r/GUI/Camera.hpp"
#if ENABLE_GL_SHADERS_ATTRIBUTES
#include "slic3r/GUI/Plater.hpp"
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#include <GL/glew.h> #include <GL/glew.h>
@ -74,23 +77,34 @@ void MeshClipper::set_transformation(const Geometry::Transformation& trafo)
} }
} }
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
void MeshClipper::render_cut(const ColorRGBA& color) void MeshClipper::render_cut(const ColorRGBA& color)
#else #else
void MeshClipper::render_cut() void MeshClipper::render_cut()
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
{ {
if (! m_triangles_valid) if (! m_triangles_valid)
recalculate_triangles(); recalculate_triangles();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
if (m_model.vertices_count() == 0 || m_model.indices_count() == 0)
return;
GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); GLShaderProgram* curr_shader = wxGetApp().get_current_shader();
if (curr_shader != nullptr) if (curr_shader != nullptr)
curr_shader->stop_using(); curr_shader->stop_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_model.set_color(color); m_model.set_color(color);
m_model.render(); m_model.render();
shader->stop_using(); shader->stop_using();
@ -101,7 +115,7 @@ void MeshClipper::render_cut()
#else #else
if (m_vertex_array.has_VBOs()) if (m_vertex_array.has_VBOs())
m_vertex_array.render(); m_vertex_array.render();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
@ -218,16 +232,13 @@ void MeshClipper::recalculate_triangles()
tr.pretranslate(0.001 * m_plane.get_normal().normalized()); // to avoid z-fighting tr.pretranslate(0.001 * m_plane.get_normal().normalized()); // to avoid z-fighting
std::vector<Vec2f> triangles2d = m_fill_cut #if ENABLE_LEGACY_OPENGL_REMOVAL
? triangulate_expolygons_2f(expolys, m_trafo.get_matrix().matrix().determinant() < 0.)
: std::vector<Vec2f>();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
m_model.reset(); m_model.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::index_type(triangles2d.size()) }; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 };
init_data.reserve_vertices(triangles2d.size()); init_data.reserve_vertices(m_triangles2d.size());
init_data.reserve_indices(triangles2d.size()); init_data.reserve_indices(m_triangles2d.size());
// vertices + indices // vertices + indices
for (auto it = triangles2d.cbegin(); it != triangles2d.cend(); it = it + 3) { for (auto it = triangles2d.cbegin(); it != triangles2d.cend(); it = it + 3) {
@ -235,10 +246,7 @@ void MeshClipper::recalculate_triangles()
init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 1)).x(), (*(it + 1)).y(), height_mesh)).cast<float>(), (Vec3f)up.cast<float>()); init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 1)).x(), (*(it + 1)).y(), height_mesh)).cast<float>(), (Vec3f)up.cast<float>());
init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 2)).x(), (*(it + 2)).y(), height_mesh)).cast<float>(), (Vec3f)up.cast<float>()); init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 2)).x(), (*(it + 2)).y(), height_mesh)).cast<float>(), (Vec3f)up.cast<float>());
const size_t idx = it - triangles2d.cbegin(); const size_t idx = it - triangles2d.cbegin();
if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) init_data.add_triangle((unsigned int)idx, (unsigned int)idx + 1, (unsigned int)idx + 2);
init_data.add_ushort_triangle((unsigned short)idx, (unsigned short)idx + 1, (unsigned short)idx + 2);
else
init_data.add_uint_triangle((unsigned int)idx, (unsigned int)idx + 1, (unsigned int)idx + 2);
} }
if (!init_data.is_empty()) if (!init_data.is_empty())
@ -253,7 +261,7 @@ void MeshClipper::recalculate_triangles()
m_vertex_array.push_triangle(idx, idx+1, idx+2); m_vertex_array.push_triangle(idx, idx+1, idx+2);
} }
m_vertex_array.finalize_geometry(true); m_vertex_array.finalize_geometry(true);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
triangles2d = {}; triangles2d = {};

View File

@ -7,11 +7,11 @@
#include "libslic3r/SLA/IndexedMesh.hpp" #include "libslic3r/SLA/IndexedMesh.hpp"
#include "admesh/stl.h" #include "admesh/stl.h"
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#include "slic3r/GUI/GLModel.hpp" #include "slic3r/GUI/GLModel.hpp"
#else #else
#include "slic3r/GUI/3DScene.hpp" #include "slic3r/GUI/3DScene.hpp"
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#include <cfloat> #include <cfloat>
@ -102,15 +102,12 @@ public:
// Render the triangulated cut. Transformation matrices should // Render the triangulated cut. Transformation matrices should
// be set in world coords. // be set in world coords.
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void render_cut(const ColorRGBA& color); void render_cut(const ColorRGBA& color);
void render_contour(const ColorRGBA& color); void render_contour(const ColorRGBA& color);
#else #else
void render_cut(); void render_cut();
// Render the triangulated contour. Transformation matrices should #endif // ENABLE_LEGACY_OPENGL_REMOVAL
// be set in world coords.
void render_contour();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
private: private:
void recalculate_triangles(); void recalculate_triangles();
@ -120,13 +117,12 @@ private:
const TriangleMesh* m_negative_mesh = nullptr; const TriangleMesh* m_negative_mesh = nullptr;
ClippingPlane m_plane; ClippingPlane m_plane;
ClippingPlane m_limiting_plane = ClippingPlane::ClipsNothing(); ClippingPlane m_limiting_plane = ClippingPlane::ClipsNothing();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel m_model; GLModel m_model;
GLModel m_model_expanded; GLModel m_model_expanded;
#else #else
GLIndexedVertexArray m_vertex_array; GLIndexedVertexArray m_vertex_array;
GLIndexedVertexArray m_vertex_array_expanded; #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
bool m_triangles_valid = false; bool m_triangles_valid = false;
bool m_fill_cut = true; bool m_fill_cut = true;
double m_contour_width = 0.; double m_contour_width = 0.;

View File

@ -139,6 +139,19 @@ static void add_msg_content(wxWindow* parent, wxBoxSizer* content_sizer, wxStrin
wxFont monospace = wxGetApp().code_font(); wxFont monospace = wxGetApp().code_font();
wxColour text_clr = wxGetApp().get_label_clr_default(); wxColour text_clr = wxGetApp().get_label_clr_default();
wxColour bgr_clr = parent->GetBackgroundColour(); wxColour bgr_clr = parent->GetBackgroundColour();
#ifdef __APPLE__
// On macOS 10.13 and older the background color returned by wxWidgets
// is wrong, which leads to https://github.com/prusa3d/PrusaSlicer/issues/7603
// and https://github.com/prusa3d/PrusaSlicer/issues/3775. wxSYS_COLOUR_WINDOW
// may not match the window background exactly, but it seems to never end up
// as black on black.
if (wxPlatformInfo::Get().GetOSMajorVersion() == 10
&& wxPlatformInfo::Get().GetOSMinorVersion() < 14)
bgr_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
#endif
auto text_clr_str = encode_color(ColorRGB(text_clr.Red(), text_clr.Green(), text_clr.Blue())); auto text_clr_str = encode_color(ColorRGB(text_clr.Red(), text_clr.Green(), text_clr.Blue()));
auto bgr_clr_str = encode_color(ColorRGB(bgr_clr.Red(), bgr_clr.Green(), bgr_clr.Blue())); auto bgr_clr_str = encode_color(ColorRGB(bgr_clr.Red(), bgr_clr.Green(), bgr_clr.Blue()));
const int font_size = font.GetPointSize(); const int font_size = font.GetPointSize();

View File

@ -1260,11 +1260,11 @@ void Selection::render(float scale_factor)
m_scale_factor = scale_factor; m_scale_factor = scale_factor;
// render cumulative bounding box of selected volumes // render cumulative bounding box of selected volumes
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
render_bounding_box(get_bounding_box(), ColorRGB::WHITE()); render_bounding_box(get_bounding_box(), ColorRGB::WHITE());
#else #else
render_selected_volumes(); render_selected_volumes();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
render_synchronized_volumes(); render_synchronized_volumes();
} }
@ -1274,33 +1274,47 @@ void Selection::render_center(bool gizmo_is_dragging)
if (!m_valid || is_empty()) if (!m_valid || is_empty())
return; return;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
shader->start_using(); shader->start_using();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
const Vec3d center = gizmo_is_dragging ? m_cache.dragging_center : get_bounding_box().center(); const Vec3d center = gizmo_is_dragging ? m_cache.dragging_center : get_bounding_box().center();
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
Transform3d view_model_matrix = camera.get_view_matrix() * Geometry::assemble_transform(center);
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(center.x(), center.y(), center.z())); glsafe(::glTranslated(center.x(), center.y(), center.z()));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_vbo_sphere.set_color(ColorRGBA::WHITE()); m_vbo_sphere.set_color(ColorRGBA::WHITE());
#else #else
m_vbo_sphere.set_color(-1, ColorRGBA::WHITE()); m_vbo_sphere.set_color(-1, ColorRGBA::WHITE());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
m_vbo_sphere.render(); m_vbo_sphere.render();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#endif // ENABLE_RENDER_SELECTION_CENTER #endif // ENABLE_RENDER_SELECTION_CENTER
@ -1309,8 +1323,12 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
if (sidebar_field.empty()) if (sidebar_field.empty())
return; return;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader(boost::starts_with(sidebar_field, "layer") ? "flat_attr" : "gouraud_light_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader(boost::starts_with(sidebar_field, "layer") ? "flat" : "gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader(boost::starts_with(sidebar_field, "layer") ? "flat" : "gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
@ -1326,19 +1344,31 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
shader->start_using(); shader->start_using();
glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d base_matrix = Geometry::assemble_transform(get_bounding_box().center());
Transform3d orient_matrix = Transform3d::Identity();
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (!boost::starts_with(sidebar_field, "layer")) { if (!boost::starts_with(sidebar_field, "layer")) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
shader->set_uniform("emission_factor", 0.05f);
#else
const Vec3d& center = get_bounding_box().center(); const Vec3d& center = get_bounding_box().center();
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (is_single_full_instance() && !wxGetApp().obj_manipul()->get_world_coordinates()) { if (is_single_full_instance() && !wxGetApp().obj_manipul()->get_world_coordinates()) {
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glTranslated(center.x(), center.y(), center.z())); glsafe(::glTranslated(center.x(), center.y(), center.z()));
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
if (!boost::starts_with(sidebar_field, "position")) { if (!boost::starts_with(sidebar_field, "position")) {
#if !ENABLE_GL_SHADERS_ATTRIBUTES
Transform3d orient_matrix = Transform3d::Identity(); Transform3d orient_matrix = Transform3d::Identity();
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
if (boost::starts_with(sidebar_field, "scale")) if (boost::starts_with(sidebar_field, "scale"))
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
else if (boost::starts_with(sidebar_field, "rotation")) { else if (boost::starts_with(sidebar_field, "rotation")) {
@ -1346,36 +1376,60 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
else if (boost::ends_with(sidebar_field, "y")) { else if (boost::ends_with(sidebar_field, "y")) {
const Vec3d& rotation = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation(); const Vec3d& rotation = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation();
if (rotation(0) == 0.0) if (rotation.x() == 0.0)
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
else else
orient_matrix.rotate(Eigen::AngleAxisd(rotation(2), Vec3d::UnitZ())); orient_matrix.rotate(Eigen::AngleAxisd(rotation.z(), Vec3d::UnitZ()));
} }
} }
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glMultMatrixd(orient_matrix.data())); glsafe(::glMultMatrixd(orient_matrix.data()));
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
} }
} else if (is_single_volume() || is_single_modifier()) { }
else if (is_single_volume() || is_single_modifier()) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
#else
glsafe(::glTranslated(center.x(), center.y(), center.z())); glsafe(::glTranslated(center.x(), center.y(), center.z()));
Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (!boost::starts_with(sidebar_field, "position")) if (!boost::starts_with(sidebar_field, "position"))
orient_matrix = orient_matrix * (*m_volumes)[*m_list.begin()]->get_volume_transformation().get_matrix(true, false, true, true); orient_matrix = orient_matrix * (*m_volumes)[*m_list.begin()]->get_volume_transformation().get_matrix(true, false, true, true);
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glMultMatrixd(orient_matrix.data())); glsafe(::glMultMatrixd(orient_matrix.data()));
} else { #endif // !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glTranslated(center(0), center(1), center(2))); }
else {
#if ENABLE_GL_SHADERS_ATTRIBUTES
if (requires_local_axes())
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
#else
glsafe(::glTranslated(center.x(), center.y(), center.z()));
if (requires_local_axes()) { if (requires_local_axes()) {
const Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); const Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
glsafe(::glMultMatrixd(orient_matrix.data())); glsafe(::glMultMatrixd(orient_matrix.data()));
} }
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
} }
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
if (!boost::starts_with(sidebar_field, "layer")) if (!boost::starts_with(sidebar_field, "layer"))
glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
if (boost::starts_with(sidebar_field, "position"))
render_sidebar_position_hints(sidebar_field, *shader, base_matrix * orient_matrix);
else if (boost::starts_with(sidebar_field, "rotation"))
render_sidebar_rotation_hints(sidebar_field, *shader, base_matrix * orient_matrix);
else if (boost::starts_with(sidebar_field, "scale") || boost::starts_with(sidebar_field, "size"))
render_sidebar_scale_hints(sidebar_field, *shader, base_matrix * orient_matrix);
else if (boost::starts_with(sidebar_field, "layer"))
render_sidebar_layers_hints(sidebar_field, *shader);
#else
if (boost::starts_with(sidebar_field, "position")) if (boost::starts_with(sidebar_field, "position"))
render_sidebar_position_hints(sidebar_field); render_sidebar_position_hints(sidebar_field);
else if (boost::starts_with(sidebar_field, "rotation")) else if (boost::starts_with(sidebar_field, "rotation"))
@ -1386,16 +1440,17 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
render_sidebar_layers_hints(sidebar_field); render_sidebar_layers_hints(sidebar_field);
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
if (!boost::starts_with(sidebar_field, "layer")) if (!boost::starts_with(sidebar_field, "layer"))
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
} }
bool Selection::requires_local_axes() const bool Selection::requires_local_axes() const
{ {
return (m_mode == Volume) && is_from_single_instance(); return m_mode == Volume && is_from_single_instance();
} }
void Selection::copy_to_clipboard() void Selection::copy_to_clipboard()
@ -1405,8 +1460,7 @@ void Selection::copy_to_clipboard()
m_clipboard.reset(); m_clipboard.reset();
for (const ObjectIdxsToInstanceIdxsMap::value_type& object : m_cache.content) for (const ObjectIdxsToInstanceIdxsMap::value_type& object : m_cache.content) {
{
ModelObject* src_object = m_model->objects[object.first]; ModelObject* src_object = m_model->objects[object.first];
ModelObject* dst_object = m_clipboard.add_object(); ModelObject* dst_object = m_clipboard.add_object();
dst_object->name = src_object->name; dst_object->name = src_object->name;
@ -1419,26 +1473,22 @@ void Selection::copy_to_clipboard()
dst_object->layer_height_profile.assign(src_object->layer_height_profile); dst_object->layer_height_profile.assign(src_object->layer_height_profile);
dst_object->origin_translation = src_object->origin_translation; dst_object->origin_translation = src_object->origin_translation;
for (int i : object.second) for (int i : object.second) {
{
dst_object->add_instance(*src_object->instances[i]); dst_object->add_instance(*src_object->instances[i]);
} }
for (unsigned int i : m_list) for (unsigned int i : m_list) {
{
// Copy the ModelVolumes only for the selected GLVolumes of the 1st selected instance. // Copy the ModelVolumes only for the selected GLVolumes of the 1st selected instance.
const GLVolume* volume = (*m_volumes)[i]; const GLVolume* volume = (*m_volumes)[i];
if ((volume->object_idx() == object.first) && (volume->instance_idx() == *object.second.begin())) if (volume->object_idx() == object.first && volume->instance_idx() == *object.second.begin()) {
{
int volume_idx = volume->volume_idx(); int volume_idx = volume->volume_idx();
if ((0 <= volume_idx) && (volume_idx < (int)src_object->volumes.size())) if (0 <= volume_idx && volume_idx < (int)src_object->volumes.size()) {
{
ModelVolume* src_volume = src_object->volumes[volume_idx]; ModelVolume* src_volume = src_object->volumes[volume_idx];
ModelVolume* dst_volume = dst_object->add_volume(*src_volume); ModelVolume* dst_volume = dst_object->add_volume(*src_volume);
dst_volume->set_new_unique_id(); dst_volume->set_new_unique_id();
} else {
assert(false);
} }
else
assert(false);
} }
} }
} }
@ -1831,22 +1881,22 @@ void Selection::do_remove_object(unsigned int object_idx)
} }
} }
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
void Selection::render_selected_volumes() const void Selection::render_selected_volumes() const
{ {
float color[3] = { 1.0f, 1.0f, 1.0f }; float color[3] = { 1.0f, 1.0f, 1.0f };
render_bounding_box(get_bounding_box(), color); render_bounding_box(get_bounding_box(), color);
} }
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
void Selection::render_synchronized_volumes() void Selection::render_synchronized_volumes()
{ {
if (m_mode == Instance) if (m_mode == Instance)
return; return;
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
float color[3] = { 1.0f, 1.0f, 0.0f }; float color[3] = { 1.0f, 1.0f, 0.0f };
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
for (unsigned int i : m_list) { for (unsigned int i : m_list) {
const GLVolume& volume = *(*m_volumes)[i]; const GLVolume& volume = *(*m_volumes)[i];
@ -1860,16 +1910,16 @@ void Selection::render_synchronized_volumes()
if (v.object_idx() != object_idx || v.volume_idx() != volume_idx) if (v.object_idx() != object_idx || v.volume_idx() != volume_idx)
continue; continue;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
render_bounding_box(v.transformed_convex_hull_bounding_box(), ColorRGB::YELLOW()); render_bounding_box(v.transformed_convex_hull_bounding_box(), ColorRGB::YELLOW());
#else #else
render_bounding_box(v.transformed_convex_hull_bounding_box(), color); render_bounding_box(v.transformed_convex_hull_bounding_box(), color);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
} }
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void Selection::render_bounding_box(const BoundingBoxf3& box, const ColorRGB& color) void Selection::render_bounding_box(const BoundingBoxf3& box, const ColorRGB& color)
{ {
#else #else
@ -1885,9 +1935,9 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
glsafe(::glColor3fv(color)); glsafe(::glColor3fv(color));
glsafe(::glLineWidth(2.0f * m_scale_factor)); glsafe(::glLineWidth(2.0f * m_scale_factor));
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
const BoundingBoxf3& curr_box = m_box.get_bounding_box(); const BoundingBoxf3& curr_box = m_box.get_bounding_box();
if (!m_box.is_initialized() || !is_approx(box.min, curr_box.min) || !is_approx(box.max, curr_box.max)) { if (!m_box.is_initialized() || !is_approx(box.min, curr_box.min) || !is_approx(box.max, curr_box.max)) {
m_box.reset(); m_box.reset();
@ -1897,7 +1947,7 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con
const Vec3f size = 0.2f * box.size().cast<float>(); const Vec3f size = 0.2f * box.size().cast<float>();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(48); init_data.reserve_vertices(48);
init_data.reserve_indices(48); init_data.reserve_indices(48);
@ -1959,8 +2009,8 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con
init_data.add_vertex(Vec3f(b_min.x(), b_max.y(), b_max.z() - size.z())); init_data.add_vertex(Vec3f(b_min.x(), b_max.y(), b_max.z() - size.z()));
// indices // indices
for (unsigned short i = 0; i < 48; ++i) { for (unsigned int i = 0; i < 48; ++i) {
init_data.add_ushort_index(i); init_data.add_index(i);
} }
m_box.init_from(std::move(init_data)); m_box.init_from(std::move(init_data));
@ -1970,11 +2020,20 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con
glsafe(::glLineWidth(2.0f * m_scale_factor)); glsafe(::glLineWidth(2.0f * m_scale_factor));
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_box.set_color(to_rgba(color)); m_box.set_color(to_rgba(color));
m_box.render(); m_box.render();
shader->stop_using(); shader->stop_using();
@ -2014,7 +2073,7 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con
::glVertex3f(b_min(0), b_max(1), b_max(2)); ::glVertex3f(b_min(0), b_max(1), b_max(2) - size(2)); ::glVertex3f(b_min(0), b_max(1), b_max(2)); ::glVertex3f(b_min(0), b_max(1), b_max(2) - size(2));
glsafe(::glEnd()); glsafe(::glEnd());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
static ColorRGBA get_color(Axis axis) static ColorRGBA get_color(Axis axis)
@ -2022,20 +2081,46 @@ static ColorRGBA get_color(Axis axis)
return AXES_COLOR[axis]; return AXES_COLOR[axis];
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void Selection::render_sidebar_position_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix)
#else
void Selection::render_sidebar_position_hints(const std::string& sidebar_field) void Selection::render_sidebar_position_hints(const std::string& sidebar_field)
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d view_matrix = camera.get_view_matrix() * matrix;
shader.set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (boost::ends_with(sidebar_field, "x")) { if (boost::ends_with(sidebar_field, "x")) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d view_model_matrix = view_matrix * Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitZ());
shader.set_uniform("view_model_matrix", view_model_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0)); glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_arrow.set_color(get_color(X)); m_arrow.set_color(get_color(X));
m_arrow.render(); m_arrow.render();
} }
else if (boost::ends_with(sidebar_field, "y")) { else if (boost::ends_with(sidebar_field, "y")) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
shader.set_uniform("view_model_matrix", view_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_arrow.set_color(get_color(Y)); m_arrow.set_color(get_color(Y));
m_arrow.render(); m_arrow.render();
} }
else if (boost::ends_with(sidebar_field, "z")) { else if (boost::ends_with(sidebar_field, "z")) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d view_model_matrix = view_matrix * Geometry::assemble_transform(Vec3d::Zero(), 0.5 * PI * Vec3d::UnitX());
shader.set_uniform("view_model_matrix", view_model_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); glsafe(::glRotated(90.0, 1.0, 0.0, 0.0));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_arrow.set_color(get_color(Z)); m_arrow.set_color(get_color(Z));
m_arrow.render(); m_arrow.render();
} }
@ -2054,31 +2139,68 @@ void Selection::render_sidebar_position_hints(const std::string& sidebar_field)
m_arrow.set_color(-1, get_color(Z)); m_arrow.set_color(-1, get_color(Z));
m_arrow.render(); m_arrow.render();
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix)
#else
void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field) void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field)
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
auto render_sidebar_rotation_hint = [this](GLShaderProgram& shader, const Transform3d& matrix) {
Transform3d view_model_matrix = matrix;
shader.set_uniform("view_model_matrix", view_model_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
m_curved_arrow.render();
view_model_matrix = matrix * Geometry::assemble_transform(Vec3d::Zero(), PI * Vec3d::UnitZ());
shader.set_uniform("view_model_matrix", view_model_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
m_curved_arrow.render();
};
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d view_matrix = camera.get_view_matrix() * matrix;
shader.set_uniform("projection_matrix", camera.get_projection_matrix());
#else
auto render_sidebar_rotation_hint = [this]() { auto render_sidebar_rotation_hint = [this]() {
m_curved_arrow.render(); m_curved_arrow.render();
glsafe(::glRotated(180.0, 0.0, 0.0, 1.0)); glsafe(::glRotated(180.0, 0.0, 0.0, 1.0));
m_curved_arrow.render(); m_curved_arrow.render();
}; };
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (boost::ends_with(sidebar_field, "x")) { if (boost::ends_with(sidebar_field, "x")) {
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glRotated(90.0, 0.0, 1.0, 0.0)); glsafe(::glRotated(90.0, 0.0, 1.0, 0.0));
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
m_curved_arrow.set_color(get_color(X)); m_curved_arrow.set_color(get_color(X));
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_sidebar_rotation_hint(shader, view_matrix * Geometry::assemble_transform(Vec3d::Zero(), 0.5 * PI * Vec3d::UnitY()));
#else
render_sidebar_rotation_hint(); render_sidebar_rotation_hint();
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
} }
else if (boost::ends_with(sidebar_field, "y")) { else if (boost::ends_with(sidebar_field, "y")) {
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0));
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
m_curved_arrow.set_color(get_color(Y)); m_curved_arrow.set_color(get_color(Y));
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_sidebar_rotation_hint(shader, view_matrix * Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitX()));
#else
render_sidebar_rotation_hint(); render_sidebar_rotation_hint();
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
} }
else if (boost::ends_with(sidebar_field, "z")) { else if (boost::ends_with(sidebar_field, "z")) {
m_curved_arrow.set_color(get_color(Z)); m_curved_arrow.set_color(get_color(Z));
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_sidebar_rotation_hint(shader, view_matrix);
#else
render_sidebar_rotation_hint(); render_sidebar_rotation_hint();
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
} }
#else #else
auto render_sidebar_rotation_hint = [this]() { auto render_sidebar_rotation_hint = [this]() {
@ -2101,53 +2223,96 @@ void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field)
m_curved_arrow.set_color(-1, get_color(Z)); m_curved_arrow.set_color(-1, get_color(Z));
render_sidebar_rotation_hint(); render_sidebar_rotation_hint();
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void Selection::render_sidebar_scale_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix)
#else
void Selection::render_sidebar_scale_hints(const std::string& sidebar_field) void Selection::render_sidebar_scale_hints(const std::string& sidebar_field)
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
{ {
bool uniform_scale = requires_uniform_scale() || wxGetApp().obj_manipul()->get_uniform_scaling(); const bool uniform_scale = requires_uniform_scale() || wxGetApp().obj_manipul()->get_uniform_scaling();
#if ENABLE_GL_SHADERS_ATTRIBUTES
auto render_sidebar_scale_hint = [this, uniform_scale](Axis axis, GLShaderProgram& shader, const Transform3d& matrix) {
#else
auto render_sidebar_scale_hint = [this, uniform_scale](Axis axis) { auto render_sidebar_scale_hint = [this, uniform_scale](Axis axis) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GL_SHADERS_ATTRIBUTES
#if ENABLE_LEGACY_OPENGL_REMOVAL
m_arrow.set_color(uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis)); m_arrow.set_color(uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis));
#else #else
m_arrow.set_color(-1, uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis)); m_arrow.set_color(-1, uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis));
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
Transform3d view_model_matrix = matrix * Geometry::assemble_transform(5.0 * Vec3d::UnitY());
shader.set_uniform("view_model_matrix", view_model_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
GLShaderProgram* shader = wxGetApp().get_current_shader(); GLShaderProgram* shader = wxGetApp().get_current_shader();
if (shader != nullptr) if (shader != nullptr)
shader->set_uniform("emission_factor", 0.0f); shader->set_uniform("emission_factor", 0.0f);
glsafe(::glTranslated(0.0, 5.0, 0.0)); glsafe(::glTranslated(0.0, 5.0, 0.0));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_arrow.render(); m_arrow.render();
#if ENABLE_GL_SHADERS_ATTRIBUTES
view_model_matrix = matrix * Geometry::assemble_transform(-5.0 * Vec3d::UnitY(), PI * Vec3d::UnitZ());
shader.set_uniform("view_model_matrix", view_model_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glTranslated(0.0, -10.0, 0.0)); glsafe(::glTranslated(0.0, -10.0, 0.0));
glsafe(::glRotated(180.0, 0.0, 0.0, 1.0)); glsafe(::glRotated(180.0, 0.0, 0.0, 1.0));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_arrow.render(); m_arrow.render();
}; };
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d view_matrix = camera.get_view_matrix() * matrix;
shader.set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (boost::ends_with(sidebar_field, "x") || uniform_scale) { if (boost::ends_with(sidebar_field, "x") || uniform_scale) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_sidebar_scale_hint(X, shader, view_matrix * Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitZ()));
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0)); glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0));
render_sidebar_scale_hint(X); render_sidebar_scale_hint(X);
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
} }
if (boost::ends_with(sidebar_field, "y") || uniform_scale) { if (boost::ends_with(sidebar_field, "y") || uniform_scale) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_sidebar_scale_hint(Y, shader, view_matrix);
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
render_sidebar_scale_hint(Y); render_sidebar_scale_hint(Y);
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
} }
if (boost::ends_with(sidebar_field, "z") || uniform_scale) { if (boost::ends_with(sidebar_field, "z") || uniform_scale) {
#if ENABLE_GL_SHADERS_ATTRIBUTES
render_sidebar_scale_hint(Z, shader, view_matrix * Geometry::assemble_transform(Vec3d::Zero(), 0.5 * PI * Vec3d::UnitX()));
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); glsafe(::glRotated(90.0, 1.0, 0.0, 0.0));
render_sidebar_scale_hint(Z); render_sidebar_scale_hint(Z);
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
} }
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
void Selection::render_sidebar_layers_hints(const std::string& sidebar_field, GLShaderProgram& shader)
#else
void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) void Selection::render_sidebar_layers_hints(const std::string& sidebar_field)
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
{ {
static const float Margin = 10.0f; static const float Margin = 10.0f;
@ -2178,35 +2343,35 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field)
const BoundingBoxf3& box = get_bounding_box(); const BoundingBoxf3& box = get_bounding_box();
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
const float min_x = float(box.min.x()) - Margin; const float min_x = float(box.min.x()) - Margin;
const float max_x = float(box.max.x()) + Margin; const float max_x = float(box.max.x()) + Margin;
const float min_y = float(box.min.y()) - Margin; const float min_y = float(box.min.y()) - Margin;
const float max_y = float(box.max.y()) + Margin; const float max_y = float(box.max.y()) + Margin;
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
// view dependend order of rendering to keep correct transparency // view dependend order of rendering to keep correct transparency
const bool camera_on_top = wxGetApp().plater()->get_camera().is_looking_downward(); const bool camera_on_top = wxGetApp().plater()->get_camera().is_looking_downward();
const float z1 = camera_on_top ? min_z : max_z; const float z1 = camera_on_top ? min_z : max_z;
const float z2 = camera_on_top ? max_z : min_z; const float z2 = camera_on_top ? max_z : min_z;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
const Vec3f p1 = { float(box.min.x()) - Margin, float(box.min.y()) - Margin, z1 }; const Vec3f p1 = { float(box.min.x()) - Margin, float(box.min.y()) - Margin, z1 };
const Vec3f p2 = { float(box.max.x()) + Margin, float(box.max.y()) + Margin, z2 }; const Vec3f p2 = { float(box.max.x()) + Margin, float(box.max.y()) + Margin, z2 };
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
glsafe(::glDisable(GL_CULL_FACE)); glsafe(::glDisable(GL_CULL_FACE));
glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
if (!m_planes.models[0].is_initialized() || !is_approx(m_planes.check_points[0], p1)) { if (!m_planes.models[0].is_initialized() || !is_approx(m_planes.check_points[0], p1)) {
m_planes.check_points[0] = p1; m_planes.check_points[0] = p1;
m_planes.models[0].reset(); m_planes.models[0].reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(4); init_data.reserve_vertices(4);
init_data.reserve_indices(6); init_data.reserve_indices(6);
@ -2217,8 +2382,8 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field)
init_data.add_vertex(Vec3f(p1.x(), p2.y(), z1)); init_data.add_vertex(Vec3f(p1.x(), p2.y(), z1));
// indices // indices
init_data.add_ushort_triangle(0, 1, 2); init_data.add_triangle(0, 1, 2);
init_data.add_ushort_triangle(2, 3, 0); init_data.add_triangle(2, 3, 0);
m_planes.models[0].init_from(std::move(init_data)); m_planes.models[0].init_from(std::move(init_data));
} }
@ -2228,7 +2393,7 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field)
m_planes.models[1].reset(); m_planes.models[1].reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 };
init_data.reserve_vertices(4); init_data.reserve_vertices(4);
init_data.reserve_indices(6); init_data.reserve_indices(6);
@ -2239,12 +2404,18 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field)
init_data.add_vertex(Vec3f(p1.x(), p2.y(), z2)); init_data.add_vertex(Vec3f(p1.x(), p2.y(), z2));
// indices // indices
init_data.add_ushort_triangle(0, 1, 2); init_data.add_triangle(0, 1, 2);
init_data.add_ushort_triangle(2, 3, 0); init_data.add_triangle(2, 3, 0);
m_planes.models[1].init_from(std::move(init_data)); m_planes.models[1].init_from(std::move(init_data));
} }
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader.set_uniform("view_model_matrix", camera.get_view_matrix());
shader.set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_planes.models[0].set_color((camera_on_top && type == 1) || (!camera_on_top && type == 2) ? SOLID_PLANE_COLOR : TRANSPARENT_PLANE_COLOR); m_planes.models[0].set_color((camera_on_top && type == 1) || (!camera_on_top && type == 2) ? SOLID_PLANE_COLOR : TRANSPARENT_PLANE_COLOR);
m_planes.models[0].render(); m_planes.models[0].render();
m_planes.models[1].set_color((camera_on_top && type == 2) || (!camera_on_top && type == 1) ? SOLID_PLANE_COLOR : TRANSPARENT_PLANE_COLOR); m_planes.models[1].set_color((camera_on_top && type == 2) || (!camera_on_top && type == 1) ? SOLID_PLANE_COLOR : TRANSPARENT_PLANE_COLOR);
@ -2265,7 +2436,7 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field)
::glVertex3f(max_x, max_y, z2); ::glVertex3f(max_x, max_y, z2);
::glVertex3f(min_x, max_y, z2); ::glVertex3f(min_x, max_y, z2);
glsafe(::glEnd()); glsafe(::glEnd());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glEnable(GL_CULL_FACE)); glsafe(::glEnable(GL_CULL_FACE));
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));

View File

@ -218,7 +218,7 @@ private:
GLModel m_arrow; GLModel m_arrow;
GLModel m_curved_arrow; GLModel m_curved_arrow;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLModel m_box; GLModel m_box;
struct Planes struct Planes
{ {
@ -226,7 +226,7 @@ private:
std::array<GLModel, 2> models; std::array<GLModel, 2> models;
}; };
Planes m_planes; Planes m_planes;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
float m_scale_factor; float m_scale_factor;
@ -370,16 +370,23 @@ private:
void do_remove_object(unsigned int object_idx); void do_remove_object(unsigned int object_idx);
void set_bounding_boxes_dirty() { m_bounding_box.reset(); m_unscaled_instance_bounding_box.reset(); m_scaled_instance_bounding_box.reset(); } void set_bounding_boxes_dirty() { m_bounding_box.reset(); m_unscaled_instance_bounding_box.reset(); m_scaled_instance_bounding_box.reset(); }
void render_synchronized_volumes(); void render_synchronized_volumes();
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void render_bounding_box(const BoundingBoxf3& box, const ColorRGB& color); void render_bounding_box(const BoundingBoxf3& box, const ColorRGB& color);
#else #else
void render_selected_volumes() const; void render_selected_volumes() const;
void render_bounding_box(const BoundingBoxf3& box, float* color) const; void render_bounding_box(const BoundingBoxf3& box, float* color) const;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
void render_sidebar_position_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix);
void render_sidebar_rotation_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix);
void render_sidebar_scale_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix);
void render_sidebar_layers_hints(const std::string& sidebar_field, GLShaderProgram& shader);
#else
void render_sidebar_position_hints(const std::string& sidebar_field); void render_sidebar_position_hints(const std::string& sidebar_field);
void render_sidebar_rotation_hints(const std::string& sidebar_field); void render_sidebar_rotation_hints(const std::string& sidebar_field);
void render_sidebar_scale_hints(const std::string& sidebar_field); void render_sidebar_scale_hints(const std::string& sidebar_field);
void render_sidebar_layers_hints(const std::string& sidebar_field); void render_sidebar_layers_hints(const std::string& sidebar_field);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
public: public:
enum SyncRotationType { enum SyncRotationType {

View File

@ -21,9 +21,9 @@
#include <libslic3r/ObjectID.hpp> #include <libslic3r/ObjectID.hpp>
#include <libslic3r/Utils.hpp> #include <libslic3r/Utils.hpp>
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#include "slic3r/GUI/3DScene.hpp" #include "slic3r/GUI/3DScene.hpp"
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#include <boost/foreach.hpp> #include <boost/foreach.hpp>