556 ctxInfo->glAttachShader(shaderProgram, vertID); 557 for (i = 0; i < length; i++) { 558 ctxInfo->glAttachShader(shaderProgram, fragIDs[i]); 559 } 560 561 // bind any user-defined index values to their corresponding names 562 indexsPtr = (*env)->GetIntArrayElements(env, indexs, NULL); 563 for (i = 0; i < numAttrs; i++) { 564 attrName = (*env)->GetObjectArrayElement(env, attrs, i); 565 attrNameString = strJavaToC(env, attrName); 566 ctxInfo->glBindAttribLocation(shaderProgram, indexsPtr[i], attrNameString); 567 free(attrNameString); 568 } 569 570 // link the program 571 ctxInfo->glLinkProgram(shaderProgram); 572 ctxInfo->glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); 573 574 if (success == GL_FALSE) { 575 GLint length; 576 ctxInfo->glGetShaderiv(shaderProgram, GL_INFO_LOG_LENGTH , &length ); 577 if (length) { 578 char* msg = (char *) malloc((length * sizeof(char)) + 1); 579 ctxInfo->glGetShaderInfoLog ( shaderProgram , length , NULL , msg ); 580 printf("Shader validation log: %s\n",msg); 581 free(msg); 582 } 583 } 584 585 if (success == GL_FALSE) { 586 valid = JNI_FALSE; 587 } else { 588 ctxInfo->glValidateProgram(shaderProgram); 589 ctxInfo->glGetProgramiv(shaderProgram, GL_VALIDATE_STATUS, &status); 590 if (status == GL_FALSE) { 591 valid = JNI_FALSE; 592 fprintf(stderr, "Program validation failed"); 593 594 if (success == GL_FALSE) { 595 GLint length; 596 ctxInfo->glGetShaderiv(shaderProgram, GL_INFO_LOG_LENGTH , &length ); 597 if (length) { 598 char* msg = (char *) malloc((length * sizeof(char)) + 1); 599 ctxInfo->glGetShaderInfoLog ( shaderProgram , length , NULL , msg ); 600 fprintf(stderr, "Shader validation log: %s\n", msg); 601 fflush(stderr); 602 free(msg); 603 } 604 } 605 } else { 606 valid = JNI_TRUE; 607 } 608 } 609 #ifdef ANDROID_NDK 610 valid = JNI_TRUE; 611 #endif 612 if (!valid) { 613 ctxInfo->glDetachShader(shaderProgram, vertID); 614 ctxInfo->glDeleteShader(vertID); 615 for(i = 0; i < length; i++) { 616 ctxInfo->glDetachShader(shaderProgram, fragIDs[i]); 617 ctxInfo->glDeleteShader(fragIDs[i]); 618 } 619 ctxInfo->glDeleteProgram(shaderProgram); 620 return 0; 621 } 622 623 (*env)->ReleaseIntArrayElements(env, fragIDArr, fragIDs, JNI_ABORT); 624 | 556 ctxInfo->glAttachShader(shaderProgram, vertID); 557 for (i = 0; i < length; i++) { 558 ctxInfo->glAttachShader(shaderProgram, fragIDs[i]); 559 } 560 561 // bind any user-defined index values to their corresponding names 562 indexsPtr = (*env)->GetIntArrayElements(env, indexs, NULL); 563 for (i = 0; i < numAttrs; i++) { 564 attrName = (*env)->GetObjectArrayElement(env, attrs, i); 565 attrNameString = strJavaToC(env, attrName); 566 ctxInfo->glBindAttribLocation(shaderProgram, indexsPtr[i], attrNameString); 567 free(attrNameString); 568 } 569 570 // link the program 571 ctxInfo->glLinkProgram(shaderProgram); 572 ctxInfo->glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); 573 574 if (success == GL_FALSE) { 575 GLint length; 576 577 valid = JNI_FALSE; 578 ctxInfo->glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH , &length ); 579 if (length) { 580 char* msg = (char *) malloc((length * sizeof(char))); 581 ctxInfo->glGetProgramInfoLog ( shaderProgram , length , NULL , msg ); 582 printf("Program link log: %s\n",msg); 583 free(msg); 584 } 585 } else { 586 ctxInfo->glValidateProgram(shaderProgram); 587 ctxInfo->glGetProgramiv(shaderProgram, GL_VALIDATE_STATUS, &status); 588 if (status == GL_FALSE) { 589 GLint length; 590 valid = JNI_FALSE; 591 fprintf(stderr, "Program validation failed\n"); 592 ctxInfo->glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH , &length ); 593 if (length) { 594 char* msg = (char *) malloc((length * sizeof(char))); 595 ctxInfo->glGetProgramInfoLog ( shaderProgram , length , NULL , msg ); 596 fprintf(stderr, "Program validation log: %s\n", msg); 597 fflush(stderr); 598 free(msg); 599 } 600 } else { 601 valid = JNI_TRUE; 602 } 603 } 604 #ifdef ANDROID_NDK 605 valid = JNI_TRUE; 606 #endif 607 if (!valid) { 608 ctxInfo->glDetachShader(shaderProgram, vertID); 609 ctxInfo->glDeleteShader(vertID); 610 for(i = 0; i < length; i++) { 611 ctxInfo->glDetachShader(shaderProgram, fragIDs[i]); 612 ctxInfo->glDeleteShader(fragIDs[i]); 613 } 614 ctxInfo->glDeleteProgram(shaderProgram); 615 return 0; 616 } 617 618 (*env)->ReleaseIntArrayElements(env, fragIDArr, fragIDs, JNI_ABORT); 619 |