VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
SpriteShader.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 SPRITESHADER_H
18 #define SPRITESHADER_H
19 
20 #include "RendererCommon.h"
21 #include "SingletonInstancedShaderBase.h"
22 
33 class SpriteShader : public SingletonInstancedShaderBase<SpriteShader> {
34 public:
41  void setGlobalProjectionTransform(const Matrix4& matrix);
46  void setTransform(const Matrix4& matrix);
52  void setTexCoordScale(const Vector2& value);
58  void setTexCoordOffset(const Vector2& value);
67  void setOpacity(float value);
75  void setTexture(const TexturePtr& texture);
76 
77 protected:
81  virtual void updateState() override;
82 
83 private:
84  friend class InstancedShaderBase<SpriteShader>;
85  static std::string getVertexShaderCode();
86  static std::string getFragmentShaderCode();
87  static AttributeSetPtr getAttributeSet();
88  static std::vector<std::string> getUniformNames();
89 
90  Matrix4 mTransform;
91  Vector2 mTexCoordScale = Vector2(1.0f, 1.0f);
92  Vector2 mTexCoordOffset = Vector2(0.0f, 0.0f);
93  float mOpacity = 1.0f;
94  TexturePtr mTexture;
95 
96  static const char* VERTEX_SHADER;
97  static const char* FRAGMENT_SHADER;
98 };
99 
100 #endif // SPRITESHADER_H
const std::vector< std::string > & getUniformNames() const
Returns the list of indexed uniforms.
Definition: Shader.h:104
void setOpacity(float value)
Sets the overall transparency of the rendered texture, with 0.0f completely transparent, and 1.0f fully opaque.
Header declaring and including types common to renderer classes such as Vector2. Also includes GL hea...
void setTexCoordScale(const Vector2 &value)
Sets the offset to apply to texture coordinates, shifting the source rectangle in the source texture...
float Matrix4[16]
4x4 float matrix, whose layout is compatible with GL.
Definition: RendererCommon.h:46
void setGlobalProjectionTransform(const Matrix4 &matrix)
Sets the projection matrix, which is a global uniform.
Shader use by Renderer to draw textured rectangles (sprites).
Definition: SpriteShader.h:33
std::shared_ptr< AttributeSet > AttributeSetPtr
Shared pointer typedef for AttributeSet.
Definition: PointerDeclarations.h:63
b2Vec2 Vector2
2D float vector, whose layout is compatible with GL.
Definition: RendererCommon.h:50
std::shared_ptr< Texture > TexturePtr
Shared pointer typedef for Texture.
Definition: PointerDeclarations.h:173
void setTexture(const TexturePtr &texture)
Sets the source Texture to apply to the drawn rectangle.
void setTransform(const Matrix4 &matrix)
Sets the model transform.
void setTexCoordOffset(const Vector2 &value)
Sets the scaling factor to apply to texture coordinates, shrinking or expanding the source rectangle ...
virtual void updateState() override
Implementation of InstancedShader::updateState().
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