aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Render/JSL.h
blob: 88ac65e0b9f5838ddc1d5b0472e00dde3e387597 (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
65
66
67
68
69
70
71
72
73
74
#ifndef __JIN_JSL_H
#define __JIN_JSL_H
#include "../modules.h"
#if JIN_MODULES_RENDER

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

namespace jin
{
namespace render
{

    class JSLProgram
    {

    public:

        static JSLProgram* createJSLProgram(const char* program);

        ~JSLProgram();

        inline void JSLProgram::use()
        {
            glUseProgram(pid);
            currentJSLProgram = this;
        }

        static inline void JSLProgram::unuse()
        {
            glUseProgram(0);
            currentJSLProgram = nullptr;
        }

        void sendFloat(const char* name, float number);
        void sendTexture(const char*  name, const Texture* image);
        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);

        static inline JSLProgram* getCurrentJSL()
        {
            return currentJSLProgram;
        }

    private:

        JSLProgram(const char* program);

        static JSLProgram* currentJSLProgram;

        GLuint pid; 

        std::map<std::string, GLint> texturePool;

        GLint currentTextureUnit;
        GLint getTextureUnit(const std::string& name);

        inline void initialize(const char* program);
        inline void destroy();

    };

}
}

#endif // JIN_MODULES_RENDER
#endif // __JIN_JSL_H