Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: client/deps/glbench/src/glx_stuff.cc

Issue 1168005: Initialization cleanups and couple other minor things: (Closed)
Patch Set: fixes Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/deps/glbench/src/egl_stuff.cc ('k') | client/deps/glbench/src/teartest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 7
7 #include "main.h" 8 #include "main.h"
8 #include "xlib_window.h" 9 #include "xlib_window.h"
9 10
10 GLXContext glx_context = NULL; 11 static GLXContext glx_context = NULL;
11 12
12 #define F(fun, type) type fun = NULL; 13 #define F(fun, type) type fun = NULL;
13 LIST_PROC_FUNCTIONS(F) 14 LIST_PROC_FUNCTIONS(F)
14 #undef F 15 #undef F
15 16
16 bool Init() { 17 bool Init() {
17 return XlibInit(); 18 return XlibInit();
18 } 19 }
19 20
21 VisualID GetVisualID() {
22 int screen = DefaultScreen(xlib_display);
23 int attrib[] = {
24 GLX_DOUBLEBUFFER, True,
25 GLX_RED_SIZE, 1,
26 GLX_GREEN_SIZE, 1,
27 GLX_BLUE_SIZE, 1,
28 GLX_DEPTH_SIZE, 1,
29 GLX_STENCIL_SIZE, 1,
30 GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
31 None
32 };
33 int nelements;
34 GLXFBConfig *fbconfigs = glXChooseFBConfig(xlib_display, screen,
35 attrib, &nelements);
36 CHECK(nelements >= 1);
37 int visual_id;
38 glXGetFBConfigAttrib(xlib_display, fbconfigs[0], GLX_VISUAL_ID, &visual_id);
39 XFree(fbconfigs);
40 return static_cast<VisualID>(visual_id);
41 }
42
20 bool InitContext() { 43 bool InitContext() {
21 XWindowAttributes attributes; 44 glx_context = glXCreateContext(xlib_display, xlib_visinfo, 0, True);
22 XGetWindowAttributes(xlib_display, xlib_window, &attributes); 45 if (!glx_context)
23 XVisualInfo visual_info_template;
24 visual_info_template.visualid = XVisualIDFromVisual(attributes.visual);
25 int visual_info_count = 0;
26 XVisualInfo *visual_info_list = XGetVisualInfo(xlib_display, VisualIDMask,
27 &visual_info_template,
28 &visual_info_count);
29 glx_context = 0;
30 for (int i = 0; i < visual_info_count; ++i) {
31 glx_context = glXCreateContext(xlib_display, visual_info_list + i, 0, True);
32 if (glx_context) break;
33 }
34 XFree(visual_info_list);
35 if (!glx_context) {
36 return false; 46 return false;
37 } 47
38 if (!glXMakeCurrent(xlib_display, xlib_window, glx_context)) { 48 if (!glXMakeCurrent(xlib_display, xlib_window, glx_context)) {
39 glXDestroyContext(xlib_display, glx_context); 49 glXDestroyContext(xlib_display, glx_context);
40 return false; 50 return false;
41 } 51 }
42 52
43 glClearColor(1.f, 0, 0, 1.f); 53 glClearColor(1.f, 0, 0, 1.f);
44 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 54 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
45 SwapBuffers(); 55 SwapBuffers();
46 glClearColor(0, 1.f, 0, 1.f); 56 glClearColor(0, 1.f, 0, 1.f);
47 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 57 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
(...skipping 18 matching lines...) Expand all
66 glXDestroyContext(xlib_display, glx_context); 76 glXDestroyContext(xlib_display, glx_context);
67 } 77 }
68 78
69 void SwapBuffers() { 79 void SwapBuffers() {
70 glXSwapBuffers(xlib_display, xlib_window); 80 glXSwapBuffers(xlib_display, xlib_window);
71 } 81 }
72 82
73 bool SwapInterval(int interval) { 83 bool SwapInterval(int interval) {
74 return glXSwapIntervalSGI(interval) == 0; 84 return glXSwapIntervalSGI(interval) == 0;
75 } 85 }
OLDNEW
« no previous file with comments | « client/deps/glbench/src/egl_stuff.cc ('k') | client/deps/glbench/src/teartest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698