60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
/* ================================================================
|
|
Program
|
|
----------------
|
|
This file describes our Program class. This class is responsible for
|
|
loading, creating, and compiling OpenGL programs.
|
|
================================================================ */
|
|
#ifndef PROGRAM_HPP
|
|
#define PROGRAM_HPP
|
|
#include "common.hpp"
|
|
#include <vector>
|
|
class Program {
|
|
//
|
|
public:
|
|
class Variable {
|
|
friend class Program;
|
|
public:
|
|
enum VariableType {
|
|
UNDEF, INT, UINT, FLOAT, DOUBLE, TEXTURE
|
|
};
|
|
Variable(VariableType type);
|
|
~Variable();
|
|
protected:
|
|
int type; // 0 = uniform, 1 = attribute
|
|
GLint location;
|
|
int data_type;
|
|
char *data;
|
|
size_t length;
|
|
};
|
|
class Texture {
|
|
friend class Program;
|
|
public:
|
|
Texture() { location = -1; index = 0; texture = 0;};
|
|
protected:
|
|
GLint location;
|
|
GLuint index;
|
|
GLuint texture;
|
|
};
|
|
public:
|
|
Program();
|
|
~Program();
|
|
int addShader(const char *file, GLenum type);
|
|
int attachTexture(GLuint index, GLuint texture);
|
|
int setTexture(GLuint index, GLuint texture);
|
|
int doCompile();
|
|
int doClean();
|
|
GLuint getUniform(const char *name);
|
|
GLuint getProgram();
|
|
int activate();
|
|
int deactivate();
|
|
protected:
|
|
GLuint program; // Compiled shader program
|
|
private:
|
|
std::vector<GLenum> shader_type; // Type of shader program, tied to v
|
|
std::vector<GLuint> shader_prog; // Compiled shader program, tied to ^
|
|
std::vector<GLuint> shader_uniform; // Shader uniform locations
|
|
std::vector<Texture> shader_textures;// Textures that this shader uses
|
|
std::vector<Variable> shader_variables;
|
|
};
|
|
#endif
|