1 #ifndef MSP_GL_RENDERPASS_H_
2 #define MSP_GL_RENDERPASS_H_
4 #include <msp/core/refptr.h>
5 #include <msp/datafile/objectloader.h>
20 Describes the appearance of a surface with a shader, uniform values and
23 A Material can be used to automatically populate most of the fields of a
29 class Loader: public DataFile::CollectionObjectLoader<RenderMethod>
32 std::string inline_base_name;
34 static ActionMap shared_actions;
37 Loader(RenderMethod &, Collection &);
39 virtual void init_actions();
42 void set_inline_base_name(const std::string &);
45 virtual void finish();
48 void blend_factors(BlendFactor, BlendFactor);
49 void material_inline();
50 void material(const std::string &);
51 void shader(const std::string &);
52 void texture(const std::string &);
54 void uniform_slot(const std::string &);
55 void uniform_slot2(const std::string &, const std::string &);
61 class Loader: public DataFile::CollectionObjectLoader<TextureSlot>
64 std::string auto_slot_name;
67 Loader(TextureSlot &, const std::string &, Collection *);
74 std::string slot_name;
75 const Texture *texture;
76 const Sampler *sampler;
78 TextureSlot(Tag t): tag(t), texture(0), sampler(0) { }
81 const Program *shprog = 0;
82 bool shprog_from_material = false;
83 RefPtr<ProgramData> shdata;
84 std::map<Tag, Tag> uniform_slots;
85 const Material *material = 0;
86 std::string material_slot;
87 std::vector<TextureSlot> textures;
88 CullMode face_cull = NO_CULL;
90 bool receive_shadows = false;
91 bool image_based_lighting = false;
92 bool instancing = false;
94 void maybe_create_material_shader();
95 void set_material_textures();
98 /** Sets the shader program and uniform values. */
99 void set_shader_program(const Program *, const ProgramData *);
101 const Program *get_shader_program() const { return shprog; }
102 const ProgramData *get_shader_data() const { return shdata.get(); }
103 Tag get_slotted_uniform_tag(Tag) const;
105 /** Sets a Material to use as a basis for the render method. If a shader
106 has not been explicitly set, the material's shader will be used. */
107 void set_material(const Material *);
109 const Material *get_material() const { return material; }
110 const std::string &get_material_slot_name() const { return material_slot; }
111 void set_texture(Tag, const Texture *, const Sampler * = 0);
112 Tag get_texture_tag(const std::string &) const;
113 void set_face_cull(CullMode);
114 CullMode get_face_cull() const { return face_cull; }
115 void set_blend(const Blend &);
116 const Blend &get_blend() const { return blend; }
118 /** Toggles shadows on objects using this render method. Only affects
119 shaders created from materials. A ShadowMap effect is required. */
120 void set_receive_shadows(bool);
122 bool get_receive_shadows() const { return receive_shadows; }
124 /** Toggles the use of an environment map as a light source. Only affects
125 shaders created from materials. An EnvironmentMap effect is required. */
126 void set_image_based_lighting(bool);
128 bool get_image_based_lighting() const { return image_based_lighting; }
130 /** Toggles instanced rendering. Only affects shaders created from
131 materials. Should be used with InstanceArray. */
132 void set_instancing(bool);
134 bool get_instancing() const { return instancing; }
136 void apply(Renderer &) const;
138 void set_debug_name(const std::string &);