X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogram.h;h=a3fe57bfbece6c409cf7e967191e580a5fd5c5ac;hp=af249edefa2066c29bcf23e7c6f643ddd7d6c95c;hb=97b8f0d945474582c2213b70418d399e5641f0d5;hpb=cea3c333797cadd9629aefaa5b82243173a02d16 diff --git a/source/program.h b/source/program.h index af249ede..a3fe57bf 100644 --- a/source/program.h +++ b/source/program.h @@ -1,76 +1,124 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #ifndef MSP_GL_PROGRAM_H_ #define MSP_GL_PROGRAM_H_ #include #include -#include -#include -#include "types.h" +#include +#include "bindable.h" +#include "gl.h" +#include "programbuilder.h" +#include "vertexformat.h" namespace Msp { namespace GL { class Shader; -class Program +/** +A complete shader program. Programs can be assembled of individual Shaders or +generated with a set of standard features. +*/ +class Program: public Bindable { -private: - uint id; - std::list shaders; - bool del_shaders; - bool linked; - - static Program *cur_prog; - public: - class Loader: public DataFile::Loader + class Loader: public DataFile::ObjectLoader { - private: - Program &prog; - public: Loader(Program &); - ~Loader(); private: - void vertex_shader(const std::string &); + virtual void finish(); + + 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 &); + }; + + typedef unsigned LayoutHash; + struct UniformBlockInfo; + + struct UniformInfo + { + std::string name; + const UniformBlockInfo *block; + unsigned location; + unsigned size; + unsigned array_stride; + unsigned matrix_stride; + GLenum type; + }; + + struct UniformBlockInfo + { + std::string name; + unsigned data_size; + int bind_point; + std::vector uniforms; + LayoutHash layout_hash; }; + typedef std::list ShaderList; + typedef std::map UniformMap; + typedef std::map UniformBlockMap; + +private: + unsigned id; + ShaderList shaders; + ShaderList owned_data; + bool linked; + UniformBlockMap uniform_blocks; + UniformMap uniforms; + LayoutHash uniform_layout_hash; + bool legacy_vars; + +public: + /// Constructs an empty Program with no Shaders attached. Program(); + + /// 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: virtual ~Program(); void attach_shader(Shader &shader); + void attach_shader_owned(Shader *shader); void detach_shader(Shader &shader); - const std::list &get_shaders() const { return shaders; } - void set_del_shaders(bool); - void bind_attribute(int, const std::string &); - bool link(); - int get_param(GLenum param) const; - bool get_linked() const { return linked; } + 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 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; - void bind(); + + 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; - void uniform(int, int); - void uniform(int, float); - void uniform(int, float, float); - void uniform(int, float, float, float); - void uniform(int, float, float, float, float); - void uniform4(int, const float *); - void uniform_matrix4(int, const float *); - static void unbind(); + bool uses_legacy_variables() const { return legacy_vars; } -private: - void maybe_bind(); + void bind() const; + static void unbind(); }; } // namespace GL