• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef API_RENDER_GLES_IDEVICE_GLES_H
17 #define API_RENDER_GLES_IDEVICE_GLES_H
18 
19 #include <render/device/intf_device.h>
20 #include <render/device/intf_gpu_resource_manager.h>
21 #include <render/namespace.h>
22 
23 // Platform / Backend specific typedefs.
24 #if RENDER_HAS_GLES_BACKEND
25 #include <EGL/egl.h>
26 #elif RENDER_HAS_GL_BACKEND
27 #ifndef WINAPI
28 #define WINAPI __stdcall
29 using HANDLE = void*;
30 using HINSTANCE = struct HINSTANCE__*;
31 using HMODULE = HINSTANCE;
32 using HWND = struct HWND__*;
33 using HDC = struct HDC__*;
34 using HGLRC = struct HGLRC__*;
35 #endif
36 #endif
37 
38 RENDER_BEGIN_NAMESPACE()
39 /** \addtogroup group_gfx_gles_idevicegles
40  *  @{
41  */
42 #if RENDER_HAS_GLES_BACKEND || DOXYGEN
43 /** Backend extra gles */
44 struct BackendExtraGLES : public BackendExtra {
45     /** Application context, If != EGL_NO_CONTEXT the device/engine will use this EGLContext to do rendering.
46         *WARNING* GLES state caching might cause issues in this case.
47         (application can change engine GL state and engine can change application GL state)
48     */
49     EGLContext applicationContext { EGL_NO_CONTEXT };
50     /** Shared context If != EGL_NO_CONTEXT the device/engine will create it's own context with context sharing enabled.
51      */
52     EGLContext sharedContext { EGL_NO_CONTEXT };
53     /** Display to use */
54     NativeDisplayType display { EGL_DEFAULT_DISPLAY };
55     /** MSAA samples, 0 no MSAA, 4 = 4xMSAA backbuffer, 8 = 8X MSAA */
56     uint32_t MSAASamples { 0 };
57     /** Alpha bits, request 8 bits of alpha to backbuffer by default */
58     uint32_t alphaBits { 8 };
59     /** Depth bits, request NO depth buffer by default. */
60     uint32_t depthBits { 24 };
61     /** Stencil bits, request NO stencil buffer by default. */
62     uint32_t stencilBits { 0 };
63 };
64 
65 /** Device platform data gles */
66 struct DevicePlatformDataGLES : DevicePlatformData {
67     /** Display */
68     EGLDisplay display { EGL_NO_DISPLAY };
69     /** Config */
70     EGLConfig config { nullptr };
71     /** Context */
72     EGLContext context { EGL_NO_CONTEXT };
73     /** EGL Version */
74     uint32_t majorVersion { 0 };
75     uint32_t minorVersion { 0 };
76     /** Does EGL have EGL_KHR_gl_colorspace **/
77     bool hasColorSpaceExt { false };
78     /** Context created by us, also destroy it */
79     bool contextCreated { false };
80     /** Call eglInitialize/eglTerminate or not */
81     bool eglInitialized { false };
82 };
83 
84 /** The following structure can be used to pass a TextureObject from application GLES context to Engine Context
85  * (device must be created with context sharing enabled or with app context) */
86 struct ImageDescGLES : BackendSpecificImageDesc {
87     /** Type, GL_TEXTURE_2D / GL_TEXTURE_EXTERNAL_OES / etc */
88     uint32_t type;
89     /** Image, Texture handle (glGenTextures) */
90     uint32_t image;
91     /** Internal format, GL_RGBA16F etc */
92     uint32_t internalFormat;
93     /** Format, GL_RGB etc */
94     uint32_t format;
95     /** Data type, GL_FLOAT etc */
96     uint32_t dataType;
97     /** Bytes per pixel */
98     uint32_t bytesperpixel;
99 
100     /** If non-zero should ba a valid EGLImage handle to be used as the source for the image. */
101     uintptr_t eglImage { 0u };
102 };
103 #endif
104 
105 #if RENDER_HAS_GL_BACKEND || DOXYGEN
106 
107 /** Backend extra gl */
108 struct BackendExtraGL : public BackendExtra {
109     /** MSAA samples, 0 no MSAA, 4 = 4xMSAA backbuffer, 8 = 8X MSAA */
110     uint32_t MSAASamples { 0 };
111     /** Alpha bits, request 8 bits of alpha to backbuffer by default */
112     uint32_t alphaBits { 8 };
113     /** Depth bits, request NO depth buffer by default. */
114     uint32_t depthBits { 24 };
115     /** Stencil bits, request NO stencil buffer by default. */
116     uint32_t stencilBits { 0 };
117 };
118 
119 /** Device platform data gl */
120 struct DevicePlatformDataGL : DevicePlatformData {
121 #if _WIN32 || DOXYGEN
122     /** Hwnd */
123     HWND mhWnd = NULL;
124     /** Display */
125     HDC display = NULL;
126     /** Context */
127     HGLRC context = NULL;
128 #endif
129 };
130 
131 /** The following structure can be used to pass a TextureObject from application GLES context to Engine Context
132  * (device must be created with context sharing enabled or with app context) */
133 struct ImageDescGL : BackendSpecificImageDesc {
134     /** Type, GL_TEXTURE_2D / GL_TEXTURE_EXTERNAL_OES / etc */
135     uint32_t type;
136     /** Texture handle (glGenTextures) */
137     uint32_t image;
138     /** Internal format, GL_RGBA16F etc */
139     uint32_t internalFormat;
140     /** Format, GL_RGB etc */
141     uint32_t format;
142     /** Data type, GL_FLOAT etc */
143     uint32_t dataType;
144     /** Bytes per pixel */
145     uint32_t bytesperpixel;
146 };
147 #endif
148 
149 /** Provides interface for low-level access */
150 class ILowLevelDeviceGLES : public ILowLevelDevice {
151 public:
152     // no-support for low level resource access
153 protected:
154     ILowLevelDeviceGLES() = default;
155     ~ILowLevelDeviceGLES() = default;
156 };
157 /** @} */
158 RENDER_END_NAMESPACE()
159 
160 #endif // API_RENDER_GLES_IDEVICE_GLES_H
161