Xith3D for SWT

I have a question. I am in the process of porting the
Xith3D engine to SWT, (as well as implementing the
3D texturing correctly >:( , but that’s not the subject of
this post). Half of the work is done. That is, since I
noticed that Xith3D sits on top of JoGL, I ported the
JoGL binding to SWT. Now I can use JoGL in a SWT
GLCanvas. To test that all of the functionality of JoGL
was correctly exposed a volumetric shadow test was
implemented. This tested everything from shaders to
pbuffers, all at once. It works fine ;D . Step 2 is to
implement a Canvas- and Render- Peer in SWT. Also
a fairly simple task, however, this is not all that has to
be done.

This brings me to the heart of the post, event handling.
Right now, all of the events throughout the Xith3D code
base are AWT events, that leaves SWT events out in the
cold. So even though there is a SWT-based GLCanvas
that is acting as the CanvasPeer, there are no events
coming out of it and into the rest of the system. This
is because the rest of the system is listening for AWT
events, which they will never receive. My planned course
is to write abstractions for all of the events, and then
listen for those in the code base instead.

I am writing to ask if the actual Xith3D developers think
that this is a reasonable course of action. There are a
lot of surprises throughout the code base that I have been
coming across. Like the need to do event handling correctly
in the UIWindow as well as in the general system. It would
be great to know whether or not there are other gotchas in
the code base, or if you guys planned on implementing
SWT integration in a different way.

Holla Back . . .

                                                       -T

If Xith3D is to be truly independant of the rendering layer (which it will need to be if it is ever to be used with LWJGL as well) then we will need these abstractions. Most of the event handling stuff is really just a temporary hack I believe. Abstracting these events could also mean seemless JInput integration too.

Another important one is the concept of the Window - so that it will be possible to change for example the title and size of the window in an implementation independant way (currently one has to get the JFrame which isn’t so great). This shouldn’t be a large task - a simple interface would hopefully suffice but still it needs to be done.

If you do write an event input interface for Xith3d - would you consider adding in Joystick (and GamePad) support along with mouse, keyboard and window events?

+1 for the abstraction of events from me :slight_smile:

Please keep us posted on your progress.

Will.

A bit off topic but I noticed when creating a LWJGL demo that the frame is created and displayed onto the screen in less than half second which is pretty amazing.
Using the regular Jstuff, a frame could take up to 2-3 seconds to show anything on the screen…
I wonder if SWT is any better than AWT or Swing

[quote]I wonder if SWT is any better than AWT or Swing
[/quote]
I wounder that too, especially with the enhancements in Java1.5.

On the topic of portability - I assume that the user inferface library of Xith3d will always require Swing to be installed yes? I guess it too could be abstracted but that wouldn’t be trivial and I’m sure we’d lose some functionality.

Will.

Regarding speed, the short answer is that bringing up
a SWT Shell, (equivalent of a JFrame), is SIGNIFICANTLY
faster than bringing up a JFrame in Swing.

The real reason my company uses SWT, is because of a
bug in JoGL on Windows. If you bring up a Frame or
Window with multiple GLCanvases in it, draw
to them, and then remove all of them and create new
GLCanvases in the same Window or Frame to replace
them, you will get a crash. Perhaps not the first time,
perhaps not the second, but sooner or later if you
replace GLCanvases enough, a crash will ensue.

This bug was pretty annoying actually. Haven’t tried it
on 1.5, but we shipped our product last year, so we
HAD to go with SWT, or not use OpenGL. I am revisiting
the situation now to see if there has been any progress.
I think that Xith3D is the only thing out there that we
would have use for, so I am porting it to SWT so that
we can use it in the future, like the next release.

One thing I will say though, our product has really been
kickin’ the s#!t out of a competing product also written
in Java, but using AWT and Swing. Why that is I don’t
know, as I have not used this competitor’s product, but
there it is.

                                                   -T

Well if you need any help regarding the port, I’m right here making myself your first volunteer ;D

Thanx JCD . . .

THAT is EXACTLY what I was hoping for . . .

Right now I am still inventorying the code base.

I just got a look at it in depth for the first time
yesterday. Tomorrow I will have a better
idea of what I think the abstractions should look
like. More importantly, I will be able to back up
my assertions with data. Right now you guys are
WAY ahead of me in your understanding of the
code base. I have to catch up in order to facilitate
a productive interchange.

I WILL be running some ideas by you tomorrow
though, if you are available.

                                              -T

Quick question:
Say we successfully switch Xith3D’s current AWT/SWING dependencies to SWT, does that mean that JET could finally .exe a Xith3D demo?
/me day dreams

Without Swing it is maybe possible to use gcj (or kaffe). This means:
[] Xith3D can run with a free version of Java and can make it in the Linux toolchains one day (wow, just the thought of this is amazing). That’s the way eclipse conquered the Linux developers desktop.
[
] Xith3D programs can be compiled to native code on every relevant platform, which is a very good thing, because it depends on native libraries anyway.

What a pain that I have exams now and not much time to investigate further on the two points above, which would take Xith3D’s strength to a new level. I’ll certainly do what time permits. If anyone knows a reason why the above is not possible at all, please tell me.

Regarding the event abstraction: I’m all for it and I already mentioned this weakness of Xith3D several times.

Of course we have to take care of existing Xith3D projects (especially Magicosm). The changes above almost certainly break Xith3D, but if it helps to make it more powerful, it’s worth it. I would like very much, if Yuri or David could join this discussion, because they have the best overview of the structure of Xith3D.

Btw. I’m very pleased to see new people interested in supporting Xith3D here.

JCD,

Yes it could, with a few caveats regarding UIWindow
that I’m not sure about yet . . .

I will be soon.

Jens,

Yeah, I agree there are some real cool opportunities
here. I myself will probably start with an Eclipse shader
program editor, but others can integrate into other
tools, as Xith3D is open source. As I said, my principle
thrust is to get a shader programming framework that
is useable by MY company, but others are free to do
what pleases them.

Now my REAL question,

Who are Yuri and David ? ? ?

And would they be of help here ? ? ?

David started and runs the Xith3D project, Yuri has added many great features (check the http://xith.org/demo/com.xith3d.test.php page) :slight_smile:

Will.

Hi,

[quote]Who are Yuri and David ? ? ?
[/quote]
OK, say, my name is Yuri :slight_smile: . If you’d like to see my profile - you are welcome to http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=announcements;action=display;num=1074215610;start=15#15 thread, but this is off-topic here.

Now as of SWT port for JOGL and Xith3D.

For me, SWT is nothing different that AWT and Swing - this is just another GUI library with nice features, but also with its own open topics.

Xith3D is first of all scenegraph-based rendering engine. Of course, there is a need, a very big need, to add support for event handling and behavior processing.

Time ago I was implementing support for OpenGL-based picking in Xith3D, and came to the issues of handling UI events associated with 3D rendering components.

As of now, UI event processing (except of UIWindow) is completely up to the application that uses Xith3D. CanvasPeer has a method for obtaining a Component that acts as 3D rendering component, and then application can attach any event handlers to it. I see this approach very reasonable, because of it allows to keep Xith3D core aware of any of UI-library-specific event processing issues (again, except of UIWindow).

The visible problem with SWT integration is that [maybe - I don’t know] SWT version of GLCanvas extends something other than java.awt.Component, so it may make it incompatible with current CanvasPeer API. This can be easily changed by adding, say,

public Object get3DRenderingUIComponent()

that will return something other than Component.

I even don’t see any reason of changing Canvas- and Render Peer in order to support SWT, just because of this may be a part of JOGL - it already contains factory method of creating GLCanvas:

GLDrawableFactory.getFactory().createGLCanvas(gc);

So we can keep the same peer classes for all of the JOGL-based UI components.

As of event handling in general, I see the following structure of application that uses Xith3D:

  1. Application creates CanvasPeerImpl of interest, maybe providing some peer-implementation flags indicating details of canvas creation.

  2. Application attaches event handlers to created CanvasPeerImpl in implementation-specific way.

  3. Application attaches View to Canvas and runs rendering loop (either built-in or custom).

  4. Upon UI events received, application modifies Xith3D scenegraph accordingly, which results in visible dynamic changes.

If we speat about JInput and other related things, then I would say that there should be separate scenegraph modification subsystem, that may/will run in rendering thread context and will react to different external events. This will bring us to known concept of Java3d Behaviors, which is currently not implemented in Xith3D [OK, I have partially implemented some parts of it for my projects, but this is not 100% compatible and has only part of core Java3D behaviors implemented (interpolator and base mouse behaviors)].

Comparing to Java3D, Xith3D can be really flexible on supported behavior types, so we can make set of behaviors that react on different types of input - say. we can have set of AWT-based mouse behaviors, as well as SWT-based, as well as more generic JInput-based.

But, at the end, I see this as a separate Xith3D subsystem, Scenegraph Manipulation API, so we can still keep Scenegraph Rendering API independent on the underlying UI library, platform and rendering subsystem.

I would prefer to break Xith3D project to subsystems, so it will not become a non-maintenable monster, but a set of optional subcomponents. We see excellent example of this with XML serialization - this is a part of xith-tk project, and interoperates with Xith3D core very well. If we need to make some changes in Xith3D core in order to suppoer SWT, there is absolutely no problems.

Yuri

P.S. This is not a “final decision of Xith3D team”, but my personal opinion [that I see very reasonable], so I am open for discussion anyway.

This would be a very good idea indeed. Other examples of potential sub systems are the collider code, Swing UI, Ase Loader, and terrain generation. It’s certianly important that these packages stay “optional” in the sense that Xith3D doesn’t depend on them. Reasons include as you said, maintainability and also preventing download size bloat and letting the developer easily use an alternative api (for example Odejava instead of the collider code).

Will.

Here I was talking to someone about abstracting away the basic context management for GL applications using an interface. I believe that the most sensible way forward for everyone in this space is to make a concerted effort on this interface.

Because, ultimately, all GL bindings actually co-operate together and work the same way, it should not matter beyond the context management exactly what the GL binding looks like.

If we could just convince JOGL to branch out into JOGL and JOGL-Context we could all implement the same interface (eg. LWJGL’s Window would implement it, SWT could have an SWT canvas that implemented it, and AWT could have a GLCanvase that implemented it). This code only needs to be done once and maintained in one place.

Cas :slight_smile:

well that would help LWJGL support :slight_smile:

a good idea, but, do you think they’ll go for it?

Will.

Cas,

So, if I understand you right, your suggesting is to isolate OpenGL bindings from UI components that display OpenGL-rendered content via common GLContext/GLCanvas/GL*** interface?

In this case we should think about complete Binding <-> UI Element interaction API, which will be a good idea.

With complete API I mean that we should have in mind also something like GLDrawable callbacks for JOGL.

Yuri

Yes, I think you’re saying what I’m saying. Basically, OpenGL rendering in Java is split into 3 layers: context creation, context management, and GL API calls.

Context creation is the preserve of the underlying windowing system. So LWJGL, SWT, and AWT all have their own ways of creating a context.

GL API calls are all being done in slightly different ways depending on your tastes/requirements - but the crucial thing is that it doesn’t matter what API you call or when you call it or even if you mix them: the same native functions get called. (As I pointed out recently in the JOGL forum, you can freely mix and match calls to both APIs).

So that leaves the bit in the middle which has only one thing to do: it must be the common interface between context creation, management, and GL API calls.

If your context creation system is effectively a factory that creates concrete implementations of the interface, you have abstracted away the fact that LWJGL, AWT, and SWT use very, very different methods to set up a context. In LWJGL our Windows and Pbuffers are contexts. SWT uses some SWTGLCanvas and JOGL uses whatever JOGL uses.

The management of the context is then down to the actual implementation but there’s really very little it has to do. In fact the only thing it has to do is make itself current for the current thread, and provide rudimentary information about itself such as its size and buffer depths.

Where does this get everyone?

Well, it means that I could write a model renderer in LWJGL that could be told to render on to a JOGL canvas. Or a Xith3D scene could be rendered into a LWJGL window and then I could paint my GL rendered GUIs on top with LWJGL. (Forget, for now, the fact that you’d have two native libraries - that’s under-the-hood). Or I could have Swing components in my LWJGL window manipulating a Xith3D scene. In short we could concentrate on writing software components that render stuff without worrying about what’s underneath so much.

I’m quite excited by the prospect of making this possible without hurting anyone’s APIs or philosophies.

Cas :slight_smile:

OK, I’m back and armed with data.

Princec,

An abstraction of GLContext handling will be a little more
tricky than it seems. Firstly, AWT and Swing both have the
concept of locking and freeing. These are things you don’t
have to worry about in LWJGL Window or with SWT. That’s
why people use those, because they are more simple.
That’s also why JoGL on AWT or Swing freaks out if you
try to do any complicated context handling, like removing
and creating Canvases in an AWT or Swing container on
the fly. This is also the reason for all of the rendering
thread management calls in JoGL, and that’s a whole other
mess that AWT and Swing oblige you to deal with.

I think it is instructive here to consider what the people
at JoGL have done to help us in this regard. They knew
about the assanine nature of AWT and Swing when they
started reworking the GL4Java code, so they hid the
GLContext altogether. You can’t get to it from the public
APIs. The only HACKish part of the interface to the
GLCanvas is all of the render thread crap and the auto
redraw handling. However, in as much as there is a
disagreement with those APIs being there, it could almost
be called philosophical. The fact is you can use JoGL in
a semi-sane manner with what they’ve given you.

I think this is the model to follow. Take a close look at it,
and see what you think.

                                                        -T

Cas, you are 100% right about the context management. And perspective of having binding-independent API for higher-level systems such as Xith3D sounds quite interesting.

Now coming to practical point: in Xith3D, this is relatively easy to add one more indirection level to isolate CanvasPeer/RenderingPeer from binding-specific context management. But what we should do with GL calls? I assume that both LWJGL and JOGL can be used to call native-level OpenGL functions, but how we are going to handle differences in their APIs, and especially differencies in parameter passing (if any, but I can imagine there are differences)?

[OK, I understand that this is a beginning of longer discussion that (I hope) will result in creation of LWJGL renderer for Xith3D, so lets continue]

Yuri

Charlie Dobbie is already working on an LWJGL renderer for Xith3D. I invited him to join the discussion. LWJGL support would be very nice to have. ;D