hgl/render/改为hgl/graph/

This commit is contained in:
hyzboy 2018-11-30 17:46:58 +08:00
parent 623ca91c55
commit 03900a66b0
15 changed files with 470 additions and 17 deletions

View File

@ -1,8 +1,8 @@
#include<hgl/render/RenderDevice.h>
#include<hgl/render/RenderWindow.h>
#include<hgl/graph/RenderDevice.h>
#include<hgl/graph/RenderWindow.h>
#include<iostream>
#include<GLEWCore/glew.h>
#include<hgl/render/Shader.h>
#include<hgl/graph/Shader.h>
#include<hgl/math/Math.h>
using namespace hgl;
@ -18,7 +18,6 @@ void InitMatrix()
false); //Y轴使用底为0顶为1
}
constexpr char vertex_shader[]=R"(
#version 330 core

View File

@ -1,5 +1,5 @@
#include<hgl/render/RenderDevice.h>
#include<hgl/render/RenderWindow.h>
#include<hgl/graph/RenderDevice.h>
#include<hgl/graph/RenderWindow.h>
#include<iostream>
#include<GLFW/glfw3.h>
#include<GL/glcorearb.h>

View File

@ -1,4 +1,4 @@
#include<hgl/render/RenderDevice.h>
#include<hgl/graph/RenderDevice.h>
#include<iostream>
#include<math.h>

View File

@ -1,5 +1,5 @@
#include<hgl/render/RenderDevice.h>
#include<hgl/render/RenderWindow.h>
#include<hgl/graph/RenderDevice.h>
#include<hgl/graph/RenderWindow.h>
#include<iostream>
#include<GLFW/glfw3.h>

View File

@ -1,5 +1,5 @@
#include<hgl/render/RenderDevice.h>
#include<hgl/render/RenderWindow.h>
#include<hgl/graph/RenderDevice.h>
#include<hgl/graph/RenderWindow.h>
#include<iostream>
#include<string.h>
#include<GLEWCore/glew.h>

View File

@ -0,0 +1,136 @@
#ifndef HGL_RENDER_DEVICE_INCLUDE
#define HGL_RENDER_DEVICE_INCLUDE
#include<hgl/type/_Object.h>
#include<hgl/type/BaseString.h>
#include<hgl/type/List.h>
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<VideoMode> &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; ///<Alpha缓冲区位深度,默认8位
uint depth; ///<Depth缓冲区位深度,默认24
uint stencil; ///<Stencil缓冲区位深度,默认8,不使用请写0
bool no_use_stencil; ///<不使用stencil缓冲区
struct
{
uint red; ///<Accum缓冲区红色位深度,默认0
uint green; ///<Accum缓冲区绿色位深度,默认0
uint blue; ///<Accum缓冲区蓝色位深度,默认0
uint alpha; ///<Accum缓冲区Alpha位深度,默认0
}accum;
uint msaa; ///<多重采样级别(全屏抗矩齿级别)
struct
{
struct
{
bool nicest; ///<高质量贴图压缩,默认为真
}compress;
bool rect; ///<是否启用矩形贴图,默认为否
bool npot; ///<是否启用非2次幂贴图默认为否
float lod_bias; ///<默认纹理LOD Bias(默认0)
float max_anistropy; ///<纹理最大各向异性过滤值比例(使用0.0-1.0默认1)
}texture;
struct
{
bool debug=true;
bool core=true;
bool es=false;
bool egl=false;
uint major=3;
uint minor=3;
}opengl;
};
class RenderWindow;
/**
* <br/>
* 访
*/
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<Display *> &)=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

View File

@ -0,0 +1,25 @@
#ifndef HGL_RENDER_DRIVER_INCLUDE
#define HGL_RENDER_DRIVER_INCLUDE
#include<hgl/graph/RenderStatus.h>
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

View File

@ -0,0 +1,47 @@
#ifndef HGL_RENDER_STATUS_INCLUDE
#define HGL_RENDER_STATUS_INCLUDE
#include<hgl/type/Color4f.h>
#include<hgl/CompOperator.h>
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

View File

@ -0,0 +1,51 @@
#ifndef HGL_RENDER_WINDOW_INCLUDE
#define HGL_RENDER_WINDOW_INCLUDE
#include<hgl/type/Vertex2.h>
#include<hgl/type/BaseString.h>
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

195
inc/hgl/graph/Shader.h Normal file
View File

@ -0,0 +1,195 @@
#ifndef HGL_SHADER_INCLUDE
#define HGL_SHADER_INCLUDE
#include<hgl/type/BaseString.h>
#include<hgl/type/Map.h>
#include<hgl/math/Math.h>
// #include<hgl/graph/UBO.h>
// #include<hgl/graph/SSBO.h>
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<UTF8String,int> attrib_location;
Map<UTF8String,int> uniform_location;
// Map<UTF8String,int> uniform_block_index;
// MapObject<UTF8String,UBO> uniform_block_object;
//
// Map<UTF8String,int> ssbo_index;
// MapObject<UTF8String,SSBO> 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

View File

@ -1,4 +1,4 @@
#include<hgl/render/RenderDevice.h>
#include<hgl/graph/RenderDevice.h>
#include<GLEWCore/glew.h>
#include<GLFW/glfw3.h>
#include<iostream>

View File

@ -1,4 +1,4 @@
#include<hgl/render/RenderWindow.h>
#include<hgl/graph/RenderWindow.h>
#include<GLFW/glfw3.h>
namespace hgl

View File

@ -1,4 +1,4 @@
#include<hgl/render/RenderDriver.h>
#include<hgl/graph/RenderDriver.h>
namespace hgl
{

View File

@ -1,4 +1,4 @@
#include<hgl/render/Shader.h>
#include<hgl/graph/Shader.h>
//#include<hgl/LogInfo.h>
#include<hgl/type/Smart.h>
#include<malloc.h>

View File

@ -1,5 +1,5 @@
#include<hgl/render/Shader.h>
//#include<hgl/render/UBO.h>
#include<hgl/graph/Shader.h>
//#include<hgl/graph/UBO.h>
namespace hgl
{