• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Main repository of MikuMikuStudio


Commit MetaInfo

Revision117bbd18c343b9ea2836d61b38def0713f746ebb (tree)
Time2013-04-08 10:01:24
AuthorshadowisLORD <shadowisLORD@75d0...>
CommitershadowisLORD

Log Message

  • Added glGetError() checks after every GL call (its ugly, I know, but it helps with debugging). Added option to disable it with constant on RendererUtil.ENABLE_ERROR_CHECKING.
  • Set lastFb in OGLESShaderRenderer when context is reset, this is needed otherwise the state tracker would not work correctly.
  • Fix issue with Mesh.Mode.Hybrid that wasn't rendering triangle fans correctly (was rendering them as triangle strips instead).
  • Remove call to glPointSize in OGLESShaderRenderer (it would most likely crash anyway, since GLES10 calls can't be used in a GLES20 context)
  • TestCustomMesh now uses shorts instead of ints for the index buffer. 32-bit indices are not supported on Android and are slower on Desktop, don't use them if you can avoid it.

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@10525 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

Change Summary

Incremental Difference

--- a/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java
+++ b/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java
@@ -121,13 +121,6 @@ public class OGLESShaderRenderer implements Renderer {
121121 nameBuf.rewind();
122122 }
123123
124- private void checkGLError() {
125- int error;
126- while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
127- throw new RendererException("OpenGL Error " + error);
128- }
129- }
130-
131124 public Statistics getStatistics() {
132125 return statistics;
133126 }
@@ -330,6 +323,9 @@ public class OGLESShaderRenderer implements Renderer {
330323 // Allocate buffer for compressed formats.
331324 IntBuffer compressedFormats = BufferUtils.createIntBuffer(numCompressedFormats);
332325 GLES20.glGetIntegerv(GLES20.GL_COMPRESSED_TEXTURE_FORMATS, compressedFormats);
326+
327+ // Check for errors after all glGet calls.
328+ RendererUtil.checkGLError();
333329
334330 // Print compressed formats.
335331 for (int i = 0; i < numCompressedFormats; i++) {
@@ -337,9 +333,10 @@ public class OGLESShaderRenderer implements Renderer {
337333 }
338334
339335 TextureUtil.loadTextureFeatures(extensions);
340-
336+
341337 applyRenderState(RenderState.DEFAULT);
342338 GLES20.glDisable(GLES20.GL_DITHER);
339+ RendererUtil.checkGLError();
343340
344341 useVBO = false;
345342
@@ -363,7 +360,7 @@ public class OGLESShaderRenderer implements Renderer {
363360 objManager.resetObjects();
364361 statistics.clearMemory();
365362 boundShader = null;
366-// lastFb = null;
363+ lastFb = null;
367364 context.reset();
368365 }
369366
@@ -383,6 +380,7 @@ public class OGLESShaderRenderer implements Renderer {
383380 \*********************************************************************/
384381 public void setDepthRange(float start, float end) {
385382 GLES20.glDepthRangef(start, end);
383+ RendererUtil.checkGLError();
386384 }
387385
388386 public void clearBuffers(boolean color, boolean depth, boolean stencil) {
@@ -398,11 +396,13 @@ public class OGLESShaderRenderer implements Renderer {
398396 }
399397 if (bits != 0) {
400398 GLES20.glClear(bits);
399+ RendererUtil.checkGLError();
401400 }
402401 }
403402
404403 public void setBackgroundColor(ColorRGBA color) {
405404 GLES20.glClearColor(color.r, color.g, color.b, color.a);
405+ RendererUtil.checkGLError();
406406 }
407407
408408 public void applyRenderState(RenderState state) {
@@ -418,24 +418,30 @@ public class OGLESShaderRenderer implements Renderer {
418418 if (state.isDepthTest() && !context.depthTestEnabled) {
419419 GLES20.glEnable(GLES20.GL_DEPTH_TEST);
420420 GLES20.glDepthFunc(GLES20.GL_LEQUAL);
421+ RendererUtil.checkGLError();
421422 context.depthTestEnabled = true;
422423 } else if (!state.isDepthTest() && context.depthTestEnabled) {
423424 GLES20.glDisable(GLES20.GL_DEPTH_TEST);
425+ RendererUtil.checkGLError();
424426 context.depthTestEnabled = false;
425427 }
426428
427429 if (state.isDepthWrite() && !context.depthWriteEnabled) {
428430 GLES20.glDepthMask(true);
431+ RendererUtil.checkGLError();
429432 context.depthWriteEnabled = true;
430433 } else if (!state.isDepthWrite() && context.depthWriteEnabled) {
431434 GLES20.glDepthMask(false);
435+ RendererUtil.checkGLError();
432436 context.depthWriteEnabled = false;
433437 }
434438 if (state.isColorWrite() && !context.colorWriteEnabled) {
435439 GLES20.glColorMask(true, true, true, true);
440+ RendererUtil.checkGLError();
436441 context.colorWriteEnabled = true;
437442 } else if (!state.isColorWrite() && context.colorWriteEnabled) {
438443 GLES20.glColorMask(false, false, false, false);
444+ RendererUtil.checkGLError();
439445 context.colorWriteEnabled = false;
440446 }
441447 // if (state.isPointSprite() && !context.pointSprite) {
@@ -452,6 +458,8 @@ public class OGLESShaderRenderer implements Renderer {
452458 GLES20.glEnable(GLES20.GL_POLYGON_OFFSET_FILL);
453459 GLES20.glPolygonOffset(state.getPolyOffsetFactor(),
454460 state.getPolyOffsetUnits());
461+ RendererUtil.checkGLError();
462+
455463 context.polyOffsetEnabled = true;
456464 context.polyOffsetFactor = state.getPolyOffsetFactor();
457465 context.polyOffsetUnits = state.getPolyOffsetUnits();
@@ -460,6 +468,8 @@ public class OGLESShaderRenderer implements Renderer {
460468 || state.getPolyOffsetUnits() != context.polyOffsetUnits) {
461469 GLES20.glPolygonOffset(state.getPolyOffsetFactor(),
462470 state.getPolyOffsetUnits());
471+ RendererUtil.checkGLError();
472+
463473 context.polyOffsetFactor = state.getPolyOffsetFactor();
464474 context.polyOffsetUnits = state.getPolyOffsetUnits();
465475 }
@@ -467,6 +477,8 @@ public class OGLESShaderRenderer implements Renderer {
467477 } else {
468478 if (context.polyOffsetEnabled) {
469479 GLES20.glDisable(GLES20.GL_POLYGON_OFFSET_FILL);
480+ RendererUtil.checkGLError();
481+
470482 context.polyOffsetEnabled = false;
471483 context.polyOffsetFactor = 0;
472484 context.polyOffsetUnits = 0;
@@ -475,8 +487,10 @@ public class OGLESShaderRenderer implements Renderer {
475487 if (state.getFaceCullMode() != context.cullMode) {
476488 if (state.getFaceCullMode() == RenderState.FaceCullMode.Off) {
477489 GLES20.glDisable(GLES20.GL_CULL_FACE);
490+ RendererUtil.checkGLError();
478491 } else {
479492 GLES20.glEnable(GLES20.GL_CULL_FACE);
493+ RendererUtil.checkGLError();
480494 }
481495
482496 switch (state.getFaceCullMode()) {
@@ -484,12 +498,15 @@ public class OGLESShaderRenderer implements Renderer {
484498 break;
485499 case Back:
486500 GLES20.glCullFace(GLES20.GL_BACK);
501+ RendererUtil.checkGLError();
487502 break;
488503 case Front:
489504 GLES20.glCullFace(GLES20.GL_FRONT);
505+ RendererUtil.checkGLError();
490506 break;
491507 case FrontAndBack:
492508 GLES20.glCullFace(GLES20.GL_FRONT_AND_BACK);
509+ RendererUtil.checkGLError();
493510 break;
494511 default:
495512 throw new UnsupportedOperationException("Unrecognized face cull mode: "
@@ -502,6 +519,7 @@ public class OGLESShaderRenderer implements Renderer {
502519 if (state.getBlendMode() != context.blendMode) {
503520 if (state.getBlendMode() == RenderState.BlendMode.Off) {
504521 GLES20.glDisable(GLES20.GL_BLEND);
522+ RendererUtil.checkGLError();
505523 } else {
506524 GLES20.glEnable(GLES20.GL_BLEND);
507525 switch (state.getBlendMode()) {
@@ -532,6 +550,7 @@ public class OGLESShaderRenderer implements Renderer {
532550 throw new UnsupportedOperationException("Unrecognized blend mode: "
533551 + state.getBlendMode());
534552 }
553+ RendererUtil.checkGLError();
535554 }
536555 context.blendMode = state.getBlendMode();
537556 }
@@ -543,6 +562,8 @@ public class OGLESShaderRenderer implements Renderer {
543562 public void setViewPort(int x, int y, int w, int h) {
544563 if (x != vpX || vpY != y || vpW != w || vpH != h) {
545564 GLES20.glViewport(x, y, w, h);
565+ RendererUtil.checkGLError();
566+
546567 vpX = x;
547568 vpY = y;
548569 vpW = w;
@@ -553,10 +574,12 @@ public class OGLESShaderRenderer implements Renderer {
553574 public void setClipRect(int x, int y, int width, int height) {
554575 if (!context.clipRectEnabled) {
555576 GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
577+ RendererUtil.checkGLError();
556578 context.clipRectEnabled = true;
557579 }
558580 if (clipX != x || clipY != y || clipW != width || clipH != height) {
559581 GLES20.glScissor(x, y, width, height);
582+ RendererUtil.checkGLError();
560583 clipX = x;
561584 clipY = y;
562585 clipW = width;
@@ -567,6 +590,7 @@ public class OGLESShaderRenderer implements Renderer {
567590 public void clearClipRect() {
568591 if (context.clipRectEnabled) {
569592 GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
593+ RendererUtil.checkGLError();
570594 context.clipRectEnabled = false;
571595
572596 clipX = 0;
@@ -577,10 +601,8 @@ public class OGLESShaderRenderer implements Renderer {
577601 }
578602
579603 public void onFrame() {
580- int error = GLES20.glGetError();
581- if (error != GLES20.GL_NO_ERROR){
582- throw new RendererException("OpenGL Error " + error + ". Enable error checking for more info.");
583- }
604+ RendererUtil.checkGLErrorForced();
605+
584606 objManager.deleteUnused(this);
585607 }
586608
@@ -598,6 +620,8 @@ public class OGLESShaderRenderer implements Renderer {
598620 stringBuf.append(uniform.getName()).append('\0');
599621 updateNameBuffer();
600622 int loc = GLES20.glGetUniformLocation(shader.getId(), uniform.getName());
623+ RendererUtil.checkGLError();
624+
601625 if (loc < 0) {
602626 uniform.setLocation(-1);
603627 // uniform is not declared in shader
@@ -610,6 +634,8 @@ public class OGLESShaderRenderer implements Renderer {
610634 int shaderId = shader.getId();
611635 if (context.boundShaderProgram != shaderId) {
612636 GLES20.glUseProgram(shaderId);
637+ RendererUtil.checkGLError();
638+
613639 statistics.onShaderUse(shader, true);
614640 boundShader = shader;
615641 context.boundShaderProgram = shaderId;
@@ -626,6 +652,8 @@ public class OGLESShaderRenderer implements Renderer {
626652
627653 if (context.boundShaderProgram != shaderId) {
628654 GLES20.glUseProgram(shaderId);
655+ RendererUtil.checkGLError();
656+
629657 statistics.onShaderUse(shader, true);
630658 boundShader = shader;
631659 context.boundShaderProgram = shaderId;
@@ -730,6 +758,7 @@ public class OGLESShaderRenderer implements Renderer {
730758 default:
731759 throw new UnsupportedOperationException("Unsupported uniform type: " + uniform.getVarType());
732760 }
761+ RendererUtil.checkGLError();
733762 }
734763
735764 protected void updateShaderUniforms(Shader shader) {
@@ -775,6 +804,8 @@ public class OGLESShaderRenderer implements Renderer {
775804 if (id == -1) {
776805 // Create id
777806 id = GLES20.glCreateShader(convertShaderType(source.getType()));
807+ RendererUtil.checkGLError();
808+
778809 if (id <= 0) {
779810 throw new RendererException("Invalid ID received when trying to create shader.");
780811 }
@@ -821,7 +852,10 @@ public class OGLESShaderRenderer implements Renderer {
821852 // System.out.println("precision "+precision[0]);
822853
823854 GLES20.glCompileShader(id);
855+ RendererUtil.checkGLError();
856+
824857 GLES20.glGetShaderiv(id, GLES20.GL_COMPILE_STATUS, intBuf1);
858+ RendererUtil.checkGLError();
825859
826860 boolean compiledOK = intBuf1.get(0) == GLES20.GL_TRUE;
827861 String infoLog = null;
@@ -830,7 +864,7 @@ public class OGLESShaderRenderer implements Renderer {
830864 // even if compile succeeded, check
831865 // log for warnings
832866 GLES20.glGetShaderiv(id, GLES20.GL_INFO_LOG_LENGTH, intBuf1);
833- checkGLError();
867+ RendererUtil.checkGLError();
834868 infoLog = GLES20.glGetShaderInfoLog(id);
835869 }
836870
@@ -858,6 +892,7 @@ public class OGLESShaderRenderer implements Renderer {
858892 if (id == -1) {
859893 // create program
860894 id = GLES20.glCreateProgram();
895+ RendererUtil.checkGLError();
861896
862897 if (id <= 0) {
863898 throw new RendererException("Invalid ID received when trying to create shader program.");
@@ -871,23 +906,30 @@ public class OGLESShaderRenderer implements Renderer {
871906 if (source.isUpdateNeeded()) {
872907 updateShaderSourceData(source);
873908 }
909+
874910 GLES20.glAttachShader(id, source.getId());
911+ RendererUtil.checkGLError();
875912 }
876913
877914 // link shaders to program
878915 GLES20.glLinkProgram(id);
916+ RendererUtil.checkGLError();
917+
879918 GLES20.glGetProgramiv(id, GLES20.GL_LINK_STATUS, intBuf1);
919+ RendererUtil.checkGLError();
880920
881921 boolean linkOK = intBuf1.get(0) == GLES20.GL_TRUE;
882922 String infoLog = null;
883923
884924 if (VALIDATE_SHADER || !linkOK) {
885925 GLES20.glGetProgramiv(id, GLES20.GL_INFO_LOG_LENGTH, intBuf1);
926+ RendererUtil.checkGLError();
886927
887928 int length = intBuf1.get(0);
888929 if (length > 3) {
889930 // get infos
890931 infoLog = GLES20.glGetProgramInfoLog(id);
932+ RendererUtil.checkGLError();
891933 }
892934 }
893935
@@ -940,7 +982,10 @@ public class OGLESShaderRenderer implements Renderer {
940982 }
941983
942984 source.clearUpdateNeeded();
985+
943986 GLES20.glDeleteShader(source.getId());
987+ RendererUtil.checkGLError();
988+
944989 source.resetObject();
945990 }
946991
@@ -953,11 +998,15 @@ public class OGLESShaderRenderer implements Renderer {
953998 for (ShaderSource source : shader.getSources()) {
954999 if (source.getId() != -1) {
9551000 GLES20.glDetachShader(shader.getId(), source.getId());
1001+ RendererUtil.checkGLError();
1002+
9561003 deleteShaderSource(source);
9571004 }
9581005 }
9591006
9601007 GLES20.glDeleteProgram(shader.getId());
1008+ RendererUtil.checkGLError();
1009+
9611010 statistics.onDeleteShader();
9621011 shader.resetObject();
9631012 }
@@ -1161,12 +1210,16 @@ public class OGLESShaderRenderer implements Renderer {
11611210 int id = rb.getId();
11621211 if (id == -1) {
11631212 GLES20.glGenRenderbuffers(1, intBuf1);
1213+ RendererUtil.checkGLError();
1214+
11641215 id = intBuf1.get(0);
11651216 rb.setId(id);
11661217 }
11671218
11681219 if (context.boundRB != id) {
11691220 GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, id);
1221+ RendererUtil.checkGLError();
1222+
11701223 context.boundRB = id;
11711224 }
11721225
@@ -1198,6 +1251,8 @@ public class OGLESShaderRenderer implements Renderer {
11981251 imageFormat.renderBufferStorageFormat,
11991252 fb.getWidth(),
12001253 fb.getHeight());
1254+
1255+ RendererUtil.checkGLError();
12011256 }
12021257 }
12031258
@@ -1229,6 +1284,8 @@ public class OGLESShaderRenderer implements Renderer {
12291284 convertTextureType(tex.getType()),
12301285 image.getId(),
12311286 0);
1287+
1288+ RendererUtil.checkGLError();
12321289 }
12331290
12341291 public void updateFrameBufferAttachment(FrameBuffer fb, RenderBuffer rb) {
@@ -1246,6 +1303,8 @@ public class OGLESShaderRenderer implements Renderer {
12461303 convertAttachmentSlot(rb.getSlot()),
12471304 GLES20.GL_RENDERBUFFER,
12481305 rb.getId());
1306+
1307+ RendererUtil.checkGLError();
12491308 }
12501309 }
12511310
@@ -1255,6 +1314,8 @@ public class OGLESShaderRenderer implements Renderer {
12551314 intBuf1.clear();
12561315 // create FBO
12571316 GLES20.glGenFramebuffers(1, intBuf1);
1317+ RendererUtil.checkGLError();
1318+
12581319 id = intBuf1.get(0);
12591320 fb.setId(id);
12601321 objManager.registerForCleanup(fb);
@@ -1264,6 +1325,8 @@ public class OGLESShaderRenderer implements Renderer {
12641325
12651326 if (context.boundFBO != id) {
12661327 GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, id);
1328+ RendererUtil.checkGLError();
1329+
12671330 // binding an FBO automatically sets draw buf to GL_COLOR_ATTACHMENT0
12681331 context.boundDrawBuf = 0;
12691332 context.boundFBO = id;
@@ -1309,6 +1372,7 @@ public class OGLESShaderRenderer implements Renderer {
13091372 // int textureType = convertTextureType(tex.getType(), tex.getImage().getMultiSamples(), rb.getFace());
13101373 int textureType = convertTextureType(tex.getType());
13111374 GLES20.glGenerateMipmap(textureType);
1375+ RendererUtil.checkGLError();
13121376 }
13131377 }
13141378 }
@@ -1317,6 +1381,8 @@ public class OGLESShaderRenderer implements Renderer {
13171381 // unbind any fbos
13181382 if (context.boundFBO != 0) {
13191383 GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
1384+ RendererUtil.checkGLError();
1385+
13201386 statistics.onFrameBufferUse(null, true);
13211387
13221388 context.boundFBO = 0;
@@ -1347,6 +1413,8 @@ public class OGLESShaderRenderer implements Renderer {
13471413
13481414 if (context.boundFBO != fb.getId()) {
13491415 GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fb.getId());
1416+ RendererUtil.checkGLError();
1417+
13501418 statistics.onFrameBufferUse(fb, true);
13511419
13521420 // update viewport to reflect framebuffer's resolution
@@ -1395,6 +1463,8 @@ public class OGLESShaderRenderer implements Renderer {
13951463 // select this draw buffer
13961464 if (context.boundDrawBuf != rb.getSlot()) {
13971465 GLES20.glActiveTexture(convertAttachmentSlot(rb.getSlot()));
1466+ RendererUtil.checkGLError();
1467+
13981468 context.boundDrawBuf = rb.getSlot();
13991469 }
14001470 }
@@ -1427,6 +1497,8 @@ public class OGLESShaderRenderer implements Renderer {
14271497 setFrameBuffer(fb);
14281498 if (context.boundReadBuf != rb.getSlot()) {
14291499 GLES20.glActiveTexture(convertAttachmentSlot(rb.getSlot()));
1500+ RendererUtil.checkGLError();
1501+
14301502 context.boundReadBuf = rb.getSlot();
14311503 }
14321504 } else {
@@ -1434,17 +1506,21 @@ public class OGLESShaderRenderer implements Renderer {
14341506 }
14351507
14361508 GLES20.glReadPixels(vpX, vpY, vpW, vpH, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, byteBuf);
1509+ RendererUtil.checkGLError();
14371510 }
14381511
14391512 private void deleteRenderBuffer(FrameBuffer fb, RenderBuffer rb) {
14401513 intBuf1.put(0, rb.getId());
14411514 GLES20.glDeleteRenderbuffers(1, intBuf1);
1515+ RendererUtil.checkGLError();
14421516 }
14431517
14441518 public void deleteFrameBuffer(FrameBuffer fb) {
14451519 if (fb.getId() != -1) {
14461520 if (context.boundFBO == fb.getId()) {
14471521 GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
1522+ RendererUtil.checkGLError();
1523+
14481524 context.boundFBO = 0;
14491525 }
14501526
@@ -1457,6 +1533,8 @@ public class OGLESShaderRenderer implements Renderer {
14571533
14581534 intBuf1.put(0, fb.getId());
14591535 GLES20.glDeleteFramebuffers(1, intBuf1);
1536+ RendererUtil.checkGLError();
1537+
14601538 fb.resetObject();
14611539
14621540 statistics.onDeleteFrameBuffer();
@@ -1539,6 +1617,7 @@ public class OGLESShaderRenderer implements Renderer {
15391617
15401618 GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_MIN_FILTER, minFilter);
15411619 GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_MAG_FILTER, magFilter);
1620+ RendererUtil.checkGLError();
15421621
15431622 /*
15441623 if (tex.getAnisotropicFilter() > 1){
@@ -1565,6 +1644,8 @@ public class OGLESShaderRenderer implements Renderer {
15651644 // fall down here is intentional..
15661645 // case OneDimensional:
15671646 GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S)));
1647+
1648+ RendererUtil.checkGLError();
15681649 break;
15691650 default:
15701651 throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
@@ -1594,6 +1675,8 @@ public class OGLESShaderRenderer implements Renderer {
15941675 if (texId == -1) {
15951676 // create texture
15961677 GLES20.glGenTextures(1, intBuf1);
1678+ RendererUtil.checkGLError();
1679+
15971680 texId = intBuf1.get(0);
15981681 img.setId(texId);
15991682 objManager.registerForCleanup(img);
@@ -1606,10 +1689,14 @@ public class OGLESShaderRenderer implements Renderer {
16061689 if (context.boundTextures[0] != img) {
16071690 if (context.boundTextureUnit != 0) {
16081691 GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
1692+ RendererUtil.checkGLError();
1693+
16091694 context.boundTextureUnit = 0;
16101695 }
16111696
16121697 GLES20.glBindTexture(target, texId);
1698+ RendererUtil.checkGLError();
1699+
16131700 context.boundTextures[0] = img;
16141701 }
16151702
@@ -1697,6 +1784,8 @@ public class OGLESShaderRenderer implements Renderer {
16971784 }
16981785
16991786 GLES20.glBindTexture(type, texId);
1787+ RendererUtil.checkGLError();
1788+
17001789 textures[unit] = image;
17011790
17021791 statistics.onTextureUse(tex.getImage(), true);
@@ -1734,6 +1823,8 @@ public class OGLESShaderRenderer implements Renderer {
17341823 intBuf1.position(0).limit(1);
17351824
17361825 GLES20.glDeleteTextures(1, intBuf1);
1826+ RendererUtil.checkGLError();
1827+
17371828 image.resetObject();
17381829
17391830 statistics.onDeleteTexture();
@@ -1791,6 +1882,8 @@ public class OGLESShaderRenderer implements Renderer {
17911882 if (bufId == -1) {
17921883 // create buffer
17931884 GLES20.glGenBuffers(1, intBuf1);
1885+ RendererUtil.checkGLError();
1886+
17941887 bufId = intBuf1.get(0);
17951888 vb.setId(bufId);
17961889 objManager.registerForCleanup(vb);
@@ -1804,12 +1897,16 @@ public class OGLESShaderRenderer implements Renderer {
18041897 target = GLES20.GL_ELEMENT_ARRAY_BUFFER;
18051898 if (context.boundElementArrayVBO != bufId) {
18061899 GLES20.glBindBuffer(target, bufId);
1900+ RendererUtil.checkGLError();
1901+
18071902 context.boundElementArrayVBO = bufId;
18081903 }
18091904 } else {
18101905 target = GLES20.GL_ARRAY_BUFFER;
18111906 if (context.boundArrayVBO != bufId) {
18121907 GLES20.glBindBuffer(target, bufId);
1908+ RendererUtil.checkGLError();
1909+
18131910 context.boundArrayVBO = bufId;
18141911 }
18151912 }
@@ -1825,21 +1922,21 @@ public class OGLESShaderRenderer implements Renderer {
18251922 case Byte:
18261923 case UnsignedByte:
18271924 GLES20.glBufferData(target, size, (ByteBuffer) vb.getData(), usage);
1925+ RendererUtil.checkGLError();
18281926 break;
1829- //case Half:
18301927 case Short:
18311928 case UnsignedShort:
18321929 GLES20.glBufferData(target, size, (ShortBuffer) vb.getData(), usage);
1930+ RendererUtil.checkGLError();
18331931 break;
18341932 case Int:
18351933 case UnsignedInt:
18361934 GLES20.glBufferData(target, size, (IntBuffer) vb.getData(), usage);
1935+ RendererUtil.checkGLError();
18371936 break;
18381937 case Float:
18391938 GLES20.glBufferData(target, size, (FloatBuffer) vb.getData(), usage);
1840- break;
1841- case Double:
1842- GLES20.glBufferData(target, size, (DoubleBuffer) vb.getData(), usage);
1939+ RendererUtil.checkGLError();
18431940 break;
18441941 default:
18451942 throw new RuntimeException("Unknown buffer format.");
@@ -1851,20 +1948,21 @@ public class OGLESShaderRenderer implements Renderer {
18511948 case Byte:
18521949 case UnsignedByte:
18531950 GLES20.glBufferSubData(target, 0, size, (ByteBuffer) vb.getData());
1951+ RendererUtil.checkGLError();
18541952 break;
18551953 case Short:
18561954 case UnsignedShort:
18571955 GLES20.glBufferSubData(target, 0, size, (ShortBuffer) vb.getData());
1956+ RendererUtil.checkGLError();
18581957 break;
18591958 case Int:
18601959 case UnsignedInt:
18611960 GLES20.glBufferSubData(target, 0, size, (IntBuffer) vb.getData());
1961+ RendererUtil.checkGLError();
18621962 break;
18631963 case Float:
18641964 GLES20.glBufferSubData(target, 0, size, (FloatBuffer) vb.getData());
1865- break;
1866- case Double:
1867- GLES20.glBufferSubData(target, 0, size, (DoubleBuffer) vb.getData());
1965+ RendererUtil.checkGLError();
18681966 break;
18691967 default:
18701968 throw new RuntimeException("Unknown buffer format.");
@@ -1881,6 +1979,8 @@ public class OGLESShaderRenderer implements Renderer {
18811979 intBuf1.position(0).limit(1);
18821980
18831981 GLES20.glDeleteBuffers(1, intBuf1);
1982+ RendererUtil.checkGLError();
1983+
18841984 vb.resetObject();
18851985 }
18861986 }
@@ -1891,6 +1991,8 @@ public class OGLESShaderRenderer implements Renderer {
18911991 int idx = attribList.oldList[i];
18921992
18931993 GLES20.glDisableVertexAttribArray(idx);
1994+ RendererUtil.checkGLError();
1995+
18941996 context.boundAttribs[idx] = null;
18951997 }
18961998 context.attribIndexList.copyNewToOld();
@@ -1920,6 +2022,7 @@ public class OGLESShaderRenderer implements Renderer {
19202022
19212023 String attributeName = "in" + vb.getBufferType().name();
19222024 loc = GLES20.glGetAttribLocation(programId, attributeName);
2025+ RendererUtil.checkGLError();
19232026
19242027 // not really the name of it in the shader (inPosition\0) but
19252028 // the internal name of the enum (Position).
@@ -1934,6 +2037,7 @@ public class OGLESShaderRenderer implements Renderer {
19342037 VertexBuffer[] attribs = context.boundAttribs;
19352038 if (!context.attribIndexList.moveToNew(loc)) {
19362039 GLES20.glEnableVertexAttribArray(loc);
2040+ RendererUtil.checkGLError();
19372041 //System.out.println("Enabled ATTRIB IDX: "+loc);
19382042 }
19392043 if (attribs[loc] != vb) {
@@ -1946,8 +2050,9 @@ public class OGLESShaderRenderer implements Renderer {
19462050 }
19472051
19482052 if (context.boundArrayVBO != bufId) {
1949-
19502053 GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufId);
2054+ RendererUtil.checkGLError();
2055+
19512056 context.boundArrayVBO = bufId;
19522057 }
19532058
@@ -1959,6 +2064,8 @@ public class OGLESShaderRenderer implements Renderer {
19592064 vb.isNormalized(),
19602065 vb.getStride(),
19612066 0);
2067+
2068+ RendererUtil.checkGLError();
19622069
19632070 attribs[loc] = vb;
19642071 }
@@ -1977,6 +2084,7 @@ public class OGLESShaderRenderer implements Renderer {
19772084 vertCount, count);
19782085 }else{*/
19792086 GLES20.glDrawArrays(convertElementMode(mode), 0, vertCount);
2087+ RendererUtil.checkGLError();
19802088 /*
19812089 }*/
19822090 }
@@ -1994,11 +2102,13 @@ public class OGLESShaderRenderer implements Renderer {
19942102 assert bufId != -1;
19952103
19962104 if (bufId == -1) {
1997- logger.warning("invalid buffer id!");
2105+ throw new RendererException("Invalid buffer ID");
19982106 }
19992107
20002108 if (context.boundElementArrayVBO != bufId) {
20012109 GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, bufId);
2110+ RendererUtil.checkGLError();
2111+
20022112 context.boundElementArrayVBO = bufId;
20032113 }
20042114
@@ -2044,6 +2154,7 @@ public class OGLESShaderRenderer implements Renderer {
20442154 } else {
20452155 indexBuf.getData().position(curOffset);
20462156 GLES20.glDrawElements(elMode, elementLength, fmt, indexBuf.getData());
2157+ RendererUtil.checkGLError();
20472158 /*
20482159 glDrawRangeElements(elMode,
20492160 0,
@@ -2074,6 +2185,7 @@ public class OGLESShaderRenderer implements Renderer {
20742185 indexBuf.getData().limit(),
20752186 convertVertexBufferFormat(indexBuf.getFormat()),
20762187 0);
2188+ RendererUtil.checkGLError();
20772189 }
20782190 }
20792191 }
@@ -2180,6 +2292,7 @@ public class OGLESShaderRenderer implements Renderer {
21802292 drawTriangleList_Array(indices, mesh, count);
21812293 } else {
21822294 GLES20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
2295+ RendererUtil.checkGLError();
21832296 }
21842297 clearVertexAttribs();
21852298 clearTextureUnits();
@@ -2219,18 +2332,23 @@ public class OGLESShaderRenderer implements Renderer {
22192332 } else {
22202333 // throw new UnsupportedOperationException("Cannot render without index buffer");
22212334 GLES20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
2335+ RendererUtil.checkGLError();
22222336 }
22232337 clearVertexAttribs();
22242338 clearTextureUnits();
22252339 }
22262340
22272341 public void renderMesh(Mesh mesh, int lod, int count) {
2342+ /*
2343+ * NOTE: not supported in OpenGL ES 2.0.
22282344 if (context.pointSize != mesh.getPointSize()) {
22292345 GLES10.glPointSize(mesh.getPointSize());
22302346 context.pointSize = mesh.getPointSize();
22312347 }
2348+ */
22322349 if (context.lineWidth != mesh.getLineWidth()) {
22332350 GLES20.glLineWidth(mesh.getLineWidth());
2351+ RendererUtil.checkGLError();
22342352 context.lineWidth = mesh.getLineWidth();
22352353 }
22362354
@@ -2281,12 +2399,13 @@ public class OGLESShaderRenderer implements Renderer {
22812399 if (i == stripStart) {
22822400 elMode = convertElementMode(Mode.TriangleStrip);
22832401 } else if (i == fanStart) {
2284- elMode = convertElementMode(Mode.TriangleStrip);
2402+ elMode = convertElementMode(Mode.TriangleFan);
22852403 }
22862404 int elementLength = elementLengths[i];
22872405
22882406 indexBuf.getData().position(curOffset);
22892407 GLES20.glDrawElements(elMode, elementLength, fmt, indexBuf.getData());
2408+ RendererUtil.checkGLError();
22902409
22912410 curOffset += elementLength * elSize;
22922411 }
@@ -2296,6 +2415,7 @@ public class OGLESShaderRenderer implements Renderer {
22962415 indexBuf.getData().limit(),
22972416 convertVertexBufferFormat(indexBuf.getFormat()),
22982417 indexBuf.getData());
2418+ RendererUtil.checkGLError();
22992419 }
23002420 }
23012421
@@ -2323,6 +2443,8 @@ public class OGLESShaderRenderer implements Renderer {
23232443 String attributeName = "in" + vb.getBufferType().name();
23242444
23252445 loc = GLES20.glGetAttribLocation(programId, attributeName);
2446+ RendererUtil.checkGLError();
2447+
23262448 if (loc < 0) {
23272449 attrib.setLocation(-1);
23282450 return; // not available in shader.
@@ -2345,8 +2467,11 @@ public class OGLESShaderRenderer implements Renderer {
23452467 vb.isNormalized(),
23462468 vb.getStride(),
23472469 avb.getData());
2470+
2471+ RendererUtil.checkGLError();
23482472
23492473 GLES20.glEnableVertexAttribArray(loc);
2474+ RendererUtil.checkGLError();
23502475
23512476 attribs[loc] = vb;
23522477 } // if (attribs[loc] != vb)
@@ -2366,8 +2491,10 @@ public class OGLESShaderRenderer implements Renderer {
23662491 public void setAlphaToCoverage(boolean value) {
23672492 if (value) {
23682493 GLES20.glEnable(GLES20.GL_SAMPLE_ALPHA_TO_COVERAGE);
2494+ RendererUtil.checkGLError();
23692495 } else {
23702496 GLES20.glDisable(GLES20.GL_SAMPLE_ALPHA_TO_COVERAGE);
2497+ RendererUtil.checkGLError();
23712498 }
23722499 }
23732500
@@ -2375,6 +2502,6 @@ public class OGLESShaderRenderer implements Renderer {
23752502 public void invalidateState() {
23762503 context.reset();
23772504 boundShader = null;
2378-// lastFb = null;
2505+ lastFb = null;
23792506 }
23802507 }
--- /dev/null
+++ b/engine/src/android/com/jme3/renderer/android/RendererUtil.java
@@ -0,0 +1,53 @@
1+package com.jme3.renderer.android;
2+
3+import android.opengl.GLES20;
4+import android.opengl.GLU;
5+import com.jme3.renderer.RendererException;
6+
7+/**
8+ * Utility class used by the {@link OGLESShaderRenderer renderer} and sister classes.
9+ *
10+ * @author Kirill Vainer
11+ */
12+public class RendererUtil {
13+
14+ /**
15+ * When set to true, every OpenGL call will check for errors and throw
16+ * an exception if there is one, if false, no error checking is performed.
17+ */
18+ public static boolean ENABLE_ERROR_CHECKING = true;
19+
20+ /**
21+ * Checks for an OpenGL error and throws a {@link RendererException}
22+ * if there is one. Ignores the value of {@link RendererUtil#ENABLE_ERROR_CHECKING}.
23+ */
24+ public static void checkGLErrorForced() {
25+ int error = GLES20.glGetError();
26+ if (error != 0) {
27+ String message = GLU.gluErrorString(error);
28+ if (message == null) {
29+ throw new RendererException("An unknown OpenGL error has occurred.");
30+ } else {
31+ throw new RendererException("An OpenGL error has occurred: " + message);
32+ }
33+ }
34+ }
35+
36+ /**
37+ * Checks for an OpenGL error and throws a {@link RendererException}
38+ * if there is one. Does nothing if {@link RendererUtil#ENABLE_ERROR_CHECKING}
39+ * is set to <code>false</code>.
40+ */
41+ public static void checkGLError() {
42+ if (!ENABLE_ERROR_CHECKING) return;
43+ int error = GLES20.glGetError();
44+ if (error != 0) {
45+ String message = GLU.gluErrorString(error);
46+ if (message == null) {
47+ throw new RendererException("An unknown OpenGL error has occurred.");
48+ } else {
49+ throw new RendererException("An OpenGL error has occurred: " + message);
50+ }
51+ }
52+ }
53+}
--- a/engine/src/android/com/jme3/renderer/android/TextureUtil.java
+++ b/engine/src/android/com/jme3/renderer/android/TextureUtil.java
@@ -103,10 +103,10 @@ public class TextureUtil {
103103 logger.log(Level.FINEST, " - Uploading bitmap directly. Cannot compress as alpha present.");
104104 if (subTexture) {
105105 GLUtils.texSubImage2D(target, level, x, y, bitmap);
106- checkGLError();
106+ RendererUtil.checkGLError();
107107 } else {
108108 GLUtils.texImage2D(target, level, bitmap, 0);
109- checkGLError();
109+ RendererUtil.checkGLError();
110110 }
111111 } else {
112112 // Convert to RGB565
@@ -150,7 +150,8 @@ public class TextureUtil {
150150 ETC1.ETC1_RGB8_OES,
151151 etc1tex.getData().capacity(),
152152 etc1tex.getData());
153- checkGLError();
153+
154+ RendererUtil.checkGLError();
154155 } else {
155156 GLES20.glCompressedTexImage2D(target,
156157 level,
@@ -160,7 +161,8 @@ public class TextureUtil {
160161 0,
161162 etc1tex.getData().capacity(),
162163 etc1tex.getData());
163- checkGLError();
164+
165+ RendererUtil.checkGLError();
164166 }
165167
166168 // ETC1Util.loadTexture(target, level, 0, GLES20.GL_RGB,
@@ -208,17 +210,17 @@ public class TextureUtil {
208210 if (subTexture) {
209211 System.err.println("x : " + x + " y :" + y + " , " + bitmap.getWidth() + "/" + bitmap.getHeight());
210212 GLUtils.texSubImage2D(target, 0, x, y, bitmap);
211- checkGLError();
213+ RendererUtil.checkGLError();
212214 } else {
213215 GLUtils.texImage2D(target, 0, bitmap, 0);
214- checkGLError();
216+ RendererUtil.checkGLError();
215217 }
216218
217219 if (needMips) {
218220 // No pregenerated mips available,
219221 // generate from base level if required
220222 GLES20.glGenerateMipmap(target);
221- checkGLError();
223+ RendererUtil.checkGLError();
222224 }
223225 }
224226 }
@@ -485,13 +487,6 @@ public class TextureUtil {
485487 }
486488 }
487489
488- private static void checkGLError() {
489- int error;
490- while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
491- throw new RendererException("OpenGL Error " + error);
492- }
493- }
494-
495490 /**
496491 * Update the texture currently bound to target at with data from the given
497492 * Image at position x and y. The parameter index is used as the zoffset in
@@ -564,10 +559,10 @@ public class TextureUtil {
564559
565560 if (imageFormat.compress && data != null) {
566561 GLES20.glCompressedTexSubImage2D(target, i, x, y, mipWidth, mipHeight, imageFormat.format, data.remaining(), data);
567- checkGLError();
562+ RendererUtil.checkGLError();
568563 } else {
569564 GLES20.glTexSubImage2D(target, i, x, y, mipWidth, mipHeight, imageFormat.format, imageFormat.dataType, data);
570- checkGLError();
565+ RendererUtil.checkGLError();
571566 }
572567
573568 pos += mipSizes[i];
--- a/engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglRenderer.java
+++ b/engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglRenderer.java
@@ -2256,7 +2256,7 @@ public class LwjglRenderer implements Renderer {
22562256 if (i == stripStart) {
22572257 elMode = convertElementMode(Mode.TriangleStrip);
22582258 } else if (i == fanStart) {
2259- elMode = convertElementMode(Mode.TriangleStrip);
2259+ elMode = convertElementMode(Mode.TriangleFan);
22602260 }
22612261 int elementLength = elementLengths[i];
22622262
--- a/engine/src/test/jme3test/model/shape/TestCustomMesh.java
+++ b/engine/src/test/jme3test/model/shape/TestCustomMesh.java
@@ -75,12 +75,12 @@ public class TestCustomMesh extends SimpleApplication {
7575 texCoord[3] = new Vector2f(1,1);
7676
7777 // Indexes. We define the order in which mesh should be constructed
78- int [] indexes = {2,0,1,1,3,2};
78+ short[] indexes = {2, 0, 1, 1, 3, 2};
7979
8080 // Setting buffers
8181 m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
8282 m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
83- m.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes));
83+ m.setBuffer(Type.Index, 1, BufferUtils.createShortBuffer(indexes));
8484 m.updateBound();
8585
8686 // *************************************************************************