blob: 0e316a49ad2fc02c92a113277b19e8b7ac206077 [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
bsalomon@google.com05ef5102011-05-02 21:14:59 +000031GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000032
bsalomon@google.com05ef5102011-05-02 21:14:59 +000033 if (kOpenGL_Shaders_GrEngine == engine ||
34 kOpenGL_Fixed_GrEngine == engine) {
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000035 // 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 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +000044 if (!GrGLGetGLInterface()->validate(engine)) {
45#if GR_DEBUG
46 GrPrintf("Failed GL interface validation!");
47#endif
48 return NULL;
49 }
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000050 }
twiz@google.com59a190b2011-03-14 21:23:01 +000051
reed@google.comac10a2d2010-12-22 21:39:39 +000052 GrGpu* gpu = NULL;
53
54 switch (engine) {
bsalomon@google.com05ef5102011-05-02 21:14:59 +000055 case kOpenGL_Shaders_GrEngine:
reed@google.comac10a2d2010-12-22 21:39:39 +000056 GrAssert(NULL == context3D);
junov@google.comf93e7172011-03-31 21:26:24 +000057 {
58#if GR_USE_NEW_GLSHADERS
59 gpu = new GrGpuGLShaders;
60#else
61 gpu = new GrGpuGLShaders2;
62#endif
63 }
reed@google.comac10a2d2010-12-22 21:39:39 +000064 break;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000065 case kOpenGL_Fixed_GrEngine:
reed@google.comac10a2d2010-12-22 21:39:39 +000066 GrAssert(NULL == context3D);
reed@google.comac10a2d2010-12-22 21:39:39 +000067 gpu = new GrGpuGLFixed;
reed@google.comac10a2d2010-12-22 21:39:39 +000068 break;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000069 case kDirect3D9_GrEngine:
reed@google.comac10a2d2010-12-22 21:39:39 +000070 GrAssert(NULL != context3D);
71#if GR_WIN32_BUILD
72// gpu = new GrGpuD3D9((IDirect3DDevice9*)context3D);
73#endif
74 break;
75 default:
76 GrAssert(!"unknown engine");
77 break;
78 }
79
80 return gpu;
81}