| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 1 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 9 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | #include "GrTypes.h" |
| 11 | |
| 12 | // must be before GrGLConfig.h |
| 13 | #if GR_WIN32_BUILD |
| 14 | // #include "GrGpuD3D9.h" |
| 15 | #endif |
| 16 | |
| 17 | #include "GrGLConfig.h" |
| 18 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 19 | #include "GrGpu.h" |
| junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 20 | #include "GrGpuGLFixed.h" |
| 21 | #include "GrGpuGLShaders.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | |
| bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 23 | GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) { |
| bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 24 | |
| bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 25 | if (kOpenGL_Shaders_GrEngine == engine || |
| 26 | kOpenGL_Fixed_GrEngine == engine) { |
| bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 27 | // If no GL bindings have been installed, fall-back to calling the |
| 28 | // GL functions that have been linked with the executable. |
| 29 | if (!GrGLGetGLInterface()) { |
| 30 | GrGLSetDefaultGLInterface(); |
| 31 | // If there is no platform-default then just fail. |
| 32 | if (!GrGLGetGLInterface()) { |
| 33 | return NULL; |
| 34 | } |
| 35 | } |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 36 | if (!GrGLGetGLInterface()->validate(engine)) { |
| 37 | #if GR_DEBUG |
| 38 | GrPrintf("Failed GL interface validation!"); |
| 39 | #endif |
| 40 | return NULL; |
| 41 | } |
| bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 42 | } |
| twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 43 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 44 | GrGpu* gpu = NULL; |
| 45 | |
| 46 | switch (engine) { |
| bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 47 | case kOpenGL_Shaders_GrEngine: |
| bsalomon@google.com | 1da0e5e | 2011-05-09 13:28:55 +0000 | [diff] [blame] | 48 | GrAssert(NULL == (void*)context3D); |
| junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 49 | { |
| bsalomon@google.com | 2ba4abb | 2011-05-05 12:39:20 +0000 | [diff] [blame] | 50 | #if 0 // old code path, will be removed soon |
| junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 51 | gpu = new GrGpuGLShaders2; |
| bsalomon@google.com | 2ba4abb | 2011-05-05 12:39:20 +0000 | [diff] [blame] | 52 | #else |
| 53 | gpu = new GrGpuGLShaders; |
| junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 54 | #endif |
| 55 | } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 56 | break; |
| bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 57 | case kOpenGL_Fixed_GrEngine: |
| bsalomon@google.com | 1da0e5e | 2011-05-09 13:28:55 +0000 | [diff] [blame] | 58 | GrAssert(NULL == (void*)context3D); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 59 | gpu = new GrGpuGLFixed; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | break; |
| bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 61 | case kDirect3D9_GrEngine: |
| bsalomon@google.com | 1da0e5e | 2011-05-09 13:28:55 +0000 | [diff] [blame] | 62 | GrAssert(NULL != (void*)context3D); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 63 | #if GR_WIN32_BUILD |
| 64 | // gpu = new GrGpuD3D9((IDirect3DDevice9*)context3D); |
| 65 | #endif |
| 66 | break; |
| 67 | default: |
| 68 | GrAssert(!"unknown engine"); |
| 69 | break; |
| 70 | } |
| 71 | |
| 72 | return gpu; |
| 73 | } |