FrameBuffers with GLSurfaceView template in OpenGLES 1.1 on android ndk

in Android NDK, is it possible to get OpenGL ES 1.1 to work with a typical Java-based GLSurfaceView template (overriding methods from GLSurfaceView.Renderer onDrawFrame, onSurfaceCreated, etc.) using the C ++ side frame, color and depth of buffers and VBO?

I am trying to create them using this:

void ES1Renderer::on_surface_created() { // Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer glGenFramebuffersOES(1, &defaultFramebuffer); glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer); // Create color renderbuffer object. glGenRenderbuffersOES(1, &colorRenderbuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer); // create depth renderbuffer object. glGenRenderbuffersOES(1, &depthRenderbuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer); } 

However, this does not seem to fit the context that I think was created when initializing GLSurfaceView and the java side.

I'm not an expert on NDK or OpenGLES, but I need to port an iOS application that uses OpenGL ES 1.1, and I try to use as much code as I can. Since the application also uses the user interface components for the platform (buttons, lists, etc.), Rice GL graphics, I thought this would be the best way. However, now I am considering using my native activity, although I'm not sure what will happen to the other java components.

+4
source share
1 answer

Absolutely, yes. The standard approach is that you create GLSurfaceView , just like when using OpenGL with Java, create and connect the GLSurfaceView.Renderer implementation and start the rendering stream.

From your Renderer methods, such as onSurfaceCreated() and onDrawFrame() , you can now call JNI functions that call functions in your own code. In these native functions, you can force any OpenGL API to call your heart desires. For example, in a function that you call from onSurfaceCreated() , you can create some objects and set some initial state. In the function you call from onSurfaceChanged() , you can customize your viewport and projection. In the function you call from onDrawFrame() , you are rendering.

You can even make OpenGL calls from Java and native code. The Java OpenGL API is a very thin layer around its own functions. It doesn’t matter if functions are called from native code or through the Java API.

The only thing you need to pay attention to is that you call all of your own code that calls the OpenGL API calls from the GLSurfaceView.Renderer onSurfaceCreated() , onSurfaceChanged() and onDrawFrame() . When these methods are called, you are in the stream rendering and have the current OpenGL context. If native OpenGL code is called from another place, most likely you are in the wrong thread and / or you do not have the current OpenGL context.

There are, of course, more complex settings where you create your own OpenGL contexts, do them explicitly, etc. But I highly recommend following the simple approach above if you have no good reason why you need something else. For most standard OpenGL rendering, what I described should be sufficient.

+6
source

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


All Articles