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

Side by Side Diff: src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp

Issue 12328111: Use glGetStringi to get extensions when available. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "gl/GrGLExtensions.h"
10 #include "gl/GrGLInterface.h" 11 #include "gl/GrGLInterface.h"
11 #include "../GrGLUtil.h" 12 #include "../GrGLUtil.h"
12 13
13 #include <GL/glx.h> 14 #include <GL/glx.h>
14 #include <GL/gl.h> 15 #include <GL/gl.h>
15 #include <GL/glext.h> 16 #include <GL/glext.h>
16 #include <GL/glu.h> 17 #include <GL/glu.h>
17 18
18 #define GR_GL_GET_PROC(F) interface->f ## F = (GrGL ## F ## Proc) \ 19 #define GR_GL_GET_PROC(F) interface->f ## F = (GrGL ## F ## Proc) \
19 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F)); 20 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F));
20 #define GR_GL_GET_PROC_SUFFIX(F, S) interface->f ## F = (GrGL ## F ## Proc) \ 21 #define GR_GL_GET_PROC_SUFFIX(F, S) interface->f ## F = (GrGL ## F ## Proc) \
21 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F #S)); 22 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F #S));
22 23
23 const GrGLInterface* GrGLCreateNativeInterface() { 24 const GrGLInterface* GrGLCreateNativeInterface() {
24 if (NULL != glXGetCurrentContext()) { 25 if (NULL != glXGetCurrentContext()) {
26
25 const char* versionString = (const char*) glGetString(GL_VERSION); 27 const char* versionString = (const char*) glGetString(GL_VERSION);
26 const char* extString = (const char*) glGetString(GL_EXTENSIONS);
27 GrGLVersion glVer = GrGLGetVersionFromString(versionString); 28 GrGLVersion glVer = GrGLGetVersionFromString(versionString);
28 29
30 // This may or may not succeed depending on the gl version.
31 GrGLGetStringiProc glGetStringi =
32 (GrGLGetStringiProc) glXGetProcAddress(reinterpret_cast<const GLubyt e*>("glGetStringi"));
33
34 GrGLExtensions extensions;
35 if (!extensions.init(kDesktop_GrGLBinding, glGetString, glGetStringi, gl GetIntegerv)) {
36 return NULL;
37 }
38
29 if (glVer < GR_GL_VER(1,5)) { 39 if (glVer < GR_GL_VER(1,5)) {
30 // We must have array and element_array buffer objects. 40 // We must have array and element_array buffer objects.
31 return NULL; 41 return NULL;
32 } 42 }
33 43
34 GrGLInterface* interface = new GrGLInterface(); 44 GrGLInterface* interface = new GrGLInterface();
35 45
36 interface->fActiveTexture = glActiveTexture; 46 interface->fActiveTexture = glActiveTexture;
37 GR_GL_GET_PROC(AttachShader); 47 GR_GL_GET_PROC(AttachShader);
38 GR_GL_GET_PROC(BindAttribLocation); 48 GR_GL_GET_PROC(BindAttribLocation);
39 GR_GL_GET_PROC(BindBuffer); 49 GR_GL_GET_PROC(BindBuffer);
40 GR_GL_GET_PROC(BindFragDataLocation); 50 GR_GL_GET_PROC(BindFragDataLocation);
41 GR_GL_GET_PROC(BeginQuery); 51 GR_GL_GET_PROC(BeginQuery);
42 interface->fBindTexture = glBindTexture; 52 interface->fBindTexture = glBindTexture;
43 interface->fBlendFunc = glBlendFunc; 53 interface->fBlendFunc = glBlendFunc;
44 54
45 if (glVer >= GR_GL_VER(1,4) || 55 if (glVer >= GR_GL_VER(1,4) ||
46 GrGLHasExtensionFromString("GL_ARB_imaging", extString) || 56 extensions.has("GL_ARB_imaging") ||
47 GrGLHasExtensionFromString("GL_EXT_blend_color", extString)) { 57 extensions.has("GL_EXT_blend_color")) {
48 GR_GL_GET_PROC(BlendColor); 58 GR_GL_GET_PROC(BlendColor);
49 } 59 }
50 60
51 GR_GL_GET_PROC(BufferData); 61 GR_GL_GET_PROC(BufferData);
52 GR_GL_GET_PROC(BufferSubData); 62 GR_GL_GET_PROC(BufferSubData);
53 interface->fClear = glClear; 63 interface->fClear = glClear;
54 interface->fClearColor = glClearColor; 64 interface->fClearColor = glClearColor;
55 interface->fClearStencil = glClearStencil; 65 interface->fClearStencil = glClearStencil;
56 interface->fColorMask = glColorMask; 66 interface->fColorMask = glColorMask;
57 GR_GL_GET_PROC(CompileShader); 67 GR_GL_GET_PROC(CompileShader);
(...skipping 18 matching lines...) Expand all
76 GR_GL_GET_PROC(EndQuery); 86 GR_GL_GET_PROC(EndQuery);
77 interface->fFinish = glFinish; 87 interface->fFinish = glFinish;
78 interface->fFlush = glFlush; 88 interface->fFlush = glFlush;
79 interface->fFrontFace = glFrontFace; 89 interface->fFrontFace = glFrontFace;
80 GR_GL_GET_PROC(GenBuffers); 90 GR_GL_GET_PROC(GenBuffers);
81 GR_GL_GET_PROC(GetBufferParameteriv); 91 GR_GL_GET_PROC(GetBufferParameteriv);
82 interface->fGetError = glGetError; 92 interface->fGetError = glGetError;
83 interface->fGetIntegerv = glGetIntegerv; 93 interface->fGetIntegerv = glGetIntegerv;
84 GR_GL_GET_PROC(GetQueryObjectiv); 94 GR_GL_GET_PROC(GetQueryObjectiv);
85 GR_GL_GET_PROC(GetQueryObjectuiv); 95 GR_GL_GET_PROC(GetQueryObjectuiv);
86 if (glVer >= GR_GL_VER(3,3) || 96 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
87 GrGLHasExtensionFromString("GL_ARB_timer_query", extString)) {
88 GR_GL_GET_PROC(GetQueryObjecti64v); 97 GR_GL_GET_PROC(GetQueryObjecti64v);
89 GR_GL_GET_PROC(GetQueryObjectui64v); 98 GR_GL_GET_PROC(GetQueryObjectui64v);
90 GR_GL_GET_PROC(QueryCounter); 99 GR_GL_GET_PROC(QueryCounter);
91 } else if (GrGLHasExtensionFromString("GL_EXT_timer_query", extString)) { 100 } else if (extensions.has("GL_EXT_timer_query")) {
92 GR_GL_GET_PROC_SUFFIX(GetQueryObjecti64v, EXT); 101 GR_GL_GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
93 GR_GL_GET_PROC_SUFFIX(GetQueryObjectui64v, EXT); 102 GR_GL_GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
94 } 103 }
95 GR_GL_GET_PROC(GetQueryiv); 104 GR_GL_GET_PROC(GetQueryiv);
96 GR_GL_GET_PROC(GetProgramInfoLog); 105 GR_GL_GET_PROC(GetProgramInfoLog);
97 GR_GL_GET_PROC(GetProgramiv); 106 GR_GL_GET_PROC(GetProgramiv);
98 GR_GL_GET_PROC(GetShaderInfoLog); 107 GR_GL_GET_PROC(GetShaderInfoLog);
99 GR_GL_GET_PROC(GetShaderiv); 108 GR_GL_GET_PROC(GetShaderiv);
100 interface->fGetString = glGetString; 109 interface->fGetString = glGetString;
110 GR_GL_GET_PROC(GetStringi);
101 interface->fGetTexLevelParameteriv = glGetTexLevelParameteriv; 111 interface->fGetTexLevelParameteriv = glGetTexLevelParameteriv;
102 GR_GL_GET_PROC(GenQueries); 112 GR_GL_GET_PROC(GenQueries);
103 interface->fGenTextures = glGenTextures; 113 interface->fGenTextures = glGenTextures;
104 GR_GL_GET_PROC(GetUniformLocation); 114 GR_GL_GET_PROC(GetUniformLocation);
105 interface->fLineWidth = glLineWidth; 115 interface->fLineWidth = glLineWidth;
106 GR_GL_GET_PROC(LinkProgram); 116 GR_GL_GET_PROC(LinkProgram);
107 GR_GL_GET_PROC(MapBuffer); 117 GR_GL_GET_PROC(MapBuffer);
108 interface->fPixelStorei = glPixelStorei; 118 interface->fPixelStorei = glPixelStorei;
109 interface->fReadBuffer = glReadBuffer; 119 interface->fReadBuffer = glReadBuffer;
110 interface->fReadPixels = glReadPixels; 120 interface->fReadPixels = glReadPixels;
111 if (GrGLHasExtensionFromString("GL_NV_framebuffer_multisample_coverage", 121 if (extensions.has("GL_NV_framebuffer_multisample_coverage")) {
112 extString)) {
113 GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisampleCoverage, NV); 122 GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisampleCoverage, NV);
114 } 123 }
115 interface->fScissor = glScissor; 124 interface->fScissor = glScissor;
116 GR_GL_GET_PROC(ShaderSource); 125 GR_GL_GET_PROC(ShaderSource);
117 interface->fStencilFunc = glStencilFunc; 126 interface->fStencilFunc = glStencilFunc;
118 GR_GL_GET_PROC(StencilFuncSeparate); 127 GR_GL_GET_PROC(StencilFuncSeparate);
119 interface->fStencilMask = glStencilMask; 128 interface->fStencilMask = glStencilMask;
120 GR_GL_GET_PROC(StencilMaskSeparate); 129 GR_GL_GET_PROC(StencilMaskSeparate);
121 interface->fStencilOp = glStencilOp; 130 interface->fStencilOp = glStencilOp;
122 GR_GL_GET_PROC(StencilOpSeparate); 131 GR_GL_GET_PROC(StencilOpSeparate);
123 interface->fTexImage2D = glTexImage2D; 132 interface->fTexImage2D = glTexImage2D;
124 interface->fTexParameteri = glTexParameteri; 133 interface->fTexParameteri = glTexParameteri;
125 interface->fTexParameteriv = glTexParameteriv; 134 interface->fTexParameteriv = glTexParameteriv;
126 if (glVer >= GR_GL_VER(4,2) || 135 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) {
127 GrGLHasExtensionFromString("GL_ARB_texture_storage", extString)) {
128 GR_GL_GET_PROC(TexStorage2D); 136 GR_GL_GET_PROC(TexStorage2D);
129 } else if (GrGLHasExtensionFromString("GL_EXT_texture_storage", extStrin g)) { 137 } else if (extensions.has("GL_EXT_texture_storage")) {
130 GR_GL_GET_PROC_SUFFIX(TexStorage2D, EXT); 138 GR_GL_GET_PROC_SUFFIX(TexStorage2D, EXT);
131 } 139 }
132 interface->fTexSubImage2D = glTexSubImage2D; 140 interface->fTexSubImage2D = glTexSubImage2D;
133 GR_GL_GET_PROC(Uniform1f); 141 GR_GL_GET_PROC(Uniform1f);
134 GR_GL_GET_PROC(Uniform1i); 142 GR_GL_GET_PROC(Uniform1i);
135 GR_GL_GET_PROC(Uniform1fv); 143 GR_GL_GET_PROC(Uniform1fv);
136 GR_GL_GET_PROC(Uniform1iv); 144 GR_GL_GET_PROC(Uniform1iv);
137 GR_GL_GET_PROC(Uniform2f); 145 GR_GL_GET_PROC(Uniform2f);
138 GR_GL_GET_PROC(Uniform2i); 146 GR_GL_GET_PROC(Uniform2i);
139 GR_GL_GET_PROC(Uniform2fv); 147 GR_GL_GET_PROC(Uniform2fv);
(...skipping 11 matching lines...) Expand all
151 GR_GL_GET_PROC(UniformMatrix4fv); 159 GR_GL_GET_PROC(UniformMatrix4fv);
152 GR_GL_GET_PROC(UnmapBuffer); 160 GR_GL_GET_PROC(UnmapBuffer);
153 GR_GL_GET_PROC(UseProgram); 161 GR_GL_GET_PROC(UseProgram);
154 GR_GL_GET_PROC(VertexAttrib4fv); 162 GR_GL_GET_PROC(VertexAttrib4fv);
155 GR_GL_GET_PROC(VertexAttribPointer); 163 GR_GL_GET_PROC(VertexAttribPointer);
156 interface->fViewport = glViewport; 164 interface->fViewport = glViewport;
157 GR_GL_GET_PROC(BindFragDataLocationIndexed); 165 GR_GL_GET_PROC(BindFragDataLocationIndexed);
158 166
159 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since 167 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
160 // GL_ARB_framebuffer_object doesn't use ARB suffix.) 168 // GL_ARB_framebuffer_object doesn't use ARB suffix.)
161 if (glVer >= GR_GL_VER(3,0) || 169 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object ")) {
162 GrGLHasExtensionFromString("GL_ARB_framebuffer_object",
163 extString)) {
164 GR_GL_GET_PROC(GenFramebuffers); 170 GR_GL_GET_PROC(GenFramebuffers);
165 GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv); 171 GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv);
166 GR_GL_GET_PROC(GetRenderbufferParameteriv); 172 GR_GL_GET_PROC(GetRenderbufferParameteriv);
167 GR_GL_GET_PROC(BindFramebuffer); 173 GR_GL_GET_PROC(BindFramebuffer);
168 GR_GL_GET_PROC(FramebufferTexture2D); 174 GR_GL_GET_PROC(FramebufferTexture2D);
169 GR_GL_GET_PROC(CheckFramebufferStatus); 175 GR_GL_GET_PROC(CheckFramebufferStatus);
170 GR_GL_GET_PROC(DeleteFramebuffers); 176 GR_GL_GET_PROC(DeleteFramebuffers);
171 GR_GL_GET_PROC(RenderbufferStorage); 177 GR_GL_GET_PROC(RenderbufferStorage);
172 GR_GL_GET_PROC(GenRenderbuffers); 178 GR_GL_GET_PROC(GenRenderbuffers);
173 GR_GL_GET_PROC(DeleteRenderbuffers); 179 GR_GL_GET_PROC(DeleteRenderbuffers);
174 GR_GL_GET_PROC(FramebufferRenderbuffer); 180 GR_GL_GET_PROC(FramebufferRenderbuffer);
175 GR_GL_GET_PROC(BindRenderbuffer); 181 GR_GL_GET_PROC(BindRenderbuffer);
176 GR_GL_GET_PROC(RenderbufferStorageMultisample); 182 GR_GL_GET_PROC(RenderbufferStorageMultisample);
177 GR_GL_GET_PROC(BlitFramebuffer); 183 GR_GL_GET_PROC(BlitFramebuffer);
178 } else if (GrGLHasExtensionFromString("GL_EXT_framebuffer_object", 184 } else if (extensions.has("GL_EXT_framebuffer_object")) {
179 extString)) {
180 GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT); 185 GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT);
181 GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT); 186 GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
182 GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT); 187 GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
183 GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT); 188 GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT);
184 GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT); 189 GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
185 GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT); 190 GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
186 GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT); 191 GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
187 GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT); 192 GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT);
188 GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT); 193 GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT);
189 GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT); 194 GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
190 GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT); 195 GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
191 GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT); 196 GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT);
192 if (GrGLHasExtensionFromString("GL_EXT_framebuffer_multisample", 197 if (extensions.has("GL_EXT_framebuffer_multisample")) {
193 extString)) {
194 GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT); 198 GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
195 } 199 }
196 if (GrGLHasExtensionFromString("GL_EXT_framebuffer_blit", 200 if (extensions.has("GL_EXT_framebuffer_blit")) {
197 extString)) {
198 GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT); 201 GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT);
199 } 202 }
200 } else { 203 } else {
201 // we must have FBOs 204 // we must have FBOs
202 delete interface; 205 delete interface;
203 return NULL; 206 return NULL;
204 } 207 }
205 interface->fBindingsExported = kDesktop_GrGLBinding; 208 interface->fBindingsExported = kDesktop_GrGLBinding;
206 209
207 return interface; 210 return interface;
208 } else { 211 } else {
209 return NULL; 212 return NULL;
210 } 213 }
211 } 214 }
OLDNEW
« no previous file with comments | « src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp ('k') | src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698