Пример #1
0
  @Override
  public final void ppBegin(final GL gl) {
    if (null == sp) {
      throw new IllegalStateException("Not initialized");
    }
    if (0 == frameStart) {
      throw new IllegalStateException("beginFrame not called");
    }
    final GL2ES2 gl2es2 = gl.getGL2ES2();

    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glActiveTexture(GL.GL_TEXTURE0 + getTextureUnit());

    gl2es2.glDisable(GL.GL_CULL_FACE);
    gl2es2.glDisable(GL.GL_DEPTH_TEST);
    gl2es2.glDisable(GL.GL_BLEND);

    if (!gl2es2.isGLcore()) {
      gl2es2.glEnable(GL.GL_TEXTURE_2D);
    }

    sp.useProgram(gl2es2, true);

    gl2es2.glUniform(texUnit0);
  }
Пример #2
0
  public static void setBoundElementVBO(final RendererRecord rendRecord, final int id) {
    final GL gl = GLContext.getCurrentGL();

    if (!rendRecord.isElementVboValid() || rendRecord.getCurrentElementVboId() != id) {
      gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, id);
      rendRecord.setCurrentElementVboId(id);
      rendRecord.setElementVboValid(true);
    }
  }
Пример #3
0
 @Override
 public void init(final GLAutoDrawable drawable) {
   final GL gl = drawable.getGL();
   System.err.println("GL_VENDOR   " + gl.glGetString(GL.GL_VENDOR));
   System.err.println("GL_RENDERER " + gl.glGetString(GL.GL_RENDERER));
   System.err.println("GL_VERSION  " + gl.glGetString(GL.GL_VERSION));
   if (useVBO) {
     gl.glGenBuffers(1, vboName, 0);
     if (0 == vboName[0]) {
       throw new GLException("glGenBuffers didn't return valid VBO name");
     }
   }
 }
Пример #4
0
  protected static void setup(GL pGL, int width, int height) {
    pGL.getGL2().glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pGL.getGL2().glLoadIdentity();

    // coordinate system origin at lower left with width and height same as the
    // window
    final GLU glu = new GLU();
    glu.gluOrtho2D(0.0f, width, 0.0f, height);

    pGL.getGL2().glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pGL.getGL2().glLoadIdentity();

    pGL.glViewport(0, 0, width, height);
  }
Пример #5
0
  protected void applyBackgroundTextureState(
      DrawContext dc, int width, int height, double opacity, WWTexture texture) {
    super.applyBackgroundTextureState(dc, width, height, opacity, texture);

    // Setup the texture filters to correspond to the smoothing and mipmap settings.
    int minFilter =
        this.isEnableSmoothing()
            ? (this.isUseMipmaps() ? GL.GL_LINEAR_MIPMAP_LINEAR : GL.GL_LINEAR)
            : GL.GL_NEAREST;
    int magFilter = this.isEnableSmoothing() ? GL.GL_LINEAR : GL.GL_NEAREST;

    GL gl = dc.getGL();
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, minFilter);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, magFilter);
  }
Пример #6
0
  public void drawGL2(GL gl) {
    gl.getGL2().glPointSize(width);
    gl.getGL2().glBegin(GL.GL_POINTS);

    if (coordinates != null) {
      for (Coord3d coord : coordinates) {
        Color color = mapper.getColor(coord); // TODO: should store
        // result in the
        // point color
        gl.getGL2().glColor4f(color.r, color.g, color.b, color.a);
        gl.getGL2().glVertex3f(coord.x, coord.y, coord.z);
      }
    }
    gl.getGL2().glEnd();
  }
Пример #7
0
  protected void checkError(GL gl, String location) {

    int error = gl.glGetError();
    if (error != GL_NO_ERROR) {
      String errorString;
      switch (error) {
        case GL_INVALID_ENUM:
          errorString = "GL_INVALID_ENUM";
          break;
        case GL_INVALID_VALUE:
          errorString = "GL_INVALID_VALUE";
          break;
        case GL_INVALID_OPERATION:
          errorString = "GL_INVALID_OPERATION";
          break;
        case GL_INVALID_FRAMEBUFFER_OPERATION:
          errorString = "GL_INVALID_FRAMEBUFFER_OPERATION";
          break;
        case GL_OUT_OF_MEMORY:
          errorString = "GL_OUT_OF_MEMORY";
          break;
        default:
          errorString = "UNKNOWN";
          break;
      }
      System.out.println("OpenGL Error(" + errorString + "): " + location);
      throw new Error();
    }
  }
Пример #8
0
  @Override
  public final void ppOneEye(final GL gl, final int eyeNum) {
    final GenericEye eye = eyes[eyeNum];
    final GL2ES2 gl2es2 = gl.getGL2ES2();

    eye.updateUniform(gl2es2, sp);
    eye.enableVBO(gl2es2, true);
    gl2es2.glDrawElements(GL.GL_TRIANGLES, eye.indexCount, GL.GL_UNSIGNED_SHORT, 0);
    eyes[eyeNum].enableVBO(gl2es2, false);
  }
Пример #9
0
  @Override
  public void draw(GL gl, GLU glu, Camera cam) {
    doTransform(gl, glu, cam);

    if (gl.isGL2()) {
      drawGL2(gl);
    } else {
      drawGLES2();
    }

    doDrawBounds(gl, glu, cam);
  }
Пример #10
0
  @Test
  public void test02GLDebugError() throws InterruptedException {
    final GLProfile glp = GLProfile.getDefault();

    final WindowContext winctx = createWindow(glp, true);

    final MyGLDebugListener myGLDebugListener =
        new MyGLDebugListener(
            GL2ES2.GL_DEBUG_SOURCE_API, GL2ES2.GL_DEBUG_TYPE_ERROR, GL2ES2.GL_DEBUG_SEVERITY_HIGH);
    winctx.context.addGLDebugListener(myGLDebugListener);

    final GL gl = winctx.context.getGL();

    gl.glBindFramebuffer(-1, -1); // ERROR !

    if (winctx.context.isGLDebugMessageEnabled()) {
      Assert.assertEquals(true, myGLDebugListener.received());
    }

    destroyWindow(winctx);
  }
Пример #11
0
  public static void applyScissors(final RendererRecord rendRecord) {
    final GL gl = GLContext.getCurrentGL();
    final Stack<ReadOnlyRectangle2> clips = rendRecord.getScissorClips();

    if (clips.size() > 0) {
      final Rectangle2 init = Rectangle2.fetchTempInstance();
      init.set(-1, -1, -1, -1);
      ReadOnlyRectangle2 r;
      boolean first = true;
      for (int i = clips.size(); --i >= 0; ) {
        r = clips.get(i);

        if (r == null) {
          break;
        }
        if (first) {
          init.set(r);
          first = false;
        } else {
          init.intersect(r, init);
        }
        if (init.getWidth() <= 0 || init.getHeight() <= 0) {
          init.setWidth(0);
          init.setHeight(0);
          break;
        }
      }

      if (init.getWidth() == -1) {
        setClippingEnabled(rendRecord, false);
      } else {
        setClippingEnabled(rendRecord, true);
        gl.glScissor(init.getX(), init.getY(), init.getWidth(), init.getHeight());
      }
      Rectangle2.releaseTempInstance(init);
    } else {
      // no clips, so disable
      setClippingEnabled(rendRecord, false);
    }
  }
Пример #12
0
 @Override
 public final void dispose(final GL gl) {
   final GL2ES2 gl2es2 = gl.getGL2ES2();
   if (null != sp) {
     sp.useProgram(gl2es2, false);
   }
   for (int i = 0; i < eyes.length; i++) {
     eyes[i].dispose(gl2es2);
   }
   if (null != sp) {
     sp.destroy(gl2es2);
   }
 }
Пример #13
0
 @Override
 public void clear(final GL gl, final int sizeLimit, final boolean fading) {
   isFading = fading;
   if (sizeLimit == 0) {
     objects.clear();
   } else {
     int size = objects.size();
     for (int i = 0, n = size - sizeLimit; i < n; i++) {
       objects.poll();
     }
   }
   currentList = newCurrentList();
   objects.offer(currentList);
   Integer index = openGLListIndex;
   if (index != null) {
     gl.getGL2().glDeleteLists(index, 1);
     openGLListIndex = null;
   }
 }
Пример #14
0
  protected static void render(GL pGL, int width, int height) {
    pGL.glClear(GL.GL_COLOR_BUFFER_BIT);

    // draw a triangle filling the window
    pGL.getGL2().glLoadIdentity();
    pGL.getGL2().glBegin(GL.GL_TRIANGLES);
    pGL.getGL2().glColor3f(r, 0, 0);
    pGL.getGL2().glVertex2f(0, 0);
    pGL.getGL2().glColor3f(0, g, 0);
    pGL.getGL2().glVertex2f(width, 0);
    pGL.getGL2().glColor3f(0, 0, b);
    pGL.getGL2().glVertex2f(width / 2, height);
    pGL.getGL2().glEnd();
  }
Пример #15
0
  public void init(final GLAutoDrawable drawable) {
    GL _gl = drawable.getGL();

    _gl.glGetError(); // flush error ..

    if (glDebug) {
      try {
        _gl =
            _gl.getContext()
                .setGL(GLPipelineFactory.create("com.jogamp.opengl.Debug", null, _gl, null));
      } catch (final Exception e) {
        throw new RuntimeException("can not set debug pipeline", e);
      }
    }

    if (glTrace) {
      try {
        _gl =
            _gl.getContext()
                .setGL(
                    GLPipelineFactory.create(
                        "com.jogamp.opengl.Trace", null, _gl, new Object[] {System.err}));
      } catch (final Exception e) {
        throw new RuntimeException("can not set trace pipeline", e);
      }
    }

    System.out.println(_gl);

    _gl.getContext().setGLReadDrawable(externalRead);
    if (_gl.isGL2GL3()) {
      _gl.getGL2GL3().glReadBuffer(GL.GL_FRONT);
    }
    System.out.println("---------------------------");
    System.out.println(_gl.getContext());
    System.out.println("---------------------------");
  }
Пример #16
0
 @Override
 public final void ppEnd(final GL gl) {
   sp.useProgram(gl.getGL2ES2(), false);
 }
Пример #17
0
  @Override
  public final void init(final GL gl) {
    if (StereoDevice.DEBUG) {
      System.err.println(JoglVersion.getGLInfo(gl, null).toString());
    }
    if (null != sp) {
      throw new IllegalStateException("Already initialized");
    }
    if (!ppAvailable()) {
      return;
    }
    final GL2ES2 gl2es2 = gl.getGL2ES2();

    final String vertexShaderBasename;
    final String fragmentShaderBasename;
    {
      final boolean usesTimewarp = StereoUtil.usesTimewarpDistortion(distortionBits);
      final boolean usesChromatic = StereoUtil.usesChromaticDistortion(distortionBits);

      final StringBuilder sb = new StringBuilder();
      sb.append(shaderPrefix01);
      if (!usesChromatic && !usesTimewarp) {
        sb.append(shaderPlainSuffix);
      } else if (usesChromatic && !usesTimewarp) {
        sb.append(shaderChromaSuffix);
      } else if (usesTimewarp) {
        sb.append(shaderTimewarpSuffix);
        if (usesChromatic) {
          sb.append(shaderChromaSuffix);
        }
      }
      vertexShaderBasename = sb.toString();
      sb.setLength(0);
      sb.append(shaderPrefix01);
      if (usesChromatic) {
        sb.append(shaderChromaSuffix);
      } else {
        sb.append(shaderPlainSuffix);
      }
      fragmentShaderBasename = sb.toString();
    }
    final ShaderCode vp0 =
        ShaderCode.create(
            gl2es2,
            GL2ES2.GL_VERTEX_SHADER,
            GenericStereoDeviceRenderer.class,
            "shader",
            "shader/bin",
            vertexShaderBasename,
            true);
    final ShaderCode fp0 =
        ShaderCode.create(
            gl2es2,
            GL2ES2.GL_FRAGMENT_SHADER,
            GenericStereoDeviceRenderer.class,
            "shader",
            "shader/bin",
            fragmentShaderBasename,
            true);
    vp0.defaultShaderCustomization(gl2es2, true, true);
    fp0.defaultShaderCustomization(gl2es2, true, true);

    sp = new ShaderProgram();
    sp.add(gl2es2, vp0, System.err);
    sp.add(gl2es2, fp0, System.err);
    if (!sp.link(gl2es2, System.err)) {
      throw new GLException("could not link program: " + sp);
    }
    sp.useProgram(gl2es2, true);
    if (0 > texUnit0.setLocation(gl2es2, sp.program())) {
      throw new GLException("Couldn't locate " + texUnit0);
    }
    for (int i = 0; i < eyes.length; i++) {
      eyes[i].linkData(gl2es2, sp);
    }
    sp.useProgram(gl2es2, false);
  }
Пример #18
0
 public final void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
   GL gl = drawable.getGL();
   gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
   gl.glViewport(0, 0, width, height);
   return;
 }
Пример #19
-1
 @Override
 public void dispose(final GLAutoDrawable drawable) {
   final GL gl = drawable.getGL();
   if (0 != vboName[0]) {
     gl.glDeleteBuffers(1, vboName, 0);
     vboName[0] = 0;
   }
 }
Пример #20
-1
  public static void setClippingEnabled(final RendererRecord rendRecord, final boolean enabled) {
    final GL gl = GLContext.getCurrentGL();

    if (enabled && (!rendRecord.isClippingTestValid() || !rendRecord.isClippingTestEnabled())) {
      gl.glEnable(GL.GL_SCISSOR_TEST);
      rendRecord.setClippingTestEnabled(true);
    } else if (!enabled
        && (!rendRecord.isClippingTestValid() || rendRecord.isClippingTestEnabled())) {
      gl.glDisable(GL.GL_SCISSOR_TEST);
      rendRecord.setClippingTestEnabled(false);
    }
    rendRecord.setClippingTestValid(true);
  }