Is it possible to create OpenGL ES calls from your C ++ and Java code?

I have an application that will use the NDK for high graphics requirements and terrain generation libraries that I wrote in C ++. My question is: if I already made my GUI with the SDK and I make a random call to opengl in java, for example GLES20.glEnable(GL_CULL_FACE); , and then go to the call glEnable(GL_DEPTH_TEST); in C ++ via JNI, will there be any known build errors / problems? In case someone asks why I ask this and / or thinks this is a stupid question, this is because there is an existing OpenGL context in the desktop OpenGL (although GLFW took care of that). I am concerned that OpenGL ES also has an existing context . If so, would make OpenGL ES calls from both java and C ++ to the previously declared context ?

+6
source share
2 answers

In OpenGL, you always deal with context, yes. The critical parts for you are

  • when and how is your OpenGL context bound to parts of Java?
  • - This is an OpenGL context supported when called into native code.

Almost all Java calls for OpenGL fit in some way into native code. Therefore, if you write parts of your program using the NDK and call these parts in the same way as you call directly in OpenGL, then the OpenGL context will be relevant and will be used.

+4
source

The direct answer is Yes , but you have to be careful how you write your code in C ++ and Java

  • NDK offers several NativeActivity and native_app_glue codes to help you write clean C ++ codes for game logic, rendering, etc. and minimize the need for writing Java code. You will find some entry point function like android_main() if you use this method. In this case, you cannot mix the OpenGL call in Java and C ++ codes in the same context, since your own code runs in another thread and exchanges data through the channel with the Java thread [Dalvik VM stream]
  • Calling a native function in Java via JNI, it will in the same thread, in the same context, call the OpenGL API in Java or C ++, there should be no difference, just like @datenwolf's answer

Hope this helps ~

+2
source

Source: https://habr.com/ru/post/979745/


All Articles