-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiplatform? #6
Comments
With pleasure, however JitPack is enough for me at the moment I know Bintray and Maven require going throw so much pain that makes me giving up. But if you want to try, you are very welcome.. I sent you an invite :) |
Ah sweet, I'll give it a try. I also just noticed it has a dependency on |
There is another problem you have to solve first. I think the way we handle native memory is dependent on lwjgl or at least dependent on |
Well, I just did a search for How much do you care about breaking changes? |
I personally don't care. If we go multiplatform |
Oh man, I lost the reply mail.. anyway @Dominaezzz, the limitation with the stdlib unsigned is that they dont extend Extending We may discuss if this is actually useful also for unsigned.. maybe we could switch to stdlib unsigned and make unsigned vectors somehow special compared to the others. Regarding breaking changes, I personally repute that if the change makes sense, then we should just go for it Although I'd pay attention for any regression performance-wise |
any news, @Dominaezzz ? |
I made a branch with some changes. Have you looked at it? |
The current code is a bit of a tangle of interfaces, which is quite bothersome to make multiplatform. Would be easier to wait for |
Yep, they are only confined to gradle or?
I'm totally available to change the current structure if it makes sense. By |
Yes, the new revamped kotlinx-io. It should be released sometime around Kotlin 1.4 release. Oh, maybe I didn't push. Also, dependencies would also need to be made multiplatform. unsigned won't work well with Kotlin native, there would be a fair bit of copying involved. It's a bit of work. |
Where is possible to read something about that?
What would you do then? Top functions inside the
Problem with the stdlib unsigned is that they do not extend the We could keep unsigned a jvm-only dep |
The most official thing I can point to is the Kotlin
You would need to make a lot of the member functions into extension functions or top-level functions. This would make the library not very nice to use from Java.
I understand the need for this but using |
No other ways? Otherwise we can theoretical have the top level functions as the real multiplatform core and the jvm interfaces would just point to those (maybe inlined)
Ok, let's start with the projection matrix functions, if you can prepare the structure and point me to the right location I'll move a couple of those
Yeah, but the convenience is huge. Otherwise we shall write a lot of boilerplate code (or auto-generate) |
Hi @Dominaezzz, still interested in this? From my side there is plenty of availability I've been notified of some rising interest into multiplatform libraries for images and fonts (@Sylvyrfysh). I'd love to merge all the spare efforts in an unique one.
We can skip unsigned for the moment and postpone any decision/evaluation for later
What is preferred among the two? We can always add an additional layer/wrapper explicitely for Java to make it play nicely with it
We can start by the What do you think? |
I think extension functions. (Might have to be on a case by case basis).
We could start there, after pulling out
I am but I'm not available to do the work on it. |
Ok, then extension functions be
Fine, but I have no idea where to start from
It's ok, I can do the part about writing the mathematical code (methods, classes and so on), but I have no experience in native/MP, that's your knowledge I guess Could you take care of the project structure? I just deleted everything in the |
What backends do you want, @Dominaezzz ? The code I've started working with is aimed at everything, do you also want everything or is a subset what you want? |
Everything really, I don't expect this to require anything platform specific. |
I gave it a refresh, @Dominaezzz I started with the gradle build file, moved to kotlin script, followed the tutorial on the website removed the I have some problems understanding how to distinguish common code from the jvm specific one and how to set that in gradle if you could help on that, it'd be great |
Reading through the thread and seeing what I can do to help. Some thoughts:
|
We can forget about Java for the moment. If you need the methods as extension function, this is no problem at all. However I can see a solution to that. We can define all our methods as extension functions as Dominic suggested and then I'll add an additional wrapper exclusively for the jvm, to make it play nice with Java (at least the core functions, already today there are stuff, like custom vector swizzle, which is basically kotlin-only). My final goal is to have a library which helps with 3d real time graphics. Having something resembling the standard de-facto library on C/C++ world is a huge adavantage.
The advantage of an unsigned extending But again, this is not a strict requirement
I'll send you an invitation :) |
That's a good approach, I think
Definitely.
As Dominic mentioned above, using generics actually causes automatic boxing (ie, the storage type of Vec3 and Mat4 will end up being Object on the JVM, and possibly elsewhere). In order to avoid that we'd actually have to define the various vector and matrix types separately, and depending on how many there are, it might be best to do that through code generation using something like kotlinpoet. That would eliminate the need for the I'll take a look what I can do about the Multiplatform build |
Yep, that would do eliminate it However it might be worth starting small with a manual writing of some classes and see how it plays on different platform before trying to scale up and use kotlinpoet (are you familiar with it though?) |
definitely. yeah I've used Kotlin poet before with the kgl implementation, but I have to admit it's a pain to use codegen in general, but it's also a pain to have to write everything manually. |
Yeah, which platform(s) in particular are you interested in? |
I'm personally working with Kotlin/Native (Linux, macOS, and Windows), but with common code, it's trivial to run on any platform. |
@elect86 what was the reason for choosing |
Clashes with the |
So going through the code after removing the lwjgl dependency, a multiplatform port would basically require starting over from scratch. Every data type is written with memory management in mind, which is something that's platform-specific and should either be omitted, or offloaded to a platform-specific module (eg |
@elect86 Because of how templates work in C++, I've set up the basic structure for codegen in the multiplatform branch and put in a basic Vec2 class generation. I haven't touched the travis or jitpack files, but they'll likely need to be updated or replaced for multiplatform CI (I'm not very knowledgable about that) |
Generation code looks pretty clear and logic, I like it
are vecs and mats backed by primitive arrays fine in native?
I can handle those later Shall we offload to code generation also Extension function means something like, for example:
Is this ok for you, guys? |
They are preferable. primitive arrays can be pinned and sent to C functions as pointers, which basically every C function expects in some way. Exposing the inner storage through an
In terms of types, glm actually defines only Float, Double, Boolean, Int, and UInt vectors, and many functions are specific to floating point types. That should be reflected in the API for this library. The goal should be feature parity, but in a Kotlinic way, with as much API mirroring as reasonable. It's also a question whether the Kotlin port needs to keep the extremely short type names, since they're not kotlinic at all. I would propose using FloatVec2, IntVec2, etc, FloatMat3, FloatMat3x2, FloatMat4, etc as a compromise between conciseness and clarity. EDIT: On a related note, while many collection types in Kotlin have mutable and immutable variants, vectors work much like arrays, which even in Kotlin are always mutable. |
Excellent, this is what I like as well
Ok
It makes sense
Maybe Float2, Int2 for vectors? This wouldn't however work very well with matrices, although I never saw the needs beyond floating point types..
we may use view interfaces, that would allow the values to be simply retrieved |
Float2, Int2, etc are established ways to name vectors in the industry (cf DirectX and Metal), but doesn't fit with GLM, which uses the EDIT: Matrices would be named as
What I'm saying is that I don't think we need immutable types since vectors are basically fixed-length arrays with linear algebra logic built in, so I don't think view interfaces are necessary either. |
We can start then like that.
ok Do you happen to know how to generate methods comments? |
So there's an |
|
|
|
It is currently possible to do this actually. We can write a Kotlin compiler plugin to convert generic types to multiple specific types. class Vector2<T>(val x: T, val y: T, val z: T)
@Reify
typealias Vector2f = Vector2<Float>
@Reify
typealias Vector2d = Vector2<Double> after building with our Reification plugin,
Example of compiler plugin in action -> kotlin-power-assert |
That is fascinating... I'm not sure what it would look like to try and implement functions that can take a different generic type than the class though. for example: fun <T, U> Vector2<T>.plus(scalar: U): Vector2<T> Perhaps a parameter on the Reifiy annotation? I feel like in many ways this would make coding easier, but I'm not sure if it's a rabbit hole worth going down 🤔 And then there'd need to be an option for the compiler to remove the generic version entirely (or perhaps a sealed class hierarchy is able to achieve what's needed there) |
Lots of interesting discussions here. Just wondering if any thoughts have been put into, rather than doing a major reworking of the entire library for Multiplatform use, doing it piece by piece and start with simply splitting the interfaces into basic ones and more full featured (JVM-only ones)? So that for any ones that currently include JVM-specific functionality they each extend a second I would be perfectly fine having some of the ByteBuffer, InputStream functions etc be JVM only to begin with. Then platform specific implementations could be added over time to bring the full multiplatform library up to par with the JVM-only parts? |
@nlbuescher started writing down something for code generation, I also wrote something in this direction, especially on the DSL side, but I don't have much time. Also I wonder if the approach you mention makes actually more sense at the very moment.
Yeah, I totally agree with I'd send you an invitation in case you are interested in some contributions |
Hi all, also currently trying to use this in a multiplatform project, but one that has only JVM and common platforms. One thing I've been experimenting with is similar to what This will only work for JVM platforms, but it can be extended to add support for native platforms down the line For my purposes, this is ideal, as the common code using these matrixes doesn't need any of the java dependant features |
A note: I'm experimenting using the stdlib unsigned for the moment |
First multiplatform test (jvm + linux) passing |
I did a bit of work on this one, you might want to take a look at it: https://github.com/ArcheCraft/glm/tree/mp |
nice @ArcheCraft , don't hesitate to PR so we don't duplicate efforts Also, I can add you as a collaborator (just sent) |
I'd like to gather some feedbacks for the It needs still some functions, but most of core is already there |
I'll check it out when I get home from work |
One little thing that still needs to be manually executed is the Gradle task |
ok, so |
Vulkan is a bit complicated in this regard since the only way you can write to a uniform is by mapping memory. There's push constants but those take values and not pointers to values. OpenGL on native would just take a |
I am trying to build
|
@dmitrykolesnikovich, are you on Windows, aren't you? That's case insensitive and the generation won't work, I'm gonna rename those methods sooner or later |
Yes i'm using windows. |
I want to use this library in a multiplatform application.
Since the bulk of this library is written in pure Kotlin, going multiplatform would be fairly trivial.
The only possible issue I can think of is that JitPack may not work with it, breaking current users.
Would need to setup build for all platforms to publish to Bintray or Maven central.
The text was updated successfully, but these errors were encountered: