blob: 17153330dd89abb7aff5d2938c503a49db6143e8 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
twiz@google.com59a190b2011-03-14 21:23:01 +00002 Copyright 2011 Google Inc.
reed@google.comac10a2d2010-12-22 21:39:39 +00003
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.comac10a2d2010-12-22 21:39:39 +000017#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.comac10a2d2010-12-22 21:39:39 +000026#include "GrGpu.h"
junov@google.comf93e7172011-03-31 21:26:24 +000027#include "GrGpuGLFixed.h"
28#include "GrGpuGLShaders.h"
29#include "GrGpuGLShaders2.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000030
31GrGpu* GrGpu::Create(Engine engine, Platform3DContext context3D) {
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000032
33 if (kOpenGL_Shaders_Engine == engine ||
34 kOpenGL_Fixed_Engine == engine) {
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.com59a190b2011-03-14 21:23:01 +000045
reed@google.comac10a2d2010-12-22 21:39:39 +000046 GrGpu* gpu = NULL;
47
48 switch (engine) {
49 case kOpenGL_Shaders_Engine:
50 GrAssert(NULL == context3D);
junov@google.comf93e7172011-03-31 21:26:24 +000051 {
52#if GR_USE_NEW_GLSHADERS
53 gpu = new GrGpuGLShaders;
54#else
55 gpu = new GrGpuGLShaders2;
56#endif
57 }
reed@google.comac10a2d2010-12-22 21:39:39 +000058 break;
59 case kOpenGL_Fixed_Engine:
60 GrAssert(NULL == context3D);
reed@google.comac10a2d2010-12-22 21:39:39 +000061 gpu = new GrGpuGLFixed;
reed@google.comac10a2d2010-12-22 21:39:39 +000062 break;
63 case kDirect3D9_Engine:
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}