Package com.sun.opengl.util.texture

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


        }

        if (isLoaded(tex))
            return tex;
        try {
            TextureData texData = _texProc.getTextureData(gpath);
            if (texData != null) {
                tex = TextureIO.newTexture(texData);
                lay.put(gpath, tex);
                return tex;
            } else {
View Full Code Here


 
  public TextureData getTextureData(String gpath) throws TextureNotAvailableException {
    //if(_canDownload)
    if(_texsNA.get(gpath)!=null) throw new TextureNotAvailableException();
   
    TextureData texData = _texsActive.get(gpath);
    if(texData==null) {
      if(_texsCache.get(gpath)!=null) {
        if(!_loadFromCache.contains(gpath)) {
          _loadFromCache.addLast(gpath);
          synchronized(this) { notifyAll(); }
View Full Code Here

      // load new textures
      if(!_loadFromCache.isEmpty()) {
        String gpath = _loadFromCache.pollFirst();
        try {
          // System.out.println(makeFileNameFromVEPath(gpath));
          TextureData td = TextureIO.newTextureData(new File(makeFileNameFromPath(gpath)), false,"");
          tex_count++;
          _texsActive.put(gpath, td);
          ltexs.push(gpath);
        } catch (IOException ioe) {
          if(_canDownload) {
            _dwCtrl.addPath(gpath);
          } else {
            _texsNA.put(gpath, "N/A");
          }
        } catch (OutOfMemoryError e) {
          // TODO: good memory free
          System.out.println("gc");
          freeAll();
          System.gc();
        }
      }
     
      // clean textures
      if(!_texsToFree.isEmpty()) {
        String gpath = _texsToFree.pop();
        TextureData td = _texsActive.get(gpath);
        if(td!=null) {
          _texsActive.remove(gpath);
          _texsCache.remove(gpath);
          _texsNA.remove(gpath);
          // System.out.println("free: "+gpath);
          tex_count--;
          td.flush();
          td=null;
        }
      }
      String res[] = new String[ltexs.size()];
      for(int i=0; i < res.length; i++) {
View Full Code Here

        image.texture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
        cachedImages.add(image);
  }
  private void cacheUnbuffered(ch.blackspirit.graphics.jogl.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_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
    image.texture.setTexParameteri(GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
       
    image.texture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
View Full Code Here

    this.buffered = true;
    this.forceAlpha = false;
   
    if(bufferType == BufferTypes.RGBA_4Byte) {
      try {
        TextureData tempData = TextureIO.newTextureData(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(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(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(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(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(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(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(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(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

      throws IOException {
    BufferedImage img = ImageIO.read(file);
    if (img == null) {
      return null;
    }
    return new TextureData(internalFormat, pixelFormat, mipmap, img);
  }
View Full Code Here

TOP

Related Classes of com.sun.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.