gt: 		IntBuffer intBuffer = tmp.asIntBuffer();
context: package org.oscim.gdx;
  
  /*******************************************************************************
   * Copyright 2011 Mario Zechner <badlogicgames@gmail.com>
   * Copyright 2011 Nathan Sweet <nathan.sweet@gmail.com>
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   ******************************************************************************/
  
  import java.nio.Buffer;
  import java.nio.ByteBuffer;
  import java.nio.ByteOrder;
  import java.nio.DoubleBuffer;
  import java.nio.FloatBuffer;
  import java.nio.IntBuffer;
  import java.nio.ShortBuffer;
  
  import org.lwjgl.BufferUtils;
  import org.lwjgl.opengl.EXTFramebufferObject;
  import org.lwjgl.opengl.GL11;
  import org.lwjgl.opengl.GL13;
  import org.lwjgl.opengl.GL14;
  import org.lwjgl.opengl.GL15;
  import org.lwjgl.opengl.GL20;
  
  import com.badlogic.gdx.utils.GdxRuntimeException;
  
  /**
   * An implementation of the {@link GL20} interface based on LWJGL. Note that
   * LWJGL shaders and OpenGL ES shaders will not be 100%
   * compatible. Some glGetXXX methods are not implemented.
   * 
   * @author mzechner
   */
  final class GdxGL20 implements org.oscim.backend.GL20 {
  	public void glActiveTexture(int texture) {
  		GL13.glActiveTexture(texture);
  	}
  
  	public void glAttachShader(int program, int shader) {
  		GL20.glAttachShader(program, shader);
  	}
  
  	public void glBindAttribLocation(int program, int index, String name) {
  		GL20.glBindAttribLocation(program, index, name);
  	}
  
  	public void glBindBuffer(int target, int buffer) {
  		GL15.glBindBuffer(target, buffer);
  	}
  
  	public void glBindFramebuffer(int target, int framebuffer) {
  		EXTFramebufferObject.glBindFramebufferEXT(target, framebuffer);
  	}
  
  	public void glBindRenderbuffer(int target, int renderbuffer) {
  		EXTFramebufferObject.glBindRenderbufferEXT(target, renderbuffer);
  	}
  
  	public void glBindTexture(int target, int texture) {
  		GL11.glBindTexture(target, texture);
  	}
  
  	public void glBlendColor(float red, float green, float blue, float alpha) {
  		GL14.glBlendColor(red, green, blue, alpha);
  	}
  
  	public void glBlendEquation(int mode) {
  		GL14.glBlendEquation(mode);
  	}
  
  	public void glBlendEquationSeparate(int modeRGB, int modeAlpha) {
  		GL20.glBlendEquationSeparate(modeRGB, modeAlpha);
  	}
  
  	public void glBlendFunc(int sfactor, int dfactor) {
  		GL11.glBlendFunc(sfactor, dfactor);
  	}
  
  	public void glBlendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
  		GL14.glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
  	}
  
  	public void glBufferData(int target, int size, Buffer data, int usage) {
  		if (data == null)
  			throw new GdxRuntimeException("Using null for the data not possible, blame LWJGL");
  		else if (data instanceof ByteBuffer)
  			GL15.glBufferData(target, (ByteBuffer) data, usage);
  		else if (data instanceof IntBuffer)
  			GL15.glBufferData(target, (IntBuffer) data, usage);
  		else if (data instanceof FloatBuffer)
  			GL15.glBufferData(target, (FloatBuffer) data, usage);
  		else if (data instanceof DoubleBuffer)
  			GL15.glBufferData(target, (DoubleBuffer) data, usage);
  		else if (data instanceof ShortBuffer) //
  			GL15.glBufferData(target, (ShortBuffer) data, usage);
  	}
  
  	public void glBufferSubData(int target, int offset, int size, Buffer data) {
  		if (data == null)
  			throw new GdxRuntimeException("Using null for the data not possible, blame LWJGL");
  		else if (data instanceof ByteBuffer)
  			GL15.glBufferSubData(target, offset, (ByteBuffer) data);
  		else if (data instanceof IntBuffer)
  			GL15.glBufferSubData(target, offset, (IntBuffer) data);
  		else if (data instanceof FloatBuffer)
  			GL15.glBufferSubData(target, offset, (FloatBuffer) data);
  		else if (data instanceof DoubleBuffer)
  			GL15.glBufferSubData(target, offset, (DoubleBuffer) data);
  		else if (data instanceof ShortBuffer) //
  			GL15.glBufferSubData(target, offset, (ShortBuffer) data);
  	}
  
  	public int glCheckFramebufferStatus(int target) {
  		return EXTFramebufferObject.glCheckFramebufferStatusEXT(target);
  	}
  
  	public void glClear(int mask) {
  		GL11.glClear(mask);
  	}
  
  	public void glClearColor(float red, float green, float blue, float alpha) {
  		GL11.glClearColor(red, green, blue, alpha);
  	}
  
  	public void glClearDepthf(float depth) {
  		GL11.glClearDepth(depth);
  	}
  
  	public void glClearStencil(int s) {
  		GL11.glClearStencil(s);
  	}
  
  	public void glColorMask(boolean red, boolean green, boolean blue, boolean alpha) {
  		GL11.glColorMask(red, green, blue, alpha);
  	}
  
  	public void glCompileShader(int shader) {
  		GL20.glCompileShader(shader);
  	}
  
  	public void glCompressedTexImage2D(int target, int level, int internalformat, int width,
  	        int height, int border,
  	        int imageSize, Buffer data) {
  		if (data instanceof ByteBuffer) {
  			GL13.glCompressedTexImage2D(target,
  			                            level,
  			                            internalformat,
  			                            width,
  			                            height,
  			                            border,
  			                            (ByteBuffer) data);
  		} else {
  			throw new GdxRuntimeException("Can't use " + data.getClass().getName()
  			        + " with this method. Use ByteBuffer instead.");
  		}
  	}
  
  	public void glCompressedTexSubImage2D(int target, int level, int xoffset, int yoffset,
  	        int width, int height, int format,
  	        int imageSize, Buffer data) {
  		throw new GdxRuntimeException("not implemented");
  	}
  
  	public void glCopyTexImage2D(int target, int level, int internalformat, int x, int y,
  	        int width, int height, int border) {
  		GL11.glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
  	}
  
  	public void glCopyTexSubImage2D(int target, int level, int xoffset, int yoffset, int x, int y,
  	        int width, int height) {
  		GL11.glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
  	}
  
  	public int glCreateProgram() {
  		return GL20.glCreateProgram();
  	}
  
  	public int glCreateShader(int type) {
  		return GL20.glCreateShader(type);
  	}
  
  	public void glCullFace(int mode) {
  		GL11.glCullFace(mode);
  	}
  
  	public void glDeleteBuffers(int n, IntBuffer buffers) {
  		GL15.glDeleteBuffers(buffers);
  	}
  
  	public void glDeleteFramebuffers(int n, IntBuffer framebuffers) {
  		EXTFramebufferObject.glDeleteFramebuffersEXT(framebuffers);
  	}
  
  	public void glDeleteProgram(int program) {
  		GL20.glDeleteProgram(program);
  	}
  
  	public void glDeleteRenderbuffers(int n, IntBuffer renderbuffers) {
  		EXTFramebufferObject.glDeleteRenderbuffersEXT(renderbuffers);
  	}
  
  	public void glDeleteShader(int shader) {
  		GL20.glDeleteShader(shader);
  	}
  
  	public void glDeleteTextures(int n, IntBuffer textures) {
  		GL11.glDeleteTextures(textures);
  	}
  
  	public void glDepthFunc(int func) {
  		GL11.glDepthFunc(func);
  	}
  
  	public void glDepthMask(boolean flag) {
  		GL11.glDepthMask(flag);
  	}
  
  	public void glDepthRangef(float zNear, float zFar) {
  		GL11.glDepthRange(zNear, zFar);
  	}
  
  	public void glDetachShader(int program, int shader) {
  		GL20.glDetachShader(program, shader);
  	}
  
  	public void glDisable(int cap) {
  		GL11.glDisable(cap);
  	}
  
  	public void glDisableVertexAttribArray(int index) {
  		GL20.glDisableVertexAttribArray(index);
  	}
  
  	public void glDrawArrays(int mode, int first, int count) {
  		GL11.glDrawArrays(mode, first, count);
  	}
  
  	public void glDrawElements(int mode, int count, int type, Buffer indices) {
  		if (indices instanceof ShortBuffer && type == GL_UNSIGNED_SHORT)
  			GL11.glDrawElements(mode, (ShortBuffer) indices);
  		else if (indices instanceof ByteBuffer && type == GL_UNSIGNED_SHORT)
  			GL11.glDrawElements(mode, ((ByteBuffer) indices).asShortBuffer()); // FIXME yay...
  		else if (indices instanceof ByteBuffer && type == GL_UNSIGNED_BYTE)
  			GL11.glDrawElements(mode, (ByteBuffer) indices);
  		else
  			throw new GdxRuntimeException("Can't use " + indices.getClass().getName()
  			        + " with this method. Use ShortBuffer or ByteBuffer instead. Blame LWJGL");
  	}
  
  	public void glEnable(int cap) {
  		GL11.glEnable(cap);
  	}
  
  	public void glEnableVertexAttribArray(int index) {
  		GL20.glEnableVertexAttribArray(index);
  	}
  
  	public void glFinish() {
  		GL11.glFinish();
  	}
  
  	public void glFlush() {
  		GL11.glFlush();
  	}
  
  	public void glFramebufferRenderbuffer(int target, int attachment, int renderbuffertarget,
  	        int renderbuffer) {
  		EXTFramebufferObject.glFramebufferRenderbufferEXT(target,
  		                                                  attachment,
  		                                                  renderbuffertarget,
  		                                                  renderbuffer);
  	}
  
  	public void glFramebufferTexture2D(int target, int attachment, int textarget, int texture,
  	        int level) {
  		EXTFramebufferObject.glFramebufferTexture2DEXT(target,
  		                                               attachment,
  		                                               textarget,
  		                                               texture,
  		                                               level);
  	}
  
  	public void glFrontFace(int mode) {
  		GL11.glFrontFace(mode);
  	}
  
  	public void glGenBuffers(int n, IntBuffer buffers) {
  		GL15.glGenBuffers(buffers);
  	}
  
  	public void glGenFramebuffers(int n, IntBuffer framebuffers) {
  		EXTFramebufferObject.glGenFramebuffersEXT(framebuffers);
  	}
  
  	public void glGenRenderbuffers(int n, IntBuffer renderbuffers) {
  		EXTFramebufferObject.glGenRenderbuffersEXT(renderbuffers);
  	}
  
  	public void glGenTextures(int n, IntBuffer textures) {
  		GL11.glGenTextures(textures);
  	}
  
  	public void glGenerateMipmap(int target) {
  		EXTFramebufferObject.glGenerateMipmapEXT(target);
  	}
  
  	public String glGetActiveAttrib(int program, int index, IntBuffer size, Buffer type) {
  		// FIXME this is less than ideal of course...
  		IntBuffer typeTmp = BufferUtils.createIntBuffer(2);
  		String name = GL20.glGetActiveAttrib(program, index, 256, typeTmp);
  		size.put(typeTmp.get(0));
  		if (type instanceof IntBuffer)
  			((IntBuffer) type).put(typeTmp.get(1));
  		return name;
  	}
  
  	public String glGetActiveUniform(int program, int index, IntBuffer size, Buffer type) {
  		// FIXME this is less than ideal of course...
  		IntBuffer typeTmp = BufferUtils.createIntBuffer(2);
  		String name = GL20.glGetActiveUniform(program, index, 256, typeTmp);
  		size.put(typeTmp.get(0));
  		if (type instanceof IntBuffer)
  			((IntBuffer) type).put(typeTmp.get(1));
  		return name;
  	}
  
  	public void glGetAttachedShaders(int program, int maxcount, Buffer count, IntBuffer shaders) {
  		GL20.glGetAttachedShaders(program, (IntBuffer) count, shaders);
  	}
  
  	public int glGetAttribLocation(int program, String name) {
  		return GL20.glGetAttribLocation(program, name);
  	}
  
  	public void glGetBooleanv(int pname, Buffer params) {
  		GL11.glGetBoolean(pname, (ByteBuffer) params);
  	}
  
  	public void glGetBufferParameteriv(int target, int pname, IntBuffer params) {
  		GL15.glGetBufferParameter(target, pname, params);
  	}
  
  	public int glGetError() {
  		return GL11.glGetError();
  	}
  
  	public void glGetFloatv(int pname, FloatBuffer params) {
  		GL11.glGetFloat(pname, params);
  	}
  
  	public void glGetFramebufferAttachmentParameteriv(int target, int attachment, int pname,
  	        IntBuffer params) {
  		EXTFramebufferObject.glGetFramebufferAttachmentParameterEXT(target,
  		                                                            attachment,
  		                                                            pname,
  		                                                            params);
  	}
  
  	public void glGetIntegerv(int pname, IntBuffer params) {
  		GL11.glGetInteger(pname, params);
  	}
  
  	public String glGetProgramInfoLog(int program) {
  		ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 10);
  		buffer.order(ByteOrder.nativeOrder());
  		ByteBuffer tmp = ByteBuffer.allocateDirect(4);
  		tmp.order(ByteOrder.nativeOrder());
  		IntBuffer intBuffer = tmp.asIntBuffer();
  
  		GL20.glGetProgramInfoLog(program, intBuffer, buffer);
  		int numBytes = intBuffer.get(0);
  		byte[] bytes = new byte[numBytes];
  		buffer.get(bytes);
  		return new String(bytes);
  	}
  
  	public void glGetProgramiv(int program, int pname, IntBuffer params) {
  		GL20.glGetProgram(program, pname, params);
  	}
  
  	public void glGetRenderbufferParameteriv(int target, int pname, IntBuffer params) {
  		EXTFramebufferObject.glGetRenderbufferParameterEXT(target, pname, params);
  	}
  
  	public String glGetShaderInfoLog(int shader) {
  		ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 10);
  		buffer.order(ByteOrder.nativeOrder());
  		ByteBuffer tmp = ByteBuffer.allocateDirect(4);
  		tmp.order(ByteOrder.nativeOrder());
  