OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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 "GrGLAssembleInterface.h" | 10 #include "GrGLAssembleInterface.h" |
11 #include "GrGLUtil.h" | 11 #include "GrGLUtil.h" |
12 | 12 |
13 #define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F) | 13 #define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F) |
14 #define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "
gl" #F #S) | 14 #define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "
gl" #F #S) |
15 #define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl
" #F) | 15 #define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl
" #F) |
16 | 16 |
| 17 // The glStencilThenCover* methods are a new addition to NV_path_rendering. They |
| 18 // aren't available on all drivers. In the event that they are not present, this |
| 19 // function can be used to add methods to the given GrGLInterface that emulate |
| 20 // them using the existing glStencil*/glCover* methods. |
| 21 static void emulate_nvpr_stencil_then_cover(GrGLInterface*); |
| 22 |
17 const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { | 23 const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { |
18 GET_PROC_LOCAL(GetString); | 24 GET_PROC_LOCAL(GetString); |
19 GET_PROC_LOCAL(GetStringi); | 25 GET_PROC_LOCAL(GetStringi); |
20 GET_PROC_LOCAL(GetIntegerv); | 26 GET_PROC_LOCAL(GetIntegerv); |
21 | 27 |
22 // GetStringi may be NULL depending on the GL version. | 28 // GetStringi may be NULL depending on the GL version. |
23 if (NULL == GetString || NULL == GetIntegerv) { | 29 if (NULL == GetString || NULL == GetIntegerv) { |
24 return NULL; | 30 return NULL; |
25 } | 31 } |
26 | 32 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 GET_PROC_SUFFIX(PathStencilFunc, NV); | 238 GET_PROC_SUFFIX(PathStencilFunc, NV); |
233 GET_PROC_SUFFIX(StencilFillPath, NV); | 239 GET_PROC_SUFFIX(StencilFillPath, NV); |
234 GET_PROC_SUFFIX(StencilStrokePath, NV); | 240 GET_PROC_SUFFIX(StencilStrokePath, NV); |
235 GET_PROC_SUFFIX(StencilFillPathInstanced, NV); | 241 GET_PROC_SUFFIX(StencilFillPathInstanced, NV); |
236 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV); | 242 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV); |
237 GET_PROC_SUFFIX(PathTexGen, NV); | 243 GET_PROC_SUFFIX(PathTexGen, NV); |
238 GET_PROC_SUFFIX(CoverFillPath, NV); | 244 GET_PROC_SUFFIX(CoverFillPath, NV); |
239 GET_PROC_SUFFIX(CoverStrokePath, NV); | 245 GET_PROC_SUFFIX(CoverStrokePath, NV); |
240 GET_PROC_SUFFIX(CoverFillPathInstanced, NV); | 246 GET_PROC_SUFFIX(CoverFillPathInstanced, NV); |
241 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV); | 247 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV); |
| 248 GET_PROC_SUFFIX(StencilThenCoverFillPath, NV); |
| 249 GET_PROC_SUFFIX(StencilThenCoverStrokePath, NV); |
| 250 GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, NV); |
| 251 GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, NV); |
242 GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV); | 252 GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV); |
| 253 |
| 254 if (NULL == interface->fFunctions.fStencilThenCoverFillPath || |
| 255 NULL == interface->fFunctions.fStencilThenCoverStrokePath || |
| 256 NULL == interface->fFunctions.fStencilThenCoverFillPathInstanced || |
| 257 NULL == interface->fFunctions.fStencilThenCoverFillPathInstanced) { |
| 258 emulate_nvpr_stencil_then_cover(interface); |
| 259 } |
243 } | 260 } |
244 | 261 |
245 if (extensions.has("GL_EXT_debug_marker")) { | 262 if (extensions.has("GL_EXT_debug_marker")) { |
246 GET_PROC_SUFFIX(InsertEventMarker, EXT); | 263 GET_PROC_SUFFIX(InsertEventMarker, EXT); |
247 GET_PROC_SUFFIX(PushGroupMarker, EXT); | 264 GET_PROC_SUFFIX(PushGroupMarker, EXT); |
248 GET_PROC_SUFFIX(PopGroupMarker, EXT); | 265 GET_PROC_SUFFIX(PopGroupMarker, EXT); |
249 } | 266 } |
250 | 267 |
251 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_invalidate_subdata"))
{ | 268 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_invalidate_subdata"))
{ |
252 GET_PROC(InvalidateBufferData); | 269 GET_PROC(InvalidateBufferData); |
253 GET_PROC(InvalidateBufferSubData); | 270 GET_PROC(InvalidateBufferSubData); |
254 GET_PROC(InvalidateFramebuffer); | 271 GET_PROC(InvalidateFramebuffer); |
255 GET_PROC(InvalidateSubFramebuffer); | 272 GET_PROC(InvalidateSubFramebuffer); |
256 GET_PROC(InvalidateTexImage); | 273 GET_PROC(InvalidateTexImage); |
257 GET_PROC(InvalidateTexSubImage); | 274 GET_PROC(InvalidateTexSubImage); |
258 } | 275 } |
259 | 276 |
260 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_program_interface_quer
y")) { | 277 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_program_interface_quer
y")) { |
261 GET_PROC(GetProgramResourceLocation); | 278 GET_PROC(GetProgramResourceLocation); |
262 } | 279 } |
263 | 280 |
264 interface->fStandard = kGL_GrGLStandard; | 281 interface->fStandard = kGL_GrGLStandard; |
265 interface->fExtensions.swap(&extensions); | 282 interface->fExtensions.swap(&extensions); |
266 | 283 |
267 return interface; | 284 return interface; |
268 } | 285 } |
| 286 |
| 287 static GrGLStencilFillPathProc gStencilFillPath; |
| 288 static GrGLCoverFillPathProc gCoverFillPath; |
| 289 static GrGLvoid GR_GL_FUNCTION_TYPE stencil_then_cover_fill_path( |
| 290 GrGLuint path, GrGLenum fillMode, |
| 291 GrGLuint mask, GrGLenum coverMode) { |
| 292 gStencilFillPath(path, fillMode, mask); |
| 293 gCoverFillPath(path, coverMode); |
| 294 } |
| 295 |
| 296 |
| 297 static GrGLStencilStrokePathProc gStencilStrokePath; |
| 298 static GrGLCoverStrokePathProc gCoverStrokePath; |
| 299 static GrGLvoid GR_GL_FUNCTION_TYPE stencil_then_cover_stroke_path( |
| 300 GrGLuint path, GrGLint reference, |
| 301 GrGLuint mask, GrGLenum coverMode) { |
| 302 gStencilStrokePath(path, reference, mask); |
| 303 gCoverStrokePath(path, coverMode); |
| 304 } |
| 305 |
| 306 static GrGLStencilFillPathInstancedProc gStencilFillPathInstanced; |
| 307 static GrGLCoverFillPathInstancedProc gCoverFillPathInstanced; |
| 308 static GrGLvoid GR_GL_FUNCTION_TYPE stencil_then_cover_fill_path_instanced( |
| 309 GrGLsizei numPaths, GrGLenum pathNameTyp
e, |
| 310 const GrGLvoid *paths, GrGLuint pathBase
, |
| 311 GrGLenum fillMode, GrGLuint mask, |
| 312 GrGLenum coverMode, GrGLenum transformTy
pe, |
| 313 const GrGLfloat *transformValues) { |
| 314 gStencilFillPathInstanced(numPaths, pathNameType, paths, pathBase, |
| 315 fillMode, mask, transformType, transformValues); |
| 316 gCoverFillPathInstanced(numPaths, pathNameType, paths, pathBase, |
| 317 coverMode, transformType, transformValues); |
| 318 } |
| 319 |
| 320 static GrGLStencilStrokePathInstancedProc gStencilStrokePathInstanced; |
| 321 static GrGLCoverStrokePathInstancedProc gCoverStrokePathInstanced; |
| 322 static GrGLvoid GR_GL_FUNCTION_TYPE stencil_then_cover_stroke_path_instanced( |
| 323 GrGLsizei numPaths, GrGLenum pathNameTyp
e, |
| 324 const GrGLvoid *paths, GrGLuint pathBase
, |
| 325 GrGLint reference, GrGLuint mask, |
| 326 GrGLenum coverMode, GrGLenum transformTy
pe, |
| 327 const GrGLfloat *transformValues) { |
| 328 gStencilStrokePathInstanced(numPaths, pathNameType, paths, pathBase, |
| 329 reference, mask, transformType, transformValues)
; |
| 330 gCoverStrokePathInstanced(numPaths, pathNameType, paths, pathBase, |
| 331 coverMode, transformType, transformValues); |
| 332 } |
| 333 |
| 334 static void emulate_nvpr_stencil_then_cover(GrGLInterface* interface) { |
| 335 if (NULL == gStencilFillPath) { |
| 336 gStencilFillPath = (GrGLStencilFillPathProc)interface->fFunctions.fStenc
ilFillPath; |
| 337 } |
| 338 if (NULL == gCoverFillPath) { |
| 339 gCoverFillPath = (GrGLCoverFillPathProc)interface->fFunctions.fCoverFill
Path; |
| 340 } |
| 341 if (NULL == gStencilStrokePath) { |
| 342 gStencilStrokePath = (GrGLStencilStrokePathProc)interface->fFunctions.fS
tencilStrokePath; |
| 343 } |
| 344 if (NULL == gCoverStrokePath) { |
| 345 gCoverStrokePath = (GrGLCoverStrokePathProc)interface->fFunctions.fCover
StrokePath; |
| 346 } |
| 347 if (NULL == gStencilFillPathInstanced) { |
| 348 gStencilFillPathInstanced = (GrGLStencilFillPathInstancedProc) |
| 349 interface->fFunctions.fStencilFillPathInstanced; |
| 350 } |
| 351 if (NULL == gCoverFillPathInstanced) { |
| 352 gCoverFillPathInstanced = (GrGLCoverFillPathInstancedProc) |
| 353 interface->fFunctions.fCoverFillPathInstanced; |
| 354 } |
| 355 if (NULL == gStencilStrokePathInstanced) { |
| 356 gStencilStrokePathInstanced = (GrGLStencilStrokePathInstancedProc) |
| 357 interface->fFunctions.fStencilStrokePathInstanced; |
| 358 } |
| 359 if (NULL == gCoverStrokePathInstanced) { |
| 360 gCoverStrokePathInstanced = (GrGLCoverStrokePathInstancedProc) |
| 361 interface->fFunctions.fCoverStrokePathInstanced; |
| 362 } |
| 363 |
| 364 if (interface->fFunctions.fStencilFillPath != gStencilFillPath || |
| 365 interface->fFunctions.fCoverFillPath != gCoverFillPath || |
| 366 interface->fFunctions.fStencilStrokePath != gStencilStrokePath || |
| 367 interface->fFunctions.fCoverStrokePath != gCoverStrokePath || |
| 368 interface->fFunctions.fStencilFillPathInstanced != gStencilFillPathInsta
nced || |
| 369 interface->fFunctions.fCoverFillPathInstanced != gCoverFillPathInstanced
|| |
| 370 interface->fFunctions.fStencilStrokePathInstanced != gStencilStrokePathI
nstanced || |
| 371 interface->fFunctions.fCoverStrokePathInstanced != gCoverStrokePathInsta
nced) { |
| 372 // While not every windowing system requires GetProcAddress to return |
| 373 // the same addresses in different contexts, it is guaranteed to do so |
| 374 // in any context that supports NV_path_rendering. |
| 375 SkFAIL("GetProcAddress returned different addresses for the same nvpr fu
nctions"); |
| 376 return; |
| 377 } |
| 378 |
| 379 interface->fFunctions.fStencilThenCoverFillPath = &stencil_then_cover_fill_p
ath; |
| 380 interface->fFunctions.fStencilThenCoverStrokePath = &stencil_then_cover_stro
ke_path; |
| 381 interface->fFunctions.fStencilThenCoverFillPathInstanced = &stencil_then_cov
er_fill_path_instanced; |
| 382 interface->fFunctions.fStencilThenCoverStrokePathInstanced = &stencil_then_c
over_stroke_path_instanced; |
| 383 } |
OLD | NEW |