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

Commit 7f872ae

Browse files
authored
Merge pull request #50 from LabyMod/develop
Release 0.4.3 - GPU driver and inspector fix
2 parents f04b7bc + e632437 commit 7f872ae

File tree

8 files changed

+45
-31
lines changed

8 files changed

+45
-31
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Using the library with maven:
3838
<groupId>com.labymedia</groupId>
3939
<artifactId>ultralight-java-base</artifactId>
4040
<!-- Replace with latest version from https://search.maven.org/artifact/com.labymedia/ultralight-java-base !-->
41-
<version>0.4.1</version>
41+
<version>%VERSION%</version>
4242
</dependency>
4343
```
4444

@@ -48,19 +48,19 @@ If you need Javascript interop:
4848
<groupId>com.labymedia</groupId>
4949
<artifactId>ultralight-java-databind</artifactId>
5050
<!-- Replace with latest version from https://search.maven.org/artifact/com.labymedia/ultralight-java-databind !-->
51-
<version>0.4.1</version>
51+
<version>%VERSION%</version>
5252
</dependency>
5353
```
5454

5555
### Gradle
5656
```kotlin
5757
dependencies {
5858
// Replace with latest version from https://search.maven.org/artifact/com.labymedia/ultralight-java-base
59-
implementation("com.labymedia", "ultralight-java-base", "0.4.1")
59+
implementation("com.labymedia", "ultralight-java-base", "%VERSION%")
6060

6161
// // Replace with latest version from https://search.maven.org/artifact/com.labymedia/ultralight-java-databind
6262
// Remove the comments if you need Javascript interop
63-
// implementation("com.labymedia", "ultralight-java-databind", "0.4.1")
63+
// implementation("com.labymedia", "ultralight-java-databind", "%VERSION%")
6464
}
6565
```
6666

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.2
1+
0.4.3

example/lwjgl3-opengl/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ dependencies {
3535

3636
implementation group: 'org.lwjgl', name: 'lwjgl-glfw', version: '3.2.2'
3737
runtimeOnly group: 'org.lwjgl', name: 'lwjgl-glfw', version: '3.2.2', classifier: lwjglClassifier()
38-
3938
}
4039

4140
def runDir = file("run")

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public ExampleApplication() {
5050
setCallback(GLFW::glfwSetErrorCallback, this::onGLFWError);
5151

5252
// Prepare GLFW for use
53-
if(!glfwInit()) {
53+
if (!glfwInit()) {
5454
throw new IllegalStateException("Failed to initialize GLFW");
5555
}
5656

5757
// Create a GLFW window
5858
window = glfwCreateWindow(640, 480, "Ultralight GLFW", MemoryUtil.NULL, MemoryUtil.NULL);
59-
if(window == MemoryUtil.NULL) {
59+
if (window == MemoryUtil.NULL) {
6060
// Window creation failed
6161
stop();
6262
throw new IllegalStateException("Failed to create a GLFW window");
@@ -65,33 +65,34 @@ public ExampleApplication() {
6565
// Make sure to update the framebuffer size when resizing
6666
setCallback(GLFW::glfwSetFramebufferSizeCallback, this::updateSize);
6767

68+
glfwMakeContextCurrent(this.window);
69+
6870
// Set up various internal controllers
6971
this.cursorManager = new CursorAdapter(window);
7072
this.webController = new WebController(cursorManager, window);
71-
7273
}
7374

7475
/**
7576
* Centers the window on screen.
7677
*/
7778
public void centerWindow() {
7879
// Create a memory stack so we don't have to worry about free's
79-
try(MemoryStack stack = MemoryStack.stackPush()) {
80+
try (MemoryStack stack = MemoryStack.stackPush()) {
8081
// Retrieve current monitor of the window
8182
long monitor = glfwGetWindowMonitor(window);
82-
if(monitor == MemoryUtil.NULL) {
83+
if (monitor == MemoryUtil.NULL) {
8384
// The window is not on any monitor, get the primary one
8485
monitor = glfwGetPrimaryMonitor();
8586
}
8687

8788
// If there is no monitor, we can't center the window
88-
if(monitor == MemoryUtil.NULL) {
89+
if (monitor == MemoryUtil.NULL) {
8990
return;
9091
}
9192

9293
// Retrieve the video mode of the monitor
9394
GLFWVidMode videoMode = glfwGetVideoMode(monitor);
94-
if(videoMode == null) {
95+
if (videoMode == null) {
9596
// The monitor has no video mode?
9697
return;
9798
}
@@ -131,7 +132,7 @@ public void centerWindow() {
131132
* Stops the application and destroys allocated resources
132133
*/
133134
public void stop() {
134-
if(window != MemoryUtil.NULL) {
135+
if (window != MemoryUtil.NULL) {
135136
// Delete the window if it is not null
136137
glfwDestroyWindow(window);
137138
}
@@ -174,7 +175,7 @@ public void run() {
174175
// Manually update focus for the first time
175176
inputAdapter.focusCallback(window, glfwGetWindowAttrib(window, GLFW_FOCUSED) != 0);
176177

177-
try(MemoryStack stack = MemoryStack.stackPush()) {
178+
try (MemoryStack stack = MemoryStack.stackPush()) {
178179
// Update window size for the first time
179180
IntBuffer sizeBuffer = stack.callocInt(2);
180181

@@ -202,18 +203,18 @@ public void run() {
202203

203204
// Retrieve the size into the int buffer
204205
glfwGetFramebufferSize(window,
205-
(IntBuffer) framebufferSizeBuffer.slice().position(0), (IntBuffer) sizeBuffer.slice().position(1));
206+
(IntBuffer) framebufferSizeBuffer.slice().position(0), (IntBuffer) sizeBuffer.slice().position(1));
206207

207208
// Calculate scale
208209
float xScale = ((float) (framebufferSizeBuffer.get(0))) / ((float) (sizeBuffer.get(0)));
209210
float yScale = ((float) (framebufferSizeBuffer.get(1))) / ((float) (sizeBuffer.get(1)));
210211

211212
// Fix up scale in case it gets corrupted... somehow
212-
if(xScale == 0.0f) {
213+
if (xScale == 0.0f) {
213214
xScale = 1.0f;
214215
}
215216

216-
if(yScale == 0.0f) {
217+
if (yScale == 0.0f) {
217218
yScale = 1.0f;
218219
}
219220

@@ -236,7 +237,7 @@ public void run() {
236237
OpenGLDrawer drawer = new OpenGLDrawer();
237238

238239
// Keep running until a window close is requested
239-
while(!glfwWindowShouldClose(window)) {
240+
while (!glfwWindowShouldClose(window)) {
240241
// Poll events to keep the window responsive
241242
glfwPollEvents();
242243

@@ -253,7 +254,7 @@ public void run() {
253254
// Super bad implementation of FPS display...
254255
double currentTime = glfwGetTime();
255256
frameCount++;
256-
if(currentTime - lastTime >= 1.0) {
257+
if (currentTime - lastTime >= 1.0) {
257258
double msPerFrame = 1000.0 / ((double) frameCount);
258259
glfwSetWindowTitle(window, "Ultralight GLFW (" + msPerFrame + " | " + frameCount + ")");
259260
frameCount = 0;
@@ -301,7 +302,7 @@ private void onGLFWError(int error, long message) {
301302
*/
302303
private <T, C extends Callback> void setCallback(Function<T, C> setter, T newValue) {
303304
C oldValue = setter.apply(newValue);
304-
if(oldValue != null) {
305+
if (oldValue != null) {
305306
oldValue.free();
306307
}
307308
}
@@ -316,7 +317,7 @@ private <T, C extends Callback> void setCallback(Function<T, C> setter, T newVal
316317
*/
317318
private <T, C extends Callback> void setCallback(BiFunction<Long, T, C> setter, T newValue) {
318319
C oldValue = setter.apply(window, newValue);
319-
if(oldValue != null) {
320+
if (oldValue != null) {
320321
oldValue.free();
321322
}
322323
}

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import com.labymedia.ultralight.lwjgl3.opengl.input.InputAdapter;
3333
import com.labymedia.ultralight.lwjgl3.opengl.listener.ExampleLoadListener;
3434
import com.labymedia.ultralight.lwjgl3.opengl.listener.ExampleViewListener;
35+
import org.lwjgl.glfw.GLFW;
3536

37+
import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent;
3638
import static org.lwjgl.opengl.GL20.*;
3739

3840
/**
@@ -66,15 +68,14 @@ public WebController(CursorAdapter cursorManager, long window) {
6668

6769
this.platform.setConfig(
6870
new UltralightConfig()
71+
.forceRepaint(false)
6972
.resourcePath("./resources/")
7073
.fontHinting(FontHinting.NORMAL)
7174
);
7275
this.platform.usePlatformFontLoader();
7376
this.platform.setFileSystem(new ExampleFileSystem());
7477
this.platform.setLogger(new ExampleLogger());
7578
this.platform.setClipboard(new ClipboardAdapter());
76-
77-
7879
}
7980

8081
public void initGPUDriver() {
@@ -161,11 +162,18 @@ public void render() {
161162
}
162163

163164
glPopAttrib();
165+
this.renderHtmlTexture(this.view, this.window);
166+
glfwMakeContextCurrent(window);
164167

165-
long text = this.view.renderTarget().getTextureId();
168+
}
169+
170+
private void renderHtmlTexture(UltralightView view, long window) {
171+
driver.getContext().setActiveWindow(window);
172+
glfwMakeContextCurrent(window);
173+
long text = view.renderTarget().getTextureId();
166174
int width = (int) view.width();
167175
int height = (int) view.height();
168-
glClearColor(0,0,0,1);
176+
glClearColor(0, 0, 0, 1);
169177
glEnable(GL_TEXTURE_2D);
170178
// Set up the OpenGL state for rendering of a fullscreen quad
171179
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
@@ -176,10 +184,9 @@ public void render() {
176184
glMatrixMode(GL_PROJECTION);
177185
glPushMatrix();
178186
glLoadIdentity();
179-
glOrtho(0, this.view.width(), this.view.height(), 0, -1, 1);
187+
glOrtho(0, view.width(), view.height(), 0, -1, 1);
180188
glMatrixMode(GL_MODELVIEW);
181189
glPushMatrix();
182-
183190
// Disable lighting and scissoring, they could mess up th renderer
184191
glLoadIdentity();
185192
glDisable(GL_LIGHTING);

example/lwjgl3-opengl/src/main/resources/shader_v2f_c4f_t2f.vs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ float ScreenWidth() { return State[1]; }
1212
float ScreenHeight() { return State[2]; }
1313
float ScreenScale() { return State[3]; }
1414
float Scalar(uint i) { if (i < 4u) return Scalar4[0][i]; else return Scalar4[1][i - 4u]; }
15-
vec4 sRGBToLinear(vec4 val) { return vec4(val.xyz * (val.xyz * (val.xyz * 0.305306011 + 0.682171111) + 0.012522878), val.w); }
15+
vec4 sRGBToLinear(vec4 val) {
16+
return val;
17+
// return vec4(val.xyz * (val.xyz * (val.xyz * 0.305306011 + 0.682171111) + 0.012522878), val.w);
18+
}
1619
// Vertex Attributes
1720
in vec2 in_Position;
1821
in vec4 in_Color;

example/lwjgl3-opengl/src/main/resources/shader_v2f_c4f_t2f_t2f_d28f.vs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ float ScreenWidth() { return State[1]; }
1212
float ScreenHeight() { return State[2]; }
1313
float ScreenScale() { return State[3]; }
1414
float Scalar(uint i) { if (i < 4u) return Scalar4[0][i]; else return Scalar4[1][i - 4u]; }
15-
vec4 sRGBToLinear(vec4 val) { return vec4(val.xyz * (val.xyz * (val.xyz * 0.305306011 + 0.682171111) + 0.012522878), val.w); }
15+
vec4 sRGBToLinear(vec4 val) {
16+
return val;
17+
// return vec4(val.xyz * (val.xyz * (val.xyz * 0.305306011 + 0.682171111) + 0.012522878), val.w);
18+
}
1619
// Vertex Attributes
1720
in vec2 in_Position;
1821
in vec4 in_Color;

ultralight-java-native/src/main/c/src/java_bridges/ultralight_view_jni.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ namespace ultralight_java {
387387
}
388388

389389
auto inspector = view->inspector();
390-
return UltralightRefPtrJNI::create(env, std::move(ultralight::RefPtr<ultralight::View>(std::move(inspector))));
390+
auto pointer = UltralightRefPtrJNI::create(env, std::move(ultralight::RefPtr<ultralight::View>(std::move(inspector))));
391+
return env->NewObject(runtime.ultralight_view.clazz, runtime.ultralight_view.constructor, pointer);
391392
}
392393

393394
jobject UltralightViewJNI::render_target(JNIEnv *env, jobject instance) {

0 commit comments

Comments
 (0)