1 /*
2 * Copyright (c) 2025 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 #include "Gl4ApiTest.h"
17 #include <hilog/log.h>
18 #undef LOG_DOMAIN
19 #define LOG_DOMAIN 0xD003200
20 #ifndef LOGI
21 #define LOGI(FMT, VARS...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "GL4_LOG", FMT, ##VARS))
22 #endif
23
24 #define INT_INIT_VAL 0
25 #define CLEAR_10 1.0f
26 #define CREAT_NUM_ONE 1
InitContext(void * window)27 bool Gl4ApiTest::InitContext(void* window)
28 {
29 LOGI("InitContext");
30 eglWindow = static_cast<EGLNativeWindowType>(window);
31 eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
32 if (eglDisplay == EGL_NO_DISPLAY) {
33 LOGI("eglGetDisplay: unable to get EGL display");
34 return false;
35 }
36 EGLint majorVersion = 0;
37 EGLint minorVersion = 0;
38 if (!eglInitialize(eglDisplay, &majorVersion, &minorVersion)) {
39 LOGI("eglInitialize: unable to get initialize EGL display");
40 return false;
41 }
42 eglBindAPI(EGL_OPENGL_API);
43 const char *eglVendor = eglQueryString(eglDisplay, EGL_VENDOR);
44 if (eglVendor != nullptr) {
45 LOGI("egl vendor %{public}s", eglVendor);
46 }
47 return true;
48 }
49
Release()50 void Gl4ApiTest::Release()
51 {
52 LOGI("Release");
53 if (eglDisplay != EGL_NO_DISPLAY) {
54 eglTerminate(eglDisplay);
55 eglDisplay = EGL_NO_DISPLAY;
56 }
57 eglWindow = nullptr;
58 }
59
GLTextureARBAbnormal()60 GLenum Gl4ApiTest::GLTextureARBAbnormal()
61 {
62 glActiveTextureARB(GL_TEXTURE0);
63 return glGetError();
64 }
65
GLBufferARBAbnormal()66 GLenum Gl4ApiTest::GLBufferARBAbnormal()
67 {
68 GLuint vbo = INT_INIT_VAL;
69 glGenBuffersARB(CREAT_NUM_ONE, &vbo);
70 glBindBufferARB(GL_ARRAY_BUFFER, vbo);
71 GLfloat vertices[] = {CLEAR_10, CLEAR_10, CLEAR_10, CLEAR_10};
72 glBufferDataARB(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
73 glBufferSubDataARB(GL_ZERO, FAILED, FAILED, nullptr);
74 glDrawBuffersARB(FAILED, nullptr);
75 glGetBufferSubDataARB(GL_ZERO, FAILED, FAILED, nullptr);
76 glDeleteBuffersARB(CREAT_NUM_ONE, &vbo);
77 return glGetError();
78 }
79
GLUniformARBAbnormal()80 GLenum Gl4ApiTest::GLUniformARBAbnormal()
81 {
82 glUniform1fvARB(GL_ZERO, FAILED, nullptr);
83 glUniform1iARB(GL_ZERO, GL_ZERO);
84 glUniform1ivARB(GL_ZERO, FAILED, nullptr);
85 glUniform2fvARB(GL_ZERO, FAILED, nullptr);
86 glUniform2ivARB(GL_ZERO, FAILED, nullptr);
87 glUniform3fvARB(GL_ZERO, FAILED, nullptr);
88 glUniform3ivARB(GL_ZERO, FAILED, nullptr);
89 glUniform4fvARB(GL_ZERO, FAILED, nullptr);
90 glUniform4ivARB(GL_ZERO, FAILED, nullptr);
91 return glGetError();
92 }
93
GLUniformMatrixARBAbnormal()94 GLenum Gl4ApiTest::GLUniformMatrixARBAbnormal()
95 {
96 glUniformMatrix2fvARB(GL_ZERO, FAILED, GL_TRUE, nullptr);
97 glUniformMatrix3fvARB(GL_ZERO, FAILED, GL_TRUE, nullptr);
98 glUniformMatrix4fvARB(GL_ZERO, FAILED, GL_TRUE, nullptr);
99 return glGetError();
100 }
101