reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 2 | Copyright 2011 Google Inc. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 17 | #include "GrTypes.h" |
| 18 | |
| 19 | // must be before GrGLConfig.h |
| 20 | #if GR_WIN32_BUILD |
| 21 | // #include "GrGpuD3D9.h" |
| 22 | #endif |
| 23 | |
| 24 | #include "GrGLConfig.h" |
| 25 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | #include "GrGpu.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 27 | #include "GrGpuGLFixed.h" |
| 28 | #include "GrGpuGLShaders.h" |
| 29 | #include "GrGpuGLShaders2.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 30 | |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 31 | GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) { |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 32 | |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 33 | if (kOpenGL_Shaders_GrEngine == engine || |
| 34 | kOpenGL_Fixed_GrEngine == engine) { |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 35 | // If no GL bindings have been installed, fall-back to calling the |
| 36 | // GL functions that have been linked with the executable. |
| 37 | if (!GrGLGetGLInterface()) { |
| 38 | GrGLSetDefaultGLInterface(); |
| 39 | // If there is no platform-default then just fail. |
| 40 | if (!GrGLGetGLInterface()) { |
| 41 | return NULL; |
| 42 | } |
| 43 | } |
| 44 | } |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 45 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 46 | GrGpu* gpu = NULL; |
| 47 | |
| 48 | switch (engine) { |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 49 | case kOpenGL_Shaders_GrEngine: |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | GrAssert(NULL == context3D); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 51 | { |
| 52 | #if GR_USE_NEW_GLSHADERS |
| 53 | gpu = new GrGpuGLShaders; |
| 54 | #else |
| 55 | gpu = new GrGpuGLShaders2; |
| 56 | #endif |
| 57 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 58 | break; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 59 | case kOpenGL_Fixed_GrEngine: |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | GrAssert(NULL == context3D); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 61 | gpu = new GrGpuGLFixed; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 62 | break; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 63 | case kDirect3D9_GrEngine: |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 64 | GrAssert(NULL != context3D); |
| 65 | #if GR_WIN32_BUILD |
| 66 | // gpu = new GrGpuD3D9((IDirect3DDevice9*)context3D); |
| 67 | #endif |
| 68 | break; |
| 69 | default: |
| 70 | GrAssert(!"unknown engine"); |
| 71 | break; |
| 72 | } |
| 73 | |
| 74 | return gpu; |
| 75 | } |