private static TextureHandle getTexture(GLDrawContext context) { if (texture == null || !texture.isValid()) { long startTime = System.currentTimeMillis(); short[] data; synchronized (preloadMutex) { if (preloadedTexture != null) { data = preloadedTexture; // free the array preloadedTexture = null; } else { data = getTexture(); } } ByteBuffer buffer = ByteBuffer.allocateDirect(data.length * 2).order(ByteOrder.nativeOrder()); buffer.asShortBuffer().put(data); texture = context.generateTexture(TEXTURE_SIZE, TEXTURE_SIZE, buffer.asShortBuffer(), "background"); System.out.println("Background texture generated in " + (System.currentTimeMillis() - startTime) + "ms"); } return texture; }
private void loadTexture(GLDrawContext gl) { try { final DataInputStream in = new DataInputStream(new BufferedInputStream(file)); int i = in.available() / 2; final int height = nextLowerPOT(Math.sqrt(i)); final int width = nextLowerPOT(i / height); // TODO: Use better buffering. final ShortBuffer data = ByteBuffer.allocateDirect(width * height * 2).order(ByteOrder.nativeOrder()).asShortBuffer(); while (data.hasRemaining()) { data.put(in.readShort()); } data.rewind(); textureIndex = gl.generateTexture(width, height, data, name); } catch (final IOException e) { e.printStackTrace(); textureIndex = null; } }
private synchronized void loadTexture(GLDrawContext gl) throws IOException { if (buffers == null) { allocateBuffers(); FileInputStream in = new FileInputStream(cacheFile); try { byte[] line = new byte[this.width * 2]; while (in.available() > 0) { if (in.read(line) <= 0) { throw new IOException(); } byteBuffer.put(line); } byteBuffer.rewind(); } finally { in.close(); } } buffers.rewind(); texture = gl.generateTexture(width, height, buffers, name); System.out.println("opengl Texture: " + texture + ", thread: " + Thread.currentThread().toString()); if (texture != null) { textureValid = true; } buffers = null; byteBuffer = null; }
protected void checkHandles(GLDrawContext gl) throws IllegalBufferException { if (texture == null || !texture.isValid()) { texture = gl.generateTexture(twidth, theight, tdata, name); } if(geometryIndex == null || SharedGeometry.isInvalid(gl, geometryIndex)) { geometryIndex = SharedGeometry.addGeometry(gl, getGeometry()); } }
texture = context.generateTexture(width, height, data, "minimap"); updatedLines.clear(); imageIsValid = true;