FPLBase
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
material.h
Go to the documentation of this file.
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef FPLBASE_MATERIAL_H
16 #define FPLBASE_MATERIAL_H
17 
18 #include <assert.h>
19 #include <vector>
20 
21 #include "fplbase/config.h" // Must come first.
22 
23 #include "fplbase/asset.h"
24 #include "fplbase/render_state.h"
25 #include "fplbase/texture.h"
26 
27 namespace fplbase {
28 
29 /// @file
30 /// @addtogroup fplbase_material
31 /// @{
32 
33 class Renderer;
34 class Texture;
35 
36 /// @brief Collections of textures used for rendering multi-texture models.
37 class Material : public Asset {
38  public:
39  /// @brief Default constructor for Material.
40  Material() : blend_mode_(kBlendModeOff) {}
41 
42  /// @brief Set the renderer for this Material.
43  /// @param[in] renderer The renderer to set for this Material.
44  void Set(Renderer &renderer);
45 
46  /// @brief Get all Textures from this Material.
47  /// @return Returns a `std::vector<Texture *>` reference to get all
48  /// the Textures from this Material.
49  std::vector<Texture *> &textures() { return textures_; }
50 
51  /// @brief Get all Textures from this Material.
52  /// @return Returns a const `std::vector<Texture *>` reference to get all
53  /// the Textures from this Material.
54  const std::vector<Texture *> &textures() const { return textures_; }
55 
56  /// @brief Get the blend mode for this Material.
57  /// @return Returns an `int` corresponding the the @ref fplbase_material
58  /// "BlendMode" enum for this Material.
59  int blend_mode() const { return blend_mode_; }
60 
61  /// @brief Set the blend mode.
62  /// @param[in] blend_mode A @ref fplbase_material "BlendMode" enum
63  /// corresponding to the blend mode to set for this texture.
64  /// @warning Asserts if an invalid enum value for `blend_mode` is passed in.
66  assert(0 <= blend_mode && blend_mode < kBlendModeCount);
67  blend_mode_ = blend_mode;
68  }
69 
70  /// @brief Delete all Textures in this Material.
71  void DeleteTextures();
72 
73  /// @brief Load a .fplmat file, and all the textures referenced from it.
74  /// Used by the more convenient AssetManager interface, but can be used
75  /// without it.
76  static Material *LoadFromMaterialDef(const char *filename,
77  const TextureLoaderFn &tlf);
78 
79  private:
80  std::vector<Texture *> textures_;
81  BlendMode blend_mode_;
82 };
83 
84 /// @}
85 } // namespace fplbase
86 
87 #endif // FPLBASE_MATERIAL_H
Definition: render_state.h:41
BlendMode
Specifies the blending mode used by the blend function.
Definition: render_state.h:40
static Material * LoadFromMaterialDef(const char *filename, const TextureLoaderFn &tlf)
Load a .fplmat file, and all the textures referenced from it. Used by the more convenient AssetManage...
void DeleteTextures()
Delete all Textures in this Material.
Base class of all assets that may be managed by Assetmanager.
Definition: asset.h:26
Collections of textures used for rendering multi-texture models.
Definition: material.h:37
int blend_mode() const
Get the blend mode for this Material.
Definition: material.h:59
Material()
Default constructor for Material.
Definition: material.h:40
const std::vector< Texture * > & textures() const
Get all Textures from this Material.
Definition: material.h:54
std::vector< Texture * > & textures()
Get all Textures from this Material.
Definition: material.h:49
Definition: render_state.h:60
std::function< Texture *(const char *filename, TextureFormat format, TextureFlags flags)> TextureLoaderFn
used by some functions to allow the texture loading mechanism to be specified by the caller...
Definition: texture.h:431
void Set(Renderer &renderer)
Set the renderer for this Material.
Renderer is the main API class for rendering commands.
Definition: renderer.h:310
void set_blend_mode(BlendMode blend_mode)
Set the blend mode.
Definition: material.h:65