1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef _GL_CORE_ 17 #define _GL_CORE_ 18 19 #include <GLES3/gl3.h> 20 #include <EGL/egl.h> 21 #include <EGL/eglext.h> 22 23 #include <string> 24 25 class EGLCore { 26 public: EGLCore(std::string & id)27 explicit EGLCore(std::string& id) : id_(id) {}; 28 void GLContextInit(void* window, int w, int h); 29 void ChangeShape(); 30 void DrawTriangle(); 31 void ChangeColor(); 32 33 public: 34 std::string id_; 35 int width_; 36 int height_; 37 38 private: 39 void Update(); 40 bool checkGlError(const char* op); 41 GLuint LoadShader(GLenum type, const char *shaderSrc); 42 GLuint CreateProgram(const char *vertexShader, const char *fragShader); 43 44 EGLNativeWindowType mEglWindow; 45 EGLDisplay mEGLDisplay = EGL_NO_DISPLAY; 46 EGLConfig mEGLConfig = nullptr; 47 EGLContext mEGLContext = EGL_NO_CONTEXT; 48 EGLContext mSharedEGLContext = EGL_NO_CONTEXT; 49 EGLSurface mEGLSurface = nullptr; 50 GLuint mProgramHandle; 51 }; 52 53 #endif // _GL_CORE_ 54