All Projects → zhouxingkong → NativeGL_demo

zhouxingkong / NativeGL_demo

Licence: other
此程序使用android native代码实现EGL,并使用SurfaceView作为OpenGL绘图窗口。即可提高图形渲染性能,又可使用java层定义的图形界面

Programming Languages

C++
36643 projects - #6 most used programming language
java
68154 projects - #9 most used programming language
CMake
9771 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to NativeGL demo

Jni.hpp
A modern, type-safe, header-only, C++14 wrapper for JNI
Stars: ✭ 313 (+627.91%)
Mutual labels:  ndk, jni
Androiddevwithcpp
Android Develop With C++
Stars: ✭ 106 (+146.51%)
Mutual labels:  ndk, jni
Keepalive
Fighting against force-stop kill process on Android with binder ioctl / Android高级保活
Stars: ✭ 376 (+774.42%)
Mutual labels:  ndk, jni
SecurityDemo
ndk进行简单的签名校验,密钥保护demo,android应用签名校验
Stars: ✭ 22 (-48.84%)
Mutual labels:  ndk, jni
ChangeVoice
NDK语音消息的变声处理
Stars: ✭ 33 (-23.26%)
Mutual labels:  ndk, jni
Jni4android
JNI Generater for Android
Stars: ✭ 261 (+506.98%)
Mutual labels:  ndk, jni
Android Luajit Launcher
Android NativeActivity based launcher for LuaJIT, implementing the main loop within Lua land via FFI
Stars: ✭ 87 (+102.33%)
Mutual labels:  ndk, jni
Anyndk
🔥 Android native library, make your development faster and easier. Android各种native库,让你的开发更快更简单
Stars: ✭ 35 (-18.6%)
Mutual labels:  ndk, jni
Androidsecurity
Android安全实践
Stars: ✭ 150 (+248.84%)
Mutual labels:  ndk, jni
Native Opencv Android Template
A tutorial for setting up OpenCV 4.5.0 (and other 4.x.y version) for Android in Android Studio with Native Development Kit (NDK) support.
Stars: ✭ 131 (+204.65%)
Mutual labels:  ndk, jni
premake-android-studio
premake5 module for android-studio and gradle build.
Stars: ✭ 24 (-44.19%)
Mutual labels:  ndk, jni
Relinker
A robust native library loader for Android.
Stars: ✭ 2,612 (+5974.42%)
Mutual labels:  ndk, jni
Camera2GLPreview
Android camera preview application using Camera2 API and OpenGL ES/Vulkan
Stars: ✭ 140 (+225.58%)
Mutual labels:  ndk, jni
Jnioor
基于C++模板函数与Fluent API设计的JNI反射库,极大的简化JNI反射调用,提高JNI开发效率与稳定性
Stars: ✭ 278 (+546.51%)
Mutual labels:  ndk, jni
Googleserialport
Android串口通信:抱歉,学会它真的可以为所欲为 ! ! !
Stars: ✭ 130 (+202.33%)
Mutual labels:  ndk, jni
Jpegkit Android
Efficient JPEG operations for Android without the risk of an OutOfMemoryException.
Stars: ✭ 154 (+258.14%)
Mutual labels:  ndk, jni
Android Disassembler
Disassemble ANY files including .so (NDK, JNI), Windows PE(EXE, DLL, SYS, etc), linux binaries, libraries, and any other files such as pictures, audios, etc(for fun)files on Android. Capstone-based disassembler application on android. 안드로이드 NDK 공유 라이브러리, Windows 바이너리, etc,... 리버싱 앱
Stars: ✭ 250 (+481.4%)
Mutual labels:  ndk, jni
java-cpp-example
Example of using C++ classes from Java. Showcases SWIG, JNA and JNI
Stars: ✭ 135 (+213.95%)
Mutual labels:  jni
gdx-jnigen
jnigen is a small library that can be used with or without libGDX which allows C/C++ code to be written inline with Java source code.
Stars: ✭ 32 (-25.58%)
Mutual labels:  jni
Android-Code-Demos
📦 Android learning code demos.
Stars: ✭ 41 (-4.65%)
Mutual labels:  ndk

NativeGL_demo

1方案介绍

在实际应用中,经常遇到OpenGL ES渲染性能达不到要求,图像卡顿等GG问题。这时,在不改变平台选型的情况下,选择一个好的方案实现OpenGL渲染很重要。 在android应用程序中使用OpenGL ES共有四种方案

  1. 使用GLSurfaceView作为绘图的窗口,使用GLSurfaceView.Renderer实现OpenGL渲染上下文,并通过调用android.opengl.GLES20中的API函数实现对图像的渲染
  2. 使用GLSurfaceView作为绘图的窗口,使用GLSurfaceView.Renderer实现OpenGL渲染上下文,和1不一样的是通过JNI接口调用#include <GLES2/gl2.h>中的API函数来实现图形渲染
  3. 使用NativeActivity实现OpenGL渲染上下文,并通过JNI接口调用#include <GLES2/gl2.h>中的API函数来实现图形渲染。使用这种方案就意味着整个APP全部用C++语言编写,不能实现android基本控件的绘制,如Button/TextView
  4. 最后一种方法,也是我所提倡使用的方法,就是使用SurfaceView作为绘图的窗口,并使用native层的pthread作为OpenGL渲染上下文,并通过pthread调用#include <GLES2/gl2.h>实现图形渲染

本例程以帮助类的形式将方案4的OpenGL渲染上下文封装在GLRender类中。用户使用时只需要继承GLRender类并像使用GLSurfaceView.Renderer接口一样,实现渲染上下文的回调函数,并在回调函数中调用#include <GLES2/gl2.h>中的API函数

2方案实现方法

使用本方案需要注意以下几点:

  1. 编写CMakeLists.txt,添加如下语句。如果不添加会使程序编译GG。
# now build app's shared lib
#不加这句不能用std命名空间的函数
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")

#使用这句将编译后的native-lib库和android、log、EGL、GLESv2四个库进行链接。
#不加这个会GG,将导致上面提到的四个功能无法使用
target_link_libraries( # Specifies the target library.
                       native-lib
                       # Links the target library to the log library
                       # included in the NDK.
                       android
                       log
                       EGL
                       GLESv2 )
  1. 在布局文件中定义一个SurfaceView,并实现SurfaceHolder.Callback接口。在接口中使用JNI调用GLRender.SetWindow函数将SurfaceView与NativeWindow关联。以以便在Native空间进行绘图。
public class SViewHolder implements SurfaceHolder.Callback {
//...............
    public void surfaceCreated(SurfaceHolder holder) {
        JNIProxy.SetSurfaceS(holder.getSurface());
        JNIProxy.StartRenderS();
    }
//................
}
  1. 在Native空间继承GLRenderer类,并实现GLRenderer类中的以下抽象函数。不实现程序会GG
/*
 * 下面三个函数为OpenGL渲染上下文回调函数,这三个函数需要用户通过继承GLRenderer类的方法来实现
 * 实现方法同android.opengl.GLSurfaceView.Render中的方法。详细请参考develop.google
 * */
virtual void SurfaceCreate()=0;
virtual void SurfaceChange(int width, int height)=0;
virtual void DrawFrame()=0;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].