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

Commit 2aa4f84

Browse files
committed
Fix remaining bugs and example
1 parent 2860aa0 commit 2aa4f84

File tree

10 files changed

+55
-123
lines changed

10 files changed

+55
-123
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.nio.file.Path;
2929
import java.nio.file.Paths;
3030
import java.nio.file.StandardCopyOption;
31-
import java.util.concurrent.CountDownLatch;
3231

3332
/**
3433
* Entry pointer for the example application.
@@ -59,11 +58,6 @@ public static void main(String[] args) throws UltralightLoadException {
5958
// This only extracts the native library for ultralight-java-base, but not the other Ultralight libraries.
6059
// It is your task to get them into the run directory, possibly by extracting them on your own.
6160
UltralightJava.extractNativeLibrary(nativesDir);
62-
/*try {
63-
GPUDriverUtil.extractNativeLibrary(nativesDir);
64-
} catch (IOException e) {
65-
e.printStackTrace();
66-
}*/
6761

6862
// Load the native libraries from the given directory. This method makes sure everything is loaded in the
6963
// correct order. If you want to manually load all natives, either don't use this function or pass 'false' as

example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/FBOEntry.java renamed to example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/gpu/FBOEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919

20-
package com.labymedia.ultralight.lwjgl3.opengl;
20+
package com.labymedia.ultralight.lwjgl3.opengl.gpu;
2121

2222
public class FBOEntry {
2323
long fboId;

example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/GPUContextGL.java renamed to example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/gpu/GPUContextGL.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,7 @@
1717
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919

20-
package com.labymedia.ultralight.lwjgl3.opengl;/*
21-
* Ultralight Java - Java wrapper for the Ultralight web engine
22-
* Copyright (C) 2020 - 2021 LabyMedia and contributors
23-
*
24-
* This program is free software; you can redistribute it and/or
25-
* modify it under the terms of the GNU Lesser General Public
26-
* License as published by the Free Software Foundation; either
27-
* version 3 of the License, or (at your option) any later version.
28-
*
29-
* This program is distributed in the hope that it will be useful,
30-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
31-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32-
* Lesser General Public License for more details.
33-
*
34-
* You should have received a copy of the GNU Lesser General Public License
35-
* along with this program; if not, write to the Free Software Foundation,
36-
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
37-
*/
20+
package com.labymedia.ultralight.lwjgl3.opengl.gpu;
3821

3922
public class GPUContextGL {
4023
private long window;

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

Lines changed: 40 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,7 @@
1717
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919

20-
package com.labymedia.ultralight.lwjgl3.opengl;/*
21-
* Ultralight Java - Java wrapper for the Ultralight web engine
22-
* Copyright (C) 2020 - 2021 LabyMedia and contributors
23-
*
24-
* This program is free software; you can redistribute it and/or
25-
* modify it under the terms of the GNU Lesser General Public
26-
* License as published by the Free Software Foundation; either
27-
* version 3 of the License, or (at your option) any later version.
28-
*
29-
* This program is distributed in the hope that it will be useful,
30-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
31-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32-
* Lesser General Public License for more details.
33-
*
34-
* You should have received a copy of the GNU Lesser General Public License
35-
* along with this program; if not, write to the Free Software Foundation,
36-
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
37-
*/
20+
package com.labymedia.ultralight.lwjgl3.opengl.gpu;
3821

3922
import com.labymedia.ultralight.math.UltralightMatrix;
4023
import com.labymedia.ultralight.math.UltralightMatrix4x4;
@@ -60,17 +43,9 @@
6043
import static org.lwjgl.opengl.GL30.*;
6144
import static org.lwjgl.opengl.GL32.GL_TEXTURE_2D_MULTISAMPLE;
6245
import static org.lwjgl.opengl.GL32.glTexImage2DMultisample;
63-
import static org.lwjgl.opengl.GLUtil.setupDebugMessageCallback;
6446

6547
public class GPUDriverGL implements UltralightGPUDriver {
66-
67-
public static final int KCOMMANDTYPE_CLEARRENDERBUFFER = 0;
68-
public static final int KCOMMANDTYPE_DRAWGEOMETRY = 1;
69-
70-
public static final short KSHADERTYPE_FILL = 0;
71-
public static final short KSHADERTYPE_FILLPATH = 1;
72-
73-
private final Map<Short, ProgramEntry> programs = new HashMap<>();
48+
private final Map<UltralightShaderType, ProgramEntry> programs = new HashMap<>();
7449
private final List<UltralightCommand> commands = new LinkedList<>();
7550
private final Map<Long, TextureEntry> textureMap = new HashMap<>();
7651
private final Map<Long, GeometryEntry> geometryMap = new HashMap<>();
@@ -105,10 +80,10 @@ public void drawCommandList() {
10580
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
10681

10782
for (UltralightCommand command : commands) {
108-
if (command.commandType == KCOMMANDTYPE_DRAWGEOMETRY) {
109-
drawGeometry(command.geometryId, command.indicesCount, command.indicesOffset, command.gpuState);
110-
} else if (command.commandType == KCOMMANDTYPE_CLEARRENDERBUFFER) {
111-
clearRenderBuffer(command.gpuState.renderBufferId);
83+
if (command.getCommandType() == UltralightCommandType.DRAW_GEOMETRY) {
84+
drawGeometry(command.getGeometryId(), command.getIndicesCount(), command.getIndicesOffset(), command.getGpuState());
85+
} else if (command.getCommandType() == UltralightCommandType.CLEAR_RENDER_BUFFER) {
86+
clearRenderBuffer(command.getGpuState().getRenderBufferId());
11287
}
11388
}
11489

@@ -252,12 +227,12 @@ private void drawGeometry(long geometryId, long indicesCount, long indicesOffset
252227
if (programs.isEmpty())
253228
loadPrograms();
254229

255-
bindRenderBuffer(state.renderBufferId);
230+
bindRenderBuffer(state.getRenderBufferId());
256231

257-
setViewport(state.viewportWidth, state.viewportHeight);
232+
setViewport(state.getViewportWidth(), state.getViewportHeight());
258233

259234
GeometryEntry geometry = geometryMap.computeIfAbsent(geometryId, unused -> new GeometryEntry());
260-
selectProgram(state.shaderType);
235+
selectProgram(state.getShaderType());
261236
updateUniforms(state);
262237

263238
CHECK_GL();
@@ -267,31 +242,31 @@ private void drawGeometry(long geometryId, long indicesCount, long indicesOffset
267242
glBindVertexArray(Math.toIntExact(vaoEntry));
268243
CHECK_GL();
269244

270-
bindTexture(0, state.texture1Id);
271-
bindTexture(1, state.texture2Id);
272-
bindTexture(2, state.texture3Id);
245+
bindTexture(0, state.getTexture1Id());
246+
bindTexture(1, state.getTexture2Id());
247+
bindTexture(2, state.getTexture3Id());
273248

274249
CHECK_GL();
275-
if (state.enableScissor) {
250+
if (state.shouldEnableScissor()) {
276251
glEnable(GL_SCISSOR_TEST);
277-
IntRect r = state.scissorRect;
252+
IntRect r = state.getScissorRect();
278253
glScissor(r.getLeft(), r.getTop(), (r.getRight() - r.getLeft()), (r.getBottom() - r.getTop()));
279254
} else {
280255
glDisable(GL_SCISSOR_TEST);
281256
}
282257

283-
if (state.enableBlend) {
258+
if (state.shouldEnableBlend()) {
284259
glEnable(GL_BLEND);
285-
}
286-
else
260+
} else {
287261
glDisable(GL_BLEND);
262+
}
288263
CHECK_GL();
289264
glDrawElements(GL_TRIANGLES, Math.toIntExact(indicesCount), GL_UNSIGNED_INT, indicesOffset * Integer.BYTES);
290265
CHECK_GL();
291266
glBindVertexArray(0);
292267

293268
if (context.isEnableOffscreenGl()) {
294-
RenderBufferEntry renderBufferEntry = renderBufferMap.computeIfAbsent(state.renderBufferId, unused -> new RenderBufferEntry());
269+
RenderBufferEntry renderBufferEntry = renderBufferMap.computeIfAbsent(state.getRenderBufferId(), unused -> new RenderBufferEntry());
295270

296271
if (renderBufferEntry.bitmap != null)
297272
renderBufferEntry.needsUpdate = true;
@@ -423,33 +398,33 @@ private void createVAOIfNeededForActiveContext(long geometryId) {
423398
}
424399

425400
void updateUniforms(UltralightGPUState state) {
426-
boolean flip_y = state.renderBufferId != 0;
427-
UltralightMatrix modelViewProjection = applyProjection(state.transformMatrix, state.viewportWidth, state.viewportHeight, flip_y);
401+
boolean flip_y = state.getRenderBufferId() != 0;
402+
UltralightMatrix modelViewProjection = applyProjection(state.getTransformMatrix(), state.getViewportWidth(), state.getViewportHeight(), flip_y);
428403

429404
float[] params = new float[]{
430-
(float) (glfwGetTime() / 1000.0), state.viewportWidth, state.viewportHeight, 1.0f
405+
(float) (glfwGetTime() / 1000.0), state.getViewportWidth(), state.getViewportHeight(), 1.0f
431406
};
432407
setUniform4f("State", params);
433408
CHECK_GL();
434409
UltralightMatrix4x4 mat = modelViewProjection.getMatrix4x4();
435410
setUniformMatrix4fv("Transform", mat.getData());
436411
CHECK_GL();
437-
setUniform4fv("Scalar4", state.uniformScalar);
412+
setUniform4fv("Scalar4", state.getUniformScalar());
438413
CHECK_GL();
439414
float[] vectorData = new float[8 * 4];
440415

441416
for (int i = 0; i < 8 * 4; i += 4) {
442-
System.arraycopy(state.uniformVector[i / 4].getValue(), 0, vectorData, i, 4);
417+
System.arraycopy(state.getUniformVector()[i / 4].getValue(), 0, vectorData, i, 4);
443418
}
444419

445420
setUniform4fv("Vector", vectorData);
446421
CHECK_GL();
447-
setUniform1ui("ClipSize", state.clipSize);
422+
setUniform1ui("ClipSize", state.getClipSize());
448423
CHECK_GL();
449424

450425
float[] clip = new float[8 * 16];
451426
for (int i = 0; i < 8 * 16; i += 16) {
452-
System.arraycopy(state.clip[i / 16].getData(), 0, clip, i, 16);
427+
System.arraycopy(state.getClip()[i / 16].getData(), 0, clip, i, 16);
453428
}
454429

455430
setUniformMatrix4fv("Clip", clip);
@@ -484,11 +459,11 @@ void setUniformMatrix4fv(String name, float[] val) {
484459
}
485460

486461
private void loadPrograms() {
487-
loadProgram(KSHADERTYPE_FILL);
488-
loadProgram(KSHADERTYPE_FILLPATH);
462+
loadProgram(UltralightShaderType.FILL);
463+
loadProgram(UltralightShaderType.FILL_PATH);
489464
}
490465

491-
void selectProgram(short type) {
466+
void selectProgram(UltralightShaderType type) {
492467
CHECK_GL();
493468
ProgramEntry programEntry = this.programs.get(type);
494469
if (programEntry == null) {
@@ -500,15 +475,15 @@ void selectProgram(short type) {
500475
}
501476

502477

503-
private void loadProgram(short type) {
478+
private void loadProgram(UltralightShaderType type) {
504479
CHECK_GL();
505480
ProgramEntry prog = new ProgramEntry();
506-
if (type == KSHADERTYPE_FILL) {
481+
if (type == UltralightShaderType.FILL) {
507482
prog.vertShaderId = loadShaderFromSource(GL_VERTEX_SHADER,
508483
readShader("shader_v2f_c4f_t2f_t2f_d28f.vs"), "shader_v2f_c4f_t2f_t2f_d28f.vert");
509484
prog.fragShaderId = loadShaderFromSource(GL_FRAGMENT_SHADER,
510485
readShader("shader_fill_frag.fs"), "shader_fill.frag");
511-
} else if (type == KSHADERTYPE_FILLPATH) {
486+
} else if (type == UltralightShaderType.FILL_PATH) {
512487
prog.vertShaderId = loadShaderFromSource(GL_VERTEX_SHADER,
513488
readShader("shader_v2f_c4f_t2f.vs"), "shader_v2f_c4f_t2f.vert");
514489
prog.fragShaderId = loadShaderFromSource(GL_FRAGMENT_SHADER,
@@ -523,7 +498,7 @@ private void loadProgram(short type) {
523498
glBindAttribLocation(prog.programId, 1, "in_Color");
524499
glBindAttribLocation(prog.programId, 2, "in_TexCoord");
525500

526-
if (type == KSHADERTYPE_FILL) {
501+
if (type == UltralightShaderType.FILL) {
527502
glBindAttribLocation(prog.programId, 3, "in_ObjCoord");
528503
glBindAttribLocation(prog.programId, 4, "in_Data0");
529504
glBindAttribLocation(prog.programId, 5, "in_Data1");
@@ -537,7 +512,7 @@ private void loadProgram(short type) {
537512
glLinkProgram(prog.programId);
538513
glUseProgram(prog.programId);
539514

540-
if (type == KSHADERTYPE_FILL) {
515+
if (type == UltralightShaderType.FILL) {
541516
glUniform1i(glGetUniformLocation(prog.programId, "Texture1"), 0);
542517
glUniform1i(glGetUniformLocation(prog.programId, "Texture2"), 1);
543518
glUniform1i(glGetUniformLocation(prog.programId, "Texture3"), 2);
@@ -750,9 +725,9 @@ public void createRenderBuffer(long renderBufferId, UltralightRenderBuffer buffe
750725
}
751726

752727
RenderBufferEntry entry = renderBufferMap.computeIfAbsent(renderBufferId, (unused) -> new RenderBufferEntry());
753-
entry.textureId = buffer.textureId;
728+
entry.textureId = buffer.getTextureId();
754729

755-
TextureEntry textureEntry = textureMap.get(buffer.textureId);
730+
TextureEntry textureEntry = textureMap.get(buffer.getTextureId());
756731
textureEntry.renderBufferId = renderBufferId;
757732

758733
// We don't actually create FBOs here-- they are lazily-created
@@ -805,17 +780,17 @@ public void destroyRenderBuffer(long renderBufferId) {
805780
public void createGeometry(long geometryId, UltralightVertexBuffer vertices, UltralightIndexBuffer indices) {
806781
CHECK_GL();
807782
GeometryEntry geometry = new GeometryEntry();
808-
geometry.vertexFormat = vertices.format;
783+
geometry.vertexFormat = vertices.getFormat();
809784

810785
geometry.vboVertices = glGenBuffers();
811786

812787
glBindBuffer(GL_ARRAY_BUFFER, geometry.vboVertices);
813-
glBufferData(GL_ARRAY_BUFFER, vertices.data, GL_DYNAMIC_DRAW);
788+
glBufferData(GL_ARRAY_BUFFER, vertices.getData(), GL_DYNAMIC_DRAW);
814789
CHECK_GL();
815790

816791
geometry.vboIndices = glGenBuffers();
817792
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, geometry.vboIndices);
818-
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.data,
793+
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.getData(),
819794
GL_STATIC_DRAW);
820795

821796
geometryMap.put(geometryId, geometry);
@@ -827,10 +802,10 @@ public void updateGeometry(long geometryId, UltralightVertexBuffer vertices, Ult
827802
GeometryEntry geometry = geometryMap.get(geometryId);
828803
CHECK_GL();
829804
glBindBuffer(GL_ARRAY_BUFFER, geometry.vboVertices);
830-
glBufferData(GL_ARRAY_BUFFER, vertices.data, GL_DYNAMIC_DRAW);
805+
glBufferData(GL_ARRAY_BUFFER, vertices.getData(), GL_DYNAMIC_DRAW);
831806
CHECK_GL();
832807
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, geometry.vboIndices);
833-
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.data, GL_STATIC_DRAW);
808+
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.getData(), GL_STATIC_DRAW);
834809
CHECK_GL();
835810
}
836811

example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/GeometryEntry.java renamed to example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/gpu/GeometryEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919

20-
package com.labymedia.ultralight.lwjgl3.opengl;
20+
package com.labymedia.ultralight.lwjgl3.opengl.gpu;
2121

2222
import com.labymedia.ultralight.plugin.render.UltralightVertexBufferFormat;
2323

example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/ProgramEntry.java renamed to example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/gpu/ProgramEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919

20-
package com.labymedia.ultralight.lwjgl3.opengl;
20+
package com.labymedia.ultralight.lwjgl3.opengl.gpu;
2121

2222
public class ProgramEntry {
2323

example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/RenderBufferEntry.java renamed to example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/gpu/RenderBufferEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919

20-
package com.labymedia.ultralight.lwjgl3.opengl;
20+
package com.labymedia.ultralight.lwjgl3.opengl.gpu;
2121

2222
import com.labymedia.ultralight.bitmap.UltralightBitmap;
2323

example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/TextureEntry.java renamed to example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/gpu/TextureEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919

20-
package com.labymedia.ultralight.lwjgl3.opengl;
20+
package com.labymedia.ultralight.lwjgl3.opengl.gpu;
2121

2222
public class TextureEntry {
2323
long texId;

0 commit comments

Comments
 (0)