blob: 02d9f46a0071f51b21e98aba63dcc24be8028d56 (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#ifndef __ASURA_ENGINE_SHADER_H__
#define __ASURA_ENGINE_SHADER_H__
#include <map>
#include <string>
#include "luax/luax.h"
#include "StringMap.hpp"
#include "Object.h"
#include "Color.h"
#include "Manager.hpp"
#include "Texture.h"
#include "Math/Vector2.h"
#include "Math/Vector3.h"
#include "Math/Vector4.h"
#include "GL.h"
namespace AsuraEngine
{
namespace Graphics
{
///
/// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩuniformsuseɫķ༭ÿ
/// shaderͨshaderҵuniforms¶frameworkmaterialá
///
class Shader : virtual public Object
{
public:
Shader();
~Shader();
///
/// ӴshaderʱȼǷϴλuniforms location map
///
void Load(const std::string& vertexShader, const std::string& fragmentShader);
///
/// shaderΪ
///
void Use();
///
/// shaderΪǻ
///
void UnUse();
///
/// һϵuniformsķ
///
void SetUniformFloat(const std::string& uniform, float value);
void SetUniformTexture(const std::string& uniform, const Texture& texture);
void SetUniformVector2(const std::string& uniform, const Math::Vector2& vec2);
void SetUniformVector3(const std::string& uniform, const Math::Vector3& vec3);
void SetUniformVector4(const std::string& uniform, const Math::Vector4& vec4);
///
/// Ѿ֪uniform location£ֵ
///
void SetUniformFloat(uint loc, float value);
void SetUniformTexture(uint loc, const Texture& texture);
void SetUniformVector2(uint loc, const Math::Vector2& vec2);
void SetUniformVector3(uint loc, const Math::Vector3& vec3);
void SetUniformVector4(uint loc, const Math::Vector4& vec4);
/*
///
/// עܷframeworkʵ֣㣬shadereditorҲõ
/// ջunifrom location±shaderµuniform location
///
void ClearUniformLocation();
*/
///
/// program id
///
GLint GetNativeHandle();
uint GetUniformLocation(const std::string& uniform);
private:
///
/// ñ
/// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ
/// vec2 Asura_RenderTargetSize RTĴСΪλ
/// Texture Asura_MainTexture
///
void SetBuiltInUniforms();
// OpenGLɫʶprogram id
GLuint mPID;
//// Uniformlocations
//StringMap<uint> mUniformLocation;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
LUAX_DECL_FACTORY(SimShader);
LUAX_DECL_METHOD(l_SetBuiltInUniforms);
LUAX_DECL_METHOD(l_SetUniformFloat);
LUAX_DECL_METHOD(l_SetUniformTexture);
LUAX_DECL_METHOD(l_SetUniformVector2);
LUAX_DECL_METHOD(l_SetUniformVector3);
LUAX_DECL_METHOD(l_SetUniformVector4);
};
}
}
#endif
|