Skip to content

Commit

Permalink
Add new MetalANGLE backend (ios/robovm) (libgdx#6681)
Browse files Browse the repository at this point in the history
* gdx-backend-robovm-metalangle project is automatically generated from gdx-backend-robovm
* See libgdx#6681 for more information.

Co-authored-by: Desu <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
3 people authored May 12, 2022
1 parent eaa9d35 commit e03b757
Show file tree
Hide file tree
Showing 62 changed files with 6,026 additions and 3 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/fix-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Apply formatter
- name: Generate MobiVM MetalANGLE backend
run: ./gradlew :backends:gdx-backend-robovm-metalangle:generate :backends:gdx-backend-robovm-metalangle:spotlessApply
- name: Commit generation changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add backends/gdx-backend-robovm-metalangle/src
git commit -m "Generate MobiVM MetalANGLE backend" -a
continue-on-error: true
- name: Apply formater
run: ./gradlew spotlessApply
- name: Commit formatting changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Apply formatter" -a
continue-on-error: true
- name: Push formatting changes
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ libgdx-*.zip.MD5

#the LWJGL3 libs are pulled via fetch.xml
/backends/gdx-backend-lwjgl3/libs/lwjgl*.jar
/backends/gdx-backend-robovm-metalangle/res/META-INF/robovm/ios/libs

#ensure gdx-setup.jar works properly
!/extensions/gdx-setup/src/com/badlogic/gdx/setup/resources/gwt/war
Expand Down
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[1.11.1]
- iOS: Add new MobiVM MetalANGLE backend

[1.11.0]
- [BREAKING CHANGE] iOS: Increased min supported iOS version to 9.0. Update your Info.plist file if necessary.
- [BREAKING CHANGE] Removed Maven and Ant build systems. libGDX is now solely built with Gradle. See https://libgdx.com/dev/from-source/ for updated build instructions.
Expand Down
33 changes: 33 additions & 0 deletions THIRDPARTY
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
ANGLE/MetalANGLE:
// Copyright 2018 The ANGLE Project Authors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of TransGaming Inc., Google Inc., 3DLabs Inc.
// Ltd., nor the names of their contributors may be used to endorse
// or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
136 changes: 136 additions & 0 deletions backends/gdx-backend-robovm-metalangle/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
import org.gradle.internal.os.OperatingSystem

sourceSets {
generator {
java {
srcDir 'generator'
}
resources {
srcDir 'generator'
}
}
main {
java {
srcDir 'src'
}
resources {
srcDir 'res'
}
}
}
configurations {
generatorCompile.extendsFrom testCompile
generatorRuntime.extendsFrom testRuntime
}

configurations { generator }

dependencies {
api libraries.robovm
generatorImplementation 'com.github.javaparser:javaparser-core:3.24.2'
}

task generate(type: JavaExec) {
dependsOn configurations.generator

main = 'JavaCodeGenerator'
classpath = sourceSets.generator.runtimeClasspath

inputs.dir '../gdx-backend-robovm/src/'
outputs.dir 'src/'
}

task fetchMetalANGLE(type: Download) {
doFirst {
file("build/tmp").mkdirs();
}
src 'https://github.com/kakashidinho/metalangle/releases/download/gles3-0.0.7/MetalANGLE.framework.ios.zip'
dest 'build/tmp/MetalANGLE.framework.ios.zip'
onlyIfModified true
useETag "all"
}

task fetchMetalANGLESimulator(type: Download) {
doFirst {
file("build/tmp").mkdirs();
}
src 'https://github.com/kakashidinho/metalangle/releases/download/gles3-0.0.7/MetalANGLE.framework.ios.simulator.zip'
dest 'build/tmp/MetalANGLE.framework.ios.simulator.zip'
onlyIfModified true
useETag "all"
}

task verifyMetalANGLE(dependsOn: fetchMetalANGLE, type: Verify) {
src 'build/tmp/MetalANGLE.framework.ios.zip'
algorithm 'SHA-256'
checksum '66fcf9eed2ede9e5725bf64e5b3169e0f39d1a515fe425447354c41968fc7999'
}

task verifyMetalANGLESimulator(dependsOn: fetchMetalANGLESimulator, type: Verify) {
src 'build/tmp/MetalANGLE.framework.ios.simulator.zip'
algorithm 'SHA-256'
checksum 'e9aa526d2f19c57e1efbae4ec04d76701da4cf596bf8c6fb6ef6c507dbc2fdc4'
}

task extractMetalANGLE(dependsOn: verifyMetalANGLE, type: Copy) {
doFirst {
file("build/tmp/real").mkdirs();
}
from zipTree('build/tmp/MetalANGLE.framework.ios.zip')
into 'build/tmp/real'
}

task extractMetalANGLESimulator(dependsOn: verifyMetalANGLESimulator, type: Copy) {
doFirst {
file("build/tmp/sim").mkdirs();
}
from zipTree('build/tmp/MetalANGLE.framework.ios.simulator.zip')
into 'build/tmp/sim'
}

task buildMetalANGLE(dependsOn: [
extractMetalANGLE,
extractMetalANGLESimulator
], type: Exec) {
doFirst {
file("res/META-INF/robovm/ios/libs").mkdirs();
}
commandLine 'xcodebuild', '-create-xcframework', '-framework', 'build/tmp/real/MetalANGLE.framework', '-framework', 'build/tmp/sim/MetalANGLE.framework', '-output', 'res/META-INF/robovm/ios/libs/MetalANGLE.xcframework'
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}

inputs.dir 'build/tmp/real/MetalANGLE.framework'
inputs.dir 'build/tmp/sim/MetalANGLE.framework'
outputs.dir 'res/META-INF/robovm/ios/libs/MetalANGLE.xcframework'
}

task jnigenBuildIOS(dependsOn: buildMetalANGLE) {
}

task jnigenBuild() {
}

//Dummy task to make compatible with publish
task jnigen() {
}

if(OperatingSystem.current() == OperatingSystem.MAC_OS) {
jnigenBuild.dependsOn jnigenBuildIOS
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import com.github.javaparser.JavaParser;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.expr.Name;
import com.github.javaparser.ast.expr.SimpleName;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.ast.visitor.ModifierVisitor;
import com.github.javaparser.ast.visitor.Visitable;
import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter;

public class JavaCodeGenerator {
/** This would allow us to keep exact formatting, but it's broken for FieldDeclarations for some reason. Potential related to
* https://github.com/javaparser/javaparser/issues/1601 */
private static boolean LEXICAL_PRESERVING_PRINTER = false;

private static File BASE_PROJECT_SRC = new File("../gdx-backend-robovm/src");

private static Map<String, String> IMPORT_REPLACEMENTS = new HashMap<>();
private static Map<String, String> CLASS_REPLACEMENTS = new HashMap<>();

static {
IMPORT_REPLACEMENTS.put("org.robovm.apple.opengles.EAGLContext",
"com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLContext");
IMPORT_REPLACEMENTS.put("org.robovm.apple.opengles.EAGLRenderingAPI",
"com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLRenderingAPI");

IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKView",
"com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKView");
IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewController",
"com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKViewController");
IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewControllerDelegate",
"com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKViewControllerDelegate");
IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewDelegate",
"com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKViewDelegate");
IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewDrawableColorFormat",
"com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableColorFormat");
IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewDrawableDepthFormat",
"com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableDepthFormat");
IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewDrawableMultisample",
"com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableMultisample");
IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewDrawableStencilFormat",
"com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableStencilFormat");

for (Entry<String, String> e : IMPORT_REPLACEMENTS.entrySet()) {
String o = e.getKey().substring(e.getKey().lastIndexOf('.') + 1);
String n = e.getValue().substring(e.getValue().lastIndexOf('.') + 1);
CLASS_REPLACEMENTS.put(o, n);
}
}

public static void main (String[] args) throws Exception {
search(BASE_PROJECT_SRC);
}

private static void search (File f) throws Exception {
if (f.isDirectory()) {
for (File child : f.listFiles())
search(child);
return;
}

if (!f.getName().endsWith(".java")) {
return;
}

parse(f);
}

private static void parse (File f) throws Exception {
CompilationUnit cu = StaticJavaParser.parse(f);

if (LEXICAL_PRESERVING_PRINTER) cu = LexicalPreservingPrinter.setup(cu);

cu.setBlockComment("DO NOT EDIT THIS FILE - it is machine generated");

final JavaParser javaParser = new JavaParser();

ModifierVisitor<Object> visitor = new ModifierVisitor() {
@Override
public Name visit (Name n, final Object arg) {
n = (Name)super.visit(n, arg);
if (IMPORT_REPLACEMENTS.containsKey(n.asString())) {
n = new Name(IMPORT_REPLACEMENTS.get(n.asString()));
}
return n;
}

@Override
public Visitable visit (SimpleName n, Object arg) {
n = (SimpleName)super.visit(n, arg);
if (CLASS_REPLACEMENTS.containsKey(n.asString())) {
n = new SimpleName(CLASS_REPLACEMENTS.get(n.asString()));
}
return n;
}

@Override
public Visitable visit (ClassOrInterfaceType n, final Object arg) {
n = (ClassOrInterfaceType)super.visit(n, arg);

if (CLASS_REPLACEMENTS.containsKey(n.asString())) {
n = javaParser.parseClassOrInterfaceType(CLASS_REPLACEMENTS.get(n.asString())).getResult().get();
}
return n;
}

@Override
public Visitable visit (ClassOrInterfaceDeclaration n, Object arg) {
n = (ClassOrInterfaceDeclaration)super.visit(n, arg);

String base = n.getJavadocComment().isPresent() ? n.getJavadocComment().get().getContent() : "";

n.setJavadocComment("DO NOT EDIT THIS FILE - it is machine generated\n" + base);

if (n.getNameAsString().equals("IOSViewDelegate")) {
for (MethodDeclaration m : n.getMethodsByName("willPause"))
m.remove();
}

return n;
}
};

cu.accept(visitor, null);

File out = new File("src", f.getCanonicalPath().substring(BASE_PROJECT_SRC.getCanonicalPath().length()));
try (FileWriter writer = new FileWriter(out)) {
if (LEXICAL_PRESERVING_PRINTER)
LexicalPreservingPrinter.print(cu, writer);
else
writer.append(cu.toString());
}
}
}
1 change: 1 addition & 0 deletions backends/gdx-backend-robovm-metalangle/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
POM_NAME=libGDX iOS RoboVM Backend (MetalANGLE)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<config>
<frameworks>
<framework>MetalANGLE</framework>
<framework>Metal</framework>
</frameworks>
<frameworkPaths>
<path variant="device">libs/MetalANGLE.xcframework/ios-arm64_armv7/</path>
<path variant="simulator">libs/MetalANGLE.xcframework/ios-arm64_i386_x86_64-simulator/</path>
</frameworkPaths>
</config>
Loading

0 comments on commit e03b757

Please sign in to comment.