X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterials%2Frenderpass.h;fp=source%2Fmaterials%2Frenderpass.h;h=9e704376a446b56abb056edf0d1aab803a269f7d;hb=7aaec9a70b8d7733429bec043f8e33e02956f266;hp=0000000000000000000000000000000000000000;hpb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;p=libs%2Fgl.git diff --git a/source/materials/renderpass.h b/source/materials/renderpass.h new file mode 100644 index 00000000..9e704376 --- /dev/null +++ b/source/materials/renderpass.h @@ -0,0 +1,103 @@ +#ifndef MSP_GL_RENDERPASS_H_ +#define MSP_GL_RENDERPASS_H_ + +#include +#include + +namespace Msp { +namespace GL { + +class Material; +class Program; +class ProgramData; +class Renderer; +class Sampler; +class Texture; +class Texturing; + +/** +Encapsulates the data that determines the appearance of a rendered surface. +This includes shader and data for it, material and texturing. +*/ +class RenderPass +{ +public: + class Loader: public DataFile::CollectionObjectLoader + { + public: + Loader(RenderPass &); + Loader(RenderPass &, Collection &); + + private: + void init(); + + void material_inline(); + void material(const std::string &); + void shader(const std::string &); + void texunit(unsigned); + void texunit_auto(const std::string &); + void texunit_named(unsigned, const std::string &); + void uniforms(); + void uniform_slot(const std::string &); + void uniform_slot2(const std::string &, const std::string &); + }; + +private: + struct TextureLoader: public DataFile::CollectionObjectLoader + { + private: + unsigned index; + const Texture *tex; + const Sampler *samp; + + public: + TextureLoader(Texturing &, unsigned, Collection *); + private: + virtual void finish(); + + void sampler(const std::string &); + void texture(const std::string &); + }; + + RefPtr shprog; + bool shprog_from_material; + RefPtr shdata; + std::map uniform_slots; + RefPtr material; + std::string material_slot; + Texturing *texturing; + std::map tex_names; + bool back_faces; + +public: + RenderPass(); + RenderPass(const RenderPass &); + RenderPass &operator=(const RenderPass &); + ~RenderPass(); + +private: + void finalize_material(DataFile::Collection *); + void maybe_create_material_shader(DataFile::Collection *); + void ensure_private_shader_data(); + +public: + void set_shader_program(const Program *, const ProgramData *); + const Program *get_shader_program() const { return shprog.get(); } + const ProgramData *get_shader_data() const { return shdata.get(); } + const std::string &get_slotted_uniform_name(const std::string &) const; + void set_material(const Material *); + const Material *get_material() const { return material.get(); } + const std::string &get_material_slot_name() const { return material_slot; } + void set_texture(unsigned, const Texture *); + const Texturing *get_texturing() const { return texturing; } + int get_texture_index(const std::string &) const; + void set_back_faces(bool); + bool get_back_faces() const { return back_faces; } + + void apply(Renderer &) const; +}; + +} // namespace GL +} // namespace Msp + +#endif