Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
| 3 | * |
| 4 | * Copyright (C) 2014 Adrián Arroyo Calle <adrian.arroyocalle@gmail.com> |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #include <errno.h> |
| 26 | #include <dlfcn.h> |
Emil Velikov | bf0e4d2 | 2015-02-28 17:12:40 +0000 | [diff] [blame] | 27 | #include <stdint.h> |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 28 | #include <stdio.h> |
| 29 | |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 30 | #include "eglconfig.h" |
| 31 | #include "eglcontext.h" |
Alexander von Gluck IV | 1b97a72 | 2018-12-27 20:41:47 +0000 | [diff] [blame] | 32 | #include "egldevice.h" |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 33 | #include "egldisplay.h" |
| 34 | #include "egldriver.h" |
| 35 | #include "eglcurrent.h" |
| 36 | #include "egllog.h" |
| 37 | #include "eglsurface.h" |
| 38 | #include "eglimage.h" |
| 39 | #include "egltypedefs.h" |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 40 | |
| 41 | #include <InterfaceKit.h> |
| 42 | #include <OpenGLKit.h> |
| 43 | |
| 44 | |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 45 | #ifdef DEBUG |
| 46 | # define TRACE(x...) printf("egl_haiku: " x) |
| 47 | # define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__) |
| 48 | #else |
| 49 | # define TRACE(x...) |
| 50 | # define CALLED() |
| 51 | #endif |
| 52 | #define ERROR(x...) printf("egl_haiku: " x) |
| 53 | |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 54 | |
| 55 | _EGL_DRIVER_STANDARD_TYPECASTS(haiku_egl) |
| 56 | |
| 57 | |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 58 | struct haiku_egl_config |
| 59 | { |
Alexander von Gluck IV | e7ac212 | 2014-12-22 16:02:50 +0000 | [diff] [blame] | 60 | _EGLConfig base; |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | struct haiku_egl_context |
| 64 | { |
| 65 | _EGLContext ctx; |
| 66 | }; |
| 67 | |
| 68 | struct haiku_egl_surface |
| 69 | { |
| 70 | _EGLSurface surf; |
| 71 | BGLView* gl; |
| 72 | }; |
| 73 | |
| 74 | |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 75 | /** |
Eric Engestrom | cc03448 | 2020-07-20 13:38:24 +0200 | [diff] [blame] | 76 | * Called via eglCreateWindowSurface(), drv->CreateWindowSurface(). |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 77 | */ |
| 78 | static _EGLSurface * |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 79 | haiku_create_window_surface(const _EGLDriver *drv, _EGLDisplay *disp, |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 80 | _EGLConfig *conf, void *native_window, const EGLint *attrib_list) |
| 81 | { |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 82 | CALLED(); |
| 83 | |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 84 | struct haiku_egl_surface* surface; |
Emil Velikov | 46f87b2 | 2015-06-11 12:17:23 +0100 | [diff] [blame] | 85 | surface = (struct haiku_egl_surface*) calloc(1, sizeof (*surface)); |
| 86 | if (!surface) { |
| 87 | _eglError(EGL_BAD_ALLOC, "haiku_create_window_surface"); |
| 88 | return NULL; |
| 89 | } |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 90 | |
Alexander von Gluck IV | e22e0de | 2015-06-29 23:29:44 -0500 | [diff] [blame] | 91 | if (!_eglInitSurface(&surface->surf, disp, EGL_WINDOW_BIT, |
Paulo Zanoni | 04ecda3 | 2019-05-01 15:42:26 -0700 | [diff] [blame] | 92 | conf, attrib_list, native_window)) { |
Alexander von Gluck IV | e22e0de | 2015-06-29 23:29:44 -0500 | [diff] [blame] | 93 | free(surface); |
| 94 | return NULL; |
| 95 | } |
Emil Velikov | 46f87b2 | 2015-06-11 12:17:23 +0100 | [diff] [blame] | 96 | |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 97 | (&surface->surf)->SwapInterval = 1; |
| 98 | |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 99 | TRACE("Creating window\n"); |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 100 | BWindow* win = (BWindow*)native_window; |
| 101 | |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 102 | TRACE("Creating GL view\n"); |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 103 | surface->gl = new BGLView(win->Bounds(), "OpenGL", B_FOLLOW_ALL_SIDES, 0, |
| 104 | BGL_RGB | BGL_DOUBLE | BGL_ALPHA); |
| 105 | |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 106 | TRACE("Adding GL\n"); |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 107 | win->AddChild(surface->gl); |
| 108 | |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 109 | TRACE("Showing window\n"); |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 110 | win->Show(); |
| 111 | return &surface->surf; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | static _EGLSurface * |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 116 | haiku_create_pixmap_surface(const _EGLDriver *drv, _EGLDisplay *disp, |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 117 | _EGLConfig *conf, void *native_pixmap, const EGLint *attrib_list) |
| 118 | { |
Alexander von Gluck IV | e7ac212 | 2014-12-22 16:02:50 +0000 | [diff] [blame] | 119 | return NULL; |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | |
| 123 | static _EGLSurface * |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 124 | haiku_create_pbuffer_surface(const _EGLDriver *drv, _EGLDisplay *disp, |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 125 | _EGLConfig *conf, const EGLint *attrib_list) |
| 126 | { |
Alexander von Gluck IV | e7ac212 | 2014-12-22 16:02:50 +0000 | [diff] [blame] | 127 | return NULL; |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | |
| 131 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 132 | haiku_destroy_surface(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 133 | { |
Emil Velikov | e77a32f | 2015-06-11 12:33:55 +0100 | [diff] [blame] | 134 | if (_eglPutSurface(surf)) { |
| 135 | // XXX: detach haiku_egl_surface::gl from the native window and destroy it |
| 136 | free(surf); |
Alexander von Gluck IV | e22e0de | 2015-06-29 23:29:44 -0500 | [diff] [blame] | 137 | } |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 138 | return EGL_TRUE; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | static EGLBoolean |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 143 | haiku_add_configs_for_visuals(_EGLDisplay *disp) |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 144 | { |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 145 | CALLED(); |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 146 | |
Alexander von Gluck IV | e7ac212 | 2014-12-22 16:02:50 +0000 | [diff] [blame] | 147 | struct haiku_egl_config* conf; |
Emil Velikov | 46f87b2 | 2015-06-11 12:17:23 +0100 | [diff] [blame] | 148 | conf = (struct haiku_egl_config*) calloc(1, sizeof (*conf)); |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 149 | if (!conf) |
| 150 | return _eglError(EGL_BAD_ALLOC, "haiku_add_configs_for_visuals"); |
Alexander von Gluck IV | e7ac212 | 2014-12-22 16:02:50 +0000 | [diff] [blame] | 151 | |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 152 | _eglInitConfig(&conf->base, disp, 1); |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 153 | TRACE("Config inited\n"); |
| 154 | |
Eric Engestrom | 7bee388 | 2020-02-13 15:53:03 +0000 | [diff] [blame] | 155 | conf->base.RedSize = 8; |
| 156 | conf->base.BlueSize = 8; |
| 157 | conf->base.GreenSize = 8; |
| 158 | conf->base.LuminanceSize = 0; |
| 159 | conf->base.AlphaSize = 8; |
| 160 | conf->base.ColorBufferType = EGL_RGB_BUFFER; |
| 161 | conf->base.BufferSize = conf->base.RedSize |
| 162 | + conf->base.GreenSize |
| 163 | + conf->base.BlueSize |
| 164 | + conf->base.AlphaSize; |
| 165 | conf->base.ConfigCaveat = EGL_NONE; |
| 166 | conf->base.ConfigId = 1; |
| 167 | conf->base.BindToTextureRGB = EGL_FALSE; |
| 168 | conf->base.BindToTextureRGBA = EGL_FALSE; |
| 169 | conf->base.StencilSize = 0; |
| 170 | conf->base.TransparentType = EGL_NONE; |
| 171 | conf->base.NativeRenderable = EGL_TRUE; // Let's say yes |
| 172 | conf->base.NativeVisualID = 0; // No visual |
| 173 | conf->base.NativeVisualType = EGL_NONE; // No visual |
| 174 | conf->base.RenderableType = 0x8; |
| 175 | conf->base.SampleBuffers = 0; // TODO: How to get the right value ? |
| 176 | conf->base.Samples = conf->base.SampleBuffers == 0 ? 0 : 0; |
| 177 | conf->base.DepthSize = 24; // TODO: How to get the right value ? |
| 178 | conf->base.Level = 0; |
| 179 | conf->base.MaxPbufferWidth = 0; // TODO: How to get the right value ? |
| 180 | conf->base.MaxPbufferHeight = 0; // TODO: How to get the right value ? |
| 181 | conf->base.MaxPbufferPixels = 0; // TODO: How to get the right value ? |
| 182 | conf->base.SurfaceType = EGL_WINDOW_BIT /*| EGL_PIXMAP_BIT | EGL_PBUFFER_BIT*/; |
Alexander von Gluck IV | e7ac212 | 2014-12-22 16:02:50 +0000 | [diff] [blame] | 183 | |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 184 | TRACE("Config configuated\n"); |
Alexander von Gluck IV | e7ac212 | 2014-12-22 16:02:50 +0000 | [diff] [blame] | 185 | if (!_eglValidateConfig(&conf->base, EGL_FALSE)) { |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 186 | _eglLog(_EGL_DEBUG, "Haiku: failed to validate config"); |
Emil Velikov | b0f33e9 | 2015-06-11 13:07:08 +0100 | [diff] [blame] | 187 | goto cleanup; |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 188 | } |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 189 | TRACE("Validated config\n"); |
Alexander von Gluck IV | e22e0de | 2015-06-29 23:29:44 -0500 | [diff] [blame] | 190 | |
Alexander von Gluck IV | e7ac212 | 2014-12-22 16:02:50 +0000 | [diff] [blame] | 191 | _eglLinkConfig(&conf->base); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 192 | if (!_eglGetArraySize(disp->Configs)) { |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 193 | _eglLog(_EGL_WARNING, "Haiku: failed to create any config"); |
Emil Velikov | b0f33e9 | 2015-06-11 13:07:08 +0100 | [diff] [blame] | 194 | goto cleanup; |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 195 | } |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 196 | TRACE("Config successfull\n"); |
Emil Velikov | b0f33e9 | 2015-06-11 13:07:08 +0100 | [diff] [blame] | 197 | |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 198 | return EGL_TRUE; |
Emil Velikov | b0f33e9 | 2015-06-11 13:07:08 +0100 | [diff] [blame] | 199 | |
| 200 | cleanup: |
| 201 | free(conf); |
| 202 | return EGL_FALSE; |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 203 | } |
| 204 | |
Alexander von Gluck IV | e22e0de | 2015-06-29 23:29:44 -0500 | [diff] [blame] | 205 | |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 206 | extern "C" |
| 207 | EGLBoolean |
Eric Engestrom | ad61d4f | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 208 | init_haiku(_EGLDisplay *disp) |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 209 | { |
Emil Velikov | 0099270 | 2018-09-04 11:20:03 +0100 | [diff] [blame] | 210 | _EGLDevice *dev; |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 211 | CALLED(); |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 212 | |
Emil Velikov | 0099270 | 2018-09-04 11:20:03 +0100 | [diff] [blame] | 213 | dev = _eglAddDevice(-1, true); |
| 214 | if (!dev) { |
| 215 | _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to find EGLDevice"); |
| 216 | return EGL_FALSE; |
| 217 | } |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 218 | disp->Device = dev; |
Emil Velikov | 0099270 | 2018-09-04 11:20:03 +0100 | [diff] [blame] | 219 | |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 220 | TRACE("Add configs\n"); |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 221 | if (!haiku_add_configs_for_visuals(disp)) |
Emil Velikov | b0f33e9 | 2015-06-11 13:07:08 +0100 | [diff] [blame] | 222 | return EGL_FALSE; |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 223 | |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 224 | TRACE("Initialization finished\n"); |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 225 | |
| 226 | return EGL_TRUE; |
| 227 | } |
| 228 | |
| 229 | |
| 230 | extern "C" |
| 231 | EGLBoolean |
Eric Engestrom | 435ad51 | 2018-04-22 16:48:15 +0200 | [diff] [blame^] | 232 | haiku_terminate(_EGLDisplay *disp) |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 233 | { |
| 234 | return EGL_TRUE; |
| 235 | } |
| 236 | |
| 237 | |
| 238 | extern "C" |
| 239 | _EGLContext* |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 240 | haiku_create_context(const _EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 241 | _EGLContext *share_list, const EGLint *attrib_list) |
| 242 | { |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 243 | CALLED(); |
| 244 | |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 245 | struct haiku_egl_context* context; |
Emil Velikov | 46f87b2 | 2015-06-11 12:17:23 +0100 | [diff] [blame] | 246 | context = (struct haiku_egl_context*) calloc(1, sizeof (*context)); |
| 247 | if (!context) { |
| 248 | _eglError(EGL_BAD_ALLOC, "haiku_create_context"); |
| 249 | return NULL; |
| 250 | } |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 251 | |
| 252 | if (!_eglInitContext(&context->ctx, disp, conf, attrib_list)) |
Emil Velikov | b0f33e9 | 2015-06-11 13:07:08 +0100 | [diff] [blame] | 253 | goto cleanup; |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 254 | |
| 255 | TRACE("Context created\n"); |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 256 | return &context->ctx; |
Emil Velikov | b0f33e9 | 2015-06-11 13:07:08 +0100 | [diff] [blame] | 257 | |
| 258 | cleanup: |
| 259 | free(context); |
| 260 | return NULL; |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | |
| 264 | extern "C" |
| 265 | EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 266 | haiku_destroy_context(const _EGLDriver* drv, _EGLDisplay *disp, _EGLContext* ctx) |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 267 | { |
Emil Velikov | b0f33e9 | 2015-06-11 13:07:08 +0100 | [diff] [blame] | 268 | struct haiku_egl_context* context = haiku_egl_context(ctx); |
| 269 | |
| 270 | if (_eglPutContext(ctx)) { |
| 271 | // XXX: teardown the context ? |
| 272 | free(context); |
Alexander von Gluck IV | e22e0de | 2015-06-29 23:29:44 -0500 | [diff] [blame] | 273 | ctx = NULL; |
Emil Velikov | b0f33e9 | 2015-06-11 13:07:08 +0100 | [diff] [blame] | 274 | } |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 275 | return EGL_TRUE; |
| 276 | } |
| 277 | |
| 278 | |
| 279 | extern "C" |
| 280 | EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 281 | haiku_make_current(const _EGLDriver* drv, _EGLDisplay *disp, _EGLSurface *dsurf, |
Alexander von Gluck IV | e22e0de | 2015-06-29 23:29:44 -0500 | [diff] [blame] | 282 | _EGLSurface *rsurf, _EGLContext *ctx) |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 283 | { |
Emil Velikov | ed9dcdf | 2015-06-11 12:02:45 +0100 | [diff] [blame] | 284 | CALLED(); |
| 285 | |
Emil Velikov | 0e55db3 | 2015-06-11 13:08:00 +0100 | [diff] [blame] | 286 | struct haiku_egl_context* cont = haiku_egl_context(ctx); |
| 287 | struct haiku_egl_surface* surf = haiku_egl_surface(dsurf); |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 288 | _EGLContext *old_ctx; |
Emil Velikov | 0e55db3 | 2015-06-11 13:08:00 +0100 | [diff] [blame] | 289 | _EGLSurface *old_dsurf, *old_rsurf; |
Emil Velikov | b0f33e9 | 2015-06-11 13:07:08 +0100 | [diff] [blame] | 290 | |
| 291 | if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) |
| 292 | return EGL_FALSE; |
| 293 | |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 294 | //cont->ctx.DrawSurface=&surf->surf; |
| 295 | surf->gl->LockGL(); |
| 296 | return EGL_TRUE; |
| 297 | } |
| 298 | |
| 299 | |
| 300 | extern "C" |
| 301 | EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 302 | haiku_swap_buffers(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 303 | { |
Emil Velikov | 0e55db3 | 2015-06-11 13:08:00 +0100 | [diff] [blame] | 304 | struct haiku_egl_surface* surface = haiku_egl_surface(surf); |
| 305 | |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 306 | surface->gl->SwapBuffers(); |
| 307 | //gl->Render(); |
| 308 | return EGL_TRUE; |
| 309 | } |
| 310 | |
| 311 | |
Alexander von Gluck IV | 400b833 | 2014-12-22 10:10:13 -0500 | [diff] [blame] | 312 | extern "C" |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 313 | const _EGLDriver _eglDriver = { |
Eric Engestrom | d24e3ea | 2020-07-22 01:06:05 +0200 | [diff] [blame] | 314 | .Initialize = init_haiku, |
| 315 | .Terminate = haiku_terminate, |
| 316 | .CreateContext = haiku_create_context, |
| 317 | .DestroyContext = haiku_destroy_context, |
| 318 | .MakeCurrent = haiku_make_current, |
| 319 | .CreateWindowSurface = haiku_create_window_surface, |
| 320 | .CreatePixmapSurface = haiku_create_pixmap_surface, |
| 321 | .CreatePbufferSurface = haiku_create_pbuffer_surface, |
| 322 | .DestroySurface = haiku_destroy_surface, |
| 323 | .SwapBuffers = haiku_swap_buffers, |
| 324 | }; |