blob: ae24548a167439d11a068e410a937078871f80df (
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
#ifndef __ASURA_ENGINE_SHADER_H__
#define __ASURA_ENGINE_SHADER_H__
#include <map>
#include <string>
#include <asura-utils/scripting/portable.hpp>
#include <asura-utils/io/renewable.h>
#include <asura-utils/math/vector2.hpp>
#include <asura-utils/math/vector3.hpp>
#include <asura-utils/math/vector4.h>
#include <asura-utils/math/matrix44.h>
#include <asura-utils/stringmap.hpp>
#include <asura-utils/manager.hpp>
#include "shader_source.h"
#include "color.h"
#include "texture.h"
#include "gl.h"
namespace AsuraEngine
{
namespace Graphics
{
///
/// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ
/// uniformsuseɫķ༭ÿshaderͨshaderҵuniforms
/// ¶frameworkmaterialá
///
class Shader ASURA_FINAL
: public Scripting::Portable<Shader>
, public AEIO::Renewable
{
public:
LUAX_DECL_FACTORY(Shader);
Shader();
~Shader();
///
/// ӴshaderʱȼǷϴλuniforms location mapʹ
/// glAttachShader±ɫɫ
///
//bool Load(const std::string& vertexShader, const std::string& fragmentShader);
bool Refresh(AEIO::DecodedData* decodeData) override;
///
/// shaderΪ
///
void Use();
///
/// shaderΪǻ
///
void Unuse();
///
/// Ѿ֪uniform location£ֵ
///
void SetUniformFloat(uint loc, float value);
void SetUniformTexture(uint loc, const Texture& texture);
void SetUniformVector2(uint loc, const Math::Vector2f& vec2);
void SetUniformVector3(uint loc, const Math::Vector3f& vec3);
void SetUniformVector4(uint loc, const Math::Vector4f& vec4);
void SetUniformColor(uint loc, const Color& color);
void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44);
uint GetUniformLocation(const std::string& uniform);
bool HasUniform(const std::string& uniform);
GLuint GetGLProgramHandle();
///
/// texture unitһΪ16
///
static uint GetGLTextureUnitCount();
private:
///
/// ǰshader
///
static Shader* mCurrentShader;
///
/// ñ
/// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ
/// vec2 Asura_RenderTargetSize RTĴСΪλ
/// Texture Asura_MainTexture
///
void SetBuiltInUniforms();
///
/// OpenGL shader program handle.
///
GLuint mProgram;
Luax::LuaxMemberRef mCodeRef;
private:
//----------------------------------------------------------------------------//
LUAX_DECL_METHOD(_New);
LUAX_DECL_METHOD(_Use);
LUAX_DECL_METHOD(_Unuse);
LUAX_DECL_METHOD(_Load);
LUAX_DECL_METHOD(_HasUniform);
LUAX_DECL_METHOD(_GetUniformLocation);
LUAX_DECL_METHOD(_SetBuiltInUniforms);
LUAX_DECL_METHOD(_SetUniformFloat);
LUAX_DECL_METHOD(_SetUniformTexture);
LUAX_DECL_METHOD(_SetUniformVector2);
LUAX_DECL_METHOD(_SetUniformVector3);
LUAX_DECL_METHOD(_SetUniformVector4);
LUAX_DECL_METHOD(_SetUniformColor);
//----------------------------------------------------------------------------//
};
}
}
#endif
|