aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics/Shader.h
blob: d27d53841743b5e212e8dd0489743da873767b58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef __LIBJIN_JSL_H
#define __LIBJIN_JSL_H
#include "../jin_configuration.h"
#if LIBJIN_MODULES_RENDER

#include <string>
#include <map>
#include "color.h"
#include "texture.h"
#include "canvas.h"
#include "../3rdparty/GLee/GLee.h"

namespace jin
{
namespace graphics
{

    class Shader
    {
    public:
        static Shader* createShader(const std::string& program);
        static inline Shader* getCurrentShader() { return currentShader; }
        static void unuse();

		static const char* SHADER_PROJECTION_MATRIX;
		static const char* SHADER_MODEL_MATRIX;
		static const char* SHADER_MAIN_TEXTURE;
		static const char* SHADER_VERTEX_COORDS;
		static const char* SHADER_TEXTURE_COORDS;

        virtual ~Shader();

        void use(); 
        void sendFloat(const char* name, float number);
        void sendTexture(const char*  name, const Texture* image);
        void sendInt(const char* name, int value);
        void sendVec2(const char* name, float x, float y);
        void sendVec3(const char* name, float x, float y, float z);
        void sendVec4(const char* name, float x, float y, float z, float w);
        void sendCanvas(const char* name, const Canvas* canvas);
        void sendColor(const char* name, const Color* col);
        void sendMatrix4(const char* name, const math::Matrix* mat4);

        void bindVertexPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers);
		void bindUVPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers);

    protected:
        static Shader* currentShader;

        GLint claimTextureUnit(const std::string& name);
		Shader(const std::string& program);
        bool compile(const std::string& program);

        GLuint pid; 
        GLint currentTextureUnit;
        std::map<std::string, GLint> textureUnits;

    };

} // graphics
} // jin

#endif // LIBJIN_MODULES_RENDER
#endif // __LIBJIN_JSL_H