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