|
19 | 19 |
|
20 | 20 | package com.labymedia.ultralight.util; |
21 | 21 |
|
22 | | -import com.labymedia.ultralight.gpu.UltralightGPUDriverNativeUtil; |
23 | 22 | import com.labymedia.ultralight.gpu.UltralightOpenGLGPUDriverNative; |
24 | 23 | import org.lwjgl.glfw.GLFW; |
25 | 24 | import org.lwjgl.opengl.GL11; |
26 | | -import org.lwjgl.opengl.GL11C; |
27 | 25 |
|
28 | 26 | /** |
29 | 27 | * GPU Driver implementation of {@link com.labymedia.ultralight.plugin.render.UltralightGPUDriver}. |
30 | 28 | */ |
31 | 29 | public class UltralightGlfwOpenGLGPUDriver implements UltralightOpenGLGPUDriver { |
32 | 30 |
|
33 | | - private final boolean msaa; |
34 | | - private UltralightOpenGLGPUDriverNative driverNative; |
35 | | - private UltralightGlfwOpenGLContext context; |
36 | | - private Long renderTargetId; |
| 31 | + private final boolean msaa; |
| 32 | + private UltralightOpenGLGPUDriverNative driverNative; |
| 33 | + private UltralightGlfwOpenGLContext context; |
37 | 34 |
|
38 | | - private UltralightGlfwOpenGLGPUDriver(boolean msaa) { |
39 | | - this.msaa = msaa; |
40 | | - } |
| 35 | + private UltralightGlfwOpenGLGPUDriver(boolean msaa) { |
| 36 | + this.msaa = msaa; |
| 37 | + } |
41 | 38 |
|
42 | | - /** |
43 | | - * Set the {@link UltralightOpenGLGPUDriverNative} instance to the {@link com.labymedia.ultralight.UltralightPlatform}. |
44 | | - */ |
45 | | - @Override |
46 | | - public void initialize(UltralightGlfwOpenGLContext context) { |
47 | | - this.driverNative = new UltralightOpenGLGPUDriverNative(context.getMainWindow().getWindowHandle(), this.msaa, GLFW.Functions.GetProcAddress); |
48 | | - this.context = context; |
49 | | - this.context.getPlatform().setGPUDriver(this.driverNative); |
50 | | - } |
| 39 | + /** |
| 40 | + * Set the {@link UltralightOpenGLGPUDriverNative} instance to the {@link com.labymedia.ultralight.UltralightPlatform}. |
| 41 | + */ |
| 42 | + @Override |
| 43 | + public void initialize(UltralightGlfwOpenGLContext context) { |
| 44 | + this.driverNative = new UltralightOpenGLGPUDriverNative(context.getMainWindow().getWindowHandle(), this.msaa, GLFW.Functions.GetProcAddress); |
| 45 | + this.context = context; |
| 46 | + this.context.getPlatform().setGPUDriver(this.driverNative); |
| 47 | + } |
51 | 48 |
|
52 | | - /** |
53 | | - * {@inheritDoc} |
54 | | - */ |
55 | | - @Override |
56 | | - public void renderTexture(UltralightGlfwOpenGLWindow window) { |
57 | | - this.context.postAndWait(() -> { |
58 | | - this.driverNative.setActiveWindow(window.getWindowHandle()); |
| 49 | + /** |
| 50 | + * {@inheritDoc} |
| 51 | + */ |
| 52 | + @Override |
| 53 | + public void renderTexture(UltralightGlfwOpenGLWindow window) { |
| 54 | + this.context.postAndWait(() -> { |
| 55 | + this.driverNative.setActiveWindow(window.getWindowHandle()); |
59 | 56 |
|
60 | | - UltralightRendererInstanceHolder.getRenderer().render(); |
61 | | - if (this.driverNative.hasCommandsPending()) { |
62 | | - this.driverNative.drawCommandList(); |
63 | | - } |
64 | | - this.renderTargetId = window.getView().renderTarget().getTextureId(); |
65 | | - GL11.glFinish(); |
66 | | - }); |
67 | | - } |
| 57 | + UltralightRendererInstanceHolder.getRenderer().render(); |
| 58 | + if (this.driverNative.hasCommandsPending()) { |
| 59 | + this.driverNative.drawCommandList(); |
| 60 | + } |
| 61 | + GL11.glFinish(); |
| 62 | + }); |
| 63 | + } |
68 | 64 |
|
69 | 65 |
|
70 | | - /** |
71 | | - * {@inheritDoc} |
72 | | - */ |
73 | | - @Override |
74 | | - public void bindTexture(UltralightGlfwOpenGLWindow window) { |
75 | | - this.driverNative.bindTexture(0, this.renderTargetId); |
76 | | - } |
| 66 | + /** |
| 67 | + * {@inheritDoc} |
| 68 | + */ |
| 69 | + @Override |
| 70 | + public void bindTexture(UltralightGlfwOpenGLWindow window) { |
| 71 | + this.driverNative.bindTexture(0, window.postAndWait(() -> window.getView().renderTarget().getTextureId())); |
| 72 | + } |
77 | 73 |
|
78 | | - /** |
79 | | - * Create a new instance of {@link UltralightGlfwOpenGLGPUDriver}. |
80 | | - * Should only be called once, since the {@link UltralightGlfwOpenGLContext} can also only be instantiated once due to some Ultralight limitations. |
81 | | - * |
82 | | - * @param msaa define if MSAA should active for the new driver |
83 | | - * @return the constructed driver instance |
84 | | - */ |
85 | | - public static UltralightGlfwOpenGLGPUDriver create(boolean msaa) { |
86 | | - return new UltralightGlfwOpenGLGPUDriver(msaa); |
87 | | - } |
| 74 | + /** |
| 75 | + * Create a new instance of {@link UltralightGlfwOpenGLGPUDriver}. |
| 76 | + * Should only be called once, since the {@link UltralightGlfwOpenGLContext} can also only be instantiated once due to some Ultralight limitations. |
| 77 | + * |
| 78 | + * @param msaa define if MSAA should active for the new driver |
| 79 | + * @return the constructed driver instance |
| 80 | + */ |
| 81 | + public static UltralightGlfwOpenGLGPUDriver create(boolean msaa) { |
| 82 | + return new UltralightGlfwOpenGLGPUDriver(msaa); |
| 83 | + } |
88 | 84 | } |
0 commit comments