X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogram.h;h=cbb52cd4536e93bd0b2cd65c0f9868cfe946b1f5;hp=132c21d5b126ec7d1dc3d2d9bb94ec1814747fb0;hb=03d3984ecd2c4e7c38b6a62b4b7a81bab69f8d40;hpb=3f7b09b2e12830eb439889b300f0d6591c4952ac diff --git a/source/program.h b/source/program.h index 132c21d5..cbb52cd4 100644 --- a/source/program.h +++ b/source/program.h @@ -1,17 +1,23 @@ #ifndef MSP_GL_PROGRAM_H_ #define MSP_GL_PROGRAM_H_ -#include #include +#include #include #include "bindable.h" #include "gl.h" +#include "programbuilder.h" +#include "vertexformat.h" namespace Msp { namespace GL { class Shader; +/** +A complete shader program. Programs can be assembled of individual Shaders or +generated with a set of standard features. +*/ class Program: public Bindable { public: @@ -25,32 +31,12 @@ public: void attribute(unsigned, const std::string &); void fragment_shader(const std::string &); + void geometry_shader(const std::string &); void standard(); void vertex_shader(const std::string &); }; - struct StandardFeatures - { - class Loader: public DataFile::ObjectLoader - { - public: - Loader(StandardFeatures &); - }; - - bool texture; - bool material; - bool lighting; - bool specular; - bool normalmap; - bool shadow; - bool reflection; - bool transform; - - StandardFeatures(); - - std::string create_flags() const; - }; - + typedef unsigned LayoutHash; struct UniformBlockInfo; struct UniformInfo @@ -68,12 +54,12 @@ public: { std::string name; unsigned data_size; - unsigned bind_point; + int bind_point; std::vector uniforms; - unsigned layout_hash; + LayoutHash layout_hash; }; - typedef std::list ShaderList; + typedef std::vector ShaderList; typedef std::map UniformMap; typedef std::map UniformBlockMap; @@ -84,12 +70,22 @@ private: bool linked; UniformBlockMap uniform_blocks; UniformMap uniforms; - unsigned uniform_layout_hash; + LayoutHash uniform_layout_hash; + bool legacy_vars; public: + /// Constructs an empty Program with no Shaders attached. Program(); - Program(const StandardFeatures &); + + /// Constructs a Program with standard features. + Program(const ProgramBuilder::StandardFeatures &); + + /// Constructs a Program from unified source code using ProgramCompiler. + Program(const std::string &); + + /// Constructs a Program from vertex and fragment shader source code. Program(const std::string &, const std::string &); + private: void init(); public: @@ -98,28 +94,29 @@ public: void attach_shader(Shader &shader); void attach_shader_owned(Shader *shader); void detach_shader(Shader &shader); - void add_standard_shaders(const StandardFeatures &); -private: - static std::string process_standard_source(const char **, const std::string &); -public: - const ShaderList &get_shaders() const { return shaders; } + const ShaderList &get_attached_shaders() const { return shaders; } void bind_attribute(unsigned, const std::string &); + void bind_attribute(VertexComponent, const std::string &); + void bind_fragment_data(unsigned, const std::string &); void link(); private: - static unsigned compute_layout_hash(const std::vector &); + static LayoutHash compute_layout_hash(const std::vector &); + static bool uniform_location_compare(const UniformInfo *, const UniformInfo *); public: bool is_linked() const { return linked; } std::string get_info_log() const; - unsigned get_uniform_layout_hash() const { return uniform_layout_hash; } + LayoutHash get_uniform_layout_hash() const { return uniform_layout_hash; } const UniformBlockMap &get_uniform_blocks() const { return uniform_blocks; } const UniformBlockInfo &get_uniform_block_info(const std::string &) const; const UniformMap &get_uniforms() const { return uniforms; } const UniformInfo &get_uniform_info(const std::string &) const; int get_uniform_location(const std::string &) const; + bool uses_legacy_variables() const { return legacy_vars; } + void bind() const; static void unbind(); };