From 7f16ec21711fdb97930166175c29d8235f75202e Mon Sep 17 00:00:00 2001 From: Pablo Ceballos Date: Thu, 28 Jan 2016 20:04:23 -0800 Subject: [PATCH] Implement glCreateShaderProgramv JNI Bug 26851015 Change-Id: Ibfa3bdee929a16389925ce2576715a87253718fe --- core/jni/android_opengl_GLES31.cpp | 64 +++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/core/jni/android_opengl_GLES31.cpp b/core/jni/android_opengl_GLES31.cpp index 5751add0bdead..156e7bdda5f22 100644 --- a/core/jni/android_opengl_GLES31.cpp +++ b/core/jni/android_opengl_GLES31.cpp @@ -888,9 +888,69 @@ android_glActiveShaderProgram__II static jint android_glCreateShaderProgramv (JNIEnv *_env, jobject _this, jint type, jobjectArray strings) { + jint _exception = 0; + const char * _exceptionType = NULL; + const char * _exceptionMessage = NULL; + GLsizei _count; + const GLchar** _strings = NULL; + jstring* _jstrings = NULL; + GLuint _returnValue = 0; - jniThrowException(_env, "java/lang/UnsupportedOperationException", "not yet implemented"); - return 0; + if (!strings) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "strings == null"; + goto exit; + } + + _count = _env->GetArrayLength(strings); + + _strings = (const GLchar**) calloc(_count, sizeof(const GLchar*)); + if (!_strings) { + _exception = 1; + _exceptionType = "java/lang/OutOfMemoryError"; + _exceptionMessage = "out of memory"; + goto exit; + } + + _jstrings = (jstring*) calloc(_count, sizeof(jstring)); + if (!_jstrings) { + _exception = 1; + _exceptionType = "java/lang/OutOfMemoryError"; + _exceptionMessage = "out of memory"; + goto exit; + } + + for(int i = 0; i < _count; i++) { + _jstrings[i] = (jstring) _env->GetObjectArrayElement(strings, i); + if (!_jstrings[i]) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "strings == null"; + goto exit; + } + _strings[i] = _env->GetStringUTFChars(_jstrings[i], 0); + } + + _returnValue = glCreateShaderProgramv((GLenum)type, _count, _strings); +exit: + if (_strings && _jstrings) { + for(int i = 0; i < _count; i++) { + if (_strings[i] && _jstrings[i]) { + _env->ReleaseStringUTFChars(_jstrings[i], _strings[i]); + } + } + } + if (_strings) { + free(_strings); + } + if (_jstrings) { + free(_jstrings); + } + if (_exception) { + jniThrowException(_env, _exceptionType, _exceptionMessage); + } + return (jint)_returnValue; } /* void glBindProgramPipeline ( GLuint pipeline ) */ static void