Skip to content

Commit 700612c

Browse files
committed
Angle backend
1 parent ca61194 commit 700612c

15 files changed

Lines changed: 1115 additions & 128 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ javadoc_deploy.pub
5050
!.vscode/settings.json
5151
!.vscode/JME_style.xml
5252
!.vscode/extensions.json
53+
joysticks-*.txt
54+
hs_err_pid*.log

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ lwjgl3-opencl = { module = "org.lwjgl:lwjgl-opencl", version.ref = "lwjgl3"
3434
lwjgl3-opengl = { module = "org.lwjgl:lwjgl-opengl", version.ref = "lwjgl3" }
3535
lwjgl3-openvr = { module = "org.lwjgl:lwjgl-openvr", version.ref = "lwjgl3" }
3636
lwjgl3-ovr = { module = "org.lwjgl:lwjgl-ovr", version.ref = "lwjgl3" }
37+
lwjgl3-opengles = { module = "org.lwjgl:lwjgl-opengles", version.ref = "lwjgl3" }
3738

3839
mokito-core = "org.mockito:mockito-core:3.12.4"
3940

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

Lines changed: 3 additions & 1 deletion
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>
@@ -282,7 +284,7 @@ public final class AppSettings extends HashMap<String, Object> {
282284
defaults.put("Samples", 0);
283285
defaults.put("Fullscreen", false);
284286
defaults.put("Title", JmeVersion.FULL_NAME);
285-
defaults.put("Renderer", LWJGL_OPENGL32);
287+
defaults.put("Renderer", ANGLE_GLES3);
286288
defaults.put("AudioRenderer", LWJGL_OPENAL);
287289
defaults.put("DisableJoysticks", true);
288290
defaults.put("UseInput", true);

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
*
@@ -428,11 +439,15 @@ public static void extractNativeLibrary(Platform platform, String name, File tar
428439
/**
429440
* First extracts the native library and then loads it.
430441
*
431-
* @param name The name of the library to load.
432-
* @param isRequired If true and the library fails to load, throw exception. If
433-
* false, do nothing if it fails to load.
442+
* @param name
443+
* The name of the library to load.
444+
* @param isRequired
445+
* If true and the library fails to load, throw exception. If false, do nothing if it fails to
446+
* load.
447+
*
448+
* @return The absolute path of the loaded library.
434449
*/
435-
public static void loadNativeLibrary(String name, boolean isRequired) {
450+
public static String loadNativeLibrary(String name, boolean isRequired) {
436451
if (JmeSystem.isLowPermissions()) {
437452
throw new UnsupportedOperationException("JVM is running under "
438453
+ "reduced permissions. Cannot load native libraries.");
@@ -453,15 +468,15 @@ public static void loadNativeLibrary(String name, boolean isRequired) {
453468
" is not available for your OS: {1}",
454469
new Object[]{name, platform});
455470
}
456-
return;
471+
return null;
457472
}
458473
}
459474

460475
final String pathInJar = library.getPathInNativesJar();
461476

462477
if (pathInJar == null) {
463478
// This platform does not require the native library to be loaded.
464-
return;
479+
return null;
465480
}
466481

467482
URL url = Resources.getResource(pathInJar);
@@ -476,7 +491,7 @@ public static void loadNativeLibrary(String name, boolean isRequired) {
476491
" was not found in the classpath via ''{1}''.",
477492
new Object[]{library.getName(), pathInJar});
478493
}
479-
return;
494+
return null;
480495
}
481496

482497
// The library has been found and is ready to be extracted.
@@ -526,6 +541,8 @@ public static void loadNativeLibrary(String name, boolean isRequired) {
526541
if (logger.isLoggable(Level.FINE)) {
527542
logger.log(Level.FINE, "Loaded native library {0}.", library.getName());
528543
}
544+
545+
return targetFile.getAbsolutePath();
529546
} catch (IOException ex) {
530547
/*if (ex.getMessage().contains("used by another process")) {
531548
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)

jme3-desktop/src/main/java/jme3tools/converters/ImageToAwt.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@ public DecodeParams(int bpp, int rm, int rs, int im, int is){
183183
private ImageToAwt() {
184184
}
185185

186+
private static Format toGLESFormat(Format format){
187+
if (format == Format.BGR8) {
188+
return Format.RGB8;
189+
}
190+
if (format == Format.BGRA8 || format == Format.ABGR8 || format == Format.ARGB8) {
191+
return Format.RGBA8;
192+
}
193+
return format;
194+
}
195+
186196
private static int Ix(int x, int y, int w){
187197
return y * w + x;
188198
}
@@ -214,6 +224,8 @@ private static void writePixel(ByteBuffer buf, int idx, int pixel, int bpp){
214224
* @param buf the output buffer (not null, modified)
215225
*/
216226
public static void convert(BufferedImage image, Format format, ByteBuffer buf) {
227+
format = toGLESFormat(format);
228+
217229
DecodeParams p = params.get(format);
218230
if (p == null)
219231
throw new UnsupportedOperationException("Image format " + format + " is not supported");

jme3-examples/src/main/java/jme3test/light/pbr/TestPBRSimple.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.jme3.math.FastMath;
4040
import com.jme3.scene.Geometry;
4141
import com.jme3.scene.Spatial;
42+
import com.jme3.system.AppSettings;
4243
import com.jme3.util.SkyFactory;
4344
import com.jme3.util.mikktspace.MikktspaceTangentGenerator;
4445

@@ -49,7 +50,13 @@ public class TestPBRSimple extends SimpleApplication {
4950
private boolean REALTIME_BAKING = false;
5051

5152
public static void main(String[] args) {
52-
new TestPBRSimple().start();
53+
AppSettings settings = new AppSettings(true);
54+
settings.setX11PlatformPreferred(true);
55+
settings.setRenderer(AppSettings.ANGLE_GLES3);
56+
settings.setGammaCorrection(true);
57+
TestPBRSimple app = new TestPBRSimple();
58+
app.setSettings(settings);
59+
app.start();
5360
}
5461

5562
@Override

0 commit comments

Comments
 (0)