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

Side by Side Diff: src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp

Issue 12328111: Use glGetStringi to get extensions when available. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "gl/GrGLUtil.h"
12 #define WIN32_LEAN_AND_MEAN 13 #define WIN32_LEAN_AND_MEAN
13 #include <Windows.h> 14 #include <Windows.h>
14 15
15 /* 16 /*
16 * Windows makes the GL funcs all be __stdcall instead of __cdecl :( 17 * Windows makes the GL funcs all be __stdcall instead of __cdecl :(
17 * This implementation will only work if GR_GL_FUNCTION_TYPE is __stdcall. 18 * This implementation will only work if GR_GL_FUNCTION_TYPE is __stdcall.
18 * Otherwise, a springboard would be needed that hides the calling convention. 19 * Otherwise, a springboard would be needed that hides the calling convention.
19 */ 20 */
20 21
21 #define SET_PROC(F) interface->f ## F = (GrGL ## F ## Proc) GetProcAddress(alu.g et(), "gl" #F); 22 #define SET_PROC(F) interface->f ## F = (GrGL ## F ## Proc) GetProcAddress(alu.g et(), "gl" #F);
(...skipping 19 matching lines...) Expand all
41 42
42 const GrGLInterface* GrGLCreateNativeInterface() { 43 const GrGLInterface* GrGLCreateNativeInterface() {
43 // wglGetProcAddress requires a context. 44 // wglGetProcAddress requires a context.
44 // GL Function pointers retrieved in one context may not be valid in another 45 // GL Function pointers retrieved in one context may not be valid in another
45 // context. For that reason we create a new GrGLInterface each time we're 46 // context. For that reason we create a new GrGLInterface each time we're
46 // called. 47 // called.
47 AutoLibraryUnload alu("opengl32.dll"); 48 AutoLibraryUnload alu("opengl32.dll");
48 if (NULL == alu.get()) { 49 if (NULL == alu.get()) {
49 return NULL; 50 return NULL;
50 } 51 }
51 GrGLGetStringProc glGetString =
52 (GrGLGetStringProc) GetProcAddress(alu.get(), "glGetString");
53 52
54 if (NULL != wglGetCurrentContext()) { 53 if (NULL != wglGetCurrentContext()) {
54
55 // These should always be present and don't require wglGetProcAddress
56 GrGLGetStringProc glGetString =
57 (GrGLGetStringProc) GetProcAddress(alu.get(), "glGetString");
58 GrGLGetIntegervProc glGetIntegerv =
59 (GrGLGetIntegervProc) GetProcAddress(alu.get(), "glGetIntegerv");
60 if (NULL == glGetString || NULL == glGetIntegerv) {
61 return NULL;
62 }
63
64 // This may or may not succeed depending on the gl version.
65 GrGLGetStringiProc glGetStringi = (GrGLGetStringiProc) wglGetProcAddres s("glGetStringi");
66
67 GrGLExtensions extensions;
68 if (!extensions.init(kDesktop_GrGLBinding, glGetString, glGetStringi, gl GetIntegerv)) {
69 return NULL;
70 }
55 const char* versionString = (const char*) glGetString(GR_GL_VERSION); 71 const char* versionString = (const char*) glGetString(GR_GL_VERSION);
56 const char* extString = (const char*) glGetString(GR_GL_EXTENSIONS);
57 GrGLVersion glVer = GrGLGetVersionFromString(versionString); 72 GrGLVersion glVer = GrGLGetVersionFromString(versionString);
58 73
59 if (glVer < GR_GL_VER(1,5)) { 74 if (glVer < GR_GL_VER(1,5)) {
60 // We must have array and element_array buffer objects. 75 // We must have array and element_array buffer objects.
61 return NULL; 76 return NULL;
62 } 77 }
63 GrGLInterface* interface = new GrGLInterface(); 78 GrGLInterface* interface = new GrGLInterface();
64 79
65 // Functions that are part of GL 1.1 will return NULL in 80 // Functions that are part of GL 1.1 will return NULL in
66 // wglGetProcAddress 81 // wglGetProcAddress
67 SET_PROC(BindTexture) 82 SET_PROC(BindTexture)
68 SET_PROC(BlendFunc) 83 SET_PROC(BlendFunc)
69 84
70 if (glVer >= GR_GL_VER(1,4) || 85 if (glVer >= GR_GL_VER(1,4) ||
71 GrGLHasExtensionFromString("GL_ARB_imaging", extString) || 86 extensions.has("GL_ARB_imaging") ||
72 GrGLHasExtensionFromString("GL_EXT_blend_color", extString)) { 87 extensions.has("GL_EXT_blend_color")) {
73 WGL_SET_PROC(BlendColor); 88 WGL_SET_PROC(BlendColor);
74 } 89 }
75 90
76 SET_PROC(Clear) 91 SET_PROC(Clear)
77 SET_PROC(ClearColor) 92 SET_PROC(ClearColor)
78 SET_PROC(ClearStencil) 93 SET_PROC(ClearStencil)
79 SET_PROC(ColorMask) 94 SET_PROC(ColorMask)
80 SET_PROC(CullFace) 95 SET_PROC(CullFace)
81 SET_PROC(DeleteTextures) 96 SET_PROC(DeleteTextures)
82 SET_PROC(DepthMask) 97 SET_PROC(DepthMask)
(...skipping 17 matching lines...) Expand all
100 SET_PROC(PixelStorei) 115 SET_PROC(PixelStorei)
101 SET_PROC(ReadBuffer) 116 SET_PROC(ReadBuffer)
102 SET_PROC(ReadPixels) 117 SET_PROC(ReadPixels)
103 SET_PROC(Scissor) 118 SET_PROC(Scissor)
104 SET_PROC(StencilFunc) 119 SET_PROC(StencilFunc)
105 SET_PROC(StencilMask) 120 SET_PROC(StencilMask)
106 SET_PROC(StencilOp) 121 SET_PROC(StencilOp)
107 SET_PROC(TexImage2D) 122 SET_PROC(TexImage2D)
108 SET_PROC(TexParameteri) 123 SET_PROC(TexParameteri)
109 SET_PROC(TexParameteriv) 124 SET_PROC(TexParameteriv)
110 if (glVer >= GR_GL_VER(4,2) || 125 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) {
111 GrGLHasExtensionFromString("GL_ARB_texture_storage", extString)) {
112 WGL_SET_PROC(TexStorage2D); 126 WGL_SET_PROC(TexStorage2D);
113 } else if (GrGLHasExtensionFromString("GL_EXT_texture_storage", extStrin g)) { 127 } else if (extensions.has("GL_EXT_texture_storage")) {
114 WGL_SET_PROC_SUFFIX(TexStorage2D, EXT); 128 WGL_SET_PROC_SUFFIX(TexStorage2D, EXT);
115 } 129 }
116 SET_PROC(TexSubImage2D) 130 SET_PROC(TexSubImage2D)
117 SET_PROC(Viewport) 131 SET_PROC(Viewport)
118 132
119 WGL_SET_PROC(ActiveTexture); 133 WGL_SET_PROC(ActiveTexture);
120 WGL_SET_PROC(AttachShader); 134 WGL_SET_PROC(AttachShader);
121 WGL_SET_PROC(BeginQuery); 135 WGL_SET_PROC(BeginQuery);
122 WGL_SET_PROC(BindAttribLocation); 136 WGL_SET_PROC(BindAttribLocation);
123 WGL_SET_PROC(BindBuffer); 137 WGL_SET_PROC(BindBuffer);
(...skipping 11 matching lines...) Expand all
135 WGL_SET_PROC(DisableVertexAttribArray); 149 WGL_SET_PROC(DisableVertexAttribArray);
136 WGL_SET_PROC(DrawBuffers); 150 WGL_SET_PROC(DrawBuffers);
137 WGL_SET_PROC(EnableVertexAttribArray); 151 WGL_SET_PROC(EnableVertexAttribArray);
138 WGL_SET_PROC(EndQuery); 152 WGL_SET_PROC(EndQuery);
139 WGL_SET_PROC(GenBuffers); 153 WGL_SET_PROC(GenBuffers);
140 WGL_SET_PROC(GenQueries); 154 WGL_SET_PROC(GenQueries);
141 WGL_SET_PROC(GetBufferParameteriv); 155 WGL_SET_PROC(GetBufferParameteriv);
142 WGL_SET_PROC(GetQueryiv); 156 WGL_SET_PROC(GetQueryiv);
143 WGL_SET_PROC(GetQueryObjectiv); 157 WGL_SET_PROC(GetQueryObjectiv);
144 WGL_SET_PROC(GetQueryObjectuiv); 158 WGL_SET_PROC(GetQueryObjectuiv);
145 if (glVer > GR_GL_VER(3,3) || 159 if (glVer > GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
146 GrGLHasExtensionFromString("GL_ARB_timer_query", extString)) {
147 WGL_SET_PROC(GetQueryObjecti64v); 160 WGL_SET_PROC(GetQueryObjecti64v);
148 WGL_SET_PROC(GetQueryObjectui64v); 161 WGL_SET_PROC(GetQueryObjectui64v);
149 WGL_SET_PROC(QueryCounter); 162 WGL_SET_PROC(QueryCounter);
150 } else if (GrGLHasExtensionFromString("GL_EXT_timer_query", extString)) { 163 } else if (extensions.has("GL_EXT_timer_query")) {
151 WGL_SET_PROC_SUFFIX(GetQueryObjecti64v, EXT); 164 WGL_SET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
152 WGL_SET_PROC_SUFFIX(GetQueryObjectui64v, EXT); 165 WGL_SET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
153 } 166 }
154 WGL_SET_PROC(GetProgramInfoLog); 167 WGL_SET_PROC(GetProgramInfoLog);
155 WGL_SET_PROC(GetProgramiv); 168 WGL_SET_PROC(GetProgramiv);
156 WGL_SET_PROC(GetShaderInfoLog); 169 WGL_SET_PROC(GetShaderInfoLog);
157 WGL_SET_PROC(GetShaderiv); 170 WGL_SET_PROC(GetShaderiv);
171 WGL_SET_PROC(GetStringi)
158 WGL_SET_PROC(GetUniformLocation); 172 WGL_SET_PROC(GetUniformLocation);
159 WGL_SET_PROC(LinkProgram); 173 WGL_SET_PROC(LinkProgram);
160 if (GrGLHasExtensionFromString("GL_NV_framebuffer_multisample_coverage", extString)) { 174 if (extensions.has("GL_NV_framebuffer_multisample_coverage")) {
161 WGL_SET_PROC_SUFFIX(RenderbufferStorageMultisampleCoverage, NV); 175 WGL_SET_PROC_SUFFIX(RenderbufferStorageMultisampleCoverage, NV);
162 } 176 }
163 WGL_SET_PROC(ShaderSource); 177 WGL_SET_PROC(ShaderSource);
164 WGL_SET_PROC(StencilFuncSeparate); 178 WGL_SET_PROC(StencilFuncSeparate);
165 WGL_SET_PROC(StencilMaskSeparate); 179 WGL_SET_PROC(StencilMaskSeparate);
166 WGL_SET_PROC(StencilOpSeparate); 180 WGL_SET_PROC(StencilOpSeparate);
167 WGL_SET_PROC(Uniform1f); 181 WGL_SET_PROC(Uniform1f);
168 WGL_SET_PROC(Uniform1i); 182 WGL_SET_PROC(Uniform1i);
169 WGL_SET_PROC(Uniform1fv); 183 WGL_SET_PROC(Uniform1fv);
170 WGL_SET_PROC(Uniform1iv); 184 WGL_SET_PROC(Uniform1iv);
(...skipping 12 matching lines...) Expand all
183 WGL_SET_PROC(UniformMatrix2fv); 197 WGL_SET_PROC(UniformMatrix2fv);
184 WGL_SET_PROC(UniformMatrix3fv); 198 WGL_SET_PROC(UniformMatrix3fv);
185 WGL_SET_PROC(UniformMatrix4fv); 199 WGL_SET_PROC(UniformMatrix4fv);
186 WGL_SET_PROC(UseProgram); 200 WGL_SET_PROC(UseProgram);
187 WGL_SET_PROC(VertexAttrib4fv); 201 WGL_SET_PROC(VertexAttrib4fv);
188 WGL_SET_PROC(VertexAttribPointer); 202 WGL_SET_PROC(VertexAttribPointer);
189 WGL_SET_PROC(BindFragDataLocationIndexed); 203 WGL_SET_PROC(BindFragDataLocationIndexed);
190 204
191 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since 205 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
192 // GL_ARB_framebuffer_object doesn't use ARB suffix.) 206 // GL_ARB_framebuffer_object doesn't use ARB suffix.)
193 if (glVer > GR_GL_VER(3,0) || 207 if (glVer > GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object" )) {
194 GrGLHasExtensionFromString("GL_ARB_framebuffer_object", extString)) {
195 WGL_SET_PROC(GenFramebuffers); 208 WGL_SET_PROC(GenFramebuffers);
196 WGL_SET_PROC(GetFramebufferAttachmentParameteriv); 209 WGL_SET_PROC(GetFramebufferAttachmentParameteriv);
197 WGL_SET_PROC(GetRenderbufferParameteriv); 210 WGL_SET_PROC(GetRenderbufferParameteriv);
198 WGL_SET_PROC(BindFramebuffer); 211 WGL_SET_PROC(BindFramebuffer);
199 WGL_SET_PROC(FramebufferTexture2D); 212 WGL_SET_PROC(FramebufferTexture2D);
200 WGL_SET_PROC(CheckFramebufferStatus); 213 WGL_SET_PROC(CheckFramebufferStatus);
201 WGL_SET_PROC(DeleteFramebuffers); 214 WGL_SET_PROC(DeleteFramebuffers);
202 WGL_SET_PROC(RenderbufferStorage); 215 WGL_SET_PROC(RenderbufferStorage);
203 WGL_SET_PROC(GenRenderbuffers); 216 WGL_SET_PROC(GenRenderbuffers);
204 WGL_SET_PROC(DeleteRenderbuffers); 217 WGL_SET_PROC(DeleteRenderbuffers);
205 WGL_SET_PROC(FramebufferRenderbuffer); 218 WGL_SET_PROC(FramebufferRenderbuffer);
206 WGL_SET_PROC(BindRenderbuffer); 219 WGL_SET_PROC(BindRenderbuffer);
207 WGL_SET_PROC(RenderbufferStorageMultisample); 220 WGL_SET_PROC(RenderbufferStorageMultisample);
208 WGL_SET_PROC(BlitFramebuffer); 221 WGL_SET_PROC(BlitFramebuffer);
209 } else if (GrGLHasExtensionFromString("GL_EXT_framebuffer_object", 222 } else if (extensions.has("GL_EXT_framebuffer_object")) {
210 extString)) {
211 WGL_SET_PROC_SUFFIX(GenFramebuffers, EXT); 223 WGL_SET_PROC_SUFFIX(GenFramebuffers, EXT);
212 WGL_SET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT); 224 WGL_SET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
213 WGL_SET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT); 225 WGL_SET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
214 WGL_SET_PROC_SUFFIX(BindFramebuffer, EXT); 226 WGL_SET_PROC_SUFFIX(BindFramebuffer, EXT);
215 WGL_SET_PROC_SUFFIX(FramebufferTexture2D, EXT); 227 WGL_SET_PROC_SUFFIX(FramebufferTexture2D, EXT);
216 WGL_SET_PROC_SUFFIX(CheckFramebufferStatus, EXT); 228 WGL_SET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
217 WGL_SET_PROC_SUFFIX(DeleteFramebuffers, EXT); 229 WGL_SET_PROC_SUFFIX(DeleteFramebuffers, EXT);
218 WGL_SET_PROC_SUFFIX(RenderbufferStorage, EXT); 230 WGL_SET_PROC_SUFFIX(RenderbufferStorage, EXT);
219 WGL_SET_PROC_SUFFIX(GenRenderbuffers, EXT); 231 WGL_SET_PROC_SUFFIX(GenRenderbuffers, EXT);
220 WGL_SET_PROC_SUFFIX(DeleteRenderbuffers, EXT); 232 WGL_SET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
221 WGL_SET_PROC_SUFFIX(FramebufferRenderbuffer, EXT); 233 WGL_SET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
222 WGL_SET_PROC_SUFFIX(BindRenderbuffer, EXT); 234 WGL_SET_PROC_SUFFIX(BindRenderbuffer, EXT);
223 if (GrGLHasExtensionFromString("GL_EXT_framebuffer_multisample", ext String)) { 235 if (extensions.has("GL_EXT_framebuffer_multisample")) {
224 WGL_SET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT); 236 WGL_SET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
225 } 237 }
226 if (GrGLHasExtensionFromString("GL_EXT_framebuffer_blit", extString) ) { 238 if (extensions.has("GL_EXT_framebuffer_blit")) {
227 WGL_SET_PROC_SUFFIX(BlitFramebuffer, EXT); 239 WGL_SET_PROC_SUFFIX(BlitFramebuffer, EXT);
228 } 240 }
229 } else { 241 } else {
230 // we must have FBOs 242 // we must have FBOs
231 delete interface; 243 delete interface;
232 return NULL; 244 return NULL;
233 } 245 }
234 WGL_SET_PROC(MapBuffer); 246 WGL_SET_PROC(MapBuffer);
235 WGL_SET_PROC(UnmapBuffer); 247 WGL_SET_PROC(UnmapBuffer);
236 248
237 if (GrGLHasExtensionFromString("GL_NV_path_rendering", extString)) { 249 if (extensions.has("GL_NV_path_rendering")) {
238 WGL_SET_PROC_SUFFIX(PathCommands, NV); 250 WGL_SET_PROC_SUFFIX(PathCommands, NV);
239 WGL_SET_PROC_SUFFIX(PathCoords, NV); 251 WGL_SET_PROC_SUFFIX(PathCoords, NV);
240 WGL_SET_PROC_SUFFIX(PathSubCommands, NV); 252 WGL_SET_PROC_SUFFIX(PathSubCommands, NV);
241 WGL_SET_PROC_SUFFIX(PathSubCoords, NV); 253 WGL_SET_PROC_SUFFIX(PathSubCoords, NV);
242 WGL_SET_PROC_SUFFIX(PathString, NV); 254 WGL_SET_PROC_SUFFIX(PathString, NV);
243 WGL_SET_PROC_SUFFIX(PathGlyphs, NV); 255 WGL_SET_PROC_SUFFIX(PathGlyphs, NV);
244 WGL_SET_PROC_SUFFIX(PathGlyphRange, NV); 256 WGL_SET_PROC_SUFFIX(PathGlyphRange, NV);
245 WGL_SET_PROC_SUFFIX(WeightPaths, NV); 257 WGL_SET_PROC_SUFFIX(WeightPaths, NV);
246 WGL_SET_PROC_SUFFIX(CopyPath, NV); 258 WGL_SET_PROC_SUFFIX(CopyPath, NV);
247 WGL_SET_PROC_SUFFIX(InterpolatePaths, NV); 259 WGL_SET_PROC_SUFFIX(InterpolatePaths, NV);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 WGL_SET_PROC_SUFFIX(PointAlongPath, NV); 298 WGL_SET_PROC_SUFFIX(PointAlongPath, NV);
287 } 299 }
288 300
289 interface->fBindingsExported = kDesktop_GrGLBinding; 301 interface->fBindingsExported = kDesktop_GrGLBinding;
290 302
291 return interface; 303 return interface;
292 } else { 304 } else {
293 return NULL; 305 return NULL;
294 } 306 }
295 } 307 }
OLDNEW
« no previous file with comments | « src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698