OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <EGL/egl.h> | 5 #include <EGL/egl.h> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "main.h" | 8 #include "main.h" |
9 #include "xlib_window.h" | 9 #include "xlib_window.h" |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 XVisualInfo* GetXVisual() { | 33 XVisualInfo* GetXVisual() { |
34 if (!egl_config) { | 34 if (!egl_config) { |
35 EGLint attribs[] = { | 35 EGLint attribs[] = { |
36 EGL_RED_SIZE, 1, | 36 EGL_RED_SIZE, 1, |
37 EGL_GREEN_SIZE, 1, | 37 EGL_GREEN_SIZE, 1, |
38 EGL_BLUE_SIZE, 1, | 38 EGL_BLUE_SIZE, 1, |
39 EGL_DEPTH_SIZE, 1, | 39 EGL_DEPTH_SIZE, 1, |
40 EGL_STENCIL_SIZE, 1, | 40 EGL_STENCIL_SIZE, 1, |
41 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, | 41 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 42 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
42 EGL_NONE | 43 EGL_NONE |
43 }; | 44 }; |
44 | 45 |
45 EGLNativeDisplayType native_display = | 46 EGLNativeDisplayType native_display = |
46 static_cast<EGLNativeDisplayType>(g_xlib_display); | 47 static_cast<EGLNativeDisplayType>(g_xlib_display); |
47 | 48 |
48 egl_display = eglGetDisplay(native_display); | 49 egl_display = eglGetDisplay(native_display); |
49 CHECK_EGL(); | 50 CHECK_EGL(); |
50 | 51 |
51 eglInitialize(egl_display, NULL, NULL); | 52 eglInitialize(egl_display, NULL, NULL); |
52 CHECK_EGL(); | 53 CHECK_EGL(); |
53 | 54 |
54 EGLint num_configs = -1; | 55 EGLint num_configs = -1; |
55 eglGetConfigs(egl_display, NULL, 0, &num_configs); | 56 eglGetConfigs(egl_display, NULL, 0, &num_configs); |
56 CHECK_EGL(); | 57 CHECK_EGL(); |
57 | 58 |
58 eglChooseConfig(egl_display, attribs, &egl_config, 1, &num_configs); | 59 eglChooseConfig(egl_display, attribs, &egl_config, 1, &num_configs); |
59 CHECK_EGL(); | 60 CHECK_EGL(); |
60 } | 61 } |
61 | 62 |
| 63 // TODO: for some reason on some systems EGL_NATIVE_VISUAL_ID returns an ID |
| 64 // that XVisualIDFromVisual cannot find. Use default visual until this is |
| 65 // resolved. |
| 66 #if 0 |
62 EGLint visual_id; | 67 EGLint visual_id; |
63 eglGetConfigAttrib(egl_display, egl_config, EGL_NATIVE_VISUAL_ID, &visual_id); | 68 eglGetConfigAttrib(egl_display, egl_config, EGL_NATIVE_VISUAL_ID, &visual_id); |
64 CHECK_EGL(); | 69 CHECK_EGL(); |
65 | |
66 XVisualInfo vinfo_template; | 70 XVisualInfo vinfo_template; |
67 vinfo_template.visualid = static_cast<VisualID>(visual_id); | 71 vinfo_template.visualid = static_cast<VisualID>(visual_id); |
| 72 #else |
| 73 XVisualInfo vinfo_template; |
| 74 vinfo_template.visualid = XVisualIDFromVisual(DefaultVisual( |
| 75 g_xlib_display, DefaultScreen(g_xlib_display))); |
| 76 #endif |
| 77 |
68 int nitems = 0; | 78 int nitems = 0; |
69 XVisualInfo* ret = XGetVisualInfo(g_xlib_display, VisualIDMask, | 79 XVisualInfo* ret = XGetVisualInfo(g_xlib_display, VisualIDMask, |
70 &vinfo_template, &nitems); | 80 &vinfo_template, &nitems); |
71 CHECK(nitems == 1); | 81 CHECK(nitems == 1); |
72 return ret; | 82 return ret; |
73 } | 83 } |
74 | 84 |
75 bool InitContext() { | 85 bool InitContext() { |
| 86 EGLint attribs[] = { |
| 87 EGL_CONTEXT_CLIENT_VERSION, 2, |
| 88 EGL_NONE |
| 89 }; |
76 EGLContext egl_context = eglCreateContext(egl_display, egl_config, | 90 EGLContext egl_context = eglCreateContext(egl_display, egl_config, |
77 NULL, NULL); | 91 NULL, attribs); |
78 CHECK_EGL(); | 92 CHECK_EGL(); |
79 | 93 |
80 eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context); | 94 eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context); |
81 CHECK_EGL(); | 95 CHECK_EGL(); |
82 | 96 |
83 eglQuerySurface(egl_display, egl_surface, EGL_WIDTH, &g_width); | 97 eglQuerySurface(egl_display, egl_surface, EGL_WIDTH, &g_width); |
84 eglQuerySurface(egl_display, egl_surface, EGL_HEIGHT, &g_height); | 98 eglQuerySurface(egl_display, egl_surface, EGL_HEIGHT, &g_height); |
85 | 99 |
86 #ifndef USE_EGL | |
87 glMatrixMode(GL_MODELVIEW); | |
88 glLoadIdentity(); | |
89 #endif | |
90 | |
91 return true; | 100 return true; |
92 } | 101 } |
93 | 102 |
94 void DestroyContext() { | 103 void DestroyContext() { |
95 eglMakeCurrent(egl_display, NULL, NULL, NULL); | 104 eglMakeCurrent(egl_display, NULL, NULL, NULL); |
96 eglDestroyContext(egl_display, egl_context); | 105 eglDestroyContext(egl_display, egl_context); |
97 } | 106 } |
98 | 107 |
99 void TerminateGL() { | 108 void TerminateGL() { |
100 eglDestroySurface(egl_display, egl_surface); | 109 eglDestroySurface(egl_display, egl_surface); |
101 eglTerminate(egl_display); | 110 eglTerminate(egl_display); |
102 } | 111 } |
103 | 112 |
104 void SwapBuffers() { | 113 void SwapBuffers() { |
105 eglSwapBuffers(egl_display, egl_surface); | 114 eglSwapBuffers(egl_display, egl_surface); |
106 } | 115 } |
107 | 116 |
108 bool SwapInterval(int interval) { | 117 bool SwapInterval(int interval) { |
109 return eglSwapInterval(egl_display, interval) == EGL_TRUE; | 118 return eglSwapInterval(egl_display, interval) == EGL_TRUE; |
110 } | 119 } |
OLD | NEW |