/** * Generates the gl texture handle used for drawing this texture. * * @param gl * The gl context. * @return The texture handle. */ public TextureHandle getTextureIndex(GLDrawContext gl) { if (textureIndex == null || !textureIndex.isValid()) { loadTexture(gl); } return textureIndex; }
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; }
/** * Gets the texture handle. * * @param gl * The gl context to use when creating the texutre. * @return A valid texture handle. */ public TextureHandle getTexture(GLDrawContext gl) { if (!textureValid || !texture.isValid()) { if (texture != null) { gl.deleteTexture(texture); } try { loadTexture(gl); } catch (IOException e) { e.printStackTrace(); } } return texture; }
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()); } }
@Override protected void checkHandles(GLDrawContext gl) throws IllegalBufferException { if ((texture == null || !texture.isValid())) { gl2 = gl instanceof GL2DrawContext && (this.torso != null || this.shadow != null); if(gl2) generateUData(); } super.checkHandles(gl); if(!gl2) { if (torso != null && torso.getWidth() == getWidth() && torso.getHeight() == getHeight() && torso.getOffsetX() == getOffsetX() && torso.getOffsetY() == getOffsetY()) { torso.setGeometry(geometryIndex); } } }