OpenGL ES2.0 module coming!

Monkey Forums/Monkey Programming/OpenGL ES2.0 module coming!

marksibly(Posted 2012) [#1]
Hi,

The GLES20 module is now mostly going - demo here:

http://www.blitzbasic.com/tmp/gles20cube/MonkeyGame.html

Hold mouse at top of page to zoom in, bottom of page to zoom out.

The module works with glfw, html5, android and ios.

A few notes:

* GLES20 requires Gingerbread (2.3 I think) on Android, which means it wont work on a lot of phones out there, eg: my Samsung Galaxy S - boohoo! On IOS, it requires 3GS, and on Windows you'll need GL2.1 or better. This IMO means that a GLES11 engine is still a viable project. As it'll work on a far greater range of devices - except for html5 of course.

* GLES20 is a lot more work to get going than GLES11. There is no fixed function stuff, so you must write shaders, create frustum matrices etc yourself. There are no lights, no materials, everything's shader code.

* There are a few things you can't do in html5. There is no LoadImageData, so you need to use a form of glTexImage2D that specifies an image path instead of a databuffer. I've emulated this on other targets though. Also, you must use VBOs on html5 - you can't bind DataBuffers to VertexAttribPointers or use them as indices for DrawElements. This isn't really a big deal though, as VBOs are the way to go.

* I can't get WebGL going on Mac OS at all, not even 3rd party apps, though I haven't tried very hard. iOS is no problem.

Source code here - a bit rough, I just added stuff as it was needed:


Vertex shader:


Fragment shader:



Beaker(Posted 2012) [#2]
The demo above throws a monkey error on ipad2 in safari. Anyone else?


DruggedBunny(Posted 2012) [#3]
Oooh... nice! Gonna have to hack my phone now, though I spent about two hours getting nowhere this evening.

Works nicely in Chrome here though.

[ Note to bruZard in advance: PLEASE keep supporting GLES11 as well! :P ]


marksibly(Posted 2012) [#4]
Hi,

> The demo above throws a monkey error on ipad2 in safari. Anyone else?

I don't think WebGL is available on iOS yet:

http://en.wikipedia.org/wiki/WebGL

Can you run anything here?

http://www.chromeexperiments.com/webgl

> [ Note to bruZard in advance: PLEASE keep supporting GLES11 as well! :P ]

Definitely agree! I was quite disappointed my Galaxy S didn't cut it - it's not THAT old, and plenty of people I know have crappier Android devices.


Jesse(Posted 2012) [#5]
>I can't get WebGL going on Mac OS at all, not even 3rd party apps, though I haven't tried very hard.

I am able to run WebGL on my MacBook under Safari
with the latest WebKit nightly builds:
http://nightly.webkit.org/

I can run them. Problem is I can't compile them. Is that what you mean?


bruZard(Posted 2012) [#6]
Good news!

No panic DruggedBunny, i'll keep es1.1 supported ;)


AdamRedwoods(Posted 2012) [#7]
How do you beat the boss mandril? thx


simonh(Posted 2012) [#8]
Great work Mark. Tempted to finally start tinkering with this shader stuff.

Demo doesn't work on my MacBook though - I get these errors:

Monkey runtime error: GL Error 1280
C:/Dropbox/monkeydev/bananas/mak/gles20cube/gles20cube.monkey<9>
C:/Dropbox/monkeydev/bananas/mak/gles20cube/gles20cube.monkey<153>
C:/Dropbox/monkeydev/bananas/mak/gles20cube/gles20cube.monkey<181>
C:/Dropbox/monkeydev/bananas/mak/gles20cube/gles20cube.monkey<223>
C:/Dropbox/monkeydev/bananas/mak/gles20cube/gles20cube.monkey<434>
C:/Dropbox/monkeydev/modules/mojo/app.monkey<72>


The MacBook is fairly old (crappy Intel GMA X3100 card), but it can run other WebGL stuff.


Beaker(Posted 2012) [#9]
Mark said:
I don't think WebGL is available on iOS yet:

That's what I thought until I read the last bit of this from your first post:
* I can't get WebGL going on Mac OS at all, not even 3rd party apps, though I haven't tried very hard. iOS is no problem.


Demo works fine on my Mac in Firefox.


JIM(Posted 2012) [#10]
I've only found WebGL to work on Android through a Firefox beta if I remember correctly. No iOS.


bruZard(Posted 2012) [#11]
GLES2.0 works fine with Android 2.2 (API Level 8), why you need Gingerbread?


charlie(Posted 2012) [#12]
Oooh! Exciting!

Looking forward to trying this out soon.

Cheers
Charlie


charlie(Posted 2012) [#13]
the demo works fine on chrome on my mac. not tried to compile it though.

Cheers
Charlie


taumel(Posted 2012) [#14]
Finally! Same as charlie.


marksibly(Posted 2012) [#15]
Hi,

> GLES2.0 works fine with Android 2.2 (API Level 8), why you need Gingerbread?

Weirdly, the API 8 version of GL2.0 is missing 2 fairly crucial functions - glDrawElements and glVertexAttribPointer with int offsets for use with VBOs.

This either severely limits or entirely cripples the use of VBOs (not sure which, haven't played with them) and IMO means the API 8 GL2.0 is not really GL2.0.

You are welcome to try and use GL2.0 on API 8, but I don't intend to support it as, like I say, it's not really GL2.0.


Tibit(Posted 2012) [#16]
Cool! Can we do 2D with lights and shadows?

Like this: http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/dynamic-2d-soft-shadows-r2032

Btw Mark what devices do you have?


skid(Posted 2012) [#17]
If you haven't watched this video it's not a bad overview to ES2.0 on Android.

Google I/O 2011: 3D Graphics on Android: Lessons learned from Google Body

http://www.youtube.com/watch?v=YLVbLVtjDDw


GC-Martijn(Posted 2012) [#18]
> http://www.blitzbasic.com/tmp/gles20cube/MonkeyGame.html

Google Chrome (latest)

Monkey runtime error: TypeError: Cannot call method 'createTexture' of null
C:/Dropbox/monkeydev/bananas/mak/gles20cube/gles20cube.monkey<383>
C:/Dropbox/monkeydev/modules/mojo/app.monkey<55>


simonh(Posted 2012) [#19]

That can be done in OpenGL ES 1.1. I know as my work colleague has just implemented that very routine.


DruggedBunny(Posted 2012) [#20]

Weirdly, the API 8 version of GL2.0 is missing 2 fairly crucial functions - glDrawElements and glVertexAttribPointer with int offsets for use with VBOs.


Yeah, I get a glVertexAttribPointer error on my Android 2.2 phone.


bruZard(Posted 2012) [#21]
my fail. ES2.0 is supported since Android2.0, but Java support ES2.0 fully since 2.3


JIM(Posted 2012) [#22]
@mark. In the video that skid posted, there's a fix for those missing functions in 2.2. The guy says it's a pretty easy fix, but I'm not sure if monkey can do it transparently. The fix is at minute 27-30.

Slightly OT: If more people would be ok with rooting + custom ROMs, almost everyone would have 2.3.7 right now :)


DruggedBunny(Posted 2012) [#23]
@JIM: Nice find! Mark, please can you implement this? It looks pretty easy, going by the video, but this guy has already written the code and explained the process. I couldn't quite figure out how to include it into the Monkey project, but I'm sure you can!

http://blog.micha.monoid.net/2010/08/workaround-using-vertex-buffer-objects.html

The attachment on that page didn't work for me, but the one below Comment 2 here does:

http://code.google.com/p/android/issues/detail?id=8931


DruggedBunny(Posted 2012) [#24]
Hmm, I got it to build successfully (built gles20cube with Monkey, exited, built the lib and added the src/fix stuff, added the includes to src/com/monkey, finally got no errors and confirmed the .apk includes the libfix-GLES20.o file), but I still get the error for glVertexAttribPointer (I removed my previous MonkeyGame install first).

I may well have got something wrong, but please give it a whirl, Mark!


AdamRedwoods(Posted 2012) [#25]
Yup, the whole story behind incomplete gl20 bindings is here, and the guy at google comes forward in the comments:
http://www.badlogicgames.com/wordpress/?p=760

My question with the fix would be, how compatible is it? Most Android is ARM based, but which devices are not?
EDIT: google tv is not arm
http://stackoverflow.com/questions/4490136/does-android-really-exist-on-other-platforms-than-arm


DruggedBunny(Posted 2012) [#26]
I can't get that first link to load, but I don't think the CPU should matter, should it? It's just some Java/C decls. Still, worth pointing to that guy's fix too:

http://code.google.com/p/gl2-android/


marksibly(Posted 2012) [#27]
Hi,

> My question with the fix would be, how compatible is it? Most Android is ARM based, but which devices are not?

Yeah, to be honest I'm not keen on adding native stuff to the android target as I'm not sure what the ramifications are. So far, the android target is 100% pure Java, and I like that. I was really hoping to hold off on the native code until we added an 'all native' NDK target...

That said, I'll try to get this working as Froyo is still apparently in widespread use. Whether it still will be by the time anyone actually does anything in GL2 is another question...

Perhaps this fix could be something you optionally add to your target?


marksibly(Posted 2012) [#28]
Hi,

> but I don't think the CPU should matter, should it? It's just some Java/C decls.

The C code needs to be precompiled to a .so library (android doesn't compile it), which is native code like a .dll or .exe. This library gets embedded in your app, so your app effectively becomes architecture dependent.

Ideally, it'd be nice NOT to require people to have to install the NDK (and therefore cygwin!) so we'd probably want to ship precompiled, native .so code. But by using it, you're limiting your app to only be runnable on the architecture supported by the .so.


skid(Posted 2012) [#29]
NDK has been mingw based for some time thank god, but yes monkey users shouldn't need to install it. If you use invoke NDK with:

/Users/simon/android-ndk-r7/ndk-build NDK_DEBUG=1 APP_ABI=all


it should create following which i think is only extra you will need to distribute and may have to be managed /copied by trans for each project.

libs
libs/armeabi
libs/armeabi-v7a
libs/x86


marksibly(Posted 2012) [#30]
HI,

> NDK has been mingw based for some time thank god,

Yeah? My installation docs say:

"Windows users will need to install Cygwin 1.7 or later (http://www.cygwin.com) to
use the NDK. Note that running it under MSys or Cygwin 1.5 is not supported."

Seems to work with cygwin anyway...well, I've built something, not run it yet. I'd prefer cygwin anyway - mingw's too flaky. Where is it these days? The nuwen.net guy's not hosting it anymore...

> you will need to distribute and may have to be managed /copied by trans for each project.

So we're gonna need something like 'ANDROID_NATIVE_TARGET' now too?

I really, really hate where this is going..!


Samah(Posted 2012) [#31]
I'd prefer cygwin anyway - mingw's too flaky. Where is it these days? The nuwen.net guy's not hosting it anymore...

http://www.mingw.org/
Last update November?


DruggedBunny(Posted 2012) [#32]
Ooh, can of worms...

Still, it'd be nice even if you had to (optionally, for 2.2 support) distribute pre-built libs. Most phones are going to be ARM for the near future, but it sounds like skid's method would produce libs for all anyway.

The only other option is to require 2.3, but that means more dodgy attempts at flashing phones/tablets (and mine won't reboot into recovery mode no matter what, making it even more risky). For the sake of two missing functions it seems a bit much!


Ideally, it'd be nice NOT to require people to have to install the NDK (and therefore cygwin!)



I do agree... but for what it's worth, I don't have Cygwin installed and it built for me.

I don't think having to have the NDK *if you want to support 2.2* would be unreasonable; the minimum being 2.3 if you're happy with that, but I don't know how easy it would be to support a default 2.3 and an optional 2.2...


skid(Posted 2012) [#33]
Legacy NDK hacks do seem a little off base.


DruggedBunny(Posted 2012) [#34]
Yeah, you're probably right... I'd just like someone/anyone to get it to work!


marksibly(Posted 2012) [#35]
Hi,

> I do agree... but for what it's worth, I don't have Cygwin installed and it built for me.

How did you do it? I'm still stuck...perhaps I need to try MinGW?

I've got the .so files appearing in libs/blah/... but Java loadLibrary still fails when I run it.

Do I need to change anything else?


marksibly(Posted 2012) [#36]
Hi,

Fixed! And I have no idea how/why!

Looks like all the compilers/linkers etc are built into the NDK (doh!) - you don't need cygwin or mingw at all as far as I can tell. I'm loving the idea of this as an eventual target SDK now...

I think I can turn this into an 'unofficial' thing you can drop into your target projects if you want better GL2 support in 2.2. I'm still uncomfortable with adding this to the official release for now, but maybe once it's had a bit of a thrashing...?

Should have a 52(d) up by the end of the day.


AdamRedwoods(Posted 2012) [#37]
The GDC2011 talk transcript also discusses the gl20 <> froyo fixes (just before textures):
http://code.google.com/p/gdc2011-android-opengl/wiki/TalkTranscript

Thanks Mark! I think a side set of files should be fine for us monkeyers for now. I (for one) don't plan on using GL20 right away, although per-pixel lighting is nice.


Edit: As for all NDK Mojo for android, looks like they allow this now without java glue: http://developer.android.com/reference/android/app/NativeActivity.html


DruggedBunny(Posted 2012) [#38]
Cool, Mark -- an unofficial/unsupported drop-in is probably for the best anyway if you can do it.


skid(Posted 2012) [#39]
I would investigate moving entire android target to NDK/C++.

Pure native app development has been available for some time and STL is now supported.

Have a squizz at $ndk/samples/native-activity/jni/main.c for more info.


marksibly(Posted 2012) [#40]
Hi,

> Cool, Mark -- an unofficial/unsupported drop-in is probably for the best anyway if you can do it.

It's probably gonna have to be quite intrusive, so I'll build it into the android target and add a ANDROID_NATIVE_GL_ENABLED config var.

Also, I guess this'll mean I have to use reflection for the working versions of these methods even though I'll only ever call them if they exist!


matty(Posted 2012) [#41]
Sorry I've not followed this thread too closely but am I correct in thinking that Android 2.2 is not supported by the new features being added in Monkey? Does this mean Monkey won't support Android 2.2 from v53 onwards?

Aside from the fact that my own phone is a 2.2 (HTC Desire) approximately 1/3 of users of my apps use 2.2 or lower, and 1/2 my users use 2.3.3+, with the remaining 20% split between all the other versions of Android.

?


marksibly(Posted 2012) [#42]
Hi,

> am I correct in thinking that Android 2.2 is not supported by the new features being added in Monkey?

This is all to do with the newly added OpenGL ES 2.0 module. It has nothing to do with mojo or any existing modules, which I plan to keep as compatible as possible with as much hardware as possible for as long as possible!

On that note:

V52(d) is now up with native kludge for new GLES20 stuff so it works on 2.2.

Use:

#ANDROID_NATIVE_GL_ENABLED="true" 'new config setting!

...at the top of your code to enable it. Currently, all it does is fix the 2.2 issue, but I've left the name a bit vague like this 'coz I may add more to it in future...

The whole 'libs' dir for all 3 ABIs is only 20k, so I don't really see the point in allowing users to select a subset of ABIs here, as that'll only limit the devices an app can run on for very little benefit.


matty(Posted 2012) [#43]
Thanks Mark, that's good to know (that mojo etc will remain compatible with a lot of hardware)..


DruggedBunny(Posted 2012) [#44]
Hmm, I get it to build and run successfully now, but the display is entirely pink -- no cubes and no error messages. Randomising glClearColor at least shows it's running and not just frozen.

I noticed versions.txt mentions "Mojo redirects stdout to android Log" -- how do I view that if I go through and add a load of Print checks to the sample/module?


bruZard(Posted 2012) [#45]
found in gles20_src.txt:
'Not available in WebGL!
Function glVertexAttribPointer:Void( indx, size, type, normalized?, stride, data:DataBuffer )

that is not true, glVertexAttribPointer is available in WebGL. The following example use it: http://www.peter-strohm.de/webgl/kapitel1.html


marksibly(Posted 2012) [#46]
Hi,

> Hmm, I get it to build and run successfully now, but the display is entirely pink

Well, I don't have a 2.2 device so all I could check was whether the native hack worked or not, and it did.

Have you deleted your .build dir?

Have you added this at the top of the code?

#ANDROID_NATIVE_GL_ENABLED="true"

> how do I view that if I go through and add a load of Print checks to the sample/module?

To print in native code, you can use bb_std_lang.print( blah ) or System.out.println( blah ).

> that is not true,

It is according to the webgl spec:

https://www.khronos.org/registry/webgl/specs/1.0/#WEBGLCONTEXTATTRIBUTES

In section 6.2: "The WebGL does not support client-side arrays" - ie: you must use VBOs. So the array/databuffer versions of glDrawElements and glVertexAttribPointer aren't available, only the 'int offset into VBO' versions.


marksibly(Posted 2012) [#47]
HI,

> Hmm, I get it to build and run successfully now, but the display is entirely pink

Woah, think I've found it! Look out for a new version soon.


DruggedBunny(Posted 2012) [#48]

Woah, think I've found it!


Cool... and yes, I'd deleted build and set the const to true. (Just done it again to double-check...)


marksibly(Posted 2012) [#49]
Hi,

James, just emailed you!


DruggedBunny(Posted 2012) [#50]
Yep, replied -- all good now!


MonkeyPig(Posted 2012) [#51]
Hi Mark,

I pulled down the latest MonkeyPro52e to have a play with the GLES2 stuff.

It was all working quite beautifully (nice job BTW) but I do appear to have run into an HTML5 error...

Monkey Runtime error: RangeError: ArrayBuffer length minus the byteOffset is not a multiple of the element size.

The offending line is...

Local idata:=DataBuffer.Create( icount*2 )


The mesh I'm attempting to load has 952 verts and 4011 indices.

The Android & GLFW builds of the same code load and display it correctly.

All I've done is take your basic GLES2 sample; re-organized it a little and implemented by own ObjLoader.

Let me know if you want the code and data-set if it's an unknown issue.

Cheers,