OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium 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 <GL/glew.h> | |
6 | |
7 #include "app/gfx/gl/gl_context.h" | 5 #include "app/gfx/gl/gl_context.h" |
| 6 #include "app/gfx/gl/gl_bindings.h" |
| 7 #include "app/gfx/gl/gl_implementation.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 | 9 |
10 namespace gfx { | 10 namespace gfx { |
11 | 11 |
12 // GLEW initialization is extremely expensive because it looks up | |
13 // hundreds of function pointers. Realistically we are not going to | |
14 // switch between GL implementations on the fly, so for the time being | |
15 // we only do the context-dependent GLEW initialization once. | |
16 bool InitializeGLEW() { | |
17 #if defined(UNIT_TEST) | |
18 return true; | |
19 #else | |
20 static bool initialized = false; | |
21 if (initialized) | |
22 return true; | |
23 | |
24 // Initializes context-dependent parts of GLEW. | |
25 if (glewInit() != GLEW_OK) { | |
26 LOG(ERROR) << "GLEW failed initialization"; | |
27 return false; | |
28 } | |
29 | |
30 // Check to see that we can use the OpenGL vertex attribute APIs | |
31 // TODO(petersont): Return false if this check fails, but because some | |
32 // Intel hardware does not support OpenGL 2.0, yet does support all of the | |
33 // extensions we require, we only log an error. A future CL should change | |
34 // this check to ensure that all of the extension strings we require are | |
35 // present. | |
36 if (!GLEW_VERSION_2_0) { | |
37 DLOG(ERROR) << "GL drivers do not have OpenGL 2.0 functionality."; | |
38 } | |
39 | |
40 // Check for necessary extensions. | |
41 bool extensions_found = true; | |
42 if (!GLEW_ARB_vertex_buffer_object) { | |
43 // NOTE: Linux NVidia drivers claim to support OpenGL 2.0 when using | |
44 // indirect rendering (e.g. remote X), but it is actually lying. The | |
45 // ARB_vertex_buffer_object functions silently no-op (!) when using | |
46 // indirect rendering, leading to crashes. Fortunately, in that case, the | |
47 // driver claims to not support ARB_vertex_buffer_object, so fail in that | |
48 // case. | |
49 DLOG(ERROR) << "GL drivers do not support vertex buffer objects."; | |
50 extensions_found = false; | |
51 } | |
52 if (!GLEW_EXT_framebuffer_object) { | |
53 DLOG(ERROR) << "GL drivers do not support framebuffer objects."; | |
54 extensions_found = false; | |
55 } | |
56 if (!GLEW_VERSION_2_0 && !GLEW_EXT_stencil_two_side) { | |
57 DLOG(ERROR) << "Two sided stencil extension missing."; | |
58 extensions_found = false; | |
59 } | |
60 if (!GLEW_VERSION_1_4 && !GLEW_EXT_blend_func_separate) { | |
61 DLOG(ERROR) <<"Separate blend func extension missing."; | |
62 extensions_found = false; | |
63 } | |
64 if (!GLEW_VERSION_2_0 && !GLEW_EXT_blend_equation_separate) { | |
65 DLOG(ERROR) << "Separate blend function extension missing."; | |
66 extensions_found = false; | |
67 } | |
68 if (!extensions_found) | |
69 return false; | |
70 | |
71 initialized = true; | |
72 return true; | |
73 #endif | |
74 } | |
75 | |
76 bool GLContext::InitializeCommon() { | 12 bool GLContext::InitializeCommon() { |
77 if (!MakeCurrent()) | 13 if (!MakeCurrent()) |
78 return false; | 14 return false; |
79 | 15 |
80 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | 16 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
81 if (glGetError() != GL_NO_ERROR) | 17 if (glGetError() != GL_NO_ERROR) |
82 return false; | 18 return false; |
83 | 19 |
84 return true; | 20 return true; |
85 } | 21 } |
86 } // namespace gfx | 22 } // namespace gfx |
OLD | NEW |