aboutsummaryrefslogtreecommitdiff
path: root/include/waffle/waffle.h
blob: c08610c251a03cebd63531eedbfa4573f5d65129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
// Copyright 2012 Intel Corporation
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
//   list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#pragma once

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>

#include "waffle_version.h"

#ifdef __cplusplus
extern "C" {
#endif

#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 301)
#    define WAFFLE_DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#    define WAFFLE_DEPRECATED __declspec(deprecated)
#else
#    define WAFFLE_DEPRECATED
#endif

#if WAFFLE_API_VERSION >= 0x0106
#    define WAFFLE_DEPRECATED_1_06 WAFFLE_DEPRECATED
#else
#    define WAFFLE_DEPRECATED_1_06
#endif

struct waffle_display;
struct waffle_config;
struct waffle_context;
struct waffle_window;

union waffle_native_display;
union waffle_native_config;
union waffle_native_context;
union waffle_native_window;

// ---------------------------------------------------------------------------
// waffle_error
// ---------------------------------------------------------------------------

enum waffle_error {
    WAFFLE_NO_ERROR                                     = 0x00,
    WAFFLE_ERROR_FATAL                                  = 0x01,
    WAFFLE_ERROR_UNKNOWN                                = 0x02,
    WAFFLE_ERROR_INTERNAL                               = 0x03,
    WAFFLE_ERROR_BAD_ALLOC                              = 0x04,
    WAFFLE_ERROR_NOT_INITIALIZED                        = 0x05,
    WAFFLE_ERROR_ALREADY_INITIALIZED                    = 0x06,
    WAFFLE_ERROR_BAD_ATTRIBUTE                          = 0x08,
    WAFFLE_ERROR_BAD_PARAMETER                          = 0x10,
    WAFFLE_ERROR_BAD_DISPLAY_MATCH                      = 0x11,
    WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM                = 0x12,
    WAFFLE_ERROR_BUILT_WITHOUT_SUPPORT                  = 0x13,
};

struct waffle_error_info {
    enum waffle_error code;
    const char *message;
    size_t message_length;
};

enum waffle_error
waffle_error_get_code(void);

const struct waffle_error_info*
waffle_error_get_info(void);

const char*
waffle_error_to_string(enum waffle_error e);

// ---------------------------------------------------------------------------
// waffle_enum
// ---------------------------------------------------------------------------

enum waffle_enum {
    // ------------------------------------------------------------------
    // Generic
    // ------------------------------------------------------------------

    WAFFLE_DONT_CARE                                            = -1,
    WAFFLE_NONE                                                 =  0,

    // ------------------------------------------------------------------
    // For waffle_init()
    // ------------------------------------------------------------------

    WAFFLE_PLATFORM                                             = 0x0010,
        WAFFLE_PLATFORM_ANDROID                                 = 0x0011,
        WAFFLE_PLATFORM_CGL                                     = 0x0012,
        WAFFLE_PLATFORM_GLX                                     = 0x0013,
        WAFFLE_PLATFORM_WAYLAND                                 = 0x0014,
        WAFFLE_PLATFORM_X11_EGL                                 = 0x0015,
        WAFFLE_PLATFORM_GBM                                     = 0x0016,
        WAFFLE_PLATFORM_WGL                                     = 0x0017,
        WAFFLE_PLATFORM_NACL                                    = 0x0018,

    // ------------------------------------------------------------------
    // For waffle_config_choose()
    // ------------------------------------------------------------------

    WAFFLE_CONTEXT_API                                          = 0x020a,
        WAFFLE_CONTEXT_OPENGL                                   = 0x020b,
        WAFFLE_CONTEXT_OPENGL_ES1                               = 0x020c,
        WAFFLE_CONTEXT_OPENGL_ES2                               = 0x020d,
        WAFFLE_CONTEXT_OPENGL_ES3                               = 0x0214,

    WAFFLE_CONTEXT_MAJOR_VERSION                                = 0x020e,
    WAFFLE_CONTEXT_MINOR_VERSION                                = 0x020f,

    WAFFLE_CONTEXT_PROFILE                                      = 0x0210,
        WAFFLE_CONTEXT_CORE_PROFILE                             = 0x0211,
        WAFFLE_CONTEXT_COMPATIBILITY_PROFILE                    = 0x0212,

#if WAFFLE_API_VERSION >= 0x0103
    WAFFLE_CONTEXT_FORWARD_COMPATIBLE                           = 0x0215,
    WAFFLE_CONTEXT_DEBUG                                        = 0x0216,
#endif

    WAFFLE_RED_SIZE                                             = 0x0201,
    WAFFLE_GREEN_SIZE                                           = 0x0202,
    WAFFLE_BLUE_SIZE                                            = 0x0203,
    WAFFLE_ALPHA_SIZE                                           = 0x0204,

    WAFFLE_DEPTH_SIZE                                           = 0x0205,
    WAFFLE_STENCIL_SIZE                                         = 0x0206,

    WAFFLE_SAMPLE_BUFFERS                                       = 0x0207,
    WAFFLE_SAMPLES                                              = 0x0208,

    WAFFLE_DOUBLE_BUFFERED                                      = 0x0209,

    WAFFLE_ACCUM_BUFFER                                         = 0x0213,

    // ------------------------------------------------------------------
    // For waffle_dl_sym()
    // ------------------------------------------------------------------

    WAFFLE_DL_OPENGL                                            = 0x0301,
    WAFFLE_DL_OPENGL_ES1                                        = 0x0302,
    WAFFLE_DL_OPENGL_ES2                                        = 0x0303,
    WAFFLE_DL_OPENGL_ES3                                        = 0x0304,

    // ------------------------------------------------------------------
    // For waffle_window
    // ------------------------------------------------------------------

    WAFFLE_WINDOW_WIDTH                                         = 0x0310,
    WAFFLE_WINDOW_HEIGHT                                        = 0x0311,
};

const char*
waffle_enum_to_string(int32_t e);

// ---------------------------------------------------------------------------

bool
waffle_init(const int32_t *attrib_list);

#if WAFFLE_API_VERSION >= 0x0106
bool
waffle_teardown(void);
#endif

bool
waffle_make_current(struct waffle_display *dpy,
                    struct waffle_window *window,
                    struct waffle_context *ctx);

void*
waffle_get_proc_address(const char *name);

bool
waffle_is_extension_in_string(const char *extension_string,
                              const char *extension_name);

// ---------------------------------------------------------------------------
// waffle_display
// ---------------------------------------------------------------------------

struct waffle_display*
waffle_display_connect(const char *name);

bool
waffle_display_disconnect(struct waffle_display *self);

bool
waffle_display_supports_context_api(struct waffle_display *self,
                                    int32_t context_api);

bool
waffle_display_print_info(struct waffle_display *self, bool verbose);

union waffle_native_display*
waffle_display_get_native(struct waffle_display *self);

// ---------------------------------------------------------------------------
// waffle_config
// ---------------------------------------------------------------------------

struct waffle_config*
waffle_config_choose(struct waffle_display *dpy,
                     const int32_t attrib_list[]);

bool
waffle_config_destroy(struct waffle_config *self);

union waffle_native_config*
waffle_config_get_native(struct waffle_config *self);

// ---------------------------------------------------------------------------
// waffle_context
// ---------------------------------------------------------------------------

struct waffle_context*
waffle_context_create(struct waffle_config *config,
                      struct waffle_context *shared_ctx);

bool
waffle_context_destroy(struct waffle_context *self);

union waffle_native_context*
waffle_context_get_native(struct waffle_context *self);

// ---------------------------------------------------------------------------
// waffle_window
// ---------------------------------------------------------------------------

#if WAFFLE_API_VERSION >= 0x0106
struct waffle_window*
waffle_window_create2(
        struct waffle_config *config,
        const intptr_t attrib_list[]);
#endif

struct waffle_window*
waffle_window_create(
        struct waffle_config *config,
        int32_t width,
        int32_t height);

bool
waffle_window_destroy(struct waffle_window *self);

bool
waffle_window_show(struct waffle_window *self);

bool
waffle_window_swap_buffers(struct waffle_window *self);

union waffle_native_window*
waffle_window_get_native(struct waffle_window *self);

#if defined(WAFFLE_API_EXPERIMENTAL) && WAFFLE_API_VERSION >= 0x0103
bool
waffle_window_resize(
        struct waffle_window *self,
        int32_t width,
        int32_t height);
#endif

// ---------------------------------------------------------------------------
// waffle_dl
// ---------------------------------------------------------------------------

bool
waffle_dl_can_open(int32_t dl);

void*
waffle_dl_sym(int32_t dl, const char *name);

// ---------------------------------------------------------------------------
// waffle_native
// ---------------------------------------------------------------------------

struct waffle_gbm_config;
struct waffle_gbm_context;
struct waffle_gbm_display;
struct waffle_gbm_window;
struct waffle_glx_config;
struct waffle_glx_context;
struct waffle_glx_display;
struct waffle_glx_window;
struct waffle_wayland_config;
struct waffle_wayland_context;
struct waffle_wayland_display;
struct waffle_wayland_window;
struct waffle_x11_egl_config;
struct waffle_x11_egl_context;
struct waffle_x11_egl_display;
struct waffle_x11_egl_window;

union waffle_native_display {
    struct waffle_gbm_display *gbm;
    struct waffle_glx_display *glx;
    struct waffle_x11_egl_display *x11_egl;
    struct waffle_wayland_display *wayland;
};

union waffle_native_config {
    struct waffle_gbm_config *gbm;
    struct waffle_glx_config *glx;
    struct waffle_x11_egl_config *x11_egl;
    struct waffle_wayland_config *wayland;
};

union waffle_native_context {
    struct waffle_gbm_context *gbm;
    struct waffle_glx_context *glx;
    struct waffle_x11_egl_context *x11_egl;
    struct waffle_wayland_context *wayland;
};

union waffle_native_window {
    struct waffle_gbm_window *gbm;
    struct waffle_glx_window *glx;
    struct waffle_x11_egl_window *x11_egl;
    struct waffle_wayland_window *wayland;
};

// ---------------------------------------------------------------------------
// waffle_attrib_list
// ---------------------------------------------------------------------------

WAFFLE_DEPRECATED_1_06 int32_t
waffle_attrib_list_length(const int32_t attrib_list[]);

WAFFLE_DEPRECATED_1_06 bool
waffle_attrib_list_get(
        const int32_t attrib_list[],
        int32_t key,
        int32_t *value);

WAFFLE_DEPRECATED_1_06 bool
waffle_attrib_list_get_with_default(
        const int32_t attrib_list[],
        int32_t key,
        int32_t *value,
        int32_t default_value);

WAFFLE_DEPRECATED_1_06 bool
waffle_attrib_list_update(
        int32_t *attrib_list,
        int32_t key,
        int32_t value);

#ifdef __cplusplus
} // end extern "C"
#endif