1 /* 2 * Copyright (c) 2023 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 #ifndef NATIVE_XCOMPONENT_EGL_CORE_H 16 #define NATIVE_XCOMPONENT_EGL_CORE_H 17 18 #include <EGL/egl.h> 19 #include <EGL/eglext.h> 20 #include <GLES3/gl3.h> 21 22 namespace NativeXComponentSample { 23 class EGLCore { 24 public: EGLCore()25 explicit EGLCore() {}; ~EGLCore()26 ~EGLCore() {} 27 bool EglContextInit(void* window, int width, int height); 28 bool CreateEnvironment(); 29 void Draw(int& hasDraw); 30 void Background(); 31 void ChangeColor(int& hasChangeColor); 32 void Release(); 33 void UpdateSize(int width, int height); 34 35 private: 36 GLuint LoadShader(GLenum type, const char* shaderSrc); 37 GLuint CreateProgram(const char* vertexShader, const char* fragShader); 38 GLint PrepareDraw(); 39 bool ExecuteDraw(GLint position, const GLfloat* color, const GLfloat shapeVertices[], unsigned long vertSize); 40 bool ExecuteDrawStar(GLint position, const GLfloat* color, const GLfloat shapeVertices[], unsigned long vertSize); 41 bool ExecuteDrawNewStar(GLint position, const GLfloat* color, 42 const GLfloat shapeVertices[], unsigned long vertSize); 43 void Rotate2d(GLfloat centerX, GLfloat centerY, GLfloat* rotateX, GLfloat* rotateY, GLfloat theta); 44 bool FinishDraw(); 45 46 private: 47 EGLNativeWindowType eglWindow_; 48 EGLDisplay eglDisplay_ = EGL_NO_DISPLAY; 49 EGLConfig eglConfig_ = EGL_NO_CONFIG_KHR; 50 EGLSurface eglSurface_ = EGL_NO_SURFACE; 51 EGLContext eglContext_ = EGL_NO_CONTEXT; 52 GLuint program_; 53 bool flag_ = false; 54 int width_; 55 int height_; 56 GLfloat widthPercent_; 57 }; 58 } // namespace NativeXComponentSample 59 #endif // NATIVE_XCOMPONENT_EGL_CORE_H 60