From 23fea91e840960e666f00521b7ed77f847953d8a Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Thu, 8 Oct 2015 12:21:05 +0300 Subject: [PATCH] minor fixes --- modules/java/CMakeLists.txt | 21 +++++++------- .../java/android+CameraGLRendererBase.java | 28 +++++++++++++++---- .../tutorial-4-opencl/jni/CLprocessor.cpp | 14 +++------- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/modules/java/CMakeLists.txt b/modules/java/CMakeLists.txt index 3906040dfe..1a1512d361 100644 --- a/modules/java/CMakeLists.txt +++ b/modules/java/CMakeLists.txt @@ -179,19 +179,18 @@ if(NOT ANDROID) else() file(GLOB_RECURSE handwrittren_lib_project_files_rel RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/" "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/*") list(REMOVE_ITEM handwrittren_lib_project_files_rel "${ANDROID_MANIFEST_FILE}") + + # calc default SDK Target + android_get_compatible_target(android_sdk_target ${ANDROID_NATIVE_API_LEVEL} ${ANDROID_SDK_TARGET} 11) + string(REGEX REPLACE "android-" "" android_sdk_target_num ${android_sdk_target}) + # filter out + if( (ANDROID_SDK_TARGET AND ANDROID_SDK_TARGET LESS 21) OR (android_sdk_target_num LESS 21) ) + message(STATUS "[OpenCV for Android SDK]: A new OpenGL Camera Bridge (CameraGLSurfaceView, CameraGLRendererBase, CameraRenderer, Camera2Renderer) is disabled, because ANDROID_SDK_TARGET (${android_sdk_target_num}) < 21") + ocv_list_filterout(handwritten_java_sources "android\\\\+CameraGL") + ocv_list_filterout(handwritten_java_sources "android\\\\+Camera.?Renderer") + endif() endif() -# Calc default SDK Target -android_get_compatible_target(android_sdk_target ${ANDROID_NATIVE_API_LEVEL} ${ANDROID_SDK_TARGET} 11) -string(REGEX REPLACE "android-" "" android_sdk_target_num ${android_sdk_target}) - -if( (ANDROID_SDK_TARGET AND ANDROID_SDK_TARGET LESS 21) OR (android_sdk_target_num LESS 21) ) - message(STATUS "[OpenCV for Android SDK]: A new OpenGL Camera Bridge (CameraGLSurfaceView, CameraGLRendererBase, CameraRenderer, Camera2Renderer) is disabled, because ANDROID_SDK_TARGET (${android_sdk_target_num}) < 21") - ocv_list_filterout(handwritten_java_sources "android\\\\+CameraGL") - ocv_list_filterout(handwritten_java_sources "android\\\\+Camera.?Renderer") -endif() - - # IMPORTANT: add dependencies to cmake (we should rerun cmake if any of these files is modified) add_cmake_dependencies(${scripts_gen_java} ${scripts_hdr_parser} ${opencv_public_headers}) diff --git a/modules/java/generator/src/java/android+CameraGLRendererBase.java b/modules/java/generator/src/java/android+CameraGLRendererBase.java index 3971d0cb42..60c37c304e 100644 --- a/modules/java/generator/src/java/android+CameraGLRendererBase.java +++ b/modules/java/generator/src/java/android+CameraGLRendererBase.java @@ -219,9 +219,9 @@ public abstract class CameraGLRendererBase implements GLSurfaceView.Renderer, Su int vshader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER); GLES20.glShaderSource(vshader, vss); GLES20.glCompileShader(vshader); - int[] compiled = new int[1]; - GLES20.glGetShaderiv(vshader, GLES20.GL_COMPILE_STATUS, compiled, 0); - if (compiled[0] == 0) { + int[] status = new int[1]; + GLES20.glGetShaderiv(vshader, GLES20.GL_COMPILE_STATUS, status, 0); + if (status[0] == 0) { Log.e("CameraGLRendererBase", "Could not compile vertex shader: "+GLES20.glGetShaderInfoLog(vshader)); GLES20.glDeleteShader(vshader); vshader = 0; @@ -231,8 +231,8 @@ public abstract class CameraGLRendererBase implements GLSurfaceView.Renderer, Su int fshader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER); GLES20.glShaderSource(fshader, fss); GLES20.glCompileShader(fshader); - GLES20.glGetShaderiv(fshader, GLES20.GL_COMPILE_STATUS, compiled, 0); - if (compiled[0] == 0) { + GLES20.glGetShaderiv(fshader, GLES20.GL_COMPILE_STATUS, status, 0); + if (status[0] == 0) { Log.e("CameraGLRendererBase", "Could not compile fragment shader:"+GLES20.glGetShaderInfoLog(fshader)); GLES20.glDeleteShader(vshader); GLES20.glDeleteShader(fshader); @@ -244,9 +244,25 @@ public abstract class CameraGLRendererBase implements GLSurfaceView.Renderer, Su GLES20.glAttachShader(program, vshader); GLES20.glAttachShader(program, fshader); GLES20.glLinkProgram(program); - Log.d("CameraGLRendererBase", "shaders were compiled OK"); GLES20.glDeleteShader(vshader); GLES20.glDeleteShader(fshader); + GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, status, 0); + if (status[0] == 0) { + Log.e("CameraGLRendererBase", "Could not link shader program: "+GLES20.glGetProgramInfoLog(program)); + program = 0; + return 0; + } + GLES20.glValidateProgram(program); + GLES20.glGetProgramiv(program, GLES20.GL_VALIDATE_STATUS, status, 0); + if (status[0] == 0) + { + Log.e("CameraGLRendererBase", "Shader program validation error: "+GLES20.glGetProgramInfoLog(program)); + GLES20.glDeleteProgram(program); + program = 0; + return 0; + } + + Log.d("CameraGLRendererBase", "Shader program is built OK"); return program; } diff --git a/samples/android/tutorial-4-opencl/jni/CLprocessor.cpp b/samples/android/tutorial-4-opencl/jni/CLprocessor.cpp index b7bf530b97..b71dc10182 100644 --- a/samples/android/tutorial-4-opencl/jni/CLprocessor.cpp +++ b/samples/android/tutorial-4-opencl/jni/CLprocessor.cpp @@ -237,23 +237,17 @@ void drawFrameProcCPU(int w, int h, int texOut) int64_t t; // let's modify pixels in FBO texture in C++ code (on CPU) - const int BUFF_SIZE = 1<<24;//2k*2k*4; - static char tmpBuff[BUFF_SIZE]; - if(w*h > BUFF_SIZE) - { - LOGE("Internal temp buffer is too small, can't make CPU frame processing"); - return; - } + static cv::Mat m; + m.create(h, w, CV_8UC4); // read t = getTimeMs(); // expecting FBO to be bound - glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, tmpBuff); + glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, m.data); LOGD("glReadPixels() costs %d ms", getTimeInterval(t)); // modify t = getTimeMs(); - cv::Mat m(h, w, CV_8UC4, tmpBuff); cv::Laplacian(m, m, CV_8U); m *= 10; LOGD("Laplacian() costs %d ms", getTimeInterval(t)); @@ -262,7 +256,7 @@ void drawFrameProcCPU(int w, int h, int texOut) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texOut); t = getTimeMs(); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, tmpBuff); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, m.data); LOGD("glTexSubImage2D() costs %d ms", getTimeInterval(t)); }