diff --git a/example/DirectGLRender/main.cpp b/example/DirectGLRender/main.cpp index 78330eff..e49e4360 100644 --- a/example/DirectGLRender/main.cpp +++ b/example/DirectGLRender/main.cpp @@ -6,6 +6,7 @@ #include using namespace hgl; +using namespace hgl::graph; constexpr uint screen_width=1280; constexpr uint screen_height=720; diff --git a/inc/hgl/graph/Shader.h b/inc/hgl/graph/Shader.h index 9817aa2c..f0d3124e 100644 --- a/inc/hgl/graph/Shader.h +++ b/inc/hgl/graph/Shader.h @@ -8,188 +8,191 @@ // #include namespace hgl { - constexpr uint HGL_MAX_SHADER_NAME_LENGTH=128; ///<最大Shader名称长度 - - /** - * 着色程序类型枚举 - */ - enum ShaderType ///着色程序类型 + namespace graph { - stVertex=0, ///<顶点着色程序 - stTessControl, ///<镶嵌控制着色程序(需OpenGL 4.0或ARB_tessellation_shader) - stTessEval, ///<镶嵌评估着色程序(需OpenGL 4.0或ARB_tessellation_shader) - stGeometry, ///<几何着色程序 - stFragment, ///<片断着色程序 - stCompute, ///<计算着色程序(需OpenGL 4.3或ARB_compute_shader) + constexpr uint HGL_MAX_SHADER_NAME_LENGTH=128; ///<最大Shader名称长度 - stEnd - };//enum ShaderType - - extern const char ShaderTypeName[ShaderType::stEnd][32]; ///<着色程序名称 - - /** - * 着色器程序 - */ - class Shader - { - uint program; - - uint shader_index[ShaderType::stEnd]; - - private: - - bool Link(); ///<连接使用当前着色程序 - - protected: - - Map attrib_location; - Map uniform_location; - -// Map uniform_block_index; -// MapObject uniform_block_object; -// -// Map ssbo_index; -// MapObject ssbo_object; - - int _GetAttribLocation(const char *); ///<取得指定属性地址 - int _GetUniformLocation(const char *); ///<取得一个变量的地址 -// int _GetUniformBlockIndex(const char *); ///<取得一个只读数据块的地址索引 -// int _GetShaderStorageIndex(const char *); ///<取得一个数据存储区的地址索引 - - public: - - Shader(){program=0;hgl_zero(shader_index,ShaderType::stEnd);} - ~Shader(){Clear();} - - void Clear(); ///<清除着色程序 - - bool AddShader (const int shader_type,const char *); ///<增加一个着色程序 - - bool AddVertexShader (const char *code){return AddShader(ShaderType::stVertex,code);} ///<增加一个顶点着色程序 - bool AddGeometryShader (const char *code){return AddShader(ShaderType::stGeometry,code);} ///<增加一个几何着色程序 - bool AddFragmentShader (const char *code){return AddShader(ShaderType::stFragment,code);} ///<增加一个片断着色程序 - bool AddComputeShader (const char *code){return AddShader(ShaderType::stFragment,code);} ///<增加一个计算着色程序 - - bool AddTessShader (const char *tess_control_shader,const char *tess_evaluation_shader) ///<增加一个镶嵌着色程序 + /** + * 着色程序类型枚举 + */ + enum ShaderType ///着色程序类型 { - if(!AddShader(ShaderType::stTessControl,tess_control_shader ))return(false); - if(!AddShader(ShaderType::stTessEval, tess_evaluation_shader ))return(false); - return(true); - } + stVertex=0, ///<顶点着色程序 + stTessControl, ///<镶嵌控制着色程序(需OpenGL 4.0或ARB_tessellation_shader) + stTessEval, ///<镶嵌评估着色程序(需OpenGL 4.0或ARB_tessellation_shader) + stGeometry, ///<几何着色程序 + stFragment, ///<片断着色程序 + stCompute, ///<计算着色程序(需OpenGL 4.3或ARB_compute_shader) - bool Build(); ///<构建当前添加的着色程序 + stEnd + };//enum ShaderType - bool Use(); ///<使用当前着色程序 + extern const char ShaderTypeName[ShaderType::stEnd][32]; ///<着色程序名称 - int GetAttribLocation(const char *); ///<取得指定属性地址 - int GetUniformLocation(const char *); ///<取得一个变量的地址 -// int GetUniformBlockIndex(const char *); ///<取得一个只读数据块索引 -// int GetShaderStorageIndex(const char *); ///<取得一个数据存储区索引 + /** + * 着色器程序 + */ + class Shader + { + uint program; - //bool SetAttrib1f(int,float); - //bool GetAttrib1f(int,float &); + uint shader_index[ShaderType::stEnd]; - public: //设置一致变量用函数 + private: - bool SetUniform1f(int,float); - bool SetUniform2f(int,float,float); - bool SetUniform3f(int,float,float,float); - bool SetUniform4f(int,float,float,float,float); + bool Link(); ///<连接使用当前着色程序 - bool SetUniform1i(int,int); - bool SetUniform2i(int,int,int); - bool SetUniform3i(int,int,int,int); - bool SetUniform4i(int,int,int,int,int); + protected: - bool SetUniform1ui(int,unsigned int); - bool SetUniform2ui(int,unsigned int,unsigned int); - bool SetUniform3ui(int,unsigned int,unsigned int,unsigned int); - bool SetUniform4ui(int,unsigned int,unsigned int,unsigned int,unsigned int); + Map attrib_location; + Map uniform_location; - bool SetUniform1fv(int,const float *); - bool SetUniform2fv(int,const float *); - bool SetUniform3fv(int,const float *); - bool SetUniform4fv(int,const float *); + // Map uniform_block_index; + // MapObject uniform_block_object; + // + // Map ssbo_index; + // MapObject ssbo_object; - bool SetUniform2fv(int index,const Vector2f &v){return SetUniform2fv(index,(const float *)&v);} - bool SetUniform3fv(int index,const Vector3f &v){return SetUniform3fv(index,(const float *)&v);} - bool SetUniform4fv(int index,const Vector4f &v){return SetUniform4fv(index,(const float *)&v);} + int _GetAttribLocation(const char *); ///<取得指定属性地址 + int _GetUniformLocation(const char *); ///<取得一个变量的地址 + // int _GetUniformBlockIndex(const char *); ///<取得一个只读数据块的地址索引 + // int _GetShaderStorageIndex(const char *); ///<取得一个数据存储区的地址索引 - bool SetUniform1iv(int,const int *); - bool SetUniform2iv(int,const int *); - bool SetUniform3iv(int,const int *); - bool SetUniform4iv(int,const int *); + public: - bool SetUniform1uiv(int,const unsigned int *); - bool SetUniform2uiv(int,const unsigned int *); - bool SetUniform3uiv(int,const unsigned int *); - bool SetUniform4uiv(int,const unsigned int *); + Shader(){program=0;hgl_zero(shader_index,ShaderType::stEnd);} + ~Shader(){Clear();} - bool SetUniformMatrix2fv(int,const float *); - bool SetUniformMatrix3fv(int,const float *); - bool SetUniformMatrix4fv(int,const float *); + void Clear(); ///<清除着色程序 - bool SetUniformMatrix2x3fv(int,const float *); - bool SetUniformMatrix3x2fv(int,const float *); - bool SetUniformMatrix2x4fv(int,const float *); - bool SetUniformMatrix4x2fv(int,const float *); - bool SetUniformMatrix3x4fv(int,const float *); - bool SetUniformMatrix4x3fv(int,const float *); + bool AddShader (const int shader_type,const char *); ///<增加一个着色程序 - public: + bool AddVertexShader (const char *code){return AddShader(ShaderType::stVertex,code);} ///<增加一个顶点着色程序 + bool AddGeometryShader (const char *code){return AddShader(ShaderType::stGeometry,code);} ///<增加一个几何着色程序 + bool AddFragmentShader (const char *code){return AddShader(ShaderType::stFragment,code);} ///<增加一个片断着色程序 + bool AddComputeShader (const char *code){return AddShader(ShaderType::stFragment,code);} ///<增加一个计算着色程序 - bool SetUniform1f(const char *,float); - bool SetUniform2f(const char *,float,float); - bool SetUniform3f(const char *,float,float,float); - bool SetUniform4f(const char *,float,float,float,float); + bool AddTessShader (const char *tess_control_shader,const char *tess_evaluation_shader) ///<增加一个镶嵌着色程序 + { + if(!AddShader(ShaderType::stTessControl,tess_control_shader ))return(false); + if(!AddShader(ShaderType::stTessEval, tess_evaluation_shader ))return(false); + return(true); + } - bool SetUniform1i(const char *,int); - bool SetUniform2i(const char *,int,int); - bool SetUniform3i(const char *,int,int,int); - bool SetUniform4i(const char *,int,int,int,int); + bool Build(); ///<构建当前添加的着色程序 - bool SetUniform1ui(const char *,unsigned int); - bool SetUniform2ui(const char *,unsigned int,unsigned int); - bool SetUniform3ui(const char *,unsigned int,unsigned int,unsigned int); - bool SetUniform4ui(const char *,unsigned int,unsigned int,unsigned int,unsigned int); + bool Use(); ///<使用当前着色程序 - bool SetUniform1fv(const char *,const float *); - bool SetUniform2fv(const char *,const float *); - bool SetUniform3fv(const char *,const float *); - bool SetUniform4fv(const char *,const float *); + int GetAttribLocation(const char *); ///<取得指定属性地址 + int GetUniformLocation(const char *); ///<取得一个变量的地址 + // int GetUniformBlockIndex(const char *); ///<取得一个只读数据块索引 + // int GetShaderStorageIndex(const char *); ///<取得一个数据存储区索引 - bool SetUniform2fv(const char *name,const Vector2f &v){return SetUniform2fv(name,(const float *)&v);} - bool SetUniform3fv(const char *name,const Vector3f &v){return SetUniform3fv(name,(const float *)&v);} - bool SetUniform4fv(const char *name,const Vector4f &v){return SetUniform4fv(name,(const float *)&v);} + //bool SetAttrib1f(int,float); + //bool GetAttrib1f(int,float &); - bool SetUniform1iv(const char *,const int *); - bool SetUniform2iv(const char *,const int *); - bool SetUniform3iv(const char *,const int *); - bool SetUniform4iv(const char *,const int *); + public: //设置一致变量用函数 - bool SetUniform1uiv(const char *,const unsigned int *); - bool SetUniform2uiv(const char *,const unsigned int *); - bool SetUniform3uiv(const char *,const unsigned int *); - bool SetUniform4uiv(const char *,const unsigned int *); + bool SetUniform1f(int,float); + bool SetUniform2f(int,float,float); + bool SetUniform3f(int,float,float,float); + bool SetUniform4f(int,float,float,float,float); - bool SetUniformMatrix2fv(const char *,const float *); - bool SetUniformMatrix3fv(const char *,const float *); - bool SetUniformMatrix4fv(const char *,const float *); + bool SetUniform1i(int,int); + bool SetUniform2i(int,int,int); + bool SetUniform3i(int,int,int,int); + bool SetUniform4i(int,int,int,int,int); - bool SetUniformMatrix3fv(const char *name,const Matrix3f &m){return SetUniformMatrix3fv(name,(const float *)&m);} - bool SetUniformMatrix4fv(const char *name,const Matrix4f &m){return SetUniformMatrix4fv(name,(const float *)&m);} + bool SetUniform1ui(int,unsigned int); + bool SetUniform2ui(int,unsigned int,unsigned int); + bool SetUniform3ui(int,unsigned int,unsigned int,unsigned int); + bool SetUniform4ui(int,unsigned int,unsigned int,unsigned int,unsigned int); - bool SetUniformMatrix2x3fv(const char *,const float *); - bool SetUniformMatrix3x2fv(const char *,const float *); - bool SetUniformMatrix2x4fv(const char *,const float *); - bool SetUniformMatrix4x2fv(const char *,const float *); - bool SetUniformMatrix3x4fv(const char *,const float *); - bool SetUniformMatrix4x3fv(const char *,const float *); + bool SetUniform1fv(int,const float *); + bool SetUniform2fv(int,const float *); + bool SetUniform3fv(int,const float *); + bool SetUniform4fv(int,const float *); - // public: //Uniform Block - // - // UBO *GetUniformBlock(const char *,uint=HGL_DYNAMIC_DRAW); - // SSBO *GetShaderStorage(const char *,uint=HGL_DYNAMIC_DRAW); - };//class Shader + bool SetUniform2fv(int index,const Vector2f &v){return SetUniform2fv(index,(const float *)&v);} + bool SetUniform3fv(int index,const Vector3f &v){return SetUniform3fv(index,(const float *)&v);} + bool SetUniform4fv(int index,const Vector4f &v){return SetUniform4fv(index,(const float *)&v);} + + bool SetUniform1iv(int,const int *); + bool SetUniform2iv(int,const int *); + bool SetUniform3iv(int,const int *); + bool SetUniform4iv(int,const int *); + + bool SetUniform1uiv(int,const unsigned int *); + bool SetUniform2uiv(int,const unsigned int *); + bool SetUniform3uiv(int,const unsigned int *); + bool SetUniform4uiv(int,const unsigned int *); + + bool SetUniformMatrix2fv(int,const float *); + bool SetUniformMatrix3fv(int,const float *); + bool SetUniformMatrix4fv(int,const float *); + + bool SetUniformMatrix2x3fv(int,const float *); + bool SetUniformMatrix3x2fv(int,const float *); + bool SetUniformMatrix2x4fv(int,const float *); + bool SetUniformMatrix4x2fv(int,const float *); + bool SetUniformMatrix3x4fv(int,const float *); + bool SetUniformMatrix4x3fv(int,const float *); + + public: + + bool SetUniform1f(const char *,float); + bool SetUniform2f(const char *,float,float); + bool SetUniform3f(const char *,float,float,float); + bool SetUniform4f(const char *,float,float,float,float); + + bool SetUniform1i(const char *,int); + bool SetUniform2i(const char *,int,int); + bool SetUniform3i(const char *,int,int,int); + bool SetUniform4i(const char *,int,int,int,int); + + bool SetUniform1ui(const char *,unsigned int); + bool SetUniform2ui(const char *,unsigned int,unsigned int); + bool SetUniform3ui(const char *,unsigned int,unsigned int,unsigned int); + bool SetUniform4ui(const char *,unsigned int,unsigned int,unsigned int,unsigned int); + + bool SetUniform1fv(const char *,const float *); + bool SetUniform2fv(const char *,const float *); + bool SetUniform3fv(const char *,const float *); + bool SetUniform4fv(const char *,const float *); + + bool SetUniform2fv(const char *name,const Vector2f &v){return SetUniform2fv(name,(const float *)&v);} + bool SetUniform3fv(const char *name,const Vector3f &v){return SetUniform3fv(name,(const float *)&v);} + bool SetUniform4fv(const char *name,const Vector4f &v){return SetUniform4fv(name,(const float *)&v);} + + bool SetUniform1iv(const char *,const int *); + bool SetUniform2iv(const char *,const int *); + bool SetUniform3iv(const char *,const int *); + bool SetUniform4iv(const char *,const int *); + + bool SetUniform1uiv(const char *,const unsigned int *); + bool SetUniform2uiv(const char *,const unsigned int *); + bool SetUniform3uiv(const char *,const unsigned int *); + bool SetUniform4uiv(const char *,const unsigned int *); + + bool SetUniformMatrix2fv(const char *,const float *); + bool SetUniformMatrix3fv(const char *,const float *); + bool SetUniformMatrix4fv(const char *,const float *); + + bool SetUniformMatrix3fv(const char *name,const Matrix3f &m){return SetUniformMatrix3fv(name,(const float *)&m);} + bool SetUniformMatrix4fv(const char *name,const Matrix4f &m){return SetUniformMatrix4fv(name,(const float *)&m);} + + bool SetUniformMatrix2x3fv(const char *,const float *); + bool SetUniformMatrix3x2fv(const char *,const float *); + bool SetUniformMatrix2x4fv(const char *,const float *); + bool SetUniformMatrix4x2fv(const char *,const float *); + bool SetUniformMatrix3x4fv(const char *,const float *); + bool SetUniformMatrix4x3fv(const char *,const float *); + + // public: //Uniform Block + // + // UBO *GetUniformBlock(const char *,uint=HGL_DYNAMIC_DRAW); + // SSBO *GetShaderStorage(const char *,uint=HGL_DYNAMIC_DRAW); + };//class Shader + }//namespace graph }//namespace hgl #endif//HGL_SHADER_INCLUDE diff --git a/src/RenderDriver/GLCore/RenderDriverGLCore.cpp b/src/RenderDriver/GLCore/RenderDriverGLCore.cpp index 5f241632..1ee0df10 100644 --- a/src/RenderDriver/GLCore/RenderDriverGLCore.cpp +++ b/src/RenderDriver/GLCore/RenderDriverGLCore.cpp @@ -1,21 +1,24 @@ -#include +#include namespace hgl { - class RenderDriverGLCore:public RenderDriver + namespace graph { - public: - - void SetCurStatus(const RenderStatus &rs) override + class RenderDriverGLCore:public RenderDriver { - } + public: - void ClearColorBuffer() override - { - } + void SetCurStatus(const RenderStatus &rs) override + { + } - void ClearDepthBuffer() override - { - } - };//class RenderDriverGLCore:public RenderDriver + void ClearColorBuffer() override + { + } + + void ClearDepthBuffer() override + { + } + };//class RenderDriverGLCore:public RenderDriver + }//namespace graph }//namespace hgl diff --git a/src/RenderDriver/GLSL.cpp b/src/RenderDriver/GLSL.cpp index ce2c129a..23d53672 100644 --- a/src/RenderDriver/GLSL.cpp +++ b/src/RenderDriver/GLSL.cpp @@ -1,4 +1,4 @@ -#include +#include //#include #include #include @@ -6,388 +6,391 @@ namespace hgl { - namespace + namespace graph { - constexpr uint OpenGLShaderType[ShaderType::stEnd]= + namespace { - GL_VERTEX_SHADER, ///<顶点着色程序 - GL_TESS_CONTROL_SHADER, ///<镶嵌控制着色程序(需OpenGL 4.0或ARB_tessellation_shader) - GL_TESS_EVALUATION_SHADER, ///<镶嵌评估着色程序(需OpenGL 4.0或ARB_tessellation_shader) - GL_GEOMETRY_SHADER, ///<几何着色程序 - GL_FRAGMENT_SHADER, ///<片断着色程序 - GL_COMPUTE_SHADER ///<计算着色程序(需OpenGL 4.3或ARB_compute_shader) + constexpr uint OpenGLShaderType[ShaderType::stEnd]= + { + GL_VERTEX_SHADER, ///<顶点着色程序 + GL_TESS_CONTROL_SHADER, ///<镶嵌控制着色程序(需OpenGL 4.0或ARB_tessellation_shader) + GL_TESS_EVALUATION_SHADER, ///<镶嵌评估着色程序(需OpenGL 4.0或ARB_tessellation_shader) + GL_GEOMETRY_SHADER, ///<几何着色程序 + GL_FRAGMENT_SHADER, ///<片断着色程序 + GL_COMPUTE_SHADER ///<计算着色程序(需OpenGL 4.3或ARB_compute_shader) + }; + } + + const char ShaderTypeName[ShaderType::stEnd][32]= + { + "Vertex", + "TessControl", + "TessEvaluation", + "Geometry", + "Fragment", + "Compute" }; - } - const char ShaderTypeName[ShaderType::stEnd][32]= - { - "Vertex", - "TessControl", - "TessEvaluation", - "Geometry", - "Fragment", - "Compute" - }; - - namespace - { - /** - * 编译一段shader - * @param type 类型 - * @param name 名称 - * @param shader_source 代码 - * @return 编译成功的shader句柄 - * @return 0 编译失败 - */ - GLuint CompileShader(GLenum type,const char *name,const char *shader_source) + namespace { - if(!shader_source)return(0); + /** + * 编译一段shader + * @param type 类型 + * @param name 名称 + * @param shader_source 代码 + * @return 编译成功的shader句柄 + * @return 0 编译失败 + */ + GLuint CompileShader(GLenum type,const char *name,const char *shader_source) + { + if(!shader_source)return(0); - GLuint shader=glCreateShader(type); + GLuint shader=glCreateShader(type); - glShaderSource(shader,1,&shader_source,0); + glShaderSource(shader,1,&shader_source,0); - glCompileShader(shader); + glCompileShader(shader); - GLint compiled,log_length; + GLint compiled,log_length; - glGetShaderiv(shader,GL_COMPILE_STATUS,&compiled); + glGetShaderiv(shader,GL_COMPILE_STATUS,&compiled); - if(compiled) - return(shader); + if(compiled) + return(shader); - glGetShaderiv(shader,GL_INFO_LOG_LENGTH,&log_length); + glGetShaderiv(shader,GL_INFO_LOG_LENGTH,&log_length); - GLint char_writen; - char *log=new char[log_length]; + GLint char_writen; + char *log=new char[log_length]; - glGetShaderInfoLog(shader,log_length,&char_writen,log); + glGetShaderInfoLog(shader,log_length,&char_writen,log); -// LOG_HINT(UTF8String(name)+U8_TEXT(" shader compile error\n\n")+ UTF8String(log)); + // LOG_HINT(UTF8String(name)+U8_TEXT(" shader compile error\n\n")+ UTF8String(log)); + + delete[] log; + + //LOG_ERROR(shader_source); + + glDeleteShader(shader); + + return(0); + } + }//namespace + + void Shader::Clear() + { + for(int i=0;i=ShaderType::stEnd)return(false); + if(shader_index[shader_type])return(false); + + if(!shader_codes + ||!(*shader_codes))return(false); + + shader_index[shader_type]=CompileShader(OpenGLShaderType[shader_type],ShaderTypeName[shader_type],shader_codes); + + if(!shader_index[shader_type]) + return(false); + + return(true); + } + + bool Shader::Build() + { + program=glCreateProgram(); + + for(int i=0;i=ShaderType::stEnd)return(false); - if(shader_index[shader_type])return(false); - - if(!shader_codes - ||!(*shader_codes))return(false); - - shader_index[shader_type]=CompileShader(OpenGLShaderType[shader_type],ShaderTypeName[shader_type],shader_codes); - - if(!shader_index[shader_type]) - return(false); - - return(true); - } - - bool Shader::Build() - { - program=glCreateProgram(); - - for(int i=0;i +#include //#include namespace hgl { - /** - * 取得属性索引地址 - * @param name 属性名称 - * @return 索引地址 - * @return -1 出错 - */ - int Shader::GetAttribLocation(const char *name) + namespace graph { - if(!name||!(*name))return(-1); - - int result; - - if(!attrib_location.Get(name,result)) + /** + * 取得属性索引地址 + * @param name 属性名称 + * @return 索引地址 + * @return -1 出错 + */ + int Shader::GetAttribLocation(const char *name) { - result=_GetAttribLocation(name); + if(!name||!(*name))return(-1); - attrib_location.Add(name,result); + int result; + + if(!attrib_location.Get(name,result)) + { + result=_GetAttribLocation(name); + + attrib_location.Add(name,result); + } + + return result; } - return result; - } - - /** - * 取得一个变量的地址 - * @param name 变量名称 - * @return 地址 - * @return -1 出错 - */ - int Shader::GetUniformLocation(const char *name) ///<取得一个变量的地址 - { - if(!name||!(*name))return(-1); - - int result; - - if(!uniform_location.Get(name,result)) + /** + * 取得一个变量的地址 + * @param name 变量名称 + * @return 地址 + * @return -1 出错 + */ + int Shader::GetUniformLocation(const char *name) ///<取得一个变量的地址 { - result=_GetUniformLocation(name); + if(!name||!(*name))return(-1); - uniform_location.Add(name,result); + int result; + + if(!uniform_location.Get(name,result)) + { + result=_GetUniformLocation(name); + + uniform_location.Add(name,result); + } + + return result; } - return result; - } + // /** + // * 取得一个Shader只读数据区索引 + // * @param name 数据区名称 + // * @return 数据区索引 + // * @return -1 出错 + // */ + // int Shader::GetUniformBlockIndex(const char *name) + // { + // if(!name||!(*name))return(-1); + // + // int result; + // + // if(!uniform_block_index.Get(name,result)) + // { + // result=_GetUniformBlockIndex(name); + // + // uniform_block_index.Add(name,result); + // } + // + // return result; + // } + // + // /** + // * 取得一个Shader数据存储区索引 + // * @param name 数据存储区名称 + // * @return 数据存储区索引 + // * @return -1 出错 + // */ + // int Shader::GetShaderStorageIndex(const char *name) + // { + // if(!name||!(*name))return(-1); + // + // int result; + // + // if(!ssbo_index.Get(name,result)) + // { + // result=_GetShaderStorageIndex(name); + // + // ssbo_index.Add(name,result); + // } + // + // return result; + // } -// /** -// * 取得一个Shader只读数据区索引 -// * @param name 数据区名称 -// * @return 数据区索引 -// * @return -1 出错 -// */ -// int Shader::GetUniformBlockIndex(const char *name) -// { -// if(!name||!(*name))return(-1); -// -// int result; -// -// if(!uniform_block_index.Get(name,result)) -// { -// result=_GetUniformBlockIndex(name); -// -// uniform_block_index.Add(name,result); -// } -// -// return result; -// } -// -// /** -// * 取得一个Shader数据存储区索引 -// * @param name 数据存储区名称 -// * @return 数据存储区索引 -// * @return -1 出错 -// */ -// int Shader::GetShaderStorageIndex(const char *name) -// { -// if(!name||!(*name))return(-1); -// -// int result; -// -// if(!ssbo_index.Get(name,result)) -// { -// result=_GetShaderStorageIndex(name); -// -// ssbo_index.Add(name,result); -// } -// -// return result; -// } - - #define HGL_GLSL_SetUniform1234(func,type) bool Shader::SetUniform1##func(const char *uniform_name,type v0) \ - { \ - const int location=GetUniformLocation(uniform_name); \ - \ - if(location==-1)return(false); \ - \ - return SetUniform1##func(location,v0); \ - } \ - \ - bool Shader::SetUniform2##func(const char *uniform_name,type v0,type v1) \ - { \ - const int location=GetUniformLocation(uniform_name); \ - \ - if(location==-1)return(false); \ - \ - return SetUniform2##func(location,v0,v1); \ - } \ - \ - bool Shader::SetUniform3##func(const char *uniform_name,type v0,type v1,type v2) \ - { \ - const int location=GetUniformLocation(uniform_name); \ - \ - if(location==-1)return(false); \ - \ - return SetUniform3##func(location,v0,v1,v2); \ - } \ - \ - bool Shader::SetUniform4##func(const char *uniform_name,type v0,type v1,type v2,type v3) \ - { \ - const int location=GetUniformLocation(uniform_name); \ - \ - if(location==-1)return(false); \ - \ - return SetUniform4##func(location,v0,v1,v2,v3); \ - } - HGL_GLSL_SetUniform1234(f,float); - HGL_GLSL_SetUniform1234(i,int); - HGL_GLSL_SetUniform1234(ui,unsigned int); - - #undef HGL_GLSL_SetUniform1234 - - #define HGL_GLSL_SetUniformPointer(func,type) bool Shader::SetUniform##func(const char *uniform_name,const type *value) \ + #define HGL_GLSL_SetUniform1234(func,type) bool Shader::SetUniform1##func(const char *uniform_name,type v0) \ { \ const int location=GetUniformLocation(uniform_name); \ \ if(location==-1)return(false); \ \ - return SetUniform##func(location,value); \ - } - - HGL_GLSL_SetUniformPointer(1fv,float); - HGL_GLSL_SetUniformPointer(2fv,float); - HGL_GLSL_SetUniformPointer(3fv,float); - HGL_GLSL_SetUniformPointer(4fv,float); - - HGL_GLSL_SetUniformPointer(1iv,int); - HGL_GLSL_SetUniformPointer(2iv,int); - HGL_GLSL_SetUniformPointer(3iv,int); - HGL_GLSL_SetUniformPointer(4iv,int); - - HGL_GLSL_SetUniformPointer(1uiv,unsigned int); - HGL_GLSL_SetUniformPointer(2uiv,unsigned int); - HGL_GLSL_SetUniformPointer(3uiv,unsigned int); - HGL_GLSL_SetUniformPointer(4uiv,unsigned int); - - #undef HGL_GLSL_SetUniformPointer - - #define HGL_GLSL_SetUniformMatrixPointer(func) bool Shader::SetUniformMatrix##func(const char *uniform_name,const float *mat) \ + return SetUniform1##func(location,v0); \ + } \ + \ + bool Shader::SetUniform2##func(const char *uniform_name,type v0,type v1) \ { \ const int location=GetUniformLocation(uniform_name); \ \ if(location==-1)return(false); \ \ - return SetUniformMatrix##func(location,mat); \ + return SetUniform2##func(location,v0,v1); \ + } \ + \ + bool Shader::SetUniform3##func(const char *uniform_name,type v0,type v1,type v2) \ + { \ + const int location=GetUniformLocation(uniform_name); \ + \ + if(location==-1)return(false); \ + \ + return SetUniform3##func(location,v0,v1,v2); \ + } \ + \ + bool Shader::SetUniform4##func(const char *uniform_name,type v0,type v1,type v2,type v3) \ + { \ + const int location=GetUniformLocation(uniform_name); \ + \ + if(location==-1)return(false); \ + \ + return SetUniform4##func(location,v0,v1,v2,v3); \ } + HGL_GLSL_SetUniform1234(f,float); + HGL_GLSL_SetUniform1234(i,int); + HGL_GLSL_SetUniform1234(ui,unsigned int); - HGL_GLSL_SetUniformMatrixPointer(2fv); - HGL_GLSL_SetUniformMatrixPointer(3fv); - HGL_GLSL_SetUniformMatrixPointer(4fv); + #undef HGL_GLSL_SetUniform1234 - HGL_GLSL_SetUniformMatrixPointer(2x3fv); - HGL_GLSL_SetUniformMatrixPointer(3x2fv); - HGL_GLSL_SetUniformMatrixPointer(2x4fv); - HGL_GLSL_SetUniformMatrixPointer(4x2fv); - HGL_GLSL_SetUniformMatrixPointer(3x4fv); - HGL_GLSL_SetUniformMatrixPointer(4x3fv); + #define HGL_GLSL_SetUniformPointer(func,type) bool Shader::SetUniform##func(const char *uniform_name,const type *value) \ + { \ + const int location=GetUniformLocation(uniform_name); \ + \ + if(location==-1)return(false); \ + \ + return SetUniform##func(location,value); \ + } - #undef HGL_GLSL_SetUniformMatrixPointer + HGL_GLSL_SetUniformPointer(1fv,float); + HGL_GLSL_SetUniformPointer(2fv,float); + HGL_GLSL_SetUniformPointer(3fv,float); + HGL_GLSL_SetUniformPointer(4fv,float); -// /** -// * 取得一个Shader只读数据区的访问对象 -// * @param name 对象名称 -// * @param level 访问级别 -// * @return 对象指针 -// */ -// UBO *Shader::GetUniformBlock(const char *name,uint level) -// { -// if(!name||!(*name)) -// { -// LOG_ERROR(U8_TEXT("UBO name error:")); -// return(nullptr); -// } -// -// UBO *ubo=uniform_block_object[name]; -// -// if(ubo) -// return ubo; -// -// const int index=GetUniformBlockIndex(name); -// -// if(index<0) -// { -// LOG_ERROR(U8_TEXT("UBO name error:")+UTF8String(name)); -// return(nullptr); -// } -// -// ubo=new UBO(name,program,index,level); -// -// uniform_block_object.Add(name,ubo); -// -// return ubo; -// } -// -// /** -// * 取得一个Shader数据存储区的访问对象 -// * @param name 对象名称 -// * @param level 访问级别 -// * @return 对象指针 -// */ -// SSBO *Shader::GetShaderStorage(const char *name,uint level) -// { -// if(!name||!(*name)) -// { -// LOG_ERROR(U8_TEXT("SSBO name error:")); -// return(nullptr); -// } -// -// SSBO *ssbo=ssbo_object[name]; -// -// if(ssbo) -// return ssbo; -// -// const int index=GetShaderStorageIndex(name); -// -// if(index<0) -// { -// LOG_ERROR(U8_TEXT("SSBO name error:")+UTF8String(name)); -// return(nullptr); -// } -// -// ssbo=new SSBO(name,program,index,level); -// -// ssbo_object.Add(name,ssbo); -// -// return ssbo; -// } + HGL_GLSL_SetUniformPointer(1iv,int); + HGL_GLSL_SetUniformPointer(2iv,int); + HGL_GLSL_SetUniformPointer(3iv,int); + HGL_GLSL_SetUniformPointer(4iv,int); + + HGL_GLSL_SetUniformPointer(1uiv,unsigned int); + HGL_GLSL_SetUniformPointer(2uiv,unsigned int); + HGL_GLSL_SetUniformPointer(3uiv,unsigned int); + HGL_GLSL_SetUniformPointer(4uiv,unsigned int); + + #undef HGL_GLSL_SetUniformPointer + + #define HGL_GLSL_SetUniformMatrixPointer(func) bool Shader::SetUniformMatrix##func(const char *uniform_name,const float *mat) \ + { \ + const int location=GetUniformLocation(uniform_name); \ + \ + if(location==-1)return(false); \ + \ + return SetUniformMatrix##func(location,mat); \ + } + + HGL_GLSL_SetUniformMatrixPointer(2fv); + HGL_GLSL_SetUniformMatrixPointer(3fv); + HGL_GLSL_SetUniformMatrixPointer(4fv); + + HGL_GLSL_SetUniformMatrixPointer(2x3fv); + HGL_GLSL_SetUniformMatrixPointer(3x2fv); + HGL_GLSL_SetUniformMatrixPointer(2x4fv); + HGL_GLSL_SetUniformMatrixPointer(4x2fv); + HGL_GLSL_SetUniformMatrixPointer(3x4fv); + HGL_GLSL_SetUniformMatrixPointer(4x3fv); + + #undef HGL_GLSL_SetUniformMatrixPointer + + // /** + // * 取得一个Shader只读数据区的访问对象 + // * @param name 对象名称 + // * @param level 访问级别 + // * @return 对象指针 + // */ + // UBO *Shader::GetUniformBlock(const char *name,uint level) + // { + // if(!name||!(*name)) + // { + // LOG_ERROR(U8_TEXT("UBO name error:")); + // return(nullptr); + // } + // + // UBO *ubo=uniform_block_object[name]; + // + // if(ubo) + // return ubo; + // + // const int index=GetUniformBlockIndex(name); + // + // if(index<0) + // { + // LOG_ERROR(U8_TEXT("UBO name error:")+UTF8String(name)); + // return(nullptr); + // } + // + // ubo=new UBO(name,program,index,level); + // + // uniform_block_object.Add(name,ubo); + // + // return ubo; + // } + // + // /** + // * 取得一个Shader数据存储区的访问对象 + // * @param name 对象名称 + // * @param level 访问级别 + // * @return 对象指针 + // */ + // SSBO *Shader::GetShaderStorage(const char *name,uint level) + // { + // if(!name||!(*name)) + // { + // LOG_ERROR(U8_TEXT("SSBO name error:")); + // return(nullptr); + // } + // + // SSBO *ssbo=ssbo_object[name]; + // + // if(ssbo) + // return ssbo; + // + // const int index=GetShaderStorageIndex(name); + // + // if(index<0) + // { + // LOG_ERROR(U8_TEXT("SSBO name error:")+UTF8String(name)); + // return(nullptr); + // } + // + // ssbo=new SSBO(name,program,index,level); + // + // ssbo_object.Add(name,ssbo); + // + // return ssbo; + // } + }//namespace graph }//namespace hgl