NativeScript and WebGL - how to do it


#1

Hello everyone, I have a question regarding NativeScript and OpenGL
We have an angular application with webGL stuff, that we want to port to mobile, but I’m not sure how to handle webgl with nativeScript
We write raw webgl so there is almost a perfect mapping between our webgl calls and native opengl ES calls.
I understand nativeScript does not convert webgl calls to native calls so we will have to do it ourselves and that’s not a problem, but I’m trying to understand how this fits conceptually in the “nativeScript way”.
Do we have to write some sort of native openGL plugin that would interface with nativeScript?

I’m trying to understand the target architecture

thanks

all the best

fruty


#2

btw here is our angular application we want to port to mobile with nativeScript:
https://viewer.exospacehq.com/

(currently it’s angular1 but we are porting it to angular2 before making the move with nativeScript)


#3

You don’t have to write a plugin so to speak. You can communicate with the native APIs directly in your js code, for Android: https://developer.android.com/guide/topics/graphics/opengl.html I haven’t used OpenGL myself so I don’t have direct experience with the API but hopefully knowing you don’t need a “plugin” helps. However, the benefit of wrapping into a plugin is then in your code base you use the plugins api that you create in your code so you don’t have to write platform checks before calling the different native apis. Hope that makes some sense :slight_smile:


#4

many thanks for your answer, if I understand correctly, from nativeScript we can simply call the native platform graphics API directly?
If yes that’s awesome


#5

no guarantees the openGL will work from my word :slight_smile: but yes, you can call native apis direct. It’s the greatest thing in the world :thumbsup:. That is how all of the plugins and the core work. For example: https://github.com/bradmartin/nativescript-snackbar/blob/master/snackbar.android.ts#L28 this is a plugin I worked on and just called the Android snackbar. If this wasn’t in a plugin and I had the android library pulled into my app, you could do the same in your app code. Like var snackBar = .... just the same.