GLXWorkstation.st
changeset 46 7b331e9012fd
parent 35 f1a194c18429
child 54 29a6b2f8e042
--- a/GLXWorkstation.st	Thu Jun 02 23:21:42 1994 +0200
+++ b/GLXWorkstation.st	Fri Jun 03 02:54:39 1994 +0200
@@ -18,33 +18,8 @@
 !
 
 GLXWorkstation comment:'
-
 COPYRIGHT (c) 1993 by Claus Gittinger
               All Rights Reserved
-
-this class was originally written as a demo on how an interface to 
-a c graphics library could be implemented. In the mean time, it has become
-quite complete ...
-
-It provides an interface to either a real GL (on SGI workstations)
-or a simulated VGL (GL-light; low nicotine).
-
-Most of the hard work was done by Jeff (thanks indeed) ...
-
-I do really not know what most of these functions do - for more
-detail, see the GL man pages (on SGI) or the doc provided with VGL.
-
-The interface offered here provides a very very low level (i.e one-to-one)
-interface to GL functions. More high-level stuff is required, to make
-3D drawing be more object-oriented. (see a bit of this in clients/IRIS-specials)
-
-Some functions are dublicated, Jeff and I developed those in parallel - 
-one of them will vanish - that is certain ...
-
-$Header: /cvs/stx/stx/libview/GLXWorkstation.st,v 1.9 1994-02-25 13:12:16 claus Exp $
-written june 93 by claus
-VGL stuff dec 93
-many many additions jan 94 by Jeff McAffer <jeff@is.s.u-tokyo.ac.jp>
 '!
 
 %{
@@ -54,6 +29,17 @@
  */
 
 /*
+ * define this to enable:
+ *    blendcolor getgconfig getmultisample leftbuffer rightbuffer monobuffer
+ *    msalpha msmask mspattern mssize multisample stereobuffer
+ *    t3s t3i t3f t3d t4s t4i t4f t4d tlutbind zbsize
+ *
+ * these are not available on all gl's
+ */
+
+/* #define FULL_GLX */
+
+/*
  * this is stupid, GLX defines String, which is also defined here ...
  */
 # define String GLX_String
@@ -87,12 +73,13 @@
  * put/pack them into corresponding c variables.
  *
  */
-#define MKDPY(o)       (Display *)(_intVal(o))
-#define MKWIN(o)       (Window)(_intVal(o))
-#define MKGC(o)        (GC)(_intVal(o))
-#define MKCURS(o)      (Cursor)(_intVal(o))
-#define MKFONT(o)      (XFontStruct *)(_intVal(o))
-#define MKDPSContext(o)      (DPSContext)(_intVal(o))
+#if defined(hpux) && defined(POSITIVE_ADDRESSES)
+# define MKDPY(o)       (Display *)((int)(o) & ~TAG_INT)
+# define MKWIN(o)        (Window)((int)(o) & ~TAG_INT)
+#else
+# define MKDPY(o)       (Display *)(_intVal(o))
+# define MKWIN(o)       (Window)(_intVal(o))
+#endif
 
 #define myDpy MKDPY(_INST(displayId))
 
@@ -557,7 +544,93 @@
     return (Matrix *)0;
 }
 
-%}
+static float*
+getFloatsFromFloatArrayInto(obj, fp)
+    OBJ obj;
+    float *fp;
+{
+    OBJ cls;
+    extern OBJ FloatArray, DoubleArray, Array;
+    int ninstVars;
+
+    if (! _isNonNilObject(obj)) return (float *)0;
+    cls = _qClass(obj);
+    if (cls == FloatArray)
+        return _FloatArrayInstPtr(obj)->f_element;
+
+    if ((_intVal(_ClassInstPtr(cls)->c_flags) & ARRAYMASK) == FLOATARRAY) {
+        ninstVars = _intVal(_ClassInstPtr(cls)->c_ninstvars);
+        return (float *) &(_InstPtr(obj)->i_instvars[ninstVars]);
+    }
+
+    /*
+     * need more here (i.e. convert from array-of-floats)
+     */
+    return (float *)0;
+}
+
+%}
+
+!GLXWorkstation class methodsFor:'documentation'!
+
+copyright
+"
+COPYRIGHT (c) 1993 by Claus Gittinger
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+!
+
+version
+"
+$Header: /cvs/stx/stx/libview/GLXWorkstation.st,v 1.10 1994-06-03 00:52:41 claus Exp $
+"
+!
+
+documentation
+"
+    this class was originally written as a demo on how an interface to
+    a c graphics library could be implemented. In the mean time, it has become
+    quite complete ...
+
+    It provides an interface to either a real GL (on SGI workstations)
+    or a simulated VGL (i.e. GL-light; low nicotine).
+    The GL simulation is derived from the PD vogl library, with slight
+    modifiactions to support multiple GL views.
+
+    Most of the hard work was done by Jeff (thanks indeed) ...
+
+    I do really not know what most of these functions do - for more
+    detail, see the GL man pages (on SGI) or the doc provided with VGL.
+
+    The interface offered here provides a very very low level (i.e one-to-one)
+    interface to GL functions. More high-level stuff is required, to make
+    3D drawing be more object-oriented. 
+    (see a bit of this in clients/IRIS-specials)
+
+    Some functions are duplicated, Jeff and I developed those in parallel -
+    those will be merged - that is certain ...
+
+    Also, in a hurry to implement all those methods, many do no or only
+    limited argument checking - make certain, that you pass the correct
+    arguments.
+
+    $Header: /cvs/stx/stx/libview/GLXWorkstation.st,v 1.10 1994-06-03 00:52:41 claus Exp $
+
+    written june 93 by claus
+    VGL stuff dec 93
+    many many additions jan 94 by Jeff McAffer <jeff@is.s.u-tokyo.ac.jp>
+
+    Since this is a demo (consider it a free add-on goody) there is 
+    *** NO WARRANTY ** for this.
+"
+! !
 
 !GLXWorkstation methodsFor:'queries'!
 
@@ -586,11 +659,6 @@
      weventMask wiconView wiconViewId bitGravity viewGravity vBgColor
      vBgForm deepForm|
 
-    "{ Symbol: colorIndexSingleBuffer }"
-    "{ Symbol: colorIndexDoubleBuffer }"
-    "{ Symbol: rgbSingleBuffer }"
-    "{ Symbol: rgbDoubleBuffer }"
-
     wsuperView := aView superView.
     wsuperView notNil ifTrue:[
         wsuperViewId := wsuperView id
@@ -611,13 +679,13 @@
             parentWindow = RootWindow(dpy, screen);
         }
 
-        if (glxType == _colorIndexSingleBuffer)
+        if (glxType == @symbol(colorIndexSingleBuffer))
             t = GLXcolorIndexSingleBuffer;
-        else if (glxType == _colorIndexDoubleBuffer)
+        else if (glxType == @symbol(colorIndexDoubleBuffer))
             t = GLXcolorIndexDoubleBuffer;
-        else if (glxType == _rgbSingleBuffer)
+        else if (glxType == @symbol(rgbSingleBuffer))
             t = GLXrgbSingleBuffer;
-        else if (glxType == _rgbDoubleBuffer)
+        else if (glxType == @symbol(rgbDoubleBuffer))
             t = GLXrgbDoubleBuffer;
         else {
             RETURN ( nil );
@@ -770,19 +838,15 @@
     "rotate the current matrix around the axis given by the axis arg,
      which must be one of the symbols: #x, #y or #z"
 
-    "{ Symbol: x }"
-    "{ Symbol: y }"
-    "{ Symbol: z }"
-
 %{  /* NOCONTEXT */
 
     char c_axis;
 
-    if (axis == _x)
+    if (axis == @symbol(x))
         c_axis = 'x';
-    else if (axis == _y)
+    else if (axis == @symbol(y))
         c_axis = 'y';
-    else if (axis == _z)
+    else if (axis == @symbol(z))
         c_axis = 'z';
     else {
         RETURN (false);
@@ -834,10 +898,6 @@
     "define a material, light source or lighting model;
      props must be a FloatArray or a subclass of FloatArray"
 
-    "{ Symbol: material }"
-    "{ Symbol: light }"
-    "{ Symbol: lightModel }"
-
 %{  /* NOCONTEXT */
 #ifdef GLX
     short defType;
@@ -847,11 +907,11 @@
     OBJ cls;
     int ninstVars, nInstBytes;
 
-    if (what == _material)
+    if (what == @symbol(material))
         defType = DEFMATERIAL;
-    else if (what == _light)
+    else if (what == @symbol(light))
         defType = DEFLIGHT;
-    else if (what == _lightModel)
+    else if (what == @symbol(lightModel))
         defType = DEFLMODEL;
     else {
         RETURN (false);
@@ -886,44 +946,32 @@
 glxLmbind:target index:index in:aGLXWindowId
     "select a material, lighyt or lighting model"
 
-    "{ Symbol: material }"
-    "{ Symbol: backMaterial }"
-    "{ Symbol: light0 }"
-    "{ Symbol: light1 }"
-    "{ Symbol: light2 }"
-    "{ Symbol: light3 }"
-    "{ Symbol: light4 }"
-    "{ Symbol: light5 }"
-    "{ Symbol: light6 }"
-    "{ Symbol: light7 }"
-    "{ Symbol: lightModel }"
-
 %{  /* NOCONTEXT */
 #ifdef GLX
     short defType;
     short i_index;
 
-    if (target == _material)
+    if (target == @symbol(material))
         defType = MATERIAL;
-    else if (target == _backMaterial)
+    else if (target == @symbol(backMaterial))
         defType = BACKMATERIAL;
-    else if (target == _light0)
+    else if (target == @symbol(light0))
         defType = LIGHT0;
-    else if (target == _light1)
+    else if (target == @symbol(light1))
         defType = LIGHT1;
-    else if (target == _light2)
+    else if (target == @symbol(light2))
         defType = LIGHT2;
-    else if (target == _light3)
+    else if (target == @symbol(light3))
         defType = LIGHT3;
-    else if (target == _light4)
+    else if (target == @symbol(light4))
         defType = LIGHT4;
-    else if (target == _light5)
+    else if (target == @symbol(light5))
         defType = LIGHT5;
-    else if (target == _light6)
+    else if (target == @symbol(light6))
         defType = LIGHT6;
-    else if (target == _light7)
+    else if (target == @symbol(light7))
         defType = LIGHT7;
-    else if (target == _lightModel)
+    else if (target == @symbol(lightModel))
         defType = LMODEL;
     else { 
         RETURN (false); 
@@ -1099,16 +1147,13 @@
 glxNmode:aSymbol in:aGLXWindowId
     "set normalize mode: #auto, #normalize"
 
-    "{ Symbol: auto }"
-    "{ Symbol: normalize }"
-
-%{  /* NOCONTEXT */
-#ifdef GLX
-    if (aSymbol == _auto) {
+%{  /* NOCONTEXT */
+#ifdef GLX
+    if (aSymbol == @symbol(auto)) {
         nmode(NAUTO);
         RETURN (true);
     }
-    if (aSymbol == _normalize) {
+    if (aSymbol == @symbol(normalize)) {
         nmode(NNORMALIZE);
         RETURN (true);
     }
@@ -1121,26 +1166,21 @@
 glxMmode:aSymbol in:aGLXWindowId
     "set matrix mode: #single, #viewing, #projection or #texture"
 
-    "{ Symbol: single }"
-    "{ Symbol: viewing }"
-    "{ Symbol: projection }"
-    "{ Symbol: texture }"
-
-%{  /* NOCONTEXT */
-#ifdef GLX
-    if (aSymbol == _single) {
+%{  /* NOCONTEXT */
+#ifdef GLX
+    if (aSymbol == @symbol(single)) {
         mmode(MSINGLE);
         RETURN (true);
     }
-    if (aSymbol == _viewing) {
+    if (aSymbol == @symbol(viewing)) {
         mmode(MVIEWING);
         RETURN (true);
     }
-    if (aSymbol == _projection) {
+    if (aSymbol == @symbol(projection)) {
         mmode(MPROJECTION);
         RETURN (true);
     }
-    if (aSymbol == _texture) {
+    if (aSymbol == @symbol(texture)) {
         mmode(MTEXTURE);
         RETURN (true);
     }
@@ -1930,7 +1970,7 @@
 glxBlendcolorRed: red green: green blue: blue alpha: alpha in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     blendcolor(_floatVal(red), _floatVal(green), _floatVal(blue), _floatVal(alpha)); 
     RETURN (true);
@@ -2988,7 +3028,7 @@
 glxGetgconfigBuffer: buffer in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     RETURN (_MKSMALLINT(getgconfig(_longVal(buffer))));
 #endif
@@ -3116,7 +3156,7 @@
 glxGetmultisampleIn: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     RETURN (_MKBOOLEAN(getmultisample()));
 #endif
@@ -3434,7 +3474,7 @@
 glxLeftbuffer: bool in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     leftbuffer(_booleanVal(bool));
     RETURN (true);
@@ -3447,7 +3487,7 @@
 glxRightbuffer: bool in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     rightbuffer(_booleanVal(bool));
     RETURN (true);
@@ -3686,7 +3726,7 @@
 glxMonobufferIn: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     monobuffer();
     RETURN (true);
@@ -3792,7 +3832,7 @@
 glxMsalphaMode: mode in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     msalpha(_longVal(mode));
     RETURN (true);
@@ -3805,7 +3845,7 @@
 glxMsmask: mask inverse: inverse in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     msmask(_floatVal(mask), _booleanVal(inverse));
     RETURN (true);
@@ -3818,7 +3858,7 @@
 glxMspattern: pattern in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     mspattern(_longVal(pattern));
     RETURN (true);
@@ -3831,7 +3871,7 @@
 glxMssizeSamples: samples zsize: zsize ssize: ssize in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     mssize(_longVal(samples), _longVal(zsize), _longVal(ssize));
     RETURN (true);
@@ -3870,7 +3910,7 @@
 glxMultisample: bool in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     multisample(_booleanVal(bool));
     RETURN (true);
@@ -5645,7 +5685,7 @@
 glxStereobufferIn: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     stereobuffer();
     RETURN (true);
@@ -5787,7 +5827,7 @@
 glxT3s: v in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     short vec[3], *c_v;
 
     if (! (c_v = getShortsFromInto(v, vec, 3))) RETURN(false);
@@ -5803,7 +5843,7 @@
 glxT3i: v in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     long vec[3], *c_v;
 
     if (! (c_v = getLongsFromInto(v, vec, 3))) RETURN(false);
@@ -5819,7 +5859,7 @@
 glxT3f: v in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     float vec[3], *c_v;
 
     if (! (c_v = getFloatsFromInto(v, vec, 3))) RETURN(false);
@@ -5835,7 +5875,7 @@
 glxT3d: v in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     double vec[3], *c_v;
 
     if (! (c_v = getDoublesFromInto(v, vec, 3))) RETURN(false);
@@ -5851,7 +5891,7 @@
 glxT4s: v in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     short vec[4], *c_v;
 
     if (! (c_v = getShortsFromInto(v, vec, 4))) RETURN(false);
@@ -5867,7 +5907,7 @@
 glxT4i: v in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     long vec[4], *c_v;
 
     if (! (c_v = getLongsFromInto(v, vec, 4))) RETURN(false);
@@ -5883,7 +5923,7 @@
 glxT4f: v in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     float vec[4], *c_v;
 
     if (! (c_v = getFloatsFromInto(v, vec, 4))) RETURN(false);
@@ -5899,7 +5939,7 @@
 glxT4d: v in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     double vec[4], *c_v;
 
     if (! (c_v = getDoublesFromInto(v, vec, 4))) RETURN(false);
@@ -5912,6 +5952,31 @@
     ^ false
 !
 
+glxTexDef2dIndex: index nc:nc width:w height:h bits:image np:np props:props in: aGLXWindowId
+    "bind a texture"
+
+%{  /* NOCONTEXT */
+#ifdef GLX
+    unsigned char *cp;
+    const float *fp;
+    OBJ cls;
+    float fbuff[30];
+
+    if (__isByteArray(image)) {
+	cp = _ByteArrayInstPtr(image)->ba_element;
+	fp = getFloatsFromFloatArrayInto(props, fbuff);
+
+        SETWIN(aGLXWindowId)
+        texdef2d(_longVal(index), _longVal(nc), _longVal(w), _longVal(h),
+	         (const unsigned long *)cp, _longVal(np), fp);
+        RETURN (true);
+    }
+#endif
+%}
+.
+    ^ false
+! 
+
 glxTevbind: target index: index in: aGLXWindowId
 
 %{  /* NOCONTEXT */
@@ -5926,6 +5991,7 @@
 ! 
 
 glxTexbind: target index: index in: aGLXWindowId
+    "bind a texture"
 
 %{  /* NOCONTEXT */
 #ifdef GLX
@@ -5994,7 +6060,7 @@
 glxTlutbind: target index: index in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     tlutbind(_longVal(target), _longVal(index));
     RETURN (true);
@@ -6555,7 +6621,7 @@
 glxZbsize: planes in: aGLXWindowId
 
 %{  /* NOCONTEXT */
-#ifdef GLX
+#ifdef FULL_GLX
     SETWIN(aGLXWindowId)
     zbsize(_longVal(planes));
     RETURN (true);