Main repository of MikuMikuStudio
修订版 | 117bbd18c343b9ea2836d61b38def0713f746ebb (tree) |
---|---|
时间 | 2013-04-08 10:01:24 |
作者 | shadowisLORD <shadowisLORD@75d0...> |
Commiter | shadowisLORD |
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@10525 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
@@ -121,13 +121,6 @@ public class OGLESShaderRenderer implements Renderer { | ||
121 | 121 | nameBuf.rewind(); |
122 | 122 | } |
123 | 123 | |
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 | - | |
131 | 124 | public Statistics getStatistics() { |
132 | 125 | return statistics; |
133 | 126 | } |
@@ -330,6 +323,9 @@ public class OGLESShaderRenderer implements Renderer { | ||
330 | 323 | // Allocate buffer for compressed formats. |
331 | 324 | IntBuffer compressedFormats = BufferUtils.createIntBuffer(numCompressedFormats); |
332 | 325 | GLES20.glGetIntegerv(GLES20.GL_COMPRESSED_TEXTURE_FORMATS, compressedFormats); |
326 | + | |
327 | + // Check for errors after all glGet calls. | |
328 | + RendererUtil.checkGLError(); | |
333 | 329 | |
334 | 330 | // Print compressed formats. |
335 | 331 | for (int i = 0; i < numCompressedFormats; i++) { |
@@ -337,9 +333,10 @@ public class OGLESShaderRenderer implements Renderer { | ||
337 | 333 | } |
338 | 334 | |
339 | 335 | TextureUtil.loadTextureFeatures(extensions); |
340 | - | |
336 | + | |
341 | 337 | applyRenderState(RenderState.DEFAULT); |
342 | 338 | GLES20.glDisable(GLES20.GL_DITHER); |
339 | + RendererUtil.checkGLError(); | |
343 | 340 | |
344 | 341 | useVBO = false; |
345 | 342 |
@@ -363,7 +360,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
363 | 360 | objManager.resetObjects(); |
364 | 361 | statistics.clearMemory(); |
365 | 362 | boundShader = null; |
366 | -// lastFb = null; | |
363 | + lastFb = null; | |
367 | 364 | context.reset(); |
368 | 365 | } |
369 | 366 |
@@ -383,6 +380,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
383 | 380 | \*********************************************************************/ |
384 | 381 | public void setDepthRange(float start, float end) { |
385 | 382 | GLES20.glDepthRangef(start, end); |
383 | + RendererUtil.checkGLError(); | |
386 | 384 | } |
387 | 385 | |
388 | 386 | public void clearBuffers(boolean color, boolean depth, boolean stencil) { |
@@ -398,11 +396,13 @@ public class OGLESShaderRenderer implements Renderer { | ||
398 | 396 | } |
399 | 397 | if (bits != 0) { |
400 | 398 | GLES20.glClear(bits); |
399 | + RendererUtil.checkGLError(); | |
401 | 400 | } |
402 | 401 | } |
403 | 402 | |
404 | 403 | public void setBackgroundColor(ColorRGBA color) { |
405 | 404 | GLES20.glClearColor(color.r, color.g, color.b, color.a); |
405 | + RendererUtil.checkGLError(); | |
406 | 406 | } |
407 | 407 | |
408 | 408 | public void applyRenderState(RenderState state) { |
@@ -418,24 +418,30 @@ public class OGLESShaderRenderer implements Renderer { | ||
418 | 418 | if (state.isDepthTest() && !context.depthTestEnabled) { |
419 | 419 | GLES20.glEnable(GLES20.GL_DEPTH_TEST); |
420 | 420 | GLES20.glDepthFunc(GLES20.GL_LEQUAL); |
421 | + RendererUtil.checkGLError(); | |
421 | 422 | context.depthTestEnabled = true; |
422 | 423 | } else if (!state.isDepthTest() && context.depthTestEnabled) { |
423 | 424 | GLES20.glDisable(GLES20.GL_DEPTH_TEST); |
425 | + RendererUtil.checkGLError(); | |
424 | 426 | context.depthTestEnabled = false; |
425 | 427 | } |
426 | 428 | |
427 | 429 | if (state.isDepthWrite() && !context.depthWriteEnabled) { |
428 | 430 | GLES20.glDepthMask(true); |
431 | + RendererUtil.checkGLError(); | |
429 | 432 | context.depthWriteEnabled = true; |
430 | 433 | } else if (!state.isDepthWrite() && context.depthWriteEnabled) { |
431 | 434 | GLES20.glDepthMask(false); |
435 | + RendererUtil.checkGLError(); | |
432 | 436 | context.depthWriteEnabled = false; |
433 | 437 | } |
434 | 438 | if (state.isColorWrite() && !context.colorWriteEnabled) { |
435 | 439 | GLES20.glColorMask(true, true, true, true); |
440 | + RendererUtil.checkGLError(); | |
436 | 441 | context.colorWriteEnabled = true; |
437 | 442 | } else if (!state.isColorWrite() && context.colorWriteEnabled) { |
438 | 443 | GLES20.glColorMask(false, false, false, false); |
444 | + RendererUtil.checkGLError(); | |
439 | 445 | context.colorWriteEnabled = false; |
440 | 446 | } |
441 | 447 | // if (state.isPointSprite() && !context.pointSprite) { |
@@ -452,6 +458,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
452 | 458 | GLES20.glEnable(GLES20.GL_POLYGON_OFFSET_FILL); |
453 | 459 | GLES20.glPolygonOffset(state.getPolyOffsetFactor(), |
454 | 460 | state.getPolyOffsetUnits()); |
461 | + RendererUtil.checkGLError(); | |
462 | + | |
455 | 463 | context.polyOffsetEnabled = true; |
456 | 464 | context.polyOffsetFactor = state.getPolyOffsetFactor(); |
457 | 465 | context.polyOffsetUnits = state.getPolyOffsetUnits(); |
@@ -460,6 +468,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
460 | 468 | || state.getPolyOffsetUnits() != context.polyOffsetUnits) { |
461 | 469 | GLES20.glPolygonOffset(state.getPolyOffsetFactor(), |
462 | 470 | state.getPolyOffsetUnits()); |
471 | + RendererUtil.checkGLError(); | |
472 | + | |
463 | 473 | context.polyOffsetFactor = state.getPolyOffsetFactor(); |
464 | 474 | context.polyOffsetUnits = state.getPolyOffsetUnits(); |
465 | 475 | } |
@@ -467,6 +477,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
467 | 477 | } else { |
468 | 478 | if (context.polyOffsetEnabled) { |
469 | 479 | GLES20.glDisable(GLES20.GL_POLYGON_OFFSET_FILL); |
480 | + RendererUtil.checkGLError(); | |
481 | + | |
470 | 482 | context.polyOffsetEnabled = false; |
471 | 483 | context.polyOffsetFactor = 0; |
472 | 484 | context.polyOffsetUnits = 0; |
@@ -475,8 +487,10 @@ public class OGLESShaderRenderer implements Renderer { | ||
475 | 487 | if (state.getFaceCullMode() != context.cullMode) { |
476 | 488 | if (state.getFaceCullMode() == RenderState.FaceCullMode.Off) { |
477 | 489 | GLES20.glDisable(GLES20.GL_CULL_FACE); |
490 | + RendererUtil.checkGLError(); | |
478 | 491 | } else { |
479 | 492 | GLES20.glEnable(GLES20.GL_CULL_FACE); |
493 | + RendererUtil.checkGLError(); | |
480 | 494 | } |
481 | 495 | |
482 | 496 | switch (state.getFaceCullMode()) { |
@@ -484,12 +498,15 @@ public class OGLESShaderRenderer implements Renderer { | ||
484 | 498 | break; |
485 | 499 | case Back: |
486 | 500 | GLES20.glCullFace(GLES20.GL_BACK); |
501 | + RendererUtil.checkGLError(); | |
487 | 502 | break; |
488 | 503 | case Front: |
489 | 504 | GLES20.glCullFace(GLES20.GL_FRONT); |
505 | + RendererUtil.checkGLError(); | |
490 | 506 | break; |
491 | 507 | case FrontAndBack: |
492 | 508 | GLES20.glCullFace(GLES20.GL_FRONT_AND_BACK); |
509 | + RendererUtil.checkGLError(); | |
493 | 510 | break; |
494 | 511 | default: |
495 | 512 | throw new UnsupportedOperationException("Unrecognized face cull mode: " |
@@ -502,6 +519,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
502 | 519 | if (state.getBlendMode() != context.blendMode) { |
503 | 520 | if (state.getBlendMode() == RenderState.BlendMode.Off) { |
504 | 521 | GLES20.glDisable(GLES20.GL_BLEND); |
522 | + RendererUtil.checkGLError(); | |
505 | 523 | } else { |
506 | 524 | GLES20.glEnable(GLES20.GL_BLEND); |
507 | 525 | switch (state.getBlendMode()) { |
@@ -532,6 +550,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
532 | 550 | throw new UnsupportedOperationException("Unrecognized blend mode: " |
533 | 551 | + state.getBlendMode()); |
534 | 552 | } |
553 | + RendererUtil.checkGLError(); | |
535 | 554 | } |
536 | 555 | context.blendMode = state.getBlendMode(); |
537 | 556 | } |
@@ -543,6 +562,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
543 | 562 | public void setViewPort(int x, int y, int w, int h) { |
544 | 563 | if (x != vpX || vpY != y || vpW != w || vpH != h) { |
545 | 564 | GLES20.glViewport(x, y, w, h); |
565 | + RendererUtil.checkGLError(); | |
566 | + | |
546 | 567 | vpX = x; |
547 | 568 | vpY = y; |
548 | 569 | vpW = w; |
@@ -553,10 +574,12 @@ public class OGLESShaderRenderer implements Renderer { | ||
553 | 574 | public void setClipRect(int x, int y, int width, int height) { |
554 | 575 | if (!context.clipRectEnabled) { |
555 | 576 | GLES20.glEnable(GLES20.GL_SCISSOR_TEST); |
577 | + RendererUtil.checkGLError(); | |
556 | 578 | context.clipRectEnabled = true; |
557 | 579 | } |
558 | 580 | if (clipX != x || clipY != y || clipW != width || clipH != height) { |
559 | 581 | GLES20.glScissor(x, y, width, height); |
582 | + RendererUtil.checkGLError(); | |
560 | 583 | clipX = x; |
561 | 584 | clipY = y; |
562 | 585 | clipW = width; |
@@ -567,6 +590,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
567 | 590 | public void clearClipRect() { |
568 | 591 | if (context.clipRectEnabled) { |
569 | 592 | GLES20.glDisable(GLES20.GL_SCISSOR_TEST); |
593 | + RendererUtil.checkGLError(); | |
570 | 594 | context.clipRectEnabled = false; |
571 | 595 | |
572 | 596 | clipX = 0; |
@@ -577,10 +601,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
577 | 601 | } |
578 | 602 | |
579 | 603 | 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 | + | |
584 | 606 | objManager.deleteUnused(this); |
585 | 607 | } |
586 | 608 |
@@ -598,6 +620,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
598 | 620 | stringBuf.append(uniform.getName()).append('\0'); |
599 | 621 | updateNameBuffer(); |
600 | 622 | int loc = GLES20.glGetUniformLocation(shader.getId(), uniform.getName()); |
623 | + RendererUtil.checkGLError(); | |
624 | + | |
601 | 625 | if (loc < 0) { |
602 | 626 | uniform.setLocation(-1); |
603 | 627 | // uniform is not declared in shader |
@@ -610,6 +634,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
610 | 634 | int shaderId = shader.getId(); |
611 | 635 | if (context.boundShaderProgram != shaderId) { |
612 | 636 | GLES20.glUseProgram(shaderId); |
637 | + RendererUtil.checkGLError(); | |
638 | + | |
613 | 639 | statistics.onShaderUse(shader, true); |
614 | 640 | boundShader = shader; |
615 | 641 | context.boundShaderProgram = shaderId; |
@@ -626,6 +652,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
626 | 652 | |
627 | 653 | if (context.boundShaderProgram != shaderId) { |
628 | 654 | GLES20.glUseProgram(shaderId); |
655 | + RendererUtil.checkGLError(); | |
656 | + | |
629 | 657 | statistics.onShaderUse(shader, true); |
630 | 658 | boundShader = shader; |
631 | 659 | context.boundShaderProgram = shaderId; |
@@ -730,6 +758,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
730 | 758 | default: |
731 | 759 | throw new UnsupportedOperationException("Unsupported uniform type: " + uniform.getVarType()); |
732 | 760 | } |
761 | + RendererUtil.checkGLError(); | |
733 | 762 | } |
734 | 763 | |
735 | 764 | protected void updateShaderUniforms(Shader shader) { |
@@ -775,6 +804,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
775 | 804 | if (id == -1) { |
776 | 805 | // Create id |
777 | 806 | id = GLES20.glCreateShader(convertShaderType(source.getType())); |
807 | + RendererUtil.checkGLError(); | |
808 | + | |
778 | 809 | if (id <= 0) { |
779 | 810 | throw new RendererException("Invalid ID received when trying to create shader."); |
780 | 811 | } |
@@ -821,7 +852,10 @@ public class OGLESShaderRenderer implements Renderer { | ||
821 | 852 | // System.out.println("precision "+precision[0]); |
822 | 853 | |
823 | 854 | GLES20.glCompileShader(id); |
855 | + RendererUtil.checkGLError(); | |
856 | + | |
824 | 857 | GLES20.glGetShaderiv(id, GLES20.GL_COMPILE_STATUS, intBuf1); |
858 | + RendererUtil.checkGLError(); | |
825 | 859 | |
826 | 860 | boolean compiledOK = intBuf1.get(0) == GLES20.GL_TRUE; |
827 | 861 | String infoLog = null; |
@@ -830,7 +864,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
830 | 864 | // even if compile succeeded, check |
831 | 865 | // log for warnings |
832 | 866 | GLES20.glGetShaderiv(id, GLES20.GL_INFO_LOG_LENGTH, intBuf1); |
833 | - checkGLError(); | |
867 | + RendererUtil.checkGLError(); | |
834 | 868 | infoLog = GLES20.glGetShaderInfoLog(id); |
835 | 869 | } |
836 | 870 |
@@ -858,6 +892,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
858 | 892 | if (id == -1) { |
859 | 893 | // create program |
860 | 894 | id = GLES20.glCreateProgram(); |
895 | + RendererUtil.checkGLError(); | |
861 | 896 | |
862 | 897 | if (id <= 0) { |
863 | 898 | throw new RendererException("Invalid ID received when trying to create shader program."); |
@@ -871,23 +906,30 @@ public class OGLESShaderRenderer implements Renderer { | ||
871 | 906 | if (source.isUpdateNeeded()) { |
872 | 907 | updateShaderSourceData(source); |
873 | 908 | } |
909 | + | |
874 | 910 | GLES20.glAttachShader(id, source.getId()); |
911 | + RendererUtil.checkGLError(); | |
875 | 912 | } |
876 | 913 | |
877 | 914 | // link shaders to program |
878 | 915 | GLES20.glLinkProgram(id); |
916 | + RendererUtil.checkGLError(); | |
917 | + | |
879 | 918 | GLES20.glGetProgramiv(id, GLES20.GL_LINK_STATUS, intBuf1); |
919 | + RendererUtil.checkGLError(); | |
880 | 920 | |
881 | 921 | boolean linkOK = intBuf1.get(0) == GLES20.GL_TRUE; |
882 | 922 | String infoLog = null; |
883 | 923 | |
884 | 924 | if (VALIDATE_SHADER || !linkOK) { |
885 | 925 | GLES20.glGetProgramiv(id, GLES20.GL_INFO_LOG_LENGTH, intBuf1); |
926 | + RendererUtil.checkGLError(); | |
886 | 927 | |
887 | 928 | int length = intBuf1.get(0); |
888 | 929 | if (length > 3) { |
889 | 930 | // get infos |
890 | 931 | infoLog = GLES20.glGetProgramInfoLog(id); |
932 | + RendererUtil.checkGLError(); | |
891 | 933 | } |
892 | 934 | } |
893 | 935 |
@@ -940,7 +982,10 @@ public class OGLESShaderRenderer implements Renderer { | ||
940 | 982 | } |
941 | 983 | |
942 | 984 | source.clearUpdateNeeded(); |
985 | + | |
943 | 986 | GLES20.glDeleteShader(source.getId()); |
987 | + RendererUtil.checkGLError(); | |
988 | + | |
944 | 989 | source.resetObject(); |
945 | 990 | } |
946 | 991 |
@@ -953,11 +998,15 @@ public class OGLESShaderRenderer implements Renderer { | ||
953 | 998 | for (ShaderSource source : shader.getSources()) { |
954 | 999 | if (source.getId() != -1) { |
955 | 1000 | GLES20.glDetachShader(shader.getId(), source.getId()); |
1001 | + RendererUtil.checkGLError(); | |
1002 | + | |
956 | 1003 | deleteShaderSource(source); |
957 | 1004 | } |
958 | 1005 | } |
959 | 1006 | |
960 | 1007 | GLES20.glDeleteProgram(shader.getId()); |
1008 | + RendererUtil.checkGLError(); | |
1009 | + | |
961 | 1010 | statistics.onDeleteShader(); |
962 | 1011 | shader.resetObject(); |
963 | 1012 | } |
@@ -1161,12 +1210,16 @@ public class OGLESShaderRenderer implements Renderer { | ||
1161 | 1210 | int id = rb.getId(); |
1162 | 1211 | if (id == -1) { |
1163 | 1212 | GLES20.glGenRenderbuffers(1, intBuf1); |
1213 | + RendererUtil.checkGLError(); | |
1214 | + | |
1164 | 1215 | id = intBuf1.get(0); |
1165 | 1216 | rb.setId(id); |
1166 | 1217 | } |
1167 | 1218 | |
1168 | 1219 | if (context.boundRB != id) { |
1169 | 1220 | GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, id); |
1221 | + RendererUtil.checkGLError(); | |
1222 | + | |
1170 | 1223 | context.boundRB = id; |
1171 | 1224 | } |
1172 | 1225 |
@@ -1198,6 +1251,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1198 | 1251 | imageFormat.renderBufferStorageFormat, |
1199 | 1252 | fb.getWidth(), |
1200 | 1253 | fb.getHeight()); |
1254 | + | |
1255 | + RendererUtil.checkGLError(); | |
1201 | 1256 | } |
1202 | 1257 | } |
1203 | 1258 |
@@ -1229,6 +1284,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1229 | 1284 | convertTextureType(tex.getType()), |
1230 | 1285 | image.getId(), |
1231 | 1286 | 0); |
1287 | + | |
1288 | + RendererUtil.checkGLError(); | |
1232 | 1289 | } |
1233 | 1290 | |
1234 | 1291 | public void updateFrameBufferAttachment(FrameBuffer fb, RenderBuffer rb) { |
@@ -1246,6 +1303,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1246 | 1303 | convertAttachmentSlot(rb.getSlot()), |
1247 | 1304 | GLES20.GL_RENDERBUFFER, |
1248 | 1305 | rb.getId()); |
1306 | + | |
1307 | + RendererUtil.checkGLError(); | |
1249 | 1308 | } |
1250 | 1309 | } |
1251 | 1310 |
@@ -1255,6 +1314,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1255 | 1314 | intBuf1.clear(); |
1256 | 1315 | // create FBO |
1257 | 1316 | GLES20.glGenFramebuffers(1, intBuf1); |
1317 | + RendererUtil.checkGLError(); | |
1318 | + | |
1258 | 1319 | id = intBuf1.get(0); |
1259 | 1320 | fb.setId(id); |
1260 | 1321 | objManager.registerForCleanup(fb); |
@@ -1264,6 +1325,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1264 | 1325 | |
1265 | 1326 | if (context.boundFBO != id) { |
1266 | 1327 | GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, id); |
1328 | + RendererUtil.checkGLError(); | |
1329 | + | |
1267 | 1330 | // binding an FBO automatically sets draw buf to GL_COLOR_ATTACHMENT0 |
1268 | 1331 | context.boundDrawBuf = 0; |
1269 | 1332 | context.boundFBO = id; |
@@ -1309,6 +1372,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
1309 | 1372 | // int textureType = convertTextureType(tex.getType(), tex.getImage().getMultiSamples(), rb.getFace()); |
1310 | 1373 | int textureType = convertTextureType(tex.getType()); |
1311 | 1374 | GLES20.glGenerateMipmap(textureType); |
1375 | + RendererUtil.checkGLError(); | |
1312 | 1376 | } |
1313 | 1377 | } |
1314 | 1378 | } |
@@ -1317,6 +1381,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1317 | 1381 | // unbind any fbos |
1318 | 1382 | if (context.boundFBO != 0) { |
1319 | 1383 | GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); |
1384 | + RendererUtil.checkGLError(); | |
1385 | + | |
1320 | 1386 | statistics.onFrameBufferUse(null, true); |
1321 | 1387 | |
1322 | 1388 | context.boundFBO = 0; |
@@ -1347,6 +1413,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1347 | 1413 | |
1348 | 1414 | if (context.boundFBO != fb.getId()) { |
1349 | 1415 | GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fb.getId()); |
1416 | + RendererUtil.checkGLError(); | |
1417 | + | |
1350 | 1418 | statistics.onFrameBufferUse(fb, true); |
1351 | 1419 | |
1352 | 1420 | // update viewport to reflect framebuffer's resolution |
@@ -1395,6 +1463,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1395 | 1463 | // select this draw buffer |
1396 | 1464 | if (context.boundDrawBuf != rb.getSlot()) { |
1397 | 1465 | GLES20.glActiveTexture(convertAttachmentSlot(rb.getSlot())); |
1466 | + RendererUtil.checkGLError(); | |
1467 | + | |
1398 | 1468 | context.boundDrawBuf = rb.getSlot(); |
1399 | 1469 | } |
1400 | 1470 | } |
@@ -1427,6 +1497,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1427 | 1497 | setFrameBuffer(fb); |
1428 | 1498 | if (context.boundReadBuf != rb.getSlot()) { |
1429 | 1499 | GLES20.glActiveTexture(convertAttachmentSlot(rb.getSlot())); |
1500 | + RendererUtil.checkGLError(); | |
1501 | + | |
1430 | 1502 | context.boundReadBuf = rb.getSlot(); |
1431 | 1503 | } |
1432 | 1504 | } else { |
@@ -1434,17 +1506,21 @@ public class OGLESShaderRenderer implements Renderer { | ||
1434 | 1506 | } |
1435 | 1507 | |
1436 | 1508 | GLES20.glReadPixels(vpX, vpY, vpW, vpH, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, byteBuf); |
1509 | + RendererUtil.checkGLError(); | |
1437 | 1510 | } |
1438 | 1511 | |
1439 | 1512 | private void deleteRenderBuffer(FrameBuffer fb, RenderBuffer rb) { |
1440 | 1513 | intBuf1.put(0, rb.getId()); |
1441 | 1514 | GLES20.glDeleteRenderbuffers(1, intBuf1); |
1515 | + RendererUtil.checkGLError(); | |
1442 | 1516 | } |
1443 | 1517 | |
1444 | 1518 | public void deleteFrameBuffer(FrameBuffer fb) { |
1445 | 1519 | if (fb.getId() != -1) { |
1446 | 1520 | if (context.boundFBO == fb.getId()) { |
1447 | 1521 | GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); |
1522 | + RendererUtil.checkGLError(); | |
1523 | + | |
1448 | 1524 | context.boundFBO = 0; |
1449 | 1525 | } |
1450 | 1526 |
@@ -1457,6 +1533,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1457 | 1533 | |
1458 | 1534 | intBuf1.put(0, fb.getId()); |
1459 | 1535 | GLES20.glDeleteFramebuffers(1, intBuf1); |
1536 | + RendererUtil.checkGLError(); | |
1537 | + | |
1460 | 1538 | fb.resetObject(); |
1461 | 1539 | |
1462 | 1540 | statistics.onDeleteFrameBuffer(); |
@@ -1539,6 +1617,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
1539 | 1617 | |
1540 | 1618 | GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_MIN_FILTER, minFilter); |
1541 | 1619 | GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_MAG_FILTER, magFilter); |
1620 | + RendererUtil.checkGLError(); | |
1542 | 1621 | |
1543 | 1622 | /* |
1544 | 1623 | if (tex.getAnisotropicFilter() > 1){ |
@@ -1565,6 +1644,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1565 | 1644 | // fall down here is intentional.. |
1566 | 1645 | // case OneDimensional: |
1567 | 1646 | GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S))); |
1647 | + | |
1648 | + RendererUtil.checkGLError(); | |
1568 | 1649 | break; |
1569 | 1650 | default: |
1570 | 1651 | throw new UnsupportedOperationException("Unknown texture type: " + tex.getType()); |
@@ -1594,6 +1675,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1594 | 1675 | if (texId == -1) { |
1595 | 1676 | // create texture |
1596 | 1677 | GLES20.glGenTextures(1, intBuf1); |
1678 | + RendererUtil.checkGLError(); | |
1679 | + | |
1597 | 1680 | texId = intBuf1.get(0); |
1598 | 1681 | img.setId(texId); |
1599 | 1682 | objManager.registerForCleanup(img); |
@@ -1606,10 +1689,14 @@ public class OGLESShaderRenderer implements Renderer { | ||
1606 | 1689 | if (context.boundTextures[0] != img) { |
1607 | 1690 | if (context.boundTextureUnit != 0) { |
1608 | 1691 | GLES20.glActiveTexture(GLES20.GL_TEXTURE0); |
1692 | + RendererUtil.checkGLError(); | |
1693 | + | |
1609 | 1694 | context.boundTextureUnit = 0; |
1610 | 1695 | } |
1611 | 1696 | |
1612 | 1697 | GLES20.glBindTexture(target, texId); |
1698 | + RendererUtil.checkGLError(); | |
1699 | + | |
1613 | 1700 | context.boundTextures[0] = img; |
1614 | 1701 | } |
1615 | 1702 |
@@ -1697,6 +1784,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1697 | 1784 | } |
1698 | 1785 | |
1699 | 1786 | GLES20.glBindTexture(type, texId); |
1787 | + RendererUtil.checkGLError(); | |
1788 | + | |
1700 | 1789 | textures[unit] = image; |
1701 | 1790 | |
1702 | 1791 | statistics.onTextureUse(tex.getImage(), true); |
@@ -1734,6 +1823,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1734 | 1823 | intBuf1.position(0).limit(1); |
1735 | 1824 | |
1736 | 1825 | GLES20.glDeleteTextures(1, intBuf1); |
1826 | + RendererUtil.checkGLError(); | |
1827 | + | |
1737 | 1828 | image.resetObject(); |
1738 | 1829 | |
1739 | 1830 | statistics.onDeleteTexture(); |
@@ -1791,6 +1882,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1791 | 1882 | if (bufId == -1) { |
1792 | 1883 | // create buffer |
1793 | 1884 | GLES20.glGenBuffers(1, intBuf1); |
1885 | + RendererUtil.checkGLError(); | |
1886 | + | |
1794 | 1887 | bufId = intBuf1.get(0); |
1795 | 1888 | vb.setId(bufId); |
1796 | 1889 | objManager.registerForCleanup(vb); |
@@ -1804,12 +1897,16 @@ public class OGLESShaderRenderer implements Renderer { | ||
1804 | 1897 | target = GLES20.GL_ELEMENT_ARRAY_BUFFER; |
1805 | 1898 | if (context.boundElementArrayVBO != bufId) { |
1806 | 1899 | GLES20.glBindBuffer(target, bufId); |
1900 | + RendererUtil.checkGLError(); | |
1901 | + | |
1807 | 1902 | context.boundElementArrayVBO = bufId; |
1808 | 1903 | } |
1809 | 1904 | } else { |
1810 | 1905 | target = GLES20.GL_ARRAY_BUFFER; |
1811 | 1906 | if (context.boundArrayVBO != bufId) { |
1812 | 1907 | GLES20.glBindBuffer(target, bufId); |
1908 | + RendererUtil.checkGLError(); | |
1909 | + | |
1813 | 1910 | context.boundArrayVBO = bufId; |
1814 | 1911 | } |
1815 | 1912 | } |
@@ -1825,21 +1922,21 @@ public class OGLESShaderRenderer implements Renderer { | ||
1825 | 1922 | case Byte: |
1826 | 1923 | case UnsignedByte: |
1827 | 1924 | GLES20.glBufferData(target, size, (ByteBuffer) vb.getData(), usage); |
1925 | + RendererUtil.checkGLError(); | |
1828 | 1926 | break; |
1829 | - //case Half: | |
1830 | 1927 | case Short: |
1831 | 1928 | case UnsignedShort: |
1832 | 1929 | GLES20.glBufferData(target, size, (ShortBuffer) vb.getData(), usage); |
1930 | + RendererUtil.checkGLError(); | |
1833 | 1931 | break; |
1834 | 1932 | case Int: |
1835 | 1933 | case UnsignedInt: |
1836 | 1934 | GLES20.glBufferData(target, size, (IntBuffer) vb.getData(), usage); |
1935 | + RendererUtil.checkGLError(); | |
1837 | 1936 | break; |
1838 | 1937 | case Float: |
1839 | 1938 | 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(); | |
1843 | 1940 | break; |
1844 | 1941 | default: |
1845 | 1942 | throw new RuntimeException("Unknown buffer format."); |
@@ -1851,20 +1948,21 @@ public class OGLESShaderRenderer implements Renderer { | ||
1851 | 1948 | case Byte: |
1852 | 1949 | case UnsignedByte: |
1853 | 1950 | GLES20.glBufferSubData(target, 0, size, (ByteBuffer) vb.getData()); |
1951 | + RendererUtil.checkGLError(); | |
1854 | 1952 | break; |
1855 | 1953 | case Short: |
1856 | 1954 | case UnsignedShort: |
1857 | 1955 | GLES20.glBufferSubData(target, 0, size, (ShortBuffer) vb.getData()); |
1956 | + RendererUtil.checkGLError(); | |
1858 | 1957 | break; |
1859 | 1958 | case Int: |
1860 | 1959 | case UnsignedInt: |
1861 | 1960 | GLES20.glBufferSubData(target, 0, size, (IntBuffer) vb.getData()); |
1961 | + RendererUtil.checkGLError(); | |
1862 | 1962 | break; |
1863 | 1963 | case Float: |
1864 | 1964 | 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(); | |
1868 | 1966 | break; |
1869 | 1967 | default: |
1870 | 1968 | throw new RuntimeException("Unknown buffer format."); |
@@ -1881,6 +1979,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1881 | 1979 | intBuf1.position(0).limit(1); |
1882 | 1980 | |
1883 | 1981 | GLES20.glDeleteBuffers(1, intBuf1); |
1982 | + RendererUtil.checkGLError(); | |
1983 | + | |
1884 | 1984 | vb.resetObject(); |
1885 | 1985 | } |
1886 | 1986 | } |
@@ -1891,6 +1991,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1891 | 1991 | int idx = attribList.oldList[i]; |
1892 | 1992 | |
1893 | 1993 | GLES20.glDisableVertexAttribArray(idx); |
1994 | + RendererUtil.checkGLError(); | |
1995 | + | |
1894 | 1996 | context.boundAttribs[idx] = null; |
1895 | 1997 | } |
1896 | 1998 | context.attribIndexList.copyNewToOld(); |
@@ -1920,6 +2022,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
1920 | 2022 | |
1921 | 2023 | String attributeName = "in" + vb.getBufferType().name(); |
1922 | 2024 | loc = GLES20.glGetAttribLocation(programId, attributeName); |
2025 | + RendererUtil.checkGLError(); | |
1923 | 2026 | |
1924 | 2027 | // not really the name of it in the shader (inPosition\0) but |
1925 | 2028 | // the internal name of the enum (Position). |
@@ -1934,6 +2037,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
1934 | 2037 | VertexBuffer[] attribs = context.boundAttribs; |
1935 | 2038 | if (!context.attribIndexList.moveToNew(loc)) { |
1936 | 2039 | GLES20.glEnableVertexAttribArray(loc); |
2040 | + RendererUtil.checkGLError(); | |
1937 | 2041 | //System.out.println("Enabled ATTRIB IDX: "+loc); |
1938 | 2042 | } |
1939 | 2043 | if (attribs[loc] != vb) { |
@@ -1946,8 +2050,9 @@ public class OGLESShaderRenderer implements Renderer { | ||
1946 | 2050 | } |
1947 | 2051 | |
1948 | 2052 | if (context.boundArrayVBO != bufId) { |
1949 | - | |
1950 | 2053 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufId); |
2054 | + RendererUtil.checkGLError(); | |
2055 | + | |
1951 | 2056 | context.boundArrayVBO = bufId; |
1952 | 2057 | } |
1953 | 2058 |
@@ -1959,6 +2064,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
1959 | 2064 | vb.isNormalized(), |
1960 | 2065 | vb.getStride(), |
1961 | 2066 | 0); |
2067 | + | |
2068 | + RendererUtil.checkGLError(); | |
1962 | 2069 | |
1963 | 2070 | attribs[loc] = vb; |
1964 | 2071 | } |
@@ -1977,6 +2084,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
1977 | 2084 | vertCount, count); |
1978 | 2085 | }else{*/ |
1979 | 2086 | GLES20.glDrawArrays(convertElementMode(mode), 0, vertCount); |
2087 | + RendererUtil.checkGLError(); | |
1980 | 2088 | /* |
1981 | 2089 | }*/ |
1982 | 2090 | } |
@@ -1994,11 +2102,13 @@ public class OGLESShaderRenderer implements Renderer { | ||
1994 | 2102 | assert bufId != -1; |
1995 | 2103 | |
1996 | 2104 | if (bufId == -1) { |
1997 | - logger.warning("invalid buffer id!"); | |
2105 | + throw new RendererException("Invalid buffer ID"); | |
1998 | 2106 | } |
1999 | 2107 | |
2000 | 2108 | if (context.boundElementArrayVBO != bufId) { |
2001 | 2109 | GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, bufId); |
2110 | + RendererUtil.checkGLError(); | |
2111 | + | |
2002 | 2112 | context.boundElementArrayVBO = bufId; |
2003 | 2113 | } |
2004 | 2114 |
@@ -2044,6 +2154,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
2044 | 2154 | } else { |
2045 | 2155 | indexBuf.getData().position(curOffset); |
2046 | 2156 | GLES20.glDrawElements(elMode, elementLength, fmt, indexBuf.getData()); |
2157 | + RendererUtil.checkGLError(); | |
2047 | 2158 | /* |
2048 | 2159 | glDrawRangeElements(elMode, |
2049 | 2160 | 0, |
@@ -2074,6 +2185,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
2074 | 2185 | indexBuf.getData().limit(), |
2075 | 2186 | convertVertexBufferFormat(indexBuf.getFormat()), |
2076 | 2187 | 0); |
2188 | + RendererUtil.checkGLError(); | |
2077 | 2189 | } |
2078 | 2190 | } |
2079 | 2191 | } |
@@ -2180,6 +2292,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
2180 | 2292 | drawTriangleList_Array(indices, mesh, count); |
2181 | 2293 | } else { |
2182 | 2294 | GLES20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); |
2295 | + RendererUtil.checkGLError(); | |
2183 | 2296 | } |
2184 | 2297 | clearVertexAttribs(); |
2185 | 2298 | clearTextureUnits(); |
@@ -2219,18 +2332,23 @@ public class OGLESShaderRenderer implements Renderer { | ||
2219 | 2332 | } else { |
2220 | 2333 | // throw new UnsupportedOperationException("Cannot render without index buffer"); |
2221 | 2334 | GLES20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); |
2335 | + RendererUtil.checkGLError(); | |
2222 | 2336 | } |
2223 | 2337 | clearVertexAttribs(); |
2224 | 2338 | clearTextureUnits(); |
2225 | 2339 | } |
2226 | 2340 | |
2227 | 2341 | public void renderMesh(Mesh mesh, int lod, int count) { |
2342 | + /* | |
2343 | + * NOTE: not supported in OpenGL ES 2.0. | |
2228 | 2344 | if (context.pointSize != mesh.getPointSize()) { |
2229 | 2345 | GLES10.glPointSize(mesh.getPointSize()); |
2230 | 2346 | context.pointSize = mesh.getPointSize(); |
2231 | 2347 | } |
2348 | + */ | |
2232 | 2349 | if (context.lineWidth != mesh.getLineWidth()) { |
2233 | 2350 | GLES20.glLineWidth(mesh.getLineWidth()); |
2351 | + RendererUtil.checkGLError(); | |
2234 | 2352 | context.lineWidth = mesh.getLineWidth(); |
2235 | 2353 | } |
2236 | 2354 |
@@ -2281,12 +2399,13 @@ public class OGLESShaderRenderer implements Renderer { | ||
2281 | 2399 | if (i == stripStart) { |
2282 | 2400 | elMode = convertElementMode(Mode.TriangleStrip); |
2283 | 2401 | } else if (i == fanStart) { |
2284 | - elMode = convertElementMode(Mode.TriangleStrip); | |
2402 | + elMode = convertElementMode(Mode.TriangleFan); | |
2285 | 2403 | } |
2286 | 2404 | int elementLength = elementLengths[i]; |
2287 | 2405 | |
2288 | 2406 | indexBuf.getData().position(curOffset); |
2289 | 2407 | GLES20.glDrawElements(elMode, elementLength, fmt, indexBuf.getData()); |
2408 | + RendererUtil.checkGLError(); | |
2290 | 2409 | |
2291 | 2410 | curOffset += elementLength * elSize; |
2292 | 2411 | } |
@@ -2296,6 +2415,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
2296 | 2415 | indexBuf.getData().limit(), |
2297 | 2416 | convertVertexBufferFormat(indexBuf.getFormat()), |
2298 | 2417 | indexBuf.getData()); |
2418 | + RendererUtil.checkGLError(); | |
2299 | 2419 | } |
2300 | 2420 | } |
2301 | 2421 |
@@ -2323,6 +2443,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
2323 | 2443 | String attributeName = "in" + vb.getBufferType().name(); |
2324 | 2444 | |
2325 | 2445 | loc = GLES20.glGetAttribLocation(programId, attributeName); |
2446 | + RendererUtil.checkGLError(); | |
2447 | + | |
2326 | 2448 | if (loc < 0) { |
2327 | 2449 | attrib.setLocation(-1); |
2328 | 2450 | return; // not available in shader. |
@@ -2345,8 +2467,11 @@ public class OGLESShaderRenderer implements Renderer { | ||
2345 | 2467 | vb.isNormalized(), |
2346 | 2468 | vb.getStride(), |
2347 | 2469 | avb.getData()); |
2470 | + | |
2471 | + RendererUtil.checkGLError(); | |
2348 | 2472 | |
2349 | 2473 | GLES20.glEnableVertexAttribArray(loc); |
2474 | + RendererUtil.checkGLError(); | |
2350 | 2475 | |
2351 | 2476 | attribs[loc] = vb; |
2352 | 2477 | } // if (attribs[loc] != vb) |
@@ -2366,8 +2491,10 @@ public class OGLESShaderRenderer implements Renderer { | ||
2366 | 2491 | public void setAlphaToCoverage(boolean value) { |
2367 | 2492 | if (value) { |
2368 | 2493 | GLES20.glEnable(GLES20.GL_SAMPLE_ALPHA_TO_COVERAGE); |
2494 | + RendererUtil.checkGLError(); | |
2369 | 2495 | } else { |
2370 | 2496 | GLES20.glDisable(GLES20.GL_SAMPLE_ALPHA_TO_COVERAGE); |
2497 | + RendererUtil.checkGLError(); | |
2371 | 2498 | } |
2372 | 2499 | } |
2373 | 2500 |
@@ -2375,6 +2502,6 @@ public class OGLESShaderRenderer implements Renderer { | ||
2375 | 2502 | public void invalidateState() { |
2376 | 2503 | context.reset(); |
2377 | 2504 | boundShader = null; |
2378 | -// lastFb = null; | |
2505 | + lastFb = null; | |
2379 | 2506 | } |
2380 | 2507 | } |
@@ -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 | +} |
@@ -103,10 +103,10 @@ public class TextureUtil { | ||
103 | 103 | logger.log(Level.FINEST, " - Uploading bitmap directly. Cannot compress as alpha present."); |
104 | 104 | if (subTexture) { |
105 | 105 | GLUtils.texSubImage2D(target, level, x, y, bitmap); |
106 | - checkGLError(); | |
106 | + RendererUtil.checkGLError(); | |
107 | 107 | } else { |
108 | 108 | GLUtils.texImage2D(target, level, bitmap, 0); |
109 | - checkGLError(); | |
109 | + RendererUtil.checkGLError(); | |
110 | 110 | } |
111 | 111 | } else { |
112 | 112 | // Convert to RGB565 |
@@ -150,7 +150,8 @@ public class TextureUtil { | ||
150 | 150 | ETC1.ETC1_RGB8_OES, |
151 | 151 | etc1tex.getData().capacity(), |
152 | 152 | etc1tex.getData()); |
153 | - checkGLError(); | |
153 | + | |
154 | + RendererUtil.checkGLError(); | |
154 | 155 | } else { |
155 | 156 | GLES20.glCompressedTexImage2D(target, |
156 | 157 | level, |
@@ -160,7 +161,8 @@ public class TextureUtil { | ||
160 | 161 | 0, |
161 | 162 | etc1tex.getData().capacity(), |
162 | 163 | etc1tex.getData()); |
163 | - checkGLError(); | |
164 | + | |
165 | + RendererUtil.checkGLError(); | |
164 | 166 | } |
165 | 167 | |
166 | 168 | // ETC1Util.loadTexture(target, level, 0, GLES20.GL_RGB, |
@@ -208,17 +210,17 @@ public class TextureUtil { | ||
208 | 210 | if (subTexture) { |
209 | 211 | System.err.println("x : " + x + " y :" + y + " , " + bitmap.getWidth() + "/" + bitmap.getHeight()); |
210 | 212 | GLUtils.texSubImage2D(target, 0, x, y, bitmap); |
211 | - checkGLError(); | |
213 | + RendererUtil.checkGLError(); | |
212 | 214 | } else { |
213 | 215 | GLUtils.texImage2D(target, 0, bitmap, 0); |
214 | - checkGLError(); | |
216 | + RendererUtil.checkGLError(); | |
215 | 217 | } |
216 | 218 | |
217 | 219 | if (needMips) { |
218 | 220 | // No pregenerated mips available, |
219 | 221 | // generate from base level if required |
220 | 222 | GLES20.glGenerateMipmap(target); |
221 | - checkGLError(); | |
223 | + RendererUtil.checkGLError(); | |
222 | 224 | } |
223 | 225 | } |
224 | 226 | } |
@@ -485,13 +487,6 @@ public class TextureUtil { | ||
485 | 487 | } |
486 | 488 | } |
487 | 489 | |
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 | - | |
495 | 490 | /** |
496 | 491 | * Update the texture currently bound to target at with data from the given |
497 | 492 | * Image at position x and y. The parameter index is used as the zoffset in |
@@ -564,10 +559,10 @@ public class TextureUtil { | ||
564 | 559 | |
565 | 560 | if (imageFormat.compress && data != null) { |
566 | 561 | GLES20.glCompressedTexSubImage2D(target, i, x, y, mipWidth, mipHeight, imageFormat.format, data.remaining(), data); |
567 | - checkGLError(); | |
562 | + RendererUtil.checkGLError(); | |
568 | 563 | } else { |
569 | 564 | GLES20.glTexSubImage2D(target, i, x, y, mipWidth, mipHeight, imageFormat.format, imageFormat.dataType, data); |
570 | - checkGLError(); | |
565 | + RendererUtil.checkGLError(); | |
571 | 566 | } |
572 | 567 | |
573 | 568 | pos += mipSizes[i]; |
@@ -2256,7 +2256,7 @@ public class LwjglRenderer implements Renderer { | ||
2256 | 2256 | if (i == stripStart) { |
2257 | 2257 | elMode = convertElementMode(Mode.TriangleStrip); |
2258 | 2258 | } else if (i == fanStart) { |
2259 | - elMode = convertElementMode(Mode.TriangleStrip); | |
2259 | + elMode = convertElementMode(Mode.TriangleFan); | |
2260 | 2260 | } |
2261 | 2261 | int elementLength = elementLengths[i]; |
2262 | 2262 |
@@ -75,12 +75,12 @@ public class TestCustomMesh extends SimpleApplication { | ||
75 | 75 | texCoord[3] = new Vector2f(1,1); |
76 | 76 | |
77 | 77 | // 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}; | |
79 | 79 | |
80 | 80 | // Setting buffers |
81 | 81 | m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices)); |
82 | 82 | 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)); | |
84 | 84 | m.updateBound(); |
85 | 85 | |
86 | 86 | // ************************************************************************* |