diff options
author | chai <chaifix@163.com> | 2019-04-02 08:47:15 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-04-02 08:47:15 +0800 |
commit | 250e30d73f09e9da2b5a81d0fbae63744ae12a73 (patch) | |
tree | 0f55daf334c073e1779d7a1284799a2056aad714 /source/libs/asura-lib-core/graphics/shader.h | |
parent | 66fe16dd5ed57ae958fc25158d0defae2e6fae6a (diff) |
*misc
Diffstat (limited to 'source/libs/asura-lib-core/graphics/shader.h')
-rw-r--r-- | source/libs/asura-lib-core/graphics/shader.h | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/source/libs/asura-lib-core/graphics/shader.h b/source/libs/asura-lib-core/graphics/shader.h new file mode 100644 index 0000000..1c81355 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/shader.h @@ -0,0 +1,126 @@ +#ifndef __ASURA_ENGINE_SHADER_H__ +#define __ASURA_ENGINE_SHADER_H__ + +#include <map> +#include <string> + +#include <asura-lib-utils/scripting/portable.hpp> +#include <asura-lib-utils/io/reloadable.h> +#include <asura-lib-utils/math/vector2.hpp> +#include <asura-lib-utils/math/vector3.hpp> +#include <asura-lib-utils/math/vector4.h> +#include <asura-lib-utils/math/matrix44.h> +#include <asura-lib-utils/stringmap.hpp> +#include <asura-lib-utils/manager.hpp> + +#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::Reloadable + { + public: + + Shader(); + + ~Shader(); + + /// + /// ӴshaderʱȼǷϴλuniforms location mapʹglAttachShader±ɫ + /// ɫ + /// + bool Load(const std::string& vertexShader, const std::string& fragmentShader); + + /// + /// 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 mProgramHandle; + + //------------------------------------------------------------------------------// + + public: + + LUAX_DECL_FACTORY(SimShader); + + 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); + + private: + + Luax::LuaxMemberRef mCodeLuaRef; + + }; + + } +} + +#endif
\ No newline at end of file |