gt: 		ByteBuffer tmp = ByteBuffer.allocateDirect(4);
context: /*
   * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.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.
   */
  
  package org.mt4j.util.opengl;
  
  import java.nio.Buffer;
  import java.nio.ByteBuffer;
  import java.nio.ByteOrder;
  import java.nio.FloatBuffer;
  import java.nio.IntBuffer;
  
  import javax.media.opengl.GL;
  
  /*
   * This class combines OpenGL 20 functionality and old OpenGL 1.1 functionality for Jogl Desktop Usage!
   */
  
  /**
   * An implementation of the {@link GL20} and {@link GL11} interface based on Jogl. Note that Jogl shaders and OpenGL ES shaders will not be 100%
   * compatible. Some glGetXXX methods are not implemented.
   * 
   * @author mzechner
   * 
   */
  public final class JoglGL20Plus implements GL20, GL11, GL11Plus {
  	private final GL gl;
  
  	public JoglGL20Plus (GL gl) {
  		this.gl = gl;
  	}
  	
  
  	@Override
  	public void setSwapInterval(int interval) {
  		gl.setSwapInterval(interval);
  	}
  	
  	@Override
  	public boolean isExtensionAvailable(String name) {
  		return gl.isExtensionAvailable(name);
  	}
  	
  	//Added for backwards compatibility
  	@Override
  	public void glCallList(int id) {
  		gl.glCallList(id);
  	}
  
  	@Override
  	public void glCallLists(int arg0, int arg1, Buffer arg2) {
  		gl.glCallLists(arg0, arg1, arg2);
  	}
  
  	@Override
  	public int glGenLists(int id) {
  		return gl.glGenLists(id);
  	}
  	
  	@Override
  	public void glPushAttrib(int att){
  		gl.glPushAttrib(att);
  	}
  	
  	@Override
  	public void glPopAttrib(){
  		gl.glPopAttrib();
  	}
  	
  	@Override
  	public void glLineStipple(int t, short stipple){
  		gl.glLineStipple(t, stipple);
  	}
  
  	@Override
  	public void glTexImage1D(
  			int target, 
  			int level, 
  			int internalFormat, 
  			int width, 
  			int border, 
  			int format, 
  			int type, 
  			Buffer data)
  	{
  		gl.glTexImage1D(target, level, internalFormat, width, border, format, type, data);
  	}
  
  	@Override
  	public void glTexSubImage1D(
  			int target, 
  			int level, 
  			int xoffset,
  			int width, 
  			int format, 
  			int type, 
  			Buffer pixels)
  	{
  		gl.glTexSubImage1D(target,level,xoffset,width,format,type, pixels);
  	}
  	
  	@Override
  	public void glGetTexImage(
  			int  	target, 
  			int  	level, 
  			int  	format, 
  			int  	type, 
  			Buffer	img)
  	{
  		gl.glGetTexImage(target, level, format, type, img);
  	}
  	
  	@Override
  	public void glColorMaterial(int face, int mode){
  		gl.glColorMaterial(face, mode);
  	}
  	
  	
  	@Override
  	public void glNewList(int id, int mode) {
  		gl.glNewList(id, mode);
  	}
  	
  	@Override
  	public void glEndList(){
  		gl.glEndList();
  	}
  	
  	@Override
  	public void glDeleteLists(int list, int range){
  		gl.glDeleteLists(list, range);
  	}
  
  	//TODO dont check in drawMethods if glDrawBuffer supported
  	//-> just cast -> but check at setUseVBOs() and setUseDisplaylists() if correct gl version
  	
  
  	//FIXME GL20 stuff
  	@Override public void glActiveTexture (int texture) {
  		gl.glActiveTexture(texture);
  	}
  
  	@Override public void glAttachShader (int program, int shader) {
  		gl.glAttachShader(program, shader);
  	}
  
  	@Override public void glBindAttribLocation (int program, int index, String name) {
  		gl.glBindAttribLocation(program, index, name);
  	}
  
  	@Override public void glBindBuffer (int target, int buffer) {
  		gl.glBindBuffer(target, buffer);
  	}
  
  	@Override public void glBindFramebuffer (int target, int framebuffer) {
  		gl.glBindFramebufferEXT(target, framebuffer);
  	}
  
  	@Override public void glBindRenderbuffer (int target, int renderbuffer) {
  		gl.glBindRenderbufferEXT(target, renderbuffer);
  	}
  
  	@Override public void glBindTexture (int target, int texture) {
  		gl.glBindTexture(target, texture);
  	}
  
  	@Override public void glBlendColor (float red, float green, float blue, float alpha) {
  		gl.glBlendColor(red, green, blue, alpha);
  	}
  
  	@Override public void glBlendEquation (int mode) {
  		gl.glBlendEquation(mode);
  	}
  
  	@Override public void glBlendEquationSeparate (int modeRGB, int modeAlpha) {
  		gl.glBlendEquationSeparate(modeRGB, modeAlpha);
  	}
  
  	@Override public void glBlendFunc (int sfactor, int dfactor) {
  		gl.glBlendFunc(sfactor, dfactor);
  	}
  
  	@Override public void glBlendFuncSeparate (int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
  		gl.glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
  	}
  
  	@Override public void glBufferData (int target, int size, Buffer data, int usage) {
  		gl.glBufferData(target, size, data, usage);
  	}
  
  	@Override public void glBufferSubData (int target, int offset, int size, Buffer data) {
  		gl.glBufferSubData(target, offset, size, data);
  	}
  
  	@Override public int glCheckFramebufferStatus (int target) {
  		return gl.glCheckFramebufferStatusEXT(target);
  	}
  
  	@Override public void glClear (int mask) {
  		gl.glClear(mask);
  	}
  
  	@Override public void glClearColor (float red, float green, float blue, float alpha) {
  		gl.glClearColor(red, green, blue, alpha);
  	}
  
  	@Override public void glClearDepthf (float depth) {
  		gl.glClearDepth(depth);
  	}
  
  	@Override public void glClearStencil (int s) {
  		gl.glClearStencil(s);
  	}
  
  	@Override public void glColorMask (boolean red, boolean green, boolean blue, boolean alpha) {
  		gl.glColorMask(red, green, blue, alpha);
  	}
  
  	@Override public void glCompileShader (int shader) {
  		gl.glCompileShader(shader);
  	}
  
  	@Override public void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height, int border,
  		int imageSize, Buffer data) {
  		gl.glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
  	}
  
  	@Override public void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height,
  		int format, int imageSize, Buffer data) {
  		gl.glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
  	}
  
  	@Override public void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height,
  		int border) {
  		gl.glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
  	}
  
  	@Override public void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width, int height) {
  		gl.glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
  	}
  
  	@Override public int glCreateProgram () {
  		return gl.glCreateProgram();
  	}
  
  	@Override public int glCreateShader (int type) {
  		return gl.glCreateShader(type);
  	}
  
  	@Override public void glCullFace (int mode) {
  		gl.glCullFace(mode);
  	}
  
  	@Override public void glDeleteBuffers (int n, IntBuffer buffers) {
  		gl.glDeleteBuffers(n, buffers);
  	}
  
  	@Override public void glDeleteFramebuffers (int n, IntBuffer framebuffers) {
  		gl.glDeleteFramebuffersEXT(n, framebuffers);
  	}
  
  	@Override public void glDeleteProgram (int program) {
  		gl.glDeleteProgram(program);
  	}
  
  	@Override public void glDeleteRenderbuffers (int n, IntBuffer renderbuffers) {
  		gl.glDeleteRenderbuffersEXT(n, renderbuffers);
  	}
  
  	@Override public void glDeleteShader (int shader) {
  		gl.glDeleteShader(shader);
  	}
  
  	@Override public void glDeleteTextures (int n, IntBuffer textures) {
  		gl.glDeleteTextures(n, textures);
  	}
  
  	@Override public void glDepthFunc (int func) {
  		gl.glDepthFunc(func);
  	}
  
  	@Override public void glDepthMask (boolean flag) {
  		gl.glDepthMask(flag);
  	}
  
  	@Override public void glDepthRangef (float zNear, float zFar) {
  		gl.glDepthRange(zNear, zFar);
  	}
  
  	@Override public void glDetachShader (int program, int shader) {
  		gl.glDetachShader(program, shader);
  	}
  
  	@Override public void glDisable (int cap) {
  		gl.glDisable(cap);
  	}
  
  	@Override public void glDisableVertexAttribArray (int index) {
  		gl.glDisableVertexAttribArray(index);
  	}
  
  	@Override public void glDrawArrays (int mode, int first, int count) {
  		gl.glDrawArrays(mode, first, count);
  	}
  
  	@Override public void glDrawElements (int mode, int count, int type, Buffer indices) {
  		gl.glDrawElements(mode, count, type, indices);
  	}
  
  	@Override public void glEnable (int cap) {
  		gl.glEnable(cap);
  	}
  
  	@Override public void glEnableVertexAttribArray (int index) {
  		gl.glEnableVertexAttribArray(index);
  	}
  
  	@Override public void glFinish () {
  		gl.glFinish();
  	}
  
  	@Override public void glFlush () {
  		gl.glFlush();
  	}
  
  	@Override public void glFramebufferRenderbuffer (int target, int attachment, int renderbuffertarget, int renderbuffer) {
  		gl.glFramebufferRenderbufferEXT(target, attachment, renderbuffertarget, renderbuffer);
  	}
  
  	@Override public void glFramebufferTexture2D (int target, int attachment, int textarget, int texture, int level) {
  		gl.glFramebufferTexture2DEXT(target, attachment, textarget, texture, level);
  	}
  
  	@Override public void glFrontFace (int mode) {
  		gl.glFrontFace(mode);
  	}
  
  	@Override public void glGenBuffers (int n, IntBuffer buffers) {
  		gl.glGenBuffers(n, buffers);
  	}
  
  	@Override public void glGenFramebuffers (int n, IntBuffer framebuffers) {
  		gl.glGenFramebuffersEXT(n, framebuffers);
  	}
  
  	@Override public void glGenRenderbuffers (int n, IntBuffer renderbuffers) {
  		gl.glGenRenderbuffersEXT(n, renderbuffers);
  	}
  
  	@Override public void glGenTextures (int n, IntBuffer textures) {
  		gl.glGenTextures(n, textures);
  	}
  
  	@Override public void glGenerateMipmap (int target) {
  		gl.glGenerateMipmapEXT(target);
  	}
  
  	@Override public String glGetActiveAttrib (int program, int index, IntBuffer size, Buffer type) {
  		throw new UnsupportedOperationException("not implemented"); // FIXME
  	}
  
  	@Override public String glGetActiveUniform (int program, int index, IntBuffer size, Buffer type) {
  		throw new UnsupportedOperationException("not implemented"); // FIXME
  	}
  
  	@Override public void glGetAttachedShaders (int program, int maxcount, Buffer count, IntBuffer shaders) {
  		gl.glGetAttachedShaders(program, maxcount, (IntBuffer)count, shaders);
  	}
  
  	@Override public int glGetAttribLocation (int program, String name) {
  		return gl.glGetAttribLocation(program, name);
  	}
  
  	@Override public void glGetBooleanv (int pname, Buffer params) {
  		throw new UnsupportedOperationException("not implemented"); // FIXME
  	}
  
  	@Override public void glGetBufferParameteriv (int target, int pname, IntBuffer params) {
  		gl.glGetBufferParameteriv(target, pname, params);
  	}
  
  	@Override public int glGetError () {
  		return gl.glGetError();
  	}
  
  	@Override public void glGetFloatv (int pname, FloatBuffer params) {
  		gl.glGetFloatv(pname, params);
  	}
  
  	@Override public void glGetFramebufferAttachmentParameteriv (int target, int attachment, int pname, IntBuffer params) {
  		gl.glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params);
  	}
  
  	@Override public void glGetIntegerv (int pname, IntBuffer params) {
  		gl.glGetIntegerv(pname, params);
  	}
  
  	@Override 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();
  
  		gl.glGetProgramInfoLog(program, 1024 * 10, intBuffer, buffer);
  		int numBytes = intBuffer.get(0);
  		byte[] bytes = new byte[numBytes];
  		buffer.get(bytes);
  		return new String(bytes);
  	}
  
  	@Override public void glGetProgramiv (int program, int pname, IntBuffer params) {
  		gl.glGetProgramiv(program, pname, params);
  	}
  
  	@Override public void glGetRenderbufferParameteriv (int target, int pname, IntBuffer params) {
  		gl.glGetRenderbufferParameterivEXT(target, pname, params);
  	}
  
  	@Override public String glGetShaderInfoLog (int shader) {
  		ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 10);
  		buffer.order(ByteOrder.nativeOrder());
  