VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
InstancedShaderBase.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 INSTANCEDSHADERBASE_H
18 #define INSTANCEDSHADERBASE_H
19 
20 #include "InstancedShader.h"
21 #include "RendererCommon.h"
22 #include "ShaderBase.h"
23 
43 template<typename TShaderImpl>
45 public:
50 
58  static const ShaderPtr& getSharedShader() {
59  // To avoid static shared pointers and initialization issues, make this
60  // a raw pointer to a shared pointer.
61  // Note: It never gets deleted, similarly with our other singletons.
62  static ShaderPtr* sSharedShader = nullptr;
63  if (!sSharedShader) {
64  sSharedShader = new ShaderPtr(TShaderImpl::createSharedShader());
65  }
66  return *sSharedShader;
67  }
68 
69 protected:
77  std::string vertexShaderCode(TShaderImpl::getVertexShaderCode());
78  std::string fragmentShaderCode(TShaderImpl::getFragmentShaderCode());
79  AttributeSetPtr attributeSet(TShaderImpl::getAttributeSet());
80  std::vector<std::string> uniformNames(TShaderImpl::getUniformNames());
81  ShaderPtr shader = ShaderPtr(new ShaderBase(vertexShaderCode, fragmentShaderCode,
82  attributeSet, uniformNames));
83  shader->compile();
84  return shader;
85  }
86 };
87 
88 #endif // INSTANCEDSHADERBASE_H
Header declaring and including types common to renderer classes such as Vector2. Also includes GL hea...
Implementation of Shader which compiles itself from shader code.
Definition: ShaderBase.h:37
Shader which has instanced values for uniforms and other GL state.
Definition: InstancedShader.h:46
static ShaderPtr createSharedShader()
The default implementation of createSharedShader().
Definition: InstancedShaderBase.h:76
std::shared_ptr< AttributeSet > AttributeSetPtr
Shared pointer typedef for AttributeSet.
Definition: PointerDeclarations.h:63
std::shared_ptr< Shader > ShaderPtr
Shared pointer typedef for Shader.
Definition: PointerDeclarations.h:143
InstancedShaderBase()
Construct this InstancedShader, creating the shared Shader if necessary.
Definition: InstancedShaderBase.h:49
static const ShaderPtr & getSharedShader()
Returns the shared Shader singleton, creating it if necessary.
Definition: InstancedShaderBase.h:58
Helper class to implement InstancedShader subclasses, by managing a shared Shader.
Definition: InstancedShaderBase.h:44