Revision: 75309
          http://sourceforge.net/p/brlcad/code/75309
Author:   starseeker
Date:     2020-04-08 20:44:34 +0000 (Wed, 08 Apr 2020)
Log Message:
-----------
Make a stab at adapting wgl.c - untested, clearly will need additional wrappers.

Modified Paths:
--------------
    brlcad/trunk/src/libdm/CMakeLists.txt
    brlcad/trunk/src/libdm/dm-wgl.c

Removed Paths:
-------------
    brlcad/trunk/src/libdm/dm-pex.h

Modified: brlcad/trunk/src/libdm/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libdm/CMakeLists.txt       2020-04-08 20:11:16 UTC (rev 
75308)
+++ brlcad/trunk/src/libdm/CMakeLists.txt       2020-04-08 20:44:34 UTC (rev 
75309)
@@ -137,7 +137,6 @@
   dm-ogl.h
   dm-osgl.cpp
   dm-osgl.h
-  dm-pex.h
   dm-plot.h
   dm-ps.h
   dm-qt.cpp

Deleted: brlcad/trunk/src/libdm/dm-pex.h
===================================================================
--- brlcad/trunk/src/libdm/dm-pex.h     2020-04-08 20:11:16 UTC (rev 75308)
+++ brlcad/trunk/src/libdm/dm-pex.h     2020-04-08 20:44:34 UTC (rev 75309)
@@ -1,97 +0,0 @@
-/*                          D M - P E X . H
- * BRL-CAD
- *
- * Copyright (c) 1993-2020 United States Government as represented by
- * the U.S. Army Research Laboratory.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this file; see the file named COPYING for more
- * information.
- */
-
-/** @addtogroup libdm */
-/** @{ */
-/** @file dm-pex.h
- *
- */
-
-#ifndef DM_PEX_H
-#define DM_PEX_H
-
-#include "common.h"
-
-/*
- * Display coordinate conversion:
- *  GED is using -2048..+2048,
- *  X is 0..width, 0..height
- */
-#define        GED_TO_Xx(_dmp, x) ((int)(((x)/4096.0+0.5)*((struct pex_vars 
*)((_dmp)->dmr_vars))->width))
-#define        GED_TO_Xy(_dmp, x) ((int)((0.5-(x)/4096.0)*((struct pex_vars 
*)((_dmp)->dmr_vars))->height))
-#define Xx_TO_GED(_dmp, x) ((int)(((x)/(double)((struct pex_vars 
*)((_dmp)->dmr_vars))->width - 0.5) * 4095))
-#define Xy_TO_GED(_dmp, x) ((int)((0.5 - (x)/(double)((struct pex_vars 
*)((_dmp)->dmr_vars))->height) * 4095))
-
-#define TRY_DEPTHCUE 0
-#define Pex_MV_O(_m) offsetof(struct modifiable_pex_vars, _m)
-
-struct modifiable_pex_vars {
-#if TRY_DEPTHCUE
-    int cue;
-#endif
-    int perspective_mode;
-    int dummy_perspective;
-};
-
-struct pex_vars {
-    struct bu_list l;
-    Display *dpy;
-    Window win;
-    Tk_Window xtkwin;
-    int width;
-    int height;
-    int omx, omy;
-    unsigned int mb_mask;
-    int perspective_angle;
-    XFontStruct *fontstruct;
-    GC gc;
-#ifdef DOUBLE_BUFFERING_WITH_PIXMAPS
-    Pixmap pix;
-    int pix_width, pix_height;
-#endif
-    PEXRenderer renderer;
-    PEXRendererAttributes rattrs;
-    int is_monochrome;
-    unsigned long black, gray, white, yellow, red, blue;
-    unsigned long bd, bg, fg;   /* color of border, background, foreground */
-    struct modifiable_pex_vars mvars;
-};
-
-__BEGIN_DECLS
-
-extern void Pex_configure_window_shape();
-extern void Pex_establish_perspective();
-extern void Pex_set_perspective();
-extern struct pex_vars head_pex_vars;
-
-__END_DECLS
-
-#endif /* DM_PEX_H */
-
-/** @} */
-/*
- * Local Variables:
- * mode: C
- * tab-width: 8
- * indent-tabs-mode: t
- * c-file-style: "stroustrup"
- * End:
- * ex: shiftwidth=4 tabstop=8
- */

Modified: brlcad/trunk/src/libdm/dm-wgl.c
===================================================================
--- brlcad/trunk/src/libdm/dm-wgl.c     2020-04-08 20:11:16 UTC (rev 75308)
+++ brlcad/trunk/src/libdm/dm-wgl.c     2020-04-08 20:44:34 UTC (rev 75309)
@@ -219,11 +219,10 @@
     Tk_Window tkwin;
     HWND hwnd;
     HDC hdc;
-       int gotvisual;
+    int gotvisual;
 
-    if ((tkwin = Tk_MainWindow(interp)) == NULL) {
-       return DM_NULL;
-    }
+    struct dm_xvars *pubvars = NULL;
+    struct wgl_vars *privvars = NULL;
 
     BU_ALLOC(dmp, struct dm_internal);
 
@@ -232,7 +231,9 @@
     dmp->dm_light = 1;
 
     BU_ALLOC(dmp->dm_vars.pub_vars, struct dm_xvars);
+    pubvars = (struct dm_xvars *)dmp->dm_vars.pub_vars;
     BU_ALLOC(dmp->dm_vars.priv_vars, struct wgl_vars);
+    privvars = (struct wgl_vars *)dmp->dm_vars.priv_vars;
 
     dmp->dm_get_internal(dmp);
     mvars = (struct modifiable_ogl_vars *)dmp->m_vars;
@@ -239,6 +240,10 @@
 
     dmp->dm_vp = &default_viewscale;
 
+    if ((tkwin = (*context->dm_window_main)(dmp)) == NULL) {
+       return DM_NULL;
+    }
+
     bu_vls_init(&dmp->dm_pathName);
     bu_vls_init(&dmp->dm_tkName);
     bu_vls_init(&dmp->dm_dName);
@@ -262,9 +267,9 @@
        bu_vls_strcpy(&init_proc_vls, "bind_dm");
 
     /* initialize dm specific variables */
-    ((struct dm_xvars *)dmp->dm_vars.pub_vars)->devmotionnotify = LASTEvent;
-    ((struct dm_xvars *)dmp->dm_vars.pub_vars)->devbuttonpress = LASTEvent;
-    ((struct dm_xvars *)dmp->dm_vars.pub_vars)->devbuttonrelease = LASTEvent;
+    pubvars->devmotionnotify = LASTEvent;
+    pubvars->devbuttonpress = LASTEvent;
+    pubvars->devbuttonrelease = LASTEvent;
     dmp->dm_aspect = 1.0;
 
     /* initialize modifiable variables */
@@ -280,7 +285,7 @@
     mvars->boundFlag = dmp->dm_boundFlag;
 
     /* this is important so that wgl_configureWin knows to set the font */
-    ((struct dm_xvars *)dmp->dm_vars.pub_vars)->fontstruct = NULL;
+    pubvars->fontstruct = NULL;
 
     if (dmp->dm_width == 0) {
        dmp->dm_width = GetSystemMetrics(SM_CXSCREEN)- 30;
@@ -305,7 +310,6 @@
     if (dmp->dm_top) {
        /* Make xtkwin a toplevel window */
        Tcl_DString ds;
-
        Tcl_DStringInit(&ds);
        Tcl_DStringAppend(&ds, "toplevel ", -1);
        Tcl_DStringAppend(&ds, bu_vls_addr(&dmp->dm_pathName), -1);
@@ -315,47 +319,41 @@
            Tcl_DStringFree(&ds);
            return DM_NULL;
        }
-       ((struct dm_xvars *)dmp->dm_vars.pub_vars)->xtkwin =
-           Tk_NameToWindow(interp, bu_vls_addr(&dmp->dm_pathName), tkwin);
        Tcl_DStringFree(&ds);
-       ((struct dm_xvars *)dmp->dm_vars.pub_vars)->top = ((struct dm_xvars 
*)dmp->dm_vars.pub_vars)->xtkwin;
+       pubvars->xtkwin = 
(Tk_Window)(*context->dm_window_create_from_path)(dmp, tkwin,
+                bu_vls_cstr(&dmp->dm_pathName), bu_vls_cstr(&dmp->dm_dName));
+       pubvars->top = pubvars->xtkwin;
     } else {
        char *cp;
 
        cp = strrchr(bu_vls_addr(&dmp->dm_pathName), (int)'.');
        if (cp == bu_vls_addr(&dmp->dm_pathName)) {
-           ((struct dm_xvars *)dmp->dm_vars.pub_vars)->top = tkwin;
+           pubvars->top = tkwin;
        } else {
            struct bu_vls top_vls = BU_VLS_INIT_ZERO;
 
            bu_vls_strncpy(&top_vls, (const char 
*)bu_vls_addr(&dmp->dm_pathName), cp - bu_vls_addr(&dmp->dm_pathName));
 
-           ((struct dm_xvars *)dmp->dm_vars.pub_vars)->top =
-               Tk_NameToWindow(interp, bu_vls_addr(&top_vls), tkwin);
+           pubvars->top = (Tk_Window)(*context->dm_window_from_name)(dmp, 
bu_vls_cstr(&top_vls), tkwin);
            bu_vls_free(&top_vls);
        }
 
        /* Make xtkwin an embedded window */
-       ((struct dm_xvars *)dmp->dm_vars.pub_vars)->xtkwin =
-           Tk_CreateWindow(interp, ((struct dm_xvars 
*)dmp->dm_vars.pub_vars)->top,
-                           cp + 1, (char *)NULL);
+       pubvars->xtkwin = (Tk_Window)(*context->dm_window_create_embedded)(dmp, 
pubvars->top, cp + 1);
     }
 
-    if (((struct dm_xvars *)dmp->dm_vars.pub_vars)->xtkwin == NULL) {
-       bu_log("open_gl: Failed to open %s\n", bu_vls_addr(&dmp->dm_pathName));
+    if (pubvars->xtkwin == NULL) {
+       bu_log("wgl: Failed to open %s\n", bu_vls_addr(&dmp->dm_pathName));
        bu_vls_free(&init_proc_vls);
        (void)wgl_close(dmp, context);
        return DM_NULL;
     }
 
-    bu_vls_printf(&dmp->dm_tkName, "%s",
-                 (char *)Tk_Name(((struct dm_xvars 
*)dmp->dm_vars.pub_vars)->xtkwin));
+    const char *winname = (*context->dm_window_name)(dmp, pubvars->xtkwin);
+    bu_vls_printf(&dmp->dm_tkName, "%s", winname);
 
-    bu_vls_printf(&str, "_init_dm %s %s\n",
-                 bu_vls_addr(&init_proc_vls),
-                 bu_vls_addr(&dmp->dm_pathName));
 
-    if (Tcl_Eval(interp, bu_vls_addr(&str)) == BRLCAD_ERROR) {
+    if ((*context->dm_init)(dmp, bu_vls_cstr(&init_proc_vls)) == BRLCAD_ERROR) 
{
        bu_log("open_wgl: _init_dm failed\n");
        bu_vls_free(&init_proc_vls);
        bu_vls_free(&str);
@@ -366,30 +364,28 @@
     bu_vls_free(&init_proc_vls);
     bu_vls_free(&str);
 
-    ((struct dm_xvars *)dmp->dm_vars.pub_vars)->dpy =
-       Tk_Display(((struct dm_xvars *)dmp->dm_vars.pub_vars)->top);
+    pubvars->dpy = (Display *)(*context->dm_display)(dmp, pubvars->top);
 
     /* make sure there really is a display before proceeding. */
-    if (!((struct dm_xvars *)dmp->dm_vars.pub_vars)->dpy) {
+    if (!pubvars->dpy) {
+       bu_vls_free(&init_proc_vls);
+       bu_vls_free(&str);
        (void)wgl_close(dmp, context);
        return DM_NULL;
     }
 
-    Tk_GeometryRequest(((struct dm_xvars *)dmp->dm_vars.pub_vars)->xtkwin,
-                      dmp->dm_width,
-                      dmp->dm_height);
+    (*context->dm_window_geom)(dmp, pubvars->xtkwin, &dmp->dm_width, 
&dmp->dm_height);
 
-    Tk_MakeWindowExist(((struct dm_xvars *)dmp->dm_vars.pub_vars)->xtkwin);
+    (*context->dm_window_make_exist)(dmp, pubvars->xtkwin);
 
-    ((struct dm_xvars *)dmp->dm_vars.pub_vars)->win =
-       Tk_WindowId(((struct dm_xvars *)dmp->dm_vars.pub_vars)->xtkwin);
-    dmp->dm_id = ((struct dm_xvars *)dmp->dm_vars.pub_vars)->win;
+    pubvars->win = (*context->dm_window_id)(dmp, pubvars->xtkwin);
+    dmp->dm_id = pubvars->win;
 
-    hwnd = TkWinGetHWND(((struct dm_xvars *)dmp->dm_vars.pub_vars)->win);
+    hwnd = TkWinGetHWND(pubvars->win);
     hdc = GetDC(hwnd);
-    ((struct dm_xvars *)dmp->dm_vars.pub_vars)->hdc = hdc;
+    pubvars->hdc = hdc;
 
-       gotvisual = wgl_choose_visual(dmp, ((struct dm_xvars 
*)dmp->dm_vars.pub_vars)->xtkwin);
+    gotvisual = wgl_choose_visual(dmp, pubvars->xtkwin);
     if (!gotvisual) {
        bu_log("wgl_open: Can't get an appropriate visual.\n");
        (void)wgl_close(dmp, context);
@@ -396,18 +392,16 @@
        return DM_NULL;
     }
 
-    ((struct dm_xvars *)dmp->dm_vars.pub_vars)->depth = mvars->depth;
+    pubvars->depth = mvars->depth;
 
     /* open GLX context */
-    if ((((struct wgl_vars *)dmp->dm_vars.priv_vars)->glxc =
-        wglCreateContext(((struct dm_xvars 
*)dmp->dm_vars.pub_vars)->hdc))==NULL) {
+    if (privvars->glxc = wglCreateContext(pubvars->hdc)==NULL) {
        bu_log("wgl_open: couldn't create glXContext.\n");
        (void)wgl_close(dmp, context);
        return DM_NULL;
     }
 
-    if (!wglMakeCurrent(((struct dm_xvars *)dmp->dm_vars.pub_vars)->hdc,
-                       ((struct wgl_vars *)dmp->dm_vars.priv_vars)->glxc)) {
+    if (!wglMakeCurrent(pubvars->hdc, privvars->glxc)) {
        bu_log("wgl_open: couldn't make context current\n");
        (void)wgl_close(dmp, context);
        return DM_NULL;
@@ -414,7 +408,7 @@
     }
 
     /* display list (fontOffset + char) will display a given ASCII char */
-    if ((((struct wgl_vars *)dmp->dm_vars.priv_vars)->fontOffset = 
glGenLists(128))==0) {
+    if ((privvars->fontOffset = glGenLists(128))==0) {
        bu_log("wgl_open: couldn't make display lists for font.\n");
        (void)wgl_close(dmp, context);
        return DM_NULL;
@@ -421,7 +415,7 @@
     }
 
     /* This is the applications display list offset */
-    dmp->dm_displaylist = ((struct wgl_vars 
*)dmp->dm_vars.priv_vars)->fontOffset + 128;
+    dmp->dm_displaylist = privvars->fontOffset + 128;
 
     wgl_setBGColor(dmp, 0, 0, 0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -452,13 +446,13 @@
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     glOrtho(-xlim_view, xlim_view, -ylim_view, ylim_view, 0.0, 2.0);
-    glGetDoublev(GL_PROJECTION_MATRIX, ((struct wgl_vars 
*)dmp->dm_vars.priv_vars)->faceplate_mat);
+    glGetDoublev(GL_PROJECTION_MATRIX, privvars->faceplate_mat);
     glPushMatrix();
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
     glPushMatrix();
     glLoadIdentity();
-    ((struct wgl_vars *)dmp->dm_vars.priv_vars)->face_flag = 1;        /* 
faceplate matrix is on top of stack */
+    privvars->face_flag = 1;   /* faceplate matrix is on top of stack */
 
     wgl_setZBuffer(dmp, dmp->dm_zbuffer);
     wgl_setLight(dmp, dmp->dm_light);
@@ -482,9 +476,9 @@
        return DM_NULL;
     }
 
-    Tk_MapWindow(((struct dm_xvars *)dmp->dm_vars.pub_vars)->xtkwin);
+    (*context->dm_window_map)(dmp, pubvars->xtkwin);
 
-       Tk_CreateEventHandler(((struct dm_xvars 
*)dmp->dm_vars.pub_vars)->xtkwin, VisibilityChangeMask, WGLEventProc, 
(ClientData)dmp);
+    Tk_CreateEventHandler(pubvars->xtkwin, VisibilityChangeMask, WGLEventProc, 
(ClientData)dmp);
 
     return dmp;
 }
@@ -653,22 +647,23 @@
  *  Gracefully release the display.
  */
 HIDDEN int
-wgl_close(dm *dmp, struct dm_context *UNUSED(context))
+wgl_close(dm *dmp, struct dm_context *context)
 {
-    if (((struct dm_xvars *)dmp->dm_vars.pub_vars)->dpy) {
-       if (((struct wgl_vars *)dmp->dm_vars.priv_vars)->glxc) {
-           wglMakeCurrent(((struct dm_xvars *)dmp->dm_vars.pub_vars)->hdc,
-                          ((struct wgl_vars *)dmp->dm_vars.priv_vars)->glxc);
-           wglDeleteContext(((struct wgl_vars *)dmp->dm_vars.priv_vars)->glxc);
+    struct dm_xvars *pubvars = (struct dm_xvars *)dmp->dm_vars.pub_vars;
+    struct wgl_vars *privvars = (struct wgl_vars *)dmp->dm_vars.priv_vars;
+
+    if (pubvars->dpy) {
+       if (privvars->glxc) {
+           wglMakeCurrent(pubvars->hdc, priv_vars->glxc);
+           wglDeleteContext(privvars->glxc);
        }
 
-       if (((struct dm_xvars *)dmp->dm_vars.pub_vars)->cmap)
-           XFreeColormap(((struct dm_xvars *)dmp->dm_vars.pub_vars)->dpy,
-                         ((struct dm_xvars *)dmp->dm_vars.pub_vars)->cmap);
+       if (pubvars->cmap)
+           XFreeColormap(pub_vars->dpy, pub_vars->cmap);
 
-       if (((struct dm_xvars *)dmp->dm_vars.pub_vars)->xtkwin) {
-               Tk_DeleteEventHandler(((struct dm_xvars 
*)dmp->dm_vars.pub_vars)->xtkwin, VisibilityChangeMask, WGLEventProc, 
(ClientData)dmp);
-               Tk_DestroyWindow(((struct dm_xvars 
*)dmp->dm_vars.pub_vars)->xtkwin);
+       if (pub_vars->xtkwin) {
+               Tk_DeleteEventHandler(pubvars->xtkwin, VisibilityChangeMask, 
WGLEventProc, (ClientData)dmp);
+               (*context->dm_window_destroy)(dmp, pubvars->xtkwin);
        }
     }
 
@@ -1534,8 +1529,7 @@
  * OpenGL
  */
 HIDDEN int
-wgl_choose_visual(dm *dmp,
-                 Tk_Window tkwin)
+wgl_choose_visual(dm *dmp, Tk_Window tkwin)
 {
     struct modifiable_ogl_vars *mvars = (struct modifiable_ogl_vars 
*)dmp->m_vars;
     int iPixelFormat;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to