egl working with shader!
This commit is contained in:
parent
caed914bcd
commit
c039ddba14
1 changed files with 73 additions and 41 deletions
98
glonkers.c
98
glonkers.c
|
|
@ -167,53 +167,85 @@ wl_registry_listener = {
|
|||
};
|
||||
|
||||
static void egl_init(struct client_state *state) {
|
||||
EGLint major;
|
||||
EGLint minor;
|
||||
EGLint num_configs;
|
||||
EGLint attribs[] = {
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
||||
EGLint major, minor, count, n, size;
|
||||
EGLConfig *configs;
|
||||
int i;
|
||||
EGLint config_attribs[] = {
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
static const EGLint context_attribs[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
state->egl_window = wl_egl_window_create(state->wl_surface, state->width,
|
||||
state->height);
|
||||
|
||||
state->egl_display = eglGetDisplay((EGLNativeDisplayType) state->wl_display);
|
||||
if(state->wl_display == EGL_NO_DISPLAY) {
|
||||
fprintf(stderr, "Couldn't get EGL display\n");
|
||||
exit(EXIT_FAILURE);
|
||||
if (state->egl_display == EGL_NO_DISPLAY) {
|
||||
fprintf(stderr, "Can't create egl display\n");
|
||||
exit(1);
|
||||
} else {
|
||||
fprintf(stderr, "Created egl display\n");
|
||||
}
|
||||
|
||||
if(eglInitialize(state->egl_display, &major, &minor) != EGL_TRUE) {
|
||||
fprintf(stderr, "Couldnt initialize EGL\n");
|
||||
exit(EXIT_FAILURE);
|
||||
if (eglInitialize(state->egl_display, &major, &minor) != EGL_TRUE) {
|
||||
fprintf(stderr, "Can't initialise egl display\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("EGL major: %d, minor %d\n", major, minor);
|
||||
|
||||
eglGetConfigs(state->egl_display, NULL, 0, &count);
|
||||
printf("EGL has %d configs\n", count);
|
||||
|
||||
configs = calloc(count, sizeof *configs);
|
||||
|
||||
eglChooseConfig(state->egl_display, config_attribs,
|
||||
configs, count, &n);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
eglGetConfigAttrib(state->egl_display,
|
||||
configs[i], EGL_BUFFER_SIZE, &size);
|
||||
printf("Buffer size for config %d is %d\n", i, size);
|
||||
eglGetConfigAttrib(state->egl_display,
|
||||
configs[i], EGL_RED_SIZE, &size);
|
||||
printf("Red size for config %d is %d\n", i, size);
|
||||
|
||||
// just choose the first one
|
||||
state->egl_config = configs[i];
|
||||
break;
|
||||
}
|
||||
|
||||
if(eglChooseConfig(state->egl_display, attribs, &state->egl_config, 1,
|
||||
&num_configs) != EGL_TRUE) {
|
||||
fprintf(stderr, "Couldn't find matching EGL config\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
state->egl_surface = eglCreateWindowSurface(state->egl_display,
|
||||
state->egl_context =
|
||||
eglCreateContext(state->egl_display,
|
||||
state->egl_config,
|
||||
(EGLNativeWindowType) state->egl_window, NULL);
|
||||
if(state->egl_surface == EGL_NO_SURFACE) {
|
||||
fprintf(stderr, "Couldn't create EGL surface\n");
|
||||
exit(EXIT_FAILURE);
|
||||
EGL_NO_CONTEXT, context_attribs);
|
||||
|
||||
|
||||
// EGL window
|
||||
state->egl_window = wl_egl_window_create(state->wl_surface,
|
||||
state->width, state->height);
|
||||
if (state->egl_window == EGL_NO_SURFACE) {
|
||||
fprintf(stderr, "Can't create egl window\n");
|
||||
exit(1);
|
||||
} else {
|
||||
fprintf(stderr, "Created egl window\n");
|
||||
}
|
||||
|
||||
state->egl_context = eglCreateContext(state->egl_display, state->egl_config,
|
||||
EGL_NO_CONTEXT, NULL);
|
||||
if(state->egl_context == EGL_NO_CONTEXT) {
|
||||
fprintf(stderr, "Couldn't create EGL context\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
state->egl_surface =
|
||||
eglCreateWindowSurface(state->egl_display,
|
||||
state->egl_config,
|
||||
(unsigned long) state->egl_window, NULL);
|
||||
|
||||
if(!eglMakeCurrent(state->egl_display, state->egl_surface,
|
||||
if (eglMakeCurrent(state->egl_display, state->egl_surface,
|
||||
state->egl_surface, state->egl_context)) {
|
||||
fprintf(stderr, "Couldn't make EGL context current\n");
|
||||
exit(EXIT_FAILURE);
|
||||
fprintf(stderr, "Made current\n");
|
||||
} else {
|
||||
fprintf(stderr, "Made current failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue