Merged changes from original repo and modified some web port releated files
This commit is contained in:
@@ -24,8 +24,6 @@ package com.watabou.glwrap;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.watabou.utils.DeviceCompat;
|
||||
|
||||
public class Attribute {
|
||||
|
||||
@@ -38,22 +36,20 @@ public class Attribute {
|
||||
public int location() {
|
||||
return location;
|
||||
}
|
||||
|
||||
private static final GL20 activeGL = (DeviceCompat.isWeb()) ? Gdx.gl30 : Gdx.gl;
|
||||
|
||||
public void enable() {
|
||||
activeGL.glEnableVertexAttribArray( location );
|
||||
Gdx.gl.glEnableVertexAttribArray( location );
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
activeGL.glDisableVertexAttribArray( location );
|
||||
Gdx.gl.glDisableVertexAttribArray( location );
|
||||
}
|
||||
|
||||
public void vertexPointer( int size, int stride, FloatBuffer ptr ) {
|
||||
activeGL.glVertexAttribPointer( location, size, GL20.GL_FLOAT, false, stride * 4, ptr );
|
||||
Gdx.gl.glVertexAttribPointer( location, size, Gdx.gl.GL_FLOAT, false, stride * 4, ptr );
|
||||
}
|
||||
|
||||
public void vertexBuffer( int size, int stride, int offset) {
|
||||
activeGL.glVertexAttribPointer( location, size, GL20.GL_FLOAT, false, stride * 4, offset * 4 );
|
||||
Gdx.gl.glVertexAttribPointer(location, size, Gdx.gl.GL_FLOAT, false, stride * 4, offset * 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ package com.watabou.noosa;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.watabou.utils.DeviceCompat;
|
||||
import com.watabou.glscripts.Script;
|
||||
import com.watabou.glwrap.Attribute;
|
||||
import com.watabou.glwrap.Quad;
|
||||
@@ -36,9 +35,9 @@ import java.nio.FloatBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
public class NoosaScript extends Script {
|
||||
|
||||
private static final GL20 activeGL = (DeviceCompat.isWeb()) ? Gdx.gl30 : Gdx.gl20;
|
||||
|
||||
private static final GL20 activeGL = (DeviceCompat.isWeb()) ? Gdx.gl30 : Gdx.gl20;
|
||||
|
||||
public Uniform uCamera;
|
||||
public Uniform uModel;
|
||||
public Uniform uTex;
|
||||
@@ -65,13 +64,14 @@ public class NoosaScript extends Script {
|
||||
|
||||
Quad.setupIndices();
|
||||
Quad.bindIndices();
|
||||
|
||||
|
||||
if (DeviceCompat.isWeb()) {
|
||||
vertexBufferId = Gdx.gl30.glGenBuffer();
|
||||
Gdx.gl30.glBindBuffer(Gdx.gl30.GL_ARRAY_BUFFER, vertexBufferId);
|
||||
Gdx.gl30.glBufferData(Gdx.gl30.GL_ARRAY_BUFFER, 16384, null, Gdx.gl30.GL_DYNAMIC_DRAW);
|
||||
Gdx.gl30.glBindBuffer(Gdx.gl30.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,6 +85,7 @@ public class NoosaScript extends Script {
|
||||
}
|
||||
|
||||
public void drawElements( FloatBuffer vertices, ShortBuffer indices, int size ) {
|
||||
|
||||
if (DeviceCompat.isWeb()) {
|
||||
activeGL.glBindBuffer(GL20.GL_ARRAY_BUFFER, vertexBufferId);
|
||||
((Buffer)vertices).position( 0 );
|
||||
@@ -111,6 +112,7 @@ public class NoosaScript extends Script {
|
||||
}
|
||||
|
||||
public void drawQuad( FloatBuffer vertices ) {
|
||||
|
||||
if (DeviceCompat.isWeb()) {
|
||||
activeGL.glBindBuffer(GL20.GL_ARRAY_BUFFER, vertexBufferId);
|
||||
((Buffer)vertices).position( 0 );
|
||||
@@ -126,7 +128,7 @@ public class NoosaScript extends Script {
|
||||
|
||||
((Buffer)vertices).position( 2 );
|
||||
aUV.vertexPointer( 2, 4, vertices );
|
||||
|
||||
|
||||
Gdx.gl20.glDrawElements( Gdx.gl20.GL_TRIANGLES, Quad.SIZE, Gdx.gl20.GL_UNSIGNED_SHORT, 0 );
|
||||
}
|
||||
}
|
||||
@@ -142,7 +144,7 @@ public class NoosaScript extends Script {
|
||||
|
||||
buffer.release();
|
||||
|
||||
activeGL.glDrawElements( GL20.GL_TRIANGLES, Quad.SIZE, GL20.GL_UNSIGNED_SHORT, 0 );
|
||||
Gdx.gl20.glDrawElements( Gdx.gl20.GL_TRIANGLES, Quad.SIZE, Gdx.gl20.GL_UNSIGNED_SHORT, 0 );
|
||||
}
|
||||
|
||||
public void drawQuadSet( FloatBuffer vertices, int size ) {
|
||||
@@ -168,9 +170,10 @@ public class NoosaScript extends Script {
|
||||
|
||||
((Buffer)vertices).position( 2 );
|
||||
aUV.vertexPointer( 2, 4, vertices );
|
||||
|
||||
|
||||
Gdx.gl20.glDrawElements( Gdx.gl20.GL_TRIANGLES, Quad.SIZE * size, Gdx.gl20.GL_UNSIGNED_SHORT, 0 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void drawQuadSet( Vertexbuffer buffer, int length, int offset ){
|
||||
@@ -188,7 +191,7 @@ public class NoosaScript extends Script {
|
||||
|
||||
buffer.release();
|
||||
|
||||
activeGL.glDrawElements( GL20.GL_TRIANGLES, Quad.SIZE * length, GL20.GL_UNSIGNED_SHORT, Quad.SIZE * Short.SIZE/8 * offset );
|
||||
Gdx.gl20.glDrawElements( Gdx.gl20.GL_TRIANGLES, Quad.SIZE * length, Gdx.gl20.GL_UNSIGNED_SHORT, Quad.SIZE * Short.SIZE/8 * offset );
|
||||
}
|
||||
|
||||
public void lighting( float rm, float gm, float bm, float am, float ra, float ga, float ba, float aa ) {
|
||||
@@ -209,7 +212,7 @@ public class NoosaScript extends Script {
|
||||
uCamera.valueM4( camera.matrix );
|
||||
|
||||
if (!camera.fullScreen) {
|
||||
activeGL.glEnable( GL20.GL_SCISSOR_TEST );
|
||||
Gdx.gl20.glEnable( Gdx.gl20.GL_SCISSOR_TEST );
|
||||
|
||||
//This fixes pixel scaling issues on some hidpi displays (mainly on macOS)
|
||||
// because for some reason all other openGL operations work on virtual pixels
|
||||
@@ -217,13 +220,13 @@ public class NoosaScript extends Script {
|
||||
float xScale = DeviceCompat.getRealPixelScaleX();
|
||||
float yScale = DeviceCompat.getRealPixelScaleY();
|
||||
|
||||
activeGL.glScissor(
|
||||
Gdx.gl20.glScissor(
|
||||
Math.round(camera.x * xScale),
|
||||
Math.round((Game.height - camera.screenHeight - camera.y) * yScale),
|
||||
Math.round(camera.screenWidth * xScale),
|
||||
Math.round(camera.screenHeight * yScale));
|
||||
} else {
|
||||
activeGL.glDisable( GL20.GL_SCISSOR_TEST );
|
||||
Gdx.gl20.glDisable( Gdx.gl20.GL_SCISSOR_TEST );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,41 +240,41 @@ public class NoosaScript extends Script {
|
||||
return SHADER;
|
||||
}
|
||||
|
||||
private static String SHADER;
|
||||
private static final String SHADER;
|
||||
static {
|
||||
if (DeviceCompat.isWeb()) {
|
||||
SHADER =
|
||||
//vertex shader
|
||||
"#version 300 es\n" +
|
||||
"uniform mat4 uCamera;\n" +
|
||||
"uniform mat4 uModel;\n" +
|
||||
"in vec4 aXYZW;\n" +
|
||||
"in vec2 aUV;\n" +
|
||||
"out vec2 vUV;\n" +
|
||||
"void main() {\n" +
|
||||
" gl_Position = uCamera * uModel * aXYZW;\n" +
|
||||
" vUV = aUV;\n" +
|
||||
"}\n" +
|
||||
if (DeviceCompat.isWeb()) {
|
||||
SHADER =
|
||||
//vertex shader
|
||||
"#version 300 es\n" +
|
||||
"uniform mat4 uCamera;\n" +
|
||||
"uniform mat4 uModel;\n" +
|
||||
"in vec4 aXYZW;\n" +
|
||||
"in vec2 aUV;\n" +
|
||||
"out vec2 vUV;\n" +
|
||||
"void main() {\n" +
|
||||
" gl_Position = uCamera * uModel * aXYZW;\n" +
|
||||
" vUV = aUV;\n" +
|
||||
"}\n" +
|
||||
|
||||
//this symbol separates the vertex and fragment shaders (see Script.compile)
|
||||
"//\n" +
|
||||
|
||||
//fragment shader
|
||||
//preprocessor directives let us define precision on GLES platforms, and ignore it elsewhere
|
||||
//this symbol separates the vertex and fragment shaders (see Script.compile)
|
||||
"//\n" +
|
||||
|
||||
//fragment shader
|
||||
//preprocessor directives let us define precision on GLES platforms, and ignore it elsewhere
|
||||
"#version 300 es\n" +
|
||||
"#ifdef GL_ES\n" +
|
||||
" precision mediump float;\n" +
|
||||
"#endif\n" +
|
||||
"in vec2 vUV;\n" +
|
||||
"uniform sampler2D uTex;\n" +
|
||||
"uniform vec4 uColorM;\n" +
|
||||
"uniform vec4 uColorA;\n" +
|
||||
"#ifdef GL_ES\n" +
|
||||
" precision mediump float;\n" +
|
||||
"#endif\n" +
|
||||
"in vec2 vUV;\n" +
|
||||
"uniform sampler2D uTex;\n" +
|
||||
"uniform vec4 uColorM;\n" +
|
||||
"uniform vec4 uColorA;\n" +
|
||||
"out vec4 fragColor;\n" +
|
||||
"void main() {\n" +
|
||||
" fragColor = texture( uTex, vUV ) * uColorM + uColorA;\n" +
|
||||
"}\n";
|
||||
} else {
|
||||
SHADER =
|
||||
"void main() {\n" +
|
||||
" fragColor = texture( uTex, vUV ) * uColorM + uColorA;\n" +
|
||||
"}\n";
|
||||
} else {
|
||||
SHADER =
|
||||
//vertex shader
|
||||
"uniform mat4 uCamera;\n" +
|
||||
"uniform mat4 uModel;\n" +
|
||||
@@ -298,6 +301,6 @@ public class NoosaScript extends Script {
|
||||
"void main() {\n" +
|
||||
" gl_FragColor = texture2D( uTex, vUV ) * uColorM + uColorA;\n" +
|
||||
"}\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,40 +45,40 @@ public class NoosaScriptNoLighting extends NoosaScript {
|
||||
return SHADER;
|
||||
}
|
||||
|
||||
private static String SHADER;
|
||||
|
||||
private static final String SHADER;
|
||||
|
||||
static {
|
||||
if (DeviceCompat.isWeb()) {
|
||||
SHADER =
|
||||
//vertex shader
|
||||
if (DeviceCompat.isWeb()) {
|
||||
SHADER =
|
||||
//vertex shader
|
||||
"#version 300 es\n" +
|
||||
"uniform mat4 uCamera;\n" +
|
||||
"uniform mat4 uModel;\n" +
|
||||
"in vec4 aXYZW;\n" +
|
||||
"in vec2 aUV;\n" +
|
||||
"out vec2 vUV;\n" +
|
||||
"void main() {\n" +
|
||||
" gl_Position = uCamera * uModel * aXYZW;\n" +
|
||||
" vUV = aUV;\n" +
|
||||
"}\n" +
|
||||
"uniform mat4 uCamera;\n" +
|
||||
"uniform mat4 uModel;\n" +
|
||||
"in vec4 aXYZW;\n" +
|
||||
"in vec2 aUV;\n" +
|
||||
"out vec2 vUV;\n" +
|
||||
"void main() {\n" +
|
||||
" gl_Position = uCamera * uModel * aXYZW;\n" +
|
||||
" vUV = aUV;\n" +
|
||||
"}\n" +
|
||||
|
||||
//this symbol separates the vertex and fragment shaders (see Script.compile)
|
||||
"//\n" +
|
||||
//this symbol separates the vertex and fragment shaders (see Script.compile)
|
||||
"//\n" +
|
||||
|
||||
//fragment shader
|
||||
//preprocessor directives let us define precision on GLES platforms, and ignore it elsewhere
|
||||
//fragment shader
|
||||
//preprocessor directives let us define precision on GLES platforms, and ignore $
|
||||
"#version 300 es\n" +
|
||||
"#ifdef GL_ES\n" +
|
||||
" precision mediump float;\n" +
|
||||
"#endif\n" +
|
||||
"in vec2 vUV;\n" +
|
||||
"uniform sampler2D uTex;\n" +
|
||||
"#ifdef GL_ES\n" +
|
||||
" precision mediump float;\n" +
|
||||
"#endif\n" +
|
||||
"in vec2 vUV;\n" +
|
||||
"uniform sampler2D uTex;\n" +
|
||||
"out vec4 fragColor;\n" +
|
||||
"void main() {\n" +
|
||||
" fragColor = texture( uTex, vUV );\n" +
|
||||
"}\n";
|
||||
} else {
|
||||
SHADER =
|
||||
"void main() {\n" +
|
||||
" fragColor = texture( uTex, vUV );\n" +
|
||||
"}\n";
|
||||
} else {
|
||||
SHADER =
|
||||
//vertex shader
|
||||
"uniform mat4 uCamera;\n" +
|
||||
"uniform mat4 uModel;\n" +
|
||||
|
||||
@@ -79,7 +79,7 @@ public class RenderedText extends Image {
|
||||
private static final ArrayList<Character> alreadyReported = new ArrayList<>();
|
||||
|
||||
private synchronized void measure(){
|
||||
|
||||
|
||||
if (!DeviceCompat.isWeb()) {
|
||||
if (Thread.currentThread().getName().equals("SHPD Actor Thread")){
|
||||
throw new RuntimeException("Text measured from the actor thread!");
|
||||
|
||||
@@ -198,6 +198,7 @@ public class Tilemap extends Visual {
|
||||
public void draw() {
|
||||
|
||||
super.draw();
|
||||
|
||||
if (DeviceCompat.isWeb()) {
|
||||
fullUpdate = true;
|
||||
}
|
||||
|
||||
@@ -487,13 +487,13 @@ public class Bundle {
|
||||
//useful to turn this off for save data debugging.
|
||||
private static final boolean compressByDefault;
|
||||
|
||||
static {
|
||||
if (DeviceCompat.isWeb()) {
|
||||
compressByDefault = false;
|
||||
} else {
|
||||
compressByDefault = true;
|
||||
}
|
||||
}
|
||||
static {
|
||||
if (DeviceCompat.isWeb()) {
|
||||
compressByDefault = false;
|
||||
} else {
|
||||
compressByDefault = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static final int GZIP_BUFFER = 1024*4; //4 kb
|
||||
|
||||
|
||||
@@ -50,9 +50,9 @@ public class DeviceCompat {
|
||||
Gdx.app.getType() == Application.ApplicationType.WebGL;
|
||||
}
|
||||
|
||||
public static boolean isWeb(){
|
||||
public static boolean isWeb(){
|
||||
return Gdx.app.getType() == Application.ApplicationType.WebGL;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasHardKeyboard(){
|
||||
return Gdx.input.isPeripheralAvailable(Input.Peripheral.HardwareKeyboard);
|
||||
|
||||
@@ -53,9 +53,9 @@ public abstract class PlatformSupport {
|
||||
);
|
||||
}
|
||||
|
||||
//returns a display cutout (if one is present) in device pixels, or null is none is present
|
||||
//returns a display cutout (if one is present) in device pixels, or empty if none is present
|
||||
public RectF getDisplayCutout(){
|
||||
return null;
|
||||
return new RectF();
|
||||
}
|
||||
|
||||
public abstract void updateSystemUI();
|
||||
|
||||
Reference in New Issue
Block a user