初步定义glfw版本的render device
This commit is contained in:
parent
d8bc6d3ee8
commit
c4db898439
@ -19,4 +19,6 @@ include_directories(inc)
|
|||||||
|
|
||||||
add_subdirectory(3rdpty/MathGeoLib)
|
add_subdirectory(3rdpty/MathGeoLib)
|
||||||
|
|
||||||
|
add_subdirectory(src)
|
||||||
|
|
||||||
add_subdirectory(example)
|
add_subdirectory(example)
|
||||||
|
@ -2,9 +2,96 @@
|
|||||||
#define HGL_RENDER_DEVICE_INCLUDE
|
#define HGL_RENDER_DEVICE_INCLUDE
|
||||||
|
|
||||||
#include<hgl/type/_Object.h>
|
#include<hgl/type/_Object.h>
|
||||||
#include<hgl/type/BaseString.h?
|
#include<hgl/type/BaseString.h>
|
||||||
|
#include<hgl/type/List.h>
|
||||||
|
|
||||||
namespace hgl
|
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()=0;
|
||||||
|
virtual const ObjectList<VideoMode> &GetVideoModeList()=0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WindowSetup
|
||||||
|
{
|
||||||
|
UTF8String Name; ///<窗口标题
|
||||||
|
|
||||||
|
// OSString IconFilename; ///<图标文件名称
|
||||||
|
// OSString CursorFilename; ///<光标文件名称
|
||||||
|
bool Edge; ///<是否显示边框
|
||||||
|
|
||||||
|
bool SysMenu; ///<是否显示系统菜单
|
||||||
|
bool Right; ///<窗口是否使用靠右风格
|
||||||
|
|
||||||
|
bool Resize; ///<窗口大小是否可调整
|
||||||
|
bool Minimize; ///<窗口是否可以最小化
|
||||||
|
bool Maximize; ///<窗口是否可以最大化
|
||||||
|
|
||||||
|
bool TopMost; ///<永远在最上面
|
||||||
|
bool AppTaskBar; ///<程序项在任务栏显示
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渲染设备
|
||||||
|
*/
|
||||||
|
struct RenderSetup
|
||||||
|
{
|
||||||
|
uint alpha; ///<Alpha缓冲区位深度,默认8位
|
||||||
|
uint depth; ///<Depth缓冲区位深度,默认24
|
||||||
|
uint stencil; ///<Stencil缓冲区位深度,默认8,不使用请写0
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
class RenderWindow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染设备基础类<br/>
|
* 渲染设备基础类<br/>
|
||||||
* 该类是程序与操作系统或其它系统库的访问交接模块
|
* 该类是程序与操作系统或其它系统库的访问交接模块
|
||||||
@ -16,12 +103,18 @@ namespace hgl
|
|||||||
RenderDevice()=default;
|
RenderDevice()=default;
|
||||||
virtual ~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 *> &); ///<取得显示屏列表
|
||||||
|
virtual const Display * GetDefaultDisplay()=0; ///<取得默认显示屏
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual UTF8String ToDebugString() override ///<输出调试用字符串
|
virtual RenderWindow *Create(int,int,const WindowSetup *,const RenderSetup *)=0; ///<创建一个窗口渲染设备
|
||||||
{
|
virtual RenderWindow *Create(const Display *,const VideoMode *,const RenderSetup *)=0; ///<创建一个全屏渲染设备
|
||||||
return UTF8String(U8_TEXT("RenderDevice(),this is BUG,please override this Function."));
|
|
||||||
}
|
|
||||||
};//class RenderDevice
|
};//class RenderDevice
|
||||||
|
|
||||||
RenderDevice *CreateRenderDeviceGLFW(); ///<创建一个基于GLFW的渲染设备
|
RenderDevice *CreateRenderDeviceGLFW(); ///<创建一个基于GLFW的渲染设备
|
||||||
|
482
inc/hgl/type/List.cpp
Normal file
482
inc/hgl/type/List.cpp
Normal file
@ -0,0 +1,482 @@
|
|||||||
|
#ifndef HGL_LIST_CPP
|
||||||
|
#define HGL_LIST_CPP
|
||||||
|
|
||||||
|
#include<string.h>
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// 代码中的部分memcpy可替换为memmove,但这样会引起CodeGuard/Valgrind之类的内存调试器报错
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
bool List<T>::Get(int index,T &ti)const
|
||||||
|
{
|
||||||
|
if(!items||index<0||index>=count)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
memcpy(&ti,items+index,sizeof(T));
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool List<T>::Begin(T &ti)const
|
||||||
|
{
|
||||||
|
if(!items)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
memcpy(&ti,items,sizeof(T));
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool List<T>::End(T &ti)const
|
||||||
|
{
|
||||||
|
if(!items)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
memcpy(&ti,items+count-1,sizeof(T));
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool List<T>::Rand(T &ti)const
|
||||||
|
{
|
||||||
|
if(!items||count<=0)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
memcpy(&ti,items+(lrand48()%count),sizeof(T));
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool List<T>::Set(int index,const T &val)
|
||||||
|
{
|
||||||
|
if(!items||index<0||index>=count)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
memcpy(items+index,&val,sizeof(T));//items[index]=val;
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向列表中添加一个空数据
|
||||||
|
* @return 这个数据的指针
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
T *List<T>::Add()
|
||||||
|
{
|
||||||
|
if(!items)
|
||||||
|
{
|
||||||
|
count=1;
|
||||||
|
max_count=1;
|
||||||
|
items=hgl_aligned_malloc<T>(1);
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
max_count=power_to_2(count+1);
|
||||||
|
|
||||||
|
items=(T *)hgl_realloc(items,max_count*sizeof(T));
|
||||||
|
|
||||||
|
++count;
|
||||||
|
return(items+(count-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向列表中添加一个数据对象
|
||||||
|
* @param data 要添加的数据对象
|
||||||
|
* @return 这个数据的索引号
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
int List<T>::Add(const T &data)
|
||||||
|
{
|
||||||
|
if(!items)
|
||||||
|
{
|
||||||
|
count=0;
|
||||||
|
max_count=1;
|
||||||
|
items=hgl_aligned_malloc<T>(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
max_count=power_to_2(count+1);
|
||||||
|
|
||||||
|
items=(T *)hgl_realloc(items,max_count*sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(items+count,&data,sizeof(T));//items[count]=data;
|
||||||
|
return(count++);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重复向列表中添加一个数据对象
|
||||||
|
* @param data 要添加的数据对象
|
||||||
|
* @param n 要添加的数据个数
|
||||||
|
* @return 这个数据的索引号
|
||||||
|
* @return -1 出错
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
int List<T>::Add(const T &data,int n)
|
||||||
|
{
|
||||||
|
if(n<=0)return(-1);
|
||||||
|
|
||||||
|
if(!items)
|
||||||
|
{
|
||||||
|
count=0;
|
||||||
|
max_count=power_to_2(n);
|
||||||
|
items=hgl_aligned_malloc<T>(max_count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
max_count=power_to_2(count+n);
|
||||||
|
|
||||||
|
items=(T *)hgl_realloc(items,max_count*sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
T *p=items;
|
||||||
|
int result=count;
|
||||||
|
|
||||||
|
for(int i=0;i<n;i++)
|
||||||
|
{
|
||||||
|
memcpy(p,&data,sizeof(T));//items[count]=data;
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
|
||||||
|
count+=n;
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向列表中添加一批数据对象
|
||||||
|
* @param data 要添加的数据对象
|
||||||
|
* @param n 要添加的数据数量
|
||||||
|
* @return 起始数据的索引号
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
int List<T>::Add(const T *data,int n)
|
||||||
|
{
|
||||||
|
if(!items)
|
||||||
|
{
|
||||||
|
count=0;
|
||||||
|
max_count=power_to_2(n);
|
||||||
|
|
||||||
|
items=hgl_aligned_malloc<T>(max_count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
max_count=power_to_2(count+n);
|
||||||
|
|
||||||
|
items=(T *)hgl_realloc(items,max_count*sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(items+count,data,n*sizeof(T));
|
||||||
|
|
||||||
|
int r=count;
|
||||||
|
|
||||||
|
count+=n;
|
||||||
|
return(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除整个列表
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void List<T>::Clear()
|
||||||
|
{
|
||||||
|
count=0;
|
||||||
|
max_count=0;
|
||||||
|
|
||||||
|
if(items)
|
||||||
|
{
|
||||||
|
hgl_free(items);
|
||||||
|
items=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除整个列表,但不清除缓冲区
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void List<T>::ClearData()
|
||||||
|
{
|
||||||
|
count=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void List<T>::DeleteClear()
|
||||||
|
{
|
||||||
|
if(count<=0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
T *p=items;
|
||||||
|
|
||||||
|
while(count--)
|
||||||
|
{
|
||||||
|
delete *p;
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
|
||||||
|
count=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在列表中查找指定的数据项
|
||||||
|
* @param data 要查找的数据项
|
||||||
|
* @return 数据在列表中的位置
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
int List<T>::Find(const T &data)const
|
||||||
|
{
|
||||||
|
int n=count;
|
||||||
|
|
||||||
|
while(n--)
|
||||||
|
// if(items[n]==data)return(n);
|
||||||
|
if(memcmp(items+n,&data,sizeof(T))==0)
|
||||||
|
return(n);
|
||||||
|
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除列表中的指定项,删除后将最后一个数据移到被删除的位置
|
||||||
|
* @param index 要删除的数据项的索引值
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
bool List<T>::Delete(int index)
|
||||||
|
{
|
||||||
|
if(!items||count<=0||index<0||index>=count)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
--count;
|
||||||
|
|
||||||
|
if(index<count)
|
||||||
|
memcpy(items+index,items+count,sizeof(T)); //将最后一个数据移到当前位置
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除列表中的指定项,删除后将后面的数据整体前移
|
||||||
|
* @param index 要删除的数据项的索引值
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
bool List<T>::DeleteMove(int index)
|
||||||
|
{
|
||||||
|
if(!items||count<=0||index<0||index>=count)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
--count;
|
||||||
|
|
||||||
|
if(index<count)
|
||||||
|
memmove(items+index,items+index+1,(count-index)*sizeof(T));
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除列表中的指定项
|
||||||
|
* @param start 要删除的数据项的索引起始值
|
||||||
|
* @param number 要删除的数据项数量
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
bool List<T>::Delete(int start,int number)
|
||||||
|
{
|
||||||
|
if(start>=count)return(false);
|
||||||
|
|
||||||
|
if(start<0)
|
||||||
|
{
|
||||||
|
number+=start;
|
||||||
|
start=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(start+number>count)
|
||||||
|
number=count-start;
|
||||||
|
|
||||||
|
if(number<=0)return(false);
|
||||||
|
|
||||||
|
count-=number;
|
||||||
|
|
||||||
|
if(start<count)
|
||||||
|
memmove(items+start,items+start+number,(count-start)*sizeof(T));
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除列表中的指定项
|
||||||
|
* @param data 要删除的数据项
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
bool List<T>::DeleteByValue(const T &dat)
|
||||||
|
{
|
||||||
|
const int index=Find(dat);
|
||||||
|
|
||||||
|
if(index==-1)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
Delete(index);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除列表中的指定项
|
||||||
|
* @param data 要删除的数据项
|
||||||
|
* @param n 要删除的数据个数
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void List<T>::DeleteByValue(const T *data,int n)
|
||||||
|
{
|
||||||
|
while(n--)
|
||||||
|
{
|
||||||
|
int index=Find(*data);
|
||||||
|
|
||||||
|
++data;
|
||||||
|
|
||||||
|
if(index!=-1)
|
||||||
|
Delete(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 交换列表中两个数据的位置
|
||||||
|
* @param a 第一个数据的位置
|
||||||
|
* @param b 第二个数据的位置
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void List<T>::Exchange(int a,int b)
|
||||||
|
{
|
||||||
|
//T t;
|
||||||
|
char t[sizeof(T)];
|
||||||
|
|
||||||
|
// t=items[a];
|
||||||
|
|
||||||
|
// items[a]=items[b];
|
||||||
|
// items[b]=t;
|
||||||
|
|
||||||
|
memcpy(&t,items+a,sizeof(T));
|
||||||
|
memcpy(items+a,items+b,sizeof(T));
|
||||||
|
memcpy(items+b,&t,sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在列表的指定位置中插入一个数据
|
||||||
|
* @param index 插入数据的位置
|
||||||
|
* @param data 要插入的数据
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void List<T>::Insert(int index,const T &data)
|
||||||
|
{
|
||||||
|
if(index<0)index=0;
|
||||||
|
|
||||||
|
if(index<count)
|
||||||
|
{
|
||||||
|
if(!items)
|
||||||
|
{
|
||||||
|
max_count=1;
|
||||||
|
|
||||||
|
items=hgl_aligned_malloc<T>(max_count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
max_count=power_to_2(count+1);
|
||||||
|
|
||||||
|
items=(T *)hgl_realloc(items,max_count*sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
memmove(items+index+1,items+index,(count-index)*sizeof(T));
|
||||||
|
|
||||||
|
memcpy(items+index,&data,sizeof(T));//items[index]=data;
|
||||||
|
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移动列表中的某一项到新的位置
|
||||||
|
* @param index 要移动的数据位置
|
||||||
|
* @param newindex 新的位置
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void List<T>::Move(int index,int newindex)
|
||||||
|
{
|
||||||
|
if(index==newindex)return;
|
||||||
|
if(index<=0||index>=count)return;
|
||||||
|
if(newindex<0)newindex=0;
|
||||||
|
if(newindex>=count)newindex=count-1;
|
||||||
|
|
||||||
|
//T t;
|
||||||
|
char t[sizeof(T)];
|
||||||
|
|
||||||
|
memcpy(&t,items+index,sizeof(T));//t=items[index];
|
||||||
|
|
||||||
|
if(index<newindex)memmove(items+index ,items+index+1 ,(newindex-index)*sizeof(T));
|
||||||
|
else memmove(items+newindex+1 ,items+newindex ,(index-newindex)*sizeof(T));
|
||||||
|
|
||||||
|
memcpy(items+newindex,&t,sizeof(T));//items[newindex]=t;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void List<T>::PreMalloc(int new_count)
|
||||||
|
{
|
||||||
|
if(max_count>=new_count)return;
|
||||||
|
|
||||||
|
max_count=power_to_2(new_count);
|
||||||
|
|
||||||
|
if(!items)
|
||||||
|
items=hgl_aligned_malloc<T>(max_count);
|
||||||
|
else
|
||||||
|
items=(T *)hgl_realloc(items,max_count*sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void List<T>::SetCount(int new_count)
|
||||||
|
{
|
||||||
|
if(count==new_count)return;
|
||||||
|
|
||||||
|
if(new_count<=0)
|
||||||
|
{
|
||||||
|
ClearData();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PreMalloc(new_count);
|
||||||
|
|
||||||
|
count=new_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复制整个列表
|
||||||
|
* @param lt 列表
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void List<T>::operator = (const List<T> <)
|
||||||
|
{
|
||||||
|
if(lt.count<=0)
|
||||||
|
{
|
||||||
|
count=0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetCount(lt.count);
|
||||||
|
|
||||||
|
memcpy(items,lt.items,count*sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void List<T>::operator = (const std::initializer_list<T> &l)
|
||||||
|
{
|
||||||
|
ClearData();
|
||||||
|
|
||||||
|
SetCount((int)l.size());
|
||||||
|
|
||||||
|
memcpy(items,l.begin(),count*sizeof(T));
|
||||||
|
}
|
||||||
|
}//namespace hgl
|
||||||
|
#endif//HGL_LIST_CPP
|
186
inc/hgl/type/List.h
Normal file
186
inc/hgl/type/List.h
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
#ifndef HGL_LIST_INCLUDE
|
||||||
|
#define HGL_LIST_INCLUDE
|
||||||
|
|
||||||
|
#include<stdlib.h>
|
||||||
|
#include<initializer_list>
|
||||||
|
|
||||||
|
#if defined(__BORLANDC__)||defined(__TURBOC__)||defined(__CODEGEARC__)
|
||||||
|
#pragma warn -8022 //使hides vitual function警告无效
|
||||||
|
#endif//
|
||||||
|
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* List类用于保存数据列表。可以在列表中添加、删除、查找、访问和排序数据。
|
||||||
|
*/
|
||||||
|
template <typename T> class List ///列表处理类
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
int count=0;
|
||||||
|
int max_count=0;
|
||||||
|
T *items=nullptr;
|
||||||
|
|
||||||
|
public: //属性
|
||||||
|
|
||||||
|
int GetCount ()const{return count;} ///<取得列表内数据数量
|
||||||
|
virtual void SetCount (int); ///<设置列表内数据数量
|
||||||
|
virtual void PreMalloc (int); ///<预分配指定数量的数据空间
|
||||||
|
T * GetData ()const{return items;} ///<提供原始数据项
|
||||||
|
int GetBytes ()const{return count*sizeof(T);} ///<取得原始数据总字节数
|
||||||
|
|
||||||
|
public: //方法
|
||||||
|
|
||||||
|
List(){}; ///<本类构造函数
|
||||||
|
List(const List<T> <){operator=(lt);} ///<本类构造函数
|
||||||
|
List(const std::initializer_list<T> <){operator=(lt);}
|
||||||
|
|
||||||
|
virtual ~List(){Clear();} ///<本类析构函数
|
||||||
|
|
||||||
|
virtual T * Add(); ///<添加一个空数据
|
||||||
|
virtual int Add(const T &); ///<增加一个数据
|
||||||
|
virtual int Add(const T &,int n); ///<重复增加一个数据
|
||||||
|
virtual int Add(const T *,int n); ///<增加一批数据
|
||||||
|
int Add(const List<T> &l){return Add(l.items,l.count);} ///<增加一批数据
|
||||||
|
|
||||||
|
virtual void Clear(); ///<清除所有数据
|
||||||
|
virtual void ClearData(); ///<清除所有数据,但不清空缓冲区
|
||||||
|
virtual int Find(const T &)const; ///<查找指定数据的索引
|
||||||
|
bool IsExist(const T &flag)const{return Find(flag)!=-1;} ///<确认数据项是否存在
|
||||||
|
virtual bool Delete(int); ///<删除指定索引的数据
|
||||||
|
virtual bool Delete(int,int); ///<删除指定索引的数据
|
||||||
|
virtual bool DeleteMove(int); ///<删除指定索引的数据,将后面紧邻的数据前移
|
||||||
|
virtual bool DeleteByValue(const T &); ///<删除一个指定数据
|
||||||
|
virtual void DeleteByValue(const T *,int); ///<删除一批指定的数据
|
||||||
|
virtual void Exchange(int,int); ///<根据索引交换两个数据
|
||||||
|
virtual void Insert(int,const T &); ///<在指定索引处插入一个数据
|
||||||
|
virtual void Move(int,int); ///<移动一个数据到移指索引处
|
||||||
|
|
||||||
|
void DeleteClear(); ///<清除所有数据并全部调用delete
|
||||||
|
|
||||||
|
virtual void operator = (const List<T> &); ///<操作符重载复制一个列表
|
||||||
|
virtual void operator = (const std::initializer_list<T> &l);
|
||||||
|
|
||||||
|
virtual void operator += (const T &obj){Add(obj);} ///<操作符重载添加一个数据
|
||||||
|
virtual void operator << (const T &obj){Add(obj);} ///<操作符重载添加一个数据
|
||||||
|
virtual void operator -= (const T &obj){DeleteByValue(obj);} ///<操作符重载删除一个数据
|
||||||
|
|
||||||
|
bool Get(int,T &)const; ///<取得指定索引处的数据
|
||||||
|
bool Set(int,const T &); ///<设置指定索引处的数据
|
||||||
|
bool Rand(T &)const; ///<随机取得一个数据
|
||||||
|
|
||||||
|
virtual bool Begin(T &)const; ///<取第一个数据
|
||||||
|
virtual bool End(T &)const; ///<取最后一个数据
|
||||||
|
|
||||||
|
virtual void Enum(void (*enum_func)(T &)) ///<枚举所有数据成员
|
||||||
|
{
|
||||||
|
T *obj=items;
|
||||||
|
|
||||||
|
for(int i=0;i<count;i++)
|
||||||
|
{
|
||||||
|
enum_func(*obj);
|
||||||
|
++obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};//template <typename T> class List
|
||||||
|
|
||||||
|
template<typename T> T *GetObject(const List<T *> &list,const int index)
|
||||||
|
{
|
||||||
|
T *obj;
|
||||||
|
|
||||||
|
if(list.Get(index,obj))
|
||||||
|
return(obj);
|
||||||
|
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
}//namespace hgl
|
||||||
|
|
||||||
|
#include<hgl/type/List.cpp>
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 自定义对象列表处理类与标准列表处理类的区别在于它对数据生成/清除时会多调用虚拟函数Create/Delte
|
||||||
|
*/
|
||||||
|
template<typename T> class CusObjectList:public List<T *> ///对象列表处理类
|
||||||
|
{
|
||||||
|
virtual void SetCount(int);
|
||||||
|
|
||||||
|
// virtual T * CreateObject()=0; ///<创建一个数据,但不加入列表
|
||||||
|
virtual void DeleteObject(T *)=0; ///<删除一个数据
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef T *ItemPointer;
|
||||||
|
|
||||||
|
public: //方法
|
||||||
|
|
||||||
|
CusObjectList(){}
|
||||||
|
virtual ~CusObjectList();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// virtual T * Append(); ///<追加一个数据
|
||||||
|
// virtual T * Insert(int); ///<在指定索引处创建一个数据
|
||||||
|
void Insert(int,const ItemPointer &); ///<在指定索引处插入一个数据
|
||||||
|
|
||||||
|
virtual void Clear(); ///<清除所有数据
|
||||||
|
virtual void ClearData(); ///<清除所有数据,但不清空缓冲区
|
||||||
|
|
||||||
|
virtual bool Unlink(int index){return List<T *>::Delete(index);} ///<将指定索引处的数据与列表断开
|
||||||
|
virtual bool UnlinkMove(int index){return List<T *>::DeleteMove(index);} ///<将指定索引处的数据与列表断开,将前移后面的数据
|
||||||
|
virtual bool Unlink(int start,int number){return List<T *>::Delete(start,number);} ///<将指定索引处的数据与列表断开
|
||||||
|
virtual bool UnlinkByValue(const ItemPointer &ip){return List<T *>::DeleteByValue(ip);} ///<将一个指定数据与列表断开
|
||||||
|
virtual void UnlinkByValue(const ItemPointer *ip,int n){List<T *>::DeleteByValue(ip,n);} ///<将一批指定数据与列表断开
|
||||||
|
virtual void UnlinkAll(){List<T *>::ClearData();} ///<断开所有数据
|
||||||
|
|
||||||
|
virtual bool Delete(int); ///<删除指定索引处的数据
|
||||||
|
virtual bool DeleteMove(int); ///<删除指定索引处的数据
|
||||||
|
virtual bool DeleteByValue(const ItemPointer &); ///<删除指定的一个数据
|
||||||
|
virtual void DeleteByValue(const ItemPointer *,int); ///<删除指定的一批数据
|
||||||
|
virtual void DeleteAll(); ///<删除所有数据
|
||||||
|
|
||||||
|
virtual ItemPointer &operator[](int n)const ///<操作符重载取得指定索引处的数据
|
||||||
|
{
|
||||||
|
static T *null_pointer=nullptr;
|
||||||
|
|
||||||
|
if(n<0||n>=this->count)
|
||||||
|
return(null_pointer);
|
||||||
|
|
||||||
|
return this->items[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Enum(void (*enum_func)(T *)) ///<枚举所有数据成员
|
||||||
|
{
|
||||||
|
T **obj=this->items;
|
||||||
|
|
||||||
|
for(int i=0;i<this->count;i++)
|
||||||
|
{
|
||||||
|
enum_func(*obj);
|
||||||
|
|
||||||
|
++obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};//template <typename T> class CusObjectList
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象列表处理类<br>
|
||||||
|
* 将自定义对象列表中的Create重载为new,Delete重载为delete
|
||||||
|
*/
|
||||||
|
template<typename T> class ObjectList:public CusObjectList<T>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
// virtual T * CreateObject(){return(new T);} ///<创建一个数据
|
||||||
|
virtual void DeleteObject(T *obj){if(obj)delete obj;} ///<删除一个数据
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~ObjectList()
|
||||||
|
{
|
||||||
|
CusObjectList<T>::Clear();
|
||||||
|
}
|
||||||
|
};//class ObjectList
|
||||||
|
}//namespace hgl
|
||||||
|
#include<hgl/type/ObjectList.cpp>
|
||||||
|
#endif//HGL_LIST_INCLUDE
|
249
inc/hgl/type/ObjectList.cpp
Normal file
249
inc/hgl/type/ObjectList.cpp
Normal file
@ -0,0 +1,249 @@
|
|||||||
|
#ifndef HGL_OBJECT_LIST_CPP
|
||||||
|
#define HGL_OBJECT_LIST_CPP
|
||||||
|
|
||||||
|
#include<hgl/type/List.h>
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 对象列表析构函数,会调用DeleteAll函数
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
CusObjectList<T>::~CusObjectList()
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 生成一个对象,并返回它的指针
|
||||||
|
// */
|
||||||
|
// template<typename T>
|
||||||
|
// T *CusObjectList<T>::Append()
|
||||||
|
// {
|
||||||
|
// if(!this->items)
|
||||||
|
// {
|
||||||
|
// this->max_count=1;
|
||||||
|
// this->items=(T **)hgl_aligned_malloc<T *>(1);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// if(this->count>=this->max_count)
|
||||||
|
// this->max_count<<=1;
|
||||||
|
//
|
||||||
|
// this->items=(T **)hgl_realloc(this->items,this->max_count*sizeof(T *));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return(this->items[this->count++]=CreateObject());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 在指定位置插入一个对象
|
||||||
|
// */
|
||||||
|
// template<typename T>
|
||||||
|
// T *CusObjectList<T>::Insert(int index)
|
||||||
|
// {
|
||||||
|
// if(index<0)index=0;
|
||||||
|
//
|
||||||
|
// if(index<this->count)
|
||||||
|
// {
|
||||||
|
// if(this->count>=this->max_count)
|
||||||
|
// this->max_count<<=1;
|
||||||
|
//
|
||||||
|
// this->items=(T **)hgl_realloc(this->items,this->max_count*sizeof(T *));
|
||||||
|
//
|
||||||
|
// memmove(this->items+index+1,this->items+index,(this->count-index)*sizeof(T *));
|
||||||
|
//
|
||||||
|
// this->count++;
|
||||||
|
//
|
||||||
|
// return(this->items[index]=CreateObject());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return(Append());
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在指定位置插入一个对象
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void CusObjectList<T>::Insert(int index,const ItemPointer &obj)
|
||||||
|
{
|
||||||
|
List<T *>::Insert(index,obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除所有对象,作用和DeleteAll一样
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void CusObjectList<T>::Clear()
|
||||||
|
{
|
||||||
|
DeleteAll();
|
||||||
|
List<T *>::Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除所有对象,但不释放内存
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void CusObjectList<T>::ClearData()
|
||||||
|
{
|
||||||
|
DeleteAll();
|
||||||
|
List<T *>::ClearData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除列表中的指定项
|
||||||
|
*
|
||||||
|
* 这个函数在删除指定对象时,附加使用delete方法
|
||||||
|
* @param index 要删除的对象的索引值
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
bool CusObjectList<T>::Delete(int index)
|
||||||
|
{
|
||||||
|
if(index>=0&&index<this->count)
|
||||||
|
{
|
||||||
|
DeleteObject(this->items[index]);
|
||||||
|
|
||||||
|
this->count--;
|
||||||
|
|
||||||
|
if(index<this->count)
|
||||||
|
memcpy(this->items+index,this->items+this->count,sizeof(T *));
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除列表中的指定项
|
||||||
|
*
|
||||||
|
* 这个函数在删除指定对象时,附加使用delete方法
|
||||||
|
* @param index 要删除的对象的索引值
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
bool CusObjectList<T>::DeleteMove(int index)
|
||||||
|
{
|
||||||
|
if(index>=0&&index<this->count)
|
||||||
|
{
|
||||||
|
DeleteObject(this->items[index]);
|
||||||
|
|
||||||
|
this->count--;
|
||||||
|
|
||||||
|
if(index<this->count)
|
||||||
|
memmove(this->items+index,this->items+index+1,(this->count-index)*sizeof(T *));
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除列表中的指定项
|
||||||
|
*
|
||||||
|
* 这个函数在删除指定对象时,附加使用delete方法
|
||||||
|
* @param obj 要删除的对象
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
bool CusObjectList<T>::DeleteByValue(const ItemPointer &obj)
|
||||||
|
{
|
||||||
|
int n=this->count;
|
||||||
|
|
||||||
|
while(n--)
|
||||||
|
{
|
||||||
|
if(this->items[n]==obj)
|
||||||
|
{
|
||||||
|
DeleteObject(this->items[n]);
|
||||||
|
|
||||||
|
this->count--;
|
||||||
|
|
||||||
|
if(n<this->count)
|
||||||
|
memmove(this->items+n,this->items+n+1,(this->count-n)*sizeof(T *));
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将一批对象从列表中删除
|
||||||
|
* @param obj 要删除的对象
|
||||||
|
* @param n 要删除的对象个数
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void CusObjectList<T>::DeleteByValue(const ItemPointer *obj,int n)
|
||||||
|
{
|
||||||
|
while(n--)
|
||||||
|
{
|
||||||
|
int index=List<T *>::Find(*obj);
|
||||||
|
|
||||||
|
obj++;
|
||||||
|
|
||||||
|
if(index!=-1)
|
||||||
|
Delete(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 删除整个列表中的所有对象
|
||||||
|
*
|
||||||
|
* 这个函数在删除每一个对象时,都会使用一次delete
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void CusObjectList<T>::DeleteAll()
|
||||||
|
{
|
||||||
|
if(this->count)
|
||||||
|
{
|
||||||
|
int n=this->count;
|
||||||
|
|
||||||
|
while(n--)
|
||||||
|
DeleteObject(this->items[n]);
|
||||||
|
|
||||||
|
this->count=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CusObjectList<T>::SetCount(int new_count)
|
||||||
|
{
|
||||||
|
if(this->count==new_count)return;
|
||||||
|
|
||||||
|
if(new_count<=0)
|
||||||
|
{
|
||||||
|
DeleteAll();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->max_count=power_to_2(new_count);
|
||||||
|
|
||||||
|
if(this->items)
|
||||||
|
{
|
||||||
|
if(new_count>this->count)
|
||||||
|
{
|
||||||
|
this->items=(T **)hgl_realloc(this->items,this->max_count*sizeof(T *));
|
||||||
|
|
||||||
|
// for(;this->count<new_count;this->count++)
|
||||||
|
// this->items[this->count]=CreateObject();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while(this->count-->new_count)
|
||||||
|
DeleteObject(this->items[this->count]);
|
||||||
|
|
||||||
|
this->items=(T **)hgl_realloc(this->items,this->max_count*sizeof(T *));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// this->items=(T **)hgl_aligned_malloc<T *>(this->max_count);
|
||||||
|
//
|
||||||
|
// while(new_count--)
|
||||||
|
// this->items[this->count++]=CreateObject();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}//namespace hgl
|
||||||
|
#endif//HGL_OBJECT_LIST_CPP
|
@ -1,8 +1,6 @@
|
|||||||
#ifndef HGL__OBJECT_INCLUDE
|
#ifndef HGL__OBJECT_INCLUDE
|
||||||
#define HGL__OBJECT_INCLUDE
|
#define HGL__OBJECT_INCLUDE
|
||||||
|
|
||||||
#include<hgl/type/BaseString.h>
|
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -13,10 +11,6 @@ namespace hgl
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~_Object()=default; ///<本类析构函数
|
virtual ~_Object()=default; ///<本类析构函数
|
||||||
|
|
||||||
public: //调试用
|
|
||||||
|
|
||||||
virtual UTF8String ToDebugString(){} ///<输出调试用字符串
|
|
||||||
};//class _Object
|
};//class _Object
|
||||||
|
|
||||||
typedef void (_Object::*ObjectMemberFunc)();
|
typedef void (_Object::*ObjectMemberFunc)();
|
||||||
|
2
src/CMakeLists.txt
Normal file
2
src/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
add_subdirectory(RenderDevice)
|
1
src/RenderDevice/CMakeLists.txt
Normal file
1
src/RenderDevice/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
add_library(ULRE.RenderDevice STATIC GLFW/RenderDeviceGLFW.cpp)
|
@ -1 +1,146 @@
|
|||||||
|
#include<hgl/render/device/RenderDevice.h>
|
||||||
|
#include<GLFW/glfw3.h>
|
||||||
|
#include<iostream>
|
||||||
|
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
static RenderDevice *render_device_glfw=nullptr;
|
||||||
|
|
||||||
|
void glfw_error_callback(int err,const char *desc)
|
||||||
|
{
|
||||||
|
std::cerr<<"glfw return error["<<err<<"] <<"<<desc<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DisplayGLFW:public Display
|
||||||
|
{
|
||||||
|
GLFWmonitor *glfw_monitor;
|
||||||
|
|
||||||
|
VideoMode *cur_video_mode;
|
||||||
|
ObjectList<VideoMode> video_mode_list;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
const VideoMode *GetCurVideoMode()override{return cur_video_mode;}
|
||||||
|
const ObjectList<VideoMode> &GetVideoModeList()override{return video_mode_list;}
|
||||||
|
};
|
||||||
|
|
||||||
|
VideoMode *ConvertVideoMode(const GLFWvidmode *mode)
|
||||||
|
{
|
||||||
|
if(mode)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
VideoMode *vm=new VideoMode;
|
||||||
|
|
||||||
|
vm->width =mode->width;
|
||||||
|
vm->height =mode->height;
|
||||||
|
vm->freq =mode->refreshRate;
|
||||||
|
|
||||||
|
vm->red =mode->redBits;
|
||||||
|
vm->green =mode->greenBits;
|
||||||
|
vm->blue =mode->blueBits;
|
||||||
|
|
||||||
|
vm->bit =vm->red+vm->green+vm->blue;
|
||||||
|
|
||||||
|
return vm;
|
||||||
|
}
|
||||||
|
|
||||||
|
DisplayGLFW *GetDisplayAttrib(GLFWmonitor *gm)
|
||||||
|
{
|
||||||
|
DisplayGLFW *m=new DisplayGLFW;
|
||||||
|
|
||||||
|
m->glfw_monitor=gm;
|
||||||
|
m->name=glfwGetMonitorName(gm);
|
||||||
|
|
||||||
|
glfwGetMonitorPhysicalSize(gm,&(m->width),&(m->height));
|
||||||
|
glfwGetMonitorPos(gm,&(m->x),&(m->y));
|
||||||
|
|
||||||
|
{
|
||||||
|
const GLFWvidmode *mode=glfwGetVideoMode(gm);
|
||||||
|
|
||||||
|
m->cur_video_mode=ConvertVideoMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
int count;
|
||||||
|
|
||||||
|
const GLFWvidmode *ml=glfwGetVideoModes(gm,&count);
|
||||||
|
|
||||||
|
for(int i=0;i<count;i++)
|
||||||
|
m->video_mode_list.Add(ConvertVideoMode(ml+i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RenderDeviceGLFW:public RenderDevice
|
||||||
|
{
|
||||||
|
DisplayGLFW *default_display=nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
RenderDeviceGLFW()
|
||||||
|
{
|
||||||
|
render_device_glfw=this;
|
||||||
|
}
|
||||||
|
|
||||||
|
~RenderDeviceGLFW()
|
||||||
|
{
|
||||||
|
glfwTerminate();
|
||||||
|
render_device_glfw=nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool Init()override{return true;}
|
||||||
|
const void Close()override{};
|
||||||
|
|
||||||
|
const UTF8String GetName()override ///<取得设备名称
|
||||||
|
{
|
||||||
|
return UTF8String("GLFW")+UTF8String(glfwGetVersionString());
|
||||||
|
}
|
||||||
|
|
||||||
|
const void GetDisplayList(List<Display *> &disp_list) ///<取得显示屏列表
|
||||||
|
{
|
||||||
|
int count=0;
|
||||||
|
|
||||||
|
GLFWmonitor **ml=glfwGetMonitors(&count);
|
||||||
|
|
||||||
|
for(int i=0;i<count;i++)
|
||||||
|
disp_list+=GetDisplayAttrib(ml[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Display * GetDefaultDisplay()
|
||||||
|
{
|
||||||
|
if(!default_display)
|
||||||
|
default_display=GetDisplayAttrib(glfwGetPrimaryMonitor());
|
||||||
|
|
||||||
|
return default_display;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
RenderWindow *Create(int,int,const WindowSetup *,const RenderSetup *) override
|
||||||
|
{
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderWindow *Create(const Display *,const VideoMode *,const RenderSetup *) override
|
||||||
|
{
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
};//class RenderDevice
|
||||||
|
|
||||||
|
RenderDevice *CreateRenderDeviceGLFW()
|
||||||
|
{
|
||||||
|
if(render_device_glfw)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
if(!glfwInit())
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
glfwSetErrorCallback(glfw_error_callback);
|
||||||
|
|
||||||
|
return(new RenderDeviceGLFW());
|
||||||
|
}
|
||||||
|
}//namespace hgl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user