summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/Shader.h
blob: 7cca768e7e92ad3f1baeb7e7b5df56ba0da2313b (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
#pragma once
#include <string>
#include <exception>
#include "Runtime/Graphics/OpenGL.h"
#include "Runtime/Lua/LuaHelper.h"
#include "Runtime/Utilities/UtilMacros.h"
#include "runtime/Debug/Log.h"

// ×ÅÉ«Æ÷³ÌÐò
class Shader : public LuaBind::NativeClass<Shader>
{
public:
	Shader(LuaBind::VM*vm, bool keepSrc = false);
	Shader(LuaBind::VM*vm, std::string& vert, std::string& frag, bool keepSrc = false)/*throw(ShaderCompileExecption)*/;
	~Shader();

	void ReCompile(std::string& vert, std::string frag)/*throw(ShaderCompileExecption)*/; 
	void ReCompileVert(std::string& vert)/*throw(ShaderCompileExecption)*/;
	void ReCompileFrag(std::string frag)/*throw(ShaderCompileExecption)*/;

	bool IsValid();

	GET(GLint, ID, m_ProgramID);

private:
	bool m_KeepSrc;

	std::string m_VertSrc;
	std::string m_FragSrc;

	GLint m_ProgramID;
	GLint m_FragID;
	GLint m_VertID;

	LUA_BIND_DECL_CLASS(Shader);

	LUA_BIND_DECL_METHOD(_New);
	LUA_BIND_DECL_METHOD(_ReCompile);
	LUA_BIND_DECL_METHOD(_ReCompileVert);
	LUA_BIND_DECL_METHOD(_ReCompileFrag);
	LUA_BIND_DECL_METHOD(_IsValid);
	LUA_BIND_DECL_METHOD(_GetVertCode);
	LUA_BIND_DECL_METHOD(_GetFragCode);

};

class ShaderCompileExecption : public std::exception
{
public:
	ShaderCompileExecption(std::string& err) 
	{
		m_Err = err;
	}
	char const* what() const override
	{
		return m_Err.c_str();
	}
private: 
	std::string m_Err;
};