On 19 oct, 15:25, Coolcat <[email protected]> wrote:
> Hi,
> I'm currently thinking about an class for GWT which wraps the WebGL
> (*) interface. It should be easy to wrap all the methods. E.g.
> glBindTexture would look like this:
>
> public native void bindTexture(int target, JavaScriptObject texture) /
> *-{
>         [email protected]::gl.bindTexture(target, texture);
>
> }-*/;
>
> Since native methods are inline, there should be no overhead. However,
> the problem is, what to do with fields? It would be nice to have them
> as static final fields in the GWT-WebGL class. Is there any way that
> an static final field is mapped internally/inline to it's
> corresponding field in native JavaScript?
>
> I think I need something like this:
> public native static final int TEXTURE_2D = /*-
> { [email protected]::gl.TEXTURE_2D }-*/;

Er, how can it be 'static' if you're initializing it with a 'this'?

> Is this kind of native fields even possible?

use static methods to initialize the field:

   public static final int TEXTURE_2D = initTexture2D();

   // note: I don't know WebGL other than by name; this is just an
example, not a working one ;-)
   private static native int initTexture2D() /*-{ return
$wnd.staticGL.TEXTURE_2D; }-*/;

> Since all fields do not change and are well defined it would be
> possible to define them all in the class. But because there are MANY
> of them, I'm not sure if that solution is wise:
> public static final int TEXTURE_2D = 0x0DE1;
> Would this blow up the compiled code size?

No, everything would be inlined (or put into "global constants"), so
only the fields you'll actually use will appear in the JS output.
Contrary to the "native field" above: because GWT wouldn't have any
mean of knowing it the native code would have side effects, it would
call it whether you use the value or not.

> Another way would be something like this:
> public native int TEXTURE_2D() /*-{
>         return [email protected]::gl.TEXTURE_2D;}-*/;
>
> Should be fast, but ugly because I would need "()" brackets
> everywhere.

...and again, because GWT couldn't know if there would be side
effects, the "constant value" wouldn't be "cached" in a "constant
variable", and "something.gl.TEXTURE_2D" would be evaluated each time
you call the TEXTURE_2D() method in your code.

> What do you think is the best way to do this?

If you know the constant's value, use it in your code (to initialize
your constant field); do not call JSNI if you can avoid it.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to