-/* $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 <list>
#include <string>
+#include <vector>
#include <msp/datafile/objectloader.h>
#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<Program>
{
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
+ 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
{
- class Loader: public DataFile::ObjectLoader<StandardFeatures>
- {
- public:
- Loader(StandardFeatures &);
- };
-
- bool texture;
- bool material;
- bool lighting;
- bool specular;
- bool normalmap;
- bool shadow;
-
- StandardFeatures();
-
- std::string create_flags() const;
+ std::string name;
+ unsigned data_size;
+ int bind_point;
+ std::vector<const UniformInfo *> uniforms;
+ LayoutHash layout_hash;
};
- struct UniformInfo
+ struct AttributeInfo
{
std::string name;
- int location;
- int size;
+ unsigned location;
+ unsigned size;
GLenum type;
};
+ typedef std::vector<Shader *> ShaderList;
+ typedef std::map<std::string, UniformInfo> UniformMap;
+ typedef std::map<std::string, UniformBlockInfo> UniformBlockMap;
+ typedef std::map<std::string, AttributeInfo> AttributeMap;
+
private:
unsigned id;
- std::list<Shader *> shaders;
- bool del_shaders;
+ ShaderList shaders;
+ ShaderList owned_data;
bool linked;
- std::map<std::string, UniformInfo> uniforms;
+ UniformBlockMap uniform_blocks;
+ UniformMap uniforms;
+ LayoutHash uniform_layout_hash;
+ AttributeMap attributes;
public:
+ /// Constructs an empty Program with no Shaders attached.
Program();
- Program(const StandardFeatures &);
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ /// Constructs a Program with standard features.
+ DEPRECATED Program(const ProgramBuilder::StandardFeatures &);
+#pragma GCC diagnostic pop
+
+ /// 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);
- void add_standard_shaders(const StandardFeatures &);
-private:
- static std::string process_standard_source(const char **, const std::string &);
-public:
- const std::list<Shader *> &get_shaders() const { return shaders; }
- void set_del_shaders(bool);
+ 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 void require_type(GLenum);
+ void query_uniforms();
+ void query_uniform_blocks(const std::vector<UniformInfo *> &);
+ void query_attributes();
+ static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
+ static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
+public:
bool is_linked() const { return linked; }
std::string get_info_log() const;
- void bind() const;
+
+ 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;
+ const AttributeMap &get_attributes() const { return attributes; }
+ const AttributeInfo &get_attribute_info(const std::string &) const;
+ int get_attribute_location(const std::string &) const;
+ void bind() const;
static void unbind();
};