Messages and ownership of update objects
[platform/core/uifw/dali-core.git] / dali / internal / update / effects / scene-graph-material.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_MATERIAL_H
2 #define DALI_INTERNAL_SCENE_GRAPH_MATERIAL_H
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <dali/public-api/actors/renderable-actor.h> // For CullFaceMode
21 #include <dali/internal/common/buffer-index.h>
22 #include <dali/internal/common/blending-options.h>
23 #include <dali/internal/common/event-to-update.h>
24 #include <dali/internal/update/common/double-buffered.h>
25 #include <dali/internal/update/common/property-owner.h>
26 #include <dali/internal/render/renderers/material-data-provider.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 namespace SceneGraph
33 {
34 class Sampler;
35 class Shader;
36
37 class Material : public PropertyOwner, public MaterialDataProvider
38 {
39 public:
40   typedef Dali::Vector< Sampler* > Samplers;
41
42   /**
43    * Constructor
44    */
45   Material();
46
47   /**
48    * Destructor
49    */
50   virtual ~Material();
51
52   /**
53    * Set the shader effect for this material
54    * @param[in] shader The shader effect to use
55    */
56   void SetShader( Shader* shader );
57
58   /**
59    * Get the shader effect of this material
60    * @return the shader effect;
61    */
62   Shader* GetShader();
63
64   /**
65    * Add a sampler (image + sampler modes) to the material
66    * @param[in] sampler A sampler to add
67    */
68   void AddSampler( const Sampler* sampler );
69
70   /**
71    * Remove a sampler (image + sampler modes) from the material
72    * @param[in] sampler A sampler to remove
73    */
74   void RemoveSampler( const Sampler* sampler );
75
76   /**
77    * Get the samplers this material uses.
78    * @return the samplers
79    */
80   const Samplers& GetSamplers() const;
81
82 private:
83   Shader* mShader;
84   Samplers mSamplers; // Not owned (though who does?)
85
86   // @todo MESH_REWORK add property values for cull face mode, blending options, blend color
87   // Add getters/setters?
88 };
89
90 inline void SetShaderMessage( EventToUpdate& eventToUpdate, const Material& material, Shader& shader )
91 {
92   typedef MessageValue1< Material, Shader* > LocalType;
93
94   // Reserve some memory inside the message queue
95   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
96
97   // Construct message in the message queue memory; note that delete should not be called on the return value
98   new (slot) LocalType( &material, &Material::SetShader, &shader );
99 }
100
101 inline void AddSamplerMessage( EventToUpdate& eventToUpdate, const Material& material, const Sampler& sampler )
102 {
103   typedef MessageValue1< Material, const Sampler* > LocalType;
104
105   // Reserve some memory inside the message queue
106   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
107
108   // Construct message in the message queue memory; note that delete should not be called on the return value
109   new (slot) LocalType( &material, &Material::AddSampler, &sampler );
110 }
111
112 inline void RemoveSamplerMessage( EventToUpdate& eventToUpdate, const Material& material, const Sampler& sampler )
113 {
114   typedef MessageValue1< Material, const Sampler* > LocalType;
115
116   // Reserve some memory inside the message queue
117   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
118
119   // Construct message in the message queue memory; note that delete should not be called on the return value
120   new (slot) LocalType( &material, &Material::RemoveSampler, &sampler );
121 }
122
123 } // namespace SceneGraph
124 } // namespace Internal
125 } // namespace Dali
126
127 #endif //  DALI_INTERNAL_SCENE_GRAPH_MATERIAL_H