Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit 2860aa0

Browse files
committed
Document and clean up Java code
1 parent 3e0fcc1 commit 2860aa0

22 files changed

+1124
-340
lines changed

example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/GPUDriverGL.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@
4848
import java.io.InputStreamReader;
4949
import java.nio.ByteBuffer;
5050
import java.nio.charset.StandardCharsets;
51-
import java.util.HashMap;
52-
import java.util.LinkedList;
53-
import java.util.List;
54-
import java.util.Map;
51+
import java.util.*;
5552
import java.util.stream.Collectors;
5653

5754
import static org.lwjgl.glfw.GLFW.*;
@@ -866,12 +863,10 @@ public void destroyGeometry(long geometryId) {
866863
}
867864

868865
@Override
869-
public void updateCommandList(UltralightCommandList list) {
866+
public void updateCommandList(UltralightCommand[] list) {
870867
CHECK_GL();
871-
if (list.data.length != 0) {
872-
for (UltralightCommand datum : list.data) {
873-
this.commands.add(datum);
874-
}
868+
if (list.length != 0) {
869+
Collections.addAll(this.commands, list);
875870
}
876871
CHECK_GL();
877872
}

example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/support/WebController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void render() {
170170

171171
long text = this.view.renderTarget().textureId;
172172
long buffer = this.view.renderTarget().renderBufferId;
173-
float[] uv = this.view.renderTarget().uv_coords;
173+
float[] uv = this.view.renderTarget().uvCoords;
174174
int width = (int) view.width();
175175
int height = (int) view.height();
176176
glClearColor(0,0,0,1);

ultralight-java-base/src/main/java/com/labymedia/ultralight/math/UltralightMatrix.java

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,51 @@
2424
import com.labymedia.ultralight.ffi.ObjectWithHandle;
2525
import com.labymedia.ultralight.ffi.gc.DeletableObject;
2626

27+
/**
28+
* Transformation Matrix helper.
29+
*/
2730
@NativeType("ultralight::Matrix")
2831
public class UltralightMatrix implements ObjectWithHandle {
2932
private final DeletableObject<Long> handle;
3033

34+
/**
35+
* Constructs a new {@link UltralightMatrix} and begins tracking the underlying handle.
36+
*
37+
* @param handle A pointer to a native ultralight::Matrix, the java object will take
38+
* ownership of the native pointer
39+
*/
3140
@NativeCall
3241
private UltralightMatrix(long handle) {
3342
this.handle = new DeletableObject<>(handle, UltralightMatrix::delete);
3443
}
3544

45+
/**
46+
* Constructs a new, empty matrix.
47+
*/
3648
public UltralightMatrix() {
3749
this.handle = new DeletableObject<>(construct(), UltralightMatrix::delete);
3850
}
3951

52+
/**
53+
* Sets the values of the matrix.
54+
*
55+
* @param m11 row 1, column 1
56+
* @param m12 row 1, column 2
57+
* @param m13 row 1, column 3
58+
* @param m14 row 1, column 4
59+
* @param m21 row 2, column 1
60+
* @param m22 row 2, column 2
61+
* @param m23 row 2, column 3
62+
* @param m24 row 2, column 4
63+
* @param m31 row 3, column 1
64+
* @param m32 row 3, column 2
65+
* @param m33 row 3, column 3
66+
* @param m34 row 3, column 4
67+
* @param m41 row 4, column 1
68+
* @param m42 row 4, column 2
69+
* @param m43 row 4, column 3
70+
* @param m44 row 4, column 4
71+
*/
4072
public native void set(
4173
@NativeType("double") double m11, @NativeType("double") double m12, @NativeType(
4274
"double") double m13, @NativeType("double") double m14,
@@ -48,10 +80,52 @@ public native void set(
4880
"double") double m43, @NativeType("double") double m44
4981
);
5082

83+
/**
84+
* Sets the values of this matrix by coping from a 4x4 matrix.
85+
*
86+
* @param ultralightMatrix4x4 The matrix to copy from
87+
*/
5188
public native void set(UltralightMatrix4x4 ultralightMatrix4x4);
5289

90+
/**
91+
* Set to an orthographic projection matrix suitable for use with our
92+
* vertex shaders. Optionally flip the y-coordinate space (eg, for OpenGL).
93+
*
94+
* @param screenWidth The width of the projection
95+
* @param screenHeight The height of the projection
96+
* @param flipY Whether the y coordinate space should be flipped
97+
*/
98+
public native void setOrthographicProjection(@NativeType("double") double screenWidth, @NativeType(
99+
"double") double screenHeight, @NativeType("bool") boolean flipY);
100+
101+
/**
102+
* Transforms this matrix with another matrix.
103+
*
104+
* @param transformMat The matrix to transform with
105+
*/
106+
public native void transform(UltralightMatrix transformMat);
107+
108+
/**
109+
* Retrieves this matrix as a 4x4 matrix.
110+
*
111+
* @return This matrix as a 4x4 matrix
112+
*/
113+
public native UltralightMatrix4x4 getMatrix4x4();
114+
115+
/**
116+
* Constructs a native instance of the matrix.
117+
*
118+
* @return A pointer to the crated instance.
119+
*/
53120
private static native long construct();
54121

122+
/**
123+
* Executes the deletion of the native `ultralight::Matrix` instance.
124+
* This method is static to not keep a reference to the java object, which
125+
* else would prevent deletion.
126+
*
127+
* @param handle A pointer to the instance to delete
128+
*/
55129
private static native void delete(long handle);
56130

57131
@Override
@@ -60,10 +134,5 @@ public long getHandle() {
60134
return handle.get();
61135
}
62136

63-
public native void setOrthographicProjection(@NativeType("double") double screenWidth, @NativeType(
64-
"double") double screenHeight, @NativeType("bool") boolean flipY);
65-
66-
public native void transform(UltralightMatrix transformMat);
67-
68-
public native UltralightMatrix4x4 getMatrix4x4();
137+
// TODO: Other methods
69138
}

ultralight-java-base/src/main/java/com/labymedia/ultralight/math/UltralightMatrix4x4.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,52 @@
2424
import com.labymedia.ultralight.ffi.ObjectWithHandle;
2525
import com.labymedia.ultralight.ffi.gc.DeletableObject;
2626

27+
/**
28+
* 4x4 Matrix Helper.
29+
*/
2730
@NativeType("ultralight::Matrix4x4")
2831
public class UltralightMatrix4x4 implements ObjectWithHandle {
29-
3032
private final DeletableObject<Long> handle;
3133

34+
/**
35+
* Constructs a new {@link UltralightMatrix4x4} and begins tracking the underlying handle.
36+
*
37+
* @param handle A pointer to a native ultralight::Matrix4x4, the java object will take
38+
* ownership of the native pointer
39+
*/
3240
@NativeCall
3341
private UltralightMatrix4x4(long handle) {
3442
this.handle = new DeletableObject<>(handle, UltralightMatrix4x4::delete);
3543
}
3644

45+
/**
46+
* Constructs a new, empty 4x4 matrix.
47+
*/
3748
public UltralightMatrix4x4() {
3849
this.handle = new DeletableObject<>(construct(), UltralightMatrix4x4::delete);
3950
}
4051

4152
public native @NativeType("float*") float[] getData();
4253

54+
/**
55+
* Set to identity matrix.
56+
*/
4357
public native void setIdentity();
4458

59+
/**
60+
* Constructs a native instance of the matrix.
61+
*
62+
* @return A pointer to the crated instance.
63+
*/
4564
private static native long construct();
4665

66+
/**
67+
* Executes the deletion of the native `ultralight::Matrix4x4` instance.
68+
* This method is static to not keep a reference to the java object, which
69+
* else would prevent deletion.
70+
*
71+
* @param handle A pointer to the instance to delete
72+
*/
4773
private static native void delete(long handle);
4874

4975
@Override

ultralight-java-base/src/main/java/com/labymedia/ultralight/math/Vec4.java

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,55 +23,126 @@
2323

2424
import java.util.Arrays;
2525

26+
/**
27+
* 4D Vector Helper.
28+
*/
2629
@NativeType("ultralight::Vec4")
2730
public class Vec4 {
2831
private final float[] value = new float[4];
2932

30-
public Vec4() {
31-
}
32-
33+
/**
34+
* Constructs a new, empty 4D vector.
35+
*/
36+
public Vec4() {}
37+
38+
/**
39+
* Constructs a new 4D vector with the components set.
40+
*
41+
* @param x The first vector component
42+
* @param y The second vector component
43+
* @param z The third vector component
44+
* @param w The forth vector component
45+
*/
3346
public Vec4(float x, float y, float z, float w) {
3447
this.set(x, y, z, w);
3548
}
3649

50+
/**
51+
* Constructs a new 4D vector by setting all its components to the same value.
52+
*
53+
* @param value The value to set all vector components to
54+
*/
3755
public Vec4(float value) {
3856
set(value, value, value, value);
3957
}
4058

59+
/**
60+
* Constructs a new 4D vector by copying the values from an array.
61+
*
62+
* @param value The array to copy the values from, must be exactly 4 floats
63+
*/
4164
public Vec4(float[] value) {
42-
for (int i = 0; i < 4; i++) {
43-
this.value[i] = value[i];
65+
if(value.length != 4) {
66+
throw new IllegalArgumentException("Expected value to be exactly 4 floats");
4467
}
68+
69+
System.arraycopy(value, 0, this.value, 0, 4);
4570
}
4671

72+
/**
73+
* Sets the components of the vector.
74+
*
75+
* @param x The first vector component
76+
* @param y The second vector component
77+
* @param z The third vector component
78+
* @param w The forth vector component
79+
*/
4780
public void set(float x, float y, float z, float w) {
4881
this.value[0] = x;
4982
this.value[1] = y;
5083
this.value[2] = z;
5184
this.value[3] = w;
5285
}
5386

87+
/**
88+
* Retrieves the value of the vector as a float array.
89+
* Can be used to mutate the vector.
90+
*
91+
* @return The value of this vector
92+
* @see #getValueCopy()
93+
*/
5494
public float[] getValue() {
5595
return value;
5696
}
5797

98+
/**
99+
* Copies the value of the vector as a float array.
100+
*
101+
* @return The value of this vector
102+
* @see #getValue()
103+
*/
104+
public float[] getValueCopy() {
105+
float[] copy = new float[4];
106+
System.arraycopy(value, 0, copy, 0, 4);
107+
return copy;
108+
}
109+
110+
/**
111+
* Retrieves the first component of the vector.
112+
*
113+
* @return The first component of the vector
114+
*/
58115
public float getX() {
59116
return value[0];
60117
}
61118

119+
/**
120+
* Retrieves the second component of the vector.
121+
*
122+
* @return The second component of the vector
123+
*/
62124
public float getY() {
63125
return value[1];
64126
}
65127

128+
/**
129+
* Retrieves the third component of the vector.
130+
*
131+
* @return The third component of the vector
132+
*/
66133
public float getZ() {
67134
return value[2];
68135
}
69136

137+
/**
138+
* Retrieves the forth component of the vector.
139+
*
140+
* @return The forth component of the vector
141+
*/
70142
public float getW() {
71143
return value[3];
72144
}
73145

74-
75146
@Override
76147
public boolean equals(Object o) {
77148
if (this == o) return true;

0 commit comments

Comments
 (0)