* Initialize an EGL context for the current display. */
| 721 | * Initialize an EGL context for the current display. |
| 722 | */ |
| 723 | static int engine_init_display(struct engine* engine) { |
| 724 | // initialize OpenGL ES and EGL |
| 725 | |
| 726 | /* |
| 727 | * Here specify the attributes of the desired configuration. |
| 728 | * Below, we select an EGLConfig with at least 8 bits per color |
| 729 | * component compatible with on-screen windows |
| 730 | */ |
| 731 | const EGLint attribs[] = { |
| 732 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 733 | EGL_BLUE_SIZE, 8, |
| 734 | EGL_GREEN_SIZE, 8, |
| 735 | EGL_RED_SIZE, 8, |
| 736 | //EGL_ALPHA_SIZE, 8, |
| 737 | //EGL_DEPTH_SIZE, 24, |
| 738 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, |
| 739 | EGL_NONE |
| 740 | }; |
| 741 | |
| 742 | static const EGLint ctx_attribs[] = { |
| 743 | EGL_CONTEXT_CLIENT_VERSION, 1, |
| 744 | EGL_NONE |
| 745 | }; |
| 746 | |
| 747 | EGLint w, h, dummy, format; |
| 748 | EGLint numConfigs; |
| 749 | EGLConfig config; |
| 750 | EGLSurface surface; |
| 751 | EGLContext context; |
| 752 | |
| 753 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 754 | |
| 755 | eglInitialize(display, 0, 0); |
| 756 | |
| 757 | /* Here, the application chooses the configuration it desires. In this |
| 758 | * sample, we have a very simplified selection process, where we pick |
| 759 | * the first EGLConfig that matches our criteria */ |
| 760 | eglChooseConfig(display, attribs, &config, 1, &numConfigs); |
| 761 | |
| 762 | /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is |
| 763 | * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). |
| 764 | * As soon as we picked a EGLConfig, we can safely reconfigure the |
| 765 | * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ |
| 766 | eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); |
| 767 | |
| 768 | ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format); |
| 769 | |
| 770 | surface = eglCreateWindowSurface(display, config, engine->app->window, NULL); |
| 771 | context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctx_attribs); |
| 772 | |
| 773 | if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) { |
| 774 | adprintf("Unable to eglMakeCurrent"); |
| 775 | return -1; |
| 776 | } |
| 777 | |
| 778 | eglQuerySurface(display, surface, EGL_WIDTH, &w); |
| 779 | eglQuerySurface(display, surface, EGL_HEIGHT, &h); |
| 780 |
no test coverage detected