VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
SingletonInstancedShaderBase.h
1 /*
2  * Copyright (C) 2014 Google Inc.
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 
17 #ifndef SINGLETONINSTANCEDSHADERBASE_H
18 #define SINGLETONINSTANCEDSHADERBASE_H
19 
20 #include "RendererCommon.h"
21 #include "InstancedShaderBase.h"
22 
31 template<typename TShaderImpl>
32 class SingletonInstancedShaderBase : public InstancedShaderBase<TShaderImpl> {
33 public:
37  typedef std::shared_ptr<TShaderImpl> TShaderImplPtr;
41  typedef std::weak_ptr<TShaderImpl> TShaderImplWeakPtr;
42 
47  // To avoid static shared pointers and initialization issues, make this a raw pointer to a
48  // shared pointer.
49  // Note: It never gets deleted, similarly with our other singletons.
50  static TShaderImplPtr* sInstance = nullptr;
51  if (!sInstance) {
52  sInstance = new TShaderImplPtr(new TShaderImpl());
53  }
54  return *sInstance;
55  }
56 };
57 
58 #endif // SINGLETONINSTANCEDSHADERBASE_H
std::shared_ptr< TShaderImpl > TShaderImplPtr
Helper typedef for a shared pointer to a TShaderImpl.
Definition: SingletonInstancedShaderBase.h:37
Header declaring and including types common to renderer classes such as Vector2. Also includes GL hea...
static TShaderImplPtr getInstance()
Returns the singleton instance of this shader, creating it if necessary.
Definition: SingletonInstancedShaderBase.h:46
std::weak_ptr< TShaderImpl > TShaderImplWeakPtr
Helper typedef for a weak shared pointer to a TShaderImpl.
Definition: SingletonInstancedShaderBase.h:41
Helper class to implement InstancedShader subclasses, by managing a shared Shader.
Definition: InstancedShaderBase.h:44
A helper to define singletons for InstancedShaders.
Definition: PointerDeclarations.h:45