Skip to content

Conversation

@madrazo
Copy link
Contributor

@madrazo madrazo commented Sep 7, 2017

Currently, I'm getting a GLES3 context on Android without any changes.
I am enabling GLES3 hint on Angle which should be safe on Desktop, and
it should return a GLES2 context if not available anyway. EDIT: Added a fallback to try again with GLES2 if renderer fails with GLES3.

I have added some funcions in nme.gl.Utils to detect "isGLES3compat()" (checks for
GLES>3.0, WebGL>=2.0, or desktop OpenGL>=3.3), ""isGLES()", and helper functions to write source shader code compatible with GLES3 and GLES2 shader languages. (IN(n), OUT(), OUT_COLOR("color"), HEADER())

On nme_gl_shader_source (OGLExport.cpp), there was a problem that a string was added for GLESshaders.
Now it checks if the shader starts with #v (#version) so it does not includes
that string, and now we add it form the HEADER function in nme.gl.Utils

Implemented VertexArrays "create" and "binding"
Even GLES3 is enabled it shouldn't affect current behaivor but may need
testing. Added NME_NO_GLES3COMPAT flag if revert is needed (can be added as compileflag on ToolkitBuild.xml).

please check sample
https://github.com/madrazo/nme-opengl-tutorials/tree/master/tutorial02_red_triangle

I have tested it on Windows with and without NME_NO_ANGLE and with (and without) forcing the isGLES3compat to false and initial hint with 2 and 3.

Note that the user should be responsible for checking for isGLES3compat(), if still wants to be compatible with GLES2.

Extra: Android data on the availability of GLES3 (over 60% in GLES3.0+GLES3.1)

Related issue: #162

Currently, I'm getting a GLES3 context on Android without any changes.
I am enabling GLES3 hint on Angle which should be safe on Desktop, and
it should return a GLES2 context if not available anyway.  I have added
some funcions in nme.gl.Utils to detect "isGLES3compat" (checks for
GLES>3.0 or desktop OpenGL>=3.3) and to write source shader code
compatible with GLES3 and GLES2 shader languages.
On nme_gl_shader_source, some string was added for gles shaders. Now it
checks if the shader starts with #v (#version) so it does not includes
that string, and now we add it form the HEADER function in nme.gl.Utils
Implemented VertexArrays
Even GLES3 is enabled it shouldn't affect current behaivor but may need
testing.  Added NME_NO_GLES3COMPAT flag if revert is needed.

please check sample
https://github.com/madrazo/nme-opengl-tutorials/tree/master/tutorial02_red_triangle
@madrazo
Copy link
Contributor Author

madrazo commented Sep 8, 2017

I had not considered Emscripten, but here says

Even if your application does not need any WebGL 2/OpenGL ES 3 features, consider porting the application to run on WebGL 2, because JavaScript side performance in WebGL 2 has been optimized to generate no temporary garbage, which has been observed to give a solid 3-7% speed improvement, as well as reducing potential stuttering at render time. To enable these optimizations, build with the linker flag -s USE_WEBGL2=1 and make sure to create a WebGL 2 context at GL startup time (OpenGL ES 3 context if using EGL).

Edit: "isGLES3compat()" checks for WebGL version >=2.0

look for WebGL version in nme.gl.Utils and set isGLES3compat if its
WebGL 2.0
In Angle, tries GLES3. If it fails, tries again with major=2 (GLES2)
@madrazo
Copy link
Contributor Author

madrazo commented Sep 11, 2017

this is not working on WinRT

Fixes an infinite loop when Renderer using GLES3 Fails
@madrazo
Copy link
Contributor Author

madrazo commented Sep 11, 2017

Actually I have a modification on SDL to make this work....

Comment lines [these lines] of SDL_render_gles2.c, funtion GLES2_CreateRenderer

window_flags = SDL_GetWindowFlags(window);
if (!(window_flags & SDL_WINDOW_OPENGL) ||
    profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {

    changed_window = SDL_TRUE;
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);

    if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
        goto error;
    }
}

Do not include HEADER if already includes a #v (#version). Fix IN()
macro for Fragment Shader
madrazo added a commit to madrazo/nme-opengl-tutorials that referenced this pull request Sep 13, 2017
@hughsando
Copy link
Member

Does this PR need the SDL changes to work?

@madrazo
Copy link
Contributor Author

madrazo commented Oct 13, 2017

Yes it does, otherwise you get a GLES2 context

I opened a SDL bugzilla here:
https://bugzilla.libsdl.org/show_bug.cgi?id=3821

At least for Angle. I should test in other targets (Android, Emscripten)

Also, I'm thinking on add a GL3.hx for the GLES3 functions intead of GL.hx so it's more clear the difference between APIs

@madrazo
Copy link
Contributor Author

madrazo commented Oct 17, 2017

Test, added a debug text in tutorial02 to show if it's GLES3 compatible:

  • Android OK, shows gles 3 compatible on either case
  • Angle (Windows): gles 3 with modifieded SDL, gles 2 without
  • JSPrime: ndll won't compile because needs this define. DisplayingABitmap runs normally after that. Tutorial02 doesn't run. Has error:
Source/Main.hx:56: characters 31-51 : Class<nme.gl.GL> has no field createVertexArray
Source/Main.hx:57: characters 13-31 : Class<nme.gl.GL> has no field bindVertexArray
D:\\nme\src/nme/gl/Utils.hx:23: characters 21-37 : Class<nme.gl.GL> has no field createProgram
D:\\nme\src/nme/gl/Utils.hx:8: characters 20-35 : Class<nme.gl.GL> has no field createShader
D:\\nme\src/nme/gl/Utils.hx:9: characters 7-22 : Class<nme.gl.GL> has no field shaderSource
D:\\nme\src/nme/gl/Utils.hx:10: characters 7-23 : Class<nme.gl.GL> has no field compileShader
D:\\nme\src/nme/gl/Utils.hx:11: characters 11-32 : Class<nme.gl.GL> has no field getShaderParameter
D:\\nme\src/nme/gl/Utils.hx:14: characters 20-39 : Class<nme.gl.GL> has no field getShaderInfoLog
D:\\nme\src/nme/gl/Utils.hx:31: characters 7-22 : Class<nme.gl.GL> has no field attachShader
D:\\nme\src/nme/gl/Utils.hx:32: characters 7-22 : Class<nme.gl.GL> has no field attachShader
D:\\nme\src/nme/gl/Utils.hx:33: characters 7-21 : Class<nme.gl.GL> has no field linkProgram
D:\\nme\src/nme/gl/Utils.hx:34: characters 11-33 : Class<nme.gl.GL> has no field getProgramParameter
D:\\nme\src/nme/gl/Utils.hx:36: characters 23-43 : Class<nme.gl.GL> has no field getProgramInfoLog
Source/Main.hx:70: characters 28-43 : Class<nme.gl.GL> has no field createBuffer
Source/Main.hx:71: characters 9-22 : Class<nme.gl.GL> has no field bindBuffer
Source/Main.hx:72: characters 9-22 : Class<nme.gl.GL> has no field bufferData
Source/Main.hx:77: characters 23-43 : Class<nme.gl.GL> has no field getAttribLocation
Source/Main.hx:87: characters 13-26 : Class<nme.gl.GL> has no field useProgram
Source/Main.hx:90: characters 13-39 : Class<nme.gl.GL> has no field enableVertexAttribArray
Source/Main.hx:91: characters 13-26 : Class<nme.gl.GL> has no field bindBuffer
Source/Main.hx:92: characters 13-35 : Class<nme.gl.GL> has no field vertexAttribPointer
Source/Main.hx:102: characters 13-26 : Class<nme.gl.GL> has no field drawArrays
Source/Main.hx:103: characters 13-40 : Class<nme.gl.GL> has no field disableVertexAttribArray
D:\\nme\src/nme/gl/GLObject.hx:31: characters 39-49 : Class<nme.gl.GL> has no field version
D:\\nme\src/nme/gl/GLObject.hx:56: characters 44-51 : Class<nme.gl.GL> has no field load

@madrazo
Copy link
Contributor Author

madrazo commented Oct 19, 2017

Here is the SDL change native-toolkit/libsdl#11
I'm thinking to resend this PR with the emscripten compile fixed

madrazo added a commit to madrazo/nme that referenced this pull request Oct 20, 2017
merged and improved from haxenme#496 .
Added GL3.hx for GLES3 functions.
It is only activated for windows and android because needs testing on
other targets (ios, linux, mac, emscripten). Windows angle needs
native-toolkit/libsdl#11 , otherwise gets a GLES2
context.
Tested with
https://github.com/madrazo/nme-opengl-tutorials/tree/master/tutorial02_red_triangle
@madrazo madrazo mentioned this pull request Oct 20, 2017
@madrazo
Copy link
Contributor Author

madrazo commented Oct 20, 2017

closed for #517

@madrazo madrazo closed this Oct 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants