I have an application that will be taking advantage of the NDK do to high graphics requirements and a terrain generation library that I wrote in c++. My question is if I already made my GUI with the SDK and I make a random opengl call in java such as GLES20.glEnable(GL_CULL_FACE);
and then proceed to call glEnable(GL_DEPTH_TEST);
in C++ via JNI would there be any known errors/build issues? In the case that someone wonders why I am asking this and/or thinks it is a stupid question it is because in desktop OpenGL there is an existing OpenGL context
(though GLFW took care of most of this). I am concerned if OpenGL ES also has an existing context
. If so, would making OpenGL ES calls from both java and C++ write to previously stated context
?
Asked
Active
Viewed 1,266 times
6

genpfault
- 51,148
- 11
- 85
- 139

SemperAmbroscus
- 1,308
- 2
- 12
- 23
-
1The question looked slightly different, but my answer here explains how to safely mix Java and C++ code when making OpenGL calls: http://stackoverflow.com/a/24444862/3530129 – Reto Koradi Dec 17 '14 at 00:55
2 Answers
4
In OpenGL you're always dealing with context, yes. The critical parts for you are
- when and how is your OpenGL context bound in the Java parts?
- is the OpenGL context kept current when calling into native code.
Practically all Java calls to OpenGL go into native code any way. So if you write parts of your program with the NDK and call into these parts in the same way as you'd call directly into OpenGL, then a OpenGL context will be current and be usable.

datenwolf
- 159,371
- 13
- 185
- 298
2
The direct answer is Yes, but you must be careful how you write your C++ and Java code
- NDK offer some
NativeActivity
andnative_app_glue
codes, which helps you write pure C++ codes for game logic, rendering, etc., and minimize the requirement for writing Java code. You will find some entry point function likeandroid_main()
if you are using this way. In this case, you can't mix call OpenGL in Java and C++ codes in the same context, since your native code are run in different thread, and communicate through pipe with Java thread [Dalvik VM thread] - Call native function in Java through JNI, this will in the same thread, same context, call OpenGL API in Java or C++ should be no difference, just as the answer of @datenwolf
Hope this helps~

Yan An
- 459
- 2
- 10