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 = CULL_BACK;
90 bool receive_shadows = false;
91 bool image_based_lighting = false;
93 void maybe_create_material_shader();
94 void set_material_textures();
97 /** Sets the shader program and uniform values. */
98 void set_shader_program(const Program *, const ProgramData *);
100 const Program *get_shader_program() const { return shprog; }
101 const ProgramData *get_shader_data() const { return shdata.get(); }
102 Tag get_slotted_uniform_tag(Tag) const;
104 /** Sets a Material to use as a basis for the render method. If a shader
105 has not been explicitly set, the material's shader will be used. */
106 void set_material(const Material *);
108 const Material *get_material() const { return material; }
109 const std::string &get_material_slot_name() const { return material_slot; }
110 void set_texture(Tag, const Texture *, const Sampler * = 0);
111 Tag get_texture_tag(const std::string &) const;
112 void set_face_cull(CullMode);
113 CullMode get_face_cull() const { return face_cull; }
114 void set_blend(const Blend &);
115 const Blend &get_blend() const { return blend; }
117 /** Toggles shadows on objects using this render method. Only affects
118 shaders created from materials. A ShadowMap effect is required. */
119 void set_receive_shadows(bool);
121 bool get_receive_shadows() const { return receive_shadows; }
123 /** Toggles the use of an environment map as a light source. Only affects
124 shaders created from materials. An EnvironmentMap effect is required. */
125 void set_image_based_lighting(bool);
127 bool get_image_based_lighting() const { return image_based_lighting; }
129 void apply(Renderer &) const;
131 void set_debug_name(const std::string &);