Enable 8x anti aliasing through JoGL native multisampling. 43/14243/2
Bruno JOFRET [Mon, 31 Mar 2014 10:45:50 +0000 (12:45 +0200)]
Change-Id: I567d355527c19ca9cd6b0c14ebd7cfe6a2ad54dc

scilab/CHANGES_5.5.X
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/canvas/SwingScilabCanvasImpl.java
scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/JoGLCanvas.java

index dec25d4..458cd16 100644 (file)
@@ -247,6 +247,10 @@ Known incompatibilities
 * Extracting children from an empty matrix of handles now returns an error.
   For example: f=gcf(); f.children(1).children.children returns an error.
 
+* Figure anti_aliasing property behavior changed:
+  - "off": No anti-aliasing activated on the figure.
+  - "2x", "4x", "8x", "16x": anti-aliasing activated using 8-buffers multi-sampling.
+
 
 Scilab Bug Fixes
 ================
index 3c5fc99..622dab3 100644 (file)
@@ -201,6 +201,10 @@ public class SwingScilabCanvasImpl {
     private final class SafeGLJPanel extends GLJPanel {
         private static final long serialVersionUID = -6166986369022555750L;
 
+        public SafeGLJPanel(GLCapabilities caps) {
+            super(caps);
+        }
+
         public void display() {
             try {
                 super.display();
@@ -230,6 +234,10 @@ public class SwingScilabCanvasImpl {
     */
     private final class SafeGLCanvas extends GLCanvas {
         private static final long serialVersionUID = -3315164314205693678L;
+
+        public SafeGLCanvas(GLCapabilities caps) {
+            super(caps);
+        }
     }
 
     private static SwingScilabCanvasImpl me = null;
@@ -243,11 +251,13 @@ public class SwingScilabCanvasImpl {
     }
 
     public Component createOpenGLComponent() {
+        GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+        caps.setSampleBuffers(true);
+        caps.setNumSamples(8);
         if (enableGLCanvas) {
-            return new SafeGLCanvas();
-        } else {
-            return new SafeGLJPanel();
+            return new SafeGLCanvas(caps);
         }
+        return new SafeGLJPanel(caps);
     }
 
     public SwingScilabCanvasImpl() {}
index 96c0f92..0a13910 100644 (file)
 
 package org.scilab.forge.scirenderer.implementation.jogl;
 
-import org.scilab.forge.scirenderer.Canvas;
-import org.scilab.forge.scirenderer.Drawer;
-import org.scilab.forge.scirenderer.implementation.jogl.buffers.JoGLBuffersManager;
-import org.scilab.forge.scirenderer.implementation.jogl.picking.JoGLPickingManager;
-import org.scilab.forge.scirenderer.implementation.jogl.renderer.JoGLRendererManager;
-import org.scilab.forge.scirenderer.implementation.jogl.texture.JoGLTextureManager;
-import org.scilab.forge.scirenderer.picking.PickingManager;
-
-import com.jogamp.opengl.util.awt.ImageUtil;
-import com.jogamp.opengl.util.awt.Screenshot;
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
 import java.lang.reflect.InvocationTargetException;
 import java.util.concurrent.Semaphore;
+
 import javax.media.opengl.DebugGL2;
 import javax.media.opengl.GL2;
 import javax.media.opengl.GLAutoDrawable;
@@ -37,6 +28,16 @@ import javax.media.opengl.GLPbuffer;
 import javax.media.opengl.GLProfile;
 import javax.swing.SwingUtilities;
 
+import org.scilab.forge.scirenderer.Canvas;
+import org.scilab.forge.scirenderer.Drawer;
+import org.scilab.forge.scirenderer.implementation.jogl.buffers.JoGLBuffersManager;
+import org.scilab.forge.scirenderer.implementation.jogl.picking.JoGLPickingManager;
+import org.scilab.forge.scirenderer.implementation.jogl.renderer.JoGLRendererManager;
+import org.scilab.forge.scirenderer.implementation.jogl.texture.JoGLTextureManager;
+import org.scilab.forge.scirenderer.picking.PickingManager;
+
+import com.jogamp.opengl.util.awt.Screenshot;
+
 /**
  * JoGL implementation of a Canvas.
  *
@@ -307,38 +308,15 @@ public final class JoGLCanvas implements Canvas, GLEventListener {
             if (mainDrawer != null) {
                 gl.glEnable(GL2.GL_DEPTH_TEST);
                 gl.glDepthFunc(GL2.GL_LEQUAL); // Set to less equal to allow last drawn object to be on the top.
-
-                if ((antiAliasingLevel > 0) && (antiAliasingLevel < 5) && (drawingTools.getGLCapacity().isAccumulationBufferPresent())) {
-                    org.scilab.forge.scirenderer.renderer.Renderer renderer = rendererManager.createRenderer();
-                    renderer.setDrawer(mainDrawer);
-
-                    double[][] jitter = ANTI_ALIASING_JITTER[antiAliasingLevel];
-                    Dimension dimension = getDimension();
-                    gl.glClear(GL2.GL_ACCUM_BUFFER_BIT);
-                    for (double[] aJitter : jitter) {
-                        drawingTools.glSynchronize(gl);
-
-                        gl.glMatrixMode(GL2.GL_PROJECTION);
-                        gl.glLoadIdentity();
-                        gl.glTranslated(aJitter[0] / dimension.getWidth(), aJitter[1] / dimension.getHeight(), 0.);
-
-                        gl.glClear(GL2.GL_DEPTH_BUFFER_BIT);
-                        rendererManager.draw(drawingTools, renderer);
-                        //mainDrawer.draw(drawingTools);
-                        gl.glReadBuffer(GL2.GL_BACK);
-                        gl.glAccum(GL2.GL_ACCUM, 1f / jitter.length);
-                    }
-
-                    rendererManager.dispose(drawingTools, renderer);
-
-                    gl.glDrawBuffer(GL2.GL_BACK);
-                    gl.glAccum(GL2.GL_RETURN, 1.0f);
+                if ((antiAliasingLevel > 0) && (antiAliasingLevel < 5)) {
+                    gl.glEnable(GL2.GL_MULTISAMPLE);
                 } else {
-                    gl.glMatrixMode(GL2.GL_PROJECTION);
-                    gl.glLoadIdentity();
-                    gl.glClear(GL2.GL_DEPTH_BUFFER_BIT);
-                    mainDrawer.draw(drawingTools);
+                    gl.glDisable(GL2.GL_MULTISAMPLE);
                 }
+                gl.glMatrixMode(GL2.GL_PROJECTION);
+                gl.glLoadIdentity();
+                gl.glClear(GL2.GL_DEPTH_BUFFER_BIT);
+                mainDrawer.draw(drawingTools);
             }
 
             pickingManager.glConsume(drawingTools);