1/*******************************************************************************
2 * Copyright 2011 See AUTHORS file.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *   http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 ******************************************************************************/
16
17package com.badlogic.gdx.backends.lwjgl;
18
19import java.nio.Buffer;
20import java.nio.ByteBuffer;
21import java.nio.ByteOrder;
22import java.nio.DoubleBuffer;
23import java.nio.FloatBuffer;
24import java.nio.IntBuffer;
25import java.nio.ShortBuffer;
26
27import org.lwjgl.BufferUtils;
28import org.lwjgl.opengl.EXTFramebufferObject;
29import org.lwjgl.opengl.GL11;
30import org.lwjgl.opengl.GL13;
31import org.lwjgl.opengl.GL14;
32import org.lwjgl.opengl.GL15;
33import org.lwjgl.opengl.GL20;
34
35import com.badlogic.gdx.utils.GdxRuntimeException;
36
37/** An implementation of the {@link GL20} interface based on LWJGL. Note that LWJGL shaders and OpenGL ES shaders will not be 100%
38 * compatible. Some glGetXXX methods are not implemented.
39 *
40 * @author mzechner */
41class LwjglGL20 implements com.badlogic.gdx.graphics.GL20 {
42	private ByteBuffer buffer = null;
43	private FloatBuffer floatBuffer = null;
44	private IntBuffer intBuffer = null;
45
46	private void ensureBufferCapacity (int numBytes) {
47		if (buffer == null || buffer.capacity() < numBytes) {
48			buffer = com.badlogic.gdx.utils.BufferUtils.newByteBuffer(numBytes);
49			floatBuffer = buffer.asFloatBuffer();
50			intBuffer = buffer.asIntBuffer();
51		}
52	}
53
54	private FloatBuffer toFloatBuffer (float v[], int offset, int count) {
55		ensureBufferCapacity(count << 2);
56		floatBuffer.clear();
57		com.badlogic.gdx.utils.BufferUtils.copy(v, floatBuffer, count, offset);
58		return floatBuffer;
59	}
60
61	private IntBuffer toIntBuffer (int v[], int offset, int count) {
62		ensureBufferCapacity(count << 2);
63		intBuffer.clear();
64		com.badlogic.gdx.utils.BufferUtils.copy(v, count, offset, intBuffer);
65		return intBuffer;
66	}
67
68	public void glActiveTexture (int texture) {
69		GL13.glActiveTexture(texture);
70	}
71
72	public void glAttachShader (int program, int shader) {
73		GL20.glAttachShader(program, shader);
74	}
75
76	public void glBindAttribLocation (int program, int index, String name) {
77		GL20.glBindAttribLocation(program, index, name);
78	}
79
80	public void glBindBuffer (int target, int buffer) {
81		GL15.glBindBuffer(target, buffer);
82	}
83
84	public void glBindFramebuffer (int target, int framebuffer) {
85		EXTFramebufferObject.glBindFramebufferEXT(target, framebuffer);
86	}
87
88	public void glBindRenderbuffer (int target, int renderbuffer) {
89		EXTFramebufferObject.glBindRenderbufferEXT(target, renderbuffer);
90	}
91
92	public void glBindTexture (int target, int texture) {
93		GL11.glBindTexture(target, texture);
94	}
95
96	public void glBlendColor (float red, float green, float blue, float alpha) {
97		GL14.glBlendColor(red, green, blue, alpha);
98	}
99
100	public void glBlendEquation (int mode) {
101		GL14.glBlendEquation(mode);
102	}
103
104	public void glBlendEquationSeparate (int modeRGB, int modeAlpha) {
105		GL20.glBlendEquationSeparate(modeRGB, modeAlpha);
106	}
107
108	public void glBlendFunc (int sfactor, int dfactor) {
109		GL11.glBlendFunc(sfactor, dfactor);
110	}
111
112	public void glBlendFuncSeparate (int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
113		GL14.glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
114	}
115
116	public void glBufferData (int target, int size, Buffer data, int usage) {
117		if (data == null)
118			GL15.glBufferData(target, size, usage);
119		else if (data instanceof ByteBuffer)
120			GL15.glBufferData(target, (ByteBuffer)data, usage);
121		else if (data instanceof IntBuffer)
122			GL15.glBufferData(target, (IntBuffer)data, usage);
123		else if (data instanceof FloatBuffer)
124			GL15.glBufferData(target, (FloatBuffer)data, usage);
125		else if (data instanceof DoubleBuffer)
126			GL15.glBufferData(target, (DoubleBuffer)data, usage);
127		else if (data instanceof ShortBuffer) //
128			GL15.glBufferData(target, (ShortBuffer)data, usage);
129	}
130
131	public void glBufferSubData (int target, int offset, int size, Buffer data) {
132		if (data == null)
133			throw new GdxRuntimeException("Using null for the data not possible, blame LWJGL");
134		else if (data instanceof ByteBuffer)
135			GL15.glBufferSubData(target, offset, (ByteBuffer)data);
136		else if (data instanceof IntBuffer)
137			GL15.glBufferSubData(target, offset, (IntBuffer)data);
138		else if (data instanceof FloatBuffer)
139			GL15.glBufferSubData(target, offset, (FloatBuffer)data);
140		else if (data instanceof DoubleBuffer)
141			GL15.glBufferSubData(target, offset, (DoubleBuffer)data);
142		else if (data instanceof ShortBuffer) //
143			GL15.glBufferSubData(target, offset, (ShortBuffer)data);
144	}
145
146	public int glCheckFramebufferStatus (int target) {
147		return EXTFramebufferObject.glCheckFramebufferStatusEXT(target);
148	}
149
150	public void glClear (int mask) {
151		GL11.glClear(mask);
152	}
153
154	public void glClearColor (float red, float green, float blue, float alpha) {
155		GL11.glClearColor(red, green, blue, alpha);
156	}
157
158	public void glClearDepthf (float depth) {
159		GL11.glClearDepth(depth);
160	}
161
162	public void glClearStencil (int s) {
163		GL11.glClearStencil(s);
164	}
165
166	public void glColorMask (boolean red, boolean green, boolean blue, boolean alpha) {
167		GL11.glColorMask(red, green, blue, alpha);
168	}
169
170	public void glCompileShader (int shader) {
171		GL20.glCompileShader(shader);
172	}
173
174	public void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height, int border,
175		int imageSize, Buffer data) {
176		if (data instanceof ByteBuffer) {
177			GL13.glCompressedTexImage2D(target, level, internalformat, width, height, border, (ByteBuffer)data);
178		} else {
179			throw new GdxRuntimeException("Can't use " + data.getClass().getName() + " with this method. Use ByteBuffer instead.");
180		}
181	}
182
183	public void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format,
184		int imageSize, Buffer data) {
185		throw new GdxRuntimeException("not implemented");
186	}
187
188	public void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) {
189		GL11.glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
190	}
191
192	public void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width, int height) {
193		GL11.glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
194	}
195
196	public int glCreateProgram () {
197		return GL20.glCreateProgram();
198	}
199
200	public int glCreateShader (int type) {
201		return GL20.glCreateShader(type);
202	}
203
204	public void glCullFace (int mode) {
205		GL11.glCullFace(mode);
206	}
207
208	public void glDeleteBuffers (int n, IntBuffer buffers) {
209		GL15.glDeleteBuffers(buffers);
210	}
211
212	@Override
213	public void glDeleteBuffer (int buffer) {
214		GL15.glDeleteBuffers(buffer);
215	}
216
217	public void glDeleteFramebuffers (int n, IntBuffer framebuffers) {
218		EXTFramebufferObject.glDeleteFramebuffersEXT(framebuffers);
219	}
220
221	@Override
222	public void glDeleteFramebuffer (int framebuffer) {
223		EXTFramebufferObject.glDeleteFramebuffersEXT(framebuffer);
224	}
225
226	public void glDeleteProgram (int program) {
227		GL20.glDeleteProgram(program);
228	}
229
230	public void glDeleteRenderbuffers (int n, IntBuffer renderbuffers) {
231		EXTFramebufferObject.glDeleteRenderbuffersEXT(renderbuffers);
232	}
233
234	public void glDeleteRenderbuffer (int renderbuffer) {
235		EXTFramebufferObject.glDeleteRenderbuffersEXT(renderbuffer);
236	}
237
238	public void glDeleteShader (int shader) {
239		GL20.glDeleteShader(shader);
240	}
241
242	public void glDeleteTextures (int n, IntBuffer textures) {
243		GL11.glDeleteTextures(textures);
244	}
245
246	@Override
247	public void glDeleteTexture (int texture) {
248		GL11.glDeleteTextures(texture);
249	}
250
251	public void glDepthFunc (int func) {
252		GL11.glDepthFunc(func);
253	}
254
255	public void glDepthMask (boolean flag) {
256		GL11.glDepthMask(flag);
257	}
258
259	public void glDepthRangef (float zNear, float zFar) {
260		GL11.glDepthRange(zNear, zFar);
261	}
262
263	public void glDetachShader (int program, int shader) {
264		GL20.glDetachShader(program, shader);
265	}
266
267	public void glDisable (int cap) {
268		GL11.glDisable(cap);
269	}
270
271	public void glDisableVertexAttribArray (int index) {
272		GL20.glDisableVertexAttribArray(index);
273	}
274
275	public void glDrawArrays (int mode, int first, int count) {
276		GL11.glDrawArrays(mode, first, count);
277	}
278
279	public void glDrawElements (int mode, int count, int type, Buffer indices) {
280		if (indices instanceof ShortBuffer && type == com.badlogic.gdx.graphics.GL20.GL_UNSIGNED_SHORT)
281			GL11.glDrawElements(mode, (ShortBuffer)indices);
282		else if (indices instanceof ByteBuffer && type == com.badlogic.gdx.graphics.GL20.GL_UNSIGNED_SHORT)
283			GL11.glDrawElements(mode, ((ByteBuffer)indices).asShortBuffer()); // FIXME yay...
284		else if (indices instanceof ByteBuffer && type == com.badlogic.gdx.graphics.GL20.GL_UNSIGNED_BYTE)
285			GL11.glDrawElements(mode, (ByteBuffer)indices);
286		else
287			throw new GdxRuntimeException("Can't use " + indices.getClass().getName()
288				+ " with this method. Use ShortBuffer or ByteBuffer instead. Blame LWJGL");
289	}
290
291	public void glEnable (int cap) {
292		GL11.glEnable(cap);
293	}
294
295	public void glEnableVertexAttribArray (int index) {
296		GL20.glEnableVertexAttribArray(index);
297	}
298
299	public void glFinish () {
300		GL11.glFinish();
301	}
302
303	public void glFlush () {
304		GL11.glFlush();
305	}
306
307	public void glFramebufferRenderbuffer (int target, int attachment, int renderbuffertarget, int renderbuffer) {
308		EXTFramebufferObject.glFramebufferRenderbufferEXT(target, attachment, renderbuffertarget, renderbuffer);
309	}
310
311	public void glFramebufferTexture2D (int target, int attachment, int textarget, int texture, int level) {
312		EXTFramebufferObject.glFramebufferTexture2DEXT(target, attachment, textarget, texture, level);
313	}
314
315	public void glFrontFace (int mode) {
316		GL11.glFrontFace(mode);
317	}
318
319	public void glGenBuffers (int n, IntBuffer buffers) {
320		GL15.glGenBuffers(buffers);
321	}
322
323	public int glGenBuffer () {
324		return GL15.glGenBuffers();
325	}
326
327	public void glGenFramebuffers (int n, IntBuffer framebuffers) {
328		EXTFramebufferObject.glGenFramebuffersEXT(framebuffers);
329	}
330
331	public int glGenFramebuffer () {
332		return EXTFramebufferObject.glGenFramebuffersEXT();
333	}
334
335	public void glGenRenderbuffers (int n, IntBuffer renderbuffers) {
336		EXTFramebufferObject.glGenRenderbuffersEXT(renderbuffers);
337	}
338
339	public int glGenRenderbuffer () {
340		return EXTFramebufferObject.glGenRenderbuffersEXT();
341	}
342
343	public void glGenTextures (int n, IntBuffer textures) {
344		GL11.glGenTextures(textures);
345	}
346
347	public int glGenTexture () {
348		return GL11.glGenTextures();
349	}
350
351	public void glGenerateMipmap (int target) {
352		EXTFramebufferObject.glGenerateMipmapEXT(target);
353	}
354
355	public String glGetActiveAttrib (int program, int index, IntBuffer size, Buffer type) {
356		// FIXME this is less than ideal of course...
357		IntBuffer typeTmp = BufferUtils.createIntBuffer(2);
358		String name = GL20.glGetActiveAttrib(program, index, 256, typeTmp);
359		size.put(typeTmp.get(0));
360		if (type instanceof IntBuffer) ((IntBuffer)type).put(typeTmp.get(1));
361		return name;
362	}
363
364	public String glGetActiveUniform (int program, int index, IntBuffer size, Buffer type) {
365		// FIXME this is less than ideal of course...
366		IntBuffer typeTmp = BufferUtils.createIntBuffer(2);
367		String name = GL20.glGetActiveUniform(program, index, 256, typeTmp);
368		size.put(typeTmp.get(0));
369		if (type instanceof IntBuffer) ((IntBuffer)type).put(typeTmp.get(1));
370		return name;
371	}
372
373	public void glGetAttachedShaders (int program, int maxcount, Buffer count, IntBuffer shaders) {
374		GL20.glGetAttachedShaders(program, (IntBuffer)count, shaders);
375	}
376
377	public int glGetAttribLocation (int program, String name) {
378		return GL20.glGetAttribLocation(program, name);
379	}
380
381	public void glGetBooleanv (int pname, Buffer params) {
382		GL11.glGetBoolean(pname, (ByteBuffer)params);
383	}
384
385	public void glGetBufferParameteriv (int target, int pname, IntBuffer params) {
386		GL15.glGetBufferParameter(target, pname, params);
387	}
388
389	public int glGetError () {
390		return GL11.glGetError();
391	}
392
393	public void glGetFloatv (int pname, FloatBuffer params) {
394		GL11.glGetFloat(pname, params);
395	}
396
397	public void glGetFramebufferAttachmentParameteriv (int target, int attachment, int pname, IntBuffer params) {
398		EXTFramebufferObject.glGetFramebufferAttachmentParameterEXT(target, attachment, pname, params);
399	}
400
401	public void glGetIntegerv (int pname, IntBuffer params) {
402		GL11.glGetInteger(pname, params);
403	}
404
405	public String glGetProgramInfoLog (int program) {
406		ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 10);
407		buffer.order(ByteOrder.nativeOrder());
408		ByteBuffer tmp = ByteBuffer.allocateDirect(4);
409		tmp.order(ByteOrder.nativeOrder());
410		IntBuffer intBuffer = tmp.asIntBuffer();
411
412		GL20.glGetProgramInfoLog(program, intBuffer, buffer);
413		int numBytes = intBuffer.get(0);
414		byte[] bytes = new byte[numBytes];
415		buffer.get(bytes);
416		return new String(bytes);
417	}
418
419	public void glGetProgramiv (int program, int pname, IntBuffer params) {
420		GL20.glGetProgram(program, pname, params);
421	}
422
423	public void glGetRenderbufferParameteriv (int target, int pname, IntBuffer params) {
424		EXTFramebufferObject.glGetRenderbufferParameterEXT(target, pname, params);
425	}
426
427	public String glGetShaderInfoLog (int shader) {
428		ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 10);
429		buffer.order(ByteOrder.nativeOrder());
430		ByteBuffer tmp = ByteBuffer.allocateDirect(4);
431		tmp.order(ByteOrder.nativeOrder());
432		IntBuffer intBuffer = tmp.asIntBuffer();
433
434		GL20.glGetShaderInfoLog(shader, intBuffer, buffer);
435		int numBytes = intBuffer.get(0);
436		byte[] bytes = new byte[numBytes];
437		buffer.get(bytes);
438		return new String(bytes);
439	}
440
441	public void glGetShaderPrecisionFormat (int shadertype, int precisiontype, IntBuffer range, IntBuffer precision) {
442		throw new UnsupportedOperationException("unsupported, won't implement");
443	}
444
445	public void glGetShaderiv (int shader, int pname, IntBuffer params) {
446		GL20.glGetShader(shader, pname, params);
447	}
448
449	public String glGetString (int name) {
450		return GL11.glGetString(name);
451	}
452
453	public void glGetTexParameterfv (int target, int pname, FloatBuffer params) {
454		GL11.glGetTexParameter(target, pname, params);
455	}
456
457	public void glGetTexParameteriv (int target, int pname, IntBuffer params) {
458		GL11.glGetTexParameter(target, pname, params);
459	}
460
461	public int glGetUniformLocation (int program, String name) {
462		return GL20.glGetUniformLocation(program, name);
463	}
464
465	public void glGetUniformfv (int program, int location, FloatBuffer params) {
466		GL20.glGetUniform(program, location, params);
467	}
468
469	public void glGetUniformiv (int program, int location, IntBuffer params) {
470		GL20.glGetUniform(program, location, params);
471	}
472
473	public void glGetVertexAttribPointerv (int index, int pname, Buffer pointer) {
474		throw new UnsupportedOperationException("unsupported, won't implement");
475	}
476
477	public void glGetVertexAttribfv (int index, int pname, FloatBuffer params) {
478		GL20.glGetVertexAttrib(index, pname, params);
479	}
480
481	public void glGetVertexAttribiv (int index, int pname, IntBuffer params) {
482		GL20.glGetVertexAttrib(index, pname, params);
483	}
484
485	public void glHint (int target, int mode) {
486		GL11.glHint(target, mode);
487	}
488
489	public boolean glIsBuffer (int buffer) {
490		return GL15.glIsBuffer(buffer);
491	}
492
493	public boolean glIsEnabled (int cap) {
494		return GL11.glIsEnabled(cap);
495	}
496
497	public boolean glIsFramebuffer (int framebuffer) {
498		return EXTFramebufferObject.glIsFramebufferEXT(framebuffer);
499	}
500
501	public boolean glIsProgram (int program) {
502		return GL20.glIsProgram(program);
503	}
504
505	public boolean glIsRenderbuffer (int renderbuffer) {
506		return EXTFramebufferObject.glIsRenderbufferEXT(renderbuffer);
507	}
508
509	public boolean glIsShader (int shader) {
510		return GL20.glIsShader(shader);
511	}
512
513	public boolean glIsTexture (int texture) {
514		return GL11.glIsTexture(texture);
515	}
516
517	public void glLineWidth (float width) {
518		GL11.glLineWidth(width);
519	}
520
521	public void glLinkProgram (int program) {
522		GL20.glLinkProgram(program);
523	}
524
525	public void glPixelStorei (int pname, int param) {
526		GL11.glPixelStorei(pname, param);
527	}
528
529	public void glPolygonOffset (float factor, float units) {
530		GL11.glPolygonOffset(factor, units);
531	}
532
533	public void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels) {
534		if (pixels instanceof ByteBuffer)
535			GL11.glReadPixels(x, y, width, height, format, type, (ByteBuffer)pixels);
536		else if (pixels instanceof ShortBuffer)
537			GL11.glReadPixels(x, y, width, height, format, type, (ShortBuffer)pixels);
538		else if (pixels instanceof IntBuffer)
539			GL11.glReadPixels(x, y, width, height, format, type, (IntBuffer)pixels);
540		else if (pixels instanceof FloatBuffer)
541			GL11.glReadPixels(x, y, width, height, format, type, (FloatBuffer)pixels);
542		else
543			throw new GdxRuntimeException("Can't use " + pixels.getClass().getName()
544				+ " with this method. Use ByteBuffer, ShortBuffer, IntBuffer or FloatBuffer instead. Blame LWJGL");
545	}
546
547	public void glReleaseShaderCompiler () {
548		// nothing to do here
549	}
550
551	public void glRenderbufferStorage (int target, int internalformat, int width, int height) {
552		EXTFramebufferObject.glRenderbufferStorageEXT(target, internalformat, width, height);
553	}
554
555	public void glSampleCoverage (float value, boolean invert) {
556		GL13.glSampleCoverage(value, invert);
557	}
558
559	public void glScissor (int x, int y, int width, int height) {
560		GL11.glScissor(x, y, width, height);
561	}
562
563	public void glShaderBinary (int n, IntBuffer shaders, int binaryformat, Buffer binary, int length) {
564		throw new UnsupportedOperationException("unsupported, won't implement");
565	}
566
567	public void glShaderSource (int shader, String string) {
568		GL20.glShaderSource(shader, string);
569	}
570
571	public void glStencilFunc (int func, int ref, int mask) {
572		GL11.glStencilFunc(func, ref, mask);
573	}
574
575	public void glStencilFuncSeparate (int face, int func, int ref, int mask) {
576		GL20.glStencilFuncSeparate(face, func, ref, mask);
577	}
578
579	public void glStencilMask (int mask) {
580		GL11.glStencilMask(mask);
581	}
582
583	public void glStencilMaskSeparate (int face, int mask) {
584		GL20.glStencilMaskSeparate(face, mask);
585	}
586
587	public void glStencilOp (int fail, int zfail, int zpass) {
588		GL11.glStencilOp(fail, zfail, zpass);
589	}
590
591	public void glStencilOpSeparate (int face, int fail, int zfail, int zpass) {
592		GL20.glStencilOpSeparate(face, fail, zfail, zpass);
593	}
594
595	public void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type,
596		Buffer pixels) {
597		if (pixels == null)
598			GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (ByteBuffer)null);
599		else if (pixels instanceof ByteBuffer)
600			GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (ByteBuffer)pixels);
601		else if (pixels instanceof ShortBuffer)
602			GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (ShortBuffer)pixels);
603		else if (pixels instanceof IntBuffer)
604			GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (IntBuffer)pixels);
605		else if (pixels instanceof FloatBuffer)
606			GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (FloatBuffer)pixels);
607		else if (pixels instanceof DoubleBuffer)
608			GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (DoubleBuffer)pixels);
609		else
610			throw new GdxRuntimeException("Can't use " + pixels.getClass().getName()
611				+ " with this method. Use ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer or DoubleBuffer instead. Blame LWJGL");
612	}
613
614	public void glTexParameterf (int target, int pname, float param) {
615		GL11.glTexParameterf(target, pname, param);
616	}
617
618	public void glTexParameterfv (int target, int pname, FloatBuffer params) {
619		GL11.glTexParameter(target, pname, params);
620	}
621
622	public void glTexParameteri (int target, int pname, int param) {
623		GL11.glTexParameteri(target, pname, param);
624	}
625
626	public void glTexParameteriv (int target, int pname, IntBuffer params) {
627		GL11.glTexParameter(target, pname, params);
628	}
629
630	public void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format, int type,
631		Buffer pixels) {
632		if (pixels instanceof ByteBuffer)
633			GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (ByteBuffer)pixels);
634		else if (pixels instanceof ShortBuffer)
635			GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (ShortBuffer)pixels);
636		else if (pixels instanceof IntBuffer)
637			GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (IntBuffer)pixels);
638		else if (pixels instanceof FloatBuffer)
639			GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (FloatBuffer)pixels);
640		else if (pixels instanceof DoubleBuffer)
641			GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (DoubleBuffer)pixels);
642		else
643			throw new GdxRuntimeException("Can't use " + pixels.getClass().getName()
644				+ " with this method. Use ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer or DoubleBuffer instead. Blame LWJGL");
645	}
646
647	public void glUniform1f (int location, float x) {
648		GL20.glUniform1f(location, x);
649	}
650
651	public void glUniform1fv (int location, int count, FloatBuffer v) {
652		GL20.glUniform1(location, v);
653	}
654
655	public void glUniform1fv (int location, int count, float[] v, int offset) {
656		GL20.glUniform1(location, toFloatBuffer(v, offset, count));
657	}
658
659	public void glUniform1i (int location, int x) {
660		GL20.glUniform1i(location, x);
661	}
662
663	public void glUniform1iv (int location, int count, IntBuffer v) {
664		GL20.glUniform1(location, v);
665	}
666
667	@Override
668	public void glUniform1iv (int location, int count, int[] v, int offset) {
669		GL20.glUniform1(location, toIntBuffer(v, offset, count));
670	}
671
672	public void glUniform2f (int location, float x, float y) {
673		GL20.glUniform2f(location, x, y);
674	}
675
676	public void glUniform2fv (int location, int count, FloatBuffer v) {
677		GL20.glUniform2(location, v);
678	}
679
680	public void glUniform2fv (int location, int count, float[] v, int offset) {
681		GL20.glUniform2(location, toFloatBuffer(v, offset, count << 1));
682	}
683
684	public void glUniform2i (int location, int x, int y) {
685		GL20.glUniform2i(location, x, y);
686	}
687
688	public void glUniform2iv (int location, int count, IntBuffer v) {
689		GL20.glUniform2(location, v);
690	}
691
692	public void glUniform2iv (int location, int count, int[] v, int offset) {
693		GL20.glUniform2(location, toIntBuffer(v, offset, count << 1));
694	}
695
696	public void glUniform3f (int location, float x, float y, float z) {
697		GL20.glUniform3f(location, x, y, z);
698	}
699
700	public void glUniform3fv (int location, int count, FloatBuffer v) {
701		GL20.glUniform3(location, v);
702	}
703
704	public void glUniform3fv (int location, int count, float[] v, int offset) {
705		GL20.glUniform3(location, toFloatBuffer(v, offset, count * 3));
706	}
707
708	public void glUniform3i (int location, int x, int y, int z) {
709		GL20.glUniform3i(location, x, y, z);
710	}
711
712	public void glUniform3iv (int location, int count, IntBuffer v) {
713		GL20.glUniform3(location, v);
714	}
715
716	public void glUniform3iv (int location, int count, int[] v, int offset) {
717		GL20.glUniform3(location, toIntBuffer(v, offset, count * 3));
718	}
719
720	public void glUniform4f (int location, float x, float y, float z, float w) {
721		GL20.glUniform4f(location, x, y, z, w);
722	}
723
724	public void glUniform4fv (int location, int count, FloatBuffer v) {
725		GL20.glUniform4(location, v);
726	}
727
728	public void glUniform4fv (int location, int count, float[] v, int offset) {
729		GL20.glUniform4(location, toFloatBuffer(v, offset, count << 2));
730	}
731
732	public void glUniform4i (int location, int x, int y, int z, int w) {
733		GL20.glUniform4i(location, x, y, z, w);
734	}
735
736	public void glUniform4iv (int location, int count, IntBuffer v) {
737		GL20.glUniform4(location, v);
738	}
739
740	public void glUniform4iv (int location, int count, int[] v, int offset) {
741		GL20.glUniform4(location, toIntBuffer(v, offset, count << 2));
742	}
743
744	public void glUniformMatrix2fv (int location, int count, boolean transpose, FloatBuffer value) {
745		GL20.glUniformMatrix2(location, transpose, value);
746	}
747
748	public void glUniformMatrix2fv (int location, int count, boolean transpose, float[] value, int offset) {
749		GL20.glUniformMatrix2(location, transpose, toFloatBuffer(value, offset, count << 2));
750	}
751
752	public void glUniformMatrix3fv (int location, int count, boolean transpose, FloatBuffer value) {
753		GL20.glUniformMatrix3(location, transpose, value);
754	}
755
756	public void glUniformMatrix3fv (int location, int count, boolean transpose, float[] value, int offset) {
757		GL20.glUniformMatrix3(location, transpose, toFloatBuffer(value, offset, count * 9));
758	}
759
760	public void glUniformMatrix4fv (int location, int count, boolean transpose, FloatBuffer value) {
761		GL20.glUniformMatrix4(location, transpose, value);
762	}
763
764	public void glUniformMatrix4fv (int location, int count, boolean transpose, float[] value, int offset) {
765		GL20.glUniformMatrix4(location, transpose, toFloatBuffer(value, offset, count << 4));
766	}
767
768	public void glUseProgram (int program) {
769		GL20.glUseProgram(program);
770	}
771
772	public void glValidateProgram (int program) {
773		GL20.glValidateProgram(program);
774	}
775
776	public void glVertexAttrib1f (int indx, float x) {
777		GL20.glVertexAttrib1f(indx, x);
778	}
779
780	public void glVertexAttrib1fv (int indx, FloatBuffer values) {
781		GL20.glVertexAttrib1f(indx, values.get());
782	}
783
784	public void glVertexAttrib2f (int indx, float x, float y) {
785		GL20.glVertexAttrib2f(indx, x, y);
786	}
787
788	public void glVertexAttrib2fv (int indx, FloatBuffer values) {
789		GL20.glVertexAttrib2f(indx, values.get(), values.get());
790	}
791
792	public void glVertexAttrib3f (int indx, float x, float y, float z) {
793		GL20.glVertexAttrib3f(indx, x, y, z);
794	}
795
796	public void glVertexAttrib3fv (int indx, FloatBuffer values) {
797		GL20.glVertexAttrib3f(indx, values.get(), values.get(), values.get());
798	}
799
800	public void glVertexAttrib4f (int indx, float x, float y, float z, float w) {
801		GL20.glVertexAttrib4f(indx, x, y, z, w);
802	}
803
804	public void glVertexAttrib4fv (int indx, FloatBuffer values) {
805		GL20.glVertexAttrib4f(indx, values.get(), values.get(), values.get(), values.get());
806	}
807
808	public void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, Buffer buffer) {
809		if (buffer instanceof ByteBuffer) {
810			if (type == GL_BYTE)
811				GL20.glVertexAttribPointer(indx, size, false, normalized, stride, (ByteBuffer)buffer);
812			else if (type == GL_UNSIGNED_BYTE)
813				GL20.glVertexAttribPointer(indx, size, true, normalized, stride, (ByteBuffer)buffer);
814			else if (type == GL_SHORT)
815				GL20.glVertexAttribPointer(indx, size, false, normalized, stride, ((ByteBuffer)buffer).asShortBuffer());
816			else if (type == GL_UNSIGNED_SHORT)
817				GL20.glVertexAttribPointer(indx, size, true, normalized, stride, ((ByteBuffer)buffer).asShortBuffer());
818			else if (type == GL_FLOAT)
819				GL20.glVertexAttribPointer(indx, size, normalized, stride, ((ByteBuffer)buffer).asFloatBuffer());
820			else
821				throw new GdxRuntimeException(
822					"Can't use "
823						+ buffer.getClass().getName()
824						+ " with type "
825						+ type
826						+ " with this method. Use ByteBuffer and one of GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT or GL_FLOAT for type. Blame LWJGL");
827		} else if (buffer instanceof FloatBuffer) {
828			if (type == GL_FLOAT)
829				GL20.glVertexAttribPointer(indx, size, normalized, stride, (FloatBuffer)buffer);
830			else
831				throw new GdxRuntimeException("Can't use " + buffer.getClass().getName() + " with type " + type
832					+ " with this method.");
833		} else
834			throw new GdxRuntimeException("Can't use " + buffer.getClass().getName()
835				+ " with this method. Use ByteBuffer instead. Blame LWJGL");
836	}
837
838	public void glViewport (int x, int y, int width, int height) {
839		GL11.glViewport(x, y, width, height);
840	}
841
842	public void glDrawElements (int mode, int count, int type, int indices) {
843		GL11.glDrawElements(mode, count, type, indices);
844	}
845
846	public void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, int ptr) {
847		GL20.glVertexAttribPointer(indx, size, type, normalized, stride, ptr);
848	}
849}
850