-
Notifications
You must be signed in to change notification settings - Fork 4
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
Added Packed_*_Array support #10
base: master
Are you sure you want to change the base?
Conversation
lmao forgot to commit this
TYPE_PACKED_VECTOR2_ARRAY: | ||
arr.append_array(vec2_array_to_byte_array(data[data_index])) | ||
TYPE_VECTOR2I: | ||
arr.append_array(vec2i_to_byte_array(data[data_index])) |
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.
TYPE_VECTOR2I
and TYPE_VECTOR2
require different alignments when inside a struct. Like with arrays, alignments for struct members are rounded up to the alignment of a vec4
. So for these two types, we'll need separate functions to get the byte arrays with the extra padding (+2 components).
|
||
# We have to add a value for the "z" field for the vector, | ||
# because the alignment spec for GLSL vec2s requires 16bytes | ||
return PackedInt32Array([vector.x, vector.y, 0]).to_byte_array() |
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.
The component in the Z
position here is not necessary. vec2
s in GLSL only need the x
and y
elements. As opposed to vec3
s, which are treated as 4-component vectors by GLSL.
|
||
|
||
var float_arr = PackedFloat32Array([vec.x, vec.y]).to_byte_array() | ||
bytes.append_array(float_arr) |
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.
Vectors that are inside arrays in GLSL have their alignment rounded up to a multiple of 4 of the base alignment of its elements. So here, where we define float_arr
, we would add two more components to the array to fill out the rest of the array element's space inside the array.
var arr: PackedVector2Array = PackedVector2Array() | ||
|
||
for v in range((16 + bytes.size()) / 16.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.
Since the alignment of the elements in the array are rounded up to the alignment of a vec4
, we can treat this array the same as we treat it in byte_array_to_vec3_array()
, with an array stride of 16 bytes. It would essentially look just like byte_array_to_vec3_array()
, we just build an array of Vector2
s instead.
Got around to testing your changes today, and commented some places that need a little work. Some of the alignments were off, which was mostly the issue. Nothing too crazy to fix though. |
Added array support inside Structs, for encoding/decoding structs correctly.