i open this thread to introduce a possible solution i’d like to see as a standard. this discussion is about the layer structure and the naming conventions in the different layers. my ideas might lead to a concept that is to far away from the current jogl design. if that should be the case please point me to another forum where such a structure could be discussed and set up.
the presented structure is not complete. it is a discussion-base.
i recommend an api layered in the following fashion, from bottom to top:
OpenGLCServer (called GL in jogl)
static final public int GL_TEXTURE_2D 0xXXXX;
static public void glVertex3i(int, int, int);
static public void glVertex3f(float, float, float);
static public void glVertex4f(float, float, float, float);
...
OpenGLServer
static final public int TEXTURE_2D 0xXXXX;
static public void vertex(int, int, int);
static public void vertex(float, float, float);
static public void vertex(float, float, float, float);
...
OpenGLContext
public static OpenGLContext currentContext();
public static void clearCurrentContext();
public void makeCurrentContext();
public void flushBuffer();
public OpenGLDrawable drawable();
public void clearDrawable();
public void update();
...
interface OpenGLDrawable
public OpenGLDrawable(); // constructor creates suitable OpenGLContext
public OpenGLContext context(); // returns the context bound to this drawable
public void display();
...
non-window-system-based drawables:
FullscreenOpenGLDrawable implements OpenGLDrawable
OffscreenOpenGLDrawable implements OpenGLDrawable
VirtualscreenOpenGLDrawable implements OpenGLDrawable
view/window-system-based drawables:
AWTOpenGLDrawable implements OpenGLDrawable
SwingOpenGLDrawable implements OpenGLDrawable
SWTOpenGLDrawable implements OpenGLDrawable
OpenGLCServer and OpenGLServer are identical in functionality, they only differ in syntax.
this specification would solve the following - already discussed - problems:
a) porting low-level opengl from c to java
OpenGLCServer wraps the underlying c-functions of OpenGL keeping the c-naming convention. this is a convenience class for c-programmers and other people wanting/having to stick to the c-naming scheme.
b) make opengl a good java citizen
OpenGLServer wraps the server by using method overloading. java programmers should use this interface for any new programs. this should be the recommended way to interface opengl with java. therefore it is not explicitly called OpenGLJavaServer.
c) automatic removal of unneeded pre- and postfixes with java 1.5
a static import of OpenGL©Server will remove the need to write
OpenGLCServer.glVertex3i(0,0,0); or
OpenGLServer.vertex(0,0,0);
and instead allow
glVertex3i(0,0,0); or
vertex(0,0,0);
d) partial independency of window-system
FullscreenOpenGLDrawable and OffscreenOpenGLDrawable should be independent of the underlying window-system (awt/swing/…). this opens the possibility of building apps that do not need to know anything about it.
e) exposure of the opengl context
the programmer is able to talk to the context whenever needed, not only in the draw-method. this allows for uploading/destroying textures, generating display-list, … at a choosen time.
caveats
the server-methods are kept static because opengl is a state-machine. the client itself has limited knowledge about the current active context. the programmer has to ensure that drawing is done to the right (current) context (or that the right context is current).
this becomes an issue when awt and swing are used.
the OpenGLContext has to be exposed to the programmer. otherwise the access to opengl would be to restrictive. the threading issues have to be adressed either by the programmer or by the awt/swing/… based classes.
OpenGLDrawables distinguish between the choosen output-path.
OpenGLContext is pretty near to NSOpenGLContext from apple.
input (keyboard, mouse) is not considered here.
your comments and ideas are welcome!