Is it possible to use ARKit with the OpenGLES renderer in SceneKit?

Has anyone been able to use ARKit with SceneKit using the OpenGLES renderer instead of Metal?


I have an existing project that uses an SCNView with an OpenGLES3 context. When I try and use the same technique with ARSCNView I get an EXC_BAD_ACCESS crash with this output:


[SceneKit] Error: program failed to build:

[SceneKit] Error: C3DResourceManagerMakeProgramResident failed to compile program - fallback on default program


The makes me suspect that Metal is required but I can't find any documentation that states that explicitly. Has anybody seen any explicit mention of this?

Replies

I can't speak of seeing this documented anywhere regarding the openGLES renderer, but I'm attempting to build an app using the metal renderer, its working but not quite as I'd like.


Its likely that metal is required.


An alternative would be for you to take the same architectural approach as in the metal programming sample and build your own opengles based renderer using SceneKit and creating your own ARSession and handling the ARFrames in your own custom way.


This is what I intend doing to work around some of the issues I appear to be having with my custom metal rendering and ARSceneViews

I've never worked with SceneKit, however I have a working implementation in OpenGL ES 2.0 (presumably a 3.0 context works as well) so it is definitely possible. I based it on the Metal example and instead used this core video function (included some other ogl calls to give you an idea how it works)

            CVPixelBufferRef pixelBuffer = frame.capturedImage;
///// ...
            int width1 = (int)CVPixelBufferGetWidthOfPlane(pixelBuffer, 1);
            int height1 = (int)CVPixelBufferGetHeightOfPlane(pixelBuffer, 1);
         
            glActiveTexture(GL_TEXTURE1);
            CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache, pixelBuffer, NULL, GL_TEXTURE_2D, GL_RG_EXT, width1, height1, GL_RG_EXT, GL_UNSIGNED_BYTE, 1, &outTexture1);
         
            glBindTexture(CVOpenGLESTextureGetTarget(outTexture1), CVOpenGLESTextureGetName(outTexture1));
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);


However to be honest, working with ARKit in this way seems super dodgy right now. The view and projection matrices i'm getting are weird and I need to do transforms on them to get the correct output (mostly just guess and checked it). For this reason the hitTest functions are totally broken.


I can get it all to work, but expect some ***/fudge comments.

I can't speak for the projection matrix but the camera intrinsics were correct. I use them to build our projection matrices.

Seems like ARSCNView ignores options for backing it by OpenGL renderer (SCNRenderingAPIOpenGLES2), it uses Metal always, thus mixing ARSCNView with OpenGL rendering seems not possible.