diff --git a/example/DirectGLRender/main.cpp b/example/DirectGLRender/main.cpp index a8612991..78330eff 100644 --- a/example/DirectGLRender/main.cpp +++ b/example/DirectGLRender/main.cpp @@ -1,8 +1,8 @@ -#include -#include +#include +#include #include #include -#include +#include #include using namespace hgl; @@ -18,7 +18,6 @@ void InitMatrix() false); //Y轴使用底为0顶为1 } - constexpr char vertex_shader[]=R"( #version 330 core diff --git a/example/DrawTriangle/main.cpp b/example/DrawTriangle/main.cpp index 51888f0a..4a76274a 100644 --- a/example/DrawTriangle/main.cpp +++ b/example/DrawTriangle/main.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include #include diff --git a/example/EnumRenderDevice/main.cpp b/example/EnumRenderDevice/main.cpp index eceb322b..e4d3ad43 100644 --- a/example/EnumRenderDevice/main.cpp +++ b/example/EnumRenderDevice/main.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/example/NullWindow/main.cpp b/example/NullWindow/main.cpp index d82f47db..e8a4db3c 100644 --- a/example/NullWindow/main.cpp +++ b/example/NullWindow/main.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include diff --git a/example/OutputGLInfo/main.cpp b/example/OutputGLInfo/main.cpp index c3a8037c..63a5b862 100644 --- a/example/OutputGLInfo/main.cpp +++ b/example/OutputGLInfo/main.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include #include diff --git a/inc/hgl/graph/RenderDevice.h b/inc/hgl/graph/RenderDevice.h new file mode 100644 index 00000000..f752dd74 --- /dev/null +++ b/inc/hgl/graph/RenderDevice.h @@ -0,0 +1,136 @@ +#ifndef HGL_RENDER_DEVICE_INCLUDE +#define HGL_RENDER_DEVICE_INCLUDE + +#include +#include +#include + +namespace hgl +{ + /** + * 显示模式数据结构 + */ + struct VideoMode + { + int width; ///<宽 + int height; ///<高 + int bit; ///<色彩位数 + int freq; ///<刷新率 + + int red; ///<红色位数 + int green; ///<绿色位数 + int blue; ///<蓝色位数 + };//struct VideoMode + + /** + * 显示屏数据结构 + */ + struct Display + { + UTF8String name; ///<显示屏名称 + int width,height; ///<显示屏尺寸(单位:毫米) + int x,y; ///<多显示屏时的排列位置 + + public: + + virtual const VideoMode *GetCurVideoMode()const=0; + virtual const ObjectList &GetVideoModeList()const=0; + }; + + struct WindowSetup + { + UTF8String Name; ///<窗口标题 + +// OSString IconFilename; ///<图标文件名称 +// OSString CursorFilename; ///<光标文件名称 + bool Edge =true; ///<是否显示边框 + + bool SysMenu =true; ///<是否显示系统菜单 + bool Right =false; ///<窗口是否使用靠右风格 + + bool Resize =false; ///<窗口大小是否可调整 + bool Minimize =false; ///<窗口是否可以最小化 + bool Maximize =false; ///<窗口是否可以最大化 + + bool TopMost =false; ///<永远在最上面 + bool AppTaskBar =true; ///<程序项在任务栏显示 + }; + + /** + * 渲染设备 + */ + struct RenderSetup + { + uint alpha; /// + * 该类是程序与操作系统或其它系统库的访问交接模块 + */ + class RenderDevice:public _Object + { + public: + + RenderDevice()=default; + virtual ~RenderDevice()=default; + + virtual const bool Init()=0; ///<初始化渲染设备 + virtual const void Close()=0; ///<关闭渲染设备 + + virtual const UTF8String GetName()=0; ///<取得设备名称 + + virtual const void GetDisplayList(List &)=0; ///<取得显示屏列表 + virtual const Display * GetDefaultDisplay()=0; ///<取得默认显示屏 + + public: + + virtual RenderWindow *Create(int,int,const WindowSetup *,const RenderSetup *)=0; ///<创建一个窗口渲染设备 + virtual RenderWindow *Create(const Display *,const VideoMode *,const RenderSetup *)=0; ///<创建一个全屏渲染设备 + };//class RenderDevice + + RenderDevice *CreateRenderDeviceGLFW(); ///<创建一个基于GLFW的渲染设备 +}//namespace hgl +#endif//HGL_RENDER_DEVICE_INCLUDE diff --git a/inc/hgl/graph/RenderDriver.h b/inc/hgl/graph/RenderDriver.h new file mode 100644 index 00000000..acc631cc --- /dev/null +++ b/inc/hgl/graph/RenderDriver.h @@ -0,0 +1,25 @@ +#ifndef HGL_RENDER_DRIVER_INCLUDE +#define HGL_RENDER_DRIVER_INCLUDE + +#include +namespace hgl +{ + /** + * 渲染驱动 + * 用于对真实渲染API的交接管理 + */ + class RenderDriver + { + private: + + RenderStatus current_status; + + public: + + virtual void SetCurStatus(const RenderStatus &)=0; + + virtual void ClearColorBuffer()=0; + virtual void ClearDepthBuffer()=0; + };//class RenderDriver +}//namespace hgl +#endif//HGL_RENDER_DRIVER_INCLUDE diff --git a/inc/hgl/graph/RenderStatus.h b/inc/hgl/graph/RenderStatus.h new file mode 100644 index 00000000..c973342f --- /dev/null +++ b/inc/hgl/graph/RenderStatus.h @@ -0,0 +1,47 @@ +#ifndef HGL_RENDER_STATUS_INCLUDE +#define HGL_RENDER_STATUS_INCLUDE + +#include +#include +namespace hgl +{ + enum DEPTH_TEST_FUNC + { + DEPTH_TEST_NEVER=0, + DEPTH_TEST_LESS, + DEPTH_TEST_EQUAL, + DEPTH_TEST_LEQUAL, + DEPTH_TEST_GREATER, + DEPTH_TEST_NOTEQUAL, + DEPTH_TEST_GEQUAL, + DEPTH_TEST_ALWAYS + };// + + struct DepthStatus + { + float near_depth =0, + far_depth =1; + + bool depth_mask =true; + float clear_depth =far_depth; + + DEPTH_TEST_FUNC depth_func =DEPTH_TEST_LESS; + bool depth_test; + + public: + + CompOperatorMemcmp(struct DepthStatus &); + };// + + /** + * 渲染状态 + */ + struct RenderStatus + { + bool color_mask[4]; + Color4f clear_color; + + DepthStatus depth; + };//class RenderStatus +}//namespace hgl +#endif//HGL_RENDER_STATUS_INCLUDE diff --git a/inc/hgl/graph/RenderWindow.h b/inc/hgl/graph/RenderWindow.h new file mode 100644 index 00000000..5917c8df --- /dev/null +++ b/inc/hgl/graph/RenderWindow.h @@ -0,0 +1,51 @@ +#ifndef HGL_RENDER_WINDOW_INCLUDE +#define HGL_RENDER_WINDOW_INCLUDE + +#include +#include +namespace hgl +{ + /** + * 渲染窗口基类 + */ + class RenderWindow + { + protected: + + UTF8String caption; + bool full_screen; + + int width,height; + + public: + + const uint GetWidth()const{return width;} + const uint GetHeight()const{return height;} + const bool GetFullScreen()const{return full_screen;} + + public: //方法 + + RenderWindow()=default; ///<本类构造函数 + virtual ~RenderWindow()=default; ///<本类析构函数 + + virtual void ToMin()=0; ///<窗口最小化 + virtual void ToMax()=0; ///<窗口最大化 + + virtual void Show()=0; ///<显示窗口 + virtual void Hide()=0; ///<隐藏窗口 + + virtual const UTF8String &GetCaption()const{return caption;} + virtual void SetCaption(const UTF8String &)=0; + + public: //被实际操作系统接口层所调用的函数,在不了解的情况下请不要使用 + + virtual void SetSize(int w,int h)=0; ///<设置窗口大小 + + virtual void MakeToCurrent()=0; ///<切换到当前 + virtual void SwapBuffer()=0; ///<交换缓冲区 + virtual void WaitEvent(const double &time_out=0)=0; ///<等待下一个事件 + virtual void PollEvent()=0; ///<轮询事件 + virtual bool IsOpen()=0; ///<是否依然存在 + };//class RenderWindow +}//namespace hgl +#endif//HGL_RENDER_WINDOW_INCLUDE diff --git a/inc/hgl/graph/Shader.h b/inc/hgl/graph/Shader.h new file mode 100644 index 00000000..9817aa2c --- /dev/null +++ b/inc/hgl/graph/Shader.h @@ -0,0 +1,195 @@ +#ifndef HGL_SHADER_INCLUDE +#define HGL_SHADER_INCLUDE + +#include +#include +#include +// #include +// #include +namespace hgl +{ + constexpr uint HGL_MAX_SHADER_NAME_LENGTH=128; ///<最大Shader名称长度 + + /** + * 着色程序类型枚举 + */ + enum ShaderType ///着色程序类型 + { + 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) + + 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) ///<增加一个镶嵌着色程序 + { + if(!AddShader(ShaderType::stTessControl,tess_control_shader ))return(false); + if(!AddShader(ShaderType::stTessEval, tess_evaluation_shader ))return(false); + return(true); + } + + bool Build(); ///<构建当前添加的着色程序 + + bool Use(); ///<使用当前着色程序 + + int GetAttribLocation(const char *); ///<取得指定属性地址 + int GetUniformLocation(const char *); ///<取得一个变量的地址 +// int GetUniformBlockIndex(const char *); ///<取得一个只读数据块索引 +// int GetShaderStorageIndex(const char *); ///<取得一个数据存储区索引 + + //bool SetAttrib1f(int,float); + //bool GetAttrib1f(int,float &); + + public: //设置一致变量用函数 + + bool SetUniform1f(int,float); + bool SetUniform2f(int,float,float); + bool SetUniform3f(int,float,float,float); + bool SetUniform4f(int,float,float,float,float); + + bool SetUniform1i(int,int); + bool SetUniform2i(int,int,int); + bool SetUniform3i(int,int,int,int); + bool SetUniform4i(int,int,int,int,int); + + 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 SetUniform1fv(int,const float *); + bool SetUniform2fv(int,const float *); + bool SetUniform3fv(int,const float *); + bool SetUniform4fv(int,const float *); + + 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 hgl +#endif//HGL_SHADER_INCLUDE diff --git a/src/RenderDevice/GLFW/RenderDeviceGLFW.cpp b/src/RenderDevice/GLFW/RenderDeviceGLFW.cpp index ec0a081a..16bb6a33 100644 --- a/src/RenderDevice/GLFW/RenderDeviceGLFW.cpp +++ b/src/RenderDevice/GLFW/RenderDeviceGLFW.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/src/RenderDevice/GLFW/RenderWindowGLFW.cpp b/src/RenderDevice/GLFW/RenderWindowGLFW.cpp index c3647994..3cad17f2 100644 --- a/src/RenderDevice/GLFW/RenderWindowGLFW.cpp +++ b/src/RenderDevice/GLFW/RenderWindowGLFW.cpp @@ -1,4 +1,4 @@ -#include +#include #include namespace hgl diff --git a/src/RenderDriver/GLCore/RenderDriverGLCore.cpp b/src/RenderDriver/GLCore/RenderDriverGLCore.cpp index 855d7785..5f241632 100644 --- a/src/RenderDriver/GLCore/RenderDriverGLCore.cpp +++ b/src/RenderDriver/GLCore/RenderDriverGLCore.cpp @@ -1,4 +1,4 @@ -#include +#include namespace hgl { diff --git a/src/RenderDriver/GLSL.cpp b/src/RenderDriver/GLSL.cpp index 841add90..ce2c129a 100644 --- a/src/RenderDriver/GLSL.cpp +++ b/src/RenderDriver/GLSL.cpp @@ -1,4 +1,4 @@ -#include +#include //#include #include #include diff --git a/src/RenderDriver/Shader.cpp b/src/RenderDriver/Shader.cpp index 1b9df150..9e0d0613 100644 --- a/src/RenderDriver/Shader.cpp +++ b/src/RenderDriver/Shader.cpp @@ -1,5 +1,5 @@ -#include -//#include +#include +//#include namespace hgl {