Package com.jogamp.opengl.util.texture

Examples of com.jogamp.opengl.util.texture.TextureData


        _capsUtil = new CapsUtil();
    }

    @Override
    public Image load(final InputStream is, final boolean flipped) throws IOException {
        final TextureData textureData = TextureIO.newTextureData(_capsUtil.getProfile(), is, true, null);
        final Buffer textureDataBuffer = textureData.getBuffer();
        final Image ardorImage = new Image();
        final TYPE bufferDataType = getBufferDataType(textureDataBuffer);
        if (bufferDataType == null) {
            throw new UnsupportedOperationException("Unknown buffer type " + textureDataBuffer.getClass().getName());
        } else {
            final int dataSizeInBytes = textureDataBuffer.capacity() * Buffers.sizeOfBufferElem(textureDataBuffer);
            final ByteBuffer scratch = createOnHeap ? BufferUtils.createByteBufferOnHeap(dataSizeInBytes) : Buffers
                    .newDirectByteBuffer(dataSizeInBytes);
            if (flipped) {
                flipImageData(textureDataBuffer, scratch, dataSizeInBytes, bufferDataType, textureData.getWidth(),
                        textureData.getHeight());
            } else {
                copyImageData(textureDataBuffer, scratch, bufferDataType);
            }
            ardorImage.setWidth(textureData.getWidth());
            ardorImage.setHeight(textureData.getHeight());
            ardorImage.setData(scratch);
            ardorImage.setDataFormat(JoglTextureUtil.getImageDataFormat(textureData.getPixelFormat()));
            // ardorImage.setDataType(JoglTextureUtil.getPixelDataType(textureData.getPixelType()));
            ardorImage.setDataType(PixelDataType.UnsignedByte);
            return ardorImage;
        }
    }
View Full Code Here


  private void loadTex(GL2 gl) throws IOException{
    BufferedImage atlas = TextureAtlas.getAtlas();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(atlas, "png", baos);
    InputStream is = new ByteArrayInputStream(baos.toByteArray());
    TextureData data = TextureIO.newTextureData(gl.getGLProfile(), is, false, "png");
    this.ttex = TextureIO.newTexture(data);
  }
View Full Code Here

    this.buffered = true;
    this.forceAlpha = false;
   
    if(bufferType == BufferTypes.RGBA_4Byte) {
      try {
        TextureData tempData = TextureIO.newTextureData(GLProfile.get(GLProfile.GL2), url, GL.GL_RGBA, GL.GL_RGBA, false, null);
        if(tempData.getPixelFormat() != GL.GL_RGBA) {
          textureData = convertToRGBA(tempData);
          tempData.flush();
        } else {
          textureData = tempData;
        }
        this.alpha = true;
      } catch (Throwable t) {
        throw new RuntimeException("Error loading image: " + url, t);
      }
    } else if(bufferType == BufferTypes.RGB_3Byte) {
      try {
        TextureData tempData = TextureIO.newTextureData(GLProfile.get(GLProfile.GL2), url, GL.GL_RGB, GL.GL_RGB, false, null);
        if(tempData.getPixelFormat() != GL.GL_RGB) {
          textureData = convertToRGB(tempData);
          tempData.flush();
        } else {
          textureData = tempData;
        }
        if(textureData.getPixelFormat() != GL.GL_RGB) throw new RuntimeException("Unexpected pixel format");
        this.alpha = false;
View Full Code Here

    if(bufferType == BufferTypes.RGBA_4Byte) {
      bytes = new byte[width*height*4];
      Arrays.fill(bytes, (byte)0);
      byteBuffer = ByteBuffer.wrap(bytes);
     
      textureData = new TextureData(GLProfile.get(GLProfile.GL2), GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, false, false, true, byteBuffer, null);
      textureData.setRowLength(width);
      if(textureData.getPixelFormat() != GL.GL_RGBA) throw new RuntimeException("Unexpected pixel format");
      this.alpha = true;
    } else if(bufferType == BufferTypes.RGB_3Byte) {
      bytes = new byte[width*height*3];
      Arrays.fill(bytes, (byte)0);
      byteBuffer = ByteBuffer.wrap(bytes);
     
      textureData = new TextureData(GLProfile.get(GLProfile.GL2), GL.GL_RGB, width, height, 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, false, false, true, byteBuffer, null);
      textureData.setRowLength(width);
      if(textureData.getPixelFormat() != GL.GL_RGB) throw new RuntimeException("Unexpected pixel format");
      this.alpha = false;
    } else {
      throw new UnsupportedOperationException("Unsupported buffer type");
View Full Code Here

    return textureData;
  }
  protected TextureData createTextureData() throws IOException {
    if(isBuffered()) throw new RuntimeException("TextureData must only be created when not buffered");
    if(textureData != null) {
      TextureData temp = textureData;
      this.textureData = null;
      return temp;
    } else {
      if(url != null) {
        TextureData data;
        try {
          if(forceAlpha) {
            TextureData tempData = TextureIO.newTextureData(GLProfile.get(GLProfile.GL2), url, GL.GL_RGBA, GL.GL_RGBA, false, null);
            if(tempData.getPixelFormat() != GL.GL_RGBA) {
              data = convertToRGBA(tempData);
              tempData.flush();
            } else {
              data = tempData;
            }
          } else {
            data = TextureIO.newTextureData(GLProfile.get(GLProfile.GL2), url, false, null);
          }
        } catch (Throwable t) {
          throw new RuntimeException("Error loading image: " + url, t);
        }
        return data;
      } else {
        int numBytes;
        int pixelFormat;
        if(alpha) {
          numBytes = 4;
          pixelFormat = GL.GL_RGBA;
        } else {
          numBytes = 3;
          pixelFormat = GL.GL_RGB;
        }

        byte[] tempBytes = new byte[width*height*numBytes];
        Arrays.fill(tempBytes, (byte)0);
        ByteBuffer tempByteBuffer = ByteBuffer.wrap(tempBytes);
       
        TextureData data = new TextureData(GLProfile.get(GLProfile.GL2), pixelFormat, width, height, 0, pixelFormat, GL.GL_UNSIGNED_BYTE, false, false, false, tempByteBuffer, null);
        data.setRowLength(width);
        if(data.getPixelFormat() != pixelFormat) throw new RuntimeException("Unexpected pixel format");
        return data;
      }
    }
  }
View Full Code Here

      tempbytes[destoffset++] = source[sourceoffset++]; // Green
      tempbytes[destoffset++] = source[sourceoffset++]; // Blue
      sourceoffset++; // ignore Alpha
    }

    return new TextureData(GLProfile.get(GLProfile.GL2), GL.GL_RGB, data.getWidth(), data.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, false, false, data.getMustFlipVertically(), ByteBuffer.wrap(tempbytes), null);
  }
View Full Code Here

      tempbytes[destoffset++] = source[sourceoffset++]; // Green
      tempbytes[destoffset++] = source[sourceoffset++]; // Blue
      tempbytes[destoffset++] = (byte)255; // Alpha
    }

    return new TextureData(GLProfile.get(GLProfile.GL2), GL.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, false, false, data.getMustFlipVertically(), ByteBuffer.wrap(tempbytes), null);
  }
View Full Code Here

        image.texture.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
        cachedImages.add(image);
  }
  private void cacheUnbuffered(GL2 gl, ch.blackspirit.graphics.jogl2.Image image) throws IOException {
    if(LOGGER.isLoggable(Level.FINER)) LOGGER.finer("Caching unbuffered image: " + image.toString());
    TextureData textureData = image.createTextureData();
    image.texture = TextureIO.newTexture(textureData);
    textureData.flush();
    // Default?
    image.texture.setTexParameteri(gl, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
    image.texture.setTexParameteri(gl, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
       
    image.texture.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
View Full Code Here

TOP

Related Classes of com.jogamp.opengl.util.texture.TextureData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.