| 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 | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 25 | const GrGLInterface* glInterface; |
| 26 | |
| bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 27 | if (kOpenGL_Shaders_GrEngine == engine || |
| 28 | kOpenGL_Fixed_GrEngine == engine) { |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 29 | glInterface = reinterpret_cast<const GrGLInterface*>(context3D); |
| 30 | if (NULL == glInterface) { |
| 31 | glInterface = GrGLGetDefaultGLInterface(); |
| bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 32 | } |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 33 | if (NULL == glInterface) { |
| 34 | #if GR_DEBUG |
| 35 | GrPrintf("No GL interface provided!"); |
| 36 | #endif |
| 37 | return NULL; |
| 38 | } |
| 39 | if (!glInterface->validate(engine)) { |
| bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 40 | #if GR_DEBUG |
| 41 | GrPrintf("Failed GL interface validation!"); |
| 42 | #endif |
| 43 | return NULL; |
| 44 | } |
| bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 45 | } |
| twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 46 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | GrGpu* gpu = NULL; |
| 48 | |
| 49 | switch (engine) { |
| bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 50 | case kOpenGL_Shaders_GrEngine: |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 51 | GrAssert(NULL != glInterface); |
| 52 | gpu = new GrGpuGLShaders(glInterface); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 53 | break; |
| bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 54 | case kOpenGL_Fixed_GrEngine: |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 55 | GrAssert(NULL != glInterface); |
| 56 | gpu = new GrGpuGLFixed(glInterface); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 57 | break; |
| 58 | default: |
| 59 | GrAssert(!"unknown engine"); |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | return gpu; |
| 64 | } |