Evas_GL_Wl_Window * eng_window_new(struct wl_display *disp, struct wl_surface *surface, int screen, int depth, int w, int h, int indirect, int alpha, int rot) { Evas_GL_Wl_Window *gw; int context_attrs[3]; int config_attrs[40]; int major_version, minor_version; int num_config, n = 0; const GLubyte *vendor, *renderer, *version; gw = calloc(1, sizeof(Evas_GL_Wl_Window)); if (!gw) return NULL; win_count++; gw->disp = disp; gw->surface = surface; gw->screen = screen; gw->depth = depth; gw->alpha = alpha; gw->w = w; gw->h = h; gw->rot = rot; // EGL / GLES context_attrs[0] = EGL_CONTEXT_CLIENT_VERSION; context_attrs[1] = 2; context_attrs[2] = EGL_NONE; #if defined(GLES_VARIETY_S3C6410) if (gw->visualinfo->depth == 16) // 16bpp { config_attrs[n++] = EGL_SURFACE_TYPE; config_attrs[n++] = EGL_WINDOW_BIT; config_attrs[n++] = EGL_RENDERABLE_TYPE; config_attrs[n++] = EGL_OPENGL_ES2_BIT; config_attrs[n++] = EGL_RED_SIZE; config_attrs[n++] = 5; config_attrs[n++] = EGL_GREEN_SIZE; config_attrs[n++] = 6; config_attrs[n++] = EGL_BLUE_SIZE; config_attrs[n++] = 5; config_attrs[n++] = EGL_DEPTH_SIZE; config_attrs[n++] = 0; config_attrs[n++] = EGL_STENCIL_SIZE; config_attrs[n++] = 0; config_attrs[n++] = EGL_NONE; } else // 24/32bit. no one does 8bpp anymore. and 15bpp... dead { config_attrs[n++] = EGL_SURFACE_TYPE; config_attrs[n++] = EGL_WINDOW_BIT; config_attrs[n++] = EGL_RENDERABLE_TYPE; config_attrs[n++] = EGL_OPENGL_ES2_BIT; config_attrs[n++] = EGL_RED_SIZE; config_attrs[n++] = 8; config_attrs[n++] = EGL_GREEN_SIZE; config_attrs[n++] = 8; config_attrs[n++] = EGL_BLUE_SIZE; config_attrs[n++] = 8; config_attrs[n++] = EGL_DEPTH_SIZE; config_attrs[n++] = 0; config_attrs[n++] = EGL_STENCIL_SIZE; config_attrs[n++] = 0; config_attrs[n++] = EGL_NONE; } #elif defined(GLES_VARIETY_SGX) config_attrs[n++] = EGL_SURFACE_TYPE; config_attrs[n++] = EGL_WINDOW_BIT; config_attrs[n++] = EGL_RENDERABLE_TYPE; config_attrs[n++] = EGL_OPENGL_ES2_BIT; # if 0 // FIXME: n900 - omap3 sgx libs break here config_attrs[n++] = EGL_RED_SIZE; config_attrs[n++] = 1; config_attrs[n++] = EGL_GREEN_SIZE; config_attrs[n++] = 1; config_attrs[n++] = EGL_BLUE_SIZE; config_attrs[n++] = 1; // FIXME: end n900 breakage # endif if (gw->alpha) { config_attrs[n++] = EGL_ALPHA_SIZE; config_attrs[n++] = 1; } else { config_attrs[n++] = EGL_ALPHA_SIZE; config_attrs[n++] = 0; } config_attrs[n++] = EGL_DEPTH_SIZE; config_attrs[n++] = 0; config_attrs[n++] = EGL_STENCIL_SIZE; config_attrs[n++] = 0; config_attrs[n++] = EGL_NONE; #endif gw->egl_disp = eglGetDisplay((EGLNativeDisplayType)(gw->disp)); if (!gw->egl_disp) { ERR("eglGetDisplay() fail. code=%#x", eglGetError()); eng_window_free(gw); return NULL; } if (!eglInitialize(gw->egl_disp, &major_version, &minor_version)) { ERR("eglInitialize() fail. code=%#x", eglGetError()); eng_window_free(gw); return NULL; } eglBindAPI(EGL_OPENGL_ES_API); if (eglGetError() != EGL_SUCCESS) { ERR("eglBindAPI() fail. code=%#x", eglGetError()); eng_window_free(gw); return NULL; } num_config = 0; if (!eglChooseConfig(gw->egl_disp, config_attrs, &gw->egl_config, 1, &num_config) || (num_config != 1)) { ERR("eglChooseConfig() fail. code=%#x", eglGetError()); eng_window_free(gw); return NULL; } gw->win = wl_egl_window_create(gw->surface, gw->w, gw->h); gw->egl_surface[0] = eglCreateWindowSurface(gw->egl_disp, gw->egl_config, (EGLNativeWindowType)gw->win, NULL); if (gw->egl_surface[0] == EGL_NO_SURFACE) { ERR("eglCreateWindowSurface() fail for %p. code=%#x", gw->win, eglGetError()); eng_window_free(gw); return NULL; } if (context == EGL_NO_CONTEXT) context = eglCreateContext(gw->egl_disp, gw->egl_config, NULL, context_attrs); gw->egl_context[0] = context; if (gw->egl_context[0] == EGL_NO_CONTEXT) { ERR("eglCreateContext() fail. code=%#x", eglGetError()); eng_window_free(gw); return NULL; } if (eglMakeCurrent(gw->egl_disp, gw->egl_surface[0], gw->egl_surface[0], gw->egl_context[0]) == EGL_FALSE) { ERR("eglMakeCurrent() fail. code=%#x", eglGetError()); eng_window_free(gw); return NULL; } vendor = glGetString(GL_VENDOR); renderer = glGetString(GL_RENDERER); version = glGetString(GL_VERSION); if (!vendor) vendor = (unsigned char *)"-UNKNOWN-"; if (!renderer) renderer = (unsigned char *)"-UNKNOWN-"; if (!version) version = (unsigned char *)"-UNKNOWN-"; if (getenv("EVAS_GL_INFO")) { fprintf(stderr, "vendor: %s\n", vendor); fprintf(stderr, "renderer: %s\n", renderer); fprintf(stderr, "version: %s\n", version); } gw->gl_context = evas_gl_common_context_new(); if (!gw->gl_context) { eng_window_free(gw); return NULL; } gw->gl_context->egldisp = gw->egl_disp; eng_window_use(gw); evas_gl_common_context_resize(gw->gl_context, w, h, rot); gw->surf = 1; return gw; indirect = 0; }
Evas_GL_Glew_Window * eng_window_new(HWND window, int depth, int width, int height) { PIXELFORMATDESCRIPTOR pfd; Evas_GL_Glew_Window *gw; int format; gw = calloc(1, sizeof(Evas_GL_Glew_Window)); if (!gw) return NULL; gw->window = window; gw->depth = depth; gw->dc = GetDC(window); if (!gw->dc) goto free_window; ZeroMemory(&pfd, sizeof (pfd)); pfd.nSize = sizeof (pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 32; pfd.iLayerType = PFD_MAIN_PLANE; format = ChoosePixelFormat(gw->dc, &pfd); if (!format) goto release_dc; SetPixelFormat(gw->dc, format, &pfd); if (pfd.iPixelType != PFD_TYPE_RGBA) goto release_dc; gw->context = wglCreateContext(gw->dc); if (!gw->context) goto release_dc; wglMakeCurrent(gw->dc, gw->context); if (glewInit() != GLEW_OK) goto delete_context; if (!GLEW_VERSION_2_0) { ERR("OpenGL 2.0 not supported. Exiting..."); goto delete_context; } _evas_gl_glew_window = gw; gw->gl_context = evas_gl_common_context_new(); if (!gw->gl_context) goto delete_context; evas_gl_common_context_resize(gw->gl_context, width, height); return gw; delete_context: wglMakeCurrent(NULL, NULL); wglDeleteContext(gw->context); release_dc: ReleaseDC(window, gw->dc); free_window: free(gw); return NULL; }