File: egl_angle.c

package info (click to toggle)
renpy 7.1.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,352 kB
  • sloc: python: 42,124; ansic: 4,781; makefile: 43; sh: 14
file content (122 lines) | stat: -rw-r--r-- 2,650 bytes parent folder | download
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
#include <stdio.h>
#include <SDL.h>
#include <SDL_syswm.h>
#include "pygame_sdl2/pygame_sdl2.h"
#include "EGL/egl.h"
#include "GLES2/gl2.h"

#include "eglsupport.h"

HWND window;

EGLDisplay display;
EGLSurface surface;
EGLConfig config;
EGLContext context;

int imported_pygame = 0;
int initialized = 0;

char error_message[100];

int egl_available() {
	return 1;
}

// Checks for an EGL error. Returns an error string if there is one,
// or NULL otherwise.
char *egl_error(char *where) {
	EGLint error;

	error = eglGetError();

	if (error == EGL_SUCCESS) {
		return NULL;
	}

	snprintf(error_message, 100, "Error %s (egl error 0x%x)", where, error);
	return error_message;
}

#define egl_check(where) { char *rv = egl_error(where); if (rv) return rv; }

/* Sets up an OpenGL ES 2 context. Returns NULL if it succeeds, or
 * an error message on failure.
 */
char *egl_init(SDL_Window *sdl_window, int interval) {
    SDL_SysWMinfo wminfo;
    EGLint major, minor;
    EGLint num_config;
    HWND new_window;

    const EGLint attrs[] = {
         EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
         EGL_ALPHA_SIZE, 8,
         EGL_NONE
     };

    const EGLint context_attrs[] = {
        EGL_CONTEXT_CLIENT_VERSION, 2,
        EGL_NONE
    };

    if (!imported_pygame) {
    	import_pygame_sdl2();
    	imported_pygame = 1;
    }

    SDL_VERSION(&wminfo.version);
    SDL_GetWindowWMInfo(sdl_window, &wminfo);

    new_window = wminfo.info.win.window;

    if (! initialized) {

    	display = eglGetDisplay(GetDC(new_window));
		egl_check("getting display");

		eglInitialize(display, &major, &minor);
		egl_check("initializing EGL");

		eglBindAPI(EGL_OPENGL_ES_API);
		egl_check("binding OpenGL ES");

		eglChooseConfig(display, attrs, &config, 1, &num_config);
		egl_check("choosing EGL config");

		context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attrs);
		egl_check("creating EGL context");

    	surface = eglCreateWindowSurface(display, config, new_window, NULL);
    	egl_check("creating EGL surface");


    } else if (window != wminfo.info.win.window) {

    	eglDestroySurface(display, surface);
    	egl_check("destroying existing EGL surface")

    	surface = eglCreateWindowSurface(display, config, new_window, NULL);
    	egl_check("creating EGL surface");

    }

	eglMakeCurrent(display, surface, surface, context);
	egl_check("making EGL context current");

    eglSwapInterval(display, interval);
    egl_check("setting swap interval")

	initialized = 1;
	window = new_window;

    return NULL;
}

void egl_swap() {
	eglSwapBuffers(display, surface);
}

void egl_quit() {
	// Does nothing at the moment.
}