Skip to content

Commit 9a63ca1

Browse files
committed
rewrite lwjgl3 backend to use SDL
1 parent f02c4e6 commit 9a63ca1

44 files changed

Lines changed: 2303 additions & 5952 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ javadoc_deploy.pub
4545
!.vscode/settings.json
4646
!.vscode/JME_style.xml
4747
!.vscode/extensions.json
48-
joysticks-*.txt
48+
joysticks-*.txt

common.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ repositories {
3434
flatDir {
3535
dirs rootProject.file('lib')
3636
}
37+
maven {
38+
url "https://maven.rblb.it/riccardobl/angle-natives"
39+
}
3740
}
3841

3942
dependencies {

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ lwjgl3-openal = { module = "org.lwjgl:lwjgl-openal", version.ref = "lwjgl3"
3333
lwjgl3-opencl = { module = "org.lwjgl:lwjgl-opencl", version.ref = "lwjgl3" }
3434
lwjgl3-opengl = { module = "org.lwjgl:lwjgl-opengl", version.ref = "lwjgl3" }
3535
lwjgl3-sdl = { module = "org.lwjgl:lwjgl-sdl", version.ref = "lwjgl3" }
36+
lwjgl3-opengles = { module = "org.lwjgl:lwjgl-opengles", version.ref = "lwjgl3" }
37+
lwjgl3-egl = { module = "org.lwjgl:lwjgl-egl", version.ref = "lwjgl3" }
3638

3739
mokito-core = "org.mockito:mockito-core:3.12.4"
3840

jme3-core/src/main/java/com/jme3/renderer/opengl/GLES_30.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ public interface GLES_30 extends GL {
4242

4343
public static final int GL_RGB10_A2 = 0x8059;
4444
public static final int GL_UNSIGNED_INT_2_10_10_10_REV = 0x8368;
45-
45+
public static final int GL_NUM_EXTENSIONS = 0x821D;
46+
4647
public void glBindVertexArray(int array);
4748

4849
public void glDeleteVertexArrays(IntBuffer arrays);
4950

5051
public void glGenVertexArrays(IntBuffer arrays);
52+
53+
public String glGetString(final int name, final int index);
54+
5155
}

jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,15 @@ private HashSet<String> loadExtensions() {
186186
gl3.glGetInteger(GL3.GL_NUM_EXTENSIONS, intBuf16);
187187
int extensionCount = intBuf16.get(0);
188188
for (int i = 0; i < extensionCount; i++) {
189-
String extension = gl3.glGetString(GL.GL_EXTENSIONS, i);
189+
String extension = gl3.glGetString(GL3.GL_EXTENSIONS, i);
190+
extensionSet.add(extension);
191+
}
192+
} else if (caps.contains(Caps.OpenGLES30)) {
193+
GLES_30 gles = (GLES_30) gl;
194+
gles.glGetInteger(GLES_30.GL_NUM_EXTENSIONS, intBuf16);
195+
int extensionCount = intBuf16.get(0);
196+
for (int i = 0; i < extensionCount; i++) {
197+
String extension = gles.glGetString(GLES_30.GL_EXTENSIONS, i);
190198
extensionSet.add(extension);
191199
}
192200
} else {

jme3-core/src/main/java/com/jme3/system/AppSettings.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ public final class AppSettings extends HashMap<String, Object> {
219219
*/
220220
public static final String LWJGL_OPENAL = "LWJGL";
221221

222+
public static final String ANGLE_GLES3 = "ANGLE_GLES3";
223+
222224
/**
223225
* Use the Android MediaPlayer / SoundPool based renderer for Android audio capabilities.
224226
* <p>
@@ -296,18 +298,18 @@ public final class AppSettings extends HashMap<String, Object> {
296298
static {
297299
defaults.put("Display", 0);
298300
defaults.put("CenterWindow", true);
299-
defaults.put("Width", 640);
300-
defaults.put("Height", 480);
301+
defaults.put("Width", 1440);
302+
defaults.put("Height", 900);
301303
defaults.put("WindowWidth", Integer.MIN_VALUE);
302304
defaults.put("WindowHeight", Integer.MIN_VALUE);
303305
defaults.put("BitsPerPixel", 24);
304-
defaults.put("Frequency", 60);
306+
defaults.put("Frequency", 0);
305307
defaults.put("DepthBits", 24);
306308
defaults.put("StencilBits", 0);
307309
defaults.put("Samples", 0);
308310
defaults.put("Fullscreen", false);
309311
defaults.put("Title", JmeVersion.FULL_NAME);
310-
defaults.put("Renderer", LWJGL_OPENGL32);
312+
defaults.put("Renderer", ANGLE_GLES3);
311313
defaults.put("AudioRenderer", LWJGL_OPENAL);
312314
defaults.put("DisableJoysticks", true);
313315
defaults.put("UseInput", true);
@@ -317,7 +319,7 @@ public final class AppSettings extends HashMap<String, Object> {
317319
defaults.put("MinHeight", 0);
318320
defaults.put("MinWidth", 0);
319321
defaults.put("GammaCorrection", true);
320-
defaults.put("Resizable", false);
322+
defaults.put("Resizable", true);
321323
defaults.put("SwapBuffers", true);
322324
defaults.put("OpenCL", false);
323325
defaults.put("OpenCLPlatformChooser", DefaultPlatformChooser.class.getName());

jme3-core/src/plugins/java/com/jme3/texture/plugins/TGALoader.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ public final class TGALoader implements AssetLoader {
7272
// 11 - run-length encoded, black and white image
7373
public static final int TYPE_BLACKANDWHITE_RLE = 11;
7474

75+
private static void convertBGRtoRGB(byte[] data, int dl){
76+
for (int i = 0; i < data.length; i += dl) {
77+
byte tmp = data[i];
78+
data[i] = data[i + 2];
79+
data[i + 2] = tmp;
80+
}
81+
}
82+
7583
@Override
7684
public Object load(AssetInfo info) throws IOException {
7785
if (!(info.getKey() instanceof TextureKey)) {
@@ -261,7 +269,8 @@ public static Image load(InputStream in, boolean flip) throws IOException {
261269
// rawData[rawDataIndex++] = blue;
262270
// }
263271
}
264-
format = Format.BGR8;
272+
convertBGRtoRGB(rawData, dl);
273+
format = Format.RGB8;
265274
} else if (pixelDepth == 32) {
266275
for (int i = 0; i <= (height - 1); i++) {
267276
if (!flip) {

jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public JmeContext newContext(AppSettings settings, Type contextType) {
216216
|| contextType == JmeContext.Type.Headless) {
217217
ctx = new NullContext();
218218
ctx.setSettings(settings);
219-
} else if (settings.getRenderer().startsWith("LWJGL")) {
219+
} else if (settings.getRenderer().startsWith("LWJGL") || settings.getRenderer().startsWith("ANGLE")) {
220220
ctx = newContextLwjgl(settings, contextType);
221221
ctx.setSettings(settings);
222222
} else if (settings.getRenderer().startsWith("JOGL")) {

jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.logging.Level;
4545
import java.util.logging.Logger;
4646

47+
import com.jme3.system.NativeLibraries.LibraryInfo;
4748
import com.jme3.util.res.Resources;
4849

4950
/**
@@ -94,6 +95,16 @@ public static void registerNativeLibrary(NativeLibrary library) {
9495
nativeLibraryMap.put(library.getKey(), library);
9596
}
9697

98+
/**
99+
* Register a new native library.
100+
*
101+
* This simply registers a known library, the actual extraction and loading is performed by calling
102+
* {@link #loadNativeLibrary(java.lang.String, boolean) }.
103+
*/
104+
public static void registerNativeLibrary(LibraryInfo library) {
105+
library.getNativeVariants().forEach(NativeLibraryLoader::registerNativeLibrary);
106+
}
107+
97108
/**
98109
* Register a new native library.
99110
*
@@ -432,11 +443,15 @@ public static void extractNativeLibrary(Platform platform, String name, File tar
432443
/**
433444
* First extracts the native library and then loads it.
434445
*
435-
* @param name The name of the library to load.
436-
* @param isRequired If true and the library fails to load, throw exception. If
437-
* false, do nothing if it fails to load.
446+
* @param name
447+
* The name of the library to load.
448+
* @param isRequired
449+
* If true and the library fails to load, throw exception. If false, do nothing if it fails to
450+
* load.
451+
*
452+
* @return The absolute path of the loaded library.
438453
*/
439-
public static void loadNativeLibrary(String name, boolean isRequired) {
454+
public static String loadNativeLibrary(String name, boolean isRequired) {
440455
if (JmeSystem.isLowPermissions()) {
441456
throw new UnsupportedOperationException("JVM is running under "
442457
+ "reduced permissions. Cannot load native libraries.");
@@ -457,15 +472,15 @@ public static void loadNativeLibrary(String name, boolean isRequired) {
457472
" is not available for your OS: {1}",
458473
new Object[]{name, platform});
459474
}
460-
return;
475+
return null;
461476
}
462477
}
463478

464479
final String pathInJar = library.getPathInNativesJar();
465480

466481
if (pathInJar == null) {
467482
// This platform does not require the native library to be loaded.
468-
return;
483+
return null;
469484
}
470485

471486
URL url = Resources.getResource(pathInJar);
@@ -480,7 +495,7 @@ public static void loadNativeLibrary(String name, boolean isRequired) {
480495
" was not found in the classpath via ''{1}''.",
481496
new Object[]{library.getName(), pathInJar});
482497
}
483-
return;
498+
return null;
484499
}
485500

486501
// The library has been found and is ready to be extracted.
@@ -530,6 +545,8 @@ public static void loadNativeLibrary(String name, boolean isRequired) {
530545
if (logger.isLoggable(Level.FINE)) {
531546
logger.log(Level.FINE, "Loaded native library {0}.", library.getName());
532547
}
548+
549+
return targetFile.getAbsolutePath();
533550
} catch (IOException ex) {
534551
/*if (ex.getMessage().contains("used by another process")) {
535552
return;

jme3-desktop/src/main/java/com/jme3/texture/plugins/AWTLoader.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@ private void flipImage(short[] img, int width, int height, int bpp){
101101
}
102102
}
103103

104+
private static void convertBGRtoRGB(byte[] data){
105+
for (int i = 0; i < data.length; i += 3) {
106+
byte tmp = data[i];
107+
data[i] = data[i + 2];
108+
data[i + 2] = tmp;
109+
}
110+
}
111+
112+
private static void convertABGRtoRGBA(byte[] data){
113+
for (int i = 0; i < data.length; i += 4) {
114+
byte a = data[i];
115+
byte b = data[i + 1];
116+
byte g = data[i + 2];
117+
byte r = data[i + 3];
118+
data[i] = r;
119+
data[i + 1] = g;
120+
data[i + 2] = b;
121+
data[i + 3] = a;
122+
}
123+
}
124+
104125
public Image load(BufferedImage img, boolean flipY){
105126
int width = img.getWidth();
106127
int height = img.getHeight();
@@ -110,18 +131,22 @@ public Image load(BufferedImage img, boolean flipY){
110131
byte[] dataBuf1 = (byte[]) extractImageData(img);
111132
if (flipY)
112133
flipImage(dataBuf1, width, height, 32);
134+
135+
convertABGRtoRGBA(dataBuf1);
113136

114137
ByteBuffer data1 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*4);
115138
data1.put(dataBuf1);
116-
return new Image(Format.ABGR8, width, height, data1, null, com.jme3.texture.image.ColorSpace.sRGB);
139+
return new Image(Format.RGBA8, width, height, data1, null, com.jme3.texture.image.ColorSpace.sRGB);
117140
case BufferedImage.TYPE_3BYTE_BGR: // most common in JPEG images
118141
byte[] dataBuf2 = (byte[]) extractImageData(img);
119142
if (flipY)
120143
flipImage(dataBuf2, width, height, 24);
144+
145+
convertBGRtoRGB(dataBuf2);
121146

122147
ByteBuffer data2 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*3);
123148
data2.put(dataBuf2);
124-
return new Image(Format.BGR8, width, height, data2, null, com.jme3.texture.image.ColorSpace.sRGB);
149+
return new Image(Format.RGB8, width, height, data2, null, com.jme3.texture.image.ColorSpace.sRGB);
125150
case BufferedImage.TYPE_BYTE_GRAY: // grayscale fonts
126151
byte[] dataBuf3 = (byte[]) extractImageData(img);
127152
if (flipY)

0 commit comments

Comments
 (0)