summaryrefslogtreecommitdiff
path: root/common.c
diff options
context:
space:
mode:
authorRob Clark <robdclark@gmail.com>2017-02-21 12:39:54 -0500
committerRob Clark <robdclark@gmail.com>2017-02-21 14:34:26 -0500
commitf42ba05ef0fb3a5aea77b3cdd788d21ed92f677e (patch)
tree1b90838a2b709a5bdedcdc7be8148a9c4320e581 /common.c
parent2ec69c153a5456758c924e14e70d6544e4d2a866 (diff)
downloadkmscube-f42ba05ef0fb3a5aea77b3cdd788d21ed92f677e.tar.gz
split out smooth-shaded cube
Diffstat (limited to 'common.c')
-rw-r--r--common.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/common.c b/common.c
index ee6b23f..a28cb09 100644
--- a/common.c
+++ b/common.c
@@ -40,10 +40,89 @@ const struct gbm * init_gbm(int drm_fd, int w, int h)
return NULL;
}
+ gbm.width = w;
+ gbm.height = h;
+
return &gbm;
}
+int init_egl(struct egl *egl, const struct gbm *gbm)
+{
+ EGLint major, minor, n;
+
+ static const EGLint context_attribs[] = {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE
+ };
+
+ static const EGLint config_attribs[] = {
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_RED_SIZE, 1,
+ EGL_GREEN_SIZE, 1,
+ EGL_BLUE_SIZE, 1,
+ EGL_ALPHA_SIZE, 0,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_NONE
+ };
+
+#define get_proc(name) do { \
+ egl->name = (void *)eglGetProcAddress(#name); \
+ } while (0)
+
+ get_proc(eglGetPlatformDisplayEXT);
+
+ if (egl->eglGetPlatformDisplayEXT) {
+ egl->display = egl->eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR,
+ gbm->dev, NULL);
+ } else {
+ egl->display = eglGetDisplay((void *)gbm->dev);
+ }
+
+ if (!eglInitialize(egl->display, &major, &minor)) {
+ printf("failed to initialize\n");
+ return -1;
+ }
+
+ printf("Using display %p with EGL version %d.%d\n",
+ egl->display, major, minor);
+
+ printf("EGL Version \"%s\"\n", eglQueryString(egl->display, EGL_VERSION));
+ printf("EGL Vendor \"%s\"\n", eglQueryString(egl->display, EGL_VENDOR));
+ printf("EGL Extensions \"%s\"\n", eglQueryString(egl->display, EGL_EXTENSIONS));
+
+ if (!eglBindAPI(EGL_OPENGL_ES_API)) {
+ printf("failed to bind api EGL_OPENGL_ES_API\n");
+ return -1;
+ }
+
+ if (!eglChooseConfig(egl->display, config_attribs, &egl->config, 1, &n) || n != 1) {
+ printf("failed to choose config: %d\n", n);
+ return -1;
+ }
+
+ egl->context = eglCreateContext(egl->display, egl->config,
+ EGL_NO_CONTEXT, context_attribs);
+ if (egl->context == NULL) {
+ printf("failed to create context\n");
+ return -1;
+ }
+
+ egl->surface = eglCreateWindowSurface(egl->display, egl->config,
+ (EGLNativeWindowType)gbm->surface, NULL);
+ if (egl->surface == EGL_NO_SURFACE) {
+ printf("failed to create egl surface\n");
+ return -1;
+ }
+
+ /* connect the context to the surface */
+ eglMakeCurrent(egl->display, egl->surface, egl->surface, egl->context);
+
+ printf("GL Extensions: \"%s\"\n", glGetString(GL_EXTENSIONS));
+
+ return 0;
+}
+
int create_program(const char *vs_src, const char *fs_src)
{
GLuint vertex_shader, fragment_shader, program;