void GVRActivity::onSurfaceCreated(JNIEnv& env) { LOGV("GVRActivity::onSurfaceCreated"); initializeOculusJava(env, oculusJavaGlThread_); //must happen as soon as possible as it updates the java side wherever it has default values; e.g. //resolutionWidth -1 becomes whatever VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_WIDTH is. configurationHelper_.getFramebufferConfiguration(env, mWidthConfiguration, mHeightConfiguration, vrapi_GetSystemPropertyInt(&oculusJavaGlThread_, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_WIDTH), vrapi_GetSystemPropertyInt(&oculusJavaGlThread_, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_HEIGHT), mMultisamplesConfiguration, mColorTextureFormatConfiguration, mResolveDepthConfiguration, mDepthTextureFormatConfiguration); }
void AppLocal::CreateWindowSurface() { LOG( "AppLocal::CreateWindowSurface()" ); // Optionally force the window to a different resolution, which // will be automatically scaled up by the HWComposer. // // Useful for checking operation, but note that the "frame" is always in full // display resolution, while the source crop can be shrunk down: // adb shell dumpsys SurfaceFlinger // // Strangely, setting the format here doesn't actually change the window bit depth. // The window bit depth seems to be determined solely by the EGL config, presumably // on eglMakeCurrent. // // That also means that it can't be changed by localparms between leave / enter vr mode, // you need to quit all the way out to get the new value. if ( VrSettings.Use16BitFramebuffer ) { const int displayPixelsWide = vrapi_GetSystemPropertyInt( &Java, VRAPI_SYS_PROP_DISPLAY_PIXELS_WIDE ); const int displayPixelsHigh = vrapi_GetSystemPropertyInt( &Java, VRAPI_SYS_PROP_DISPLAY_PIXELS_HIGH ); LOG( "ANativeWindow_setBuffersGeometry( %i, %i, %s )", displayPixelsWide, displayPixelsHigh, VrSettings.Use16BitFramebuffer ? "5:6:5" : "8:8:8:8" ); ANativeWindow_setBuffersGeometry( nativeWindow, displayPixelsWide, displayPixelsHigh, VrSettings.Use16BitFramebuffer ? WINDOW_FORMAT_RGB_565 : WINDOW_FORMAT_RGBA_8888 ); } EGLint attribs[16]; int numAttribs = 0; // Set the colorspace on the window if ( VrSettings.UseSrgbFramebuffer ) { attribs[numAttribs++] = EGL_GL_COLORSPACE_KHR; attribs[numAttribs++] = EGL_GL_COLORSPACE_SRGB_KHR; } attribs[numAttribs++] = EGL_NONE; // Android doesn't let the non-standard extensions show up in the // extension string, so we need to try it blind. windowSurface = eglCreateWindowSurface( glSetup.display, glSetup.config, nativeWindow, attribs ); if ( windowSurface == EGL_NO_SURFACE ) { const EGLint attribs2[] = { EGL_NONE }; windowSurface = eglCreateWindowSurface( glSetup.display, glSetup.config, nativeWindow, attribs2 ); if ( windowSurface == EGL_NO_SURFACE ) { FAIL( "eglCreateWindowSurface failed: %s", GL_GetErrorString() ); } FramebufferIsSrgb = false; } else { FramebufferIsSrgb = VrSettings.UseSrgbFramebuffer; } LOG( "nativeWindow %p gives surface %p", nativeWindow, windowSurface ); if ( eglMakeCurrent( glSetup.display, windowSurface, windowSurface, glSetup.context ) == EGL_FALSE ) { FAIL( "eglMakeCurrent failed: %s", GL_GetErrorString() ); } }
void AppLocal::CreateWindowSurface() { LOG( "AppLocal::CreateWindowSurface()" ); const int displayPixelsWide = vrapi_GetSystemPropertyInt( &Java, VRAPI_SYS_PROP_DISPLAY_PIXELS_WIDE ); const int displayPixelsHigh = vrapi_GetSystemPropertyInt( &Java, VRAPI_SYS_PROP_DISPLAY_PIXELS_HIGH ); VrSettings.ShowLoadingIcon = true; VrSettings.RenderMonoMode = false; VrSettings.UseSrgbFramebuffer = false; VrSettings.UseProtectedFramebuffer = false; VrSettings.FramebufferPixelsWide = displayPixelsWide; VrSettings.FramebufferPixelsHigh = displayPixelsHigh; VrSettings.EyeBufferParms.resolutionWidth = vrapi_GetSystemPropertyInt( &Java, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_WIDTH ); VrSettings.EyeBufferParms.resolutionHeight = vrapi_GetSystemPropertyInt( &Java, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_HEIGHT ); VrSettings.EyeBufferParms.multisamples = vrapi_GetSystemPropertyInt( &Java, VRAPI_SYS_PROP_MAX_FULLSPEED_FRAMEBUFFER_SAMPLES ); VrSettings.EyeBufferParms.colorFormat = COLOR_8888; VrSettings.EyeBufferParms.depthFormat = DEPTH_24; // Allow the app to override any settings. appInterface->Configure( VrSettings ); // Make sure the app didn't mess up the Java pointers. VrSettings.ModeParms.Java = Java; // Update the levels. FrameParms.PerformanceParms.CpuLevel = VrSettings.PerformanceParms.CpuLevel; FrameParms.PerformanceParms.GpuLevel = VrSettings.PerformanceParms.GpuLevel; // Optionally force the window to a different resolution, which // will be automatically scaled up by the HWComposer. if ( VrSettings.FramebufferPixelsWide != displayPixelsWide || VrSettings.FramebufferPixelsHigh != displayPixelsHigh ) { ANativeWindow_setBuffersGeometry( nativeWindow, VrSettings.FramebufferPixelsWide, VrSettings.FramebufferPixelsHigh, 0 ); } EGLint attribs[16]; int numAttribs = 0; // Set the colorspace on the window if ( VrSettings.UseSrgbFramebuffer ) { attribs[numAttribs++] = EGL_GL_COLORSPACE_KHR; attribs[numAttribs++] = EGL_GL_COLORSPACE_SRGB_KHR; } // Ask for TrustZone rendering support if ( VrSettings.UseProtectedFramebuffer ) { attribs[numAttribs++] = EGL_PROTECTED_CONTENT_EXT; attribs[numAttribs++] = EGL_TRUE; } attribs[numAttribs++] = EGL_NONE; // Android doesn't let the non-standard extensions show up in the // extension string, so we need to try it blind. windowSurface = eglCreateWindowSurface( glSetup.display, glSetup.config, nativeWindow, attribs ); if ( windowSurface == EGL_NO_SURFACE ) { const EGLint attribs2[] = { EGL_NONE }; windowSurface = eglCreateWindowSurface( glSetup.display, glSetup.config, nativeWindow, attribs2 ); if ( windowSurface == EGL_NO_SURFACE ) { FAIL( "eglCreateWindowSurface failed: %s", GL_GetErrorString() ); } FramebufferIsSrgb = false; FramebufferIsProtected = false; } else { FramebufferIsSrgb = VrSettings.UseSrgbFramebuffer; FramebufferIsProtected = VrSettings.UseProtectedFramebuffer; } LOG( "nativeWindow %p gives surface %p", nativeWindow, windowSurface ); LOG( "FramebufferIsSrgb: %s", FramebufferIsSrgb ? "true" : "false" ); LOG( "FramebufferIsProtected: %s", FramebufferIsProtected ? "true" : "false" ); if ( eglMakeCurrent( glSetup.display, windowSurface, windowSurface, glSetup.context ) == EGL_FALSE ) { FAIL( "eglMakeCurrent failed: %s", GL_GetErrorString() ); } CreatedSurface = true; }