Skip to content

Conversation

xian
Copy link
Contributor

@xian xian commented Jul 24, 2023

  • Add uniform[1234][fi]v().
  • Fixes apparent bug in JOGL uniform array support.

@xian
Copy link
Contributor Author

xian commented Jul 24, 2023

@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)
Copy link
Owner

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

Copy link
Contributor Author

@xian xian Aug 1, 2023

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!

@xian xian requested a review from gergelydaniel August 1, 2023 04:53
Copy link
Owner

@gergelydaniel gergelydaniel left a 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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Owner

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)

Suggested change
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)

@xian xian requested a review from gergelydaniel August 1, 2023 16:46
@xian
Copy link
Contributor Author

xian commented Aug 1, 2023

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 {
Copy link
Contributor Author

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.

Copy link
Owner

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

@xian
Copy link
Contributor Author

xian commented Aug 4, 2023

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 :-)

Copy link
Owner

@gergelydaniel gergelydaniel left a 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 {
Copy link
Owner

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

@xian
Copy link
Contributor Author

xian commented Aug 15, 2023

No problem, moved to the respective modules. Thanks!

@xian xian requested a review from gergelydaniel August 15, 2023 23:36
@xian
Copy link
Contributor Author

xian commented Aug 19, 2023

@gergelydaniel Bump

Copy link
Owner

@gergelydaniel gergelydaniel left a 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!

@gergelydaniel gergelydaniel merged commit 8ffc18d into gergelydaniel:main Aug 19, 2023
@gergelydaniel
Copy link
Owner

Note that this is present in the new release 0.6.2

@xian
Copy link
Contributor Author

xian commented Aug 20, 2023

Thanks so much @gergelydaniel, much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants