VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
InstancedShader.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 INSTANCEDSHADER_H
18 #define INSTANCEDSHADER_H
19 
20 #include "RendererCommon.h"
21 #include "Shader.h"
22 #include "Texture.h"
23 
46 class InstancedShader : public Shader {
47 public:
53  explicit InstancedShader(const ShaderPtr& sharedShader);
54  virtual ~InstancedShader();
55 
59  const ShaderPtr& getSharedShader() const { return mSharedShader; }
60 
64  virtual bool isCurrent() const override;
69  virtual bool isValid() const override;
76  virtual bool isCompiled() const override;
80  virtual GLuint getProgramId() const override;
81 
88  virtual void begin() override;
94  virtual void end() override;
98  virtual void compile() override;
99  virtual std::string getErrorLog() const override;
100 
101  virtual int getAttributeLocation(int index) const override;
102  virtual int getUniformLocation(int index) const override;
103 
114  void setIndexedTexture(int index, int stage, const TexturePtr& value, TexturePtr* stateValue);
115 
116 protected:
125  virtual void updateState();
126 
127 private:
128  ShaderPtr mSharedShader;
129  bool mCurrentShader = false;
130 };
131 
132 #endif // INSTANCEDSHADER_H
Header declaring and including types common to renderer classes such as Vector2. Also includes GL hea...
Shader which has instanced values for uniforms and other GL state.
Definition: InstancedShader.h:46
virtual std::string getErrorLog() const override
Retrieves the string describing compilation errors, if the call to compile() failed and isValid() is ...
virtual GLuint getProgramId() const override
Returns the GL program id for this shader.
virtual bool isCompiled() const override
Returns whether or not this shader has been processed for compilation.
Shader program abstract base class.
Definition: Shader.h:47
InstancedShader(const ShaderPtr &sharedShader)
Create an InstancedShader which references a shader Shader.
void setIndexedTexture(int index, int stage, const TexturePtr &value, TexturePtr *stateValue)
Set the indexed texture for this instance at the given index.
const ShaderPtr & getSharedShader() const
Returns the Shader that is shared among instances.
Definition: InstancedShader.h:59
virtual int getUniformLocation(int index) const override
Returns the location of an indexed uniform.
std::shared_ptr< Texture > TexturePtr
Shared pointer typedef for Texture.
Definition: PointerDeclarations.h:173
virtual void begin() override
Binds this shader, and sets uniforms and other GL state associated with this instance.
std::shared_ptr< Shader > ShaderPtr
Shared pointer typedef for Shader.
Definition: PointerDeclarations.h:143
virtual void updateState()
Update state in response to this instance getting bound.
virtual bool isValid() const override
Returns whether or not this shader is valid (compiled and linked) and can be used for rendering...
virtual void end() override
Unbinds this shader if bound by a corresponding call to begin().
virtual bool isCurrent() const override
Returns whether or not this instance is bound.
virtual void compile() override
Compiles this shader, resulting in the compilation of the shared Shader if necessary.
virtual int getAttributeLocation(int index) const override
Returns the location of an indexed Attribute.