mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-17 00:56:07 +09:00
apple m chips support wip
This commit is contained in:
14
.idea/libraries/gdx_lwjgl3_glfw_awt_macos_1_11_0_javadoc.xml
generated
Normal file
14
.idea/libraries/gdx_lwjgl3_glfw_awt_macos_1_11_0_javadoc.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="gdx-lwjgl3-glfw-awt-macos-1.11.0-javadoc">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/gdx-lwjgl3-glfw-awt-macos-1.11.0-sources.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/gdx-lwjgl3-glfw-awt-macos-1.11.0.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC>
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/gdx-lwjgl3-glfw-awt-macos-1.11.0-javadoc.jar!/" />
|
||||||
|
</JAVADOC>
|
||||||
|
<SOURCES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/gdx-lwjgl3-glfw-awt-macos-1.11.0-sources.jar!/" />
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
BIN
lib/gdx-lwjgl3-glfw-awt-macos-1.11.0-javadoc.jar
Normal file
BIN
lib/gdx-lwjgl3-glfw-awt-macos-1.11.0-javadoc.jar
Normal file
Binary file not shown.
BIN
lib/gdx-lwjgl3-glfw-awt-macos-1.11.0-sources.jar
Normal file
BIN
lib/gdx-lwjgl3-glfw-awt-macos-1.11.0-sources.jar
Normal file
Binary file not shown.
BIN
lib/gdx-lwjgl3-glfw-awt-macos-1.11.0.jar
Normal file
BIN
lib/gdx-lwjgl3-glfw-awt-macos-1.11.0.jar
Normal file
Binary file not shown.
@@ -51,6 +51,7 @@ import java.lang.reflect.Field;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static net.torvald.terrarum.TerrarumKt.*;
|
import static net.torvald.terrarum.TerrarumKt.*;
|
||||||
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The framework's Application Loader
|
* The framework's Application Loader
|
||||||
@@ -133,6 +134,8 @@ public class App implements ApplicationListener {
|
|||||||
public static String renderer = "(a super-fancy virtual photoradiator)";
|
public static String renderer = "(a super-fancy virtual photoradiator)";
|
||||||
public static String rendererVendor = "(aperture science psychovisualcomputation laboratory)";
|
public static String rendererVendor = "(aperture science psychovisualcomputation laboratory)";
|
||||||
|
|
||||||
|
public static boolean isAppleM = false;
|
||||||
|
|
||||||
public static int THREAD_COUNT = Runtime.getRuntime().availableProcessors();
|
public static int THREAD_COUNT = Runtime.getRuntime().availableProcessors();
|
||||||
public static boolean MULTITHREAD;
|
public static boolean MULTITHREAD;
|
||||||
|
|
||||||
@@ -341,6 +344,10 @@ public class App implements ApplicationListener {
|
|||||||
processorVendor = "Unknown CPU";
|
processorVendor = "Unknown CPU";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (processor.startsWith("Apple M") && Objects.equals(systemArch, "aarch64")) {
|
||||||
|
isAppleM = true;
|
||||||
|
System.out.println("Apple Proprietary "+processor+" detected; don't expect smooth sailing...");
|
||||||
|
}
|
||||||
|
|
||||||
if (!IS_DEVELOPMENT_BUILD) {
|
if (!IS_DEVELOPMENT_BUILD) {
|
||||||
var p = UnsafeHelper.INSTANCE.allocate(64);
|
var p = UnsafeHelper.INSTANCE.allocate(64);
|
||||||
@@ -437,7 +444,7 @@ public class App implements ApplicationListener {
|
|||||||
camera = new OrthographicCamera((scr.getWf()), (scr.getHf()));
|
camera = new OrthographicCamera((scr.getWf()), (scr.getHf()));
|
||||||
|
|
||||||
batch = new FlippingSpriteBatch();
|
batch = new FlippingSpriteBatch();
|
||||||
shapeRender = new ShapeRenderer();
|
shapeRender = new ShapeRenderer(5000, MacosGL32Shaders.INSTANCE.createShapeRendererShader());
|
||||||
|
|
||||||
initViewPort(scr.getWidth(), scr.getHeight());
|
initViewPort(scr.getWidth(), scr.getHeight());
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 2021-12-13.
|
* Created by minjaesong on 2021-12-13.
|
||||||
*/
|
*/
|
||||||
class FlippingSpriteBatch : SpriteBatch() {
|
class FlippingSpriteBatch(size: Int = 1000) : SpriteBatch(size, if (App.isAppleM) MacosGL32Shaders.createSpriteBatchShader() else null) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function draws the flipped version of the image by giving flipped uv-coord to the SpriteBatch
|
* This function draws the flipped version of the image by giving flipped uv-coord to the SpriteBatch
|
||||||
|
|||||||
128
src/net/torvald/terrarum/MacosGL32Shaders.kt
Normal file
128
src/net/torvald/terrarum/MacosGL32Shaders.kt
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
package net.torvald.terrarum
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2023-02-28
|
||||||
|
*/
|
||||||
|
object MacosGL32Shaders {
|
||||||
|
fun createSpriteBatchShader(): ShaderProgram {
|
||||||
|
val vertexShader = """
|
||||||
|
#version 150
|
||||||
|
in vec4 ${ShaderProgram.POSITION_ATTRIBUTE};
|
||||||
|
in vec4 ${ShaderProgram.COLOR_ATTRIBUTE};
|
||||||
|
in vec2 ${ShaderProgram.TEXCOORD_ATTRIBUTE}0;
|
||||||
|
uniform mat4 u_projTrans;
|
||||||
|
out vec4 v_color;
|
||||||
|
out vec2 v_texCoords;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
v_color = ${ShaderProgram.COLOR_ATTRIBUTE};
|
||||||
|
v_color.a = v_color.a * (255.0/254.0);
|
||||||
|
v_texCoords = ${ShaderProgram.TEXCOORD_ATTRIBUTE}0;
|
||||||
|
gl_Position = u_projTrans * ${ShaderProgram.POSITION_ATTRIBUTE};
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
val fragmentShader = """
|
||||||
|
#version 150
|
||||||
|
#ifdef GL_ES
|
||||||
|
#define LOWP lowp
|
||||||
|
precision mediump float;
|
||||||
|
#else
|
||||||
|
#define LOWP
|
||||||
|
#endif
|
||||||
|
in LOWP vec4 v_color;
|
||||||
|
in vec2 v_texCoords;
|
||||||
|
uniform sampler2D u_texture;
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
fragColor = v_color * texture(u_texture, v_texCoords);
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
return App.loadShaderInline(vertexShader, fragmentShader)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun createShapeRendererShader(): ShaderProgram {
|
||||||
|
return App.loadShaderInline(createShadeRendererVertexShader(), createShapeRendererFragmentShader())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun createShadeRendererVertexShader(hasNormals: Boolean = false, hasColors: Boolean = true, numTexCoords: Int = 0): String {
|
||||||
|
var shader = ("""
|
||||||
|
#version 150
|
||||||
|
in vec4 ${ShaderProgram.POSITION_ATTRIBUTE};
|
||||||
|
|
||||||
|
""".trimIndent()
|
||||||
|
+ (if (hasNormals) """
|
||||||
|
in vec3 ${ShaderProgram.NORMAL_ATTRIBUTE};
|
||||||
|
|
||||||
|
""".trimIndent()
|
||||||
|
else "")
|
||||||
|
+ if (hasColors) """
|
||||||
|
in vec4 ${ShaderProgram.COLOR_ATTRIBUTE};
|
||||||
|
|
||||||
|
""".trimIndent()
|
||||||
|
else "")
|
||||||
|
for (i in 0 until numTexCoords) {
|
||||||
|
shader += """
|
||||||
|
in vec2 ${ShaderProgram.TEXCOORD_ATTRIBUTE}$i;
|
||||||
|
|
||||||
|
""".trimIndent()
|
||||||
|
}
|
||||||
|
shader += """
|
||||||
|
uniform mat4 u_projModelView;
|
||||||
|
${if (hasColors) "in vec4 v_col;\n" else ""}
|
||||||
|
""".trimIndent()
|
||||||
|
for (i in 0 until numTexCoords) {
|
||||||
|
shader += "in vec2 v_tex$i;\n"
|
||||||
|
}
|
||||||
|
shader += """void main() {
|
||||||
|
gl_Position = u_projModelView * ${ShaderProgram.POSITION_ATTRIBUTE};
|
||||||
|
"""
|
||||||
|
if (hasColors) {
|
||||||
|
shader += """ v_col = ${ShaderProgram.COLOR_ATTRIBUTE};
|
||||||
|
v_col.a *= 255.0 / 254.0;
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
for (i in 0 until numTexCoords) {
|
||||||
|
shader += """ v_tex$i = ${ShaderProgram.TEXCOORD_ATTRIBUTE}$i;
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
shader += """ gl_PointSize = 1.0;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
return shader
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createShapeRendererFragmentShader(hasNormals: Boolean = false, hasColors: Boolean = true, numTexCoords: Int = 0): String {
|
||||||
|
var shader = """
|
||||||
|
#version 150
|
||||||
|
#ifdef GL_ES
|
||||||
|
precision mediump float;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
""".trimIndent()
|
||||||
|
if (hasColors) shader += "in vec4 v_col;\n"
|
||||||
|
for (i in 0 until numTexCoords) {
|
||||||
|
shader += "in vec2 v_tex$i;\n"
|
||||||
|
shader += "uniform sampler2D u_sampler$i;\n"
|
||||||
|
}
|
||||||
|
shader += """void main() {
|
||||||
|
gl_FragColor = ${if (hasColors) "v_col" else "vec4(1, 1, 1, 1)"}"""
|
||||||
|
if (numTexCoords > 0) shader += " * "
|
||||||
|
for (i in 0 until numTexCoords) {
|
||||||
|
shader += if (i == numTexCoords - 1) {
|
||||||
|
" texture2D(u_sampler$i, v_tex$i)"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
" texture2D(u_sampler$i, v_tex$i) *"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shader += ";\n}"
|
||||||
|
return shader
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user