protected void beginDrawAnnotations(DrawContext dc, OGLStackHandler stackHandler)
        {
            GL2 gl = dc.getGL().getGL2();                 // GL initialization checks for GL2 compatibility.

            int attributeMask = GL2.GL_COLOR_BUFFER_BIT   // for alpha test func and ref, blend func
                                | GL2.GL_CURRENT_BIT      // for current color
                                | GL2.GL_DEPTH_BUFFER_BIT // for depth test, depth mask, depth func
                                | GL2.GL_ENABLE_BIT       // for enable/disable changes
                                | GL2.GL_HINT_BIT         // for line smoothing hint
                                | GL2.GL_LINE_BIT         // for line width, line stipple
                                | GL2.GL_TRANSFORM_BIT    // for matrix mode
                                | GL2.GL_VIEWPORT_BIT;    // for viewport, depth range

            stackHandler.pushAttrib(gl, attributeMask);

            // Load a parallel projection with dimensions (viewportWidth, viewportHeight)
            stackHandler.pushProjectionIdentity(gl);
            gl.glOrtho(0d, dc.getView().getViewport().width, 0d, dc.getView().getViewport().height, -1d, 1d);

            // Push identity matrices on the texture and modelview matrix stacks. Leave the matrix mode as modelview.
            stackHandler.pushTextureIdentity(gl);
            stackHandler.pushModelviewIdentity(gl);

            // Enable the alpha test.
            gl.glEnable(GL2.GL_ALPHA_TEST);
            gl.glAlphaFunc(GL2.GL_GREATER, 0.0f);

            // Apply the depth buffer but don't change it.
            if ((!dc.isDeepPickingEnabled()))
            {
                gl.glEnable(GL.GL_DEPTH_TEST);
            }
            gl.glDepthMask(false);

            // Disable lighting and backface culling.
            gl.glDisable(GL2.GL_LIGHTING);
            gl.glDisable(GL.GL_CULL_FACE);

            if (!dc.isPickingMode())
            {
                // Enable blending in premultiplied color mode.
                gl.glEnable(GL.GL_BLEND);
                OGLUtil.applyBlending(gl, true);
            }
            else
            {
                this.pickSupport.beginPicking(dc);
            }
        }
Ejemplo n.º 2
0
        /**
         * Sets the GL blending state according to the specified color mode. If <code>havePremultipliedColors</code> is
         * true, this applies a blending function appropriate for colors premultiplied by the alpha component. Otherwise,
         * this applies a blending function appropriate for non-premultiplied colors.
         *
         * @param gl                      the GL context.
         * @param havePremultipliedColors true to configure blending for colors premultiplied by the alpha components, and
         *                                false to configure blending for non-premultiplied colors.
         *
         * @throws ArgumentException if the GL is null.
         */
        public static void applyBlending(GL2 gl, bool havePremultipliedColors)
        {
            if (gl == null)
            {
                String message = Logging.getMessage("nullValue.GLIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            gl.glEnable(GL2.GL_ALPHA_TEST);
            gl.glAlphaFunc(GL2.GL_GREATER, 0.0f);

            if (havePremultipliedColors)
            {
                gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA);
            }
            else
            {
                // The separate blend function correctly handles regular (non-premultiplied) colors. We want
                //     Cd = Cs*As + Cf*(1-As)
                //     Ad = As    + Af*(1-As)
                // So we use GL_EXT_blend_func_separate to specify different blending factors for source color and source
                // alpha.

                bool haveExtBlendFuncSeparate = gl.isExtensionAvailable(GL_EXT_BLEND_FUNC_SEPARATE);
                if (haveExtBlendFuncSeparate)
                {
                    gl.glBlendFuncSeparate(
                        GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA, // rgb   blending factors
                        GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA);      // alpha blending factors
                }
                else
                {
                    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
                }
            }
        }