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 <string.h> | 5 #include <string.h> |
6 #include <GL/glx.h> | 6 #include <GL/glx.h> |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "main.h" | 9 #include "main.h" |
10 #include "xlib_window.h" | 10 #include "xlib_window.h" |
11 | 11 |
12 static GLXContext glx_context = NULL; | 12 static GLXContext glx_context = NULL; |
| 13 static GLXFBConfig glx_fbconfig = NULL; |
13 | 14 |
14 #define F(fun, type) type fun = NULL; | 15 #define F(fun, type) type fun = NULL; |
15 LIST_PROC_FUNCTIONS(F) | 16 LIST_PROC_FUNCTIONS(F) |
16 #undef F | 17 #undef F |
17 | 18 |
18 bool Init() { | 19 bool Init() { |
19 return XlibInit(); | 20 return XlibInit(); |
20 } | 21 } |
21 | 22 |
22 VisualID GetVisualID() { | 23 XVisualInfo* GetXVisual() { |
23 int screen = DefaultScreen(g_xlib_display); | 24 if (!glx_fbconfig) { |
24 int attrib[] = { | 25 int screen = DefaultScreen(g_xlib_display); |
25 GLX_DOUBLEBUFFER, True, | 26 int attrib[] = { |
26 GLX_RED_SIZE, 1, | 27 GLX_DOUBLEBUFFER, True, |
27 GLX_GREEN_SIZE, 1, | 28 GLX_RED_SIZE, 1, |
28 GLX_BLUE_SIZE, 1, | 29 GLX_GREEN_SIZE, 1, |
29 GLX_DEPTH_SIZE, 1, | 30 GLX_BLUE_SIZE, 1, |
30 GLX_STENCIL_SIZE, 1, | 31 GLX_DEPTH_SIZE, 1, |
31 GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, | 32 GLX_STENCIL_SIZE, 1, |
32 None | 33 GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, |
33 }; | 34 None |
34 int nelements; | 35 }; |
35 GLXFBConfig *fbconfigs = glXChooseFBConfig(g_xlib_display, screen, | 36 int nelements; |
36 attrib, &nelements); | 37 GLXFBConfig *fbconfigs = glXChooseFBConfig(g_xlib_display, screen, |
37 CHECK(nelements >= 1); | 38 attrib, &nelements); |
38 int visual_id; | 39 CHECK(nelements >= 1); |
39 glXGetFBConfigAttrib(g_xlib_display, fbconfigs[0], GLX_VISUAL_ID, &visual_id); | 40 glx_fbconfig = fbconfigs[0]; |
40 XFree(fbconfigs); | 41 XFree(fbconfigs); |
41 return static_cast<VisualID>(visual_id); | 42 } |
| 43 |
| 44 return glXGetVisualFromFBConfig(g_xlib_display, glx_fbconfig); |
42 } | 45 } |
43 | 46 |
44 bool InitContext() { | 47 bool InitContext() { |
45 glx_context = glXCreateContext(g_xlib_display, g_xlib_visinfo, 0, True); | 48 glx_context = glXCreateNewContext(g_xlib_display, glx_fbconfig, |
| 49 GLX_RGBA_TYPE, 0, True); |
46 if (!glx_context) | 50 if (!glx_context) |
47 return false; | 51 return false; |
48 | 52 |
49 if (!glXMakeCurrent(g_xlib_display, g_xlib_window, glx_context)) { | 53 if (!glXMakeCurrent(g_xlib_display, g_xlib_window, glx_context)) { |
50 glXDestroyContext(g_xlib_display, glx_context); | 54 glXDestroyContext(g_xlib_display, glx_context); |
51 return false; | 55 return false; |
52 } | 56 } |
53 | 57 |
54 glClearColor(1.f, 0, 0, 1.f); | 58 glClearColor(1.f, 0, 0, 1.f); |
55 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); | 59 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); |
(...skipping 21 matching lines...) Expand all Loading... |
77 glXDestroyContext(g_xlib_display, glx_context); | 81 glXDestroyContext(g_xlib_display, glx_context); |
78 } | 82 } |
79 | 83 |
80 void SwapBuffers() { | 84 void SwapBuffers() { |
81 glXSwapBuffers(g_xlib_display, g_xlib_window); | 85 glXSwapBuffers(g_xlib_display, g_xlib_window); |
82 } | 86 } |
83 | 87 |
84 bool SwapInterval(int interval) { | 88 bool SwapInterval(int interval) { |
85 return glXSwapIntervalSGI(interval) == 0; | 89 return glXSwapIntervalSGI(interval) == 0; |
86 } | 90 } |
OLD | NEW |