2019-04-17 10:49:11 +08:00
|
|
|
//
|
|
|
|
// GLContext.cpp
|
|
|
|
// MNN
|
|
|
|
//
|
|
|
|
// Created by MNN on 2019/01/31.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
2019-05-24 11:26:54 +08:00
|
|
|
#include "GLContext.hpp"
|
2019-04-17 10:49:11 +08:00
|
|
|
#include <EGL/egl.h>
|
|
|
|
namespace MNN {
|
2019-05-24 11:26:54 +08:00
|
|
|
namespace OpenGL {
|
2019-04-17 10:49:11 +08:00
|
|
|
class GLContext::nativeContext {
|
|
|
|
public:
|
|
|
|
nativeContext() {
|
|
|
|
mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
|
|
EGLint majorVersion;
|
|
|
|
EGLint minorVersion;
|
|
|
|
eglInitialize(mDisplay, &majorVersion, &minorVersion);
|
|
|
|
EGLint numConfigs;
|
|
|
|
static const EGLint configAttribs[] = {EGL_SURFACE_TYPE,
|
|
|
|
EGL_PBUFFER_BIT,
|
|
|
|
EGL_RENDERABLE_TYPE,
|
|
|
|
EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_RED_SIZE,
|
|
|
|
8,
|
|
|
|
EGL_GREEN_SIZE,
|
|
|
|
8,
|
|
|
|
EGL_BLUE_SIZE,
|
|
|
|
8,
|
|
|
|
EGL_ALPHA_SIZE,
|
|
|
|
8,
|
|
|
|
EGL_NONE};
|
|
|
|
|
|
|
|
EGLConfig surfaceConfig;
|
|
|
|
eglChooseConfig(mDisplay, configAttribs, &surfaceConfig, 1, &numConfigs);
|
|
|
|
|
|
|
|
static const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
|
|
|
|
mContext = eglCreateContext(mDisplay, surfaceConfig, NULL, contextAttribs);
|
|
|
|
|
|
|
|
static const EGLint surfaceAttribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
|
|
|
|
mSurface = eglCreatePbufferSurface(mDisplay, surfaceConfig, surfaceAttribs);
|
|
|
|
eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);
|
|
|
|
}
|
|
|
|
~nativeContext() {
|
|
|
|
eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
eglDestroyContext(mDisplay, mContext);
|
|
|
|
eglDestroySurface(mDisplay, mSurface);
|
|
|
|
eglTerminate(mDisplay);
|
|
|
|
mDisplay = EGL_NO_DISPLAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
EGLContext mContext;
|
|
|
|
EGLDisplay mDisplay;
|
|
|
|
EGLSurface mSurface;
|
|
|
|
};
|
|
|
|
|
2019-05-24 11:26:54 +08:00
|
|
|
GLContext::nativeContext* GLContext::create(int version) {
|
2019-04-17 10:49:11 +08:00
|
|
|
return new nativeContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLContext::destroy(nativeContext* context) {
|
|
|
|
delete context;
|
|
|
|
}
|
2019-05-24 11:26:54 +08:00
|
|
|
} // namespace OpenGL
|
2019-04-17 10:49:11 +08:00
|
|
|
} // namespace MNN
|