gdx-backend-jtransc
gdx-backend-jtransc copied to clipboard
Support flash/adobe air target
There is already some work here:
https://github.com/jtransc/gdx-backend-jtransc/blob/master/gdx-backend-jtransc/src/com/jtransc/media/limelibgdx/flash/FlashGL20.java https://github.com/jtransc/gdx-backend-jtransc/blob/master/gdx-backend-jtransc/src/com/jtransc/media/limelibgdx/StateGL20.java
The most complicated thing would be shaders. I have three possible options:
1st option:
Provide a function that with a hash (md5 for example) of the shader string allows to provide a mapped agal shader assembler.
2nd option:
Support glsl preprocessor and add a #ifdef FLASH that allows to provide agal bytecode directly.
3rd option:
Fully parse glsl and generate agal bytecode.
Should be possible to port with some C++ to JVM a GLSL parser and then convert it to agal. I think that adobe already did that converting a C++ glsl parser to flash.
Started the 3rd option. Why doing this at all?
- Flash allows to display stuff on older browsers not supporting WebGL or having a fast javascript engine
- Also generating SWF allows to embed here or from here other legacy flash content
- Adobe AIR allows to create mobile applications, including iOS directly on windows
Enabling other stuff:
- Generating an AST for shaders and having a state-based GL implementation will allow to create other targets easily: directx without angle, vulkan, metal and other APIs.
- Will allow to create a pure software-based GlSL interpreter, allowing to debug it. With jtransc-dynarec that could be compiled to native instead of interpreted.
- Would allow to create a headless pure-java GL implementation.
I'm already generating AGAL shaders. It will require some more work, but most of the work for simple shaders is already in.
I forgot to mention that this would allow to use Kha too: http://kha.tech/ That could potentially allow to target consoles and unity.
I already generate binary AGAL code. Right now it fails because I have to avoid using updating varyings (I will have to use a temp instead):
C:\projects\jtransc\jtransc-examples\libgdx\cuboc>gradle runSwf
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:startScripts UP-TO-DATE
:distTar UP-TO-DATE
:distZip UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE
:runSwf
JTranscConsole_.hx:11: MyFileHandle: data/title.png
JTranscConsole_.hx:11: JTranscSyncIOLimeImpl.open: assets/data/title.png || assets/data/title.png
JTranscConsole_.hx:11: ImageDecoder.Format: Length:19057: Header:-119,80,78,71
JTranscConsole_.hx:11: Format: PNG
JTranscConsole_.hx:11: Decoding time: 2423.0
JTranscConsole_.hx:11: StateGL20.glPixelStorei(pname = [3317], param = [1])
JTranscConsole_.hx:11: FlashShader(Vertex).setSource('attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
uniform mat4 u_projTrans;
varying vec4 v_color;
varying vec2 v_texCoords;
void main()
{
v_color = a_color;
v_color.a = v_color.a * (255.0/254.0);
v_texCoords = a_texCoord0;
gl_Position = u_projTrans * a_position;
}
')
JTranscConsole_.hx:11: FlashShader.compile
JTranscConsole_.hx:11: FlashShader(Fragment).setSource('#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif
varying LOWP vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
void main()
{
gl_FragColor = v_color * texture2D(u_texture, v_texCoords);
}')
JTranscConsole_.hx:11: FlashShader.compile
JTranscConsole_.hx:11: FlashProgram().vertex:
JTranscConsole_.hx:11: - mov v1, va0
JTranscConsole_.hx:11: - mul v1.w, v1.w, vc1.x
JTranscConsole_.hx:11: - mov v0, va1
JTranscConsole_.hx:11: - mul op, vc2, va2
JTranscConsole_.hx:11: FlashProgram().fragment:
JTranscConsole_.hx:11: - tex ft0, v0, fs0 <2d,linear,repeat,mipnearest>
JTranscConsole_.hx:11: - mul oc, v1, ft0
JTranscConsole_.hx:11: FlashProgram().uniforms:
JTranscConsole_.hx:11: - u_texture : AllocatedLanes(u_texture,sampler2D,0,0-4)
JTranscConsole_.hx:11: - u_projTrans : AllocatedLanes(u_projTrans,mat4,2,0-4)
JTranscConsole_.hx:11: FlashProgram().attributes:
JTranscConsole_.hx:11: - a_position : AllocatedLanes(a_position,vec4,2,0-4)
JTranscConsole_.hx:11: - a_texCoord0 : AllocatedLanes(a_texCoord0,vec2,1,0-4)
JTranscConsole_.hx:11: - a_color : AllocatedLanes(a_color,vec4,0,0-4)
JTranscConsole_.hx:11: FlashProgram().constants:
JTranscConsole_.hx:11: - #CST#1.0039370078740157 = 1.0039370078740157 : AllocatedLanes(#CST#1.0039370078740157,float,1,0-1)
Error: Error #3644: AGAL validation failed: Varying registers can only be read in fragment programs for source
operand 1 at token 2 of vertex program.
at flash.display3D::Program3D/upload()
at com.jtransc.media.limelibgdx.flash::FlashStage3DGL20_FlashProgram_/link__V()[src/com/jtransc/media/limelibgdx/flash/FlashStage3DGL20_FlashProgram_.hx:223]
at com.jtransc.media.limelibgdx::StateGL20_/glLinkProgram_I_V()[src/com/jtransc/media/limelibgdx/StateGL20_.hx:1894]
at com.badlogic.gdx.graphics.glutils::ShaderProgram_/linkProgram_I_I()[src/com/badlogic/gdx/graphics/glutils/ShaderProgram_.hx:356]
at com.badlogic.gdx.graphics.glutils::ShaderProgram_/compileShaders_Ljava_lang_String_Ljava_lang_String__V()[src/com/badlogic/gdx/graphics/glutils/ShaderProgram_.hx:233]
at com.badlogic.gdx.graphics.glutils::ShaderProgram_/com_badlogic_gdx_graphics_glutils_ShaderProgram_init__Ljava_lang_String_Ljava_lang_String__V()[src/com/badlogic/gdx/graphics/glutils/ShaderProgram_.hx:173]
at com.badlogic.gdx.graphics.g2d::SpriteBatch_$/createDefaultShader__Lcom_badlogic_gdx_graphics_glutils_ShaderProgram_()[src/com/badlogic/gdx/graphics/g2d/SpriteBatch_.hx:280]
at com.badlogic.gdx.graphics.g2d::SpriteBatch_/com_badlogic_gdx_graphics_g2d_SpriteBatch_init__ILcom_badlogic_gdx_graphics_glutils_ShaderProgram__V()[src/com/badlogic/gdx/graphics/g2d/SpriteBatch_.hx:242]
at com.badlogic.gdx.graphics.g2d::SpriteBatch_/com_badlogic_gdx_graphics_g2d_SpriteBatch_init___V()[src/com/badlogic/gdx/graphics/g2d/SpriteBatch_.hx:31]
at com.badlogic.cubocy.screens::MainMenu_/show__V()[src/com/badlogic/cubocy/screens/MainMenu_.hx:43]
at com.badlogic.gdx::Game_/setScreen_Lcom_badlogic_gdx_Screen__V()[src/com/badlogic/gdx/Game_.hx:73]
at com.badlogic.cubocy::Cubocy_/create__V()[src/com/badlogic/cubocy/Cubocy_.hx:21]
at com.jtransc.media.limelibgdx::GdxApplicationAdapter_/create__V()[src/com/jtransc/media/limelibgdx/GdxApplicationAdapter_.hx:484]
at com.jtransc.media.limelibgdx::LimeApplication_/create__V()[src/com/jtransc/media/limelibgdx/LimeApplication_.hx:246]
at MethodInfo-523()[src/HaxeLimeGdxApplication.hx:121]