-
Notifications
You must be signed in to change notification settings - Fork 13
Support uniform float/int arrays #15
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
Conversation
@gergelydaniel if this looks good, a new release including it would be awesome. |
|
||
override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) = gl.glUniform3f(location, x, y, z) | ||
|
||
override fun uniform3fv(location: UniformLocation, value: FloatArray) = gl.glUniform3fv(location, 1, value, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right. Based on my understanding, count
is supposed to be the number of typed elements to assign, not the number of primitives. For example, in uniform3fv
, if the count
is 2, then OpenGL is about to update 2 instances of vec3f (6 floats in total), and not just two floats.
I believe the best options we can consider with uniform*v
calls is to:
A) Expose the count
parameter through Kgl functions
B) Hide the count
parameter in Kgl, and calculate it automatically. For example, for uniform3fv
it should be value.size / 3
It seems that WebGL1 doesn't support the count
parameterer, so with WebGL1 only the B) option is possible, however WebGL2 uniform*v
calls do have the srcOffset
and srcLength
parameters, which makes option A) possible
So moving forward, regarding to this PR I'd suggest going with option B) (both for existing and new *fv functions) as it offers WebGL1 compatibility, and option A) can be implemented later at any time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gergelydaniel, I made the change you describe in B), thanks for catching that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the updates, I still found some things before I could merge:
- For the sake of consistency, please apply the count calculation on all targets where it's not done automatically (besides JOGL: Android, iOS)
- JOGL matrix functions seem to be broken
If these are fixed I can do a round of testing, then merge it, as well as publish a new release soon
|
||
override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: FloatArray) = | ||
gl.glUniformMatrix3fv(location, 1, transpose, value, 0) | ||
gl.glUniformMatrix3fv(location, value.size, transpose, value, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gl.glUniformMatrix3fv(location, value.size, transpose, value, 0) | |
gl.glUniformMatrix3fv(location, value.size / 9, transpose, value, 0) |
|
||
override fun uniformMatrix4fv(location: UniformLocation, transpose: Boolean, value: FloatArray) = | ||
gl.glUniformMatrix4fv(location, 1, transpose, value, 0) | ||
gl.glUniformMatrix4fv(location, value.size, transpose, value, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gl.glUniformMatrix4fv(location, value.size, transpose, value, 0) | |
gl.glUniformMatrix4fv(location, value.size / 16, transpose, value, 0) |
override fun uniform1iv(location: UniformLocation, value: IntArray) = GL.glUniform1iv(location, 1, value, 0) | ||
|
||
override fun uniform2f(location: UniformLocation, x: Float, y: Float) = GL.glUniform2f(location, x, y) | ||
override fun uniform2fv(location: UniformLocation, value: FloatArray) = GL.glUniform2fv(location, 1, value, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we are about to do that manually on JOGL, and WebGL and LWJGL does that automatically, we should do the division thing manually on Android and iOS as well. (including matrices)
override fun uniform2fv(location: UniformLocation, value: FloatArray) = GL.glUniform2fv(location, 1, value, 0) | |
override fun uniform2fv(location: UniformLocation, value: FloatArray) = GL.glUniform2fv(location, value.size / 2, value, 0) |
Thanks @gergelydaniel! I added a check that the array sizes make sense as well. |
@@ -0,0 +1,13 @@ | |||
package com.danielgergely.kgl | |||
|
|||
public fun FloatArray.vSize(vecSize: Int): Int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't make these internal
(I guess because kotlin modules don't cross platform boundaries) so unfortunately this would become part of the kgl public API. I can make them private on each platform if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, unfortunately these would be annoying to have shown up in the IDE for float and int arrays in projects that I use KGL in. The "correct" way would probably be to create a separate Gradle module (eg named kgl-utils
), and have the functions as public there, and import that Gradle module with implementation
so it wouldn't be exposed.
It is also fine for now to just have these copied for jogl, android, ios, but I'd like to keep the public API clean
lmk how this looks, would love to pull this in soon if possible to enable some nifty features for our mutant vehicle at burningman this year :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply and the nitpicking :D the function should be cleaned up from the API, but otherwise looks good!
@@ -0,0 +1,13 @@ | |||
package com.danielgergely.kgl | |||
|
|||
public fun FloatArray.vSize(vecSize: Int): Int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, unfortunately these would be annoying to have shown up in the IDE for float and int arrays in projects that I use KGL in. The "correct" way would probably be to create a separate Gradle module (eg named kgl-utils
), and have the functions as public there, and import that Gradle module with implementation
so it wouldn't be exposed.
It is also fine for now to just have these copied for jogl, android, ios, but I'd like to keep the public API clean
No problem, moved to the respective modules. Thanks! |
@gergelydaniel Bump |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, thank you!
Note that this is present in the new release |
Thanks so much @gergelydaniel, much appreciated! |
uniform[1234][fi]v()
.