From 4ea4bbfcb03091cb987dc151d41980ec16f3d18d Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 8 Apr 2019 22:31:12 +0800 Subject: *misc --- source/modules/asura-core/graphics/shader.h | 65 ++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 14 deletions(-) (limited to 'source/modules/asura-core/graphics/shader.h') diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index 9cf9653..12d2f59 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -14,15 +14,25 @@ #include #include +#include "gl.h" #include "color.h" #include "texture.h" -#include "gl.h" +#include "gpu_buffer.h" namespace AsuraEngine { namespace Graphics { + enum BuiltInUniforms + { + BUILTIN_UNIFORM_MODEL_MATRIX = 0, + BUILTIN_UNIFORM_VIEW_MATRIX, + BUILTIN_UNIFORM_PROJECTION_MATRIX, + + BUILTIN_UNIFORM_COUNT + }; + /// /// 一个shader是一个在材质间共享的程序。Shader本身不保存uniforms和顶点数据,只提供设置 /// uniforms和use着色器的方法。编辑器针对每个shader,会通过shader代码找到声明的uniforms @@ -40,15 +50,33 @@ namespace AsuraEngine bool Load(const std::string& vert, const std::string& frag); - uint GetAttributeLocation(const std::string& name); + void OnUse(); + void OnUnuse(); + + /// + /// 设置顶点属性,Asura只支持2维顶点数据 + /// + int GetAttributeLocation(const std::string& name); + void SetAttribute(int loc, void* data, uint offset = 0, uint stride = 0); + void SetAttribute(int loc, GPUBuffer* vbo, uint offset = 0, uint stride = 0); + /// + /// 设置uniform变量 + /// + bool HasUniform(const std::string& uniform); + uint GetUniformLocation(const std::string& uniform); 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); + bool SetUniformTexture(uint loc, const Texture& texture); + + /// + /// 设置\更新内置uniform变量 + /// + void SetBuiltInUniforms(); float GetUniformFloat(uint loc); AEMath::Vector2f GetUniformVector2(uint loc); @@ -56,20 +84,10 @@ namespace AsuraEngine AEMath::Vector4f GetUniformVector4s(uint loc); AEMath::Matrix44 GetUniformMatrix44(uint loc); - uint GetUniformLocation(const std::string& uniform); - - bool HasUniform(const std::string& uniform); - - GLuint GetGLProgramHandle(); + GLuint GetGLProgram(); static uint GetGLTextureUnitCount(); - private: - - GLuint mProgram; - GLuint mVertShader; - GLuint mFragShader; - private: //----------------------------------------------------------------------------// @@ -95,6 +113,25 @@ namespace AsuraEngine std::string GetProgramWarnings(); std::string GetShaderWarnings(GLuint shader); + + /// + /// Asura shader 语义字符串统一管理。 + /// + static const char* ASLSemantics[BUILTIN_UNIFORM_COUNT]; + + GLuint mProgram; + GLuint mVertShader; + GLuint mFragShader; + + /// + /// Model\View\Projection matrix uniform变量的location。Asura要求shader必须有以下 + /// 语义: + /// 1: asura_model_matrix 模型矩阵 + /// 2: asura_view_matrix 观察者矩阵 + /// 3: asura_projection_matrix 投影(正交)矩阵 + /// 会在framework里设置更多的内置语义,公共部分的语义是游戏和编辑器共有的。 + /// + GLint mMVP[3]; }; -- cgit v1.1-26-g67d0