1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include "EGLHelper.h" #include "../log/ZqlPlayerLog.h"
EGLHelper::EGLHelper() { mEglDisplay = EGL_NO_DISPLAY; mEglSurface = EGL_NO_SURFACE; mEglContext = EGL_NO_CONTEXT; mEglConfig = NULL; }
EGLHelper::~EGLHelper() {
}
int EGLHelper::initEGL(EGLNativeWindowType win) { mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (mEglDisplay == EGL_NO_DISPLAY) { LOGE("eglGetDisplay error") return -1; }
EGLint *version = new EGLint[2]; if (!eglInitialize(mEglDisplay, &version[0], &version[1])) { LOGE("eglInitialize error"); return -1; }
const EGLint attribs[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 8, EGL_STENCIL_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; EGLint num_config; if (!eglChooseConfig(mEglDisplay, attribs, NULL, 1, &num_config)) { LOGE("eglChooseConfig error 1"); return -1; }
if (!eglChooseConfig(mEglDisplay, attribs, &mEglConfig, num_config, &num_config)) { LOGE("eglChooseConfig error 2"); return -1; }
int attrib_list[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, attrib_list); if (mEglContext == EGL_NO_CONTEXT) { LOGE("eglCreateContext error"); return -1; } mEglSurface = eglCreateWindowSurface(mEglDisplay, mEglConfig, win, NULL); if (mEglSurface == EGL_NO_SURFACE) { LOGE("eglCreateWindowSurface error"); return -1; }
if (!eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) { LOGE("eglMakeCurrent error"); return -1; }
LOGD("egl init success");
return 0; }
int EGLHelper::swapBuffers() {
if (mEglDisplay != EGL_NO_DISPLAY && mEglSurface != EGL_NO_SURFACE) { if (eglSwapBuffers(mEglDisplay, mEglSurface)) { return 0; } }
return -1; }
void EGLHelper::destoryEgl() {
if (mEglDisplay != EGL_NO_DISPLAY) { eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } if (mEglDisplay != EGL_NO_DISPLAY && mEglSurface != EGL_NO_SURFACE) { eglDestroySurface(mEglDisplay, mEglSurface); mEglSurface = EGL_NO_SURFACE; } if (mEglDisplay != EGL_NO_DISPLAY && mEglContext != EGL_NO_CONTEXT) { eglDestroyContext(mEglDisplay, mEglContext); mEglContext = EGL_NO_CONTEXT; } if (mEglDisplay != EGL_NO_DISPLAY) { eglTerminate(mEglDisplay); } }
|