VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Shader.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 SHADER_H
18 #define SHADER_H
19 
20 #include "AttributeSet.h"
21 #include "RendererCommon.h"
22 #include <assert.h>
23 #include <string>
24 #include <vector>
25 
47 class Shader {
48 public:
54  Shader(const AttributeSetPtr& attributes, const std::vector<std::string>& uniformNames);
55  virtual ~Shader();
56 
60  virtual bool isCurrent() const = 0;
65  virtual bool isValid() const = 0;
72  virtual bool isCompiled() const = 0;
76  virtual GLuint getProgramId() const = 0;
77 
81  virtual void begin() = 0;
85  virtual void end() = 0;
89  virtual void compile() = 0;
95  virtual std::string getErrorLog() const = 0;
96 
100  const AttributeSetPtr& getAttributes() const { return mAttributes; }
104  const std::vector<std::string>& getUniformNames() const { return mUniformNames; }
113  virtual int getAttributeLocation(int index) const = 0;
122  virtual int getUniformLocation(int index) const = 0;
123 
124  // TODO: This list of methods needs to be expanded.
136  void setIndexedUniform1f(int index, bool global, float value, float* stateValue);
148  void setIndexedUniform2f(int index, bool global, const Vector2& value, Vector2* stateValue);
162  void setIndexedUniform3f(int index, bool global, float value1, float value2, float value3,
163  float* stateValue);
178  void setIndexedUniform4f(int index, bool global, float value1, float value2, float value3,
179  float value4, float* stateValue);
190  void setIndexedUniform1i(int index, bool global, int value, int* stateValue);
204  void setIndexedUniformMatrix4f(int index, bool global, bool transpose, const Matrix4& value,
205  Matrix4* stateValue);
206 
207 private:
208  AttributeSetPtr mAttributes;
209  std::vector<std::string> mUniformNames;
210 };
211 
212 #endif // SHADER_H
const std::vector< std::string > & getUniformNames() const
Returns the list of indexed uniforms.
Definition: Shader.h:104
Shader(const AttributeSetPtr &attributes, const std::vector< std::string > &uniformNames)
Construct a Shader with the given list of attributes and uniforms.
void setIndexedUniform3f(int index, bool global, float value1, float value2, float value3, float *stateValue)
Set the value of a 3D float vector uniform at the given index.
Header declaring and including types common to renderer classes such as Vector2. Also includes GL hea...
void setIndexedUniform1i(int index, bool global, int value, int *stateValue)
Set the value of an integer scalar uniform at the given index.
virtual bool isCurrent() const =0
Returns whether or not this shader is bound.
virtual bool isValid() const =0
Returns whether or not this shader is valid (compiled and linked) and can be used for rendering...
virtual void compile()=0
Compiles this shader, if not already compiled.
float Matrix4[16]
4x4 float matrix, whose layout is compatible with GL.
Definition: RendererCommon.h:46
virtual int getAttributeLocation(int index) const =0
Returns the location of an indexed Attribute.
Shader program abstract base class.
Definition: Shader.h:47
void setIndexedUniform2f(int index, bool global, const Vector2 &value, Vector2 *stateValue)
Set the value of a 2D float vector uniform at the given index.
virtual GLuint getProgramId() const =0
Returns the GL program id for this shader.
virtual bool isCompiled() const =0
Returns whether or not this shader has been processed for compilation.
virtual void begin()=0
Binds this shader, updating state as necessary.
std::shared_ptr< AttributeSet > AttributeSetPtr
Shared pointer typedef for AttributeSet.
Definition: PointerDeclarations.h:63
virtual void end()=0
Unbinds this shader if bound by a corresponding call to begin().
b2Vec2 Vector2
2D float vector, whose layout is compatible with GL.
Definition: RendererCommon.h:50
void setIndexedUniform1f(int index, bool global, float value, float *stateValue)
Set the value of a float scalar uniform at the given index.
virtual std::string getErrorLog() const =0
Retrieves the string describing compilation errors, if the call to compile() failed and isValid() is ...
virtual int getUniformLocation(int index) const =0
Returns the location of an indexed uniform.
void setIndexedUniformMatrix4f(int index, bool global, bool transpose, const Matrix4 &value, Matrix4 *stateValue)
Set the value of a 4x4 float matrix uniform at the given index.
const AttributeSetPtr & getAttributes() const
Returns the list of indexed Attributes for this shader, as an AttributeSet.
Definition: Shader.h:100
void setIndexedUniform4f(int index, bool global, float value1, float value2, float value3, float value4, float *stateValue)
Set the value of a 4D float vector uniform at the given index.