Search in sources :

Example 6 with GLClipPlane

use of maspack.render.GL.GLClipPlane in project artisynth_core by artisynth.

the class GL3Viewer method doDisplay.

private void doDisplay(GLAutoDrawable drawable, int flags) {
    // updates projection matrix
    if (resetViewVolume && autoResizeEnabled) {
        resetViewVolume(gl);
        resetViewVolume = false;
    }
    if (resetViewport && autoViewportEnabled) {
        setViewport(gl, 0, 0, width, height);
        resetViewport = false;
    }
    int nclips = Math.min(2 * myClipPlanes.size(), maxClipPlanes);
    myProgramInfo.setNumClipPlanes(nclips);
    myProgManager.reconfigure(gl, lightManager.numLights(), nclips);
    myProgManager.setLights(gl, lightManager.getLights(), 1.0f / lightManager.getMaxIntensity(), viewMatrix);
    // update matrices
    maybeUpdateState(gl);
    // clear background/depth
    gl.glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], backgroundColor[3]);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    if (!isSelecting()) {
        if (gridVisible) {
            myGrid.render(this, flags);
        }
        if (axisLength > 0) {
            if (solidAxes) {
                drawSolidAxes(null, axisLength, axisLength / 50.0, false);
            } else {
                drawAxes(gl, axisLength);
            }
        }
        // not clipped by the clipping plane
        for (Dragger3d dragger : myDraggers) {
            dragger.render(this, 0);
        }
        if (myDrawTool != null) {
            myDrawTool.render(this, 0);
        }
        for (GLClipPlane cp : myClipPlanes) {
            cp.render(this, flags);
        }
    }
    for (int i = 0; i < myProgManager.numClipPlanes(); ++i) {
        boolean enabled = gl.glIsEnabled(GL3.GL_CLIP_DISTANCE0 + i);
        if (enabled) {
            Logger.getSystemLogger().debug("Why is this enabled?");
        }
    }
    // enable clip planes
    int iclips = 0;
    if (nclips > 0) {
        iclips = myProgManager.setClipPlanes(gl, myClipPlanes);
        for (int i = 0; i < iclips; ++i) {
            gl.glEnable(GL3.GL_CLIP_DISTANCE0 + i);
        }
    }
    if (!isSelecting()) {
        setFrontColor(DEFAULT_MATERIAL_COLOR);
    }
    int qid = 0;
    synchronized (myInternalRenderList) {
        qid = myInternalRenderList.renderOpaque(this, qid, flags);
    }
    RenderList elist = myExternalRenderList;
    if (elist != null) {
        synchronized (elist) {
            qid = elist.renderOpaque(this, qid, flags);
        }
    }
    if (hasTransparent3d()) {
        if (!isSelecting()) {
            enableTransparency();
        }
        synchronized (myInternalRenderList) {
            qid = myInternalRenderList.renderTransparent(this, qid, flags);
        }
        if (elist != null) {
            synchronized (elist) {
                qid = elist.renderTransparent(this, qid, flags);
            }
        }
        if (!isSelecting()) {
            disableTransparency();
        }
    }
    // disable clip planes
    for (int i = 0; i < nclips; ++i) {
        gl.glDisable(GL3.GL_CLIP_DISTANCE0 + i);
    }
    // Draw 2D objects
    if (has2d()) {
        begin2DRendering(width, height);
        try {
            synchronized (myInternalRenderList) {
                qid = myInternalRenderList.renderOpaque2d(this, qid, 0);
            }
            if (elist != null) {
                synchronized (elist) {
                    qid = elist.renderOpaque2d(this, qid, 0);
                }
            }
            if (hasTransparent2d()) {
                if (!isSelecting()) {
                    enableTransparency();
                }
                synchronized (myInternalRenderList) {
                    qid = myInternalRenderList.renderTransparent2d(this, qid, 0);
                }
                if (elist != null) {
                    synchronized (elist) {
                        qid = elist.renderTransparent2d(this, qid, 0);
                    }
                }
                if (!isSelecting()) {
                    disableTransparency();
                }
            }
        } finally {
            // methods throws and exception
            if (isTransparencyEnabled()) {
                disableTransparency();
            }
            end2DRendering();
        }
    }
    if (!isSelecting()) {
        if (myDragBox != null) {
            drawDragBox(gl);
        }
        if (myEllipticCursorActive) {
            Point cursor = myMouseHandler.getCurrentCursor();
            if (cursor != null) {
                drawEllipticCursor(gl, cursor);
            }
        }
    } else {
        // revert clear color
        gl.glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], backgroundColor[3]);
    }
    // trigger update of state (required for GLJPanel, which relies on
    // transparency to be off)
    maybeUpdateState(gl);
    gl.glFlush();
}
Also used : Point(java.awt.Point) GLClipPlane(maspack.render.GL.GLClipPlane) Point(java.awt.Point) RenderList(maspack.render.RenderList) Dragger3d(maspack.render.Dragger3d)

Example 7 with GLClipPlane

use of maspack.render.GL.GLClipPlane in project artisynth_core by artisynth.

the class GL2Viewer method doDisplay.

// public boolean isLightingEnabled() {
// return gl.glIsEnabled (GL2.GL_LIGHTING);
// }
private void doDisplay(GLAutoDrawable drawable, int flags) {
    GL2 gl = drawable.getGL().getGL2();
    // updates view matrix
    if (resetViewVolume && autoResizeEnabled) {
        resetViewVolume(gl);
        resetViewVolume = false;
    }
    if (resetViewport && autoViewportEnabled) {
        setViewport(gl, 0, 0, width, height);
        resetViewport = false;
    }
    gl.glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], backgroundColor[3]);
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    // updates view matrix
    // RigidTransform3d X = new RigidTransform3d();
    // X.invert (XEyeToWorld);
    // enter view matrix
    // GLSupport.transformToGLMatrix (GLMatrix, X);
    // GLSupport.transformToGLMatrix (GLMatrix, viewMatrix);
    // gl.glLoadMatrixd(GLMatrix, 0);
    // viewMatrixValidP = true;  // view matrix now "committed"
    // update all state, including matrices
    maybeUpdateState(gl);
    setupLights(gl);
    if (!isSelecting()) {
        if (gridVisible) {
            myGrid.render(this, flags);
        }
        if (axisLength > 0) {
            if (solidAxes) {
                drawSolidAxes(null, axisLength, axisLength / 50.0, false);
            } else {
                drawAxes(gl, axisLength);
            }
        }
        // not clipped by the clipping plane
        for (Dragger3d dragger : myDraggers) {
            dragger.render(this, 0);
        }
        if (myDrawTool != null) {
            myDrawTool.render(this, 0);
        }
        for (GLClipPlane cp : myClipPlanes) {
            cp.render(this, flags);
        }
    }
    // enable clip planes
    // update matrices before activating clip planes
    maybeUpdateState(gl);
    int nclips = 0;
    int clipIdx = GL2.GL_CLIP_PLANE0;
    for (GLClipPlane cp : myClipPlanes) {
        if (cp.isClippingEnabled()) {
            cp.getPlaneValues(myClipPlaneValues);
            myClipPlaneValues[3] += cp.getOffset();
            gl.glClipPlane(clipIdx, myClipPlaneValues, 0);
            gl.glEnable(clipIdx);
            clipIdx++;
            nclips++;
            if (nclips >= maxClipPlanes) {
                break;
            }
            if (cp.isSlicingEnabled()) {
                myClipPlaneValues[0] = -myClipPlaneValues[0];
                myClipPlaneValues[1] = -myClipPlaneValues[1];
                myClipPlaneValues[2] = -myClipPlaneValues[2];
                myClipPlaneValues[3] = -myClipPlaneValues[3] + 2 * cp.getOffset();
                gl.glClipPlane(clipIdx, myClipPlaneValues, 0);
                gl.glEnable(clipIdx);
                clipIdx++;
                nclips++;
                if (nclips >= maxClipPlanes) {
                    break;
                }
            }
        }
    }
    if (!isSelecting()) {
        setFrontColor(DEFAULT_MATERIAL_COLOR);
    }
    int qid = 0;
    synchronized (myInternalRenderList) {
        qid = myInternalRenderList.renderOpaque(this, qid, flags);
    }
    RenderList elist = myExternalRenderList;
    if (elist != null) {
        synchronized (elist) {
            qid = elist.renderOpaque(this, qid, flags);
        }
    }
    if (hasTransparent3d()) {
        if (!isSelecting()) {
            enableTransparency();
        }
        synchronized (myInternalRenderList) {
            qid = myInternalRenderList.renderTransparent(this, qid, flags);
        }
        if (elist != null) {
            synchronized (elist) {
                qid = elist.renderTransparent(this, qid, flags);
            }
        }
        if (!isSelecting()) {
            disableTransparency();
        }
    }
    // disable clipping planes
    for (int i = GL2.GL_CLIP_PLANE0; i < clipIdx; ++i) {
        gl.glDisable(i);
    }
    // Draw 2D objects
    if (has2d()) {
        begin2DRendering(width, height);
        try {
            synchronized (myInternalRenderList) {
                qid = myInternalRenderList.renderOpaque2d(this, qid, 0);
            }
            if (elist != null) {
                synchronized (elist) {
                    qid = elist.renderOpaque2d(this, qid, 0);
                }
            }
            if (hasTransparent2d()) {
                if (!isSelecting()) {
                    enableTransparency();
                }
                synchronized (myInternalRenderList) {
                    qid = myInternalRenderList.renderTransparent2d(this, qid, 0);
                }
                if (elist != null) {
                    synchronized (elist) {
                        qid = elist.renderTransparent2d(this, qid, 0);
                    }
                }
                if (!isSelecting()) {
                    disableTransparency();
                }
            }
        } finally {
            // methods throws and exception
            if (isTransparencyEnabled()) {
                disableTransparency();
            }
            end2DRendering();
        }
    }
    if (!isSelecting()) {
        if (myDragBox != null) {
            drawDragBox(gl);
        }
        if (myEllipticCursorActive) {
            Point cursor = myMouseHandler.getCurrentCursor();
            if (cursor != null) {
                drawEllipticCursor(gl, cursor);
            }
        }
    }
    // trigger update of state (required for GLJPanel, which relies on
    // transparency to be off)
    maybeUpdateState(gl);
    gl.glFlush();
}
Also used : Point(java.awt.Point) GL2(com.jogamp.opengl.GL2) GLClipPlane(maspack.render.GL.GLClipPlane) Point(java.awt.Point) RenderList(maspack.render.RenderList) Dragger3d(maspack.render.Dragger3d)

Aggregations

GLClipPlane (maspack.render.GL.GLClipPlane)7 Point (java.awt.Point)2 ByteBuffer (java.nio.ByteBuffer)2 Dragger3d (maspack.render.Dragger3d)2 RenderList (maspack.render.RenderList)2 GL2 (com.jogamp.opengl.GL2)1 Plane (maspack.matrix.Plane)1 Point3d (maspack.matrix.Point3d)1