Exemplo n.º 1
0
  public void setOrthographicView(int w, int h) {
    gl.glViewport(0, 0, w, h);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluOrtho2D(0.0, w, 0.0, h);

    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Exemplo n.º 2
0
  public void display(GLAutoDrawable drawable) {
    GL gl = drawable.getGL();

    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    gl.glRasterPos2i(1, 1);
    gl.glDrawPixels(
        dim.width,
        dim.height, //
        GL.GL_RGB,
        GL.GL_UNSIGNED_BYTE,
        pixels);

    gl.glFlush();
  }
Exemplo n.º 3
0
  public GLState(GL gl) {
    if (INSTANCES_COUNT == 0) {
      GLState.gl = gl;

      glTextureObjects = new HashSet<Integer>();
      glVertexBuffers = new HashSet<Integer>();
      glFrameBuffers = new HashSet<Integer>();
      glRenderBuffers = new HashSet<Integer>();
      glslPrograms = new HashSet<Integer>();
      glslShaders = new HashSet<Integer>();
      cgContexts = new HashSet<Object>();
      cgPrograms = new HashSet<Object>();
      cgEffects = new HashSet<Object>();

      getVersionNumbers();
      getAvailableExtensions();

      int[] val = {0};
      gl.glGetIntegerv(GL.GL_MAX_COLOR_ATTACHMENTS_EXT, val, 0);
      glMaxColorAttach = val[0];

      glu = new GLU();
      FBO = new GLFramebufferObject(gl);

      fboStack = new Stack<GLFramebufferObject>();
      destTexStack = new Stack<GLTexture[]>();
      screenFBO = new GLFramebufferObject(gl, true);
      currentFBO = screenFBO;
      emptyDestTex = new GLTexture[0];
      currentDestTex = emptyDestTex;

      singleFBO = false;
    }
    INSTANCES_COUNT++;
  }
Exemplo n.º 4
0
  public void clearColorBuffer(int color) {
    float r, g, b, a;
    int ir, ig, ib, ia;

    ia = (color >> 24) & 0xff;
    ir = (color >> 16) & 0xff;
    ig = (color >> 8) & 0xff;
    ib = color & 0xff;

    a = ia / 255.0f;
    r = ir / 255.0f;
    g = ig / 255.0f;
    b = ib / 255.0f;

    gl.glClearColor(r, g, b, a);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
  }
Exemplo n.º 5
0
  public void paintTex(int glid, int target, int w, int h, int color) {
    float r, g, b, a;
    int ir, ig, ib, ia;

    ia = (color >> 24) & 0xff;
    ir = (color >> 16) & 0xff;
    ig = (color >> 8) & 0xff;
    ib = color & 0xff;

    a = ia / 255.0f;
    r = ir / 255.0f;
    g = ig / 255.0f;
    b = ib / 255.0f;

    pushFramebuffer();
    setFramebuffer(FBO);
    FBO.setDrawBuffer(target, glid);

    saveView();
    setOrthographicView(w, h);
    gl.glColor4f(r, g, b, a);
    gl.glBegin(GL.GL_QUADS);
    gl.glVertex2f(0.0f, 0.0f);
    gl.glVertex2f(w, 0.0f);
    gl.glVertex2f(w, h);
    gl.glVertex2f(0.0f, h);
    gl.glEnd();
    restoreView();

    popFramebuffer();
  }
 private void checkCompressedTextureExtensions(TextureData data) {
   GL gl = GLU.getCurrentGL();
   if (data.isDataCompressed()) {
     switch (data.getInternalFormat()) {
       case GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
       case GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
       case GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
       case GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
         if (!gl.isExtensionAvailable("GL_EXT_texture_compression_s3tc")
             && !gl.isExtensionAvailable("GL_NV_texture_compression_vtc")) {
           throw new GLException("DXTn compressed textures not supported by this graphics card");
         }
         break;
       default:
         // FIXME: should test availability of more texture
         // compression extensions here
         break;
     }
   }
 }
Exemplo n.º 7
0
  public static int createGLResource(int type, int param) {
    int id = 0;
    if (type == GL_TEXTURE_OBJECT) {
      int[] temp = new int[1];
      gl.glGenTextures(1, temp, 0);
      id = temp[0];
      glTextureObjects.add(id);
    } else if (type == GL_VERTEX_BUFFER) {
      int[] temp = new int[1];
      gl.glGenBuffersARB(1, temp, 0);
      id = temp[0];
      glVertexBuffers.add(id);
    } else if (type == GL_FRAME_BUFFER) {
      int[] temp = new int[1];
      gl.glGenFramebuffersEXT(1, temp, 0);
      id = temp[0];
      glFrameBuffers.add(id);
    } else if (type == GL_RENDER_BUFFER) {
      int[] temp = new int[1];
      gl.glGenRenderbuffersEXT(1, temp, 0);
      id = temp[0];
      glRenderBuffers.add(id);
    } else if (type == GLSL_PROGRAM) {
      id = gl.glCreateProgram();
      glslPrograms.add(id);
    } else if (type == GLSL_SHADER) {
      id = gl.glCreateShader(param);
      glslShaders.add(id);
    }

    return id;
  }
Exemplo n.º 8
0
  public void clearTex(int glid, int target, int color) {
    float r, g, b, a;
    int ir, ig, ib, ia;

    ia = (color >> 24) & 0xff;
    ir = (color >> 16) & 0xff;
    ig = (color >> 8) & 0xff;
    ib = color & 0xff;

    a = ia / 255.0f;
    r = ir / 255.0f;
    g = ig / 255.0f;
    b = ib / 255.0f;

    pushFramebuffer();
    setFramebuffer(FBO);
    FBO.setDrawBuffer(target, glid);

    gl.glClearColor(r, g, b, a);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    popFramebuffer();
  }
Exemplo n.º 9
0
  public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    GL gl = drawable.getGL();

    gl.glViewport(0, 0, w, h);
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrtho(0, w, 0, h, -1.0, 1.0);
    gl.glMatrixMode(GL.GL_MODELVIEW);
  }
Exemplo n.º 10
0
  public void init(GLAutoDrawable drawable) {
    GL gl = drawable.getGL();

    float m[] = {
      0.0f, 1.0f, 0.0f, 0.0f, //
      0.0f, 0.0f, 1.0f, 0.0f, //
      1.0f, 0.0f, 0.0f, 0.0f, //
      0.0f, 0.0f, 0.0f, 1.0f
    };

    pixels = readImage("Data/leeds.bin", dim);
    System.out.println(pixels.toString());

    gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    gl.glMatrixMode(GL.GL_COLOR);
    gl.glLoadMatrixf(m, 0);
    gl.glMatrixMode(GL.GL_MODELVIEW);
  }
Exemplo n.º 11
0
 public static void deleteGLResource(int id, int type) {
   if (type == GL_TEXTURE_OBJECT) {
     if (glTextureObjects.contains(id)) {
       int[] temp = {id};
       gl.glDeleteTextures(1, temp, 0);
       glTextureObjects.remove(id);
     }
   } else if (type == GL_VERTEX_BUFFER) {
     if (glVertexBuffers.contains(id)) {
       int[] temp = {id};
       gl.glDeleteBuffersARB(1, temp, 0);
       glVertexBuffers.remove(id);
     }
   } else if (type == GL_FRAME_BUFFER) {
     if (glFrameBuffers.contains(id)) {
       int[] temp = {id};
       gl.glDeleteFramebuffersEXT(1, temp, 0);
       glFrameBuffers.remove(id);
     }
   } else if (type == GL_RENDER_BUFFER) {
     if (glRenderBuffers.contains(id)) {
       int[] temp = {id};
       gl.glDeleteRenderbuffersEXT(1, temp, 0);
       glRenderBuffers.remove(id);
     }
   } else if (type == GLSL_PROGRAM) {
     if (glslPrograms.contains(id)) {
       gl.glDeleteProgram(id);
       glslPrograms.remove(id);
     }
   } else if (type == GLSL_SHADER) {
     if (glslShaders.contains(id)) {
       gl.glDeleteShader(id);
       glslShaders.remove(id);
     }
   }
 }
 /**
  * Sets the OpenGL multi-integer texture parameter for the texture's target. Causes this texture
  * to be bound to the current texture state.
  *
  * @throws GLException if no OpenGL context was current or if any OpenGL-related errors occurred
  */
 public void setTexParameteriv(int parameterName, IntBuffer params) {
   bind();
   GL gl = GLU.getCurrentGL();
   gl.glTexParameteriv(target, parameterName, params);
 }
 /**
  * Sets the OpenGL integer texture parameter for the texture's target. This gives control over
  * parameters such as GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T, which by default are set to
  * GL_CLAMP_TO_EDGE if OpenGL 1.2 is supported on the current platform and GL_CLAMP if not. Causes
  * this texture to be bound to the current texture state.
  *
  * @throws GLException if no OpenGL context was current or if any OpenGL-related errors occurred
  */
 public void setTexParameteri(int parameterName, int value) {
   bind();
   GL gl = GLU.getCurrentGL();
   gl.glTexParameteri(target, parameterName, value);
 }
  /**
   * Updates the content area of the specified target of this texture using the data in the given
   * image. In general this is intended for construction of cube maps.
   *
   * @throws GLException if no OpenGL context was current or if any OpenGL-related errors occurred
   */
  public void updateImage(TextureData data, int target) throws GLException {
    GL gl = GLU.getCurrentGL();

    imgWidth = data.getWidth();
    imgHeight = data.getHeight();
    aspectRatio = (float) imgWidth / (float) imgHeight;
    mustFlipVertically = data.getMustFlipVertically();

    int texTarget = 0;
    int texParamTarget = this.target;

    // See whether we have automatic mipmap generation support
    boolean haveAutoMipmapGeneration =
        (gl.isExtensionAvailable("GL_VERSION_1_4")
            || gl.isExtensionAvailable("GL_SGIS_generate_mipmap"));

    // Indicate to the TextureData what functionality is available
    data.setHaveEXTABGR(gl.isExtensionAvailable("GL_EXT_abgr"));
    data.setHaveGL12(gl.isExtensionAvailable("GL_VERSION_1_2"));

    // Note that automatic mipmap generation doesn't work for
    // GL_ARB_texture_rectangle
    if ((!isPowerOfTwo(imgWidth) || !isPowerOfTwo(imgHeight)) && !haveNPOT(gl)) {
      haveAutoMipmapGeneration = false;
    }

    boolean expandingCompressedTexture = false;
    if (data.getMipmap() && !haveAutoMipmapGeneration) {
      // GLU always scales the texture's dimensions to be powers of
      // two. It also doesn't really matter exactly what the texture
      // width and height are because the texture coords are always
      // between 0.0 and 1.0.
      imgWidth = nextPowerOfTwo(imgWidth);
      imgHeight = nextPowerOfTwo(imgHeight);
      texWidth = imgWidth;
      texHeight = imgHeight;
      texTarget = GL.GL_TEXTURE_2D;
    } else if ((isPowerOfTwo(imgWidth) && isPowerOfTwo(imgHeight)) || haveNPOT(gl)) {
      if (DEBUG) {
        if (isPowerOfTwo(imgWidth) && isPowerOfTwo(imgHeight)) {
          System.err.println("Power-of-two texture");
        } else {
          System.err.println("Using GL_ARB_texture_non_power_of_two");
        }
      }

      texWidth = imgWidth;
      texHeight = imgHeight;
      texTarget = GL.GL_TEXTURE_2D;
    } else if (haveTexRect(gl) && !data.isDataCompressed()) {
      // GL_ARB_texture_rectangle does not work for compressed textures
      if (DEBUG) {
        System.err.println("Using GL_ARB_texture_rectangle");
      }

      texWidth = imgWidth;
      texHeight = imgHeight;
      texTarget = GL.GL_TEXTURE_RECTANGLE_ARB;
    } else {
      // If we receive non-power-of-two compressed texture data and
      // don't have true hardware support for compressed textures, we
      // can fake this support by producing an empty "compressed"
      // texture image, using glCompressedTexImage2D with that to
      // allocate the texture, and glCompressedTexSubImage2D with the
      // incoming data.
      if (data.isDataCompressed()) {
        if (data.getMipmapData() != null) {

          // We don't currently support expanding of compressed,
          // mipmapped non-power-of-two textures to the nearest power
          // of two; the obvious port of the non-mipmapped code didn't
          // work
          throw new GLException(
              "Mipmapped non-power-of-two compressed textures only supported on OpenGL 2.0 hardware (GL_ARB_texture_non_power_of_two)");
        }

        expandingCompressedTexture = true;
      }

      if (DEBUG) {
        System.err.println("Expanding texture to power-of-two dimensions");
      }

      if (data.getBorder() != 0) {
        throw new RuntimeException(
            "Scaling up a non-power-of-two texture which has a border won't work");
      }
      texWidth = nextPowerOfTwo(imgWidth);
      texHeight = nextPowerOfTwo(imgHeight);
      texTarget = GL.GL_TEXTURE_2D;
    }

    texParamTarget = texTarget;
    setImageSize(imgWidth, imgHeight, texTarget);

    if (target != 0) {
      // Allow user to override auto detection and skip bind step (for
      // cubemap construction)
      texTarget = target;
      if (this.target == 0) {
        throw new GLException("Override of target failed; no target specified yet");
      }
      texParamTarget = this.target;
      gl.glBindTexture(texParamTarget, texID);
    } else {
      gl.glBindTexture(texTarget, texID);
    }

    if (data.getMipmap() && !haveAutoMipmapGeneration) {
      int[] align = new int[1];
      gl.glGetIntegerv(GL.GL_UNPACK_ALIGNMENT, align, 0); // save alignment
      gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, data.getAlignment());

      if (data.isDataCompressed()) {
        throw new GLException("May not request mipmap generation for compressed textures");
      }

      try {
        GLU glu = new GLU();
        glu.gluBuild2DMipmaps(
            texTarget,
            data.getInternalFormat(),
            data.getWidth(),
            data.getHeight(),
            data.getPixelFormat(),
            data.getPixelType(),
            data.getBuffer());
      } finally {
        gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, align[0]); // restore alignment
      }
    } else {
      checkCompressedTextureExtensions(data);
      Buffer[] mipmapData = data.getMipmapData();
      if (mipmapData != null) {
        int width = texWidth;
        int height = texHeight;
        for (int i = 0; i < mipmapData.length; i++) {
          if (data.isDataCompressed()) {
            // Need to use glCompressedTexImage2D directly to allocate and fill this image
            // Avoid spurious memory allocation when possible
            gl.glCompressedTexImage2D(
                texTarget,
                i,
                data.getInternalFormat(),
                width,
                height,
                data.getBorder(),
                mipmapData[i].remaining(),
                mipmapData[i]);
          } else {
            // Allocate texture image at this level
            gl.glTexImage2D(
                texTarget,
                i,
                data.getInternalFormat(),
                width,
                height,
                data.getBorder(),
                data.getPixelFormat(),
                data.getPixelType(),
                null);
            updateSubImageImpl(data, texTarget, i, 0, 0, 0, 0, data.getWidth(), data.getHeight());
          }

          width = Math.max(width / 2, 1);
          height = Math.max(height / 2, 1);
        }
      } else {
        if (data.isDataCompressed()) {
          if (!expandingCompressedTexture) {
            // Need to use glCompressedTexImage2D directly to allocate and fill this image
            // Avoid spurious memory allocation when possible
            gl.glCompressedTexImage2D(
                texTarget,
                0,
                data.getInternalFormat(),
                texWidth,
                texHeight,
                data.getBorder(),
                data.getBuffer().capacity(),
                data.getBuffer());
          } else {
            ByteBuffer buf =
                DDSImage.allocateBlankBuffer(texWidth, texHeight, data.getInternalFormat());
            gl.glCompressedTexImage2D(
                texTarget,
                0,
                data.getInternalFormat(),
                texWidth,
                texHeight,
                data.getBorder(),
                buf.capacity(),
                buf);
            updateSubImageImpl(data, texTarget, 0, 0, 0, 0, 0, data.getWidth(), data.getHeight());
          }
        } else {
          if (data.getMipmap() && haveAutoMipmapGeneration) {
            // For now, only use hardware mipmapping for uncompressed 2D
            // textures where the user hasn't explicitly specified
            // mipmap data; don't know about interactions between
            // GL_GENERATE_MIPMAP and glCompressedTexImage2D
            gl.glTexParameteri(texParamTarget, GL.GL_GENERATE_MIPMAP, GL.GL_TRUE);
            usingAutoMipmapGeneration = true;
          }

          gl.glTexImage2D(
              texTarget,
              0,
              data.getInternalFormat(),
              texWidth,
              texHeight,
              data.getBorder(),
              data.getPixelFormat(),
              data.getPixelType(),
              null);
          updateSubImageImpl(data, texTarget, 0, 0, 0, 0, 0, data.getWidth(), data.getHeight());
        }
      }
    }

    int minFilter = (data.getMipmap() ? GL.GL_LINEAR_MIPMAP_LINEAR : GL.GL_LINEAR);
    int magFilter = GL.GL_LINEAR;
    int wrapMode = (gl.isExtensionAvailable("GL_VERSION_1_2") ? GL.GL_CLAMP_TO_EDGE : GL.GL_CLAMP);

    // REMIND: figure out what to do for GL_TEXTURE_RECTANGLE_ARB
    if (texTarget != GL.GL_TEXTURE_RECTANGLE_ARB) {
      gl.glTexParameteri(texParamTarget, GL.GL_TEXTURE_MIN_FILTER, minFilter);
      gl.glTexParameteri(texParamTarget, GL.GL_TEXTURE_MAG_FILTER, magFilter);
      gl.glTexParameteri(texParamTarget, GL.GL_TEXTURE_WRAP_S, wrapMode);
      gl.glTexParameteri(texParamTarget, GL.GL_TEXTURE_WRAP_T, wrapMode);
      if (this.target == GL.GL_TEXTURE_CUBE_MAP) {
        gl.glTexParameteri(texParamTarget, GL.GL_TEXTURE_WRAP_R, wrapMode);
      }
    }

    // Don't overwrite target if we're loading e.g. faces of a cube
    // map
    if ((this.target == 0)
        || (this.target == GL.GL_TEXTURE_2D)
        || (this.target == GL.GL_TEXTURE_RECTANGLE_ARB)) {
      this.target = texTarget;
    }

    // This estimate will be wrong for cube maps
    estimatedMemorySize = data.getEstimatedMemorySize();
  }
 private static boolean haveTexRect(GL gl) {
   return (!disableTexRect
       && TextureIO.isTexRectEnabled()
       && gl.isExtensionAvailable("GL_ARB_texture_rectangle"));
 }
 // Helper routines for disabling certain codepaths
 private static boolean haveNPOT(GL gl) {
   return (!disableNPOT && gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two"));
 }
Exemplo n.º 17
0
  protected void getAvailableExtensions() {
    // For a complete list of extensions, go to this sections in the openGL
    // registry:
    // http://www.opengl.org/registry/#arbextspecs
    // http://www.opengl.org/registry/#otherextspecs
    String extensions = gl.glGetString(GL.GL_EXTENSIONS);

    if (extensions.indexOf("GL_ARB_multitexture") == -1) {
      multiTexAvailable = false;
      System.out.println("GL_ARB_multitexture extension not available");
    }

    if (extensions.indexOf("GL_ARB_vertex_buffer_object") == -1) {
      vbosAvailable = false;
      System.out.println("GL_ARB_vertex_buffer_object extension not available");
    }

    if (extensions.indexOf("GL_EXT_framebuffer_object") == -1) {
      fbosAvailable = false;
      System.out.println("GL_EXT_framebuffer_object extension not available");
    }

    if (extensions.indexOf("GL_ARB_shader_objects") == -1) {
      shadersAvailable = false;
      System.out.println("GL_ARB_shader_objects extension not available");
    }

    if (extensions.indexOf("GL_EXT_geometry_shader4") == -1) {
      geoShadersAvailable = false;
      System.out.println("GL_ARB_geometry_shader4 extension not available");
    }

    if (extensions.indexOf("GL_ARB_vertex_shader") == -1) {
      vertShadersAvailable = false;
      System.out.println("GL_ARB_vertex_shader extension not available");
    }

    if (extensions.indexOf("GL_ARB_fragment_shader") == -1) {
      fragShadersAvailable = false;
      System.out.println("GL_ARB_fragment_shader extension not available");
    }

    if (extensions.indexOf("GL_ARB_shading_language_100") == -1) {
      glsl100Available = false;
      System.out.println("GL_ARB_shading_language_100 extension not available");
    }

    if (extensions.indexOf("GL_ARB_texture_float") == -1) {
      floatTexAvailable = false;
      System.out.println("GL_ARB_texture_float extension not available");
    }

    if (extensions.indexOf("GL_ARB_texture_non_power_of_two") == -1) {
      nonTwoPowTexAvailable = false;
      System.out.println("GL_ARB_texture_non_power_of_two extension not available");
    }

    if (extensions.indexOf("GL_EXT_framebuffer_multisample") == -1) {
      fboMultisampleAvailable = false;
      System.out.println("GL_EXT_framebuffer_multisample extension not available");
    }
  }
Exemplo n.º 18
0
 protected void setupDefaultBlending() {
   // Default blending mode in PGraphicsOpenGL.
   blendMode = BLEND;
   gl.glBlendEquation(GL.GL_FUNC_ADD);
   gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
 }
Exemplo n.º 19
0
 protected void getVersionNumbers() {
   glVersion = gl.glGetString(GL.GL_VERSION);
   glMajor = Character.getNumericValue(glVersion.charAt(0));
   glMinor = Character.getNumericValue(glVersion.charAt(2));
   glslVersion = gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION_ARB);
 }
Exemplo n.º 20
0
 public void saveGLState() {
   gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
   saveGLMatrices();
 }
Exemplo n.º 21
0
  protected void setupBlending(int mode) {
    blendMode = mode;

    if (blendMode == REPLACE) {
      gl.glBlendEquation(GL.GL_FUNC_ADD);
      gl.glBlendFunc(GL.GL_ONE, GL.GL_ZERO);
    } else if (blendMode == BLEND) {
      gl.glBlendEquation(GL.GL_FUNC_ADD);
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
    } else if (blendMode == ADD) {
      gl.glBlendEquation(GL.GL_FUNC_ADD);
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
    } else if (blendMode == SUBTRACT) {
      gl.glBlendEquation(GL.GL_FUNC_ADD);
      gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ZERO);
    } else if (blendMode == LIGHTEST) {
      gl.glBlendEquation(GL.GL_MAX);
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_DST_ALPHA);
    } else if (blendMode == DARKEST) {
      gl.glBlendEquation(GL.GL_MIN);
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_DST_ALPHA);
    } else if (blendMode == DIFFERENCE) {
      gl.glBlendEquation(GL.GL_FUNC_REVERSE_SUBTRACT);
      gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE);
    } else if (blendMode == EXCLUSION) {
      gl.glBlendEquation(GL.GL_FUNC_ADD);
      gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE_MINUS_SRC_COLOR);
    } else if (blendMode == MULTIPLY) {
      gl.glBlendEquation(GL.GL_FUNC_ADD);
      gl.glBlendFunc(GL.GL_DST_COLOR, GL.GL_SRC_COLOR);
    } else if (blendMode == SCREEN) {
      gl.glBlendEquation(GL.GL_FUNC_ADD);
      gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE);
    } else if (blendMode == BACKGROUND_ALPHA) {
      gl.glBlendColor(0.0f, 0.0f, 0.0f, 1.0f);
      gl.glBlendFunc(GL.GL_ONE, GL.GL_CONSTANT_COLOR);
    }
    // HARD_LIGHT, SOFT_LIGHT, OVERLAY, DODGE, BURN modes cannot be implemented
    // in fixed-function pipeline because they require conditional blending and
    // non-linear blending equations.
  }
Exemplo n.º 22
0
 public void restoreGLState() {
   restoreGLMatrices();
   gl.glPopAttrib();
 }
 /**
  * Sets the OpenGL multi-integer texture parameter for the texture's target. Causes this texture
  * to be bound to the current texture state.
  *
  * @throws GLException if no OpenGL context was current or if any OpenGL-related errors occurred
  */
 public void setTexParameteriv(int parameterName, int[] params, int params_offset) {
   bind();
   GL gl = GLU.getCurrentGL();
   gl.glTexParameteriv(target, parameterName, params, params_offset);
 }
Exemplo n.º 24
0
 public void saveGLMatrices() {
   gl.glMatrixMode(GL.GL_PROJECTION);
   gl.glPushMatrix();
   gl.glMatrixMode(GL.GL_MODELVIEW);
   gl.glPushMatrix();
 }
Exemplo n.º 25
0
  public void copyTex(GLTexture srcTex, GLTexture destTex) {
    float uscale = srcTex.getMaxTextureCoordS();
    float vscale = srcTex.getMaxTextureCoordT();

    float cx = 0.0f;
    float sx = +1.0f;
    if (destTex.isFlippedX()) {
      cx = 1.0f;
      sx = -1.0f;
    }

    float cy = 0.0f;
    float sy = +1.0f;
    if (destTex.isFlippedY()) {
      cy = 1.0f;
      sy = -1.0f;
    }

    gl.glEnable(srcTex.getTextureTarget());

    gl.glActiveTexture(GL.GL_TEXTURE0);
    gl.glBindTexture(srcTex.getTextureTarget(), srcTex.getTextureID());

    pushFramebuffer();
    setFramebuffer(FBO);
    FBO.setDrawBuffer(destTex.getTextureTarget(), destTex.getTextureID());

    saveView();
    setOrthographicView(destTex.width, destTex.height);
    gl.glEnable(srcTex.getTextureTarget());
    gl.glActiveTexture(GL.GL_TEXTURE0);
    gl.glBindTexture(srcTex.getTextureTarget(), srcTex.getTextureID());
    gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glBegin(GL.GL_QUADS);
    gl.glTexCoord2f((cx + sx * 0.0f) * uscale, (cy + sy * 0.0f) * vscale);
    gl.glVertex2f(0.0f, 0.0f);

    gl.glTexCoord2f((cx + sx * 1.0f) * uscale, (cy + sy * 0.0f) * vscale);
    gl.glVertex2f(srcTex.width, 0.0f);

    gl.glTexCoord2f((cx + sx * 1.0f) * uscale, (cy + sy * 1.0f) * vscale);
    gl.glVertex2f(srcTex.width, srcTex.height);

    gl.glTexCoord2f((cx + sx * 0.0f) * uscale, (cy + sy * 1.0f) * vscale);
    gl.glVertex2f(0.0f, srcTex.height);
    gl.glEnd();
    gl.glBindTexture(srcTex.getTextureTarget(), 0);
    restoreView();

    popFramebuffer();
  }
Exemplo n.º 26
0
 public void restoreGLMatrices() {
   gl.glMatrixMode(GL.GL_PROJECTION);
   gl.glPopMatrix();
   gl.glMatrixMode(GL.GL_MODELVIEW);
   gl.glPopMatrix();
 }
  private void updateSubImageImpl(
      TextureData data,
      int newTarget,
      int mipmapLevel,
      int dstx,
      int dsty,
      int srcx,
      int srcy,
      int width,
      int height)
      throws GLException {
    GL gl = GLU.getCurrentGL();
    data.setHaveEXTABGR(gl.isExtensionAvailable("GL_EXT_abgr"));
    data.setHaveGL12(gl.isExtensionAvailable("GL_VERSION_1_2"));

    Buffer buffer = data.getBuffer();
    if (buffer == null && data.getMipmapData() == null) {
      // Assume user just wanted to get the Texture object allocated
      return;
    }

    int rowlen = data.getRowLength();
    int dataWidth = data.getWidth();
    int dataHeight = data.getHeight();
    if (data.getMipmapData() != null) {
      // Compute the width, height and row length at the specified mipmap level
      // Note we do not support specification of the row length for
      // mipmapped textures at this point
      for (int i = 0; i < mipmapLevel; i++) {
        width = Math.max(width / 2, 1);
        height = Math.max(height / 2, 1);

        dataWidth = Math.max(dataWidth / 2, 1);
        dataHeight = Math.max(dataHeight / 2, 1);
      }
      rowlen = 0;
      buffer = data.getMipmapData()[mipmapLevel];
    }

    // Clip incoming rectangles to what is available both on this
    // texture and in the incoming TextureData
    if (srcx < 0) {
      width += srcx;
      srcx = 0;
    }
    if (srcy < 0) {
      height += srcy;
      srcy = 0;
    }
    // NOTE: not sure whether the following two are the correct thing to do
    if (dstx < 0) {
      width += dstx;
      dstx = 0;
    }
    if (dsty < 0) {
      height += dsty;
      dsty = 0;
    }

    if (srcx + width > dataWidth) {
      width = dataWidth - srcx;
    }
    if (srcy + height > dataHeight) {
      height = dataHeight - srcy;
    }
    if (dstx + width > texWidth) {
      width = texWidth - dstx;
    }
    if (dsty + height > texHeight) {
      height = texHeight - dsty;
    }

    checkCompressedTextureExtensions(data);

    if (data.isDataCompressed()) {
      gl.glCompressedTexSubImage2D(
          newTarget,
          mipmapLevel,
          dstx,
          dsty,
          width,
          height,
          data.getInternalFormat(),
          buffer.remaining(),
          buffer);
    } else {
      int[] align = new int[1];
      int[] rowLength = new int[1];
      int[] skipRows = new int[1];
      int[] skipPixels = new int[1];
      gl.glGetIntegerv(GL.GL_UNPACK_ALIGNMENT, align, 0); // save alignment
      gl.glGetIntegerv(GL.GL_UNPACK_ROW_LENGTH, rowLength, 0); // save row length
      gl.glGetIntegerv(GL.GL_UNPACK_SKIP_ROWS, skipRows, 0); // save skipped rows
      gl.glGetIntegerv(GL.GL_UNPACK_SKIP_PIXELS, skipPixels, 0); // save skipped pixels
      gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, data.getAlignment());
      if (DEBUG && VERBOSE) {
        System.out.println("Row length  = " + rowlen);
        System.out.println("skip pixels = " + srcx);
        System.out.println("skip rows   = " + srcy);
        System.out.println("dstx        = " + dstx);
        System.out.println("dsty        = " + dsty);
        System.out.println("width       = " + width);
        System.out.println("height      = " + height);
      }
      gl.glPixelStorei(GL.GL_UNPACK_ROW_LENGTH, rowlen);
      gl.glPixelStorei(GL.GL_UNPACK_SKIP_ROWS, srcy);
      gl.glPixelStorei(GL.GL_UNPACK_SKIP_PIXELS, srcx);

      gl.glTexSubImage2D(
          newTarget,
          mipmapLevel,
          dstx,
          dsty,
          width,
          height,
          data.getPixelFormat(),
          data.getPixelType(),
          buffer);
      gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, align[0]); // restore alignment
      gl.glPixelStorei(GL.GL_UNPACK_ROW_LENGTH, rowLength[0]); // restore row length
      gl.glPixelStorei(GL.GL_UNPACK_SKIP_ROWS, skipRows[0]); // restore skipped rows
      gl.glPixelStorei(GL.GL_UNPACK_SKIP_PIXELS, skipPixels[0]); // restore skipped pixels
    }
  }
Exemplo n.º 28
0
 protected void enableBlend() {
   blendEnabled = true;
   gl.glEnable(GL.GL_BLEND);
 }
 /**
  * Creates a new texture ID.
  *
  * @param gl the GL object associated with the current OpenGL context
  * @return a new texture ID
  */
 private static int createTextureID(GL gl) {
   int[] tmp = new int[1];
   gl.glGenTextures(1, tmp, 0);
   return tmp[0];
 }
Exemplo n.º 30
0
 protected void disableBlend() {
   blendEnabled = false;
   gl.glDisable(GL.GL_BLEND);
 }