Skip to content

Commit ec9c8c5

Browse files
authored
Lwjgl3 canvas (#1868)
* Fix offscreen rendering by not triggering unnecessary resize * Not title * Better javadoc * Modernize the code a bit * Modernize the code a bit * Don't init GLWF controllers (same as LWJGL 2) * Finals and interfaces * Java2D graphics based offscreen rendering Canvas solution * Import desktop
1 parent f156ce9 commit ec9c8c5

File tree

10 files changed

+390
-44
lines changed

10 files changed

+390
-44
lines changed

jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ protected FrameBuffer(FrameBuffer src) {
363363
*
364364
* @param format The format to use for the depth buffer.
365365
* @throws IllegalArgumentException If <code>format</code> is not a depth format.
366-
* @deprecated Use setDepthTarget
366+
* @deprecated Use
367+
* {@link #setDepthTarget(com.jme3.texture.FrameBuffer.FrameBufferBufferTarget)}
367368
*/
368369
@Deprecated
369370
public void setDepthBuffer(Image.Format format) {
@@ -656,7 +657,8 @@ public void addColorTexture(TextureCubeMap tex, TextureCubeMap.Face face) {
656657
* Set the depth texture to use for this framebuffer.
657658
*
658659
* @param tex The color texture to set.
659-
* @deprecated Use setDepthTarget
660+
* @deprecated Use
661+
* {@link #setDepthTarget(com.jme3.texture.FrameBuffer.FrameBufferTextureTarget)}
660662
*/
661663
@Deprecated
662664
public void setDepthTexture(Texture2D tex) {
@@ -677,7 +679,8 @@ public void setDepthTexture(Texture2D tex) {
677679
*
678680
* @param tex the TextureArray to apply
679681
* @param layer (default=-1)
680-
* @deprecated Use setDepthTarget
682+
* @deprecated Use
683+
* {@link #setDepthTarget(com.jme3.texture.FrameBuffer.FrameBufferTextureTarget)}
681684
*/
682685
@Deprecated
683686
public void setDepthTexture(TextureArray tex, int layer) {

jme3-desktop/src/main/java/com/jme3/input/AWTKeyInput.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,17 @@
3131
*/
3232
package com.jme3.input;
3333

34+
import com.jme3.input.event.KeyInputEvent;
3435
import java.awt.Component;
3536
import java.awt.event.KeyEvent;
3637
import java.awt.event.KeyListener;
38+
import java.util.Deque;
3739
import java.util.HashMap;
3840
import java.util.LinkedList;
3941
import java.util.Map;
4042

41-
import com.jme3.input.KeyInput;
42-
import com.jme3.input.event.KeyInputEvent;
4343
import com.jme3.system.AWTContext;
4444

45-
4645
/**
4746
* The implementation of the {@link KeyInput} dedicated to AWT {@link Component component}.
4847
* <p>
@@ -166,11 +165,11 @@ public class AWTKeyInput extends AWTInput implements KeyInput, KeyListener{
166165
KEY_CODE_TO_JME.put(KeyEvent.VK_META, KEY_RCONTROL);
167166
}
168167

169-
private final LinkedList<KeyInputEvent> keyInputEvents;
168+
private final Deque<KeyInputEvent> keyInputEvents;
170169

171170
public AWTKeyInput(AWTContext context) {
172171
super(context);
173-
keyInputEvents = new LinkedList<KeyInputEvent>();
172+
keyInputEvents = new LinkedList<>();
174173
}
175174

176175
@Override

jme3-desktop/src/main/java/com/jme3/input/AWTMouseInput.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,21 @@
3131
*/
3232
package com.jme3.input;
3333

34+
import com.jme3.cursors.plugins.JmeCursor;
35+
import com.jme3.input.event.MouseButtonEvent;
36+
import com.jme3.input.event.MouseMotionEvent;
3437
import java.awt.Component;
3538
import java.awt.event.MouseEvent;
3639
import java.awt.event.MouseListener;
3740
import java.awt.event.MouseMotionListener;
3841
import java.awt.event.MouseWheelEvent;
3942
import java.awt.event.MouseWheelListener;
43+
import java.util.Deque;
4044
import java.util.HashMap;
4145
import java.util.LinkedList;
4246
import java.util.Map;
4347

44-
import com.jme3.cursors.plugins.JmeCursor;
45-
import com.jme3.input.MouseInput;
46-
import com.jme3.input.event.MouseButtonEvent;
47-
import com.jme3.input.event.MouseMotionEvent;
4848
import com.jme3.system.AWTContext;
49-
5049
/**
5150
* The implementation of the {@link MouseInput} dedicated to AWT {@link Component component}.
5251
* <p>
@@ -70,18 +69,18 @@ public class AWTMouseInput extends AWTInput implements MouseInput, MouseListener
7069
*/
7170
private static final int WHEEL_SCALE = 10;
7271

73-
private final LinkedList<MouseMotionEvent> mouseMotionEvents;
72+
private final Deque<MouseMotionEvent> mouseMotionEvents;
7473

75-
private final LinkedList<MouseButtonEvent> mouseButtonEvents;
74+
private final Deque<MouseButtonEvent> mouseButtonEvents;
7675

7776
private int mouseX;
7877
private int mouseY;
7978
private int mouseWheel;
8079

8180
public AWTMouseInput(AWTContext context) {
8281
super(context);
83-
mouseMotionEvents = new LinkedList<MouseMotionEvent>();
84-
mouseButtonEvents = new LinkedList<MouseButtonEvent>();
82+
mouseMotionEvents = new LinkedList<>();
83+
mouseButtonEvents = new LinkedList<>();
8584
}
8685

8786
@Override

jme3-desktop/src/main/java/com/jme3/input/awt/AwtKeyInput.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.awt.event.KeyListener;
4040
import java.util.ArrayList;
4141
import java.util.BitSet;
42+
import java.util.List;
4243
import java.util.logging.Level;
4344
import java.util.logging.Logger;
4445

@@ -53,10 +54,10 @@ public class AwtKeyInput implements KeyInput, KeyListener {
5354

5455
private static final Logger logger = Logger.getLogger(AwtKeyInput.class.getName());
5556

56-
private final ArrayList<KeyInputEvent> eventQueue = new ArrayList<>();
57+
private final List<KeyInputEvent> eventQueue = new ArrayList<>();
5758
private RawInputListener listener;
5859
private Component component;
59-
private BitSet keyStateSet = new BitSet(0xFF);
60+
private final BitSet keyStateSet = new BitSet(0xFF);
6061

6162
public AwtKeyInput(){
6263
}

jme3-desktop/src/main/java/com/jme3/input/awt/AwtMouseInput.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public class AwtMouseInput implements MouseInput, MouseListener, MouseWheelListe
6464

6565
private Component component;
6666

67-
private final ArrayList<MouseButtonEvent> eventQueue = new ArrayList<>();
68-
private final ArrayList<MouseButtonEvent> eventQueueCopy = new ArrayList<>();
67+
private final java.util.List<MouseButtonEvent> eventQueue = new ArrayList<>();
68+
private final java.util.List<MouseButtonEvent> eventQueueCopy = new ArrayList<>();
6969

7070
private int lastEventX;
7171
private int lastEventY;

jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanel.java

+12-11
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import com.jme3.renderer.ViewPort;
3838
import com.jme3.renderer.queue.RenderQueue;
3939
import com.jme3.texture.FrameBuffer;
40-
import com.jme3.texture.Image.Format;
4140
import com.jme3.util.BufferUtils;
4241
import com.jme3.util.Screenshots;
4342
import java.awt.*;
@@ -57,6 +56,8 @@
5756

5857
public class AwtPanel extends Canvas implements SceneProcessor {
5958

59+
private static final Logger logger = Logger.getLogger(AwtPanel.class.getName());
60+
6061
private boolean attachAsMain = false;
6162

6263
private BufferedImage img;
@@ -66,19 +67,19 @@ public class AwtPanel extends Canvas implements SceneProcessor {
6667
private IntBuffer intBuf;
6768
private RenderManager rm;
6869
private PaintMode paintMode;
69-
private ArrayList<ViewPort> viewPorts = new ArrayList<>();
70+
private final java.util.List<ViewPort> viewPorts = new ArrayList<>();
7071

7172
// Visibility/drawing vars
7273
private BufferStrategy strategy;
7374
private AffineTransformOp transformOp;
74-
private AtomicBoolean hasNativePeer = new AtomicBoolean(false);
75-
private AtomicBoolean showing = new AtomicBoolean(false);
76-
private AtomicBoolean repaintRequest = new AtomicBoolean(false);
75+
private final AtomicBoolean hasNativePeer = new AtomicBoolean(false);
76+
private final AtomicBoolean showing = new AtomicBoolean(false);
77+
private final AtomicBoolean repaintRequest = new AtomicBoolean(false);
7778

7879
// Reshape vars
7980
private int newWidth = 1;
8081
private int newHeight = 1;
81-
private AtomicBoolean reshapeNeeded = new AtomicBoolean(false);
82+
private final AtomicBoolean reshapeNeeded = new AtomicBoolean(false);
8283
private final Object lock = new Object();
8384

8485
public AwtPanel(PaintMode paintMode) {
@@ -180,7 +181,7 @@ public void drawFrameInThread() {
180181
BufferCapabilities.FlipContents.UNDEFINED)
181182
);
182183
} catch (AWTException ex) {
183-
ex.printStackTrace();
184+
logger.log(Level.WARNING, "Failed to create buffer strategy!", ex);
184185
}
185186
strategy = getBufferStrategy();
186187
}
@@ -190,7 +191,7 @@ public void drawFrameInThread() {
190191
do {
191192
Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics();
192193
if (g2d == null) {
193-
Logger.getLogger(AwtPanel.class.getName()).log(Level.WARNING, "OGL: DrawGraphics was null.");
194+
logger.log(Level.WARNING, "OGL: DrawGraphics was null.");
194195
return;
195196
}
196197

@@ -210,7 +211,7 @@ public boolean isActiveDrawing() {
210211
}
211212

212213
public void attachTo(boolean overrideMainFramebuffer, ViewPort... vps) {
213-
if (viewPorts.size() > 0) {
214+
if (!viewPorts.isEmpty()) {
214215
for (ViewPort vp : viewPorts) {
215216
vp.setOutputFrameBuffer(null);
216217
}
@@ -242,8 +243,8 @@ private void reshapeInThread(int width, int height) {
242243
}
243244

244245
fb = new FrameBuffer(width, height, 1);
245-
fb.setDepthBuffer(Format.Depth);
246-
fb.setColorBuffer(Format.RGB8);
246+
fb.setDepthTarget(FrameBuffer.FrameBufferTarget.newTarget(com.jme3.texture.Image.Format.Depth));
247+
fb.addColorTarget(FrameBuffer.FrameBufferTarget.newTarget(com.jme3.texture.Image.Format.RGB8));
247248
fb.setSrgb(srgb);
248249

249250
if (attachAsMain) {

jme3-lwjgl3/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
dependencies {
22
api project(':jme3-core')
3+
api project(':jme3-desktop')
34

45
api "org.lwjgl:lwjgl:${lwjgl3Version}"
56
api "org.lwjgl:lwjgl-glfw:${lwjgl3Version}"

0 commit comments

Comments
 (0)