[Feature Request] Translating JavaScript classes to GLSL
- Vorherrschende Sprache
- JavaScript
- Sterne
- 15.5k
- Forks
- 663
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
I recently discovered a simple way to translate JavaScript classes into GLSL., but I'm not sure if gpu.js can do this yet. This is a JavaScript class:
```
class Circle{
constructor(radius){
this.radius = 1;
}
area(){
return Math.PI*this.radius*this.radius;
}
}
```
In GLSL, the same class could be defined in this way:
```
#define PI 3.1415926538
struct Circle{
float radius;
};
Circle new(float radius){
Circle self; //"this" is a reserved word in GLSL, so "self" is used here instead
self.radius = 1.0;
return self;
}
float area(Circle self){
return PI*self.radius*self.radius;
}
```
And then an "instance" of the class can be initialized:
```
Circle anInstance = new(3.0);
float the_area = area(anInstance);
```
Since functions in GLSL can be overloaded, it would be possible to define constructors for multiple "classes" in this way.
Beitragsleitfaden
Rechercherichtung
Es werden keine Dateien, Tests oder Einstiegspunkte genannt. Beginne damit, die aktuelle Unterstützung von gpu.js für die Übersetzung von JavaScript in GLSL zu finden, und ermittle, ob Klassensyntax, Konstruktoren, Methoden und Instanzen abgedeckt sind. Als abgeschlossen gilt die Aufgabe, wenn ein abgestimmtes Design und eine funktionierende Übersetzung für das Klassenbeispiel sowie eine entsprechende GLSL-Ausgabe vorliegen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- computer-graphics
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100